From 841965ba439654f76dcd7fc63efd70647f23f29f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 5 May 2017 13:31:48 +1200 Subject: Implement PT510 frame decoder workaround --- src/org/traccar/protocol/Pt502FrameDecoder.java | 28 ++++++++----------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/org/traccar') 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; -- cgit v1.2.3