aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-07-22 23:16:55 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-07-22 23:16:55 -0700
commit08442e5f2c24299b6120a2296a1cfd000a042178 (patch)
treee9a6523ad993f8ffa3c730b91a4251b02d6867c6
parentb8256eb4140dd0a03b98ae6c3e67fcbc561d0229 (diff)
downloadtraccar-server-08442e5f2c24299b6120a2296a1cfd000a042178.tar.gz
traccar-server-08442e5f2c24299b6120a2296a1cfd000a042178.tar.bz2
traccar-server-08442e5f2c24299b6120a2296a1cfd000a042178.zip
Support additional attributes
-rw-r--r--src/main/java/org/traccar/protocol/StbProtocolDecoder.java59
-rw-r--r--src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java3
2 files changed, 56 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
index 4f55bf799..bd151c604 100644
--- a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
@@ -26,10 +26,13 @@ import org.traccar.Protocol;
import org.traccar.model.Position;
import javax.json.Json;
+import javax.json.JsonNumber;
import javax.json.JsonObject;
+import javax.json.JsonString;
import javax.json.JsonValue;
import java.io.StringReader;
import java.net.SocketAddress;
+import java.util.Date;
public class StbProtocolDecoder extends BaseProtocolDecoder {
@@ -87,16 +90,60 @@ public class StbProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- getLastLocation(position, null);
-
if (type == MSG_PROPERTY) {
+ int locationType = 0;
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");
+ String id = propertyObject.getString("id");
+ switch (id) {
+ case "01101001":
+ locationType = propertyObject.getInt("value");
+ break;
+ case "01102001":
+ position.setLongitude(propertyObject.getJsonNumber("value").doubleValue());
+ break;
+ case "01103001":
+ position.setLatitude(propertyObject.getJsonNumber("value").doubleValue());
+ break;
+ case "01118001":
+ position.set(Position.KEY_DEVICE_TEMP, propertyObject.getJsonNumber("value").doubleValue());
+ break;
+ case "01122001":
+ position.set("batteryControl", propertyObject.getInt("value"));
+ break;
+ case "02301001":
+ position.set("switchCabinetCommand", propertyObject.getInt("value"));
+ break;
+ default:
+ String key = "id" + id;
+ if (propertyObject.containsKey("doorId")) {
+ key += "Door" + propertyObject.getString("doorId");
+ }
+ JsonValue value = propertyObject.get("value");
+ switch (value.getValueType()) {
+ case STRING:
+ position.set(key, ((JsonString) value).getString());
+ break;
+ case NUMBER:
+ position.set(key, ((JsonNumber) value).doubleValue());
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ }
+ if (locationType > 0) {
+ position.setTime(new Date());
+ position.setValid(locationType != 5);
+ if (locationType == 2 || locationType == 4) {
+ position.setLongitude(-position.getLongitude());
+ }
+ if (locationType == 3 || locationType == 4) {
+ position.setLatitude(-position.getLatitude());
}
- position.set(key, propertyObject.getString("value"));
+ } else {
+ getLastLocation(position, null);
}
}
diff --git a/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/StbProtocolDecoderTest.java
index 17aa7672c..5e351c19f 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);
+ verifyPosition(decoder, text(
+ "{\"msgType\":310,\"attrList\":[{\"id\":\"01106001\",\"value\":31},{\"id\":\"01101001\",\"value\":1},{\"id\":\"01102001\",\"value\":113.826355},{\"id\":\"01103001\",\"value\":22.846399}],\"devId\":\"BT106001020JPZZ210718001\",\"txnNo\":\"1626940074000\"}"));
+
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\"}"));