From 6202fdd44ece635f2b97386d1db82e0572e838c0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 3 Sep 2019 09:25:59 -0600 Subject: Add missing response --- .../protocol/RaceDynamicsProtocolDecoder.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/traccar/protocol/RaceDynamicsProtocolDecoder.java b/src/main/java/org/traccar/protocol/RaceDynamicsProtocolDecoder.java index 33b08115d..0261199a3 100644 --- a/src/main/java/org/traccar/protocol/RaceDynamicsProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/RaceDynamicsProtocolDecoder.java @@ -26,6 +26,7 @@ import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.regex.Pattern; @@ -73,6 +74,16 @@ public class RaceDynamicsProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String imei; + + private void sendResponse(Channel channel, SocketAddress remoteAddress, int type) { + if (channel != null) { + String response = String.format( + "$GPRMC,%1$d,%2$td%2$tm%2$ty,%2$tH%2$tM%2$tS,%3$s,\r\n", type, new Date(), imei); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -85,10 +96,9 @@ public class RaceDynamicsProtocolDecoder extends BaseProtocolDecoder { Parser parser = new Parser(PATTERN_LOGIN, sentence); if (parser.matches()) { - getDeviceSession(channel, remoteAddress, parser.next()); - if (channel != null) { - channel.writeAndFlush(new NetworkMessage(sentence + "\r\n", remoteAddress)); - } + imei = parser.next(); + getDeviceSession(channel, remoteAddress, imei); + sendResponse(channel, remoteAddress, type); } } else if (type == MSG_LOCATION) { @@ -131,6 +141,8 @@ public class RaceDynamicsProtocolDecoder extends BaseProtocolDecoder { } } + sendResponse(channel, remoteAddress, type); + return positions; } -- cgit v1.2.3