aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-05-13 22:26:04 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-05-13 22:26:04 -0700
commitd9dcdd8b66f197ecb29c2291be6eb2a640886cc6 (patch)
tree3b37f68c9ef1fcf67d1aee861f99d7e181e4cf45
parent19b087e836caaccb2301e70b0667bb530c1a4077 (diff)
downloadtrackermap-server-d9dcdd8b66f197ecb29c2291be6eb2a640886cc6.tar.gz
trackermap-server-d9dcdd8b66f197ecb29c2291be6eb2a640886cc6.tar.bz2
trackermap-server-d9dcdd8b66f197ecb29c2291be6eb2a640886cc6.zip
Decode additional Outsafe data
-rw-r--r--src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java22
-rw-r--r--src/test/java/org/traccar/protocol/OutsafeProtocolDecoderTest.java3
2 files changed, 24 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java b/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java
index 5e95270e8..9de77d241 100644
--- a/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2020 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.
@@ -24,11 +24,15 @@ import org.traccar.Protocol;
import org.traccar.model.Position;
import javax.json.Json;
+import javax.json.JsonNumber;
import javax.json.JsonObject;
+import javax.json.JsonString;
+import javax.json.JsonValue;
import java.io.StringReader;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Date;
+import java.util.Map;
public class OutsafeProtocolDecoder extends BaseHttpProtocolDecoder {
@@ -61,9 +65,25 @@ public class OutsafeProtocolDecoder extends BaseHttpProtocolDecoder {
position.setCourse(json.getJsonNumber("heading").intValue());
position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").intValue());
+ position.set("origin", json.getString("origin"));
+
+ JsonObject data = json.getJsonObject("data");
+ for (Map.Entry<String, JsonValue> entry : data.entrySet()) {
+ decodeUnknownParam(entry.getKey(), entry.getValue(), position);
+ }
sendResponse(channel, HttpResponseStatus.OK);
return position;
}
+ private void decodeUnknownParam(String name, JsonValue value, Position position) {
+ if (value instanceof JsonNumber) {
+ position.set(name, ((JsonNumber) value).doubleValue());
+ } else if (value instanceof JsonString) {
+ position.set(name, ((JsonString) value).getString());
+ } else if (value == JsonValue.TRUE || value == JsonValue.FALSE) {
+ position.set(name, value == JsonValue.TRUE);
+ }
+ }
+
}
diff --git a/src/test/java/org/traccar/protocol/OutsafeProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/OutsafeProtocolDecoderTest.java
index 12f0106f9..20b6617ef 100644
--- a/src/test/java/org/traccar/protocol/OutsafeProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/OutsafeProtocolDecoderTest.java
@@ -12,6 +12,9 @@ public class OutsafeProtocolDecoderTest extends ProtocolTest {
OutsafeProtocolDecoder decoder = new OutsafeProtocolDecoder(null);
verifyPosition(decoder, request(HttpMethod.POST, "/",
+ buffer("{\"device\":\"865303040103725\",\"owner\":\"\",\"data\":{\"cmd\":\"\",\"ms1\":-1,\"ms2\":-1,\"ms3\":0,\"ms4\":0,\"observation\":\"\",\"content\":null},\"time\":1589277568,\"origin\":\"mqgatte\",\"latitude\":19.346855,\"longitude\":-99.29587,\"altitude\":2757,\"heading\":0,\"rssi\":0}")));
+
+ verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{\"device\":\"862061044762093\",\"owner\":\"\",\"data\":{\"cmd\":\"GEO\",\"ms1\":82,\"ms2\":80,\"ms3\":5266,\"ms4\":-68,\"observation\":\"$NMEA 323455\",\"content\":null},\"time\":null,\"origin\":\"TCP\",\"latitude\":19.334734,\"longitude\":-99.307236,\"altitude\":2000,\"heading\":0,\"rssi\":123}")));
verifyPosition(decoder, request(HttpMethod.POST, "/",