aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/ItsFrameDecoder.java36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/protocol/ItsFrameDecoder.java b/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
index 79b341760..eb2c59e91 100644
--- a/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/ItsFrameDecoder.java
@@ -19,30 +19,40 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.traccar.BaseFrameDecoder;
+import org.traccar.helper.BufferUtil;
public class ItsFrameDecoder extends BaseFrameDecoder {
+ private static final int MINIMUM_LENGTH = 20;
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
- int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
-
- if (buf.writerIndex() > delimiterIndex + 1 && buf.getByte(delimiterIndex + 1) == '*') {
- delimiterIndex += 1;
- }
-
ByteBuf frame;
- if (buf.getByte(delimiterIndex - 2) == ',') {
- frame = buf.readRetainedSlice(delimiterIndex - 1 - buf.readerIndex());
- buf.skipBytes(1); // binary checksum
- } else {
+ int delimiterIndex = BufferUtil.indexOf("\r\n", buf);;
+ if (delimiterIndex > MINIMUM_LENGTH) {
frame = buf.readRetainedSlice(delimiterIndex - buf.readerIndex());
+ buf.skipBytes(2);
+ return frame;
+ } else {
+ delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ if (delimiterIndex > MINIMUM_LENGTH) {
+ if (buf.writerIndex() > delimiterIndex + 1 && buf.getByte(delimiterIndex + 1) == '*') {
+ delimiterIndex += 1;
+ }
+ if (buf.getByte(delimiterIndex - 2) == ',') {
+ frame = buf.readRetainedSlice(delimiterIndex - 1 - buf.readerIndex());
+ buf.skipBytes(1); // binary checksum
+ } else {
+ frame = buf.readRetainedSlice(delimiterIndex - buf.readerIndex());
+ }
+ buf.skipBytes(1); // delimiter
+ return frame;
+ }
}
- buf.skipBytes(1); // delimiter
-
- return frame;
+ return null;
}
}