fix(protocomm): added Protocomm BLE Event Structure and Event Handling

This commit is contained in:
darshan 2023-10-27 11:08:00 +05:30
parent 85ba4189f8
commit 83f4025a92
3 changed files with 59 additions and 4 deletions

View File

@ -59,6 +59,35 @@ typedef struct name_uuid {
uint16_t uuid; uint16_t uuid;
} protocomm_ble_name_uuid_t; } protocomm_ble_name_uuid_t;
/**
* @brief Structure for BLE events in Protocomm.
*/
typedef struct {
/**
* This field indicates the type of BLE event that occurred.
*/
uint16_t evt_type;
/**
* The handle of the relevant connection.
*/
uint16_t conn_handle;
union {
/**
* The status of the connection attempt;
* o 0: the connection was successfully established.
* o BLE host error code: the connection attempt failed for
* the specified reason.
*/
uint16_t conn_status;
/**
* Return code indicating the reason for the disconnect.
*/
uint16_t disconnect_reason;
};
} protocomm_ble_event_t;
/** /**
* @brief Config parameters for protocomm BLE service * @brief Config parameters for protocomm BLE service
*/ */

View File

@ -345,7 +345,13 @@ static void transport_simple_ble_disconnect(esp_gatts_cb_event_t event, esp_gatt
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "error closing the session after disconnect"); ESP_LOGE(TAG, "error closing the session after disconnect");
} else { } else {
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) { protocomm_ble_event_t ble_event = {};
/* Assign the event type */
ble_event.evt_type = PROTOCOMM_TRANSPORT_BLE_DISCONNECTED;
/* Set the Disconnection handle */
ble_event.conn_handle = param->disconnect.conn_id;
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, &ble_event, sizeof(protocomm_ble_event_t), portMAX_DELAY) != ESP_OK) {
ESP_LOGE(TAG, "Failed to post transport disconnection event"); ESP_LOGE(TAG, "Failed to post transport disconnection event");
} }
} }
@ -371,7 +377,13 @@ static void transport_simple_ble_connect(esp_gatts_cb_event_t event, esp_gatt_if
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "error creating the session"); ESP_LOGE(TAG, "error creating the session");
} else { } else {
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) { protocomm_ble_event_t ble_event = {};
/* Assign the event type */
ble_event.evt_type = PROTOCOMM_TRANSPORT_BLE_CONNECTED;
/* Set the Connection handle */
ble_event.conn_handle = param->connect.conn_id;
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, &ble_event, sizeof(protocomm_ble_event_t), portMAX_DELAY) != ESP_OK) {
ESP_LOGE(TAG, "Failed to post transport pairing event"); ESP_LOGE(TAG, "Failed to post transport pairing event");
} }
} }

View File

@ -569,7 +569,14 @@ static void transport_simple_ble_disconnect(struct ble_gap_event *event, void *a
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "error closing the session after disconnect"); ESP_LOGE(TAG, "error closing the session after disconnect");
} else { } else {
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) { protocomm_ble_event_t ble_event = {};
/* Assign the event type */
ble_event.evt_type = PROTOCOMM_TRANSPORT_BLE_DISCONNECTED;
/* Set the Disconnection handle */
ble_event.conn_handle = event->disconnect.conn.conn_handle;
ble_event.disconnect_reason = event->disconnect.reason;
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_DISCONNECTED, &ble_event, sizeof(protocomm_ble_event_t), portMAX_DELAY) != ESP_OK) {
ESP_LOGE(TAG, "Failed to post transport disconnection event"); ESP_LOGE(TAG, "Failed to post transport disconnection event");
} }
} }
@ -595,7 +602,14 @@ static void transport_simple_ble_connect(struct ble_gap_event *event, void *arg)
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "error creating the session"); ESP_LOGE(TAG, "error creating the session");
} else { } else {
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, NULL, 0, portMAX_DELAY) != ESP_OK) { protocomm_ble_event_t ble_event = {};
/* Assign the event type */
ble_event.evt_type = PROTOCOMM_TRANSPORT_BLE_CONNECTED;
/* Set the Connection handle */
ble_event.conn_handle = event->connect.conn_handle;
ble_event.conn_status = event->connect.status;
if (esp_event_post(PROTOCOMM_TRANSPORT_BLE_EVENT, PROTOCOMM_TRANSPORT_BLE_CONNECTED, &ble_event, sizeof(protocomm_ble_event_t), portMAX_DELAY) != ESP_OK) {
ESP_LOGE(TAG, "Failed to post transport pairing event"); ESP_LOGE(TAG, "Failed to post transport pairing event");
} }
} }