aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-07-23 07:57:02 -0700
committerAnton Tananaev <anton@traccar.org>2022-07-23 07:57:02 -0700
commit14dafcb4191ec25fa22494956cd509708a9e1b5c (patch)
tree16dfaa29a8a837d052bdac91327d9473e41e8bfe /src/main/java
parente3006068282d1290110df5861e45bc262bfea358 (diff)
downloadtrackermap-server-14dafcb4191ec25fa22494956cd509708a9e1b5c.tar.gz
trackermap-server-14dafcb4191ec25fa22494956cd509708a9e1b5c.tar.bz2
trackermap-server-14dafcb4191ec25fa22494956cd509708a9e1b5c.zip
Improve Xexun2 decoder
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java31
1 files changed, 13 insertions, 18 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);
}
}
}