aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authornamo <namo@gurtam.com>2017-10-24 12:43:00 +0300
committernamo <namo@gurtam.com>2017-10-24 12:43:00 +0300
commit2ef987e1352c9d9483e062ff82fa83d0511a0972 (patch)
treed33dd362affbaadf3a90a7750cc851080bf47c14 /src/org
parent4b8095a1c91ae2fc9bcd6cfc6e291c7b63af3cd1 (diff)
downloadtraccar-server-2ef987e1352c9d9483e062ff82fa83d0511a0972.tar.gz
traccar-server-2ef987e1352c9d9483e062ff82fa83d0511a0972.tar.bz2
traccar-server-2ef987e1352c9d9483e062ff82fa83d0511a0972.zip
flespi integration: listening messages (rev.6): unit test added, getLastLocation added if position is absent
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/FlespiProtocolDecoder.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/FlespiProtocolDecoder.java b/src/org/traccar/protocol/FlespiProtocolDecoder.java
index 3a12cd7b8..2e57c1dcf 100644
--- a/src/org/traccar/protocol/FlespiProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlespiProtocolDecoder.java
@@ -30,6 +30,7 @@ import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
+import javax.json.JsonString;
import java.io.StringReader;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
@@ -56,11 +57,11 @@ public class FlespiProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
for (int i = 0; i < result.size(); i++) {
JsonObject message = result.getJsonObject(i);
- String ident = message.getString("ident");
+ JsonString ident = message.getJsonString("ident");
if (ident == null) {
continue;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident);
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
if (deviceSession == null) {
continue;
}
@@ -85,12 +86,15 @@ public class FlespiProtocolDecoder extends BaseProtocolDecoder {
private void decodePosition(JsonObject object, Position position) {
position.setProtocol(protocolName);
- position.setTime(new Date((long) object.getJsonNumber("timestamp").doubleValue() * 1000));
+ Date deviceTime = new Date((long) object.getJsonNumber("timestamp").doubleValue() * 1000);
+ position.setTime(deviceTime);
JsonNumber lat = object.getJsonNumber("position.latitude");
JsonNumber lon = object.getJsonNumber("position.longitude");
if (lat != null && lon != null) {
position.setLatitude(lat.doubleValue());
position.setLongitude(lon.doubleValue());
+ } else {
+ getLastLocation(position, deviceTime);
}
JsonNumber speed = object.getJsonNumber("position.speed");
if (speed != null) {