aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java30
-rw-r--r--test/org/traccar/protocol/OsmAndProtocolDecoderTest.java3
2 files changed, 33 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 68c143257..9aaef9051 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -22,7 +22,10 @@ import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.joda.time.format.ISODateTimeFormat;
import org.traccar.BaseHttpProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
+import org.traccar.model.WifiAccessPoint;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
@@ -54,6 +57,8 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
position.setProtocol(getProtocolName());
position.setValid(true);
+ Network network = new Network();
+
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
String value = entry.getValue().get(0);
switch (entry.getKey()) {
@@ -97,6 +102,23 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
position.setLatitude(Double.parseDouble(location[0]));
position.setLongitude(Double.parseDouble(location[1]));
break;
+ case "cell":
+ String[] cell = value.split(",");
+ if (cell.length > 4) {
+ network.addCellTower(CellTower.from(
+ Integer.parseInt(cell[0]), Integer.parseInt(cell[1]),
+ Integer.parseInt(cell[2]), Integer.parseInt(cell[3]), Integer.parseInt(cell[4])));
+ } else {
+ network.addCellTower(CellTower.from(
+ Integer.parseInt(cell[0]), Integer.parseInt(cell[1]),
+ Integer.parseInt(cell[2]), Integer.parseInt(cell[3])));
+ }
+ break;
+ case "wifi":
+ String[] wifi = value.split(",");
+ network.addWifiAccessPoint(WifiAccessPoint.from(
+ wifi[0].replace('-', ':'), Integer.parseInt(wifi[1])));
+ break;
case "speed":
position.setSpeed(convertSpeed(Double.parseDouble(value), "kn"));
break;
@@ -143,6 +165,14 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
position.setTime(new Date());
}
+ if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
+ position.setNetwork(network);
+ }
+
+ if (position.getLatitude() == 0 && position.getLongitude() == 0) {
+ getLastLocation(position, position.getDeviceTime());
+ }
+
if (position.getDeviceId() != 0) {
sendResponse(channel, HttpResponseStatus.OK);
return position;
diff --git a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
index af860f371..da7aef6ea 100644
--- a/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class OsmAndProtocolDecoderTest extends ProtocolTest {
OsmAndProtocolDecoder decoder = new OsmAndProtocolDecoder(new OsmAndProtocol());
+ verifyNotNull(decoder, request(
+ "/?id=123456&timestamp=1377177267&cell=257,02,16,2224&cell=257,02,16,2223,-90&wifi=00-14-22-01-23-45,-80&wifi=00-1C-B3-09-85-15,-70"));
+
verifyNull(decoder, request(
"/?timestamp=1377177267&lat=60.0&lon=30.0"));