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); processProperties(properties);
readValue();
// QDBusPendingCall readingCall = m_descriptorInterface->asyncCall("GetAll", QVariantMap()); // QDBusPendingCall readingCall = m_descriptorInterface->asyncCall("GetAll", QVariantMap());
// QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(readingCall, this); // QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(readingCall, this);
// connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](){ // connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](){
@ -158,11 +160,11 @@ void BluetoothGattDescriptor::onReadingFinished(QDBusPendingCallWatcher *call)
void BluetoothGattDescriptor::onWritingFinished(QDBusPendingCallWatcher *call) void BluetoothGattDescriptor::onWritingFinished(QDBusPendingCallWatcher *call)
{ {
QByteArray value = m_asyncWrites.take(call);
QDBusPendingReply<void> reply = *call; QDBusPendingReply<void> reply = *call;
if (reply.isError()) { if (reply.isError()) {
qCWarning(dcBluez()) << "Could not write descriptor" << m_uuid.toString() << reply.error().name() << reply.error().message(); qCWarning(dcBluez()) << "Could not write descriptor" << m_uuid.toString() << reply.error().name() << reply.error().message();
} else { } else {
QByteArray value = m_asyncWrites.take(call);
qCDebug(dcBluez()) << "Async descriptor writing finished for" << m_uuid.toString() << value; qCDebug(dcBluez()) << "Async descriptor writing finished for" << m_uuid.toString() << value;
emit writingFinished(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")); QDBusObjectPath serviceObjectPath = qvariant_cast<QDBusObjectPath>(properties.value("Service"));
BluetoothGattService *service = findService(serviceObjectPath); BluetoothGattService *service = findService(serviceObjectPath);
if (service) if (service)
qCDebug(dcBluez()) << "Add characteristic" << serviceObjectPath.path() << properties << service;
service->addCharacteristicInternally(objectPath, properties); service->addCharacteristicInternally(objectPath, properties);
} }
@ -196,6 +197,7 @@ void BluetoothManager::processInterfaceList(const QDBusObjectPath &objectPath, c
QDBusObjectPath characterisitcObjectPath = qvariant_cast<QDBusObjectPath>(properties.value("Characteristic")); QDBusObjectPath characterisitcObjectPath = qvariant_cast<QDBusObjectPath>(properties.value("Characteristic"));
BluetoothGattCharacteristic *characteristic = findCharacteristic(characterisitcObjectPath); BluetoothGattCharacteristic *characteristic = findCharacteristic(characterisitcObjectPath);
if (characteristic) if (characteristic)
qCDebug(dcBluez()) << "Add descriptor" << characterisitcObjectPath.path() << properties << characteristic;
characteristic->addDescriptorInternally(objectPath, properties); characteristic->addDescriptorInternally(objectPath, properties);
} }

View File

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