如何在bluez中编写客户端特征配置描述符 [英] How to write a client characteristic configuration descriptor in bluez

查看:121
本文介绍了如何在bluez中编写客户端特征配置描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的 linux 板上的 bluez 附带的 example-gatt-server.py 脚本.我想向我的自定义特征之一添加通知.为此,我需要定义客户端特征配置描述符并将其添加到我的自定义特征中.这是我的做法 -

I am working with the example-gatt-server.py script that comes with bluez on my linux board. I want to add notification to one of my custom characteristics. For that I need to define the Client Characteristic Configuration Descriptor and add it to my custom characteristic. Here is how I am doing this -

类 ClientCharacteristicConfigurationDescriptor(Descriptor):

class ClientCharacteristicConfigurationDescriptor(Descriptor):

CCCD_UUID = '2902'

def __init__(self, bus, index, characteristic):
    self.value = array.array('B')
    self.value = self.value.tolist()
    #self.value = []

    Descriptor.__init__(
            self, bus, index,
            self.CCCD_UUID,
            ['read', 'write'],
            characteristic)

def ReadValue(self):
    print("I am reading CCCD value")
    print(self.value)
    return self.value

def WriteValue(self, value):
    print("I am writing CCCD value")
    print type(value)
    #self.value = value
    print(value)

这段代码的灵感来自于已经在 example-gatt-server 文件中定义的 CharacteristicUserDescriptionDescriptor 类.上面的代码在阅读或写作时给了我错误.它甚至不打印我正在读取 CCCD 值"声明.我在这里错过了什么?

This code was inspired by the CharacteristicUserDescriptionDescriptor class that already comes defined in the example-gatt-server file. The above code gives me errors while reading or writing. It doesn't even print the "I am reading CCCD value" statement. What am I missing here?

谢谢!

推荐答案

Bluez 处理客户端特征配置描述符 (CCCD).您不需要在代码中自己定义它.
如果您已经为相应的特性定义了标志notify",那么通知支持应该由 Bluez 透明地处理.

Bluez handles the Client Characteristic Configuration Descriptor (CCCD). You should not need to define it yourself in your code.
Notification support should transparently be handled by Bluez if you have defined the flag 'notify' for the corresponding characteristic.

正如您所注意到的,example-gatt-server 定义了特征用户描述 (CUD) 而不是 CCCD.

As you noticed example-gatt-server defines Characteristic User Description (CUD) and not CCCD.

这篇关于如何在bluez中编写客户端特征配置描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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