/**@brief Function for application main entry. */ int main(void) { // Initialize timers_init(); gpiote_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); // Start execution timers_start(); advertising_start(); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
int main(void) { // Initialization led_init(SQUALL_LED_PIN); led_init(BLEES_LED_PIN); led_on(SQUALL_LED_PIN); led_on(BLEES_LED_PIN); timers_init(); // must start before conn_params // Setup BLE and services ble_stack_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); // Advertise data adv_physweb(); advertising_start(); // Initialization complete led_off(SQUALL_LED_PIN); led_off(BLEES_LED_PIN); timers_start(); while (1) { power_manage(); } }
int main(void) { uint32_t err_code; // Initialize. timers_init(); err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL); APP_ERROR_CHECK(err_code); uart_init(); ble_stack_init(); twi_master_init(); err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); nrf_delay_ms(200); bsp_indication_set(BSP_INDICATE_IDLE); nrf_delay_ms(200); err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); update_sensor(0); start_advertising(); timers_start(); // Enter main loop. for (;; ) { power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize timers_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); // Start execution timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Application main function. */ int main(void) { // Initialize leds_init(); timers_init(); gpiote_init(); buttons_init(); bond_manager_init(); ble_stack_init(); scheduler_init(); gap_params_init(); advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE); services_init(); sensor_sim_init(); conn_params_init(); sec_params_init(); radio_notification_init(); // Start execution timers_start(); advertising_start(); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
int main(void) { gpio_init(); uart_init(); timers_init(); __LOG("Timers initialized."); ble_stack_init(); //device_manager_init(erase_bonds); gap_params_init(); services_init(); advertising_init(); __LOG("Radio initialized."); conn_params_init(); storage_init(); contacts_init(); __LOG("Application modules initialized"); // Start execution. timers_start(); advertising_start(); __LOG("ADV Started"); scan_start(); __LOG("Scan Started"); // Enter main loop. for (;;) { power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize timers_init(); ble_stack_init(); bsp_module_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); sec_params_init(); adc_init(); // Start execution timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop for (;;) { if(start_adc_sampling == true) { nrf_drv_saadc_sample_convert(0, &adc_value); ble_android_characteristic_update(&m_android, &adc_value); start_adc_sampling = false; } app_sched_execute(); // power_manage(); } }
/** * @brief Function for application main entry. */ int main(void) { lfclk_init(); timers_init(); timers_start(); //Arduino initialization, LFCLK and timers must have been initialized before application_setup(); // Enter main loop for (;;) { //application loop application_loop(); } }
int main(void) { uint32_t err_code; // Initialization led_init(LED_0); led_on(LED_0); // Setup clock SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, false); // Setup and start timer timers_init(); timers_start(); while (1) { power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize leds_init(); ble_stack_init(); gap_params_init(); timers_init(); advdata_update(); // Start execution timers_start(); advertising_start(); // Enter main loop for (;;) { power_manage(); } }
/**@brief Function for application main entry. */ int main(void) { // Initialize app_trace_init(); simple_uart_putstring((const uint8_t*) "trace init\r\n"); leds_init(); simple_uart_putstring((const uint8_t*) "leds init\r\n"); timers_init(); simple_uart_putstring((const uint8_t*) "timers init\r\n"); gpiote_init(); simple_uart_putstring((const uint8_t*) "gpiote init\r\n"); buttons_init(); simple_uart_putstring((const uint8_t*) "buttons init\r\n"); ble_stack_init(); simple_uart_putstring((const uint8_t*) "stack init\r\n"); scheduler_init(); simple_uart_putstring((const uint8_t*) "schedler init\r\n"); gap_params_init(); simple_uart_putstring((const uint8_t*) "gap init\r\n"); advertising_init(); simple_uart_putstring((const uint8_t*) "adv init\r\n"); services_init(); simple_uart_putstring((const uint8_t*) "services init\r\n"); conn_params_init(); simple_uart_putstring((const uint8_t*) "conn init\r\n"); sec_params_init(); simple_uart_putstring((const uint8_t*) "sec init\r\n"); ext_sensors_init(); simple_uart_putstring((const uint8_t*) "ext init\r\n"); // lfclk_config(); // simple_uart_putstring((const uint8_t*) "lfk init\r\n"); // Start execution timers_start(); advertising_start(); simple_uart_putstring((const uint8_t*) "main\r\n"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
int main(void) { uint32_t err_code; // Initialization led_init(LED_0); led_init(LED_1); led_init(LED_2); led_on(LED_0); // Setup clock SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION, false); // Setup and start timeri //APP_SCHED_INIT(APP_TIMER_SCHED_EVT_SIZE, 20); timers_init(); timers_start(); while (1) { //app_sched_execute(); power_manage(); //led_toggle(LED_1); } }
int main(void) { bool init_status; int retValue; int i = defaultPerso.fall_detection_window; // initialize LEDs nrf_gpio_cfg_output(LED_RESETTING); nrf_gpio_cfg_output(LED_NO_FALL); nrf_gpio_cfg_output(LED_FALL_DETECTED); nrf_gpio_cfg_output(LED_OTHER); welcomeLEDs(); // Initialize timers_init(); ble_stack_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); sec_params_init(); twi_master_init(); #ifdef TEST_ACTIVITY_LOG testActivityLog(); #endif initActivityLog(); initSnapshotBuffer(); initCoefficients(); // initialize values retValue = 0; init_status = mpu6050_init(MPU6050_DEVICE_ADDR); if ( false == init_status ) { init_status = mpu6050_init(MPU6050_DEVICE_ADDR+1); if ( false == init_status ) { retValue = -1; errorLEDs(); sd_nvic_SystemReset(); } } if ( 0 == retValue ) { init_status = false; i = 0; while ( false == init_status ) { if (i == 6) { errorLEDs(); sd_nvic_SystemReset(); } init_status = accel_setup(); i++; } } if (0 == retValue) { char outbuf[20]; // Start execution - write a log entry with zero steps to indicate startup // writeLogEntry(999); advertising_start(); setup_wdt(); timers_start(); // start sampliing while(1) { if (ReadSnapshots == 1) { FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START) ; SnapshotHeader *h; Sensor_Reading *r; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for(int i=0;i < getActivityLogSize(); i++) { h = &entry->hdr; sprintf (outbuf, ": SNAPSHOT # %d \n ",(i)); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16); sprintf (outbuf, "Version: 2 \n");// ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); // ptr++; r = entry->r; for (int j = 0; j < NUMBER_OF_ENTRIES; j++) { #define FLASH_READ_DELAY 40 nrf_gpio_pin_set(LED_RESETTING); sprintf (outbuf, "i: %d T: %04x ",j,r[j].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(FLASH_READ_DELAY); //ptr += sizeof(Sensor_Reading); } entry++; } ReadSnapshots = 0; } if (ReadSnapshotsPartial == 1) { PartialSnapTotal = ((PartialSnap1-('0'))*10)+(PartialSnap2-('0')); FullSnapshotEntry* entry = (FullSnapshotEntry*)(SNAPSHOT_DATA_ADDRESS_START+(((PartialSnapTotal*sizeof(FullSnapshotEntry)*10))/4)) ; SnapshotHeader *h; Sensor_Reading *r; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for(int i=0;i < 10; i++) { h = &entry->hdr; sprintf (outbuf, ": SNAPSHOT # %d \n ",(i+(PartialSnapTotal*10))); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 16); sprintf (outbuf, "Version: 2 \n");// ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 12); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); // ptr++; r = entry->r; for (int j = 0; j < NUMBER_OF_ENTRIES; j++) { #define FLASH_READ_DELAY 40 nrf_gpio_pin_set(LED_RESETTING); sprintf (outbuf, "i: %d T: %04x ",j,r[j].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",r[j].val.x_ac,r[j].val.y_ac,r[j].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",r[j].val.x_gy,r[j].val.y_gy,r[j].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(FLASH_READ_DELAY); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(FLASH_READ_DELAY); //ptr += sizeof(Sensor_Reading); } entry++; } ReadSnapshotsPartial = 0; } if (ReadDataBuffer == 1) { LogEntry *addr; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); addr = (LogEntry *)(STEP_DATA_ADDRESS_START); for(int i=0;i < getActivityLogSize(); i++) { nrf_gpio_pin_set(LED_RESETTING); nrf_delay_ms(20); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(20); // sprintf ( outbuf, ": h:%d s:%d a:%04f ",addr->item.hour, addr->item.sec, addr->item.activity_level); sprintf ( outbuf, "%d:%d - %03f ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); //nrf_delay_ms(1); addr++; } ReadDataBuffer = 0; } if (ReadDataBufferPartial == 1) { LogEntry *addr; sprintf (outbuf, "ID: %s ", getPerso()->uname); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); PartialCountTotal = ((PartialCount1-('0'))*10)+(PartialCount2-('0')); addr = (LogEntry *)(STEP_DATA_ADDRESS_START+(2*(PartialCountTotal*1000))); for(int i=0;i < 1000; i++) { nrf_gpio_pin_set(LED_RESETTING); nrf_delay_ms(20); nrf_gpio_pin_clear(LED_RESETTING); nrf_delay_ms(20); // sprintf ( outbuf, ": h:%d s:%d a:%04f ",addr->item.hour, addr->item.sec, addr->item.activity_level); sprintf ( outbuf, "%d:%d - %03f ",addr->item.hour, (addr->item.sec)/60, addr->item.activity_level); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); //nrf_delay_ms(1); addr++; } ReadDataBufferPartial = 0; } if (Dumper == 1) { sprintf (outbuf, "Log: %d ",getActivityLogSize()); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); Dumper = 0; } if (ReadBigSnapshot == 1) { SnapshotHeader *h = getSnapshotHeader(); sprintf (outbuf, "t:%d n:%d last:%d",h->data.time, h->data.num_of_data_points, h->data.latest_data_point_index); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); for (i = 0; i < NUMBER_OF_ENTRIES; i++) //i <= h->data.latest_data_point_index; i++) { #define RAM_READ_DELAY 15 sprintf (outbuf, "i: %d T: %04x ",i,raw_data[i].val.temp); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); sprintf (outbuf, "A: x%04xy%04xz%04x",raw_data[i].val.x_ac,raw_data[i].val.y_ac,raw_data[i].val.z_ac); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); sprintf (outbuf, "G: x%04xy%04xz%04x",raw_data[i].val.x_gy,raw_data[i].val.y_gy,raw_data[i].val.z_gy); ble_nus_send_string(&m_nus, (unsigned char*)outbuf, 20); nrf_delay_ms(RAM_READ_DELAY); } ReadBigSnapshot = 0; } if (do_post_processing == true) { do_post_processing = false; if (emergencyCall == 1) { makeTheCall(); emergencyCall = 0; } post_comm_processing(); } // Power Method 1 // nrf_gpio_pin_write(LED_OTHER,1); // power_manage(); // nrf_gpio_pin_write(LED_OTHER,0); } } return retValue; }
/**@brief Function for handling the Application's BLE Stack events. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_ble_evt(ble_evt_t * p_ble_evt) { uint32_t err_code; static ble_gap_evt_auth_status_t m_auth_status; bool master_id_matches; ble_gap_sec_kdist_t * p_distributed_keys; ble_gap_enc_info_t * p_enc_info; ble_gap_irk_t * p_id_info; ble_gap_sign_info_t * p_sign_info; static ble_gap_enc_key_t m_enc_key; /**< Encryption Key (Encryption Info and Master ID). */ static ble_gap_id_key_t m_id_key; /**< Identity Key (IRK and address). */ static ble_gap_sign_info_t m_sign_key; /**< Signing Key (Connection Signature Resolving Key). */ static ble_gap_sec_keyset_t m_keys = {.keys_periph = {&m_enc_key, &m_id_key, &m_sign_key}}; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_CONNECTED: m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; timers_start(); break; case BLE_GAP_EVT_DISCONNECTED: m_conn_handle = BLE_CONN_HANDLE_INVALID; app_timer_stop(m_meas_timer_id); advertising_start(); break; case BLE_GAP_EVT_SEC_PARAMS_REQUEST: err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, &m_sec_params, &m_keys); APP_ERROR_CHECK(err_code);// Check for errors break; case BLE_GATTS_EVT_SYS_ATTR_MISSING: err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS); APP_ERROR_CHECK(err_code);// Check for errors break; case BLE_GAP_EVT_AUTH_STATUS: m_auth_status = p_ble_evt->evt.gap_evt.params.auth_status; break; case BLE_GAP_EVT_SEC_INFO_REQUEST: master_id_matches = memcmp(&p_ble_evt->evt.gap_evt.params.sec_info_request.master_id, &m_enc_key.master_id, sizeof(ble_gap_master_id_t)) == 0; p_distributed_keys = &m_auth_status.kdist_periph; p_enc_info = (p_distributed_keys->enc && master_id_matches) ? &m_enc_key.enc_info : NULL; p_id_info = (p_distributed_keys->id && master_id_matches) ? &m_id_key.id_info : NULL; p_sign_info = (p_distributed_keys->sign && master_id_matches) ? &m_sign_key : NULL; err_code = sd_ble_gap_sec_info_reply(m_conn_handle, p_enc_info, p_id_info, p_sign_info); APP_ERROR_CHECK(err_code);// Check for errors break; case BLE_GAP_EVT_TIMEOUT: if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) { // Go to system-off mode (this function will not return; wakeup will cause a reset) err_code = sd_power_system_off(); APP_ERROR_CHECK(err_code);// Check for errors } break; default: // No implementation needed. break; } }