summaryrefslogtreecommitdiff
path: root/src/BLEService.h
diff options
context:
space:
mode:
authorkolban <kolban1@kolban.com>2017-09-10 13:41:31 -0500
committerkolban <kolban1@kolban.com>2017-09-10 13:41:31 -0500
commit0eecee13a75bf13fd1752d3d9b6bc60709a265d2 (patch)
tree7d1492d47841ffa8b103cc9e111772af77b35481 /src/BLEService.h
parent0.1.0 release (diff)
downloadthermostat-0eecee13a75bf13fd1752d3d9b6bc60709a265d2.tar.gz
thermostat-0eecee13a75bf13fd1752d3d9b6bc60709a265d2.tar.bz2
thermostat-0eecee13a75bf13fd1752d3d9b6bc60709a265d2.zip
0.2.0
Diffstat (limited to 'src/BLEService.h')
-rw-r--r--src/BLEService.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/BLEService.h b/src/BLEService.h
new file mode 100644
index 0000000..86d0776
--- /dev/null
+++ b/src/BLEService.h
@@ -0,0 +1,99 @@
+/*
+ * BLEService.h
+ *
+ * Created on: Mar 25, 2017
+ * Author: kolban
+ */
+
+#ifndef COMPONENTS_CPP_UTILS_BLESERVICE_H_
+#define COMPONENTS_CPP_UTILS_BLESERVICE_H_
+#include "sdkconfig.h"
+#if defined(CONFIG_BT_ENABLED)
+
+#include <esp_gatts_api.h>
+
+#include "BLECharacteristic.h"
+#include "BLEServer.h"
+#include "BLEUUID.h"
+#include "FreeRTOS.h"
+
+class BLEServer;
+
+/**
+ * @brief A data mapping used to manage the set of %BLE characteristics known to the server.
+ */
+class BLECharacteristicMap {
+public:
+ void setByUUID(const char* uuid, BLECharacteristic* pCharacteristic);
+ void setByUUID(BLEUUID uuid, BLECharacteristic* pCharacteristic);
+ void setByHandle(uint16_t handle, BLECharacteristic* pCharacteristic);
+ BLECharacteristic* getByUUID(const char* uuid);
+ BLECharacteristic* getByUUID(BLEUUID uuid);
+ BLECharacteristic* getByHandle(uint16_t handle);
+ BLECharacteristic* getFirst();
+ BLECharacteristic* getNext();
+ std::string toString();
+ void handleGATTServerEvent(
+ esp_gatts_cb_event_t event,
+ esp_gatt_if_t gatts_if,
+ esp_ble_gatts_cb_param_t* param);
+
+
+private:
+ std::map<std::string, BLECharacteristic*> m_uuidMap;
+ std::map<uint16_t, BLECharacteristic*> m_handleMap;
+ std::map<std::string, BLECharacteristic*>::iterator m_iterator;
+};
+
+
+/**
+ * @brief The model of a %BLE service.
+ *
+ */
+class BLEService {
+public:
+ BLEService(const char* uuid);
+ BLEService(BLEUUID uuid);
+
+ void addCharacteristic(BLECharacteristic* pCharacteristic);
+ BLECharacteristic* createCharacteristic(const char* uuid, uint32_t properties);
+ BLECharacteristic* createCharacteristic(BLEUUID uuid, uint32_t properties);
+ void dump();
+ void executeCreate(BLEServer* pServer);
+ BLECharacteristic* getCharacteristic(const char* uuid);
+ BLECharacteristic* getCharacteristic(BLEUUID uuid);
+ BLEUUID getUUID();
+ BLEServer* getServer();
+ void start();
+ std::string toString();
+
+private:
+ friend class BLEServer;
+ friend class BLEServiceMap;
+ friend class BLEDescriptor;
+ friend class BLECharacteristic;
+ friend class BLEDevice;
+
+ BLECharacteristicMap m_characteristicMap;
+ uint16_t m_handle;
+ BLECharacteristic* m_lastCreatedCharacteristic;
+ BLEServer* m_pServer;
+ //FreeRTOS::Semaphore m_serializeMutex;
+ FreeRTOS::Semaphore m_semaphoreAddCharEvt = FreeRTOS::Semaphore("AddCharEvt");
+ FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
+ FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt");
+ BLEUUID m_uuid;
+
+ uint16_t getHandle();
+ BLECharacteristic* getLastCreatedCharacteristic();
+ void handleGATTServerEvent(
+ esp_gatts_cb_event_t event,
+ esp_gatt_if_t gatts_if,
+ esp_ble_gatts_cb_param_t* param);
+ void setHandle(uint16_t handle);
+ //void setService(esp_gatt_srvc_id_t srvc_id);
+}; // BLEService
+
+
+#endif // CONFIG_BT_ENABLED
+#endif /* COMPONENTS_CPP_UTILS_BLESERVICE_H_ */