Search in sources :

Example 11 with Network

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

the class TeltonikaProtocolDecoder method decodeLocation.

private void decodeLocation(Position position, ChannelBuffer buf, int codec) {
    int globalMask = 0x0f;
    if (codec == CODEC_GH3000) {
        long time = buf.readUnsignedInt() & 0x3fffffff;
        // 2007-01-01 00:00:00
        time += 1167609600;
        globalMask = buf.readUnsignedByte();
        if (BitUtil.check(globalMask, 0)) {
            position.setTime(new Date(time * 1000));
            int locationMask = buf.readUnsignedByte();
            if (BitUtil.check(locationMask, 0)) {
                position.setLatitude(buf.readFloat());
                position.setLongitude(buf.readFloat());
            }
            if (BitUtil.check(locationMask, 1)) {
                position.setAltitude(buf.readUnsignedShort());
            }
            if (BitUtil.check(locationMask, 2)) {
                position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
            }
            if (BitUtil.check(locationMask, 3)) {
                position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
            }
            if (BitUtil.check(locationMask, 4)) {
                int satellites = buf.readUnsignedByte();
                position.set(Position.KEY_SATELLITES, satellites);
                position.setValid(satellites >= 3);
            }
            if (BitUtil.check(locationMask, 5)) {
                CellTower cellTower = CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort());
                if (BitUtil.check(locationMask, 6)) {
                    cellTower.setSignalStrength((int) buf.readUnsignedByte());
                }
                if (BitUtil.check(locationMask, 7)) {
                    cellTower.setOperator(buf.readUnsignedInt());
                }
                position.setNetwork(new Network(cellTower));
            } else {
                if (BitUtil.check(locationMask, 6)) {
                    position.set(Position.KEY_RSSI, buf.readUnsignedByte());
                }
                if (BitUtil.check(locationMask, 7)) {
                    position.set(Position.KEY_OPERATOR, buf.readUnsignedInt());
                }
            }
        } else {
            getLastLocation(position, new Date(time * 1000));
        }
    } else {
        position.setTime(new Date(buf.readLong()));
        position.set("priority", buf.readUnsignedByte());
        position.setLongitude(buf.readInt() / 10000000.0);
        position.setLatitude(buf.readInt() / 10000000.0);
        position.setAltitude(buf.readShort());
        position.setCourse(buf.readUnsignedShort());
        int satellites = buf.readUnsignedByte();
        position.set(Position.KEY_SATELLITES, satellites);
        position.setValid(satellites != 0);
        position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
        position.set(Position.KEY_EVENT, buf.readUnsignedByte());
        // total IO data records
        buf.readUnsignedByte();
    }
    // Read 1 byte data
    if (BitUtil.check(globalMask, 1)) {
        int cnt = buf.readUnsignedByte();
        for (int j = 0; j < cnt; j++) {
            decodeParameter(position, buf.readUnsignedByte(), buf, 1, codec);
        }
    }
    // Read 2 byte data
    if (BitUtil.check(globalMask, 2)) {
        int cnt = buf.readUnsignedByte();
        for (int j = 0; j < cnt; j++) {
            decodeParameter(position, buf.readUnsignedByte(), buf, 2, codec);
        }
    }
    // Read 4 byte data
    if (BitUtil.check(globalMask, 3)) {
        int cnt = buf.readUnsignedByte();
        for (int j = 0; j < cnt; j++) {
            decodeParameter(position, buf.readUnsignedByte(), buf, 4, codec);
        }
    }
    // Read 8 byte data
    if (codec == CODEC_FM4X00 || codec == CODEC_16) {
        int cnt = buf.readUnsignedByte();
        for (int j = 0; j < cnt; j++) {
            decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8);
        }
    }
    // Read 16 byte data
    if (extended) {
        int cnt = buf.readUnsignedByte();
        for (int j = 0; j < cnt; j++) {
            position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ChannelBuffers.hexDump(buf.readBytes(16)));
        }
    }
    decodeNetwork(position);
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network) Date(java.util.Date)

Example 12 with Network

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

the class TeltonikaProtocolDecoder method decodeNetwork.

private void decodeNetwork(Position position) {
    long cid = position.getLong(Position.PREFIX_IO + 205);
    int lac = position.getInteger(Position.PREFIX_IO + 206);
    if (cid != 0 && lac != 0) {
        CellTower cellTower = CellTower.fromLacCid(lac, cid);
        long operator = position.getInteger(Position.KEY_OPERATOR);
        if (operator != 0) {
            cellTower.setOperator(operator);
        }
        position.setNetwork(new Network(cellTower));
    }
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Example 13 with Network

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

the class Tk103ProtocolDecoder method decodeNetwork.

private Position decodeNetwork(Channel channel, SocketAddress remoteAddress, String sentence) {
    Parser parser = new Parser(PATTERN_NETWORK, 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());
    getLastLocation(position, null);
    position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Parser(org.traccar.helper.Parser)

Example 14 with Network

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

the class ThinkRaceProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    ChannelBuffer id = buf.readBytes(12);
    // separator
    buf.readUnsignedByte();
    int type = buf.readUnsignedByte();
    // length
    buf.readUnsignedShort();
    if (type == MSG_LOGIN) {
        // 0x00 - heartbeat
        int command = buf.readUnsignedByte();
        if (command == 0x01) {
            String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
            DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
            if (deviceSession != null && channel != null) {
                ChannelBuffer response = ChannelBuffers.dynamicBuffer();
                // header
                response.writeByte(0x48);
                // header
                response.writeByte(0x52);
                response.writeBytes(id);
                // separator
                response.writeByte(0x2c);
                response.writeByte(type);
                // length
                response.writeShort(0x0002);
                response.writeShort(0x8000);
                // checksum
                response.writeShort(0x0000);
                channel.write(response);
            }
        }
    } else if (type == MSG_GPS) {
        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
        if (deviceSession == null) {
            return null;
        }
        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());
        position.setTime(new Date(buf.readUnsignedInt() * 1000));
        int flags = buf.readUnsignedByte();
        position.setValid(true);
        position.setLatitude(convertCoordinate(buf.readUnsignedInt(), !BitUtil.check(flags, 0)));
        position.setLongitude(convertCoordinate(buf.readUnsignedInt(), !BitUtil.check(flags, 1)));
        position.setSpeed(buf.readUnsignedByte());
        position.setCourse(buf.readUnsignedByte());
        position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
        return position;
    }
    return null;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) Network(org.traccar.model.Network) Date(java.util.Date) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 15 with Network

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

the class TotemProtocolDecoder method decode4.

private boolean decode4(Position position, Parser parser) {
    long status = parser.nextHexLong();
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 1) ? Position.ALARM_SOS : null);
    position.set(Position.KEY_IGNITION, BitUtil.check(status, 32 - 2));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 3) ? Position.ALARM_OVERSPEED : null);
    position.set(Position.KEY_CHARGE, BitUtil.check(status, 32 - 4));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 5) ? Position.ALARM_GEOFENCE_EXIT : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 6) ? Position.ALARM_GEOFENCE_ENTER : null);
    position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 32 - 9));
    position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 32 - 10));
    position.set(Position.PREFIX_OUT + 3, BitUtil.check(status, 32 - 11));
    position.set(Position.PREFIX_OUT + 4, BitUtil.check(status, 32 - 12));
    position.set(Position.PREFIX_IN + 2, BitUtil.check(status, 32 - 13));
    position.set(Position.PREFIX_IN + 3, BitUtil.check(status, 32 - 14));
    position.set(Position.PREFIX_IN + 4, BitUtil.check(status, 32 - 15));
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 16) ? Position.ALARM_SHOCK : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 18) ? Position.ALARM_LOW_BATTERY : null);
    position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 22) ? Position.ALARM_JAMMING : null);
    position.setValid(BitUtil.check(status, 32 - 20));
    position.setTime(parser.nextDateTime());
    position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
    position.set(Position.KEY_POWER, parser.nextDouble(0));
    position.set(Position.PREFIX_ADC + 1, parser.next());
    position.set(Position.PREFIX_ADC + 2, parser.next());
    position.set(Position.PREFIX_ADC + 3, parser.next());
    position.set(Position.PREFIX_ADC + 4, parser.next());
    position.set(Position.PREFIX_TEMP + 1, parser.next());
    position.set(Position.PREFIX_TEMP + 2, parser.next());
    CellTower cellTower = CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0));
    position.set(Position.KEY_SATELLITES, parser.nextInt(0));
    cellTower.setSignalStrength(parser.nextInt(0));
    position.setNetwork(new Network(cellTower));
    position.setCourse(parser.nextDouble(0));
    position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
    position.set(Position.KEY_HDOP, parser.nextDouble(0));
    position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
    position.setLatitude(parser.nextCoordinate());
    position.setLongitude(parser.nextCoordinate());
    return true;
}
Also used : CellTower(org.traccar.model.CellTower) Network(org.traccar.model.Network)

Aggregations

Network (org.traccar.model.Network)58 Position (org.traccar.model.Position)49 DeviceSession (org.traccar.DeviceSession)37 Parser (org.traccar.helper.Parser)25 DateBuilder (org.traccar.helper.DateBuilder)16 Date (java.util.Date)12 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)12 WifiAccessPoint (org.traccar.model.WifiAccessPoint)10 CellTower (org.traccar.model.CellTower)7 LinkedList (java.util.LinkedList)6 SimpleDateFormat (java.text.SimpleDateFormat)3 DateFormat (java.text.DateFormat)2 List (java.util.List)2 BitBuffer (org.traccar.helper.BitBuffer)2 ParseException (java.text.ParseException)1 Calendar (java.util.Calendar)1 Map (java.util.Map)1 TimeZone (java.util.TimeZone)1 Matcher (java.util.regex.Matcher)1 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)1