The ESP-IDF project, docs, tools, tests and web UI move from v2/ to the root, and the Makefile, README, build scripts and test runner drop the v2/ prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
2.0 KiB
C
50 lines
2.0 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include "esp_err.h"
|
|
|
|
// Reliable bulk link on top of espnow_tx. Wire format is documented in
|
|
// led-driver/src/espnow_rx.py:
|
|
// All frames are 0x4C wire packets with extra message types (see led-driver/src/espnow_rx.py):
|
|
// data [4C][20][flags][seq u16][ver u16][idx][cnt] + fragment of an inner packet (<= 9 + 238)
|
|
// ack [4C][21][0][seq u16][cnt][mask u32] (driver -> us)
|
|
// digest [4C][22][ver u16] (broadcast)
|
|
// resync [4C][23][ver u16] (driver -> us)
|
|
// echo [4C][24][beat_idx u16] (driver -> us, bench)
|
|
#define REL_FRAG_MAX 238 // inner packet bytes per frame; 4C 03/04 wrappers plus an envelope fit in one
|
|
#define REL_MAX_FRAGS 32
|
|
|
|
typedef struct {
|
|
uint32_t acked;
|
|
uint32_t ack_timeouts;
|
|
uint32_t retransmits;
|
|
uint32_t resyncs;
|
|
uint32_t digests;
|
|
} rel_stats_t;
|
|
|
|
typedef void (*rel_resync_cb_t)(const uint8_t mac[6]);
|
|
|
|
esp_err_t rel_init(void);
|
|
|
|
// Send a message of any size up to REL_MAX_FRAGS * REL_FRAG_MAX.
|
|
// mac == NULL broadcasts it `repeat` times with one sequence number (no acks);
|
|
// otherwise it is unicast, acknowledged by the driver and retransmitted until
|
|
// acked or given up on. commit makes the driver adopt the current state version.
|
|
esp_err_t rel_send(const uint8_t *mac, const void *data, size_t len, bool commit, int repeat);
|
|
|
|
// A broadcast state change happened: advance the version drivers compare in digests
|
|
void rel_bump_ver(void);
|
|
uint16_t rel_ver(void);
|
|
|
|
void rel_set_resync_cb(rel_resync_cb_t cb);
|
|
|
|
// A driver announced itself at boot: a 0x4C ANNOUNCE packet or its JSON hello (called from the rel task)
|
|
typedef void (*rel_announce_cb_t)(const uint8_t mac[6], const uint8_t *pkt, int len);
|
|
void rel_set_announce_cb(rel_announce_cb_t cb);
|
|
void rel_stats(rel_stats_t *out);
|
|
|
|
// Milliseconds since the driver last acked; -1 if never. fails = consecutive unacked messages
|
|
int rel_peer_status(const uint8_t mac[6], int *fails);
|