Added the MAC layer callback functionality so that the Rime network layer gets information from the MAC about the status of sent packets: were they successfully transmitted, or was there a collisions? How many retries were there?

This commit is contained in:
adamdunkels 2010-02-23 18:38:05 +00:00
parent f10eedab3e
commit ca0417a923
11 changed files with 126 additions and 44 deletions

View file

@ -36,7 +36,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: abc.c,v 1.19 2009/03/12 21:58:20 adamdunkels Exp $
* $Id: abc.c,v 1.20 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -83,7 +83,7 @@ abc_send(struct abc_conn *c)
PRINTF("%d.%d: abc: abc_send on channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channel.channelno);
return chameleon_output(&c->channel);
return rime_output(&c->channel);
}
/*---------------------------------------------------------------------------*/
void
@ -97,5 +97,18 @@ abc_input(struct channel *channel)
c->u->recv(c);
}
/*---------------------------------------------------------------------------*/
void
abc_sent(struct channel *channel, int status, int num_tx)
{
struct abc_conn *c = (struct abc_conn *)channel;
PRINTF("%d.%d: abc: abc_sent on channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
channel->channelno);
if(c->u->sent) {
c->u->sent(c, status, num_tx);
}
}
/*---------------------------------------------------------------------------*/
/** @} */

View file

@ -46,7 +46,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: abc.h,v 1.15 2009/03/12 21:58:20 adamdunkels Exp $
* $Id: abc.h,v 1.16 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
* \file
@ -72,6 +72,7 @@ struct abc_conn;
struct abc_callbacks {
/** Called when a packet has been received by the abc module. */
void (* recv)(struct abc_conn *ptr);
void (* sent)(struct abc_conn *ptr, int status, int num_tx);
};
struct abc_conn {
@ -133,8 +134,10 @@ int abc_send(struct abc_conn *c);
* directly.
*
*/
void abc_input(struct channel *channel);
void abc_sent(struct channel *channel, int status, int num_tx);
#endif /* __ABC_H__ */
/** @} */

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: broadcast.c,v 1.2 2009/03/12 21:58:20 adamdunkels Exp $
* $Id: broadcast.c,v 1.3 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -74,7 +74,22 @@ recv_from_abc(struct abc_conn *bc)
c->u->recv(c, &sender);
}
/*---------------------------------------------------------------------------*/
static const struct abc_callbacks broadcast = {recv_from_abc};
static void
sent_by_abc(struct abc_conn *bc, int status, int num_tx)
{
struct broadcast_conn *c = (struct broadcast_conn *)bc;
PRINTF("%d.%d: sent to %d.%d status %d num_tx %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
packetbuf_addr(PACKETBUF_ADDR_SENDER)->u8[0],
packetbuf_addr(PACKETBUF_ADDR_SENDER)->u8[1],
status, num_tx);
if(c->u->sent) {
c->u->sent(c, status, num_tx);
}
}
/*---------------------------------------------------------------------------*/
static const struct abc_callbacks broadcast = {recv_from_abc, sent_by_abc};
/*---------------------------------------------------------------------------*/
void
broadcast_open(struct broadcast_conn *c, uint16_t channel,

View file

@ -53,7 +53,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: broadcast.h,v 1.4 2009/11/08 19:40:17 adamdunkels Exp $
* $Id: broadcast.h,v 1.5 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -81,6 +81,7 @@ struct broadcast_conn;
struct broadcast_callbacks {
/** Called when a packet has been received by the broadcast module. */
void (* recv)(struct broadcast_conn *ptr, const rimeaddr_t *sender);
void (* sent)(struct broadcast_conn *ptr, int status, int num_tx);
};
struct broadcast_conn {

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: ipolite.c,v 1.16 2010/01/25 13:54:06 adamdunkels Exp $
* $Id: ipolite.c,v 1.17 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -90,6 +90,12 @@ recv(struct broadcast_conn *broadcast, const rimeaddr_t *from)
if(c->cb->recv) {
c->cb->recv(c, from);
}
}
/*---------------------------------------------------------------------------*/
static void
sent(struct broadcast_conn *bc, int status, int num_tx)
{
}
/*---------------------------------------------------------------------------*/
static void
@ -112,7 +118,7 @@ send(void *ptr)
}
}
/*---------------------------------------------------------------------------*/
static const struct broadcast_callbacks broadcast = { recv };
static const struct broadcast_callbacks broadcast = { recv, sent };
/*---------------------------------------------------------------------------*/
void
ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t dups,

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: polite.c,v 1.9 2009/03/12 21:58:21 adamdunkels Exp $
* $Id: polite.c,v 1.10 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -79,6 +79,12 @@ recv(struct abc_conn *abc)
if(c->cb->recv) {
c->cb->recv(c);
}
}
/*---------------------------------------------------------------------------*/
static void
sent(struct abc_conn *c, int status, int num_tx)
{
}
/*---------------------------------------------------------------------------*/
static void
@ -97,7 +103,7 @@ send(void *ptr)
}
}
/*---------------------------------------------------------------------------*/
static const struct abc_callbacks abc = { recv };
static const struct abc_callbacks abc = { recv, sent };
/*---------------------------------------------------------------------------*/
void
polite_open(struct polite_conn *c, uint16_t channel,

View file

@ -34,7 +34,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: runicast.c,v 1.9 2010/01/26 10:19:26 adamdunkels Exp $
* $Id: runicast.c,v 1.10 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -73,18 +73,24 @@ static const struct packetbuf_attrlist attributes[] =
/*---------------------------------------------------------------------------*/
static void
sent_by_stunicast(struct stunicast_conn *stunicast)
sent_by_stunicast(struct stunicast_conn *stunicast, int status, int num_tx)
{
struct runicast_conn *c = (struct runicast_conn *)stunicast;
PRINTF("runicast: sent_by_stunicast c->rxmit %d num_tx %d\n",
c->rxmit, num_tx);
/* Only process data packets, not ACKs. */
if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == PACKETBUF_ATTR_PACKET_TYPE_DATA) {
c->rxmit += num_tx;
if(c->rxmit != 0) {
RIMESTATS_ADD(rexmit);
PRINTF("%d.%d: runicast: packet %u resent %u\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
packetbuf_attr(PACKETBUF_ATTR_PACKET_ID), c->rxmit);
}
c->rxmit++;
if(c->rxmit >= c->max_rxmit) {
RIMESTATS_ADD(timedout);
c->is_tx = 0;
@ -92,6 +98,7 @@ sent_by_stunicast(struct stunicast_conn *stunicast)
if(c->u->timedout) {
c->u->timedout(c, stunicast_receiver(&c->c), c->rxmit);
}
c->rxmit = 0;
PRINTF("%d.%d: runicast: packet %d timed out\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->sndnxt);
@ -101,6 +108,7 @@ sent_by_stunicast(struct stunicast_conn *stunicast)
shift = c->rxmit > 4? 4: c->rxmit;
stunicast_set_timer(&c->c, (REXMIT_TIME) << shift);
}
}
}
/*---------------------------------------------------------------------------*/
static void

View file

@ -33,7 +33,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: stunicast.c,v 1.3 2009/11/08 19:40:18 adamdunkels Exp $
* $Id: stunicast.c,v 1.4 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -68,7 +68,20 @@ recv_from_uc(struct unicast_conn *uc, const rimeaddr_t *from)
}
}
/*---------------------------------------------------------------------------*/
static const struct unicast_callbacks stunicast = {recv_from_uc};
static void
sent_by_uc(struct unicast_conn *uc, int status, int num_tx)
{
register struct stunicast_conn *c = (struct stunicast_conn *)uc;
PRINTF("%d.%d: stunicast: recv_from_uc from %d.%d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
from->u8[0], from->u8[1]);
if(c->u->sent != NULL) {
c->u->sent(c, status, num_tx);
}
}
/*---------------------------------------------------------------------------*/
static const struct unicast_callbacks stunicast = {recv_from_uc,
sent_by_uc};
/*---------------------------------------------------------------------------*/
void
stunicast_open(struct stunicast_conn *c, uint16_t channel,
@ -105,9 +118,9 @@ send(void *ptr)
queuebuf_to_packetbuf(c->buf);
unicast_send(&c->c, &c->receiver);
stunicast_set_timer(c, CLOCK_SECOND);
if(c->u->sent != NULL) {
/* if(c->u->sent != NULL) {
c->u->sent(c);
}
}*/
}
/*---------------------------------------------------------------------------*/
void
@ -134,9 +147,9 @@ stunicast_send_stubborn(struct stunicast_conn *c, const rimeaddr_t *receiver,
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->receiver.u8[0],c->receiver.u8[1]);
unicast_send(&c->c, &c->receiver);
if(c->u->sent != NULL) {
/* if(c->u->sent != NULL) {
c->u->sent(c);
}
}*/
return 1;

View file

@ -60,7 +60,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: stunicast.h,v 1.4 2009/11/08 19:40:18 adamdunkels Exp $
* $Id: stunicast.h,v 1.5 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -83,7 +83,7 @@ struct stunicast_conn;
struct stunicast_callbacks {
void (* recv)(struct stunicast_conn *c, const rimeaddr_t *from);
void (* sent)(struct stunicast_conn *c);
void (* sent)(struct stunicast_conn *c, int status, int num_tx);
};
struct stunicast_conn {

View file

@ -34,7 +34,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: unicast.c,v 1.3 2009/11/08 19:40:18 adamdunkels Exp $
* $Id: unicast.c,v 1.4 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -77,7 +77,23 @@ recv_from_broadcast(struct broadcast_conn *broadcast, const rimeaddr_t *from)
}
}
/*---------------------------------------------------------------------------*/
static const struct broadcast_callbacks uc = {recv_from_broadcast};
static void
sent_by_broadcast(struct broadcast_conn *broadcast, int status, int num_tx)
{
struct unicast_conn *c = (struct unicast_conn *)broadcast;
PRINTF("%d.%d: uc: recv_from_broadcast, receiver %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[0],
packetbuf_addr(PACKETBUF_ADDR_RECEIVER)->u8[1]);
if(c->u->sent) {
c->u->sent(c, status, num_tx);
}
}
/*---------------------------------------------------------------------------*/
static const struct broadcast_callbacks uc = {recv_from_broadcast,
sent_by_broadcast};
/*---------------------------------------------------------------------------*/
void
unicast_open(struct unicast_conn *c, uint16_t channel,

View file

@ -50,7 +50,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: unicast.h,v 1.5 2009/11/08 19:40:18 adamdunkels Exp $
* $Id: unicast.h,v 1.6 2010/02/23 18:38:05 adamdunkels Exp $
*/
/**
@ -72,6 +72,7 @@ struct unicast_conn;
struct unicast_callbacks {
void (* recv)(struct unicast_conn *c, const rimeaddr_t *from);
void (* sent)(struct unicast_conn *ptr, int status, int num_tx);
};
struct unicast_conn {