diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java | 25 |
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; |