From 4066c24ed1ba8749a1a682acb5b027401d0df70f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 14 Nov 2016 01:56:26 +1300 Subject: Another attempt to fix H02 frame decoder --- src/org/traccar/protocol/H02FrameDecoder.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index d461c9219..a22252a57 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -54,16 +54,18 @@ public class H02FrameDecoder extends FrameDecoder { } else if (marker == '$') { - if (messageLength > 0 && buf.readableBytes() >= messageLength) { - return buf.readBytes(messageLength); - } else if (buf.readableBytes() >= MESSAGE_SHORT) { - if (buf.getUnsignedByte(buf.readerIndex() + MESSAGE_SHORT - 1) == 0) { - return buf.readBytes(MESSAGE_SHORT); - } else if (buf.readableBytes() >= MESSAGE_LONG) { - return buf.readBytes(MESSAGE_LONG); + if (messageLength == 0) { + if (buf.readableBytes() == MESSAGE_LONG) { + messageLength = MESSAGE_LONG; + } else { + messageLength = MESSAGE_SHORT; } } + if (buf.readableBytes() >= messageLength) { + return buf.readBytes(messageLength); + } + } return null; -- cgit v1.2.3