Skip to content

Commit 31feea4

Browse files
committed
nrf5/bluetooth: Adding function to stop advertisment if onging
1 parent 46c21ff commit 31feea4

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

nrf5/bluetooth/ble_drv.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,21 +553,14 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
553553
} else {
554554
m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
555555
}
556+
556557
m_adv_params.p_peer_addr = NULL; // undirected advertisement
557558
m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
558559
m_adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // approx 8 ms
559560
m_adv_params.timeout = 0; // infinite advertisment
560561

561-
#if (BLUETOOTH_SD == 132)
562-
if (m_adv_in_progress == true) {
563-
if (sd_ble_gap_adv_stop() != 0) {
564-
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
565-
"Can not stop advertisment."));
566-
}
567-
}
568-
#endif
562+
ble_drv_advertise_stop();
569563

570-
m_adv_in_progress = false;
571564
err_code = sd_ble_gap_adv_start(&m_adv_params);
572565
if (err_code != 0) {
573566
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
@@ -579,6 +572,17 @@ bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
579572
return true;
580573
}
581574

575+
void ble_drv_advertise_stop(void) {
576+
if (m_adv_in_progress == true) {
577+
uint32_t err_code;
578+
if ((err_code = sd_ble_gap_adv_stop()) != 0) {
579+
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
580+
"Can not stop advertisment. status: 0x" HEX2_FMT, (uint16_t)err_code));
581+
}
582+
}
583+
m_adv_in_progress = false;
584+
}
585+
582586
void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
583587
ble_gatts_value_t gatts_value;
584588
memset(&gatts_value, 0, sizeof(gatts_value));

nrf5/bluetooth/ble_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj);
8686

8787
bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params);
8888

89+
void ble_drv_advertise_stop(void);
90+
8991
void ble_drv_gap_event_handler_set(mp_obj_t obs, ble_drv_gap_evt_callback_t evt_handler);
9092

9193
void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler);

0 commit comments

Comments
 (0)