50 #ifdef RUNICAST_CONF_REXMIT_TIME
51 #define REXMIT_TIME RUNICAST_CONF_REXMIT_TIME
53 #define REXMIT_TIME CLOCK_SECOND
56 static const struct packetbuf_attrlist attributes[] =
65 #define PRINTF(...) printf(__VA_ARGS__)
72 sent_by_stunicast(
struct stunicast_conn *stunicast,
int status,
int num_tx)
74 struct runicast_conn *c = (
struct runicast_conn *)stunicast;
76 PRINTF(
"runicast: sent_by_stunicast c->rxmit %d num_tx %d\n",
80 if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) == PACKETBUF_ATTR_PACKET_TYPE_DATA) {
85 RIMESTATS_ADD(rexmit);
86 PRINTF(
"%d.%d: runicast: sent_by_stunicast packet %u (%u) resent %u\n",
88 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID),
91 if(c->rxmit >= c->max_rxmit) {
92 RIMESTATS_ADD(timedout);
94 stunicast_cancel(&c->c);
96 c->u->timedout(c, stunicast_receiver(&c->c), c->rxmit);
99 PRINTF(
"%d.%d: runicast: packet %d timed out\n",
102 c->sndnxt = (c->sndnxt + 1) % (1 << RUNICAST_PACKET_ID_BITS);
113 recv_from_stunicast(
struct stunicast_conn *stunicast,
const linkaddr_t *from)
115 struct runicast_conn *c = (
struct runicast_conn *)stunicast;
118 PRINTF(
"%d.%d: runicast: recv_from_stunicast from %d.%d type %d seqno %d\n",
120 from->u8[0], from->u8[1],
121 packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE),
122 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
124 if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
125 PACKETBUF_ATTR_PACKET_TYPE_ACK) {
126 PRINTF(
"%d.%d: runicast: got ACK from %d.%d, seqno %d (%d)\n",
128 from->u8[0], from->u8[1],
129 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID),
131 if(packetbuf_attr(PACKETBUF_ATTR_PACKET_ID) == c->sndnxt) {
132 RIMESTATS_ADD(ackrx);
133 PRINTF(
"%d.%d: runicast: ACKed %d\n",
135 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
136 c->sndnxt = (c->sndnxt + 1) % (1 << RUNICAST_PACKET_ID_BITS);
138 stunicast_cancel(&c->c);
139 if(c->u->sent !=
NULL) {
140 c->u->sent(c, stunicast_receiver(&c->c), c->rxmit);
143 PRINTF(
"%d.%d: runicast: received bad ACK %d for %d\n",
145 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID),
147 RIMESTATS_ADD(badackrx);
149 }
else if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
150 PACKETBUF_ATTR_PACKET_TYPE_DATA) {
152 uint16_t packet_seqno;
155 RIMESTATS_ADD(reliablerx);
157 PRINTF(
"%d.%d: runicast: got packet %d\n",
159 packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
161 packet_seqno = packetbuf_attr(PACKETBUF_ATTR_PACKET_ID);
165 q = queuebuf_new_from_packetbuf();
167 PRINTF(
"%d.%d: runicast: Sending ACK to %d.%d for %d\n",
169 from->u8[0], from->u8[1],
176 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_ACK);
177 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, packet_seqno);
178 stunicast_send(&c->c, from);
179 RIMESTATS_ADD(acktx);
181 queuebuf_to_packetbuf(q);
184 PRINTF(
"%d.%d: runicast: could not send ACK to %d.%d for %d: no queued buffers\n",
186 from->u8[0], from->u8[1],
189 if(c->u->recv !=
NULL) {
190 c->u->recv(c, from, packet_seqno);
195 static const struct stunicast_callbacks runicast = {recv_from_stunicast,
199 runicast_open(
struct runicast_conn *c, uint16_t channel,
200 const struct runicast_callbacks *u)
202 stunicast_open(&c->c, channel, &runicast);
203 channel_set_attributes(channel, attributes);
211 runicast_close(
struct runicast_conn *c)
213 stunicast_close(&c->c);
217 runicast_is_transmitting(
struct runicast_conn *c)
223 runicast_send(
struct runicast_conn *c,
const linkaddr_t *receiver,
224 uint8_t max_retransmissions)
227 if(runicast_is_transmitting(c)) {
228 PRINTF(
"%d.%d: runicast: already transmitting\n",
232 packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
233 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, PACKETBUF_ATTR_PACKET_TYPE_DATA);
234 packetbuf_set_attr(PACKETBUF_ATTR_PACKET_ID, c->sndnxt);
235 packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, 3);
236 c->max_rxmit = max_retransmissions;
239 RIMESTATS_ADD(reliabletx);
240 PRINTF(
"%d.%d: runicast: sending packet %d\n",
243 ret = stunicast_send_stubborn(&c->c, receiver, REXMIT_TIME);
linkaddr_t linkaddr_node_addr
The Rime address of the node.
#define NULL
The null pointer.
Header file for the Rime stack
Reliable unicast header file
void packetbuf_clear(void)
Clear and reset the packetbuf.