hi,all
I Need add many characteristic with notify in one service,and I wish it can send notify to the phone once the phone enable cccd.
1.tx_handles can work,buf rx_handles can not ,it err_code is 0x08 or 0x3401 or 3003,how can i do?
below is my code:
a. first i init the service like below
uint32_t ble_PM50030_init(ble_nus_t * p_nus, ble_nus_init_t const * p_nus_init) { ret_code_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t nus_base_uuid = PM5_BASE_UUID; ble_add_char_params_t add_char_params; VERIFY_PARAM_NOT_NULL(p_nus); VERIFY_PARAM_NOT_NULL(p_nus_init); // Initialize the service structure. p_nus->data_handler = p_nus_init->data_handler; /**@snippet [Adding proprietary Service to the SoftDevice] */ // Add a custom base UUID. err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type); VERIFY_SUCCESS(err_code); ble_uuid.type = p_nus->uuid_type; ble_uuid.uuid = BLE_UUID_0030_SERVICE; // Add the service. err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_nus->service_handle); /**@snippet [Adding proprietary Service to the SoftDevice] */ VERIFY_SUCCESS(err_code); // Add the TX Characteristic. /**@snippet [Adding proprietary characteristic to the SoftDevice] */ memset(&add_char_params, 0, sizeof(add_char_params)); add_char_params.uuid = BLE_UUID_31_TX_CHARACTERISTIC; add_char_params.uuid_type = p_nus->uuid_type; add_char_params.max_len = 19; add_char_params.init_len = 19; add_char_params.is_var_len = true; add_char_params.char_props.notify = 1; add_char_params.read_access = SEC_OPEN; add_char_params.write_access = SEC_OPEN; add_char_params.cccd_write_access = SEC_OPEN; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_32_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->rx_handles); if (err_code != NRF_SUCCESS) { return err_code; } #if 0 add_char_params.uuid = BLE_UUID_33_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0033_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_34_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0034_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_35_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0035_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_36_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0036_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_37_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0037_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_38_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0038_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_39_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0039_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3A_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003A_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3B_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003B_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3C_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003C_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3D_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003D_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3E_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003E_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_3F_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_003F_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_40_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0040_handle); if (err_code != NRF_SUCCESS) { return err_code; } add_char_params.uuid = BLE_UUID_41_TX_CHARACTERISTIC; err_code = characteristic_add(p_nus->service_handle, &add_char_params, &Character_0041_handle); if (err_code != NRF_SUCCESS) { return err_code; } #endif } uint32_t ble_PM50030_data_send(ble_nus_t * p_nus, uint8_t * p_data, uint16_t * p_length, uint16_t conn_handle) { ret_code_t err_code; ble_gatts_hvx_params_t hvx_params; ble_nus_client_context_t * p_client; VERIFY_PARAM_NOT_NULL(p_nus); err_code = blcm_link_ctx_get(p_nus->p_link_ctx_storage, conn_handle, (void *) &p_client); VERIFY_SUCCESS(err_code); if ((conn_handle == BLE_CONN_HANDLE_INVALID) || (p_client == NULL)) { return NRF_ERROR_NOT_FOUND; } if (!p_client->is_notification_enabled) { return NRF_ERROR_INVALID_STATE; } if (*p_length > BLE_NUS_MAX_DATA_LEN) { return NRF_ERROR_INVALID_PARAM; } memset(&hvx_params, 0, sizeof(hvx_params)); hvx_params.handle = p_nus->tx_handles.value_handle; hvx_params.p_data = p_data; hvx_params.p_len = p_length; hvx_params.type = BLE_GATT_HVX_NOTIFICATION; return sd_ble_gatts_hvx(conn_handle, &hvx_params); }
2.second ,the phone turn on the notify ,and device send notify like below
static void user_delay_timeout_handler(void * p_context) { uint32_t err_code; u16 length=0; if(char31_notify_en == BLE_NUS_EVT_COMM_STARTED) { length = sizeof(C2_rowing_general_status); err_code = ble_PM50030_data_send(&m_PM50030,(u8*)&C2_rowing_general_status,&length,m_conn_handle); NRF_LOG_INFO("ble_PM50030_data_send err_code=%x\n",err_code); } if(char32_notify_en == BLE_NUS_EVT_COMM_STARTED) { length = sizeof(C2_rowing_additional_status_1); err_code = ble_PM50030_data_send(&m_PM50030,(u8*)&C2_rowing_additional_status_1,&length,m_conn_handle); NRF_LOG_INFO("ble_PM50030_data_send err_code=%x\n",err_code); } } void user_timer(void) { ret_code_t err_code; err_code = app_timer_create(&user_detection_delay_timer_id,APP_TIMER_MODE_REPEATED,user_delay_timeout_handler); if (err_code != NRF_SUCCESS) { NRF_LOG_INFO("retcode2=%d\n",err_code); } uint32_t ret = app_timer_start(user_detection_delay_timer_id, 32768, NULL); if (err_code != NRF_SUCCESS) { NRF_LOG_INFO("retcode2=%d\n",err_code); } }