From 4acc359d664db81242f6c3a1a7a6dedcf2ab465a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 26 Oct 2015 12:27:41 +1300 Subject: Modify JT600 frame decoder --- src/org/traccar/protocol/Jt600FrameDecoder.java | 26 +++++++++---------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java index 8b8f4f642..22bbd5514 100644 --- a/src/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/org/traccar/protocol/Jt600FrameDecoder.java @@ -26,34 +26,26 @@ public class Jt600FrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - // Check minimum length - int available = buf.readableBytes(); - if (available < 10) { + if (buf.readableBytes() < 10) { return null; } - // Message identifier - char first = (char) buf.getByte(buf.readerIndex()); + char type = (char) buf.getByte(buf.readerIndex()); - if (first == '$') { - // Check length + if (type == '$') { int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10; - if (length >= available) { + if (length >= buf.readableBytes()) { return buf.readBytes(length); } - } else if (first == '(') { - // Find ending - Integer endIndex = ChannelBufferTools.find(buf, buf.readerIndex(), available, ")"); - if (endIndex != null) { + } else if (type == '(') { + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')'); + if (endIndex != -1) { return buf.readBytes(endIndex + 1); } } else { - // Unknown message - throw new ParseException(null, 0); + throw new ParseException(null, 0); // unknown message } return null; -- cgit v1.2.3