Experiment with enable indication instead of notification

This commit is contained in:
Simon Stürz 2021-01-27 14:17:55 +01:00
parent a004724b0f
commit 6f46c2c16a
3 changed files with 13 additions and 7 deletions

View File

@ -76,6 +76,8 @@ BluetoothGattDescriptor::BluetoothGattDescriptor(const QDBusObjectPath &path, co
processProperties(properties);
readValue();
// QDBusPendingCall readingCall = m_descriptorInterface->asyncCall("GetAll", QVariantMap());
// QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(readingCall, this);
// connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](){
@ -158,11 +160,11 @@ void BluetoothGattDescriptor::onReadingFinished(QDBusPendingCallWatcher *call)
void BluetoothGattDescriptor::onWritingFinished(QDBusPendingCallWatcher *call)
{
QByteArray value = m_asyncWrites.take(call);
QDBusPendingReply<void> reply = *call;
if (reply.isError()) {
qCWarning(dcBluez()) << "Could not write descriptor" << m_uuid.toString() << reply.error().name() << reply.error().message();
} else {
QByteArray value = m_asyncWrites.take(call);
qCDebug(dcBluez()) << "Async descriptor writing finished for" << m_uuid.toString() << value;
emit writingFinished(value);
}

View File

@ -181,6 +181,7 @@ void BluetoothManager::processInterfaceList(const QDBusObjectPath &objectPath, c
QDBusObjectPath serviceObjectPath = qvariant_cast<QDBusObjectPath>(properties.value("Service"));
BluetoothGattService *service = findService(serviceObjectPath);
if (service)
qCDebug(dcBluez()) << "Add characteristic" << serviceObjectPath.path() << properties << service;
service->addCharacteristicInternally(objectPath, properties);
}
@ -196,6 +197,7 @@ void BluetoothManager::processInterfaceList(const QDBusObjectPath &objectPath, c
QDBusObjectPath characterisitcObjectPath = qvariant_cast<QDBusObjectPath>(properties.value("Characteristic"));
BluetoothGattCharacteristic *characteristic = findCharacteristic(characterisitcObjectPath);
if (characteristic)
qCDebug(dcBluez()) << "Add descriptor" << characterisitcObjectPath.path() << properties << characteristic;
characteristic->addDescriptorInternally(objectPath, properties);
}

View File

@ -214,18 +214,18 @@ bool Nuki::enableNotificationsIndications(BluetoothGattCharacteristic *character
return false;
}
qCDebug(dcNuki()) << "Enable notifications on" << characteristic;
if (!characteristic->startNotifications()) {
qCDebug(dcNuki()) << "Failed to start notifications on" << characteristic;
return false;
}
// qCDebug(dcNuki()) << "Enable notifications on" << characteristic;
// if (!characteristic->startNotifications()) {
// qCDebug(dcNuki()) << "Failed to start notifications on" << characteristic;
// return false;
// }
if (characteristic->properties().testFlag(BluetoothGattCharacteristic::Indicate)) {
qCDebug(dcNuki()) << "Enable indications on" << characteristic;
QByteArray configuration;
QDataStream stream(&configuration, QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
stream << static_cast<quint16>(0x02);
stream << static_cast<quint16>(2);
if (!clientConfiguration->writeValue(configuration)) {
qCWarning(dcNuki()) << "Failed to write client configuration descriptor on" << characteristic;
return false;
@ -590,6 +590,8 @@ void Nuki::setAvailable(bool available)
if (m_available) {
executeCurrentAction();
} else {
// Finish any running actions
finishCurrentAction(false);