aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Gps103ProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-27 14:25:33 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-27 14:25:33 +1200
commitcf6440ef1ae4f68dc0cdcb1579f9347a938d8675 (patch)
tree9a1f95881492da97d195b677a8331cc76011a35a /src/org/traccar/protocol/Gps103ProtocolEncoder.java
parentba7c66163bc0d22a9c1939f2bb0f47e85cfffb9d (diff)
downloadtrackermap-server-cf6440ef1ae4f68dc0cdcb1579f9347a938d8675.tar.gz
trackermap-server-cf6440ef1ae4f68dc0cdcb1579f9347a938d8675.tar.bz2
trackermap-server-cf6440ef1ae4f68dc0cdcb1579f9347a938d8675.zip
Implement Suntech commands support
Diffstat (limited to 'src/org/traccar/protocol/Gps103ProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolEncoder.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java
index 5d0e0ddd1..9d8c3e9ba 100644
--- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java
@@ -15,37 +15,28 @@
*/
package org.traccar.protocol;
-import java.util.Map;
-import org.traccar.BaseProtocolEncoder;
+import org.traccar.StringProtocolEncoder;
import org.traccar.model.Command;
-public class Gps103ProtocolEncoder extends BaseProtocolEncoder {
+public class Gps103ProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
- private String formatCommand(Command command, String format, String... keys) {
-
- String result = String.format(format, (Object[]) keys);
-
- result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId()));
- for (Map.Entry<String, Object> entry : command.getOther().entrySet()) {
- String value;
- if (entry.getKey().equals(Command.KEY_FREQUENCY)) {
- long frequency = (Long) entry.getValue();
- if (frequency / 60 / 60 > 0) {
- value = String.format("%02dh", frequency / 60 / 60);
- } else if (frequency / 60 > 0) {
- value = String.format("%02dm", frequency / 60);
- } else {
- value = String.format("%02ds", frequency);
- }
+ @Override
+ public String formatValue(String key, Object value) {
+
+ if (key.equals(Command.KEY_FREQUENCY)) {
+ long frequency = (Long) value;
+ if (frequency / 60 / 60 > 0) {
+ return String.format("%02dh", frequency / 60 / 60);
+ } else if (frequency / 60 > 0) {
+ return String.format("%02dm", frequency / 60);
} else {
- value = entry.getValue().toString();
+ return String.format("%02ds", frequency);
}
- result = result.replaceAll("\\{" + entry.getKey() + "}", value);
}
-
- return result;
+
+ return null;
}
-
+
@Override
protected Object encodeCommand(Command command) {
@@ -53,7 +44,7 @@ public class Gps103ProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_STOP:
return formatCommand(command, "**,imei:{%s},A;", Command.KEY_UNIQUE_ID);
case Command.TYPE_POSITION_FIX:
- return formatCommand(command, "**,imei:{%s},C,{%s};", Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY);
+ return formatCommand(command, "**,imei:{%s},C,{%s};", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY);
case Command.TYPE_ENGINE_STOP:
return formatCommand(command, "**,imei:{%s},K;", Command.KEY_UNIQUE_ID);
case Command.TYPE_ENGINE_RESUME:
@@ -62,5 +53,5 @@ public class Gps103ProtocolEncoder extends BaseProtocolEncoder {
return null;
}
-
+
}