Skip to content

Add external voltage extraction for h02 protocol (replaces #5703)#5788

Open
benjamingray123 wants to merge 1 commit intotraccar:masterfrom
benjamingray123:fix/h02-extended-voltage
Open

Add external voltage extraction for h02 protocol (replaces #5703)#5788
benjamingray123 wants to merge 1 commit intotraccar:masterfrom
benjamingray123:fix/h02-extended-voltage

Conversation

@benjamingray123
Copy link

This PR replaces #5703 which was accidentally closed due to a force-push error.

It addresses all maintainer feedback from the previous PR:

  • Uses relative readableBytes() checks instead of absolute indexes
  • Removes duplicate unit tests
  • Keeps frame decoder logic configurable via config (no code changes to H02FrameDecoder)

Original description below:


Following my post in the forum: https://www.traccar.org/forums/topic/automotive-relay-style-cj7320-cj730-lk720-not-displaying-vehicle-battery-voltage/

My code adds support for extracting external/vehicle battery voltage from H02 protocol binary messages with extended format (47 bytes).

The frame decoder now correctly detects and reads extended format messages when configured with protocol.h02.messageLength=47.

Changes

  • H02ProtocolDecoder.java: Extract voltage from bytes -3 and -2 (before record number byte) using relative buffer operations
  • H02ProtocolDecoderTest.java: Add unit test for voltage extraction

Configuration
Users with extended format devices should set:

<entry key='protocol.h02.messageLength'>47</entry>

Comment on lines +158 to +161
if (buf.readableBytes() >= 3) {
buf.skipBytes(buf.readableBytes() - 3);
position.set(Position.KEY_POWER, buf.readUnsignedShort() / 10.0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definitely conflicts with other protocols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants