8 #ifndef COMPONENTS_CPP_UTILS_BLEUTILS_H_
9 #define COMPONENTS_CPP_UTILS_BLEUTILS_H_
10 #include "sdkconfig.h"
11 #if defined(CONFIG_BT_ENABLED)
12 #include <esp_gattc_api.h>
13 #include <esp_gatts_api.h>
14 #include <esp_gap_ble_api.h>
16 #include "BLEClient.h"
23 static const char* addressTypeToString(esp_ble_addr_type_t type);
24 static std::string adFlagsToString(uint8_t adFlags);
25 static const char* advTypeToString(uint8_t advType);
26 static char* buildHexData(uint8_t* target, uint8_t* source, uint8_t length);
27 static std::string buildPrintData(uint8_t* source,
size_t length);
28 static std::string characteristicPropertiesToString(esp_gatt_char_prop_t prop);
29 static const char* devTypeToString(esp_bt_dev_type_t type);
30 static esp_gatt_id_t buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id = 0);
31 static esp_gatt_srvc_id_t buildGattSrvcId(esp_gatt_id_t gattId,
bool is_primary =
true);
32 static void dumpGapEvent(
33 esp_gap_ble_cb_event_t event,
34 esp_ble_gap_cb_param_t* param);
35 static void dumpGattClientEvent(
36 esp_gattc_cb_event_t event,
37 esp_gatt_if_t gattc_if,
38 esp_ble_gattc_cb_param_t* evtParam);
39 static void dumpGattServerEvent(
40 esp_gatts_cb_event_t event,
41 esp_gatt_if_t gatts_if,
42 esp_ble_gatts_cb_param_t* evtParam);
43 static const char* eventTypeToString(esp_ble_evt_type_t eventType);
44 static BLEClient* findByAddress(BLEAddress address);
45 static BLEClient* findByConnId(uint16_t conn_id);
46 static const char* gapEventToString(uint32_t eventType);
47 static std::string gattCharacteristicUUIDToString(uint32_t characteristicUUID);
48 static std::string gattClientEventTypeToString(esp_gattc_cb_event_t eventType);
49 static std::string gattCloseReasonToString(esp_gatt_conn_reason_t reason);
50 static std::string gattcServiceElementToString(esp_gattc_service_elem_t* pGATTCServiceElement);
51 static std::string gattDescriptorUUIDToString(uint32_t descriptorUUID);
52 static std::string gattServerEventTypeToString(esp_gatts_cb_event_t eventType);
53 static std::string gattServiceIdToString(esp_gatt_srvc_id_t srvcId);
54 static std::string gattServiceToString(uint32_t serviceId);
55 static std::string gattStatusToString(esp_gatt_status_t status);
56 static std::string getMember(uint32_t memberId);
57 static void registerByAddress(BLEAddress address, BLEClient* pDevice);
58 static void registerByConnId(uint16_t conn_id, BLEClient* pDevice);
59 static const char* searchEventTypeToString(esp_gap_search_evt_t searchEvt);
62 #endif // CONFIG_BT_ENABLED