From c4f5a247cccda4bad46aeff530364f7e4da2df57 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Tue, 8 Dec 2015 11:36:58 +0100 Subject: Bluetooth LE: Implement GATT server write support. Write Request, Write Command and Execute Write Request are fully implemented now. Signed Write support is still missing. Notifications and Indications are sent. The server side gets informed via the respective signals when a client writes a characteristic or descriptor. Change-Id: Icba6a0270f6e1c4c3ed2ba61b55c1a5fbb69752b Reviewed-by: Alex Blasche --- src/bluetooth/qlowenergycharacteristicdata.cpp | 43 ++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qlowenergycharacteristicdata.cpp') diff --git a/src/bluetooth/qlowenergycharacteristicdata.cpp b/src/bluetooth/qlowenergycharacteristicdata.cpp index f11779a5..a200f1c0 100644 --- a/src/bluetooth/qlowenergycharacteristicdata.cpp +++ b/src/bluetooth/qlowenergycharacteristicdata.cpp @@ -39,13 +39,19 @@ #include #include +#include + QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(QT_BT) struct QLowEnergyCharacteristicDataPrivate : public QSharedData { - QLowEnergyCharacteristicDataPrivate() : properties(QLowEnergyCharacteristic::Unknown) {} + QLowEnergyCharacteristicDataPrivate() + : properties(QLowEnergyCharacteristic::Unknown) + , minimumValueLength(0) + , maximumValueLength(INT_MAX) + {} QBluetoothUuid uuid; QLowEnergyCharacteristic::PropertyTypes properties; @@ -53,6 +59,8 @@ struct QLowEnergyCharacteristicDataPrivate : public QSharedData QByteArray value; QBluetooth::AttAccessConstraints readConstraints; QBluetooth::AttAccessConstraints writeConstraints; + int minimumValueLength; + int maximumValueLength; }; /*! @@ -196,6 +204,35 @@ QBluetooth::AttAccessConstraints QLowEnergyCharacteristicData::writeConstraints( return d->writeConstraints; } +/*! + Specifies \a minimum and \a maximum to be the smallest and largest length, respectively, + that the value of this characteristic can have. The unit is bytes. If \a minimum and + \a maximum are equal, the characteristic has a fixed-length value. + */ +void QLowEnergyCharacteristicData::setValueLength(int minimum, int maximum) +{ + d->minimumValueLength = minimum; + d->maximumValueLength = qMax(minimum, maximum); +} + +/*! + Returns the minimum length in bytes that the value of this characteristic can have. + The default is zero. + */ +int QLowEnergyCharacteristicData::minimumValueLength() const +{ + return d->minimumValueLength; +} + +/*! + Returns the maximum length in bytes that the value of this characteristic can have. + By default, there is no limit beyond the constraints of the data type. + */ +int QLowEnergyCharacteristicData::maximumValueLength() const +{ + return d->maximumValueLength; +} + /*! Returns true if and only if this characteristic is valid, that is, it has a non-null UUID. */ @@ -221,7 +258,9 @@ bool operator==(const QLowEnergyCharacteristicData &cd1, const QLowEnergyCharact && cd1.descriptors() == cd2.descriptors() && cd1.value() == cd2.value() && cd1.readConstraints() == cd2.readConstraints() - && cd1.writeConstraints() == cd2.writeConstraints()); + && cd1.writeConstraints() == cd2.writeConstraints() + && cd1.minimumValueLength() == cd2.maximumValueLength() + && cd1.maximumValueLength() == cd2.maximumValueLength()); } /*! -- cgit v1.2.3