标签:amp entry rtp event orm 事件 app command ror
一、分析内容:
这次主要分析:从上层的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; }
标签:amp entry rtp event orm 事件 app command ror
原文地址:http://www.cnblogs.com/LaowangNext/p/7868624.html