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需要读取验证。



你可能感兴趣的:(nRF51822)