8000 Provide signatures to allow BLEUUID as string · herosugi/esp32-snippets@77b0670 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77b0670

Browse files
authored
Provide signatures to allow BLEUUID as string
Code changes for nkolban#31
1 parent 4401dc0 commit 77b0670

19 files changed

+165
-6
lines changed

cpp_utils/BLEAdvertisedDevice.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ void BLEAdvertisedDevice::setScan(BLEScan* pScan) {
352352
m_pScan = pScan;
353353
} // setScan
354354

355+
/**
356+
* @brief Set the Service UUID for this device.
357+
* @param [in] serviceUUID The discovered serviceUUID
358+
*/
359+
void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
360+
return setServiceUUID(BLEUUID(serviceUUID));
361+
} // setRSSI
362+
355363
/**
356364
* @brief Set the Service UUID for this device.
357365
* @param [in] serviceUUID The discovered serviceUUID

cpp_utils/BLEAdvertisedDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class BLEAdvertisedDevice {
5959
void setName(std::string name);
6060
void setRSSI(int rssi);
6161
void setScan(BLEScan* pScan);
62+
void setServiceUUID(const char* serviceUUID);
6263
void setServiceUUID(BLEUUID serviceUUID);
6364
void setTXPower(int8_t txPower);
6465

cpp_utils/BLEAdvertising.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ void BLEAdvertising::setAppearance(uint16_t appearance) {
5656
} // setAppearance
5757

5858

59+
/**
60+
* @brief Set the service UUID.
61+
* We maintain a class member called m_advData (esp_ble_adv_data_t) that is passed to the
62+
* ESP-IDF advertising functions. In this method, we see two fields within that structure
63+
* namely service_uuid_len and p_service_uuid to be the information supplied in the passed
64+
* in service uuid.
65+
* @param [in] uuid The UUID of the service.
66+
* @return N/A.
67+
*/
68+
void BLEAdvertising::setServiceUUID(const char* serviceUUID) {
69+
return setServiceUUID(BLEUUID(serviceUUID));
70+
}
5971
/**
6072
* @brief Set the service UUID.
6173
* We maintain a class member called m_advData (esp_ble_adv_data_t) that is passed to the

cpp_utils/BLEAdvertising.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class BLEAdvertising {
2323
void start();
2424
void stop();
2525
void setAppearance(uint16_t appearance);
26+
void setServiceUUID(const char* serviceUUID);
2627
void setServiceUUID(BLEUUID serviceUUID);
2728
private:
2829
esp_ble_adv_data_t m_advData;

cpp_utils/BLECharacteristic.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ static const char* LOG_TAG = "BLECharacteristic";
2323

2424
#define NULL_HANDLE (0xffff)
2525

26+
27+
/**
28+
* @brief Construct a characteristic
29+
* @param [in] uuid - UUID (const char*) for the characteristic.
30+
* @param [in] properties - Properties for the characteristic.
31+
*/
32+
BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) {
33+
BLECharacteristic(BLEUUID(uuid), properties);
34+
}
35+
2636
/**
2737
* @brief Construct a characteristic
2838
* @param [in] uuid - UUID for the characteristic.
@@ -122,6 +132,16 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
122132
} // executeCreate
123133

124134

135+
136+
/**
137+
* @brief Return the BLE Descriptor for the given UUID if associated with this characteristic.
138+
* @param [in] descriptorUUID The UUID of the descriptor that we wish to retrieve.
139+
* @return The BLE Descriptor. If no such descriptor is associated with the characteristic, nullptr is returned.
140+
*/
141+
BLEDescriptor* BLECharacteristic::getDescriptorByUUID(const char* descriptorUUID) {
142+
return m_descriptorMap.getByUUID(BLEUUID(descriptorUUID));
143+
} // getDescriptorByUUID
144+
125145
/**
126146
* @brief Return the BLE Descriptor for the given UUID if associated with this characteristic.
127147
* @param [in] descriptorUUID The UUID of the descriptor that we wish to retrieve.

cpp_utils/BLECharacteristic.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class BLECharacteristicCallbacks;
2626
*/
2727
class BLEDescriptorMap {
2828
public:
29+
void setByUUID(const char* uuid, BLEDescriptor *pDescriptor);
2930
void setByUUID(BLEUUID uuid, BLEDescriptor *pDescriptor);
3031
void setByHandle(uint16_t handle, BLEDescriptor *pDescriptor);
32+
BLEDescriptor *getByUUID(const char* uuid);
3133
BLEDescriptor *getByUUID(BLEUUID uuid);
3234
BLEDescriptor *getByHandle(uint16_t handle);
3335
std::string toString();
@@ -52,10 +54,12 @@ class BLEDescriptorMap {
5254
*/
5355
class BLECharacteristic {
5456
public:
57+
BLECharacteristic(const char* uuid, uint32_t properties = 0);
5558
BLECharacteristic(BLEUUID uuid, uint32_t properties = 0);
5659
virtual ~BLECharacteristic();
5760

5861
void addDescriptor(BLEDescriptor* pDescriptor);
62+
BLEDescriptor* getDescriptorByUUID(const char* descriptorUUID);
5963
BLEDescriptor* getDescriptorByUUID(BLEUUID descriptorUUID);
6064
//size_t getLength();
6165
BLEUUID getUUID();

cpp_utils/BLECharacteristicMap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
#include <iomanip>
1111
#include "BLEService.h"
1212

13+
/**
14+
* @brief Return the characteristic by UUID.
15+
* @param [in] UUID The UUID to look up the characteristic.
16+
* @return The characteristic.
17+
*/
18+
BLECharacteristic* BLECharacteristicMap::getByUUID(const char* uuid) {
19+
return getByUUID(BLEUUID(uuid));
20+
}
1321

1422
/**
1523
* @brief Return the characteristic by UUID.

cpp_utils/BLEClient.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ esp_gatt_if_t BLEClient::getGattcIf() {
202202
} // getGattcIf
203203

204204

205+
206+
/**
207+
* @brief Get the service object corresponding to the uuid.
208+
* @param [in] uuid The UUID of the service being sought.
209+
* @return A reference to the Service or nullptr if don't know about it.
210+
*/
211+
BLERemoteService* BLEClient::getService(const char* uuid) {
212+
return getService(BLEUUID(uuid));
213+
}
214+
205215
/**
206216
* @brief Get the service object corresponding to the uuid.
207217
* @param [in] uuid The UUID of the service being sought.

cpp_utils/BLEClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BLEClient {
3232
void disconnect();
3333
BLEAddress getPeerAddress();
3434
std::map<std::string, BLERemoteService*>* getServices();
35+
BLERemoteService* getService(const char* uuid);
3536
BLERemoteService* getService(BLEUUID uuid);
3637
void setClientCallbacks(BLEClientCallbacks *pClientCallbacks);
3738
std::string toString();

cpp_utils/BLEDescriptor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ static const char* LOG_TAG = "BLEDescriptor";
2121

2222

2323
#define NULL_HANDLE (0xffff)
24+
25+
26+
/**
27+
* @brief BLEDescriptor constructor.
28+
*/
29+
BLEDescriptor::BLEDescriptor(const char* uuid) {
30+
BLEDescriptor(BLEUUID(uuid));
31+
}
2432
/**
2533
* @brief BLEDescriptor constructor.
2634
*/

0 commit comments

Comments
 (0)
0