tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议

上传人:tian****1990 文档编号:81742587 上传时间:2019-02-22 格式:PPT 页数:39 大小:1.09MB
返回 下载 相关 举报
tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议_第1页
第1页 / 共39页
tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议_第2页
第2页 / 共39页
tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议_第3页
第3页 / 共39页
tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议_第4页
第4页 / 共39页
tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议_第5页
第5页 / 共39页
点击查看更多>>
资源描述

《tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议》由会员分享,可在线阅读,更多相关《tinyos操作系统开发技术及实践(西电版)实践5tinyos网络协议(39页珍藏版)》请在金锄头文库上搜索。

1、实践5 TinyOS网络协议,实践指导 知识拓展,实践指导 实践5.G.1 基于分发协议的烟雾信息采集及传输。 【分析】 (1) 本例程要实现信息的采集和传输,程序实现部分需要分为两部分编写,即发送部分和接收部分。 (2) 发送部分程序要实现烟雾信息的采集和传输。 (3) 接收部分程序要实现信息的接收以及将数据传输至PC机。 (4) 下载调试,观察现象。,【参考解决方案】 1建立工程文件夹 在“/mytinyos/apps”目录下新建一个SmokeTest的文件夹(其操作步骤参照实践5.G.1),在SmokeTest文件夹下新建Sender和Receive文件夹。其中,Sender文件夹实现数

2、据的发送部分程序;Receive文件夹实现数据的接收部分程序。,2发送部分程序 在“mytinyos/apps/SmokeTest/Sender”目录下新建三个文件:SmokeTestSApp.nc、SmokeTestSC.nc和Makefile文件。其中SmokeTestSC.nc文件实现了数据的采集和发送,SmokeTestSApp.nc文件为SmokeTestSC.nc文件的顶层配件。,(1) 在SmokeTestSApp.nc中的主要代码如下: #include “BlinkToRadio.h“ configuration SmokeTestSAppC implementation c

3、omponents SmokeTestSC; components MainC; SmokeTestSC.Boot - MainC; components ActiveMessageC; SmokeTestSC.RadioControl - ActiveMessageC;,components DisseminationC; SmokeTestSC.DisseminationControl - DisseminationC; components new DisseminatorC(uint16_t, 0x2345) as Object16C; SmokeTestSC.Value16 - Ob

4、ject16C; SmokeTestSC.Update16 - Object16C; components LedsC; SmokeTestSC.Leds - LedsC; components new TimerMilliC(); SmokeTestSC.Timer - TimerMilliC;,SmokeTestSC.Packet-ActiveMessageC; SmokeTestSC.AMPacket-ActiveMessageC; SmokeTestSC.AMSend-ActiveMessageC.AMSenduniqueCount(“SmokeApp“); components ne

5、w AdcC() as ADSensor; SmokeTestSC.ADSensorControl - ADSensor; SmokeTestSC.ADSensorRead - ADSensor; ,(2) SmokeTestSC.nc文件中的主要代码实现如下: #include #include “Adc.h“ #include “BlinkToRadio.h“ module SmokeTestSC uses interface AMSend; interface Packet; interface AMPacket; interface Read as ADSensorRead; inte

6、rface AdcControl as ADSensorControl; interface Boot;,interface SplitControl as RadioControl; interface StdControl as DisseminationControl; interface DisseminationValue as Value16; interface DisseminationUpdate as Update16; interface Leds; interface Timer; implementation uint16_t counter; am_addr_t D

7、ES = 0x0003;,/*传感器采集任务*/ task void sensorTask() /选择P0.7为AD采集通道, call ADSensorControl.enable(ADC_REF_AVDD, ADC_14_BIT, ADC_AIN3); /开始采集AD信息 call ADSensorRead.read(); event void Boot.booted() call RadioControl.start(); ,event void RadioControl.startDone( error_t result ) if ( result != SUCCESS ) call

8、RadioControl.start(); else call DisseminationControl.start(); counter = 0; call Timer.startPeriodic( 2000 ); ,event void RadioControl.stopDone( error_t result ) event void Timer.fired() post sensorTask(); ,event void Value16.changed() const uint16_t* newVal = call Value16.get(); call Leds.led2Toggle

9、(); counter = *newVal; event void AMSend.sendDone(message_t* msg,error_t err) call Leds.led1Toggle(); ,/*ADC读取完毕之后将会触发readDone事件*/ event void ADSensorRead.readDone(error_t result, int16_t val) message_t pkt; BlinkToRadioMsg* btrpkt; counter = val; call Update16.change(,if(call AMSend.send(AM_BROADCA

10、ST_ADDR, ,(3) 在BlinkRadio.h文件中定义了发送数据的结构体,具体代码如下: #ifndef _BLINKTORADIO_H #define _BLINKTORADIO_H typedef nx_struct BlinkToRadioMsg nx_uint16_t nodeid; nx_uint16_t num; BlinkToRadioMsg; #endif,(4) 在Makefile文件中注明程序的顶层配件,其代码如下: COMPONENT=SmokeTestSAppC CFLAGS += -I$(TOSDIR)/lib/net -I%T/lib/net/drip i

11、nclude $(MAKERULES),3接收部分程序 在“mytinyos/apps/SmokeTest/Sender”目录下新建三个文件:SmokeTestRApp.nc、SmokeTestRC.nc和Makefile文件。其中SmokeTestRC.nc文件实现了数据的接收以及通过串口将数据传输至PC机,SmokeTestRApp.nc文件为SmokeTestRC.nc文件的顶层配件。,在SmokeTestRApp.nc中的主要代码如下: #include “BlinkToRadio.h“ configuration SmokeTestRAppC implementation compo

12、nents SmokeTestRC,MainC; SmokeTestRC.Boot - MainC; components ActiveMessageC; SmokeTestRC.RadioControl - ActiveMessageC;,components DisseminationC; SmokeTestRC.DisseminationControl - DisseminationC; components new DisseminatorC(uint16_t, 0x2345) as Object16C; SmokeTestRC.Update16 - Object16C; compon

13、ents LedsC; SmokeTestRC.Leds - LedsC; components new TimerMilliC(); SmokeTestRC.Timer - TimerMilliC;,SmokeTestRC.Packet-ActiveMessageC; SmokeTestRC.AMPacket-ActiveMessageC; SmokeTestRC.Receive-ActiveMessageC.ReceiveuniqueCount(“SmokeApp“); components PlatformSerialC; SmokeTestRC.StdControl - Platfor

14、mSerialC.StdControl; SmokeTestRC.UartStream - PlatformSerialC.UartStream; ,(2) SmokeTestRC.nc文件中的主要代码实现如下: #include #include “BlinkToRadio.h“ module SmokeTestRC uses interface Receive; interface Packet; interface AMPacket; interface StdControl; interface UartStream; interface Boot;,interface SplitCo

15、ntrol as RadioControl; interface StdControl as DisseminationControl; interface DisseminationUpdate as Update16; interface Leds; interface Timer; implementation uint16_t counter; uint8_t m_send_buf2;,event void Boot.booted() call RadioControl.start(); /开启串口传输 call StdControl.start(); ,event void RadioControl.startDone( error_t result ) if ( result != SUCCESS ) call RadioControl.start(); else call DisseminationControl.start(); counter = 0; call Timer.startPeriodic( 2000 ); ,event void RadioControl.stopDone( error_t result ) event void Timer.fired() ,/*接收信息,并通过串口

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号