sdk版本:nRF5_SDK_17.1.0_ddde560
主要更改以下函数:
uint32_t ble_nus_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 = NUS_COMMUNICATE_UUID; //服务的128bit 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_NUS_BASE; //BLE_UUID_NUS_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 by xxx 2022.6.13 -----------------------------------
ble_uuid128_t nus_rx_base_uuid = NUS_SEND_UUID; //特征值 写(对方是读) 128bit uuid
err_code = sd_ble_uuid_vs_add(&nus_rx_base_uuid, &p_nus->uuid_type);
VERIFY_SUCCESS(err_code);
//--------------------add by xxx 2022.6.13 -----------------------------------
// Add the RX Characteristic.
memset(&add_char_params, 0, sizeof(add_char_params));
add_char_params.uuid = BLE_UUID_NUS_BASE; //BLE_UUID_NUS_RX_CHARACTERISTIC;
add_char_params.uuid_type = p_nus->uuid_type;
add_char_params.max_len = BLE_NUS_MAX_RX_CHAR_LEN;
add_char_params.init_len = sizeof(uint8_t);
add_char_params.is_var_len = true; //length variable
add_char_params.char_props.write = 1;
add_char_params.char_props.write_wo_resp = 1;
add_char_params.read_access = SEC_JUST_WORKS; //SEC_OPEN
add_char_params.write_access = SEC_JUST_WORKS;
err_code = characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->rx_handles);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
//--------------------add by xxx 2022.6.13 -----------------------------------
ble_uuid128_t nus_tx_base_uuid = NUS_RECEIVE_UUID; //特征值 接收(对方是写) 128bit uuid
err_code = sd_ble_uuid_vs_add(&nus_tx_base_uuid, &p_nus->uuid_type);
VERIFY_SUCCESS(err_code);
//--------------------add by xxx 2022.6.13 -----------------------------------
// 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_NUS_BASE; //BLE_UUID_NUS_TX_CHARACTERISTIC;
add_char_params.uuid_type = p_nus->uuid_type;
add_char_params.max_len = BLE_NUS_MAX_TX_CHAR_LEN;
add_char_params.init_len = sizeof(uint8_t);
add_char_params.is_var_len = true;
add_char_params.char_props.notify = 1; //notify
add_char_params.read_access = SEC_JUST_WORKS;//SEC_OPEN;
add_char_params.write_access = SEC_JUST_WORKS;//SEC_OPEN;
add_char_params.cccd_write_access = SEC_JUST_WORKS;//SEC_OPEN;
return characteristic_add(p_nus->service_handle, &add_char_params, &p_nus->tx_handles);
}