summaryrefslogtreecommitdiff
path: root/sensor/patchedBLE/src/BLEDescriptor.h
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2018-08-03 12:23:17 +0100
committerdakkar <dakkar@thenautilus.net>2018-08-03 12:23:17 +0100
commitbb00c2da73b6ab8837f50c9f889ee151f8abc036 (patch)
tree3922eb826386260568ccaa1da7056c141f752a97 /sensor/patchedBLE/src/BLEDescriptor.h
parentdon't print from callback, there's races (diff)
parentUpload of 0.4.16 (diff)
downloadthermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.tar.gz
thermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.tar.bz2
thermostat-bb00c2da73b6ab8837f50c9f889ee151f8abc036.zip
Add 'sensor/patchedBLE/' from commit '7951347ed68313d75c367e1f2cce763cb56d1eb2'
git-subtree-dir: sensor/patchedBLE git-subtree-mainline: 27e209cf58abeda1dc110777f99a98804a13fdbf git-subtree-split: 7951347ed68313d75c367e1f2cce763cb56d1eb2
Diffstat (limited to 'sensor/patchedBLE/src/BLEDescriptor.h')
-rw-r--r--sensor/patchedBLE/src/BLEDescriptor.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/sensor/patchedBLE/src/BLEDescriptor.h b/sensor/patchedBLE/src/BLEDescriptor.h
new file mode 100644
index 0000000..d9e0aef
--- /dev/null
+++ b/sensor/patchedBLE/src/BLEDescriptor.h
@@ -0,0 +1,77 @@
+/*
+ * BLEDescriptor.h
+ *
+ * Created on: Jun 22, 2017
+ * Author: kolban
+ */
+
+#ifndef COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
+#define COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
+#include "sdkconfig.h"
+#if defined(CONFIG_BT_ENABLED)
+#include <string>
+#include "BLEUUID.h"
+#include "BLECharacteristic.h"
+#include <esp_gatts_api.h>
+#include "FreeRTOS.h"
+
+class BLEService;
+class BLECharacteristic;
+class BLEDescriptorCallbacks;
+
+/**
+ * @brief A model of a %BLE descriptor.
+ */
+class BLEDescriptor {
+public:
+ BLEDescriptor(const char* uuid);
+ BLEDescriptor(BLEUUID uuid);
+ virtual ~BLEDescriptor();
+
+ uint16_t getHandle(); // Get the handle of the descriptor.
+ size_t getLength(); // Get the length of the value of the descriptor.
+ BLEUUID getUUID(); // Get the UUID of the descriptor.
+ uint8_t* getValue(); // Get a pointer to the value of the descriptor.
+ void handleGATTServerEvent(
+ esp_gatts_cb_event_t event,
+ esp_gatt_if_t gatts_if,
+ esp_ble_gatts_cb_param_t* param);
+
+ void setAccessPermissions(esp_gatt_perm_t perm); // Set the permissions of the descriptor.
+ void setCallbacks(BLEDescriptorCallbacks* pCallbacks); // Set callbacks to be invoked for the descriptor.
+ void setValue(uint8_t* data, size_t size); // Set the value of the descriptor as a pointer to data.
+ void setValue(std::string value); // Set the value of the descriptor as a data buffer.
+
+ std::string toString(); // Convert the descriptor to a string representation.
+
+private:
+ friend class BLEDescriptorMap;
+ friend class BLECharacteristic;
+ BLEUUID m_bleUUID;
+ uint16_t m_handle;
+ BLEDescriptorCallbacks* m_pCallback;
+ BLECharacteristic* m_pCharacteristic;
+ esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
+ FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
+ esp_attr_value_t m_value;
+
+ void executeCreate(BLECharacteristic* pCharacteristic);
+ void setHandle(uint16_t handle);
+}; // BLEDescriptor
+
+
+/**
+ * @brief Callbacks that can be associated with a %BLE descriptors to inform of events.
+ *
+ * When a server application creates a %BLE descriptor, we may wish to be informed when there is either
+ * a read or write request to the descriptors value. An application can register a
+ * sub-classed instance of this class and will be notified when such an event happens.
+ */
+class BLEDescriptorCallbacks {
+public:
+ virtual ~BLEDescriptorCallbacks();
+ virtual void onRead(BLEDescriptor* pDescriptor);
+ virtual void onWrite(BLEDescriptor* pDescriptor);
+};
+#endif /* CONFIG_BT_ENABLED */
+#endif /* COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_ */