其实我不知道如何处理neighbor_recv函数。我没有收到任何数据包,就像在广播示例中收到的那样。此代码中使用的所有值都是随机初始化的。而且我想存储每个节点的邻居。目前我有3个telosb节目。
#include "contiki.h"
#include "net/rime/rime.h"
#include "random.h"
#include "node-id.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
struct adv_msg {
uint16_t val;
};
/*------------------------------------------------------------------------ ---*/
PROCESS(neighbor_process, "Neighbor example");
AUTOSTART_PROCESSES(&neighbor_process);
/*------------------------------------------------------------------------ ---*/
static void
neighbor_recv(struct neighbor_discovery_conn *c, const linkaddr_t *from)
{
printf("message received from %d.%d: '%s'\n",
from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
}
static const struct neighbor_discovery_callbacks cb ={neighbor_recv};
static struct neighbor_discovery_conn neighbor;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(neighbor_process, ev, data)
{
static struct etimer et;
clock_time_t initial=0;// randomly initialize these values
clock_time_t min=0;
clock_time_t max=10;
uint16_t val=108;
PROCESS_EXITHANDLER(neighbor_discovery_close(&neighbor));
PROCESS_BEGIN();
neighbor_discovery_open(&neighbor, 129,initial,min,max,&cb);
while(1) {
/* Delay 2-4 seconds */
etimer_set(&et, CLOCK_SECOND * 4 + random_rand() % (CLOCK_SECOND * 4));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
packetbuf_copyfrom("Hello", 5);
neighbor_discovery_set_val(&neighbor,val);
neighbor_discovery_start(&neighbor,val);
printf("message sent\n");
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/