diff options
author | Alexandre Truppel <alex.truppel@gmail.com> | 2023-02-22 15:50:19 +0100 |
---|---|---|
committer | Alexandre Truppel <alex.truppel@gmail.com> | 2023-02-22 15:50:19 +0100 |
commit | ba6a9d72e62282d64781b856b8e094e1fb612f9e (patch) | |
tree | 71189c5a3450d22551ad46bbb519da5fafadd1fa | |
parent | 345262a970292541c07aee9982c6a26a29c11f9c (diff) | |
download | trackermap-server-ba6a9d72e62282d64781b856b8e094e1fb612f9e.tar.gz trackermap-server-ba6a9d72e62282d64781b856b8e094e1fb612f9e.tar.bz2 trackermap-server-ba6a9d72e62282d64781b856b8e094e1fb612f9e.zip |
Added "setAccuracy" special case, with tests
-rw-r--r-- | src/main/java/org/traccar/protocol/WialonProtocolDecoder.java | 11 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java | 18 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java index 4c4ff7a63..e2ccfe9d8 100644 --- a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java @@ -148,7 +148,16 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { // (true, yes, etc), in which case we convert into a boolean try { - position.set(key, Double.parseDouble(value)); + double double_value = Double.parseDouble(value); + + // Since accuracy is not part of the general parameter list, + // we need to handle it separately by calling setAccuracy directly + if (key.equals("accuracy")) { + position.setAccuracy(double_value); + } + else { + position.set(key, double_value); + } } catch (NumberFormatException e) { if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("t") || value.equalsIgnoreCase("yes") || value.equalsIgnoreCase("y") diff --git a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java index 45fbfbb1d..e25ff7f9e 100644 --- a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java @@ -1,8 +1,11 @@ package org.traccar.protocol; +import org.traccar.model.Position; import org.junit.Test; import org.traccar.ProtocolTest; +import static org.junit.Assert.assertEquals; + public class WialonProtocolDecoderTest extends ProtocolTest { @Test @@ -19,12 +22,6 @@ public class WialonProtocolDecoderTest extends ProtocolTest { 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")); - verifyAttributes(decoder, text( - "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:true")); - - verifyAttributes(decoder, text( - "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:false")); - verifyNull(decoder, text( "#L#123456789012345;test")); @@ -81,6 +78,15 @@ public class WialonProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, text( "#B#110315;045857;5364.0167;N;06127.8262;E;0;155;965;7;2.40;4;0;14.77,0.02,3.6;AB45DF01145;")); + verifyAttributes(decoder, text( + "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:true")); + + verifyAttributes(decoder, text( + "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:false")); + + Position p = (Position)decoder.decode(null, null, text( + "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;accuracy:2:12.3")); + assertEquals(p.getAccuracy(), 12.3, 0.001); } } |