初级会员
- 积分
- 69
- 金钱
- 69
- 注册时间
- 2021-11-14
- 在线时间
- 9 小时
|
有大佬知道图片里的send_packet函数是如何调用transmit_packet_list函数的么,我看了半天send_packet函数没看到在哪调用的??代码如下
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
{
struct rdc_buf_list *q;
struct neighbor_queue *n;
static uint16_t seqno;
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
/* If the packet is a broadcast, do not allocate a queue
entry. Instead, just send it out. */
if(!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
&rimeaddr_null)) {
const rimeaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
/* Look for the neighbor entry */
n = neighbor_queue_from_addr(addr);
if(n == NULL) {
/* Allocate a new neighbor entry */
n = memb_alloc(&neighbor_memb);
if(n != NULL) {
/* Init neighbor entry */
rimeaddr_copy(&n->addr, addr);
n->transmissions = 0;
n->collisions = 0;
n->deferrals = 0;
/* Init packet list for this neighbor */
LIST_STRUCT_INIT(n, queued_packet_list);
/* Add neighbor to the list */
list_add(neighbor_list, n);
}
}
if(n != NULL) {
/* Add packet to the neighbor's queue */
q = memb_alloc(&packet_memb); if(q != NULL) {
q->ptr = memb_alloc(&metadata_memb);
if(q->ptr != NULL) {
q->buf = queuebuf_new_from_packetbuf();
if(q->buf != NULL) {
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
/* Neighbor and packet successfully allocated */
if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
/* Use default configuration for max transmissions */
metadata->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
} else {
metadata->max_transmissions =
packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
}
metadata->sent = sent;
metadata->cptr = ptr;
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
PACKETBUF_ATTR_PACKET_TYPE_ACK) {
// list_init(n->queued_packet_list);
list_push(n->queued_packet_list, q);
} else {
// list_init(n->queued_packet_list);
list_add(n->queued_packet_list, q);
}
/* If q is the first packet in the neighbor's queue, send asap */
if(list_head(n->queued_packet_list) == q) {
ctimer_set(&n->transmit_timer, 0, transmit_packet_list, n);//
}
return;
// transmit_packet_list(ptr);
}
memb_free(&metadata_memb, q->ptr);
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
}
memb_free(&packet_memb, q);
PRINTF("csma: could not allocate queuebuf, dropping packet\n");
}
/* The packet allocation failed. Remove and free neighbor entry if empty. */
if(list_length(n->queued_packet_list) == 0) {
list_remove(neighbor_list, n);
memb_free(&neighbor_memb, n);
}
PRINTF("csma: could not allocate packet, dropping packet\n");
} else {
PRINTF("csma: could not allocate neighbor, dropping packet\n");
}
mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1);
} else {
PRINTF("csma: send broadcast\n");
NETSTACK_RDC.send(sent, ptr);
}
}
/*---------------------------------------------------------------------------*/
static void
transmit_packet_list(void *ptr)
{
struct neighbor_queue *n = ptr;
if(n) {
struct rdc_buf_list *q = list_head(n->queued_packet_list);
if(q != NULL) {
PRINTF("csma: preparing number %d %p, queue len %d\n", n->transmissions, q,
list_length(n->queued_packet_list));
/* Send packets in the neighbor's list */
NETSTACK_RDC.send_list(packet_sent, n, q);
}
}
}
/*---------------------------------------------------------------------------*/
|
-
|