/*---------------------------------------------------------------------------*/ PROCESS_THREAD(start_app, ev, data) { PROCESS_BEGIN(); static int is_coordinator = 0; /* Switch off dongle leds */ /* Initialise ct timer, but don't let it run yet */ ctimer_set(&ct, TOGGLE_TIME, ct_callback, NULL); ctimer_stop(&ct); /* Start net stack */ if(is_coordinator) { uip_ipaddr_t prefix; uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); rpl_tools_init(&prefix); } else { rpl_tools_init(NULL); } printf("Starting RPL node\n"); rest_init_engine(); rest_activate_resource(&resource_led_toggle, "Dongle/LED-toggle"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(start_app, ev, data) { PROCESS_BEGIN(); static int is_coordinator = 0; memset(rx_buf, '\0', sizeof(rx_buf)); /* Define process that handles data */ process_start(&rx_data_process ,NULL); /* Initialise UART1 */ uart1_init(UART1_BAUD_RATE); /* Callback received byte */ uart1_set_input(handleRxChar); /* Start network stack */ if(is_coordinator) { uip_ipaddr_t prefix; uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); rpl_tools_init(&prefix); } else { rpl_tools_init(NULL); } printf("Starting RPL node\n"); rest_init_engine(); rest_activate_resource(&resource_coap_rx_uart1, "UART1-RX"); rest_activate_resource(&resource_coap_tx_uart1, "UART1-TX"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(node_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); /* 3 possible roles: * - role_6ln: simple node, will join any network, secured or not * - role_6dg: DAG root, will advertise (unsecured) beacons * */ static int is_coordinator = 0; static enum { role_6ln, role_6dr } node_role; node_role = role_6ln; #if CONFIG_VIA_BUTTON { #define CONFIG_WAIT_TIME 10 SENSORS_ACTIVATE(button_sensor); etimer_set(&et, CLOCK_SECOND * CONFIG_WAIT_TIME); while(!etimer_expired(&et)) { printf("Init: current role: %s. Will start in %u seconds.\n", node_role == role_6ln ? "6ln" : "6dr", CONFIG_WAIT_TIME); PROCESS_WAIT_EVENT_UNTIL(((ev == sensors_event) && (data == &button_sensor) && button_sensor.value(0) > 0) || etimer_expired(&et)); if(ev == sensors_event && data == &button_sensor && button_sensor.value(0) > 0) { node_role = (node_role + 1) % 2; etimer_restart(&et); } } } #endif /* CONFIG_VIA_BUTTON */ printf("Init: node starting with role %s\n", node_role == role_6ln ? "6ln" : "6dr"); is_coordinator = node_role > role_6ln; if(is_coordinator) { uip_ipaddr_t prefix; uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); rpl_tools_init(&prefix); } else { rpl_tools_init(NULL); } /* Print out routing tables every minute */ etimer_set(&et, CLOCK_SECOND * 60); while(1) { print_network_status(); PROCESS_YIELD_UNTIL(etimer_expired(&et)); etimer_reset(&et); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(border_router_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); /* While waiting for the prefix to be sent through the SLIP connection, the future * border router can join an existing DAG as a parent or child, or acquire a default * router that will later take precedence over the SLIP fallback interface. * Prevent that by turning the radio off until we are initialized as a DAG root. */ prefix_set = 0; PROCESS_PAUSE(); PRINTF("RPL-Border router started\n"); /* Request prefix until it has been received */ while(!prefix_set) { etimer_set(&et, CLOCK_SECOND); request_prefix(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); PRINTF("Waiting for prefix\n"); } PRINTF("Obtained prefix: "); uip_debug_ipaddr_print(&prefix); PRINTF("\n"); rpl_tools_init(&prefix); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(start_app, ev, data) { PROCESS_BEGIN(); static int is_coordinator = 0; /* Start network stack */ if(is_coordinator) { uip_ipaddr_t prefix; uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); rpl_tools_init(&prefix); } else { rpl_tools_init(NULL); } printf("Starting RPL node\n"); rest_init_engine(); rest_activate_resource(&resource_set_tx_power, "Set-TX-Power"); rest_activate_resource(&resource_get_tx_power, "Get-TX-Power"); PROCESS_END(); }