@@ -51,6 +51,7 @@ BLEClient::BLEClient() {
51
51
/* *
52
52
* @brief Connect to the partner.
53
53
* @param [in] address The address of the partner.
54
+ * @return True on success.
54
55
*/
55
56
bool BLEClient::connect (BLEAddress address) {
56
57
ESP_LOGD (LOG_TAG, " >> connect(%s)" , address.toString ().c_str ());
@@ -113,29 +114,38 @@ void BLEClient::gattClientEventHandler(
113
114
// ESP_GATTC_NOTIFY_EVT
114
115
//
115
116
// 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).
124
127
//
125
128
case ESP_GATTC_NOTIFY_EVT: {
126
- BLERemoteService * pBLERemoteService = getService (BLEUUID ( evtParam->notify .srvc_id . id . uuid ) );
129
+ BLERemoteService* pBLERemoteService = getService (evtParam->notify .handle );
127
130
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 );
129
133
break ;
130
134
}
131
- BLERemoteCharacteristic* pBLERemoteCharacteristic = pBLERemoteService->getCharacteristic (BLEUUID ( evtParam->notify .char_id . uuid ) );
135
+ BLERemoteCharacteristic* pBLERemoteCharacteristic = pBLERemoteService->getCharacteristic (evtParam->notify .handle );
132
136
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 );
134
139
break ;
135
140
}
136
141
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 ...
139
149
break ;
140
150
} // ESP_GATTC_NOTIFY_EVT
141
151
@@ -189,12 +199,19 @@ void BLEClient::gattClientEventHandler(
189
199
// ESP_GATTC_SEARCH_RES_EVT
190
200
//
191
201
// 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
194
206
//
195
207
case ESP_GATTC_SEARCH_RES_EVT: {
196
208
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
+ );
198
215
m_servicesMap.insert (std::pair<std::string, BLERemoteService *>(uuid.toString (), pRemoteService));
199
216
break ;
200
217
} // ESP_GATTC_SEARCH_RES_EVT
@@ -231,7 +248,12 @@ esp_gatt_if_t BLEClient::getGattcIf() {
231
248
return m_gattc_if;
232
249
} // getGattcIf
233
250
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
+ }
235
257
236
258
/* *
237
259
* @brief Get the service object corresponding to the uuid.
@@ -262,7 +284,7 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) {
262
284
std::string uuidStr = uuid.toString ();
263
285
for (auto &myPair : m_servicesMap) {
264
286
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 () );
266
288
return myPair.second ;
267
289
}
268
290
}
0 commit comments