diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-13 09:41:37 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-13 09:41:37 +1300 |
commit | 0bbf4169c0b0ebd0cc5797d756350f7a7e57831a (patch) | |
tree | e3552808edc064c1d5b2dfb1adf06023c7d0b9fa /src/org/traccar | |
parent | 4e05ed1fe9a3de0ac16e4a03970a1b38a2bda318 (diff) | |
download | traccar-server-0bbf4169c0b0ebd0cc5797d756350f7a7e57831a.tar.gz traccar-server-0bbf4169c0b0ebd0cc5797d756350f7a7e57831a.tar.bz2 traccar-server-0bbf4169c0b0ebd0cc5797d756350f7a7e57831a.zip |
Add new format to Totem frame decoder
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/TotemFrameDecoder.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java index d6a456850..83c328173 100644 --- a/src/org/traccar/protocol/TotemFrameDecoder.java +++ b/src/org/traccar/protocol/TotemFrameDecoder.java @@ -39,7 +39,15 @@ public class TotemFrameDecoder extends FrameDecoder { buf.readerIndex(beginIndex); } - int length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, Charset.defaultCharset()), 16); + int length; + + int flagIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("AA")); + if (flagIndex != -1 && flagIndex - beginIndex == 6) { + length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 4, Charset.defaultCharset())); + } else { + length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, Charset.defaultCharset()), 16); + } + if (length <= buf.readableBytes()) { return buf.readBytes(length); } |