It looks like you are using "packet" to send your first message
but checking against "pkt" in sendDone() in order to reset the
"busy" flag... Also, I would always compare busy == {FALSE,TRUE}
rather than !busy which assumes that FALSE is 0.

MS


chikh omar wrote:
> I have modified the BlinkToRadio app as follows:
>  
> 
>  #include <Timer.h>
> #include "BlinkToRadio.h"
> #include "printf.h"
> module BlinkToRadioC {
>   uses interface Boot;
>   uses interface Leds;
>   uses interface Timer<TMilli> as Timer0;
>   uses interface Packet;
>   uses interface AMPacket;
>   uses interface AMSend;
>   uses interface Receive;
>   uses interface SplitControl as AMControl;
> }
> implementation {
>   uint16_t counter;
>   message_t pkt, packet;
>   bool busy = FALSE;
>   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 AMControl.start();
>   }
>   event void AMControl.startDone(error_t err) {
>     if (err == SUCCESS) {
>       call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
>   
>   
>      counter++;
>    counter++;
>      //while(busy);
>    if (!busy) {
>      BlinkToRadioMsg* btrpkt =
>    (BlinkToRadioMsg*)(call Packet.getPayload(&packet, 
> sizeof(BlinkToRadioMsg)));
>      if (btrpkt == NULL) {
>    return;
>      }
>      btrpkt->nodeid = TOS_NODE_ID;
>      btrpkt->counter = counter;
>      if (call AMSend.send(AM_BROADCAST_ADDR, &packet, 
> sizeof(BlinkToRadioMsg)) == SUCCESS) {
>     busy = TRUE;
>     printf("BlinkToRadioMsg packet sent with success \n");
>     printf("sizeof(BlinkToRadioMsg)=%i\n",sizeof(BlinkToRadioMsg) );
>      }
>    } 
>    
>    else {
>      printf("channel busy in sending BlinkToRadioMsg\n");
>      call AMControl.start();
>    }
>   
>    printfflush();
>   
>     }
>     else {
>       call AMControl.start();
>     }
>   }
>   event void AMControl.stopDone(error_t err) {
>   }
>   event void Timer0.fired() {
>  
>  //   counter++;
>  //   if (!busy) {
>  //     BlinkToRadioMsg* btrpkt =
>  //(BlinkToRadioMsg*)(call Packet.getPayload(&pkt, 
> sizeof(BlinkToRadioMsg)));
>  //     if (btrpkt == NULL) {
>  //return;
>  //     }
>  //     btrpkt->nodeid = TOS_NODE_ID;
>  //     btrpkt->counter = counter;
>  //     if (call AMSend.send(AM_BROADCAST_ADDR,
>  //         &pkt, sizeof(BlinkToRadioMsg)) == SUCCESS) {
>  //       busy = TRUE;
>  //     }
>  //   }
>  
>   }
>   event void AMSend.sendDone(message_t* msg, error_t err) {
>     if (&pkt == msg) {
>       busy = FALSE;
>     }
>   }
>   event message_t* Receive.receive(message_t* msg, void* payload, 
> uint8_t len){
>  
>    printf("Received packet of length %hhu.\n", len); printfflush();
>  
>     if (len == sizeof(BlinkToRadioMsg)) {
>       BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload;
>       setLeds(btrpkt->counter);
>     }
>     return msg;
>   }
> }
>  
>  
> the problem is that only the first message is received.
> any help please
> 
> ***********************************************
> Omar Cheikhrouhou
> **Engineer & Researcher @SENS Lab (Software Engineering and Network 
> Security)
> Higher Institute of Technological Studies - Address : Mahdia's road Km 
> 2.5 Sfax. BP 88 A - 3099 El Bustan Sfax Telephone :  (+2... Poste : 
> 437**  **Fax: : (+216)74 431 386*
> 
> *Ph.D @ CES Lab (Computer and Embedded System)-University of Sfax, 
> National School of Engineers BP W, Sfax, 3038, Tunisia , 
> Fax:(+216)74665369 ** *
> 
> *Coordinator C2i @ ISET Sfax (Certified C2i since 2008)*
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to