Skip to content

Commit

Permalink
Fix compiling errors on nRF devices (#801)
Browse files Browse the repository at this point in the history
* Fix undeclared 'nimble_port_stop()' on nRF51

* Fix missing member 'm_pClient' in NimBLEServer
  • Loading branch information
mr258876 authored Dec 15, 2024
1 parent 267d8a6 commit 87a710c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/NimBLEServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ NimBLEServer::~NimBLEServer() {
delete m_pServerCallbacks;
}

# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
if (m_pClient != nullptr) {
delete m_pClient;
}
# endif
}

/**
Expand Down Expand Up @@ -399,10 +401,12 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
}
}

# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
if (pServer->m_pClient && pServer->m_pClient->m_connHandle == event->disconnect.conn.conn_handle) {
// If this was also the client make sure it's flagged as disconnected.
pServer->m_pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
}
# endif

if (pServer->m_svcChanged) {
pServer->resetGATT();
Expand Down
40 changes: 35 additions & 5 deletions src/nimble/porting/nimble/src/nimble_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#if !CONFIG_BT_CONTROLLER_ENABLED
#include "nimble/nimble/transport/include/nimble/transport.h"
#endif
#endif

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Expand Down Expand Up @@ -84,6 +85,7 @@ nimble_port_stop_cb(struct ble_npl_event *ev)
ble_npl_sem_release(&ble_hs_stop_sem);
}

#ifdef ESP_PLATFORM
/**
* @brief esp_nimble_init - Initialize the NimBLE host stack
*
Expand Down Expand Up @@ -324,11 +326,6 @@ IRAM_ATTR nimble_port_get_dflt_eventq(void)

#else // ESP_PLATFORM

static struct ble_npl_eventq g_eventq_dflt;

extern void os_msys_init(void);
extern void os_mempool_module_init(void);

void
nimble_port_init(void)
{
Expand Down Expand Up @@ -360,6 +357,39 @@ nimble_port_init(void)
#endif
}

int
nimble_port_stop(void)
{
int rc = 0;

rc = ble_npl_sem_init(&ble_hs_stop_sem, 0);
if (rc != 0) {
return rc;
}

/* Initiate a host stop procedure. */
rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
NULL);
if (rc != 0) {
ble_npl_sem_deinit(&ble_hs_stop_sem);
return rc;
}

/* Wait till the host stop procedure is complete */
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);

ble_npl_event_init(&ble_hs_ev_stop, nimble_port_stop_cb,
NULL);
ble_npl_eventq_put(&g_eventq_dflt, &ble_hs_ev_stop);

/* Wait till the event is serviced */
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);

ble_npl_sem_deinit(&ble_hs_stop_sem);

return rc;
}

void
nimble_port_deinit(void)
{
Expand Down

0 comments on commit 87a710c

Please sign in to comment.