aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMatjaž Črnko <m.crnko@txt.si>2022-01-04 22:09:43 +0100
committerMatjaž Črnko <m.crnko@txt.si>2022-01-04 22:09:43 +0100
commitc21626223cd0c480725d8057a2cd4bf2b9d7e0b3 (patch)
tree7d432d6387c0dd1d0a6da88b35f84e635dc8642d /src/main
parent1a32d6b9b7253716d5927200db12d287b134ee26 (diff)
downloadtrackermap-server-c21626223cd0c480725d8057a2cd4bf2b9d7e0b3.tar.gz
trackermap-server-c21626223cd0c480725d8057a2cd4bf2b9d7e0b3.tar.bz2
trackermap-server-c21626223cd0c480725d8057a2cd4bf2b9d7e0b3.zip
fix: Totem - refactor formatContent so that it does not use non-static formatCommand function anymore.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/TotemProtocolEncoder.java21
-rw-r--r--src/main/java/org/traccar/protocol/TotemProtocolSmsEncoder.java5
2 files changed, 15 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
index ee1d1ede7..6792d61a5 100644
--- a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
@@ -27,23 +27,26 @@ public class TotemProtocolEncoder extends StringProtocolEncoder {
super(protocol);
}
- protected String getCommandString(Command command) {
+ public static String formatContent(Command command) {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return formatCommand(command, "%s,%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
+ return String.format("%s,%s",
+ command.getAttributes().get(Command.KEY_DEVICE_PASSWORD),
+ command.getAttributes().get(Command.KEY_DATA)
+ );
case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "%s,006", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,006", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
case Command.TYPE_FACTORY_RESET:
- return formatCommand(command, "%s,007", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,007", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
case Command.TYPE_GET_VERSION:
- return formatCommand(command, "%s,056", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,056", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "%s,012", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,012", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
// Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8
case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "%s,025,C,1", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,025,C,1", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "%s,025,C,0", Command.KEY_DEVICE_PASSWORD);
+ return String.format("%s,025,C,0", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
default:
return null;
}
@@ -54,7 +57,7 @@ public class TotemProtocolEncoder extends StringProtocolEncoder {
initDevicePassword(command, "000000");
- String commandString = getCommandString(command);
+ String commandString = formatContent(command);
String builtCommand = String.format("$$%04dCF%s", 10 + commandString.getBytes().length, commandString);
return String.format("%s%02X", builtCommand, Checksum.xor(builtCommand));
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolSmsEncoder.java b/src/main/java/org/traccar/protocol/TotemProtocolSmsEncoder.java
index 28180b33b..8656f8a5c 100644
--- a/src/main/java/org/traccar/protocol/TotemProtocolSmsEncoder.java
+++ b/src/main/java/org/traccar/protocol/TotemProtocolSmsEncoder.java
@@ -16,10 +16,11 @@
*/
package org.traccar.protocol;
+import org.traccar.StringProtocolEncoder;
import org.traccar.model.Command;
import org.traccar.Protocol;
-public class TotemProtocolSmsEncoder extends TotemProtocolEncoder {
+public class TotemProtocolSmsEncoder extends StringProtocolEncoder {
public TotemProtocolSmsEncoder(Protocol protocol) {
super(protocol);
@@ -30,7 +31,7 @@ public class TotemProtocolSmsEncoder extends TotemProtocolEncoder {
initDevicePassword(command, "000000");
- return String.format("*%s#", super.getCommandString(command));
+ return String.format("*%s#", TotemProtocolEncoder.formatContent(command));
}
}