//softdevice task creation void nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook_t hook_fn, void * p_context) { NRF_LOG_DEBUG("Creating a SoftDevice task."); m_task_hook = hook_fn; BaseType_t xReturned = xTaskCreate(softdevice_task, "BLE", NRF_BLE_FREERTOS_SDH_TASK_STACK, p_context, 2, &m_softdevice_task); if (xReturned != pdPASS) { NRF_LOG_ERROR("SoftDevice task not created."); APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } } /* This function gets events from the SoftDevice and processes them. */ static void softdevice_task(void * pvParameter) { NRF_LOG_DEBUG("Enter softdevice_task."); if (m_task_hook != NULL) { m_task_hook(pvParameter); } while (true) { nrf_sdh_evts_poll(); // Let the handlers run first, in case the EVENT occured vTaskSuspend(NULL); } } // init the ble stack void ble_m_init(void) { // Initialization of required BLE components. ble_stack_init(); scan_init(); gap_params_init(); gatt_init(); conn_params_init(); } /**@brief Function for initialization Scanning Module. */ static void scan_init(void) { ret_code_t err_code; err_code = nrf_ble_scan_init(&m_scan, NULL, NULL); APP_ERROR_CHECK(err_code); } /**@brief Function for initiating scanning. */ void scan_start(void) { ret_code_t err_code; //Clear the current device address. memset(m_addr_str_for_connection, 0, sizeof(m_addr_str_for_connection)); // connect_addr_clear(); err_code = nrf_ble_scan_start(&m_scan); APP_ERROR_CHECK(err_code); //bsp_board_led_on(CENTRAL_SCANNING_LED); printf("Scanning\r\n"); m_scanning = true; } /**@brief Function for stopping scanning. */ void scan_stop(void) { nrf_ble_scan_stop(); //bsp_board_led_off(CENTRAL_SCANNING_LED); m_scanning = false; } //ble event processing void nrf_ble_scan_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_contex) { nrf_ble_scan_t * p_scan_data = (nrf_ble_scan_t *)p_contex; ble_gap_evt_adv_report_t const * p_adv_report = &p_ble_evt->evt.gap_evt.params.adv_report; ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt; switch (p_ble_evt->header.evt_id) { case BLE_GAP_EVT_ADV_REPORT: nrf_ble_scan_on_adv_report(p_scan_data, p_adv_report); break; default: break; } }