123 BLEEvent(esp_gap_ble_cb_event_t e, esp_ble_gap_cb_param_t *p) {
125 this->init_gap_data_(e, p);
133 BLEEvent(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
135 this->init_gattc_data_(e, i, p);
143 BLEEvent(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
145 this->init_gatts_data_(e, i, p);
156 switch (this->
type_) {
162 if (!this->
event_.gattc.is_inline && this->event_.gattc.data.heap_data !=
nullptr) {
163 delete[] this->
event_.gattc.data.heap_data;
166 this->
event_.gattc.is_inline =
false;
167 this->
event_.gattc.data.heap_data =
nullptr;
171 if (!this->
event_.gatts.is_inline && this->event_.gatts.data.heap_data !=
nullptr) {
172 delete[] this->
event_.gatts.data.heap_data;
175 this->
event_.gatts.is_inline =
false;
176 this->
event_.gatts.data.heap_data =
nullptr;
185 this->init_gap_data_(e, p);
188 void load_gattc_event(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
191 this->init_gattc_data_(e, i, p);
194 void load_gatts_event(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
197 this->init_gatts_data_(e, i, p);
267 template<
typename EventStruct,
size_t InlineSize>
268 void copy_data_with_inline_storage_(EventStruct &event,
const uint8_t *src_data, uint16_t
len,
269 uint8_t **param_value_ptr) {
270 event.data_len =
len;
272 if (
len <= InlineSize) {
273 event.is_inline =
true;
274 memcpy(event.data.inline_data, src_data,
len);
275 *param_value_ptr =
event.data.inline_data;
277 event.is_inline =
false;
278 event.data.heap_data =
new uint8_t[
len];
279 memcpy(event.data.heap_data, src_data,
len);
280 *param_value_ptr =
event.data.heap_data;
283 event.is_inline =
false;
284 event.data.heap_data =
nullptr;
285 *param_value_ptr =
nullptr;
290 void init_gap_data_(esp_gap_ble_cb_event_t e, esp_ble_gap_cb_param_t *p) {
291 this->
event_.gap.gap_event = e;
299 case ESP_GAP_BLE_SCAN_RESULT_EVT:
300 memcpy(this->
event_.gap.scan_result.bda, p->scan_rst.bda,
sizeof(esp_bd_addr_t));
301 this->
event_.gap.scan_result.ble_addr_type = p->scan_rst.ble_addr_type;
302 this->
event_.gap.scan_result.rssi = p->scan_rst.rssi;
303 this->
event_.gap.scan_result.adv_data_len = p->scan_rst.adv_data_len;
304 this->
event_.gap.scan_result.scan_rsp_len = p->scan_rst.scan_rsp_len;
305 this->
event_.gap.scan_result.search_evt = p->scan_rst.search_evt;
306 memcpy(this->
event_.gap.scan_result.ble_adv, p->scan_rst.ble_adv,
307 ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX);
310 case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
311 this->
event_.gap.scan_complete.status = p->scan_param_cmpl.status;
314 case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
315 this->
event_.gap.scan_complete.status = p->scan_start_cmpl.status;
318 case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
319 this->
event_.gap.scan_complete.status = p->scan_stop_cmpl.status;
324 case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
325 this->
event_.gap.adv_complete.status = p->adv_data_cmpl.status;
327 case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
328 this->
event_.gap.adv_complete.status = p->scan_rsp_data_cmpl.status;
330 case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
331 this->
event_.gap.adv_complete.status = p->adv_data_raw_cmpl.status;
333 case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
334 this->
event_.gap.adv_complete.status = p->adv_start_cmpl.status;
336 case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
337 this->
event_.gap.adv_complete.status = p->adv_stop_cmpl.status;
342 case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
343 this->
event_.gap.read_rssi_complete.status = p->read_rssi_cmpl.status;
344 this->
event_.gap.read_rssi_complete.rssi = p->read_rssi_cmpl.rssi;
345 memcpy(this->
event_.gap.read_rssi_complete.remote_addr, p->read_rssi_cmpl.remote_addr,
sizeof(esp_bd_addr_t));
350 case ESP_GAP_BLE_AUTH_CMPL_EVT:
351 case ESP_GAP_BLE_SEC_REQ_EVT:
352 case ESP_GAP_BLE_PASSKEY_NOTIF_EVT:
353 case ESP_GAP_BLE_PASSKEY_REQ_EVT:
354 case ESP_GAP_BLE_NC_REQ_EVT:
355 memcpy(&this->
event_.gap.security, &p->ble_security,
sizeof(esp_ble_sec_t));
368 void init_gattc_data_(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
369 this->
event_.gattc.gattc_event = e;
370 this->
event_.gattc.gattc_if = i;
374 memset(&this->
event_.gattc.gattc_param, 0,
sizeof(this->event_.gattc.gattc_param));
375 this->
event_.gattc.is_inline =
false;
376 this->
event_.gattc.data.heap_data =
nullptr;
377 this->
event_.gattc.data_len = 0;
386 this->
event_.gattc.gattc_param = *p;
392 case ESP_GATTC_NOTIFY_EVT:
393 copy_data_with_inline_storage_<
decltype(this->
event_.gattc), GATTC_INLINE_DATA_SIZE>(
394 this->
event_.gattc, p->notify.value, p->notify.value_len, &this->event_.gattc.gattc_param.notify.value);
396 case ESP_GATTC_READ_CHAR_EVT:
397 case ESP_GATTC_READ_DESCR_EVT:
398 copy_data_with_inline_storage_<
decltype(this->
event_.gattc), GATTC_INLINE_DATA_SIZE>(
399 this->
event_.gattc, p->read.value, p->read.value_len, &this->event_.gattc.gattc_param.read.value);
402 this->
event_.gattc.is_inline =
false;
403 this->
event_.gattc.data.heap_data =
nullptr;
404 this->
event_.gattc.data_len = 0;
410 void init_gatts_data_(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
411 this->
event_.gatts.gatts_event = e;
412 this->
event_.gatts.gatts_if = i;
416 memset(&this->
event_.gatts.gatts_param, 0,
sizeof(this->event_.gatts.gatts_param));
417 this->
event_.gatts.is_inline =
false;
418 this->
event_.gatts.data.heap_data =
nullptr;
419 this->
event_.gatts.data_len = 0;
428 this->
event_.gatts.gatts_param = *p;
434 case ESP_GATTS_WRITE_EVT:
435 copy_data_with_inline_storage_<
decltype(this->
event_.gatts), GATTS_INLINE_DATA_SIZE>(
436 this->
event_.gatts, p->write.value, p->write.len, &this->event_.gatts.gatts_param.write.value);
439 this->
event_.gatts.is_inline =
false;
440 this->
event_.gatts.data.heap_data =
nullptr;
441 this->
event_.gatts.data_len = 0;