|
例如将串口例程中的RX和TX特征修改为同时具有Notify,read和write属性,在回调函数中怎么区分read和write数据,数据分别是来自哪个特征的
static void on_write(ble_nus_t * p_nus, ble_evt_t * p_ble_evt)
{
ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
if (
(p_evt_write->handle == p_nus->rx_handles.cccd_handle)
&&
(p_evt_write->len == 2)
)
{
if (ble_srv_is_notification_enabled(p_evt_write->data))
{
p_nus->is_notification_enabled = true;
}
else
{
p_nus->is_notification_enabled = false;
}
}
else if (
(p_evt_write->handle == p_nus->tx_handles.value_handle)
&&
(p_nus->data_handler != NULL)
)
{
p_nus->data_handler(p_nus, p_evt_write->data, p_evt_write->len);
}
else
{
// Do Nothing. This event is not relevant for this service.
}
}
感觉app给芯片write数据应该是通过p_evt_write->handle == p_nus->tx_handles.value_handle来判断,不知道对不对,那么read(就是APP主动读取数据不是Notify给APP)是怎么处理呢 |
|