if you are talking about below code snippet
if (call AMSend.send(BsAddr, &msg, sizeof(risegMsgSent)) == SUCCESS){
     call Leds.led0Toggle();
     return 0;
   }

then replace it like this
err = call AMSend.send(BsAddr, &msg, sizeof(risegMsgSent)) ;
if (err== SUCCESS){
     call Leds.led0Toggle();
     return 0;
   }

and try to print value of err. I got the same problem earlier and i found
value to be 4 by doing this i.e. EOFF but still it goes inside the if
statement when it is written like above you written.

Thanks
Avinash Kumar Chaurasia
Department of Computer Science
IIT Kanpur, India


On Wed, Apr 21, 2010 at 2:33 AM, chikh omar <[email protected]> wrote:

>  the code is bellow. I have also attached the file.
>
> great thank,
> ==================================================
> #include <Timer.h>
> #include "riseg.h"
> // #include "printf.h"
> module RisegP {
>   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;
>   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();
>   }
>
> //function that return the GroupControllerAddress of group gid
> uint16_t getGroupControllerAddr(uint8_t gid)
> {
>
> //   return 0xFFFF;
>   return (0x0000);
> }
> ////function that return true if node is in black list
> bool nodeIsCompromised(uint16_t nid)
> {
>  return FALSE;
>
> }
> int  treatment_risegMsg_BS(riseg_msg_t *risegMsg)
> {
>     join_msg_t* joinMsg= (join_msg_t*)(risegMsg->data);
>     uint16_t nid, GcAddr;
>     uint8_t gid;
>     uint16_t len;
>     error_t res=0;
>     nid=0xffff;
>     //Action will be taken according to message type
> //     printf("BaseStationP: I am at the begin of treatment_risegMsg\n");
> //
>     printf("BaseStationP: risegMsg->type = %i\n", risegMsg->type);
> //     printf("BaseStationP: joinMsg->nid = %i \t 0X%x\n", joinMsg->nid,
> joinMsg->nid);
> //     printfflush();
>
>     switch (risegMsg->type){
>
>       //prepare a risegMsg
>       message_t msg;
>       message_t msgsent;
> //       riseg_msg_t *risegMsgSent=(riseg_msg_t*)(call
> RadioPacket.getPayload(&msg,NULL));
> //       riseg_msg_t *risegMsgSent=(riseg_msg_t*)(call
> RadioPacket.getPayload(&msg,sizeof(riseg_msg_t)));
>
>       riseg_msg_t *ptr_risegMsgSent=(riseg_msg_t*)(call
> Packet.getPayload(&msgsent,sizeof(riseg_msg_t)));
>
>       case JOIN_REQUEST:
>  printf("BaseStationP: receiving JOIN_REQUEST message \n");
>
>  //verify the validity of timestamp
>
>  //verify the validity of mac
>
>  //timestamp and mac are OK
>  //get a pointer to the join message
>
> //  //verify that node id is not in the black list
> //  nid= joinMsg->nid;
> //  //if node is compromised quit program (using return and exit)
> //  if ((res=nodeIsCompromised(nid)))
> //  {
> //
> //
> //    return res;
> //  }
> //
> // //  printf("BaseStationP: res=%i \n", res);
> //  //node is ok
> //  gid=joinMsg->gid;
> //
>  //get the GC of such group if already exist
> //  uint16_t GcAddr;
> //  GcAddr=getGroupControllerAddr(gid);
>
> //  printf("BaseStationP: GcAddr= 0x%x \n", GcAddr);
> //  //if group already exist
> //  if (GcAddr != 0x0000){
> //  //send a join inform message to the GC of such group
> //  printf("!0 BaseStationP:send a join inform message to the GC of such
> group\n");
> //  risegMsgSent->type=JOIN_INFORM;
> //  //only the timestamp of the received joinMsg will be changed
> //  //this will be done latter
> // //  risegMsgSent->data=(uint16_t*) joinMsg; //this instruction is
> useless since joinMsg pointe at risegMsgSent->data
> //
> //  //recompute the mac
> //
> //
> //  //send the message to GC
> //
> //  }
> //  //if the group does not exist already
> //  else
>  {
>    //the group does not exist yet
>    //send a group creation invite message
>    printf("BaseStationP:send a group creation invite message\n");
>    //printfflush();
> //    risegMsgSent->type=GROUP_CREATION_INVITE;
>
> //    ptr_risegMsgSent->type=GROUP_CREATION_INVITE;
>    // the message has only one field timestamp
> //    risegMsgSent->data[0]= 1; //current time
>
>    //recompute the mac
>
>
>    //send the message to the GC
> //    len=sizeof(risegMsgSent);
>    len=sizeof(riseg_msg_t);
> //    printf("radio send to: 0x%x len: %i\n", nid, len);
>    nid=0xffff;
> //    len=2;
> //    res=call Packet.send(nid, &msg, len);
> //    ptr_risegMsgSent->type=GROUP_CREATION_INVITE;
> //    printf("Av: ptr_risegMsgSent=%i;\n", ptr_risegMsgSent->type);
> // for(i=0; i
> // printf("Av: ptr_risegMsgSent->data[0]=%i;\n",
> ptr_risegMsgSent->data[0]);
> // printf("Av: ptr_risegMsgSent->data[1]=%i;\n",
> ptr_risegMsgSent->data[1]);
> // printfflush();
> //    ptr_risegMsgSent=(riseg_msg_t*)(call
> Packet.getPayload(&msgsent,sizeof(riseg_msg_t)));
> //    printf("Ap: ptr_risegMsgSent=%i;\n", ptr_risegMsgSent->type);
> //    res=call Packet.send(nid, &msgsent, len);
> //    printf("BaseStationP: call Packet.send(nid, &msg, len) return %d\n",
> res);
>    //printfflush();
>  }
>
>  break;
> //       INFORM:
> //        printf("receiving JOIN_INFORM message \n");
> //       LEAVE:
> //
> //       KEY_UPDATE:
>
>       default:
>  printf("message riseg non reconnu \n");
>  //printfflush();
>  break;
>
>     }//switch
>     printf("I am at the end of treatment_risegMsg\n");
> //     printf("BaseStationP: I am at the end of treatment_risegMsg\n");
>     //printfflush();
>
> return res;
> }
>
> /**************************************************************************/
> /*************************Here the code needed for
> EndDevice***************/
> /*************************************************************************/
> int send_join_request ()
> {
>     uint8_t len;
>     uint16_t addr;
>     message_t msg;
>     error_t res=0;
>     //create a join-request message
>     riseg_msg_t *risegMsg=(riseg_msg_t*)(call Packet.getPayload(&msg,
> NULL));
> //     riseg_msg_t *risegMsg=(riseg_msg_t*)(call Packet.getPayload(&msg,
> sizeof(riseg_msg_t)));
>     join_msg_t *joinMsg=(join_msg_t*) risegMsg->data;
>     printf("EndDevice: send_join_request () : creation  du message join\n
> ");
>     //creation  du message join
>     risegMsg->type=JOIN_REQUEST;
>     joinMsg->nid=TOS_NODE_ID;
>     joinMsg->gid=TEMP;
>     // joinMsg->t = call Time.getNow(); //a verifier
>     //risegMsg->data est un tableau de uint16_t
>     //uint tab[10];
>     //tab=pointeur;
>     // risegMsg->data= (uint16_t*) ;
>     //calcule de mac
>     //msg->mac = call Hmac.mac();
>     //send the message
>
>     // risegMsg = (risegMsg*)(call Packet.getPayload(&msg, NULL));
>  //   addr=AM_BROADCAST_ADDR;
>    addr=BsAddr;
> //     len=sizeof(risegMsg);
>
>     len=sizeof(riseg_msg_t);
> //     printf("sizeof(riseg_msg_t)=%i \t sizeof(risegMsg)=%i \t
> sizeof(*risegMsg)=%i\n",sizeof(riseg_msg_t), sizeof(risegMsg),
> sizeof(*risegMsg));
>     printf("radio send to: 0x%x len: %i\n", addr, len);
>     res=call AMSend.send(addr, &msg, len);
>     printf(" EndDevice: call AMSend.send(addr, &msg, len) return %d\n",
> res);
>
>     //printfflush();
>     return res;
> }
> // ***********************
> // int treatment_risegMsg(riseg_msg_t *risegMsg, message_t* msgrcv){
> int treatment_risegMsg_ED(riseg_msg_t *risegMsg){
>
>     //get a pointer to the join message
>     join_msg_t *joinMsg= (join_msg_t *)risegMsg->data;
>
>    //prepare a risegMsg to be sent
>     message_t msg;
>     riseg_msg_t *risegMsgSent=(riseg_msg_t*)(call Packet.getPayload(&msg,
> NULL));
>
>     riseg_msg_t *risegMsgRcv=(riseg_msg_t*)(call Packet.getPayload(&msg,
> sizeof(riseg_msg_t)));
>     riseg_msg_t *risegMsgRcv2=(riseg_msg_t*)(call Packet.getPayload(&msg,
> 2));
> //     riseg_msg_t *risegMsgSent;
>
> //   printf("msgr\n");
> printf("EndDeviceP: risegMsgRcv->type= %i\n",risegMsgRcv->type);
> //printfflush();
>      //Action will be taken according to message type
>    printf("Receive riseg message of type risegMsg->type = %d\n",
> risegMsg->type);
>     switch (risegMsg->type){
>       case GROUP_CREATION_INVITE:
>  printf("EndDeviceP: receiving GROUP_CREATION_INVITE message\n");
>  //printfflush();
>  //verify the validity of timestamp
>
>  //verify the validity of mac
>
>  //timestamp and mac are OK
>
>  //we suppose that the node accept to be a GC
>
>    //send a group creation invite message
>    risegMsgSent->type=GROUP_CREATION_ACCEPT;
>
>    // the message has only one field timestamp
> //    risegMsgSent.data= ;
>
>    //recompute the mac
>
>
>    //send the message to the Base Station
>    printf("EndDeviceP: send the message to the Base Station\n");
>    //printfflush();
>
> //    uint16_t len=sizeof(risegMsgSent);
> //    message_t* msg;
>    printf ("radio send to: 0x%x len: %i\n", BsAddr, sizeof(risegMsgSent));
>    if (call AMSend.send(BsAddr, &msg, sizeof(risegMsgSent)) == SUCCESS){
>      call Leds.led0Toggle();
>      return 0;
>    }
>    else
>      {
>      call Leds.led1Toggle();
>      return 1;
>      }
>
>  break;
>      case  JOIN_INFORM:
>       printf("receive JOIN_INFORM message\n");
>       break;
> //
> //       LEAVE:
> //
> //       KEY_UPDATE:
>
>       default:
>  printf("message riseg non reconnu \n");
>  break;
>       }
> }
>   event void Boot.booted() {
>
>      printf("**********Node ID %i: Here is the begin of
> Boot.booted()***********\n", TOS_NODE_ID);
>    //printfflush();
>
>     call AMControl.start();
>
>  //printf("**********BaseStationP: Here is the end of
> Boot.booted()***********\n", TOS_NODE_ID);
>    //printfflush();
>
>
>   }
>   event void AMControl.startDone(error_t err) {
>     if (err == SUCCESS) {
>       call Timer0.startPeriodic(TIMER_PERIOD_MILLI);
>       if (TOS_NODE_ID==EndDevice_ID)
>       {
>    //EndDevice code for riseg
>      printf("**********EndDevice %i: Searching to join a group...\n",
> TOS_NODE_ID);
>      //printfflush();
>
>    //call send_join_request();
>
>      printf("EndDevice: send_join_request() return %i\n",
> send_join_request());
>      //printfflush();
>       }
>
>     }
>     else {
>       call AMControl.start();
>     }
>   }
>   event void AMControl.stopDone(error_t err) {
>   }
>   event void Timer0.fired() {
>
> //     counter++;
> //     if (!busy) {
> //       riseg_msg_t* btrpkt =
> //  (riseg_msg_t*)(call Packet.getPayload(&pkt, sizeof(riseg_msg_t)));
> //       if (btrpkt == NULL) {
> //  return;
> //       }
> //       btrpkt->nodeid = TOS_NODE_ID;
> //       btrpkt->counter = counter;
> //       if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(riseg_msg_t))
> == SUCCESS) {
> //         busy = TRUE;
> //       }
> //     }
>   }
>   event void AMSend.sendDone(message_t* msg, error_t err) {
>
>   printf("in AMSend.sendDone \n");
>
>     if (&pkt == msg) {
>       busy = FALSE;
>     }
>   }
>   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
> len){
>
>
>     riseg_msg_t* btrpkt = (riseg_msg_t*)payload;
>     printf("BaseStationP: RadioReceive.receive(message_t *msg,void
> *payload, uint8_t len) : radio message received (%i)\n", len);
>     if (len == sizeof(riseg_msg_t)) {
>       if (TOS_NODE_ID==EndDevice_ID){
>  printf("EndDevice: received RISEG message \n");
>  //printfflush();
>  setLeds(btrpkt->type);
> //        treatment_risegMsg((riseg_msg_t*)(call
> RadioPacket.getPayload(msg,sizeof(riseg_msg_t))));
>  treatment_risegMsg_ED(btrpkt);
>       }
>       else{
>       printf("BaseStation: received RISEG message \n");
>       //printfflush();
>       setLeds(btrpkt->type);
> //        treatment_risegMsg((riseg_msg_t*)(call
> RadioPacket.getPayload(msg,sizeof(riseg_msg_t))));
>       treatment_risegMsg_BS(btrpkt);
>       }
>     }
>     return msg;
>   }
> }
>
> ***********************************************
> 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 <[email protected]>
> *À :* chikh omar <[email protected]>
> *Cc :* tinyos help <[email protected]>
> *Envoyé le :* Mar 20 avril 2010, 20 h 49 min 27 s
> *Objet :* Re: [Tinyos-help] problem tossim + printf
>
> please paste ur code snippet that will help.
> Thanks
> Avinash Kumar Chaurasia
> Department of Computer Science
> IIT Kanpur, India
>
>
> On Tue, Apr 20, 2010 at 10:19 PM, chikh omar <[email protected]> wrote:
>
>>   hello,
>>
>> when executing my code, some message are not show. Did you know
>> possible source of this problem.
>> Moreover, When I send a message AMsend.sed(...) return 0 which means
>> success ,however senddone (...) is not executed.
>>
>> 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 : (+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)*
>>
>>
>> _______________________________________________
>> 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