My Project
 All Classes Functions Variables Pages
BLERemoteCharacteristic.h
1 /*
2  * BLERemoteCharacteristic.h
3  *
4  * Created on: Jul 8, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_
9 #define COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 
13 #include <string>
14 
15 #include <esp_gattc_api.h>
16 
17 #include "BLERemoteService.h"
18 #include "BLERemoteDescriptor.h"
19 #include "BLEUUID.h"
20 #include "BLEAddress.h"
21 #include "FreeRTOS.h"
22 
23 class BLERemoteService;
24 class BLERemoteDescriptor;
25 typedef void (*notify_callback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
26 
30 class BLERemoteCharacteristic {
31 public:
32  ~BLERemoteCharacteristic();
33 
34  // Public member functions
35  bool canBroadcast();
36  bool canIndicate();
37  bool canNotify();
38  bool canRead();
39  bool canWrite();
40  bool canWriteNoResponse();
41  BLERemoteDescriptor* getDescriptor(BLEUUID uuid);
42  std::map<std::string, BLERemoteDescriptor*>* getDescriptors();
43  uint16_t getHandle();
44  BLEUUID getUUID();
45  std::string readValue();
46  uint8_t readUInt8();
47  uint16_t readUInt16();
48  uint32_t readUInt32();
49  void registerForNotify(notify_callback _callback, bool notifications = true);
50  void writeValue(uint8_t* data, size_t length, bool response = false);
51  void writeValue(std::string newValue, bool response = false);
52  void writeValue(uint8_t newValue, bool response = false);
53  std::string toString();
54  uint8_t* readRawData();
55  BLEAddress getRemoteAddress();
56 
57 private:
58  BLERemoteCharacteristic(uint16_t handle, BLEUUID uuid, esp_gatt_char_prop_t charProp, BLERemoteService* pRemoteService);
59  friend class BLEClient;
60  friend class BLERemoteService;
61  friend class BLERemoteDescriptor;
62 
63  // Private member functions
64  void gattClientEventHandler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* evtParam);
65 
66  BLERemoteService* getRemoteService();
67  void removeDescriptors();
68  void retrieveDescriptors();
69 
70  // Private properties
71  BLEUUID m_uuid;
72  esp_gatt_char_prop_t m_charProp;
73  uint16_t m_handle;
74  BLERemoteService* m_pRemoteService;
75  FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
76  FreeRTOS::Semaphore m_semaphoreRegForNotifyEvt = FreeRTOS::Semaphore("RegForNotifyEvt");
77  FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
78  std::string m_value;
79  uint8_t *m_rawData;
80  notify_callback m_notifyCallback;
81 
82  // We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID.
83  std::map<std::string, BLERemoteDescriptor*> m_descriptorMap;
84 }; // BLERemoteCharacteristic
85 #endif /* CONFIG_BT_ENABLED */
86 #endif /* COMPONENTS_CPP_UTILS_BLEREMOTECHARACTERISTIC_H_ */
Definition: FreeRTOS.h:31