summaryrefslogtreecommitdiff
path: root/ESP32_BLE_Arduino/src/BLEClient.h
blob: 898f98c18758d8ab42be21daca91021cc7a47834 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * BLEDevice.h
 *
 *  Created on: Mar 22, 2017
 *      Author: kolban
 */
 
#ifndef MAIN_BLEDEVICE_H_
#define MAIN_BLEDEVICE_H_
 
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
 
#include <esp_gattc_api.h>
#include <string.h>
#include <map>
#include <string>
#include <BLERemoteService.h>
#include "BLEService.h"
#include "BLEAddress.h"
 
class BLERemoteService;
class BLEClientCallbacks;
 
/**
 * @brief A model of a %BLE client.
 */
class BLEClient {
public:
BLEClient();
bool                                       connect(BLEAddress address);
void                                       disconnect();
BLEAddress                                 getPeerAddress();
std::map<std::string, BLERemoteService*>*  getServices();
BLERemoteService*                          getService(const char* uuid);
BLERemoteService*                          getService(BLEUUID uuid);
void                                       setClientCallbacks(BLEClientCallbacks *pClientCallbacks);
std::string                                toString();
 
private:
friend class BLEDevice;
friend class BLERemoteCharacteristic;
friend class BLERemoteService;
 
void                                       gattClientEventHandler(
esp_gattc_cb_event_t event,
esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t* param);
 
uint16_t                                   getConnId();
esp_gatt_if_t                              getGattcIf();
BLEAddress    m_peerAddress = BLEAddress((uint8_t*)"\0\0\0\0\0\0");
uint16_t      m_conn_id;
// int           m_deviceType; 
esp_gatt_if_t m_gattc_if;
 
BLEClientCallbacks* m_pClientCallbacks;
FreeRTOS::Semaphore m_semaphoreRegEvt        = FreeRTOS::Semaphore("RegEvt");
FreeRTOS::Semaphore m_semaphoreOpenEvt       = FreeRTOS::Semaphore("OpenEvt");
FreeRTOS::Semaphore m_semaphoreSearchCmplEvt = FreeRTOS::Semaphore("SearchCmplEvt");
std::map<std::string, BLERemoteService*> m_servicesMap;
bool m_haveServices; // Have we previously obtain the set of services. 
}; // class BLEDevice 
 
 
/**
 * @brief Callbacks associated with a %BLE client.
 */
class BLEClientCallbacks {
public:
virtual ~BLEClientCallbacks() {};
virtual void onConnect(BLEClient *pClient) = 0;
};
 
#endif // CONFIG_BT_ENABLED 
#endif /* MAIN_BLEDEVICE_H_ */