26#ifndef PROTOCORE_LD2410_H
27#define PROTOCORE_LD2410_H
33#define LD2410_MAX_GATES 9
36#define LD2410_FRAME_MAX 72
bool pc_ld2410_ack_ok(const Ld2410Ack *ack)
True if ack reports success (Ld2410Ack::status == 0).
size_t pc_ld2410_cmd_bluetooth(uint8_t *buf, size_t cap, bool on)
LD2410B: turn the Bluetooth radio on (value 0x0001) or off (0x0000). Word 0x00A4.
size_t pc_ld2410_cmd_engineering(uint8_t *buf, size_t cap, bool on)
Enable (0x0062) or disable (0x0063) engineering mode.
size_t pc_ld2410_cmd_get_mac(uint8_t *buf, size_t cap)
LD2410B: query the module's Bluetooth MAC address (word 0x00A5, value 0x0001).
bool pc_ld2410_stream_push(Ld2410Stream *s, uint8_t byte, Ld2410Report *out)
Feed one received byte. When it completes a valid report frame, fills out and returns true; otherwise...
bool pc_ld2410_parse_ack(const uint8_t *frame, size_t len, Ld2410Ack *out)
Decode one command-ACK frame (header, intra-frame length, footer and length agreement all checked).
bool pc_ld2410_poll()
Pump the UART through the stream.
bool pc_ld2410_set_engineering(bool on)
Enable/disable engineering mode (brackets the command with enable/end).
size_t pc_ld2410_cmd_set_bt_password(uint8_t *buf, size_t cap, const char password[6])
LD2410B: set the 6-octet Bluetooth control password (word 0x00A9). Takes effect after a restart and s...
bool pc_ld2410_parse_report(const uint8_t *frame, size_t len, Ld2410Report *out)
Decode one whole LD2410 report frame (header F4 F3 F2 F1 .. footer F8 F7 F6 F5). Pure - no I/O....
bool pc_ld2410_present(const Ld2410Report *r)
true if r shows any target (moving or stationary).
#define LD2410_MAX_GATES
Range gates the LD2410 reports energy for in engineering mode (gate 0..8).
size_t pc_ld2410_cmd_restart(uint8_t *buf, size_t cap)
Restart the module (word 0x00A3).
void pc_ld2410_stream_reset(Ld2410Stream *s)
Reset a stream to the syncing state.
uint16_t pc_ld2410_distance_cm(const Ld2410Report *r)
Best available target distance (cm): the moving distance if moving, else stationary.
const Ld2410Report * pc_ld2410_last()
The most recently decoded report, or nullptr before the first one arrives.
size_t pc_ld2410_cmd_config_end(uint8_t *buf, size_t cap)
"End configuration" (word 0x00FE).
#define LD2410_FRAME_MAX
Largest assembled frame: header(4) + len(2) + payload(<=60) + footer(4), rounded up.
bool pc_ld2410_restart()
Restart the module (brackets the command with enable/end).
bool pc_ld2410_begin(int rx_pin, int tx_pin)
Open UART2 at PC_LD2410_BAUD on rx_pin / tx_pin.
bool pc_ld2410_ack_mac(const Ld2410Ack *ack, uint8_t mac[6])
Extract the 6-octet MAC from a get-MAC ACK (word 0x01A5) into mac, in wire order.
size_t pc_ld2410_cmd_config_enable(uint8_t *buf, size_t cap)
"Enable configuration" (word 0x00FF, value 0x0001).
A decoded command-ACK frame. payload points into the caller's frame (not copied).
uint16_t status
0 = success, 1 = failure.
size_t payload_len
octets at payload.
const uint8_t * payload
command-specific data after the status word (nullptr if none).
uint16_t command
ACK command word: the request word | 0x0100 (e.g. 0x01A5 for get-MAC).
A decoded LD2410 target report. Engineering fields are 0 unless engineering.
uint16_t detect_cm
overall detection distance (cm)
uint8_t static_gate_energy[LD2410_MAX_GATES]
per-gate stationary energy (0-100)
uint16_t moving_cm
moving target distance (cm)
uint8_t out_pin
OUT pin level (0/1)
uint8_t max_static_gate
highest configured stationary gate
uint8_t state
one of LD2410_STATE_*
uint8_t static_energy
stationary target energy (0-100)
uint8_t engineering
1 if this was an engineering-mode frame (per-gate energies valid)
uint8_t moving_gate_energy[LD2410_MAX_GATES]
per-gate moving energy (0-100)
uint8_t moving_energy
moving target energy (0-100)
uint8_t max_moving_gate
highest configured moving gate
uint8_t light
photosensor level (0-255)
uint16_t static_cm
stationary target distance (cm)
Target presence state (report payload byte 2).
static constexpr uint8_t LD2410_STATE_NONE
no target
static constexpr uint8_t LD2410_STATE_BOTH
both a moving and a stationary target
static constexpr uint8_t LD2410_STATE_STATIC
stationary target only
static constexpr uint8_t LD2410_STATE_MOVING
moving target only
Byte-by-byte report-frame reassembler (fixed buffer, resyncs on noise).
uint16_t pos
bytes collected so far
uint8_t hdr_match
header bytes matched while syncing (phase = pos<4)
uint16_t total
expected full-frame length (known after the length field)
uint8_t buf[LD2410_FRAME_MAX]
frame under construction
uint8_t phase
0 sync, 1 length, 2 body