aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-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")) {