aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/WatchProtocolDecoder.java
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:33:47 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-02-17 01:33:47 +0200
commit2e130b374fed3edc10b448120be0db3e388bfb28 (patch)
treef23a1248f7c1fde3d147b785238e03eef83216cc /src/org/traccar/protocol/WatchProtocolDecoder.java
parent1e0e3a43894466246d6042ec71b9c01f63c58b13 (diff)
downloadtrackermap-server-2e130b374fed3edc10b448120be0db3e388bfb28.tar.gz
trackermap-server-2e130b374fed3edc10b448120be0db3e388bfb28.tar.bz2
trackermap-server-2e130b374fed3edc10b448120be0db3e388bfb28.zip
don't save response + decoder test
Diffstat (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 78b190030..bf4d99a49 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -17,6 +17,8 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
@@ -38,6 +40,8 @@ import java.util.regex.Pattern;
public class WatchProtocolDecoder extends BaseProtocolDecoder {
+ private static final Logger LOGGER = LoggerFactory.getLogger(WatchProtocolDecoder.class);
+
public WatchProtocolDecoder(Protocol protocol) {
super(protocol);
}
@@ -174,41 +178,45 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return manufacturer;
}
+ protected int nextIndexOf(ByteBuf buf, char delimiter) {
+ return buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) delimiter);
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ByteBuf buf = (ByteBuf) msg;
- buf.skipBytes(1); // header
+ buf.skipBytes(1); // '[' header
manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII);
- buf.skipBytes(1); // delimiter
+ buf.skipBytes(1); // '*' delimiter
- int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ int idIndex = nextIndexOf(buf, '*');
String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
- buf.skipBytes(1); // delimiter
+ buf.skipBytes(1); // '*' delimiter
String index = null;
- int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ int contentIndex = nextIndexOf(buf, '*');
if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
&& buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
- int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
+ int indexLength = nextIndexOf(buf, '*') - buf.readerIndex();
hasIndex = true;
index = buf.readSlice(indexLength).toString(StandardCharsets.US_ASCII);
- buf.skipBytes(1); // delimiter
+ buf.skipBytes(1); // '*' delimiter
}
buf.skipBytes(4); // length
- buf.skipBytes(1); // delimiter
+ buf.skipBytes(1); // '*' delimiter
- buf.writerIndex(buf.writerIndex() - 1); // ignore ending
+ buf.writerIndex(buf.writerIndex() - 1); // ']' ignore ending
- contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ contentIndex = nextIndexOf(buf, ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}
@@ -296,6 +304,14 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("TK")) {
+ if (buf.readableBytes() == 1) {
+ byte result = buf.readByte();
+ if (result != '1') {
+ LOGGER.error(type + "," + result);
+ }
+ return null;
+ }
+
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());