diff options
author | Matjaž Črnko <m.crnko@txt.si> | 2022-01-04 22:09:43 +0100 |
---|---|---|
committer | Matjaž Črnko <m.crnko@txt.si> | 2022-01-04 22:09:43 +0100 |
commit | c21626223cd0c480725d8057a2cd4bf2b9d7e0b3 (patch) | |
tree | 7d432d6387c0dd1d0a6da88b35f84e635dc8642d /src/main/java/org/traccar/protocol/TotemProtocolEncoder.java | |
parent | 1a32d6b9b7253716d5927200db12d287b134ee26 (diff) | |
download | trackermap-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/java/org/traccar/protocol/TotemProtocolEncoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/TotemProtocolEncoder.java | 21 |
1 files changed, 12 insertions, 9 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)); |