fix: config serialization correctness — padding, mfr metadata, sizes, tx_power (C7/C8/M5/M6)#100
Merged
g4bri3lDev merged 1 commit intoJul 5, 2026
Conversation
… tx_power C8: every serializer except display truncated fixed-size reserved buffers with reserved[:N] and no padding. The TLV format has no per-packet length, so one short packet shifts and misparses everything after it on the device. Pad all fixed-size buffers on serialize (ljust to the exact width). C7: _parse_manufacturer_data stored data[4:22] into reserved and left the simple-config fields at 0; a read-modify-write then zeroed the toolbox simple-config metadata at offsets 4-15. Delegate to ManufacturerData.from_bytes, which parses the layout correctly. M5: public from_bytes SIZE constants disagreed with the firmware structs (DisplayConfig 66->46, PowerOption 32->30, DataBus 28->30), so the public APIs misparsed real packets and DataBus.from_bytes produced a 12-byte reserved (feeding the C8 short-packet bug). Align the sizes and reserved slices. M6: tx_power was parsed signed in the BLE path, unsigned in from_bytes, and packed signed on serialize (firmware field is uint8). 0xF4 became -12 one way and serializing 244 raised struct.error. Treat as unsigned end-to-end. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four related config wire-format correctness fixes.
C8 — pad fixed-size buffers on serialize (🔴)
Every serializer except display did
reserved[:N]with no padding. The TLV format has no per-packet length — the firmwarememcpys a fixedsizeof(struct)— so one short packet shifts and misparses everything after it on the device. All fixed-size reserved buffers are nowljust-padded to their exact width.C7 — ManufacturerData round-trip corrupted bytes 4–21 (🔴)
_parse_manufacturer_datastoreddata[4:22]intoreservedand left the simple-config fields at 0, but the serializer writessimple_config_driver/display/power_index+configured_atat offsets 4–15. A read-modify-write therefore zeroed the toolbox "simple config" metadata. Now delegates toManufacturerData.from_bytes, which parses the layout correctly.M5 — public
from_bytesSIZE constants disagreed with firmware (🟠)DisplayConfig.SIZE 66→46,PowerOption.SIZE 32→30,DataBus.SIZE 28→30. The main parse path used the correct private sizes, but the public APIs rejected/misparsed real packets, andDataBus.from_bytesproduced a 12-byte reserved that fed the C8 short-packet bug. Sizes and reserved slices aligned to the firmware structs.M6 —
tx_powersign confusion (🟠)Parsed signed in the BLE path, unsigned in
from_bytes, packed signed on serialize (firmware field isuint8).0xF4became-12one way and serializing244raisedstruct.error. Now unsigned end-to-end.Test plan
uv run pytest -q→ 445 passed (6 new tests: mfr round-trip, public sizes, DisplayConfig/DataBus from_bytes, short-reserved padding, tx_power unsigned round-trip)ruff,mypyclean🤖 Generated with Claude Code