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 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol/WatchProtocol.java') 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 -- 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/org/traccar/protocol/WatchProtocol.java') 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 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/org/traccar/protocol/WatchProtocol.java') 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/org/traccar/protocol/WatchProtocol.java') 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/org/traccar/protocol/WatchProtocol.java') 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