diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-01-06 22:17:38 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-01-06 22:17:38 +1300 |
commit | 32d0c2e760fdc9f9b7b0b2c4160987c463d27f99 (patch) | |
tree | 82b6adb0e436759267903a102e40b1d9faf32ef3 /src/org | |
parent | 0f2a1c47fd62aeeae8e4513280e2950fdf596cf6 (diff) | |
download | trackermap-server-32d0c2e760fdc9f9b7b0b2c4160987c463d27f99.tar.gz trackermap-server-32d0c2e760fdc9f9b7b0b2c4160987c463d27f99.tar.bz2 trackermap-server-32d0c2e760fdc9f9b7b0b2c4160987c463d27f99.zip |
Minor Tzone protocol improvements
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/TzoneProtocolDecoder.java | 105 |
1 files changed, 60 insertions, 45 deletions
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java index e457f6d33..2b5d90e7a 100644 --- a/src/org/traccar/protocol/TzoneProtocolDecoder.java +++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -55,6 +57,57 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeCards(Position position, ChannelBuffer buf) { + + int index = 1; + for (int i = 0; i < 4; i++) { + + int blockLength = buf.readUnsignedShort(); + int 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; + if (odd) { + length += 1; + } + + String num = ChannelBuffers.hexDump(buf.readBytes(length / 2)); + + if (odd) { + num = num.substring(1); + } + + position.set("card" + index, num); + } + } + + buf.readerIndex(blockEnd); + } + + } + + private void decodePassengers(Position position, ChannelBuffer buf) { + + int blockLength = buf.readUnsignedShort(); + int blockEnd = buf.readerIndex() + blockLength; + + if (blockLength > 0) { + + position.set("passengersOn", buf.readUnsignedMedium()); + position.set("passengersOff", buf.readUnsignedMedium()); + + } + + buf.readerIndex(blockEnd); + + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -132,6 +185,11 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { 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 @@ -159,55 +217,12 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder { if (hardware == 0x10A || hardware == 0x10B) { - // 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; - if (odd) { - length += 1; - } - - String num = ChannelBuffers.hexDump(buf.readBytes(length / 2)); - - if (odd) { - num = num.substring(1); - } - - position.set("card" + index, num); - } - } - - buf.readerIndex(blockEnd); - } + decodeCards(position, buf); buf.skipBytes(buf.readUnsignedShort()); // temperature buf.skipBytes(buf.readUnsignedShort()); // lock - // Passengers - - blockLength = buf.readUnsignedShort(); - blockEnd = buf.readerIndex() + blockLength; - - if (blockLength > 0) { - - position.set("passengersOn", buf.readUnsignedMedium()); - position.set("passengersOff", buf.readUnsignedMedium()); - - } - - buf.readerIndex(blockEnd); + decodePassengers(position, buf); } |