aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Menk <menk@mestrona.net>2016-12-19 14:53:16 +0100
committerAlexander Menk <menk@mestrona.net>2016-12-19 14:53:16 +0100
commit539c07c3fa942445adfbbdf7091cd46094ec1224 (patch)
treed933c52a137ce5a67143de425ae3140c017fe3e2
parentcdf1dfe387b6f682680746a770941d84f52ebd05 (diff)
downloadtraccar-server-539c07c3fa942445adfbbdf7091cd46094ec1224.tar.gz
traccar-server-539c07c3fa942445adfbbdf7091cd46094ec1224.tar.bz2
traccar-server-539c07c3fa942445adfbbdf7091cd46094ec1224.zip
#2702 [WIP] Implement SET_TIMEZONE for watch Protocol
Problem: Positive time zone needs to be + prepended, custom formatter does not seem to be called
-rw-r--r--src/org/traccar/protocol/WatchProtocol.java3
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java16
2 files changed, 17 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java
index 8b7d1ee9f..fb95957c8 100644
--- a/src/org/traccar/protocol/WatchProtocol.java
+++ b/src/org/traccar/protocol/WatchProtocol.java
@@ -41,7 +41,8 @@ public class WatchProtocol extends BaseProtocol {
Command.TYPE_SILENCE_TIME,
Command.TYPE_ALARM_CLOCK,
Command.TYPE_SET_PHONEBOOK,
- Command.TYPE_VOICE_MESSAGE
+ Command.TYPE_VOICE_MESSAGE,
+ Command.TYPE_SET_TIMEZONE
);
}
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index 41f189a89..3c71d7cac 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -24,7 +24,19 @@ import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
-public class WatchProtocolEncoder extends StringProtocolEncoder {
+public class WatchProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
+
+ @Override
+ public String formatValue(String key, Object value) {
+ if (key.equals(Command.KEY_TIMEZONE)) {
+ float offset = ((Number) value).longValue();
+ if (offset > 0) {
+ return "+" + String.format("%f", offset);
+ }
+ }
+
+ return null;
+ }
protected String formatCommand(Command command, String format, String... keys) {
String content = super.formatCommand(command, format, keys);
@@ -104,6 +116,8 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, "TK," + getBinaryData(command));
case Command.TYPE_POSITION_PERIODIC:
return formatCommand(command, "UPLOAD,{%s}", Command.KEY_FREQUENCY);
+ case Command.TYPE_SET_TIMEZONE:
+ return formatCommand(command, "LZ,0,{%s}", Command.KEY_TIMEZONE);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;