Search in sources :

Example 86 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class BoxProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    if (sentence.startsWith("H,")) {
        int index = sentence.indexOf(',', 2) + 1;
        String id = sentence.substring(index, sentence.indexOf(',', index));
        getDeviceSession(channel, remoteAddress, id);
    } else if (sentence.startsWith("E,")) {
        if (channel != null) {
            channel.write("A," + sentence.substring(2) + "\r");
        }
    } else if (sentence.startsWith("L,")) {
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
        if (deviceSession == null) {
            return null;
        }
        Parser parser = new Parser(PATTERN, sentence);
        if (!parser.matches()) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setTime(parser.nextDateTime());
        position.setLatitude(parser.nextDouble(0));
        position.setLongitude(parser.nextDouble(0));
        position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
        position.setCourse(parser.nextDouble(0));
        position.set(Position.KEY_ODOMETER_TRIP, parser.nextDouble(0) * 1000);
        position.set(Position.KEY_EVENT, parser.next());
        int status = parser.nextInt(0);
        position.setValid((status & 0x04) == 0);
        position.set(Position.KEY_STATUS, status);
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 87 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class CautelaProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    Parser parser = new Parser(PATTERN, (String) msg);
    if (!parser.matches()) {
        return null;
    }
    String type = parser.next();
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder = new DateBuilder();
    dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
    position.setValid(true);
    position.setLatitude(parser.nextDouble());
    position.setLongitude(parser.nextDouble());
    dateBuilder.setHour(parser.nextInt()).setMinute(parser.nextInt());
    position.setTime(dateBuilder.getDate());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Example 88 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class CguardProtocolDecoder method decodePosition.

private Position decodePosition(DeviceSession deviceSession, String sentence) {
    Parser parser = new Parser(PATTERN_NV, sentence);
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.setTime(parser.nextDateTime());
    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.setAccuracy(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    return position;
}
Also used : Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 89 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class CityeasyProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    // length
    buf.readUnsignedShort();
    String imei = ChannelBuffers.hexDump(buf.readBytes(7));
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
    if (deviceSession == null) {
        return null;
    }
    int type = buf.readUnsignedShort();
    if (type == MSG_LOCATION_REPORT || type == MSG_LOCATION_REQUEST) {
        String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 8, StandardCharsets.US_ASCII);
        Parser parser = new Parser(PATTERN, sentence);
        if (!parser.matches()) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        if (parser.hasNext(15)) {
            position.setTime(parser.nextDateTime());
            position.setValid(parser.next().equals("A"));
            position.set(Position.KEY_SATELLITES, parser.nextInt());
            position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
            position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
            position.setSpeed(parser.nextDouble(0));
            position.set(Position.KEY_HDOP, parser.nextDouble(0));
            position.setAltitude(parser.nextDouble(0));
        } else {
            getLastLocation(position, null);
        }
        position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))));
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Parser(org.traccar.helper.Parser)

Example 90 with Parser

use of org.traccar.helper.Parser in project traccar by tananaev.

the class AutoGradeProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    Parser parser = new Parser(PATTERN, (String) msg);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder = new DateBuilder().setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());
    position.setCourse(parser.nextDouble(0));
    int status = parser.next().charAt(0);
    position.set(Position.KEY_STATUS, status);
    position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
    for (int i = 1; i <= 5; i++) {
        position.set(Position.PREFIX_ADC + i, parser.next());
    }
    for (int i = 1; i <= 5; i++) {
        position.set("can" + i, parser.next());
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Aggregations

Parser (org.traccar.helper.Parser)137 Position (org.traccar.model.Position)129 DeviceSession (org.traccar.DeviceSession)110 DateBuilder (org.traccar.helper.DateBuilder)41 Network (org.traccar.model.Network)25 WifiAccessPoint (org.traccar.model.WifiAccessPoint)8 Date (java.util.Date)7 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)7 LinkedList (java.util.LinkedList)4 Pattern (java.util.regex.Pattern)4 Matcher (java.util.regex.Matcher)2 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)2 QueryStringDecoder (org.jboss.netty.handler.codec.http.QueryStringDecoder)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1