From cff01fd43198ce786981dd8a51061dd0d415ccfd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 29 Sep 2017 19:17:55 +1300 Subject: Improve GT06 frame decoder --- src/org/traccar/protocol/Gt06FrameDecoder.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java index f35af6572..9b93979e4 100644 --- a/src/org/traccar/protocol/Gt06FrameDecoder.java +++ b/src/org/traccar/protocol/Gt06FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2016 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. @@ -26,7 +26,6 @@ public class Gt06FrameDecoder extends FrameDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - // Check minimum length if (buf.readableBytes() < 5) { return null; } @@ -35,19 +34,19 @@ public class Gt06FrameDecoder extends FrameDecoder { if (buf.getByte(buf.readerIndex()) == 0x78) { length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2); - - int type = buf.getUnsignedByte(buf.readerIndex() + 3); - if (type == Gt06ProtocolDecoder.MSG_STATUS && length == 13) { - length += 2; // workaround for #1727 - } - } else { length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2); } - // Check length and return buffer if (buf.readableBytes() >= length) { - return buf.readBytes(length); + if (buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) { + return buf.readBytes(length); + } else { + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x0d); + if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) { + return buf.readBytes(endIndex + 2 - buf.readerIndex()); + } + } } return null; -- cgit v1.2.3