aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-07-07 07:33:16 -0700
committerAnton Tananaev <anton@traccar.org>2024-07-07 07:33:16 -0700
commitd0536ccbc1b7234784c5e48288bbac00a60ef821 (patch)
tree29ba8e1349eb9a5990f564edad7ddc7b5e24d7f7 /src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
parent864872b2df3e26c94d3a5826f4df504de3cf6c62 (diff)
downloadtrackermap-server-d0536ccbc1b7234784c5e48288bbac00a60ef821.tar.gz
trackermap-server-d0536ccbc1b7234784c5e48288bbac00a60ef821.tar.bz2
trackermap-server-d0536ccbc1b7234784c5e48288bbac00a60ef821.zip
Update switch statements
Diffstat (limited to 'src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java102
1 files changed, 30 insertions, 72 deletions
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);
}
}
}