summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergyservice.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-08 13:09:55 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-15 20:39:51 +0200
commit3b32181883ba66dc21a5f88b92bbed232b487a7c (patch)
tree3733e3975cd7f5bfcc05422557fe1252f6d7054f /src/bluetooth/qlowenergyservice.cpp
parent4d2fb32117cd37e0cd4ed3de9c43941b11ad708d (diff)
Support writing of descriptors
Change-Id: I6c93ed820d8532f5540f23faefc7d82a2798667c Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'src/bluetooth/qlowenergyservice.cpp')
-rw-r--r--src/bluetooth/qlowenergyservice.cpp35
1 files changed, 35 insertions, 0 deletions
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<QLowEnergyServicePrivate> 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