50 #include "lib/random.h"
60 struct announcement_data {
65 #ifdef BROADCAST_ANNOUNCEMENT_CONF_MAX_DUPS
66 #define NUM_DUPS BROADCAST_ANNOUNCEMENT_CONF_MAX_DUPS
71 #define ANNOUNCEMENT_MSG_HEADERLEN 2
72 struct announcement_msg {
74 struct announcement_data data[];
78 static struct broadcast_announcement_state {
79 struct broadcast_conn c;
80 struct ctimer send_timer, interval_timer;
81 clock_time_t initial_interval, min_interval, max_interval;
82 clock_time_t current_interval;
90 #define PRINTF(...) printf(__VA_ARGS__)
95 #define MIN(a, b) ((a)<(b)?(a):(b))
101 struct announcement_msg *adata;
108 adata->data[adata->num].id = a->id;
109 adata->data[adata->num].value = a->value;
114 sizeof(
struct announcement_data) * adata->num);
116 PRINTF(
"%d.%d: sending neighbor advertisement with %d announcements\n",
123 PRINTF(
"%d.%d: sending neighbor advertisement with val %d\n",
129 adv_packet_received(
struct broadcast_conn *ibc,
const linkaddr_t *from)
131 struct announcement_msg adata;
132 struct announcement_data data;
139 memcpy(&adata, ptr,
sizeof(
struct announcement_msg));
140 PRINTF(
"%d.%d: adv_packet_received from %d.%d with %d announcements\n",
142 from->u8[0], from->u8[1], adata.num);
144 if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num *
sizeof(
struct announcement_data) >
packetbuf_datalen()) {
147 PRINTF(
"adata.num way out there: %d\n", adata.num);
151 ptr += ANNOUNCEMENT_MSG_HEADERLEN;
152 for(i = 0; i < adata.num; ++i) {
154 memcpy(&data, ptr,
sizeof(
struct announcement_data));
156 ptr +=
sizeof(
struct announcement_data);
161 adv_packet_sent(
struct broadcast_conn *bc,
int status,
int num_tx)
165 static void send_timer(
void *ptr);
170 ctimer_set(&c.interval_timer, c.current_interval, send_timer,
NULL);
176 send_timer(
void *ptr)
178 clock_time_t interval;
180 interval = c.current_interval * 2;
182 if(interval > c.max_interval) {
183 interval = c.max_interval;
186 c.current_interval = interval;
194 new_announcement(uint16_t
id, uint8_t has_value,
195 uint16_t newval, uint16_t oldval, uint8_t bump)
197 if(bump == ANNOUNCEMENT_BUMP) {
198 c.current_interval = c.initial_interval;
207 {adv_packet_received, adv_packet_sent };
210 broadcast_announcement_init(uint16_t channel,
211 clock_time_t initial,
216 c.initial_interval = initial;
217 c.min_interval = min;
218 c.max_interval = max;
224 broadcast_announcement_stop(
void)
232 broadcast_announcement_beacon_interval(
void)
234 return c.current_interval;
Linked list manipulation routines.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
#define CC_CONST_FUNCTION
Configure if the C compiler have problems with const function pointers.
void broadcast_close(struct broadcast_conn *c)
Close a broadcast connection.
void announcement_register_observer_callback(announcement_observer callback)
Register an observer callback with the announcement module.
void * list_item_next(void *item)
Get the next item following this item.
void announcement_heard(const linkaddr_t *from, uint16_t id, uint16_t value)
Inform the announcement module of an incoming announcement.
#define NULL
The null pointer.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
Header file for the Rime stack
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
struct announcement * announcement_list(void)
Get the list of registered announcements.
Header file for the announcement primitive
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Callback structure for broadcast.
int broadcast_send(struct broadcast_conn *c)
Send an identified best-effort broadcast packet.
void packetbuf_clear(void)
Clear and reset the packetbuf.
Representation of an announcement.
Header file for identified best-effort local area broadcast
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
void broadcast_open(struct broadcast_conn *c, uint16_t channel, const struct broadcast_callbacks *u)
Set up an identified best-effort broadcast connection.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
unsigned short random_rand(void)
Generate the next state and return the upper part of it.