Search in sources :

Example 16 with Position

use of org.traccar.model.Position 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 17 with Position

use of org.traccar.model.Position 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)

Example 18 with Position

use of org.traccar.model.Position in project traccar by tananaev.

the class ArnaviProtocolDecoder 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.set(Position.KEY_INDEX, parser.nextInt(0));
    position.set(Position.KEY_POWER, parser.nextInt(0) * 0.01);
    position.set(Position.KEY_BATTERY, parser.nextInt(0) * 0.01);
    position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
    position.set(Position.KEY_INPUT, parser.nextInt(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setValid(true);
    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 19 with Position

use of org.traccar.model.Position in project traccar by tananaev.

the class AtrackProtocolDecoder method decodeString.

private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
    Position position = new Position(getProtocolName());
    getLastLocation(position, null);
    DeviceSession deviceSession;
    if (sentence.startsWith("$INFO")) {
        Parser parser = new Parser(PATTERN_INFO, sentence);
        if (!parser.matches()) {
            return null;
        }
        deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
        position.set("model", parser.next());
        position.set(Position.KEY_VERSION_FW, parser.next());
        position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
        position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1);
        position.set(Position.KEY_SATELLITES, parser.nextInt());
        position.set(Position.KEY_RSSI, parser.nextInt());
    } else {
        deviceSession = getDeviceSession(channel, remoteAddress);
        position.set(Position.KEY_RESULT, sentence);
    }
    if (deviceSession == null) {
        return null;
    } else {
        position.setDeviceId(deviceSession.getDeviceId());
        return position;
    }
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Parser(org.traccar.helper.Parser)

Example 20 with Position

use of org.traccar.model.Position in project traccar by tananaev.

the class AutoFonProtocolDecoder method decodePosition.

private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) {
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    if (!history) {
        // interval
        buf.readUnsignedByte();
        // settings
        buf.skipBytes(8);
    }
    position.set(Position.KEY_STATUS, buf.readUnsignedByte());
    if (!history) {
        buf.readUnsignedShort();
    }
    position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
    // time
    buf.skipBytes(6);
    if (!history) {
        for (int i = 0; i < 2; i++) {
            // time
            buf.skipBytes(5);
            // interval
            buf.readUnsignedShort();
            // mode
            buf.skipBytes(5);
        }
    }
    position.set(Position.PREFIX_TEMP + 1, buf.readByte());
    int rssi = buf.readUnsignedByte();
    CellTower cellTower = CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), rssi);
    position.setNetwork(new Network(cellTower));
    int valid = buf.readUnsignedByte();
    position.setValid((valid & 0xc0) != 0);
    position.set(Position.KEY_SATELLITES, valid & 0x3f);
    DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
    position.setTime(dateBuilder.getDate());
    position.setLatitude(convertCoordinate(buf.readInt()));
    position.setLongitude(convertCoordinate(buf.readInt()));
    position.setAltitude(buf.readShort());
    position.setSpeed(buf.readUnsignedByte());
    position.setCourse(buf.readUnsignedByte() * 2.0);
    position.set(Position.KEY_HDOP, buf.readUnsignedShort());
    // reserved
    buf.readUnsignedShort();
    // checksum
    buf.readUnsignedByte();
    return position;
}
Also used : Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Aggregations

Position (org.traccar.model.Position)301 DeviceSession (org.traccar.DeviceSession)188 Parser (org.traccar.helper.Parser)129 DateBuilder (org.traccar.helper.DateBuilder)70 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)62 Network (org.traccar.model.Network)49 Date (java.util.Date)47 LinkedList (java.util.LinkedList)37 Event (org.traccar.model.Event)25 Test (org.junit.Test)22 BaseTest (org.traccar.BaseTest)16 WifiAccessPoint (org.traccar.model.WifiAccessPoint)16 SimpleDateFormat (java.text.SimpleDateFormat)13 List (java.util.List)11 TripsConfig (org.traccar.reports.model.TripsConfig)11 DateFormat (java.text.DateFormat)10 Device (org.traccar.model.Device)10 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)9 DeviceState (org.traccar.model.DeviceState)9 StopReport (org.traccar.reports.model.StopReport)9