aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-07-15 23:40:56 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-07-15 23:40:56 -0700
commit398a3a71fef1d7610940a8118bcf9b13782c21f3 (patch)
tree74011eacae188aebee67be8e3f111e5bf3864604
parentf3f73941c17c0b1d351f65ad3f9924cf6f4fe049 (diff)
downloadtraccar-server-398a3a71fef1d7610940a8118bcf9b13782c21f3.tar.gz
traccar-server-398a3a71fef1d7610940a8118bcf9b13782c21f3.tar.bz2
traccar-server-398a3a71fef1d7610940a8118bcf9b13782c21f3.zip
Decode WiFi info
-rw-r--r--src/main/java/org/traccar/model/Network.java6
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java11
-rw-r--r--src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java3
3 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/model/Network.java b/src/main/java/org/traccar/model/Network.java
index 2d56950f1..4d67fc5d8 100644
--- a/src/main/java/org/traccar/model/Network.java
+++ b/src/main/java/org/traccar/model/Network.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 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.
@@ -30,6 +30,10 @@ public class Network {
addCellTower(cellTower);
}
+ public Network(WifiAccessPoint wifiAccessPoint) {
+ addWifiAccessPoint(wifiAccessPoint);
+ }
+
private Integer homeMobileCountryCode;
public Integer getHomeMobileCountryCode() {
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index e9a943e0e..0e0d8d608 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -16,6 +16,7 @@
package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.FullHttpRequest;
@@ -25,7 +26,9 @@ import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.helper.DataConverter;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Network;
import org.traccar.model.Position;
+import org.traccar.model.WifiAccessPoint;
import javax.json.Json;
import javax.json.JsonObject;
@@ -104,7 +107,9 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
break;
case 0x06:
- buf.skipBytes(7); // wifi
+ 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
@@ -126,6 +131,10 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
buf.release();
}
+ if (position.getLatitude() == 0 && position.getLongitude() == 0) {
+ getLastLocation(position, position.getDeviceTime());
+ }
+
if (json.containsKey("rssi")) {
position.set(Position.KEY_RSSI, json.getJsonNumber("rssi").doubleValue());
}
diff --git a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
index b8ef735ce..7e7fc24bc 100644
--- a/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/SigfoxProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class SigfoxProtocolDecoderTest extends ProtocolTest {
SigfoxProtocolDecoder decoder = new SigfoxProtocolDecoder(null);
+ verifyAttributes(decoder, request(HttpMethod.POST, "/",
+ buffer("{ \"device\": \"40D310\", \"payload\": \"20061494480389f956042a\", \"time\": 1563043532, \"seqNumber\": 1076 }")));
+
verifyPosition(decoder, request(HttpMethod.POST, "/",
buffer("{ \"device\": \"1CEDCE\", \"payload\": \"2002419b4a91c2c6580e0564\", \"time\": 1559924939, \"seqNumber\": 87 }")));