aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-02-22 07:13:39 -0800
committerGitHub <noreply@github.com>2023-02-22 07:13:39 -0800
commitafef64ee9a572e1c65368de3012bc5792374e411 (patch)
tree226f30583e8cd7ec2d79bfc6233bc9d57546ae1a /src
parent392f00082faff72c9948ed569e4c883a5fabe7d6 (diff)
parenta2d9daf4b21313ebaed862f126355becf2b6d4ec (diff)
downloadtrackermap-server-afef64ee9a572e1c65368de3012bc5792374e411.tar.gz
trackermap-server-afef64ee9a572e1c65368de3012bc5792374e411.tar.bz2
trackermap-server-afef64ee9a572e1c65368de3012bc5792374e411.zip
Merge pull request #5037 from truppelito/master
Wialon attributes improvement
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/WialonProtocolDecoder.java30
-rw-r--r--src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java5
2 files changed, 33 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
index b87ba2b53..b319a5947 100644
--- a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java
@@ -135,10 +135,36 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
for (String param : values) {
Matcher paramParser = Pattern.compile("(.*):[1-3]:(.*)").matcher(param);
if (paramParser.matches()) {
+ // Parsing gives a (string,string) key-value pair
+ String key = paramParser.group(1).toLowerCase();
+ String value = paramParser.group(2);
+
+ // Key is already in correct type (string)
+
+ // If we can parse the value as a double, then we use that as the value's type.
+ // This covers both integer (x:1:y) and double (x:2:y) types in the Wialon protocol
+
+ // If not, value type is a string unless it is equal to some specific cases
+ // (true, false), in which case we convert into a boolean
+
try {
- position.set(paramParser.group(1).toLowerCase(), Double.parseDouble(paramParser.group(2)));
+ double doubleValue = 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(doubleValue);
+ } else {
+ position.set(key, doubleValue);
+ }
} catch (NumberFormatException e) {
- position.set(paramParser.group(1).toLowerCase(), paramParser.group(2));
+ if (value.equalsIgnoreCase("true")) {
+ position.set(key, true);
+ } else if (value.equalsIgnoreCase("false")) {
+ position.set(key, false);
+ } else {
+ position.set(key, value);
+ }
}
}
}
diff --git a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java
index 6953784fb..0a47edcb4 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
@@ -75,6 +78,8 @@ 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;"));
+ verifyAttribute(decoder, text(
+ "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:false"), "motion", false);
}
}