aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/StbProtocolDecoder.java57
1 files changed, 50 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;
}