有编程高手可以帮我在这个用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 [256];
- 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[1] from: 220.181.111.147: bytes=32 time=821ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=212ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=228ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=210ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=211ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=279ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=264ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=211ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=294ms TTL=128
Reply[1] from: 220.181.111.147: bytes=32 time=212ms TTL=128
我只是想要那个time的平均时间,但是我编程能力有限,不知道是改他的例子里loop还是改library里的....
求指教啊,谢谢了 |