aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/CastelProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolDecoder.java108
1 files changed, 29 insertions, 79 deletions
diff --git a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
index b076b9f66..5cabeb5a4 100644
--- a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
@@ -162,20 +162,12 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
if (!PID_LENGTH_MAP.containsKey(pids[i])) {
throw new RuntimeException(String.format("Unknown PID 0x%02x", pids[i]));
}
- switch (PID_LENGTH_MAP.get(pids[i])) {
- case 1:
- value = buf.readUnsignedByte();
- break;
- case 2:
- value = buf.readUnsignedShortLE();
- break;
- case 4:
- value = buf.readIntLE();
- break;
- default:
- value = 0;
- break;
- }
+ value = switch (PID_LENGTH_MAP.get(pids[i])) {
+ case 1 -> buf.readUnsignedByte();
+ case 2 -> buf.readUnsignedShortLE();
+ case 4 -> buf.readIntLE();
+ default -> 0;
+ };
position.add(ObdDecoder.decodeData(pids[i], value, false));
}
}
@@ -250,62 +242,24 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
private void decodeAlarm(Position position, int alarm) {
switch (alarm) {
- case 0x01:
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case 0x02:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- case 0x03:
- position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
- break;
- case 0x04:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 0x05:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 0x06:
- position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
- break;
- case 0x07:
- position.set(Position.KEY_ALARM, Position.ALARM_TOW);
- break;
- case 0x08:
- position.set(Position.KEY_ALARM, Position.ALARM_HIGH_RPM);
- break;
- case 0x09:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
- break;
- case 0x0B:
- position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE);
- break;
- case 0x0C:
- position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
- break;
- case 0x0D:
- position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING);
- break;
- case 0x0E:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
- break;
- case 0x11:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
- break;
- case 0x12:
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- case 0x16:
- position.set(Position.KEY_IGNITION, true);
- break;
- case 0x17:
- position.set(Position.KEY_IGNITION, false);
- break;
- case 0x1C:
- position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
- break;
- default:
- break;
+ case 0x01 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ case 0x02 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ case 0x03 -> position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
+ case 0x04 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ case 0x05 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ case 0x06 -> position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
+ case 0x07 -> position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ case 0x08 -> position.set(Position.KEY_ALARM, Position.ALARM_HIGH_RPM);
+ case 0x09 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
+ case 0x0B -> position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE);
+ case 0x0C -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
+ case 0x0D -> position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING);
+ case 0x0E -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
+ case 0x11 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
+ case 0x12 -> position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
+ case 0x16 -> position.set(Position.KEY_IGNITION, true);
+ case 0x17 -> position.set(Position.KEY_IGNITION, false);
+ case 0x1C -> position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
}
}
@@ -623,15 +577,11 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- switch (version) {
- case -1:
- return decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession);
- case 3:
- case 4:
- return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
- default:
- return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
- }
+ return switch (version) {
+ case -1 -> decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession);
+ case 3, 4 -> decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
+ default -> decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
+ };
}
}