Search in sources :

Example 1 with DeviceSession

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

the class AisProtocolDecoder method decodePayload.

private Position decodePayload(Channel channel, SocketAddress remoteAddress, BitBuffer buf) {
    int type = buf.readUnsigned(6);
    if (type == 1 || type == 2 || type == 3 || type == 18) {
        buf.readUnsigned(2);
        int mmsi = buf.readUnsigned(30);
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(mmsi));
        if (deviceSession == null) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setTime(new Date());
        if (type == 18) {
            // reserved
            buf.readUnsigned(8);
        } else {
            position.set(Position.KEY_STATUS, buf.readUnsigned(4));
            position.set("turn", buf.readSigned(8));
        }
        position.setSpeed(buf.readUnsigned(10) * 0.1);
        position.setValid(buf.readUnsigned(1) != 0);
        position.setLongitude(buf.readSigned(28) * 0.0001 / 60.0);
        position.setLatitude(buf.readSigned(27) * 0.0001 / 60.0);
        position.setCourse(buf.readUnsigned(12) * 0.1);
        position.set("heading", buf.readUnsigned(9));
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Date(java.util.Date)

Example 2 with DeviceSession

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

the class AppelloProtocolDecoder 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 imei = parser.next();
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    if (parser.hasNext(6)) {
        position.setTime(parser.nextDateTime());
    } else {
        getLastLocation(position, null);
    }
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    position.setAltitude(parser.nextDouble(0));
    position.setValid(parser.next().equals("F"));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 3 with DeviceSession

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

the class AquilaProtocolDecoder 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.nextInt(0));
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setTime(parser.nextDateTime());
    position.setValid(parser.next().equals("A"));
    if (parser.hasNext(3)) {
        position.set(Position.KEY_RSSI, parser.nextInt(0));
        position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
    }
    if (parser.hasNext(9)) {
        position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
        position.set(Position.PREFIX_IN + 1, parser.next());
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.PREFIX_IN + 2, parser.next());
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        int course = (parser.nextInt(0) << 3) + (parser.nextInt(0) << 2) + (parser.nextInt(0) << 1) + parser.nextInt(0);
        if (course > 0 && course <= 8) {
            position.setCourse((course - 1) * 45);
        }
    } else if (parser.hasNext(7)) {
        position.setCourse(parser.nextInt(0));
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        position.set(Position.KEY_POWER, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt(0));
        String obd = parser.next();
        position.set("obd", obd.substring(1, obd.length() - 1));
        String dtcs = parser.next();
        position.set(Position.KEY_DTCS, dtcs.substring(1, dtcs.length() - 1).replace('|', ' '));
    } else if (parser.hasNext(10)) {
        position.setCourse(parser.nextInt(0));
        position.set(Position.KEY_SATELLITES, parser.nextInt(0));
        position.set(Position.KEY_HDOP, parser.nextDouble(0));
        position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
        position.set(Position.PREFIX_IN + 1, parser.nextInt(0));
        position.set(Position.KEY_CHARGE, parser.next().equals("1"));
        position.set(Position.PREFIX_IN + 2, parser.nextInt(0));
        position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
        position.set(Position.KEY_POWER, parser.nextInt(0));
        position.set(Position.KEY_BATTERY, parser.nextInt(0));
    } else if (parser.hasNext(2)) {
        position.set("sensorId", parser.nextInt());
        position.set("sensorData", parser.next());
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 4 with DeviceSession

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

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

Example 5 with DeviceSession

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

the class ArknavX8ProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    if (sentence.charAt(2) != ',') {
        getDeviceSession(channel, remoteAddress, sentence.substring(0, 15));
        return null;
    }
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        return null;
    }
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.set(Position.KEY_TYPE, parser.next());
    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));
    position.set(Position.KEY_HDOP, parser.nextDouble(0));
    position.set(Position.KEY_STATUS, parser.next());
    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