Skip to content

fix(_read_metadata): accumulate split serial chunks so calibration survives (#61)#64

Closed
jmdevita wants to merge 1 commit into
IRNAS:masterfrom
jmdevita:fix/read-metadata-accumulate
Closed

fix(_read_metadata): accumulate split serial chunks so calibration survives (#61)#64
jmdevita wants to merge 1 commit into
IRNAS:masterfrom
jmdevita:fix/read-metadata-accumulate

Conversation

@jmdevita

@jmdevita jmdevita commented Jul 1, 2026

Copy link
Copy Markdown

Problem

_read_metadata() returns as soon as a single serial read contains "END", without accumulating earlier reads. The PPK2 sends its calibration metadata as one multi-line ASCII string ending in END, which the USB serial driver can split across multiple reads (reproducible on macOS). When that happens, calibration fields delivered in the earlier chunk — O, S, I, GS, GI, HW — are silently dropped and left at their default of 0.

With the range-0 zero-point offset O[0] missing, every low-µA reading gains a fixed offset of roughly ~1.8 µA, with no error raised — so low-current measurements read systematically high versus the nRF Connect Power Profiler.

Fix

Accumulate each decoded chunk and only return once "END" appears in the combined string (matching the official Power Profiler). The retry budget is raised 5 → 10 since a split stream needs several reads.

Test

Adds tests/test_read_metadata.py: feeds a split metadata stream through a fake serial port and asserts the full string survives and the parsed O[0] offset is preserved (it stays 0 under the old drop-chunks behaviour).

Fixes #61. This is the same root cause and approach as #62 — opening it with an accompanying regression test; happy to defer to whichever you prefer to merge.

…rvives

_read_metadata() read the device metadata in a loop but returned as soon as a
single serial read contained "END", discarding every earlier chunk. The PPK2
sends its calibration metadata as one multi-line ASCII string ending in "END",
which the USB serial driver can split across multiple reads (observed on macOS).
When that happened, calibration fields delivered in earlier chunks -- O, S, I,
GS, GI, HW -- were silently dropped and left at their default of 0. With the
range-0 zero-point offset O[0] missing, every low-uA reading gained a fixed
offset of roughly ~1.8 uA, with no error raised.

Accumulate each decoded chunk and only return once "END" appears in the
combined string (matching the official nRF Connect Power Profiler). Bump the
retry budget 5 -> 10 since a split stream needs several reads.

Bumps the version to 0.9.3 to distinguish this build from the PyPI 0.9.2 that
predates it. Same approach as upstream PR IRNAS#62; fixes IRNAS#61.

Adds tests/test_read_metadata.py: feeds a split metadata stream through a fake
serial port and asserts the full string survives and the parsed O[0] offset is
preserved (would stay 0 under the old drop-chunks behaviour).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit c3e138e)
@jmdevita

jmdevita commented Jul 1, 2026

Copy link
Copy Markdown
Author

Closing for now — opened prematurely; will re-open after review on my fork.

@jmdevita jmdevita closed this Jul 1, 2026
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.

_read_metadata() drops calibration fields when metadata arrives split across multiple serial reads

1 participant