[Tinyos-help] Re : send packet

Roberto Pagliari robertodemedici at gmail.com
Thu Apr 29 15:58:56 PDT 2010


never mind. I forgot to call AMstart in the boot sequence

On Thu, Apr 29, 2010 at 3:24 PM, Roberto Pagliari <robertodemedici at gmail.com
> wrote:

> what do you mean? packet is already global. here is the code:
>
> module NodeC @safe()
> {
>   uses interface Timer<TMilli> as Timer0;
>   uses interface Leds;
>   uses interface Boot;
>   uses interface Random;
>   uses interface ParameterInit<uint16_t> as SeedInit;
>
>   uses interface Receive;
>   uses interface AMSend;
>   uses interface SplitControl as AMControl;
>   uses interface Packet;
> }
> implementation
> {
>   message_t packet;
>   uint16_t value;
>   uint16_t mybfr[50];
>   uint8_t idx;
>   bool locked;
>
>   event void Boot.booted()
>   {
>     call SeedInit.init( 2 );
>     idx = 0; locked = FALSE;
>
>     call Leds.led0Off(); call Leds.led1Off(); call Leds.led2Off();
>
>     value = (call Random.rand16()) % 8;
>
>     call Timer0.startOneShot( (call Random.rand32()) % 2048 + 100  );
>  /*   if( (value & 1) == 1 ) {
>       call Leds.led0On();
>     }
>     if( (value & 2) == 1 )
>       call Leds.led1On();
>     else
>       call Leds.led1Off();
>     if( (value & 4) == 1 )
>       call Leds.led2On();
>     else
>       call Leds.led2Off();*/
>
>   }
>
>   event void AMControl.startDone(error_t err) {
>     if (err == SUCCESS) {
>     }
>     else {
>       call AMControl.start();
>     }
>   }
>
>   event void AMControl.stopDone(error_t err) {
>     // do nothing
>
>   }
>
>   event void Timer0.fired()
>   {
>     //dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
>     my_msg_t* rcm = (my_msg_t*)call Packet.getPayload(&packet,
> sizeof(my_msg_t));
>     if (rcm == NULL) {
>       return;
>     }
>   //  call Leds.led0Toggle();
>     rcm->color = value;
>     if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(my_msg_t)) ==
> FAIL) {
>
>       dbg("RadioCountToLedsC", "RadioCountToLedsC: packet sent.\n",
> counter);
>       call Leds.led0Toggle();
>       locked = TRUE;
>     }
>     call Timer0.startOneShot( (call Random.rand32()) % 2048 + 100  );
>   }
>
>   event message_t* Receive.receive(message_t* bufPtr, void* payload,
> uint8_t len) {
>     //dbg("RadioCountToLedsC", "Received packet of length %hhu.\n", len);
>     /*if (len != sizeof(radio_count_msg_t)) {return bufPtr;}
>     else {
>       radio_count_msg_t* rcm = (radio_count_msg_t*)payload;
>       if (rcm->counter & 0x1) {
>     call Leds.led0On();
>       }
>       else {
>     call Leds.led0Off();
>       }
>       if (rcm->counter & 0x2) {
>     call Leds.led1On();
>       }
>       else {
>     call Leds.led1Off();
>       }
>       if (rcm->counter & 0x4) {
>     call Leds.led2On();
>       }
>       else {
>     call Leds.led2Off();
>       }*/
>
>       call Leds.led1Toggle();
>       return bufPtr;
>   }
>
>   event void AMSend.sendDone(message_t* bufPtr, error_t error) {
>     if (&packet == bufPtr) {
>       locked = FALSE;
>     }
>   }
>
> }
>
> the send function always fails at the moment..
>
>
> On Thu, Apr 29, 2010 at 2:49 PM, chikh omar <enis01amor at yahoo.fr> wrote:
>
>> use message_t pkt as a global variable and it will work...
>>
>>
>> ***********************************************
>> 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 : (+216)74 237425 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)*
>>
>>
>> ------------------------------
>> *De :* avinash chaurasia <avinash.aviank2003 at gmail.com>
>> *À :* Roberto Pagliari <robertodemedici at gmail.com>
>> *Cc :* tinyos-help at millennium.berkeley.edu
>> *Envoyé le :* Jeu 29 avril 2010, 21 h 27 min 27 s
>> *Objet :* Re: [Tinyos-help] send packet
>>
>> call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(my_msg_t))  returns
>> different type of error messages are you sure it returns FAIL? or something
>> else like EOFF?
>> Thanks
>> Avinash Kumar Chaurasia
>> Department of Computer Science
>> IIT Kanpur, India
>>
>>
>> On Fri, Apr 30, 2010 at 12:43 AM, Roberto Pagliari <
>> robertodemedici at gmail.com> wrote:
>>
>>> Hi All,
>>> I'm having trouble with sending packets, I just moved from tinyos 1 to
>>> tinyos 2. In the following code a node should blinkwhen a packet is
>>> received. The problem is that no packets are sent. AMSend.send, apparently,
>>> always returns FAIL. Does anybody know if I am missing something?
>>>
>>> Thanks
>>>
>>>
>>>
>>>   event void Timer0.fired()
>>>   {
>>>     //dbg("BlinkC", "Timer 0 fired @ %s.\n", sim_time_string());
>>>     my_msg_t* rcm = (my_msg_t*)call Packet.getPayload(&packet,
>>> sizeof(my_msg_t));
>>>     if (rcm == NULL) {
>>>       return;
>>>     }
>>>   //  call Leds.led0Toggle();
>>>     rcm->color = value;
>>>     if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(my_msg_t)) ==
>>> SUCCESS) {
>>>       dbg("RadioCountToLedsC", "RadioCountToLedsC: packet sent.\n",
>>> counter);
>>>       call Leds.led0Toggle();
>>>       locked = TRUE;
>>>     }
>>>     call Timer0.startOneShot( (call Random.rand32()) % 2048 + 100  );
>>>   }
>>>
>>>   event message_t* Receive.receive(message_t* bufPtr, void* payload,
>>> uint8_t len) {
>>>       call Leds.led1Toggle();
>>>       return bufPtr;
>>>   }
>>>
>>> _______________________________________________
>>> Tinyos-help mailing list
>>> Tinyos-help at millennium.berkeley.edu
>>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>>
>>
>>
>>
>
>
> --
> Roberto Pagliari
>



-- 
Roberto Pagliari
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20100429/332cd835/attachment.htm 


More information about the Tinyos-help mailing list