From a8bd4f09290bd8965fa8880ddbbf377fb2d6d3f0 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Mon, 10 Mar 2025 19:35:10 +0800 Subject: [PATCH] fix(wifi): Return more information in the espnow send callback --- components/esp_wifi/include/esp_now.h | 17 +++++++++++------ examples/wifi/espnow/main/espnow_example_main.c | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/components/esp_wifi/include/esp_now.h b/components/esp_wifi/include/esp_now.h index 521dcbb59a..3b94187c65 100644 --- a/components/esp_wifi/include/esp_now.h +++ b/components/esp_wifi/include/esp_now.h @@ -57,8 +57,8 @@ extern "C" { * @brief Status of sending ESPNOW data . */ typedef enum { - ESP_NOW_SEND_SUCCESS = 0, /**< Send ESPNOW data successfully */ - ESP_NOW_SEND_FAIL, /**< Send ESPNOW data fail */ + ESP_NOW_SEND_SUCCESS = WIFI_SEND_SUCCESS, /**< Send ESPNOW data successfully */ + ESP_NOW_SEND_FAIL = WIFI_SEND_FAIL, /**< Send ESPNOW data fail */ } esp_now_send_status_t; /** @@ -84,7 +84,7 @@ typedef struct esp_now_peer_num { } esp_now_peer_num_t; /** - * @brief ESPNOW packet information + * @brief ESPNOW receive packet information */ typedef struct esp_now_recv_info { uint8_t * src_addr; /**< Source address of ESPNOW packet */ @@ -92,6 +92,11 @@ typedef struct esp_now_recv_info { wifi_pkt_rx_ctrl_t * rx_ctrl; /**< Rx control info of ESPNOW packet */ } esp_now_recv_info_t; +/** + * @brief ESPNOW sending packet information + */ +typedef wifi_tx_info_t esp_now_send_info_t; + /** * @brief ESPNOW rate config */ @@ -108,10 +113,10 @@ typedef void (*esp_now_recv_cb_t)(const esp_now_recv_info_t * esp_now_info, cons /** * @brief Callback function of sending ESPNOW data - * @param mac_addr peer MAC address - * @param status status of sending ESPNOW data (succeed or fail) + * @param esp_now_send_info_t Sending information for ESPNOW data + * @param status status of sending ESPNOW data (succeed or fail). This is will be removed later, since the tx_info->tx_status also works. */ -typedef void (*esp_now_send_cb_t)(const uint8_t *mac_addr, esp_now_send_status_t status); +typedef void (*esp_now_send_cb_t)(const esp_now_send_info_t *tx_info, esp_now_send_status_t status); /** * @brief Initialize ESPNOW function diff --git a/examples/wifi/espnow/main/espnow_example_main.c b/examples/wifi/espnow/main/espnow_example_main.c index 98d4d47692..61dfb55e14 100644 --- a/examples/wifi/espnow/main/espnow_example_main.c +++ b/examples/wifi/espnow/main/espnow_example_main.c @@ -61,18 +61,18 @@ static void example_wifi_init(void) /* ESPNOW sending or receiving callback function is called in WiFi task. * Users should not do lengthy operations from this task. Instead, post * necessary data to a queue and handle it from a lower priority task. */ -static void example_espnow_send_cb(const uint8_t *mac_addr, esp_now_send_status_t status) +static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status) { example_espnow_event_t evt; example_espnow_event_send_cb_t *send_cb = &evt.info.send_cb; - if (mac_addr == NULL) { + if (tx_info == NULL) { ESP_LOGE(TAG, "Send cb arg error"); return; } evt.id = EXAMPLE_ESPNOW_SEND_CB; - memcpy(send_cb->mac_addr, mac_addr, ESP_NOW_ETH_ALEN); + memcpy(send_cb->mac_addr, tx_info->des_addr, ESP_NOW_ETH_ALEN); send_cb->status = status; if (xQueueSend(s_example_espnow_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) { ESP_LOGW(TAG, "Send send queue fail");