aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/model/Command.java1
-rw-r--r--src/org/traccar/protocol/WatchProtocol.java5
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java23
-rw-r--r--test/org/traccar/protocol/WatchProtocolEncoderTest.java14
4 files changed, 40 insertions, 3 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index 51a61b966..da73af1bb 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -41,6 +41,7 @@ public class Command extends Message {
public static final String TYPE_OUTPUT_CONTROL = "outputControl";
public static final String TYPE_VOICE_MONITORING = "voiceMonitoring";
public static final String TYPE_SET_AGPS = "setAgps";
+ public static final String TYPE_SET_INDICATOR = "setIndicator";
public static final String TYPE_MODE_POWER_SAVING = "modePowerSaving";
public static final String TYPE_MODE_DEEP_SLEEP = "modeDeepSleep";
diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java
index b13fcfb11..abce3d16a 100644
--- a/src/org/traccar/protocol/WatchProtocol.java
+++ b/src/org/traccar/protocol/WatchProtocol.java
@@ -32,6 +32,7 @@ public class WatchProtocol extends BaseProtocol {
super("watch");
setSupportedCommands(
Command.TYPE_POSITION_SINGLE,
+ Command.TYPE_POSITION_PERIODIC,
Command.TYPE_SOS_NUMBER,
Command.TYPE_ALARM_SOS,
Command.TYPE_ALARM_BATTERY,
@@ -40,7 +41,9 @@ 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,
+ Command.TYPE_SET_INDICATOR);
}
@Override
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index 0b6a83ce9..f394034d3 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -21,13 +21,26 @@ import org.traccar.model.Command;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
+import java.text.DecimalFormat;
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)) {
+ double offset = ((Number) value).longValue() / 3600.0;
+ DecimalFormat fmt = new DecimalFormat("+#.##;-#.##");
+ return fmt.format(offset);
+ }
+
+ return null;
+ }
+
protected String formatCommand(Command command, String format, String... keys) {
- String content = super.formatCommand(command, format, keys);
+ String content = super.formatCommand(command, format, this, keys);
return String.format("[CS*%s*%04x*%s]",
getUniqueId(command.getDeviceId()), content.length(), content);
}
@@ -102,6 +115,12 @@ public class WatchProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, "PHB,{%s}", Command.KEY_DATA);
case Command.TYPE_VOICE_MESSAGE:
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,,{%s}", Command.KEY_TIMEZONE);
+ case Command.TYPE_SET_INDICATOR:
+ return formatCommand(command, "FLOWER,{%s}", Command.KEY_DATA);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
index 4e707a47b..a7c360d7f 100644
--- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
@@ -32,6 +32,20 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_DATA, "3333");
Assert.assertEquals("[CS*123456789012345*0005*TK,33]", encoder.encodeCommand(command));
+ command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SET_TIMEZONE);
+ command.set(Command.KEY_TIMEZONE, 60 * 60);
+ Assert.assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(command));
+
+ command.set(Command.KEY_TIMEZONE, 90 * 60);
+ Assert.assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(command));
+
+ command.set(Command.KEY_TIMEZONE, -60 * 60);
+ Assert.assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(command));
+
+ command.set(Command.KEY_TIMEZONE, -11 * 60 * 60 - 30 * 60);
+ Assert.assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(command));
}
}