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非常陌生,并且在互联网上没有任何关于BLE的解释不假设您已经了解了所有内容!因此,不要以为我知道CCCD是什么!找出CCCD代表什么已经非常困难!

编辑:另请参阅此答案,它支持我对CCCD的理解(并且让我继续怀疑为什么当有一个看起来像它应该为您完成的功能时,为什么您必须在Android中手动对其进行写操作):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

09-10 00:59
查看更多