aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocolDecoder.java27
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java4
2 files changed, 22 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
index a5a9efbb4..ea604f4ac 100644
--- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
@@ -1,6 +1,6 @@
/*
* Copyright 2017 Jan-Piet Mens (jpmens@gmail.com)
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 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.
@@ -58,6 +58,11 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder {
JsonObject root = Json.createReader(
new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject();
+ if (!root.containsKey("_type") || !root.getString("_type").equals("location")) {
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
+ return null;
+ }
+
Position position = new Position();
position.setProtocol(getProtocolName());
position.setValid(true);
@@ -83,17 +88,21 @@ public class OwnTracksProtocolDecoder extends BaseProtocolDecoder {
if (root.containsKey("batt")) {
position.set(Position.KEY_BATTERY, root.getInt("batt"));
}
- if (root.containsKey("topic")) {
- position.set("topic", root.getString("topic"));
- }
- long timestamp = root.getJsonNumber("tst").longValue();
- if (timestamp < Integer.MAX_VALUE) {
- timestamp *= 1000;
+ position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000));
+
+ String uniqueId;
+
+ if (root.containsKey("topic")) {
+ uniqueId = root.getString("topic");
+ if (root.containsKey("tid")) {
+ position.set("tid", root.getString("tid"));
+ }
+ } else {
+ uniqueId = root.getString("tid");
}
- position.setTime(new Date(timestamp));
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, root.getString("tid"));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
if (deviceSession == null) {
sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 7af856a9c..d55c307da 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -76,6 +76,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return Position.ALARM_GEOFENCE_ENTER;
} else if (BitUtil.check(status, 3)) {
return Position.ALARM_OVERSPEED;
+ } else if (BitUtil.check(status, 4)) {
+ return Position.ALARM_MOVEMENT;
} else if (BitUtil.check(status, 16)) {
return Position.ALARM_SOS;
} else if (BitUtil.check(status, 17)) {
@@ -84,6 +86,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return Position.ALARM_GEOFENCE_EXIT;
} else if (BitUtil.check(status, 19)) {
return Position.ALARM_GEOFENCE_ENTER;
+ } else if (BitUtil.check(status, 20)) {
+ return Position.ALARM_REMOVING;
}
return null;
}