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

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

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

    添加描述符的函数是:

[cpp]  view plain copy 在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 plain copy 在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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值