Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Serial Communication and Wireless Communication in TinyOS Wireless Sensor Networks

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to talk to you about TinyOS wireless sensor network serial communication and wireless communication, many people may not know much about it. In order to make you understand better, the editor summarized the following content for you. I hope you can get something according to this article.

As a novice to TinyOS, I encountered a lot of problems when learning serial communication and wireless communication. The following is mainly to give an example program written by oneself. The wireless sensor node receives the data of other nodes and sends them to the PC,PC through the serial port and sends instructions to the node through the serial port, and then the node broadcasts the instructions sent by the PC.

The project contains three files: Makefile, SerialC.nc, and SerialAppC.nc.

MakefileCOMPONENT=SerialAppCinclude $(MAKERULES) SerialAppC.nc

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;} SerialC.nc

Module SerialC {uses interface Leds; uses interface Boot; uses interface Timer 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 }} after reading the above, do you have any further understanding of serial communication and wireless communication in TinyOS wireless sensor networks? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report