Assign sequential pod IDs from the master with NVS-stable bindings.
Replaces MAC-byte self-IDs with master allocation (1–255), slave preferred-ID reconnect, debug reset via UART/UI, and rate-limited ASSIGN to avoid ESP-NOW NO_MEM storms. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+23
-1
@@ -47,6 +47,8 @@ typedef struct {
|
||||
uint32_t lipo1_mv;
|
||||
uint32_t lipo2_mv;
|
||||
uint32_t battery_updated_at;
|
||||
/** Master: last ESPNOW_ASSIGN_ID send time (rate-limit resends). */
|
||||
uint32_t last_assign_sent_at;
|
||||
} client_info_t;
|
||||
|
||||
#define CLIENT_REGISTRY_DEFAULT_ACCEL_DEADZONE 100u
|
||||
@@ -55,6 +57,23 @@ typedef struct {
|
||||
|
||||
void client_registry_init(void);
|
||||
|
||||
/**
|
||||
* Assign a stable logical id for mac (1…255). Honors preferred if free or
|
||||
* already owned by mac; otherwise allocates the next free id. Persists the
|
||||
* master id map to NVS.
|
||||
*/
|
||||
esp_err_t client_registry_assign_id(const uint8_t mac[CLIENT_MAC_LEN],
|
||||
uint32_t preferred_id, uint32_t *out_id);
|
||||
|
||||
/**
|
||||
* Clear NVS id map, RAM map, and all live registry slots. Does not notify
|
||||
* slaves (caller sends CLEAR_ID_BINDING).
|
||||
*/
|
||||
void client_registry_clear_id_map(void);
|
||||
|
||||
/** Record that ASSIGN_ID was sent to this MAC (for resend rate limiting). */
|
||||
void client_registry_mark_assign_sent(const uint8_t mac[CLIENT_MAC_LEN]);
|
||||
|
||||
/** Milliseconds since boot (same clock as stored ping timestamps). */
|
||||
uint32_t client_registry_now_ms(void);
|
||||
|
||||
@@ -75,7 +94,10 @@ esp_err_t client_registry_heartbeat(const uint8_t mac[CLIENT_MAC_LEN],
|
||||
uint32_t id, uint32_t version, bool used,
|
||||
bool *out_is_new, bool *out_reactivated);
|
||||
|
||||
/** Mark clients inactive when last_success_ping_at is older than timeout_ms. */
|
||||
/**
|
||||
* Drop live registry slots whose last_success_ping_at is older than
|
||||
* timeout_ms (NVS id map unchanged). Offline clients disappear from CLIENT_INFO.
|
||||
*/
|
||||
void client_registry_check_timeouts(uint32_t timeout_ms);
|
||||
|
||||
size_t client_registry_count(void);
|
||||
|
||||
Reference in New Issue
Block a user