aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java57
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;
+ };
}
}