Search in sources :

Example 51 with DateBuilder

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

the class CarscopProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    String sentence = (String) msg;
    DeviceSession deviceSession;
    int index = sentence.indexOf("UB05");
    if (index != -1) {
        String imei = sentence.substring(index + 4, index + 4 + 15);
        deviceSession = getDeviceSession(channel, remoteAddress, imei);
    } else {
        deviceSession = getDeviceSession(channel, remoteAddress);
    }
    if (deviceSession == null) {
        return null;
    }
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        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));
    position.setValid(parser.next().equals("A"));
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.setTime(dateBuilder.getDate());
    position.setCourse(parser.nextDouble(0));
    if (parser.hasNext(2)) {
        position.set(Position.KEY_STATUS, parser.next());
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Parser(org.traccar.helper.Parser)

Example 52 with DateBuilder

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

the class CellocatorProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // system code
    buf.skipBytes(4);
    int type = buf.readUnsignedByte();
    long deviceUniqueId = buf.readUnsignedInt();
    if (type != MSG_CLIENT_SERIAL) {
        // communication control
        buf.readUnsignedShort();
    }
    byte packetNumber = buf.readByte();
    sendReply(channel, remoteAddress, deviceUniqueId, packetNumber);
    if (type == MSG_CLIENT_STATUS) {
        Position position = new Position(getProtocolName());
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceUniqueId));
        if (deviceSession == null) {
            return null;
        }
        position.setDeviceId(deviceSession.getDeviceId());
        position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte());
        position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
        position.set("protocolVersion", buf.readUnsignedByte());
        position.set(Position.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f);
        int operator = (buf.readUnsignedByte() & 0xf0) << 4;
        operator += buf.readUnsignedByte();
        // reason data
        buf.readUnsignedByte();
        position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
        position.set("mode", buf.readUnsignedByte());
        position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt());
        operator <<= 8;
        operator += buf.readUnsignedByte();
        position.set(Position.KEY_OPERATOR, operator);
        position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt());
        position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
        // multi-purpose data
        buf.skipBytes(6);
        position.set(Position.KEY_GPS, buf.readUnsignedShort());
        position.set("locationStatus", buf.readUnsignedByte());
        position.set("mode1", buf.readUnsignedByte());
        position.set("mode2", buf.readUnsignedByte());
        position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
        position.setValid(true);
        position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
        position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
        position.setAltitude(buf.readInt() * 0.01);
        position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
        position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
        DateBuilder dateBuilder = new DateBuilder().setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort());
        position.setTime(dateBuilder.getDate());
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 53 with DateBuilder

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

the class CradlepointProtocolDecoder 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());
    int time = parser.nextInt();
    DateBuilder dateBuilder = new DateBuilder(new Date());
    dateBuilder.setHour(time / 100 / 100);
    dateBuilder.setMinute(time / 100 % 100);
    dateBuilder.setSecond(time % 100);
    position.setTime(dateBuilder.getDate());
    position.setValid(true);
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    position.set("carrid", parser.next());
    position.set("serdis", parser.next());
    position.set("rsrp", parser.next());
    position.set("dbm", parser.next());
    position.set("rsrq", parser.next());
    position.set("ecio", parser.next());
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Date(java.util.Date) Parser(org.traccar.helper.Parser)

Example 54 with DateBuilder

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

the class DmtProtocolDecoder method decodeFixed64.

private List<Position> decodeFixed64(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
    if (deviceSession == null) {
        return null;
    }
    List<Position> positions = new LinkedList<>();
    while (buf.readableBytes() >= 64) {
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        // type
        buf.readByte();
        position.set(Position.KEY_INDEX, buf.readUnsignedInt());
        long time = buf.readUnsignedInt();
        position.setTime(new DateBuilder().setYear((int) (2000 + (time & 0x3F))).setMonth((int) (time >> 6) & 0xF).setDay((int) (time >> 10) & 0x1F).setHour((int) (time >> 15) & 0x1F).setMinute((int) (time >> 20) & 0x3F).setSecond((int) (time >> 26) & 0x3F).getDate());
        position.setLongitude(buf.readInt() * 0.0000001);
        position.setLatitude(buf.readInt() * 0.0000001);
        position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
        position.setCourse(buf.readUnsignedByte() * 2);
        position.setAltitude(buf.readShort());
        // position accuracy
        buf.readUnsignedShort();
        // speed accuracy
        buf.readUnsignedByte();
        position.set(Position.KEY_EVENT, buf.readUnsignedByte());
        position.setValid(BitUtil.check(buf.readByte(), 0));
        position.set(Position.KEY_INPUT, buf.readUnsignedInt());
        position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
        for (int i = 1; i <= 5; i++) {
            position.set(Position.PREFIX_ADC + i, buf.readShort());
        }
        position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
        // accelerometer x
        buf.readShort();
        // accelerometer y
        buf.readShort();
        // accelerometer z
        buf.readShort();
        // device id
        buf.skipBytes(8);
        position.set(Position.KEY_PDOP, buf.readUnsignedShort() * 0.01);
        // reserved
        buf.skipBytes(2);
        // checksum
        buf.readUnsignedShort();
        positions.add(position);
    }
    return positions;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) LinkedList(java.util.LinkedList)

Example 55 with DateBuilder

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

the class EnforaProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // Find IMEI number
    int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {

        @Override
        public boolean find(ChannelBuffer buffer, int guessedIndex) {
            if (buffer.writerIndex() - guessedIndex >= IMEI_LENGTH) {
                for (int i = 0; i < IMEI_LENGTH; i++) {
                    if (!Character.isDigit((char) buffer.getByte(guessedIndex + i))) {
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
    });
    if (index == -1) {
        return null;
    }
    String imei = buf.toString(index, IMEI_LENGTH, StandardCharsets.US_ASCII);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    // Find NMEA sentence
    int start = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
    if (start == -1) {
        return null;
    }
    String sentence = buf.toString(start, buf.readableBytes() - start, StandardCharsets.US_ASCII);
    Parser parser = new Parser(PATTERN, sentence);
    if (!parser.matches()) {
        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));
    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 : ChannelBufferIndexFinder(org.jboss.netty.buffer.ChannelBufferIndexFinder) DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) StringFinder(org.traccar.helper.StringFinder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) 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