Search in sources :

Example 81 with Parser

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

the class RaveonProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    Parser parser = new Parser(PATTERN, sentence);
    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());
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS));
    position.setValid(parser.nextInt(0) != 0);
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.setAltitude(parser.nextInt(0));
    position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
    position.set(Position.KEY_POWER, parser.nextDouble(0));
    position.set(Position.KEY_INPUT, parser.nextInt(0));
    position.set(Position.KEY_RSSI, parser.nextInt(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
    position.setCourse(parser.nextInt(0));
    position.set(Position.KEY_ALARM, parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 82 with Parser

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

the class RitiProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    Position position = new Position(getProtocolName());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    position.set("mode", buf.readUnsignedByte());
    position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
    position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
    // status
    buf.skipBytes(5);
    // idleCount
    buf.readUnsignedShort();
    // idleTime in seconds
    buf.readUnsignedShort();
    position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
    position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
    // Parse GPRMC
    int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
    String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
    Parser parser = new Parser(PATTERN, gprmc);
    if (!parser.matches()) {
        return null;
    }
    DateBuilder dateBuilder = new DateBuilder().setTime(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));
    position.setCourse(parser.nextDouble(0));
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Parser(org.traccar.helper.Parser)

Example 83 with Parser

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

the class SanavProtocolDecoder 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;
    }
    Position position = new Position(getProtocolName());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder = new DateBuilder().setTime(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));
    position.setCourse(parser.nextDouble(0));
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    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 84 with Parser

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

the class SiwiProtocolDecoder 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());
    position.set(Position.KEY_EVENT, parser.next());
    position.set(Position.KEY_IGNITION, parser.next().equals("1"));
    position.set(Position.KEY_ODOMETER, parser.nextInt(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setCourse(parser.nextInt(0));
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "IST"));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 85 with Parser

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

the class AuroProtocolDecoder 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;
    }
    Position position = new Position(getProtocolName());
    position.set(Position.KEY_INDEX, parser.nextInt(0));
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    position.setDeviceId(deviceSession.getDeviceId());
    position.setValid(true);
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.setCourse(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.set(Position.KEY_BATTERY, parser.nextInt(0));
    position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) 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