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/RuptelaProtocolEncoder.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/RuptelaProtocolEncoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java index 5ec971a98..79c572707 100644 --- a/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java @@ -48,50 +48,57 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder { ByteBuf content = Unpooled.buffer(); - switch (command.getType()) { - case Command.TYPE_CUSTOM: + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> { String data = command.getString(Command.KEY_DATA); if (data.matches("(\\p{XDigit}{2})+")) { content.writeBytes(DataConverter.parseHex(data)); - return content; + yield content; } else { content.writeBytes(data.getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); + yield encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); } - case Command.TYPE_ENGINE_STOP: + } + case Command.TYPE_ENGINE_STOP -> { content.writeBytes("pass immobilizer 10".getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); - case Command.TYPE_ENGINE_RESUME: + yield encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); + } + case Command.TYPE_ENGINE_RESUME -> { content.writeBytes("pass resetimmob".getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); - case Command.TYPE_REQUEST_PHOTO: + yield encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content); + } + case Command.TYPE_REQUEST_PHOTO -> { content.writeByte(1); // sub-command content.writeByte(0); // source content.writeInt(0); // start timestamp content.writeInt(Integer.MAX_VALUE); // end timestamp - return encodeContent(RuptelaProtocolDecoder.MSG_FILES, content); - case Command.TYPE_CONFIGURATION: + yield encodeContent(RuptelaProtocolDecoder.MSG_FILES, content); + } + case Command.TYPE_CONFIGURATION -> { content.writeBytes((command.getString(Command.KEY_DATA) + "\r\n").getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_CONFIGURATION, content); - case Command.TYPE_GET_VERSION: - return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_VERSION, content); - case Command.TYPE_FIRMWARE_UPDATE: + yield encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_CONFIGURATION, content); + } + case Command.TYPE_GET_VERSION -> encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_VERSION, content); + case Command.TYPE_FIRMWARE_UPDATE -> { content.writeBytes("|FU_STRT*\r\n".getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_FIRMWARE_UPDATE, content); - case Command.TYPE_OUTPUT_CONTROL: + yield encodeContent(RuptelaProtocolDecoder.MSG_FIRMWARE_UPDATE, content); + } + case Command.TYPE_OUTPUT_CONTROL -> { content.writeInt(command.getInteger(Command.KEY_INDEX)); content.writeInt(command.getInteger(Command.KEY_DATA)); - return encodeContent(RuptelaProtocolDecoder.MSG_SET_IO, content); - case Command.TYPE_SET_CONNECTION: + yield encodeContent(RuptelaProtocolDecoder.MSG_SET_IO, content); + } + case Command.TYPE_SET_CONNECTION -> { String c = command.getString(Command.KEY_SERVER) + "," + command.getInteger(Command.KEY_PORT) + ",TCP"; content.writeBytes(c.getBytes(StandardCharsets.US_ASCII)); - return encodeContent(RuptelaProtocolDecoder.MSG_SET_CONNECTION, content); - case Command.TYPE_SET_ODOMETER: + yield encodeContent(RuptelaProtocolDecoder.MSG_SET_CONNECTION, content); + } + case Command.TYPE_SET_ODOMETER -> { content.writeInt(command.getInteger(Command.KEY_DATA)); - return encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content); - default: - return null; - } + yield encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content); + } + default -> null; + }; } } |