aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 11:18:05 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 11:18:05 +1200
commitae5fe50416df190f5374d084526518a22096871e (patch)
tree80ad67bfdc5eb3dde63cf466f090fd9379f96752 /src/org/traccar/protocol/MiniFinderProtocolEncoder.java
parent726b69a642e7f4d7c54863fc7367b066f7217ad2 (diff)
downloadtrackermap-server-ae5fe50416df190f5374d084526518a22096871e.tar.gz
trackermap-server-ae5fe50416df190f5374d084526518a22096871e.tar.bz2
trackermap-server-ae5fe50416df190f5374d084526518a22096871e.zip
Add more MiniFinder commands
Diffstat (limited to 'src/org/traccar/protocol/MiniFinderProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolEncoder.java47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
index 4d1d5b576..c5210aa0b 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
@@ -19,33 +19,56 @@ import org.traccar.StringProtocolEncoder;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-public class MiniFinderProtocolEncoder extends StringProtocolEncoder {
+public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
- private int getEnabledFlag(Command command) {
- return (Boolean) command.getAttributes().get(Command.KEY_ENABLE) ? 1 : 0;
+ @Override
+ public String formatValue(String key, Object value) {
+
+ if (key.equals(Command.KEY_ENABLE)) {
+ return (Boolean) value ? "1" : "0";
+ } else if (key.equals(Command.KEY_TIMEZONE)) {
+ return String.format("%+03d", ((Number) value).longValue() / 3600);
+ } else if (key.equals(Command.KEY_INDEX)) {
+ switch (((Number) value).intValue()) {
+ case 0:
+ return "A";
+ case 1:
+ return "B";
+ case 2:
+ return "C";
+ default:
+ return null;
+ }
+ }
+
+ return null;
}
@Override
protected Object encodeCommand(Command command) {
+ initDevicePassword(command, "123456");
+
switch (command.getType()) {
case Command.TYPE_SET_TIMEZONE:
- return String.format("123456L%+03d",
- ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).longValue() / 3600);
+ return formatCommand(command, "{%s}L{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_TIMEZONE);
case Command.TYPE_VOICE_MONITORING:
- return String.format("123456L%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}P{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_ALARM_SPEED:
- return formatCommand(command, "123456J1{%s}", Command.KEY_DATA);
+ return formatCommand(command, "{%s}J1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
case Command.TYPE_ALARM_GEOFENCE:
- return formatCommand(command, "123456R1{%s}", Command.KEY_RADIUS);
+ return formatCommand(command, "{%s}R1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_RADIUS);
case Command.TYPE_SET_AGPS:
- return String.format("123456AGPS%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}AGPS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_ALARM_FALL:
- return String.format("123456F%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}F{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_MODE_POWER_SAVING:
- return String.format("123456SP%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}SP{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_MODE_DEEP_SLEEP:
- return String.format("123456DS%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}DS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
+ case Command.TYPE_SOS_NUMBER:
+ return formatCommand(command, "{%s}{%s}1,{%s}", this,
+ Command.KEY_DEVICE_PASSWORD, Command.KEY_INDEX, Command.KEY_PHONE);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
return null;