8 #ifndef COMPONENTS_CPP_UTILS_BLESERVER_H_
9 #define COMPONENTS_CPP_UTILS_BLESERVER_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <esp_gatts_api.h>
19 #include "BLEAdvertising.h"
20 #include "BLECharacteristic.h"
21 #include "BLEService.h"
22 #include "BLESecurity.h"
24 #include "BLEAddress.h"
26 class BLEServerCallbacks;
40 BLEService* getByHandle(uint16_t handle);
41 BLEService* getByUUID(
const char* uuid);
42 BLEService* getByUUID(BLEUUID uuid, uint8_t inst_id = 0);
43 void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param);
44 void setByHandle(uint16_t handle, BLEService* service);
45 void setByUUID(
const char* uuid, BLEService* service);
46 void setByUUID(BLEUUID uuid, BLEService* service);
47 std::string toString();
48 BLEService* getFirst();
49 BLEService* getNext();
50 void removeService(BLEService *service);
51 int getRegisteredServiceCount();
54 std::map<uint16_t, BLEService*> m_handleMap;
55 std::map<BLEService*, std::string> m_uuidMap;
56 std::map<BLEService*, std::string>::iterator m_iterator;
65 uint32_t getConnectedCount();
66 BLEService* createService(
const char* uuid);
67 BLEService* createService(BLEUUID uuid, uint32_t numHandles=15, uint8_t inst_id=0);
68 BLEAdvertising* getAdvertising();
69 void setCallbacks(BLEServerCallbacks* pCallbacks);
70 void startAdvertising();
71 void removeService(BLEService* service);
72 BLEService* getServiceByUUID(
const char* uuid);
73 BLEService* getServiceByUUID(BLEUUID uuid);
74 bool connect(BLEAddress address);
76 void updateConnParams(esp_bd_addr_t remote_bda, uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout);
79 std::map<uint16_t, conn_status_t> getPeerDevices(
bool client);
80 void addPeerDevice(
void* peer,
bool is_client, uint16_t conn_id);
81 void removePeerDevice(uint16_t conn_id,
bool client);
82 BLEServer* getServerByConnId(uint16_t conn_id);
83 void updatePeerMTU(uint16_t connId, uint16_t mtu);
84 uint16_t getPeerMTU(uint16_t conn_id);
90 friend class BLEService;
91 friend class BLECharacteristic;
92 friend class BLEDevice;
93 esp_ble_adv_data_t m_adv_data;
96 uint32_t m_connectedCount;
98 std::map<uint16_t, conn_status_t> m_connectedServersMap;
103 BLEServiceMap m_serviceMap;
104 BLEServerCallbacks* m_pServerCallbacks =
nullptr;
106 void createApp(uint16_t appId);
107 uint16_t getGattsIf();
108 void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
109 void registerApp(uint16_t);
116 class BLEServerCallbacks {
118 virtual ~BLEServerCallbacks() {};
126 virtual void onConnect(BLEServer* pServer);
127 virtual void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t *param);
135 virtual void onDisconnect(BLEServer* pServer);
Definition: FreeRTOS.h:31