/**@brief Function for handling write events to a report CCCD. * * @param[in] p_hids HID Service structure. * @param[in] p_char_id Id of report characteristic. * @param[in] p_evt_write Write event received from the BLE stack. */ static void on_report_cccd_write(ble_hids_t * p_hids, ble_hids_char_id_t * p_char_id, ble_gatts_evt_write_t * p_evt_write) { if (p_evt_write->len == 2) { // CCCD written, update notification state if (p_hids->evt_handler != NULL) { ble_hids_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = BLE_HIDS_EVT_NOTIF_ENABLED; } else { evt.evt_type = BLE_HIDS_EVT_NOTIF_DISABLED; } evt.params.notification.char_id = *p_char_id; p_hids->evt_handler(p_hids, &evt); } } }
/**@brief Function for handling the Write event. * * @param[in] p_bas Battery Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_bas_t * p_bas, ble_evt_t * p_ble_evt) { if (p_bas->is_notification_supported) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ( (p_evt_write->handle == p_bas->battery_level_handles.cccd_handle) && (p_evt_write->len == 2) ) { // CCCD written, call application event handler if (p_bas->evt_handler != NULL) { ble_bas_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = BLE_BAS_EVT_NOTIFICATION_ENABLED; } else { evt.evt_type = BLE_BAS_EVT_NOTIFICATION_DISABLED; } p_bas->evt_handler(p_bas, &evt); } } } }
/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the S110 SoftDevice. * * @param[in] p_dfu Nordic UART Service structure. * @param[in] p_ble_evt Pointer to the event received from BLE stack. */ static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ( (p_evt_write->handle == p_nus->rx_handles.cccd_handle) && (p_evt_write->len == 2) ) { if (ble_srv_is_notification_enabled(p_evt_write->data)) { p_nus->is_notification_enabled = true; } else { p_nus->is_notification_enabled = false; } } else if ( (p_evt_write->handle == p_nus->tx_handles.value_handle) && (p_nus->data_handler != NULL) ) { p_nus->data_handler(p_nus, p_evt_write->data, p_evt_write->len); } else { // Do Nothing. This event is not relevant to this service. } }
/**@brief Function for checking if the CCCD of DFU Control point is configured for Notification. * * @details This function checks if the CCCD of DFU Control Point characteristic is configured * for Notification by the DFU Controller. * * @param[in] p_dfu DFU Service structure. * * @return True if the CCCD of DFU Control Point characteristic is configured for Notification. * False otherwise. */ static bool is_cccd_configured(ble_dfu_t * p_dfu) { // Check if the CCCDs are configured. uint8_t cccd_val_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_val_buf; // Check the CCCD Value of DFU Control Point. uint32_t err_code = sd_ble_gatts_value_get(p_dfu->conn_handle, p_dfu->dfu_ctrl_pt_handles.cccd_handle, &gatts_value); if (err_code != NRF_SUCCESS) { if (p_dfu->error_handler != NULL) { p_dfu->error_handler(err_code); } return false; } return ble_srv_is_notification_enabled(cccd_val_buf); }
static void on_write(ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; // Check if this the correct CCCD if ( (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) && (p_evt_write->len == 2) ) { // Check if this is a 'start notification' if (ble_srv_is_notification_enabled(p_evt_write->data)) { // Do connection parameter negotiation if necessary conn_params_negotiation(); } else { #ifdef USE_APP_TIMER uint32_t err_code; // Stop timer if running err_code = app_timer_stop(m_conn_params_timer_id); if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) { m_conn_params_config.error_handler(err_code); } #else /* #if !USE_APP_TIMER */ m_conn_params_timer.detach(); #endif /* #if !USE_APP_TIMER */ } } }
/**@brief Function for handling the Write event. * * @param[in] p_si7021 si7021 Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_si7021_t * p_si7021, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; NRF_LOG_DEBUG("on_write %x\n\r",p_evt_write->handle); if (p_evt_write->handle == p_si7021->value_char_handles.cccd_handle) { if (p_evt_write->len == 2 && p_si7021->evt_handler != NULL) { ble_si7021_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = BLE_si7021_EVT_NOTIFICATION_ENABLED; NRF_LOG_DEBUG("BLE_si7021_EVT_NOTIFICATION_ENABLED\n\r"); } else { evt.evt_type = BLE_si7021_EVT_NOTIFICATION_DISABLED; NRF_LOG_DEBUG("BLE_si7021_EVT_NOTIFICATION_DISABLED\n\r"); } p_si7021->evt_handler(p_si7021, &evt); } } else if (p_evt_write->handle == p_si7021->com_char_handles.value_handle) { p_si7021->interval = uint16_decode(&p_evt_write->data[0]); if (p_si7021->interval<100) { p_si7021->interval=100; // min 100ms } ble_si7021_evt_t evt; evt.evt_type = BLE_si7021_EVT_INTERVAL_CHANGE; NRF_LOG_DEBUG("BLE_si7021_EVT_INTERVAL_CHANGE %d\n\r",p_si7021->interval); p_si7021->evt_handler(p_si7021, &evt); } else { // No implementation needed. } }
/**@brief Write event handler. * * @param[in] p_dfu DFU Service structure. * @param[in] p_ble_evt Event received from the BLE stack.rtt */ static void on_write(ble_dfu_t * p_dfu, 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 != p_dfu->control_point_char.cccd_handle) { return; } if (p_evt_write->len == BLE_CCCD_VALUE_LEN) { // CCCD written, update indications state p_dfu->is_ctrlpt_notification_enabled = ble_srv_is_notification_enabled(p_evt_write->data); if (p_dfu->evt_handler != NULL) { ble_dfu_evt_t evt; if (p_dfu->is_ctrlpt_notification_enabled) { evt.type = BLE_DFU_EVT_INDICATION_ENABLED;; } else { evt.type = BLE_DFU_EVT_INDICATION_DISABLED;; } p_dfu->evt_handler(p_dfu, &evt); } } }
/**@brief Function for handling the Write event. * * @param[in] p_bas Battery Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_step_t * p_step, ble_evt_t * p_ble_evt) { if (p_step->is_notification_supported) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; //SEGGER_RTT_printf(0,"on_write:len=%d\r\n",p_evt_write->len); if ( (p_evt_write->handle == p_step->step_count_handles.cccd_handle) && (p_evt_write->len == 2) ) { // CCCD written, call application event handler if (p_step->evt_handler != NULL) { ble_step_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = BLE_STEP_EVT_NOTIFICATION_ENABLED; } else { evt.evt_type = BLE_STEP_EVT_NOTIFICATION_DISABLED; } p_step->evt_handler(p_step, &evt); } } } }
/**@brief Function for handling the Write event. * * @param[in] p_luxsync Battery Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_luxsync_t * p_luxsync, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ((p_evt_write->handle == p_luxsync->LuxSync_ACK_handles.value_handle) && (p_evt_write->len == 1) && (p_luxsync->Luxsync_ack_write_handler != NULL)) { p_luxsync->Luxsync_ack_write_handler(p_luxsync, p_evt_write->data[0]); } if (p_luxsync->is_notification_supported) { if ((p_evt_write->handle == p_luxsync->LuxSync_handles.cccd_handle)&&((p_evt_write->len == 2))) { // CCCD written, set flags if (ble_srv_is_notification_enabled(p_evt_write->data)) { m_luxsync_char_notifications.lux_sync_notification_st =BLE_LUXSYNC_EVT_NOTIFICATION_ENABLED; } else { m_luxsync_char_notifications.lux_sync_notification_st =BLE_LUXSYNC_EVT_NOTIFICATION_DISABLED; } } else if ((p_evt_write->handle == p_luxsync->LuxSync_ACK_handles.cccd_handle)&&((p_evt_write->len == 2))) { // CCCD written, set flags if (ble_srv_is_notification_enabled(p_evt_write->data)) { m_luxsync_char_notifications.lux_sync_act_notification_st =BLE_LUXSYNC_EVT_NOTIFICATION_ENABLED; } else { m_luxsync_char_notifications.lux_sync_act_notification_st = BLE_LUXSYNC_EVT_NOTIFICATION_DISABLED; } } } }
/**@brief Function for handling the Write event. * * @param[in] p_iss ITU Sensor Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(iss_t * p_iss, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ((p_evt_write->handle == p_iss->meas_val_handles.cccd_handle) && (p_evt_write->len == 2)) { p_iss->is_notification_supported = ble_srv_is_notification_enabled(p_evt_write->data); }else if (p_evt_write->handle == p_iss->meas_conf_handles.value_handle) { its_conf_decode(p_iss,p_evt_write->len,p_evt_write->data); } }
static bool is_cccd_configured(ble_dfu_t * p_dfu) { uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN]; ble_gatts_value_t gatts_value = {0}; gatts_value.len = BLE_CCCD_VALUE_LEN; gatts_value.p_value = cccd_val_buf; // Check the CCCD Value of DFU Control Point. uint32_t err_code = sd_ble_gatts_value_get(m_conn_handle, p_dfu->dfu_ctrl_pt_handles.cccd_handle, &gatts_value); VERIFY_SUCCESS(err_code); return ble_srv_is_notification_enabled(cccd_val_buf); }
/** Function for handling write events to the Temperature characteristic. * * param[in] p_evt_write Write event received from the BLE stack. */ static void on_temp_cccd_write(ble_temp_t * p_temp, ble_gatts_evt_write_t * p_evt_write) { bool enabled = ble_srv_is_notification_enabled(p_evt_write->data); if (p_evt_write->len == 2) { if (enabled) { p_temp->notify_enabled = true; PUTS("Start temp timer"); APP_ERROR_CHECK(app_timer_start(m_temperature_timer_id, m_interval_ticks, NULL)); } else { p_temp->notify_enabled = false; PUTS("Stop temp timer"); APP_ERROR_CHECK(app_timer_stop(m_temperature_timer_id)); } } }
static void on_write2(new_server_t * p_nus, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; #if ((DEBUG_UART_EN) && (ENABLE_BLE_DEBUG)) // DbgPrintf("write->handle=%x\r\n",p_evt_write->handle); #endif if((p_evt_write->handle == p_nus->rx_handles.cccd_handle)&&(p_evt_write->len == 2)) { if (ble_srv_is_notification_enabled(p_evt_write->data)) { p_nus->is_notification_enabled = true; Protocol_set_notify(1); #if ((DEBUG_UART_EN) && (ENABLE_BLE_DEBUG)) DbgPrintf("set notification3\r\n"); #endif } else { #if ((DEBUG_UART_EN) && (ENABLE_BLE_DEBUG)) DbgPrintf("clear notification3\r\n"); #endif p_nus->is_notification_enabled = false; Protocol_set_notify(0); } } else if( (p_evt_write->handle == p_nus->tx_handles.value_handle) && (p_nus->data_handler != NULL) ) { #if ((DEBUG_UART_EN) && (ENABLE_BLE_DEBUG)) DbgPrintfbuff("_write3:",strlen("_write3:")); for(uint16_t i=0;i<p_evt_write->len;i++) DbgPrintf("%02x ",p_evt_write->data[i]); DbgPrintfbuff("\r\n",2); #endif p_nus->data_handler(p_nus, p_evt_write->data, p_evt_write->len);//kevin delete } else { // Do Nothing. This event is not relevant for this service. } }
/**@brief Function for evaluating the value written in CCCD * * @details This shall be called when there is a write event received from the stack. This * function will evaluate whether or not the peer has enabled notifications and * start/stop notifications accordingly. * * @param[in] p_ble_evt Bluetooth stack event. */ static void on_write(ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ((p_evt_write->handle == m_char_handles.cccd_handle) && (p_evt_write->len == 2)) { // CCCD written. Start notifications m_is_notifying_enabled = ble_srv_is_notification_enabled(p_evt_write->data); if (m_is_notifying_enabled) { application_timers_start(); char_notify(); } else { application_timers_stop(); } } }
/**@brief Function for handling the Glucose measurement CCCD write event. * * @param[in] p_cgms Service instance. * @param[in] p_evt_write WRITE event to be handled. */ static void on_meas_cccd_write(nrf_ble_cgms_t * p_cgms, ble_gatts_evt_write_t * p_evt_write) { if (p_evt_write->len == 2) { // CCCD written, update notification state if (p_cgms->evt_handler != NULL) { nrf_ble_cgms_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = NRF_BLE_CGMS_EVT_NOTIFICATION_ENABLED; } else { evt.evt_type = NRF_BLE_CGMS_EVT_NOTIFICATION_DISABLED; } p_cgms->evt_handler(p_cgms, &evt); } } }
/**@brief Function for handling write events to the Heart Rate Measurement characteristic. * * @param[in] p_hrs Heart Rate Service structure. * @param[in] p_evt_write Write event received from the BLE stack. */ static void on_hrm_cccd_write(ble_hrs_t * p_hrs, ble_gatts_evt_write_t * p_evt_write) { if (p_evt_write->len == 2) { // CCCD written, update notification state if (p_hrs->evt_handler != NULL) { ble_hrs_evt_t evt; if (ble_srv_is_notification_enabled(p_evt_write->data)) { evt.evt_type = BLE_HRS_EVT_NOTIFICATION_ENABLED; } else { evt.evt_type = BLE_HRS_EVT_NOTIFICATION_DISABLED; } p_hrs->evt_handler(p_hrs, &evt); } } }
/**@brief Function for checking if the CCCD of DFU Control point is configured for Notification. * * @details This function checks if the CCCD of DFU Control Point characteristic is configured * for Notification by the DFU Controller. * * @param[in] p_dfu DFU Service structure. * * @return True if the CCCD of DFU Control Point characteristic is configured for Notification. * False otherwise. */ static bool is_cccd_configured(ble_dfu_t * p_dfu) { // Check if the CCCDs are configured. uint16_t cccd_len = BLE_CCCD_VALUE_LEN; uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN]; // Check the CCCD Value of DFU Control Point. uint32_t err_code = sd_ble_gatts_value_get(p_dfu->dfu_ctrl_pt_handles.cccd_handle, 0, &cccd_len, cccd_val_buf); if (err_code != NRF_SUCCESS) { if (p_dfu->error_handler != NULL) { p_dfu->error_handler(err_code); } return false; } return ble_srv_is_notification_enabled(cccd_val_buf); }
/**@brief Function for handling the Write event. * * @param[in] p_rgb_btn RGB Button Service structure. * @param[in] p_ble_evt Event received from the BLE stack. */ static void on_write(ble_rgb_btn_t * p_rgb_btn, ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; if ((p_evt_write->handle == p_rgb_btn->btn_char_handles.cccd_handle) && (p_evt_write->len == 2) ) { if (ble_srv_is_notification_enabled(p_evt_write->data)) { p_rgb_btn->is_notification_enabled = true; } else { p_rgb_btn->is_notification_enabled = false; } } else if ((p_evt_write->handle == p_rgb_btn->rgb_char_handles.value_handle) && (p_evt_write->len == 3) && (p_rgb_btn->rgb_handler != NULL)) { p_rgb_btn->rgb_handler(p_rgb_btn, p_evt_write->data); } }