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_) {
161 if (!this->
event_.gattc.is_inline && this->event_.gattc.data.heap_data !=
nullptr) {
162 delete[] this->
event_.gattc.data.heap_data;
163 this->
event_.gattc.data.heap_data =
nullptr;
167 if (!this->
event_.gatts.is_inline && this->event_.gatts.data.heap_data !=
nullptr) {
168 delete[] this->
event_.gatts.data.heap_data;
169 this->
event_.gatts.data.heap_data =
nullptr;
181 this->init_gap_data_(e, p);
184 void load_gattc_event(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
186 this->init_gattc_data_(e, i, p);
189 void load_gatts_event(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
191 this->init_gatts_data_(e, i, p);
261 template<
typename EventStruct,
size_t InlineSize>
262 void copy_data_with_inline_storage_(EventStruct &event,
const uint8_t *src_data, uint16_t
len,
263 uint8_t **param_value_ptr) {
264 event.data_len =
len;
266 if (
len <= InlineSize) {
267 event.is_inline =
true;
268 memcpy(event.data.inline_data, src_data,
len);
269 *param_value_ptr =
event.data.inline_data;
271 event.is_inline =
false;
272 event.data.heap_data =
new uint8_t[
len];
273 memcpy(event.data.heap_data, src_data,
len);
274 *param_value_ptr =
event.data.heap_data;
277 event.is_inline =
false;
278 event.data.heap_data =
nullptr;
279 *param_value_ptr =
nullptr;
284 void init_gap_data_(esp_gap_ble_cb_event_t e, esp_ble_gap_cb_param_t *p) {
285 this->
event_.gap.gap_event = e;
293 case ESP_GAP_BLE_SCAN_RESULT_EVT:
294 memcpy(this->
event_.gap.scan_result.bda, p->scan_rst.bda,
sizeof(esp_bd_addr_t));
295 this->
event_.gap.scan_result.ble_addr_type = p->scan_rst.ble_addr_type;
296 this->
event_.gap.scan_result.rssi = p->scan_rst.rssi;
297 this->
event_.gap.scan_result.adv_data_len = p->scan_rst.adv_data_len;
298 this->
event_.gap.scan_result.scan_rsp_len = p->scan_rst.scan_rsp_len;
299 this->
event_.gap.scan_result.search_evt = p->scan_rst.search_evt;
300 memcpy(this->
event_.gap.scan_result.ble_adv, p->scan_rst.ble_adv,
301 ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX);
304 case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT:
305 this->
event_.gap.scan_complete.status = p->scan_param_cmpl.status;
308 case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT:
309 this->
event_.gap.scan_complete.status = p->scan_start_cmpl.status;
312 case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT:
313 this->
event_.gap.scan_complete.status = p->scan_stop_cmpl.status;
318 case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT:
319 this->
event_.gap.adv_complete.status = p->adv_data_cmpl.status;
321 case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT:
322 this->
event_.gap.adv_complete.status = p->scan_rsp_data_cmpl.status;
324 case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT:
325 this->
event_.gap.adv_complete.status = p->adv_data_raw_cmpl.status;
327 case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
328 this->
event_.gap.adv_complete.status = p->adv_start_cmpl.status;
330 case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
331 this->
event_.gap.adv_complete.status = p->adv_stop_cmpl.status;
336 case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT:
337 this->
event_.gap.read_rssi_complete.status = p->read_rssi_cmpl.status;
338 this->
event_.gap.read_rssi_complete.rssi = p->read_rssi_cmpl.rssi;
339 memcpy(this->
event_.gap.read_rssi_complete.remote_addr, p->read_rssi_cmpl.remote_addr,
sizeof(esp_bd_addr_t));
344 case ESP_GAP_BLE_AUTH_CMPL_EVT:
345 case ESP_GAP_BLE_SEC_REQ_EVT:
346 case ESP_GAP_BLE_PASSKEY_NOTIF_EVT:
347 case ESP_GAP_BLE_PASSKEY_REQ_EVT:
348 case ESP_GAP_BLE_NC_REQ_EVT:
349 memcpy(&this->
event_.gap.security, &p->ble_security,
sizeof(esp_ble_sec_t));
362 void init_gattc_data_(esp_gattc_cb_event_t e, esp_gatt_if_t i, esp_ble_gattc_cb_param_t *p) {
363 this->
event_.gattc.gattc_event = e;
364 this->
event_.gattc.gattc_if = i;
368 memset(&this->
event_.gattc.gattc_param, 0,
sizeof(this->event_.gattc.gattc_param));
369 this->
event_.gattc.is_inline =
false;
370 this->
event_.gattc.data.heap_data =
nullptr;
371 this->
event_.gattc.data_len = 0;
380 this->
event_.gattc.gattc_param = *p;
386 case ESP_GATTC_NOTIFY_EVT:
387 copy_data_with_inline_storage_<
decltype(this->
event_.gattc), GATTC_INLINE_DATA_SIZE>(
388 this->
event_.gattc, p->notify.value, p->notify.value_len, &this->event_.gattc.gattc_param.notify.value);
390 case ESP_GATTC_READ_CHAR_EVT:
391 case ESP_GATTC_READ_DESCR_EVT:
392 copy_data_with_inline_storage_<
decltype(this->
event_.gattc), GATTC_INLINE_DATA_SIZE>(
393 this->
event_.gattc, p->read.value, p->read.value_len, &this->event_.gattc.gattc_param.read.value);
396 this->
event_.gattc.is_inline =
false;
397 this->
event_.gattc.data.heap_data =
nullptr;
398 this->
event_.gattc.data_len = 0;
404 void init_gatts_data_(esp_gatts_cb_event_t e, esp_gatt_if_t i, esp_ble_gatts_cb_param_t *p) {
405 this->
event_.gatts.gatts_event = e;
406 this->
event_.gatts.gatts_if = i;
410 memset(&this->
event_.gatts.gatts_param, 0,
sizeof(this->event_.gatts.gatts_param));
411 this->
event_.gatts.is_inline =
false;
412 this->
event_.gatts.data.heap_data =
nullptr;
413 this->
event_.gatts.data_len = 0;
422 this->
event_.gatts.gatts_param = *p;
428 case ESP_GATTS_WRITE_EVT:
429 copy_data_with_inline_storage_<
decltype(this->
event_.gatts), GATTS_INLINE_DATA_SIZE>(
430 this->
event_.gatts, p->write.value, p->write.len, &this->event_.gatts.gatts_param.write.value);
433 this->
event_.gatts.is_inline =
false;
434 this->
event_.gatts.data.heap_data =
nullptr;
435 this->
event_.gatts.data_len = 0;