aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2022-01-20 23:51:15 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2022-01-20 23:51:15 -0800
commit2284044f7e9e00935e6ec5020e68ef2492326dda (patch)
treeac040f96bc197b803a5c17c7e9fe0327205456aa /src/main/java
parent6f1449a9e22f87c22369212c0094e02d813818c0 (diff)
downloadtrackermap-server-2284044f7e9e00935e6ec5020e68ef2492326dda.tar.gz
trackermap-server-2284044f7e9e00935e6ec5020e68ef2492326dda.tar.bz2
trackermap-server-2284044f7e9e00935e6ec5020e68ef2492326dda.zip
Decode location data
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java58
1 files changed, 57 insertions, 1 deletions
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<Position> 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;
}
}