#ifndef MAIN_BLEDevice_H_
#define MAIN_BLEDevice_H_
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <esp_gap_ble_api.h>
#include <esp_gattc_api.h>
#include <map>
#include <string>
#include <esp_bt.h>
#include "BLEServer.h"
#include "BLEClient.h"
#include "BLEUtils.h"
#include "BLEScan.h"
#include "BLEAddress.h"
typedef void (*gap_event_handler)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param);
typedef void (*gattc_event_handler)(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t* param);
typedef void (*gatts_event_handler)(esp_gatts_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gatts_cb_param_t* param);
class BLEDevice {
public:
static BLEClient* createClient();
static BLEServer* createServer();
static BLEAddress getAddress();
static BLEScan* getScan();
static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID);
static void init(std::string deviceName);
static void setPower(esp_power_level_t powerLevel);
static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value);
static std::string toString();
static void whiteListAdd(BLEAddress address);
static void whiteListRemove(BLEAddress address);
static void setEncryptionLevel(esp_ble_sec_act_t level);
static void setSecurityCallbacks(BLESecurityCallbacks* pCallbacks);
static esp_err_t setMTU(uint16_t mtu);
static uint16_t getMTU();
static bool getInitialized();
static BLEAdvertising* getAdvertising();
static void startAdvertising();
static uint16_t m_appId;
static std::map<uint16_t, conn_status_t> getPeerDevices(bool client);
static void addPeerDevice(void* peer, bool is_client, uint16_t conn_id);
static void updatePeerDevice(void* peer, bool _client, uint16_t conn_id);
static void removePeerDevice(uint16_t conn_id, bool client);
static BLEClient* getClientByGattIf(uint16_t conn_id);
static void setCustomGapHandler(gap_event_handler handler);
static void setCustomGattcHandler(gattc_event_handler handler);
static void setCustomGattsHandler(gatts_event_handler handler);
static void deinit(bool release_memory = false);
static uint16_t m_localMTU;
static esp_ble_sec_act_t m_securityLevel;
private:
static BLEServer* m_pServer;
static BLEScan* m_pScan;
static BLEClient* m_pClient;
static BLESecurityCallbacks* m_securityCallbacks;
static BLEAdvertising* m_bleAdvertising;
static esp_gatt_if_t getGattcIF();
static std::map<uint16_t, conn_status_t> m_connectedClientsMap;
static void gattClientEventHandler(
esp_gattc_cb_event_t event,
esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t* param);
static void gattServerEventHandler(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* param);
static void gapEventHandler(
esp_gap_ble_cb_event_t event,
esp_ble_gap_cb_param_t* param);
public:
static gap_event_handler m_customGapHandler;
static gattc_event_handler m_customGattcHandler;
static gatts_event_handler m_customGattsHandler;
};
#endif
#endif