/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); dtls_init(); init_dtls(); print_local_addresses(); if (!dtls_context) { dtls_emerg("cannot create context\n"); PROCESS_EXIT(); } #ifdef ENABLE_POWERTRACE powertrace_start(CLOCK_SECOND * 2); #endif while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { dtls_handle_read(dtls_context); } } PROCESS_END(); }
PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); powertrace_start(CLOCK_SECOND * 2); PRINTF("Hello World!\n"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; PROCESS_BEGIN(); PROCESS_PAUSE(); powertrace_start(CLOCK_SECOND * 2); PRINTF("UDP client process started\n"); /*create new connection with remote server*/ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); if(client_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u \n", UIP_HTONS(client_conn->lport),UIP_HTONS(client_conn->rport)); etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } if(etimer_expired(&periodic)){ etimer_reset(&periodic); ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; #if WITH_COMPOWER static int print = 0; #endif PROCESS_BEGIN(); powertrace_start(CLOCK_SECOND * 30); //elnaz cc2420_set_txpower(31); printf(" Tx=%d\n", cc2420_get_txpower()); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); if(client_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); #if WITH_COMPOWER powertrace_sniff(POWERTRACE_ON); #endif etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } if(etimer_expired(&periodic)) { etimer_reset(&periodic); ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); #if WITH_COMPOWER if (print == 0) { powertrace_print("#P"); } if (++print == 3) { print = 0; } #endif } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; //static struct etimer wait; //static int tx[] = { 31, 27, 23, 19, 15, 11, 7, 3}; #if WITH_COMPOWER static int print = 0; #endif PROCESS_BEGIN(); powertrace_start(CLOCK_SECOND * 1); //elnaz cc2420_set_txpower(23); printf(" Probe v\n Tx=%d\n", cc2420_get_txpower()); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); if(client_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); #if WITH_COMPOWER powertrace_sniff(POWERTRACE_ON); #endif // etimer_set(&temp, 60*CLOCK_SECOND); // PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); etimer_set(&periodic, SEND_INTERVAL); while(1)//seq<150) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } if(etimer_expired(&periodic)) { etimer_reset(&periodic); ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); } //end etimer_expired } 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_6dr: DAG root, will advertise (unsecured) beacons * - role_6dr_sec: DAG root, will advertise secured beacons * */ static int is_coordinator = 0; static enum { role_6ln, role_6dr, role_6dr_sec } node_role; node_role = role_6ln; /* Set node with ID == 1 as coordinator, convenient in Cooja. */ if(node_id == 1) { if(LLSEC802154_ENABLED) { node_role = role_6dr_sec; } else { node_role = role_6dr; } } else { node_role = role_6ln; } #if CONFIG_VIA_BUTTON { #define CONFIG_WAIT_TIME 5 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. Press user button to toggle mode.\n", node_role == role_6ln ? "6ln" : (node_role == role_6dr) ? "6dr" : "6dr-sec", 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) % 3; if(LLSEC802154_ENABLED == 0 && node_role == role_6dr_sec) { node_role = (node_role + 1) % 3; } etimer_restart(&et); } } } #endif /* CONFIG_VIA_BUTTON */ printf("Init: node starting with role %s\n", node_role == role_6ln ? "6ln" : (node_role == role_6dr) ? "6dr" : "6dr-sec"); tsch_set_pan_secured(LLSEC802154_ENABLED && (node_role == role_6dr_sec)); is_coordinator = node_role > role_6ln; if(is_coordinator) { uip_ipaddr_t prefix; uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); net_init(&prefix); } else { net_init(NULL); } #if WITH_ORCHESTRA orchestra_init(); #endif /* WITH_ORCHESTRA */ #ifdef WITH_POWERTRACE powertrace_start(CLOCK_SECOND * 10); #endif /* Print out routing tables every minute */ etimer_set(&et, CLOCK_SECOND * 60); //etimer_set(&et, CLOCK_SECOND * 10); while(1) { print_network_status(); /*Print tsch schedule*/ tsch_schedule_print(); PROCESS_YIELD_UNTIL(etimer_expired(&et)); etimer_reset(&et); } PROCESS_END(); }