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/MiniFinderProtocolEncoder.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/MiniFinderProtocolEncoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java | 83 |
1 files changed, 37 insertions, 46 deletions
diff --git a/src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java index 059f688f7..ed2891f33 100644 --- a/src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -29,25 +29,18 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements @Override public String formatValue(String key, Object value) { - switch (key) { - case Command.KEY_ENABLE: - return (Boolean) value ? "1" : "0"; - case Command.KEY_TIMEZONE: - return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); - case Command.KEY_INDEX: - switch (((Number) value).intValue()) { - case 0: - return "A"; - case 1: - return "B"; - case 2: - return "C"; - default: - return null; - } - default: - return null; - } + return switch (key) { + case Command.KEY_ENABLE -> (Boolean) value ? "1" : "0"; + case Command.KEY_TIMEZONE -> String.format( + "%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000); + case Command.KEY_INDEX -> switch (((Number) value).intValue()) { + case 0 -> "A"; + case 1 -> "B"; + case 2 -> "C"; + default -> null; + }; + default -> null; + }; } @Override @@ -55,33 +48,31 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements initDevicePassword(command, "123456"); - switch (command.getType()) { - case Command.TYPE_SET_TIMEZONE: - return formatCommand(command, "%sL%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_TIMEZONE); - case Command.TYPE_VOICE_MONITORING: - return formatCommand(command, "%sP%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); - case Command.TYPE_ALARM_SPEED: - return formatCommand(command, "%sJ1%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); - case Command.TYPE_ALARM_GEOFENCE: - return formatCommand(command, "%sR1%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_RADIUS); - case Command.TYPE_ALARM_VIBRATION: - return formatCommand(command, "%sW1,%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); - case Command.TYPE_SET_AGPS: - return formatCommand(command, "%sAGPS%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); - case Command.TYPE_ALARM_FALL: - return formatCommand(command, "%sF%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); - case Command.TYPE_MODE_POWER_SAVING: - return formatCommand(command, "%sSP%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); - case Command.TYPE_MODE_DEEP_SLEEP: - return formatCommand(command, "%sDS%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); - case Command.TYPE_SOS_NUMBER: - return formatCommand(command, "%s%s1,%s", this, - Command.KEY_DEVICE_PASSWORD, Command.KEY_INDEX, Command.KEY_PHONE); - case Command.TYPE_SET_INDICATOR: - return formatCommand(command, "%sLED%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_SET_TIMEZONE -> formatCommand( + command, "%sL%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_TIMEZONE); + case Command.TYPE_VOICE_MONITORING -> formatCommand( + command, "%sP%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); + case Command.TYPE_ALARM_SPEED -> formatCommand( + command, "%sJ1%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); + case Command.TYPE_ALARM_GEOFENCE -> formatCommand( + command, "%sR1%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_RADIUS); + case Command.TYPE_ALARM_VIBRATION -> formatCommand( + command, "%sW1,%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); + case Command.TYPE_SET_AGPS -> formatCommand( + command, "%sAGPS%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); + case Command.TYPE_ALARM_FALL -> formatCommand( + command, "%sF%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); + case Command.TYPE_MODE_POWER_SAVING -> formatCommand( + command, "%sSP%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); + case Command.TYPE_MODE_DEEP_SLEEP -> formatCommand( + command, "%sDS%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE); + case Command.TYPE_SOS_NUMBER -> formatCommand( + command, "%s%s1,%s", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_INDEX, Command.KEY_PHONE); + case Command.TYPE_SET_INDICATOR -> formatCommand( + command, "%sLED%s", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA); + default -> null; + }; } } |