Search in sources :

Example 96 with Parser

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

the class ExtremTracProtocolDecoder 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().setTime(parser.nextInt(0), 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 97 with Parser

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

the class FifotrackProtocolDecoder 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_ALARM, parser.next());
    position.setTime(parser.nextDateTime());
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
    position.setCourse(parser.nextInt(0));
    position.setAltitude(parser.nextInt(0));
    position.set(Position.KEY_ODOMETER, parser.nextLong(0));
    position.set(Position.KEY_STATUS, parser.nextHexInt(0));
    if (parser.hasNext()) {
        position.set(Position.KEY_INPUT, parser.nextHexInt(0));
    }
    if (parser.hasNext()) {
        position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
    }
    position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
    String[] adc = parser.next().split("\\|");
    for (int i = 0; i < adc.length; i++) {
        position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16));
    }
    position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
    if (parser.hasNext()) {
        String[] sensors = parser.next().split("\\|");
        for (int i = 0; i < sensors.length; i++) {
            position.set(Position.PREFIX_IO + (i + 1), sensors[i]);
        }
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 98 with Parser

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

the class FreedomProtocolDecoder 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());
    position.setValid(true);
    position.setTime(parser.nextDateTime());
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setSpeed(parser.nextDouble(0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 99 with Parser

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

the class Gl200TextProtocolDecoder method decodeAck.

private Object decodeAck(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
    Parser parser = new Parser(PATTERN_ACK, sentence);
    if (parser.matches()) {
        String protocolVersion = parser.next();
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        if (deviceSession == null) {
            return null;
        }
        if (type.equals("HBD")) {
            if (channel != null) {
                parser.skip(6);
                channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress);
            }
        } else {
            Position position = new Position(getProtocolName());
            position.setDeviceId(deviceSession.getDeviceId());
            getLastLocation(position, parser.nextDateTime());
            position.setValid(false);
            position.set(Position.KEY_RESULT, "Command " + type + " accepted");
            return position;
        }
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 100 with Parser

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

the class Gl200TextProtocolDecoder method decodeEri.

private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_ERI, sentence);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
    if (deviceSession == null) {
        return null;
    }
    long mask = parser.nextHexLong();
    LinkedList<Position> positions = new LinkedList<>();
    Integer power = parser.nextInt();
    Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
    while (itemParser.find()) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        decodeLocation(position, itemParser);
        positions.add(position);
    }
    Position position = positions.getLast();
    decodeLocation(position, parser);
    if (power != null) {
        position.set(Position.KEY_POWER, power * 0.001);
    }
    position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
    position.set(Position.KEY_HOURS, parser.next());
    position.set(Position.PREFIX_ADC + 1, parser.next());
    position.set(Position.PREFIX_ADC + 2, parser.next());
    position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
    decodeStatus(position, parser);
    int index = 0;
    String[] data = parser.next().split(",");
    // device type
    index += 1;
    if (BitUtil.check(mask, 0)) {
        // digital fuel sensor data
        index += 1;
    }
    if (BitUtil.check(mask, 1)) {
        int deviceCount = Integer.parseInt(data[index++]);
        for (int i = 1; i <= deviceCount; i++) {
            // id
            index += 1;
            // type
            index += 1;
            if (!data[index++].isEmpty()) {
                position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625);
            }
        }
    }
    if (BitUtil.check(mask, 2)) {
        // can data
        index += 1;
    }
    if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) {
        int deviceCount = Integer.parseInt(data[index++]);
        for (int i = 1; i <= deviceCount; i++) {
            // type
            index += 1;
            if (BitUtil.check(mask, 3)) {
                position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++]));
            }
            if (BitUtil.check(mask, 4)) {
                // volume
                index += 1;
            }
        }
    }
    decodeDeviceTime(position, parser);
    if (ignoreFixTime) {
        positions.clear();
        positions.add(position);
    }
    return positions;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) LinkedList(java.util.LinkedList) WifiAccessPoint(org.traccar.model.WifiAccessPoint) 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