From 90523d6ae019cd0f8a5ac6864917229d32a9b281 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sun, 12 Feb 2017 14:24:15 +0100 Subject: [PATCH] nrf5/sdk: Adding static boolean for keeping track of whether advertisment is in progress in the bluetooth driver. Now, advertisment can be restarted with new data any time. --- nrf5/sdk/softdevice.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nrf5/sdk/softdevice.c b/nrf5/sdk/softdevice.c index 2eb694e391..eb7ddc4749 100644 --- a/nrf5/sdk/softdevice.c +++ b/nrf5/sdk/softdevice.c @@ -26,6 +26,7 @@ #include #include +#include #include "py/runtime.h" #include "softdevice.h" @@ -39,6 +40,8 @@ if (sd_enabled() == 0) { \ (void)sd_enable(); \ } +bool m_adv_in_progress = false; + #if (BLUETOOTH_SD != 100) && (BLUETOOTH_SD != 110) #include "nrf_nvic.h" @@ -357,10 +360,19 @@ bool sd_advertise_data(ubluepy_advertise_data_t * p_adv_params) { m_adv_params.interval = NON_CONNECTABLE_ADV_INTERVAL; m_adv_params.timeout = APP_CFG_NON_CONN_ADV_TIMEOUT; + if (m_adv_in_progress && sd_ble_gap_adv_stop() != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, + "Can not stop advertisment.")); + } + + m_adv_in_progress = false; + if (sd_ble_gap_adv_start(&m_adv_params) != 0) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "Can not start advertisment.")); } + m_adv_in_progress = true; + return true; }