aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-05-01 07:14:41 -0700
committerAnton Tananaev <anton@traccar.org>2024-05-01 07:14:41 -0700
commit0173d53e967a461560302772c35bcea0251426ed (patch)
treefa7ef8b4d969ecd21ea1919df9ea64a8f94af91e /src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
parentce08bd530579765c38a84eba1f57863fb5907f89 (diff)
downloadtrackermap-server-0173d53e967a461560302772c35bcea0251426ed.tar.gz
trackermap-server-0173d53e967a461560302772c35bcea0251426ed.tar.bz2
trackermap-server-0173d53e967a461560302772c35bcea0251426ed.zip
Handle Snapper no GPS data
Diffstat (limited to 'src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java25
1 files changed, 16 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;