diff options
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/TzoneProtocolDecoder.java | 96 |
1 files changed, 95 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index f67c9684f..ed463c109 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -41,7 +41,9 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(2); // header buf.readUnsignedShort(); // length - buf.readUnsignedShort(); // type + if (buf.readUnsignedShort() != 0x2424) { + return null; + } buf.readUnsignedShort(); // model buf.readUnsignedInt(); // firmware @@ -55,6 +57,8 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); + + // GPS info int blockLength = buf.readUnsignedShort(); int blockEnd = buf.readerIndex() + blockLength; @@ -89,6 +93,96 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { position.setValid(BitUtil.check(flags, 11)); buf.readerIndex(blockEnd); + + // LBS info + + blockLength = buf.readUnsignedShort(); + blockEnd = buf.readerIndex() + blockLength; + + if (blockLength > 0) { + + position.set(Event.KEY_LAC, buf.readUnsignedShort()); + position.set(Event.KEY_CELL, buf.readUnsignedShort()); + + } + + buf.readerIndex(blockEnd); + + // Status info + + blockLength = buf.readUnsignedShort(); + blockEnd = buf.readerIndex() + blockLength; + + if (blockLength > 0) { + + position.set(Event.KEY_ALARM, buf.readUnsignedByte()); + buf.readUnsignedByte(); // terminal info + position.set(Event.PREFIX_IO + 1, buf.readUnsignedShort()); + position.set(Event.KEY_GSM, buf.readUnsignedByte()); + buf.readUnsignedByte(); // GSM status + position.set(Event.KEY_BATTERY, buf.readUnsignedShort()); + position.set(Event.KEY_POWER, buf.readUnsignedShort()); + position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort()); + position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort()); + position.set(Event.PREFIX_TEMP + 1, buf.readUnsignedShort()); + + } + + buf.readerIndex(blockEnd); + + // Cards + + int index = 1; + for (int i = 0; i < 4; i++) { + + blockLength = buf.readUnsignedShort(); + blockEnd = buf.readerIndex() + blockLength; + + if (blockLength > 0) { + + int count = buf.readUnsignedByte(); + for (int j = 0; j < count; j++) { + + int length = buf.readUnsignedByte(); + + boolean odd = length % 2 != 0; + + String num = ChannelBufferTools.readHexString(buf, odd ? length + 1 : length); + + if (odd) { + num = num.substring(1); + } + + position.set("card" + index, num); + + } + } + + buf.readerIndex(blockEnd); + + } + + // Temperature + + buf.skipBytes(buf.readUnsignedShort()); + + // Lock + + buf.skipBytes(buf.readUnsignedShort()); + + // Passengers + + blockLength = buf.readUnsignedShort(); + blockEnd = buf.readerIndex() + blockLength; + + if (blockLength > 0) { + + position.set("passengers-on", buf.readUnsignedMedium()); + position.set("passengers-off", buf.readUnsignedMedium()); + + } + + buf.readerIndex(blockEnd); return position; } |