From 3b32181883ba66dc21a5f88b92bbed232b487a7c Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Tue, 8 Jul 2014 13:09:55 +0200 Subject: Support writing of descriptors Change-Id: I6c93ed820d8532f5540f23faefc7d82a2798667c Reviewed-by: Fabian Bumberger --- src/bluetooth/qlowenergyservice.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/bluetooth/qlowenergyservice.cpp') diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp index 89d9adc2..30fe5733 100644 --- a/src/bluetooth/qlowenergyservice.cpp +++ b/src/bluetooth/qlowenergyservice.cpp @@ -72,6 +72,8 @@ QLowEnergyService::QLowEnergyService(QSharedPointer p, this, SIGNAL(stateChanged(QLowEnergyService::ServiceState))); connect(p.data(), SIGNAL(characteristicChanged(QLowEnergyCharacteristic,QByteArray)), this, SIGNAL(characteristicChanged(QLowEnergyCharacteristic,QByteArray))); + connect(p.data(), SIGNAL(descriptorChanged(QLowEnergyDescriptor,QByteArray)), + this, SIGNAL(descriptorChanged(QLowEnergyDescriptor,QByteArray))); } @@ -238,4 +240,37 @@ bool QLowEnergyService::contains(const QLowEnergyDescriptor &descriptor) const return false; } +/*! + Writes \a newValue as value for \a descriptor. If the operation is successful + the \l descriptorChanged() signal is emitted. \a newValue must contain the + hexadecimal representation of new value. + + A descriptor can only be written if this service is in the \l ServiceDiscovered state + and \a characteristic is writable. + */ +void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor, + const QByteArray &newValue) +{ + //TODO not all descriptors are writable (how to deal with write errors) + Q_D(QLowEnergyService); + + if (!contains(descriptor)) + return; + + if (descriptor.value() == newValue) + return; + + if (state() != ServiceDiscovered || !d->controller) { + d->setError(QLowEnergyService::OperationError); + return; + } + + d->controller->writeDescriptor(descriptor.d_ptr, + descriptor.characteristicHandle(), + descriptor.handle(), + newValue); +} + + + QT_END_NAMESPACE -- cgit v1.2.3