aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/L100FrameDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/L100FrameDecoder.java')
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
index 98c2f9768..c8a520772 100644
--- a/src/org/traccar/protocol/L100FrameDecoder.java
+++ b/src/org/traccar/protocol/L100FrameDecoder.java
@@ -26,22 +26,32 @@ public class L100FrameDecoder extends FrameDecoder {
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
- if (buf.readableBytes() < 80) {
+ if (buf.readableBytes() < 10) {
return null;
}
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
- if (index == -1) {
- index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
+ int header = buf.getByte(buf.readerIndex());
+ boolean obd = header == 'L' || header == 'H';
+
+ int index;
+ if (obd) {
+ index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ } else {
+ index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
if (index == -1) {
- return null;
+ index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
+ if (index == -1) {
+ return null;
+ }
}
}
index += 2; // checksum
- if (buf.readableBytes() >= index - buf.readerIndex()) {
- buf.skipBytes(2); // header
+ if (buf.writerIndex() >= index) {
+ if (!obd) {
+ buf.skipBytes(2); // header
+ }
ChannelBuffer frame = buf.readBytes(index - buf.readerIndex() - 2);
buf.skipBytes(2); // footer
return frame;