/**@brief Function for handling the Current Time Service client events. * * @details This function will be called for all events in the Current Time Service client that * are passed to the application. * * @param[in] p_evt Event received from the Current Time Service client. */ static void on_cts_c_evt(ble_cts_c_t * p_cts, ble_cts_c_evt_t * p_evt) { switch (p_evt->evt_type) { case BLE_CTS_C_EVT_DISCOVERY_COMPLETE: NRF_LOG("Current Time Service discovered on server.\n"); break; case BLE_CTS_C_EVT_SERVICE_NOT_FOUND: NRF_LOG("Current Time Service not found on server.\n"); break; case BLE_CTS_C_EVT_DISCONN_COMPLETE: NRF_LOG("Disconnect Complete.\n"); break; case BLE_CTS_C_EVT_CURRENT_TIME: NRF_LOG("Current Time received.\n"); current_time_print(p_evt); break; case BLE_CTS_C_EVT_INVALID_TIME: NRF_LOG("Invalid Time received.\n"); break; default: break; } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize timers_init(); nrf_log_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); db_discovery_init(); scheduler_init(); gap_params_init(); advertising_init(); services_init(); conn_params_init(); // Start execution err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); NRF_LOG("\r\nCTS Start!\r\n"); // Enter main loop for (;;) { app_sched_execute(); power_manage(); } }
/**@brief Function for starting advertising. */ static void advertising_start(void) { NRF_LOG("[APP]: Start Advertising\r\n"); uint32_t err_code = ess_advertising_start(); APP_ERROR_CHECK(err_code); m_adv_state = W_ADV_STATE_ADVERTISING; }
/**@brief Function for printing an iOS notification. * * @param[in] p_notif Pointer to the iOS notification. */ static void notif_print(ble_ancs_c_evt_notif_t * p_notif) { NRF_LOG("\r\nNotification\r\n"); NRF_LOG_PRINTF("Event: %s\r\n", lit_eventid[p_notif->evt_id]); NRF_LOG_PRINTF("Category ID: %s\r\n", lit_catid[p_notif->category_id]); NRF_LOG_PRINTF("Category Cnt:%u\r\n", (unsigned int) p_notif->category_count); NRF_LOG_PRINTF("UID: %u\r\n", (unsigned int) p_notif->notif_uid); NRF_LOG("Flags:\r\n"); if(p_notif->evt_flags.silent == 1) { NRF_LOG(" Silent\r\n"); } if(p_notif->evt_flags.important == 1) { NRF_LOG(" Important\r\n"); } if(p_notif->evt_flags.pre_existing == 1) { NRF_LOG(" Pre-existing\r\n"); } if(p_notif->evt_flags.positive_action == 1) { NRF_LOG(" Positive Action\r\n"); } if(p_notif->evt_flags.negative_action == 1) { NRF_LOG(" Positive Action\r\n"); } }
/**@brief Function for handling the Current Time Service client events. * * @details This function will be called for all events in the Current Time Service client that * are passed to the application. * * @param[in] p_evt Event received from the Current Time Service client. */ static void on_cts_c_evt(ble_cts_c_t * p_cts, ble_cts_c_evt_t * p_evt) { uint32_t err_code; switch (p_evt->evt_type) { case BLE_CTS_C_EVT_DISCOVERY_COMPLETE: NRF_LOG("Current Time Service discovered on server.\n\r"); err_code = ble_cts_c_handles_assign(&m_cts,p_evt->conn_handle, &p_evt->params.char_handles); APP_ERROR_CHECK(err_code); break; case BLE_CTS_C_EVT_DISCOVERY_FAILED: NRF_LOG("Current Time Service not found on server. \n\r"); // CTS not found in this case we just disconnect. There is no reason to stay // in the connection for this simple app since it all wants is to interact with CT if (p_evt->conn_handle != BLE_CONN_HANDLE_INVALID) { err_code = sd_ble_gap_disconnect(p_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); APP_ERROR_CHECK(err_code); } break; case BLE_CTS_C_EVT_DISCONN_COMPLETE: NRF_LOG("Disconnect Complete.\n\r"); break; case BLE_CTS_C_EVT_CURRENT_TIME: NRF_LOG("Current Time received.\n\r"); current_time_print(p_evt); break; case BLE_CTS_C_EVT_INVALID_TIME: NRF_LOG("Invalid Time received.\n\r"); break; default: break; } }
/**@brief Function for setting up GATTC notifications from the Notification Provider. * * @details This function is called when a successful connection has been established. */ static void apple_notification_setup(void) { uint32_t err_code; nrf_delay_ms(100); err_code = ble_ancs_c_notif_source_notif_enable(&m_ancs_c); APP_ERROR_CHECK(err_code); err_code = ble_ancs_c_data_source_notif_enable(&m_ancs_c); APP_ERROR_CHECK(err_code); NRF_LOG("Notifications Enabled.\r\n"); }
int main(void) { ret_code_t err_code; bool erase_bonds; err_code = NRF_LOG_INIT(); APP_ERROR_CHECK(err_code); NRF_LOG_PRINTF("Relay Example\r\n"); APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL); buttons_leds_init(&erase_bonds); if (erase_bonds == true) { NRF_LOG("Bonds erased!\r\n"); } ble_stack_init(); peer_manager_init(erase_bonds); db_discovery_init(); hrs_c_init(); rscs_c_init(); gap_params_init(); conn_params_init(); services_init(); advertising_init(); /** Start scanning for peripherals and initiate connection to devices which * advertise Heart Rate or Running speed and cadence UUIDs. */ scan_start(); // Turn on the LED to signal scanning. LEDS_ON(CENTRAL_SCANNING_LED); // Start advertising. err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); for (;;) { // Wait for BLE events. power_manage(); } }
/**@brief Function for handling the Current Time Service errors. * * @param[in] p_evt Event received from the Current Time Service client. */ static void current_time_print(ble_cts_c_evt_t * p_evt) { NRF_LOG("\nCurrent Time:\n"); NRF_LOG("\nDate:\n"); NRF_LOG_PRINTF("\tDay of week %s\n", day_of_week[p_evt-> params. current_time. exact_time_256. day_date_time. day_of_week]); if (p_evt->params.current_time.exact_time_256.day_date_time.date_time.day == 0) { NRF_LOG("\tDay of month Unknown\n"); } else { NRF_LOG_PRINTF("\tDay of month %i\n", p_evt->params.current_time.exact_time_256.day_date_time.date_time.day); } NRF_LOG_PRINTF("\tMonth of year %s\n", month_of_year[p_evt->params.current_time.exact_time_256.day_date_time.date_time.month]); if (p_evt->params.current_time.exact_time_256.day_date_time.date_time.year == 0) { NRF_LOG("\tYear Unknown\n"); } else { NRF_LOG_PRINTF("\tYear %i\n", p_evt->params.current_time.exact_time_256.day_date_time.date_time.year); } NRF_LOG("\nTime:\n"); NRF_LOG_PRINTF("\tHours %i\n", p_evt->params.current_time.exact_time_256.day_date_time.date_time.hours); NRF_LOG_PRINTF("\tMinutes %i\n", p_evt->params.current_time.exact_time_256.day_date_time.date_time.minutes); NRF_LOG_PRINTF("\tSeconds %i\n", p_evt->params.current_time.exact_time_256.day_date_time.date_time.seconds); NRF_LOG_PRINTF("\tFractions %i/256 of a second\n", p_evt->params.current_time.exact_time_256.fractions256); NRF_LOG("\nAdjust reason:\n"); NRF_LOG_PRINTF("\tDaylight savings %x\n", p_evt->params.current_time.adjust_reason.change_of_daylight_savings_time); NRF_LOG_PRINTF("\tTime zone %x\n", p_evt->params.current_time.adjust_reason.change_of_time_zone); NRF_LOG_PRINTF("\tExternal update %x\n", p_evt->params.current_time.adjust_reason.external_reference_time_update); NRF_LOG_PRINTF("\tManual update %x\n", p_evt->params.current_time.adjust_reason.manual_time_update); }
/**@brief Function for handling events from the BSP module. * * @param[in] event Event generated by button press. */ void bsp_event_handler(bsp_event_t event) { uint32_t err_code; switch (event) { case BSP_EVENT_SLEEP: sleep_mode_enter(); break; case BSP_EVENT_DISCONNECT: err_code = sd_ble_gap_disconnect(m_cts.conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); if (err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_CHECK(err_code); } break; case BSP_EVENT_WHITELIST_OFF: err_code = ble_advertising_restart_without_whitelist(); if (err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_CHECK(err_code); } break; case BSP_EVENT_KEY_0: if (m_cts.conn_handle != BLE_CONN_HANDLE_INVALID) { err_code = ble_cts_c_current_time_read(&m_cts); if (err_code == NRF_ERROR_NOT_FOUND) { NRF_LOG("Current Time Service is not discovered.\r\n"); } } break; default: // No implementation needed. break; } }
int main(void) { ret_code_t err_code; bool erase_bonds; err_code = NRF_LOG_INIT(); APP_ERROR_CHECK(err_code); NRF_LOG_PRINTF("LE Secure Connections Example\r\n"); APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL); buttons_leds_init(&erase_bonds); if (erase_bonds) { NRF_LOG("Bonds erased!\r\n"); } ble_stack_init(); peer_manager_init(erase_bonds); db_discovery_init(); hrs_c_init(); gap_params_init(); conn_params_init(); services_init(); advertising_init(); adv_scan_start(); for (;;) { // Wait for BLE events. power_manage(); } }
/**@brief Function for handling the Application's BLE Stack events. * * @details This function will be called for advertising events which are passed to the application. * * @param[in] ble_adv_evt Advertising event. */ static void on_adv_evt(ess_adv_evt_t ess_adv_evt) { switch (ess_adv_evt) { case ESS_ADV_EVT_MODE_1: NRF_LOG_PRINTF("%s - ESS_ADV_EVT_MODE_1\r\n", __func__); break; case ESS_ADV_EVT_MODE_2: NRF_LOG_PRINTF("%s - ESS_ADV_EVT_MODE_2\r\n", __func__); break; case ESS_ADV_EVT_MODE_3: NRF_LOG_PRINTF("%s - ESS_ADV_EVT_MODE_3\r\n", __func__); m_adv_state = W_ADV_STATE_IDLE; break; case ESS_ADV_EVT_IDLE: NRF_LOG_PRINTF("%s - ESS_ADV_EVT_IDLE\r\n", __func__); NRF_LOG("[APP]: Going to sleep.\r\n\r\n\r\n"); sleep_mode_enter(); break; case ESS_ADV_EVT_WHITELIST_REQUEST: { NRF_LOG_PRINTF("%s - ESS_ADV_EVT_WHITELIST_REQUEST\r\n", __func__); ret_code_t err_code; // Storage for the whitelist. ble_gap_irk_t * irks[8]; ble_gap_addr_t * addrs[8]; ble_gap_whitelist_t whitelist = {.pp_irks = irks, .pp_addrs = addrs}; // Construct a list of peer IDs. pm_peer_id_t peer_ids[8]; pm_peer_id_t peer_id = pm_next_peer_id_get(PM_PEER_ID_INVALID); uint32_t n_peer_ids = 0; while((peer_id != PM_PEER_ID_INVALID) && (n_peer_ids < 8)) { peer_ids[n_peer_ids++] = peer_id; peer_id = pm_next_peer_id_get(peer_id); } // Create the whitelist. err_code = pm_whitelist_create(peer_ids, n_peer_ids, &whitelist); APP_ERROR_CHECK(err_code); // Apply the whitelist. err_code = ess_advertising_whitelist_reply(&whitelist); APP_ERROR_CHECK(err_code); break; } case ESS_ADV_EVT_PEER_ADDR_REQUEST: { NRF_LOG_PRINTF("%s - ESS_ADV_EVT_PEER_ADDR_REQUEST\r\n", __func__); // ble_gap_addr_t peer_address; // // Only Give peer address if we have a handle to the bonded peer. // if(m_bonded_peer_handle.appl_id != DM_INVALID_ID) // { // err_code = dm_peer_addr_get(&m_bonded_peer_handle, &peer_address); // if (err_code != (NRF_ERROR_NOT_FOUND | DEVICE_MANAGER_ERR_BASE)) // { // APP_ERROR_CHECK(err_code); // err_code = ble_advertising_peer_addr_reply(&peer_address); // APP_ERROR_CHECK(err_code); // } // } break; } default: break; } }