From cfe0c06a2b067fd2c80275a79c80f3e222fe6006 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Dec 2017 06:58:50 +1300 Subject: Support LBS for OsmAnd protocol --- .../traccar/protocol/OsmAndProtocolDecoder.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/org/traccar') 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> 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; -- cgit v1.2.3