aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/H02FrameDecoder.java
diff options
context:
space:
mode:
authorRenaud Allard <renaud@allard.it>2016-10-20 08:31:57 +0200
committerRenaud Allard <renaud@allard.it>2016-10-20 08:31:57 +0200
commit1104c2738e19579c5865db5c030388e1e320f0b4 (patch)
treea6571455b6f5d88581c8034bd1059968d506ed01 /src/org/traccar/protocol/H02FrameDecoder.java
parent0d347cd7aac2ebfad01c1635f3893964be2e67ae (diff)
parent4f7356cc1c6962f46ca522246d5b63dc06a2d268 (diff)
downloadtrackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.gz
trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.bz2
trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.zip
Merge branch 'master' of https://github.com/tananaev/traccar
Diffstat (limited to 'src/org/traccar/protocol/H02FrameDecoder.java')
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java16
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);
+ }
+ }
}