uint32_t ble_hts_is_indication_enabled(ble_hts_t * p_hts, bool * p_indication_enabled) { uint32_t err_code; uint8_t cccd_value_buf[BLE_CCCD_VALUE_LEN]; ble_gatts_value_t gatts_value; // Initialize value struct. memset(&gatts_value, 0, sizeof(gatts_value)); gatts_value.len = BLE_CCCD_VALUE_LEN; gatts_value.offset = 0; gatts_value.p_value = cccd_value_buf; err_code = sd_ble_gatts_value_get(p_hts->conn_handle, p_hts->meas_handles.cccd_handle, &gatts_value); if (err_code == NRF_SUCCESS) { *p_indication_enabled = ble_srv_is_indication_enabled(cccd_value_buf); } if (err_code == BLE_ERROR_GATTS_SYS_ATTR_MISSING) { *p_indication_enabled = false; return NRF_SUCCESS; } return err_code; }
/**@brief check if the cccd is configured * * @param[in] p_sc_ctrlpt SC Ctrlpt structure. * @return true if the sc_control point's cccd is correctly configured, false otherwise. */ static bool is_cccd_configured(ble_sc_ctrlpt_t * p_sc_ctrlpt) { uint32_t err_code; uint8_t cccd_value_buf[BLE_CCCD_VALUE_LEN]; bool is_sccp_indic_enabled = false; ble_gatts_value_t gatts_value; // Initialize value struct. memset(&gatts_value, 0, sizeof(gatts_value)); gatts_value.len = BLE_CCCD_VALUE_LEN; gatts_value.offset = 0; gatts_value.p_value = cccd_value_buf; err_code = sd_ble_gatts_value_get(p_sc_ctrlpt->conn_handle, p_sc_ctrlpt->sc_ctrlpt_handles.cccd_handle, &gatts_value); if (err_code != NRF_SUCCESS) { // Report error to application if (p_sc_ctrlpt->error_handler != NULL) { p_sc_ctrlpt->error_handler(err_code); } } is_sccp_indic_enabled = ble_srv_is_indication_enabled(cccd_value_buf); return is_sccp_indic_enabled; }
static void on_cccd_write(ble_sds_t * p_sds, ble_gatts_evt_write_t * p_evt_write) { if ((p_evt_write->len == 2) && (p_sds->evt_handler != NULL)) { ble_sds_evt_t evt; // CCCD written, update indication state if (p_sds->self_def_send_handles.cccd_handle == p_evt_write->handle) { if (ble_srv_is_indication_enabled(p_evt_write->data)) { evt.evt_type = SELF_DEF_SEND_EVT_INDICATION_ENABLED; } else { evt.evt_type = SELF_DEF_SEND_EVT_INDICATION_DISABLED; } } else { //TODO: } p_sds->evt_handler(p_sds, &evt); } else { //TODO: } }
uint32_t ble_hts_is_indication_enabled(ble_hts_t * p_hts, bool * p_indication_enabled) { uint32_t err_code; uint8_t cccd_value_buf[BLE_CCCD_VALUE_LEN]; uint16_t len = BLE_CCCD_VALUE_LEN; err_code = sd_ble_gatts_value_get(p_hts->meas_handles.cccd_handle, 0, &len, cccd_value_buf); if (err_code == NRF_SUCCESS) { *p_indication_enabled = ble_srv_is_indication_enabled(cccd_value_buf); } return err_code; }
/**@brief Write event handler. * * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_evt_t const * p_ble_evt) { const ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if (p_evt_write->handle != m_dfu.control_point_char.cccd_handle) { return; } if (p_evt_write->len == BLE_CCCD_VALUE_LEN) { // CCCD written, update indications state m_dfu.is_ctrlpt_indication_enabled = ble_srv_is_indication_enabled(p_evt_write->data); NRF_LOG_INFO("Received indication state %d", m_dfu.is_ctrlpt_indication_enabled); } }
/**@brief Handle write events to the Blood Pressure Measurement characteristic. * * @param[in] p_hts Health Thermometer Service structure. * @param[in] p_evt_write Write event received from the BLE stack. */ static void on_cccd_write(ble_hts_t * p_hts, ble_gatts_evt_write_t * p_evt_write) { if (p_evt_write->len == 2) { // CCCD written, update indication state if (p_hts->evt_handler != NULL) { ble_hts_evt_t evt; if (ble_srv_is_indication_enabled(p_evt_write->data)) { evt.evt_type = BLE_HTS_EVT_INDICATION_ENABLED; } else { evt.evt_type = BLE_HTS_EVT_INDICATION_DISABLED; } p_hts->evt_handler(p_hts, &evt); } } }
/**@brief check if the cccd is configured * * @param[in] p_sc_ctrlpt SC Ctrlpt structure. * @return true if the sc_control point's cccd is correctly configured, false otherwise. */ static bool is_cccd_configured(ble_sc_ctrlpt_t * p_sc_ctrlpt) { uint32_t err_code; uint8_t cccd_value_buf[BLE_CCCD_VALUE_LEN]; uint16_t len = BLE_CCCD_VALUE_LEN; bool is_sccp_indic_enabled = false; err_code = sd_ble_gatts_value_get(p_sc_ctrlpt->sc_ctrlpt_handles.cccd_handle, 0, &len, cccd_value_buf); if (err_code != NRF_SUCCESS) { // Report error to application if (p_sc_ctrlpt->error_handler != NULL) { p_sc_ctrlpt->error_handler(err_code); } } is_sccp_indic_enabled = ble_srv_is_indication_enabled(cccd_value_buf); return is_sccp_indic_enabled; }