51 #include "dev/radio-sensor.h"
53 #include "lib/random.h"
55 #if CONTIKI_TARGET_NETSIM
70 #define PRINTF(...) printf(__VA_ARGS__)
79 struct neighbor_discovery_conn *c = ptr;
90 PRINTF(
"%d.%d: sending neighbor advertisement with val %d\n",
96 adv_packet_received(
struct broadcast_conn *ibc,
const rimeaddr_t *from)
98 struct neighbor_discovery_conn *c = (
struct neighbor_discovery_conn *)ibc;
102 memcpy(&val, &msg->val,
sizeof(val));
104 PRINTF(
"%d.%d: adv_packet_received from %d.%d with val %d\n",
106 from->u8[0], from->u8[1], val);
115 c->u->recv(c, from, val);
120 adv_packet_sent(
struct broadcast_conn *bc,
int status,
int num_tx)
124 static void send_timer(
void *ptr);
127 set_timers(
struct neighbor_discovery_conn *c)
129 ctimer_set(&c->interval_timer, c->current_interval, send_timer, c);
130 ctimer_set(&c->send_timer, c->current_interval / 2 + random_rand() %
131 (c->current_interval / 2),
136 send_timer(
void *ptr)
138 struct neighbor_discovery_conn *c = ptr;
139 clock_time_t interval;
141 interval = c->current_interval * 2;
143 if(interval > c->max_interval) {
144 interval = c->max_interval;
147 c->current_interval = interval;
151 PRINTF(
"current_interval %lu\n", (
long unsigned int) interval);
157 {adv_packet_received, adv_packet_sent };
160 neighbor_discovery_open(
struct neighbor_discovery_conn *c, uint16_t channel,
161 clock_time_t initial,
164 const struct neighbor_discovery_callbacks *cb)
166 PRINTF(
"%d.%d: neighbor discovery open channel %d\n",
171 c->initial_interval = initial;
172 c->min_interval = min;
173 c->max_interval = max;
177 neighbor_discovery_close(
struct neighbor_discovery_conn *c)
185 neighbor_discovery_set_val(
struct neighbor_discovery_conn *c, uint16_t val)
191 neighbor_discovery_start(
struct neighbor_discovery_conn *c, uint16_t val)
193 c->current_interval = c->initial_interval;