【求组】创建characteristic的description描述符无法获取handle句柄
Posted: 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);
例如
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);