diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-05-05 13:31:48 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-05-05 13:31:48 +1200 |
commit | 841965ba439654f76dcd7fc63efd70647f23f29f (patch) | |
tree | cd93ed140386487b946e884f702fb3be4d356f39 | |
parent | 4ce5dd893d3b95fc759fd1d0e0dbf09d0d559936 (diff) | |
download | trackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.tar.gz trackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.tar.bz2 trackermap-server-841965ba439654f76dcd7fc63efd70647f23f29f.zip |
Implement PT510 frame decoder workaround
-rw-r--r-- | src/org/traccar/protocol/Pt502FrameDecoder.java | 28 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt502FrameDecoderTest.java | 10 |
2 files changed, 18 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java index 200012965..ce20dff1f 100644 --- a/src/org/traccar/protocol/Pt502FrameDecoder.java +++ b/src/org/traccar/protocol/Pt502FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,25 +32,15 @@ public class Pt502FrameDecoder extends FrameDecoder { return null; } - if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf && buf.getUnsignedByte(buf.readerIndex() + 1) == 0xfb) { - - int length = buf.getShort(buf.readerIndex() + 3); - if (buf.readableBytes() >= length) { - buf.skipBytes(BINARY_HEADER); - ChannelBuffer result = buf.readBytes(length - BINARY_HEADER - 2); - buf.skipBytes(2); - return result; - } - - } else { - - int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\n'); - if (index != -1) { - ChannelBuffer result = buf.readBytes(index - 1); - buf.skipBytes(2); - return result; - } + if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) { + buf.skipBytes(BINARY_HEADER); + } + int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r'); + if (index != -1 && index + 1 < buf.writerIndex()) { + ChannelBuffer result = buf.readBytes(index - buf.readerIndex()); + buf.skipBytes(2); + return result; } return null; diff --git a/test/org/traccar/protocol/Pt502FrameDecoderTest.java b/test/org/traccar/protocol/Pt502FrameDecoderTest.java index 34fdf9bb9..44de2459d 100644 --- a/test/org/traccar/protocol/Pt502FrameDecoderTest.java +++ b/test/org/traccar/protocol/Pt502FrameDecoderTest.java @@ -14,8 +14,16 @@ public class Pt502FrameDecoderTest extends ProtocolTest { Pt502FrameDecoder decoder = new Pt502FrameDecoder(); Assert.assertEquals( + binary("244655533836353332383032363234333836342c3531302d56312e31322c4131312d56332e30"), + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "bffb192d00244655533836353332383032363234333836342c3531302d56312e31322c4131312d56332e300d0d"))); + + Assert.assertEquals( + binary("24504f532c3836353332383032363234333836342c3134343733352e3030302c412c313333322e373038332c4e2c3230342e363833312c452c302e302c3233302e30302c3032303531372c2c2c412f30303030302c31302f312c302f3233342f2f4646392f"), + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "24504f532c3836353332383032363234333836342c3134343733352e3030302c412c313333322e373038332c4e2c3230342e363833312c452c302e302c3233302e30302c3032303531372c2c2c412f30303030302c31302f312c302f3233342f2f4646392f0d0a"))); + + Assert.assertEquals( binary("24504f532c3335333435313030303136342c3038323430352e3030302c412c313235342e383530312c4e2c31303035312e363735322c452c302e30302c3233372e39392c3136303531332c2c2c412f303030302c302f302f35353030302f2f6137312f"), - decoder.decode(null, null, binary("24504f532c3335333435313030303136342c3038323430352e3030302c412c313235342e383530312c4e2c31303035312e363735322c452c302e30302c3233372e39392c3136303531332c2c2c412f303030302c302f302f35353030302f2f6137312f0d0a"))); + decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "24504f532c3335333435313030303136342c3038323430352e3030302c412c313235342e383530312c4e2c31303035312e363735322c452c302e30302c3233372e39392c3136303531332c2c2c412f303030302c302f302f35353030302f2f6137312f0d0a"))); Assert.assertEquals( binary("24504f532c3335333435313030303136342c3038323430352e3030302c412c313235342e383530312c4e2c31303035312e363735322c452c302e30302c3233372e39392c3136303531332c2c2c412f303030302c302f302f35353030302f2f6137312f"), |