diff options
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java index 8a937a194..9449e2d5c 100644 --- a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java @@ -83,7 +83,7 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { int subtype = buf.readUnsignedShort(); int length = buf.readUnsignedShort() - 4; if (subtype == 0x0003) { - String imei = buf.readSlice(length).toString(StandardCharsets.US_ASCII); + String imei = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString(); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null && channel != null) { ByteBuf content = Unpooled.buffer(); @@ -117,7 +117,7 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, BitUtil.check(status, 14)); position.set(Position.KEY_EVENT, buf.readUnsignedShort()); - String time = buf.readSlice(12).toString(StandardCharsets.US_ASCII); + String time = buf.readCharSequence(12, StandardCharsets.US_ASCII).toString(); DateBuilder dateBuilder = new DateBuilder() .setYear(Integer.parseInt(time.substring(0, 2))) @@ -138,9 +138,33 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000); while (buf.readableBytes() > 4) { - buf.readUnsignedShort(); // subtype + int subtype = buf.readUnsignedShort(); int length = buf.readUnsignedShort() - 4; - buf.skipBytes(length); + switch (subtype) { + case 0x0001: + position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + position.set(Position.KEY_RPM, buf.readUnsignedShort()); + position.set("averageSpeed", buf.readUnsignedByte()); + buf.readUnsignedShort(); // interval fuel consumption + position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort()); + position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); + position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); + buf.readUnsignedInt(); // trip id + break; + case 0x0005: + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + position.set(Position.KEY_HDOP, buf.readUnsignedByte()); + buf.readUnsignedInt(); // run time + break; + case 0x0009: + position.set( + Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString()); + break; + default: + buf.skipBytes(length); + break; + } } sendResponse(channel, MSG_POSITION_RSP, index, null); |