Skip to content

hello battery offset + v24 rr slot cap - #74

Open
abdulsaheel wants to merge 2 commits into
mainfrom
fix/sweep-r2-protocol-main-1
Open

abdulsaheel wants to merge 2 commits into
mainfrom
fix/sweep-r2-protocol-main-1

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

hello battery scan started at payload[2], which is a fixed 0x04 byte. with a battery low byte of 1-3 it read 0x04|lo<<8 as 26.0/51.6/77.2% and never got to the real field at [3]. scan starts at 3 now.

v24/v12 records only have 4 rr slots (19..25) but the count was allowed up to 8, so a count of 5-8 read [27] and ppg_green as beats. capped at 4 there, 8 stays for r10.

also trimmed the labrador/mg comments down to the field facts.

Summary by Sourcery

Fix HELLO battery parsing and constrain v24/v12 R-R decoding to the slots available in each record.

Bug Fixes:

  • Correct battery percentage detection in HELLO payloads by skipping the fixed body byte before scanning for the battery field.
  • Reject invalid v24/v12 R-R counts above the four slots actually present, preventing unrelated fields from being decoded as beats.

Enhancements:

  • Simplify Labrador/MG field comments and documentation wording to focus on established field meanings.

Tests:

  • Add regression coverage for HELLO battery offsets and excessive v24 R-R counts.

Summary by CodeRabbit

  • Bug Fixes
    • Battery readings are now decoded from the correct field in hello messages, avoiding incorrect values caused by neighboring data.
    • Historical R-R records with declared counts above four now return no intervals, preventing unsupported values from being reported.
    • These fixes improve the accuracy of decoded battery readings and historical interval results.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry @abdulsaheel, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 9 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 55c6aa68-feea-49d5-919f-955fb5226fec
📥 Commits

Reviewing files that changed from the base of the PR and between cebbc68 and 3c92e0a.

📒 Files selected for processing (4)
  • lib/src/control.dart
  • test/doc_conformance_test.dart
  • test/gen5_historical_test.dart
  • test/labrador_reassembly_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The decoder now starts battery scanning at payload offset 3 and limits historical v24/v12 R-R slots to 4. Regression tests cover both guards. Comments and test descriptions were also revised.

Changes

Decode guards and protocol notes

Layer / File(s) Summary
Battery field parsing
lib/src/control.dart, test/decode_guards_test.dart
parseHello starts scanning at offset 3. Tests check battery values encoded at offsets 3–4.
Historical R-R slot limit
lib/src/records.dart, test/decode_guards_test.dart
The historical parser now accepts at most 4 v24/v12 R-R slots. Tests check that declared counts from 5 through 8 produce no intervals and an accepted count of zero.
Protocol and fixture notes
lib/src/labrador.dart, lib/src/control.dart, test/gen5_hello_maverick_test.dart, test/labrador_r17_test.dart, test/doc_conformance_test.dart, test/gen5_historical_test.dart, test/labrador_reassembly_test.dart
Comments describe Labrador packet layouts, flags, variability, and terminal states. Gen5 range and test-fixture descriptions were revised. A wire-format test was renamed without changing its assertions.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: droptabl

Merge Risk: ⚪ Minimal · up to 3c92e

The PR adjusts HELLO battery parsing and historical R-R slot handling, with regression tests for both paths. No merge-blocking risk is evident; it appears ready for normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: correcting the HELLO battery offset and limiting v24 R-R slots.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes HELLO battery detection by starting after the fixed prefix byte, caps v24/v12 R-R parsing at their four available slots while retaining the R10 cap of eight, and trims Labrador/MG comments to concise field-level facts.

Flow diagram for HELLO battery field detection

flowchart LR
    A[HELLO payload] --> B["payload[3..9] scan"]
    B --> C{u16 value 10..1000?}
    C -->|yes| D[Battery percentage]
    C -->|no| B
    E["payload[2] fixed 0x04 prefix"] -. skipped .-> B
Loading

Flow diagram for version-specific R-R slot caps

flowchart LR
    A[Record type] --> B{v24/v12?}
    B -->|yes| C[_kV24RrSlots = 4]
    B -->|no R10| D[kMaxRrPerRecord = 8]
    C --> E{Declared count within cap?}
    D --> E
    E -->|yes| F[Read available R-R intervals]
    E -->|no| G[Return no R-R intervals]
Loading

File-Level Changes

Change Details Files
Correct HELLO battery field discovery by skipping the fixed body prefix byte.
  • Start the u16 battery scan at payload offset 3 instead of 2.
  • Add regression coverage for low-byte values that previously produced false battery percentages and retain coverage for the real field.
lib/src/control.dart
test/decode_guards_test.dart
Enforce the four-slot R-R layout for v24/v12 records while preserving the eight-slot R10 limit.
  • Introduce a v24/v12-specific four-slot cap and reject counts above it without parsing following fields as intervals.
  • Update guard documentation and add tests covering counts 5 through 8.
lib/src/records.dart
test/decode_guards_test.dart
Simplify Labrador/MG documentation to describe only established field facts and parser behavior.
  • Trim source-provenance and application-specific commentary from Labrador comments.
  • Align synthetic fixture comments and clarify concise field semantics.
lib/src/control.dart
lib/src/labrador.dart
test/gen5_hello_maverick_test.dart
test/labrador_r17_test.dart

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

1 participant