From 0173d53e967a461560302772c35bcea0251426ed Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 1 May 2024 07:14:41 -0700 Subject: Handle Snapper no GPS data --- .../traccar/protocol/SnapperProtocolDecoder.java | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/main/java/org') 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; -- cgit v1.2.3