diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-11-22 19:30:14 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-11-22 22:34:59 +0100 |
commit | d88eee8fcf23e20ae76b3dd346b36af693849ccd (patch) | |
tree | 31407c1ef67b8e6a7f96189fc29906d70500346e /ble/BluetoothImpl.h | |
parent | e8aa2eadf309fbc0c0e1418c6bee482e505fa09b (diff) | |
download | ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.gz ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.bz2 ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.xz ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.zip |
o Working enabling of notifications.
Diffstat (limited to 'ble/BluetoothImpl.h')
-rw-r--r-- | ble/BluetoothImpl.h | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/ble/BluetoothImpl.h b/ble/BluetoothImpl.h index 975a011..5b53cd4 100644 --- a/ble/BluetoothImpl.h +++ b/ble/BluetoothImpl.h @@ -40,6 +40,46 @@ protected: // Shared classes +class DefaultBluetoothGattDescriptor : public BluetoothGattDescriptor { +public: + explicit DefaultBluetoothGattDescriptor(const BluetoothGattCharacteristicPtr& characteristic, uint16_t handle, + const Uuid &uuid) : characteristic(characteristic), handle(handle), uuid(uuid), data() {} + + ~DefaultBluetoothGattDescriptor() override { + delete data.underlying(); + }; + + BluetoothGattCharacteristicPtr getCharacteristic() const { + return characteristic; + }; + + uint16_t getHandle() const override { + return handle; + } + + const Uuid getUuid() const override { + return uuid; + } + + void setValue(const ByteBuffer &buffer) override { + delete[] data.underlying(); + + auto sz = buffer.getSize(); + data = ByteBuffer(new uint8_t[sz], sz); + data.copyFromEntire(buffer); + }; + + ByteBuffer getValue() const override { + return data; + }; + +private: + BluetoothGattCharacteristicPtr characteristic; + uint16_t handle; + Uuid uuid; + ByteBuffer data; +}; + class DefaultBluetoothGattCharacteristic : protected LogSetup, public BluetoothGattCharacteristic { public: DefaultBluetoothGattCharacteristic(const BluetoothGattServicePtr &service, uint16_t handle, Uuid uuid, @@ -62,8 +102,8 @@ public: return uuid; } - uint8_t getProperties() const override { - return properties; + CharacteristicProperties getProperties() const override { + return {properties}; } uint16_t getValueHandle() const override { @@ -71,15 +111,26 @@ public: } shared_ptr<BluetoothGattDescriptor> getDescriptor(Uuid uuid) const override { + for (auto &d: descriptors) { + if (d->getUuid() == uuid) { + return d; + } + } + return {}; } + void addDescriptor(shared_ptr<BluetoothGattDescriptor> &&d) { + descriptors.push_back(std::move(d)); + } + protected: BluetoothGattServicePtr service; uint16_t handle; Uuid uuid; uint8_t properties; uint16_t valueHandle; + vector<BluetoothGattDescriptorPtr> descriptors; }; template<typename DeviceType> |