aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-09-25 16:32:17 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-09-25 16:32:17 -0700
commit63b97670ddbcd1a528e498d0c743f480c09c91ad (patch)
tree1119ee7b20a37be7cfc4dbea00e7c3d068a90b0a /src/main/java/org/traccar
parentde76b91f467c2c4d1e393903ab3e3ae6c6167a5a (diff)
downloadtraccar-server-63b97670ddbcd1a528e498d0c743f480c09c91ad.tar.gz
traccar-server-63b97670ddbcd1a528e498d0c743f480c09c91ad.tar.bz2
traccar-server-63b97670ddbcd1a528e498d0c743f480c09c91ad.zip
Support Yabby Edge forwarder
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java
index 987361baf..ebf9a006c 100644
--- a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2021 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.
@@ -32,7 +32,11 @@ import java.io.StringReader;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.OffsetDateTime;
+import java.util.Collection;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
@@ -51,12 +55,25 @@ public class DmtHttpProtocolDecoder extends BaseHttpProtocolDecoder {
JsonObject root = Json.createReader(
new StringReader(request.content().toString(StandardCharsets.US_ASCII))).readObject();
+ Object result;
+ if (root.containsKey("device")) {
+ result = decodeEdge(channel, remoteAddress, root);
+ } else {
+ result = decodeTraditional(channel, remoteAddress, root);
+ }
+
+ sendResponse(channel, result != null ? HttpResponseStatus.OK : HttpResponseStatus.BAD_REQUEST);
+ return result;
+ }
+
+ private Collection<Position> decodeTraditional(
+ Channel channel, SocketAddress remoteAddress, JsonObject root) throws ParseException {
+
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, root.getString("IMEI"));
if (deviceSession == null) {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
}
@@ -126,8 +143,42 @@ public class DmtHttpProtocolDecoder extends BaseHttpProtocolDecoder {
positions.add(position);
}
- sendResponse(channel, HttpResponseStatus.OK);
return positions;
}
+ private Position decodeEdge(
+ Channel channel, SocketAddress remoteAddress, JsonObject root) {
+
+ JsonObject device = root.getJsonObject("device");
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, device.getString("imei"));
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setValid(true);
+ position.setTime(new Date(OffsetDateTime.parse(root.getString("date")).toInstant().toEpochMilli()));
+ position.setLatitude(root.getJsonNumber("lat").doubleValue());
+ position.setLongitude(root.getJsonNumber("lng").doubleValue());
+ position.setAccuracy(root.getJsonNumber("posAcc").doubleValue());
+
+ position.set(Position.KEY_INDEX, root.getInt("sqn"));
+ position.set(Position.KEY_EVENT, root.getInt("reason"));
+
+ JsonArray analogues = root.getJsonArray("analogues");
+ for (int i = 0; i < analogues.size(); i++) {
+ JsonObject adc = analogues.getJsonObject(i);
+ position.set(Position.PREFIX_ADC + adc.getInt("id"), adc.getInt("val"));
+ }
+
+ position.set(Position.KEY_INPUT, root.getInt("inputs"));
+ position.set(Position.KEY_OUTPUT, root.getInt("outputs"));
+ position.set(Position.KEY_STATUS, root.getInt("status"));
+
+ return position;
+ }
+
}