From 2284044f7e9e00935e6ec5020e68ef2492326dda Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 20 Jan 2022 23:51:15 -0800 Subject: Decode location data --- .../traccar/protocol/OrbcommProtocolDecoder.java | 58 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java b/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java index daef923b0..d1e079711 100644 --- a/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java @@ -19,15 +19,20 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.FullHttpResponse; import org.traccar.BasePipelineFactory; import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; import org.traccar.Protocol; +import org.traccar.helper.UnitsConverter; +import org.traccar.model.Position; import javax.json.Json; +import javax.json.JsonArray; import javax.json.JsonObject; import java.io.StringReader; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.LinkedList; import java.util.TimeZone; public class OrbcommProtocolDecoder extends BaseProtocolDecoder { @@ -54,7 +59,58 @@ public class OrbcommProtocolDecoder extends BaseProtocolDecoder { } } - return null; + LinkedList positions = new LinkedList<>(); + + JsonArray messages = json.getJsonArray("Messages"); + for (int i = 0; i < messages.size(); i++) { + JsonObject message = messages.getJsonObject(i); + DeviceSession deviceSession = getDeviceSession( + channel, remoteAddress, true, message.getJsonNumber("ID").toString()); + if (deviceSession != null) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + position.setDeviceTime(dateFormat.parse(message.getString("MessageUTC"))); + + JsonArray fields = message.getJsonObject("Payload").getJsonArray("Fields"); + for (int j = 0; j < fields.size(); j++) { + JsonObject field = fields.getJsonObject(j); + String value = field.getString("Value"); + switch (field.getString("Name")) { + case "latitude": + position.setLatitude(Integer.parseInt(value) / 60000.0); + break; + case "longitude": + position.setLongitude(Integer.parseInt(value) / 60000.0); + break; + case "speed": + position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value))); + break; + case "heading": + position.setCourse(Integer.parseInt(value) * 0.1); + break; + + default: + break; + } + } + + if (position.getLatitude() != 0 && position.getLongitude() != 0) { + position.setValid(true); + position.setFixTime(position.getDeviceTime()); + } else { + getLastLocation(position, position.getDeviceTime()); + } + + positions.add(position); + + } + } + + return positions.isEmpty() ? null : positions; } } -- cgit v1.2.3