首页 > 系统服务 > 详细

Upma Xmac 测试 03

时间:2017-11-21 00:53:09      阅读:333      评论:0      收藏:0      [点我收藏+]

一、分析内容:

   这次主要分析:从上层的AMSender.send发送packet到Xmac将packet发送出去的流程。

二、

  找到upma/apps/tests/TestXmac/SendingC$SendTimer$startPeriodic事件,代码如下:  

    event void SendTimer.fired()
    {
        if(sends)
        {
            call Leds.led2On();
            call AMSender.send(AM_BROADCAST_ADDR, &packet, 2 * sizeof(uint8_t));        
        }
    }

  call AMSender.send(AM_BROADCAST_ADDR, &packet, 2 * sizeof(uint8_t));的实现代码如下(/opt/tinyos-2.1.2/tos/system/AMQueueEntryP.nc文件):

  command error_t AMSend.send(am_addr_t dest,
                  message_t* msg,
                  uint8_t len) {
    // printf("AMSend.send!!!\r\n");
    call AMPacket.setDestination(msg, dest);        //设置packet的目的地址
    call AMPacket.setType(msg, amId);              //设置packet的类型
    return call Send.send(msg, len);             //发送packet
  }

   call Send.send(msg, len);的实现代码如下:(/opt/tinyos-2.1.2/tos/system/AMQueueImplP.nc)

    

/**
     * Accepts a properly formatted AM packet for later sending.
     * Assumes that someone has filled in the AM packet fields
     * (destination, AM type).
     *
     * @param msg - the message to send
     * @param len - the length of the payload
     *
     */
    command error_t Send.send[uint8_t clientId](message_t* msg,
                                                uint8_t len) {

    printf("Send.send!!!\r\n");
        if (clientId >= numClients) {
            return FAIL;
        }
        if (queue[clientId].msg != NULL) {
            return EBUSY;
        }
        dbg("AMQueue", "AMQueue: request to send from %hhu (%p): passed checks\n", clientId, msg);
        
        queue[clientId].msg = msg;
        call Packet.setPayloadLength(msg, len);
    
        if (current >= numClients) { // queue empty
            error_t err;
            am_id_t amId = call AMPacket.type(msg);
            am_addr_t dest = call AMPacket.destination(msg);
      
            dbg("AMQueue", "%s: request to send from %hhu (%p): queue empty\n", __FUNCTION__, clientId, msg);
            current = clientId;
            
            err = call AMSend.send[amId](dest, msg, len);
            if (err != SUCCESS) {
                dbg("AMQueue", "%s: underlying send failed.\n", __FUNCTION__);
                current = numClients;
                queue[clientId].msg = NULL;
                
            }
            return err;
        }
        else {
            dbg("AMQueue", "AMQueue: request to send from %hhu (%p): queue not empty\n", clientId, msg);
        }
        return SUCCESS;
    }

 

 

Upma Xmac 测试 03

原文:http://www.cnblogs.com/LaowangNext/p/7868624.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!