From 8a866049c73636f6f25ff59550da8c5445e7c8fc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 30 Aug 2016 21:15:12 +1200 Subject: Improve Megastek frame decoder --- src/org/traccar/protocol/MegastekFrameDecoder.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java index ba2cc1d25..da77d95fd 100644 --- a/src/org/traccar/protocol/MegastekFrameDecoder.java +++ b/src/org/traccar/protocol/MegastekFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,16 @@ public class MegastekFrameDecoder extends FrameDecoder { return buf.readBytes(length); } } else { + while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') { + buf.skipBytes(1); + } int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + if (delimiter == -1) { + delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!'); + } if (delimiter != -1) { ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex()); - buf.skipBytes(2); + buf.skipBytes(1); return result; } } -- cgit v1.2.3