Skip to content

fix(ld2451): fix FrameParser return semantics, skip config frames, document direction byte#2

Merged
poolski merged 3 commits into
mainfrom
claude/awesome-blackburn-0383ac
May 23, 2026
Merged

fix(ld2451): fix FrameParser return semantics, skip config frames, document direction byte#2
poolski merged 3 commits into
mainfrom
claude/awesome-blackburn-0383ac

Conversation

@poolski
Copy link
Copy Markdown
Owner

@poolski poolski commented May 23, 2026

Summary

  • Fix FrameParser::pop() return value on tail mismatch — previously returned true (implying a frame was produced) when the tail bytes didn't match and only 1 byte was advanced. Now returns false, consistent with the API contract that true means a complete frame was consumed.
  • Fix extract_frame_() frame_produced tracking — the loop() drain loop was setting parsed_frame = true even for sync-error retries (tail mismatch advances), silently suppressing the RX-activity diagnostic log. Refactored to separate "should keep draining" (return value) from "did a real frame get parsed" (new bool &frame_produced reference param).
  • Skip config/ACK frames cleanly in both parsers — the sensor emits two frame types: data (F4 F3 F2 F1 header) and config/ACK (FD FC FB FA header). Previously a config ACK would be consumed byte-by-byte as the parser searched for the data header, causing spurious log noise and delaying the next real frame. Both FrameParser::pop() and LD2451Component::extract_frame_() now detect the config header, read the 2-byte LE length, and erase the complete config frame in one operation.
  • Document direction byte convention — cross-referenced three external implementations (jbeale monitor, Fiooodooor LD245X, Madproforg HLK_LD2451) to resolve an ambiguity in the official PDF. Added a comment in types.h confirming 0x00 = Approaching, 0x01 = Moving away.

Test plan

  • New tests in frame_parser_test.cpp: config frame followed by data frame parses correctly; tail mismatch returns false
  • All existing host tests still pass (bash components/ld2451/tests_host/run_host_tests.sh)
  • Smoke test on hardware: verify no regression in normal target detection and that config-frame log noise is gone at startup

Note

I used Claude Code for some of these changes

@poolski poolski merged commit 6dddd72 into main May 23, 2026
2 checks passed
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