From b84d627b57181907c73d2c4ebb46ed011be8cfab Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 14 Jun 2017 04:30:27 +1200 Subject: Fix Watch frame decoder --- src/org/traccar/protocol/WatchFrameDecoder.java | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java index 26aba68c7..826a8b4d0 100644 --- a/src/org/traccar/protocol/WatchFrameDecoder.java +++ b/src/org/traccar/protocol/WatchFrameDecoder.java @@ -36,7 +36,35 @@ public class WatchFrameDecoder extends FrameDecoder { buf.getBytes(buf.readerIndex() + MESSAGE_HEADER - 4 - 1, lengthBuffer, 4); int length = Integer.parseInt(lengthBuffer.toString(StandardCharsets.US_ASCII), 16) + MESSAGE_HEADER + 1; if (buf.readableBytes() >= length) { - return buf.readBytes(length); + ChannelBuffer frame = ChannelBuffers.dynamicBuffer(); + int endIndex = buf.readerIndex() + length; + while (buf.readerIndex() < endIndex) { + byte b = buf.readByte(); + if (b == 0x7D) { + switch (buf.readByte()) { + case 0x01: + frame.writeByte(0x7D); + break; + case 0x02: + frame.writeByte(0x5B); + break; + case 0x03: + frame.writeByte(0x5D); + break; + case 0x04: + frame.writeByte(0x2C); + break; + case 0x05: + frame.writeByte(0x2A); + break; + default: + throw new IllegalArgumentException(); + } + } else { + frame.writeByte(b); + } + } + return frame; } } -- cgit v1.2.3