aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-06-08 11:16:52 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-06-08 11:16:52 -0700
commit9ba7c3f15750afd68f3f8c071a783d40b2e0f0dc (patch)
treeeeb75453fb35464a2b673b95971f020e511e16bf /src
parent920c732f65718f6b1f06b204016223e2d8462630 (diff)
downloadtrackermap-server-9ba7c3f15750afd68f3f8c071a783d40b2e0f0dc.tar.gz
trackermap-server-9ba7c3f15750afd68f3f8c071a783d40b2e0f0dc.tar.bz2
trackermap-server-9ba7c3f15750afd68f3f8c071a783d40b2e0f0dc.zip
Support new Sigfox format
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java66
-rw-r--r--src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java3
2 files changed, 60 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index d7836b35d..e9a943e0e 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,8 +46,11 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
FullHttpRequest request = (FullHttpRequest) msg;
- JsonObject json = Json.createReader(new StringReader(URLDecoder.decode(
- request.content().toString(StandardCharsets.UTF_8).split("=")[0], "UTF-8"))).readObject();
+ String content = request.content().toString(StandardCharsets.UTF_8);
+ if (!content.startsWith("{")) {
+ content = URLDecoder.decode(content.split("=")[0], "UTF-8");
+ }
+ JsonObject json = Json.createReader(new StringReader(content)).readObject();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, json.getString("device"));
if (deviceSession == null) {
@@ -60,10 +63,11 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
position.setTime(new Date(json.getInt("time") * 1000L));
- ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(json.getString("data")));
+ String data = json.getString(json.containsKey("data") ? "data" : "payload");
+ ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(data));
try {
- int type = buf.readUnsignedByte() >> 4;
- if (type == 0) {
+ int event = buf.readUnsignedByte();
+ if ((event >> 4) == 0) {
position.setValid(true);
position.setLatitude(buf.readIntLE() * 0.0000001);
@@ -75,15 +79,59 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
} else {
- getLastLocation(position, position.getDeviceTime());
+ position.set(Position.KEY_EVENT, event);
+
+ 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:
+ buf.skipBytes(7); // wifi
+ 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();
}
- position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").doubleValue());
- position.set(Position.KEY_INDEX, json.getInt("seqNumber"));
+ if (json.containsKey("rssi")) {
+ position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").doubleValue());
+ }
+ if (json.containsKey("seqNumber")) {
+ position.set(Position.KEY_INDEX, json.getInt("seqNumber"));
+ }
sendResponse(channel, HttpResponseStatus.OK);
return position;
diff --git a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
index 48adb0ccb..b8ef735ce 100644
--- a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
@@ -12,6 +12,9 @@ public class SigfoxProtocolDecoderTest extends ProtocolTest {
SigfoxProtocolDecoder decoder = new SigfoxProtocolDecoder(null);
verifyPosition(decoder, request(HttpMethod.POST, "/",
+ buffer("{ \"device\": \"1CEDCE\", \"payload\": \"2002419b4a91c2c6580e0564\", \"time\": 1559924939, \"seqNumber\": 87 }")));
+
+ verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("%7B++%22device%22%3A%222BF839%22%2C++%22time%22%3A1510605882%2C++%22duplicate%22%3Afalse%2C++%22snr%22%3A45.61%2C++%22station%22%3A%2235A9%22%2C++%22data%22%3A%2200bd6475e907398e562d01b9%22%2C++%22avgSnr%22%3A45.16%2C++%22lat%22%3A-38.0%2C++%22lng%22%3A145.0%2C++%22rssi%22%3A-98.00%2C++%22seqNumber%22%3A228+%7D=")));
}