aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-09-17 21:26:11 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-09-17 21:26:11 -0700
commit3d2a761f1df457ab5112300aaa410efd2c2cbcf2 (patch)
treed86359e28c9409f1f0af1e842c4e1071f5df03ae /src/main/java/org
parenta0db98120af45c33994428f69c2018cf5a459a02 (diff)
downloadtrackermap-server-3d2a761f1df457ab5112300aaa410efd2c2cbcf2.tar.gz
trackermap-server-3d2a761f1df457ab5112300aaa410efd2c2cbcf2.tar.bz2
trackermap-server-3d2a761f1df457ab5112300aaa410efd2c2cbcf2.zip
Support SigFox JSON location
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java133
1 files changed, 74 insertions, 59 deletions
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index ea9c9767b..f9c79fb5b 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -64,74 +64,89 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(new Date(json.getInt("time") * 1000L));
+ if (json.containsKey("time")) {
+ position.setTime(new Date(json.getInt("time") * 1000L));
+ } else {
+ position.setTime(new Date());
+ }
- String data = json.getString(json.containsKey("data") ? "data" : "payload");
- ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(data));
- try {
- int event = buf.readUnsignedByte();
- if (event >> 4 == 0) {
+ if (json.containsKey("location")) {
- position.setValid(true);
- position.setLatitude(buf.readIntLE() * 0.0000001);
- position.setLongitude(buf.readIntLE() * 0.0000001);
- position.setCourse(buf.readUnsignedByte() * 2);
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ JsonObject location = json.getJsonObject("location");
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.025);
+ position.setValid(true);
+ position.setLatitude(location.getJsonNumber("lat").doubleValue());
+ position.setLongitude(location.getJsonNumber("lng").doubleValue());
- } else {
+ } else {
- position.set(Position.KEY_EVENT, event);
- if (event == 0x22 || event == 0x62) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
+ String data = json.getString(json.containsKey("data") ? "data" : "payload");
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(data));
+ try {
+ int event = buf.readUnsignedByte();
+ if (event >> 4 == 0) {
+
+ position.setValid(true);
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
+ position.setCourse(buf.readUnsignedByte() * 2);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+
+ position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.025);
+
+ } else {
- while (buf.isReadable()) {
- int type = buf.readUnsignedByte();
- switch (type) {
- case 0x01:
- position.setValid(true);
- position.setLatitude(buf.readMedium());
- position.setLongitude(buf.readMedium());
- break;
- case 0x02:
- position.setValid(true);
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- break;
- case 0x03:
- position.set(Position.PREFIX_TEMP + 1, buf.readByte() * 0.5);
- break;
- case 0x04:
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
- break;
- case 0x05:
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- break;
- case 0x06:
- String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
- position.setNetwork(new Network(WifiAccessPoint.from(
- mac.substring(0, mac.length() - 1), buf.readUnsignedByte())));
- break;
- case 0x07:
- buf.skipBytes(10); // wifi extended
- break;
- case 0x08:
- buf.skipBytes(6); // accelerometer
- break;
- case 0x09:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- break;
- default:
- buf.readUnsignedByte(); // fence number
- break;
+ position.set(Position.KEY_EVENT, event);
+ if (event == 0x22 || event == 0x62) {
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ }
+
+ while (buf.isReadable()) {
+ int type = buf.readUnsignedByte();
+ switch (type) {
+ case 0x01:
+ position.setValid(true);
+ position.setLatitude(buf.readMedium());
+ position.setLongitude(buf.readMedium());
+ break;
+ case 0x02:
+ position.setValid(true);
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ break;
+ case 0x03:
+ position.set(Position.PREFIX_TEMP + 1, buf.readByte() * 0.5);
+ break;
+ case 0x04:
+ position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
+ break;
+ case 0x05:
+ position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ break;
+ case 0x06:
+ String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
+ position.setNetwork(new Network(WifiAccessPoint.from(
+ mac.substring(0, mac.length() - 1), buf.readUnsignedByte())));
+ break;
+ case 0x07:
+ buf.skipBytes(10); // wifi extended
+ break;
+ case 0x08:
+ buf.skipBytes(6); // accelerometer
+ break;
+ case 0x09:
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ break;
+ default:
+ buf.readUnsignedByte(); // fence number
+ break;
+ }
}
- }
+ }
+ } finally {
+ buf.release();
}
- } finally {
- buf.release();
}
if (position.getLatitude() == 0 && position.getLongitude() == 0) {