On Tuesday 28 August 2007 09:52:29 am sara k wrote:
> Hi All,
>
> I want to insert the received event inside the timer.fire()!  The
> compiler will complain of the nested events...  but
>
> I am really need something like this:
> ......
> event void AMControl.startDone(error_t err) {
>     if (err == SUCCESS ) {
>      call Timer1.startOneShot( 2000); // only once I do not need periodic
>    }
>  }
>
> event void Timer1.fired() {
>    event message_t* Receive.receive (..) {
>      ......
>   // somejob then it will call another timer
>   }
> }

The radio stack triggers receive events as it receives them.  The Timer cannot 
trigger a receive event because it doesn't have a received packet.

If you want to suspend receipt of packets for ~ 2sec after the radio starts, 
use a flag.

event void AMControl.startDone(error_t error)
{
  if (error == SUCCESS)
    call Timer1.startOneShot(2000);
}

event void Timer1.fired()
{
  m_allowReceive = TRUE;
}

event message_t* Receive.receive(mesage_t* msg, ...)
{
  if (!m_allowReceive)
    return msg;
  else {
    /* process the receive normally */
  }
}

If instead you want to receive all messages as soon as they become available 
but only deal with them at least 2 seconds after the radio starts, use a 
Queue, as shown below.  This code is pretty bone-headed, so it probably isn't 
what you'll actually want to do.  But it is does show basic use of the Pool 
and Queue interfaces to queue received messages.  You can also see this at 
work in the BaseStation sample app code.

Consider my thoughts below pseudocode; I'm doing this from memory and its sure 
to be wrong in the details.

event void AMControl.startDone(error_t error)
{
  if (error == SUCCESS)
    call Timer1.startOneShot(2000);
}

task void processMessageTask()
{
  message_t* msg = call Queue.dequeue();

  if (msg) {
    /* process the message */
    post processMessageTask();
  } else {
    /* Something must happen here to allow the receive queue to be
     * processed again later as it fills.
     */
  }
}

event void Timer1.fired()
{
  post processMessageTask();
}

event message_t* Receive.receive(mesage_t* msg, ...)
{
  message_t* returnMsg = call Pool.get();
  if (!returnMsg)
    return msg; /* No space for message */
  else {
    call Queue.enqueue(msg);
    return returnMsg;
  }
}

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

Reply via email to