From d0536ccbc1b7234784c5e48288bbac00a60ef821 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Jul 2024 07:33:16 -0700 Subject: Update switch statements --- .../protocol/ThinkPowerProtocolDecoder.java | 64 +++++++--------------- 1 file changed, 20 insertions(+), 44 deletions(-) (limited to 'src/main/java/org/traccar/protocol/ThinkPowerProtocolDecoder.java') 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; + } } } -- cgit v1.2.3