aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java25
-rw-r--r--src/test/java/org/traccar/protocol/SnapperProtocolDecoderTest.java3
2 files changed, 19 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java b/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
index e60ddc431..e60736667 100644
--- a/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
@@ -115,16 +115,11 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
String content = buf.readCharSequence(buf.readableBytes(), StandardCharsets.US_ASCII).toString();
JsonObject json = Json.createReader(new StringReader(content)).readObject();
- DateFormat dateFormat = new SimpleDateFormat("ddMMyyHHmmss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- position.setTime(dateFormat.parse(json.getString("d") + json.getString("t").split("\\.")[0]));
-
- String lat = json.getString("la");
- position.setLatitude(Integer.parseInt(lat.substring(0, 2)) + Double.parseDouble(lat.substring(2)) / 60);
- String lon = json.getString("lo");
- position.setLongitude(Integer.parseInt(lon.substring(0, 3)) + Double.parseDouble(lon.substring(3)) / 60);
-
int flags = Integer.parseInt(json.getString("f"), 16);
+ if (!BitUtil.check(flags, 3)) {
+ return;
+ }
+
position.setValid(BitUtil.check(flags, 1));
if (!BitUtil.check(flags, 6)) {
position.setLatitude(-position.getLatitude());
@@ -133,6 +128,15 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(-position.getLongitude());
}
+ DateFormat dateFormat = new SimpleDateFormat("ddMMyyHHmmss");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ position.setTime(dateFormat.parse(json.getString("d") + json.getString("t").split("\\.")[0]));
+
+ String lat = json.getString("la");
+ position.setLatitude(Integer.parseInt(lat.substring(0, 2)) + Double.parseDouble(lat.substring(2)) / 60);
+ String lon = json.getString("lo");
+ position.setLongitude(Integer.parseInt(lon.substring(0, 3)) + Double.parseDouble(lon.substring(3)) / 60);
+
position.setAltitude(Double.parseDouble(json.getString("a")));
position.setSpeed(Double.parseDouble(json.getString("s")));
position.setCourse(Double.parseDouble(json.getString("c")));
@@ -205,6 +209,9 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
break;
}
}
+ if (position.getFixTime() == null) {
+ getLastLocation(position, null);
+ }
return position;
default:
return null;
diff --git a/src/test/java/org/traccar/protocol/SnapperProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SnapperProtocolDecoderTest.java
index 7f16d6f3b..bb79194eb 100644
--- a/src/test/java/org/traccar/protocol/SnapperProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SnapperProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class SnapperProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"4b0341a6b0c608000040000005000000000000007d5e14010068656c6c6f"));
+ verifyAttributes(decoder, binary(
+ "4b044daff87aff5b8aad0000d4000000000000000b001337000500210008000d0000ffffffff7f2300190000000000000001000000000224ff000003404000000400000034008c007b2273223a22303034313438222c226332223a2230303030303030303030303030303030222c226132223a2230303030303030303030303830304530222c226f223a2230303030222c2274223a2230303030222c227a223a223030222c2277223a223030222c2272223a222d222c226d223a223030303030303030222c2262223a223030303030303030227d32000a007b2266223a223234227d330007007b2262223a5d7d"));
+
verifyPosition(decoder, binary(
"4b044daff87aff5b8aad00007b010000000013ea0c006837000500210008003e000058c48fa94823001900000080000200018080000002deff0f0003404000000400000034008c007b2273223a22303034303438222c226332223a2230303030303030303030303030303030222c226132223a2230303030303030303030303030303030222c226f223a2230303030222c2274223a2230303030222c227a223a223030222c2277223a223030222c2272223a222d222c226d223a223030303030303030222c2262223a223030303030303030227d320079007b2266223a224445222c2274223a22303932383336222c2264223a22313530343234222c226c61223a22353334312e34333732222c226c6f223a2230303935342e30373036222c2261223a22382e34222c2273223a22302e3030222c2263223a2232362e3036222c227376223a223135222c2270223a22227d33003f007b2263223a22323632222c226e223a223033222c2262223a5b7b226c223a2232423334222c2263223a223030303041313231222c2273223a223132227d5d7d"));