aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java49
-rw-r--r--src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java8
-rw-r--r--src/main/java/org/traccar/protocol/IntellitracProtocolDecoder.java32
-rw-r--r--src/main/java/org/traccar/protocol/IotmProtocolDecoder.java233
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocolDecoder.java35
-rw-r--r--src/main/java/org/traccar/protocol/ItsProtocolEncoder.java14
-rw-r--r--src/main/java/org/traccar/protocol/Ivt401ProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/JidoProtocolDecoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/Jt600ProtocolEncoder.java21
-rw-r--r--src/main/java/org/traccar/protocol/KhdProtocolDecoder.java30
-rw-r--r--src/main/java/org/traccar/protocol/KhdProtocolEncoder.java30
-rw-r--r--src/main/java/org/traccar/protocol/L100ProtocolDecoder.java24
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java67
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java52
-rw-r--r--src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java70
-rw-r--r--src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java60
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java337
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java32
-rw-r--r--src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java54
-rw-r--r--src/main/java/org/traccar/protocol/MiniFinderProtocolEncoder.java83
-rw-r--r--src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java170
-rw-r--r--src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/Mta6ProtocolDecoder.java20
-rw-r--r--src/main/java/org/traccar/protocol/NavigilProtocolDecoder.java25
-rw-r--r--src/main/java/org/traccar/protocol/NavisFrameDecoder.java24
-rw-r--r--src/main/java/org/traccar/protocol/NavisProtocolDecoder.java167
-rw-r--r--src/main/java/org/traccar/protocol/NdtpV6ProtocolEncoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/NiotProtocolDecoder.java10
-rw-r--r--src/main/java/org/traccar/protocol/NoranProtocolDecoder.java18
-rw-r--r--src/main/java/org/traccar/protocol/NoranProtocolEncoder.java24
-rw-r--r--src/main/java/org/traccar/protocol/NyitechProtocolDecoder.java35
-rw-r--r--src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/OwnTracksProtocolDecoder.java38
-rw-r--r--src/main/java/org/traccar/protocol/PacificTrackProtocolDecoder.java116
-rw-r--r--src/main/java/org/traccar/protocol/PluginProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/PortmanProtocolEncoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/PretraceProtocolEncoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/PstProtocolEncoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/Pt502ProtocolDecoder.java34
-rw-r--r--src/main/java/org/traccar/protocol/Pt502ProtocolEncoder.java23
-rw-r--r--src/main/java/org/traccar/protocol/RetranslatorProtocolDecoder.java18
-rw-r--r--src/main/java/org/traccar/protocol/RoboTrackFrameDecoder.java25
-rw-r--r--src/main/java/org/traccar/protocol/RuptelaProtocolDecoder.java188
-rw-r--r--src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java57
-rw-r--r--src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java40
-rw-r--r--src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java39
-rw-r--r--src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java219
-rw-r--r--src/main/java/org/traccar/protocol/StarcomProtocolDecoder.java86
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocolDecoder.java57
-rw-r--r--src/main/java/org/traccar/protocol/StartekProtocolEncoder.java20
-rw-r--r--src/main/java/org/traccar/protocol/StbProtocolDecoder.java38
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java120
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java98
-rw-r--r--src/main/java/org/traccar/protocol/SviasProtocolEncoder.java31
-rw-r--r--src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java74
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolDecoder.java113
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolEncoder.java10
-rw-r--r--src/main/java/org/traccar/protocol/TaipProtocolDecoder.java65
-rw-r--r--src/main/java/org/traccar/protocol/TelicProtocolDecoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java102
-rw-r--r--src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java64
-rw-r--r--src/main/java/org/traccar/protocol/ThurayaProtocolDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java161
-rw-r--r--src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java95
-rw-r--r--src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java48
-rw-r--r--src/main/java/org/traccar/protocol/TlvProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/TmgProtocolDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/TopinProtocolEncoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/TotemProtocolDecoder.java74
-rw-r--r--src/main/java/org/traccar/protocol/TotemProtocolEncoder.java43
-rw-r--r--src/main/java/org/traccar/protocol/TrakMateProtocolDecoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java39
-rw-r--r--src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/TrvProtocolDecoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/TytanProtocolDecoder.java64
-rw-r--r--src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java31
-rw-r--r--src/main/java/org/traccar/protocol/UlbotechProtocolDecoder.java101
-rw-r--r--src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/UproProtocolDecoder.java104
-rw-r--r--src/main/java/org/traccar/protocol/VltProtocolDecoder.java15
-rw-r--r--src/main/java/org/traccar/protocol/VtfmsProtocolDecoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/WatchFrameDecoder.java35
-rw-r--r--src/main/java/org/traccar/protocol/WatchProtocolEncoder.java58
-rw-r--r--src/main/java/org/traccar/protocol/WialonProtocolEncoder.java20
-rw-r--r--src/main/java/org/traccar/protocol/WliProtocolDecoder.java54
-rw-r--r--src/main/java/org/traccar/protocol/WondexProtocolEncoder.java26
-rw-r--r--src/main/java/org/traccar/protocol/WristbandProtocolDecoder.java27
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java21
-rw-r--r--src/main/java/org/traccar/protocol/XexunProtocolDecoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java144
-rw-r--r--src/main/java/org/traccar/protocol/XirgoProtocolEncoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/Xrb28ProtocolDecoder.java51
-rw-r--r--src/main/java/org/traccar/protocol/Xrb28ProtocolEncoder.java23
-rw-r--r--src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java81
96 files changed, 1682 insertions, 3487 deletions
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
index 7d634b0f2..d020b5e44 100644
--- a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
@@ -72,24 +72,16 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int event) {
- switch (event) {
- case 4:
- return Position.ALARM_FATIGUE_DRIVING;
- case 6:
- return Position.ALARM_SOS;
- case 7:
- return Position.ALARM_BRAKING;
- case 8:
- return Position.ALARM_ACCELERATION;
- case 9:
- return Position.ALARM_CORNERING;
- case 10:
- return Position.ALARM_ACCIDENT;
- case 16:
- return Position.ALARM_REMOVING;
- default:
- return null;
- }
+ return switch (event) {
+ case 4 -> Position.ALARM_FATIGUE_DRIVING;
+ case 6 -> Position.ALARM_SOS;
+ case 7 -> Position.ALARM_BRAKING;
+ case 8 -> Position.ALARM_ACCELERATION;
+ case 9 -> Position.ALARM_CORNERING;
+ case 10 -> Position.ALARM_ACCIDENT;
+ case 16 -> Position.ALARM_REMOVING;
+ default -> null;
+ };
}
@Override
@@ -163,21 +155,12 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 2) {
String value = ByteBufUtil.hexDump(buf.readSlice(2));
int digit = Integer.parseInt(value.substring(0, 1), 16);
- char prefix;
- switch (digit >> 2) {
- default:
- prefix = 'P';
- break;
- case 1:
- prefix = 'C';
- break;
- case 2:
- prefix = 'B';
- break;
- case 3:
- prefix = 'U';
- break;
- }
+ char prefix = switch (digit >> 2) {
+ default -> 'P';
+ case 1 -> 'C';
+ case 2 -> 'B';
+ case 3 -> 'U';
+ };
codes.append(prefix).append(digit % 4).append(value.substring(1));
if (buf.readableBytes() > 2) {
codes.append(' ');
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
index dc34f7b4e..7f9903e5e 100644
--- a/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
@@ -54,14 +54,6 @@ public class HuaShengProtocolEncoder extends BaseProtocolEncoder {
content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
return encodeContent(HuaShengProtocolDecoder.MSG_SET_REQ, content);
case Command.TYPE_OUTPUT_CONTROL:
- /*
-0x01: Lock the relay1; //relay on
-0x02: Unlock the relay1; //relay off
-0x03: Lock the relay2; //relay2 on
-0x04: Unlock the relay2; //relay2 off
-0x05: Lock the relay3; //relay3 on
-0x06: Unlock the relay3; //realy3 off
- */
content.writeByte(
(command.getInteger(Command.KEY_INDEX) - 1) * 2
+ (2 - command.getInteger(Command.KEY_DATA)));
diff --git a/src/main/java/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/main/java/org/traccar/protocol/IntellitracProtocolDecoder.java
index b86584016..0a8331218 100644
--- a/src/main/java/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/IntellitracProtocolDecoder.java
@@ -66,27 +66,17 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int value) {
- switch (value) {
- case 164:
- return Position.ALARM_GEOFENCE_ENTER;
- case 165:
- return Position.ALARM_GEOFENCE_EXIT;
- case 168:
- case 169:
- return Position.ALARM_LOW_POWER;
- case 170:
- return Position.ALARM_POWER_OFF;
- case 176:
- return Position.ALARM_POWER_RESTORED;
- case 180:
- return Position.ALARM_FALL_DOWN;
- case 225:
- return Position.ALARM_JAMMING;
- case 995:
- return Position.ALARM_SOS;
- default:
- return null;
- }
+ return switch (value) {
+ case 164 -> Position.ALARM_GEOFENCE_ENTER;
+ case 165 -> Position.ALARM_GEOFENCE_EXIT;
+ case 168, 169 -> Position.ALARM_LOW_POWER;
+ case 170 -> Position.ALARM_POWER_OFF;
+ case 176 -> Position.ALARM_POWER_RESTORED;
+ case 180 -> Position.ALARM_FALL_DOWN;
+ case 225 -> Position.ALARM_JAMMING;
+ case 995 -> Position.ALARM_SOS;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
index d9e6670c6..7ad2befc7 100644
--- a/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/IotmProtocolDecoder.java
@@ -36,193 +36,92 @@ public class IotmProtocolDecoder extends BaseMqttProtocolDecoder {
}
private Object readValue(ByteBuf buf, int sensorType) {
- switch (sensorType) {
- case 0:
- return false;
- case 1:
- return true;
- case 3:
- return 0;
- case 4:
- return buf.readUnsignedByte();
- case 5:
- return buf.readUnsignedShortLE();
- case 6:
- return buf.readUnsignedIntLE();
- case 7:
- case 11:
- return buf.readLongLE();
- case 8:
- return buf.readByte();
- case 9:
- return buf.readShortLE();
- case 10:
- return buf.readIntLE();
- case 12:
- return buf.readFloatLE();
- case 13:
- return buf.readDoubleLE();
- case 32:
- return buf.readCharSequence(buf.readUnsignedByte(), StandardCharsets.US_ASCII).toString();
- case 33:
- return ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()));
- case 64:
- return buf.readCharSequence(buf.readUnsignedShortLE(), StandardCharsets.US_ASCII).toString();
- case 65:
- return ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedShortLE()));
- case 2:
- default:
- return null;
- }
+ return switch (sensorType) {
+ case 0 -> false;
+ case 1 -> true;
+ case 3 -> 0;
+ case 4 -> buf.readUnsignedByte();
+ case 5 -> buf.readUnsignedShortLE();
+ case 6 -> buf.readUnsignedIntLE();
+ case 7, 11 -> buf.readLongLE();
+ case 8 -> buf.readByte();
+ case 9 -> buf.readShortLE();
+ case 10 -> buf.readIntLE();
+ case 12 -> buf.readFloatLE();
+ case 13 -> buf.readDoubleLE();
+ case 32 -> buf.readCharSequence(buf.readUnsignedByte(), StandardCharsets.US_ASCII).toString();
+ case 33 -> ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()));
+ case 64 -> buf.readCharSequence(buf.readUnsignedShortLE(), StandardCharsets.US_ASCII).toString();
+ case 65 -> ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedShortLE()));
+ default -> null;
+ };
}
private void decodeSensor(Position position, ByteBuf record, int sensorType, int sensorId) {
String key;
switch (sensorId) {
- case 0x0002:
- position.set(Position.KEY_MOTION, sensorType > 0);
- break;
- case 0x0008:
- case 0x009B:
+ case 0x0002 -> position.set(Position.KEY_MOTION, sensorType > 0);
+ case 0x0008, 0x009B -> {
if (sensorType > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_JAMMING);
}
- break;
- case 0x0010:
- case 0x0011:
- case 0x0012:
- case 0x0013:
- case 0x0014:
- case 0x0015:
+ }
+ case 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015 -> {
key = Position.PREFIX_IN + (sensorId - 0x0010 + 2);
position.set(key, sensorType > 0);
- break;
- case 0x0062:
- position.set("doorFL", sensorType > 0);
- break;
- case 0x0063:
- position.set("doorFR", sensorType > 0);
- break;
- case 0x0064:
- position.set("doorRL", sensorType > 0);
- break;
- case 0x0065:
- position.set("doorRR", sensorType > 0);
- break;
- case 0x001E:
- position.set("buttonPresent", sensorType > 0);
- break;
- case 0x006D:
- position.set(Position.KEY_IGNITION, sensorType > 0);
- break;
- case 0x008B:
- position.set("handBrake", sensorType > 0);
- break;
- case 0x008C:
- position.set("footBrake", sensorType > 0);
- break;
- case 0x0094:
- case 0x0095:
- case 0x0096:
+ }
+ case 0x0062 -> position.set("doorFL", sensorType > 0);
+ case 0x0063 -> position.set("doorFR", sensorType > 0);
+ case 0x0064 -> position.set("doorRL", sensorType > 0);
+ case 0x0065 -> position.set("doorRR", sensorType > 0);
+ case 0x001E -> position.set("buttonPresent", sensorType > 0);
+ case 0x006D -> position.set(Position.KEY_IGNITION, sensorType > 0);
+ case 0x008B -> position.set("handBrake", sensorType > 0);
+ case 0x008C -> position.set("footBrake", sensorType > 0);
+ case 0x0094, 0x0095, 0x0096 -> {
key = Position.PREFIX_OUT + (sensorId - 0x0094 + 1);
position.set(key, sensorType > 0);
- break;
- case 0x009A:
- position.set(Position.PREFIX_OUT + 4, sensorType > 0);
- break;
- case 0x2000:
- position.set(Position.KEY_OBD_SPEED, record.readUnsignedByte());
- break;
- case 0x2001:
- position.set(Position.KEY_SATELLITES, record.readUnsignedByte());
- break;
- case 0x2006:
- position.set(Position.KEY_THROTTLE, record.readUnsignedByte());
- break;
- case 0x2007:
- position.set(Position.KEY_FUEL_LEVEL, record.readUnsignedByte());
- break;
- case 0x2008:
- position.set(Position.KEY_COOLANT_TEMP, record.readUnsignedByte());
- break;
- case 0x2009:
- position.set("fuel2", record.readUnsignedByte());
- break;
- case 0x200A:
- position.set(Position.KEY_ENGINE_LOAD, record.readUnsignedByte());
- break;
- case 0x2041:
- position.set(Position.KEY_BATTERY_LEVEL, record.readUnsignedByte());
- break;
- case 0x3000:
- position.set(Position.KEY_POWER, record.readUnsignedShortLE() * 0.001);
- break;
- case 0x3001:
- case 0x3002:
- case 0x3003:
+ }
+ case 0x009A -> position.set(Position.PREFIX_OUT + 4, sensorType > 0);
+ case 0x2000 -> position.set(Position.KEY_OBD_SPEED, record.readUnsignedByte());
+ case 0x2001 -> position.set(Position.KEY_SATELLITES, record.readUnsignedByte());
+ case 0x2006 -> position.set(Position.KEY_THROTTLE, record.readUnsignedByte());
+ case 0x2007 -> position.set(Position.KEY_FUEL_LEVEL, record.readUnsignedByte());
+ case 0x2008 -> position.set(Position.KEY_COOLANT_TEMP, record.readUnsignedByte());
+ case 0x2009 -> position.set("fuel2", record.readUnsignedByte());
+ case 0x200A -> position.set(Position.KEY_ENGINE_LOAD, record.readUnsignedByte());
+ case 0x2041 -> position.set(Position.KEY_BATTERY_LEVEL, record.readUnsignedByte());
+ case 0x3000 -> position.set(Position.KEY_POWER, record.readUnsignedShortLE() * 0.001);
+ case 0x3001, 0x3002, 0x3003 -> {
key = Position.PREFIX_ADC + (0x3003 - sensorId + 3);
position.set(key, record.readUnsignedShortLE() * 0.001);
- break;
- case 0x3004:
- position.set(Position.KEY_BATTERY, record.readUnsignedShortLE() * 0.001);
- break;
- case 0x300C:
- position.set(Position.KEY_RPM, record.readUnsignedShortLE());
- break;
- case 0x3021:
- position.set(Position.KEY_FUEL_CONSUMPTION, record.readUnsignedShortLE() * 0.05);
- break;
- case 0x3037:
- position.set("cargoWeight", record.readUnsignedShortLE() * 2);
- break;
- case 0x4001:
- position.set(Position.KEY_FUEL_USED, record.readUnsignedIntLE());
- break;
- case 0x4002:
- position.set(Position.KEY_HOURS, record.readUnsignedIntLE());
- break;
- case 0x4003:
- position.set(Position.KEY_ODOMETER, record.readUnsignedIntLE() * 5);
- break;
- case 0x4063:
- position.set(Position.KEY_AXLE_WEIGHT, record.readUnsignedIntLE());
- break;
- case 0x5000:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(record.readLongLE()));
- break;
- case 0x5004:
- case 0x5005:
- case 0x5006:
- case 0x5007:
+ }
+ case 0x3004 -> position.set(Position.KEY_BATTERY, record.readUnsignedShortLE() * 0.001);
+ case 0x300C -> position.set(Position.KEY_RPM, record.readUnsignedShortLE());
+ case 0x3021 -> position.set(Position.KEY_FUEL_CONSUMPTION, record.readUnsignedShortLE() * 0.05);
+ case 0x3037 -> position.set("cargoWeight", record.readUnsignedShortLE() * 2);
+ case 0x4001 -> position.set(Position.KEY_FUEL_USED, record.readUnsignedIntLE());
+ case 0x4002 -> position.set(Position.KEY_HOURS, record.readUnsignedIntLE());
+ case 0x4003 -> position.set(Position.KEY_ODOMETER, record.readUnsignedIntLE() * 5);
+ case 0x4063 -> position.set(Position.KEY_AXLE_WEIGHT, record.readUnsignedIntLE());
+ case 0x5000 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(record.readLongLE()));
+ case 0x5004, 0x5005, 0x5006, 0x5007 -> {
key = Position.PREFIX_TEMP + (sensorId - 0x5004 + 1);
position.set(key, record.readLongLE());
- break;
- case 0x500D:
- position.set("trailerId", String.valueOf(record.readLongLE()));
- break;
- case 0xA000:
- position.set(Position.KEY_DEVICE_TEMP, record.readFloatLE());
- break;
- case 0xA001:
- position.set(Position.KEY_ACCELERATION, record.readFloatLE());
- break;
- case 0xA002:
- position.set("cornering", record.readFloatLE());
- break;
- case 0xA017:
- case 0xA018:
- case 0xA019:
- case 0xA01A:
+ }
+ case 0x500D -> position.set("trailerId", String.valueOf(record.readLongLE()));
+ case 0xA000 -> position.set(Position.KEY_DEVICE_TEMP, record.readFloatLE());
+ case 0xA001 -> position.set(Position.KEY_ACCELERATION, record.readFloatLE());
+ case 0xA002 -> position.set("cornering", record.readFloatLE());
+ case 0xA017, 0xA018, 0xA019, 0xA01A -> {
key = Position.PREFIX_TEMP + (sensorId - 0xA017 + 1);
position.set(key, record.readFloatLE());
- break;
- case 0xB002:
- position.set(Position.KEY_OBD_ODOMETER, record.readDoubleLE());
- break;
- default:
+ }
+ case 0xB002 -> position.set(Position.KEY_OBD_ODOMETER, record.readDoubleLE());
+ default -> {
key = Position.PREFIX_IO + sensorId;
position.getAttributes().put(key, readValue(record, sensorType));
- break;
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
index 8a8d734cf..832275239 100644
--- a/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ItsProtocolDecoder.java
@@ -116,29 +116,18 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(String status) {
- switch (status) {
- case "WD":
- case "EA":
- return Position.ALARM_SOS;
- case "BL":
- return Position.ALARM_LOW_BATTERY;
- case "HB":
- return Position.ALARM_BRAKING;
- case "HA":
- return Position.ALARM_ACCELERATION;
- case "RT":
- return Position.ALARM_CORNERING;
- case "OS":
- return Position.ALARM_OVERSPEED;
- case "TA":
- return Position.ALARM_TAMPERING;
- case "BD":
- return Position.ALARM_POWER_CUT;
- case "BR":
- return Position.ALARM_POWER_RESTORED;
- default:
- return null;
- }
+ return switch (status) {
+ case "WD", "EA" -> Position.ALARM_SOS;
+ case "BL" -> Position.ALARM_LOW_BATTERY;
+ case "HB" -> Position.ALARM_BRAKING;
+ case "HA" -> Position.ALARM_ACCELERATION;
+ case "RT" -> Position.ALARM_CORNERING;
+ case "OS" -> Position.ALARM_OVERSPEED;
+ case "TA" -> Position.ALARM_TAMPERING;
+ case "BD" -> Position.ALARM_POWER_CUT;
+ case "BR" -> Position.ALARM_POWER_RESTORED;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java b/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java
index f82b8e3ac..60536485c 100644
--- a/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/ItsProtocolEncoder.java
@@ -27,15 +27,11 @@ public class ItsProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return "@SET#RLP,OP1,";
- case Command.TYPE_ENGINE_RESUME:
- return "@CLR#RLP,OP1,";
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP -> "@SET#RLP,OP1,";
+ case Command.TYPE_ENGINE_RESUME -> "@CLR#RLP,OP1,";
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Ivt401ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Ivt401ProtocolDecoder.java
index 972f22ebe..1b2b84a2e 100644
--- a/src/main/java/org/traccar/protocol/Ivt401ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Ivt401ProtocolDecoder.java
@@ -159,17 +159,11 @@ public class Ivt401ProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext(6)) {
position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_OVERSPEED : null);
switch (parser.nextInt()) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
- break;
- default:
- break;
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 3 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
+ default -> {
+ }
}
position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_LOW_BATTERY : null);
position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_POWER_CUT : null);
diff --git a/src/main/java/org/traccar/protocol/JidoProtocolDecoder.java b/src/main/java/org/traccar/protocol/JidoProtocolDecoder.java
index 98fb36e11..d843ba675 100644
--- a/src/main/java/org/traccar/protocol/JidoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/JidoProtocolDecoder.java
@@ -66,14 +66,11 @@ public class JidoProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int type) {
- switch (type) {
- case 3:
- return Position.ALARM_LOW_BATTERY;
- case 4:
- return Position.ALARM_TAMPERING;
- default:
- return null;
- }
+ return switch (type) {
+ case 3 -> Position.ALARM_LOW_BATTERY;
+ case 4 -> Position.ALARM_TAMPERING;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolEncoder.java
index 199467a38..1b1ccb981 100644
--- a/src/main/java/org/traccar/protocol/Jt600ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Jt600ProtocolEncoder.java
@@ -30,19 +30,16 @@ public class Jt600ProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return "(S07,0)";
- case Command.TYPE_ENGINE_RESUME:
- return "(S07,1)";
- case Command.TYPE_SET_TIMEZONE:
+ return switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP -> "(S07,0)";
+ case Command.TYPE_ENGINE_RESUME -> "(S07,1)";
+ case Command.TYPE_SET_TIMEZONE -> {
int offset = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000;
- return "(S09,1," + offset + ")";
- case Command.TYPE_REBOOT_DEVICE:
- return "(S17)";
- default:
- return null;
- }
+ yield "(S09,1," + offset + ")";
+ }
+ case Command.TYPE_REBOOT_DEVICE -> "(S17)";
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
index 2b234ab21..6ef280166 100644
--- a/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/KhdProtocolDecoder.java
@@ -191,15 +191,11 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
int dataLength = buf.readUnsignedByte();
switch (dataType) {
- case 0x01:
- position.set(Position.KEY_FUEL_LEVEL,
- buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
- break;
- case 0x02:
- position.set(Position.PREFIX_TEMP + 1,
- buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
- break;
- case 0x05:
+ case 0x01 -> position.set(Position.KEY_FUEL_LEVEL,
+ buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
+ case 0x02 -> position.set(Position.PREFIX_TEMP + 1,
+ buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
+ case 0x05 -> {
int sign = buf.readUnsignedByte();
switch (sign) {
case 1:
@@ -212,19 +208,17 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
break;
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, BufferUtil.readString(buf, dataLength - 1));
- break;
- case 0x18:
+ }
+ case 0x18 -> {
for (int i = 1; i <= 4; i++) {
double value = buf.readUnsignedShort();
if (value > 0x0000 && value < 0xFFFF) {
position.set("fuel" + i, value / 0xFFFE);
}
}
- break;
- case 0x20:
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- break;
- case 0x23:
+ }
+ case 0x20 -> position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ case 0x23 -> {
Network network = new Network();
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
@@ -235,9 +229,7 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
if (count > 0) {
position.setNetwork(network);
}
- break;
- default:
- break;
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java b/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java
index 12353b415..c91743a4f 100644
--- a/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java
@@ -73,26 +73,20 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder {
String uniqueId = getUniqueId(command.getDeviceId());
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return encodeCommand(MSG_CUT_OIL, uniqueId, null);
- case Command.TYPE_ENGINE_RESUME:
- return encodeCommand(MSG_RESUME_OIL, uniqueId, null);
- case Command.TYPE_GET_VERSION:
- return encodeCommand(MSG_CHECK_VERSION, uniqueId, null);
- case Command.TYPE_FACTORY_RESET:
- return encodeCommand(MSG_FACTORY_RESET, uniqueId, null);
- case Command.TYPE_SET_SPEED_LIMIT:
+ return switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP -> encodeCommand(MSG_CUT_OIL, uniqueId, null);
+ case Command.TYPE_ENGINE_RESUME -> encodeCommand(MSG_RESUME_OIL, uniqueId, null);
+ case Command.TYPE_GET_VERSION -> encodeCommand(MSG_CHECK_VERSION, uniqueId, null);
+ case Command.TYPE_FACTORY_RESET -> encodeCommand(MSG_FACTORY_RESET, uniqueId, null);
+ case Command.TYPE_SET_SPEED_LIMIT -> {
ByteBuf content = Unpooled.buffer();
content.writeByte(command.getInteger(Command.KEY_DATA));
- return encodeCommand(MSG_RESUME_OIL, uniqueId, content);
- case Command.TYPE_SET_ODOMETER:
- return encodeCommand(MSG_DELETE_MILEAGE, uniqueId, null);
- case Command.TYPE_POSITION_SINGLE:
- return encodeCommand(MSG_ON_DEMAND_TRACK, uniqueId, null);
- default:
- return null;
- }
+ yield encodeCommand(MSG_RESUME_OIL, uniqueId, content);
+ }
+ case Command.TYPE_SET_ODOMETER -> encodeCommand(MSG_DELETE_MILEAGE, uniqueId, null);
+ case Command.TYPE_POSITION_SINGLE -> encodeCommand(MSG_ON_DEMAND_TRACK, uniqueId, null);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/L100ProtocolDecoder.java b/src/main/java/org/traccar/protocol/L100ProtocolDecoder.java
index 820de8f1c..62fb6b7bb 100644
--- a/src/main/java/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/L100ProtocolDecoder.java
@@ -242,17 +242,9 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
parser.next(); // reserved
switch (parser.nextInt()) {
- case 0:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- break;
- default:
- break;
+ case 0 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
position.set(Position.KEY_CHARGE, parser.nextInt() == 1);
@@ -314,14 +306,8 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
switch (parser.next()) {
- case "P":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "T":
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- default:
- break;
+ case "P" -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case "T" -> position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
index 343d42e09..3e7d53ced 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -82,31 +82,19 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(String event) {
- switch (event) {
- case "Z":
- return Position.ALARM_LOW_BATTERY;
- case "Y":
- return Position.ALARM_TOW;
- case "X":
- return Position.ALARM_GEOFENCE_ENTER;
- case "T":
- return Position.ALARM_TAMPERING;
- case "H":
- return Position.ALARM_POWER_OFF;
- case "8":
- return Position.ALARM_VIBRATION;
- case "7":
- case "4":
- return Position.ALARM_GEOFENCE_EXIT;
- case "6":
- return Position.ALARM_OVERSPEED;
- case "5":
- return Position.ALARM_POWER_CUT;
- case "3":
- return Position.ALARM_SOS;
- default:
- return null;
- }
+ return switch (event) {
+ case "Z" -> Position.ALARM_LOW_BATTERY;
+ case "Y" -> Position.ALARM_TOW;
+ case "X" -> Position.ALARM_GEOFENCE_ENTER;
+ case "T" -> Position.ALARM_TAMPERING;
+ case "H" -> Position.ALARM_POWER_OFF;
+ case "8" -> Position.ALARM_VIBRATION;
+ case "7", "4" -> Position.ALARM_GEOFENCE_EXIT;
+ case "6" -> Position.ALARM_OVERSPEED;
+ case "5" -> Position.ALARM_POWER_CUT;
+ case "3" -> Position.ALARM_SOS;
+ default -> null;
+ };
}
private String decodeEvent(String event, Position position, String model) {
@@ -140,30 +128,13 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
String event, String devicePassword, Channel channel, SocketAddress remoteAddress) {
String responseCode = null;
-
switch (event) {
- case "3":
- responseCode = "d";
- break;
- case "M":
- responseCode = "m";
- break;
- case "S":
- case "T":
- responseCode = "t";
- break;
- case "X":
- case "4":
- responseCode = "x";
- break;
- case "Y":
- responseCode = "y";
- break;
- case "Z":
- responseCode = "z";
- break;
- default:
- break;
+ case "3" -> responseCode = "d";
+ case "M" -> responseCode = "m";
+ case "S", "T" -> responseCode = "t";
+ case "X", "4" -> responseCode = "x";
+ case "Y" -> responseCode = "y";
+ case "Z" -> responseCode = "z";
}
if (responseCode != null) {
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
index aaa5a70f7..f1c556eea 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
@@ -38,19 +38,15 @@ public class LaipacProtocolEncoder extends StringProtocolEncoder {
initDevicePassword(command, LaipacProtocolDecoder.DEFAULT_DEVICE_PASSWORD);
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "%s",
- Command.KEY_DATA);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "AVREQ,%s,1",
- Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "AVRESET,%s,%s",
- Command.KEY_UNIQUE_ID, Command.KEY_DEVICE_PASSWORD);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(
+ command, "%s", Command.KEY_DATA);
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(
+ command, "AVREQ,%s,1", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_REBOOT_DEVICE -> formatCommand(
+ command, "AVRESET,%s,%s", Command.KEY_UNIQUE_ID, Command.KEY_DEVICE_PASSWORD);
+ default -> null;
+ };
}
diff --git a/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java b/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java
index 6affb85c5..bc70e8c81 100644
--- a/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LeafSpyProtocolDecoder.java
@@ -55,56 +55,36 @@ public class LeafSpyProtocolDecoder extends BaseHttpProtocolDecoder {
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
for (String value : entry.getValue()) {
switch (entry.getKey()) {
- case "pass":
+ case "pass" -> {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession == null) {
sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
- break;
- case "Lat":
- position.setLatitude(Double.parseDouble(value));
- break;
- case "Long":
- position.setLongitude(Double.parseDouble(value));
- break;
- case "RPM":
+ }
+ case "Lat" -> position.setLatitude(Double.parseDouble(value));
+ case "Long" -> position.setLongitude(Double.parseDouble(value));
+ case "RPM" -> {
position.set(Position.KEY_RPM, Integer.parseInt(value));
position.setSpeed(convertSpeed(Double.parseDouble(value) / 63, "kmh"));
- break;
- case "Elv":
- position.setAltitude(Double.parseDouble(value));
- break;
- case "SOC":
- position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value));
- break;
- case "user":
- position.set(Position.KEY_DRIVER_UNIQUE_ID, value);
- break;
- case "ChrgMode":
- position.set(Position.KEY_CHARGE, Integer.parseInt(value) != 0);
- break;
- case "Odo":
- position.set(Position.KEY_OBD_ODOMETER, Integer.parseInt(value) * 1000);
- break;
- default:
+ }
+ case "Elv" -> position.setAltitude(Double.parseDouble(value));
+ case "SOC" -> position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value));
+ case "user" -> position.set(Position.KEY_DRIVER_UNIQUE_ID, value);
+ case "ChrgMode" -> position.set(Position.KEY_CHARGE, Integer.parseInt(value) != 0);
+ case "Odo" -> position.set(Position.KEY_OBD_ODOMETER, Integer.parseInt(value) * 1000);
+ default -> {
try {
position.set(entry.getKey(), Double.parseDouble(value));
} catch (NumberFormatException e) {
switch (value) {
- case "true":
- position.set(entry.getKey(), true);
- break;
- case "false":
- position.set(entry.getKey(), false);
- break;
- default:
- position.set(entry.getKey(), value);
- break;
+ case "true" -> position.set(entry.getKey(), true);
+ case "false" -> position.set(entry.getKey(), false);
+ default -> position.set(entry.getKey(), value);
}
}
- break;
+ }
}
}
}
diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
index 06b6f0e76..c16a0752d 100644
--- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -387,54 +387,28 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
return Position.ALARM_GEOFENCE_EXIT;
}
}
- switch (value) {
- case "pw on":
- case "poweron":
- return Position.ALARM_POWER_ON;
- case "poweroff":
- return Position.ALARM_POWER_OFF;
- case "sos":
- case "help":
- return Position.ALARM_SOS;
- case "over speed":
- case "overspeed":
- return Position.ALARM_OVERSPEED;
- case "lowspeed":
- return Position.ALARM_LOW_SPEED;
- case "low battery":
- case "lowbattery":
- return Position.ALARM_LOW_BATTERY;
- case "low extern voltage":
- return Position.ALARM_LOW_POWER;
- case "gps cut":
- return Position.ALARM_GPS_ANTENNA_CUT;
- case "vib":
- return Position.ALARM_VIBRATION;
- case "move in":
- return Position.ALARM_GEOFENCE_ENTER;
- case "move out":
- return Position.ALARM_GEOFENCE_EXIT;
- case "corner":
- return Position.ALARM_CORNERING;
- case "fatigue":
- return Position.ALARM_FATIGUE_DRIVING;
- case "psd":
- return Position.ALARM_POWER_CUT;
- case "psr":
- return Position.ALARM_POWER_RESTORED;
- case "hit":
- return Position.ALARM_VIBRATION;
- case "belt on":
- case "belton":
- return Position.ALARM_LOCK;
- case "belt off":
- case "beltoff":
- return Position.ALARM_UNLOCK;
- case "error":
- return Position.ALARM_FAULT;
- default:
- return null;
- }
+ return switch (value) {
+ case "pw on", "poweron" -> Position.ALARM_POWER_ON;
+ case "poweroff" -> Position.ALARM_POWER_OFF;
+ case "sos", "help" -> Position.ALARM_SOS;
+ case "over speed", "overspeed" -> Position.ALARM_OVERSPEED;
+ case "lowspeed" -> Position.ALARM_LOW_SPEED;
+ case "low battery", "lowbattery" -> Position.ALARM_LOW_BATTERY;
+ case "low extern voltage" -> Position.ALARM_LOW_POWER;
+ case "gps cut" -> Position.ALARM_GPS_ANTENNA_CUT;
+ case "vib" -> Position.ALARM_VIBRATION;
+ case "move in" -> Position.ALARM_GEOFENCE_ENTER;
+ case "move out" -> Position.ALARM_GEOFENCE_EXIT;
+ case "corner" -> Position.ALARM_CORNERING;
+ case "fatigue" -> Position.ALARM_FATIGUE_DRIVING;
+ case "psd" -> Position.ALARM_POWER_CUT;
+ case "psr" -> Position.ALARM_POWER_RESTORED;
+ case "hit" -> Position.ALARM_VIBRATION;
+ case "belt on", "belton" -> Position.ALARM_LOCK;
+ case "belt off", "beltoff" -> Position.ALARM_UNLOCK;
+ case "error" -> Position.ALARM_FAULT;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 1f8c4d2da..c18b29288 100644
--- a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -209,30 +209,19 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x12:
- return Position.ALARM_MOVEMENT;
- case 0x13:
- return Position.ALARM_GEOFENCE_ENTER;
- case 0x14:
- return Position.ALARM_ACCIDENT;
- case 0x50:
- return Position.ALARM_POWER_OFF;
- case 0x53:
- return Position.ALARM_GPS_ANTENNA_CUT;
- case 0x72:
- return Position.ALARM_BRAKING;
- case 0x73:
- return Position.ALARM_ACCELERATION;
- default:
- return null;
- }
+ return switch (value) {
+ case 0x01 -> Position.ALARM_SOS;
+ case 0x10 -> Position.ALARM_LOW_BATTERY;
+ case 0x11 -> Position.ALARM_OVERSPEED;
+ case 0x12 -> Position.ALARM_MOVEMENT;
+ case 0x13 -> Position.ALARM_GEOFENCE_ENTER;
+ case 0x14 -> Position.ALARM_ACCIDENT;
+ case 0x50 -> Position.ALARM_POWER_OFF;
+ case 0x53 -> Position.ALARM_GPS_ANTENNA_CUT;
+ case 0x72 -> Position.ALARM_BRAKING;
+ case 0x73 -> Position.ALARM_ACCELERATION;
+ default -> null;
+ };
}
private Position decodeRegular(Position position, String sentence) {
@@ -478,21 +467,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
- switch (command) {
- case MSG_POSITION:
- case MSG_POSITION_LOGGED:
- case MSG_ALARM:
- case MSG_POSITION_IMAGE:
- return decodeRegular(position, sentence);
- case MSG_RFID:
- return decodeRfid(position, sentence);
- case MSG_OBD_RT:
- return decodeObd(position, sentence);
- case MSG_OBD_RTA:
- return decodeObdA(position, sentence);
- default:
- return null;
- }
+ return switch (command) {
+ case MSG_POSITION, MSG_POSITION_LOGGED, MSG_ALARM, MSG_POSITION_IMAGE ->
+ decodeRegular(position, sentence);
+ case MSG_RFID -> decodeRfid(position, sentence);
+ case MSG_OBD_RT -> decodeObd(position, sentence);
+ case MSG_OBD_RTA -> decodeObdA(position, sentence);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
index 88b6380a5..e9e37d18a 100644
--- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -108,41 +108,24 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int event) {
- switch (event) {
- case 1:
- return Position.ALARM_SOS;
- case 17:
- return Position.ALARM_LOW_BATTERY;
- case 18:
- return Position.ALARM_LOW_POWER;
- case 19:
- return Position.ALARM_OVERSPEED;
- case 20:
- return Position.ALARM_GEOFENCE_ENTER;
- case 21:
- return Position.ALARM_GEOFENCE_EXIT;
- case 22:
- return Position.ALARM_POWER_RESTORED;
- case 23:
- return Position.ALARM_POWER_CUT;
- case 36:
- return Position.ALARM_TOW;
- case 44:
- return Position.ALARM_JAMMING;
- case 78:
- return Position.ALARM_ACCIDENT;
- case 90:
- case 91:
- return Position.ALARM_CORNERING;
- case 129:
- return Position.ALARM_BRAKING;
- case 130:
- return Position.ALARM_ACCELERATION;
- case 135:
- return Position.ALARM_FATIGUE_DRIVING;
- default:
- return null;
- }
+ return switch (event) {
+ case 1 -> Position.ALARM_SOS;
+ case 17 -> Position.ALARM_LOW_BATTERY;
+ case 18 -> Position.ALARM_LOW_POWER;
+ case 19 -> Position.ALARM_OVERSPEED;
+ case 20 -> Position.ALARM_GEOFENCE_ENTER;
+ case 21 -> Position.ALARM_GEOFENCE_EXIT;
+ case 22 -> Position.ALARM_POWER_RESTORED;
+ case 23 -> Position.ALARM_POWER_CUT;
+ case 36 -> Position.ALARM_TOW;
+ case 44 -> Position.ALARM_JAMMING;
+ case 78 -> Position.ALARM_ACCIDENT;
+ case 90, 91 -> Position.ALARM_CORNERING;
+ case 129 -> Position.ALARM_BRAKING;
+ case 130 -> Position.ALARM_ACCELERATION;
+ case 135 -> Position.ALARM_FATIGUE_DRIVING;
+ default -> null;
+ };
}
private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
@@ -207,35 +190,22 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
switch (Objects.requireNonNullElse(getDeviceModel(deviceSession), "").toUpperCase()) {
- case "MVT340":
- case "MVT380":
+ case "MVT340", "MVT380" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.0 * 2.0 / 1024.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.0 * 16.0 / 1024.0);
- break;
- case "MT90":
+ }
+ case "MT90" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.3 * 2.0 / 4096.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0));
- break;
- case "T1":
- case "T3":
- case "MVT100":
- case "MVT600":
- case "MVT800":
- case "TC68":
- case "TC68S":
+ }
+ case "T1", "T3", "MVT100", "MVT600", "MVT800", "TC68", "TC68S" -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.3 * 2.0 / 4096.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.3 * 16.0 / 4096.0);
- break;
- case "T311":
- case "T322X":
- case "T333":
- case "T355":
- case "T366":
- case "T366G":
- default:
+ }
+ default -> {
position.set(Position.KEY_BATTERY, parser.nextHexInt() / 100.0);
position.set(Position.KEY_POWER, parser.nextHexInt(0) / 100.0);
- break;
+ }
}
}
@@ -243,12 +213,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
String eventData = parser.next();
if (eventData != null && !eventData.isEmpty()) {
switch (event) {
- case 37:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
- break;
- default:
- position.set("eventData", eventData);
- break;
+ case 37 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
+ default -> position.set("eventData", eventData);
}
}
@@ -402,42 +368,22 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x01:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x05:
- position.setValid(buf.readUnsignedByte() > 0);
- break;
- case 0x06:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case 0x07:
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case 0x14:
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- break;
- case 0x15:
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- break;
- case 0x47:
+ case 0x01 -> position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ case 0x05 -> position.setValid(buf.readUnsignedByte() > 0);
+ case 0x06 -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ case 0x07 -> position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ case 0x14 -> position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
+ case 0x15 -> position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ case 0x47 -> {
int lockState = buf.readUnsignedByte();
if (lockState > 0) {
position.set(Position.KEY_LOCK, lockState == 2);
}
- break;
- case 0x97:
- position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
- break;
- case 0x9D:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
- break;
- case 0xFE69:
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- break;
- default:
- buf.readUnsignedByte();
- break;
+ }
+ case 0x97 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
+ case 0x9D -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
+ case 0xFE69 -> position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ default -> buf.readUnsignedByte();
}
}
@@ -446,58 +392,23 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x08:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
- break;
- case 0x09:
- position.setCourse(buf.readUnsignedShortLE());
- break;
- case 0x0A:
- position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
- break;
- case 0x0B:
- position.setAltitude(buf.readShortLE());
- break;
- case 0x16:
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x17:
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x19:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x1A:
- position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x29:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x40:
- position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
- break;
- case 0x91:
- case 0x92:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
- break;
- case 0x98:
- position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
- break;
- case 0x99:
- position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
- break;
- case 0x9C:
- position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
- break;
- case 0x9F:
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
- break;
- case 0xC9:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
- break;
- default:
- buf.readUnsignedShortLE();
- break;
+ case 0x08 -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+ case 0x09 -> position.setCourse(buf.readUnsignedShortLE());
+ case 0x0A -> position.set(Position.KEY_HDOP, buf.readUnsignedShortLE());
+ case 0x0B -> position.setAltitude(buf.readShortLE());
+ case 0x16 -> position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() * 0.01);
+ case 0x17 -> position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() * 0.01);
+ case 0x19 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
+ case 0x1A -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
+ case 0x29 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShortLE() * 0.01);
+ case 0x40 -> position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
+ case 0x91, 0x92 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShortLE());
+ case 0x98 -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedShortLE());
+ case 0x99 -> position.set(Position.KEY_RPM, buf.readUnsignedShortLE());
+ case 0x9C -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShortLE());
+ case 0x9F -> position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShortLE());
+ case 0xC9 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShortLE());
+ default -> buf.readUnsignedShortLE();
}
}
@@ -506,39 +417,17 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
boolean extension = buf.getUnsignedByte(buf.readerIndex()) == 0xFE;
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (id) {
- case 0x02:
- position.setLatitude(buf.readIntLE() * 0.000001);
- break;
- case 0x03:
- position.setLongitude(buf.readIntLE() * 0.000001);
- break;
- case 0x04:
- position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01
- break;
- case 0x0C:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
- break;
- case 0x0D:
- position.set("runtime", buf.readUnsignedIntLE());
- break;
- case 0x25:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
- break;
- case 0x9B:
- position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedIntLE());
- break;
- case 0xA0:
- position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
- break;
- case 0xA2:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
- break;
- case 0xFEF4:
- position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 60000);
- break;
- default:
- buf.readUnsignedIntLE();
- break;
+ case 0x02 -> position.setLatitude(buf.readIntLE() * 0.000001);
+ case 0x03 -> position.setLongitude(buf.readIntLE() * 0.000001);
+ case 0x04 -> position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01
+ case 0x0C -> position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ case 0x0D -> position.set("runtime", buf.readUnsignedIntLE());
+ case 0x25 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
+ case 0x9B -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedIntLE());
+ case 0xA0 -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001);
+ case 0xA2 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE() * 0.01);
+ case 0xFEF4 -> position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 60000);
+ default -> buf.readUnsignedIntLE();
}
}
@@ -548,48 +437,27 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int id = extension ? buf.readUnsignedShort() : buf.readUnsignedByte();
int length = buf.readUnsignedByte();
switch (id) {
- case 0x1D:
- case 0x1E:
- case 0x1F:
- case 0x20:
- case 0x21:
- case 0x22:
- case 0x23:
- case 0x24:
- case 0x25:
+ case 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 -> {
String wifiMac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
network.addWifiAccessPoint(WifiAccessPoint.from(
wifiMac.substring(0, wifiMac.length() - 1), buf.readShortLE()));
- break;
- case 0x0E:
- case 0x0F:
- case 0x10:
- case 0x12:
- case 0x13:
+ }
+ case 0x0E, 0x0F, 0x10, 0x12, 0x13 -> {
network.addCellTower(CellTower.from(
buf.readUnsignedShortLE(), buf.readUnsignedShortLE(),
buf.readUnsignedShortLE(), buf.readUnsignedIntLE(), buf.readShortLE()));
- break;
- case 0x2A:
- case 0x2B:
- case 0x2C:
- case 0x2D:
- case 0x2E:
- case 0x2F:
- case 0x30:
- case 0x31:
+ }
+ case 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31 -> {
buf.readUnsignedByte(); // label
position.set(Position.PREFIX_TEMP + (id - 0x2A), buf.readShortLE() * 0.01);
- break;
- case 0x4B:
- buf.skipBytes(length); // network information
- break;
- case 0xFE31:
+ }
+ case 0x4B -> buf.skipBytes(length); // network information
+ case 0xFE31 -> {
buf.readUnsignedByte(); // alarm protocol
buf.readUnsignedByte(); // alarm type
buf.skipBytes(length - 2);
- break;
- case 0xFE73:
+ }
+ case 0xFE73 -> {
buf.readUnsignedByte(); // version
position.set(
"tagName",
@@ -602,8 +470,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShortLE(); // low temperature threshold
buf.readUnsignedShortLE(); // high humidity threshold
buf.readUnsignedShortLE(); // low humidity threshold
- break;
- case 0xFEA8:
+ }
+ case 0xFEA8 -> {
for (int k = 1; k <= 3; k++) {
if (buf.readUnsignedByte() > 0) {
String key = k == 1 ? Position.KEY_BATTERY_LEVEL : "battery" + k + "Level";
@@ -613,10 +481,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
}
buf.readUnsignedByte(); // battery alert
- break;
- default:
- buf.skipBytes(length);
- break;
+ }
+ default -> buf.skipBytes(length);
}
}
@@ -650,24 +516,25 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');
String type = buf.toString(index + 1, 3, StandardCharsets.US_ASCII);
- switch (type) {
- case "AAC":
+ return switch (type) {
+ case "AAC" -> {
if (channel != null) {
String response = String.format("@@z27,%s,AAC,1*", imei);
response += Checksum.sum(response) + "\r\n";
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
- return null;
- case "D00":
+ yield null;
+ }
+ case "D00" -> {
if (photo == null) {
photo = Unpooled.buffer();
}
index = index + 1 + type.length() + 1;
- int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
+ int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
String file = buf.toString(index, endIndex - index, StandardCharsets.US_ASCII);
index = endIndex + 1;
- endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
+ endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
int total = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII));
index = endIndex + 1;
endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
@@ -686,31 +553,31 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
photo.release();
photo = null;
- return position;
+ yield position;
} else {
if ((current + 1) % 8 == 0) {
requestPhotoPacket(channel, remoteAddress, imei, file, current + 1);
}
- return null;
+ yield null;
}
- case "D03":
+ }
+ case "D03" -> {
photo = Unpooled.buffer();
requestPhotoPacket(channel, remoteAddress, imei, "camera_picture.jpg", 0);
- return null;
- case "D82":
+ yield null;
+ }
+ case "D82" -> {
Position position = new Position(getProtocolName());
position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId());
getLastLocation(position, null);
String result = buf.toString(index + 1, buf.writerIndex() - index - 4, StandardCharsets.US_ASCII);
position.set(Position.KEY_RESULT, result);
- return position;
- case "CCC":
- return decodeBinaryC(channel, remoteAddress, buf);
- case "CCE":
- return decodeBinaryE(channel, remoteAddress, buf);
- default:
- return decodeRegular(channel, remoteAddress, buf);
- }
+ yield position;
+ }
+ case "CCC" -> decodeBinaryC(channel, remoteAddress, buf);
+ case "CCE" -> decodeBinaryE(channel, remoteAddress, buf);
+ default -> decodeRegular(channel, remoteAddress, buf);
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
index 365dbb35a..b66fc3241 100644
--- a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -46,26 +46,20 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
boolean alternative = AttributeUtil.lookup(
getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, 'Q', "A10");
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, 'M', "C01,0,12222");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, 'M', "C01,0,02222");
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, 'M', alternative ? "B21,1" : "C01,0,22122");
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, 'M', alternative ? "B21,0" : "C01,0,22022");
- case Command.TYPE_REQUEST_PHOTO:
+ return switch (command.getType()) {
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(command, 'Q', "A10");
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, 'M', "C01,0,12222");
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, 'M', "C01,0,02222");
+ case Command.TYPE_ALARM_ARM -> formatCommand(command, 'M', alternative ? "B21,1" : "C01,0,22122");
+ case Command.TYPE_ALARM_DISARM -> formatCommand(command, 'M', alternative ? "B21,0" : "C01,0,22022");
+ case Command.TYPE_REQUEST_PHOTO -> {
int index = command.getInteger(Command.KEY_INDEX);
- return formatCommand(command, 'D', "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg");
- case Command.TYPE_SEND_SMS:
- return formatCommand(command, 'f', "C02,0,"
- + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
- default:
- return null;
- }
+ yield formatCommand(command, 'D', "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg");
+ }
+ case Command.TYPE_SEND_SMS -> formatCommand(command, 'f', "C02,0,"
+ + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
index 84ba75e7c..4d7171d3f 100644
--- a/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MictrackProtocolDecoder.java
@@ -65,22 +65,15 @@ public class MictrackProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int event) {
- switch (event) {
- case 0:
- return Position.ALARM_POWER_ON;
- case 5:
- return Position.ALARM_SOS;
- case 8:
- return Position.ALARM_LOW_BATTERY;
- case 9:
- return Position.ALARM_GEOFENCE_ENTER;
- case 10:
- return Position.ALARM_GEOFENCE_EXIT;
- case 12:
- return Position.ALARM_POWER_OFF;
- default:
- return null;
- }
+ return switch (event) {
+ case 0 -> Position.ALARM_POWER_ON;
+ case 5 -> Position.ALARM_SOS;
+ case 8 -> Position.ALARM_LOW_BATTERY;
+ case 9 -> Position.ALARM_GEOFENCE_ENTER;
+ case 10 -> Position.ALARM_GEOFENCE_EXIT;
+ case 12 -> Position.ALARM_POWER_OFF;
+ default -> null;
+ };
}
private void decodeLocation(Position position, String data) throws ParseException {
@@ -231,28 +224,15 @@ public class MictrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_TYPE, Integer.parseInt(fragments[1]));
switch (fragments[3]) {
- case "R0":
- decodeLocation(position, fragments[4]);
- break;
- case "R1":
- decodeNetwork(position, fragments[4], true, false, false);
- break;
- case "R2":
- case "R3":
- decodeNetwork(position, fragments[4], false, false, true);
- break;
- case "R12":
- case "R13":
- decodeNetwork(position, fragments[4], true, false, true);
- break;
- case "RH":
- decodeStatus(position, fragments[4]);
- break;
- case "Y1":
- decodeNetwork(position, fragments[4], true, true, false);
- break;
- default:
+ case "R0" -> decodeLocation(position, fragments[4]);
+ case "R1" -> decodeNetwork(position, fragments[4], true, false, false);
+ case "R2", "R3" -> decodeNetwork(position, fragments[4], false, false, true);
+ case "R12", "R13" -> decodeNetwork(position, fragments[4], true, false, true);
+ case "RH" -> decodeStatus(position, fragments[4]);
+ case "Y1" -> decodeNetwork(position, fragments[4], true, true, false);
+ default -> {
return null;
+ }
}
return position;
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;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
index 539527155..ad73e7642 100644
--- a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java
@@ -85,22 +85,18 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder {
int endIndex = buf.readUnsignedByte() + buf.readerIndex();
int key = buf.readUnsignedByte();
switch (key) {
- case 0x11:
- case 0x21:
- case 0x22:
+ case 0x11, 0x21, 0x22 -> {
body.writeByte(9 + 1); // length
body.writeByte(key);
body.writeIntLE(0); // latitude
body.writeIntLE(0); // longitude
body.writeByte(0); // address
- break;
- case 0x12:
+ }
+ case 0x12 -> {
body.writeByte(5); // length
body.writeByte(key);
body.writeIntLE((int) (System.currentTimeMillis() / 1000));
- break;
- default:
- break;
+ }
}
buf.readerIndex(endIndex);
}
@@ -401,145 +397,89 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder {
int key = buf.readUnsignedByte();
switch (key) {
- case 0x01:
- position.set("moduleNumber", buf.readUnsignedInt());
- break;
- case 0x02:
- position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedInt()));
- break;
- case 0x03:
- position.set("imei", buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
- break;
- case 0x04:
- position.set(Position.KEY_ICCID, BufferUtil.readString(buf, length));
- break;
- case 0x05:
- position.set("bleMac", ByteBufUtil.hexDump(buf.readSlice(length)));
- break;
- case 0x06:
- position.set("settingTime", buf.readUnsignedInt());
- break;
- case 0x07:
- position.set("runTimes", buf.readUnsignedInt());
- break;
- case 0x0A:
+ case 0x01 -> position.set("moduleNumber", buf.readUnsignedInt());
+ case 0x02 -> position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedInt()));
+ case 0x03 -> position.set("imei", buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
+ case 0x04 -> position.set(Position.KEY_ICCID, BufferUtil.readString(buf, length));
+ case 0x05 -> position.set("bleMac", ByteBufUtil.hexDump(buf.readSlice(length)));
+ case 0x06 -> position.set("settingTime", buf.readUnsignedInt());
+ case 0x07 -> position.set("runTimes", buf.readUnsignedInt());
+ case 0x0A -> {
position.set("interval", buf.readUnsignedMedium());
position.set("petMode", buf.readUnsignedByte());
- break;
- case 0x0D:
- position.set("passwordProtect", buf.readUnsignedInt());
- break;
- case 0x0E:
- position.set("timeZone", (int) buf.readByte());
- break;
- case 0x0F:
- position.set("enableControl", buf.readUnsignedInt());
- break;
- case 0x13:
- position.set("deviceName", BufferUtil.readString(buf, length));
- break;
- case 0x14:
+ }
+ case 0x0D -> position.set("passwordProtect", buf.readUnsignedInt());
+ case 0x0E -> position.set("timeZone", (int) buf.readByte());
+ case 0x0F -> position.set("enableControl", buf.readUnsignedInt());
+ case 0x13 -> position.set("deviceName", BufferUtil.readString(buf, length));
+ case 0x14 -> {
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- break;
- case 0x15:
+ }
+ case 0x15 -> {
position.set("bleLatitude", buf.readIntLE() * 0.0000001);
position.set("bleLongitude", buf.readIntLE() * 0.0000001);
position.set("bleLocation", BufferUtil.readString(buf, length - 8));
- break;
- case 0x17:
- position.set("gpsUrl", BufferUtil.readString(buf, length));
- break;
- case 0x18:
- position.set("lbsUrl", BufferUtil.readString(buf, length));
- break;
- case 0x1A:
- position.set("firmware", BufferUtil.readString(buf, length));
- break;
- case 0x1B:
- position.set("gsmModule", BufferUtil.readString(buf, length));
- break;
- case 0x1D:
+ }
+ case 0x17 -> position.set("gpsUrl", BufferUtil.readString(buf, length));
+ case 0x18 -> position.set("lbsUrl", BufferUtil.readString(buf, length));
+ case 0x1A -> position.set("firmware", BufferUtil.readString(buf, length));
+ case 0x1B -> position.set("gsmModule", BufferUtil.readString(buf, length));
+ case 0x1D -> {
position.set("agpsUpdate", buf.readUnsignedByte());
position.set("agpsLatitude", buf.readIntLE() * 0.0000001);
position.set("agpsLongitude", buf.readIntLE() * 0.0000001);
- break;
- case 0x30:
+ }
+ case 0x30 -> {
position.set("numberFlag", buf.readUnsignedByte());
position.set("number", BufferUtil.readString(buf, length - 1));
- break;
- case 0x31:
+ }
+ case 0x31 -> {
position.set("prefixFlag", buf.readUnsignedByte());
position.set("prefix", BufferUtil.readString(buf, length - 1));
- break;
- case 0x33:
- position.set("phoneSwitches", buf.readUnsignedByte());
- break;
- case 0x40:
- position.set("apn", BufferUtil.readString(buf, length));
- break;
- case 0x41:
- position.set("apnUser", BufferUtil.readString(buf, length));
- break;
- case 0x42:
- position.set("apnPassword", BufferUtil.readString(buf, length));
- break;
- case 0x43:
+ }
+ case 0x33 -> position.set("phoneSwitches", buf.readUnsignedByte());
+ case 0x40 -> position.set("apn", BufferUtil.readString(buf, length));
+ case 0x41 -> position.set("apnUser", BufferUtil.readString(buf, length));
+ case 0x42 -> position.set("apnPassword", BufferUtil.readString(buf, length));
+ case 0x43 -> {
buf.readUnsignedByte(); // flag
position.set("port", buf.readUnsignedShort());
position.set("server", BufferUtil.readString(buf, length - 3));
- break;
- case 0x44:
+ }
+ case 0x44 -> {
position.set("heartbeatInterval", buf.readUnsignedInt());
position.set("uploadInterval", buf.readUnsignedInt());
position.set("uploadLazyInterval", buf.readUnsignedInt());
- break;
- case 0x47:
- position.set("deviceId", BufferUtil.readString(buf, length));
- break;
- case 0x4E:
- position.set("gsmBand", buf.readUnsignedByte());
- break;
- case 0x50:
- position.set("powerAlert", buf.readUnsignedInt());
- break;
- case 0x51:
- position.set("geoAlert", buf.readUnsignedInt());
- break;
- case 0x53:
- position.set("motionAlert", buf.readUnsignedInt());
- break;
- case 0x5C:
+ }
+ case 0x47 -> position.set("deviceId", BufferUtil.readString(buf, length));
+ case 0x4E -> position.set("gsmBand", buf.readUnsignedByte());
+ case 0x50 -> position.set("powerAlert", buf.readUnsignedInt());
+ case 0x51 -> position.set("geoAlert", buf.readUnsignedInt());
+ case 0x53 -> position.set("motionAlert", buf.readUnsignedInt());
+ case 0x5C -> {
position.set("barkLevel", buf.readUnsignedByte());
position.set("barkInterval", buf.readUnsignedInt());
- break;
- case 0x61:
- position.set("msisdn", BufferUtil.readString(buf, length));
- break;
- case 0x62:
+ }
+ case 0x61 -> position.set("msisdn", BufferUtil.readString(buf, length));
+ case 0x62 -> {
position.set("wifiWhitelist", buf.readUnsignedByte());
position.set("wifiWhitelistMac", ByteBufUtil.hexDump(buf.readSlice(6)));
- break;
- case 0x64:
+ }
+ case 0x64 -> {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set("networkBand", buf.readUnsignedInt());
position.set(Position.KEY_OPERATOR, BufferUtil.readString(buf, length - 5));
- break;
- case 0x65:
+ }
+ case 0x65 -> {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set("networkStatus", buf.readUnsignedByte());
position.set("serverStatus", buf.readUnsignedByte());
position.set("networkPlmn", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("homePlmn", ByteBufUtil.hexDump(buf.readSlice(6)));
- break;
- case 0x66:
- position.set("imsi", BufferUtil.readString(buf, length));
- break;
- case 0x75:
- position.set("extraEnableControl", buf.readUnsignedInt());
- break;
- default:
- break;
+ }
+ case 0x66 -> position.set("imsi", BufferUtil.readString(buf, length));
+ case 0x75 -> position.set("extraEnableControl", buf.readUnsignedInt());
}
buf.readerIndex(endIndex);
diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
index d7600ecbb..314562bd6 100644
--- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java
@@ -59,24 +59,16 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(String type) {
- switch (type) {
- case "T8":
- return Position.ALARM_LOW_BATTERY;
- case "T9":
- return Position.ALARM_VIBRATION;
- case "T10":
- return Position.ALARM_POWER_CUT;
- case "T11":
- return Position.ALARM_LOW_POWER;
- case "T12":
- return Position.ALARM_GEOFENCE_EXIT;
- case "T13":
- return Position.ALARM_OVERSPEED;
- case "T15":
- return Position.ALARM_TOW;
- default:
- return null;
- }
+ return switch (type) {
+ case "T8" -> Position.ALARM_LOW_BATTERY;
+ case "T9" -> Position.ALARM_VIBRATION;
+ case "T10" -> Position.ALARM_POWER_CUT;
+ case "T11" -> Position.ALARM_LOW_POWER;
+ case "T12" -> Position.ALARM_GEOFENCE_EXIT;
+ case "T13" -> Position.ALARM_OVERSPEED;
+ case "T15" -> Position.ALARM_TOW;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Mta6ProtocolDecoder.java
index 9704cf099..c76588d38 100644
--- a/src/main/java/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -75,21 +75,11 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
public float readFloat(ByteBuf buf) {
switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) {
- case 0:
- previousFloat = buf.readInt() << 2;
- break;
- case 1:
- previousFloat = (previousFloat & 0xffffff00) + ((buf.readUnsignedByte() & 0x3f) << 2);
- break;
- case 2:
- previousFloat = (previousFloat & 0xffff0000) + ((buf.readUnsignedShort() & 0x3fff) << 2);
- break;
- case 3:
- previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2);
- break;
- default:
- LOGGER.warn("MTA6 float decoding error", new IllegalArgumentException());
- break;
+ case 0 -> previousFloat = buf.readInt() << 2;
+ case 1 -> previousFloat = (previousFloat & 0xffffff00) + ((buf.readUnsignedByte() & 0x3f) << 2);
+ case 2 -> previousFloat = (previousFloat & 0xffff0000) + ((buf.readUnsignedShort() & 0x3fff) << 2);
+ case 3 -> previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2);
+ default -> LOGGER.warn("MTA6 float decoding error");
}
return Float.intBitsToFloat(previousFloat);
}
diff --git a/src/main/java/org/traccar/protocol/NavigilProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavigilProtocolDecoder.java
index 6dadbc559..5d3bae8e8 100644
--- a/src/main/java/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -287,22 +287,15 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
sendAcknowledgment(channel, sequenceNumber);
}
- switch (messageId) {
- case MSG_UNIT_REPORT:
- return parseUnitReport(deviceSession, buf, sequenceNumber);
- case MSG_TG2_REPORT:
- return parseTg2Report(deviceSession, buf, sequenceNumber);
- case MSG_POSITION_REPORT:
- return parsePositionReport(deviceSession, buf, sequenceNumber, timestamp);
- case MSG_POSITION_REPORT_2:
- return parsePositionReport2(deviceSession, buf, sequenceNumber, timestamp);
- case MSG_SNAPSHOT4:
- return parseSnapshot4(deviceSession, buf, sequenceNumber);
- case MSG_TRACKING_DATA:
- return parseTrackingData(deviceSession, buf, sequenceNumber, timestamp);
- default:
- return null;
- }
+ return switch (messageId) {
+ case MSG_UNIT_REPORT -> parseUnitReport(deviceSession, buf, sequenceNumber);
+ case MSG_TG2_REPORT -> parseTg2Report(deviceSession, buf, sequenceNumber);
+ case MSG_POSITION_REPORT -> parsePositionReport(deviceSession, buf, sequenceNumber, timestamp);
+ case MSG_POSITION_REPORT_2 -> parsePositionReport2(deviceSession, buf, sequenceNumber, timestamp);
+ case MSG_SNAPSHOT4 -> parseSnapshot4(deviceSession, buf, sequenceNumber);
+ case MSG_TRACKING_DATA -> parseTrackingData(deviceSession, buf, sequenceNumber, timestamp);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/NavisFrameDecoder.java b/src/main/java/org/traccar/protocol/NavisFrameDecoder.java
index 8a0bb0b9a..9d560d19c 100644
--- a/src/main/java/org/traccar/protocol/NavisFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/NavisFrameDecoder.java
@@ -57,17 +57,12 @@ public class NavisFrameDecoder extends BaseFrameDecoder {
String type = buf.toString(buf.readerIndex(), 2, StandardCharsets.US_ASCII);
switch (type) {
// FLEX 1.0
- case "~A":
- length = flexDataSize * buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH) + 1 + 1;
- break;
- case "~T":
- length = flexDataSize + 4 + 1;
- break;
- case "~C":
- length = flexDataSize + 1;
- break;
+ case "~A" -> length = flexDataSize * buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH) + 1 + 1;
+ case "~T" -> length = flexDataSize + 4 + 1;
+ case "~C" -> length = flexDataSize + 1;
+
// FLEX 2.0 (Extra packages)
- case "~E":
+ case "~E" -> {
length++;
for (int i = 0; i < buf.getByte(buf.readerIndex() + FLEX_HEADER_LENGTH); i++) {
if (buf.readableBytes() > FLEX_HEADER_LENGTH + length + 1) {
@@ -77,12 +72,11 @@ public class NavisFrameDecoder extends BaseFrameDecoder {
}
}
length++;
- break;
- case "~X":
- length = buf.getUnsignedShortLE(buf.readerIndex() + FLEX_HEADER_LENGTH) + 4 + 1;
- break;
- default:
+ }
+ case "~X" -> length = buf.getUnsignedShortLE(buf.readerIndex() + FLEX_HEADER_LENGTH) + 4 + 1;
+ default -> {
return null;
+ }
}
if (buf.readableBytes() >= FLEX_HEADER_LENGTH + length) {
diff --git a/src/main/java/org/traccar/protocol/NavisProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavisProtocolDecoder.java
index 77158b315..8a0566754 100644
--- a/src/main/java/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NavisProtocolDecoder.java
@@ -317,136 +317,90 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
switch (i) {
- case 0:
- position.set(Position.KEY_INDEX, buf.readUnsignedIntLE());
- break;
- case 1:
- position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
- break;
- case 3:
+ case 0 -> position.set(Position.KEY_INDEX, buf.readUnsignedIntLE());
+ case 1 -> position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
+ case 3 -> {
short armedStatus = buf.readUnsignedByte();
position.set(Position.KEY_ARMED, BitUtil.check(armedStatus, 0));
if (BitUtil.check(armedStatus, 1)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
- break;
- case 4:
+ }
+ case 4 -> {
status = buf.readUnsignedByte();
position.set(Position.KEY_STATUS, status);
- break;
- case 5:
+ }
+ case 5 -> {
int status2 = buf.readUnsignedByte();
position.set(Position.KEY_STATUS, (short) (BitUtil.to(status, 8) | (status2 << 8)));
- break;
- case 6:
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case 7:
+ }
+ case 6 -> position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ case 7 -> {
int navSensorState = buf.readUnsignedByte();
position.setValid(BitUtil.check(navSensorState, 1));
position.set(Position.KEY_SATELLITES, BitUtil.from(navSensorState, 2));
- break;
- case 8:
- position.setTime(new DateBuilder(new Date(buf.readUnsignedIntLE() * 1000)).getDate());
- break;
- case 9:
- position.setLatitude(buf.readIntLE() / 600000.0);
- break;
- case 10:
- position.setLongitude(buf.readIntLE() / 600000.0);
- break;
- case 11:
- position.setAltitude(buf.readIntLE() * 0.1);
- break;
- case 12:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE()));
- break;
- case 13:
- position.setCourse(buf.readUnsignedShortLE());
- break;
- case 14:
- position.set(Position.KEY_ODOMETER, buf.readFloatLE() * 1000);
- break;
- case 15:
- position.set(Position.KEY_DISTANCE, buf.readFloatLE() * 1000);
- break;
- case 18:
- position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001);
- break;
- case 19:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
- break;
- case 20:
- case 21:
- case 22:
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- position.set(Position.PREFIX_ADC + (i - 19), buf.readUnsignedShortLE());
- break;
- case 28:
+ }
+ case 8 -> position.setTime(new DateBuilder(new Date(buf.readUnsignedIntLE() * 1000)).getDate());
+ case 9 -> position.setLatitude(buf.readIntLE() / 600000.0);
+ case 10 -> position.setLongitude(buf.readIntLE() / 600000.0);
+ case 11 -> position.setAltitude(buf.readIntLE() * 0.1);
+ case 12 -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE()));
+ case 13 -> position.setCourse(buf.readUnsignedShortLE());
+ case 14 -> position.set(Position.KEY_ODOMETER, buf.readFloatLE() * 1000);
+ case 15 -> position.set(Position.KEY_DISTANCE, buf.readFloatLE() * 1000);
+ case 18 -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001);
+ case 19 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
+ case 20, 21, 22, 23, 24, 25, 26, 27 ->
+ position.set(Position.PREFIX_ADC + (i - 19), buf.readUnsignedShortLE());
+ case 28 -> {
input = buf.readUnsignedByte();
position.set(Position.KEY_INPUT, input);
for (int k = 0; k < 8; k++) {
position.set(Position.PREFIX_IN + (k + 1), BitUtil.check(input, k));
}
- break;
- case 29:
+ }
+ case 29 -> {
short input2 = buf.readUnsignedByte();
position.set(Position.KEY_INPUT, (short) (BitUtil.to(input, 8) | (input2 << 8)));
for (int k = 0; k < 8; k++) {
position.set(Position.PREFIX_IN + (k + 9), BitUtil.check(input2, k));
}
- break;
- case 30:
+ }
+ case 30 -> {
output = buf.readUnsignedByte();
position.set(Position.KEY_OUTPUT, output);
for (int k = 0; k < 8; k++) {
position.set(Position.PREFIX_OUT + (k + 1), BitUtil.check(output, k));
}
- break;
- case 31:
+ }
+ case 31 -> {
short output2 = buf.readUnsignedByte();
position.set(Position.KEY_OUTPUT, (short) (BitUtil.to(output, 8) | (output2 << 8)));
for (int k = 0; k < 8; k++) {
position.set(Position.PREFIX_OUT + (k + 9), BitUtil.check(output2, k));
}
- break;
- case 36:
- position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
- break;
- case 44:
- case 45:
- case 46:
- case 47:
- case 48:
- case 49:
- case 50:
- case 51:
- position.set(Position.PREFIX_TEMP + (i - 43), buf.readByte());
- break;
- case 68:
- position.set("can-speed", buf.readUnsignedByte());
- break;
+ }
+ case 36 -> position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
+ case 44, 45, 46, 47, 48, 49, 50, 51 -> position.set(Position.PREFIX_TEMP + (i - 43), buf.readByte());
+ case 68 -> position.set("can-speed", buf.readUnsignedByte());
+
// FLEX 2.0
- case 69:
+ case 69 -> {
int satVisible = 0;
for (int k = 0; k < 8; k++) {
satVisible += buf.readUnsignedByte();
}
position.set(Position.KEY_SATELLITES_VISIBLE, satVisible);
- break;
- case 70:
+ }
+ case 70 -> {
position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
position.set(Position.KEY_PDOP, buf.readUnsignedByte() * 0.1);
- break;
- default:
+ }
+ default -> {
if (i < FLEX_FIELDS_SIZES.length) {
buf.skipBytes(FLEX_FIELDS_SIZES[i]);
}
- break;
+ }
}
}
@@ -616,17 +570,15 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
} else {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession != null) {
- switch (type) {
- case "*>A":
- return processNtcbArray(deviceSession, channel, buf);
- case "*>T":
- return processNtcbSingle(deviceSession, channel, buf);
- case "*>F":
+ return switch (type) {
+ case "*>A" -> processNtcbArray(deviceSession, channel, buf);
+ case "*>T" -> processNtcbSingle(deviceSession, channel, buf);
+ case "*>F" -> {
buf.skipBytes(3);
- return processFlexNegotiation(channel, buf);
- default:
- break;
- }
+ yield processFlexNegotiation(channel, buf);
+ }
+ default -> null;
+ };
}
}
@@ -644,23 +596,16 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession != null) {
- switch (type) {
+ return switch (type) {
// FLEX 1.0
- case "~A":
- return processFlexArray(this::parseFlexPosition, type, deviceSession, channel, buf);
- case "~T":
- case "~C":
- return processFlexSingle(this::parseFlexPosition, type, deviceSession, channel, buf);
+ case "~A" -> processFlexArray(this::parseFlexPosition, type, deviceSession, channel, buf);
+ case "~T", "~C" -> processFlexSingle(this::parseFlexPosition, type, deviceSession, channel, buf);
// FLEX 2.0 (extra packages)
- case "~E":
- return processFlexArray(this::parseFlex20Position, type, deviceSession, channel, buf);
- case "~X":
- return processFlexSingle(this::parseFlex20Position, type, deviceSession, channel, buf);
- default:
- break;
- }
+ case "~E" -> processFlexArray(this::parseFlex20Position, type, deviceSession, channel, buf);
+ case "~X" -> processFlexSingle(this::parseFlex20Position, type, deviceSession, channel, buf);
+ default -> null;
+ };
}
-
return null;
}
diff --git a/src/main/java/org/traccar/protocol/NdtpV6ProtocolEncoder.java b/src/main/java/org/traccar/protocol/NdtpV6ProtocolEncoder.java
index 7aac8658a..eac6de133 100644
--- a/src/main/java/org/traccar/protocol/NdtpV6ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/NdtpV6ProtocolEncoder.java
@@ -27,16 +27,12 @@ public class NdtpV6ProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_IDENTIFICATION:
- return "BB+IDNT";
- case Command.TYPE_REBOOT_DEVICE:
- return "BB+RESET";
- case Command.TYPE_POSITION_SINGLE:
- return "BB+RRCD";
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_IDENTIFICATION -> "BB+IDNT";
+ case Command.TYPE_REBOOT_DEVICE -> "BB+RESET";
+ case Command.TYPE_POSITION_SINGLE -> "BB+RRCD";
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
index 35614ccca..d53271778 100644
--- a/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NiotProtocolDecoder.java
@@ -99,14 +99,8 @@ public class NiotProtocolDecoder extends BaseProtocolDecoder {
int statusX = buf.readUnsignedByte();
position.setValid(BitUtil.check(statusX, 7));
switch (BitUtil.between(statusX, 3, 5)) {
- case 0b10:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case 0b01:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- default:
- break;
+ case 0b10 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case 0b01 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
diff --git a/src/main/java/org/traccar/protocol/NoranProtocolDecoder.java b/src/main/java/org/traccar/protocol/NoranProtocolDecoder.java
index 53b58f9b6..80ac587e5 100644
--- a/src/main/java/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NoranProtocolDecoder.java
@@ -90,20 +90,10 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
short alarm = buf.readUnsignedByte();
switch (alarm) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
- break;
- case 9:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
- break;
- default:
- break;
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ case 3 -> position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
+ case 9 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
}
if (newFormat) {
diff --git a/src/main/java/org/traccar/protocol/NoranProtocolEncoder.java b/src/main/java/org/traccar/protocol/NoranProtocolEncoder.java
index e02a1313c..c8043224d 100644
--- a/src/main/java/org/traccar/protocol/NoranProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/NoranProtocolEncoder.java
@@ -49,21 +49,17 @@ public class NoranProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return encodeContent("*KW,000,000,000000#");
- case Command.TYPE_POSITION_PERIODIC:
+ return switch (command.getType()) {
+ case Command.TYPE_POSITION_SINGLE -> encodeContent("*KW,000,000,000000#");
+ case Command.TYPE_POSITION_PERIODIC -> {
int interval = command.getInteger(Command.KEY_FREQUENCY);
- return encodeContent("*KW,000,002,000000," + interval + "#");
- case Command.TYPE_POSITION_STOP:
- return encodeContent("*KW,000,002,000000,0#");
- case Command.TYPE_ENGINE_STOP:
- return encodeContent("*KW,000,007,000000,0#");
- case Command.TYPE_ENGINE_RESUME:
- return encodeContent("*KW,000,007,000000,1#");
- default:
- return null;
- }
+ yield encodeContent("*KW,000,002,000000," + interval + "#");
+ }
+ case Command.TYPE_POSITION_STOP -> encodeContent("*KW,000,002,000000,0#");
+ case Command.TYPE_ENGINE_STOP -> encodeContent("*KW,000,007,000000,0#");
+ case Command.TYPE_ENGINE_RESUME -> encodeContent("*KW,000,007,000000,1#");
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/NyitechProtocolDecoder.java b/src/main/java/org/traccar/protocol/NyitechProtocolDecoder.java
index 49bc5b824..0366cffcd 100644
--- a/src/main/java/org/traccar/protocol/NyitechProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/NyitechProtocolDecoder.java
@@ -63,18 +63,13 @@ public class NyitechProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int type) {
- switch (type) {
- case 0x09:
- return Position.ALARM_ACCELERATION;
- case 0x0a:
- return Position.ALARM_BRAKING;
- case 0x0b:
- return Position.ALARM_CORNERING;
- case 0x0e:
- return Position.ALARM_SOS;
- default:
- return null;
- }
+ return switch (type) {
+ case 0x09 -> Position.ALARM_ACCELERATION;
+ case 0x0a -> Position.ALARM_BRAKING;
+ case 0x0b -> Position.ALARM_CORNERING;
+ case 0x0e -> Position.ALARM_SOS;
+ default -> null;
+ };
}
@Override
@@ -121,18 +116,10 @@ public class NyitechProtocolDecoder extends BaseProtocolDecoder {
int pid = buf.readUnsignedShortLE();
int length = buf.readUnsignedByte();
switch (length) {
- case 1:
- position.add(ObdDecoder.decodeData(pid, buf.readByte(), true));
- break;
- case 2:
- position.add(ObdDecoder.decodeData(pid, buf.readShortLE(), true));
- break;
- case 4:
- position.add(ObdDecoder.decodeData(pid, buf.readIntLE(), true));
- break;
- default:
- buf.skipBytes(length);
- break;
+ case 1 -> position.add(ObdDecoder.decodeData(pid, buf.readByte(), true));
+ case 2 -> position.add(ObdDecoder.decodeData(pid, buf.readShortLE(), true));
+ case 4 -> position.add(ObdDecoder.decodeData(pid, buf.readIntLE(), true));
+ default -> buf.skipBytes(length);
}
}
}
diff --git a/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java b/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java
index 7ed13d647..48303a65d 100644
--- a/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OrbcommProtocolDecoder.java
@@ -85,24 +85,14 @@ public class OrbcommProtocolDecoder extends BaseProtocolDecoder {
JsonObject field = fields.getJsonObject(j);
String value = field.getString("Value");
switch (field.getString("Name").toLowerCase()) {
- case "eventtime":
- position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
- break;
- case "latitude":
- position.setLatitude(Integer.parseInt(value) / 60000.0);
- break;
- case "longitude":
- position.setLongitude(Integer.parseInt(value) / 60000.0);
- break;
- case "speed":
- position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
- break;
- case "heading":
+ case "eventtime" -> position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
+ case "latitude" -> position.setLatitude(Integer.parseInt(value) / 60000.0);
+ case "longitude" -> position.setLongitude(Integer.parseInt(value) / 60000.0);
+ case "speed" -> position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
+ case "heading" -> {
int heading = Integer.parseInt(value);
position.setCourse(heading <= 360 ? heading : 0);
- break;
- default:
- break;
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java
index c8968023a..b044b9596 100644
--- a/src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -151,15 +151,9 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
position.set(entry.getKey(), Double.parseDouble(value));
} catch (NumberFormatException e) {
switch (value) {
- case "true":
- position.set(entry.getKey(), true);
- break;
- case "false":
- position.set(entry.getKey(), false);
- break;
- default:
- position.set(entry.getKey(), value);
- break;
+ case "true" -> position.set(entry.getKey(), true);
+ case "false" -> position.set(entry.getKey(), false);
+ default -> position.set(entry.getKey(), value);
}
}
break;
diff --git a/src/main/java/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/main/java/org/traccar/protocol/OwnTracksProtocolDecoder.java
index e54d07fa7..f04c4a295 100644
--- a/src/main/java/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/OwnTracksProtocolDecoder.java
@@ -167,31 +167,15 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder {
private void setEventOrAlarm(Position position, String trigger, Integer reportType) {
switch (trigger) {
- case "9":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "1":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
- break;
- case "i":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "I":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "E":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
- break;
- case "e":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "!":
- position.set(Position.KEY_ALARM, Position.ALARM_TOW);
- break;
- case "s":
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case "h":
+ case "9" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case "1" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
+ case "i" -> position.set(Position.KEY_IGNITION, true);
+ case "I" -> position.set(Position.KEY_IGNITION, false);
+ case "E" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
+ case "e" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case "!" -> position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ case "s" -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ case "h" -> {
switch (reportType) {
case 0:
case 3:
@@ -207,9 +191,7 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder {
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
break;
}
- break;
- default:
- break;
+ }
}
}
}
diff --git a/src/main/java/org/traccar/protocol/PacificTrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/PacificTrackProtocolDecoder.java
index 7079745be..87ae74727 100644
--- a/src/main/java/org/traccar/protocol/PacificTrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/PacificTrackProtocolDecoder.java
@@ -94,101 +94,45 @@ public class PacificTrackProtocolDecoder extends BaseProtocolDecoder {
int fieldPrefix = BitUtil.from(field, 5);
if (fieldPrefix < 0b100) {
switch (BitUtil.between(field, 2, 5)) {
- case 0b000:
- position.set("bus", BitUtil.to(field, 2));
- break;
- case 0b001:
- position.set("currentGear", BitUtil.to(field, 2));
- break;
- default:
- break;
+ case 0b000 -> position.set("bus", BitUtil.to(field, 2));
+ case 0b001 -> position.set("currentGear", BitUtil.to(field, 2));
}
} else if (fieldPrefix < 0b101) {
switch (BitUtil.to(field, 5)) {
- case 0b00000:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
- break;
- case 0b00001:
- position.set(Position.KEY_RPM, buf.readUnsignedByte() * 32);
- break;
- case 0b00011:
- position.set("oilPressure", buf.readUnsignedByte() * 4);
- break;
- case 0b00100:
- position.set("oilLevel", buf.readUnsignedByte() * 0.4);
- break;
- case 0b00101:
- position.set("oilTemp", buf.readUnsignedByte() - 40);
- break;
- case 0b00110:
- position.set("coolantLevel", buf.readUnsignedByte() * 0.4);
- break;
- case 0b00111:
- position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
- break;
- case 0b01000:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
- break;
- case 0b01001:
- position.set("defLevel", buf.readUnsignedByte() * 0.4);
- break;
- case 0b01010:
- position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte());
- break;
- case 0b01011:
- position.set("barometer", buf.readUnsignedByte() * 0.5);
- break;
- case 0b01100:
- position.set("intakeManifoldTemp", buf.readUnsignedByte() - 40);
- break;
- case 0b01101:
- position.set("fuelTankTemp", buf.readUnsignedByte() - 40);
- break;
- case 0b01110:
- position.set("intercoolerTemp", buf.readUnsignedByte() - 40);
- break;
- case 0b01111:
- position.set("turboOilTemp", buf.readUnsignedByte() - 40);
- break;
- case 0b10000:
- position.set("transOilTemp", buf.readUnsignedByte() - 40);
- break;
- default:
- buf.readUnsignedByte();
- break;
+ case 0b00000 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
+ case 0b00001 -> position.set(Position.KEY_RPM, buf.readUnsignedByte() * 32);
+ case 0b00011 -> position.set("oilPressure", buf.readUnsignedByte() * 4);
+ case 0b00100 -> position.set("oilLevel", buf.readUnsignedByte() * 0.4);
+ case 0b00101 -> position.set("oilTemp", buf.readUnsignedByte() - 40);
+ case 0b00110 -> position.set("coolantLevel", buf.readUnsignedByte() * 0.4);
+ case 0b00111 -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
+ case 0b01000 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
+ case 0b01001 -> position.set("defLevel", buf.readUnsignedByte() * 0.4);
+ case 0b01010 -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte());
+ case 0b01011 -> position.set("barometer", buf.readUnsignedByte() * 0.5);
+ case 0b01100 -> position.set("intakeManifoldTemp", buf.readUnsignedByte() - 40);
+ case 0b01101 -> position.set("fuelTankTemp", buf.readUnsignedByte() - 40);
+ case 0b01110 -> position.set("intercoolerTemp", buf.readUnsignedByte() - 40);
+ case 0b01111 -> position.set("turboOilTemp", buf.readUnsignedByte() - 40);
+ case 0b10000 -> position.set("transOilTemp", buf.readUnsignedByte() - 40);
+ default -> buf.readUnsignedByte();
}
} else if (fieldPrefix < 0b110) {
switch (BitUtil.to(field, 5)) {
- case 0b00010:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() / 512.0);
- break;
- case 0b00011:
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort() * 0.03125 - 273);
- break;
- default:
- buf.readUnsignedShort();
- break;
+ case 0b00010 -> position.set(
+ Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() / 512.0);
+ case 0b00011 -> position.set(
+ Position.PREFIX_TEMP + 1, buf.readUnsignedShort() * 0.03125 - 273);
+ default -> buf.readUnsignedShort();
}
} else if (fieldPrefix < 0b111) {
switch (BitUtil.to(field, 5)) {
- case 0b00000:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
- break;
- case 0b00001:
- position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 180);
- break;
- case 0b00010:
- position.set("idleHours", buf.readUnsignedInt() * 180);
- break;
- case 0b00100:
- position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5);
- break;
- case 0b00101:
- position.set("fuelUsedIdle", buf.readUnsignedInt() * 0.5);
- break;
- default:
- buf.readUnsignedInt();
- break;
+ case 0b00000 -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
+ case 0b00001 -> position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 180);
+ case 0b00010 -> position.set("idleHours", buf.readUnsignedInt() * 180);
+ case 0b00100 -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5);
+ case 0b00101 -> position.set("fuelUsedIdle", buf.readUnsignedInt() * 0.5);
+ default -> buf.readUnsignedInt();
}
} else {
buf.skipBytes(buf.readUnsignedByte());
diff --git a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
index 6ee95d18a..aca5d3eb6 100644
--- a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
@@ -125,15 +125,8 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext()) {
int event = parser.nextInt();
switch (event) {
- case 11317:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 11319:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- default:
- break;
-
+ case 11317 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 11319 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
}
position.set(Position.KEY_EVENT, event);
}
diff --git a/src/main/java/org/traccar/protocol/PortmanProtocolEncoder.java b/src/main/java/org/traccar/protocol/PortmanProtocolEncoder.java
index eb3115db8..22c4c3127 100644
--- a/src/main/java/org/traccar/protocol/PortmanProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/PortmanProtocolEncoder.java
@@ -28,14 +28,11 @@ public class PortmanProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "&&%s,XA5\r\n", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "&&%s,XA6\r\n", Command.KEY_UNIQUE_ID);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, "&&%s,XA5\r\n", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "&&%s,XA6\r\n", Command.KEY_UNIQUE_ID);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/PretraceProtocolEncoder.java b/src/main/java/org/traccar/protocol/PretraceProtocolEncoder.java
index a109e7a07..354fc5992 100644
--- a/src/main/java/org/traccar/protocol/PretraceProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/PretraceProtocolEncoder.java
@@ -36,15 +36,13 @@ public class PretraceProtocolEncoder extends BaseProtocolEncoder {
String uniqueId = getUniqueId(command.getDeviceId());
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(uniqueId, command.getString(Command.KEY_DATA));
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(
- uniqueId, String.format("D221%1$d,%1$d,,", command.getInteger(Command.KEY_FREQUENCY)));
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(
+ uniqueId, command.getString(Command.KEY_DATA));
+ case Command.TYPE_POSITION_PERIODIC -> formatCommand(
+ uniqueId, String.format("D221%1$d,%1$d,,", command.getInteger(Command.KEY_FREQUENCY)));
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/PstProtocolEncoder.java b/src/main/java/org/traccar/protocol/PstProtocolEncoder.java
index f3d193324..ad7186630 100644
--- a/src/main/java/org/traccar/protocol/PstProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/PstProtocolEncoder.java
@@ -49,14 +49,11 @@ public class PstProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return encodeContent(command.getDeviceId(), 0x0002, 0xffff, 0xffff);
- case Command.TYPE_ENGINE_RESUME:
- return encodeContent(command.getDeviceId(), 0x0001, 0xffff, 0xffff);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP -> encodeContent(command.getDeviceId(), 0x0002, 0xffff, 0xffff);
+ case Command.TYPE_ENGINE_RESUME -> encodeContent(command.getDeviceId(), 0x0001, 0xffff, 0xffff);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Pt502ProtocolDecoder.java
index 2a6a81a65..2e88186b8 100644
--- a/src/main/java/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -66,28 +66,18 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(String value) {
- switch (value) {
- case "IN1":
- return Position.ALARM_SOS;
- case "GOF":
- return Position.ALARM_GEOFENCE;
- case "TOW":
- return Position.ALARM_TOW;
- case "HDA":
- return Position.ALARM_ACCELERATION;
- case "HDB":
- return Position.ALARM_BRAKING;
- case "FDA":
- return Position.ALARM_FATIGUE_DRIVING;
- case "SKA":
- return Position.ALARM_VIBRATION;
- case "PMA":
- return Position.ALARM_MOVEMENT;
- case "CPA":
- return Position.ALARM_POWER_CUT;
- default:
- return null;
- }
+ return switch (value) {
+ case "IN1" -> Position.ALARM_SOS;
+ case "GOF" -> Position.ALARM_GEOFENCE;
+ case "TOW" -> Position.ALARM_TOW;
+ case "HDA" -> Position.ALARM_ACCELERATION;
+ case "HDB" -> Position.ALARM_BRAKING;
+ case "FDA" -> Position.ALARM_FATIGUE_DRIVING;
+ case "SKA" -> Position.ALARM_VIBRATION;
+ case "PMA" -> Position.ALARM_MOVEMENT;
+ case "CPA" -> Position.ALARM_POWER_CUT;
+ default -> null;
+ };
}
private Position decodePosition(Channel channel, SocketAddress remoteAddress, String sentence) {
diff --git a/src/main/java/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Pt502ProtocolEncoder.java
index 364ecae86..2530ae131 100644
--- a/src/main/java/org/traccar/protocol/Pt502ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Pt502ProtocolEncoder.java
@@ -44,20 +44,15 @@ public class Pt502ProtocolEncoder extends StringProtocolEncoder implements Strin
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "%s\r\n", Command.KEY_DATA);
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "#OPC%s,%s\r\n", Command.KEY_INDEX, Command.KEY_DATA);
- case Command.TYPE_SET_TIMEZONE:
- return formatCommand(command, "#TMZ%s\r\n", Command.KEY_TIMEZONE);
- case Command.TYPE_ALARM_SPEED:
- return formatCommand(command, "#SPD%s\r\n", Command.KEY_DATA);
- case Command.TYPE_REQUEST_PHOTO:
- return formatCommand(command, "#PHO\r\n");
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(command, "%s\r\n", Command.KEY_DATA);
+ case Command.TYPE_OUTPUT_CONTROL ->
+ formatCommand(command, "#OPC%s,%s\r\n", Command.KEY_INDEX, Command.KEY_DATA);
+ case Command.TYPE_SET_TIMEZONE -> formatCommand(command, "#TMZ%s\r\n", Command.KEY_TIMEZONE);
+ case Command.TYPE_ALARM_SPEED -> formatCommand(command, "#SPD%s\r\n", Command.KEY_DATA);
+ case Command.TYPE_REQUEST_PHOTO -> formatCommand(command, "#PHO\r\n");
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/RetranslatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/RetranslatorProtocolDecoder.java
index afbf7e511..6296eb5b9 100644
--- a/src/main/java/org/traccar/protocol/RetranslatorProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/RetranslatorProtocolDecoder.java
@@ -81,22 +81,14 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_SATELLITES, buf.readByte());
} else {
switch (dataType) {
- case 1:
+ case 1 -> {
int len = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x00) - buf.readerIndex();
position.set(name, buf.readCharSequence(len, StandardCharsets.US_ASCII).toString());
buf.readByte();
- break;
- case 3:
- position.set(name, buf.readInt());
- break;
- case 4:
- position.set(name, buf.readDoubleLE());
- break;
- case 5:
- position.set(name, buf.readLong());
- break;
- default:
- break;
+ }
+ case 3 -> position.set(name, buf.readInt());
+ case 4 -> position.set(name, buf.readDoubleLE());
+ case 5 -> position.set(name, buf.readLong());
}
}
diff --git a/src/main/java/org/traccar/protocol/RoboTrackFrameDecoder.java b/src/main/java/org/traccar/protocol/RoboTrackFrameDecoder.java
index 85ed6c76f..237519a23 100644
--- a/src/main/java/org/traccar/protocol/RoboTrackFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/RoboTrackFrameDecoder.java
@@ -23,22 +23,15 @@ import org.traccar.BaseFrameDecoder;
public class RoboTrackFrameDecoder extends BaseFrameDecoder {
private int messageLength(ByteBuf buf) {
- switch (buf.getUnsignedByte(buf.readerIndex())) {
- case RoboTrackProtocolDecoder.MSG_ID:
- return 69;
- case RoboTrackProtocolDecoder.MSG_ACK:
- return 3;
- case RoboTrackProtocolDecoder.MSG_GPS:
- case RoboTrackProtocolDecoder.MSG_GSM:
- case RoboTrackProtocolDecoder.MSG_IMAGE_START:
- return 24;
- case RoboTrackProtocolDecoder.MSG_IMAGE_DATA:
- return 8 + buf.getUnsignedShortLE(buf.readerIndex() + 1);
- case RoboTrackProtocolDecoder.MSG_IMAGE_END:
- return 6;
- default:
- return Integer.MAX_VALUE;
- }
+ return switch (buf.getUnsignedByte(buf.readerIndex())) {
+ case RoboTrackProtocolDecoder.MSG_ID -> 69;
+ case RoboTrackProtocolDecoder.MSG_ACK -> 3;
+ case RoboTrackProtocolDecoder.MSG_GPS, RoboTrackProtocolDecoder.MSG_GSM,
+ RoboTrackProtocolDecoder.MSG_IMAGE_START -> 24;
+ case RoboTrackProtocolDecoder.MSG_IMAGE_DATA -> 8 + buf.getUnsignedShortLE(buf.readerIndex() + 1);
+ case RoboTrackProtocolDecoder.MSG_IMAGE_END -> 6;
+ default -> Integer.MAX_VALUE;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/main/java/org/traccar/protocol/RuptelaProtocolDecoder.java
index e1efb5757..057c593d3 100644
--- a/src/main/java/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -64,34 +64,28 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_TYPE, type);
- switch (type) {
- case MSG_DEVICE_CONFIGURATION:
- case MSG_DEVICE_VERSION:
- case MSG_FIRMWARE_UPDATE:
- case MSG_SMS_VIA_GPRS_RESPONSE:
+ return switch (type) {
+ case MSG_DEVICE_CONFIGURATION, MSG_DEVICE_VERSION, MSG_FIRMWARE_UPDATE, MSG_SMS_VIA_GPRS_RESPONSE -> {
position.set(Position.KEY_RESULT,
buf.toString(buf.readerIndex(), buf.readableBytes() - 2, StandardCharsets.US_ASCII).trim());
- return position;
- case MSG_SET_IO:
+ yield position;
+ }
+ case MSG_SET_IO -> {
position.set(Position.KEY_RESULT,
String.valueOf(buf.readUnsignedByte()));
- return position;
- default:
- return null;
- }
+ yield position;
+ }
+ default -> null;
+ };
}
private long readValue(ByteBuf buf, int length, boolean signed) {
- switch (length) {
- case 1:
- return signed ? buf.readByte() : buf.readUnsignedByte();
- case 2:
- return signed ? buf.readShort() : buf.readUnsignedShort();
- case 4:
- return signed ? buf.readInt() : buf.readUnsignedInt();
- default:
- return buf.readLong();
- }
+ return switch (length) {
+ case 1 -> signed ? buf.readByte() : buf.readUnsignedByte();
+ case 2 -> signed ? buf.readShort() : buf.readUnsignedShort();
+ case 4 -> signed ? buf.readInt() : buf.readUnsignedInt();
+ default -> buf.readLong();
+ };
}
private void decodeDriver(Position position, String part1, String part2) {
@@ -106,136 +100,70 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
private void decodeParameter(Position position, int id, ByteBuf buf, int length) {
switch (id) {
- case 2:
- case 3:
- case 4:
- case 5:
- position.set(Position.PREFIX_IN + (id - 1), readValue(buf, length, false));
- break;
- case 13:
- case 173:
- position.set(Position.KEY_MOTION, readValue(buf, length, false) > 0);
- break;
- case 20:
- position.set(Position.PREFIX_ADC + 3, readValue(buf, length, false));
- break;
- case 21:
- position.set(Position.PREFIX_ADC + 4, readValue(buf, length, false));
- break;
- case 22:
- position.set(Position.PREFIX_ADC + 1, readValue(buf, length, false));
- break;
- case 23:
- position.set(Position.PREFIX_ADC + 2, readValue(buf, length, false));
- break;
- case 29:
- position.set(Position.KEY_POWER, readValue(buf, length, false) * 0.001);
- break;
- case 30:
- position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
- break;
- case 32:
- position.set(Position.KEY_DEVICE_TEMP, readValue(buf, length, true));
- break;
- case 39:
- position.set(Position.KEY_ENGINE_LOAD, readValue(buf, length, false));
- break;
- case 65:
- position.set(Position.KEY_ODOMETER, readValue(buf, length, false));
- break;
- case 74:
- position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
- break;
- case 78:
- case 79:
- case 80:
- position.set(Position.PREFIX_TEMP + (id - 78), readValue(buf, length, true) * 0.1);
- break;
- case 88:
+ case 2, 3, 4, 5 -> position.set(Position.PREFIX_IN + (id - 1), readValue(buf, length, false));
+ case 13, 173 -> position.set(Position.KEY_MOTION, readValue(buf, length, false) > 0);
+ case 20 -> position.set(Position.PREFIX_ADC + 3, readValue(buf, length, false));
+ case 21 -> position.set(Position.PREFIX_ADC + 4, readValue(buf, length, false));
+ case 22 -> position.set(Position.PREFIX_ADC + 1, readValue(buf, length, false));
+ case 23 -> position.set(Position.PREFIX_ADC + 2, readValue(buf, length, false));
+ case 29 -> position.set(Position.KEY_POWER, readValue(buf, length, false) * 0.001);
+ case 30 -> position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
+ case 32 -> position.set(Position.KEY_DEVICE_TEMP, readValue(buf, length, true));
+ case 39 -> position.set(Position.KEY_ENGINE_LOAD, readValue(buf, length, false));
+ case 65 -> position.set(Position.KEY_ODOMETER, readValue(buf, length, false));
+ case 74 -> position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
+ case 78, 79, 80 -> position.set(Position.PREFIX_TEMP + (id - 78), readValue(buf, length, true) * 0.1);
+ case 88 -> {
if (readValue(buf, length, false) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_JAMMING);
}
- break;
- case 94:
- position.set(Position.KEY_RPM, readValue(buf, length, false) * 0.25);
- break;
- case 95:
- position.set(Position.KEY_OBD_SPEED, readValue(buf, length, false));
- break;
- case 98:
- position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false) * 100 / 255.0);
- break;
- case 100:
- position.set(Position.KEY_FUEL_CONSUMPTION, readValue(buf, length, false) / 20.0);
- break;
- case 134:
+ }
+ case 94 -> position.set(Position.KEY_RPM, readValue(buf, length, false) * 0.25);
+ case 95 -> position.set(Position.KEY_OBD_SPEED, readValue(buf, length, false));
+ case 98 -> position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false) * 100 / 255.0);
+ case 100 -> position.set(Position.KEY_FUEL_CONSUMPTION, readValue(buf, length, false) / 20.0);
+ case 134 -> {
if (readValue(buf, length, false) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
}
- break;
- case 136:
+ }
+ case 136 -> {
if (readValue(buf, length, false) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
}
- break;
- case 150:
- position.set(Position.KEY_OPERATOR, readValue(buf, length, false));
- break;
- case 163:
- position.set(Position.KEY_ODOMETER, readValue(buf, length, false) * 5);
- break;
- case 164:
- position.set(Position.KEY_ODOMETER_TRIP, readValue(buf, length, false) * 5);
- break;
- case 165:
- position.set(Position.KEY_OBD_SPEED, readValue(buf, length, false) / 256.0);
- break;
- case 166:
- case 197:
- position.set(Position.KEY_RPM, readValue(buf, length, false) * 0.125);
- break;
- case 170:
- position.set(Position.KEY_CHARGE, readValue(buf, length, false) > 0);
- break;
- case 205:
- position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false));
- break;
- case 207:
- position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false) * 0.4);
- break;
- case 208:
- position.set(Position.KEY_FUEL_USED, readValue(buf, length, false) * 0.5);
- break;
- case 251:
- case 409:
- position.set(Position.KEY_IGNITION, readValue(buf, length, false) > 0);
- break;
- case 410:
+ }
+ case 150 -> position.set(Position.KEY_OPERATOR, readValue(buf, length, false));
+ case 163 -> position.set(Position.KEY_ODOMETER, readValue(buf, length, false) * 5);
+ case 164 -> position.set(Position.KEY_ODOMETER_TRIP, readValue(buf, length, false) * 5);
+ case 165 -> position.set(Position.KEY_OBD_SPEED, readValue(buf, length, false) / 256.0);
+ case 166, 197 -> position.set(Position.KEY_RPM, readValue(buf, length, false) * 0.125);
+ case 170 -> position.set(Position.KEY_CHARGE, readValue(buf, length, false) > 0);
+ case 205 -> position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false));
+ case 207 -> position.set(Position.KEY_FUEL_LEVEL, readValue(buf, length, false) * 0.4);
+ case 208 -> position.set(Position.KEY_FUEL_USED, readValue(buf, length, false) * 0.5);
+ case 251, 409 -> position.set(Position.KEY_IGNITION, readValue(buf, length, false) > 0);
+ case 410 -> {
if (readValue(buf, length, false) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_TOW);
}
- break;
- case 411:
+ }
+ case 411 -> {
if (readValue(buf, length, false) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
}
- break;
- case 415:
+ }
+ case 415 -> {
if (readValue(buf, length, false) == 0) {
position.set(Position.KEY_ALARM, Position.ALARM_GPS_ANTENNA_CUT);
}
- break;
- case 645:
- position.set(Position.KEY_OBD_ODOMETER, readValue(buf, length, false) * 1000);
- break;
- case 758:
+ }
+ case 645 -> position.set(Position.KEY_OBD_ODOMETER, readValue(buf, length, false) * 1000);
+ case 758 -> {
if (readValue(buf, length, false) == 1) {
position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
}
- break;
- default:
- position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
- break;
+ }
+ default -> position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
}
}
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;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
index e0dfab9b2..2be3f6489 100644
--- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -209,42 +209,28 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
while (buf.isReadable()) {
int type = buf.readUnsignedByte();
switch (type) {
- case 0x01:
+ case 0x01 -> {
position.setValid(true);
position.setLatitude(buf.readMedium());
position.setLongitude(buf.readMedium());
- break;
- case 0x02:
+ }
+ case 0x02 -> {
position.setValid(true);
position.setLatitude(buf.readFloat());
position.setLongitude(buf.readFloat());
- break;
- case 0x03:
- position.set(Position.PREFIX_TEMP + 1, buf.readByte() * 0.5);
- break;
- case 0x04:
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
- break;
- case 0x05:
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- break;
- case 0x06:
+ }
+ case 0x03 -> position.set(Position.PREFIX_TEMP + 1, buf.readByte() * 0.5);
+ case 0x04 -> position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
+ case 0x05 -> position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
+ case 0x06 -> {
String mac = ByteBufUtil.hexDump(buf.readSlice(6)).replaceAll("(..)", "$1:");
position.setNetwork(new Network(WifiAccessPoint.from(
mac.substring(0, mac.length() - 1), buf.readUnsignedByte())));
- break;
- case 0x07:
- buf.skipBytes(10); // wifi extended
- break;
- case 0x08:
- buf.skipBytes(6); // accelerometer
- break;
- case 0x09:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- break;
- default:
- buf.readUnsignedByte(); // fence number
- break;
+ }
+ case 0x07 -> buf.skipBytes(10); // wifi extended
+ case 0x08 -> buf.skipBytes(6); // accelerometer
+ case 0x09 -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ default -> buf.readUnsignedByte(); // fence number
}
}
} finally {
diff --git a/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java b/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
index ef1a4426a..1af4ec9eb 100644
--- a/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SnapperProtocolDecoder.java
@@ -93,19 +93,17 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // index
int type = buf.readUnsignedByte();
switch (type) {
- case 0x00:
+ case 0x00 -> {
position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1);
position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case 0x01:
+ }
+ case 0x01 -> {
position.set("interiorTemp", buf.readByte());
position.set("engineTemp", buf.readByte());
buf.readUnsignedByte(); // reserved
- break;
- default:
- buf.skipBytes(3);
- break;
+ }
+ default -> buf.skipBytes(3);
}
}
}
@@ -185,19 +183,22 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- switch (type) {
- case MSG_SEND_EVENTS:
+ return switch (type) {
+ case MSG_SEND_EVENTS -> {
decodeEvents(position, buf);
getLastLocation(position, null); // TODO read timestamp
- return position;
- case MSG_SEND_TECH_INFO:
+ yield position;
+ }
+ case MSG_SEND_TECH_INFO -> {
decodeTechInfo(position, buf);
getLastLocation(position, null);
- return position;
- case MSG_SEND_GPS_DATA:
+ yield position;
+ }
+ case MSG_SEND_GPS_DATA -> {
decodeGpsData(position, buf.readSlice(length));
- return position;
- case MSG_SEND_CONCATENATED_PACKET:
+ yield position;
+ }
+ case MSG_SEND_CONCATENATED_PACKET -> {
int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
int partType = buf.readUnsignedShortLE();
@@ -220,10 +221,10 @@ public class SnapperProtocolDecoder extends BaseProtocolDecoder {
if (position.getFixTime() == null) {
getLastLocation(position, null);
}
- return position;
- default:
- return null;
- }
+ yield position;
+ }
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
index 193005e28..33d1153cf 100644
--- a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
@@ -97,26 +97,17 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int event) {
- switch (event) {
- case 6:
- return Position.ALARM_OVERSPEED;
- case 7:
- return Position.ALARM_GEOFENCE_ENTER;
- case 8:
- return Position.ALARM_GEOFENCE_EXIT;
- case 9:
- return Position.ALARM_POWER_CUT;
- case 11:
- return Position.ALARM_LOW_BATTERY;
- case 26:
- return Position.ALARM_TOW;
- case 36:
- return Position.ALARM_SOS;
- case 42:
- return Position.ALARM_JAMMING;
- default:
- return null;
- }
+ return switch (event) {
+ case 6 -> Position.ALARM_OVERSPEED;
+ case 7 -> Position.ALARM_GEOFENCE_ENTER;
+ case 8 -> Position.ALARM_GEOFENCE_EXIT;
+ case 9 -> Position.ALARM_POWER_CUT;
+ case 11 -> Position.ALARM_LOW_BATTERY;
+ case 26 -> Position.ALARM_TOW;
+ case 36 -> Position.ALARM_SOS;
+ case 42 -> Position.ALARM_JAMMING;
+ default -> null;
+ };
}
@Override
@@ -156,22 +147,11 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
continue;
}
switch (dataTags[i]) {
- case "#ALT#":
- case "#ALTD#":
- position.setAltitude(Double.parseDouble(data[i]));
- break;
- case "#DAL#":
- case "#DID#":
- position.set(Position.KEY_DRIVER_UNIQUE_ID, data[i]);
- break;
- case "#EDT#":
- position.setDeviceTime(dateFormat.parse(data[i]));
- break;
- case "#EDV1#":
- case "#EDV2#":
- position.set("external" + dataTags[i].charAt(4), data[i]);
- break;
- case "#EID#":
+ case "#ALT#", "#ALTD#" -> position.setAltitude(Double.parseDouble(data[i]));
+ case "#DAL#", "#DID#" -> position.set(Position.KEY_DRIVER_UNIQUE_ID, data[i]);
+ case "#EDT#" -> position.setDeviceTime(dateFormat.parse(data[i]));
+ case "#EDV1#", "#EDV2#" -> position.set("external" + dataTags[i].charAt(4), data[i]);
+ case "#EID#" -> {
event = Integer.parseInt(data[i]);
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
@@ -180,137 +160,58 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
} else if (event == 25) {
position.set(Position.KEY_IGNITION, false);
}
- break;
- case "#EDSC#":
- position.set("reason", data[i]);
- break;
- case "#IARM#":
- position.set(Position.KEY_ARMED, Integer.parseInt(data[i]) > 0);
- break;
- case "#PDT#":
- position.setFixTime(dateFormat.parse(data[i]));
- break;
- case "#LAT#":
- position.setLatitude(parseCoordinate(data[i]));
- break;
- case "#LONG#":
- position.setLongitude(parseCoordinate(data[i]));
- break;
- case "#SPD#":
- position.setSpeed(Double.parseDouble(data[i]));
- break;
- case "#SPDK#":
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(data[i])));
- break;
- case "#HEAD#":
- position.setCourse(Integer.parseInt(data[i]));
- break;
- case "#ODO#":
- case "#ODOD#":
- position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(data[i]) * 1000));
- break;
- case "#BATC#":
- position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(data[i]));
- break;
- case "#BATH#":
- position.set("batteryHealth", Integer.parseInt(data[i]));
- break;
- case "#TVI#":
- position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(data[i]));
- break;
- case "#CFL#":
- position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(data[i]));
- break;
- case "#CFL2#":
- position.set("fuel2", Integer.parseInt(data[i]));
- break;
- case "#IN1#":
- case "#IN2#":
- case "#IN3#":
- case "#IN4#":
- position.set(Position.PREFIX_IN + dataTags[i].charAt(3), Integer.parseInt(data[i]));
- break;
- case "#OUT1#":
- case "#OUT2#":
- case "#OUT3#":
- case "#OUT4#":
- position.set(Position.PREFIX_OUT + dataTags[i].charAt(4), Integer.parseInt(data[i]));
- break;
- case "#OUTA#":
- case "#OUTB#":
- case "#OUTC#":
- case "#OUTD#":
- position.set(Position.PREFIX_OUT + (dataTags[i].charAt(4) - 'A' + 1), Integer.parseInt(data[i]));
- break;
- case "#PDOP#":
- position.set(Position.KEY_PDOP, Double.parseDouble(data[i]));
- break;
- case "#LAC#":
+ }
+ case "#EDSC#" -> position.set("reason", data[i]);
+ case "#IARM#" -> position.set(Position.KEY_ARMED, Integer.parseInt(data[i]) > 0);
+ case "#PDT#" -> position.setFixTime(dateFormat.parse(data[i]));
+ case "#LAT#" -> position.setLatitude(parseCoordinate(data[i]));
+ case "#LONG#" -> position.setLongitude(parseCoordinate(data[i]));
+ case "#SPD#" -> position.setSpeed(Double.parseDouble(data[i]));
+ case "#SPDK#" -> position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(data[i])));
+ case "#HEAD#" -> position.setCourse(Integer.parseInt(data[i]));
+ case "#ODO#", "#ODOD#" ->
+ position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(data[i]) * 1000));
+ case "#BATC#" -> position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(data[i]));
+ case "#BATH#" -> position.set("batteryHealth", Integer.parseInt(data[i]));
+ case "#TVI#" -> position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(data[i]));
+ case "#CFL#" -> position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(data[i]));
+ case "#CFL2#" -> position.set("fuel2", Integer.parseInt(data[i]));
+ case "#IN1#", "#IN2#", "#IN3#", "#IN4#" -> position.set(
+ Position.PREFIX_IN + dataTags[i].charAt(3), Integer.parseInt(data[i]));
+ case "#OUT1#", "#OUT2#", "#OUT3#", "#OUT4#" -> position.set(
+ Position.PREFIX_OUT + dataTags[i].charAt(4), Integer.parseInt(data[i]));
+ case "#OUTA#", "#OUTB#", "#OUTC#", "#OUTD#" -> position.set(
+ Position.PREFIX_OUT + (dataTags[i].charAt(4) - 'A' + 1), Integer.parseInt(data[i]));
+ case "#PDOP#" -> position.set(Position.KEY_PDOP, Double.parseDouble(data[i]));
+ case "#LAC#" -> {
if (!data[i].isEmpty()) {
lac = Integer.parseInt(data[i]);
}
- break;
- case "#CID#":
+ }
+ case "#CID#" -> {
if (!data[i].isEmpty()) {
cid = Integer.parseInt(data[i]);
}
- break;
- case "#CSS#":
- position.set(Position.KEY_RSSI, Integer.parseInt(data[i]));
- break;
- case "#VIN#":
- position.set(Position.KEY_POWER, Double.parseDouble(data[i]));
- break;
- case "#VBAT#":
- position.set(Position.KEY_BATTERY, Double.parseDouble(data[i]));
- break;
- case "#DEST#":
- position.set("destination", data[i]);
- break;
- case "#IGN#":
- case "#IGNL#":
- case "#ENG#":
- position.set(Position.KEY_IGNITION, Integer.parseInt(data[i]) > 0);
- break;
- case "#DUR#":
- case "#TDUR#":
- position.set(Position.KEY_HOURS, Integer.parseInt(data[i]));
- break;
- case "#SAT#":
- case "#SATN#":
- position.set(Position.KEY_SATELLITES_VISIBLE, Integer.parseInt(data[i]));
- break;
- case "#SATU#":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(data[i]));
- break;
- case "#STRT#":
- position.set("starter", Double.parseDouble(data[i]));
- break;
- case "#TS1#":
- position.set("sensor1State", Integer.parseInt(data[i]));
- break;
- case "#TS2#":
- position.set("sensor2State", Integer.parseInt(data[i]));
- break;
- case "#TD1#":
- case "#TD2#":
+ }
+ case "#CSS#" -> position.set(Position.KEY_RSSI, Integer.parseInt(data[i]));
+ case "#VIN#" -> position.set(Position.KEY_POWER, Double.parseDouble(data[i]));
+ case "#VBAT#" -> position.set(Position.KEY_BATTERY, Double.parseDouble(data[i]));
+ case "#DEST#" -> position.set("destination", data[i]);
+ case "#IGN#", "#IGNL#", "#ENG#" -> position.set(Position.KEY_IGNITION, Integer.parseInt(data[i]) > 0);
+ case "#DUR#", "#TDUR#" -> position.set(Position.KEY_HOURS, Integer.parseInt(data[i]));
+ case "#SAT#", "#SATN#" -> position.set(Position.KEY_SATELLITES_VISIBLE, Integer.parseInt(data[i]));
+ case "#SATU#" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(data[i]));
+ case "#STRT#" -> position.set("starter", Double.parseDouble(data[i]));
+ case "#TS1#" -> position.set("sensor1State", Integer.parseInt(data[i]));
+ case "#TS2#" -> position.set("sensor2State", Integer.parseInt(data[i]));
+ case "#TD1#", "#TD2#" -> {
StarLinkMessage.mEventReport_TDx message =
StarLinkMessage.mEventReport_TDx.parseFrom(DataConverter.parseBase64(data[i]));
- position.set(
- "sensor" + message.getSensorNumber() + "Id",
- message.getSensorID());
- position.set(
- "sensor" + message.getSensorNumber() + "Temp",
- message.getTemperature() * 0.1);
- position.set(
- "sensor" + message.getSensorNumber() + "Humidity",
- message.getTemperature() * 0.1);
- position.set(
- "sensor" + message.getSensorNumber() + "Voltage",
- message.getVoltage() * 0.001);
- break;
- default:
- break;
+ position.set("sensor" + message.getSensorNumber() + "Id", message.getSensorID());
+ position.set("sensor" + message.getSensorNumber() + "Temp", message.getTemperature() * 0.1);
+ position.set("sensor" + message.getSensorNumber() + "Humidity", message.getTemperature() * 0.1);
+ position.set("sensor" + message.getSensorNumber() + "Voltage", message.getVoltage() * 0.001);
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/StarcomProtocolDecoder.java b/src/main/java/org/traccar/protocol/StarcomProtocolDecoder.java
index 325847b16..8efa23fa3 100644
--- a/src/main/java/org/traccar/protocol/StarcomProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StarcomProtocolDecoder.java
@@ -45,74 +45,32 @@ public class StarcomProtocolDecoder extends BaseProtocolDecoder {
String key = entry.substring(0, delimiter);
String value = entry.substring(delimiter + 1);
switch (key) {
- case "unit":
+ case "unit" -> {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
}
- break;
- case "gps_valid":
- position.setValid(Integer.parseInt(value) != 0);
- break;
- case "datetime_actual":
- position.setTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value));
- break;
- case "latitude":
- position.setLatitude(Double.parseDouble(value));
- break;
- case "longitude":
- position.setLongitude(Double.parseDouble(value));
- break;
- case "altitude":
- position.setAltitude(Double.parseDouble(value));
- break;
- case "velocity":
- position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
- break;
- case "heading":
- position.setCourse(Integer.parseInt(value));
- break;
- case "eventid":
- position.set(Position.KEY_EVENT, Integer.parseInt(value));
- break;
- case "odometer":
- position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(value) * 1000));
- break;
- case "satellites":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
- break;
- case "ignition":
- position.set(Position.KEY_IGNITION, Integer.parseInt(value) != 0);
- break;
- case "door":
- position.set(Position.KEY_DOOR, Integer.parseInt(value) != 0);
- break;
- case "arm":
- position.set(Position.KEY_ARMED, Integer.parseInt(value) != 0);
- break;
- case "fuel":
- position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(value));
- break;
- case "rpm":
- position.set(Position.KEY_RPM, Integer.parseInt(value));
- break;
- case "main_voltage":
- position.set(Position.KEY_POWER, Double.parseDouble(value));
- break;
- case "backup_voltage":
- position.set(Position.KEY_BATTERY, Double.parseDouble(value));
- break;
- case "analog1":
- case "analog2":
- case "analog3":
- position.set(Position.PREFIX_ADC + (key.charAt(key.length() - 1) - '0'), Double.parseDouble(value));
- break;
- case "extra1":
- case "extra2":
- case "extra3":
- default:
- position.set(key, value);
- break;
+ }
+ case "gps_valid" -> position.setValid(Integer.parseInt(value) != 0);
+ case "datetime_actual" -> position.setTime(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse(value));
+ case "latitude" -> position.setLatitude(Double.parseDouble(value));
+ case "longitude" -> position.setLongitude(Double.parseDouble(value));
+ case "altitude" -> position.setAltitude(Double.parseDouble(value));
+ case "velocity" -> position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(value)));
+ case "heading" -> position.setCourse(Integer.parseInt(value));
+ case "eventid" -> position.set(Position.KEY_EVENT, Integer.parseInt(value));
+ case "odometer" -> position.set(Position.KEY_ODOMETER, (long) (Double.parseDouble(value) * 1000));
+ case "satellites" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
+ case "ignition" -> position.set(Position.KEY_IGNITION, Integer.parseInt(value) != 0);
+ case "door" -> position.set(Position.KEY_DOOR, Integer.parseInt(value) != 0);
+ case "arm" -> position.set(Position.KEY_ARMED, Integer.parseInt(value) != 0);
+ case "fuel" -> position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(value));
+ case "rpm" -> position.set(Position.KEY_RPM, Integer.parseInt(value));
+ case "main_voltage" -> position.set(Position.KEY_POWER, Double.parseDouble(value));
+ case "backup_voltage" -> position.set(Position.KEY_BATTERY, Double.parseDouble(value));
+ case "analog1", "analog2", "analog3" -> position.set(
+ Position.PREFIX_ADC + (key.charAt(key.length() - 1) - '0'), Double.parseDouble(value));
+ default -> position.set(key, value);
}
}
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java
index 0eeb5b2aa..4b7e2cfad 100644
--- a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java
@@ -98,27 +98,17 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_SOS;
- case 5:
- case 6:
- return Position.ALARM_DOOR;
- case 17:
- return Position.ALARM_LOW_POWER;
- case 18:
- return Position.ALARM_POWER_CUT;
- case 19:
- return Position.ALARM_POWER_RESTORED;
- case 39:
- return Position.ALARM_ACCELERATION;
- case 40:
- return Position.ALARM_BRAKING;
- case 41:
- return Position.ALARM_CORNERING;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_SOS;
+ case 5, 6 -> Position.ALARM_DOOR;
+ case 17 -> Position.ALARM_LOW_POWER;
+ case 18 -> Position.ALARM_POWER_CUT;
+ case 19 -> Position.ALARM_POWER_RESTORED;
+ case 39 -> Position.ALARM_ACCELERATION;
+ case 40 -> Position.ALARM_BRAKING;
+ case 41 -> Position.ALARM_CORNERING;
+ default -> null;
+ };
}
@Override
@@ -137,19 +127,18 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder {
String type = parser.next();
String content = parser.next();
- switch (type) {
- case "000":
- return decodePosition(deviceSession, content);
- case "710":
- return decodeSerial(deviceSession, content);
- default:
+ return switch (type) {
+ case "000" -> decodePosition(deviceSession, content);
+ case "710" -> decodeSerial(deviceSession, content);
+ default -> {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
position.set(Position.KEY_TYPE, type);
position.set(Position.KEY_RESULT, content);
- return position;
- }
+ yield position;
+ }
+ };
}
private Object decodePosition(DeviceSession deviceSession, String content) {
@@ -268,7 +257,7 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder {
int index = 0;
String type = values[index++];
switch (type) {
- case "T1":
+ case "T1" -> {
index += 1; // speed
position.set(Position.KEY_RPM, Double.parseDouble(values[index++]));
index += 1; // fuel consumption
@@ -298,8 +287,8 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder {
index += 1; // brake pedal
position.set("catalystLevel", Double.parseDouble(values[index++]));
index += 1; // fuel type
- break;
- case "T2":
+ }
+ case "T2" -> {
position.set(Position.KEY_ODOMETER, Double.parseDouble(values[index++]) * 1000);
index += 1; // total fuel
index += 1; // fuel used cruise
@@ -322,9 +311,7 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder {
index += 1; // total cruise control distance
position.set(Position.KEY_FUEL_USED, Double.parseDouble(values[index++]));
index += 1; // total drive time
- break;
- default:
- break;
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
index 011a8dfae..f001b698f 100644
--- a/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/StartekProtocolEncoder.java
@@ -39,18 +39,14 @@ public class StartekProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Channel channel, Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "%s", Command.KEY_DATA);
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "900,%s,%s", Command.KEY_INDEX, Command.KEY_DATA);
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "900,1,1");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "900,1,0");
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(command, "%s", Command.KEY_DATA);
+ case Command.TYPE_OUTPUT_CONTROL ->
+ formatCommand(command, "900,%s,%s", Command.KEY_INDEX, Command.KEY_DATA);
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, "900,1,1");
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "900,1,0");
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
index c52ab485f..18f529712 100644
--- a/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StbProtocolDecoder.java
@@ -75,36 +75,24 @@ public class StbProtocolDecoder extends BaseProtocolDecoder {
JsonObject propertyObject = property.asJsonObject();
String id = propertyObject.getString("id");
switch (id) {
- case "01101001":
- locationType = Integer.parseInt(propertyObject.getString("value"));
- break;
- case "01102001":
- position.setLongitude(
- Double.parseDouble(propertyObject.getString("value")));
- break;
- case "01103001":
- position.setLatitude(
- Double.parseDouble(propertyObject.getString("value")));
- break;
- case "01118001":
- position.set(
- Position.KEY_DEVICE_TEMP, Double.parseDouble(propertyObject.getString("value")));
- break;
- case "01122001":
- position.set(
- "batteryControl", Integer.parseInt(propertyObject.getString("value")));
- break;
- case "02301001":
- position.set(
- "switchCabinetCommand", Integer.parseInt(propertyObject.getString("value")));
- break;
- default:
+ case "01101001" -> locationType = Integer.parseInt(propertyObject.getString("value"));
+ case "01102001" -> position.setLongitude(
+ Double.parseDouble(propertyObject.getString("value")));
+ case "01103001" -> position.setLatitude(
+ Double.parseDouble(propertyObject.getString("value")));
+ case "01118001" -> position.set(
+ Position.KEY_DEVICE_TEMP, Double.parseDouble(propertyObject.getString("value")));
+ case "01122001" -> position.set(
+ "batteryControl", Integer.parseInt(propertyObject.getString("value")));
+ case "02301001" -> position.set(
+ "switchCabinetCommand", Integer.parseInt(propertyObject.getString("value")));
+ default -> {
String key = "id" + id;
if (propertyObject.containsKey("doorId")) {
key += "Door" + propertyObject.getString("doorId");
}
position.set(key, propertyObject.getString("value"));
- break;
+ }
}
}
if (locationType > 0) {
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
index c9d6f16ef..8a440e765 100644
--- a/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -167,56 +167,34 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeEmergency(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_SOS;
- case 2:
- return Position.ALARM_PARKING;
- case 3:
- return Position.ALARM_POWER_CUT;
- case 5:
- case 6:
- return Position.ALARM_DOOR;
- case 7:
- return Position.ALARM_MOVEMENT;
- case 8:
- return Position.ALARM_VIBRATION;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_SOS;
+ case 2 -> Position.ALARM_PARKING;
+ case 3 -> Position.ALARM_POWER_CUT;
+ case 5, 6 -> Position.ALARM_DOOR;
+ case 7 -> Position.ALARM_MOVEMENT;
+ case 8 -> Position.ALARM_VIBRATION;
+ default -> null;
+ };
}
private String decodeAlert(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_OVERSPEED;
- case 5:
- return Position.ALARM_GEOFENCE_EXIT;
- case 6:
- return Position.ALARM_GEOFENCE_ENTER;
- case 14:
- return Position.ALARM_LOW_BATTERY;
- case 15:
- return Position.ALARM_VIBRATION;
- case 16:
- return Position.ALARM_ACCIDENT;
- case 40:
- return Position.ALARM_POWER_RESTORED;
- case 41:
- return Position.ALARM_POWER_CUT;
- case 42:
- return Position.ALARM_SOS;
- case 46:
- return Position.ALARM_ACCELERATION;
- case 47:
- return Position.ALARM_BRAKING;
- case 50:
- return Position.ALARM_JAMMING;
- case 132:
- return Position.ALARM_DOOR;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_OVERSPEED;
+ case 5 -> Position.ALARM_GEOFENCE_EXIT;
+ case 6 -> Position.ALARM_GEOFENCE_ENTER;
+ case 14 -> Position.ALARM_LOW_BATTERY;
+ case 15 -> Position.ALARM_VIBRATION;
+ case 16 -> Position.ALARM_ACCIDENT;
+ case 40 -> Position.ALARM_POWER_RESTORED;
+ case 41 -> Position.ALARM_POWER_CUT;
+ case 42 -> Position.ALARM_SOS;
+ case 46 -> Position.ALARM_ACCELERATION;
+ case 47 -> Position.ALARM_BRAKING;
+ case 50 -> Position.ALARM_JAMMING;
+ case 132 -> Position.ALARM_DOOR;
+ default -> null;
+ };
}
private Position decode4(
Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException {
@@ -323,19 +301,13 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
value = value.substring(0, value.indexOf('.'));
}
switch (pair[0].charAt(0)) {
- case 't':
- position.set(Position.PREFIX_TEMP + pair[0].charAt(2), Integer.parseInt(value, 16));
- break;
- case 'N':
+ case 't' -> position.set(Position.PREFIX_TEMP + pair[0].charAt(2), Integer.parseInt(value, 16));
+ case 'N' -> {
int fuel = Integer.parseInt(value, 16);
totalFuel += fuel;
position.set("fuel" + pair[0].charAt(2), fuel);
- break;
- case 'Q':
- position.set("drivingQuality", Integer.parseInt(value, 16));
- break;
- default:
- break;
+ }
+ case 'Q' -> position.set("drivingQuality", Integer.parseInt(value, 16));
}
}
} else {
@@ -411,24 +383,14 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
}
switch (type) {
- case "STT":
+ case "STT" -> {
position.set(Position.KEY_STATUS, Integer.parseInt(values[index++]));
position.set(Position.KEY_INDEX, Integer.parseInt(values[index++]));
- break;
- case "EMG":
- position.set(Position.KEY_ALARM, decodeEmergency(Integer.parseInt(values[index++])));
- break;
- case "EVT":
- position.set(Position.KEY_EVENT, Integer.parseInt(values[index++]));
- break;
- case "ALT":
- position.set(Position.KEY_ALARM, decodeAlert(Integer.parseInt(values[index++])));
- break;
- case "UEX":
- index = decodeSerialData(position, values, index);
- break;
- default:
- break;
+ }
+ case "EMG" -> position.set(Position.KEY_ALARM, decodeEmergency(Integer.parseInt(values[index++])));
+ case "EVT" -> position.set(Position.KEY_EVENT, Integer.parseInt(values[index++]));
+ case "ALT" -> position.set(Position.KEY_ALARM, decodeAlert(Integer.parseInt(values[index++])));
+ case "UEX" -> index = decodeSerialData(position, values, index);
}
if (isHbm(deviceSession.getDeviceId())) {
@@ -608,7 +570,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
}
switch (type) {
- case "ALT":
+ case "ALT" -> {
if (BitUtil.check(mask, 19)) {
int alertId = Integer.parseInt(values[index++]);
position.set(Position.KEY_ALARM, decodeAlert(alertId));
@@ -619,11 +581,9 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(mask, 21)) {
position.set("alertData", values[index++]);
}
- break;
- case "UEX":
- index = decodeSerialData(position, values, index);
- break;
- default:
+ }
+ case "UEX" -> index = decodeSerialData(position, values, index);
+ default -> {
if (BitUtil.check(mask, 19)) {
position.set("mode", Integer.parseInt(values[index++]));
}
@@ -633,7 +593,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(mask, 21)) {
position.set(Position.KEY_INDEX, Integer.parseInt(values[index++]));
}
- break;
+ }
}
if (BitUtil.check(mask, 22)) {
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;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/SviasProtocolEncoder.java b/src/main/java/org/traccar/protocol/SviasProtocolEncoder.java
index d218f63ce..b62c1b773 100644
--- a/src/main/java/org/traccar/protocol/SviasProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/SviasProtocolEncoder.java
@@ -28,26 +28,17 @@ public class SviasProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "%s", Command.KEY_DATA);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "AT+STR=1*");
- case Command.TYPE_SET_ODOMETER:
- return formatCommand(command, "AT+ODT=%s*", Command.KEY_DATA);
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "AT+OUT=1,1*");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "AT+OUT=1,0*");
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, "AT+OUT=2,1*");
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, "AT+OUT=2,0*");
- case Command.TYPE_ALARM_REMOVE:
- return formatCommand(command, "AT+PNC=600*");
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(command, "%s", Command.KEY_DATA);
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "AT+STR=1*");
+ case Command.TYPE_SET_ODOMETER -> formatCommand(command, "AT+ODT=%s*", Command.KEY_DATA);
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, "AT+OUT=1,1*");
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "AT+OUT=1,0*");
+ case Command.TYPE_ALARM_ARM -> formatCommand(command, "AT+OUT=2,1*");
+ case Command.TYPE_ALARM_DISARM -> formatCommand(command, "AT+OUT=2,0*");
+ case Command.TYPE_ALARM_REMOVE -> formatCommand(command, "AT+PNC=600*");
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java b/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
index 9e64ec9be..c58960ab5 100644
--- a/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T622IridiumProtocolDecoder.java
@@ -84,62 +84,24 @@ public class T622IridiumProtocolDecoder extends BaseProtocolDecoder {
for (int parameter : parameters) {
switch (parameter) {
- case 0x01:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x02:
- position.setLatitude(buf.readIntLE() / 1000000.0);
- break;
- case 0x03:
- position.setLongitude(buf.readIntLE() / 1000000.0);
- break;
- case 0x04:
- position.setTime(new Date((buf.readUnsignedIntLE() + 946684800) * 1000));
- break;
- case 0x05:
- position.setValid(buf.readUnsignedByte() > 0);
- break;
- case 0x06:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case 0x07:
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case 0x08:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
- break;
- case 0x09:
- position.setCourse(buf.readUnsignedShortLE());
- break;
- case 0x0A:
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
- break;
- case 0x0B:
- position.setAltitude(buf.readShortLE());
- break;
- case 0x0C:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
- break;
- case 0x0D:
- position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
- break;
- case 0x14:
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- break;
- case 0x15:
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- break;
- case 0x19:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x1A:
- position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
- break;
- case 0x1B:
- buf.readUnsignedByte(); // geofence
- break;
- default:
- break;
+ case 0x01 -> position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ case 0x02 -> position.setLatitude(buf.readIntLE() / 1000000.0);
+ case 0x03 -> position.setLongitude(buf.readIntLE() / 1000000.0);
+ case 0x04 -> position.setTime(new Date((buf.readUnsignedIntLE() + 946684800) * 1000));
+ case 0x05 -> position.setValid(buf.readUnsignedByte() > 0);
+ case 0x06 -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ case 0x07 -> position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ case 0x08 -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+ case 0x09 -> position.setCourse(buf.readUnsignedShortLE());
+ case 0x0A -> position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
+ case 0x0B -> position.setAltitude(buf.readShortLE());
+ case 0x0C -> position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ case 0x0D -> position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000);
+ case 0x14 -> position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
+ case 0x15 -> position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ case 0x19 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
+ case 0x1A -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
+ case 0x1B -> buf.readUnsignedByte(); // geofence
}
}
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
index 23750be8d..d5be0416d 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
@@ -81,55 +81,33 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm1(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_POWER_CUT;
- case 2:
- return Position.ALARM_LOW_BATTERY;
- case 3:
- return Position.ALARM_SOS;
- case 4:
- return Position.ALARM_OVERSPEED;
- case 5:
- return Position.ALARM_GEOFENCE_ENTER;
- case 6:
- return Position.ALARM_GEOFENCE_EXIT;
- case 7:
- return Position.ALARM_TOW;
- case 8:
- case 10:
- return Position.ALARM_VIBRATION;
- case 21:
- return Position.ALARM_JAMMING;
- case 23:
- return Position.ALARM_POWER_RESTORED;
- case 24:
- return Position.ALARM_LOW_POWER;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_POWER_CUT;
+ case 2 -> Position.ALARM_LOW_BATTERY;
+ case 3 -> Position.ALARM_SOS;
+ case 4 -> Position.ALARM_OVERSPEED;
+ case 5 -> Position.ALARM_GEOFENCE_ENTER;
+ case 6 -> Position.ALARM_GEOFENCE_EXIT;
+ case 7 -> Position.ALARM_TOW;
+ case 8, 10 -> Position.ALARM_VIBRATION;
+ case 21 -> Position.ALARM_JAMMING;
+ case 23 -> Position.ALARM_POWER_RESTORED;
+ case 24 -> Position.ALARM_LOW_POWER;
+ default -> null;
+ };
}
private String decodeAlarm2(int value) {
- switch (value) {
- case 1:
- case 4:
- return Position.ALARM_REMOVING;
- case 2:
- return Position.ALARM_TAMPERING;
- case 3:
- return Position.ALARM_SOS;
- case 5:
- return Position.ALARM_FALL_DOWN;
- case 6:
- return Position.ALARM_LOW_BATTERY;
- case 14:
- return Position.ALARM_GEOFENCE_ENTER;
- case 15:
- return Position.ALARM_GEOFENCE_EXIT;
- default:
- return null;
- }
+ return switch (value) {
+ case 1, 4 -> Position.ALARM_REMOVING;
+ case 2 -> Position.ALARM_TAMPERING;
+ case 3 -> Position.ALARM_SOS;
+ case 5 -> Position.ALARM_FALL_DOWN;
+ case 6 -> Position.ALARM_LOW_BATTERY;
+ case 14 -> Position.ALARM_GEOFENCE_ENTER;
+ case 15 -> Position.ALARM_GEOFENCE_EXIT;
+ default -> null;
+ };
}
private Date readDate(ByteBuf buf) {
@@ -195,24 +173,15 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
switch (buf.readUnsignedByte()) {
- case 0:
- case 4:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 1:
- case 3:
- case 5:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 2:
+ case 0, 4 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 1, 3, 5 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 2 -> {
if (type == MSG_DRIVER_BEHAVIOR_1) {
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
} else {
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
}
- break;
- default:
- break;
+ }
}
position.setTime(readDate(buf));
@@ -275,14 +244,14 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
int i = 1;
while (buf.isReadable()) {
switch (buf.readUnsignedShort()) {
- case 0x01:
+ case 0x01 -> {
position.set("tag" + i + "Id", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", buf.readUnsignedByte() * 0.01 + 1.22);
position.set("tag" + i + "TirePressure", buf.readUnsignedByte() * 1.527 * 2);
position.set("tag" + i + "TireTemp", buf.readUnsignedByte() - 55);
position.set("tag" + i + "TireStatus", buf.readUnsignedByte());
- break;
- case 0x02:
+ }
+ case 0x02 -> {
position.set("tag" + i + "Id", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", BcdUtil.readInteger(buf, 2) * 0.1);
switch (buf.readUnsignedByte()) {
@@ -297,8 +266,8 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
buf.readUnsignedByte(); // status
buf.skipBytes(16); // location
- break;
- case 0x03:
+ }
+ case 0x03 -> {
position.set(Position.KEY_DRIVER_UNIQUE_ID, ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", BcdUtil.readInteger(buf, 2) * 0.1);
if (buf.readUnsignedByte() == 1) {
@@ -306,8 +275,8 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
buf.readUnsignedByte(); // status
buf.skipBytes(16); // location
- break;
- case 0x04:
+ }
+ case 0x04 -> {
position.set("tag" + i + "Id", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", buf.readUnsignedByte() * 0.01 + 2);
buf.readUnsignedByte(); // battery level
@@ -315,23 +284,21 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
position.set("tag" + i + "Humidity", buf.readUnsignedShort() * 0.01);
position.set("tag" + i + "LightSensor", buf.readUnsignedShort());
position.set("tag" + i + "Rssi", buf.readUnsignedByte() - 128);
- break;
- case 0x05:
+ }
+ case 0x05 -> {
position.set("tag" + i + "Id", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", buf.readUnsignedByte() * 0.01 + 2);
buf.readUnsignedByte(); // battery level
position.set("tag" + i + "Temp", decodeBleTemp(buf));
position.set("tag" + i + "Door", buf.readUnsignedByte() > 0);
position.set("tag" + i + "Rssi", buf.readUnsignedByte() - 128);
- break;
- case 0x06:
+ }
+ case 0x06 -> {
position.set("tag" + i + "Id", ByteBufUtil.hexDump(buf.readSlice(6)));
position.set("tag" + i + "Battery", buf.readUnsignedByte() * 0.01 + 2);
position.set("tag" + i + "Output", buf.readUnsignedByte() > 0);
position.set("tag" + i + "Rssi", buf.readUnsignedByte() - 128);
- break;
- default:
- break;
+ }
}
i += 1;
}
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
index 74587c8b1..2360484ee 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolEncoder.java
@@ -58,12 +58,10 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
header = channel.pipeline().get(T800xProtocolDecoder.class).getHeader();
}
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(command, header, command.getString(Command.KEY_DATA));
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> encodeContent(command, header, command.getString(Command.KEY_DATA));
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java
index 448d7ffca..bfa8b10c2 100644
--- a/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TaipProtocolDecoder.java
@@ -122,30 +122,21 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x02:
- return Position.ALARM_POWER_CUT;
- default:
- return null;
- }
+ return switch (value) {
+ case 0x01 -> Position.ALARM_SOS;
+ case 0x02 -> Position.ALARM_POWER_CUT;
+ default -> null;
+ };
}
private String decodeAlarm2(int value) {
- switch (value) {
- case 22:
- return Position.ALARM_ACCELERATION;
- case 23:
- return Position.ALARM_BRAKING;
- case 24:
- return Position.ALARM_ACCIDENT;
- case 26:
- case 28:
- return Position.ALARM_CORNERING;
- default:
- return null;
- }
+ return switch (value) {
+ case 22 -> Position.ALARM_ACCELERATION;
+ case 23 -> Position.ALARM_BRAKING;
+ case 24 -> Position.ALARM_ACCIDENT;
+ case 26, 28 -> Position.ALARM_CORNERING;
+ default -> null;
+ };
}
@Override
@@ -273,7 +264,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
String key = attribute.substring(0, index).toLowerCase();
String value = attribute.substring(index + 1);
switch (key) {
- case "id":
+ case "id" -> {
uniqueId = value;
deviceSession = getDeviceSession(channel, remoteAddress, value);
if (deviceSession != null) {
@@ -282,31 +273,19 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
if (messageIndex == null) {
indexFirst = false;
}
- break;
- case "io":
+ }
+ case "io" -> {
position.set(Position.KEY_IGNITION, BitUtil.check(value.charAt(0) - '0', 0));
position.set(Position.KEY_CHARGE, BitUtil.check(value.charAt(0) - '0', 1));
position.set(Position.KEY_OUTPUT, value.charAt(1) - '0');
position.set(Position.KEY_INPUT, value.charAt(2) - '0');
- break;
- case "ix":
- position.set(Position.PREFIX_IO + 1, value);
- break;
- case "ad":
- position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value));
- break;
- case "sv":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
- break;
- case "bl":
- position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001);
- break;
- case "vo":
- position.set(Position.KEY_ODOMETER, Long.parseLong(value));
- break;
- default:
- position.set(key, value);
- break;
+ }
+ case "ix" -> position.set(Position.PREFIX_IO + 1, value);
+ case "ad" -> position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value));
+ case "sv" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
+ case "bl" -> position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001);
+ case "vo" -> position.set(Position.KEY_ODOMETER, Long.parseLong(value));
+ default -> position.set(key, value);
}
} else if (attribute.startsWith("#")) {
messageIndex = attribute;
diff --git a/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java b/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
index 9681dc565..d7fbb1870 100644
--- a/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TelicProtocolDecoder.java
@@ -58,25 +58,16 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int eventId) {
-
- switch (eventId) {
- case 1:
- return Position.ALARM_POWER_ON;
- case 2:
- return Position.ALARM_SOS;
- case 5:
- return Position.ALARM_POWER_OFF;
- case 7:
- return Position.ALARM_GEOFENCE_ENTER;
- case 8:
- return Position.ALARM_GEOFENCE_EXIT;
- case 22:
- return Position.ALARM_LOW_BATTERY;
- case 25:
- return Position.ALARM_MOVEMENT;
- default:
- return null;
- }
+ return switch (eventId) {
+ case 1 -> Position.ALARM_POWER_ON;
+ case 2 -> Position.ALARM_SOS;
+ case 5 -> Position.ALARM_POWER_OFF;
+ case 7 -> Position.ALARM_GEOFENCE_ENTER;
+ case 8 -> Position.ALARM_GEOFENCE_EXIT;
+ case 22 -> Position.ALARM_LOW_BATTERY;
+ case 25 -> Position.ALARM_MOVEMENT;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 1f7192eb4..93280c5aa 100644
--- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -179,16 +179,12 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
private long readValue(ByteBuf buf, int length) {
- switch (length) {
- case 1:
- return buf.readUnsignedByte();
- case 2:
- return buf.readUnsignedShort();
- case 4:
- return buf.readUnsignedInt();
- default:
- return buf.readLong();
- }
+ return switch (length) {
+ case 1 -> buf.readUnsignedByte();
+ case 2 -> buf.readUnsignedShort();
+ case 4 -> buf.readUnsignedInt();
+ default -> buf.readLong();
+ };
}
private static void register(int id, Set<String> models, BiConsumer<Position, ByteBuf> handler) {
@@ -282,17 +278,9 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
});
register(253, null, (p, b) -> {
switch (b.readUnsignedByte()) {
- case 1:
- p.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 2:
- p.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 3:
- p.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
- break;
- default:
- break;
+ case 1 -> p.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 2 -> p.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 3 -> p.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
}
});
register(636, fmbXXX, (p, b) -> p.set("cid4g", b.readUnsignedInt()));
@@ -301,44 +289,22 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private void decodeGh3000Parameter(Position position, int id, ByteBuf buf, int length) {
switch (id) {
- case 1:
- position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length));
- break;
- case 2:
- position.set("usbConnected", readValue(buf, length) == 1);
- break;
- case 5:
- position.set("uptime", readValue(buf, length));
- break;
- case 20:
- position.set(Position.KEY_HDOP, readValue(buf, length) * 0.1);
- break;
- case 21:
- position.set(Position.KEY_VDOP, readValue(buf, length) * 0.1);
- break;
- case 22:
- position.set(Position.KEY_PDOP, readValue(buf, length) * 0.1);
- break;
- case 67:
- position.set(Position.KEY_BATTERY, readValue(buf, length) * 0.001);
- break;
- case 221:
- position.set("button", readValue(buf, length));
- break;
- case 222:
+ case 1 -> position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length));
+ case 2 -> position.set("usbConnected", readValue(buf, length) == 1);
+ case 5 -> position.set("uptime", readValue(buf, length));
+ case 20 -> position.set(Position.KEY_HDOP, readValue(buf, length) * 0.1);
+ case 21 -> position.set(Position.KEY_VDOP, readValue(buf, length) * 0.1);
+ case 22 -> position.set(Position.KEY_PDOP, readValue(buf, length) * 0.1);
+ case 67 -> position.set(Position.KEY_BATTERY, readValue(buf, length) * 0.001);
+ case 221 -> position.set("button", readValue(buf, length));
+ case 222 -> {
if (readValue(buf, length) == 1) {
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
}
- break;
- case 240:
- position.set(Position.KEY_MOTION, readValue(buf, length) == 1);
- break;
- case 244:
- position.set(Position.KEY_ROAMING, readValue(buf, length) == 1);
- break;
- default:
- position.set(Position.PREFIX_IO + id, readValue(buf, length));
- break;
+ }
+ case 240 -> position.set(Position.KEY_MOTION, readValue(buf, length) == 1);
+ case 244 -> position.set(Position.KEY_ROAMING, readValue(buf, length) == 1);
+ default -> position.set(Position.PREFIX_IO + id, readValue(buf, length));
}
}
@@ -602,14 +568,12 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
int parameterId = beacon.readUnsignedByte();
int parameterLength = beacon.readUnsignedByte();
switch (parameterId) {
- case 0:
- position.set("tag" + i + "Rssi", (int) beacon.readByte());
- break;
- case 1:
+ case 0 -> position.set("tag" + i + "Rssi", (int) beacon.readByte());
+ case 1 -> {
String beaconId = ByteBufUtil.hexDump(beacon.readSlice(parameterLength));
position.set("tag" + i + "Id", beaconId);
- break;
- case 2:
+ }
+ case 2 -> {
ByteBuf beaconData = beacon.readSlice(parameterLength);
int flag = beaconData.readUnsignedByte();
if (BitUtil.check(flag, 6)) {
@@ -618,16 +582,10 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(flag, 7)) {
position.set("tag" + i + "Voltage", beaconData.readUnsignedByte() * 10 + 2000);
}
- break;
- case 13:
- position.set("tag" + i + "LowBattery", beacon.readUnsignedByte());
- break;
- case 14:
- position.set("tag" + i + "Battery", beacon.readUnsignedShort());
- break;
- default:
- beacon.skipBytes(parameterLength);
- break;
+ }
+ case 13 -> position.set("tag" + i + "LowBattery", beacon.readUnsignedByte());
+ case 14 -> position.set("tag" + i + "Battery", beacon.readUnsignedShort());
+ default -> beacon.skipBytes(parameterLength);
}
}
}
diff --git a/src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java b/src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java
index e7ab23e5b..c929621b5 100644
--- a/src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java
@@ -63,67 +63,43 @@ public class ThinkPowerProtocolDecoder extends BaseProtocolDecoder {
private void decodeValue(Position position, int type, ByteBuf buf) {
switch (type) {
- case 0x01:
+ case 0x01 -> {
position.setValid(true);
position.setLatitude(BufferUtil.readSignedMagnitudeInt(buf) * 0.0000001);
position.setLongitude(BufferUtil.readSignedMagnitudeInt(buf) * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
position.setCourse(buf.readUnsignedShort() * 0.01);
- break;
- case 0x02:
- position.setValid(buf.readUnsignedByte() > 0);
- break;
- case 0x03:
- buf.skipBytes(3); // geofence
- break;
- case 0x06:
- case 0x07:
- case 0x08:
- buf.skipBytes(2); // g-sensor x/y/z
- break;
- case 0x09:
- buf.readUnsignedByte(); // collision alarm
- break;
- case 0x0A:
- buf.readUnsignedByte(); // drop alarm
- break;
- case 0x10:
+ }
+ case 0x02 -> position.setValid(buf.readUnsignedByte() > 0);
+ case 0x03 -> buf.skipBytes(3); // geofence
+ case 0x06, 0x07, 0x08 -> buf.skipBytes(2); // g-sensor x/y/z
+ case 0x09 -> buf.readUnsignedByte(); // collision alarm
+ case 0x0A -> buf.readUnsignedByte(); // drop alarm
+ case 0x10 -> {
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
}
- break;
- case 0x12:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
- break;
- case 0x13:
+ }
+ case 0x12 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
+ case 0x13 -> {
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
}
- break;
- case 0x16:
- buf.readUnsignedShort(); // temperature
- break;
- case 0x17:
- buf.readUnsignedByte(); // humidity
- break;
- case 0x18:
- buf.readUnsignedShort(); // high temperature
- break;
- case 0x19:
- buf.readUnsignedByte(); // high humidity
- break;
- case 0x50:
+ }
+ case 0x16 -> buf.readUnsignedShort(); // temperature
+ case 0x17 -> buf.readUnsignedByte(); // humidity
+ case 0x18 -> buf.readUnsignedShort(); // high temperature
+ case 0x19 -> buf.readUnsignedByte(); // high humidity
+ case 0x50 -> {
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
}
- break;
- case 0x51:
+ }
+ case 0x51 -> {
if (buf.readUnsignedByte() > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
}
- break;
- default:
- break;
+ }
}
}
diff --git a/src/main/java/org/traccar/protocol/ThurayaProtocolDecoder.java b/src/main/java/org/traccar/protocol/ThurayaProtocolDecoder.java
index a287ece34..ea1879cf2 100644
--- a/src/main/java/org/traccar/protocol/ThurayaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ThurayaProtocolDecoder.java
@@ -110,24 +110,16 @@ public class ThurayaProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int event) {
- switch (event) {
- case 10:
- return Position.ALARM_VIBRATION;
- case 11:
- return Position.ALARM_OVERSPEED;
- case 12:
- return Position.ALARM_POWER_CUT;
- case 13:
- return Position.ALARM_LOW_BATTERY;
- case 18:
- return Position.ALARM_GPS_ANTENNA_CUT;
- case 20:
- return Position.ALARM_ACCELERATION;
- case 21:
- return Position.ALARM_BRAKING;
- default:
- return null;
- }
+ return switch (event) {
+ case 10 -> Position.ALARM_VIBRATION;
+ case 11 -> Position.ALARM_OVERSPEED;
+ case 12 -> Position.ALARM_POWER_CUT;
+ case 13 -> Position.ALARM_LOW_BATTERY;
+ case 18 -> Position.ALARM_GPS_ANTENNA_CUT;
+ case 20 -> Position.ALARM_ACCELERATION;
+ case 21 -> Position.ALARM_BRAKING;
+ default -> null;
+ };
}
private String readString(ByteBuf buf) {
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
index 6c926da90..7a7a0cc3b 100644
--- a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -157,123 +157,52 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_ACCIDENT;
- case 2:
- return Position.ALARM_SOS;
- case 3:
- return Position.ALARM_VIBRATION;
- case 4:
- return Position.ALARM_LOW_SPEED;
- case 5:
- return Position.ALARM_OVERSPEED;
- case 6:
- return Position.ALARM_GEOFENCE_EXIT;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_ACCIDENT;
+ case 2 -> Position.ALARM_SOS;
+ case 3 -> Position.ALARM_VIBRATION;
+ case 4 -> Position.ALARM_LOW_SPEED;
+ case 5 -> Position.ALARM_OVERSPEED;
+ case 6 -> Position.ALARM_GEOFENCE_EXIT;
+ default -> null;
+ };
}
private void decodeType(Position position, String type, String data) {
switch (type) {
- case "BQ81":
+ case "BQ81" -> {
switch (Integer.parseInt(data)) {
- case 0:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 4:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 5:
- position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
- break;
- default:
- break;
+ case 0 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
+ case 3 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 4 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 5 -> position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
}
- break;
- case "BO01":
- position.set(Position.KEY_ALARM, decodeAlarm(data.charAt(0) - '0'));
- break;
- case "ZC11":
- case "DW31":
- case "DW51":
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- case "ZC12":
- case "DW32":
- case "DW52":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "ZC13":
- case "DW33":
- case "DW53":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "ZC15":
- case "DW35":
- case "DW55":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "ZC16":
- case "DW36":
- case "DW56":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "ZC29":
- case "DW42":
- case "DW62":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "ZC17":
- case "DW37":
- case "DW57":
- position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
- break;
- case "ZC25":
- case "DW3E":
- case "DW5E":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "ZC26":
- case "DW3F":
- case "DW5F":
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- case "ZC27":
- case "DW40":
- case "DW60":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- default:
- break;
+ }
+ case "BO01" -> position.set(Position.KEY_ALARM, decodeAlarm(data.charAt(0) - '0'));
+ case "ZC11", "DW31", "DW51" -> position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
+ case "ZC12", "DW32", "DW52" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case "ZC13", "DW33", "DW53" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case "ZC15", "DW35", "DW55" -> position.set(Position.KEY_IGNITION, true);
+ case "ZC16", "DW36", "DW56" -> position.set(Position.KEY_IGNITION, false);
+ case "ZC29", "DW42", "DW62" -> position.set(Position.KEY_IGNITION, true);
+ case "ZC17", "DW37", "DW57" -> position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
+ case "ZC25", "DW3E", "DW5E" -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case "ZC26", "DW3F", "DW5F" -> position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ case "ZC27", "DW40", "DW60" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
}
}
private Integer decodeBattery(int value) {
- switch (value) {
- case 6:
- return 100;
- case 5:
- return 80;
- case 4:
- return 50;
- case 3:
- return 20;
- case 2:
- return 10;
- default:
- return null;
- }
+ return switch (value) {
+ case 6 -> 100;
+ case 5 -> 80;
+ case 4 -> 50;
+ case 3 -> 20;
+ case 2 -> 10;
+ default -> null;
+ };
}
private Position decodeBattery(Channel channel, SocketAddress remoteAddress, String sentence) {
@@ -516,32 +445,30 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
int key = Integer.parseInt(pair[0], 16);
ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(pair[1]));
switch (key) {
- case 0x90:
+ case 0x90 -> {
position.set("cumulativeVoltage", buf.readUnsignedShortLE() * 0.1);
position.set("gatherVoltage", buf.readUnsignedShortLE() * 0.1);
position.set("current", (buf.readUnsignedShortLE() - 30000) * 0.1);
position.set("soc", buf.readUnsignedShortLE() * 0.1);
- break;
- case 0x91:
+ }
+ case 0x91 -> {
position.set("maxCellVoltage", buf.readUnsignedShortLE() * 0.001);
position.set("maxCellVoltageCount", buf.readUnsignedByte());
position.set("minCellVoltage", buf.readUnsignedShortLE() * 0.001);
position.set("minCellVoltageCount", buf.readUnsignedByte());
- break;
- case 0x92:
+ }
+ case 0x92 -> {
position.set("maxTemp", buf.readUnsignedByte() - 40);
position.set("maxTempCount", buf.readUnsignedByte());
position.set("minTemp", buf.readUnsignedByte() - 40);
position.set("minTempCount", buf.readUnsignedByte());
- break;
- case 0x96:
+ }
+ case 0x96 -> {
buf.readUnsignedByte(); // frame
while (buf.isReadable()) {
position.set("cellTemp" + buf.readerIndex(), buf.readUnsignedByte() - 40);
}
- break;
- default:
- break;
+ }
}
}
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;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
index c8ea66b6c..2d59ffda8 100644
--- a/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -101,43 +101,17 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
private void decodeStatus(Position position, String status) {
switch (status) {
- case "AUTOSTART":
- case "AUTO":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "AUTOSTOP":
- case "AUTOLOW":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "TOWED":
- position.set(Position.KEY_ALARM, Position.ALARM_TOW);
- break;
- case "SHAKE":
- position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
- break;
- case "SOS":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "DEF":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "BLP":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "CLP":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- case "OS":
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
- break;
- case "RS":
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_ENTER);
- break;
- case "OVERSPEED":
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- default:
- break;
+ case "AUTOSTART", "AUTO" -> position.set(Position.KEY_IGNITION, true);
+ case "AUTOSTOP", "AUTOLOW" -> position.set(Position.KEY_IGNITION, false);
+ case "TOWED" -> position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ case "SHAKE" -> position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
+ case "SOS" -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case "DEF" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case "BLP" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case "CLP" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ case "OS" -> position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
+ case "RS" -> position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_ENTER);
+ case "OVERSPEED" -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
}
}
diff --git a/src/main/java/org/traccar/protocol/TlvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TlvProtocolDecoder.java
index 7870c778a..21ed8fba4 100644
--- a/src/main/java/org/traccar/protocol/TlvProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TlvProtocolDecoder.java
@@ -62,19 +62,9 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
switch (type) {
- case "0A":
- case "0C":
- sendResponse(channel, remoteAddress, type);
- break;
- case "0B":
- sendResponse(channel, remoteAddress, type, "1482202689", "10", "20", "15");
- break;
- case "0E":
- case "0F":
- sendResponse(channel, remoteAddress, type, "30", "Unknown");
- break;
- default:
- break;
+ case "0A", "0C" -> sendResponse(channel, remoteAddress, type);
+ case "0B" -> sendResponse(channel, remoteAddress, type, "1482202689", "10", "20", "15");
+ case "0E", "0F" -> sendResponse(channel, remoteAddress, type, "30", "Unknown");
}
}
diff --git a/src/main/java/org/traccar/protocol/TmgProtocolDecoder.java b/src/main/java/org/traccar/protocol/TmgProtocolDecoder.java
index 00dc2a09b..9a8f5830a 100644
--- a/src/main/java/org/traccar/protocol/TmgProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TmgProtocolDecoder.java
@@ -104,28 +104,12 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
switch (type) {
- case "rmv":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "ebl":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- case "ibl":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "tmp":
- case "smt":
- case "btt":
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- case "ion":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "iof":
- position.set(Position.KEY_IGNITION, false);
- break;
- default:
- break;
+ case "rmv" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case "ebl" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ case "ibl" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case "tmp", "smt", "btt" -> position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ case "ion" -> position.set(Position.KEY_IGNITION, true);
+ case "iof" -> position.set(Position.KEY_IGNITION, false);
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
diff --git a/src/main/java/org/traccar/protocol/TopinProtocolEncoder.java b/src/main/java/org/traccar/protocol/TopinProtocolEncoder.java
index 77f80b9d4..b3b6bc23f 100644
--- a/src/main/java/org/traccar/protocol/TopinProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/TopinProtocolEncoder.java
@@ -54,13 +54,13 @@ public class TopinProtocolEncoder extends BaseProtocolEncoder {
ByteBuf content = Unpooled.buffer();
- switch (command.getType()) {
- case Command.TYPE_SOS_NUMBER:
+ return switch (command.getType()) {
+ case Command.TYPE_SOS_NUMBER -> {
content.writeCharSequence(command.getString(Command.KEY_PHONE), StandardCharsets.US_ASCII);
- return encodeContent(TopinProtocolDecoder.MSG_SOS_NUMBER, content);
- default:
- return null;
- }
+ yield encodeContent(TopinProtocolDecoder.MSG_SOS_NUMBER, content);
+ }
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
index 6f039c324..c48db5b3f 100644
--- a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
@@ -218,57 +218,35 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm123(int value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x30:
- return Position.ALARM_PARKING;
- case 0x42:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x43:
- return Position.ALARM_GEOFENCE_ENTER;
- default:
- return null;
- }
+ return switch (value) {
+ case 0x01 -> Position.ALARM_SOS;
+ case 0x10 -> Position.ALARM_LOW_BATTERY;
+ case 0x11 -> Position.ALARM_OVERSPEED;
+ case 0x30 -> Position.ALARM_PARKING;
+ case 0x42 -> Position.ALARM_GEOFENCE_EXIT;
+ case 0x43 -> Position.ALARM_GEOFENCE_ENTER;
+ default -> null;
+ };
}
private String decodeAlarm4(int value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x02:
- return Position.ALARM_OVERSPEED;
- case 0x04:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x05:
- return Position.ALARM_GEOFENCE_ENTER;
- case 0x06:
- return Position.ALARM_TOW;
- case 0x07:
- return Position.ALARM_GPS_ANTENNA_CUT;
- case 0x10:
- return Position.ALARM_POWER_CUT;
- case 0x11:
- return Position.ALARM_POWER_RESTORED;
- case 0x12:
- return Position.ALARM_LOW_POWER;
- case 0x13:
- return Position.ALARM_LOW_BATTERY;
- case 0x40:
- return Position.ALARM_VIBRATION;
- case 0x41:
- return Position.ALARM_IDLE;
- case 0x42:
- return Position.ALARM_ACCELERATION;
- case 0x43:
- return Position.ALARM_BRAKING;
- default:
- return null;
- }
+ return switch (value) {
+ case 0x01 -> Position.ALARM_SOS;
+ case 0x02 -> Position.ALARM_OVERSPEED;
+ case 0x04 -> Position.ALARM_GEOFENCE_EXIT;
+ case 0x05 -> Position.ALARM_GEOFENCE_ENTER;
+ case 0x06 -> Position.ALARM_TOW;
+ case 0x07 -> Position.ALARM_GPS_ANTENNA_CUT;
+ case 0x10 -> Position.ALARM_POWER_CUT;
+ case 0x11 -> Position.ALARM_POWER_RESTORED;
+ case 0x12 -> Position.ALARM_LOW_POWER;
+ case 0x13 -> Position.ALARM_LOW_BATTERY;
+ case 0x40 -> Position.ALARM_VIBRATION;
+ case 0x41 -> Position.ALARM_IDLE;
+ case 0x42 -> Position.ALARM_ACCELERATION;
+ case 0x43 -> Position.ALARM_BRAKING;
+ default -> null;
+ };
}
private Position decode12(Channel channel, SocketAddress remoteAddress, String sentence, Pattern pattern) {
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
index 4b22ade03..fea9e2d2c 100644
--- a/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/TotemProtocolEncoder.java
@@ -28,28 +28,27 @@ public class TotemProtocolEncoder extends StringProtocolEncoder {
}
public static String formatContent(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return String.format("%s,%s",
- command.getAttributes().get(Command.KEY_DEVICE_PASSWORD),
- command.getAttributes().get(Command.KEY_DATA)
- );
- case Command.TYPE_REBOOT_DEVICE:
- return String.format("%s,006", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- case Command.TYPE_FACTORY_RESET:
- return String.format("%s,007", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- case Command.TYPE_GET_VERSION:
- return String.format("%s,056", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- case Command.TYPE_POSITION_SINGLE:
- return String.format("%s,012", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- // Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8
- case Command.TYPE_ENGINE_STOP:
- return String.format("%s,025,C,1", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- case Command.TYPE_ENGINE_RESUME:
- return String.format("%s,025,C,0", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM ->
+ String.format(
+ "%s,%s",
+ command.getAttributes().get(Command.KEY_DEVICE_PASSWORD),
+ command.getAttributes().get(Command.KEY_DATA));
+ case Command.TYPE_REBOOT_DEVICE ->
+ String.format("%s,006", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ case Command.TYPE_FACTORY_RESET ->
+ String.format("%s,007", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ case Command.TYPE_GET_VERSION ->
+ String.format("%s,056", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ case Command.TYPE_POSITION_SINGLE ->
+ String.format("%s,012", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ // Assuming PIN 8 (Output C) is the power wire, like manual says, but it can be PIN 5,7,8
+ case Command.TYPE_ENGINE_STOP ->
+ String.format("%s,025,C,1", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ case Command.TYPE_ENGINE_RESUME ->
+ String.format("%s,025,C,0", command.getAttributes().get(Command.KEY_DEVICE_PASSWORD));
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrakMateProtocolDecoder.java
index b1f50dc10..78c21b40d 100644
--- a/src/main/java/org/traccar/protocol/TrakMateProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TrakMateProtocolDecoder.java
@@ -91,16 +91,12 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_SOS;
- case 3:
- return Position.ALARM_GEOFENCE;
- case 4:
- return Position.ALARM_POWER_CUT;
- default:
- return null;
- }
+ return switch (value) {
+ case 1 -> Position.ALARM_SOS;
+ case 3 -> Position.ALARM_GEOFENCE;
+ case 4 -> Position.ALARM_POWER_CUT;
+ default -> null;
+ };
}
private Object decodeSrt(Channel channel, SocketAddress remoteAddress, String sentence) {
@@ -220,14 +216,11 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
}
String type = sentence.substring(typeIndex + 3, typeIndex + 6);
- switch (type) {
- case "ALT":
- return decodeAlt(channel, remoteAddress, sentence);
- case "SRT":
- return decodeSrt(channel, remoteAddress, sentence);
- default:
- return decodePer(channel, remoteAddress, sentence);
- }
+ return switch (type) {
+ case "ALT" -> decodeAlt(channel, remoteAddress, sentence);
+ case "SRT" -> decodeSrt(channel, remoteAddress, sentence);
+ default -> decodePer(channel, remoteAddress, sentence);
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java b/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java
index 4a9a9a58f..f12211f81 100644
--- a/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -167,7 +167,7 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
while (buf.isReadable()) {
int type = buf.readUnsignedByte();
switch (type) {
- case 0:
+ case 0 -> {
position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
buf.readUnsignedIntLE(); // event data
@@ -193,34 +193,19 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
position.setFixTime(new Date(buf.readUnsignedIntLE() * 1000));
buf.readUnsignedByte(); // reserved
- break;
- case 1:
- buf.skipBytes(buf.readUnsignedShortLE() - 3); // landmark
- break;
- case 4:
- buf.skipBytes(53); // trip
- break;
- case 20:
- buf.skipBytes(32); // extended
- break;
- case 22:
+ }
+ case 1 -> buf.skipBytes(buf.readUnsignedShortLE() - 3); // landmark
+ case 4 -> buf.skipBytes(53); // trip
+ case 20 -> buf.skipBytes(32); // extended
+ case 22 -> {
buf.readUnsignedByte(); // zone flag
buf.skipBytes(buf.readUnsignedShortLE()); // zone name
- break;
- case 30:
- buf.skipBytes(79); // system status
- break;
- case 40:
- buf.skipBytes(40); // analog
- break;
- case 50:
- buf.skipBytes(buf.readUnsignedShortLE() - 3); // console
- break;
- case 255:
- buf.skipBytes(4); // acknowledgement
- break;
- default:
- throw new IllegalArgumentException(String.format("Unknown type %d", type));
+ }
+ case 30 -> buf.skipBytes(79); // system status
+ case 40 -> buf.skipBytes(40); // analog
+ case 50 -> buf.skipBytes(buf.readUnsignedShortLE() - 3); // console
+ case 255 -> buf.skipBytes(4); // acknowledgement
+ default -> throw new IllegalArgumentException(String.format("Unknown type %d", type));
}
}
diff --git a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
index 816b5d2cf..e3f7ae36f 100644
--- a/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TranSyncProtocolDecoder.java
@@ -37,24 +37,16 @@ public class TranSyncProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(int value) {
- switch (value) {
- case 4:
- return Position.ALARM_LOW_BATTERY;
- case 6:
- return Position.ALARM_POWER_RESTORED;
- case 10:
- return Position.ALARM_SOS;
- case 13:
- return Position.ALARM_BRAKING;
- case 14:
- return Position.ALARM_ACCELERATION;
- case 17:
- return Position.ALARM_OVERSPEED;
- case 23:
- return Position.ALARM_ACCIDENT;
- default:
- return null;
- }
+ return switch (value) {
+ case 4 -> Position.ALARM_LOW_BATTERY;
+ case 6 -> Position.ALARM_POWER_RESTORED;
+ case 10 -> Position.ALARM_SOS;
+ case 13 -> Position.ALARM_BRAKING;
+ case 14 -> Position.ALARM_ACCELERATION;
+ case 17 -> Position.ALARM_OVERSPEED;
+ case 23 -> Position.ALARM_ACCIDENT;
+ default -> null;
+ };
}
@Override
diff --git a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
index 7f298c8cf..2f2b7d8c2 100644
--- a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
@@ -249,15 +249,8 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext()) {
switch (parser.nextInt()) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case 5:
- case 6:
- position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
- break;
- default:
- break;
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case 5, 6 -> position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
}
}
@@ -332,28 +325,24 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
String[] values = sentence.split(",");
switch (type) {
- case "AP49":
- position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
- break;
- case "APHT":
+ case "AP49" -> position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
+ case "APHT" -> {
position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
position.set("pressureSystolic", Integer.parseInt(values[2]));
position.set("pressureDiastolic", Integer.parseInt(values[3]));
- break;
- case "APHP":
+ }
+ case "APHP" -> {
position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[1]));
position.set("pressureSystolic", Integer.parseInt(values[2]));
position.set("pressureDiastolic", Integer.parseInt(values[3]));
position.set("spo2", Integer.parseInt(values[4]));
position.set("bloodSugar", Double.parseDouble(values[5]));
position.set("temperature", Double.parseDouble(values[6]));
- break;
- case "AP50":
+ }
+ case "AP50" -> {
position.set("temperature", Double.parseDouble(values[1]));
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[2]));
- break;
- default:
- break;
+ }
}
return position;
diff --git a/src/main/java/org/traccar/protocol/TytanProtocolDecoder.java b/src/main/java/org/traccar/protocol/TytanProtocolDecoder.java
index 6169e0545..04461f9cc 100644
--- a/src/main/java/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TytanProtocolDecoder.java
@@ -51,55 +51,39 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
int n;
switch (type) {
- case 2:
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedMedium());
- break;
- case 5:
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- break;
- case 6:
+ case 2 -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedMedium());
+ case 5 -> position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ case 6 -> {
n = buf.readUnsignedByte() >> 4;
if (n < 2) {
position.set(Position.PREFIX_ADC + n, buf.readFloat());
} else {
position.set("di" + (n - 2), buf.readFloat());
}
- break;
- case 7:
+ }
+ case 7 -> {
int alarm = buf.readUnsignedByte();
buf.readUnsignedByte();
if (BitUtil.check(alarm, 5)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
- break;
- case 8:
- position.set("antihijack", buf.readUnsignedByte());
- break;
- case 9:
- position.set("unauthorized", ByteBufUtil.hexDump(buf.readSlice(8)));
- break;
- case 10:
- position.set("authorized", ByteBufUtil.hexDump(buf.readSlice(8)));
- break;
- case 24:
+ }
+ case 8 -> position.set("antihijack", buf.readUnsignedByte());
+ case 9 -> position.set("unauthorized", ByteBufUtil.hexDump(buf.readSlice(8)));
+ case 10 -> position.set("authorized", ByteBufUtil.hexDump(buf.readSlice(8)));
+ case 24 -> {
for (int i = 0; i < length / 2; i++) {
position.set(Position.PREFIX_TEMP + buf.readUnsignedByte(), buf.readByte());
}
- break;
- case 28:
+ }
+ case 28 -> {
position.set(Position.KEY_AXLE_WEIGHT, buf.readUnsignedShort());
buf.readUnsignedByte();
- break;
- case 90:
- position.set(Position.KEY_POWER, buf.readFloat());
- break;
- case 101:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
- break;
- case 102:
- position.set(Position.KEY_RPM, buf.readUnsignedByte() * 50);
- break;
- case 107:
+ }
+ case 90 -> position.set(Position.KEY_POWER, buf.readFloat());
+ case 101 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
+ case 102 -> position.set(Position.KEY_RPM, buf.readUnsignedByte() * 50);
+ case 107 -> {
int fuel = buf.readUnsignedShort();
int fuelFormat = fuel >> 14;
if (fuelFormat == 1) {
@@ -109,16 +93,10 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
} else if (fuelFormat == 3) {
position.set("fuelValue", (fuel & 0x3fff) * -0.5 + " l");
}
- break;
- case 108:
- position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5);
- break;
- case 150:
- position.set(Position.KEY_DOOR, buf.readUnsignedByte());
- break;
- default:
- buf.skipBytes(length);
- break;
+ }
+ case 108 -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5);
+ case 150 -> position.set(Position.KEY_DOOR, buf.readUnsignedByte());
+ default -> buf.skipBytes(length);
}
}
}
diff --git a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
index f0b1e709d..8fbea5808 100644
--- a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -60,26 +60,17 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
private String decodeAlarm(Short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x14:
- return Position.ALARM_BRAKING;
- case 0x15:
- return Position.ALARM_ACCELERATION;
- case 0x30:
- return Position.ALARM_PARKING;
- case 0x42:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x43:
- return Position.ALARM_GEOFENCE_ENTER;
- default:
- return null;
- }
+ return switch (value) {
+ case 0x01 -> Position.ALARM_SOS;
+ case 0x10 -> Position.ALARM_LOW_BATTERY;
+ case 0x11 -> Position.ALARM_OVERSPEED;
+ case 0x14 -> Position.ALARM_BRAKING;
+ case 0x15 -> Position.ALARM_ACCELERATION;
+ case 0x30 -> Position.ALARM_PARKING;
+ case 0x42 -> Position.ALARM_GEOFENCE_EXIT;
+ case 0x43 -> Position.ALARM_GEOFENCE_ENTER;
+ default -> null;
+ };
}
private boolean decodeGps(Position position, ByteBuf buf, int hardware) {
diff --git a/src/main/java/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/main/java/org/traccar/protocol/UlbotechProtocolDecoder.java
index c9b35158e..53eec55d0 100644
--- a/src/main/java/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -147,21 +147,11 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
int id = BitUtil.from(value, 12);
value = BitUtil.to(value, 12);
switch (id) {
- case 0:
- position.set(Position.KEY_POWER, value * (100 + 10) / 4096.0 - 10);
- break;
- case 1:
- position.set(Position.PREFIX_TEMP + 1, value * (125 + 55) / 4096.0 - 55);
- break;
- case 2:
- position.set(Position.KEY_BATTERY, value * (100 + 10) / 4096.0 - 10);
- break;
- case 3:
- position.set(Position.PREFIX_ADC + 1, value * (100 + 10) / 4096.0 - 10);
- break;
- default:
- position.set(Position.PREFIX_IO + id, value);
- break;
+ case 0 -> position.set(Position.KEY_POWER, value * (100 + 10) / 4096.0 - 10);
+ case 1 -> position.set(Position.PREFIX_TEMP + 1, value * (125 + 55) / 4096.0 - 55);
+ case 2 -> position.set(Position.KEY_BATTERY, value * (100 + 10) / 4096.0 - 10);
+ case 3 -> position.set(Position.PREFIX_ADC + 1, value * (100 + 10) / 4096.0 - 10);
+ default -> position.set(Position.PREFIX_IO + id, value);
}
}
}
@@ -236,8 +226,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
int length = type == DATA_CANBUS ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (type) {
-
- case DATA_GPS:
+ case DATA_GPS -> {
hasLocation = true;
position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
@@ -246,9 +235,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
int hdop = buf.readUnsignedShort();
position.setValid(hdop < 9999);
position.set(Position.KEY_HDOP, hdop * 0.01);
- break;
-
- case DATA_LBS:
+ }
+ case DATA_LBS -> {
if (length == 11) {
position.setNetwork(new Network(CellTower.from(
buf.readUnsignedShort(), buf.readUnsignedShort(),
@@ -261,72 +249,39 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
if (length > 9 && length != 11) {
buf.skipBytes(length - 9);
}
- break;
-
- case DATA_STATUS:
+ }
+ case DATA_STATUS -> {
int status = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(status, 9));
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedShort()));
- break;
-
- case DATA_ODOMETER:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- break;
-
- case DATA_ADC:
- decodeAdc(position, buf, length);
- break;
-
- case DATA_GEOFENCE:
+ }
+ case DATA_ODOMETER -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ case DATA_ADC -> decodeAdc(position, buf, length);
+ case DATA_GEOFENCE -> {
position.set("geofenceIn", buf.readUnsignedInt());
position.set("geofenceAlarm", buf.readUnsignedInt());
- break;
-
- case DATA_OBD2:
- decodeObd(position, buf, length);
- break;
-
- case DATA_FUEL:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() / 10000.0);
- break;
-
- case DATA_OBD2_ALARM:
- decodeObd(position, buf, length);
- break;
-
- case DATA_HARSH_DRIVER:
- decodeDriverBehavior(position, buf);
- break;
-
- case DATA_CANBUS:
- position.set("can", ByteBufUtil.hexDump(buf.readSlice(length)));
- break;
-
- case DATA_J1708:
- decodeJ1708(position, buf, length);
- break;
-
- case DATA_VIN:
- position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII));
- break;
-
- case DATA_RFID:
+ }
+ case DATA_OBD2 -> decodeObd(position, buf, length);
+ case DATA_FUEL -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() / 10000.0);
+ case DATA_OBD2_ALARM -> decodeObd(position, buf, length);
+ case DATA_HARSH_DRIVER -> decodeDriverBehavior(position, buf);
+ case DATA_CANBUS -> position.set("can", ByteBufUtil.hexDump(buf.readSlice(length)));
+ case DATA_J1708 -> decodeJ1708(position, buf, length);
+ case DATA_VIN ->
+ position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII));
+ case DATA_RFID -> {
position.set(Position.KEY_DRIVER_UNIQUE_ID,
buf.readSlice(length - 1).toString(StandardCharsets.US_ASCII));
position.set("authorized", buf.readUnsignedByte() != 0);
- break;
-
- case DATA_EVENT:
+ }
+ case DATA_EVENT -> {
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
if (length > 1) {
position.set("eventMask", buf.readUnsignedInt());
}
- break;
-
- default:
- buf.skipBytes(length);
- break;
+ }
+ default -> buf.skipBytes(length);
}
}
diff --git a/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java b/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java
index 5528c7242..10f408821 100644
--- a/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/UlbotechProtocolEncoder.java
@@ -30,13 +30,11 @@ public class UlbotechProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return Unpooled.copiedBuffer(
- "*TS01," + command.getString(Command.KEY_DATA) + "#", StandardCharsets.US_ASCII);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> Unpooled.copiedBuffer(
+ "*TS01," + command.getString(Command.KEY_DATA) + "#", StandardCharsets.US_ASCII);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
index d3f9882dd..b866c4112 100644
--- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java
@@ -154,29 +154,21 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
String stringValue;
switch (dataType) {
- case 'A':
- decodeLocation(position, data.toString(StandardCharsets.US_ASCII));
- break;
- case 'B':
- position.set(Position.KEY_STATUS, data.toString(StandardCharsets.US_ASCII));
- break;
- case 'C':
+ case 'A' -> decodeLocation(position, data.toString(StandardCharsets.US_ASCII));
+ case 'B' -> position.set(Position.KEY_STATUS, data.toString(StandardCharsets.US_ASCII));
+ case 'C' -> {
long odometer = 0;
while (data.isReadable()) {
odometer <<= 4;
odometer += data.readByte() - (byte) '0';
}
position.set(Position.KEY_ODOMETER, odometer * 2 * 1852 / 3600);
- break;
- case 'F':
- position.setSpeed(
- Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
- break;
- case 'G':
- position.setAltitude(
- Integer.parseInt(data.readSlice(6).toString(StandardCharsets.US_ASCII)) * 0.1);
- break;
- case 'I':
+ }
+ case 'F' -> position.setSpeed(
+ Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
+ case 'G' -> position.setAltitude(
+ Integer.parseInt(data.readSlice(6).toString(StandardCharsets.US_ASCII)) * 0.1);
+ case 'I' -> {
stringValue = data.toString(StandardCharsets.US_ASCII);
count = Integer.parseInt(stringValue.substring(0, 1));
if (stringValue.length() == 6 + count * 10) {
@@ -191,8 +183,8 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
Integer.parseInt(stringValue.substring(offset + 8, offset + 10))));
}
}
- break;
- case 'J':
+ }
+ case 'J' -> {
if (data.readableBytes() == 6) {
char index = (char) data.readUnsignedByte();
int status = data.readUnsignedByte();
@@ -202,11 +194,9 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
position.set(Position.PREFIX_TEMP + index, value);
}
- break;
- case 'K':
- position.set("statusExtended", data.toString(StandardCharsets.US_ASCII));
- break;
- case 'M':
+ }
+ case 'K' -> position.set("statusExtended", data.toString(StandardCharsets.US_ASCII));
+ case 'M' -> {
if (data.readableBytes() == 3) {
position.set(Position.KEY_BATTERY_LEVEL,
Integer.parseInt(data.readSlice(3).toString(StandardCharsets.US_ASCII)) * 0.1);
@@ -217,16 +207,12 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
"humidity" + index,
Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
}
- break;
- case 'N':
- position.set(Position.KEY_RSSI,
- Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
- break;
- case 'O':
- position.set(Position.KEY_SATELLITES,
- Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
- break;
- case 'P':
+ }
+ case 'N' -> position.set(Position.KEY_RSSI,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ case 'O' -> position.set(Position.KEY_SATELLITES,
+ Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
+ case 'P' -> {
if (data.readableBytes() >= 16) {
position.setNetwork(new Network(CellTower.from(
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)),
@@ -234,13 +220,13 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII), 16),
Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII), 16))));
}
- break;
- case 'Q':
+ }
+ case 'Q' -> {
if (!head.startsWith("HQ")) {
position.set("obdPid", ByteBufUtil.hexDump(data));
}
- break;
- case 'R':
+ }
+ case 'R' -> {
if (head.startsWith("HQ")) {
position.set(Position.KEY_RSSI,
Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII)));
@@ -249,25 +235,19 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
} else {
position.set("odbTravel", ByteBufUtil.hexDump(data));
}
- break;
- case 'S':
- position.set("obdTraffic", ByteBufUtil.hexDump(data));
- break;
- case 'T':
+ }
+ case 'S' -> position.set("obdTraffic", ByteBufUtil.hexDump(data));
+ case 'T' -> {
if (data.readableBytes() == 2) {
position.set(Position.KEY_BATTERY_LEVEL,
Integer.parseInt(data.toString(StandardCharsets.US_ASCII)));
}
- break;
- case 'V':
- position.set(Position.KEY_POWER,
- Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
- break;
- case 'W':
- position.set(Position.KEY_ALARM,
- decodeAlarm(Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII))));
- break;
- case 'X':
+ }
+ case 'V' -> position.set(Position.KEY_POWER,
+ Integer.parseInt(data.readSlice(4).toString(StandardCharsets.US_ASCII)) * 0.1);
+ case 'W' -> position.set(Position.KEY_ALARM,
+ decodeAlarm(Integer.parseInt(data.readSlice(2).toString(StandardCharsets.US_ASCII))));
+ case 'X' -> {
String[] cells = data.toString(StandardCharsets.US_ASCII).split(";");
if (!cells[0].startsWith("(")) {
for (int i = 0; i < cells.length; i++) {
@@ -285,8 +265,8 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
position.setNetwork(network);
}
- break;
- case 'Y':
+ }
+ case 'Y' -> {
stringValue = data.toString(StandardCharsets.US_ASCII);
count = Integer.parseInt(stringValue.substring(0, 1));
if (stringValue.length() == 6 + count * 14) {
@@ -304,18 +284,14 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_POWER,
Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.001);
}
- break;
- case 'b':
+ }
+ case 'b' -> {
if (data.readableBytes() > 3) {
position.set("serial", data.toString(StandardCharsets.US_ASCII).substring(3));
}
- break;
- case 'd':
- position.set(Position.PREFIX_ADC + 1,
- Integer.parseInt(data.toString(StandardCharsets.US_ASCII)) / 100.0);
- break;
- default:
- break;
+ }
+ case 'd' -> position.set(Position.PREFIX_ADC + 1,
+ Integer.parseInt(data.toString(StandardCharsets.US_ASCII)) / 100.0);
}
}
diff --git a/src/main/java/org/traccar/protocol/VltProtocolDecoder.java b/src/main/java/org/traccar/protocol/VltProtocolDecoder.java
index 01c0563f5..40fb5eef7 100644
--- a/src/main/java/org/traccar/protocol/VltProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/VltProtocolDecoder.java
@@ -121,19 +121,18 @@ public class VltProtocolDecoder extends BaseHttpProtocolDecoder {
sendResponse(channel, HttpResponseStatus.OK);
- switch (type) {
- case "NRM":
- return decodePosition(deviceSession, sentence.substring(3 + 15));
- case "BTH":
+ return switch (type) {
+ case "NRM" -> decodePosition(deviceSession, sentence.substring(3 + 15));
+ case "BTH" -> {
List<Position> positions = new LinkedList<>();
int count = Integer.parseInt(sentence.substring(index, index += 3));
for (int i = 0; i < count; i++) {
positions.add(decodePosition(deviceSession, sentence.substring(index, index += 78)));
}
- return positions;
- default:
- return null;
- }
+ yield positions;
+ }
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/main/java/org/traccar/protocol/VtfmsProtocolDecoder.java
index bf0cdcb51..36cc98df9 100644
--- a/src/main/java/org/traccar/protocol/VtfmsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/VtfmsProtocolDecoder.java
@@ -77,20 +77,14 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder {
.compile();
private String decodeAlarm(int value) {
- switch (value) {
- case 10:
- return Position.ALARM_OVERSPEED;
- case 14:
- return Position.ALARM_POWER_CUT;
- case 15:
- return Position.ALARM_POWER_RESTORED;
- case 32:
- return Position.ALARM_BRAKING;
- case 33:
- return Position.ALARM_ACCELERATION;
- default:
- return null;
- }
+ return switch (value) {
+ case 10 -> Position.ALARM_OVERSPEED;
+ case 14 -> Position.ALARM_POWER_CUT;
+ case 15 -> Position.ALARM_POWER_RESTORED;
+ case 32 -> Position.ALARM_BRAKING;
+ case 33 -> Position.ALARM_ACCELERATION;
+ default -> null;
+ };
}
private double convertToDegrees(double value) {
diff --git a/src/main/java/org/traccar/protocol/WatchFrameDecoder.java b/src/main/java/org/traccar/protocol/WatchFrameDecoder.java
index 9dfae8726..992cb02ab 100644
--- a/src/main/java/org/traccar/protocol/WatchFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/WatchFrameDecoder.java
@@ -32,14 +32,8 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
for (int i = buf.readerIndex(); i < buf.writerIndex(); i++) {
byte b = buf.getByte(i);
switch (b) {
- case '[':
- brackets += 1;
- break;
- case ']':
- brackets -= 1;
- break;
- default:
- break;
+ case '[' -> brackets += 1;
+ case ']' -> brackets -= 1;
}
if (brackets == 0 && i > buf.readerIndex()) {
endIndex = i + 1;
@@ -54,24 +48,13 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
if (b1 == '}') {
byte b2 = buf.readByte();
switch (b2) {
- case 0x01:
- frame.writeByte('}');
- break;
- case 0x02:
- frame.writeByte('[');
- break;
- case 0x03:
- frame.writeByte(']');
- break;
- case 0x04:
- frame.writeByte(',');
- break;
- case 0x05:
- frame.writeByte('*');
- break;
- default:
- throw new IllegalArgumentException(String.format(
- "unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, b2));
+ case 0x01 -> frame.writeByte('}');
+ case 0x02 -> frame.writeByte('[');
+ case 0x03 -> frame.writeByte(']');
+ case 0x04 -> frame.writeByte(',');
+ case 0x05 -> frame.writeByte('*');
+ default -> throw new IllegalArgumentException(
+ String.format("unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, b2));
}
} else {
frame.writeByte(b1);
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolEncoder.java b/src/main/java/org/traccar/protocol/WatchProtocolEncoder.java
index 14ebe2852..2911d423a 100644
--- a/src/main/java/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/WatchProtocolEncoder.java
@@ -134,42 +134,28 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin
@Override
protected Object encodeCommand(Channel channel, Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatTextCommand(channel, command, command.getString(Command.KEY_DATA));
- case Command.TYPE_POSITION_SINGLE:
- return formatTextCommand(channel, command, "CR");
- case Command.TYPE_SOS_NUMBER:
- return formatTextCommand(channel, command, "SOS%s,%s", Command.KEY_INDEX, Command.KEY_PHONE);
- case Command.TYPE_ALARM_SOS:
- return formatTextCommand(channel, command, "SOSSMS,%s", Command.KEY_ENABLE);
- case Command.TYPE_ALARM_BATTERY:
- return formatTextCommand(channel, command, "LOWBAT,%s", Command.KEY_ENABLE);
- case Command.TYPE_REBOOT_DEVICE:
- return formatTextCommand(channel, command, "RESET");
- case Command.TYPE_POWER_OFF:
- return formatTextCommand(channel, command, "POWEROFF");
- case Command.TYPE_ALARM_REMOVE:
- return formatTextCommand(channel, command, "REMOVE,%s", Command.KEY_ENABLE);
- case Command.TYPE_SILENCE_TIME:
- return formatTextCommand(channel, command, "SILENCETIME,%s", Command.KEY_DATA);
- case Command.TYPE_ALARM_CLOCK:
- return formatTextCommand(channel, command, "REMIND,%s", Command.KEY_DATA);
- case Command.TYPE_SET_PHONEBOOK:
- return formatTextCommand(channel, command, "PHB,%s", Command.KEY_DATA);
- case Command.TYPE_MESSAGE:
- return formatTextCommand(channel, command, "MESSAGE,%s", Command.KEY_MESSAGE);
- case Command.TYPE_VOICE_MESSAGE:
- return formatBinaryCommand(channel, command, "TK,", getBinaryData(command));
- case Command.TYPE_POSITION_PERIODIC:
- return formatTextCommand(channel, command, "UPLOAD,%s", Command.KEY_FREQUENCY);
- case Command.TYPE_SET_TIMEZONE:
- return formatTextCommand(channel, command, "LZ,%s,%s", Command.KEY_LANGUAGE, Command.KEY_TIMEZONE);
- case Command.TYPE_SET_INDICATOR:
- return formatTextCommand(channel, command, "FLOWER,%s", Command.KEY_DATA);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatTextCommand(channel, command, command.getString(Command.KEY_DATA));
+ case Command.TYPE_POSITION_SINGLE -> formatTextCommand(channel, command, "CR");
+ case Command.TYPE_SOS_NUMBER ->
+ formatTextCommand(channel, command, "SOS%s,%s", Command.KEY_INDEX, Command.KEY_PHONE);
+ case Command.TYPE_ALARM_SOS -> formatTextCommand(channel, command, "SOSSMS,%s", Command.KEY_ENABLE);
+ case Command.TYPE_ALARM_BATTERY -> formatTextCommand(channel, command, "LOWBAT,%s", Command.KEY_ENABLE);
+ case Command.TYPE_REBOOT_DEVICE -> formatTextCommand(channel, command, "RESET");
+ case Command.TYPE_POWER_OFF -> formatTextCommand(channel, command, "POWEROFF");
+ case Command.TYPE_ALARM_REMOVE -> formatTextCommand(channel, command, "REMOVE,%s", Command.KEY_ENABLE);
+ case Command.TYPE_SILENCE_TIME -> formatTextCommand(channel, command, "SILENCETIME,%s", Command.KEY_DATA);
+ case Command.TYPE_ALARM_CLOCK -> formatTextCommand(channel, command, "REMIND,%s", Command.KEY_DATA);
+ case Command.TYPE_SET_PHONEBOOK -> formatTextCommand(channel, command, "PHB,%s", Command.KEY_DATA);
+ case Command.TYPE_MESSAGE -> formatTextCommand(channel, command, "MESSAGE,%s", Command.KEY_MESSAGE);
+ case Command.TYPE_VOICE_MESSAGE -> formatBinaryCommand(channel, command, "TK,", getBinaryData(command));
+ case Command.TYPE_POSITION_PERIODIC ->
+ formatTextCommand(channel, command, "UPLOAD,%s", Command.KEY_FREQUENCY);
+ case Command.TYPE_SET_TIMEZONE ->
+ formatTextCommand(channel, command, "LZ,%s,%s", Command.KEY_LANGUAGE, Command.KEY_TIMEZONE);
+ case Command.TYPE_SET_INDICATOR -> formatTextCommand(channel, command, "FLOWER,%s", Command.KEY_DATA);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/WialonProtocolEncoder.java b/src/main/java/org/traccar/protocol/WialonProtocolEncoder.java
index 93086bf8a..7712f3cfc 100644
--- a/src/main/java/org/traccar/protocol/WialonProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/WialonProtocolEncoder.java
@@ -28,18 +28,14 @@ public class WialonProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "reboot\r\n");
- case Command.TYPE_SEND_USSD:
- return formatCommand(command, "USSD:%s\r\n", Command.KEY_PHONE);
- case Command.TYPE_IDENTIFICATION:
- return formatCommand(command, "VER?\r\n");
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "L%s=%s\r\n", Command.KEY_INDEX, Command.KEY_DATA);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_REBOOT_DEVICE -> formatCommand(command, "reboot\r\n");
+ case Command.TYPE_SEND_USSD -> formatCommand(command, "USSD:%s\r\n", Command.KEY_PHONE);
+ case Command.TYPE_IDENTIFICATION -> formatCommand(command, "VER?\r\n");
+ case Command.TYPE_OUTPUT_CONTROL ->
+ formatCommand(command, "L%s=%s\r\n", Command.KEY_INDEX, Command.KEY_DATA);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/WliProtocolDecoder.java b/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
index ec1c4d17a..a01cdb0cf 100644
--- a/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WliProtocolDecoder.java
@@ -99,54 +99,28 @@ public class WliProtocolDecoder extends BaseProtocolDecoder {
String value = buf.readCharSequence(
endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString();
- int networkFieldsOffset;
- switch (type) {
- case 0xE4:
- networkFieldsOffset = 10;
- break;
- case 0xCB:
- networkFieldsOffset = 80;
- break;
- case 0x1E:
- networkFieldsOffset = 182;
- break;
- case 0xC9:
- default:
- networkFieldsOffset = 35;
- break;
- }
+ int networkFieldsOffset = switch (type) {
+ case 0xE4 -> 10;
+ case 0xCB -> 80;
+ case 0x1E -> 182;
+ default -> 35;
+ };
if (fieldNumber - networkFieldsOffset >= 0 && fieldNumber - networkFieldsOffset < 10) {
switch (fieldNumber - networkFieldsOffset) {
- case 0:
- cellTower.setMobileCountryCode(Integer.parseInt(value));
- break;
- case 1:
- cellTower.setMobileNetworkCode(Integer.parseInt(value));
- break;
- case 2:
- cellTower.setLocationAreaCode(Integer.parseInt(value));
- break;
- case 3:
- cellTower.setCellId(Long.parseLong(value));
- break;
- case 4:
- cellTower.setSignalStrength(Integer.parseInt(value));
- break;
- default:
- break;
+ case 0 -> cellTower.setMobileCountryCode(Integer.parseInt(value));
+ case 1 -> cellTower.setMobileNetworkCode(Integer.parseInt(value));
+ case 2 -> cellTower.setLocationAreaCode(Integer.parseInt(value));
+ case 3 -> cellTower.setCellId(Long.parseLong(value));
+ case 4 -> cellTower.setSignalStrength(Integer.parseInt(value));
}
} else {
switch (fieldNumber) {
- case 246:
+ case 246 -> {
String[] values = value.split(",");
position.set(Position.KEY_POWER, Integer.parseInt(values[2]) * 0.01);
position.set(Position.KEY_BATTERY, Integer.parseInt(values[3]) * 0.01);
- break;
- case 255:
- position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
- break;
- default:
- break;
+ }
+ case 255 -> position.setDeviceTime(new Date(Long.parseLong(value) * 1000));
}
}
diff --git a/src/main/java/org/traccar/protocol/WondexProtocolEncoder.java b/src/main/java/org/traccar/protocol/WondexProtocolEncoder.java
index fb213dc40..035a5d2d3 100644
--- a/src/main/java/org/traccar/protocol/WondexProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/WondexProtocolEncoder.java
@@ -30,22 +30,16 @@ public class WondexProtocolEncoder extends StringProtocolEncoder {
initDevicePassword(command, "0000");
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "$WP+REBOOT=%s", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_DEVICE_STATUS:
- return formatCommand(command, "$WP+TEST=%s", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_MODEM_STATUS:
- return formatCommand(command, "$WP+GSMINFO=%s", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_IDENTIFICATION:
- return formatCommand(command, "$WP+IMEI=%s", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "$WP+GETLOCATION=%s", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_VERSION:
- return formatCommand(command, "$WP+VER=%s", Command.KEY_DEVICE_PASSWORD);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_REBOOT_DEVICE -> formatCommand(command, "$WP+REBOOT=%s", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_GET_DEVICE_STATUS -> formatCommand(command, "$WP+TEST=%s", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_GET_MODEM_STATUS -> formatCommand(command, "$WP+GSMINFO=%s", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_IDENTIFICATION -> formatCommand(command, "$WP+IMEI=%s", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_POSITION_SINGLE ->
+ formatCommand(command, "$WP+GETLOCATION=%s", Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_GET_VERSION -> formatCommand(command, "$WP+VER=%s", Command.KEY_DEVICE_PASSWORD);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/WristbandProtocolDecoder.java b/src/main/java/org/traccar/protocol/WristbandProtocolDecoder.java
index 323992ddd..f8cfe2b5e 100644
--- a/src/main/java/org/traccar/protocol/WristbandProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/WristbandProtocolDecoder.java
@@ -155,31 +155,22 @@ public class WristbandProtocolDecoder extends BaseProtocolDecoder {
String data = parser.next();
switch (type) {
- case 90:
- sendResponse(channel, imei, version, type, getServer(channel, ','));
- break;
- case 91:
+ case 90 -> sendResponse(channel, imei, version, type, getServer(channel, ','));
+ case 91 -> {
String time = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
sendResponse(channel, imei, version, type, time + "|" + getServer(channel, ','));
- break;
- case 1:
+ }
+ case 1 -> {
positions.add(decodeStatus(deviceSession, data));
sendResponse(channel, imei, version, type, data.split(",")[1]);
- break;
- case 2:
+ }
+ case 2 -> {
for (String fragment : data.split("\\|")) {
positions.add(decodePosition(deviceSession, fragment));
}
- break;
- case 3:
- case 4:
- positions.add(decodeNetwork(deviceSession, data, type == 3));
- break;
- case 64:
- sendResponse(channel, imei, version, type, data);
- break;
- default:
- break;
+ }
+ case 3, 4 -> positions.add(decodeNetwork(deviceSession, data, type == 3));
+ case 64 -> sendResponse(channel, imei, version, type, data);
}
return positions.isEmpty() ? null : positions;
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
index 8f3fa5672..f08e60a67 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
@@ -52,19 +52,14 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
protected Object encodeCommand(Command command) {
String uniqueId = getUniqueId(command.getDeviceId());
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(uniqueId, command.getString(Command.KEY_DATA));
- case Command.TYPE_POSITION_PERIODIC:
- return encodeContent(uniqueId,
- String.format("tracking_send=%1$d,%1$d", command.getInteger(Command.KEY_FREQUENCY)));
- case Command.TYPE_POWER_OFF:
- return encodeContent(uniqueId, "of=1");
- case Command.TYPE_REBOOT_DEVICE:
- return encodeContent(uniqueId, "reset");
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> encodeContent(uniqueId, command.getString(Command.KEY_DATA));
+ case Command.TYPE_POSITION_PERIODIC -> encodeContent(
+ uniqueId, String.format("tracking_send=%1$d,%1$d", command.getInteger(Command.KEY_FREQUENCY)));
+ case Command.TYPE_POWER_OFF -> encodeContent(uniqueId, "of=1");
+ case Command.TYPE_REBOOT_DEVICE -> encodeContent(uniqueId, "reset");
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/XexunProtocolDecoder.java b/src/main/java/org/traccar/protocol/XexunProtocolDecoder.java
index e41d467d5..5d8507543 100644
--- a/src/main/java/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/XexunProtocolDecoder.java
@@ -65,33 +65,16 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private String decodeStatus(Position position, String value) {
+ private void decodeStatus(Position position, String value) {
if (value != null) {
switch (value.toLowerCase()) {
- case "acc on":
- case "accstart":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "acc off":
- case "accstop":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "help me!":
- case "help me":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "low battery":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "move!":
- case "moved!":
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- default:
- break;
+ case "acc on", "accstart" -> position.set(Position.KEY_IGNITION, true);
+ case "acc off", "accstop" -> position.set(Position.KEY_IGNITION, false);
+ case "help me!", "help me" -> position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ case "low battery" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ case "move!", "moved!" -> position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
}
}
- return null;
}
@Override
diff --git a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
index 220c28054..56681bb40 100644
--- a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -116,63 +116,22 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_EVENT, event);
switch (event) {
- case 4001:
- case 4003:
- case 6011:
- case 6013:
- position.set(Position.KEY_IGNITION, true);
- break;
- case 4002:
- case 4004:
- case 6012:
- case 6014:
- position.set(Position.KEY_IGNITION, false);
- break;
- case 4005:
- position.set(Position.KEY_CHARGE, false);
- break;
- case 6002:
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case 6006:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 6007:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 6008:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- case 6009:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case 6010:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
- break;
- case 6016:
- position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
- break;
- case 6017:
- position.set(Position.KEY_ALARM, Position.ALARM_TOW);
- break;
- case 6030:
- case 6071:
- position.set(Position.KEY_MOTION, true);
- break;
- case 6031:
- position.set(Position.KEY_MOTION, false);
- break;
- case 6032:
- position.set(Position.KEY_ALARM, Position.ALARM_PARKING);
- break;
- case 6090:
- position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
- break;
- case 6091:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- default:
- break;
+ case 4001, 4003, 6011, 6013 -> position.set(Position.KEY_IGNITION, true);
+ case 4002, 4004, 6012, 6014 -> position.set(Position.KEY_IGNITION, false);
+ case 4005 -> position.set(Position.KEY_CHARGE, false);
+ case 6002 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ case 6006 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 6007 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 6008 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ case 6009 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ case 6010 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
+ case 6016 -> position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
+ case 6017 -> position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ case 6030, 6071 -> position.set(Position.KEY_MOTION, true);
+ case 6031 -> position.set(Position.KEY_MOTION, false);
+ case 6032 -> position.set(Position.KEY_ALARM, Position.ALARM_PARKING);
+ case 6090 -> position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
+ case 6091 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
}
}
@@ -213,76 +172,49 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < keys.length; i++) {
switch (keys[i]) {
- case "UID":
- case "IM":
+ case "UID", "IM" -> {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[i]);
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
}
- break;
- case "EV":
- decodeEvent(position, Integer.parseInt(values[i]));
- break;
- case "D":
+ }
+ case "EV" -> decodeEvent(position, Integer.parseInt(values[i]));
+ case "D" -> {
String[] date = values[i].split("/");
dateBuilder.setMonth(Integer.parseInt(date[0]));
dateBuilder.setDay(Integer.parseInt(date[1]));
dateBuilder.setYear(Integer.parseInt(date[2]));
- break;
- case "T":
+ }
+ case "T" -> {
String[] time = values[i].split(":");
dateBuilder.setHour(Integer.parseInt(time[0]));
dateBuilder.setMinute(Integer.parseInt(time[1]));
dateBuilder.setSecond(Integer.parseInt(time[2]));
- break;
- case "LT":
- position.setLatitude(Double.parseDouble(values[i]));
- break;
- case "LN":
- position.setLongitude(Double.parseDouble(values[i]));
- break;
- case "AL":
- position.setAltitude(Integer.parseInt(values[i]));
- break;
- case "GSPT":
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[i])));
- break;
- case "HD":
+ }
+ case "LT" -> position.setLatitude(Double.parseDouble(values[i]));
+ case "LN" -> position.setLongitude(Double.parseDouble(values[i]));
+ case "AL" -> position.setAltitude(Integer.parseInt(values[i]));
+ case "GSPT" -> position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[i])));
+ case "HD" -> {
if (values[i].contains(".")) {
position.setCourse(Double.parseDouble(values[i]));
} else {
position.setCourse(Integer.parseInt(values[i]) * 0.1);
}
- break;
- case "SV":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i]));
- break;
- case "BV":
- position.set(Position.KEY_BATTERY, Double.parseDouble(values[i]));
- break;
- case "CQ":
- position.set(Position.KEY_RSSI, Integer.parseInt(values[i]));
- break;
- case "MI":
- position.set(Position.KEY_ODOMETER, Integer.parseInt(values[i]));
- break;
- case "GS":
- position.setValid(Integer.parseInt(values[i]) == 3);
- break;
- case "SI":
- position.set(Position.KEY_ICCID, values[i]);
- break;
- case "IG":
+ }
+ case "SV" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i]));
+ case "BV" -> position.set(Position.KEY_BATTERY, Double.parseDouble(values[i]));
+ case "CQ" -> position.set(Position.KEY_RSSI, Integer.parseInt(values[i]));
+ case "MI" -> position.set(Position.KEY_ODOMETER, Integer.parseInt(values[i]));
+ case "GS" -> position.setValid(Integer.parseInt(values[i]) == 3);
+ case "SI" -> position.set(Position.KEY_ICCID, values[i]);
+ case "IG" -> {
int ignition = Integer.parseInt(values[i]);
if (ignition > 0) {
position.set(Position.KEY_IGNITION, ignition == 1);
}
- break;
- case "OT":
- position.set(Position.KEY_OUTPUT, Integer.parseInt(values[i]));
- break;
- default:
- break;
+ }
+ case "OT" -> position.set(Position.KEY_OUTPUT, Integer.parseInt(values[i]));
}
}
diff --git a/src/main/java/org/traccar/protocol/XirgoProtocolEncoder.java b/src/main/java/org/traccar/protocol/XirgoProtocolEncoder.java
index aa85e9e0e..76ec03d7a 100644
--- a/src/main/java/org/traccar/protocol/XirgoProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/XirgoProtocolEncoder.java
@@ -28,12 +28,11 @@ public class XirgoProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_OUTPUT_CONTROL:
- return String.format("+XT:7005,%d,1", command.getInteger(Command.KEY_DATA) + 1);
- default:
- return null;
- }
+ return switch (command.getType()) {
+ case Command.TYPE_OUTPUT_CONTROL ->
+ String.format("+XT:7005,%d,1", command.getInteger(Command.KEY_DATA) + 1);
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Xrb28ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xrb28ProtocolDecoder.java
index 6033293c4..4f915af15 100644
--- a/src/main/java/org/traccar/protocol/Xrb28ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xrb28ProtocolDecoder.java
@@ -119,56 +119,33 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
switch (type) {
- case "Q0":
+ case "Q0" -> {
position.set(Position.KEY_BATTERY, Integer.parseInt(values[index++]) * 0.01);
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[index++]));
position.set(Position.KEY_RSSI, Integer.parseInt(values[index++]));
- break;
- case "H0":
+ }
+ case "H0" -> {
position.set(Position.KEY_BLOCKED, Integer.parseInt(values[index++]) > 0);
position.set(Position.KEY_BATTERY, Integer.parseInt(values[index++]) * 0.01);
position.set(Position.KEY_RSSI, Integer.parseInt(values[index++]));
position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[index++]));
- break;
- case "W0":
+ }
+ case "W0" -> {
switch (Integer.parseInt(values[index++])) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- default:
- break;
+ case 1 -> position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
+ case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
+ case 3 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
}
- break;
- case "E0":
+ }
+ case "E0" -> {
position.set(Position.KEY_ALARM, Position.ALARM_FAULT);
position.set("error", Integer.parseInt(values[index++]));
- break;
- case "S1":
- position.set(Position.KEY_EVENT, Integer.parseInt(values[index++]));
- break;
- case "R0":
- case "L0":
- case "L1":
- case "S4":
- case "S5":
- case "S6":
- case "S7":
- case "V0":
- case "G0":
- case "K0":
- case "I0":
- case "M0":
+ }
+ case "S1" -> position.set(Position.KEY_EVENT, Integer.parseInt(values[index++]));
+ case "R0", "L0", "L1", "S4", "S5", "S6", "S7", "V0", "G0", "K0", "I0", "M0" -> {
String[] remaining = Arrays.copyOfRange(values, index, values.length);
position.set(Position.KEY_RESULT, String.join(",", remaining));
- break;
- default:
- break;
+ }
}
return !position.getAttributes().isEmpty() ? position : null;
diff --git a/src/main/java/org/traccar/protocol/Xrb28ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xrb28ProtocolEncoder.java
index 3e69af329..cdb55c310 100644
--- a/src/main/java/org/traccar/protocol/Xrb28ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xrb28ProtocolEncoder.java
@@ -33,25 +33,22 @@ public class Xrb28ProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Channel channel, Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, command.getString(Command.KEY_DATA));
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "D0");
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(command, "D1," + command.getInteger(Command.KEY_FREQUENCY));
- case Command.TYPE_ENGINE_STOP:
- case Command.TYPE_ALARM_DISARM:
+ return switch (command.getType()) {
+ case Command.TYPE_CUSTOM -> formatCommand(command, command.getString(Command.KEY_DATA));
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "D0");
+ case Command.TYPE_POSITION_PERIODIC ->
+ formatCommand(command, "D1," + command.getInteger(Command.KEY_FREQUENCY));
+ case Command.TYPE_ENGINE_STOP, Command.TYPE_ALARM_DISARM -> {
if (channel != null) {
Xrb28ProtocolDecoder decoder = channel.pipeline().get(Xrb28ProtocolDecoder.class);
if (decoder != null) {
decoder.setPendingCommand(command.getType());
}
}
- return formatCommand(command, "R0,0,20,1234," + System.currentTimeMillis() / 1000);
- default:
- return null;
- }
+ yield formatCommand(command, "R0,0,20,1234," + System.currentTimeMillis() / 1000);
+ }
+ default -> null;
+ };
}
}
diff --git a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
index 11f9e0654..ce097740a 100644
--- a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
@@ -126,76 +126,41 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
for (byte b : format) {
int tag = b & 0xFF;
switch (tag) {
- case 0x03:
+ case 0x03 -> {
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
- break;
- case 0x04:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x05:
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
- break;
- case 0x06:
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- break;
- case 0x07:
- position.setLatitude(buf.readInt() * 0.000001);
- break;
- case 0x08:
- position.setLongitude(buf.readInt() * 0.000001);
- break;
- case 0x09:
- position.setAltitude(buf.readShort() * 0.1);
- break;
- case 0x0a:
- position.setCourse(buf.readShort() * 0.1);
- break;
- case 0x0b:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- break;
- case 0x10:
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
- break;
- case 0x12:
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
- break;
- case 0x13:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case 0x14:
- position.set(Position.KEY_RSSI, buf.readShort());
- break;
- case 0x16:
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
- break;
- case 0x17:
- position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1);
- break;
- case 0x57:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort());
- break;
- case 0x65:
- position.set(Position.KEY_VIN, buf.readSlice(17).toString(StandardCharsets.US_ASCII));
- break;
- case 0x6C:
+ }
+ case 0x04 -> position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ case 0x05 -> position.set(Position.KEY_INDEX, buf.readUnsignedShort());
+ case 0x06 -> position.setTime(new Date(buf.readUnsignedInt() * 1000));
+ case 0x07 -> position.setLatitude(buf.readInt() * 0.000001);
+ case 0x08 -> position.setLongitude(buf.readInt() * 0.000001);
+ case 0x09 -> position.setAltitude(buf.readShort() * 0.1);
+ case 0x0a -> position.setCourse(buf.readShort() * 0.1);
+ case 0x0b -> position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ case 0x10 -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
+ case 0x12 -> position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
+ case 0x13 -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ case 0x14 -> position.set(Position.KEY_RSSI, buf.readShort());
+ case 0x16 -> position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
+ case 0x17 -> position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1);
+ case 0x57 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort());
+ case 0x65 -> position.set(Position.KEY_VIN, buf.readSlice(17).toString(StandardCharsets.US_ASCII));
+ case 0x6C -> {
buf.readUnsignedByte(); // mil
int ecuCount = buf.readUnsignedByte();
for (int i = 0; i < ecuCount; i++) {
buf.readUnsignedByte(); // ecu id
buf.skipBytes(buf.readUnsignedByte() * 6);
}
- break;
- case 0x73:
- position.set(Position.KEY_VERSION_FW, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim());
- break;
- default:
- buf.skipBytes(getTagLength(tag));
- break;
+ }
+ case 0x73 -> position.set(
+ Position.KEY_VERSION_FW, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim());
+ default -> buf.skipBytes(getTagLength(tag));
}
}