aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-05-05 13:31:48 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-05-05 13:31:48 +1200
commit841965ba439654f76dcd7fc63efd70647f23f29f (patch)
treecd93ed140386487b946e884f702fb3be4d356f39 /src/org/traccar/protocol
parent4ce5dd893d3b95fc759fd1d0e0dbf09d0d559936 (diff)
downloadtrackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.tar.gz
trackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.tar.bz2
trackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.zip
Implement PT510 frame decoder workaround
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/Pt502FrameDecoder.java28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java
index 200012965..ce20dff1f 100644
--- a/src/org/traccar/protocol/Pt502FrameDecoder.java
+++ b/src/org/traccar/protocol/Pt502FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,25 +32,15 @@ public class Pt502FrameDecoder extends FrameDecoder {
return null;
}
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf && buf.getUnsignedByte(buf.readerIndex() + 1) == 0xfb) {
-
- int length = buf.getShort(buf.readerIndex() + 3);
- if (buf.readableBytes() >= length) {
- buf.skipBytes(BINARY_HEADER);
- ChannelBuffer result = buf.readBytes(length - BINARY_HEADER - 2);
- buf.skipBytes(2);
- return result;
- }
-
- } else {
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\n');
- if (index != -1) {
- ChannelBuffer result = buf.readBytes(index - 1);
- buf.skipBytes(2);
- return result;
- }
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
+ buf.skipBytes(BINARY_HEADER);
+ }
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
+ if (index != -1 && index + 1 < buf.writerIndex()) {
+ ChannelBuffer result = buf.readBytes(index - buf.readerIndex());
+ buf.skipBytes(2);
+ return result;
}
return null;