diff options
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r-- | src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java index 3dfcd459b..20ff78c21 100644 --- a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java @@ -19,6 +19,8 @@ import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.Protocol; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import javax.json.Json; @@ -52,7 +54,7 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { JsonObject payload = root.getJsonObject("payload"); - if (topic.contains("gnss")) { + if (topic.contains("/gnss/")) { position.setValid(true); @@ -72,7 +74,25 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, payload.getInt("gnss.num_sv")); - } else if (topic.contains("obd")) { + } else if (topic.contains("/cellular1/")) { + + getLastLocation(position, new Date(payload.getInt("modem1.ts") * 1000L)); + + position.set("imei", payload.getString("modem1.imei")); + position.set("imsi", payload.getString("modem1.imsi")); + position.set(Position.KEY_ICCID, payload.getString("modem1.iccid")); + + String operator = payload.getString("modem1.operator"); + if (!operator.isEmpty()) { + position.setNetwork(new Network(CellTower.from( + Integer.parseInt(operator.substring(0, 3)), + Integer.parseInt(operator.substring(3)), + Integer.parseInt(payload.getString("modem1.lac"), 16), + Integer.parseInt(payload.getString("modem1.cell_id"), 16), + payload.getInt("modem1.rssi")))); + } + + } else if (topic.contains("/obd/")) { getLastLocation(position, new Date(payload.getInt("obd.ts") * 1000L)); @@ -89,7 +109,7 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VIN, payload.getString("obd.vin")); } - } else if (topic.contains("motion")) { + } else if (topic.contains("/motion/")) { getLastLocation(position, new Date(payload.getInt("motion.ts") * 1000L)); @@ -100,6 +120,31 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { position.set("gy", payload.getJsonNumber("motion.gy").doubleValue()); position.set("gz", payload.getJsonNumber("motion.gz").doubleValue()); + } else if (topic.contains("/io/")) { + + getLastLocation(position, new Date(payload.getInt("io.ts") * 1000L)); + + if (payload.containsKey("io.IGN")) { + position.set(Position.KEY_IGNITION, payload.getInt("io.IGN") > 0); + } + + for (String key : payload.keySet()) { + if (key.startsWith("io.AI")) { + position.set(Position.PREFIX_ADC + key.substring(5), payload.getJsonNumber(key).doubleValue()); + } else if (key.startsWith("io.DI") && !key.endsWith("_pullup")) { + position.set(Position.PREFIX_IN + key.substring(5), payload.getInt(key) > 0); + } else if (key.startsWith("io.DO")) { + position.set(Position.PREFIX_OUT + key.substring(5), payload.getInt(key) > 0); + } + } + + } else if (topic.contains("/sysinfo/")) { + + getLastLocation(position, new Date(payload.getInt("sysinfo.ts") * 1000L)); + + position.set("serial", payload.getString("sysinfo.serial_number")); + position.set(Position.KEY_VERSION_FW, payload.getString("sysinfo.firmware_version")); + } else { return null; |