Search in sources :

Example 56 with Network

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

the class TotemProtocolDecoder method decode12.

private boolean decode12(Position position, Parser parser, Pattern pattern) {
    if (parser.hasNext()) {
        position.set(Position.KEY_ALARM, decodeAlarm123(Short.parseShort(parser.next(), 16)));
    }
    DateBuilder dateBuilder = new DateBuilder();
    int year = 0, month = 0, day = 0;
    if (pattern == PATTERN2) {
        day = parser.nextInt(0);
        month = parser.nextInt(0);
        year = parser.nextInt(0);
    }
    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));
    if (pattern == PATTERN1) {
        day = parser.nextInt(0);
        month = parser.nextInt(0);
        year = parser.nextInt(0);
    }
    if (year == 0) {
        // ignore invalid data
        return false;
    }
    dateBuilder.setDate(year, month, day);
    position.setTime(dateBuilder.getDate());
    if (pattern == PATTERN1) {
        position.set(Position.KEY_PDOP, parser.nextDouble());
        position.set(Position.KEY_HDOP, parser.nextDouble());
        position.set(Position.KEY_VDOP, parser.nextDouble());
    } else {
        position.set(Position.KEY_HDOP, parser.nextDouble());
    }
    position.set(Position.PREFIX_IO + 1, parser.next());
    if (pattern == PATTERN1) {
        position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.01);
    } else {
        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());
    int lac = parser.nextHexInt(0);
    int cid = parser.nextHexInt(0);
    if (lac != 0 && cid != 0) {
        position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
    }
    position.set(Position.PREFIX_TEMP + 1, parser.next());
    position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
    return true;
}
Also used : DateBuilder(org.traccar.helper.DateBuilder) Network(org.traccar.model.Network)

Example 57 with Network

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

the class TzoneProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    ChannelBuffer buf = (ChannelBuffer) msg;
    // header
    buf.skipBytes(2);
    // length
    buf.readUnsignedShort();
    if (buf.readUnsignedShort() != 0x2424) {
        return null;
    }
    int hardware = buf.readUnsignedShort();
    long firmware = buf.readUnsignedInt();
    String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
    if (deviceSession == null) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.set(Position.KEY_VERSION_HW, hardware);
    position.set(Position.KEY_VERSION_FW, firmware);
    position.setDeviceTime(new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
    // GPS info
    int blockLength = buf.readUnsignedShort();
    int blockEnd = buf.readerIndex() + blockLength;
    if (blockLength < 22) {
        return null;
    }
    position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
    double lat;
    double lon;
    if (hardware == 0x10A || hardware == 0x10B) {
        lat = buf.readUnsignedInt() / 600000.0;
        lon = buf.readUnsignedInt() / 600000.0;
    } else {
        lat = buf.readUnsignedInt() / 100000.0 / 60.0;
        lon = buf.readUnsignedInt() / 100000.0 / 60.0;
    }
    position.setFixTime(new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
    position.setSpeed(buf.readUnsignedShort() * 0.01);
    position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
    int flags = buf.readUnsignedShort();
    position.setCourse(BitUtil.to(flags, 9));
    if (!BitUtil.check(flags, 10)) {
        lat = -lat;
    }
    position.setLatitude(lat);
    if (BitUtil.check(flags, 9)) {
        lon = -lon;
    }
    position.setLongitude(lon);
    position.setValid(BitUtil.check(flags, 11));
    buf.readerIndex(blockEnd);
    // LBS info
    blockLength = buf.readUnsignedShort();
    blockEnd = buf.readerIndex() + blockLength;
    if (blockLength > 0 && (hardware == 0x10A || hardware == 0x10B)) {
        position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
    }
    buf.readerIndex(blockEnd);
    // Status info
    blockLength = buf.readUnsignedShort();
    blockEnd = buf.readerIndex() + blockLength;
    if (blockLength >= 13) {
        position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
        position.set("terminalInfo", buf.readUnsignedByte());
        int status = buf.readUnsignedByte();
        position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 0));
        position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 1));
        status = buf.readUnsignedByte();
        position.set(Position.PREFIX_IN + 1, BitUtil.check(status, 4));
        if (BitUtil.check(status, 0)) {
            position.set(Position.KEY_ALARM, Position.ALARM_SOS);
        }
        position.set(Position.KEY_RSSI, buf.readUnsignedByte());
        position.set("gsmStatus", buf.readUnsignedByte());
        position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
        position.set(Position.KEY_POWER, buf.readUnsignedShort());
        position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
        position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
    }
    if (blockLength >= 15) {
        position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
    }
    buf.readerIndex(blockEnd);
    if (hardware == 0x10A || hardware == 0x10B) {
        decodeCards(position, buf);
        // temperature
        buf.skipBytes(buf.readUnsignedShort());
        // lock
        buf.skipBytes(buf.readUnsignedShort());
        decodePassengers(position, buf);
    }
    return position;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DateBuilder(org.traccar.helper.DateBuilder) Network(org.traccar.model.Network) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 58 with Network

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

the class AtrackProtocolDecoder method readCustomData.

private void readCustomData(Position position, ChannelBuffer buf, String form) {
    CellTower cellTower = new CellTower();
    String[] keys = form.substring(1).split("%");
    for (String key : keys) {
        switch(key) {
            case "SA":
                position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
                break;
            case "MV":
                position.set(Position.KEY_POWER, buf.readUnsignedShort());
                break;
            case "BV":
                position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
                break;
            case "GQ":
                cellTower.setSignalStrength((int) buf.readUnsignedByte());
                break;
            case "CE":
                cellTower.setCellId(buf.readUnsignedInt());
                break;
            case "LC":
                cellTower.setLocationAreaCode(buf.readUnsignedShort());
                break;
            case "CN":
                // cccnn
                int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000);
                cellTower.setMobileCountryCode(combinedMobileCodes / 100);
                cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
                break;
            case "RL":
                // rxlev
                buf.readUnsignedByte();
                break;
            case "PC":
                position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
                break;
            case "AT":
                position.setAltitude(buf.readUnsignedInt());
                break;
            case "RP":
                position.set(Position.KEY_RPM, buf.readUnsignedShort());
                break;
            case "GS":
                position.set(Position.KEY_RSSI, buf.readUnsignedByte());
                break;
            case "DT":
                position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
                break;
            case "VN":
                position.set(Position.KEY_VIN, readString(buf));
                break;
            case "MF":
                // mass air flow rate
                buf.readUnsignedShort();
                break;
            case "EL":
                // engine load
                buf.readUnsignedByte();
                break;
            case "TR":
                position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
                break;
            case "ET":
                position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
                break;
            case "FL":
                position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
                break;
            case "ML":
                // mil status
                buf.readUnsignedByte();
                break;
            case "FC":
                position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
                break;
            case "CI":
                // format string
                readString(buf);
                break;
            case "AV1":
                position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
                break;
            case "NC":
                // gsm neighbor cell info
                readString(buf);
                break;
            case "SM":
                // max speed between reports
                buf.readUnsignedShort();
                break;
            case "GL":
                // google link
                readString(buf);
                break;
            case "MA":
                // mac address
                readString(buf);
                break;
            default:
                break;
        }
    }
    if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null && cellTower.getCellId() != null && cellTower.getLocationAreaCode() != null) {
        position.setNetwork(new Network(cellTower));
    } else if (cellTower.getSignalStrength() != null) {
        position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
    }
}
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