Fix ESP-NOW unicast by using sender MAC in client registry.
Register slaves from recv src_addr instead of protobuf mac bytes, add ESPNOW_UNICAST_TEST for path verification, restore unicast deadzone, and expose unicast-test in goTool. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -45,6 +45,22 @@ static client_slot_t *find_slot(const uint8_t mac[CLIENT_MAC_LEN]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void evict_stale_id(uint32_t id, const uint8_t mac[CLIENT_MAC_LEN]) {
|
||||
for (size_t i = 0; i < CLIENT_REGISTRY_MAX; i++) {
|
||||
if (!s_clients[i].active || s_clients[i].info.id != id) {
|
||||
continue;
|
||||
}
|
||||
if (mac_equal(s_clients[i].info.mac, mac)) {
|
||||
continue;
|
||||
}
|
||||
char old_mac[18];
|
||||
mac_to_str(s_clients[i].info.mac, old_mac, sizeof(old_mac));
|
||||
ESP_LOGW(TAG, "dropping stale id=%lu mac=%s (now %02x:…:%02x)", (unsigned long)id,
|
||||
old_mac, mac[0], mac[5]);
|
||||
s_clients[i].active = false;
|
||||
}
|
||||
}
|
||||
|
||||
static client_slot_t *alloc_slot(const uint8_t mac[CLIENT_MAC_LEN],
|
||||
bool *out_is_new) {
|
||||
client_slot_t *slot = find_slot(mac);
|
||||
@@ -98,6 +114,7 @@ esp_err_t client_registry_upsert(const uint8_t mac[CLIENT_MAC_LEN], uint32_t id,
|
||||
slot->info.used = used;
|
||||
slot->info.last_ping_at = ts;
|
||||
slot->info.last_success_ping_at = ts;
|
||||
evict_stale_id(id, mac);
|
||||
|
||||
if (out_is_new != NULL) {
|
||||
*out_is_new = is_new;
|
||||
@@ -130,6 +147,7 @@ esp_err_t client_registry_heartbeat(const uint8_t mac[CLIENT_MAC_LEN],
|
||||
slot->info.available = true;
|
||||
slot->info.last_ping_at = ts;
|
||||
slot->info.last_success_ping_at = ts;
|
||||
evict_stale_id(id, mac);
|
||||
|
||||
if (out_is_new != NULL) {
|
||||
*out_is_new = is_new;
|
||||
|
||||
Reference in New Issue
Block a user