Skip to content

Commit f19354c

Browse files
committed
Iterim fixes for #82
1 parent 2e05c69 commit f19354c

25 files changed

+540
-193
lines changed

cpp_utils/BLEAdvertisedDevice.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
329329
void BLEAdvertisedDevice::setName(std::string name) {
330330
m_name = name;
331331
m_haveName = true;
332-
ESP_LOGD(LOG_TAG, "- name: %s", m_name.c_str());
332+
ESP_LOGD(LOG_TAG, "- setName(): name: %s", m_name.c_str());
333333
} // setName
334334

335335

@@ -340,7 +340,7 @@ void BLEAdvertisedDevice::setName(std::string name) {
340340
void BLEAdvertisedDevice::setRSSI(int rssi) {
341341
m_rssi = rssi;
342342
m_haveRSSI = true;
343-
ESP_LOGD(LOG_TAG, "- rssi: %d", m_rssi);
343+
ESP_LOGD(LOG_TAG, "- setRSSI(): rssi: %d", m_rssi);
344344
} // setRSSI
345345

346346

@@ -367,7 +367,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
367367
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
368368
m_serviceUUID = serviceUUID;
369369
m_haveServiceUUID = true;
370-
ESP_LOGD(LOG_TAG, "- serviceUUID: %s", serviceUUID.toString().c_str());
370+
ESP_LOGD(LOG_TAG, "- setServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
371371
} // setRSSI
372372

373373

cpp_utils/BLECharacteristic.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ class BLEDescriptorMap {
2929
void setByUUID(const char* uuid, BLEDescriptor *pDescriptor);
3030
void setByUUID(BLEUUID uuid, BLEDescriptor *pDescriptor);
3131
void setByHandle(uint16_t handle, BLEDescriptor *pDescriptor);
32-
BLEDescriptor *getByUUID(const char* uuid);
33-
BLEDescriptor *getByUUID(BLEUUID uuid);
34-
BLEDescriptor *getByHandle(uint16_t handle);
35-
std::string toString();
32+
BLEDescriptor* getByUUID(const char* uuid);
33+
BLEDescriptor* getByUUID(BLEUUID uuid);
34+
BLEDescriptor* getByHandle(uint16_t handle);
35+
std::string toString();
3636
void handleGATTServerEvent(
3737
esp_gatts_cb_event_t event,
3838
esp_gatt_if_t gatts_if,
39-
esp_ble_gatts_cb_param_t *param);
40-
BLEDescriptor *getFirst();
41-
BLEDescriptor *getNext();
39+
esp_ble_gatts_cb_param_t* param);
40+
BLEDescriptor* getFirst();
41+
BLEDescriptor* getNext();
4242
private:
4343
std::map<std::string, BLEDescriptor *> m_uuidMap;
4444
std::map<uint16_t, BLEDescriptor *> m_handleMap;

cpp_utils/BLEClient.cpp

+41-19
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ BLEClient::BLEClient() {
5151
/**
5252
* @brief Connect to the partner.
5353
* @param [in] address The address of the partner.
54+
* @return True on success.
5455
*/
5556
bool BLEClient::connect(BLEAddress address) {
5657
ESP_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
@@ -113,29 +114,38 @@ void BLEClient::gattClientEventHandler(
113114
// ESP_GATTC_NOTIFY_EVT
114115
//
115116
// notify
116-
// uint16_t conn_id
117-
// esp_bd_addr_t remote_bda
118-
// esp_gatt_srvc_id_t srvc_id
119-
// esp_gatt_id_t char_id
120-
// esp_gatt_id_t descr_id
121-
// uint16_t value_len
122-
// uint8_t* value
123-
// bool is_notify
117+
// - uint16_t conn_id
118+
// - esp_bd_addr_t remote_bda
119+
// - uint16_t handle
120+
// - uint16_t value_len
121+
// - uint8_t* value
122+
// - bool is_notify
123+
//
124+
// We have received a notification event which means that the server wishes us to know about a notification
125+
// piece of data. What we must now do is find the characteristic with the associated handle and then
126+
// invoke its notification callback (if it has one).
124127
//
125128
case ESP_GATTC_NOTIFY_EVT: {
126-
BLERemoteService *pBLERemoteService = getService(BLEUUID(evtParam->notify.srvc_id.id.uuid));
129+
BLERemoteService* pBLERemoteService = getService(evtParam->notify.handle);
127130
if (pBLERemoteService == nullptr) {
128-
ESP_LOGE(LOG_TAG, "Could not find service with UUID %s for notification", BLEUUID(evtParam->notify.srvc_id.id.uuid).toString().c_str());
131+
ESP_LOGE(LOG_TAG, "Could not find service containing handle %d 0x%.2x for notification",
132+
evtParam->notify.handle, evtParam->notify.handle);
129133
break;
130134
}
131-
BLERemoteCharacteristic* pBLERemoteCharacteristic = pBLERemoteService->getCharacteristic(BLEUUID(evtParam->notify.char_id.uuid));
135+
BLERemoteCharacteristic* pBLERemoteCharacteristic = pBLERemoteService->getCharacteristic(evtParam->notify.handle);
132136
if (pBLERemoteCharacteristic == nullptr) {
133-
ESP_LOGE(LOG_TAG, "Could not find characteristic with UUID %s for notification", BLEUUID(evtParam->notify.char_id.uuid).toString().c_str());
137+
ESP_LOGE(LOG_TAG, "Could not find characteristic with handle %d 0x%.2x for notification",
138+
evtParam->notify.handle, evtParam->notify.handle);
134139
break;
135140
}
136141
if (pBLERemoteCharacteristic->m_notifyCallback != nullptr) {
137-
pBLERemoteCharacteristic->m_notifyCallback(pBLERemoteCharacteristic, evtParam->notify.value, evtParam->notify.value_len, evtParam->notify.is_notify);
138-
}
142+
pBLERemoteCharacteristic->m_notifyCallback(
143+
pBLERemoteCharacteristic,
144+
evtParam->notify.value,
145+
evtParam->notify.value_len,
146+
evtParam->notify.is_notify
147+
);
148+
} // End we have a callback function ...
139149
break;
140150
} // ESP_GATTC_NOTIFY_EVT
141151

@@ -189,12 +199,19 @@ void BLEClient::gattClientEventHandler(
189199
// ESP_GATTC_SEARCH_RES_EVT
190200
//
191201
// search_res:
192-
// - uint16_t conn_id
193-
// - esp_gatt_srvc_id_t srvc_id
202+
// - uint16_t conn_id
203+
// - uint16_t start_handle
204+
// - uint16_t end_handle
205+
// - esp_gatt_id_t srvc_id
194206
//
195207
case ESP_GATTC_SEARCH_RES_EVT: {
196208
BLEUUID uuid = BLEUUID(evtParam->search_res.srvc_id);
197-
BLERemoteService* pRemoteService = new BLERemoteService(evtParam->search_res.srvc_id, this);
209+
BLERemoteService* pRemoteService = new BLERemoteService(
210+
evtParam->search_res.srvc_id,
211+
this,
212+
evtParam->search_res.start_handle,
213+
evtParam->search_res.end_handle
214+
);
198215
m_servicesMap.insert(std::pair<std::string, BLERemoteService *>(uuid.toString(), pRemoteService));
199216
break;
200217
} // ESP_GATTC_SEARCH_RES_EVT
@@ -231,7 +248,12 @@ esp_gatt_if_t BLEClient::getGattcIf() {
231248
return m_gattc_if;
232249
} // getGattcIf
233250

234-
251+
BLERemoteService* BLEClient::getService(uint16_t handle) {
252+
ESP_LOGD(LOG_TAG, ">> getService: handle: %d", handle);
253+
ESP_LOGE(LOG_TAG, "!!! NOT IMPLEMENTED !!!");
254+
ESP_LOGD(LOG_TAG, "<< getService");
255+
return nullptr;
256+
}
235257

236258
/**
237259
* @brief Get the service object corresponding to the uuid.
@@ -262,7 +284,7 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) {
262284
std::string uuidStr = uuid.toString();
263285
for (auto &myPair : m_servicesMap) {
264286
if (myPair.first == uuidStr) {
265-
ESP_LOGD(LOG_TAG, "<< getService: found");
287+
ESP_LOGD(LOG_TAG, "<< getService: found the service with uuid: %s", uuid.toString().c_str());
266288
return myPair.second;
267289
}
268290
}

cpp_utils/BLEClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BLEClient {
3434
std::map<std::string, BLERemoteService*>* getServices();
3535
BLERemoteService* getService(const char* uuid);
3636
BLERemoteService* getService(BLEUUID uuid);
37+
BLERemoteService* getService(uint16_t handle);
3738
void setClientCallbacks(BLEClientCallbacks *pClientCallbacks);
3839
std::string toString();
3940

cpp_utils/BLEDevice.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,19 @@ void BLEDevice::gattServerEventHandler(
6969
* @brief Handle GATT client events.
7070
*
7171
* Handler for the GATT client events.
72-
* * `ESP_GATTC_OPEN_EVT` – Invoked when a connection is opened.
72+
* * `ESP_GATTC_OPEN_EVT` – Invoked when a connection is opened.
7373
* * `ESP_GATTC_PREP_WRITE_EVT` – Response to write a characteristic.
74-
* * `ESP_GATTC_READ_CHAR_EVT` – Response to read a characteristic.
75-
* * `ESP_GATTC_REG_EVT` – Invoked when a GATT client has been registered.
74+
* * `ESP_GATTC_READ_CHAR_EVT` – Response to read a characteristic.
75+
* * `ESP_GATTC_REG_EVT` – Invoked when a GATT client has been registered.
7676
*
7777
* @param [in] event
7878
* @param [in] gattc_if
7979
* @param [in] param
8080
*/
8181
void BLEDevice::gattClientEventHandler(
82-
esp_gattc_cb_event_t event,
83-
esp_gatt_if_t gattc_if,
84-
esp_ble_gattc_cb_param_t *param) {
82+
esp_gattc_cb_event_t event,
83+
esp_gatt_if_t gattc_if,
84+
esp_ble_gattc_cb_param_t* param) {
8585

8686
ESP_LOGD(LOG_TAG, "gattClientEventHandler [esp_gatt_if: %d] ... %s",
8787
gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str());

0 commit comments

Comments
 (0)