aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-12-18 19:32:38 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-12-18 19:32:38 -0800
commit9403fd618339d0ba432794a162f90f22cdc2ebd4 (patch)
tree1b9e231311be36458cd7ef58d9d6cfc708f3e379 /src
parenteda05aa8e846b273c4cb30f77ebf3c4db48443ad (diff)
downloadtrackermap-server-9403fd618339d0ba432794a162f90f22cdc2ebd4.tar.gz
trackermap-server-9403fd618339d0ba432794a162f90f22cdc2ebd4.tar.bz2
trackermap-server-9403fd618339d0ba432794a162f90f22cdc2ebd4.zip
Implement protocol response
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
index 249915b39..9e04f0b02 100644
--- a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -19,8 +19,11 @@ 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;
+import org.traccar.config.Keys;
import org.traccar.helper.BcdUtil;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
@@ -30,6 +33,10 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
public class TzoneProtocolDecoder extends BaseProtocolDecoder {
@@ -37,6 +44,18 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, int index) {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+ String ack = String.format("@ACK,%d#", index);
+ String time = String.format("@UTC time:%s", dateFormat.format(new Date()));
+
+ if (channel != null) {
+ channel.writeAndFlush(new NetworkMessage(ack + time, remoteAddress));
+ }
+ }
+
private String decodeAlarm(Short value) {
switch (value) {
case 0x01:
@@ -348,6 +367,10 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
+ if (Context.getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
+ sendResponse(channel, remoteAddress, buf.getUnsignedShort(buf.writerIndex() - 6));
+ }
+
return position;
}