diff --git a/examples/ipv6/simple-udp-rpl/broadcast-example.c b/examples/ipv6/simple-udp-rpl/broadcast-example.c index 575adf1ab..ea3e151a7 100644 --- a/examples/ipv6/simple-udp-rpl/broadcast-example.c +++ b/examples/ipv6/simple-udp-rpl/broadcast-example.c @@ -13,7 +13,7 @@ #define UDP_PORT 1234 -#define SEND_INTERVAL (10 * CLOCK_SECOND) +#define SEND_INTERVAL (20 * CLOCK_SECOND) #define SEND_TIME (random_rand() % (SEND_INTERVAL)) static struct simple_udp_connection broadcast_connection; @@ -39,6 +39,7 @@ PROCESS_THREAD(broadcast_example_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; + uip_ipaddr_t addr; PROCESS_BEGIN(); @@ -48,18 +49,14 @@ PROCESS_THREAD(broadcast_example_process, ev, data) etimer_set(&periodic_timer, SEND_INTERVAL); while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + etimer_reset(&periodic_timer); + etimer_set(&send_timer, SEND_TIME); - PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER); - if(data == &periodic_timer) { - etimer_reset(&periodic_timer); - etimer_set(&send_timer, SEND_TIME); - } - if(data == &send_timer) { - uip_ipaddr_t addr; - printf("Sending broadcast\n"); - uip_create_linklocal_allnodes_mcast(&addr); - simple_udp_sendto(&broadcast_connection, "hej\n", 4, &addr); - } + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); + printf("Sending broadcast\n"); + uip_create_linklocal_allnodes_mcast(&addr); + simple_udp_sendto(&broadcast_connection, "Test", 4, &addr); } PROCESS_END(); diff --git a/examples/ipv6/simple-udp-rpl/unicast-sender.c b/examples/ipv6/simple-udp-rpl/unicast-sender.c index e8ebadaa8..6ca3b33be 100644 --- a/examples/ipv6/simple-udp-rpl/unicast-sender.c +++ b/examples/ipv6/simple-udp-rpl/unicast-sender.c @@ -65,6 +65,7 @@ PROCESS_THREAD(unicast_sender_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; + uip_ipaddr_t *addr; PROCESS_BEGIN(); @@ -78,25 +79,22 @@ PROCESS_THREAD(unicast_sender_process, ev, data) etimer_set(&periodic_timer, SEND_INTERVAL); while(1) { - PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER); - if(data == &periodic_timer) { - etimer_reset(&periodic_timer); - etimer_set(&send_timer, SEND_TIME); - } - if(data == &send_timer) { - uip_ipaddr_t *addr; - addr = servreg_hack_lookup(SERVICE_ID); - if(addr != NULL) { - char buf[20]; + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + etimer_reset(&periodic_timer); + etimer_set(&send_timer, SEND_TIME); - printf("Sending unicast to "); - uip_debug_ipaddr_print(addr); - printf("\n"); - sprintf(buf, "From %d", node_id); - simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr); - } else { - printf("Service %d not found\n", SERVICE_ID); - } + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); + addr = servreg_hack_lookup(SERVICE_ID); + if(addr != NULL) { + char buf[20]; + + printf("Sending unicast to "); + uip_debug_ipaddr_print(addr); + printf("\n"); + sprintf(buf, "From %d", node_id); + simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr); + } else { + printf("Service %d not found\n", SERVICE_ID); } }