aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-07-13 20:58:13 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-07-13 20:58:13 -0700
commit75647118260d712c0d260050c548026b684b78c4 (patch)
tree4cd73491987337203cc2ffb916d08daf99510fa3 /src
parent74c4da689dff83f5f86c2941a686dd81e96ed544 (diff)
downloadtrackermap-server-75647118260d712c0d260050c548026b684b78c4.tar.gz
trackermap-server-75647118260d712c0d260050c548026b684b78c4.tar.bz2
trackermap-server-75647118260d712c0d260050c548026b684b78c4.zip
Decode properties report
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/StbProtocolDecoder.java57
-rw-r--r--src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java3
2 files changed, 53 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
index 0e4f030cf..4f55bf799 100644
--- a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
@@ -16,14 +16,18 @@
package org.traccar.protocol;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonProcessingException;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
+import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
+import org.traccar.model.Position;
import javax.json.Json;
import javax.json.JsonObject;
+import javax.json.JsonValue;
import java.io.StringReader;
import java.net.SocketAddress;
@@ -33,6 +37,10 @@ public class StbProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ public static final int MSG_LOGIN = 110;
+ public static final int MSG_PROPERTY = 310;
+ public static final int MSG_ALARM = 410;
+
public static class Response {
@JsonProperty("msgType")
private int type;
@@ -44,21 +52,56 @@ public class StbProtocolDecoder extends BaseProtocolDecoder {
private String transaction;
}
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- JsonObject root = Json.createReader(new StringReader((String) msg)).readObject();
+ private void sendResponse(
+ Channel channel, SocketAddress remoteAddress, int type, String deviceId, JsonObject root)
+ throws JsonProcessingException {
Response response = new Response();
- response.type = root.getInt("msgType") + 1;
- response.deviceId = root.getString("devId");
+ response.type = type + 1;
+ response.deviceId = deviceId;
response.result = 1;
response.transaction = root.getString("txnNo");
if (channel != null) {
channel.writeAndFlush(new NetworkMessage(
Context.getObjectMapper().writeValueAsString(response), remoteAddress));
}
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ JsonObject root = Json.createReader(new StringReader((String) msg)).readObject();
+ int type = root.getInt("msgType");
+ String deviceId = root.getString("devId");
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, deviceId);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ sendResponse(channel, remoteAddress, type, deviceId, root);
+
+ if (type == MSG_PROPERTY || type == MSG_ALARM) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ if (type == MSG_PROPERTY) {
+ for (JsonValue property : root.getJsonArray("attrList")) {
+ JsonObject propertyObject = property.asJsonObject();
+ String key = "id" + propertyObject.getString("id");
+ if (propertyObject.containsKey("doorId")) {
+ key += "Door" + propertyObject.getString("doorId");
+ }
+ position.set(key, propertyObject.getString("value"));
+ }
+ }
+
+ return position;
+ }
return null;
}
diff --git a/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java
index b6f720133..17aa7672c 100644
--- a/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class StbProtocolDecoderTest extends ProtocolTest {
var decoder = new StbProtocolDecoder(null);
+ verifyAttributes(decoder, text(
+ "{\"attrList\":[{\"doorId\":\"4\",\"id\":\"02103001\",\"value\":\"1\"},{\"doorId\":\"2\",\"id\":\"02103001\",\"value\":\"0\"},{\"id\":\"02120001\",\"value\":\"11.37\"},{\"doorId\":\"6\",\"id\":\"02106001\",\"value\":\"\"},{\"doorId\":\"5\",\"id\":\"02103001\",\"value\":\"0\"},{\"id\":\"02105001\",\"value\":\"-150\"},{\"id\":\"02102001\",\"value\":\"1\"},{\"doorId\":\"5\",\"id\":\"02106001\",\"value\":\"\"},{\"doorId\":\"5\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"1\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"1\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"6\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"7\",\"id\":\"02103001\",\"value\":\"0\"},{\"doorId\":\"3\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"1\",\"id\":\"02106001\",\"value\":\"\"},{\"id\":\"02101001\",\"value\":\"\"},{\"id\":\"02119001\",\"value\":\"1\"},{\"doorId\":\"6\",\"id\":\"02103001\",\"value\":\"0\"},{\"doorId\":\"8\",\"id\":\"02103001\",\"value\":\"0\"},{\"doorId\":\"3\",\"id\":\"02103001\",\"value\":\"0\"},{\"doorId\":\"2\",\"id\":\"02106001\",\"value\":\"\"},{\"id\":\"02108001\",\"value\":\"0.922\"},{\"doorId\":\"2\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"7\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"4\",\"id\":\"02106001\",\"value\":\"\"},{\"doorId\":\"3\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"8\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"1\",\"id\":\"02103001\",\"value\":\"0\"},{\"doorId\":\"2\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"7\",\"id\":\"02106001\",\"value\":\"\"},{\"doorId\":\"8\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"3\",\"id\":\"02106001\",\"value\":\"\"},{\"doorId\":\"4\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"8\",\"id\":\"02106001\",\"value\":\"\"},{\"id\":\"02112001\",\"value\":\"0.0\"},{\"doorId\":\"4\",\"id\":\"02104001\",\"value\":\"0\"},{\"id\":\"02111001\",\"value\":\"0.0\"},{\"id\":\"02113001\",\"value\":\"27\"},{\"doorId\":\"5\",\"id\":\"02118001\",\"value\":\"1\"},{\"doorId\":\"7\",\"id\":\"02104001\",\"value\":\"0\"},{\"doorId\":\"6\",\"id\":\"02118001\",\"value\":\"1\"},{\"id\":\"02107001\",\"value\":\"229.7\"}],\"devId\":\"CHZD08KPD0210425046\",\"isFull\":0,\"msgType\":310,\"txnNo\":\"1626153841985\"}"));
+
verifyNull(decoder, text(
"{\"devId\":\"CHZD08KPD0210425046\",\"devType\":2,\"hardVersion\":\"HDTTVA19\",\"msgType\":110,\"protocolVersion\":\"V1\",\"softVersion\":\"3.1.8\",\"switchCabStatus\":\"1\",\"txnNo\":\"1625212741537\"}"));