Skip to content

Commit adc3026

Browse files
committed
Fixes for #114
1 parent 240d94e commit adc3026

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

cpp_utils/BLEService.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ static const char* LOG_TAG = "BLEService"; // Tag for logging.
2929
/**
3030
* @brief Construct an instance of the BLEService
3131
* @param [in] uuid The UUID of the service.
32+
* @param [in] numHandles The maximum number of handles associated with the service.
3233
*/
33-
BLEService::BLEService(const char* uuid) : BLEService(BLEUUID(uuid)) {
34+
BLEService::BLEService(const char* uuid, uint32_t numHandles) : BLEService(BLEUUID(uuid), numHandles) {
3435
}
3536

3637

3738
/**
3839
* @brief Construct an instance of the BLEService
3940
* @param [in] uuid The UUID of the service.
41+
* @param [in] numHandles The maximum number of handles associated with the service.
4042
*/
41-
BLEService::BLEService(BLEUUID uuid) {
42-
m_uuid = uuid;
43-
m_handle = NULL_HANDLE;
44-
m_pServer = nullptr;
43+
BLEService::BLEService(BLEUUID uuid, uint32_t numHandles) {
44+
m_uuid = uuid;
45+
m_handle = NULL_HANDLE;
46+
m_pServer = nullptr;
4547
//m_serializeMutex.setName("BLEService");
4648
m_lastCreatedCharacteristic = nullptr;
49+
m_numHandles = numHandles;
4750
} // BLEService
4851

4952

@@ -62,7 +65,11 @@ void BLEService::executeCreate(BLEServer *pServer) {
6265
esp_gatt_srvc_id_t srvc_id;
6366
srvc_id.id.inst_id = 0;
6467
srvc_id.id.uuid = *m_uuid.getNative();
65-
esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, 10);
68+
esp_err_t errRc = ::esp_ble_gatts_create_service(
69+
getServer()->getGattsIf(),
70+
&srvc_id,
71+
m_numHandles // The maximum number of handles associated with the service.
72+
);
6673

6774
if (errRc != ESP_OK) {
6875
ESP_LOGE(LOG_TAG, "esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));

cpp_utils/BLEService.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class BLECharacteristicMap {
5252
*/
5353
class BLEService {
5454
public:
55-
BLEService(const char* uuid);
56-
BLEService(BLEUUID uuid);
55+
BLEService(const char* uuid, uint32_t numHandles=10);
56+
BLEService(BLEUUID uuid, uint32_t numHandles=10);
5757

5858
void addCharacteristic(BLECharacteristic* pCharacteristic);
5959
BLECharacteristic* createCharacteristic(const char* uuid, uint32_t properties);
@@ -79,9 +79,10 @@ class BLEService {
7979
BLECharacteristic* m_lastCreatedCharacteristic;
8080
BLEServer* m_pServer;
8181
//FreeRTOS::Semaphore m_serializeMutex;
82-
FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
83-
FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt");
82+
FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
83+
FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt");
8484
BLEUUID m_uuid;
85+
uint32_t m_numHandles;
8586

8687
uint16_t getHandle();
8788
BLECharacteristic* getLastCreatedCharacteristic();

cpp_utils/BLEUtils.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -1542,13 +1542,23 @@ void BLEUtils::dumpGattServerEvent(
15421542
} // ESP_GATTS_ADD_CHAR_DESCR_EVT
15431543

15441544
case ESP_GATTS_ADD_CHAR_EVT: {
1545-
ESP_LOGD(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
1546-
gattStatusToString(evtParam->add_char.status).c_str(),
1547-
evtParam->add_char.attr_handle,
1548-
evtParam->add_char.attr_handle,
1549-
evtParam->add_char.service_handle,
1550-
evtParam->add_char.service_handle,
1551-
BLEUUID(evtParam->add_char.char_uuid).toString().c_str());
1545+
if (evtParam->add_char.status == ESP_GATT_OK) {
1546+
ESP_LOGD(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
1547+
gattStatusToString(evtParam->add_char.status).c_str(),
1548+
evtParam->add_char.attr_handle,
1549+
evtParam->add_char.attr_handle,
1550+
evtParam->add_char.service_handle,
1551+
evtParam->add_char.service_handle,
1552+
BLEUUID(evtParam->add_char.char_uuid).toString().c_str());
1553+
} else {
1554+
ESP_LOGE(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
1555+
gattStatusToString(evtParam->add_char.status).c_str(),
1556+
evtParam->add_char.attr_handle,
1557+
evtParam->add_char.attr_handle,
1558+
evtParam->add_char.service_handle,
1559+
evtParam->add_char.service_handle,
1560+
BLEUUID(evtParam->add_char.char_uuid).toString().c_str());
1561+
}
15521562
break;
15531563
} // ESP_GATTS_ADD_CHAR_EVT
15541564

0 commit comments

Comments
 (0)