From f449d805a01e709b06c4b06e6dcb35d1651f73ad Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 25 Jul 2015 12:36:50 +1200 Subject: Parse extra TZone infomation --- src/org/traccar/model/Event.java | 1 + src/org/traccar/protocol/TzoneProtocolDecoder.java | 96 +++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index b42a776ae..caee7133b 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -51,6 +51,7 @@ public abstract class Event { } } + // Words separated by dashes (word-second-third) public static final String KEY_INDEX = "index"; public static final String KEY_HDOP = "hdop"; public static final String KEY_SATELLITES = "sat"; 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; @@ -88,6 +92,96 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(BitUtil.check(flags, 9) ? -lon : lon); 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; -- cgit v1.2.3