Qt蓝牙:获取电池电量值通知

问题描述

我正在开发一个程序,以读取智能手表的一些特征(心率,电池电量,湿度和温度)。 为此,我遵循心率游戏示例。从此示例中,我可以从智能手机上的模拟器获取有关心率的通知,但对于其他参数,我无法获取这些值。 例如,对于心率,我正在为stateChanged:(connect(m_service,&QLowEnergyService::stateChanged,this,&DeviceHandler::serviceStateChanged);

if (uuid == QBluetoothUuid(QBluetoothUuid::HeartRate)) {
        const QLowEnergyCharacteristic hrChar = m_service->characteristic(QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement));
        m_notificationDesc = hrChar.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
        m_service->writeDescriptor(m_notificationDesc,QByteArray::fromHex("0100"));

这是updateValue:(connect(m_service,&QLowEnergyService::characteristicChanged,&DeviceHandler::updateValue);

auto data = reinterpret_cast<const quint8 *>(value.constData());
quint8 flags = *data;


 if (flags & 0x1) // HR 16 bit? otherwise 8 bit
     hrvalue = static_cast<int>(qFromLittleEndian<quint16>(data[1]));
 else
     hrvalue = static_cast<int>(data[1]);
qCDebug(BLELog) << hrvalue;

如果我运行程序,它会找到设备并连接到该设备,并且每次按模拟器上的“通知”按钮时,我都会正确获取新的心率值。

对于其他服务,我没有HeartRateMeasurment。 对于电池,我尝试使用BatteryService,然后使用batterylevel作为特征,但是我的程序在静止不动(但未阻塞)时不读取值。 我应该使用哪些服务和特性来获得与心律相同的结果? 非常感谢您的所有帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)