fix(nimble): Fix issues found in review for nimble examples

This commit is contained in:
Rahul Tank
2026-07-24 17:50:29 +08:00
committed by BOT
parent 99b87ca81f
commit fa1bf5e2fc
73 changed files with 1299 additions and 635 deletions
@@ -102,18 +102,21 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg)
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status == 0) {
s_ble_multi_conn_num++;
ESP_LOGI(TAG, "Connection established. Handle:%d, Total:%d", event->connect.conn_handle,
++s_ble_multi_conn_num);
s_ble_multi_conn_num);
/* Remember peer. */
rc = peer_add(event->connect.conn_handle);
if (rc != 0) {
ESP_LOGE(TAG, "Failed to add peer; rc=%d\n", rc);
ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM);
} else {
/* Perform service discovery */
rc = peer_disc_svc_by_uuid(event->connect.conn_handle, remote_svc_uuid,
ble_cent_on_disc_complete, NULL);
if(rc != 0) {
ESP_LOGE(TAG, "Failed to discover services; rc=%d\n", rc);
ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM);
}
}
} else {
@@ -130,9 +133,10 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg)
/* Forget about peer. */
peer_delete(event->disconnect.conn.conn_handle);
s_ble_multi_conn_num--;
ESP_LOGI(TAG, "Central disconnected; Handle:%d, Reason=%d, Total:%d",
event->disconnect.conn.conn_handle, event->disconnect.reason,
--s_ble_multi_conn_num);
s_ble_multi_conn_num);
/* Resume scanning. */
ble_cent_scan();
@@ -282,8 +286,8 @@ ble_cent_scan(void)
return;
}
struct ble_gap_ext_disc_params uncoded_disc_params;
struct ble_gap_ext_disc_params coded_disc_params;
struct ble_gap_ext_disc_params uncoded_disc_params = {0};
struct ble_gap_ext_disc_params coded_disc_params = {0};
/* Perform a passive scan. I.e., don't send follow-up scan requests to
* each advertiser.
@@ -409,8 +413,10 @@ blecent_on_sync(void)
* the `MINIMUM_CONN_INTERVAL` should be greater than ((261 * 8us) * 2 + 150us) * 10 = 43260us.
*
*/
rc = ble_gap_common_factor_set(true, (BLE_PREF_CONN_ITVL_MS * 1000) / 625);
assert(rc == 0);
if (BLE_PEER_MAX_NUM > 0) {
rc = ble_gap_common_factor_set(true, (BLE_PREF_CONN_ITVL_MS * 1000) / 625);
assert(rc == 0);
}
/* Make sure we have proper identity address set (public preferred) */
rc = ble_hs_util_ensure_addr(0);
@@ -24,7 +24,7 @@ static uint8_t ext_adv_pattern_1[] = {
#endif
static const char *TAG = "ESP_MULTI_CONN_PRPH";
static uint8_t s_ble_prph_conn_num = 0;
static volatile uint8_t s_ble_prph_conn_num = 0;
static SemaphoreHandle_t s_sem_restart_adv = NULL;
static int ble_prph_gap_event(struct ble_gap_event *event, void *arg);
@@ -194,8 +194,9 @@ ble_prph_gap_event(struct ble_gap_event *event, void *arg)
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status == 0) {
/* A new connection was established. */
s_ble_prph_conn_num++;
ESP_LOGI(TAG, "Connection established. Handle:%d. Total:%d", event->connect.conn_handle,
++s_ble_prph_conn_num);
s_ble_prph_conn_num);
#if CONFIG_EXAMPLE_RESTART_ADV_AFTER_CONNECTED
ble_prph_restart_adv();
#endif //CONFIG_EXAMPLE_RESTART_ADV_AFTER_CONNECTED
@@ -206,8 +207,9 @@ ble_prph_gap_event(struct ble_gap_event *event, void *arg)
return 0;
case BLE_GAP_EVENT_DISCONNECT:
s_ble_prph_conn_num--;
ESP_LOGI(TAG, "Disconnect. Handle:%d. Reason=%d. Total:%d",
event->disconnect.conn.conn_handle, event->disconnect.reason, --s_ble_prph_conn_num);
event->disconnect.conn.conn_handle, event->disconnect.reason, s_ble_prph_conn_num);
/* Connection terminated; resume advertising. */
ble_prph_restart_adv();