1
如何在recv_uc
函數中打印接收到的數據?在這種情況下是var的值。我使用packetbuf_copyfrom(&var, 5)
將var
放入發送的數據包中。Contiki:使用Rime收到打印數據
PROCESS(sending_rand, "Sending rand");
AUTOSTART_PROCESSES(&sending_rand);
static void
recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
{
printf("unicast message received from %d.%d\nreceived data: %d\n",
from->u8[0], from->u8[1], /* print data received */);
}
static const struct unicast_callbacks unicast_call = {recv_uc};
static struct unicast_conn unicast;
PROCESS_THREAD(sending_rand, ev, data)
{
static struct etimer et;//oggetto di tipo etimer
int var;
PROCESS_EXITHANDLER(unicast_close(&unicast);)
PROCESS_BEGIN();
unicast_open(&unicast, 129, &unicast_call);
while(1) {
/* Delay 2-4 seconds */
etimer_set(&et, CLOCK_SECOND * 4 + random_rand() % (CLOCK_SECOND * 4));
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
var = random_rand();
packetbuf_copyfrom(&var, 5);
addr.u8[0] = 1;
addr.u8[1] = 0;
if(!rimeaddr_cmp(&addr, &rimeaddr_node_addr)) {
unicast_send(&unicast, &addr);
}
printf("unicast message sent\n");
}
PROCESS_END();
}
非常感謝你:-) – vrizz