aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-01 16:21:22 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-01 16:21:22 +1200
commitba7ae0c0b49b61805d21df6b64df9d013c396176 (patch)
tree60161e39c2b02058025d81ae9dc1b297830cee2f /src/org/traccar
parent74f3c9f2877da3dcfbc28c103d0e2c8904991cff (diff)
downloadtrackermap-server-ba7ae0c0b49b61805d21df6b64df9d013c396176.tar.gz
trackermap-server-ba7ae0c0b49b61805d21df6b64df9d013c396176.tar.bz2
trackermap-server-ba7ae0c0b49b61805d21df6b64df9d013c396176.zip
Implement H02 time sync response
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 2abde7d6f..64c45a22f 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -20,6 +20,7 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BcdUtil;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
@@ -31,7 +32,10 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.TimeZone;
import java.util.regex.Pattern;
public class H02ProtocolDecoder extends BaseProtocolDecoder {
@@ -156,7 +160,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.text("V4,")
.expression("(.*),") // response
.or()
- .expression("V[^,]*,")
+ .expression("(V[^,]*),")
.groupEnd()
.number("(?:(dd)(dd)(dd))?,") // time (hhmmss)
.groupEnd()
@@ -254,6 +258,15 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.text("#").optional()
.compile();
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, String id, String type) {
+ if (channel != null && id != null) {
+ DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String response = String.format("*HQ,%s,V4,%s,%s#", id, type, dateFormat.format(new Date()));
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
+ }
+ }
+
private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN, sentence);
@@ -261,7 +274,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ String id = parser.next();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
@@ -273,6 +287,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_RESULT, parser.next());
}
+ if (parser.hasNext() && parser.next().equals("V1")) {
+ sendResponse(channel, remoteAddress, id, "V1");
+ }
+
DateBuilder dateBuilder = new DateBuilder();
if (parser.hasNext(3)) {
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
@@ -341,11 +359,14 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ String id = parser.next();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
+ sendResponse(channel, remoteAddress, id, "NBR");
+
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());