diff options
-rw-r--r-- | src/org/traccar/protocol/UlbotechProtocolDecoder.java | 21 | ||||
-rw-r--r-- | test/org/traccar/protocol/UlbotechProtocolDecoderTest.java | 3 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 9cbaadfb4..2fd7d8f74 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -65,6 +65,25 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { } } + private void decodeJ1708(Position position, ChannelBuffer buf, short length) { + + int end = buf.readerIndex() + length; + + while (buf.readerIndex() < end) { + int mark = buf.readUnsignedByte(); + int len = BitUtil.between(mark, 0, 6); + int type = BitUtil.between(mark, 6, 8); + int id = buf.readUnsignedByte(); + if (type == 3) { + id += 256; + } + String value = ChannelBuffers.hexDump(buf.readBytes(len - 1)); + if (type == 2 || type == 3) { + position.set("pid" + id, value); + } + } + } + private void decodeDriverBehavior(Position position, ChannelBuffer buf) { int value = buf.readUnsignedByte(); @@ -200,7 +219,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_J1708: - position.set("j1708", ChannelBuffers.hexDump(buf.readBytes(length))); + decodeJ1708(position, buf, length); break; case DATA_VIN: diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index 5036c4a40..cb4e43c38 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class UlbotechProtocolDecoderTest extends ProtocolTest { UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); + verifyPosition(decoder, binary( + "F8010103596580420045259CFB3329010E015ED91506BDE5A800000000009E030402420000040400492AA405060344197E220D071131058F410C1591310D48312F8F413107C60804027666B00C138254D182607A826EE083BE554385F50019423CAD1DF8")); + verifyNotNull(decoder, binary( "F8010108683230231070781EA3676E020BFFFFFFFFFFFFFFFFFFFF780304000000030404000002C20506032A1790220E100101AC72F8")); |