pingResult callback is called one too many
pingResult callback is called one too many
I am using esp_ping_set_target() and ping_init(), and found that the callback pingResult() is called 5 times, when I set PING_TARGET_IP_ADDRESS_COUNT to 4. Is this a bug?
Re: pingResult callback is called one too many
By reading the source code of esp_ping.c, I noticed that for the last call of the callback, ping_err is set to PING_RES_FINISH. So the behaviour is intentional. Problem solved.
Re: pingResult callback is called one too many
I think it would be helpful if pingResult callback got a different msgType
in latest call (for PING_RES_FINISH case).
The benefit:
1. Can avoid print a duplicate print in latest pingResult callback
2. The application can easily know the ping is done
And the change is pretty simple:
diff --git a/components/lwip/apps/ping/esp_ping.c b/components/lwip/apps/ping/esp_ping.c
index 75b669412d7a..54703f812cfa 100644
--- a/components/lwip/apps/ping/esp_ping.c
+++ b/components/lwip/apps/ping/esp_ping.c
@@ -158,9 +158,11 @@ esp_err_t esp_ping_result(uint8_t res_val, uint16_t ping_len, uint32_t ping_time
}
if (ping_option_info->ping_res_fn) {
- ping_option_info->ping_res_fn(PING_TARGET_RES_FN, &ping_option_info->ping_res);
if (res_val == PING_RES_FINISH) {
+ ping_option_info->ping_res_fn(PING_TARGET_RES_FN_END, &ping_option_info->ping_res);
memset(&ping_option_info->ping_res, 0, sizeof(esp_ping_found));
+ } else {
+ ping_option_info->ping_res_fn(PING_TARGET_RES_FN, &ping_option_info->ping_res);
}
}
diff --git a/components/lwip/include/apps/esp_ping.h b/components/lwip/include/apps/esp_ping.h
index 238679528342..ae13e9878432 100644
--- a/components/lwip/include/apps/esp_ping.h
+++ b/components/lwip/include/apps/esp_ping.h
@@ -54,7 +54,8 @@ typedef enum {
PING_TARGET_RES_FN = 55, /**< ping result callback function */
PING_TARGET_RES_RESET = 56, /**< ping result statistic reset */
PING_TARGET_DATA_LEN = 57, /**< ping data length*/
- PING_TARGET_IP_TOS = 58 /**< ping QOS*/
+ PING_TARGET_IP_TOS = 58, /**< ping QOS*/
+ PING_TARGET_RES_FN_END = 59 /**< the latest ping result callback function */
} ping_target_id_t;
typedef enum {
in latest call (for PING_RES_FINISH case).
The benefit:
1. Can avoid print a duplicate print in latest pingResult callback
2. The application can easily know the ping is done
And the change is pretty simple:
diff --git a/components/lwip/apps/ping/esp_ping.c b/components/lwip/apps/ping/esp_ping.c
index 75b669412d7a..54703f812cfa 100644
--- a/components/lwip/apps/ping/esp_ping.c
+++ b/components/lwip/apps/ping/esp_ping.c
@@ -158,9 +158,11 @@ esp_err_t esp_ping_result(uint8_t res_val, uint16_t ping_len, uint32_t ping_time
}
if (ping_option_info->ping_res_fn) {
- ping_option_info->ping_res_fn(PING_TARGET_RES_FN, &ping_option_info->ping_res);
if (res_val == PING_RES_FINISH) {
+ ping_option_info->ping_res_fn(PING_TARGET_RES_FN_END, &ping_option_info->ping_res);
memset(&ping_option_info->ping_res, 0, sizeof(esp_ping_found));
+ } else {
+ ping_option_info->ping_res_fn(PING_TARGET_RES_FN, &ping_option_info->ping_res);
}
}
diff --git a/components/lwip/include/apps/esp_ping.h b/components/lwip/include/apps/esp_ping.h
index 238679528342..ae13e9878432 100644
--- a/components/lwip/include/apps/esp_ping.h
+++ b/components/lwip/include/apps/esp_ping.h
@@ -54,7 +54,8 @@ typedef enum {
PING_TARGET_RES_FN = 55, /**< ping result callback function */
PING_TARGET_RES_RESET = 56, /**< ping result statistic reset */
PING_TARGET_DATA_LEN = 57, /**< ping data length*/
- PING_TARGET_IP_TOS = 58 /**< ping QOS*/
+ PING_TARGET_IP_TOS = 58, /**< ping QOS*/
+ PING_TARGET_RES_FN_END = 59 /**< the latest ping result callback function */
} ping_target_id_t;
typedef enum {
Who is online
Users browsing this forum: No registered users and 51 guests