极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8803|回复: 1

有编程高手可以帮我在这个用ping的例子里加上平均时间吗?

[复制链接]
发表于 2013-2-12 14:45:02 | 显示全部楼层 |阅读模式
有编程高手可以帮我在这个用ping的例子里加上平均时间吗?
例子的代码其实在附近的icmpping的library里也有
  1. #include <SPI.h>         
  2. #include <Ethernet.h>
  3. #include <ICMPPing.h>

  4. byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // max address for ethernet shield
  5. byte ip[] = {192,168,1,15}; // ip address for ethernet shield
  6. byte pingAddr[] = {220,181,111,147}; // ip address to ping

  7. SOCKET pingSocket = 0;

  8. char buffer [256];

  9. void setup()
  10. {
  11.   // start Ethernet
  12.   Ethernet.begin(mac, ip);
  13.   Serial.begin(9600);
  14. }

  15. void loop()
  16. {
  17.   ICMPPing ping(pingSocket);
  18.   ping(4, pingAddr, buffer);
  19.   Serial.println(buffer);
  20.   delay(500);
  21. }
复制代码
这个例子的结果是:
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里的....
求指教啊,谢谢了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-2-15 11:27:47 | 显示全部楼层
建议还是不要改库,可以考虑在代码中截取buffer字符串,取得时间,转换成int,然后再平均,虽然比较笨,但是保留了库的一致性,便于今后更新库。
另外可以具体看看库文件,有没有直接获取时间的函数或者方法。如果有,就比较方便了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-5-9 11:15 , Processed in 0.040540 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表