fix ping bug

This commit is contained in:
MarcusXing 2018-08-16 13:15:00 +08:00
parent 65ad4479f2
commit b81bbf4077

View File

@ -847,22 +847,34 @@ static void ec20_socket_set_event_cb(at_socket_evt_t event, at_evt_cb_t cb)
static void urc_ping_func(const char *data, rt_size_t size) static void urc_ping_func(const char *data, rt_size_t size)
{ {
static int icmp_seq = 0; static int icmp_seq = 0;
int i, j = 0;
int result, recv_len, time, ttl; int result, recv_len, time, ttl;
int sent, rcvd, lost, min, max, avg;
char dst_ip[16] = { 0 }; char dst_ip[16] = { 0 };
RT_ASSERT(data); RT_ASSERT(data);
sscanf(data, "+QPING: %d,%[^,],%d,%d,%d", &result, dst_ip, &recv_len, &time, &ttl); for (i=0;i<size;i++)
switch(result)
{ {
case 0: if(*(data+i) == '.')
rt_kprintf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n", recv_len, dst_ip, icmp_seq++, ttl, time); j++;
break; }
default: if (j != 0)
rt_kprintf("ping: "); {
sscanf(data, "+QPING: %d,%[^,],%d,%d,%d", &result, dst_ip, &recv_len, &time, &ttl);
if (result == 0)
LOG_I("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms", recv_len, dst_ip, icmp_seq++, ttl, time);
}
else
{
sscanf(data, "+QPING: %d,%d,%d,%d,%d,%d,%d", &result, &sent, &rcvd, &lost, &min, &max, &avg);
if (result == 0)
LOG_I("%d sent %d received %d lost, min=%dms max=%dms average=%dms", sent, rcvd, lost, min, max, avg);
}
if (result != 0)
{
LOG_E("ping: ");
at_tcp_ip_errcode_parse(result); at_tcp_ip_errcode_parse(result);
break;
} }
} }