forked from espressif/esp-idf
fix(wifi): Return more information in the espnow send callback
This commit is contained in:
@@ -57,8 +57,8 @@ extern "C" {
|
|||||||
* @brief Status of sending ESPNOW data .
|
* @brief Status of sending ESPNOW data .
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ESP_NOW_SEND_SUCCESS = 0, /**< Send ESPNOW data successfully */
|
ESP_NOW_SEND_SUCCESS = WIFI_SEND_SUCCESS, /**< Send ESPNOW data successfully */
|
||||||
ESP_NOW_SEND_FAIL, /**< Send ESPNOW data fail */
|
ESP_NOW_SEND_FAIL = WIFI_SEND_FAIL, /**< Send ESPNOW data fail */
|
||||||
} esp_now_send_status_t;
|
} esp_now_send_status_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +84,7 @@ typedef struct esp_now_peer_num {
|
|||||||
} esp_now_peer_num_t;
|
} esp_now_peer_num_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ESPNOW packet information
|
* @brief ESPNOW receive packet information
|
||||||
*/
|
*/
|
||||||
typedef struct esp_now_recv_info {
|
typedef struct esp_now_recv_info {
|
||||||
uint8_t * src_addr; /**< Source address of ESPNOW packet */
|
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 */
|
wifi_pkt_rx_ctrl_t * rx_ctrl; /**< Rx control info of ESPNOW packet */
|
||||||
} esp_now_recv_info_t;
|
} esp_now_recv_info_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ESPNOW sending packet information
|
||||||
|
*/
|
||||||
|
typedef wifi_tx_info_t esp_now_send_info_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ESPNOW rate config
|
* @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
|
* @brief Callback function of sending ESPNOW data
|
||||||
* @param mac_addr peer MAC address
|
* @param esp_now_send_info_t Sending information for ESPNOW data
|
||||||
* @param status status of sending ESPNOW data (succeed or fail)
|
* @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
|
* @brief Initialize ESPNOW function
|
||||||
|
@@ -61,18 +61,18 @@ static void example_wifi_init(void)
|
|||||||
/* ESPNOW sending or receiving callback function is called in WiFi task.
|
/* ESPNOW sending or receiving callback function is called in WiFi task.
|
||||||
* Users should not do lengthy operations from this task. Instead, post
|
* Users should not do lengthy operations from this task. Instead, post
|
||||||
* necessary data to a queue and handle it from a lower priority task. */
|
* 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_t evt;
|
||||||
example_espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
|
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");
|
ESP_LOGE(TAG, "Send cb arg error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.id = EXAMPLE_ESPNOW_SEND_CB;
|
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;
|
send_cb->status = status;
|
||||||
if (xQueueSend(s_example_espnow_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
|
if (xQueueSend(s_example_espnow_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
|
||||||
ESP_LOGW(TAG, "Send send queue fail");
|
ESP_LOGW(TAG, "Send send queue fail");
|
||||||
|
Reference in New Issue
Block a user