diff options
author | Anton Tananaev <anton@traccar.org> | 2022-10-12 17:47:35 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-10-12 17:47:35 -0700 |
commit | c801d33f44ae346d01e19e47a3b97c8405f4d5b4 (patch) | |
tree | e5e5855d64f8a5de23c0823ca0a2e341dd1a2175 /src | |
parent | dfaef4eca85a065e35c360fd6f712b2ad62f2e7a (diff) | |
download | trackermap-server-c801d33f44ae346d01e19e47a3b97c8405f4d5b4.tar.gz trackermap-server-c801d33f44ae346d01e19e47a3b97c8405f4d5b4.tar.bz2 trackermap-server-c801d33f44ae346d01e19e47a3b97c8405f4d5b4.zip |
Fix G1RUS decoding
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java | 8 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/G1rusProtocolDecoderTest.java | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java index e974e446d..17cfbc1eb 100644 --- a/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/G1rusProtocolDecoder.java @@ -124,8 +124,12 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; + buf.readUnsignedByte(); // header + buf.readUnsignedByte(); // version + int type = buf.readUnsignedByte(); String imei = String.valueOf(buf.readLong()); + buf.readerIndex(buf.readerIndex() - 1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; @@ -144,14 +148,14 @@ public class G1rusProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.to(subtype, 6) == MSG_REGULAR) { positions.add(decodeRegular(deviceSession, buf, subtype)); } else { - buf.skipBytes(length); + buf.skipBytes(length - 1); } } return positions.isEmpty() ? null : positions; } - buf.skipBytes(2); + buf.readUnsignedShort(); // checksum buf.readUnsignedByte(); // tail return null; diff --git a/src/test/java/org/traccar/protocol/G1rusProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/G1rusProtocolDecoderTest.java new file mode 100644 index 000000000..c8b4e35fe --- /dev/null +++ b/src/test/java/org/traccar/protocol/G1rusProtocolDecoderTest.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class G1rusProtocolDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + var decoder = inject(new G1rusProtocolDecoder(null)); + + verifyPositions(decoder, binary( + "f84604000d85f5e55298004b012ad7d524003d1d0f50726f6d61205361742031303030201556312e31302656312e312e340a03120fa0142b8475a157050401846dfc060175120a29a10d02440111002100310041005107d10ef8")); + + } + +} |