Skip to content

Commit

Permalink
Merge branch 'feat/espnow_rx_cb_opt' into 'master'
Browse files Browse the repository at this point in the history
esp_wifi: upload more pkt info for espnow rx cb

Closes WIFI-4754

See merge request espressif/esp-idf!18261
  • Loading branch information
jack0c committed Dec 6, 2022
2 parents 454aeb3 + 45ead31 commit 8223a59
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions components/esp_wifi/include/esp_now.h
Expand Up @@ -80,13 +80,23 @@ typedef struct esp_now_peer_num {
int encrypt_num; /**< Number of encrypted ESPNOW peers, maximum value is ESP_NOW_MAX_ENCRYPT_PEER_NUM */
} esp_now_peer_num_t;

/**
* @brief ESPNOW packet information
*/
typedef struct esp_now_recv_info {
uint8_t * src_addr; /**< Source address of ESPNOW packet */
uint8_t * des_addr; /**< Destination address of ESPNOW packet */
wifi_pkt_rx_ctrl_t * rx_ctrl; /**< Rx control info of ESPNOW packet */
} esp_now_recv_info_t;

/**
* @brief Callback function of receiving ESPNOW data
* @param mac_addr peer MAC address
* @param esp_now_info received ESPNOW packet information
* @param data received data
* @param data_len length of received data
* @attention esp_now_info is a local variable,it can only be used in the callback.
*/
typedef void (*esp_now_recv_cb_t)(const uint8_t *mac_addr, const uint8_t *data, int data_len);
typedef void (*esp_now_recv_cb_t)(const esp_now_recv_info_t * esp_now_info, const uint8_t *data, int data_len);

/**
* @brief Callback function of sending ESPNOW data
Expand Down
1 change: 1 addition & 0 deletions components/esp_wifi/include/esp_wifi_types.h
Expand Up @@ -489,6 +489,7 @@ typedef struct {
typedef struct {
wifi_pkt_rx_ctrl_t rx_ctrl;/**< received packet radio metadata header of the CSI data */
uint8_t mac[6]; /**< source MAC address of the CSI data */
uint8_t dmac[6]; /**< destination MAC address of the CSI data */
bool first_word_invalid; /**< first four bytes of the CSI data is invalid or not */
int8_t *buf; /**< buffer of CSI data */
uint16_t len; /**< length of CSI data */
Expand Down
3 changes: 2 additions & 1 deletion examples/wifi/espnow/main/espnow_example_main.c
Expand Up @@ -79,10 +79,11 @@ static void example_espnow_send_cb(const uint8_t *mac_addr, esp_now_send_status_
}
}

static void example_espnow_recv_cb(const uint8_t *mac_addr, const uint8_t *data, int len)
static void example_espnow_recv_cb(const esp_now_recv_info_t *recv_info, const uint8_t *data, int len)
{
example_espnow_event_t evt;
example_espnow_event_recv_cb_t *recv_cb = &evt.info.recv_cb;
uint8_t * mac_addr = recv_info->src_addr;

if (mac_addr == NULL || data == NULL || len <= 0) {
ESP_LOGE(TAG, "Receive cb arg error");
Expand Down

0 comments on commit 8223a59

Please sign in to comment.