Skip to content

Commit 87a710c

Browse files
authored
Fix compiling errors on nRF devices (#801)
* Fix undeclared 'nimble_port_stop()' on nRF51 * Fix missing member 'm_pClient' in NimBLEServer
1 parent 267d8a6 commit 87a710c

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/NimBLEServer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ NimBLEServer::~NimBLEServer() {
7070
delete m_pServerCallbacks;
7171
}
7272

73+
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
7374
if (m_pClient != nullptr) {
7475
delete m_pClient;
7576
}
77+
# endif
7678
}
7779

7880
/**
@@ -399,10 +401,12 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
399401
}
400402
}
401403

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

407411
if (pServer->m_svcChanged) {
408412
pServer->resetGATT();

src/nimble/porting/nimble/src/nimble_port.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#if !CONFIG_BT_CONTROLLER_ENABLED
4848
#include "nimble/nimble/transport/include/nimble/transport.h"
4949
#endif
50+
#endif
5051

5152
#include "freertos/FreeRTOS.h"
5253
#include "freertos/task.h"
@@ -84,6 +85,7 @@ nimble_port_stop_cb(struct ble_npl_event *ev)
8485
ble_npl_sem_release(&ble_hs_stop_sem);
8586
}
8687

88+
#ifdef ESP_PLATFORM
8789
/**
8890
* @brief esp_nimble_init - Initialize the NimBLE host stack
8991
*
@@ -324,11 +326,6 @@ IRAM_ATTR nimble_port_get_dflt_eventq(void)
324326

325327
#else // ESP_PLATFORM
326328

327-
static struct ble_npl_eventq g_eventq_dflt;
328-
329-
extern void os_msys_init(void);
330-
extern void os_mempool_module_init(void);
331-
332329
void
333330
nimble_port_init(void)
334331
{
@@ -360,6 +357,39 @@ nimble_port_init(void)
360357
#endif
361358
}
362359

360+
int
361+
nimble_port_stop(void)
362+
{
363+
int rc = 0;
364+
365+
rc = ble_npl_sem_init(&ble_hs_stop_sem, 0);
366+
if (rc != 0) {
367+
return rc;
368+
}
369+
370+
/* Initiate a host stop procedure. */
371+
rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
372+
NULL);
373+
if (rc != 0) {
374+
ble_npl_sem_deinit(&ble_hs_stop_sem);
375+
return rc;
376+
}
377+
378+
/* Wait till the host stop procedure is complete */
379+
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
380+
381+
ble_npl_event_init(&ble_hs_ev_stop, nimble_port_stop_cb,
382+
NULL);
383+
ble_npl_eventq_put(&g_eventq_dflt, &ble_hs_ev_stop);
384+
385+
/* Wait till the event is serviced */
386+
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
387+
388+
ble_npl_sem_deinit(&ble_hs_stop_sem);
389+
390+
return rc;
391+
}
392+
363393
void
364394
nimble_port_deinit(void)
365395
{

0 commit comments

Comments
 (0)