有编程高手可以帮我在这个用ping的例子里加上平均时间吗?
有编程高手可以帮我在这个用ping的例子里加上平均时间吗?例子的代码其实在附近的icmpping的library里也有#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // max address for ethernet shield
byte ip[] = {192,168,1,15}; // ip address for ethernet shield
byte pingAddr[] = {220,181,111,147}; // ip address to ping
SOCKET pingSocket = 0;
char buffer ;
void setup()
{
// start Ethernet
Ethernet.begin(mac, ip);
Serial.begin(9600);
}
void loop()
{
ICMPPing ping(pingSocket);
ping(4, pingAddr, buffer);
Serial.println(buffer);
delay(500);
}这个例子的结果是:
Reply from: 220.181.111.147: bytes=32 time=821ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=212ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=228ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=210ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=211ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=279ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=264ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=211ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=294ms TTL=128
Reply from: 220.181.111.147: bytes=32 time=212ms TTL=128
我只是想要那个time的平均时间,但是我编程能力有限,不知道是改他的例子里loop还是改library里的....
求指教啊,谢谢了 建议还是不要改库,可以考虑在代码中截取buffer字符串,取得时间,转换成int,然后再平均,虽然比较笨,但是保留了库的一致性,便于今后更新库。
另外可以具体看看库文件,有没有直接获取时间的函数或者方法。如果有,就比较方便了。
页:
[1]