From e8aa2eadf309fbc0c0e1418c6bee482e505fa09b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 19 Nov 2018 23:13:50 +0100 Subject: ble-read-characteristic: working READ mode, starting on NOTIFY. --- include/ble/Bluetooth.h | 38 ++++++++++++++++++++++++++++++++------ include/ble/misc.h | 6 ++++-- 2 files changed, 36 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index d95d843..f97f3b8 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -1,7 +1,7 @@ #ifndef BLUETOOTH_H #define BLUETOOTH_H -#include +#include #include #include #include @@ -17,23 +17,30 @@ namespace trygvis { namespace bluetooth { -using namespace std; +using std::shared_ptr; +using std::string; +using std::vector; +using std::map; +using std::runtime_error; + template -using o = std::experimental::optional; +using o = std::optional; class BluetoothAdapter; class BluetoothDevice; class BluetoothGatt; +typedef shared_ptr BluetoothGattPtr; class BluetoothGattService; +typedef shared_ptr BluetoothGattServicePtr; class BluetoothGattCharacteristic; - -typedef shared_ptr BluetoothGattPtr; typedef shared_ptr BluetoothGattCharacteristicPtr; -typedef shared_ptr BluetoothGattServicePtr; + +class BluetoothGattDescriptor; +typedef shared_ptr BluetoothGattDescriptorPtr; class Mac { public: @@ -76,6 +83,17 @@ public: Iterator end(); }; +class BluetoothGattDescriptor { +public: + static const uint8_t DISABLE_NOTIFICATION_VALUE[]; + static const uint8_t ENABLE_INDICATION_VALUE[]; + static const uint8_t ENABLE_NOTIFICATION_VALUE[]; + + virtual ~BluetoothGattDescriptor() = default; + + virtual BluetoothGattCharacteristicPtr getCharacteristic() const = 0; +}; + class BluetoothGattCharacteristic { public: virtual ~BluetoothGattCharacteristic() = default; @@ -89,6 +107,12 @@ public: virtual uint8_t getProperties() const = 0; virtual uint16_t getValueHandle() const = 0; + + virtual shared_ptr getDescriptor(Uuid uuid) const = 0; + + virtual shared_ptr getDescriptor(ShortUuid uuid) const { + return getDescriptor(uuid.toLong()); + }; }; class BluetoothGattService { @@ -131,6 +155,8 @@ public: virtual ByteBuffer readValue(const BluetoothGattCharacteristicPtr &c, ByteBuffer& response) = 0; + virtual void setCharacteristicNotification(const BluetoothGattDescriptorPtr &c, bool enable) = 0; + virtual void discoverServices() = 0; virtual vector> getServices() const = 0; diff --git a/include/ble/misc.h b/include/ble/misc.h index 4ba3309..2508d8e 100644 --- a/include/ble/misc.h +++ b/include/ble/misc.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -10,7 +10,7 @@ namespace trygvis { namespace bluetooth { template -using o = std::experimental::optional; +using o = std::optional; class BluetoothAdapter; class BluetoothDevice; @@ -86,6 +86,8 @@ const ShortUuid PRIMARY_SERVICE{0x2800}; const ShortUuid SECONDARY_SERVICE{0x2801}; const ShortUuid CHARACTERISTIC{0x2803}; +const ShortUuid CLIENT_CHARACTERISTIC_CONFIG{0x2902}; + const ShortUuid TemperatureMeasurement{0x2A1C}; } -- cgit v1.2.3