/**@brief Function for handling the Device Manager events. * * @param[in] p_evt Data associated to the device manager event. */ static uint32_t device_manager_evt_handler(dm_handle_t const * p_handle, dm_event_t const * p_event, ret_code_t event_result) { uint32_t err_code; bool is_indication_enabled; APP_ERROR_CHECK(event_result); switch(p_event->event_id) { case DM_EVT_LINK_SECURED: // Send a single blood pressure measurement if indication is enabled. // NOTE: For this to work, make sure ble_bps_on_ble_evt() is called before // ble_bondmngr_on_ble_evt() in ble_evt_dispatch(). err_code = ble_bps_is_indication_enabled(&m_bps, &is_indication_enabled); APP_ERROR_CHECK(err_code); if (is_indication_enabled) { blood_pressure_measurement_send(); } break; default: // No implementation needed. break; } return NRF_SUCCESS; }
/**@brief Bond Manager module event handler. * * @param[in] p_evt Data associated to the bond manager event. */ static void bond_evt_handler(ble_bondmngr_evt_t * p_evt) { uint32_t err_code; bool is_indication_enabled; switch (p_evt->evt_type) { case BLE_BONDMNGR_EVT_ENCRYPTED: break; case BLE_BONDMNGR_EVT_CONN_TO_BONDED_MASTER: // Send a single blood pressure measurement if indication is enabled. // NOTE: For this to work, make sure ble_bps_on_ble_evt() is called before // ble_bondmngr_on_ble_evt() in ble_evt_dispatch(). err_code = ble_bps_is_indication_enabled(&m_bps, &is_indication_enabled); APP_ERROR_CHECK(err_code); if (is_indication_enabled) { blood_pressure_measurement_send(); } break; default: break; } }
/**@brief Function for simulating and sending one Blood Pressure Measurement. */ static void blood_pressure_measurement_send(void) { ble_bps_meas_t simulated_meas; uint32_t err_code; bool is_indication_enabled; err_code = ble_bps_is_indication_enabled(&m_bps, &is_indication_enabled); APP_ERROR_CHECK(err_code); if (is_indication_enabled && !m_bps_meas_ind_conf_pending) { bps_sim_measurement(&simulated_meas); err_code = ble_bps_measurement_send(&m_bps, &simulated_meas); switch (err_code) { case NRF_SUCCESS: // Measurement was successfully sent, wait for confirmation. m_bps_meas_ind_conf_pending = true; break; case NRF_ERROR_INVALID_STATE: // Ignore error. break; default: APP_ERROR_HANDLER(err_code); break; } } }