diff options
author | Anton Tananaev <anton@traccar.org> | 2023-07-20 06:48:50 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2023-07-20 06:55:36 -0700 |
commit | 6631d7c4b3522e81af563e3ac82131a6e5c50b89 (patch) | |
tree | 84f34380fb407c5bc5d963eb524b604a5e601268 /src/main/java/org/traccar/protocol | |
parent | f1470e56708b66c805e63619209930e83116f4ea (diff) | |
download | trackermap-server-6631d7c4b3522e81af563e3ac82131a6e5c50b89.tar.gz trackermap-server-6631d7c4b3522e81af563e3ac82131a6e5c50b89.tar.bz2 trackermap-server-6631d7c4b3522e81af563e3ac82131a6e5c50b89.zip |
Improve RF-V48 frame decoding
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r-- | src/main/java/org/traccar/protocol/WatchFrameDecoder.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/WatchFrameDecoder.java b/src/main/java/org/traccar/protocol/WatchFrameDecoder.java index ec67aa34d..9dfae8726 100644 --- a/src/main/java/org/traccar/protocol/WatchFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchFrameDecoder.java @@ -27,9 +27,21 @@ public class WatchFrameDecoder extends BaseFrameDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { + int brackets = 0; int endIndex = -1; - for (int i = buf.writerIndex() - 1; i >= buf.readerIndex(); i--) { - if (buf.getByte(i) == ']') { + for (int i = buf.readerIndex(); i < buf.writerIndex(); i++) { + byte b = buf.getByte(i); + switch (b) { + case '[': + brackets += 1; + break; + case ']': + brackets -= 1; + break; + default: + break; + } + if (brackets == 0 && i > buf.readerIndex()) { endIndex = i + 1; break; } |