Search in sources :

Example 61 with DateBuilder

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

the class H02ProtocolDecoder method decodeV3.

private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) {
    Parser parser = new Parser(PATTERN_V3, 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());
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    int mcc = parser.nextInt();
    int mnc = parser.nextInt();
    int count = parser.nextInt();
    Network network = new Network();
    String[] values = parser.next().split(",");
    for (int i = 0; i < count; i++) {
        network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1])));
    }
    position.setNetwork(network);
    position.set(Position.KEY_BATTERY, parser.nextHexInt());
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    getLastLocation(position, dateBuilder.getDate());
    processStatus(position, parser.nextLong(16, 0));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 62 with DateBuilder

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

the class H02ProtocolDecoder method decodeLink.

private Position decodeLink(String sentence, Channel channel, SocketAddress remoteAddress) {
    Parser parser = new Parser(PATTERN_LINK, 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());
    DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    position.set(Position.KEY_RSSI, parser.nextInt());
    position.set(Position.KEY_SATELLITES, parser.nextInt());
    position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
    position.set(Position.KEY_STEPS, parser.nextInt());
    position.set("turnovers", parser.nextInt());
    dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    getLastLocation(position, dateBuilder.getDate());
    processStatus(position, parser.nextLong(16, 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 63 with DateBuilder

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

the class H02ProtocolDecoder method decodeText.

private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
    Parser parser = new Parser(PATTERN, 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());
    if (parser.hasNext()) {
        position.set(Position.KEY_RESULT, parser.next());
    }
    DateBuilder dateBuilder = new DateBuilder();
    if (parser.hasNext(3)) {
        dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
    }
    if (parser.hasNext()) {
        position.setValid(parser.next().equals("A"));
    }
    if (parser.hasNext()) {
        // coding scheme
        parser.nextInt();
        position.setValid(true);
    }
    if (parser.hasNext(2)) {
        position.setLatitude(-parser.nextCoordinate());
    }
    if (parser.hasNext(2)) {
        position.setLatitude(parser.nextCoordinate());
    }
    if (parser.hasNext(2)) {
        position.setLongitude(-parser.nextCoordinate());
    }
    if (parser.hasNext(2)) {
        position.setLongitude(parser.nextCoordinate());
    }
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    if (parser.hasNext(3)) {
        dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
        position.setTime(dateBuilder.getDate());
    } else {
        position.setTime(new Date());
    }
    if (parser.hasNext()) {
        processStatus(position, parser.nextLong(16, 0));
    }
    if (parser.hasNext(6)) {
        position.set(Position.KEY_ODOMETER, parser.nextInt(0));
        position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
        position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble(0));
        position.setAltitude(parser.nextInt(0));
        position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
    }
    if (parser.hasNext(4)) {
        String[] values = parser.next().split(",");
        for (int i = 0; i < values.length; i++) {
            position.set(Position.PREFIX_IO + (i + 1), values[i].trim());
        }
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Network(org.traccar.model.Network) Date(java.util.Date) Parser(org.traccar.helper.Parser)

Example 64 with DateBuilder

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

the class Gt30ProtocolDecoder 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().trim());
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    if (parser.hasNext()) {
        position.set(Position.KEY_ALARM, decodeAlarm(parser.next().charAt(0)));
    }
    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.KEY_HDOP, parser.nextDouble());
    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)

Example 65 with DateBuilder

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

the class KhdProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    int type = buf.readUnsignedByte();
    // size
    buf.readUnsignedShort();
    if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) {
        Position position = new Position(getProtocolName());
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readSerialNumber(buf));
        if (deviceSession == null) {
            return null;
        }
        position.setDeviceId(deviceSession.getDeviceId());
        DateBuilder dateBuilder = new DateBuilder().setYear(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setDay(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
        position.setTime(dateBuilder.getDate());
        position.setLatitude(BcdUtil.readCoordinate(buf));
        position.setLongitude(BcdUtil.readCoordinate(buf));
        position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
        position.setCourse(BcdUtil.readInteger(buf, 4));
        position.setValid((buf.readUnsignedByte() & 0x80) != 0);
        if (type != MSG_ALARM) {
            position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
            position.set(Position.KEY_STATUS, buf.readUnsignedInt());
            position.set(Position.KEY_HDOP, buf.readUnsignedByte());
            position.set(Position.KEY_VDOP, buf.readUnsignedByte());
            position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
            // other location data
            buf.skipBytes(5);
            if (type == MSG_PERIPHERAL) {
                // data length
                buf.readUnsignedShort();
                int dataType = buf.readUnsignedByte();
                // content length
                buf.readUnsignedByte();
                switch(dataType) {
                    case 0x01:
                        position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
                        break;
                    case 0x02:
                        position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
                        break;
                    default:
                        break;
                }
            }
        }
        return position;
    } else if (type == MSG_LOGIN && channel != null) {
        // serial number
        buf.skipBytes(4);
        // reserved
        buf.readByte();
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        // header
        response.writeByte(0x29);
        // header
        response.writeByte(0x29);
        response.writeByte(MSG_CONFIRMATION);
        // size
        response.writeShort(5);
        response.writeByte(buf.readUnsignedByte());
        response.writeByte(type);
        // reserved
        response.writeByte(0);
        response.writeByte(Checksum.xor(response.toByteBuffer()));
        // ending
        response.writeByte(0x0D);
        channel.write(response);
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

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