Hi Cory and Michael,

I have been stuck with the Timer problem for a long time, I hope I could get any suggestions from you. Currently, I implemented an application which sets up a single radio link between one transmitter and one receiver. I want to implement the frequency change at both the transmitter and the receiver ends. The transmitter is switched on first, and keeps transmitting the messages (the message content is the counter value) on one particular frequency (Let's say on channel 11). It won't change its frequency until the receiver is switched on as well and send back an acknowledgement to the transmitter. At the time when the transmitter receives the ack from the receiver, both ends change the transmission frequency at the same rate and keep synchronisation all the time.

I used Timer0 to control the rate (fire every 0.25s) to fire the timer and send the counter value, and used Timer1 to control the rate (5s) of frequency change (from channel 11 to channel 26). I can get the acknowledgement back from the receiver when it is switched on, but I can't get the transmissin frequency changed even I did call Timer1.start( ) within the Send.sendDone( ). I suspected that it nevet gets a chance to set a new transmission frequency before sending out the messages due to the not precise timing, since the Timer0 and Timer1 are the instances of Timer. However, I am not sure if I am right to this, and I can't find a solution to the problem. My code is pasted here for you to look at.

command result_t StdControl.init()
 {
   m_int = 0;
   freq_int = 0;
   period_Timer0 = 256;
   period_Timer1 = 5120;
   m_sending = FALSE;
   call Leds.init();
   return SUCCESS;
 }

 command result_t StdControl.start()
 {
     call MacControl.enableAck();
   if( TOS_LOCAL_ADDRESS == 1 ){
        call Timer0.start( TIMER_REPEAT, period_Timer0 );
   }
   return SUCCESS;
 }

 command result_t StdControl.stop()
 {
   return SUCCESS;
 }

 /**
  * Tim0 is only called in the transmitter.
  */
 event result_t Timer0.fired()
 {
   if( m_sending == FALSE )
   {
     CountMsg_t* body = (CountMsg_t*)m_msg.data;
     body->n = m_int;
     body->src = TOS_LOCAL_ADDRESS;
     if( call SendMsg.send( 0, sizeof(CountMsg_t), &m_msg ) == SUCCESS )
        {
              call Leds.set(m_int);
               m_sending = TRUE;
     }
   }
m_int++; return SUCCESS;
 }
event result_t Timer1.fired()
 {
if (freq_int <= 15) {
       call CC2420Control.TunePreset(freq_channel[freq_int]);
       freq_int++;
   }
   else
   {
       freq_int = 0;
       call CC2420Control.TunePreset(freq_channel[freq_int]);
} return SUCCESS;
 }

 event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success)
 {
   if (!(msg->ack)){
       m_int--;
       call Leds.yellowToggle();
       }
       else {
           call MacControl.disableAck();
           call Timer1.start( TIMER_REPEAT, period_Timer1 );
} m_sending = FALSE;
   return SUCCESS;
 }

 event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr msg)
 {
     CountMsg_t* body = (CountMsg_t*)(&msg->data[0]);
     call Leds.set(body->n);
     return msg;
 }
}

Could you help me with this please? Thank you very much!

Best regards,
Ruoshui Liu
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to