TinyOS periodic Bcast AMSend not received

1.1k Views Asked by At

I want to send messages periodically through this program, the messages are broadcasted fine and I get a sendDone message. The problem is that these messages are not received well. I would really appreciate any help to find out where the problem is?

Here is the code(please ignore unused variables as I have cut a lot of the code):

includes lqer;    

module lqer_M{
 provides {
           interface SplitControl;
           interface AMSend[am_id_t id];
           interface Receive[uint8_t id];

       };

    uses {
        interface SplitControl as AMControl;

        interface Timer<TMilli> as LQERTimer;


        interface Random;
        interface AMPacket;
        interface AMSend as SendPacket;

        interface Receive as ReceivePacket;


            interface PacketAcknowledgements;
         interface Packet;

    }
}
implementation{

        message_t lqer_msg_;
        message_t* p_lqer_msg_;
        lqer_table l_table[LQER_FT_SIZE];

        node_info info;
        uint8_t max=0, Pos=0;
        message_t* newADV;
        bool busy = FALSE;

    command error_t SplitControl.start() {
     int i,j;
     p_lqer_msg_ = &lqer_msg_;
    info.hop=1000;
    for(i=0; i<16; i++){
        info.m[i]=1;
    }

    for(i = 0; i< LQER_FT_SIZE; i++) { 
             l_table[i].nid = INVALID_NODE_ID;
        l_table[i].hop  = 1000;
        for (j=0; j<16; j++)
        {            
            l_table[i].m[j]=1;

        } 
        }

        call AMControl.start();
        return SUCCESS;
    }
    command error_t SplitControl.stop() {
        call AMControl.stop();
        return SUCCESS;
    }    



  event void AMControl.startDone( error_t e ) { 
    if ( e == SUCCESS ) { 
      call LQERTimer.startPeriodic( LQER_DEFAULT_PERIOD ); 
      signal SplitControl.startDone(e); 
    } else { 
      call AMControl.start(); 
    } 
  } 



  event void AMControl.stopDone(error_t e){ 
    call LQERTimer.stop(); 
    signal SplitControl.stopDone(e); 
  }


event void LQERTimer.fired() {
        message_t* lqer_adv_msg;

        lqer_adv_hdr* new_ADV=(lqer_adv_hdr*)(lqer_adv_msg->data);
        am_addr_t me = call AMPacket.address();




        if (me==0001){
            new_ADV->src = me;

            new_ADV->hop = 0;

            newADV= (message_t*)(&new_ADV);

            dbg("GRAPE_DBG", "%s\t LQER: Sink address: %d\n", sim_time_string(), me);
                  call PacketAcknowledgements.requestAck(newADV);
            call SendPacket.send( AM_BROADCAST_ADDR, newADV, call Packet.payloadLength(newADV) );

        }


  } 


event message_t* ReceivePacket.receive( message_t* p_msg, void* payload, uint8_t len ) {


    lqer_adv_hdr* lqer_hdr = (lqer_adv_hdr*)(p_msg->data);
    lqer_adv_hdr* msg_lqer_hdr =(lqer_adv_hdr*)(p_lqer_msg_->data);
    uint8_t i;

    lqer_adv_hdr* new_ADV =(lqer_adv_hdr*)(p_lqer_msg_->data);

    dbg("GRAPE_DBG", "%s\t ADV: RecievedADV dst: \n", sim_time_string());
       msg_lqer_hdr->src = lqer_hdr->src; 
       msg_lqer_hdr->hop = lqer_hdr->hop;


        new_ADV->src = msg_lqer_hdr->src;

        new_ADV->hop = msg_lqer_hdr->hop;

        newADV= (message_t*)(&new_ADV);
        call PacketAcknowledgements.requestAck( newADV );
        call SendPacket.send( AM_BROADCAST_ADDR, newADV, call Packet.payloadLength(newADV) );


    return p_msg; 


}


 command error_t AMSend.cancel[am_id_t id](message_t* msg) { 
    return call SendPacket.cancel(msg); 
  } 


  command uint8_t AMSend.maxPayloadLength[am_id_t id]() { 
    return call Packet.maxPayloadLength(); 
  } 


  command void* AMSend.getPayload[am_id_t id](message_t* m, uint8_t len) { 
    return call Packet.getPayload(m, 0); 
  } 



  default event void AMSend.sendDone[uint8_t id](message_t* msg, error_t err) { 
    return; 
  } 

  default event message_t* Receive.receive[am_id_t id](message_t* msg, void* payload, uint8_t len) { 
    return msg; 
  }
 command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len)
  {


    call SendPacket.send( TOS_BCAST_ADDR , msg, call Packet.payloadLength(msg) );



    return SUCCESS;

  }
  event void SendPacket.sendDone(message_t* p_msg, error_t e) {

    dbg("GRAPE_DBG", "%s\t ADV: SendDone\n", sim_time_string());

        if( p_msg== newADV)
         busy=FALSE;




 } 


} 
1

There are 1 best solutions below

3
On

You should look at what is the error value in the sendDone event. It is possible that send returns success, but the sending fail after that, and the error code is returned in the sendDone. These error includes ENOACK, ENOMEM, etc.

Also, check your destination address and the AM address of the receiver.