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__)
95 send_adv(clock_time_t interval)
97 struct announcement_msg *adata;
104 adata->data[adata->num].id = a->id;
105 adata->data[adata->num].value = a->value;
110 sizeof(
struct announcement_data) * adata->num);
112 PRINTF(
"%d.%d: sending neighbor advertisement with %d announcements\n",
122 adv_packet_received(
struct ipolite_conn *ipolite,
const linkaddr_t *from)
124 struct announcement_msg adata;
125 struct announcement_data data;
132 memcpy(&adata, ptr,
sizeof(
struct announcement_msg));
133 PRINTF(
"%d.%d: adv_packet_received from %d.%d with %d announcements\n",
135 from->u8[0], from->u8[1], adata.num);
137 if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num *
sizeof(
struct announcement_data) >
packetbuf_datalen()) {
140 PRINTF(
"adata.num way out there: %d\n", adata.num);
144 ptr += ANNOUNCEMENT_MSG_HEADERLEN;
145 for(i = 0; i < adata.num; ++i) {
147 memcpy(&data, ptr,
sizeof(
struct announcement_data));
149 ptr +=
sizeof(
struct announcement_data);
154 send_timer(
void *ptr)
156 send_adv(c.interval);
161 c.interval = MIN(c.interval * 2, c.max_interval);
165 new_announcement(uint16_t
id, uint8_t has_value, uint16_t newval,
166 uint16_t oldval, uint8_t bump)
168 if(newval != oldval) {
169 c.interval = c.min_interval;
175 {adv_packet_received,
NULL, NULL};
178 polite_announcement_init(uint16_t channel,
182 ipolite_open(&c.c, channel, NUM_DUPS, &ipolite_callbacks);
184 c.min_interval = min;
185 c.max_interval = max;
191 polite_announcement_stop(
void)
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
void announcement_register_observer_callback(announcement_observer callback)
Register an observer callback with the announcement module.
Representation of an announcement.
Header file for the announcement primitive
void packetbuf_clear(void)
Clear and reset the packetbuf.
Default definitions of C compiler quirk work-arounds.
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.
void ipolite_close(struct ipolite_conn *c)
Close an ipolite connection.
A structure with callback functions for an ipolite connection.
Header file for the Rime stack
#define NULL
The null pointer.
struct announcement * announcement_list(void)
Get the list of registered announcements.
Linked list manipulation routines.
An opaque structure with no user-visible elements that holds the state of an ipolite connection...
Header file for Ipolite best effort local Broadcast (ipolite)
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
void ipolite_open(struct ipolite_conn *c, uint16_t channel, uint8_t dups, const struct ipolite_callbacks *cb)
Open an ipolite connection.
void ctimer_stop(struct ctimer *c)
Stop a pending callback timer.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
int ipolite_send(struct ipolite_conn *c, clock_time_t interval, uint8_t hdrsize)
Send a packet on an ipolite connection.