Search code examples
qtbluetoothformatbluetooth-lowenergygatt

BLE GATT server data format


I'm playing on this example:

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

to better understand how to configure a GATT server. The example fakes a HeartRate profile. In detail it creates a characteristic with this client descriptor:

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

from here:

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

I understand it has both notifications and indications disabled by default (in fact I need to enable them from a client application in order to be notified).

What I really don't understand is this code:

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.
    ...

Well, it appends two bytes to the characteristic's value because it was defined above:

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

but what does the first one mean?

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

I cannot find any documentation about this "format".


Solution

  • The first byte is the flags field specified in the Heart Rate Service (HRS)here. In this example, flags field indicates that the heart rate measurement value is in uint8 format.