diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-12-21 22:40:55 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-21 22:40:55 +1300 |
commit | d8e016bc5fcb55f43fa0af676f977a99ebcb35b8 (patch) | |
tree | d70be97a1d2c4428b3483c94190dc7114da5de1c /src/org/traccar/protocol/WatchProtocolEncoder.java | |
parent | 48f83827701d06c3c2eab7d051a5f011cc42f65d (diff) | |
parent | c70c026d31ae673e06abb58333f4808db875f6a6 (diff) | |
download | trackermap-server-d8e016bc5fcb55f43fa0af676f977a99ebcb35b8.tar.gz trackermap-server-d8e016bc5fcb55f43fa0af676f977a99ebcb35b8.tar.bz2 trackermap-server-d8e016bc5fcb55f43fa0af676f977a99ebcb35b8.zip |
Merge pull request #2712 from AddisMap/feature/2702-watch-ext
Feature #2702 watch ext
Diffstat (limited to 'src/org/traccar/protocol/WatchProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolEncoder.java | 23 |
1 files changed, 21 insertions, 2 deletions
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; |