diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-20 16:32:24 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-20 16:32:24 +1300 |
commit | f64840b9e85d4869c92e9f20a2f5043522ad4008 (patch) | |
tree | f2cc0e4f7c893ebbc7313adaa3ea656b1c0ea7c8 /src/org/traccar/protocol/H02FrameDecoder.java | |
parent | 23e11715cc6f5e94002123293a1108a48044316e (diff) | |
download | trackermap-server-f64840b9e85d4869c92e9f20a2f5043522ad4008.tar.gz trackermap-server-f64840b9e85d4869c92e9f20a2f5043522ad4008.tar.bz2 trackermap-server-f64840b9e85d4869c92e9f20a2f5043522ad4008.zip |
Use heuristics for H02 message length
Diffstat (limited to 'src/org/traccar/protocol/H02FrameDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/H02FrameDecoder.java | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index feba8033d..2a005e760 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -22,6 +22,9 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class H02FrameDecoder extends FrameDecoder { + private static final int MESSAGE_SHORT = 32; + private static final int MESSAGE_LONG = 45; + private int messageLength; public H02FrameDecoder(int messageLength) { @@ -49,10 +52,17 @@ public class H02FrameDecoder extends FrameDecoder { return buf.readBytes(index + 1 - buf.readerIndex()); } - } else if (marker == '$' && buf.readableBytes() >= messageLength) { + } else if (marker == '$') { - // Return binary message - return buf.readBytes(messageLength); + 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); + } + } } |