您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關 TinyOS無線傳感器網絡串口通信和無線通信是怎樣的,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
我作為TinyOS入門新手,在學習串口通信和無線通信時遇到不少問題。下面主要是給出一個自己寫的示例程序。無線傳感器節點收到其他節點的數據通過串口發送給PC,PC通過串口發送指令到節點,節點再通過無線廣播PC發送的指令。
項目包含3個文件:Makefile、SerialC.nc、SerialAppC.nc。
COMPONENT=SerialAppC include $(MAKERULES)
configuration SerialAppC { } implementation { components MainC, SerialC, LedsC, ActiveMessageC; components PlatformSerialC; components SerialC as App; components new TimerMilliC() as Timer0; components new AMSenderC(6); components new AMReceiverC(6); App -> MainC.Boot; App.Leds -> LedsC; App.Timer0->Timer0; App.StdControl->PlatformSerialC.StdControl; App.UartStream->PlatformSerialC.UartStream; App.RadioSend -> AMSenderC; App.RadioPacket -> AMSenderC; App.RadioAMPacket -> AMSenderC; App.RadioControl -> ActiveMessageC; App.RadioReceive -> AMReceiverC; }
module SerialC { uses interface Leds; uses interface Boot; uses interface Timer<TMilli> as Timer0; uses interface Packet as RadioPacket; uses interface AMPacket as RadioAMPacket; uses interface AMSend as RadioSend; uses interface Receive as RadioReceive; uses interface SplitControl as RadioControl; uses interface StdControl; uses interface UartStream; } implementation { uint32_t count=0; uint8_t buff[2]; bool radiobusy=FALSE; bool serialbusy=FALSE; message_t pkt; typedef nx_struct RadioMsg { nx_uint16_t nodeid; nx_uint16_t count; }RadioMsg; 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 RadioControl.start(); call StdControl.start(); } event void Timer0.fired(){} async event void UartStream.sendDone(uint8_t *buf,uint16_t len,error_t error) { serialbusy=FALSE; } async event void UartStream.receivedByte(uint8_t byte) { call Leds.led2Toggle(); setLeds(byte); if(!radiobusy) { RadioMsg* btrpkt=(RadioMsg*)(call RadioPacket.getPayload(&pkt,sizeof(RadioMsg))); btrpkt->nodeid=TOS_NODE_ID; btrpkt->count=byte; if(call RadioSend.send(AM_BROADCAST_ADDR,&pkt,sizeof(RadioMsg))==SUCCESS) radiobusy=TRUE; } } async event void UartStream.receiveDone(uint8_t *buf,uint16_t len,error_t error) { } event void RadioControl.startDone(error_t err) { } event void RadioControl.stopDone(error_t err) { } event void RadioSend.sendDone(message_t* msg,error_t error) { if(&pkt==msg) radiobusy=FALSE; } event message_t* RadioReceive.receive(message_t* msg,void *payload,uint8_t len) { call Leds.led1Toggle(); if(len==sizeof(RadioMsg)) { RadioMsg* btrpkt =(RadioMsg*)payload; buff[0]=btrpkt->nodeid; buff[1]=btrpkt->count; } if(!serialbusy) { serialbusy=TRUE; call UartStream.send(buff, sizeof(buff) ); } return msg; } }
看完上述內容,你們對 TinyOS無線傳感器網絡串口通信和無線通信是怎樣的有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。