Hello dear Omprakash Gnawali,

This is part of my code where I do send msg. I have two kinds of
notification: Local notification: nodos do broadcast
Sink Notification: the node that receive 2 local notification send one sink
notification.
The BS can receive around 8 messages, and after that my node just reset and
stop. If the BS is turn off the node don't report any problem, but of course
i cannot receive the messages :/
Thanks a lot for any help.
Leah

task void report_base() {
    base.tipo = REPORT_BASE;
    base.from = local.id;
    base.nSinks = contSinkNotification;
    if (sizeof base <= call MultihopSend.maxPayloadLength())
     {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call MultihopSend.getPayload(&sendbuf, sizeof(base)),
                  &base, sizeof base);
       if (call MultihopSend.send(&sendbuf, sizeof base) == SUCCESS)
       {
        sendbusy = TRUE;
           }
     }
    else {
      report_problem();
      post report_base();
    }
}

 task void sinkSend() {
     if (//!sendbusy &&
         (sizeof sink <= call MultihopSend.maxPayloadLength()))
     {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call MultihopSend.getPayload(&sendbuf, sizeof(sink)),
                  &sink, sizeof sink);
       if (call MultihopSend.send(&sendbuf, sizeof sink) == SUCCESS)
       {
        sendbusy = TRUE;
        contSinkNotification++;
           }
     }
    else {
      report_problem();
      post sinkSend();
    }
  }

  void prepareSink() {
    int i;
    sink.from = local.id;
    atomic {
      for(i=0;i<=NNOTIFICATIONS;i++) {
        sink.ids[i]=idsBuf[i];
        sink.registros[i]=registrosBuf[i];
        sink.estouros[i]=estourosBuf[i];
      }
    }
    contLocalNotification = 0;
    sink.tipo = SINKNOTIFICATION;
    post sinkSend();
  }


  void startTimer() {
    call Timer.startPeriodic(local.interval);
    call Vida.startPeriodic(10*1024);
    if (TOS_NODE_ID == 0) {
    local.tipo = SINCRONIZACAO;
    memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
              sendbusy = TRUE;
      }
    tempoEntreAmostragens = 10; // microsegundos
    contLocalNotification=0;
    call ReadStream.postBuffer(Buf,NREADINGS);
  }


event void Boot.booted() {
    local.interval = 1024; // DEFAULT_INTERVAL;
    local.id = TOS_NODE_ID;
    toleranciaParaSink=5;
    registroReferencia=P60DB;
    if (call RadioControl.start() != SUCCESS)
      report_problem();
    if (call RoutingControl.start() != SUCCESS)
      report_problem();
    atomic {estouros = 0;}
}

  event void RadioControl.startDone(error_t error) {
    if (error != SUCCESS)
      report_problem();

    if (sizeof(local) > call AMSend.maxPayloadLength())
      report_problem();

     // This is how to set yourself as a root to the collection layer:
    if (local.id % 500 == 0)
      call RootControl.setRoot();

   startTimer();
 }

  event void RadioControl.stopDone(error_t error) { }

  event message_t* RootReceive.receive (message_t* msg, void* payload,
uint8_t len) {

     oscilloscope_t *omsg = payload;
     multihop_t *smsg = payload;
     report_base_t *rmsg = payload;
    if(rmsg->tipo == REPORT_BASE) {
    printf("\nVVVVVVVVVVVV\nFrom: %u\n",rmsg->from);
    printf("n: %u\n", rmsg->nSinks);
    printfflush();
    }
    if(omsg->tipo == LOCALNOTIFICATION) {
        printf("*************\nR: %u\n",omsg->tempo_read);
        printf("S: %u\n ----------\n",omsg->tempo_sendDone);
        printfflush();
        printf("id: %d\n",omsg->id);
        printf("estouros e ticks: %ld  %u \n",omsg->estouros,omsg->ticks);
        printf("energia consumida: [*900000000] %u
%ld\n\n",omsg->energia_aux,omsg->energia);
        printfflush();
    }
    if(smsg-> tipo == SINKNOTIFICATION) {
    atomic {
    printf("\n[][][][]\nfrom: \t%u\nRegistros: \t%u\t %u\n",
                    smsg->from,
task void report_base() {
    base.tipo = REPORT_BASE;
    base.from = local.id;
    base.nSinks = contSinkNotification;
    if (sizeof base <= call MultihopSend.maxPayloadLength())
     {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call MultihopSend.getPayload(&sendbuf, sizeof(base)),
                  &base, sizeof base);
       if (call MultihopSend.send(&sendbuf, sizeof base) == SUCCESS)
       {
        sendbusy = TRUE;
           }
     }
    else {
      report_problem();
      post report_base();
    }
}

 task void sinkSend() {
     if (//!sendbusy &&
         (sizeof sink <= call MultihopSend.maxPayloadLength()))
     {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call MultihopSend.getPayload(&sendbuf, sizeof(sink)),
                  &sink, sizeof sink);
       if (call MultihopSend.send(&sendbuf, sizeof sink) == SUCCESS)
       {
        sendbusy = TRUE;
        contSinkNotification++;
        }
     }
    else {
      report_problem();
      post sinkSend();
    }
  }

  void prepareSink() {
    int i;
    sink.from = local.id;
    atomic {
      for(i=0;i<=NNOTIFICATIONS;i++) {
        sink.ids[i]=idsBuf[i];
        sink.registros[i]=registrosBuf[i];
        sink.estouros[i]=estourosBuf[i];
      }
    }
    contLocalNotification = 0;
    sink.tipo = SINKNOTIFICATION;
    post sinkSend();
  }


  void startTimer() {
    call Timer.startPeriodic(local.interval);
    call Vida.startPeriodic(10*1024);
    if (TOS_NODE_ID == 0) {
    local.tipo = SINCRONIZACAO;
    memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
              sendbusy = TRUE;
      }
    tempoEntreAmostragens = 10; // microsegundos
    contLocalNotification=0;
    call ReadStream.postBuffer(Buf,NREADINGS);
  }


event void Boot.booted() {
    local.interval = 1024; // DEFAULT_INTERVAL;
    local.id = TOS_NODE_ID;
    toleranciaParaSink=5;
    registroReferencia=P60DB;
    if (call RadioControl.start() != SUCCESS)
      report_problem();
    if (call RoutingControl.start() != SUCCESS)
      report_problem();
    atomic {estouros = 0;}
}

  event void RadioControl.startDone(error_t error) {
    if (error != SUCCESS)
      report_problem();

    if (sizeof(local) > call AMSend.maxPayloadLength())
      report_problem();

     // This is how to set yourself as a root to the collection layer:
    if (local.id % 500 == 0)
      call RootControl.setRoot();

   startTimer();
 }

  event void RadioControl.stopDone(error_t error) { }

  event message_t* RootReceive.receive (message_t* msg, void* payload,
uint8_t len) {

     oscilloscope_t *omsg = payload;
     multihop_t *smsg = payload;
     report_base_t *rmsg = payload;
    if(rmsg->tipo == REPORT_BASE) {
    printf("\nVVVVVVVVVVVV\nFrom: %u\n",rmsg->from);
    printf("n: %u\n", rmsg->nSinks);
    printfflush();
    }
    if(omsg->tipo == LOCALNOTIFICATION) {
        printf("*************\nR: %u\n",omsg->tempo_read);
        printf("S: %u\n ----------\n",omsg->tempo_sendDone);
        printfflush();
        printf("id: %d\n",omsg->id);
        printf("estouros e ticks: %ld  %u \n",omsg->estouros,omsg->ticks);
        printf("energia consumida: [*900000000] %u
%ld\n\n",omsg->energia_aux,omsg->energia);
        printfflush();
    }
    if(smsg-> tipo == SINKNOTIFICATION) {
    atomic {
    printf("\n[][][][]\nfrom: \t%u\nRegistros: \t%u\t %u\n",
                    smsg->from,
                    smsg->registros[0],
                    smsg->registros[1]);
    printf("IDs: \t\t%u \t %u\n",
                    smsg->ids[0],
                    smsg->ids[1]);
/*    printf("Estouros: \t%ld \t %ld\n[][][][]\n",
                     smsg->estouros[0],
                     smsg->estouros[1]);
*/
    printfflush();
    }
    }
   calc_energia(ERLN);
   return msg;

  }

  event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len) {
    oscilloscope_t *omsg = payload;

  /*
   * Se a mensagem for do tipo SINCRONIZACAO, o no da um novo
   * startPeriodic para sincronizar-se
   */
   atomic {
     if (omsg->tipo == SINCRONIZACAO) {
        call Vida.startPeriodic(1024);
     }

     else { report_multihop(); }
   }

    /* Se escutou uma LocalNotification, armazena o registro e guarda
    *  o estouro referente ao recebimento da LocalNotification
    *  Se o numero de localNotifications for igual ao NNOTIFICATIONS
    * especificado entao prepara um SinkNotification, e zera o contador
    * de locaNotifications
    */

    if ((omsg->tipo == LOCALNOTIFICATION) && (local.id != 0)) {

/* Adciona nos respectivos buffers os registros, ids, e estouros */
     atomic {
      registrosBuf[contLocalNotification]=omsg->registro;
      idsBuf[contLocalNotification]=omsg->id;
      estourosBuf[contLocalNotification]=omsg->estouros;
     }

      if(autorizadoParaSink) {
          contLocalNotification++;
      }

      if (contLocalNotification == NNOTIFICATIONS) {
            prepareSink();
            contLocalNotification=0;
      }

    }



    /* If we receive a newer version, update our interval.
    */
    if (omsg->version > local.version)  {
    local.version = omsg->version;
    local.interval = omsg->interval;
    }

    printf("\n=============\nR: %u\n",omsg->tempo_read);
    printf("S: %u\n ----------\n",omsg->tempo_sendDone);
    printfflush();

    if ((local.id == 0) && (omsg->id !=0)) {
        printf("id: %d\n",omsg->id);
    printf("registro: %u\n", omsg->registro);
        printf("estouros e ticks: %ld  %u \n",omsg->estouros,omsg->ticks);
        printf("energia consumida: [*900000000] %u
%ld\n\n",omsg->energia_aux,omsg->energia);
        printfflush();
    }

    calc_energia(ERLN);

    /* CH encaminha msg para Root */
    atomic {
      if (local.id ==  1) {
    local.tipo = omsg-> tipo;
    local.version = omsg->version;
    local.interval = omsg->interval;
        local.id = omsg->id;
    local.registro = omsg->registro;
        local.ticks = omsg->ticks;
        local.estouros = omsg->estouros;
        local.tempo_read = omsg->tempo_read;
        local.tempo_sendDone = omsg->tempo_sendDone;
        local.energia = omsg->energia;
        local.energia_aux = omsg->energia_aux;

        memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(0,   //AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
               sendbusy = TRUE;
       else
        report_problem();

        local.id = TOS_NODE_ID;
     }
    }

    return msg;

  }

  event message_t*  Snoop.receive(message_t* msg, void* payload, uint8_t
len) {
    oscilloscope_t *omsg = payload;

   atomic {
     if (omsg->tipo == SINCRONIZACAO) {
        call Vida.startPeriodic(1024);
     }
   }
   calc_energia(ERLN);
    return msg;
  }

  /* At each sample period:
     - se a pressao for expressiva e a ultima LocalNotification
       recebida nao for validada, envia uma LocalNotification.
     - read next sample
  */
  event void Timer.fired() {

    // envia mensagem de sincronizacao

    local.energia = energia;
    local.energia_aux = energia_aux;
       // (!LNValida() && pressaoExpressiva && local.id != 0)
    if((local.id !=0 ) && (local.id != 1))
    {
        if ((!sendbusy) &&
            ((sizeof local) <= (call AMSend.maxPayloadLength())))
        {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
          sendbusy = TRUE;
     }
     else{
           if( sendbusy)
        report_problem();
     }
         pressaoExpressiva=FALSE;
   }

   if(local.id != 0) {
     if (call ReadStream.read(tempoEntreAmostragens) != SUCCESS)
       ; //report_multihop();
      else {
            atomic {
         local.tempo_read = call Vida.getNow();
                 local.ticks = call Vida.getNow();
                 local.estouros = estouros;
            }

      }
   }
   if(suprimeLN)
     report_ln();

  }

event void AMSend.sendDone(message_t* msg, error_t error) {
    if (error == SUCCESS) {
          report_sent();
          atomic { local.tempo_sendDone = call Vida.getNow(); }
    }
    else {
      report_problem();
    }
    calc_energia(ESLN);
    sendbusy = FALSE;
 }

 event void MultihopSend.sendDone(message_t* msg, error_t error) {
    if (error == SUCCESS)
      report_multihop();
    else
      report_problem();
    sendbusy = FALSE;

    calc_energia(ESLN);
}

  event void ReadStream.bufferDone(error_t result,uint16_t *buf, uint16_t
count) {
    copiaBuffer(Buf2,buf);
  }

  event void ReadStream.readDone(error_t result, uint32_t usActualPeriod) {
    if (result != SUCCESS)
    report_problem();
    registro_tmp = calculaRegistro(Buf2);

    /* Se escutar registro acima do esperado, entao a pressao foi
    *  considerada expressiva, entaolibera o envio da mensagem.
    */
    if (registro_tmp > registroReferencia) {
      local.registro = registro_tmp;
      pressaoExpressiva=TRUE;
    }
    else {
    pressaoExpressiva=FALSE;
    if(registro_tmp >= (registroReferencia - toleranciaParaSink)) {
        autorizadoParaSink = TRUE;
    }
    else {
        autorizadoParaSink = FALSE;
    }
    }

    call ReadStream.postBuffer(Buf,NREADINGS);
  }

/* Quando houver o estour do timer vida, incrementa os estouros*/
  event void Vida.fired() {
    atomic {
      estouros++;

    }
    if ((estouros%60) == 0) {
       if(contSinkNotification > 0) {
      post report_base();
       }
    }
  }

}
                    smsg->registros[0],
                    smsg->registros[1]);
    printf("IDs: \t\t%u \t %u\n",
                    smsg->ids[0],
                    smsg->ids[1]);
/*    printf("Estouros: \t%ld \t %ld\n[][][][]\n",
                     smsg->estouros[0],
                     smsg->estouros[1]);
*/
    printfflush();
    }
    }
   calc_energia(ERLN);
   return msg;

  }

  event message_t* Receive.receive(message_t* msg, void* payload, uint8_t
len) {
    oscilloscope_t *omsg = payload;

  /*
   * Se a mensagem for do tipo SINCRONIZACAO, o no da um novo
   * startPeriodic para sincronizar-se
   */
   atomic {
     if (omsg->tipo == SINCRONIZACAO) {
        call Vida.startPeriodic(1024);
     }

     else { report_multihop(); }
   }

    /* Se escutou uma LocalNotification, armazena o registro e guarda
    *  o estouro referente ao recebimento da LocalNotification
    *  Se o numero de localNotifications for igual ao NNOTIFICATIONS
    * especificado entao prepara um SinkNotification, e zera o contador
    * de locaNotifications
    */

    if ((omsg->tipo == LOCALNOTIFICATION) && (local.id != 0)) {

/* Adciona nos respectivos buffers os registros, ids, e estouros */
     atomic {
      registrosBuf[contLocalNotification]=omsg->registro;
      idsBuf[contLocalNotification]=omsg->id;
      estourosBuf[contLocalNotification]=omsg->estouros;
     }

      if(autorizadoParaSink) {
          contLocalNotification++;
      }

      if (contLocalNotification == NNOTIFICATIONS) {
            prepareSink();
            contLocalNotification=0;
      }

    }



    /* If we receive a newer version, update our interval.
    */
    if (omsg->version > local.version)  {
    local.version = omsg->version;
    local.interval = omsg->interval;
    }

    printf("\n=============\nR: %u\n",omsg->tempo_read);
    printf("S: %u\n ----------\n",omsg->tempo_sendDone);
    printfflush();

    if ((local.id == 0) && (omsg->id !=0)) {
        printf("id: %d\n",omsg->id);
    printf("registro: %u\n", omsg->registro);
        printf("estouros e ticks: %ld  %u \n",omsg->estouros,omsg->ticks);
        printf("energia consumida: [*900000000] %u
%ld\n\n",omsg->energia_aux,omsg->energia);
        printfflush();
    }

    calc_energia(ERLN);

    /* CH encaminha msg para Root */
    atomic {
      if (local.id ==  1) {
    local.tipo = omsg-> tipo;
    local.version = omsg->version;
    local.interval = omsg->interval;
        local.id = omsg->id;
    local.registro = omsg->registro;
        local.ticks = omsg->ticks;
        local.estouros = omsg->estouros;
        local.tempo_read = omsg->tempo_read;
        local.tempo_sendDone = omsg->tempo_sendDone;
        local.energia = omsg->energia;
        local.energia_aux = omsg->energia_aux;

        memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(0,   //AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
               sendbusy = TRUE;
       else
        report_problem();

        local.id = TOS_NODE_ID;
     }
    }

    return msg;

  }

  event message_t*  Snoop.receive(message_t* msg, void* payload, uint8_t
len) {
    oscilloscope_t *omsg = payload;

   atomic {
     if (omsg->tipo == SINCRONIZACAO) {
        call Vida.startPeriodic(1024);
     }
   }
   calc_energia(ERLN);
    return msg;
  }

  /* At each sample period:
     - se a pressao for expressiva e a ultima LocalNotification
       recebida nao for validada, envia uma LocalNotification.
     - read next sample
  */
  event void Timer.fired() {

    // envia mensagem de sincronizacao

    local.energia = energia;
    local.energia_aux = energia_aux;
       // (!LNValida() && pressaoExpressiva && local.id != 0)
    if((local.id !=0 ) && (local.id != 1))
    {
        if ((!sendbusy) &&
            ((sizeof local) <= (call AMSend.maxPayloadLength())))
        {
       // Don't need to check for null because we've already
           // checked length above
       memcpy(call AMSend.getPayload(&sendbuf, sizeof(local)),
                  &local, sizeof local);
       if (call AMSend.send(AM_BROADCAST_ADDR,
                  &sendbuf, sizeof local) == SUCCESS)
          sendbusy = TRUE;
     }
     else{
           if( sendbusy)
        report_problem();
     }
         pressaoExpressiva=FALSE;
   }

   if(local.id != 0) {
     if (call ReadStream.read(tempoEntreAmostragens) != SUCCESS)
       ; //report_multihop();
      else {
            atomic {
         local.tempo_read = call Vida.getNow();
                 local.ticks = call Vida.getNow();
                 local.estouros = estouros;
            }

      }
   }
   if(suprimeLN)
     report_ln();

  }

event void AMSend.sendDone(message_t* msg, error_t error) {
    if (error == SUCCESS) {
          report_sent();
          atomic { local.tempo_sendDone = call Vida.getNow(); }
    }
    else {
      report_problem();
    }
    calc_energia(ESLN);
    sendbusy = FALSE;
 }

 event void MultihopSend.sendDone(message_t* msg, error_t error) {
    if (error == SUCCESS)
      report_multihop();
    else
      report_problem();
    sendbusy = FALSE;

    calc_energia(ESLN);
}

  event void ReadStream.bufferDone(error_t result,uint16_t *buf, uint16_t
count) {
    copiaBuffer(Buf2,buf);
  }

  event void ReadStream.readDone(error_t result, uint32_t usActualPeriod) {
    if (result != SUCCESS)
    report_problem();
    registro_tmp = calculaRegistro(Buf2);

    /* Se escutar registro acima do esperado, entao a pressao foi
    *  considerada expressiva, entaolibera o envio da mensagem.
    */
    if (registro_tmp > registroReferencia) {
      local.registro = registro_tmp;
      pressaoExpressiva=TRUE;
    }
    else {
    pressaoExpressiva=FALSE;
    if(registro_tmp >= (registroReferencia - toleranciaParaSink)) {
        autorizadoParaSink = TRUE;
    }
    else {
        autorizadoParaSink = FALSE;
    }
    }

    call ReadStream.postBuffer(Buf,NREADINGS);
  }

/* Quando houver o estour do timer vida, incrementa os estouros*/
  event void Vida.fired() {
    atomic {
      estouros++;

    }
    if ((estouros%60) == 0) {
       if(contSinkNotification > 0) {
      post report_base();
       }
    }
  }

}
On Thu, Jan 14, 2010 at 4:46 PM, Omprakash Gnawali
<[email protected]>wrote:

> On Thu, Jan 7, 2010 at 2:48 AM, ** Underléa ** <[email protected]> wrote:
> > Dear all,
> >
> > I am running an acoustic application on the platform micaz mote using
> tinyos
> > 2.1.
> > I am using the colection protocol to send the message from mote to the BS
> > via multi-hop.
> > The problem is that I can send 6 messages and node crashes. Stop to send
> > messages and start report error through red led
> > Has anyone had this problem, or have any tips that would explain this
> > behavior? I have no idea what to do :(
>
> CTP crashes after sending 6 messages? You should post the code for
> send and sendDone and we can take a look.
>
> - om_p
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to