低功耗蓝牙4.0BLE编程-nrf51822开发(10)-描述符

来源:互联网 发布:mac图片放大快捷键 编辑:程序博客网 时间:2024/06/12 19:17

特性中的属性有两种:属性值或描述符。

    支持通知或指示的特性中默认有一个描述符:客户端特性配置描述符(Client Characteristic Configuration Descriptor,CCCD)。它的UUID是0x2902。

    添加描述符的函数是:

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. uint32_t sd_ble_gatts_descriptor_add  ( uint16_t  char_handle,    
  2.   ble_gatts_attr_t const *const  p_attr,    
  3.   uint16_t *const  p_handle    
  4.  )   

Parameters

[in]

char_handle

Handle of the characteristic where the descriptor is to be placed, if BLE_GATT_HANDLE_INVALID is used, it will be placed sequentially.

[in]

p_attr

Pointer to the attribute structure.

[out]

p_handle

Pointer to a 16-bit word where the assigned handle will be stored.

示例代码:

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_REPORT_REF_DESCR);  
  2.   
  3. memset(&attr_md, 0, sizeof(attr_md));  
  4.   
  5. attr_md.read_perm = p_bas_init->battery_level_report_read_perm;  
  6. BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.write_perm);  
  7.   
  8. attr_md.vloc       = BLE_GATTS_VLOC_STACK;  
  9. attr_md.rd_auth    = 0;  
  10. attr_md.wr_auth    = 0;  
  11. attr_md.vlen       = 0;  
  12.   
  13. init_len = ble_srv_report_ref_encode(encoded_report_ref, p_bas_init->p_report_ref);  
  14.   
  15. memset(&attr_char_value, 0, sizeof(attr_char_value));  
  16.   
  17. attr_char_value.p_uuid       = &ble_uuid;  
  18. attr_char_value.p_attr_md    = &attr_md;  
  19. attr_char_value.init_len     = init_len;  
  20. attr_char_value.init_offs    = 0;  
  21. attr_char_value.max_len      = attr_char_value.init_len;  
  22. attr_char_value.p_value      = encoded_report_ref;  
  23.   
  24. err_code = sd_ble_gatts_descriptor_add(p_bas->battery_level_handles.value_handle,  
  25.                                        &attr_char_value,  
  26.                                        &p_bas->report_ref_handle);  
  27. if (err_code != NRF_SUCCESS)  
  28. {  
  29.     return err_code;  
  30. }  
0 0
原创粉丝点击