Skip to content

Commit 44ca1d2

Browse files
committed
ping: switch from ping_error to ping_status
1 parent c10430d commit 44ca1d2

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

UNOR4USBBridge/cmds_esp_generic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ void CAtHandler::add_cmds_esp_generic() {
417417

418418
auto ping_res = execute_ping(target.c_str(), atoi(ttl.c_str()), atoi(cnt.c_str()));
419419
char rsl[8];
420-
if (ping_res.error == SUCCESS) {
420+
if (ping_res.status == ping_status::SUCCESS) {
421421
sprintf(rsl,"%.0f", ping_res.averagertt);
422422
} else {
423-
sprintf(rsl,"%d", ping_res.error);
423+
sprintf(rsl,"%d", ping_res.status);
424424
}
425425

426426
srv.write_response_prompt();

UNOR4USBBridge/ping.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void ping_timeout(esp_ping_handle_t hdl, void *args) {
2424
}
2525

2626
static void ping_end(esp_ping_handle_t hdl, void *args) {
27-
_stats.error = SUCCESS;
27+
_stats.status = ping_status::SUCCESS;
2828
}
2929

3030
ping_statistics execute_ping(const char* address, uint8_t ttl, uint8_t count) {
@@ -39,7 +39,7 @@ ping_statistics execute_ping(const char* address, uint8_t ttl, uint8_t count) {
3939

4040
if(getaddrinfo(address, NULL, &hint, &res) != 0) {
4141
log_e("resolution error");
42-
_stats.error = DNS_RESOLUTION_ERROR;
42+
_stats.status = ping_status::DNS_RESOLUTION_ERROR;
4343
return _stats;
4444
}
4545

@@ -62,14 +62,14 @@ ping_statistics execute_ping(const char* address, uint8_t ttl, uint8_t count) {
6262
cbs.cb_args = NULL;
6363

6464
memset(&_stats, 0, sizeof(_stats));
65-
_stats.error = RUNNING;
65+
_stats.status = ping_status::RUNNING;
6666

6767
esp_ping_handle_t ping; // FIXME do I need this?
6868
esp_ping_new_session(&ping_config, &cbs, &ping);
6969
esp_ping_start(ping);
7070

7171
// wait for the end of ping session
72-
while(_stats.error != RUNNING) {
72+
while(_stats.status != ping_status::RUNNING) {
7373
delay(10);
7474
}
7575

UNOR4USBBridge/ping.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
#include <stdint.h>
44

5-
enum ping_error: uint8_t {
6-
RUNNING,
7-
SUCCESS,
8-
ERROR,
9-
DNS_RESOLUTION_ERROR,
5+
enum class ping_status: int {
6+
ERROR = -4,
7+
DNS_RESOLUTION_ERROR = -3,
8+
TIMEOUT = -2,
9+
RUNNING = 0,
10+
SUCCESS = 1
1011
};
1112

1213
struct ping_statistics {
1314
uint8_t success_count;
1415
uint8_t timedout_count;
1516
float averagertt; // measured in ms
16-
volatile ping_error error;
17+
volatile ping_status status;
1718
};
1819

1920
ping_statistics execute_ping(const char* address, uint8_t ttl, uint8_t count);

0 commit comments

Comments
 (0)