aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2022-01-11 23:36:47 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2022-01-11 23:36:47 -0800
commitad102cd882dd9ec6f7e4ffedad34c793184ea23b (patch)
tree9193cf47b6e9ad8d41e9bf5c31e6602ab90a5384 /src
parent7b2e47a143a34cb97cb8b52c00081e36898db346 (diff)
downloadtrackermap-server-ad102cd882dd9ec6f7e4ffedad34c793184ea23b.tar.gz
trackermap-server-ad102cd882dd9ec6f7e4ffedad34c793184ea23b.tar.bz2
trackermap-server-ad102cd882dd9ec6f7e4ffedad34c793184ea23b.zip
Add FlexAPI motion decoding
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java13
-rw-r--r--src/test/java/org/traccar/protocol/FlexApiProtocolDecoderTest.java5
2 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java
index d4d539a9e..3dfcd459b 100644
--- a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ * Copyright 2021 - 2022 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.
@@ -89,6 +89,17 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_VIN, payload.getString("obd.vin"));
}
+ } else if (topic.contains("motion")) {
+
+ getLastLocation(position, new Date(payload.getInt("motion.ts") * 1000L));
+
+ position.set("ax", payload.getJsonNumber("motion.ax").doubleValue());
+ position.set("ay", payload.getJsonNumber("motion.ay").doubleValue());
+ position.set("az", payload.getJsonNumber("motion.az").doubleValue());
+ position.set("gx", payload.getJsonNumber("motion.gx").doubleValue());
+ position.set("gy", payload.getJsonNumber("motion.gy").doubleValue());
+ position.set("gz", payload.getJsonNumber("motion.gz").doubleValue());
+
} else {
return null;
diff --git a/src/test/java/org/traccar/protocol/FlexApiProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FlexApiProtocolDecoderTest.java
index a276a01e9..43b4e097f 100644
--- a/src/test/java/org/traccar/protocol/FlexApiProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FlexApiProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class FlexApiProtocolDecoderTest extends ProtocolTest {
var decoder = new FlexApiProtocolDecoder(null);
verifyAttributes(decoder, text(
+ "${\"topic\":\"v1/VF3102021113001/motion/info\",\"payload\":{\"motion.ts\":1641885877,\"motion.ax\":0.006344,\"motion.ay\":0.289384,\"motion.az\":-0.939156,\"motion.gx\":0.420000,\"motion.gy\":0.420000,\"motion.gz\":-0.280000}}xx"));
+
+ verifyAttributes(decoder, text(
"${\"topic\":\"v1/VF3102021113001/gnss/info\",\"payload\":{\"gnss.ts\":1639713510,\"gnss.latitude\":30.587509,\"gnss.longitude\":104.053650,\"gnss.altitude\":391,\"gnss.speed\":0,\"gnss.heading\":0,\"gnss.hdop\":1.100000,\"gnss.fix\":4,\"gnss.num_sv\":10}}xx"));
verifyNull(decoder, text(
@@ -25,7 +28,7 @@ public class FlexApiProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"${\"topic\":\"v1/VF3102021111601/gnss/info\",\"payload\":{\"time\":1637225390,\"lat\":30.587942,\"log\":104.053543,\"gnss.altitude\":480.399994,\"gnss.speed\":0,\"gnss.heading\":0,\"gnss.hdop\":0.900000,\"gnss.fix\":4,\"gnss.num_sv\":11}}xx"));
- verifyNull(decoder, text(
+ verifyAttributes(decoder, text(
"${\"topic\":\"v1/VF3102021111601/motion/info\",\"payload\":{\"motion.ts\":1637225450,\"motion.ax\":0.009272,\"motion.ay\":0.278404,\"motion.az\":-0.941596,\"motion.gx\":0.420000,\"motion.gy\":-0.490000,\"motion.gz\":0.140000}}xx"));
verifyNull(decoder, text(