现在的位置: 首页 > 综合 > 正文

TinyOS 关于surge和路由

2012年07月27日 ⁄ 综合 ⁄ 共 6995字 ⁄ 字号 评论关闭

However, unlike Internetprotocol development, since the routing protocol application for TinyOS is justlike a standard application. We have to specify the configuration, situation,topology and so on. To achieve the goal, we must have the control of the mode,including
the mote identification number, the number of messages sent for anymote, even the data information such as size, type and so on.

 

I add some new codes and put the code together totest the routing:

1.     RoutingTest.nc

 

configuration RoutingTest {

}

implementation {

 components Main, RoutingTestM, TimerC, LedsC, NoLeds, Photo, RandomLFSR,

   GenericCommPromiscuous as Comm, Bcast, MultiHopRouter as MyRouting,QueuedSend, Sounder;

 

 Main.StdControl -> RoutingTestM.StdControl;

 Main.StdControl -> Bcast.StdControl;

  Main.StdControl-> MyRouting.StdControl;

 Main.StdControl -> QueuedSend.StdControl;

 Main.StdControl -> TimerC;

 Main.StdControl -> Comm;

 

 

 RoutingTestM.Timer -> TimerC.Timer[unique("Timer")];

 RoutingTestM.Leds  -> LedsC; //NoLeds;

 RoutingTestM.Sounder -> Sounder;

 

 RoutingTestM.Bcast -> Bcast.Receive[AM_RoutingTestCMDMSG];

 Bcast.ReceiveMsg[AM_RoutingTestCMDMSG] ->Comm.ReceiveMsg[AM_RoutingTestCMDMSG];

 

 RoutingTestM.RouteControl -> MyRouting;

 RoutingTestM.Send -> MyRouting.Send[AM_RoutingTestMSG];

 MyRouting.ReceiveMsg[AM_RoutingTestMSG] ->Comm.ReceiveMsg[AM_RoutingTestMSG];

 

}

 

2.     RoutingTestM.nc

 

module RoutingTestM {

 provides {

   interface StdControl;

 }

 uses {

   interface ADC;

   interface Timer;

   interface Leds;

   interface StdControl as Sounder;

   interface Send;

   interface Receive as Bcast;

   interface RouteControl;

 }

}

 

implementation {

 

 enum {

   TIMER_GETADC_COUNT = 1,           

   TIMER_CHIRP_COUNT = 10,           

 };

 

 bool sleeping;           

 bool focused;

 bool rebroadcast_adc_packet;

 

 TOS_Msg gMsgBuffer;

 norace uint16_t gSensorData;      

 bool gfSendBusy;

 

 

 int timer_rate;

 int timer_ticks;

 

     

 static void initialize() {

   timer_rate = INITIAL_TIMER_RATE;

   atomic gfSendBusy = FALSE;

   sleeping = FALSE;

   rebroadcast_adc_packet = FALSE;

   focused = FALSE;

 }

 

 

 command result_t StdControl.init() {

   initialize();

   return SUCCESS;

 }

 

 command result_t StdControl.start() {

   return call Timer.start(TIMER_REPEAT, timer_rate);

   return SUCCESS;

 }

 

 command result_t StdControl.stop() {

   return call Timer.stop();

 }

 

 task void SendData() {

   RoutingTestMsg *pReading;

   uint16_t Len;

   dbg(DBG_USR1, "RoutingTestM: Sending sensor reading\n");

     

   if (pReading = (RoutingTestMsg *)callSend.getBuffer(&gMsgBuffer,&Len)) {

     pReading->type = SURGE_TYPE_SENSORREADING;

     pReading->parentaddr = call RouteControl.getParent();

     pReading->reading = gSensorData;

     

     if ((call Send.send(&gMsgBuffer,sizeof(RoutingTestMsg))) != SUCCESS)

     atomicgfSendBusy = FALSE;

   }

 

 }

 

 event TOS_MsgPtr Bcast.receive(TOS_MsgPtr pMsg, void* payload, uint16_tpayloadLen) {

   SurgeCmdMsg *pCmdMsg = (SurgeCmdMsg *)payload;

 

   dbg(DBG_USR2, "RoutingTestM: Bcast type 0x%02x\n", pCmdMsg->type);

 

   if (pCmdMsg->type == SURGE_TYPE_SETRATE) {       // Set timer rate

     timer_rate = pCmdMsg->args.newrate;

     dbg(DBG_USR2, "RoutingTestM: set rate %d\n", timer_rate);

     call Timer.stop();

     call Timer.start(TIMER_REPEAT, timer_rate);

 

   } else if (pCmdMsg->type == SURGE_TYPE_SLEEP) {

     // Go to sleep - ignore everything until a SURGE_TYPE_WAKEUP

     dbg(DBG_USR2, "RoutingTestM: sleep\n");

     sleeping = TRUE;

     call Timer.stop();

     call Leds.greenOff();

     call Leds.yellowOff();

 

   } else if (pCmdMsg->type == SURGE_TYPE_WAKEUP) {

     dbg(DBG_USR2, "RoutingTestM: wakeup\n");

 

     // Wake up from sleep state

     if (sleeping) {

     initialize();

       call Timer.start(TIMER_REPEAT, timer_rate);

     sleeping= FALSE;

     }

 

   } else if (pCmdMsg->type == SURGE_TYPE_FOCUS) {

     dbg(DBG_USR2, "RoutingTestM: focus %d\n", pCmdMsg->args.focusaddr);

 

     if (pCmdMsg->args.focusaddr == TOS_LOCAL_ADDRESS) {

 

     focused= TRUE;

     callSounder.init();

     callTimer.stop();

     callTimer.start(TIMER_REPEAT, FOCUS_TIMER_RATE);

     } else {

 

     callTimer.stop();

     callTimer.start(TIMER_REPEAT, FOCUS_NOTME_TIMER_RATE);

     }

 

   } else if (pCmdMsg->type == SURGE_TYPE_UNFOCUS) {

 

     dbg(DBG_USR2, "RoutingTestM: unfocus\n");

     focused = FALSE;

     call Sounder.stop();

     call Timer.stop();

     call Timer.start(TIMER_REPEAT, timer_rate);

   }

   return pMsg;

 }

 

 

 event result_t Timer.fired() {

   dbg(DBG_USR1, "RoutingTestM: Timer fired\n");

   timer_ticks++;

   if (timer_ticks % TIMER_GETADC_COUNT == 0) {

     call ADC.getData();

   }

 

   if (focused && timer_ticks % TIMER_CHIRP_COUNT == 0) {

     call Sounder.start();

   }

 

   if (focused && timer_ticks % TIMER_CHIRP_COUNT == 1) {

     call Sounder.stop();

   }

   return SUCCESS;

 }

 

 

 async event result_t ADC.dataReady(uint16_t data) {

   //RoutingTestMsg *pReading;

   //uint16_t Len;

   dbg(DBG_USR1, "RoutingTestM: Got ADC reading: 0x%x\n", data);

   atomic {

     if (!gfSendBusy) {

     gfSendBusy= TRUE;

     gSensorData= data;

     postSendData();

     }

   }

   return SUCCESS;

 }

 

 

 

 event result_t Send.sendDone(TOS_MsgPtr pMsg, result_t success) {

   dbg(DBG_USR2, "RoutingTestM: output complete 0x%x\n",success);

   //call Leds.greenToggle();

   atomic gfSendBusy = FALSE;

   return SUCCESS;

 }

}

 

 

 

 

 

 

 

 

 

 

 

 

So, now I canput the protocol codes and this testing configuration codes together to be a standard applicationfor TinyOS and nesC.

 

 

 

 

 

 

The compiling is successful without errors.

Screenshot 1 Thecompilation

 

 

 

To track the debug informationduring running, I set the debug output information to AM and usr1. the environment variablevalue “am” enables DBG AM messages, and the value “usr1” enables DBG USR1messages.

Screenshot 2 DBG setup

TinyVizcan be attached to a running simulation. Now TOSSIM is being made to wait forTinyViz to connect before it starts up.  Withthe graph interface, TinyViz captures all of the events in a given simulation.Now, TinyViz is ready for 10-node
simulation:

Screenshot 3 TinyVizready

Before the simulation, I make somesetup to get ready for the routing.

1.     Radio model

Screenshot 4 Radio model1

 

The radio model is the radio rangeof each mode. The default radio range is empirical. We can see from thefollowing picture, the modes can communicate everyone in the graph.

Screenshot 5 Radio model2

 

 

 

 

 

 

To see the mutil-hop routing, we donot expect that node can “see” all the others. Therefore, we set the fixedradio radius to 10. Now node 7 can only talk to 9, 2, 4 and 8.

Screenshot 6 Radio model 2

 

 

 

Now node 0 can onlytalk to 6, 3, 9.

Screenshot 7 Radio model 3

 

2.     The next step is to set Radio links. It is supposed tosee the radio links during the transmission.

Screenshot 8 Radio Links

 

 

3.     TinyViz also provide the interface to track debug messages. It can showonly the radio messages, only the selected motes messages and the completedebug messages.

Screenshot 9 Debug messages from TinyViz

 

 

 

 

 

 

After the basic setup, thesimulation is ready to work. This is the running status(node 6 is sendingmessage):

Screenshot 10 Running

 

We can get information from theconsole too:

Screenshot 11 Debug information during running from theconsole

 

 

 

 

This is the graph after running fora while (node 1 has finished a message):

Screenshot 12 Routing

 

Screenshot 12 Debug information during routing from theconsole

 

 

 

A routing process:

Step 1: node 1 is sending message tonode 6.

Step 2: node 6 is forwarding themessage to node 9.

Step 3: node 9 is forwarding themessage to node 2.

Step 4: node 2 is forwarding themessage to node 4.

Step 5: finished.

 

So, the routing path is 1à6à9à2à4à5.

 

The routing is successful. However,there are still some questions to be addressed.

1.     The routing path is not optimal. I have to modify to make it effective.

2.     I cannot see the radio links from TinyViz.

抱歉!评论已关闭.