Search in sources :

Example 46 with Parser

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

the class Gl200TextProtocolDecoder method decodeIda.

private Object decodeIda(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_IDA, sentence);
    Position position = initPosition(parser, channel, remoteAddress);
    if (position == null) {
        return null;
    }
    position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
    decodeLocation(position, parser);
    position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
    decodeDeviceTime(position, parser);
    return position;
}
Also used : Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 47 with Parser

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

the class Gl200TextProtocolDecoder method decodeObd.

private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_OBD, sentence);
    Position position = initPosition(parser, channel, remoteAddress);
    if (position == null) {
        return null;
    }
    position.set(Position.KEY_RPM, parser.nextInt());
    position.set(Position.KEY_OBD_SPEED, parser.nextInt());
    position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
    position.set(Position.KEY_FUEL_CONSUMPTION, parser.next());
    position.set("dtcsClearedDistance", parser.nextInt());
    if (parser.hasNext()) {
        position.set("odbConnect", parser.nextInt() == 1);
    }
    position.set("dtcsNumber", parser.nextInt());
    position.set("dtcsCodes", parser.next());
    position.set(Position.KEY_THROTTLE, parser.nextInt());
    position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
    if (parser.hasNext()) {
        position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000);
    }
    decodeLocation(position, parser);
    if (parser.hasNext()) {
        position.set(Position.KEY_OBD_ODOMETER, (int) (parser.nextDouble() * 1000));
    }
    decodeDeviceTime(position, parser);
    return position;
}
Also used : Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 48 with Parser

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

the class GlobalSatProtocolDecoder method decodeAlternative.

private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN, sentence);
    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());
    position.setValid(!parser.next().equals("1"));
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.set(Position.KEY_HDOP, parser.nextDouble());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 49 with Parser

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

the class H02ProtocolDecoder method decodeLbs.

private Position decodeLbs(String sentence, Channel channel, SocketAddress remoteAddress) {
    Parser parser = new Parser(PATTERN_NBR, 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());
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    Network network = new Network();
    int mcc = parser.nextInt(0);
    int mnc = parser.nextInt(0);
    String[] cells = parser.next().split(",");
    for (int i = 0; i < cells.length / 3; i++) {
        network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(cells[i * 3]), Integer.parseInt(cells[i * 3 + 1]), Integer.parseInt(cells[i * 3 + 2])));
    }
    position.setNetwork(network);
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    getLastLocation(position, dateBuilder.getDate());
    processStatus(position, parser.nextLong(16, 0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 50 with Parser

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

the class HunterProProtocolDecoder 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();
    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)

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