From 6ded2f7b1fc1e6593512f3b2b24400a90991aa89 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 17 Jun 2017 12:13:17 +1200 Subject: Implement Atrack command response --- .../traccar/protocol/AtrackProtocolDecoder.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/org') 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 -- cgit v1.2.3