【问题标题】:BLE GATT server data formatBLE GATT 服务器数据格式
【发布时间】:2016-06-19 12:53:43
【问题描述】:

我正在玩这个例子:

https://doc-snapshots.qt.io/qt5-dev/qtbluetooth-heartrate-server-example.html

更好地了解如何配置 GATT 服务器。 该示例伪造了心率配置文件。详细地说,它使用此客户端描述符创建一个特征:

const QLowEnergyDescriptorData clientConfig(QBluetoothUuid::ClientCharacteristicConfiguration, QByteArray(2, 0));

从这里:

https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorViewer.aspx?u=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml

我知道它默认禁用通知和指示(实际上我需要从客户端应用程序启用它们才能收到通知)。

我真正不明白的是这段代码:

quint8 currentHeartRate = 60;
const auto heartbeatProvider = [&service, &currentHeartRate, &valueChange]() {
    QByteArray value;
    value.append(char(0)); // Flags that specify the format of the value.
    value.append(char(currentHeartRate)); // Actual value.
    QLowEnergyCharacteristic characteristic = service->characteristic(QBluetoothUuid::HeartRateMeasurement);
    service->writeCharacteristic(characteristic, value); // Potentially causes notification.
    ...

好吧,它在特征值上附加了两个字节,因为它是在上面定义的:

QLowEnergyCharacteristicData charData;
charData.setUuid(QBluetoothUuid::HeartRateMeasurement);
charData.setValue(QByteArray(2, 0));

但是第一个是什么意思?

value.append(char(0)); // Flags that specify the format of the value.

我找不到任何关于这种“格式”的文档。

【问题讨论】:

    标签: qt bluetooth format bluetooth-lowenergy gatt


    【解决方案1】:

    第一个字节是心率服务 (HRS)here 中指定的标志字段。本例中,flags 字段表示心率测量值为 uint8 格式。

    【讨论】:

    • 我生成了随机 UUID 来制作我自己的 GATT 服务器。但是,如果我尝试将值和描述符都设置为QByteArray(1, 0),以便让有效负载只有一个字节长度,我会得到:qt.bluetooth.bluez: attribute of type "{00002902-0000-1000-8000-00805f9b34fb}" has invalid length of 1 bytes。除了 2 之外的任何字节数都会发生同样的情况。为什么?现在没有关于心率配置文件的内容了!
    • 00002902-0000-1000-8000-00805f9b34fb 是Client特征配置描述符uuid,其值为2字节。看来您正在设置此描述符值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多