From 6631d7c4b3522e81af563e3ac82131a6e5c50b89 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 20 Jul 2023 06:48:50 -0700 Subject: Improve RF-V48 frame decoding --- .../java/org/traccar/protocol/WatchFrameDecoder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/main/java/org') 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; } -- cgit v1.2.3