Skip to content

Commit 240d94e

Browse files
committed
Changes for enhancement #113
1 parent d8f4d7a commit 240d94e

File tree

3 files changed

+70
-29
lines changed

3 files changed

+70
-29
lines changed

cpp_utils/BLEService.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void BLEService::handleGATTServerEvent(
248248
break;
249249
} // ESP_GATTS_ADD_CHAR_EVT
250250

251+
251252
// ESP_GATTS_START_EVT
252253
//
253254
// start:

cpp_utils/BLEUtils.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,29 @@ static const member_t members_ids[] = {
288288
{0, "" }
289289
};
290290

291+
typedef struct {
292+
uint32_t assignedNumber;
293+
std::string name;
294+
} gattdescriptor_t;
295+
296+
static const gattdescriptor_t g_descriptor_ids[] = {
297+
{0x2905,"Characteristic Aggregate Format"},
298+
{0x2900,"Characteristic Extended Properties"},
299+
{0x2904,"Characteristic Presentation Format"},
300+
{0x2901,"Characteristic User Description"},
301+
{0x2902,"Client Characteristic Configuration"},
302+
{0x290B,"Environmental Sensing Configuration"},
303+
{0x290C,"Environmental Sensing Measurement"},
304+
{0x290D,"Environmental Sensing Trigger Setting"},
305+
{0x2907,"External Report Reference"},
306+
{0x2909,"Number of Digitals"},
307+
{0x2908,"Report Reference"},
308+
{0x2903,"Server Characteristic Configuration"},
309+
{0x290E,"Time Trigger Setting"},
310+
{0x2906,"Valid Range"},
311+
{0x290A,"Value Trigger Setting"},
312+
{ 0, "" }
313+
};
291314

292315
typedef struct {
293316
uint32_t assignedNumber;
@@ -1801,6 +1824,23 @@ std::string BLEUtils::gattCharacteristicUUIDToString(uint32_t characteristicUUID
18011824
} // gattCharacteristicUUIDToString
18021825

18031826

1827+
/**
1828+
* @brief Given the UUID for a BLE defined descriptor, return its string representation.
1829+
* @param [in] descriptorUUID UUID of the descriptor to be returned as a string.
1830+
* @return The string representation of a descriptor UUID.
1831+
*/
1832+
std::string BLEUtils::gattDescriptorUUIDToString(uint32_t descriptorUUID) {
1833+
gattdescriptor_t* p = (gattdescriptor_t *)g_descriptor_ids;
1834+
while (p->name.length() > 0) {
1835+
if (p->assignedNumber == descriptorUUID) {
1836+
return p->name;
1837+
}
1838+
p++;
1839+
}
1840+
return "";
1841+
} // gattDescriptorUUIDToString
1842+
1843+
18041844
/**
18051845
* @brief Return a string representation of an esp_gattc_service_elem_t.
18061846
* @return A string representation of an esp_gattc_service_elem_t.

cpp_utils/BLEUtils.h

+29-29
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,42 @@
2020
*/
2121
class BLEUtils {
2222
public:
23-
static const char* advTypeToString(uint8_t advType);
24-
static esp_gatt_id_t buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id=0);
25-
23+
static const char* addressTypeToString(esp_ble_addr_type_t type);
24+
static const char* advTypeToString(uint8_t advType);
25+
static esp_gatt_id_t buildGattId(esp_bt_uuid_t uuid, uint8_t inst_id=0);
2626
static esp_gatt_srvc_id_t buildGattSrvcId(esp_gatt_id_t gattId, bool is_primary=true);
27-
static std::string characteristicPropertiesToString(esp_gatt_char_prop_t prop);
28-
static char* buildHexData(uint8_t *target, uint8_t *source, uint8_t length);
29-
static BLEClient* findByConnId(uint16_t conn_id);
30-
static BLEClient* findByAddress(BLEAddress address);
31-
static std::string gattClientEventTypeToString(esp_gattc_cb_event_t eventType);
32-
static std::string gattServerEventTypeToString(esp_gatts_cb_event_t eventType);
33-
static std::string gattcServiceElementToString(esp_gattc_service_elem_t *pGATTCServiceElement);
34-
static std::string gattServiceIdToString(esp_gatt_srvc_id_t srvcId);
35-
static std::string gattStatusToString(esp_gatt_status_t status);
36-
static std::string gattServiceToString(uint32_t serviceId);
37-
static std::string gattCloseReasonToString(esp_gatt_conn_reason_t reason);
38-
static void registerByAddress(BLEAddress address, BLEClient* pDevice);
39-
static void registerByConnId(uint16_t conn_id, BLEClient* pDevice);
40-
static std::string gattCharacteristicUUIDToString(uint32_t characteristicUUID);
41-
static std::string getMember(uint32_t memberId);
42-
static std::string buildPrintData(uint8_t* source, size_t length);
27+
static char* buildHexData(uint8_t* target, uint8_t* source, uint8_t length);
28+
static std::string buildPrintData(uint8_t* source, size_t length);
29+
static std::string characteristicPropertiesToString(esp_gatt_char_prop_t prop);
30+
static const char* devTypeToString(esp_bt_dev_type_t type);
31+
static void dumpGapEvent(
32+
esp_gap_ble_cb_event_t event,
33+
esp_ble_gap_cb_param_t* param);
4334
static void dumpGattClientEvent(
44-
esp_gattc_cb_event_t event,
45-
esp_gatt_if_t gattc_if,
35+
esp_gattc_cb_event_t event,
36+
esp_gatt_if_t gattc_if,
4637
esp_ble_gattc_cb_param_t* evtParam);
4738
static void dumpGattServerEvent(
48-
esp_gatts_cb_event_t event,
49-
esp_gatt_if_t gatts_if,
39+
esp_gatts_cb_event_t event,
40+
esp_gatt_if_t gatts_if,
5041
esp_ble_gatts_cb_param_t* evtParam);
51-
static const char* devTypeToString(esp_bt_dev_type_t type);
52-
static void dumpGapEvent(
53-
esp_gap_ble_cb_event_t event,
54-
esp_ble_gap_cb_param_t* param);
42+
static const char* eventTypeToString(esp_ble_evt_type_t eventType);
43+
static BLEClient* findByAddress(BLEAddress address);
44+
static BLEClient* findByConnId(uint16_t conn_id);
5545
static const char* gapEventToString(uint32_t eventType);
46+
static std::string gattCharacteristicUUIDToString(uint32_t characteristicUUID);
47+
static std::string gattClientEventTypeToString(esp_gattc_cb_event_t eventType);
48+
static std::string gattCloseReasonToString(esp_gatt_conn_reason_t reason);
49+
static std::string gattcServiceElementToString(esp_gattc_service_elem_t *pGATTCServiceElement);
50+
static std::string gattDescriptorUUIDToString(uint32_t descriptorUUID);
51+
static std::string gattServerEventTypeToString(esp_gatts_cb_event_t eventType);
52+
static std::string gattServiceIdToString(esp_gatt_srvc_id_t srvcId);
53+
static std::string gattServiceToString(uint32_t serviceId);
54+
static std::string gattStatusToString(esp_gatt_status_t status);
55+
static std::string getMember(uint32_t memberId);
56+
static void registerByAddress(BLEAddress address, BLEClient* pDevice);
57+
static void registerByConnId(uint16_t conn_id, BLEClient* pDevice);
5658
static const char* searchEventTypeToString(esp_gap_search_evt_t searchEvt);
57-
static const char* addressTypeToString(esp_ble_addr_type_t type);
58-
static const char *eventTypeToString(esp_ble_evt_type_t eventType);
5959
};
6060

6161
#endif // CONFIG_BT_ENABLED

0 commit comments

Comments
 (0)