aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-12-02 21:34:18 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-12-02 21:34:18 +1300
commit9164f1fbdf12ba2ed65839eb83a794fcc602edf8 (patch)
tree17333ef659b36cff0405c765d39a5bedb01cd6f8
parent2039c90485caaa03ab4833797daaca3250174203 (diff)
downloadtrackermap-server-9164f1fbdf12ba2ed65839eb83a794fcc602edf8.tar.gz
trackermap-server-9164f1fbdf12ba2ed65839eb83a794fcc602edf8.tar.bz2
trackermap-server-9164f1fbdf12ba2ed65839eb83a794fcc602edf8.zip
Handle empty speed and course
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java18
-rw-r--r--test/org/traccar/protocol/WialonProtocolDecoderTest.java6
2 files changed, 20 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 65cc17bcd..5b8d9a24e 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -47,8 +47,8 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
"([NS]);" +
"(\\d{3})(\\d{2}\\.\\d+);" + // Longitude (DDDMM.MMMM)
"([EW]);" +
- "(\\d+\\.?\\d*);" + // Speed
- "(\\d+\\.?\\d*);" + // Course
+ "(\\d+\\.?\\d*)?;" + // Speed
+ "(\\d+\\.?\\d*)?;" + // Course
"(?:(\\d+\\.?\\d*)|NA);" + // Altitude
"(?:(\\d+)|NA)" + // Satellites
".*"); // Full format
@@ -103,10 +103,20 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude);
// Speed
- position.setSpeed(Double.valueOf(parser.group(index++)) * 0.539957);
+ String speed = parser.group(index++);
+ if (speed != null) {
+ position.setSpeed(Double.valueOf(speed) * 0.539957);
+ } else {
+ position.setSpeed(0.0);
+ }
// Course
- position.setCourse(Double.valueOf(parser.group(index++)));
+ String course = parser.group(index++);
+ if (course != null) {
+ position.setCourse(Double.valueOf(course));
+ } else {
+ position.setCourse(0.0);
+ }
// Altitude
String altitude = parser.group(index++);
diff --git a/test/org/traccar/protocol/WialonProtocolDecoderTest.java b/test/org/traccar/protocol/WialonProtocolDecoderTest.java
index f5ef8f277..13aad6e2e 100644
--- a/test/org/traccar/protocol/WialonProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WialonProtocolDecoderTest.java
@@ -20,12 +20,18 @@ public class WialonProtocolDecoderTest {
verify(decoder.decode(null, null,
"#SD#270413;205601;5544.6025;N;03739.6834;E;1;2;3;4"));
+
+ verify(decoder.decode(null, null,
+ "#SD#021214;065947;2237.7552;N;11404.8851;E;0.000;;170.9;5"));
verify(decoder.decode(null, null,
"#D#270413;205601;5544.6025;N;03739.6834;E;1;2;3;4;0.0;0;0;14.77,0.02,3.6;NA;count1:1:564,fuel:2:45.8,hw:3:V4.5"));
verify(decoder.decode(null, null,
"#D#190114;051312;4459.6956;N;04105.9930;E;35;306;204.000000;12;NA;452986639;NA;106.000000;NA;sats_gps:1:9,sats_glonass:1:3,balance:2:12123.000000,stay_balance:1:0"));
+
+ verify(decoder.decode(null, null,
+ "#D#021214;065947;2237.7552;N;11404.8851;E;0.000;;170.9;5;1.74;NA;NA;NA;NA;NA"));
verify(decoder.decode(null, null,
"#B#080914;073235;5027.50625;N;03026.19321;E;0.700;0.000;NA;4;NA;NA;NA;;NA;Батарея:3:100 %|080914;073420;5027.50845;N;03026.18854;E;1.996;292.540;NA;4;NA;NA;NA;;NA;Батарея:3:100 %"));