From 2ef987e1352c9d9483e062ff82fa83d0511a0972 Mon Sep 17 00:00:00 2001 From: namo Date: Tue, 24 Oct 2017 12:43:00 +0300 Subject: flespi integration: listening messages (rev.6): unit test added, getLastLocation added if position is absent --- src/org/traccar/protocol/FlespiProtocolDecoder.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') 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 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) { -- cgit v1.2.3