My Project
 All Classes Functions Variables Pages
BLEService.h
1 /*
2  * BLEService.h
3  *
4  * Created on: Mar 25, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLESERVICE_H_
9 #define COMPONENTS_CPP_UTILS_BLESERVICE_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 
13 #include <esp_gatts_api.h>
14 
15 #include "BLECharacteristic.h"
16 #include "BLEServer.h"
17 #include "BLEUUID.h"
18 #include "FreeRTOS.h"
19 
20 class BLEServer;
21 
25 class BLECharacteristicMap {
26 public:
27  void setByUUID(BLECharacteristic* pCharacteristic, const char* uuid);
28  void setByUUID(BLECharacteristic* pCharacteristic, BLEUUID uuid);
29  void setByHandle(uint16_t handle, BLECharacteristic* pCharacteristic);
30  BLECharacteristic* getByUUID(const char* uuid);
31  BLECharacteristic* getByUUID(BLEUUID uuid);
32  BLECharacteristic* getByHandle(uint16_t handle);
33  BLECharacteristic* getFirst();
34  BLECharacteristic* getNext();
35  std::string toString();
36  void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param);
37 
38 private:
39  std::map<BLECharacteristic*, std::string> m_uuidMap;
40  std::map<uint16_t, BLECharacteristic*> m_handleMap;
41  std::map<BLECharacteristic*, std::string>::iterator m_iterator;
42 };
43 
44 
49 class BLEService {
50 public:
51  void addCharacteristic(BLECharacteristic* pCharacteristic);
52  BLECharacteristic* createCharacteristic(const char* uuid, uint32_t properties);
53  BLECharacteristic* createCharacteristic(BLEUUID uuid, uint32_t properties);
54  void dump();
55  void executeCreate(BLEServer* pServer);
56  void executeDelete();
57  BLECharacteristic* getCharacteristic(const char* uuid);
58  BLECharacteristic* getCharacteristic(BLEUUID uuid);
59  BLEUUID getUUID();
60  BLEServer* getServer();
61  void start();
62  void stop();
63  std::string toString();
64  uint16_t getHandle();
65  uint8_t m_instId = 0;
66 
67 private:
68  BLEService(const char* uuid, uint16_t numHandles);
69  BLEService(BLEUUID uuid, uint16_t numHandles);
70  friend class BLEServer;
71  friend class BLEServiceMap;
72  friend class BLEDescriptor;
73  friend class BLECharacteristic;
74  friend class BLEDevice;
75 
76  BLECharacteristicMap m_characteristicMap;
77  uint16_t m_handle;
78  BLECharacteristic* m_lastCreatedCharacteristic = nullptr;
79  BLEServer* m_pServer = nullptr;
80  BLEUUID m_uuid;
81 
82  FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
83  FreeRTOS::Semaphore m_semaphoreDeleteEvt = FreeRTOS::Semaphore("DeleteEvt");
84  FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt");
85  FreeRTOS::Semaphore m_semaphoreStopEvt = FreeRTOS::Semaphore("StopEvt");
86 
87  uint16_t m_numHandles;
88 
89  BLECharacteristic* getLastCreatedCharacteristic();
90  void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param);
91  void setHandle(uint16_t handle);
92  //void setService(esp_gatt_srvc_id_t srvc_id);
93 }; // BLEService
94 
95 
96 #endif // CONFIG_BT_ENABLED
97 #endif /* COMPONENTS_CPP_UTILS_BLESERVICE_H_ */
Definition: FreeRTOS.h:31