unified replace PING_CHECK by ESP_GOTO_ON_FALSE

unified replace PING_CHECK by ESP_GOTO_ON_FALSE

replace PING_CHECK macro by ESP_GOTO_ON_FALSE

Include header

grammar fix
pull/8012/head
AndriiFilippov 2021-11-04 11:22:44 +01:00
rodzic 9464a232a1
commit f42d1f48c6
1 zmienionych plików z 14 dodań i 24 usunięć

Wyświetl plik

@ -22,20 +22,10 @@
#include "lwip/sockets.h"
#include "esp_log.h"
#include "ping/ping_sock.h"
#include "esp_check.h"
const static char *TAG = "ping_sock";
#define PING_CHECK(a, str, goto_tag, ret_value, ...) \
do \
{ \
if (!(a)) \
{ \
ESP_LOGE(TAG, "%s(%d): " str, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
ret = ret_value; \
goto goto_tag; \
} \
} while (0)
#define PING_TIME_DIFF_MS(_end, _start) ((uint32_t)(((_end).tv_sec - (_start).tv_sec) * 1000 + \
((_end).tv_usec - (_start).tv_usec) / 1000))
@ -208,11 +198,11 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
{
esp_err_t ret = ESP_FAIL;
esp_ping_t *ep = NULL;
PING_CHECK(config, "ping config can't be null", err, ESP_ERR_INVALID_ARG);
PING_CHECK(hdl_out, "ping handle can't be null", err, ESP_ERR_INVALID_ARG);
ESP_GOTO_ON_FALSE(config, ESP_ERR_INVALID_ARG, err, TAG, "ping config can't be null");
ESP_GOTO_ON_FALSE(hdl_out, ESP_ERR_INVALID_ARG, err, TAG, "ping handle can't be null");
ep = mem_calloc(1, sizeof(esp_ping_t));
PING_CHECK(ep, "no memory for esp_ping object", err, ESP_ERR_NO_MEM);
ESP_GOTO_ON_FALSE(ep, ESP_ERR_NO_MEM, err, TAG, "no memory for esp_ping object");
/* set INIT flag, so that ping task won't exit (must set before create ping task) */
ep->flags |= PING_FLAGS_INIT;
@ -220,7 +210,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
/* create ping thread */
BaseType_t xReturned = xTaskCreate(esp_ping_thread, "ping", config->task_stack_size, ep,
config->task_prio, &ep->ping_task_hdl);
PING_CHECK(xReturned == pdTRUE, "create ping task failed", err, ESP_ERR_NO_MEM);
ESP_GOTO_ON_FALSE(xReturned == pdTRUE, ESP_ERR_NO_MEM, err, TAG, "create ping task failed");
/* callback functions */
if (cbs) {
@ -235,7 +225,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
ep->interval_ms = config->interval_ms;
ep->icmp_pkt_size = sizeof(struct icmp_echo_hdr) + config->data_size;
ep->packet_hdr = mem_calloc(1, ep->icmp_pkt_size);
PING_CHECK(ep->packet_hdr, "no memory for echo packet", err, ESP_ERR_NO_MEM);
ESP_GOTO_ON_FALSE(ep->packet_hdr,ESP_ERR_NO_MEM, err, TAG, "no memory for echo packet");
/* set ICMP type and code field */
ep->packet_hdr->code = 0;
/* ping id should be unique, treat task handle as ping ID */
@ -259,7 +249,7 @@ esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_c
ep->sock = socket(AF_INET6, SOCK_RAW, IP6_NEXTH_ICMP6);
}
#endif
PING_CHECK(ep->sock >= 0, "create socket failed: %d", err, ESP_FAIL, ep->sock);
ESP_GOTO_ON_FALSE(ep->sock >= 0, ESP_FAIL, err, TAG, "create socket failed: %d", ep->sock);
/* set if index */
if(config->interface) {
struct ifreq iface;
@ -319,7 +309,7 @@ esp_err_t esp_ping_delete_session(esp_ping_handle_t hdl)
{
esp_err_t ret = ESP_OK;
esp_ping_t *ep = (esp_ping_t *)hdl;
PING_CHECK(ep, "ping handle can't be null", err, ESP_ERR_INVALID_ARG);
ESP_GOTO_ON_FALSE(ep, ESP_ERR_INVALID_ARG, err, TAG, "ping handle can't be null");
/* reset init flags, then ping task will exit */
ep->flags &= ~PING_FLAGS_INIT;
return ESP_OK;
@ -331,7 +321,7 @@ esp_err_t esp_ping_start(esp_ping_handle_t hdl)
{
esp_err_t ret = ESP_OK;
esp_ping_t *ep = (esp_ping_t *)hdl;
PING_CHECK(ep, "ping handle can't be null", err, ESP_ERR_INVALID_ARG);
ESP_GOTO_ON_FALSE(ep, ESP_ERR_INVALID_ARG, err, TAG, "ping handle can't be null");
ep->flags |= PING_FLAGS_START;
xTaskNotifyGive(ep->ping_task_hdl);
return ESP_OK;
@ -343,7 +333,7 @@ esp_err_t esp_ping_stop(esp_ping_handle_t hdl)
{
esp_err_t ret = ESP_OK;
esp_ping_t *ep = (esp_ping_t *)hdl;
PING_CHECK(ep, "ping handle can't be null", err, ESP_ERR_INVALID_ARG);
ESP_GOTO_ON_FALSE(ep, ESP_ERR_INVALID_ARG, err, TAG, "ping handle can't be null");
ep->flags &= ~PING_FLAGS_START;
return ESP_OK;
err:
@ -356,8 +346,8 @@ esp_err_t esp_ping_get_profile(esp_ping_handle_t hdl, esp_ping_profile_t profile
esp_ping_t *ep = (esp_ping_t *)hdl;
const void *from = NULL;
uint32_t copy_size = 0;
PING_CHECK(ep, "ping handle can't be null", err, ESP_ERR_INVALID_ARG);
PING_CHECK(data, "profile data can't be null", err, ESP_ERR_INVALID_ARG);
ESP_GOTO_ON_FALSE(ep, ESP_ERR_INVALID_ARG, err, TAG, "ping handle can't be null");
ESP_GOTO_ON_FALSE(data, ESP_ERR_INVALID_ARG, err, TAG, "profile data can't be null");
switch (profile) {
case ESP_PING_PROF_SEQNO:
from = &ep->packet_hdr->seqno;
@ -392,10 +382,10 @@ esp_err_t esp_ping_get_profile(esp_ping_handle_t hdl, esp_ping_profile_t profile
copy_size = sizeof(ep->total_time_ms);
break;
default:
PING_CHECK(false, "unknow profile: %d", err, ESP_ERR_INVALID_ARG, profile);
ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "unknown profile: %d", profile);
break;
}
PING_CHECK(size >= copy_size, "unmatched data size for profile %d", err, ESP_ERR_INVALID_SIZE, profile);
ESP_GOTO_ON_FALSE(size >= copy_size, ESP_ERR_INVALID_SIZE, err, TAG, "unmatched data size for profile %d", profile);
memcpy(data, from, copy_size);
return ESP_OK;
err: