无线传感器实验二报告.docx_第1页
无线传感器实验二报告.docx_第2页
无线传感器实验二报告.docx_第3页
无线传感器实验二报告.docx_第4页
无线传感器实验二报告.docx_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

浙江工业大学计算机学院实 验 报 告实验名称 无线传感网络实验之丢包率检测日 期 2014年12月30日 一、 实验内容 本次实验主要是通过代码的编写测试节点的发送功率和距离的远近对接收节点的丢包率的影响。对发送功率的设置是通过修改CC2420.h文件中的参数实现的。其中距离的远近的调节是容易实现的。而对丢包率的计算是由接收节点的主机B将收到的数据包打印到屏幕上,主机A烧写的节点则是实现每次发送100个数据包。二、程序源代码主机A(发送方) BlinkToRadio.h#ifndef BLINKTORADIO_H#define BLINKTORADIO_Henum AM_BLINKTORADIO = 6, TIMER_PERIOD_MILLI = 250;typedef nx_struct BlinkToRadioMsg nx_uint16_t nodeid; nx_uint16_t counter; BlinkToRadioMsg;#endif BlinkToRadioAppC.nc#include #include BlinkToRadio.hconfiguration BlinkToRadioAppC implementation components MainC; components LedsC; components BlinkToRadioC as App; components new TimerMilliC() as Timer0; components ActiveMessageC; components new AMSenderC(AM_BLINKTORADIO); components new AMReceiverC(AM_BLINKTORADIO); App.Boot - MainC; App.Leds - LedsC; App.Timer0 - Timer0; App.Packet - AMSenderC; App.AMPacket - AMSenderC; App.AMControl - ActiveMessageC; App.AMSend - AMSenderC; App.Receive - AMReceiverC; BlinkToRadioC.nc#include #include BlinkToRadio.hmodule BlinkToRadioC uses interface Boot; uses interface Leds; uses interface Timer as Timer0; uses interface Packet; uses interface AMPacket; uses interface AMSend; uses interface Receive; uses interface SplitControl as AMControl;implementation uint16_t counter; message_t pkt; bool busy = FALSE; void setLeds(uint16_t val) if (val & 0x01) call Leds.led0On(); else call Leds.led0Off(); if (val & 0x02) call Leds.led1On(); else call Leds.led1Off(); if (val & 0x04) call Leds.led2On(); else call Leds.led2Off(); event void Boot.booted() call AMControl.start(); event void AMControl.startDone(error_t err) if (err = SUCCESS) call Timer0.startPeriodic(TIMER_PERIOD_MILLI); else call AMControl.start(); event void AMControl.stopDone(error_t err) event void Timer0.fired() counter+;/发送100个数据包 if(counter nodeid = 10; btrpkt-counter = counter; if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg) = SUCCESS) busy = TRUE; event void AMSend.sendDone(message_t* msg, error_t err) if (&pkt = msg) busy = FALSE; event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) if (len = sizeof(BlinkToRadioMsg) BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload; setLeds(btrpkt-counter); return msg; MakefileCOMPONENT=BlinkToRadioAppCinclude $(MAKERULES)主机B(接收方) BlinkToRadio.h#ifndef BLINKTORADIO_H#define BLINKTORADIO_Henum AM_BLINKTORADIO = 6, TIMER_PERIOD_MILLI = 250;typedef nx_struct BlinkToRadioMsg nx_uint16_t nodeid; nx_uint16_t counter; BlinkToRadioMsg;#endif BlinkToRadioAppC.nc#include #include BlinkToRadio.hconfiguration BlinkToRadioAppC implementation components MainC; components LedsC; components BlinkToRadioC as App; components new TimerMilliC() as Timer0; components ActiveMessageC; components new AMSenderC(AM_BLINKTORADIO); components new AMReceiverC(AM_BLINKTORADIO); App.Boot - MainC; App.Leds - LedsC; App.Timer0 - Timer0; App.Packet - AMSenderC; App.AMPacket - AMSenderC; App.AMControl - ActiveMessageC; App.AMSend - AMSenderC; App.Receive - AMReceiverC; BlinkToRadioC.nc#include #include BlinkToRadio.h#include printf.hmodule BlinkToRadioC uses interface Boot; uses interface Leds; uses interface Timer as Timer0; uses interface Packet; uses interface AMPacket; uses interface AMSend; uses interface Receive; uses interface SplitControl as AMControl;implementation uint16_t counter; message_t pkt; bool busy = FALSE; uint32_t nowtime; uint16_t Number=0; event void Boot.booted() call AMControl.start(); event void AMControl.startDone(error_t err) if (err = SUCCESS) else call AMControl.start(); event void AMControl.stopDone(error_t err) event void Timer0.fired() printf(now is:%dn,(call Timer0.getNow();printfflush(); call Leds.led0Toggle(); event void AMSend.sendDone(message_t* msg, error_t err) if (&pkt = msg) busy = FALSE; event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) if (len = sizeof(BlinkToRadioMsg) BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload; if(btrpkt-nodeid=10) /= if (!busy) call Leds.led2Toggle(); Number+; printf(No.%d pakage is received,the number:%dn,btrpkt-counter,Number); printfflush(); if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg) = SUCCESS) busy = TRUE; return msg; MakefileCOMPONENT=BlinkToRadioAppCCFLAGS += -I$(TOSDIR)/lib/printfinclude $(MAKERULES)三、实验步骤1.在实验四的代码基础上,修改BlinkToRadioC.nc中的事件Timer0.fired()和事件Receive.receive中收到数据包后输出对应的信息。2. 在cygwin中进行编译并烧写节点,进行测试。3.开始时,设置发送节点的功率为3,不断拉大两个节点之间的距离,这时就算把接收节点拿到实验室最远的地方,大概有10米的距离还是能做到完全接收到所有发送节点发送的数据(这个截图忘了)。4.将发送节点的功率设为1,在近距离的时候,接收节点能做到完全接收到所有发送节点发送的数据。当距离在超过1米时,开始明显得丢包了。四、实验截图主机B(接收方):功率为1,距离1米时,接收到了90个包,共发送了100个包,所以这个时候的丢包率为 90%功率为1,距离为3米左右的时候测得丢包率,这个时候可以看到只接收到了17个数据包,可以看出丢掉的数据包已经很多了。这个时候的丢包率为:17%五、实验总结 本次实验的关键还是在代码编写,在实验四的框架下,还是比较容易实现的。为了测试丢包率,就一定要知道发送方发送的节点数,和对应的接收方接收的节点数。这里我们为了方便计算,就让发送节点按照一秒发送4个数据包的速率一次性发

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论