8 #ifndef MAIN_BLEDevice_H_
9 #define MAIN_BLEDevice_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <esp_gap_ble_api.h>
13 #include <esp_gattc_api.h>
18 #include "BLEServer.h"
19 #include "BLEClient.h"
22 #include "BLEAddress.h"
27 typedef void (*gap_event_handler)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
28 typedef void (*gattc_event_handler)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param);
29 typedef void (*gatts_event_handler)(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param);
34 static BLEClient* createClient();
35 static BLEServer* createServer();
36 static BLEAddress getAddress();
37 static BLEScan* getScan();
38 static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID);
39 static void init(std::string deviceName);
40 static void setPower(esp_power_level_t powerLevel);
41 static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value);
42 static std::string toString();
43 static void whiteListAdd(BLEAddress address);
44 static void whiteListRemove(BLEAddress address);
45 static void setEncryptionLevel(esp_ble_sec_act_t level);
46 static void setSecurityCallbacks(BLESecurityCallbacks* pCallbacks);
47 static esp_err_t setMTU(uint16_t mtu);
48 static uint16_t getMTU();
49 static bool getInitialized();
51 static BLEAdvertising* getAdvertising();
52 static void startAdvertising();
53 static uint16_t m_appId;
55 static std::map<uint16_t, conn_status_t> getPeerDevices(
bool client);
56 static void addPeerDevice(
void* peer,
bool is_client, uint16_t conn_id);
57 static void updatePeerDevice(
void* peer,
bool _client, uint16_t conn_id);
58 static void removePeerDevice(uint16_t conn_id,
bool client);
59 static BLEClient* getClientByGattIf(uint16_t conn_id);
60 static void setCustomGapHandler(gap_event_handler handler);
61 static void setCustomGattcHandler(gattc_event_handler handler);
62 static void setCustomGattsHandler(gatts_event_handler handler);
63 static void deinit(
bool release_memory =
false);
64 static uint16_t m_localMTU;
65 static esp_ble_sec_act_t m_securityLevel;
68 static BLEServer* m_pServer;
69 static BLEScan* m_pScan;
70 static BLEClient* m_pClient;
71 static BLESecurityCallbacks* m_securityCallbacks;
72 static BLEAdvertising* m_bleAdvertising;
73 static esp_gatt_if_t getGattcIF();
74 static std::map<uint16_t, conn_status_t> m_connectedClientsMap;
76 static void gattClientEventHandler(
77 esp_gattc_cb_event_t event,
78 esp_gatt_if_t gattc_if,
79 esp_ble_gattc_cb_param_t* param);
81 static void gattServerEventHandler(
82 esp_gatts_cb_event_t event,
83 esp_gatt_if_t gatts_if,
84 esp_ble_gatts_cb_param_t* param);
86 static void gapEventHandler(
87 esp_gap_ble_cb_event_t event,
88 esp_ble_gap_cb_param_t* param);
92 static gap_event_handler m_customGapHandler;
93 static gattc_event_handler m_customGattcHandler;
94 static gatts_event_handler m_customGattsHandler;
98 #endif // CONFIG_BT_ENABLED