diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
commit | 55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch) | |
tree | b86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | |
parent | c04ad7d48331253c095fc123ded1b00f6ff871d3 (diff) | |
parent | 2788174193def918a3a1a5be3bbed24c9613323f (diff) | |
download | trackermap-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/HuabaoProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | 312 |
1 files changed, 95 insertions, 217 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index d010a8fe0..443da28a3 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -323,77 +323,39 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); int length = buf.readUnsignedByte(); switch (type) { - case 0x01: - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100L); - break; - case 0x02: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.1); - break; - case 0x03: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x56: + case 0x01 -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100L); + case 0x02 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.1); + case 0x03 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x56 -> { buf.readUnsignedByte(); // power level position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); - break; - case 0x61: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); - break; - case 0x69: - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); - break; - case 0x80: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); - break; - case 0x81: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x82: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); - break; - case 0x83: - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); - break; - case 0x84: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); - break; - case 0x85: - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort()); - break; - case 0x86: - position.set("intakeTemp", buf.readUnsignedByte() - 40); - break; - case 0x87: - position.set("intakeFlow", buf.readUnsignedShort()); - break; - case 0x88: - position.set("intakePressure", buf.readUnsignedByte()); - break; - case 0x89: - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); - break; - case 0x8B: + } + case 0x61 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); + case 0x69 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); + case 0x80 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); + case 0x81 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x82 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); + case 0x83 -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); + case 0x84 -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + case 0x85 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort()); + case 0x86 -> position.set("intakeTemp", buf.readUnsignedByte() - 40); + case 0x87 -> position.set("intakeFlow", buf.readUnsignedShort()); + case 0x88 -> position.set("intakePressure", buf.readUnsignedByte()); + case 0x89 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + case 0x8B -> { position.set(Position.KEY_VIN, buf.readCharSequence(17, StandardCharsets.US_ASCII).toString()); - break; - case 0x8C: - position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100L); - break; - case 0x8D: - position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 1000L); - break; - case 0x8E: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); - break; - case 0xA0: + } + case 0x8C -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100L); + case 0x8D -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 1000L); + case 0x8E -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + case 0xA0 -> { String codes = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString(); position.set(Position.KEY_DTCS, codes.replace(',', ' ')); - break; - case 0xCC: + } + case 0xCC -> { position.set(Position.KEY_ICCID, buf.readCharSequence(20, StandardCharsets.US_ASCII).toString()); - break; - default: - buf.skipBytes(length); - break; + } + default -> buf.skipBytes(length); } } } @@ -543,20 +505,10 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // alarm serial number buf.readUnsignedByte(); // alarm status switch (buf.readUnsignedByte()) { - case 0x01: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 0x02: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 0x03: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 0x16: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - default: - break; + case 0x01 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 0x02 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 0x03 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 0x16 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); } break; case 0x69: @@ -710,68 +662,49 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); break; + case 0xF1: + position.set(Position.KEY_POWER, buf.readUnsignedInt() * 0.001); + break; case 0xF3: while (buf.readerIndex() < endIndex) { int extendedType = buf.readUnsignedShort(); int extendedLength = buf.readUnsignedByte(); switch (extendedType) { - case 0x0002: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x0003: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x0004: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); - break; - case 0x0005: - position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100); - break; - case 0x0007: - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.1); - break; - case 0x0008: - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedShort() * 0.1); - break; - case 0x0009: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShort() - 40); - break; - case 0x000B: - position.set("intakePressure", buf.readUnsignedShort()); - break; - case 0x000C: - position.set("intakeTemp", buf.readUnsignedShort() - 40); - break; - case 0x000D: - position.set("intakeFlow", buf.readUnsignedShort()); - break; - case 0x000E: - position.set(Position.KEY_THROTTLE, buf.readUnsignedShort() * 100 / 255); - break; - case 0x0050: + case 0x0002 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x0003 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x0004 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); + case 0x0005 -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100); + case 0x0007 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.1); + case 0x0008 -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedShort() * 0.1); + case 0x0009 -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShort() - 40); + case 0x000B -> position.set("intakePressure", buf.readUnsignedShort()); + case 0x000C -> position.set("intakeTemp", buf.readUnsignedShort() - 40); + case 0x000D -> position.set("intakeFlow", buf.readUnsignedShort()); + case 0x000E -> position.set(Position.KEY_THROTTLE, buf.readUnsignedShort() * 100 / 255); + case 0x0050 -> { position.set(Position.KEY_VIN, buf.readSlice(17).toString(StandardCharsets.US_ASCII)); - break; - case 0x0100: - position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 0.1); - break; - case 0x0102: - position.set("tripFuel", buf.readUnsignedShort() * 0.1); - break; - case 0x0112: - position.set("hardAccelerationCount", buf.readUnsignedShort()); - break; - case 0x0113: - position.set("hardDecelerationCount", buf.readUnsignedShort()); - break; - case 0x0114: - position.set("hardCorneringCount", buf.readUnsignedShort()); - break; - default: - buf.skipBytes(extendedLength); - break; + } + case 0x0100 -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 0.1); + case 0x0102 -> position.set("tripFuel", buf.readUnsignedShort() * 0.1); + case 0x0112 -> position.set("hardAccelerationCount", buf.readUnsignedShort()); + case 0x0113 -> position.set("hardDecelerationCount", buf.readUnsignedShort()); + case 0x0114 -> position.set("hardCorneringCount", buf.readUnsignedShort()); + default -> buf.skipBytes(extendedLength); } } break; + case 0xF7: + position.set(Position.KEY_BATTERY, buf.readUnsignedInt() * 0.001); + if (length >= 5) { + short batteryStatus = buf.readUnsignedByte(); + if (batteryStatus == 2 || batteryStatus == 3) { + position.set(Position.KEY_CHARGE, true); + } + } + if (length >= 6) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + } + break; case 0xFE: if (length == 1) { position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); @@ -982,77 +915,34 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { int id = buf.readUnsignedShort(); int length = buf.readUnsignedByte(); switch (id) { - case 0x0102: - case 0x0528: - case 0x0546: + case 0x0102, 0x0528, 0x0546 -> { position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100); - break; - case 0x0103: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01); - break; - case 0x0111: - position.set("fuelTemp", buf.readUnsignedByte() - 40); - break; - case 0x012E: - position.set("oilLevel", buf.readUnsignedShort() * 0.1); - break; - case 0x052A: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01); - break; - case 0x0105: - case 0x052C: - position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01); - break; - case 0x014A: - case 0x0537: - case 0x0538: - case 0x0539: + } + case 0x0103 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01); + case 0x0111 -> position.set("fuelTemp", buf.readUnsignedByte() - 40); + case 0x012E -> position.set("oilLevel", buf.readUnsignedShort() * 0.1); + case 0x052A -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01); + case 0x0105, 0x052C -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01); + case 0x014A, 0x0537, 0x0538, 0x0539 -> { position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01); - break; - case 0x052B: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); - break; - case 0x052D: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); - break; - case 0x052E: - position.set("airTemp", buf.readUnsignedByte() - 40); - break; - case 0x0530: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); - break; - case 0x0535: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x0536: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x053D: - position.set("intakePressure", buf.readUnsignedShort() * 0.1); - break; - case 0x0544: - position.set("liquidLevel", buf.readUnsignedByte()); - break; - case 0x0547: - case 0x0548: - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); - break; - default: + } + case 0x052B -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + case 0x052D -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + case 0x052E -> position.set("airTemp", buf.readUnsignedByte() - 40); + case 0x0530 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); + case 0x0535 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x0536 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x053D -> position.set("intakePressure", buf.readUnsignedShort() * 0.1); + case 0x0544 -> position.set("liquidLevel", buf.readUnsignedByte()); + case 0x0547, 0x0548 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + default -> { switch (length) { - case 1: - position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); - break; - case 2: - position.set(Position.PREFIX_IO + id, buf.readUnsignedShort()); - break; - case 4: - position.set(Position.PREFIX_IO + id, buf.readUnsignedInt()); - break; - default: - buf.skipBytes(length); - break; + case 1 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); + case 2 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedShort()); + case 4 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedInt()); + default -> buf.skipBytes(length); } - break; + } } } getLastLocation(position, time); @@ -1133,24 +1023,12 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { case 0x15: int event = buf.readInt(); switch (event) { - case 51: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 52: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 53: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 54: - position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); - break; - case 56: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - default: - position.set(Position.KEY_EVENT, event); - break; + case 51 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 52 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 53 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 54 -> position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); + case 56 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + default -> position.set(Position.KEY_EVENT, event); } getLastLocation(position, time); break; |