android– 为什么setCharacteristicNotification()实际上没有启用通知?

android– 为什么setCharacteristicNotification()实际上没有启用通知?,第1张

概述BluetoothLeGattAndroidBLE示例包含以下代码:publicvoidsetCharacteristicNotification(BluetoothGattCharacteristiccharacteristic,booleanenabled){if(mBluetoothAdapter==null||mBluetoothGatt==null){

BluetoothLeGatt Android BLE示例包含以下代码:

public voID setCharacteristicNotification(BluetoothGattCharacteristic characteristic,                                          boolean enabled) {    if (mBluetoothAdapter == null || mBluetoothGatt == null) {        Log.w(TAG, "BluetoothAdapter not initialized");        return;    }    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);    // This is specific to Heart Rate Measurement.    if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuID())) {        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(                UUID.fromString(SampleGattAttributes.CLIENT_CHaraCTERISTIC_CONfig));        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);        mBluetoothGatt.writeDescriptor(descriptor);    }}

我的问题基本上是,为什么标记的代码特定于心率测量?似乎具有客户端特征配置描述符(CCCD)特性是控制特征通知的标准方法,那么为什么setCharacteristicNotification()没有负责写入呢?而且由于它没有那样做,setCharacteristicNotification()实际上做了什么?

我对BLE很新,在互联网上没有任何解释,并不认为你已经理解了这一切!所以不要以为我知道什么是CCCD或其他什么!很难找到CCCD甚至代表什么!

编辑:另请参阅此答案,该答案支持我对CCCD的理解(并让我继续想知道为什么你必须在AndroID中手动写入它们,当有一个看起来应该为你做的功能时):https://devzone.nordicsemi.com/index.php/what-does-cccd-mean

解决方法:

我觉得回答有点迟,但今天我有同样的疑问,我找到了一个明确的答案.
使用setCharacteristicNotification()启用通知localy(在AndroID设备上)并将CCC描述符设置为ENABLE_NOTIFICATION_VALUE,您可以在ble外设上启用通知.实际上,为了启用CCC通知,您必须使用setValue()和writeDescriptor(),它们是用于将特性(在本例中为特征描述符)写入远程设备的方法.
我发现了这个:http://processors.wiki.ti.com/index.php/SensorTag_User_Guide

总结

以上是内存溢出为你收集整理的android – 为什么setCharacteristicNotification()实际上没有启用通知?全部内容,希望文章能够帮你解决android – 为什么setCharacteristicNotification()实际上没有启用通知?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098611.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存