aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index fe62874b5..6adcb34f2 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 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.
@@ -60,10 +60,15 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.expression("(.*)") // cell and wifi
.compile();
- private void sendResponse(Channel channel, String manufacturer, String id, String content) {
+ private void sendResponse(Channel channel, String manufacturer, String id, String index, String content) {
if (channel != null) {
- channel.write(String.format(
- "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
+ if (index != null) {
+ channel.write(String.format(
+ "[%s*%s*%s*%04x*%s]", manufacturer, id, index, content.length(), content));
+ } else {
+ channel.write(String.format(
+ "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
+ }
}
}
@@ -134,13 +139,22 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
String manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // delimiter
- String id = buf.readBytes(10).toString(StandardCharsets.US_ASCII);
+ int idLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ String id = buf.readBytes(idLength).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
buf.skipBytes(1); // delimiter
+
+ String index = null;
+ if (idLength > 10) {
+ int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ index = buf.readBytes(indexLength).toString(StandardCharsets.US_ASCII);
+ buf.skipBytes(1); // delimiter
+ }
+
buf.skipBytes(4); // length
buf.skipBytes(1); // delimiter
@@ -159,7 +173,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
if (type.equals("LK")) {
- sendResponse(channel, manufacturer, id, "LK");
+ sendResponse(channel, manufacturer, id, index, "LK");
if (buf.readable()) {
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
@@ -179,7 +193,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
|| type.equals("AL") || type.equals("WT")) {
if (type.equals("AL")) {
- sendResponse(channel, manufacturer, id, "AL");
+ sendResponse(channel, manufacturer, id, index, "AL");
}
Parser parser = new Parser(PATTERN_POSITION, buf.toString(StandardCharsets.US_ASCII));
@@ -217,7 +231,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("TKQ")) {
- sendResponse(channel, manufacturer, id, "TKQ");
+ sendResponse(channel, manufacturer, id, index, "TKQ");
} else if (type.equals("PULSE") || type.equals("heart")) {