diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java | 31 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Xexun2ProtocolDecoderTest.java | 3 |
2 files changed, 15 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java index 402095391..28e7fbda3 100644 --- a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -180,25 +180,20 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(positionMask, 7)) { int dataLength = buf.readUnsignedShort(); if (dataLength > 0) { - if (buf.readByte() != 'G') { - buf.skipBytes(dataLength - 1); - } else { - int gpsDataLen = buf.readUnsignedShort(); - if (gpsDataLen != 27) { - buf.skipBytes(dataLength - 3); - } else { - position.setFixTime(position.getDeviceTime()); - position.setLongitude(convertCoordinate(buf.readDouble())); - position.setLatitude(convertCoordinate(buf.readDouble())); - position.setValid(buf.readUnsignedByte() > 0); - position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); - buf.readUnsignedByte(); // satellite signal to noise ratio - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); - position.setCourse(buf.readUnsignedShort() * 0.1); - position.setAltitude(buf.readFloat()); - buf.skipBytes(dataLength - 30); - } + int dataType = buf.readUnsignedByte(); + int dataEndIndex = buf.readerIndex() + buf.readUnsignedShort(); + if (dataType == 'G') { + position.setFixTime(position.getDeviceTime()); + position.setLongitude(convertCoordinate(buf.readDouble())); + position.setLatitude(convertCoordinate(buf.readDouble())); + position.setValid(buf.readUnsignedByte() > 0); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + buf.readUnsignedByte(); // satellite signal-to-noise ratio + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); + position.setCourse(buf.readUnsignedShort() * 0.1); + position.setAltitude(buf.readFloat()); } + buf.readerIndex(dataEndIndex); } } } diff --git a/src/test/java/org/traccar/protocol/Xexun2ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Xexun2ProtocolDecoderTest.java index 215b90c66..48ba1a691 100644 --- a/src/test/java/org/traccar/protocol/Xexun2ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Xexun2ProtocolDecoderTest.java @@ -26,7 +26,8 @@ public class Xexun2ProtocolDecoderTest extends ProtocolTest { "FAAF00140CF18626490454584530002BF2DD0200130013D360EFD7F514006402010D46322C4A450BA026D460EFD7FA14006402010D46322C4A450BA026FAAF")); verifyPositions(decoder, binary( - "FAAF0014000C8622050512345670002DF3A001002A0062D9047400005E0280001E47001B400D4BA732DF505E40B4153AAF78FEF00109000000000042B36666FAAF")); + "FAAF0014000C8622050512345670002DF3A001002A0062D9047400005E0280001E47001B400D4BA732DF505E40B4153AAF78FEF00109000000000042B36666FAAF"), + position("2022-07-21 07:47:00.000", true, 51.68715, 0.06103)); } |