aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java95
1 files changed, 39 insertions, 56 deletions
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
index e3e1ae961..ed6eed6a7 100644
--- a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
@@ -49,65 +49,48 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder {
initDevicePassword(command, "123456");
if (alternative || forceAlternative) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatAlt(command, "%s", Command.KEY_DATA);
- case Command.TYPE_GET_VERSION:
- return formatAlt(command, "*about*");
- case Command.TYPE_POWER_OFF:
- return formatAlt(command, "*turnoff*");
- case Command.TYPE_REBOOT_DEVICE:
- return formatAlt(command, "88888888");
- case Command.TYPE_POSITION_SINGLE:
- return formatAlt(command, "*getposl*");
- case Command.TYPE_POSITION_PERIODIC:
- return formatAlt(command, "*routetrack*99*");
- case Command.TYPE_POSITION_STOP:
- return formatAlt(command, "*routetrackoff*");
- case Command.TYPE_GET_DEVICE_STATUS:
- return formatAlt(command, "*status*");
- case Command.TYPE_IDENTIFICATION:
- return formatAlt(command, "999999");
- case Command.TYPE_MODE_DEEP_SLEEP:
- return formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*sleep*2*" : "*sleepoff*");
- case Command.TYPE_MODE_POWER_SAVING:
- return formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*sleepv*" : "*sleepoff*");
- case Command.TYPE_ALARM_SOS:
- return formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*soson*" : "*sosoff*");
- case Command.TYPE_SET_CONNECTION:
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatAlt(command, "%s", Command.KEY_DATA);
+ case Command.TYPE_GET_VERSION -> formatAlt(command, "*about*");
+ case Command.TYPE_POWER_OFF -> formatAlt(command, "*turnoff*");
+ case Command.TYPE_REBOOT_DEVICE -> formatAlt(command, "88888888");
+ case Command.TYPE_POSITION_SINGLE -> formatAlt(command, "*getposl*");
+ case Command.TYPE_POSITION_PERIODIC -> formatAlt(command, "*routetrack*99*");
+ case Command.TYPE_POSITION_STOP -> formatAlt(command, "*routetrackoff*");
+ case Command.TYPE_GET_DEVICE_STATUS -> formatAlt(command, "*status*");
+ case Command.TYPE_IDENTIFICATION -> formatAlt(command, "999999");
+ case Command.TYPE_MODE_DEEP_SLEEP ->
+ formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*sleep*2*" : "*sleepoff*");
+ case Command.TYPE_MODE_POWER_SAVING ->
+ formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*sleepv*" : "*sleepoff*");
+ case Command.TYPE_ALARM_SOS ->
+ formatAlt(command, command.getBoolean(Command.KEY_ENABLE) ? "*soson*" : "*sosoff*");
+ case Command.TYPE_SET_CONNECTION -> {
String server = command.getString(Command.KEY_SERVER).replace(".", "*");
- return formatAlt(command, "*setip*" + server + "*%s*", Command.KEY_PORT);
- case Command.TYPE_SOS_NUMBER:
- return formatAlt(command, "*master*%s*%s*", Command.KEY_DEVICE_PASSWORD, Command.KEY_PHONE);
- default:
- return null;
- }
+ yield formatAlt(command, "*setip*" + server + "*%s*", Command.KEY_PORT);
+ }
+ case Command.TYPE_SOS_NUMBER ->
+ formatAlt(command, "*master*%s*%s*", Command.KEY_DEVICE_PASSWORD, Command.KEY_PHONE);
+ default -> null;
+ };
} else {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "(%s%s)", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
- case Command.TYPE_GET_VERSION:
- return formatCommand(command, "(%sAP07)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "(%sAT00)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_SET_ODOMETER:
- return formatCommand(command, "(%sAX01)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "(%sAP00)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_PERIODIC:
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(command, "(%s%s)", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
+ case Command.TYPE_GET_VERSION -> formatCommand(command, "(%sAP07)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_REBOOT_DEVICE -> formatCommand(command, "(%sAT00)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_SET_ODOMETER -> formatCommand(command, "(%sAX01)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "(%sAP00)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_POSITION_PERIODIC -> {
String frequency = String.format("%04X", command.getInteger(Command.KEY_FREQUENCY));
- return formatCommand(command, "(%sAR00" + frequency + "0000)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_STOP:
- return formatCommand(command, "(%sAR0000000000)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "(%sAV010)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "(%sAV011)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "(%sAV00%s)", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
- default:
- return null;
- }
+ yield formatCommand(command, "(%sAR00" + frequency + "0000)", Command.KEY_UNIQUE_ID);
+ }
+ case Command.TYPE_POSITION_STOP -> formatCommand(command, "(%sAR0000000000)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, "(%sAV010)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "(%sAV011)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_OUTPUT_CONTROL ->
+ formatCommand(command, "(%sAV00%s)", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
+ default -> null;
+ };
}
}