aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java8
-rw-r--r--src/test/java/org/traccar/protocol/TranSyncProtocolDecoderTest.java6
2 files changed, 7 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
index 759c012b8..acb46ec48 100644
--- a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
@@ -131,7 +131,9 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
ByteBuf buf = (ByteBuf) msg;
+
if (Arrays.equals(ByteBufUtil.getBytes(buf, 0, 2), STX)) {
buf.readUnsignedShort();
}
@@ -183,14 +185,14 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
position.setNetwork(new Network(cellTower));
- if (buf.readableBytes() > 2) {
+ if (buf.readableBytes() > 5) {
buf.readUnsignedByte(); // odometerIndex
int odometerLength = buf.readUnsignedByte();
if (odometerLength > 0) {
int odometer = buf.readBytes(odometerLength).readInt();
position.set(Position.KEY_ODOMETER, odometer);
}
- if ((buf.readableBytes() > 2)) {
+ if ((buf.readableBytes() > 5)) {
buf.readUnsignedByte(); // tagIndex
int tagLength = buf.readUnsignedByte();
if (tagLength > 0) {
@@ -205,7 +207,7 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
}
}
if ((buf.readableBytes() > 5)) {
- buf.readUnsignedByte(); // adc2Index
+ buf.readUnsignedByte(); // adc3Index
int adc2Length = buf.readUnsignedByte();
if (adc2Length > 0 && adc2Length <= buf.readableBytes() - 2) {
position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort());
diff --git a/src/test/java/org/traccar/protocol/TranSyncProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TranSyncProtocolDecoderTest.java
index 6cf2d0c1f..c84ae2e0f 100644
--- a/src/test/java/org/traccar/protocol/TranSyncProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/TranSyncProtocolDecoderTest.java
@@ -10,10 +10,8 @@ public class TranSyncProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new TranSyncProtocolDecoder(null));
- verifyPosition(decoder, binary(
- "3a3a2b583f086065705154043900801017050b11190f01623ef40887dff00000c25e9ff707000007152a2d0000000105004794916902050000100000050252ee060200822323"));
+ verifyPosition(decoder, binary("3a3a2b583f086065705154043900801017050b11190f01623ef40887dff00000c25e9ff707000007152a2d0000000105004794916902050000100000050252ee060200822323"));
- verifyAttributes(decoder, binary(
- "3a3a2b583f086065705154043900801017050b11190f01623ef40887dff00000c25e9ff707000007152a2d0000000105004794916902050000000000050252ee060200822323"));
+ verifyAttributes(decoder, binary("3a3a2b583f086065705154043900801017050b11190f01623ef40887dff00000c25e9ff707000007152a2d0000000105004794916902050000000000050252ee060200822323"));
}
}