Search in sources :

Example 36 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Tk103ProtocolDecoder method decodeCommandResult.

private Position decodeCommandResult(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_COMMAND_RESULT, 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());
    getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.set(Position.KEY_RESULT, parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 37 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class Tk103ProtocolDecoder method decodeNetwork.

private Position decodeNetwork(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_NETWORK, 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());
    getLastLocation(position, null);
    position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 38 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class TmgProtocolDecoder 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());
    switch(type) {
        case "rmv":
            position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
            break;
        case "ebl":
            position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
            break;
        case "ibl":
            position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
            break;
        case "tmp":
        case "smt":
        case "btt":
            position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
            break;
        case "ion":
            position.set(Position.KEY_IGNITION, true);
            break;
        case "iof":
            position.set(Position.KEY_IGNITION, false);
            break;
        default:
            break;
    }
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.setValid(parser.nextInt() > 0);
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
    position.setCourse(parser.nextDouble());
    if (parser.hasNext(15)) {
        position.setAltitude(parser.nextDouble());
        position.set(Position.KEY_HDOP, parser.nextDouble());
        position.set(Position.KEY_SATELLITES, parser.nextInt());
        position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt());
        position.set(Position.KEY_OPERATOR, parser.next());
        position.set(Position.KEY_RSSI, parser.nextInt());
        position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
        position.set(Position.KEY_BATTERY, parser.nextDouble());
        position.set(Position.KEY_POWER, parser.nextDouble());
        int input = parser.nextBinInt();
        int output = parser.nextBinInt();
        if (!BitUtil.check(input, 0)) {
            position.set(Position.KEY_ALARM, Position.ALARM_SOS);
        }
        position.set(Position.KEY_INPUT, input);
        position.set(Position.KEY_OUTPUT, output);
        position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
        position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
        position.set(Position.KEY_VERSION_FW, parser.next());
        position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
    }
    if (parser.hasNext(6)) {
        position.set(Position.KEY_RSSI, parser.nextInt());
        position.set(Position.KEY_SATELLITES, parser.nextInt());
        position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
        char[] input = parser.next().toCharArray();
        for (int i = 0; i < input.length; i++) {
            position.set(Position.PREFIX_IN + (i + 1), input[i] == 'H');
        }
        char[] output = parser.next().toCharArray();
        for (int i = 0; i < output.length; i++) {
            position.set(Position.PREFIX_OUT + (i + 1), output[i] == 'H');
        }
        position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
        position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
        position.set(Position.KEY_ODOMETER, parser.nextInt());
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 39 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class TopflytechProtocolDecoder 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.setTime(parser.nextDateTime());
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 40 with DeviceSession

use of org.traccar.DeviceSession in project traccar by tananaev.

the class TelicProtocolDecoder 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());
    int event = parser.nextInt(0);
    position.set(Position.KEY_EVENT, event);
    position.set(Position.KEY_ALARM, decodeAlarm(event));
    if (event == 11) {
        position.set(Position.KEY_IGNITION, true);
    } else if (event == 12) {
        position.set(Position.KEY_IGNITION, false);
    }
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    if (parser.hasNext(6)) {
        position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
        position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
    }
    if (parser.hasNext(2)) {
        position.setLongitude(parser.nextDouble(0) / 10000);
        position.setLatitude(parser.nextDouble(0) / 10000);
    }
    position.setValid(parser.nextInt(0) != 1);
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.setCourse(parser.nextDouble(0));
    if (parser.hasNext()) {
        position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    }
    position.set(Position.KEY_BATTERY, parser.nextInt(0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Aggregations

DeviceSession (org.traccar.DeviceSession)197 Position (org.traccar.model.Position)188 Parser (org.traccar.helper.Parser)110 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)64 DateBuilder (org.traccar.helper.DateBuilder)63 Date (java.util.Date)37 Network (org.traccar.model.Network)37 LinkedList (java.util.LinkedList)30 SimpleDateFormat (java.text.SimpleDateFormat)10 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)10 List (java.util.List)9 WifiAccessPoint (org.traccar.model.WifiAccessPoint)9 DateFormat (java.text.DateFormat)8 Pattern (java.util.regex.Pattern)6 StringReader (java.io.StringReader)4 JsonObject (javax.json.JsonObject)4 QueryStringDecoder (org.jboss.netty.handler.codec.http.QueryStringDecoder)4 Matcher (java.util.regex.Matcher)3 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2