/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_collect_process, ev, data) { static struct etimer periodic; static struct etimer et; PROCESS_BEGIN(); collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); if(rimeaddr_node_addr.u8[0] == 1 && rimeaddr_node_addr.u8[1] == 0) { printf("I am sink\n"); collect_set_sink(&tc, 1); } /* Allow some time for the network to settle. */ etimer_set(&et, 120 * CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&et)); while(1) { /* Send a packet every 30 seconds. */ if(etimer_expired(&periodic)) { etimer_set(&periodic, CLOCK_SECOND * 30); etimer_set(&et, random_rand() % (CLOCK_SECOND * 30)); } PROCESS_WAIT_EVENT(); if(etimer_expired(&et)) { static rimeaddr_t oldparent; const rimeaddr_t *parent; printf("Sending\n"); packetbuf_clear(); packetbuf_set_datalen(sprintf(packetbuf_dataptr(), "%s", "Hello") + 1); collect_send(&tc, 15); parent = collect_parent(&tc); if(!rimeaddr_cmp(parent, &oldparent)) { //alten parent ausgeben (falls der nicht null war) if(!rimeaddr_cmp(&oldparent, &rimeaddr_null)) { printf("#L %d 0\n", oldparent.u8[0]); } //neuen parent ausgeben (falls der nicht null ist) if(!rimeaddr_cmp(parent, &rimeaddr_null)) { printf("#L %d 1\n", parent->u8[0]); } //speichern rimeaddr_copy(&oldparent, parent); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_collect_process, ev, data) { PROCESS_BEGIN(); SENSORS_ACTIVATE(button_sensor); collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); if(rimeaddr_node_addr.u8[0] == 1 && rimeaddr_node_addr.u8[1] == 1) { printf("I am sink\n"); collect_set_sink(&tc, 1); } while(1) { static struct etimer et; /* Send a packet every 16 seconds; first wait 8 seconds, than a random time between 0 and 8 seconds. */ etimer_set(&et, CLOCK_SECOND * 16 + random_rand() % (CLOCK_SECOND * 16)); PROCESS_WAIT_EVENT(); if(etimer_expired(&et)) { while(tc.sending) { PROCESS_PAUSE(); } printf("Sending\n"); packetbuf_clear(); packetbuf_set_datalen(sprintf(packetbuf_dataptr(), "%s", "Hello") + 1); collect_send(&tc, 4); } if(ev == sensors_event) { if(data == &button_sensor) { printf("I am sink\n"); collect_set_sink(&tc, 1); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void shell_rime_init(void) { netflood_open(&netflood, CLOCK_SECOND * 8, SHELL_RIME_CHANNEL_NODES, &netflood_callbacks); collect_open(&collect, SHELL_RIME_CHANNEL_COLLECT, &collect_callbacks); shell_register_command(&collect_command); shell_register_command(&mac_command); shell_register_command(&nodes_command); shell_register_command(&packetize_command); shell_register_command(&routes_command); shell_register_command(&send_command); #if WITH_TREEDEPTH shell_register_command(&treedepth_command); #endif /* WITH_TREEDEPTH */ }