为什么setCharacteristicNotification()实际上未启用通知? [英] Why does setCharacteristicNotification() not actually enable notifications?

查看:1036
本文介绍了为什么setCharacteristicNotification()实际上未启用通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The BluetoothLeGatt Android BLE example contains the following code:

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()实际上是做什么的?

My question is basically, why is the marked code specific to Heart Rate Measurement? It seems like having a Client Characteristic Config Descriptor (CCCD) characteristic is the standard way to control characteristic notification, so why doesn't setCharacteristicNotification() take care of writing to it? And since it doesn't do that, what does setCharacteristicNotification() actually do?

我对BLE还是很陌生,在互联网上没有关于它的任何解释都不能假设您已经了解了所有知识!因此,不要以为我知道CCCD是什么!找出CCCD甚至代表什么都非常困难!

I'm pretty new to BLE and there aren't any explanations of it on the internet that don't assume that you already understand it all! So don't assume I know what a CCCD or whatever is! It was difficult enough finding out what CCCD even stands for!

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

See also this answer which supports my understanding of CCCDs (and makes me continue to wonder why you have to write to them manually in Android when there is a function that looks like it should do that for you): https://devzone.nordicsemi.com/index.php/what-does-cccd-mean

推荐答案

我认为给出答案有点晚了,但是今天我有同样的疑问,并且找到了明确的答案. 使用setCharacteristicNotification()可以启用通知区域设置(在android设备上),并将CCC描述符设置为ENABLE_NOTIFICATION_VALUE可以在ble外设上启用通知.实际上,要启用CCC通知,您必须使用setValue()writeDescriptor(),它们是用于将特征(在这种情况下为特征描述符)写入远程设备的方法. 我在以下位置找到了它: http://processors.wiki.ti.com/index.php/SensorTag_User_Guide

I think is a litte bit late for give an answer but today I had the same doubt and I found a clear answer. Using setCharacteristicNotification() you enable notification localy (on android device) and setting CCC descriptor to ENABLE_NOTIFICATION_VALUE you enable notification on ble peripheral. In fact for enabling CCC notification you have to use setValue() and writeDescriptor() that are methods used for writing characteristics (in this case characteristics descriptors) to remote device. I found this on: http://processors.wiki.ti.com/index.php/SensorTag_User_Guide

这篇关于为什么setCharacteristicNotification()实际上未启用通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆