41 #include "net/neighbor-attr.h"
46 #define PRINTF(...) printf(__VA_ARGS__)
51 static uint16_t timeout = 0;
59 neighbor_addr_get(
const rimeaddr_t *addr)
64 if(memb_inmemb(&neighbor_addr_mem, (
char *)addr)) {
80 neighbor_attr_list_neighbors(
void)
88 if(attr->default_value !=
NULL) {
89 memcpy((
char *)attr->data + index * attr->size,
90 attr->default_value, attr->size);
93 memset((
char *)attr->data + index * attr->size, 0, attr->size);
105 for(addr =
list_head(neighbor_addrs); addr !=
NULL; addr = addr->next) {
106 set_attr(def, addr->index);
112 neighbor_attr_has_neighbor(
const rimeaddr_t *addr)
114 return neighbor_addr_get(addr) !=
NULL;
118 neighbor_attr_add_neighbor(
const rimeaddr_t *addr)
125 if(neighbor_attr_has_neighbor(addr)) {
140 ptr = neighbor_addr_mem.mem;
141 for(i = 0; i < neighbor_addr_mem.num; ++i) {
142 if(&ptr[i] == item) {
149 for(def =
list_head(neighbor_attrs); def !=
NULL; def = def->next) {
157 neighbor_attr_remove_neighbor(
const rimeaddr_t *addr)
170 neighbor_attr_get_data(
struct neighbor_attr *def,
const rimeaddr_t *addr)
175 return (
char *)def->data + attr->index * def->size;
181 neighbor_attr_set_data(
struct neighbor_attr *def,
const rimeaddr_t *addr,
187 if(neighbor_attr_add_neighbor(addr)) {
188 attr = neighbor_addr_get(addr);
193 memcpy((
char *)def->data + attr->index * def->size, data, def->size);
200 neighbor_attr_tick(
const rimeaddr_t * addr)
210 neighbor_attr_get_timeout(
void)
215 static struct ctimer ct;
217 #define TIMEOUT_SECONDS 5
219 timeout_check(
void *ptr)
224 while(item !=
NULL) {
225 item->time += TIMEOUT_SECONDS;
226 if(item->time >= timeout) {
241 neighbor_attr_set_timeout(uint16_t time)
243 if(timeout == 0 && time > 0) {
245 }
else if(timeout > 0 && time == 0) {