aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-12-31 10:49:08 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2018-12-31 10:49:08 -0800
commitb8353006ba89aa67eefc6c06f423812d9c06432a (patch)
treec928fd470f57debef0a173b8ba23bc85880dd4f1
parentff6a7b59b84dbb648f35e08f013f8852060e321d (diff)
downloadtraccar-server-b8353006ba89aa67eefc6c06f423812d9c06432a.tar.gz
traccar-server-b8353006ba89aa67eefc6c06f423812d9c06432a.tar.bz2
traccar-server-b8353006ba89aa67eefc6c06f423812d9c06432a.zip
Decode additional Wristband data
-rw-r--r--src/org/traccar/protocol/WristbandProtocolDecoder.java61
-rw-r--r--test/org/traccar/protocol/WristbandProtocolDecoderTest.java11
2 files changed, 68 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/WristbandProtocolDecoder.java b/src/org/traccar/protocol/WristbandProtocolDecoder.java
index b93bbcfd1..7f2b0af85 100644
--- a/src/org/traccar/protocol/WristbandProtocolDecoder.java
+++ b/src/org/traccar/protocol/WristbandProtocolDecoder.java
@@ -25,7 +25,10 @@ import org.traccar.Protocol;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
+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;
@@ -91,6 +94,50 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeStatus(DeviceSession deviceSession, String sentence) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(sentence.split(",")[0]));
+
+ return position;
+ }
+
+ private Position decodeNetwork(DeviceSession deviceSession, String sentence, boolean wifi) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ Network network = new Network();
+ String[] fragments = sentence.split("\\|");
+
+ if (wifi) {
+ for (String item : fragments[0].split("_")) {
+ String[] values = item.split(",");
+ network.addWifiAccessPoint(WifiAccessPoint.from(values[0], Integer.parseInt(values[1])));
+ }
+ }
+
+ for (String item : fragments[wifi ? 1 : 0].split(":")) {
+ String[] values = item.split(",");
+ int lac = Integer.parseInt(values[0]);
+ int mnc = Integer.parseInt(values[1]);
+ int mcc = Integer.parseInt(values[2]);
+ int cid = Integer.parseInt(values[3]);
+ int rssi = Integer.parseInt(values[4]);
+ network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi));
+ }
+
+ position.setNetwork(network);
+
+ return position;
+ }
+
private List<Position> decodeMessage(
Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
@@ -109,6 +156,7 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
int type = parser.nextInt();
List<Position> positions = new LinkedList<>();
+ String data = parser.next();
switch (type) {
case 90:
@@ -119,14 +167,21 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, imei, version, type, time + "|" + getServer(channel, ','));
break;
case 1:
- case 64:
- sendResponse(channel, imei, version, type, "1");
+ positions.add(decodeStatus(deviceSession, data));
+ sendResponse(channel, imei, version, type, data.split(",")[1]);
break;
case 2:
- for (String fragment : parser.next().split("\\|")) {
+ for (String fragment : data.split("\\|")) {
positions.add(decodePosition(deviceSession, fragment));
}
break;
+ case 3:
+ case 4:
+ positions.add(decodeNetwork(deviceSession, data, type == 3));
+ break;
+ case 64:
+ sendResponse(channel, imei, version, type, data);
+ break;
default:
break;
}
diff --git a/test/org/traccar/protocol/WristbandProtocolDecoderTest.java b/test/org/traccar/protocol/WristbandProtocolDecoderTest.java
index 1c094d075..5635ce3d4 100644
--- a/test/org/traccar/protocol/WristbandProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WristbandProtocolDecoderTest.java
@@ -10,6 +10,15 @@ public class WristbandProtocolDecoderTest extends ProtocolTest {
WristbandProtocolDecoder decoder = new WristbandProtocolDecoder(null);
+ verifyNotNull(decoder, binary(
+ "000102004459583836383730343034343735303035357c56312e307c317c7b4630342331382c30372c332c3539303139322c33303a31382c30372c332c3539303139322c33307d0d0afffefc"));
+
+ verifyNotNull(decoder, binary(
+ "000102009c59583836383730343034343735303035357c56312e307c317c7b4630332330383a30353a38313a64383a31383a38372c2d37365f30303a37663a32383a63373a62613a63312c2d37375f39633a33643a63663a65643a62643a36622c2d36335f64383a65623a39373a65653a37373a32342c2d38327c31382c30372c332c3539303735342c33303a31382c30372c332c3539303735342c33307d0d0afffefc"));
+
+ verifyNull(decoder, binary(
+ "000102002259583836383730343034343735303035357c56312e307c307c7b46363423317d0d0afffefc"));
+
verifyPositions(decoder, binary(
"00010200bc59583836383730343034343735303035357c56312e307c317c7b4630322337372e3437373831372c2d33382e3839363239322c3230313831323239313235352c302e35387c37372e3437373739362c2d33382e3839363234352c3230313831323239313235352c302e30307c37372e3437373738392c2d33382e3839363233322c3230313831323239313235352c302e30307c37372e3437373737362c2d33382e3839363232322c3230313831323239313235352c302e30307d0d0afffefc"));
@@ -19,7 +28,7 @@ public class WristbandProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"000102004159583336373535313631303030303934347c56312e307c317c7b4639312330317c30307c30307c33475f7065745f323031382f30352f31362031313a30307d0d0afffefc"));
- verifyNull(decoder, binary(
+ verifyPositions(decoder, false, binary(
"000102003559583836383730343034343735303035357c56312e307c317c7b4630312339342c312c3130302c302c33313030302c3930307d0d0afffefc"));
}