Compare commits
No commits in common. "main" and "v1.7.0" have entirely different histories.
@ -187,18 +187,6 @@ extern "C"
|
|||||||
*/
|
*/
|
||||||
esp_err_t zh_espnow_get_mac(uint8_t *mac_addr);
|
esp_err_t zh_espnow_get_mac(uint8_t *mac_addr);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get the number of available places in the queue.
|
|
||||||
*
|
|
||||||
* @return Number of available places.
|
|
||||||
*/
|
|
||||||
uint8_t zh_espnow_get_queue_space(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Clean up the message queue.
|
|
||||||
*/
|
|
||||||
void zh_espnow_clear_queue(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
@ -1 +1 @@
|
|||||||
1.8.0
|
1.7.0
|
112
zh_espnow.c
112
zh_espnow.c
@ -14,13 +14,6 @@ static const char *TAG = "zh_espnow";
|
|||||||
return err; \
|
return err; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ZH_ESPNOW_CHECK_GOTO(cond, err, tag, msg, ...) \
|
|
||||||
if (!(cond)) \
|
|
||||||
{ \
|
|
||||||
ZH_ESPNOW_LOGE_ERR(msg, err); \
|
|
||||||
goto tag; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DATA_SEND_SUCCESS BIT0
|
#define DATA_SEND_SUCCESS BIT0
|
||||||
#define DATA_SEND_FAIL BIT1
|
#define DATA_SEND_FAIL BIT1
|
||||||
#define WAIT_CONFIRM_MAX_TIME 50
|
#define WAIT_CONFIRM_MAX_TIME 50
|
||||||
@ -58,9 +51,9 @@ static void _zh_espnow_process_send(_queue_t *queue);
|
|||||||
static void _zh_espnow_process_recv(_queue_t *queue);
|
static void _zh_espnow_process_recv(_queue_t *queue);
|
||||||
static void _zh_espnow_processing(void *pvParameter);
|
static void _zh_espnow_processing(void *pvParameter);
|
||||||
|
|
||||||
static EventGroupHandle_t _event_group_handle = NULL;
|
static EventGroupHandle_t _event_group_handle = {0};
|
||||||
static QueueHandle_t _queue_handle = NULL;
|
static QueueHandle_t _queue_handle = {0};
|
||||||
static TaskHandle_t _processing_task_handle = NULL;
|
static TaskHandle_t _processing_task_handle = {0};
|
||||||
static zh_espnow_init_config_t _init_config = {0};
|
static zh_espnow_init_config_t _init_config = {0};
|
||||||
static zh_espnow_stats_t _stats = {0};
|
static zh_espnow_stats_t _stats = {0};
|
||||||
static bool _is_initialized = false;
|
static bool _is_initialized = false;
|
||||||
@ -80,24 +73,66 @@ esp_err_t zh_espnow_init(const zh_espnow_init_config_t *config)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
esp_err_t err = _zh_espnow_validate_config(config);
|
esp_err_t err = _zh_espnow_validate_config(config);
|
||||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "ESP-NOW initialization failed. Initial configuration check failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW initial configuration check completed successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE("ESP-NOW initialization failed. Initial configuration check failed.");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("ESP-NOW initial configuration check completed successfully.");
|
||||||
|
}
|
||||||
_init_config = *config;
|
_init_config = *config;
|
||||||
err = _zh_espnow_init_wifi(config);
|
err = _zh_espnow_init_wifi(config);
|
||||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "ESP-NOW initialization failed. WiFi initialization failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("WiFi initialization completed successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE("ESP-NOW initialization failed. WiFi initialization failed.");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("WiFi initialization completed successfully.");
|
||||||
|
}
|
||||||
err = _zh_espnow_init_resources(config);
|
err = _zh_espnow_init_resources(config);
|
||||||
ZH_ESPNOW_CHECK_GOTO(err == ESP_OK, err, CLEANUP, "ESP-NOW initialization failed. Resources initialization failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW resources initialization completed successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE("ESP-NOW initialization failed. Resources initialization failed.");
|
||||||
|
goto CLEANUP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("ESP-NOW resources initialization completed successfully.");
|
||||||
|
}
|
||||||
err = esp_now_init();
|
err = esp_now_init();
|
||||||
ZH_ESPNOW_CHECK_GOTO(err == ESP_OK, err, CLEANUP, "ESP-NOW initialization failed. ESP-NOW driver initialization failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW driver initialization completed successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE_ERR("ESP-NOW initialization failed. ESP-NOW driver initialization failed.", err);
|
||||||
|
goto CLEANUP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("ESP-NOW driver initialization completed successfully.");
|
||||||
|
}
|
||||||
err = _zh_espnow_register_callbacks(config->battery_mode);
|
err = _zh_espnow_register_callbacks(config->battery_mode);
|
||||||
ZH_ESPNOW_CHECK_GOTO(err == ESP_OK, err, CLEANUP, "ESP-NOW initialization failed. ESP-NOW callbacks registration failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW callbacks registered successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE("ESP-NOW initialization failed. ESP-NOW callbacks registration failed.");
|
||||||
|
goto CLEANUP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("ESP-NOW callbacks registered successfully.");
|
||||||
|
}
|
||||||
err = _zh_espnow_create_task(config);
|
err = _zh_espnow_create_task(config);
|
||||||
ZH_ESPNOW_CHECK_GOTO(err == ESP_OK, err, CLEANUP, "ESP-NOW initialization failed. Processing task initialization failed.");
|
if (err != ESP_OK)
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW processing task initialization completed successfully.");
|
{
|
||||||
|
ZH_ESPNOW_LOGE("ESP-NOW initialization failed. Processing task initialization failed.");
|
||||||
|
goto CLEANUP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGI("ESP-NOW processing task initialization completed successfully.");
|
||||||
|
}
|
||||||
_is_initialized = true;
|
_is_initialized = true;
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW initialization completed successfully.");
|
ZH_ESPNOW_LOGI("ESP-NOW initialization completed successfully.");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
@ -237,7 +272,7 @@ static esp_err_t _zh_espnow_init_resources(const zh_espnow_init_config_t *config
|
|||||||
_event_group_handle = xEventGroupCreate();
|
_event_group_handle = xEventGroupCreate();
|
||||||
ZH_ESPNOW_CHECK(_event_group_handle != NULL, ESP_FAIL, "Event group creation failed.");
|
ZH_ESPNOW_CHECK(_event_group_handle != NULL, ESP_FAIL, "Event group creation failed.");
|
||||||
_queue_handle = xQueueCreate(config->queue_size, sizeof(_queue_t));
|
_queue_handle = xQueueCreate(config->queue_size, sizeof(_queue_t));
|
||||||
ZH_ESPNOW_CHECK(_queue_handle != NULL, ESP_FAIL, "Queue creation failed.");
|
ZH_ESPNOW_CHECK(_queue_handle != 0, ESP_FAIL, "Queue creation failed.");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +562,11 @@ esp_err_t zh_espnow_set_channel(uint8_t channel)
|
|||||||
ZH_ESPNOW_CHECK(_is_initialized == true, ESP_ERR_INVALID_STATE, "ESP-NOW channel set failed. ESP-NOW is not initialized.");
|
ZH_ESPNOW_CHECK(_is_initialized == true, ESP_ERR_INVALID_STATE, "ESP-NOW channel set failed. ESP-NOW is not initialized.");
|
||||||
ZH_ESPNOW_CHECK(channel > 0 && channel < 15, ESP_ERR_INVALID_ARG, "ESP-NOW channel set failed. Invalid channel.");
|
ZH_ESPNOW_CHECK(channel > 0 && channel < 15, ESP_ERR_INVALID_ARG, "ESP-NOW channel set failed. Invalid channel.");
|
||||||
esp_err_t err = esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
esp_err_t err = esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
|
||||||
ZH_ESPNOW_CHECK(err == ESP_OK, err, "ESP-NOW channel set failed.");
|
if (err != ESP_OK)
|
||||||
|
{
|
||||||
|
ZH_ESPNOW_LOGE_ERR("ESP-NOW channel set failed.", err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
_init_config.wifi_channel = channel;
|
_init_config.wifi_channel = channel;
|
||||||
ZH_ESPNOW_LOGI("ESP-NOW channel set successfully.");
|
ZH_ESPNOW_LOGI("ESP-NOW channel set successfully.");
|
||||||
return err;
|
return err;
|
||||||
@ -558,29 +597,4 @@ esp_err_t zh_espnow_set_battery_mode(bool battery_mode)
|
|||||||
esp_err_t zh_espnow_get_mac(uint8_t *mac_addr)
|
esp_err_t zh_espnow_get_mac(uint8_t *mac_addr)
|
||||||
{
|
{
|
||||||
return esp_wifi_get_mac(_init_config.wifi_interface, mac_addr);
|
return esp_wifi_get_mac(_init_config.wifi_interface, mac_addr);
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t zh_espnow_get_queue_space(void)
|
|
||||||
{
|
|
||||||
if (_queue_handle == NULL)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return uxQueueSpacesAvailable(_queue_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void zh_espnow_clear_queue(void)
|
|
||||||
{
|
|
||||||
if (_queue_handle != NULL)
|
|
||||||
{
|
|
||||||
_queue_t queue = {0};
|
|
||||||
while (xQueueReceive(_queue_handle, &queue, 0) == pdTRUE)
|
|
||||||
{
|
|
||||||
if (queue.data.payload != NULL)
|
|
||||||
{
|
|
||||||
heap_caps_free(queue.data.payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ZH_ESPNOW_LOGI("Queue clear completed successfully.");
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user