aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/NavisFrameDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-01-31 23:08:47 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-01-31 23:08:47 -0800
commit89a5e5c75306b9676c1534b853ec9c09c49052ef (patch)
tree6b94e7da319126c1c074d641dbe661c6236551ae /src/org/traccar/protocol/NavisFrameDecoder.java
parent46d3fe1130fe6963a2e0480c6033cfc5d36514bf (diff)
downloadtrackermap-server-89a5e5c75306b9676c1534b853ec9c09c49052ef.tar.gz
trackermap-server-89a5e5c75306b9676c1534b853ec9c09c49052ef.tar.bz2
trackermap-server-89a5e5c75306b9676c1534b853ec9c09c49052ef.zip
Minor Navis cleanup
Diffstat (limited to 'src/org/traccar/protocol/NavisFrameDecoder.java')
-rw-r--r--src/org/traccar/protocol/NavisFrameDecoder.java40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/org/traccar/protocol/NavisFrameDecoder.java b/src/org/traccar/protocol/NavisFrameDecoder.java
index 0146243cd..8a0bb0b9a 100644
--- a/src/org/traccar/protocol/NavisFrameDecoder.java
+++ b/src/org/traccar/protocol/NavisFrameDecoder.java
@@ -18,39 +18,31 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.TooLongFrameException;
import java.nio.charset.StandardCharsets;
import org.traccar.BaseFrameDecoder;
import org.traccar.BasePipelineFactory;
public class NavisFrameDecoder extends BaseFrameDecoder {
- private int flexDataSize; // bytes
-
private static final int NTCB_HEADER_LENGTH = 16;
private static final int NTCB_LENGTH_OFFSET = 12;
private static final int FLEX_HEADER_LENGTH = 2;
- private static final int MAX_FRAME_LENGTH = 65551;
+
+ private int flexDataSize;
+
+ public void setFlexDataSize(int flexDataSize) {
+ this.flexDataSize = flexDataSize;
+ }
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
- // Check minimum length
- if (buf.readableBytes() < 1) {
- return null;
- }
-
- if (buf.readableBytes() > MAX_FRAME_LENGTH) {
- throw new TooLongFrameException();
- }
-
if (buf.getByte(buf.readerIndex()) == 0x7F) {
- // FLEX keep alive frame
- return buf.readRetainedSlice(1);
+ return buf.readRetainedSlice(1); // keep alive
}
- if (ctx != null) {
+ if (ctx != null && flexDataSize == 0) {
NavisProtocolDecoder protocolDecoder =
BasePipelineFactory.getHandler(ctx.pipeline(), NavisProtocolDecoder.class);
if (protocolDecoder != null) {
@@ -59,7 +51,7 @@ public class NavisFrameDecoder extends BaseFrameDecoder {
}
if (flexDataSize > 0) {
- // FLEX frame
+
if (buf.readableBytes() > FLEX_HEADER_LENGTH) {
int length = 0;
String type = buf.toString(buf.readerIndex(), 2, StandardCharsets.US_ASCII);
@@ -97,23 +89,21 @@ public class NavisFrameDecoder extends BaseFrameDecoder {
return buf.readRetainedSlice(buf.readableBytes());
}
}
+
} else {
- // NTCB frame
+
if (buf.readableBytes() < NTCB_HEADER_LENGTH) {
return null;
}
- int length = buf.getUnsignedShortLE(buf.readerIndex() + NTCB_LENGTH_OFFSET);
- if (buf.readableBytes() >= NTCB_HEADER_LENGTH + length) {
- return buf.readRetainedSlice(NTCB_HEADER_LENGTH + length);
+ int length = NTCB_HEADER_LENGTH + buf.getUnsignedShortLE(buf.readerIndex() + NTCB_LENGTH_OFFSET);
+ if (buf.readableBytes() >= length) {
+ return buf.readRetainedSlice(length);
}
+
}
return null;
}
- public void setFlexDataSize(int flexDataSize) {
- this.flexDataSize = flexDataSize;
- }
-
}