60 struct announcement_data {
65 #ifdef POLITE_ANNOUNCEMENT_CONF_MAX_DUPS
66 #define NUM_DUPS POLITE_ANNOUNCEMENT_CONF_MAX_DUPS
71 #define ANNOUNCEMENT_MSG_HEADERLEN 2
72 struct announcement_msg {
74 struct announcement_data data[];
78 static struct polite_announcement_state {
81 clock_time_t interval;
82 clock_time_t min_interval, max_interval;
88 #define PRINTF(...) printf(__VA_ARGS__)
93 #define MIN(a, b) ((a)<(b)?(a):(b))
97 send_adv(clock_time_t interval)
99 struct announcement_msg *adata;
106 adata->data[adata->num].id = a->id;
107 adata->data[adata->num].value = a->value;
112 sizeof(
struct announcement_data) * adata->num);
114 PRINTF(
"%d.%d: sending neighbor advertisement with %d announcements\n",
124 adv_packet_received(
struct ipolite_conn *ipolite,
const linkaddr_t *from)
126 struct announcement_msg adata;
127 struct announcement_data data;
134 memcpy(&adata, ptr,
sizeof(
struct announcement_msg));
135 PRINTF(
"%d.%d: adv_packet_received from %d.%d with %d announcements\n",
137 from->u8[0], from->u8[1], adata.num);
139 if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num *
sizeof(
struct announcement_data) >
packetbuf_datalen()) {
142 PRINTF(
"adata.num way out there: %d\n", adata.num);
146 ptr += ANNOUNCEMENT_MSG_HEADERLEN;
147 for(i = 0; i < adata.num; ++i) {
149 memcpy(&data, ptr,
sizeof(
struct announcement_data));
151 ptr +=
sizeof(
struct announcement_data);
156 send_timer(
void *ptr)
158 send_adv(c.interval);
163 c.interval = MIN(c.interval * 2, c.max_interval);
167 new_announcement(uint16_t
id, uint8_t has_value, uint16_t newval,
168 uint16_t oldval, uint8_t bump)
170 if(newval != oldval) {
171 c.interval = c.min_interval;
177 {adv_packet_received,
NULL, NULL};
180 polite_announcement_init(uint16_t channel,
184 ipolite_open(&c.c, channel, NUM_DUPS, &ipolite_callbacks);
186 c.min_interval = min;
187 c.max_interval = max;
193 polite_announcement_stop(
void)
A structure with callback functions for an ipolite connection.
Linked list manipulation routines.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
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 ipolite_close(struct ipolite_conn *c)
Close an ipolite connection.
void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t dups, const struct ipolite_callbacks *cb)
Open an ipolite connection.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Header file for Ipolite best effort local Broadcast (ipolite)
An opaque structure with no user-visible elements that holds the state of an ipolite connection...
void packetbuf_clear(void)
Clear and reset the packetbuf.
Representation of an announcement.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int ipolite_send(struct ipolite_conn *c, clock_time_t interval, uint8_t hdrsize)
Send a packet on an ipolite connection.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.