BLE 读取characteristic时,为什么没有 'BLE_GATTS_EVT_READ' ?

今天在添加自定义服务时,

发现有当attribute被写入当时候,有BLE_GATTS_EVT_WRITE 可以响应。

但是没有找到BLE_GATTS_EVT_READ,理论上不应该是成对出现啊?google了一下,还真有人和我有一样的问题。

https://devzone.nordicsemi.com/question/70600/why-do-not-have-ble_gatts_evt_read/


翻译一下高票答案。

What? If you don't set the read characteristic to require authorisation then the stack doesn't call you back, it just returns the data in the characteristic. This is the default case, because in most cases you just want to set the data and have the stack handle it automatically. This is all in the message sequence charts, the chart for GATTS Read Request without Authorization shows there are no callbacks.

If you want to know the characteristic was read, authorise it, change the data before it goes out or in any other way intercept the read, you use BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST and set the characteristic to require read auth.

If you don't need to know, authorise it, change the data before it goes out then you just let the stack handle it for you. Simple.

如果你没有设置读取characteristic是要验证,蓝牙堆栈根本就不会回调你,它直接返回数据。

这是缺省设置,因为在大多数情况下你只是想设置数据后,然后让蓝牙栈自动帮你处理。这些都写在消息流程图里。

如果你想要被回调,当characteristic被读取,被验证,或者需要返回前修改值,使用BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST设置这个characteristic需要读取验证。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值