diff options
-rw-r--r-- | src/org/traccar/protocol/AtrackProtocolDecoder.java | 27 | ||||
-rw-r--r-- | test/org/traccar/protocol/AtrackProtocolDecoderTest.java | 6 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 456ae7bee..3566631f0 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -195,6 +195,31 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { } } + private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + if (sentence.startsWith("$INFO")) { + + return null; + + } else { + + position.set(Position.KEY_RESULT, sentence); + + } + + return position; + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -206,6 +231,8 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { channel.write(buf, remoteAddress); // keep-alive message } return null; + } else if (buf.getByte(buf.readerIndex()) == '$') { + return decodeString(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim()); } buf.skipBytes(2); // prefix diff --git a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java index 93d8db09b..756c09cef 100644 --- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java @@ -40,6 +40,12 @@ public class AtrackProtocolDecoderTest extends ProtocolTest { verifyPositions(decoder, binary( "40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000000000000000")); + verifyAttributes(decoder, buffer( + "$OK\r\n")); + + verifyAttributes(decoder, buffer( + "$ERROR=101\r\n")); + } } |