/*---------------------------------------------------------------------------*/ PROCESS_THREAD(depth_blink_process, ev, data) { static struct etimer et; static int count; PROCESS_BEGIN(); while(1) { etimer_set(&et, CLOCK_SECOND * 10); PROCESS_WAIT_UNTIL(etimer_expired(&et)); count = collect_depth(&tc); if(count == COLLECT_MAX_DEPTH) { leds_on(LEDS_BLUE); } else { leds_off(LEDS_BLUE); count /= COLLECT_LINK_ESTIMATE_UNIT; while(count > 0) { leds_on(LEDS_RED); etimer_set(&et, CLOCK_SECOND / 32); PROCESS_WAIT_UNTIL(etimer_expired(&et)); leds_off(LEDS_RED); etimer_set(&et, CLOCK_SECOND / 8); PROCESS_WAIT_UNTIL(etimer_expired(&et)); --count; } } } 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(); }
/* A periodic process to send TSCH Enhanced Beacons (EB) */ PROCESS_THREAD(tsch_send_eb_process, ev, data) { static struct etimer eb_timer; PROCESS_BEGIN(); /* Wait until association */ etimer_set(&eb_timer, CLOCK_SECOND / 10); while(!tsch_is_associated) { PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer)); etimer_reset(&eb_timer); } /* Set an initial delay except for coordinator, which should send an EB asap */ if(!tsch_is_coordinator) { etimer_set(&eb_timer, random_rand() % TSCH_EB_PERIOD); PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer)); } while(1) { unsigned long delay; if(tsch_is_associated && tsch_current_eb_period > 0) { /* Enqueue EB only if there isn't already one in queue */ if(tsch_queue_packet_count(&tsch_eb_address) == 0) { int eb_len; uint8_t hdr_len = 0; uint8_t tsch_sync_ie_offset; /* Prepare the EB packet and schedule it to be sent */ eb_len = tsch_packet_create_eb(&hdr_len, &tsch_sync_ie_offset); if(eb_len > 0) { struct tsch_packet *p; /* Enqueue EB packet */ if(!(p = tsch_queue_add_packet(&tsch_eb_address, NULL, NULL))) { PRINTF("TSCH:! could not enqueue EB packet\n"); } else { PRINTF("TSCH: enqueue EB packet %u %u\n", eb_len, hdr_len); p->tsch_sync_ie_offset = tsch_sync_ie_offset; p->header_len = hdr_len; } } } } if(tsch_current_eb_period > 0) { /* Next EB transmission with a random delay * within [tsch_current_eb_period*0.75, tsch_current_eb_period[ */ delay = (tsch_current_eb_period - tsch_current_eb_period / 4) + random_rand() % (tsch_current_eb_period / 4); } else { delay = TSCH_EB_PERIOD; } etimer_set(&eb_timer, delay); PROCESS_WAIT_UNTIL(etimer_expired(&eb_timer)); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_collect_process, ev, data) { static struct etimer periodic; static struct etimer et; PROCESS_BEGIN(); collect_open(&tc, 130, COLLECT_ROUTER, &callbacks); if(linkaddr_node_addr.u8[0] == 1 && linkaddr_node_addr.u8[1] == 0) { printf("I am sink\n"); collect_set_sink(&tc, 1); } /* Allow some time for the network to settle. */ etimer_set(&et, 120 * CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&et)); while(1) { /* Send a packet every 30 seconds. */ etimer_set(&periodic, CLOCK_SECOND * 30); etimer_set(&et, random_rand() % (CLOCK_SECOND * 30)); PROCESS_WAIT_UNTIL(etimer_expired(&et)); { static linkaddr_t oldparent; const linkaddr_t *parent; printf("Sending\n"); packetbuf_clear(); packetbuf_set_datalen(sprintf(packetbuf_dataptr(), "%s", "Hello") + 1); collect_send(&tc, 15); parent = collect_parent(&tc); if(!linkaddr_cmp(parent, &oldparent)) { if(!linkaddr_cmp(&oldparent, &linkaddr_null)) { printf("#L %d 0\n", oldparent.u8[0]); } if(!linkaddr_cmp(parent, &linkaddr_null)) { printf("#L %d 1\n", parent->u8[0]); } linkaddr_copy(&oldparent, parent); } } PROCESS_WAIT_UNTIL(etimer_expired(&periodic)); } 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(); if(node_id == 0) { NETSTACK_RDC.off(0); printf("Node id unset, my mac is "); uip_debug_lladdr_print(&rimeaddr_node_addr); printf("\n"); PROCESS_EXIT(); } cc2420_set_txpower(RF_POWER); cc2420_set_cca_threshold(RSSI_THR); orpl_log_start(); printf("App: %u starting\n", node_id); deployment_init(&global_ipaddr); #if WITH_ORPL orpl_init(node_id == ROOT_ID, 0); #endif /* WITH_ORPL */ simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); if(node_id == ROOT_ID) { NETSTACK_RDC.off(1); etimer_set(&periodic_timer, 2 * 60 * 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_UNTIL(etimer_expired(&send_timer)); if(check_reachable_count()) { uip_ipaddr_t dest_ipaddr; static uint16_t target_id; static uint16_t i; do { target_id = get_node_id_from_index((random_rand()>>8)%get_n_nodes()); set_ipaddr_from_id(&dest_ipaddr, target_id); } while (target_id == ROOT_ID || !orpl_routing_set_contains(&dest_ipaddr)); app_send_to(target_id); } PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); } }
PROCESS_THREAD(shell_broadcast_hi_process, ev, data) { static struct etimer etimer; // PROCESS_EXITHANDLER(broadcast_close(&broadcast);) // PROCESS_EXITHANDLER(mesh_close(&mesh); broadcast_close(&broadcast);) PROCESS_BEGIN(); static int8_t counter = 0; static uint8_t fail_count = 0; mesh_open(&mesh, 132, &callbacks); broadcast_open(&broadcast, 129, &broadcast_call); while(1) { counter++; leds_on(LEDS_ALL); etimer_set(&etimer, 3 * CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_off(LEDS_ALL); etimer_set(&etimer, random_rand() % 5 * CLOCK_SECOND + random_rand() % 100 * CLOCK_SECOND / 100); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); packetbuf_copyfrom("Hello", 6); broadcast_send(&broadcast); etimer_set(&etimer, random_rand() % 5 * CLOCK_SECOND + random_rand() % 100 * CLOCK_SECOND / 100); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); char message[6] = "Hello"; rimeaddr_t addr; packetbuf_copyfrom(message, sizeof(message)); addr.u8[0] = 62; addr.u8[1] = 41; uint8_t mesh_sent = 0; mesh_sent = mesh_send(&mesh, &addr); if (mesh_sent == 0) { fail_count++; if (counter == 10 && fail_count >= 4) { mesh_open(&mesh, 132, &callbacks); counter = 0; fail_count = 0; } else if (counter == 10) counter = 0; } } 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(); printf("App: %u starting\n", node_id); uip_ip6addr(&root_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); if(node_id == ROOT_ID) { memcpy(&global_ipaddr, &root_ipaddr, 16); uip_ds6_addr_add(&global_ipaddr, 0, ADDR_MANUAL); rpl_dag_t *dag = rpl_set_root(RPL_DEFAULT_INSTANCE, &global_ipaddr); rpl_set_prefix(dag, &global_ipaddr, 64); } else { uip_ip6addr(&global_ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&global_ipaddr, &uip_lladdr); uip_ds6_addr_add(&global_ipaddr, 0, ADDR_AUTOCONF); } orpl_init(&global_ipaddr, node_id == ROOT_ID, 1); simple_udp_register(&unicast_connection, UDP_PORT, NULL, UDP_PORT, receiver); if(node_id == ROOT_ID) { NETSTACK_RDC.off(1); } else { etimer_set(&periodic_timer, SEND_INTERVAL); while(1) { etimer_set(&send_timer, random_rand() % (SEND_INTERVAL)); PROCESS_WAIT_UNTIL(etimer_expired(&send_timer)); if(orpl_current_edc() != 0xffff) { app_send_to(ROOT_ID); } else { printf("App: not in DODAG\n"); } PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(acc_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); printf("Starting measuring acceleration\r\n"); boardPrintStringDescription(); SENSORS_ACTIVATE(acc_sensor); // Enable High Range. //acc_sensor.configure(ACC_RANGE, ACC_HIGH_RANGE); // Enable High Pass Filter. //acc_sensor.configure(ACC_HPF, ACC_1HZ); while(1) { etimer_set(&etimer, CLOCK_SECOND/2); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); printf("(X,Y,Z): (%d,%d,%d) mg \r",acc_sensor.value(ACC_X_AXIS),acc_sensor.value(ACC_Y_AXIS),acc_sensor.value(ACC_Z_AXIS)); } PROCESS_END(); }
PROCESS_THREAD(button_process, ev, data) { static struct etimer etimer; PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); printf("button_process starting\n"); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_MSG && data != NULL && ((struct button_msg *)data)->type == BUTTON_MSG_TYPE) { printf("button press\n"); leds_toggle(LEDS_ALL); etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_toggle(LEDS_ALL); } } exit: printf("button_process exiting\n"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(burn_process, ev, data) { PROCESS_BEGIN(); etimer_set(&etimer, 5*CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); watchdog_stop(); leds_on(LEDS_RED); #if NODEID printf("Burning node id %d\n", NODEID); node_id_burn(NODEID); leds_on(LEDS_BLUE); node_id_restore(); printf("Restored node id %d\n", node_id); #else #error "burn-nodeid must be compiled with nodeid=<the ID of the node>" node_id_restore(); printf("Restored node id %d\n", node_id); #endif leds_off(LEDS_RED + LEDS_BLUE); watchdog_start(); while(1) { PROCESS_WAIT_EVENT(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_change_detect_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); leds_init(); while(1) { sensor_init(); etimer_set(&etimer, CLOCK_SECOND / 4); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); sample = sensor_read(); sensor_uinit(); printf("sample = %d\n",sample); if(abs_sub(sample, sample_mean) > (sample_std_dev * NUM_DEVS)) { // Change detected, turn on LED(s)? leds_on(LEDS_RED); } else { // Turn off LED(s). leds_off(LEDS_RED); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_process, ev, data) { PROCESS_BEGIN(); // Wait a second... etimer_set(&timer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); PRINTD("Starting test...\n"); // Run tests... char *result = run_tests(); if (result != 0) { printf("%s\n", result); } else { printf("ALL TESTS PASSED\n"); } printf("Tests run: %d\n", tests_run); return result != 0; cfs_fat_umount_device(); // printf("#################################################################"); while (1); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_download_process, ev, data) { const char *nextptr; static rimeaddr_t addr; int len; char buf[32]; PROCESS_BEGIN(); /* Parse node addr */ addr.u8[0] = shell_strtolong(data, &nextptr); if(nextptr == data || *nextptr != '.') { shell_output_str(&download_command, "download <node addr> <filename>: need node address", ""); PROCESS_EXIT(); } ++nextptr; addr.u8[1] = shell_strtolong(nextptr, &nextptr); /* Get the length of the file, excluding a terminating NUL character. */ while(nextptr[0] == ' ') { nextptr++; } len = strlen(nextptr); /*snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);*/ /*shell_output_str(&download_command, "Downloading from: ", buf);*/ if(len > PACKETBUF_SIZE - 32) { snprintf(buf, sizeof(buf), "%d", len); shell_output_str(&download_command, "filename too large: ", buf); PROCESS_EXIT(); } /*shell_output_str(&download_command, "Downloading file: ", nextptr);*/ /* Send file request */ downloading = 1; rucb_open(&rucb, RUCB_CHANNEL, &rucb_call); packetbuf_clear(); *((uint8_t *)packetbuf_dataptr()) = ++req_seq_counter; memcpy(((char *)packetbuf_dataptr()) + 1, nextptr, len + 1); packetbuf_set_datalen(len + 2); PRINTF("requesting '%s'\n", nextptr); runicast_send(&runicast, &addr, MAX_RETRANSMISSIONS); /* Wait for download to finish */ leds_on(LEDS_BLUE); PROCESS_WAIT_UNTIL(!runicast_is_transmitting(&runicast) && !downloading); leds_off(LEDS_BLUE); rucb_close(&rucb); /*shell_output_str(&download_command, "Done!", "");*/ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer et, wake_timer, periodic_timer; uip_ipaddr_t ipaddr; PROCESS_BEGIN(); PRINTF("UDP client process started\n"); #if UIP_CONF_ROUTER set_global_address(); #endif print_local_addresses(); set_connection_address(&ipaddr); /* new connection with remote host */ client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL); udp_bind(client_conn, UIP_HTONS(3001)); 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, CLOCK_SECOND*10); PROCESS_WAIT_UNTIL(etimer_expired(&et)); // Wait for DAD and Router Discovery procedure to end. etimer_set(&et, SEND_INTERVAL); etimer_set(&wake_timer, AWAKE_INTERVAL); etimer_set(&periodic_timer, 1); while(1) { PROCESS_YIELD(); if(etimer_expired(&wake_timer)){ // if timer hasn't expired do not go in deep sleep, in order to receive a response. printf("Sleeping...\r\n"); sensorsPowerDown(); sleep_seconds(SLEEP_INTERVAL_SECONDS); // Put system in deep sleep mode for a while. sensorsPowerUp(); printf("Awake\r\n"); } if(etimer_expired(&et)) { timeout_handler(); etimer_restart(&et); etimer_restart(&wake_timer); } else if(ev == tcpip_event) { tcpip_handler(); } /* Make the process be called almost immediately, * so that it can force the system to go into deep sleep. */ etimer_restart(&periodic_timer); } PROCESS_END(); }
static void test_rtimer(void) { while(1) { printf("Now = %u\r\n",RTIMER_NOW()); rtimer_set(&task, RTIMER_NOW() + RTIMER_SECOND*2, RTIMER_SECOND, &callback, NULL); PROCESS_WAIT_UNTIL(sem); sem=0; } }
PROCESS_THREAD(led_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); while (1) { PRINTD("LED1\r\n"); PORTB |= (1<<PB1); PORTD |= (1<<PD3); etimer_set(&etimer, CLOCK_SECOND*0.5); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); PORTB &= ~(1<<PB1); PORTD &= ~(1<<PD3); etimer_set(&etimer, CLOCK_SECOND*0.5); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); } PROCESS_END(); }
/*-------------------------------------------------------*/ PROCESS_THREAD(example_process, ev, data) { PROCESS_BEGIN(); do_something(); PROCESS_PAUSE(); do_something_else(); PROCESS_WAIT_UNTIL(temperatur > 30); do_something_completely_else(); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(uip_fw_process, ev, data) { PROCESS_BEGIN(); tcpip_set_outputfunc(uip_fw_output); PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(multicast_example_process, ev, data) { PROCESS_BEGIN(); /* Create a linkl-local multicast addresses. */ uip_ip6addr(&addr, 0xff02, 0, 0, 0, 0, 0, 0x1337, 0x0001); /* Join local group. */ if(uip_ds6_maddr_add(&addr) == NULL) { printf("Error: could not join local multicast group.\n"); } /* Register UDP socket callback */ udp_socket_register(&s, NULL, receiver); /* Bind UDP socket to local port */ udp_socket_bind(&s, PORT); /* Connect UDP socket to remote port */ udp_socket_connect(&s, NULL, PORT); while(1) { /* Set up two timers, one for keeping track of the send interval, which is periodic, and one for setting up a randomized send time within that interval. */ etimer_set(&periodic_timer, SEND_INTERVAL); etimer_set(&send_timer, (random_rand() % SEND_INTERVAL)); PROCESS_WAIT_UNTIL(etimer_expired(&send_timer)); printf("Sending multicast\n"); udp_socket_sendto(&s, "hello", 6, &addr, PORT); PROCESS_WAIT_UNTIL(etimer_expired(&periodic_timer)); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_nodes_process, ev, data) { static struct etimer etimer; struct netflood_msg *msg; char buf[10]; PROCESS_BEGIN(); if(!is_sink) { shell_output_str(&nodes_command, "Setting up a collection network...", ""); #if TIMESYNCH_CONF_ENABLED timesynch_set_authority_level(0); #endif collect_set_sink(&collect, 1); etimer_set(&etimer, CLOCK_SECOND * 2); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); is_sink = 1; } packetbuf_clear(); msg = packetbuf_dataptr(); packetbuf_set_datalen(sizeof(struct netflood_msg)); msg->type = NETFLOOD_TYPE_NODES; netflood_send(&netflood, nodes_seqno++); etimer_set(&etimer, CLOCK_SECOND * 10); waiting_for_nodes = 1; shell_output_str(&nodes_command, "Request sent, waiting for replies...", ""); messages_received = 0; PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); snprintf(buf, sizeof(buf), "%d", messages_received); shell_output_str(&nodes_command, buf, " nodes heard"); waiting_for_nodes = 0; PROCESS_END(); }
PROCESS_THREAD(run_test_session,ev,data) { PROCESS_BEGIN(); current = 0; simple_udp_register(&unicast_connection, UDP_RECEIVER_PORT, NULL, UDP_SENDER_PORT, receiver); PROCESS_WAIT_UNTIL(current == TEST_AMOUNT-1); //PROCESS_WAIT_UNTIL(current == 2749); PROCESS_END(); PROCESS_EXIT(); }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(blink_blue_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; while (1) { etimer_set(&timer, TIMER_INTERRUPT_HZ * 2); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); blueLedToggle(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(simple_energest_process, ev, data) { static struct etimer periodic; PROCESS_BEGIN(); etimer_set(&periodic, 60 * CLOCK_SECOND); while(1) { PROCESS_WAIT_UNTIL(etimer_expired(&periodic)); etimer_reset(&periodic); simple_energest_step(); } PROCESS_END(); }
PROCESS_THREAD(test_process, ev, data) { static struct etimer etimer; PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); printf("test_process starting\n"); while(1) { leds_on(LEDS_RED); etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_off(LEDS_RED); etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); } exit: printf("test_process exiting\n"); leds_off(LEDS_RED); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_seq_data1_process, ev, data) { static uint16_t data_sam[NUM_SAM]; uint16_t sum = 0; uint16_t sqsum = 0; static struct etimer etimer; PROCESS_BEGIN(); //DEBUG CODE printf("cusum-seq: Gathering post-change data... "); // Gather NUM_SAM samples over 1 second of time SENSORS_ACTIVATE(light_sensor); for(counter = 0;counter < NUM_SAM;counter++) { // Get data for no change analysis. etimer_set(&etimer, CLOCK_SECOND / NUM_SAM); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); data_sam[counter] = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC); } printf("done!\n"); SENSORS_DEACTIVATE(light_sensor); sum = 0; sqsum = 0; // Sum the change data for(counter = 0;counter < NUM_SAM;counter++) { sum = sum + data_sam[counter]; } printf("cusum-seq: sum = %d\n",sum); mean_1 = sum/NUM_SAM; // 542.3846 printf("mean_1 = %d\n",mean_1); // Caclulate std_dev_1 for(counter = 0;counter < NUM_SAM;counter++) { sqsum = sqsum + mypow2(abs_sub(data_sam[counter], mean_1)); } std_dev_1 = sqsum/NUM_SAM; // 16.8388 std_dev_1 = mysqrt(std_dev_1); printf("cusum-seq: std_dev_1 = %d\n",std_dev_1); // DEBUG CODE blink_LEDs(LEDS_ALL); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_rime_ping_process, ev, data) { static int i; static struct etimer timeout, periodic; static rimeaddr_t receiver; struct rime_ping_msg *ping; const char *nextptr; char buf[32]; PROCESS_BEGIN(); receiver.u8[0] = shell_strtolong(data, &nextptr); if(nextptr == data || *nextptr != '.') { shell_output_str(&rime_ping_command, "ping <receiver>: recevier must be specified", ""); PROCESS_EXIT(); } ++nextptr; receiver.u8[1] = shell_strtolong(nextptr, &nextptr); snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]); shell_output_str(&rime_ping_command, "Sending 4 pings to ", buf); for(i = 0; i < 4; ++i) { packetbuf_clear(); ping = packetbuf_dataptr(); packetbuf_set_datalen(sizeof(struct rime_ping_msg)); #if TIMESYNCH_CONF_ENABLED ping->pingtime = timesynch_time(); #else ping->pingtime = rtimer_arch_now(); #endif mesh_send(&mesh, &receiver); etimer_set(&timeout, CLOCK_SECOND * 8); etimer_set(&periodic, CLOCK_SECOND * 1); waiting_for_pong = 1; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout) || waiting_for_pong == 0); if(waiting_for_pong == 0) { PROCESS_WAIT_UNTIL(etimer_expired(&periodic)); } else { shell_output_str(&rime_ping_command, "Timed out", ""); } waiting_for_pong = 0; } PROCESS_END(); }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(blink_red_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; while (1) { etimer_set(&timer, TIMER_INTERRUPT_HZ / 2); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); redLedToggle(); yellowLedToggle(); // for Atmega } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_reboot_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); shell_output_str(&reboot_command, "Rebooting the node in four seconds...", ""); etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_on(LEDS_RED); etimer_reset(&etimer); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_on(LEDS_GREEN); etimer_reset(&etimer); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); leds_on(LEDS_BLUE); etimer_reset(&etimer); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); watchdog_reboot(); PROCESS_END(); }
PROCESS_THREAD(infrequent_glossy_test, ev, data) { static struct etimer et; PROCESS_BEGIN(); /* Allow some time for the network to settle. */ etimer_set(&et, 30 * CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&et)); printf("node_id %d\n", node_id); process_start(&tailored_lwb_process, NULL); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(test_process, ev, data) { PROCESS_BEGIN(); // Wait a second... etimer_set(&timer, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&timer)); RUN_TEST("battery_init", test_battery_init); RUN_TEST("battery_value", test_battery_value); RUN_TEST("battery_deinit", test_battery_deinit); TESTS_DONE(); PROCESS_END(); }