aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
committerIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
commit55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch)
treeb86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java
parentc04ad7d48331253c095fc123ded1b00f6ff871d3 (diff)
parent2788174193def918a3a1a5be3bbed24c9613323f (diff)
downloadtrackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolDecoder.java120
1 files changed, 40 insertions, 80 deletions
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)) {