My Project
 All Classes Functions Variables Pages
BLEDescriptor.h
1 /*
2  * BLEDescriptor.h
3  *
4  * Created on: Jun 22, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
9 #define COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <string>
13 #include "BLEUUID.h"
14 #include "BLECharacteristic.h"
15 #include <esp_gatts_api.h>
16 #include "FreeRTOS.h"
17 
18 class BLEService;
19 class BLECharacteristic;
20 class BLEDescriptorCallbacks;
21 
25 class BLEDescriptor {
26 public:
27  BLEDescriptor(const char* uuid, uint16_t max_len = 100);
28  BLEDescriptor(BLEUUID uuid, uint16_t max_len = 100);
29  virtual ~BLEDescriptor();
30 
31  uint16_t getHandle(); // Get the handle of the descriptor.
32  size_t getLength(); // Get the length of the value of the descriptor.
33  BLEUUID getUUID(); // Get the UUID of the descriptor.
34  uint8_t* getValue(); // Get a pointer to the value of the descriptor.
35  void handleGATTServerEvent(
36  esp_gatts_cb_event_t event,
37  esp_gatt_if_t gatts_if,
38  esp_ble_gatts_cb_param_t* param);
39 
40  void setAccessPermissions(esp_gatt_perm_t perm); // Set the permissions of the descriptor.
41  void setCallbacks(BLEDescriptorCallbacks* pCallbacks); // Set callbacks to be invoked for the descriptor.
42  void setValue(uint8_t* data, size_t size); // Set the value of the descriptor as a pointer to data.
43  void setValue(std::string value); // Set the value of the descriptor as a data buffer.
44 
45  std::string toString(); // Convert the descriptor to a string representation.
46 
47 private:
48  friend class BLEDescriptorMap;
49  friend class BLECharacteristic;
50  BLEUUID m_bleUUID;
51  uint16_t m_handle;
52  BLEDescriptorCallbacks* m_pCallback;
53  BLECharacteristic* m_pCharacteristic;
54  esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
55  FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
56  esp_attr_value_t m_value;
57 
58  void executeCreate(BLECharacteristic* pCharacteristic);
59  void setHandle(uint16_t handle);
60 }; // BLEDescriptor
61 
62 
70 class BLEDescriptorCallbacks {
71 public:
72  virtual ~BLEDescriptorCallbacks();
73  virtual void onRead(BLEDescriptor* pDescriptor);
74  virtual void onWrite(BLEDescriptor* pDescriptor);
75 };
76 #endif /* CONFIG_BT_ENABLED */
77 #endif /* COMPONENTS_CPP_UTILS_BLEDESCRIPTOR_H_ */
Definition: FreeRTOS.h:31