aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-05-18 23:06:00 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-05-18 23:06:00 -0700
commit8622bb41a28d8efaf787fbe0f4170127461b5f6c (patch)
tree0cbccd4b6a72012874bf4a224048cbe8e1576e7b
parent040792aac03882874bffc6d2252e6380b07a3c9f (diff)
downloadtrackermap-server-8622bb41a28d8efaf787fbe0f4170127461b5f6c.tar.gz
trackermap-server-8622bb41a28d8efaf787fbe0f4170127461b5f6c.tar.bz2
trackermap-server-8622bb41a28d8efaf787fbe0f4170127461b5f6c.zip
Handle missing location data
-rw-r--r--src/main/java/org/traccar/protocol/WialonProtocolDecoder.java26
-rw-r--r--src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java3
2 files changed, 18 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
index 223d032b8..80299ff08 100644
--- a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,12 +49,12 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.number("(dd)(dd)(dd);") // date (ddmmyy)
.number("(dd)(dd)(dd);") // time (hhmmss)
- .number("(dd)(dd.d+);") // latitude
- .expression("([NS]);")
- .number("(ddd)(dd.d+);") // longitude
- .expression("([EW]);")
+ .number("(?:NA|(dd)(dd.d+));") // latitude
+ .expression("(?:NA|([NS]));")
+ .number("(?:NA|(ddd)(dd.d+));") // longitude
+ .expression("(?:NA|([EW]));")
.number("(d+.?d*)?;") // speed
- .number("(d+.?d*)?;") // course
+ .number("(?:NA|(d+.?d*))?;") // course
.number("(?:NA|(-?d+.?d*));") // altitude
.number("(?:NA|(d+))") // satellites
.groupBegin().text(";")
@@ -97,11 +97,15 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
+ if (parser.hasNext(9)) {
+ position.setLatitude(parser.nextCoordinate());
+ position.setLongitude(parser.nextCoordinate());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
+ position.setCourse(parser.nextDouble(0));
+ position.setAltitude(parser.nextDouble(0));
+ } else {
+ getLastLocation(position, position.getDeviceTime());
+ }
if (parser.hasNext()) {
int satellites = parser.nextInt(0);
diff --git a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java
index bf986dd8c..7387f5325 100644
--- a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class WialonProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, text(
"#L#2.0;42001300083;;CE45"));
+ verifyAttributes(decoder, text(
+ "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;101_521347:1:521246,101_158:1:510,101_521055:1:510,101_521055_2.9:1:509,101_521056:1:3;626B"));
+
verifyNull(decoder, text(
"#L#123456789012345;test"));