My Project
 All Classes Functions Variables Pages
BLERemoteService.h
1 /*
2  * BLERemoteService.h
3  *
4  * Created on: Jul 8, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
9 #define COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 
13 #include <map>
14 
15 #include "BLEClient.h"
16 #include "BLERemoteCharacteristic.h"
17 #include "BLEUUID.h"
18 #include "FreeRTOS.h"
19 
20 class BLEClient;
21 class BLERemoteCharacteristic;
22 
23 
27 class BLERemoteService {
28 public:
29  virtual ~BLERemoteService();
30 
31  // Public methods
32  BLERemoteCharacteristic* getCharacteristic(const char* uuid); // Get the specified characteristic reference.
33  BLERemoteCharacteristic* getCharacteristic(BLEUUID uuid); // Get the specified characteristic reference.
34  BLERemoteCharacteristic* getCharacteristic(uint16_t uuid); // Get the specified characteristic reference.
35  std::map<std::string, BLERemoteCharacteristic*>* getCharacteristics();
36  std::map<uint16_t, BLERemoteCharacteristic*>* getCharacteristicsByHandle(); // Get the characteristics map.
37  void getCharacteristics(std::map<uint16_t, BLERemoteCharacteristic*>* pCharacteristicMap);
38 
39  BLEClient* getClient(void); // Get a reference to the client associated with this service.
40  uint16_t getHandle(); // Get the handle of this service.
41  BLEUUID getUUID(void); // Get the UUID of this service.
42  std::string getValue(BLEUUID characteristicUuid); // Get the value of a characteristic.
43  void setValue(BLEUUID characteristicUuid, std::string value); // Set the value of a characteristic.
44  std::string toString(void);
45 
46 private:
47  // Private constructor ... never meant to be created by a user application.
48  BLERemoteService(esp_gatt_id_t srvcId, BLEClient* pClient, uint16_t startHandle, uint16_t endHandle);
49 
50  // Friends
51  friend class BLEClient;
52  friend class BLERemoteCharacteristic;
53 
54  // Private methods
55  void retrieveCharacteristics(void); // Retrieve the characteristics from the BLE Server.
56  esp_gatt_id_t* getSrvcId(void);
57  uint16_t getStartHandle(); // Get the start handle for this service.
58  uint16_t getEndHandle(); // Get the end handle for this service.
59 
60  void gattClientEventHandler(
61  esp_gattc_cb_event_t event,
62  esp_gatt_if_t gattc_if,
63  esp_ble_gattc_cb_param_t* evtParam);
64 
65  void removeCharacteristics();
66 
67  // Properties
68 
69  // We maintain a map of characteristics owned by this service keyed by a string representation of the UUID.
70  std::map<std::string, BLERemoteCharacteristic*> m_characteristicMap;
71 
72  // We maintain a map of characteristics owned by this service keyed by a handle.
73  std::map<uint16_t, BLERemoteCharacteristic*> m_characteristicMapByHandle;
74 
75  bool m_haveCharacteristics; // Have we previously obtained the characteristics.
76  BLEClient* m_pClient;
77  FreeRTOS::Semaphore m_semaphoreGetCharEvt = FreeRTOS::Semaphore("GetCharEvt");
78  esp_gatt_id_t m_srvcId;
79  BLEUUID m_uuid; // The UUID of this service.
80  uint16_t m_startHandle; // The starting handle of this service.
81  uint16_t m_endHandle; // The ending handle of this service.
82 }; // BLERemoteService
83 
84 #endif /* CONFIG_BT_ENABLED */
85 #endif /* COMPONENTS_CPP_UTILS_BLEREMOTESERVICE_H_ */
Definition: FreeRTOS.h:31