Qt GATT服务器数据格式

Qt GATT服务器数据格式,qt,bluetooth,format,bluetooth-lowenergy,gatt,Qt,Bluetooth,Format,Bluetooth Lowenergy,Gatt,我在玩这个例子: 更好地了解如何配置GATT服务器。 该示例伪造了心率配置文件。具体而言,它使用此客户端描述符创建了一个特征: const QLowEnergyDescriptorData clientConfig(QBluetoothUuid::ClientCharacteristicConfiguration, QByteArray(2, 0)); 从这里开始: 我知道它在默认情况下禁用了通知和指示(事实上,我需要从客户端应用程序启用它们才能收到通知) 我真正不明白的是这个代码: qu

我在玩这个例子:

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

const QLowEnergyDescriptorData clientConfig(QBluetoothUuid::ClientCharacteristicConfiguration, QByteArray(2, 0));
从这里开始:

我知道它在默认情况下禁用了通知和指示(事实上,我需要从客户端应用程序启用它们才能收到通知)

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

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.

我找不到有关此“格式”的任何文档。

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

我生成了随机UUID以创建自己的GATT服务器。但是,如果我试图将值和描述符都设置为
QByteArray(1,0)
以便有效负载只有一个字节的长度,我会得到:
qt.bluetooth.bluez:{00002902-0000-1000-8000-00805f9b34fb}类型的属性具有无效的1字节长度
。除2以外的任何字节数也会发生同样的情况。为什么?现在没有任何关于心率的资料!00002902-0000-1000-8000-00805f9b34fb是客户端特征配置描述符uuid,其值为2字节。您似乎正在设置此描述符值。