diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-01-03 00:18:15 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-01-03 00:18:15 -0800 |
commit | 02c799327874a238e7d514a7f050695f53c2c06b (patch) | |
tree | 7fdc7511d4ee7ddadb7e4694a4e2068ca8efced0 | |
parent | 8a9dabb6b35f24bb26ecc1650b6bdfc3a25615d1 (diff) | |
download | trackermap-server-02c799327874a238e7d514a7f050695f53c2c06b.tar.gz trackermap-server-02c799327874a238e7d514a7f050695f53c2c06b.tar.bz2 trackermap-server-02c799327874a238e7d514a7f050695f53c2c06b.zip |
Implement generic response
-rw-r--r-- | src/main/java/org/traccar/protocol/H02ProtocolDecoder.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java index 47e5aede0..529643f6c 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -287,9 +288,15 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, SocketAddress remoteAddress, String id, String type) { if (channel != null && id != null) { - DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + String response; + DateFormat dateFormat = new SimpleDateFormat(type.equals("R12") ? "HHmmss" : "yyyyMMddHHmmss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - String response = String.format("*HQ,%s,V4,%s,%s#", id, type, dateFormat.format(new Date())); + String time = dateFormat.format(new Date()); + if (type.equals("R12")) { + response = String.format("*HQ,%s,%s,%s#", id, type, time); + } else { + response = String.format("*HQ,%s,V4,%s,%s#", id, type, time); + } channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } @@ -316,6 +323,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { if (parser.hasNext() && parser.next().equals("V1")) { sendResponse(channel, remoteAddress, id, "V1"); + } else if (Context.getConfig().getBoolean(getProtocolName() + ".ack")) { + sendResponse(channel, remoteAddress, id, "R12"); } DateBuilder dateBuilder = new DateBuilder(); |