Skip to content

Commit

Permalink
Support LBS for OsmAnd protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 19, 2017
1 parent f9b7863 commit cfe0c06
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/org/traccar/protocol/OsmAndProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
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;
Expand Down Expand Up @@ -54,6 +57,8 @@ protected Object decode(
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()) {
Expand Down Expand Up @@ -97,6 +102,23 @@ protected Object decode(
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;
Expand Down Expand Up @@ -143,6 +165,14 @@ protected Object decode(
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;
Expand Down
3 changes: 3 additions & 0 deletions test/org/traccar/protocol/OsmAndProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public void testDecode() throws Exception {

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"));

Expand Down

0 comments on commit cfe0c06

Please sign in to comment.