fix: write_config first chunk must carry 200 data bytes (C4)#99
Conversation
The chunked write_config first packet sent total_size(2) + 198 data = 200 payload bytes. Firmware enters chunked mode only when the payload length exceeds 200 and expects [total:2LE][200 data] = 202 payload bytes. With 200 bytes it took the single-chunk path and saveConfig()'d the 2-byte size header plus a truncated config, then NACKed every following 0x42 chunk; the 198-byte first chunk also broke its expectedChunks = ceil(total/200) accounting. Since a realistic full config exceeds 200 bytes, write_config was broken for most real configs. Send a full 200 data bytes in the first chunk. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
|
Independently re-verified this finding by simulating the firmware's Why this never failed in practice: typical configs never reach the chunked path. Serialized with this library: system + manufacturer + power + display = 133 bytes, plus an LED = 157 bytes — both ≤ 200, so they take the single-chunk path, which was always correct. The chunked path only engages above 200 bytes (e.g. any config with a The load-bearing firmware detail: the dispatcher calls Broken case, demonstrated (old code, 423-byte config with This PR's fix, verified against the same simulation: round-trips byte-identically at 201, 202, 250, 400, 401, 600, 3800, and 4000 bytes. One follow-up worth noting: the firmware rejects the 21st packet ( |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
The chunked
write_configfirst packet (build_write_config_command) senttotal_size(2) + 198 data = 200payload bytes. But the firmware:[total:2LE][200 data]= 202 payload bytes.With a 200-byte payload, the firmware took the single-chunk path and
saveConfig()'d the raw 200 bytes (the 2-byte size header plus a truncated config stored as the whole config), then NACKed every subsequent0x42chunk. The 198-byte first chunk also broke the firmware'sexpectedChunks = ceil(total / 200)accounting.Since a realistic full config (system + manufacturer + power + display + …) exceeds 200 bytes,
write_configwas broken against this firmware for most real configs.Fix
The first chunk now carries a full 200 data bytes (
payload = size(2) + 200 = 202), and continuations remain 200 bytes each — so the firmware enters chunked mode and itsceil(total/200)accounting matches.Test plan
uv run pytest -q→ 442 passed (3 new tests: single-chunk boundary, first chunk carries 200 data bytes, chunk count == ceil(total/200))ruff,mypyclean🤖 Generated with Claude Code