未收到TinyOS定期Bcast AMSend

时间:2012-06-04 04:31:34

标签: objective-c broadcasting transmission tinyos

我想通过此程序定期发送消息,消息被广播好,我收到sendDone消息。问题是这些消息收不好。我真的很感激帮助找出问题所在?

这是代码(请忽略未使用的变量,因为我已经删除了很多代码):

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 个答案:

答案 0 :(得分:0)

您应该查看sendDone事件中的错误值。 send可能会返回成功,但之后发送失败,并在sendDone中返回错误代码。这些错误包括ENOACK,ENOMEM等。

另外,请检查目的地地址和接收方的AM地址。