diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
commit | 55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch) | |
tree | b86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java | |
parent | c04ad7d48331253c095fc123ded1b00f6ff871d3 (diff) | |
parent | 2788174193def918a3a1a5be3bbed24c9613323f (diff) | |
download | trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2 trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip |
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java | 98 |
1 files changed, 42 insertions, 56 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java index a4faacf13..a6a05707e 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java @@ -52,73 +52,59 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { } protected Object encodeUniversalCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_REBOOT_DEVICE: - return formatCommand(command, "CMD;%s;03;03\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_POSITION_SINGLE: - return formatCommand(command, "CMD;%s;03;01\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_OUTPUT_CONTROL: + return switch (command.getType()) { + case Command.TYPE_REBOOT_DEVICE -> formatCommand(command, "CMD;%s;03;03\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "CMD;%s;03;01\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_OUTPUT_CONTROL -> { if (command.getAttributes().get(Command.KEY_DATA).equals("1")) { - switch (command.getInteger(Command.KEY_INDEX)) { - case 1: - return formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); - case 2: - return formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); - case 3: - return formatCommand(command, "CMD;%s;04;09\r", Command.KEY_UNIQUE_ID); - default: - return null; - } + yield switch (command.getInteger(Command.KEY_INDEX)) { + case 1 -> formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); + case 2 -> formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); + case 3 -> formatCommand(command, "CMD;%s;04;09\r", Command.KEY_UNIQUE_ID); + default -> null; + }; } else { - switch (command.getInteger(Command.KEY_INDEX)) { - case 1: - return formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); - case 2: - return formatCommand(command, "CMD;%s;04;04\r", Command.KEY_UNIQUE_ID); - case 3: - return formatCommand(command, "CMD;%s;04;10\r", Command.KEY_UNIQUE_ID); - default: - return null; - } + yield switch (command.getInteger(Command.KEY_INDEX)) { + case 1 -> formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); + case 2 -> formatCommand(command, "CMD;%s;04;04\r", Command.KEY_UNIQUE_ID); + case 3 -> formatCommand(command, "CMD;%s;04;10\r", Command.KEY_UNIQUE_ID); + default -> null; + }; } - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_ARM: - return formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_DISARM: - return formatCommand(command, "CMD;%s;04;04\r", Command.KEY_UNIQUE_ID); - default: - return null; - } + } + case Command.TYPE_ENGINE_STOP -> formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_ARM -> formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_DISARM -> formatCommand(command, "CMD;%s;04;04\r", Command.KEY_UNIQUE_ID); + default -> null; + }; } protected Object encodeLegacyCommand(String prefix, Command command) { - switch (command.getType()) { - case Command.TYPE_REBOOT_DEVICE: - return formatCommand(command, prefix + "CMD;%s;02;Reboot\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_POSITION_SINGLE: - return formatCommand(command, prefix + "CMD;%s;02;StatusReq\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_OUTPUT_CONTROL: + return switch (command.getType()) { + case Command.TYPE_REBOOT_DEVICE -> + formatCommand(command, prefix + "CMD;%s;02;Reboot\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_POSITION_SINGLE -> + formatCommand(command, prefix + "CMD;%s;02;StatusReq\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_OUTPUT_CONTROL -> { if (command.getAttributes().get(Command.KEY_DATA).equals("1")) { - return formatCommand(command, prefix + "CMD;%s;02;Enable%s\r", + yield formatCommand(command, prefix + "CMD;%s;02;Enable%s\r", Command.KEY_UNIQUE_ID, Command.KEY_INDEX); } else { - return formatCommand(command, prefix + "CMD;%s;02;Disable%s\r", + yield formatCommand(command, prefix + "CMD;%s;02;Disable%s\r", Command.KEY_UNIQUE_ID, Command.KEY_INDEX); } - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, prefix + "CMD;%s;02;Enable1\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, prefix + "CMD;%s;02;Disable1\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_ARM: - return formatCommand(command, prefix + "CMD;%s;02;Enable2\r", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_DISARM: - return formatCommand(command, prefix + "CMD;%s;02;Disable2\r", Command.KEY_UNIQUE_ID); - default: - return null; - } + } + case Command.TYPE_ENGINE_STOP -> + formatCommand(command, prefix + "CMD;%s;02;Enable1\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ENGINE_RESUME -> + formatCommand(command, prefix + "CMD;%s;02;Disable1\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_ARM -> + formatCommand(command, prefix + "CMD;%s;02;Enable2\r", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_DISARM -> + formatCommand(command, prefix + "CMD;%s;02;Disable2\r", Command.KEY_UNIQUE_ID); + default -> null; + }; } } |