Search in sources :

Example 1 with DateBuilder

use of org.traccar.helper.DateBuilder 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 2 with DateBuilder

use of org.traccar.helper.DateBuilder 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)

Example 3 with DateBuilder

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

the class CarTrackProtocolDecoder 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_COMMAND, parser.next());
    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());
    position.set(Position.PREFIX_IO + 1, parser.next());
    String odometer = parser.next();
    odometer = odometer.replace(":", "A");
    odometer = odometer.replace(";", "B");
    odometer = odometer.replace("<", "C");
    odometer = odometer.replace("=", "D");
    odometer = odometer.replace(">", "E");
    odometer = odometer.replace("?", "F");
    position.set(Position.KEY_ODOMETER, Integer.parseInt(odometer, 16));
    // there is no meaningful alarms
    parser.next();
    position.set(Position.PREFIX_ADC + 1, parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Example 4 with DateBuilder

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

the class CastelProtocolDecoder method readPosition.

private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) {
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
    position.setTime(dateBuilder.getDate());
    double lat = buf.readUnsignedInt() / 3600000.0;
    double lon = buf.readUnsignedInt() / 3600000.0;
    position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
    position.setCourse(buf.readUnsignedShort() * 0.1);
    int flags = buf.readUnsignedByte();
    if ((flags & 0x02) == 0) {
        lat = -lat;
    }
    if ((flags & 0x01) == 0) {
        lon = -lon;
    }
    position.setLatitude(lat);
    position.setLongitude(lon);
    position.setValid((flags & 0x0C) > 0);
    position.set(Position.KEY_SATELLITES, flags >> 4);
    return position;
}
Also used : Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder)

Example 5 with DateBuilder

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

the class EasyTrackProtocolDecoder 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_COMMAND, parser.next());
    position.setValid(parser.next().equals("A"));
    DateBuilder dateBuilder = new DateBuilder().setDate(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0)).setTime(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0));
    position.setTime(dateBuilder.getDate());
    if (BitUtil.check(parser.nextHexInt(0), 3)) {
        position.setLatitude(-parser.nextHexInt(0) / 600000.0);
    } else {
        position.setLatitude(parser.nextHexInt(0) / 600000.0);
    }
    if (BitUtil.check(parser.nextHexInt(0), 3)) {
        position.setLongitude(-parser.nextHexInt(0) / 600000.0);
    } else {
        position.setLongitude(parser.nextHexInt(0) / 600000.0);
    }
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextHexInt(0) / 100.0));
    position.setCourse(parser.nextHexInt(0) / 100.0);
    position.set(Position.KEY_STATUS, parser.next());
    position.set("signal", parser.next());
    position.set(Position.KEY_POWER, parser.nextDouble(0));
    position.set("oil", parser.nextHexInt(0));
    position.set(Position.KEY_ODOMETER, parser.nextHexInt(0) * 100);
    position.setAltitude(parser.nextDouble(0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Aggregations

DateBuilder (org.traccar.helper.DateBuilder)75 Position (org.traccar.model.Position)70 DeviceSession (org.traccar.DeviceSession)63 Parser (org.traccar.helper.Parser)41 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)26 Network (org.traccar.model.Network)16 LinkedList (java.util.LinkedList)9 Date (java.util.Date)5 WifiAccessPoint (org.traccar.model.WifiAccessPoint)5 List (java.util.List)3 Pattern (java.util.regex.Pattern)3 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)2 QueryStringDecoder (org.jboss.netty.handler.codec.http.QueryStringDecoder)2 CellTower (org.traccar.model.CellTower)2 DateFormat (java.text.DateFormat)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 ChannelBufferIndexFinder (org.jboss.netty.buffer.ChannelBufferIndexFinder)1