/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(program_handler_process, ev, data) { #ifdef WITH_LOADER_ARCH unsigned char err; struct dsc *dsc; #endif /* WITH_LOADER_ARCH */ unsigned char i; struct dsc **dscp; PROCESS_BEGIN(); /* Create the menus */ ctk_menu_add(&contikimenu); #if WITH_LOADER_ARCH runmenuitem = ctk_menuitem_add(&contikimenu, "Run program..."); make_windows(); #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU quitmenuitem = ctk_menuitem_add(&contikimenu, "Quit"); #endif /* QUIT_MENU */ displayname = NULL; #if CTK_CONF_SCREENSAVER program_handler_screensaver[0] = 0; #endif /* CTK_CONF_SCREENSAVER */ while(1) { PROCESS_WAIT_EVENT(); if(ev == ctk_signal_button_activate) { #ifdef WITH_LOADER_ARCH if(data == (process_data_t)&loadbutton) { ctk_window_close(&runwindow); program_handler_load(name, NULL); } else if(data == (process_data_t)&errorokbutton) { ctk_dialog_close(); } #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU if(data == (process_data_t)&quityesbutton) { ctk_draw_init(); exit(EXIT_SUCCESS); } else if(data == (process_data_t)&quitnobutton) { ctk_dialog_close(); } #endif /* QUIT_MENU */ dscp = &contikidsc[0]; for(i = 0; i < CTK_MAXMENUITEMS; ++i) { if(*dscp != NULL #if CTK_CONF_ICONS && data == (process_data_t)(*dscp)->icon #endif /* CTK_CONF_ICONS */ ) { RUN((*dscp)->prgname, (*dscp)->process, NULL); break; } ++dscp; } } else if(ev == ctk_signal_menu_activate) { if((struct ctk_menu *)data == &contikimenu) { #if WITH_LOADER_ARCH dsc = contikidsc[contikimenu.active]; if(dsc != NULL) { RUN(dsc->prgname, dsc->process, NULL); } else if(contikimenu.active == runmenuitem) { make_windows(); ctk_window_close(&runwindow); ctk_window_open(&runwindow); CTK_WIDGET_FOCUS(&runwindow, &nameentry); } #else /* WITH_LOADER_ARCH */ if(contikidsc[contikimenu.active] != NULL) { RUN(contikidsc[contikimenu.active]->prgname, contikidsc[contikimenu.active]->process, NULL); } #endif /* WITH_LOADER_ARCH */ #if QUIT_MENU if(contikimenu.active == quitmenuitem) { ctk_dialog_new(&quitdialog, 24, 5); CTK_WIDGET_ADD(&quitdialog, &quitdialoglabel); CTK_WIDGET_ADD(&quitdialog, &quityesbutton); CTK_WIDGET_ADD(&quitdialog, &quitnobutton); CTK_WIDGET_FOCUS(&quitdialog, &quitnobutton); ctk_dialog_open(&quitdialog); } #endif /* QUIT_MENU */ } #if CTK_CONF_SCREENSAVER } else if(ev == ctk_signal_screensaver_start) { #if WITH_LOADER_ARCH if(program_handler_screensaver[0] != 0) { program_handler_load(program_handler_screensaver, NULL); } #endif /* WITH_LOADER_ARCH */ #endif /* CTK_CONF_SCREENSAVER */ } else if(ev == LOADER_EVENT_DISPLAY_NAME) { #if WITH_LOADER_ARCH if(displayname == NULL) { make_windows(); ctk_label_set_text(&loadingname, ((struct pnarg *)data)->name); ctk_dialog_open(&loadingdialog); process_post(&program_handler_process, LOADER_EVENT_LOAD, data); displayname = data; } else { /* Try again. */ process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); } #endif /* WITH_LOADER_ARCH */ } else if(ev == LOADER_EVENT_LOAD) { #if WITH_LOADER_ARCH if(displayname == data) { ctk_dialog_close(); displayname = NULL; log_message("Loading ", ((struct pnarg *)data)->name); err = LOADER_LOAD(((struct pnarg *)data)->name, ((struct pnarg *)data)->arg); if(err != LOADER_OK) { make_windows(); errorfilename[0] = '"'; strncpy(errorfilename + 1, ((struct pnarg *)data)->name, sizeof(errorfilename) - 2); errorfilename[1 + strlen(((struct pnarg *)data)->name)] = '"'; ctk_label_set_text(&errortype, (char *)errormsgs[err]); ctk_dialog_open(&errordialog); log_message((char *)errormsgs[err], errorfilename); } pnarg_free(data); } else { /* Try again. */ process_post(&program_handler_process, LOADER_EVENT_DISPLAY_NAME, data); } #endif /* WITH_LOADEER_ARCH */ } } 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 */ packetbuf_clear(); /* We don't use seqno 0 */ if(++tsch_packet_seqno == 0) { tsch_packet_seqno++; } packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_BEACONFRAME); packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, tsch_packet_seqno); #if LLSEC802154_ENABLED if(tsch_is_pan_secured) { /* Set security level, key id and index */ packetbuf_set_attr(PACKETBUF_ATTR_SECURITY_LEVEL, TSCH_SECURITY_KEY_SEC_LEVEL_EB); packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, FRAME802154_1_BYTE_KEY_ID_MODE); /* Use 1-byte key index */ packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, TSCH_SECURITY_KEY_INDEX_EB); } #endif /* LLSEC802154_ENABLED */ eb_len = tsch_packet_create_eb(packetbuf_dataptr(), PACKETBUF_SIZE, tsch_packet_seqno, &hdr_len, &tsch_sync_ie_offset); if(eb_len != 0) { struct tsch_packet *p; packetbuf_set_datalen(eb_len); /* 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(cc2538_demo_process, ev, data) { PROCESS_EXITHANDLER(broadcast_close(&bc)) PROCESS_BEGIN(); counter = 0; broadcast_open(&bc, BROADCAST_CHANNEL, &bc_rx); printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10); while(1) { etimer_set(&et, CLOCK_SECOND*10); //ivanm // Configure ADC, Internal reference, 512 decimation rate (12bit) // SOCADCSingleConfigure(SOCADC_12_BIT, SOCADC_REF_INTERNAL); // // Trigger single conversion on AIN6 (connected to LV_ALS_OUT). // SOCADCSingleStart(SOCADC_VDD); // // Wait until conversion is completed // while(!SOCADCEndOfCOnversionGet()) { } // // Get data and shift down based on decimation rate // ui1Dummy = SOCADCDataGet() >> SOCADC_12_BIT_RSHIFT; printf("konverzija(ADC) = 0x%08x\n",ui1Dummy); PROCESS_YIELD(); if(ev == PROCESS_EVENT_TIMER) { leds_on(LEDS_PERIODIC); printf("Counter = 0x%08x\n", counter); err = s_measure(&temperature, checksum, TEMP); if (err == 0) { //printf("Temperature (ADC value) = 0x%4x\n", temperature); err = s_measure(&humidity, checksum, HUMI); if (err == 0) { //printf("Humidity (ADC value) = 0x%4x\n", humidity); //tc=sht11_TemperatureC(temperature); //hc=sht11_Humidity(temperature,humidity); tc=0; hc=0; printf("temp:%u.%u\nhumidity:%u.%u\n",(int)tc,((int)(tc*10))%10 , (int)hc,((int)(hc*10))%10); } else printf("SHT11 error - could not read humidity!\n"); } else printf("SHT11 error - could not read temperature!\n"); etimer_set(&et, CLOCK_SECOND); rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1, rt_callback, NULL); } else if(ev == sensors_event) { if(data == &button_select_sensor) { if (swt==0) { packetbuf_copyfrom(&temperature, sizeof(temperature)); broadcast_send(&bc); swt=1; } else { packetbuf_copyfrom(&humidity, sizeof(humidity)); broadcast_send(&bc); swt=0; } } else if(data == &button_left_sensor || data == &button_right_sensor) { leds_toggle(LEDS_BUTTON); } else if(data == &button_down_sensor) { cpu_cpsid(); leds_on(LEDS_REBOOT); watchdog_reboot(); } else if(data == &button_up_sensor) { sys_ctrl_reset(); } } else if(ev == serial_line_event_message) { leds_toggle(LEDS_SERIAL_IN); } counter++; /* put measaruement sht11 here*/ } PROCESS_END(); }
PROCESS_THREAD(checkpoint_serial_process, ev, data) { static int set_fd = -1; static int set_count = -1; PROCESS_BEGIN(); /* Note: 'cp', 'rb', and 'mt' commands are intercepted */ PROCESS_PAUSE(); uart1_set_input(serial_input_byte_intercept); /* Format Coffee? */ PRINTF("Formatting Coffee\n"); cfs_coffee_format(); PRINTF("Formatting Coffee... done!\n"); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL); if(strcmp("set", data) == 0) { /* TODO Handle set command */ /* Open file */ cfs_remove("cp"); cfs_coffee_reserve("cp", checkpoint_arch_size()); set_fd = cfs_open("cp", CFS_WRITE); set_count = 0; if(set_fd < 0) { printf("SET:FSBUSY\n"); } else { printf("SET:LINE\n"); } } else if(set_fd >= 0 && strcmp("set:done", data) == 0) { cfs_close(set_fd); set_fd = -1; if(set_count == 9862) { printf("SET:DONE\n"); } else { printf("SET:WRONGSIZE\n"); } } else if(set_fd >= 0) { /* We are ready for another line */ printf("SET:LINE\n"); /* Set command: parse hex data */ int len = strlen((char*)data); if(len > 16 || (len%2)!=0) { printf("WARN: bad set data: %s\n", (char*)data); } else { int i; for (i=0; i < len; i+=2) { uint8_t b = (hex_decode_char(((char*)data)[i]) << 4) + (hex_decode_char(((char*)data)[i+1])); PRINTF("Parsing set command: writing to CFS: %02x\n", b); write_byte(set_fd, b); /* TODO Check return value */ set_count++; } } } else if(strcmp("", data) == 0 || strcmp("cp", data) == 0 || strcmp("rb", data) == 0 || strcmp("mt", data) == 0) { /* ignore commands: handled by interrupt */ } else if(strcmp("ping", data) == 0) { nr_pongs++; printf("pong %u\n", nr_pongs); } else if(strcmp("get", data) == 0) { handle_get_command(); } else { printf("WARN: Unknown command: '%s'\n", (char*)data); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic, set_tx_timer; 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)); //---------------------- Set Tx ---------- etimer_set(&set_tx_timer, 30 * CLOCK_SECOND); set_tx_flag(); set_tx(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&set_tx_timer)); clear_tx_flag(); //-------------------------------------- #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(etimer_process, ev, data) { struct etimer *t, *u; PROCESS_BEGIN(); timerlist = NULL; while(1) { PROCESS_YIELD(); if(ev == PROCESS_EVENT_EXITED) { struct process *p = data; while(timerlist != NULL && timerlist->p == p) { timerlist = timerlist->next; } if(timerlist != NULL) { t = timerlist; while(t->next != NULL) { if(t->next->p == p) { t->next = t->next->next; } else t = t->next; } } continue; } else if(ev != PROCESS_EVENT_POLL) { continue; } again: u = NULL; for(t = timerlist; t != NULL; t = t->next) { if(timer_expired(&t->timer)) { if(process_post(t->p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK) { /* Reset the process ID of the event timer, to signal that the etimer has expired. This is later checked in the etimer_expired() function. */ t->p = PROCESS_NONE; if(u != NULL) { u->next = t->next; } else { timerlist = t->next; } t->next = NULL; update_time(); goto again; } else { etimer_request_poll(); } } u = t; } } PROCESS_END(); }
PROCESS_THREAD(sbk_in_process, ev, data) { PROCESS_BEGIN(); while (1) { PROCESS_WAIT_UNTIL(sbk_in_track!=0); DBG("Einfahrt auf Gleis "); DBG('0' + sbk_in_track); DBG("\r\n"); switch (sbk_in_track) { case 1: shiftreg |= (1<<RELAIS_G1_IN); break; case 2: shiftreg |= (1<<RELAIS_G2_IN); break; case 3: shiftreg |= (1<<RELAIS_G3_IN); break; case 4: shiftreg |= (1<<RELAIS_G4_IN); break; case 5: shiftreg |= (1<<RELAIS_G5_IN); break; case 6: shiftreg |= (1<<RELAIS_G6_IN); break; default: break; } shiftreg_out16(shiftreg,1); #if 0 // First: wait until track is free (allows proper functioning of the cleaning mode) PROCESS_WAIT_UNTIL((gbm_register_filt_filt&(1<<sbk_in_track))==0); // Second: wait until track is occupied again PROCESS_WAIT_UNTIL((gbm_register_filt_filt&(1<<sbk_in_track))!=0); #else while ((gbm_register_filt_filt&(1<<sbk_in_track))!=0) { PROCESS_PAUSE(); } while ((gbm_register_filt_filt&(1<<sbk_in_track))==0) { PROCESS_PAUSE(); } #endif if ((sbk_in_track!=sbk_out_track) && (sbk_mode==SBK_MODE_FSS)) { // --> FSS aktivieren via LN --> 120612: nicht nötig, da ständig aktiv shiftreg |= (1<<RELAIS_FSS); shiftreg_out16(shiftreg,1); etimer_set(&sbk_in_timer, 3*CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&sbk_in_timer)); } //PT_WAIT_UNTIL(pt, (TickGet()-sbk_in_timer) >= 3*TICKS_PER_SECOND); shiftreg &= ~((1<<RELAIS_G1_IN) |(1<<RELAIS_G2_IN) |(1<<RELAIS_G3_IN) |(1<<RELAIS_G4_IN) |(1<<RELAIS_G5_IN) |(1<<RELAIS_G6_IN) |(1<<RELAIS_FSS)); // FSS deaktivieren (oder automatisch nach Ablauf von Timeout) shiftreg_out16(shiftreg,1); sbk_in_track = 0; process_poll(&sbk_out_process); } 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}; static int i ; #if WITH_COMPOWER static int print = 0; #endif PROCESS_BEGIN(); //powertrace_start(CLOCK_SECOND * 2); //elnaz cc2420_set_txpower(19); 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); //for(i = 0 ; i<8 ; i++) //{ while(seq<100) { 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 } seq = 0; etimer_stop(&periodic); etimer_set(&wait, WAIT_INTERVAL); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER); etimer_set(&periodic, SEND_INTERVAL); // } // end loop on Tx PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { PROCESS_BEGIN() ; PROCESS_PAUSE() ; set_global_address(); // senderStartTime = get_time_ms(); 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); 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)); // Initial value of nodeInf // Initial values nodeInf.sinkMinTX = 65535; stopCond = 0; static struct etimer et; //etimer_set(&et, CLOCK_SECOND * 1 + random_rand() % (CLOCK_SECOND * 1)); static struct etimer periodic; //etimer_set(&et, 2 * CLOCK_SECOND); int i; while (1) { // PROCESS_YIELD(); PROCESS_WAIT_EVENT() ; /* Send a packet every 30 seconds. */ if (etimer_expired(&periodic)) { i = 0; etimer_set(&periodic, CLOCK_SECOND * 2); etimer_set(&et, random_rand() % (CLOCK_SECOND * 2)); } if (stopCond == 1) { break; } // if (ev == tcpip_event) { tcpip_handler(); } else if (etimer_expired(&et)) { client_send(); } } PROCESS_END(); }
PROCESS_THREAD(er_example_server, ev, data) { PROCESS_BEGIN(); PROCESS_PAUSE(); PRINTF("Starting Erbium Example Server\n"); #ifdef RF_CHANNEL PRINTF("RF channel: %u\n", RF_CHANNEL); #endif #ifdef IEEE802154_PANID PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID); #endif PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* Initialize the REST engine. */ rest_init_engine(); /* * Bind the resources to their Uri-Path. * WARNING: Activating twice only means alternate path, not two instances! * All static variables are the same for each URI path. */ rest_activate_resource(&res_hello, "test/hello"); /* rest_activate_resource(&res_mirror, "debug/mirror"); */ /* rest_activate_resource(&res_chunks, "test/chunks"); */ /* rest_activate_resource(&res_separate, "test/separate"); */ rest_activate_resource(&res_push, "test/push"); /* rest_activate_resource(&res_event, "test/serial"); */ /* rest_activate_resource(&res_sub, "test/sub"); */ /* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */ #if PLATFORM_HAS_LEDS /* rest_activate_resource(&res_leds, "actuators/leds"); */ rest_activate_resource(&res_toggle, "actuators/toggle"); #endif #if PLATFORM_HAS_LIGHT rest_activate_resource(&res_light, "sensors/light"); SENSORS_ACTIVATE(light_sensor); #endif #if PLATFORM_HAS_BATTERY rest_activate_resource(&res_battery, "sensors/battery"); SENSORS_ACTIVATE(battery_sensor); #endif #if PLATFORM_HAS_TEMPERATURE rest_activate_resource(&res_temperature, "sensors/temperature"); SENSORS_ACTIVATE(temperature_sensor); #endif /* #if PLATFORM_HAS_RADIO rest_activate_resource(&res_radio, "sensors/radio"); SENSORS_ACTIVATE(radio_sensor); #endif #if PLATFORM_HAS_SHT11 rest_activate_resource(&res_sht11, "sensors/sht11"); SENSORS_ACTIVATE(sht11_sensor); #endif */ #if PLATFORM_HAS_PRESSURE rest_activate_resource(&res_pressure, "sensors/pressure"); SENSORS_ACTIVATE(pressure_sensor); #endif #if PLATFORM_HAS_GYROSCOPE rest_activate_resource(&res_gyros, "sensors/gyros"); SENSORS_ACTIVATE(gyr_sensor); #endif #if PLATFORM_HAS_ACCELEROMETER rest_activate_resource(&res_accel, "sensors/accel"); SENSORS_ACTIVATE(acc_sensor); #endif #if PLATFORM_HAS_MAGNETOMETER rest_activate_resource(&res_magne, "sensors/magne"); SENSORS_ACTIVATE(mag_sensor); #endif /* Define application-specific events here. */ while(1) { PROCESS_WAIT_EVENT(); if(ev == serial_line_event_message) { res_serial_data = (char*)data; /* Call the event_handler for this application-specific event. */ res_event.trigger(); /* Also call the separate response example handler. */ // res_separate.resume(); } } /* while (1) */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_BEGIN(); uint32_t err_code; // Initialize the SoftDevice handler module. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); APP_ERROR_CHECK(err_code); // Register with the SoftDevice handler module for BLE events. err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch); APP_ERROR_CHECK(err_code); ble_gap_conn_sec_mode_t sec_mode; char name_buffer[9]; sprintf(name_buffer, "%08X",(unsigned int) NRF_FICR->DEVICEID[0]); BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)name_buffer, strlen(name_buffer)); APP_ERROR_CHECK(err_code); ble_advdata_t advdata; uint8_t flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; ble_advdata_service_data_t service_data[2]; uint8_t battery_data = 98;//battery_level_get(); uint32_t temperature_data = 0xFE001213; service_data[0].service_uuid = BLE_UUID_BATTERY_SERVICE; service_data[0].data.size = sizeof(battery_data); service_data[0].data.p_data = &battery_data; service_data[1].service_uuid = BLE_UUID_HEALTH_THERMOMETER_SERVICE; service_data[1].data.size = sizeof(temperature_data); service_data[1].data.p_data = (uint8_t *) &temperature_data; // Build and set advertising data memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags.size = sizeof(flags); advdata.flags.p_data = &flags; advdata.service_data_count = 2; advdata.p_service_data_array = service_data; err_code = ble_advdata_set(&advdata, NULL); APP_ERROR_CHECK(err_code); ble_gap_adv_params_t adv_params; // Start advertising memset(&adv_params, 0, sizeof(adv_params)); adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND; adv_params.p_peer_addr = NULL; adv_params.fp = BLE_GAP_ADV_FP_ANY; adv_params.interval = ADV_INTERVAL; adv_params.timeout = ADV_TIMEOUT_IN_SECONDS; err_code = sd_ble_gap_adv_start(&adv_params); APP_ERROR_CHECK(err_code); leds_off(LEDS_ALL); leds_on(LEDS_RED); PROCESS_PAUSE(); etimer_set(&et_hello, CLOCK_SECOND/2); rand_val = 0; blinks = 0; while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { sd_rand_application_vector_get(&blinks,1); printf("Sensor says #%X\n", (unsigned int) blinks); etimer_reset(&et_hello); } } PROCESS_END(); }
/*---------------------------------------------------------------*/ PROCESS_THREAD(null_app_process, ev, data) { PROCESS_BEGIN(); printf("Sine Wave Started\n"); serial_shell_init(); remote_shell_init(); shell_reboot_init(); shell_blink_init(); shell_sky_init(); app_conn_open(&nullApp_callback); /* if (node_id != 0) etimer_set(&et,16); else etimer_set(&et,200); */ if (node_id != 0) { ctimer_set(&ct,10,sample_fun,(void*)NULL); /* while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); uint8_t i; for(i = 0; i < 6; i++) { data_buf[i] = sinI(counter); counter++; } app_conn_send((uint8_t *)data_buf,6*sizeof(int8_t)); } */ } /* else { while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); } } */ /* int8_t data_buf[6] = {0}; static struct etimer et; //static uint16_t counter = 0; uint8_t i; etimer_set(&et,(unsigned long)102); if (node_id != 0) { while(1) { //etimer_set(&et,(unsigned long)102); //printf("here 1\n"); printf("1timer start %lu interval %lu process %s\n",et.timer.start,et.timer.interval,et.p->name); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); printf("if expired %u\n",etimer_expired(&et)); etimer_reset(&et); printf("2timer start %lu interval %lu process %s\n",et.timer.start,et.timer.interval,et.p->name); printf("next timer start %lu interval %lu process %s\n",et.next->timer.start,et.next->timer.interval,et.next->p->name); for(i = 0; i < 6; i++) { data_buf[i] = sinI(counter); counter++; } printf("here 3\n"); app_conn_send((uint8_t *)data_buf,6*sizeof(int8_t)); printf("here 4\n"); } } */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(clock_test_process, ev, data) { PROCESS_BEGIN(); etimer_set(&et, 2 * CLOCK_SECOND); PROCESS_YIELD(); #if TEST_CLOCK_DELAY_USEC printf("clock_delay_usec test, (10,000 x i) usec:\n"); i = 1; while(i < 7) { start_count = RTIMER_NOW(); clock_delay_usec(10000 * i); end_count = RTIMER_NOW(); diff = end_count - start_count; printf("Requested: %u usec, Real: %u rtimer ticks = ~%u us\n", 10000 * i, diff, diff * 64); i++; } #endif #if TEST_RTIMER printf("Rtimer Test, 1 sec (%u rtimer ticks):\n", RTIMER_SECOND); i = 0; while(i < 5) { etimer_set(&et, 2 * CLOCK_SECOND); printf("=======================\n"); ct = clock_time(); rt_now = RTIMER_NOW(); rt_for = rt_now + RTIMER_SECOND; printf("Now=%u (clock = %u) - For=%u\n", rt_now, ct, rt_for); if(rtimer_set(&rt, rt_for, 1, (rtimer_callback_t) rt_callback, NULL) != RTIMER_OK) { printf("Error setting\n"); } PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); i++; } #endif #if TEST_ETIMER printf("Clock tick and etimer test, 1 sec (%u clock ticks):\n", CLOCK_SECOND); i = 0; while(i < 10) { etimer_set(&et, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); count = clock_time(); printf("%u ticks\n", count); leds_toggle(LEDS_RED); i++; } #endif #if TEST_CLOCK_SECONDS printf("Clock seconds test (5s):\n"); i = 0; while(i < 10) { etimer_set(&et, 5 * CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); sec = clock_seconds(); printf("%lu seconds\n", sec); leds_toggle(LEDS_GREEN); i++; } #endif printf("Done!\n"); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(remote_grove_gyro_process, ev, data) { PROCESS_BEGIN(); uint8_t aux; /* Use Contiki's sensor macro to enable the sensor */ SENSORS_ACTIVATE(grove_gyro); /* The sensor itself is in low-power mode, to power on just the sensor and not * the 3 gyroscope axis use GROVE_GYRO_SENSOR. Alternatively the value * GROVE_GYRO_ALL could also be used to power everything at once */ grove_gyro.configure(GROVE_GYRO_POWER_ON, GROVE_GYRO_SENSOR); /* Read back the configured sensor I2C address to check if the sensor is * working OK, this is the only case in which the value() returns a value */ aux = grove_gyro.value(GROVE_GYRO_ADDR); if(aux == GROVE_GYRO_EXPECTED_ADDR) { printf("Gyro sensor started with addr 0x%02X\n", GROVE_GYRO_EXPECTED_ADDR); } else { printf("Gyro sensor with unrecognized address 0x%02X\n", aux); PROCESS_EXIT(); } /* Register the interrupt handler */ GROVE_GYRO_REGISTER_INT(gyro_interrupt_callback); /* The gyroscope sensor should be on now but the three gyroscope axis should * be off, to enable a single axis or any combination of the 3 you can use as * argument either GROVE_GYRO_X, GROVE_GYRO_Y, GROVE_GYRO_Z. To enable or * disable the three axis alternatively use GROVE_GYRO_XYZ */ grove_gyro.configure(GROVE_GYRO_POWER_ON, GROVE_GYRO_XYZ); /* Calibrate the sensor taking 200 samples every 5ms for the zero-point offset * value, this has to be done manually and is up to the user */ grove_gyro.configure(GROVE_GYRO_CALIBRATE_ZERO, 1); /* Enabling the data interrupt will feed data directly to the extern data * structure and notify us about it, depending on the sampling rate and * divisor this could generate many interrupts/second. A zero argument would * disable the interrupts */ grove_gyro.configure(GROVE_GYRO_DATA_INTERRUPT, 1); /* And periodically poll the sensor, values are in º/s */ while(1) { etimer_set(&et, SENSOR_READ_INTERVAL); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); /* This sensor has a different operation from others using Contiki's sensor * API, to make data acquisition we write the readings directly to the * extern data structure, allowing to write more than 1 value at the same * operation, and also allowing upon a data interrupt event to immediatly * access the data. The return value of the value() call is then the status * result of the read operation */ if(grove_gyro.value(GROVE_GYRO_XYZ) == GROVE_GYRO_SUCCESS) { /* Converted values with a 2-digit precision */ printf("Gyro: X: %u.%u, Y: %u.%u, Z: %u.%u\n", gyro_values.x / 100, gyro_values.x % 100, gyro_values.y / 100, gyro_values.y % 100, gyro_values.z / 100, gyro_values.z % 100); } else { printf("Error, enable the DEBUG flag in the grove-gyro driver for info,"); printf(" or check if the sensor is properly connected\n"); PROCESS_EXIT(); } if(grove_gyro.value(GROVE_GYRO_TEMP) == GROVE_GYRO_SUCCESS) { printf("Gyro: temperature %d.%02u C\n", gyro_values.temp / 100, gyro_values.temp % 100); } else { printf("Error, enable the DEBUG flag in the grove-gyro driver for info,"); printf(" or check if the sensor is properly connected\n"); PROCESS_EXIT(); } } PROCESS_END(); }
PROCESS_THREAD(test_RTC_process, ev, data) { PROCESS_BEGIN(); leds_off(LEDS_ALL); // Set the RTC time to be 12:34:56 on 30/1/15 // struct RTC_time t = { 0, // hundredths 0, // tenths 56, // seconds 34, // minutes 12, // hours 30, // day 01, // month 15 // year }; struct RTC_alarm q = { 10, // seconds 35, // minutes 12, // hours 30, // day 01 // month }; RTC_setTime(&t); // Alarm can be set with a callback // (or this can be NULL) RTC_setAlarm(&q, alarmCallback, RPT_MINUTE); int i = 0; while(1) { printf("GOING TO SLEEP\n"); clock_delay_msec(50); /* ------------ * Go to sleep * ------------ */ *CRM_SLEEP_CNTL = 0x71; // hibernate, keep all RAM pages, retain state, don't power GPIO, approx. 2kHz = 16.1uA while((*CRM_STATUS & 0x1) == 0) // wait for the sleep cycle to complete { continue; } *CRM_STATUS = 1; // write 1 to sleep_sync --- this clears the bit (it's a r1wc bit) and powers down /* ------------ * Wake up again * ------------ */ printf("AWAKE AGAIN\n"); for (i = 0; i < 2; i++) FLASH_LED(LEDS_ALL); PROCESS_YIELD(); RTC_getTime(&t); printf("%02d/%02d/%02d %02d:%02d:%02d.%d%d\n", t.day, t.month, t.year, t.hours, t.minutes, t.seconds, t.tenths, t.hundredths); } PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(simpletelnet_process, ev, data) { struct ctk_widget *w; int sendlen; PROCESS_BEGIN(); ctk_window_new(&telnetwindow, TELNET_WINDOW_WIDTH, TELNET_WINDOW_HEIGHT, "Simple telnet"); strcpy(telnetport, "23"); CTK_WIDGET_ADD(&telnetwindow, &telnethostlabel); CTK_WIDGET_ADD(&telnetwindow, &telnetportlabel); CTK_WIDGET_ADD(&telnetwindow, &telnethosttextentry); CTK_WIDGET_ADD(&telnetwindow, &telnetporttextentry); CTK_WIDGET_ADD(&telnetwindow, &telnetconnectbutton); CTK_WIDGET_ADD(&telnetwindow, &telnetdisconnectbutton); CTK_WIDGET_ADD(&telnetwindow, &telnetlinetextentry); CTK_WIDGET_ADD(&telnetwindow, &telnetsendbutton); CTK_WIDGET_ADD(&telnetwindow, &telnetsep1); CTK_WIDGET_ADD(&telnetwindow, &telnettextarea); CTK_WIDGET_ADD(&telnetwindow, &telnetsep2); CTK_WIDGET_ADD(&telnetwindow, &telnetstatus); CTK_WIDGET_FOCUS(&telnetwindow, &telnethosttextentry); ctk_window_open(&telnetwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == ctk_signal_button_activate) { w = (struct ctk_widget *)data; if(w == (struct ctk_widget *)&telnetsendbutton) { strcpy(sendline, telnetline); sendlen = (int)strlen(sendline); petsciiconv_toascii(sendline, sendlen); sendline[sendlen++] = ISO_CR; sendline[sendlen++] = ISO_NL; if(telnet_send(&ts_appstate, sendline, sendlen)) { /* Could not send. */ ctk_label_set_text(&telnetstatus, "Could not send"); ctk_window_redraw(&telnetwindow); /* } else {*/ /* Could send */ } } else if(w == (struct ctk_widget *)&telnetdisconnectbutton) { telnet_close(&ts_appstate); show("Closing..."); } else if(w == (struct ctk_widget *)&telnetconnectbutton) { connect(); ctk_window_redraw(&telnetwindow); } #if UIP_UDP } else if(ev == resolv_event_found) { if(strcmp(data, telnethost) == 0) { if(resolv_lookup(telnethost) != NULL) { connect(); } else { show("Host not found"); } } #endif /* UIP_UDP */ } else if( #if CTK_CONF_WINDOWCLOSE ev == ctk_signal_window_close || #endif /* CTK_CONF_WINDOWCLOSE */ ev == PROCESS_EVENT_EXIT) { process_exit(&simpletelnet_process); ctk_window_close(&telnetwindow); LOADER_UNLOAD(); } else if(ev == tcpip_event) { telnet_app(data); } } PROCESS_END(); }
PROCESS_THREAD(felicia_main, ev, data) { static struct etimer timer; PROCESS_BEGIN(); /* Initialize the CoAP server and activate resources */ rest_init_engine(); #if PLATFORM_HAS_LEDS #ifdef RESOURCE_LED0_CONF_LED rest_activate_resource(&resource_led, (char *)"led"); rest_activate_resource(&resource_led0, (char *)"led/0"); #endif #ifdef RESOURCE_LED1_CONF_LED rest_activate_resource(&resource_led1, (char *)"led/1"); #endif #endif rest_activate_resource(&resource_ipv6_neighbors, (char *)"ipv6/neighbors"); rest_activate_resource(&resource_rpl_info, (char *)"rpl-info"); rest_activate_resource(&resource_rpl_parent, (char *)"rpl-info/parent"); rest_activate_resource(&resource_rpl_rank, (char *)"rpl-info/rank"); rest_activate_resource(&resource_rpl_link_metric, (char *)"rpl-info/link-metric"); #if PLATFORM_HAS_SLIDE_SWITCH SENSORS_ACTIVATE(slide_switch_sensor); #endif #if PLATFORM_HAS_BUTTON SENSORS_ACTIVATE(button_sensor); rest_activate_resource(&resource_push_button_event, (char *)"push-button"); #endif #if PLATFORM_HAS_SENSORS rest_activate_resource(&resource_temperature, (char *)"temperature"); #endif PROCESS_PAUSE(); #if WITH_WEBSERVER process_start(&node_webserver_simple_process, NULL); #endif #if WITH_IPSO /* Initialize the OMA LWM2M engine */ lwm2m_engine_init(); /* Register default LWM2M objects */ lwm2m_engine_register_default_objects(); /* Register default IPSO objects */ ipso_objects_init(); setup_lwm2m_servers(); #endif while(1) { etimer_set(&timer, CLOCK_SECOND * 5); PROCESS_WAIT_EVENT(); #if PLATFORM_HAS_BUTTON if(ev == sensors_event && data == &button_sensor) { resource_push_button_event.trigger(); PRINTF("Button pressed!\n"); } #endif #if PLATFORM_HAS_SLIDE_SWITCH if(ev == sensors_event && data == &slide_switch_sensor) { PRINTF("Sliding switch is %s\n", slide_switch_sensor.value(0) ? "on" : "off"); } #endif } PROCESS_END(); }
PROCESS_THREAD(spirit_radio_process, ev, data) { PROCESS_BEGIN(); PRINTF("Spirit1: process started\n"); while(1) { int len; PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL); PRINTF("Spirit1: polled\n"); packetbuf_clear(); len = spirit_radio_read(packetbuf_dataptr(), PACKETBUF_SIZE); if(len > 0) { #if NULLRDC_CONF_802154_AUTOACK /* Check if the packet has an ACK request */ frame802154_t info154; if(len > ACK_LEN && frame802154_parse((char*)packetbuf_dataptr(), len, &info154) != 0) { if(info154.fcf.frame_type == FRAME802154_DATAFRAME && info154.fcf.ack_required != 0 && rimeaddr_cmp((rimeaddr_t *)&info154.dest_addr, &rimeaddr_node_addr)) { /* Send an ACK packet */ uint8_t ack_frame[ACK_LEN] = { FRAME802154_ACKFRAME, 0x00, info154.seq }; spirit1_strobe(SPIRIT1_STROBE_FTX); SpiritPktBasicSetPayloadLength((uint16_t) ACK_LEN); SpiritSpiWriteLinearFifo((uint16_t) ACK_LEN, (uint8_t *) ack_frame); SpiritSetReadyState(); spirit1_strobe(SPIRIT1_STROBE_TX); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_TX, 1 * RTIMER_SECOND/1000); BUSYWAIT_UNTIL(SPIRIT1_STATUS() != SPIRIT1_STATE_TX, 1 * RTIMER_SECOND/1000); ACKPRINTF("debug_ack: sent ack %d\n", ack_frame[2]); } } #endif /* NULLRDC_CONF_802154_AUTOACK */ packetbuf_set_datalen(len); NETSTACK_RDC.input(); } if(!IS_RXBUF_EMPTY()){ process_poll(&spirit_radio_process); } if(interrupt_callback_wants_poll) { spirit1_interrupt_callback(); if(SPIRIT1_STATUS() == SPIRIT1_STATE_READY) { spirit1_strobe(SPIRIT1_STROBE_RX); BUSYWAIT_UNTIL(SPIRIT1_STATUS() == SPIRIT1_STATE_RX, 1 * RTIMER_SECOND/1000); } } } PROCESS_END(); }
PROCESS_THREAD(sbk_out_process, ev, data) { PROCESS_BEGIN(); while (1) { PROCESS_WAIT_UNTIL(sbk_out_track!=0); if (sbk_in_track==sbk_out_track) DBG("Durchfahrt auf Gleis "); else DBG("Ausfahrt von Gleis "); DBG('0' + sbk_out_track); DBG("\r\n"); PROCESS_WAIT_UNTIL(sbk_out_track!=sbk_in_track); switch (sbk_out_track) { case 1: shiftreg |= (1<<RELAIS_G1_OUT); break; case 2: shiftreg |= (1<<RELAIS_G2_OUT); break; case 3: shiftreg |= (1<<RELAIS_G3_OUT); break; case 4: shiftreg |= (1<<RELAIS_G4_OUT); break; case 5: shiftreg |= (1<<RELAIS_G5_OUT); break; case 6: shiftreg |= (1<<RELAIS_G6_OUT); break; default: break; } shiftreg_out16(shiftreg,1); // First: wait until track is occupied (allows setting route even when track is empty) while ((gbm_register_filt_filt&(1<<sbk_out_track))==0) { PROCESS_PAUSE(); } // Second: wait until track is free again. while ((gbm_register_filt_filt&(1<<sbk_out_track))!=0) { PROCESS_PAUSE(); } /* while (1) { if (!gbm_register_filt&(1<<TRACK2GBM(sbk_out_track))) { break; } PT_YIELD(pt); } */ etimer_set(&sbk_out_timer, 20*CLOCK_SECOND); //sbk_out_timer = TickGet(); // Wait for timeout before resetting sbk exit (this can be overridden by the upper control system) //PT_WAIT_UNTIL(pt, (TickGet()-sbk_out_timer) >= 20*TICKS_PER_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&sbk_out_timer)); shiftreg &= ~((1<<RELAIS_G1_OUT) |(1<<RELAIS_G2_OUT) |(1<<RELAIS_G3_OUT) |(1<<RELAIS_G4_OUT) |(1<<RELAIS_G5_OUT) |(1<<RELAIS_G6_OUT)); shiftreg_out16(shiftreg,1); sbk_out_track = 0; process_poll(&sbk_in_process); } 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)); // printf("%d \n", CLOCK_SECOND); #if WITH_COMPOWER powertrace_sniff(POWERTRACE_ON); #endif configure_adc(); //etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { // tcpip_handler(); } //if(etimer_expired(&periodic)) { //PRINTF("Timer Expired "); //etimer_reset(&periodic); //} if(ev==event_data_ready) { /*if(counter == 33) { memmove(buf+2, buffer, 66); counter = 0; ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); //printf("Counter %d \n",counter); }*/ #if WITH_COMPOWER if (print == 0) { powertrace_print("#P"); } if (++print == 3) { print = 0; } #endif } } PROCESS_END(); }
PROCESS_THREAD(component_topologycontrol, ev, data) { PROCESS_BEGIN(); memb_init(&memb_nodelist); list_init(list_nodelist); BOOT_COMPONENT_WAIT(component_topologycontrol); static struct etimer waittime; etimer_set(&waittime, CLOCK_SECOND * COMPONENT_TOPOLOGYCONTROL_LMST_UPDATEINTERVAL); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&waittime)); etimer_reset(&waittime); // with a large neighbourhood the algorithm may take a looong time, so stop the watchdog // that the node is not rebooted because the CPU thinks there's an endless loop running watchdog_stop(); // Prim algorithm // (connects edge of every node except the graph's root node - the node this code is running on= _lmst_nodelist_reconstruct(); while(_lmst_nodelist_hasunconnected()) { // find best edge according to PRIM and LMST algorithm neighbor_t *edge_actual, *edge_best = NULL; for(edge_actual = list_head(component_neighbordiscovery_neighbors()); edge_actual != NULL; edge_actual = list_item_next(edge_actual)) { bool node1_connected = _lmst_nodelist_isconnected(edge_actual->node1) && !_lmst_nodelist_isconnected(edge_actual->node2); bool node2_connected = _lmst_nodelist_isconnected(edge_actual->node2) && !_lmst_nodelist_isconnected(edge_actual->node1); if(node1_connected ^ node2_connected) { bool criteria1 = (edge_best == NULL || MAX(edge_actual->weight_node1_to_node2, edge_actual->weight_node2_to_node1) < MAX(edge_best->weight_node1_to_node2, edge_best->weight_node2_to_node1)); bool criteria2 = (MAX(edge_actual->weight_node1_to_node2, edge_actual->weight_node2_to_node1) == MAX(edge_best->weight_node1_to_node2, edge_best->weight_node2_to_node1) && networkaddr_cmp(NETWORKADDR_MAX(edge_actual), NETWORKADDR_MAX(edge_best)) < 0); if(criteria1 || criteria2) edge_best = edge_actual; } } if(edge_best == NULL) { printf("ERROR[topologycontrol-lmst]: no edge for spanning tree found\n"); watchdog_reboot(); // we would end in an endless loop } _lmst_nodelist_connect(edge_best); } #if DEBUG node_t *item_node; PRINTF("DEBUG: [topologycontrol-lmst] spanning tree: "); for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) { if(networkaddr_equal(item_node->address, networkaddr_node_addr())) continue; PRINTF("%s<->", networkaddr2string_buffered(item_node->edge->node1)); PRINTF("%s", networkaddr2string_buffered(item_node->edge->node2)); PRINTF("%s", item_node->next == NULL ? "\n" : ", "); } #endif // ignore every node which is not directly connected in the spanning tree node_t *node; for(node = list_head(list_nodelist); node != NULL; node = list_item_next(node)) { if(!networkaddr_equal(node->address, networkaddr_node_addr()) && !networkaddr_equal(node->edge->node1, networkaddr_node_addr()) && !networkaddr_equal(node->edge->node2, networkaddr_node_addr())) { component_network_ignoredlinks_add(node->address); } } watchdog_start(); // LMST is only run once because if links have been ignored they are no longer available in the neighbor discovery // and hence a spanning tree can no longer be built PRINTF("DEBUG: [topologycontrol-lmst] LMST algorithm is finished and will run no more\n"); break; } PROCESS_END(); }
/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(vnc_process, ev, data) { unsigned short x, y; unsigned char xc, yc; PROCESS_BEGIN(); ctk_window_new(&mainwindow, 36, HEIGHT, "VNC client"); ctk_window_move(&mainwindow, 0, 0); CTK_WIDGET_ADD(&mainwindow, &hosttextentry); CTK_WIDGET_FOCUS(&mainwindow, &hosttextentry); CTK_WIDGET_ADD(&mainwindow, &porttextentry); CTK_WIDGET_ADD(&mainwindow, &connectbutton); CTK_WIDGET_ADD(&mainwindow, &sep1); CTK_WIDGET_ADD(&mainwindow, &vncbitmap); CTK_WIDGET_ADD(&mainwindow, &leftbutton); CTK_WIDGET_ADD(&mainwindow, &upbutton); CTK_WIDGET_ADD(&mainwindow, &downbutton); CTK_WIDGET_ADD(&mainwindow, &rightbutton); vnc_draw_init(); ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == ctk_signal_button_activate) { if(data == (process_data_t)&connectbutton) { connect(); } } else if(ev == ctk_signal_window_close) { process_exit(&vnc_process); LOADER_UNLOAD(); } else if(ev == resolv_event_found) { if(strcmp(data, host) == 0) { if(resolv_lookup(host, NULL) == RESOLV_STATUS_CACHED) { connect(); } else { show("Host not found"); } } } else if(ev == ctk_signal_pointer_move) { /* Check if pointer is within the VNC viewer area */ x = ctk_mouse_x(); y = ctk_mouse_y(); xc = ctk_mouse_xtoc(x); yc = ctk_mouse_ytoc(y); if(xc >= 2 && yc >= 2 && xc < 2 + VNC_VIEWPORT_WIDTH / 8 && yc < 2 + VNC_VIEWPORT_HEIGHT / 8) { VNC_VIEWER_POST_POINTER_EVENT(x, y, 0); } } else if(ev == tcpip_event) { vnc_viewer_appcall(data); } } PROCESS_END(); }
PROCESS_THREAD(usb_process, ev , data) { PROCESS_BEGIN(); PRINTF("USB process started\r\n"); while(1) { PROCESS_WAIT_EVENT(); if (ev == PROCESS_EVENT_EXIT) break; if (ev == PROCESS_EVENT_POLL) { unsigned int events = usb_arch_get_global_events(); if (events) { if (events & USB_EVENT_RESET) { submit_setup(); usb_configuration_value = 0; notify_user(USB_EVENT_RESET); } if (events & USB_EVENT_SUSPEND) { notify_user(USB_EVENT_SUSPEND); } if (events & USB_EVENT_RESUME) { notify_user(USB_EVENT_RESUME); } } events = usb_get_ep_events(0); if (events) { if ((events & USB_EP_EVENT_NOTIFICATION) && !(ctrl_buffer.flags & USB_BUFFER_SUBMITTED)) { /* PRINTF("Endpoint 0\r\n"); */ if (ctrl_buffer.flags & USB_BUFFER_FAILED) { /* Something went wrong with the buffer, just wait for a new SETUP packet */ PRINTF("Discarded\r\n"); submit_setup(); } else if (ctrl_buffer.flags & USB_BUFFER_SETUP) { struct USBRequestHandlerHook *hook = usb_request_handler_hooks; PRINTF("Setup\r\n"); #if 0 { unsigned int i; for (i = 0; i< 8; i++) PRINTF(" %02x", ((unsigned char*)&usb_setup_buffer)[i]); PRINTF("\r\n"); } #endif while(hook) { const struct USBRequestHandler *handler = hook->handler; /* Check if the handler matches the request */ if (((handler->request_type ^ usb_setup_buffer.bmRequestType) & handler->request_type_mask) == 0 && ((handler->request ^ usb_setup_buffer.bRequest) & handler->request_mask) == 0) { if (handler->handler_func()) break; } hook = hook->next; } if (!hook) { /* No handler found */ usb_error_stall(); PRINTF("Unhandled setup: %02x %02x %04x %04x %04x\r\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest, usb_setup_buffer.wValue, usb_setup_buffer.wIndex, usb_setup_buffer.wLength); } /* Check if any handler stalled the pipe, if so prepare for next setup */ if (error_stall) { error_stall = 0; submit_setup(); } } else { if (ctrl_buffer.id == IN_ID) { /* Receive status stage */ PRINTF("Status OUT\r\n"); ctrl_buffer.flags = USB_BUFFER_NOTIFY; ctrl_buffer.next = NULL; ctrl_buffer.data = NULL; ctrl_buffer.left = 0; ctrl_buffer.id = STATUS_OUT_ID; usb_submit_recv_buffer(0,&ctrl_buffer); } else if (ctrl_buffer.id == STATUS_OUT_ID) { PRINTF("Status OUT done\r\n"); submit_setup(); } else if (ctrl_buffer.id == STATUS_IN_ID) { PRINTF("Status IN done\r\n"); if (usb_flags & USB_FLAG_ADDRESS_PENDING) { while(usb_send_pending(0)); usb_arch_set_address(LOW_BYTE(usb_setup_buffer.wValue)); usb_flags &= ~USB_FLAG_ADDRESS_PENDING; } submit_setup(); } else if (ctrl_buffer.id == OUT_ID) { PRINTF("OUT\r\n"); if (data_callback) { data_callback(ctrl_data, ctrl_data_len- ctrl_buffer.left); } else { usb_send_ctrl_status(); } } } } } } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_server_process, ev, data) { PROCESS_BEGIN(); PROCESS_PAUSE(); SENSORS_ACTIVATE(button_sensor); PRINTF("UDP server started\n"); #if UIP_CONF_ROUTER uip_ipaddr_t ipaddr; struct uip_ds6_addr *root_if; /* The choice of server address determines its 6LoPAN header compression. * Obviously the choice made here must also be selected in udp-client.c. * * For correct Wireshark decoding using a sniffer, add the /64 prefix to the 6LowPAN protocol preferences, * e.g. set Context 0 to aaaa::. At present Wireshark copies Context/128 and then overwrites it. * (Setting Context 0 to aaaa::1111:2222:3333:4444 will report a 16 bit compressed address of aaaa::1111:22ff:fe33:xxxx) * Note Wireshark's IPCMV6 checksum verification depends on the correct uncompressed addresses. */ #if 0 /* Mode 1 - 64 bits inline */ uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 1); #elif 1 /* Mode 2 - 16 bits inline */ uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0x00ff, 0xfe00, 1); #else /* Mode 3 - derived from link local (MAC) address */ uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); #endif uip_ds6_addr_add(&ipaddr, 0, ADDR_MANUAL); root_if = uip_ds6_addr_lookup(&ipaddr); if(root_if != NULL) { rpl_dag_t *dag; dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&ipaddr); uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); rpl_set_prefix(dag, &ipaddr, 64); PRINTF("created a new RPL dag\n"); } else { PRINTF("failed to create a new RPL DAG\n"); } #endif /* UIP_CONF_ROUTER */ print_local_addresses(); /* The data sink runs with a 100% duty cycle in order to ensure high packet reception rates. */ NETSTACK_MAC.off(1); server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL); if(server_conn == NULL) { PRINTF("No UDP connection available, exiting the process!\n"); PROCESS_EXIT(); } udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT)); PRINTF("Created a server connection with remote address "); PRINT6ADDR(&server_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(server_conn->lport), UIP_HTONS(server_conn->rport)); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } else if (ev == sensors_event && data == &button_sensor) { PRINTF("Initiaing global repair\n"); rpl_repair_root(RPL_DEFAULT_INSTANCE); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rest_server_example, ev, data) { PROCESS_BEGIN(); PRINTF("Starting Erbium Example Server\n"); #ifdef RF_CHANNEL PRINTF("RF channel: %u\n", RF_CHANNEL); #endif #ifdef IEEE802154_PANID PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID); #endif PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* if static routes are used rather than RPL */ #if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE) set_global_address(); configure_routing(); #endif /* Initialize the REST engine. */ rest_init_engine(); /* Activate the application-specific resources. */ #if REST_RES_HELLO rest_activate_resource(&resource_helloworld); #endif #if REST_RES_MIRROR rest_activate_resource(&resource_mirror); #endif #if REST_RES_CHUNKS rest_activate_resource(&resource_chunks); #endif #if REST_RES_PUSHING rest_activate_periodic_resource(&periodic_resource_pushing); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT rest_activate_event_resource(&resource_event); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3 /* No pre-handler anymore, user coap_separate_accept() and coap_separate_reject(). */ rest_activate_resource(&resource_separate); #endif #if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3)) SENSORS_ACTIVATE(button_sensor); #endif #if REST_RES_SUB rest_activate_resource(&resource_sub); #endif #if defined (PLATFORM_HAS_LEDS) #if REST_RES_LEDS rest_activate_resource(&resource_leds); #endif #if REST_RES_TOGGLE rest_activate_resource(&resource_toggle); #endif #endif /* PLATFORM_HAS_LEDS */ #if defined (PLATFORM_HAS_LIGHT) && REST_RES_LIGHT SENSORS_ACTIVATE(light_sensor); rest_activate_resource(&resource_light); #endif #if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY SENSORS_ACTIVATE(battery_sensor); rest_activate_resource(&resource_battery); #endif #if defined (PLATFORM_HAS_RADIO) && REST_RES_RADIO SENSORS_ACTIVATE(radio_sensor); rest_activate_resource(&resource_radio); #endif /* Define application-specific events here. */ while(1) { PROCESS_WAIT_EVENT(); #if defined (PLATFORM_HAS_BUTTON) if(ev == sensors_event && data == &button_sensor) { PRINTF("BUTTON\n"); #if REST_RES_EVENT /* Call the event_handler for this application-specific event. */ event_event_handler(&resource_event); #endif #if REST_RES_SEPARATE && WITH_COAP>3 /* Also call the separate response example handler. */ separate_finalize_handler(); #endif } #endif /* PLATFORM_HAS_BUTTON */ } /* while (1) */ PROCESS_END(); }
PROCESS_THREAD(hello_world_process, ev, data) { //static struct etimer timer; PROCESS_BEGIN(); //begintimer(); //etimer_set(&timer, CLOCK_CONF_SECOND * 1); uint32_t ui32PrevCount = 0; // // Set the clocking to run directly from the external crystal/oscillator. // (no ext 32k osc, no internal osc) // //SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ); // // Set IO clock to the same as system clock // //SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ); // // The Timer0 peripheral must be enabled for use. // SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer operation. // //InitConsole(); // // Display the example setup on the console. // printf(" 16-Bit Timer Interrupt ->\n\r"); printf(" Timer = Timer0B\n\r"); printf(" Mode = Periodic\n\r"); printf(" Number of interrupts = %d \n\r", NUMBER_OF_INTS); printf(" Rate = 1ms\n\r"); // // Configure Timer0B as a 16-bit periodic timer. // TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR | GPTIMER_CFG_A_PERIODIC | GPTIMER_CFG_B_PWM); /* TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR | GPTIMER_CFG_A_PWM | GPTIMER_CFG_B_PWM); */ // // Set the Timer0B load value to 1ms. // TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, sys_ctrl_get_sys_clock() / 100 ); // TimerLoadSet(GPTIMER0_BASE, GPTIMER_B, SYS_CTRL_32MHZ ); // // The following call will result in a dynamic interrupt table being used. // The table resides in RAM. // Alternatively SysTickIntHandler can be statically registred in your // application. // TimerIntRegister(GPTIMER0_BASE, GPTIMER_B, Timer0BIntHandler); // // Enable processor interrupts. // //IntMasterEnable(); INTERRUPTS_ENABLE(); // // Configure the Timer0B interrupt for timer timeout. // TimerIntEnable(GPTIMER0_BASE, GPTIMER_TIMB_TIMEOUT); // // Enable the Timer0B interrupt on the processor (NVIC). // IntEnable(INT_TIMER0B); // // Initialize the interrupt counter. // g_ui32Counter = 0; // // Enable Timer0B. // TimerEnable(GPTIMER0_BASE, GPTIMER_B); // // Loop forever while the Timer0B runs. // while(1) { // // If the interrupt count changed, print the new value // if(ui32PrevCount != g_ui32Counter) { // // Print the periodic interrupt counter. // printf("Number of interrupts: %d\r", g_ui32Counter); ui32PrevCount = g_ui32Counter; } } /* while(1) { //PROCESS_YIELD(); //if(ev == PROCESS_EVENT_TIMER) { printf(" Hello Hi \n\r" ); //etimer_set(&timer, CLOCK_SECOND); //} } */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_read_process, ev, data) { static int fd = 0; static int block_size = MAX_BLOCKSIZE; char *next; char filename[MAX_FILENAME_LEN]; int len; int offset = 0; char buf[MAX_BLOCKSIZE]; struct shell_input *input; PROCESS_EXITHANDLER(cfs_close(fd)); PROCESS_BEGIN(); if(data != NULL) { next = strchr(data, ' '); if(next == NULL) { strncpy(filename, data, sizeof(filename)); } else { len = (int)(next - (char *)data); if(len <= 0) { shell_output_str(&read_command, "read: filename too short: ", data); PROCESS_EXIT(); } if(len > MAX_FILENAME_LEN) { shell_output_str(&read_command, "read: filename too long: ", data); PROCESS_EXIT(); } memcpy(filename, data, len); filename[len] = 0; offset = shell_strtolong(next, NULL); next++; next = strchr(next, ' '); if(next != NULL) { block_size = shell_strtolong(next, NULL); if(block_size > MAX_BLOCKSIZE) { shell_output_str(&read_command, "read: block size too large: ", data); PROCESS_EXIT(); } } } fd = cfs_open(filename, CFS_READ); cfs_seek(fd, offset, CFS_SEEK_SET); if(fd < 0) { shell_output_str(&read_command, "read: could not open file for reading: ", filename); } else { while(1) { len = cfs_read(fd, buf, block_size); if(len <= 0) { cfs_close(fd); PROCESS_EXIT(); } shell_output(&read_command, buf, len, "", 0); process_post(&shell_read_process, PROCESS_EVENT_CONTINUE, NULL); PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_CONTINUE || ev == shell_event_input); if(ev == shell_event_input) { input = data; /* printf("cat input %d %d\n", input->len1, input->len2);*/ if(input->len1 + input->len2 == 0) { cfs_close(fd); PROCESS_EXIT(); } } } } } PROCESS_END(); }
PROCESS_THREAD(i2c_process, ev, data) { static size_t i; #if (DEBUG==1) static u32_t i2c_ticks; #endif PROCESS_BEGIN(); vAHI_SiRegisterCallback(i2c_irq); vAHI_SiConfigure(true,true,I2C_400KHZ_FAST_MODE); while ((transaction=list_pop(transactions))) { #if (DEBUG==1) printf("i2c: to 0x%x start, %d written, %d read\n", transaction->addr, transaction->wrlen, transaction->rdlen); i2c_ticks = u32AHI_TickTimerRead(); #endif if (transaction->wrlen) { /* send slave address, start condition */ vAHI_SiWriteData8(transaction->addr); vAHI_SiSetCmdReg(E_AHI_SI_START_BIT, E_AHI_SI_NO_STOP_BIT, E_AHI_SI_NO_SLAVE_READ, E_AHI_SI_SLAVE_WRITE, E_AHI_SI_SEND_ACK, E_AHI_SI_NO_IRQ_ACK); PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_POLL); if (i2c_status==FAIL) { /* we only test for ACK on the first byte! */ if (transaction->cb) transaction->cb(false); #if (DEBUG==1) printf("i2c: to 0x%x failed, %d written, %d read in %d ticks\n", transaction->addr, transaction->wrlen, transaction->rdlen, u32AHI_TickTimerRead() - i2c_ticks); #endif continue; } } /* send wr data. If repeated_start and there is something to read, send no * stop condition, else send a stop condition on the last byte. */ for (i=0; i<transaction->wrlen; i++) { vAHI_SiWriteData8(transaction->buf[i]); vAHI_SiSetCmdReg(E_AHI_SI_NO_START_BIT, (transaction->wrlen!=0) ? E_AHI_SI_NO_STOP_BIT : transaction->rdlen, E_AHI_SI_NO_SLAVE_READ, E_AHI_SI_SLAVE_WRITE, E_AHI_SI_SEND_ACK, E_AHI_SI_NO_IRQ_ACK); PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_POLL); if (i2c_status==FAIL) { /* we only test for ACK on the first byte! */ if (transaction->cb) transaction->cb(false); #if (DEBUG==1) printf("i2c: to 0x%x failed, %d written, %d read in %d ticks\n", transaction->addr, transaction->wrlen, transaction->rdlen, (uint32_t) u32AHI_TickTimerRead() - i2c_ticks); #endif continue; } } if (transaction->rdlen) { /* send slave addr, start condition */ vAHI_SiWriteData8(transaction->addr|1); vAHI_SiSetCmdReg(E_AHI_SI_START_BIT, E_AHI_SI_NO_STOP_BIT, E_AHI_SI_NO_SLAVE_READ, E_AHI_SI_SLAVE_WRITE, E_AHI_SI_SEND_ACK, E_AHI_SI_NO_IRQ_ACK); PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_POLL); } /* read data, send stop condition on last byte, send nak on last byte when * end_of_transmission is set.*/ for (i=0; i<transaction->rdlen; i++) { vAHI_SiSetCmdReg(E_AHI_SI_NO_START_BIT, i==transaction->rdlen-1, E_AHI_SI_SLAVE_READ, E_AHI_SI_NO_SLAVE_WRITE, (i==transaction->rdlen-1) ? E_AHI_SI_SEND_NACK : E_AHI_SI_SEND_ACK, E_AHI_SI_NO_IRQ_ACK); PROCESS_YIELD_UNTIL(ev==PROCESS_EVENT_POLL); transaction->buf[transaction->wrlen+i] = u8AHI_SiReadData8(); } #if (DEBUG==1) printf("i2c: to 0x%x completed, %d written, %d read in %d ticks (rd:", transaction->addr, transaction->wrlen, transaction->rdlen, (u32_t) u32AHI_TickTimerRead() - i2c_ticks); for (i=0; i<transaction->rdlen+transaction->wrlen; i++) printf("0x%x,", transaction->buf[i]); printf(")\n"); #endif if (transaction->cb) transaction->cb(i2c_status==SUCCESS); } vAHI_SiConfigure(false,false,0); PROCESS_END(); }
PROCESS_THREAD(tcpip_process, ev, data) { PROCESS_BEGIN(); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(aestest, ev, data) { static int i, j; unsigned long start, end; static struct etimer periodic_timer; PROCESS_BEGIN(); printf("#Fixed AES-128 implementation test for %s.\n", TARGET_NAME); #ifndef AES_128_CONF printf("#Using Contiki software implementation.\n"); #else printf("#Using Hardware coprocessor.\n"); #endif printf("#Rounds in each sample: %d\n", NROUND); printf("#Sample size: %d\n", NSAMPLE); printf("#Rtimer clock ticks per second on this platform is : %lu\n", (unsigned long) RTIMER_SECOND); printf("#datablock address: %u\n", (unsigned int) datablock); etimer_set(&periodic_timer, (2 * CLOCK_SECOND)); //Initialise Data for (j = 0; j < NROUND; j++) memcpy(datablock[j], fixed_data, AES_BLOCK_LEN); for (i = 0; i < NSAMPLE; i++) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); etimer_reset(&periodic_timer); #ifdef VERBOSE_AESTEST printf("#Sample %d/%d\n", i + 1, NSAMPLE); PrintBlock("#Key\t: ", Aes128Key, "\n"); PrintBlock("#Plaintext\t: ", datablock[0], "\n"); #endif AES_128.set_key(Aes128Key); //Start timing. start = RTIMER_NOW(); #ifndef TIMING_FRAMEWORK_TEST for (j = 0; j < NROUND; j++) { AES_128.encrypt(datablock[j]); } #else for (j = 0; j < NROUND * 10; j++) { random_rand(); } #endif end = RTIMER_NOW(); //Print result. #ifdef VERBOSE_AESTEST PrintBlock("#Ciphertext\t: ", datablock[0], "\n"); printf("#Round\t: %d\n", NROUND); printf("#Start\t: %lu\n", start); printf("#End\t: %lu\n", end); printf("#Time Elapsed\t:\n"); #endif printf("%lu\n", end - start); finalise(); } printf("#%d tests done for %s.\n", NSAMPLE, TARGET_NAME); PROCESS_END(); }