diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-10-26 17:05:46 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-10-26 17:05:46 -0700 |
commit | 3e36fcdb303f4c7af2df8e859f8fc6b1c7ba3fd0 (patch) | |
tree | e43ba14f871b0ad4249d7f3ad079f09b8c989686 /src/main/java/org/traccar/protocol/SuntechFrameDecoder.java | |
parent | 73c676e4faa3a8d71c9e8880417bd387eed20c7e (diff) | |
download | trackermap-server-3e36fcdb303f4c7af2df8e859f8fc6b1c7ba3fd0.tar.gz trackermap-server-3e36fcdb303f4c7af2df8e859f8fc6b1c7ba3fd0.tar.bz2 trackermap-server-3e36fcdb303f4c7af2df8e859f8fc6b1c7ba3fd0.zip |
Support binary Suntech protocol
Diffstat (limited to 'src/main/java/org/traccar/protocol/SuntechFrameDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/SuntechFrameDecoder.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechFrameDecoder.java b/src/main/java/org/traccar/protocol/SuntechFrameDecoder.java index de8de17f0..7b8337468 100644 --- a/src/main/java/org/traccar/protocol/SuntechFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/SuntechFrameDecoder.java @@ -32,13 +32,24 @@ public class SuntechFrameDecoder extends BaseFrameDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r'); - while (delimiterIndex > 0) { - if (delimiterIndex + 1 < buf.writerIndex() && buf.getByte(delimiterIndex + 1) == '\n') { - delimiterIndex = buf.indexOf(delimiterIndex + 1, buf.writerIndex(), (byte) '\r'); - } else { - return readFrame(buf, delimiterIndex); + if (buf.getByte(buf.readerIndex()) == (byte) 0x81) { + + int length = 1 + 2 + buf.getShort(buf.readerIndex() + 1); + if (buf.readableBytes() >= length) { + return buf.readRetainedSlice(length); } + + } else { + + int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r'); + while (delimiterIndex > 0) { + if (delimiterIndex + 1 < buf.writerIndex() && buf.getByte(delimiterIndex + 1) == '\n') { + delimiterIndex = buf.indexOf(delimiterIndex + 1, buf.writerIndex(), (byte) '\r'); + } else { + return readFrame(buf, delimiterIndex); + } + } + } return null; |