aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java2
2 files changed, 6 insertions, 15 deletions
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
index 4efed2a35..4bff3c7ed 100644
--- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
@@ -63,8 +63,6 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- long timestamp;
- String deviceId = new String();
Position position = new Position();
position.setProtocol(getProtocolName());
position.setValid(true);
@@ -94,27 +92,20 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_BATTERY, root.getInt("batt"));
}
- if (root.containsKey("tst")) {
- timestamp = root.getJsonNumber("tst").longValue();
- if (timestamp < Integer.MAX_VALUE) {
- timestamp *= 1000;
- }
- } else {
- timestamp = new Date().getTime();
- }
- position.setTime(new Date(timestamp));
+ position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000));
+ String uniqueId = "";
if (root.containsKey("tid")) {
- deviceId = root.getString("tid");
+ uniqueId = root.getString("tid");
}
if (root.containsKey("topic")) {
- deviceId = root.getString("topic");
+ uniqueId = root.getString("topic");
if (root.containsKey("tid")) {
position.set("tid", root.getString("tid"));
}
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, deviceId);
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
if (deviceSession == null) {
sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
diff --git a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java
index 57e5d7eca..89b994fbe 100644
--- a/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/OwnTracksProtocolDecoderTest.java
@@ -18,7 +18,7 @@ public class OwnTracksProtocolDecoderTest extends ProtocolTest {
buffer("{\"cog\":271,\"lon\":2.29513,\"acc\":5,\"vel\":61,\"vac\":21,\"lat\":48.85833,\"tst\":1497349316,\"alt\":167,\"_type\":\"location\",\"tid\":\"JJ\",\"t\":\"u\",\"batt\":67}")));
verifyPosition(decoder, request(HttpMethod.POST, "/",
- buffer(text("{\"lat\":48.85,\"lon\":2.295,\"_type\":\"location\",\"tid\":\"JJ\"}"))));
+ buffer("{\"lat\":48.85,\"lon\":2.295,\"_type\":\"location\",\"tid\":\"JJ\",\"tst\":1497476456}")));
}
}