Skip to content

Commit

Permalink
Merge branch 'feature/protocomm_update_params_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
fix(protocomm): added Protocomm BLE Event Structure and Event Handling (v5.1)

See merge request espressif/esp-idf!26899
  • Loading branch information
rahult-github committed Nov 18, 2023
2 parents 4023a22 + b9528ba commit 54e3737
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
29 changes: 29 additions & 0 deletions components/protocomm/include/transports/protocomm_ble.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,35 @@ typedef struct name_uuid {
uint16_t uuid;
} 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
*/
Expand Down
16 changes: 14 additions & 2 deletions components/protocomm/src/transports/protocomm_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ static void transport_simple_ble_disconnect(esp_gatts_cb_event_t event, esp_gatt
if (ret != ESP_OK) {
ESP_LOGE(TAG, "error closing the session after disconnect");
} 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");
}
}
Expand All @@ -371,7 +377,13 @@ static void transport_simple_ble_connect(esp_gatts_cb_event_t event, esp_gatt_if
if (ret != ESP_OK) {
ESP_LOGE(TAG, "error creating the session");
} 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");
}
}
Expand Down
18 changes: 16 additions & 2 deletions components/protocomm/src/transports/protocomm_nimble.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,14 @@ static void transport_simple_ble_disconnect(struct ble_gap_event *event, void *a
if (ret != ESP_OK) {
ESP_LOGE(TAG, "error closing the session after disconnect");
} 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");
}
}
Expand All @@ -595,7 +602,14 @@ static void transport_simple_ble_connect(struct ble_gap_event *event, void *arg)
if (ret != ESP_OK) {
ESP_LOGE(TAG, "error creating the session");
} 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");
}
}
Expand Down

0 comments on commit 54e3737

Please sign in to comment.