diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-07-07 12:38:28 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-07-07 12:38:28 -0700 |
commit | 0130b9093bca894268493d27173e8ecac02c0179 (patch) | |
tree | b0e638a7f91fc844ce17ffc967805af575dec7fc /src/main/java/org/traccar/protocol | |
parent | cd13e96debdfe28233ef8f5b0d77688b02ce0d44 (diff) | |
download | traccar-server-0130b9093bca894268493d27173e8ecac02c0179.tar.gz traccar-server-0130b9093bca894268493d27173e8ecac02c0179.tar.bz2 traccar-server-0130b9093bca894268493d27173e8ecac02c0179.zip |
Decode OBD data
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-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); |