aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-01-14 17:21:40 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-01-14 17:21:40 +1300
commite142f095923519d638e8f480cdd4eb2c12b23501 (patch)
tree87d7f6a24d38c12a5cfba129483ae8ca48bee049 /src/org/traccar
parent12ce5606c7f3a4d29202dc0666342ff944cf44aa (diff)
downloadtrackermap-server-e142f095923519d638e8f480cdd4eb2c12b23501.tar.gz
trackermap-server-e142f095923519d638e8f480cdd4eb2c12b23501.tar.bz2
trackermap-server-e142f095923519d638e8f480cdd4eb2c12b23501.zip
Support cell and wifi for Watch protocol
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 07df2de13..bb760b3a0 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 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.
@@ -18,11 +18,15 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
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.util.Date;
@@ -56,11 +60,13 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*),") // course
.number("(d+.?d*),") // altitude
.number("(d+),") // satellites
- .number("(d+),") // gsm
+ .number("(d+),") // rssi
.number("(d+),") // battery
.number("(d+),") // steps
.number("d+,") // tumbles
- .any()
+ .number("(x+),") // status
+ .expression("([^\\]]*)") // cell and wifi
+ .text("]").optional()
.compile();
private void sendResponse(Channel channel, String manufacturer, String id, String content) {
@@ -70,6 +76,57 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private String decodeAlarm(int status) {
+ if (BitUtil.check(status, 0)) {
+ return Position.ALARM_LOW_BATTERY;
+ } else if (BitUtil.check(status, 1)) {
+ return Position.ALARM_GEOFENCE_EXIT;
+ } else if (BitUtil.check(status, 2)) {
+ return Position.ALARM_GEOFENCE_ENTER;
+ } else if (BitUtil.check(status, 3)) {
+ return Position.ALARM_OVERSPEED;
+ } else if (BitUtil.check(status, 16)) {
+ return Position.ALARM_SOS;
+ } else if (BitUtil.check(status, 17)) {
+ return Position.ALARM_LOW_BATTERY;
+ } else if (BitUtil.check(status, 18)) {
+ return Position.ALARM_GEOFENCE_EXIT;
+ } else if (BitUtil.check(status, 19)) {
+ return Position.ALARM_GEOFENCE_ENTER;
+ }
+ return null;
+ }
+
+ private void decodeLbs(Position position, String data) {
+ String[] values = data.split(",");
+ int index = 0;
+
+ Network network = new Network();
+
+ int cellCount = Integer.parseInt(values[index++]);
+ index += 1; // timing advance
+ int mcc = Integer.parseInt(values[index++]);
+ int mnc = Integer.parseInt(values[index++]);
+
+ for (int i = 0; i < cellCount; i++) {
+ network.addCellTower(CellTower.from(mcc, mnc,
+ Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),
+ Integer.parseInt(values[index++])));
+ }
+
+ if (index < values.length && !values[index].isEmpty()) {
+ int wifiCount = Integer.parseInt(values[index++]);
+
+ for (int i = 0; i < wifiCount; i++) {
+ index += 1; // wifi name
+ network.addWifiAccessPoint(WifiAccessPoint.from(
+ values[index++], Integer.parseInt(values[index++])));
+ }
+ }
+
+ position.setNetwork(network);
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -141,6 +198,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
position.set("steps", parser.nextInt());
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt(16)));
+
+ decodeLbs(position, parser.next());
+
return position;
} else if (type.equals("TKQ")) {