Shell ping command: print out delay

This commit is contained in:
Simon Duquennoy 2017-07-07 15:43:31 +02:00
parent 09e0d75b53
commit 03f76a9058

View File

@ -65,16 +65,17 @@
static struct uip_icmp6_echo_reply_notification echo_reply_notification; static struct uip_icmp6_echo_reply_notification echo_reply_notification;
static shell_output_func *curr_ping_output_func = NULL; static shell_output_func *curr_ping_output_func = NULL;
static struct process *curr_ping_process; static struct process *curr_ping_process;
static uint8_t curr_ping_ttl;
static uint16_t curr_ping_datalen;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static void static void
echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen)
{ {
if(curr_ping_output_func != NULL) { if(curr_ping_output_func != NULL) {
SHELL_OUTPUT(curr_ping_output_func, "Received ping reply from ");
shell_output_6addr(curr_ping_output_func, source);
SHELL_OUTPUT(curr_ping_output_func, ", ttl %u, len %u\n", ttl, datalen);
curr_ping_output_func = NULL; curr_ping_output_func = NULL;
curr_ping_ttl = ttl;
curr_ping_datalen = datalen;
process_poll(curr_ping_process); process_poll(curr_ping_process);
} }
} }
@ -111,6 +112,11 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args))
if(curr_ping_output_func != NULL) { if(curr_ping_output_func != NULL) {
SHELL_OUTPUT(output, "Timeout\n"); SHELL_OUTPUT(output, "Timeout\n");
curr_ping_output_func = NULL; curr_ping_output_func = NULL;
} else {
SHELL_OUTPUT(output, "Received ping reply from ");
shell_output_6addr(output, &remote_addr);
SHELL_OUTPUT(output, ", len %u, ttl %u, delay %u ms\n",
curr_ping_datalen, curr_ping_ttl, (1000*(unsigned)(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND);
} }
PT_END(pt); PT_END(pt);