【求组】创建characteristic的description描述符无法获取handle句柄

lpxvcl
Posts: 11
Joined: Mon Jun 07, 2021 12:59 pm

【求组】创建characteristic的description描述符无法获取handle句柄

Postby lpxvcl » Tue Aug 03, 2021 6:38 am

采用在 GATT Server例程中,不采用注册表,单独手动添加characteristic,
例如
profile C 下面
service 1
characteristic 1
characteristic 2

其中characteristic 1和characteristic 2均需要配置description描述符,设置UUID = 0x2902(宏 ESP_GATT_UUID_CHAR_CLIENT_CONFIG)
// add char 1 略
pro_c_srvc_1_char_1.descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
esp_ble_gatts_add_char_descr(pro_c_srvc_1.service_handle, &pro_c_srvc_1_char_1.descr_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
&char1_desc, NULL);

//add char 2 略
pro_c_srvc_1_char_2.descr_uuid.uuid.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG;
esp_ble_gatts_add_char_descr(pro_c_srvc_1.service_handle, &pro_c_srvc_1_char_2.descr_uuid,
ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE,
&char2_desc, NULL);

发现在 ESP_GATTS_ADD_CHAR_DESCR_EVT触发事件中,无法获取characteristic 1和characteristic 2 的 description handle
原因是通过characteristic 1和characteristic 2 的 description UUID都一样(0x2902),无法区别,
if (param->add_char_descr.service_handle == pro_c_srvc_1.service_handle)
{//service 1
if (param->add_char_descr.descr_uuid.uuid.uuid16 == PRO_C_SERVICE_1_DESCR_C1_UUID)
{
pro_c_srvc_1_char_1.descr_handle = param->add_char_descr.attr_handle;
printf("pro_c_srvc_1_char_1.descr_handle \n");
}
else if (param->add_char_descr.descr_uuid.uuid.uuid16 == PRO_C_SERVICE_1_DESCR_C2_UUID)
{
pro_c_srvc_1_char_2.descr_handle = param->add_char_descr.attr_handle;
printf("pro_c_srvc_1_char_2.descr_handle \n");
}
else
....

哪位大佬有什么招数么?


另外,esp_ble_gatts_add_char_descr ()这个函数传参,并没有指定将description 添加给哪一个characteristic
指定的只是service,这个算BUG么?作为用户使用,有点懵。
建议在esp_ble_gatts_add_char_descr ()这个函数传参中增加 characteristic handle。
如有不对,还请指正。
/**
* @brief This function is called to add characteristic descriptor. When
* it's done, a callback event ESP_GATTS_ADD_DESCR_EVT is called
* to report the status and an ID number for this descriptor.
*
* @param[in] service_handle: service handle to which this characteristic descriptor is to
* be added.
* @param[in] perm: descriptor access permission.
* @param[in] descr_uuid: descriptor UUID.
* @param[in] char_descr_val : Characteristic descriptor value
* @param[in] control : attribute response control byte
* @return
* - ESP_OK : success
* - other : failed
*
*/
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
esp_bt_uuid_t *descr_uuid,
esp_gatt_perm_t perm, esp_attr_value_t *char_descr_val,
esp_attr_control_t *control);

ESP_XuLZ
Posts: 173
Joined: Fri Mar 26, 2021 6:04 am

Re: 【求组】创建characteristic的description描述符无法获取handle句柄

Postby ESP_XuLZ » Mon Aug 09, 2021 3:54 am

1. 像 gatt_server_service_table 中创建属性一样, 这些service、char、descr 都是一条条属性在server 中的属性库中按照一定规则顺序排列的, descr 是跟着 char 或其他 descr 的,是修饰它紧挨着的上面的 char 的,这可能是 esp_ble_gatts_add_char_descr() 未增加 char_handle 的考虑
2. 为同一 service 下的两个char 都增加descr 在 gatt_server 也是可行的,按顺序 char1——>descr1 ——>char2——>descr2 , 可以参考附件中的gatts_demo.c
3. 使用 esp_ble_gatts_create_service()创建 service num_handle 数目一定要够存放你后面增加的 char 或 descr
4. 可在 menuconfig 中打开 gatt_layer 的 DEBUG log level
Attachments
gatts_demo.c
(34.58 KiB) Downloaded 387 times

Who is online

Users browsing this forum: No registered users and 83 guests