发送的终极函数
sd_ble_gattc_write
那么猜测对应读的终极函数是
sd_ble_gattc_read
但是它没有SDK的案例
摸索一下
赋值 跟踪 p_chars
nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
ble_gatt_db_char_t * p_chars
跟踪 ble_gatt_db_char_t
typedef struct
{
ble_gattc_char_t characteristic; /**< Structure containing information about the characteristic. */
uint16_t cccd_handle; /**< CCCD Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a CCCD is not present at the server. */
uint16_t ext_prop_handle; /**< Extended Properties Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if an Extended Properties descriptor is not present at the server. */
uint16_t user_desc_handle; /**< User Description Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a User Description descriptor is not present at the server. */
uint16_t report_ref_handle; /**< Report Reference Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a Report Reference descriptor is not present at the server. */
} ble_gatt_db_char_t;
果然 有 user_desc_handle
这就有希望啦!!!!
typedef struct
{
uint16_t nus_tx_handle; /**< Handle of the NUS TX characteristic as provided by a discovery. */
uint16_t nus_tx_cccd_handle; /**< Handle of the CCCD of the NUS TX characteristic as provided by a discovery. */
uint16_t user_desc_handle;
uint16_t nus_rx_handle; /**< Handle of the NUS RX characteristic as provided by a discovery. */
uint16_t nus_code_handle;
uint16_t nus_code_cccd_handle;
} ble_nus_c_handles_t;
void ble_nus_c_on_db_disc_evt(ble_nus_c_t * p_ble_nus_c, ble_db_discovery_evt_t * p_evt)
{
case BLE_UUID_NUS_TX_CHARACTERISTIC:
nus_c_evt.handles.nus_tx_handle = p_chars[i].characteristic.handle_value;
nus_c_evt.handles.nus_tx_cccd_handle = p_chars[i].cccd_handle;
nus_c_evt.handles.user_desc_handle = p_chars[i].user_desc_handle;
NRF_LOG_ERROR("BLE_UUID_NUS_TX_CHARACTERISTIC[%4x]-%[%4x]\r\n", nus_c_evt.handles.nus_tx_cccd_handle,nus_c_evt.handles.user_desc_handle);
break;
发现完成
uint32_t ble_nus_c_handles_assign(ble_nus_c_t * p_ble_nus,
uint16_t conn_handle,
ble_nus_c_handles_t const * p_peer_handles)
{
VERIFY_PARAM_NOT_NULL(p_ble_nus);
p_ble_nus->conn_handle = conn_handle;
if (p_peer_handles != NULL)
{
p_ble_nus->orcode = p_peer_handles->nus_code_handle;//booló?·¨
p_ble_nus->handles.user_desc_handle = p_peer_handles->user_desc_handle;
p_ble_nus->handles.nus_tx_cccd_handle = p_peer_handles->nus_tx_cccd_handle;
p_ble_nus->handles.nus_tx_handle = p_peer_handles->nus_tx_handle;
p_ble_nus->handles.nus_rx_handle = p_peer_handles->nus_rx_handle;
p_ble_nus->handles.nus_code_handle = p_peer_handles->nus_code_handle;
p_ble_nus->handles.nus_code_cccd_handle = p_peer_handles->nus_code_cccd_handle;
}
NRF_LOG_DEBUG("ble_nus_c_handles_assign %04x:%04x:%04x:%04x:%04x",\
p_ble_nus->conn_handle,\
p_ble_nus->handles.nus_code_cccd_handle,\
p_ble_nus->handles.nus_code_handle,\
p_ble_nus->handles.nus_rx_handle,\
p_ble_nus->handles.user_desc_handle,\
p_ble_nus->orcode);
return NRF_SUCCESS;
}
sd_ble_gattc_read
目前没有参考
https://devzone.nordicsemi.com/f/nordic-q-a/19721/where-use-sd_ble_gattc_read
BLE_GATTC_EVT_READ_RSP
case BLE_GATTC_EVT_READ_RSP:
if(p_ble_evt->evt.gattc_evt.params.read_rsp.handle == 0x29)
{
for(uint16_t x = p_ble_evt->evt.gattc_evt.params.read_rsp.offset;x < p_ble_evt->evt.gattc_evt.params.read_rsp.offset +20;x++)
{
readvalue[x] = p_ble_evt->evt.gattc_evt.params.read_rsp.data[x - p_ble_evt->evt.gattc_evt.params.read_rsp.offset];
}
}
break;
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
ret_code_t err_code;
// For readability.
ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt;
switch (p_ble_evt->header.evt_id)
{
// Upon connection, check which peripheral is connected, initiate DB
// discovery, update LEDs status, and resume scanning, if necessary.
case BLE_GATTC_EVT_READ_RSP:
NRF_LOG_INFO("BLE_GATTC_EVT_READ_RSP 0x%x ",
p_gap_evt->conn_handle);
break;
case BLE_GAP_EVT_CONNECTED://全自动 发此消息
switch (p_ble_nus_evt->evt_type)
{
// Found node by BLE
case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
NRF_LOG_INFO("[BLE] Discovery complete.");
err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt->conn_handle, &p_ble_nus_evt->handles);
APP_ERROR_CHECK(err_code);
err_code = sd_ble_gattc_read(p_ble_nus_evt->conn_handle, p_ble_nus_evt->handles.user_desc_handle, 0);
APP_ERROR_CHECK(err_code);
此时
[00:00:10.081,817] <debug> ble_nus_c: ble_nus_c_code_notif_enable id=0:18:19
[00:00:10.089,447] <error> app: ERROR 17 [NRF_ERROR_BUSY] at ..\..\..\main.c:1287
PC at: 0x00028BCD
[00:00:10.089,691] <error> app: End of error report
https://blog.csdn.net/qq_36347513/article/details/107928213
uint32_t ble_gattc_read_req_enc (uint16_t conn_handle, uint16_t handle, uint16_t offset, uint8_t *const p_buf, uint32_t *p_buf_len)
Encodes sd_ble_gattc_read command request. More...
https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk51.v10.0.0%2Fgroup__ble__gattc__app.html
准备找一找从机的问题目前看上去描述如图 是子UUID的
冷静分析一下别人的回答
1--何时可以调用 sd_ble_gattc_read 只要有连接句柄即可 那我的 BLE_NUS_C_EVT_DISCOVERY_COMPLETE 是可以的
2--流程 我发这个函数以后 需要等待回答 BLE_GATTC_EVT_READ_RSP 再继续发其他命令 如果你不等就继续操作 那就会出现 NRF_ERROR_BUSY
一