61 struct announcement_data {
66 #ifdef POLITE_ANNOUNCEMENT_CONF_MAX_DUPS
67 #define NUM_DUPS POLITE_ANNOUNCEMENT_CONF_MAX_DUPS
72 #define ANNOUNCEMENT_MSG_HEADERLEN 2
73 struct announcement_msg {
75 struct announcement_data data[];
79 static struct polite_announcement_state {
82 clock_time_t interval;
83 clock_time_t min_interval, max_interval;
89 #define PRINTF(...) printf(__VA_ARGS__)
94 #define MIN(a, b) ((a)<(b)?(a):(b))
98 send_adv(clock_time_t interval)
100 struct announcement_msg *adata;
107 adata->data[adata->num].id = a->id;
108 adata->data[adata->num].value = a->value;
113 sizeof(
struct announcement_data) * adata->num);
115 PRINTF(
"%d.%d: sending neighbor advertisement with %d announcements\n",
125 adv_packet_received(
struct ipolite_conn *ipolite,
const rimeaddr_t *from)
127 struct announcement_msg adata;
132 PRINTF(
"%d.%d: adv_packet_received from %d.%d with %d announcements\n",
134 from->u8[0], from->u8[1], adata.num);
136 for(i = 0; i < adata.num; ++i) {
137 struct announcement_data data;
142 memcpy(&data.value, &((
struct announcement_msg *)
packetbuf_dataptr())->data[i].value,
151 send_timer(
void *ptr)
153 send_adv(c.interval);
158 c.interval = MIN(c.interval * 2, c.max_interval);
162 new_announcement(uint16_t
id, uint8_t has_value, uint16_t newval,
163 uint16_t oldval, uint8_t bump)
165 if(newval != oldval) {
166 c.interval = c.min_interval;
172 {adv_packet_received,
NULL, NULL};
175 polite_announcement_init(uint16_t channel,
179 ipolite_open(&c.c, channel, NUM_DUPS, &ipolite_callbacks);
181 c.min_interval = min;
182 c.max_interval = max;
188 polite_announcement_stop(
void)