Fix udp-client example, now using NETSTACK_ROUTING

This commit is contained in:
Simon Duquennoy 2017-12-10 12:17:42 -08:00
parent 5f4ad6d657
commit 0fc93b6d37

View File

@ -45,6 +45,7 @@ PROCESS_THREAD(udp_client_process, ev, data)
{
static struct etimer periodic_timer;
static unsigned count;
uip_ipaddr_t dest_ipaddr;
PROCESS_BEGIN();
@ -56,25 +57,21 @@ PROCESS_THREAD(udp_client_process, ev, data)
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
if(rpl_is_reachable()) {
if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) {
/* Send to DAG root */
rpl_dag_t *dag = rpl_get_any_dag();
if(dag != NULL) { /* Only a sanity check. Should never be NULL
as rpl_is_reachable() is true */
LOG_INFO("Sending request %u to ", count);
LOG_INFO_6ADDR(&dag->dag_id);
LOG_INFO_("\n");
/* Set the number of transmissions to use for this packet -
this can be used to create more reliable transmissions or
less reliable than the default. Works end-to-end if
UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1.
*/
uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5);
simple_udp_sendto(&udp_conn, &count, sizeof(count), &dag->dag_id);
count++;
}
LOG_INFO("Sending request %u to ", count);
LOG_INFO_6ADDR(&dest_ipaddr);
LOG_INFO_("\n");
/* Set the number of transmissions to use for this packet -
this can be used to create more reliable transmissions or
less reliable than the default. Works end-to-end if
UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1.
*/
uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5);
simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr);
count++;
} else {
LOG_INFO("Not reachable yet %p\n", rpl_get_any_dag());
LOG_INFO("Not reachable yet\n");
}
/* Add some jitter */