/*-------------------------------------------------------------------*/ PROCESS_THREAD(blink_leds_proc, ev, data) { static struct etimer timer1; static struct etimer timer2; static struct etimer timer3; PROCESS_BEGIN(); etimer_set(&timer1, INTERVAL1); etimer_set(&timer2, INTERVAL2); etimer_set(&timer3, INTERVAL3); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER && data == &timer1) { etimer_reset(&timer1); leds_toggle(LEDS_RED); } else if(ev == PROCESS_EVENT_TIMER && data == &timer2) { etimer_reset(&timer2); leds_toggle(LEDS_GREEN); } else if(ev == PROCESS_EVENT_TIMER && data == &timer3) { etimer_reset(&timer3); leds_toggle(LEDS_YELLOW); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(receiver_node_process, ev, data) { static struct etimer et; static struct uip_ds6_notification n; uip_ipaddr_t *ipaddr; PROCESS_BEGIN(); ipaddr = set_global_address(); uip_ds6_notification_add(&n, route_callback); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&et, CLOCK_SECOND); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); if(should_blink) { leds_on(LEDS_ALL); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); leds_off(LEDS_ALL); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(blinker_process, ev, data) { static struct etimer et; static uint8_t red, green; PROCESS_BEGIN(); etimer_set(&et, CLOCK_SECOND / 2); while(1) { PROCESS_WAIT_UNTIL(etimer_expired(&et)); etimer_reset(&et); if(0) { leds_on(LEDS_RED); red = 1; } else { red = 0; } if(!ip64_hostaddr_is_configured()) { leds_on(LEDS_GREEN); green = 1; } else { green = 0; } PROCESS_WAIT_UNTIL(etimer_expired(&et)); etimer_reset(&et); if(red) { leds_off(LEDS_RED); } if(green) { leds_off(LEDS_GREEN); } } PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(tres_process, ev, data) { PROCESS_BEGIN(); srand(node_id); rest_init_engine(); tres_init(); SENSORS_ACTIVATE(light_sensor); rest_activate_periodic_resource(&periodic_resource_light); rplinfo_activate_resources(); static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ SERVER_NODE(&server_ipaddr); /* receives all CoAP messages */ coap_receiver_init(); int wait_time = getRandUint(MAX_WAITING); int base_wait = BASE_WAITING; static int g_time=0; static char content[12]; etimer_set(&et, (wait_time + base_wait) * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) break; } etimer_reset(&et); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { coap_init_message(request, COAP_TYPE_NON, COAP_POST, 0 ); coap_set_header_uri_path(request, service_urls[1]); coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++)); coap_transaction_t *transaction; request->mid = coap_get_mid(); if ((transaction = coap_new_transaction(request->mid, &server_ipaddr, REMOTE_PORT))) { transaction->packet_len = coap_serialize_message(request, transaction->packet); coap_send_transaction(transaction); } etimer_reset(&et); } } /* while (1) */ PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(tres_process, ev, data) { PROCESS_BEGIN(); srand(node_id); rest_init_engine(); tres_init(); rest_activate_resource(&actuator, "actuator"); rplinfo_activate_resources(); sprintf(setpoint, "0"); #if PYOT_KEEPALIVE static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ SERVER_NODE(&server_ipaddr); int wait_time = (unsigned int)(rand() % MAX_WAITING); int base_wait = BASE_WAITING; static int g_time=0; static char content[12]; etimer_set(&et, (wait_time + base_wait) * CLOCK_SECOND); while(1) { PROCESS_YIELD(); //PROCESS_WAIT_EVENT(); if (etimer_expired(&et)) break; } etimer_reset(&et); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { coap_init_message(request, COAP_TYPE_NON, COAP_POST, 0 ); coap_set_header_uri_path(request, "/rd"); coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++)); //PRINT6ADDR(&server_ipaddr); //PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT)); coap_transaction_t *transaction; request->mid = coap_get_mid(); if ((transaction = coap_new_transaction(request->mid, &server_ipaddr, REMOTE_PORT))) { transaction->packet_len = coap_serialize_message(request, transaction->packet); coap_send_transaction(transaction); } etimer_reset(&et); } } /* while (1) */ #endif PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(network_reboot_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; static struct etimer countdown_timer; PROCESS_BEGIN(); /* Wait for a while before starting to listen to the reboot code. */ etimer_set(&periodic_timer, STARTUP_GRACE_PERIOD); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); simple_udp_register(&broadcast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&periodic_timer, SEND_INTERVAL); etimer_set(&send_timer, SEND_TIME); etimer_set(&countdown_timer, CLOCK_SECOND); while(1) { PROCESS_WAIT_EVENT(); if(data == &countdown_timer) { etimer_reset(&countdown_timer); if(seconds_until_reboot > 0) { printf("Seconds until reboot %d\n", seconds_until_reboot); leds_toggle(LEDS_ALL); seconds_until_reboot--; if(seconds_until_reboot == 0) { printf("Rebooting\n"); watchdog_reboot(); } } } if(data == &periodic_timer) { etimer_reset(&periodic_timer); etimer_set(&send_timer, SEND_TIME); } if(data == &send_timer) { if(seconds_until_reboot > 0) { send_msg(&broadcast_connection, seconds_until_reboot); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(stest_process, ev, data) { static struct etimer timer; PROCESS_BEGIN(); clrscr_arch(); #ifdef RS232_INTR rs232_arch_init(serial_line_input_byte, 0); #endif etimer_set(&timer, CLOCK_SECOND); log_message("Starting serial test process"); while(1) { PROCESS_WAIT_EVENT(); if (etimer_expired(&timer)) { log_message("Sending serial data now"); rs232_print("GNU's not Unix\n"); etimer_reset(&timer); } if(ev == serial_line_event_message) { log_message(data); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(unicast_sender_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; uip_ipaddr_t global_ipaddr; PROCESS_BEGIN(); random_rand(); rpl_log_start(); if(node_id ==0) { NETSTACK_RDC.off(0); uint16_t mymac = linkaddr_node_addr.u8[7] << 8 | linkaddr_node_addr.u8[6]; printf("Node id unset, my mac is 0x%04x\n", mymac); PROCESS_EXIT(); } cc2420_set_txpower(RF_POWER); cc2420_set_cca_threshold(RSSI_THR); printf("App: %u starting\n", node_id); deployment_init(&global_ipaddr); //rpl_setup(node_id == ROOT_ID, node_id); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); if(node_id == ROOT_ID) { uip_ipaddr_t my_ipaddr; set_ipaddr_from_id(&my_ipaddr, node_id); //NETSTACK_RDC.off(1); } else { etimer_set(&periodic_timer,1 * 30 * CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); etimer_set(&periodic_timer, SEND_INTERVAL); while(1) { etimer_set(&send_timer, random_rand() % (SEND_INTERVAL)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); int rank = default_instance != NULL ? default_instance->current_dag->rank : 0xffff; if(rank != 0xffff){ app_send_to(ROOT_ID); } else{ printf("App: not in DODAG\n"); } PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); } } PROCESS_END(); }
/* Glowny program */ PROCESS_THREAD(program_UDP, ev, data) { static struct etimer et; PROCESS_BEGIN(); #if UIP_CONF_IPV6 > 0 uip_ip6addr(&ipaddr, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]); #else uip_ipaddr(&ipaddr, addr[0], addr[1], addr[2], addr[3]); #endif conn = udp_new(&ipaddr, UIP_HTONS(port), &state); udp_bind(conn, UIP_HTONS(port + 1)); printf("Binded\n"); etimer_set(&et, CLOCK_CONF_SECOND * 3); while (1) { PROCESS_WAIT_EVENT(); if (uip_newdata()) { str = uip_appdata; str[uip_datalen()] = '\0'; printf("Received: '%s'\n", str); } etimer_reset(&et); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(broadcast_example_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; uip_ipaddr_t addr; PROCESS_BEGIN(); simple_udp_register(&broadcast_connection, UDP_PORT, NULL, UDP_PORT, receiver); 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_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); // printf("Jamming\n"); uip_create_linklocal_allnodes_mcast(&addr); simple_udp_sendto(&broadcast_connection, "jamming", 7, &addr); } PROCESS_END(); }
/* This is the implementation of our process */ PROCESS_THREAD(hello_world_process, ev, data) { // Variables are declared static to ensure their values are kept // between kernel calls. static struct etimer timer; // this is an event timer static int count = 0; // any process must start wtih this PROCESS_BEGIN(); // set the etimer module to generate an event in one second etimer_set(&timer, CLOCK_CONF_SECOND); while (1) { // Wait here for an even to happen PROCESS_WAIT_EVENT(); // if the event is the timer event as expected... if (ev == PROCESS_EVENT_TIMER) { // to the process work printf("Hello, world #%i\n", count); count++; // reset the timer so it will generate another event // the exact same time after it expired (periodicity quaranteed) etimer_reset(&timer); } } // end loop // every process must end with this, even if it is never reached PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(broadcast_example_process, ev, data) { static struct etimer periodic_timer; static struct etimer send_timer; uip_ipaddr_t addr; PROCESS_BEGIN(); //set_global_address(); udp_bconn = udp_broadcast_new(UIP_HTONS(BROADCAST_PORT),NULL); //uip_create_unspecified(&udp_bconn->ripaddr); if(udp_bconn == NULL) { printf("NUC E\n"); PROCESS_EXIT(); } 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_WAIT_EVENT_UNTIL(etimer_expired(&send_timer)); printf("Sending broadcast\n"); send_broadcast("hi",sizeof("hi")); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); static struct etimer et; etimer_set(&et, CLOCK_SECOND*4); while(1){ PROCESS_WAIT_EVENT(); if(etimer_expired(&et)){ printf("Timer expired\n"); etimer_reset(&et); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(otau_client_process, ev, data) { static struct etimer server_timer; uip_ip6addr_t *srv_addr; PROCESS_BEGIN(); servreg_hack_init(); set_global_address(); ota_mgr_init(); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); etimer_set(&server_timer, SEND_INTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&server_timer)); srv_addr = servreg_hack_lookup(SERVICE_ID); if(srv_addr != NULL) { printf("Server address configured\r\n"); server_configured =1; configure_server_details(srv_addr); memcpy((uint8_t *)&(global_server_addr.u16[4]),&(srv_addr->u16[4]),NATIVE_ADDR_SIZE); //uip_create_linklocal_allnodes_mcast(srv_addr); etimer_stop(&server_timer); } else { etimer_reset(&server_timer); printf("server not found\r\n"); } } PROCESS_END(); }
PROCESS_THREAD(port_process, ev, data) { static uint16_t ct0, ct1; uint16_t i, in; PROCESS_BEGIN(); etimer_set(&port_timer, 20E-3*CLOCK_SECOND); while(1) { PROCESS_YIELD(); // DI (digital input) handling PORT_PIN_STATUS(in); i = port_di ^ ~in; // key changed ? ct0 = ~( ct0 & i ); // reset or count ct0 ct1 = ct0 ^ (ct1 & i); // reset or count ct1 i &= ct0 & ct1; // count until roll over ? port_di ^= i; // then toggle debounced state //relay_process(); pwm_step(); etimer_reset(&port_timer); } PROCESS_END(); }
PROCESS_THREAD(coap_client_example, ev, data) { PROCESS_BEGIN(); SERVER_NODE(&server_ipaddr); /* new connection with server */ client_conn = udp_new(&server_ipaddr, UIP_HTONS(REMOTE_PORT), NULL); udp_bind(client_conn, UIP_HTONS(LOCAL_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(&et, 5 * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { send_data(); etimer_reset(&et); } else if (ev == tcpip_event) { handle_incoming_data(); } } PROCESS_END(); }
PROCESS_THREAD(arduino_sketch, ev, data) { static struct etimer loop_periodic_timer; PROCESS_BEGIN(); adc_init (); mcu_sleep_init (); setup (); /* Define application-specific events here. */ etimer_set(&loop_periodic_timer, LOOP_INTERVAL); while (1) { PROCESS_WAIT_EVENT(); #if PLATFORM_HAS_BUTTON if(ev == sensors_event && data == &button_sensor) { mcu_sleep_off(); PRINTF("*******BUTTON*******\n"); button (); mcu_sleep_on(); } #endif /* PLATFORM_HAS_BUTTON */ if(etimer_expired(&loop_periodic_timer)) { mcu_sleep_off(); loop (); mcu_sleep_on(); etimer_reset(&loop_periodic_timer); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rx_process, ev, data) { PROCESS_BEGIN(); arduino_spi_init(); status_led_init(); lora_radio_driver.init(); // Start infinite RX lora_radio_driver.on(); // Print CPU serial printf("CPU serial nb: %08x, %08x, %08x, %08x\n",(unsigned int) U_ID->UI_0,(unsigned int) U_ID->UI_1, (unsigned int) U_ID->UI_2,(unsigned int) U_ID->UI_3); etimer_set(&rx_timer, 10 * CLOCK_SECOND); while( 1 ) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { leds_toggle(LEDS_ALL); printf( "Alive %d\n\r", counter++); etimer_reset(&rx_timer); } } PROCESS_END(); }
PROCESS_THREAD(blink_process, ev , data) { static struct etimer timer; PROCESS_BEGIN(); etimer_set(&timer, CLOCK_SECOND/2); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || ev== PROCESS_EVENT_TIMER); if (ev == PROCESS_EVENT_EXIT) break; leds_invert(LEDS_RED); #if 0 { DISABLE_FIFOP_INT(); printf("FSMSTATE: %04x",cc2420_getreg(CC2420_FSMSTATE)); ENABLE_FIFOP_INT(); if (SFD_IS_1) printf(" SFD"); if (FIFO_IS_1) printf(" FIFO"); if (FIFOP_IS_1) printf(" FIFOP"); putchar('\n'); } #endif etimer_reset(&timer); } printf("Ended process\n"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rs232_process, ev, data) { static struct etimer timer; char ch; unsigned char i, stat; PROCESS_BEGIN(); rs232_arch_init(RS232_BAUD_RATE); etimer_set(&timer, CLOCK_SECOND / 16); while(1) { PROCESS_WAIT_EVENT(); if (etimer_expired(&timer)) { for (i = 0; i < RS232_BUFSIZE; i++) { ch = rs232_arch_poll(&stat); if (stat == 0) { break; } /* We have an input data */ RS232_CALLBACK(ch); } etimer_reset(&timer); } } PROCESS_END(); }
static void dtls_handler(process_event_t ev, process_data_t data){ if (ev == dtls_event){ if (dtls_rehandshake()){ etimer_stop(&et); } else if (dtls_connected()){ connection = (Connection*)data; etimer_set(&et, SEND_INTERVAL); DTLS_Write(connection, hello_msg, 11); } else if (dtls_newdata()){ dtls_appdata[dtls_applen] = 0; } } else if (ev == PROCESS_EVENT_TIMER){ if (etimer_expired(&et)){ DTLS_Write(connection, hello_msg, 11); etimer_reset(&et); } if (etimer_expired(&et2)){ DTLS_Close(connection); etimer_stop(&et); etimer_stop(&et2); } } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(slip_radio_process, ev, data) { static struct etimer et; PROCESS_BEGIN(); init(); NETSTACK_RDC.off(1); #ifdef SLIP_RADIO_CONF_SENSORS SLIP_RADIO_CONF_SENSORS.init(); #endif printf("Slip Radio started...\n"); etimer_set(&et, CLOCK_SECOND * 3); while(1) { PROCESS_YIELD(); if(etimer_expired(&et)) { etimer_reset(&et); #ifdef SLIP_RADIO_CONF_SENSORS SLIP_RADIO_CONF_SENSORS.send(); #endif } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_server_process, ev, data) { struct process *p; struct shell_command *c; static struct etimer etimer; PROCESS_BEGIN(); etimer_set(&etimer, CLOCK_SECOND * 10); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_EXITED) { p = data; /* printf("process exited '%s' (front '%s')\n", p->name, front_process->name);*/ for(c = list_head(commands); c != NULL && c->process != p; c = c->next); while(c != NULL) { if(c->child != NULL && c->child->process != NULL) { /* printf("Killing '%s'\n", c->process->name);*/ input_to_child_command(c->child, "", 0, "", 0); /* process_exit(c->process);*/ } c = c->child; } } else if(ev == PROCESS_EVENT_TIMER) { etimer_reset(&etimer); shell_set_time(shell_time()); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(web_sense_process, ev, data) { static struct etimer timer; PROCESS_BEGIN(); sensors_pos = 0; etimer_set(&timer, CLOCK_SECOND * 2); #if CONTIKI_TARGET_SKY SENSORS_ACTIVATE(light_sensor); SENSORS_ACTIVATE(sht11_sensor); #endif while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); etimer_reset(&timer); #if CONTIKI_TARGET_SKY light1[sensors_pos] = get_light();; temperature[sensors_pos] = get_temp(); sensors_pos = (sensors_pos + 1) % HISTORY; #endif } 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(); 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_sender_process, ev, data) { static struct etimer period_timer, wait_timer; PROCESS_BEGIN(); set_global_address(); PRINTF("UDP sender process started\n"); print_local_address(); /* new connection with remote host */ sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL); udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT)); PRINTF("Created a connection with the sink "); PRINT6ADDR(&sender_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(sender_conn->lport), UIP_HTONS(sender_conn->rport)); etimer_set(&period_timer, CLOCK_SECOND * PERIOD); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { if(data == &period_timer) { etimer_reset(&period_timer); etimer_set(&wait_timer, random_rand() % (CLOCK_SECOND * RANDWAIT)); } else if(data ==&wait_timer) { /* Time to send a data. */ collect_common_send(); } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); frame_manager_init(); status_led_init(); status_led_rx_on(led_on); status_led_tx_on(led_on); etimer_set(&et_hello, 1 * CLOCK_SECOND); while( 1 ) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { if (led_on) led_on = FALSE; else led_on = TRUE; status_led_rx_on(led_on); status_led_tx_on(led_on); etimer_reset(&et_hello); } } PROCESS_END(); }
PROCESS_THREAD(rest_manager_process, ev, data) { PROCESS_BEGIN(); PROCESS_PAUSE(); /* Initialize the PERIODIC_RESOURCE timers, which will be handled by this process. */ periodic_resource_t* periodic_resource = NULL; for (periodic_resource = (periodic_resource_t*) list_head(restful_periodic_services); periodic_resource; periodic_resource = periodic_resource->next) { if (periodic_resource->period) { PRINTF("Periodic: Set timer for %s to %lu\n", periodic_resource->resource->url, periodic_resource->period); etimer_set(&periodic_resource->periodic_timer, periodic_resource->period); } } while (1) { PROCESS_WAIT_EVENT(); if (ev == PROCESS_EVENT_TIMER) { for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services);periodic_resource;periodic_resource = periodic_resource->next) { if (periodic_resource->period && etimer_expired(&periodic_resource->periodic_timer)) { PRINTF("Periodic: etimer expired for /%s (period: %lu)\n", periodic_resource->resource->url, periodic_resource->period); /* Call the periodic_handler function if it exists. */ if (periodic_resource->periodic_handler) { (periodic_resource->periodic_handler)(periodic_resource->resource); } etimer_reset(&periodic_resource->periodic_timer); } } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(servreg_hack_process, ev, data) { static struct etimer periodic; static struct uip_udp_conn *outconn, *inconn; PROCESS_BEGIN(); /* Create outbound UDP connection. */ outconn = udp_broadcast_new(UIP_HTONS(UDP_PORT), NULL); udp_bind(outconn, UIP_HTONS(UDP_PORT)); /* Create inbound UDP connection. */ inconn = udp_new(NULL, UIP_HTONS(UDP_PORT), NULL); udp_bind(inconn, UIP_HTONS(UDP_PORT)); etimer_set(&periodic, PERIOD_TIME); etimer_set(&sendtimer, random_rand() % (PERIOD_TIME)); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER && data == &periodic) { etimer_reset(&periodic); etimer_set(&sendtimer, random_rand() % (PERIOD_TIME)); } else if(ev == PROCESS_EVENT_TIMER && data == &sendtimer) { send_udp_packet(outconn); } else if(ev == tcpip_event) { parse_incoming_packet(uip_appdata, uip_datalen()); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(sensors_sample_process, ev, data) { /* Variables are declared static to ensure their values are kept between kernel calls. */ static struct etimer timer; /* Any process must start with this. */ PROCESS_BEGIN(); /* Set the etimer to generate an event in one second. */ etimer_set(&timer, CLOCK_CONF_SECOND); while(1) { /* Wait for an event. */ PROCESS_WAIT_EVENT(); /* Got the timer's event~ */ if (ev == PROCESS_EVENT_TIMER) { /* Read raw temperature value. */ int16_t temp_raw = sensor_temp_get_raw(); /* Read temperature value in specified unit (C/F). */ int16_t temp = sensor_temp_get(TEMP_UNIT_CELCIUS); /* Read raw light value. */ int16_t light_raw = sensor_light_get_raw(); printf("temp_raw:%d\ntemp:%d\nlight_raw:%d", temp_raw, temp, light_raw); /* Reset the etimer so it will generate another event after the exact same time. */ etimer_reset(&timer); } } // while (1) /* Any process must end with this, even if it is never reached. */ PROCESS_END(); }