51 #include "lib/random.h"
62 struct announcement_data {
67 #ifdef BROADCAST_ANNOUNCEMENT_CONF_MAX_DUPS
68 #define NUM_DUPS BROADCAST_ANNOUNCEMENT_CONF_MAX_DUPS
73 #define ANNOUNCEMENT_MSG_HEADERLEN 2
74 struct announcement_msg {
76 struct announcement_data data[];
80 static struct broadcast_announcement_state {
81 struct broadcast_conn c;
82 struct ctimer send_timer, interval_timer;
83 clock_time_t initial_interval, min_interval, max_interval;
84 clock_time_t current_interval;
92 #define PRINTF(...) printf(__VA_ARGS__)
97 #define MIN(a, b) ((a)<(b)?(a):(b))
103 struct announcement_msg *adata;
110 adata->data[adata->num].id = a->id;
111 adata->data[adata->num].value = a->value;
116 sizeof(
struct announcement_data) * adata->num);
118 PRINTF(
"%d.%d: sending neighbor advertisement with %d announcements\n",
125 PRINTF(
"%d.%d: sending neighbor advertisement with val %d\n",
131 adv_packet_received(
struct broadcast_conn *ibc,
const rimeaddr_t *from)
133 struct announcement_msg adata;
138 PRINTF(
"%d.%d: adv_packet_received from %d.%d with %d announcements\n",
140 from->u8[0], from->u8[1], adata.num);
142 if(adata.num /
sizeof(
struct announcement_data) >
sizeof(
struct announcement_msg)) {
145 printf(
"adata.num way out there: %d\n", adata.num);
149 for(i = 0; i < adata.num; ++i) {
150 struct announcement_data data;
155 memcpy(&data.value, &((
struct announcement_msg *)
packetbuf_dataptr())->data[i].value,
164 adv_packet_sent(
struct broadcast_conn *bc,
int status,
int num_tx)
168 static void send_timer(
void *ptr);
173 ctimer_set(&c.interval_timer, c.current_interval, send_timer,
NULL);
174 ctimer_set(&c.send_timer, random_rand() % c.current_interval,
179 send_timer(
void *ptr)
181 clock_time_t interval;
183 interval = c.current_interval * 2;
185 if(interval > c.max_interval) {
186 interval = c.max_interval;
189 c.current_interval = interval;
197 new_announcement(uint16_t
id, uint8_t has_value,
198 uint16_t newval, uint16_t oldval, uint8_t bump)
200 if(bump == ANNOUNCEMENT_BUMP) {
201 c.current_interval = c.initial_interval;
210 {adv_packet_received, adv_packet_sent };
213 broadcast_announcement_init(uint16_t channel,
214 clock_time_t initial,
219 c.initial_interval = initial;
220 c.min_interval = min;
221 c.max_interval = max;
227 broadcast_announcement_stop(
void)
235 broadcast_announcement_beacon_interval(
void)
237 return c.current_interval;