From cdf1dfe387b6f682680746a770941d84f52ebd05 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Mon, 19 Dec 2016 14:04:54 +0100 Subject: #2702 Implement POSITION_PERIODIC for watch Protocol --- src/org/traccar/protocol/WatchProtocol.java | 4 +++- src/org/traccar/protocol/WatchProtocolEncoder.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index b13fcfb11..8b7d1ee9f 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,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 + ); } @Override diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index 0b6a83ce9..41f189a89 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -102,6 +102,8 @@ 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); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3 From 539c07c3fa942445adfbbdf7091cd46094ec1224 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Mon, 19 Dec 2016 14:53:16 +0100 Subject: #2702 [WIP] Implement SET_TIMEZONE for watch Protocol Problem: Positive time zone needs to be + prepended, custom formatter does not seem to be called --- src/org/traccar/protocol/WatchProtocol.java | 3 ++- src/org/traccar/protocol/WatchProtocolEncoder.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') 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; -- cgit v1.2.3 From 2c8187fbef2838d90dd39e7636a7f30a6ac3e343 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Mon, 19 Dec 2016 21:27:16 +0100 Subject: #2702 [WIP] Implement SET_TIMEZONE for watch Protocol - Remove value formatter + not needed anyways, I was experiencing some bug in the watch --- src/org/traccar/protocol/WatchProtocolEncoder.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index 3c71d7cac..a84cf9ef0 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -24,19 +24,7 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; -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; - } +public class WatchProtocolEncoder extends StringProtocolEncoder { protected String formatCommand(Command command, String format, String... keys) { String content = super.formatCommand(command, format, keys); @@ -117,7 +105,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin 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); + return formatCommand(command, "LZ,,{%s}", Command.KEY_TIMEZONE); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3 From 884f0d60bb31b063fdac35d91dcd51fe3987f9be Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Tue, 20 Dec 2016 08:41:59 +0100 Subject: #2702Implement setHearts for watch Protocol Using this function you can display a certain amount of hearts on the watch. Nothing more, nothing less. --- src/org/traccar/model/Command.java | 2 ++ src/org/traccar/protocol/WatchProtocol.java | 3 ++- src/org/traccar/protocol/WatchProtocolEncoder.java | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 51a61b966..2d4a4458b 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_HEARTS = "setHearts"; public static final String TYPE_MODE_POWER_SAVING = "modePowerSaving"; public static final String TYPE_MODE_DEEP_SLEEP = "modeDeepSleep"; @@ -63,5 +64,6 @@ public class Command extends Message { public static final String KEY_DATA = "data"; public static final String KEY_INDEX = "index"; public static final String KEY_PHONE = "phone"; + public static final String KEY_HEARTS = "hearts"; } diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index fb95957c8..57ccf7043 100644 --- a/src/org/traccar/protocol/WatchProtocol.java +++ b/src/org/traccar/protocol/WatchProtocol.java @@ -42,7 +42,8 @@ public class WatchProtocol extends BaseProtocol { Command.TYPE_ALARM_CLOCK, Command.TYPE_SET_PHONEBOOK, Command.TYPE_VOICE_MESSAGE, - Command.TYPE_SET_TIMEZONE + Command.TYPE_SET_TIMEZONE, + Command.TYPE_SET_HEARTS ); } diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index a84cf9ef0..aa7db6a32 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -106,6 +106,8 @@ public class WatchProtocolEncoder extends StringProtocolEncoder { 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_HEARTS: + return formatCommand(command, "FLOWER,{%s}", Command.KEY_HEARTS); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3 From 7cdf0851113b68d378a3ffca777507d7515aafce Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Tue, 20 Dec 2016 11:00:21 +0100 Subject: #2702 Rename "Hearts" function to "Indicator" to be more general --- src/org/traccar/model/Command.java | 3 +-- src/org/traccar/protocol/WatchProtocol.java | 2 +- src/org/traccar/protocol/WatchProtocolEncoder.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 2d4a4458b..da73af1bb 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -41,7 +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_HEARTS = "setHearts"; + 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"; @@ -64,6 +64,5 @@ public class Command extends Message { public static final String KEY_DATA = "data"; public static final String KEY_INDEX = "index"; public static final String KEY_PHONE = "phone"; - public static final String KEY_HEARTS = "hearts"; } diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index 57ccf7043..0dc910d8c 100644 --- a/src/org/traccar/protocol/WatchProtocol.java +++ b/src/org/traccar/protocol/WatchProtocol.java @@ -43,7 +43,7 @@ public class WatchProtocol extends BaseProtocol { Command.TYPE_SET_PHONEBOOK, Command.TYPE_VOICE_MESSAGE, Command.TYPE_SET_TIMEZONE, - Command.TYPE_SET_HEARTS + Command.TYPE_SET_INDICATOR ); } diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index aa7db6a32..7c96c8a83 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -106,8 +106,8 @@ public class WatchProtocolEncoder extends StringProtocolEncoder { 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_HEARTS: - return formatCommand(command, "FLOWER,{%s}", Command.KEY_HEARTS); + case Command.TYPE_SET_INDICATOR: + return formatCommand(command, "FLOWER,{%s}", Command.KEY_DATA); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3 From fd4422aa07017e467925a06608a412d15c2a08a4 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Tue, 20 Dec 2016 11:10:49 +0100 Subject: #2702 CodeStyle Fix --- src/org/traccar/protocol/WatchProtocol.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java index 0dc910d8c..abce3d16a 100644 --- a/src/org/traccar/protocol/WatchProtocol.java +++ b/src/org/traccar/protocol/WatchProtocol.java @@ -43,8 +43,7 @@ public class WatchProtocol extends BaseProtocol { Command.TYPE_SET_PHONEBOOK, Command.TYPE_VOICE_MESSAGE, Command.TYPE_SET_TIMEZONE, - Command.TYPE_SET_INDICATOR - ); + Command.TYPE_SET_INDICATOR); } @Override -- cgit v1.2.3 From e0f8ae0ef6a2dbaa973e23650e347cbcf77b387a Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Tue, 20 Dec 2016 12:47:19 +0100 Subject: #2702 SetTimezone: Conversion to Seconds, Formating improvement (+ sign) --- src/org/traccar/protocol/WatchProtocolEncoder.java | 17 +++++++++++++++-- test/org/traccar/protocol/WatchProtocolEncoderTest.java | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index 7c96c8a83..7c353e26d 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() / 60.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); } diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java index 4e707a47b..eaf290216 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); + Assert.assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(command)); + + command.set(Command.KEY_TIMEZONE, 90); + Assert.assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(command)); + + command.set(Command.KEY_TIMEZONE, -60); + Assert.assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(command)); + + command.set(Command.KEY_TIMEZONE, -11 * 60 - 30); + Assert.assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(command)); } } -- cgit v1.2.3 From c70c026d31ae673e06abb58333f4808db875f6a6 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Wed, 21 Dec 2016 09:45:02 +0100 Subject: #2702 SetTimezone: Really - Conversion to Seconds NOT Minutes --- src/org/traccar/protocol/WatchProtocolEncoder.java | 2 +- test/org/traccar/protocol/WatchProtocolEncoderTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java index 7c353e26d..f394034d3 100644 --- a/src/org/traccar/protocol/WatchProtocolEncoder.java +++ b/src/org/traccar/protocol/WatchProtocolEncoder.java @@ -30,7 +30,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin @Override public String formatValue(String key, Object value) { if (key.equals(Command.KEY_TIMEZONE)) { - double offset = ((Number) value).longValue() / 60.0; + double offset = ((Number) value).longValue() / 3600.0; DecimalFormat fmt = new DecimalFormat("+#.##;-#.##"); return fmt.format(offset); } diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java index eaf290216..a7c360d7f 100644 --- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java +++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java @@ -35,16 +35,16 @@ public class WatchProtocolEncoderTest extends ProtocolTest { command = new Command(); command.setDeviceId(1); command.setType(Command.TYPE_SET_TIMEZONE); - command.set(Command.KEY_TIMEZONE, 60); + command.set(Command.KEY_TIMEZONE, 60 * 60); Assert.assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(command)); - command.set(Command.KEY_TIMEZONE, 90); + command.set(Command.KEY_TIMEZONE, 90 * 60); Assert.assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(command)); - command.set(Command.KEY_TIMEZONE, -60); + command.set(Command.KEY_TIMEZONE, -60 * 60); Assert.assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(command)); - command.set(Command.KEY_TIMEZONE, -11 * 60 - 30); + command.set(Command.KEY_TIMEZONE, -11 * 60 * 60 - 30 * 60); Assert.assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(command)); } -- cgit v1.2.3