TinyOS操作系统开发技术及实践课件实践5TinyOS网络协议.ppt

TinyOS操作系统开发技术及实践课件实践5TinyOS网络协议.ppt

实践5 TinyOS网络协议 实践指导 ? 实践5.G.1   基于分发协议的烟雾信息采集及传输。   【分析】   (1) 本例程要实现信息的采集和传输,程序实现部分需要分为两部分编写,即发送部分和接收部分。   (2) 发送部分程序要实现烟雾信息的采集和传输。   (3) 接收部分程序要实现信息的接收以及将数据传输至PC机。   (4) 下载调试,观察现象。 【参考解决方案】   1.建立工程文件夹   在“/mytinyos/apps”目录下新建一个SmokeTest的文件夹(其操作步骤参照实践5.G.1),在SmokeTest文件夹下新建Sender和Receive文件夹。其中,Sender文件夹实现数据的发送部分程序;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 { components 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 - Object16C; SmokeTestSC.Update16 - Object16C; components LedsC; SmokeTestSC.Leds - LedsC; components new TimerMilliC(); SmokeTestSC.Timer - TimerMilliC; SmokeTestSC.Packet-ActiveMessageC; SmokeTestSC.AMPacket-ActiveMessageC; SmokeTestSC.AMSend-ActiveMessageC.AMSend[uniqueCount(SmokeApp)]; components new AdcC() as ADSensor; SmokeTestSC.ADSensorControl - ADSensor; SmokeTestSC.ADSensorRead - ADSensor; } (2) ?SmokeTestSC.nc文件中的主要代码实现如下: #include Timer.h #include Adc.h #include BlinkToRadio.h module SmokeTestSC { uses { interface AMSend; interface Packet; interface AMPacket; interface Readint16_t as ADSensorRead; interface AdcControl as ADSensorControl; interface Boot; interface SplitControl as RadioControl; interface StdControl as DisseminationControl; interface DisseminationValueuint16_t as Value16; interface DisseminationUpdateuint16_t as Update16; interface Leds; interface TimerTMilli; } } implementation { uint16_t counter; am_addr_t DES = 0x0003; /*传感器采集任务*/ task void sensorTask() { //选择P0.7为AD采集通道, call

文档评论(0)

1亿VIP精品文档

相关文档