From 4ecca566c4faba5f526b92d5920f542a5b03cc95 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 5 Oct 2019 14:34:01 -0700 Subject: Fix frame decoding --- src/main/java/org/traccar/protocol/Jt600FrameDecoder.java | 2 +- src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java b/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java index b5d060ecc..bfefb94a7 100644 --- a/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java @@ -35,7 +35,7 @@ public class Jt600FrameDecoder extends BaseFrameDecoder { char type = (char) buf.getByte(buf.readerIndex()); if (type == '$') { - boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75; + boolean longFormat = Jt600ProtocolDecoder.isLongFormat(buf, buf.readerIndex() + 1); int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10; if (length <= buf.readableBytes()) { return buf.readRetainedSlice(length); diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java index 82abeb42e..f456cd1ef 100644 --- a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -86,13 +86,17 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { } + static boolean isLongFormat(ByteBuf buf, int flagIndex) { + return buf.getUnsignedByte(flagIndex) >> 4 == 0x7; + } + private List decodeBinary(ByteBuf buf, Channel channel, SocketAddress remoteAddress) { List positions = new LinkedList<>(); buf.readByte(); // header - boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) >> 4 == 0x7; + boolean longFormat = isLongFormat(buf, buf.readerIndex()); String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5)))); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); -- cgit v1.2.3