static bool frame_to_adv_is_tlm(const es_adv_timing_evt_t * p_evt) { const es_slot_reg_t * p_reg = es_slot_get_registry(); return (p_reg->tlm_configured && (p_evt->slot_no == p_reg->tlm_slot || p_evt->evt_id == ES_ADV_TIMING_EVT_ADV_ETLM)); }
/**@brief Function for finding and setting advertisement timing configuration. */ static void adv_timing_set(void) { ret_code_t err_code; const es_slot_reg_t * p_reg = es_slot_get_registry(); es_adv_timing_resolver_input_t resolver_input = { .adv_interval = m_current_adv_interval, .p_result = &m_adv_timing_result, .num_slots_configured = p_reg->num_configured_slots, .p_slots_configured = p_reg->slots_configured, .num_eid_slots_configured = p_reg->num_configured_eid_slots, .p_eid_slots_configured = p_reg->eid_slots_configured, .tlm_configured = p_reg->tlm_configured, .tlm_slot = p_reg->tlm_slot}; err_code = es_adv_timing_resolve(&resolver_input); APP_ERROR_CHECK(err_code); } void es_adv_timing_start(uint16_t adv_interval) { ret_code_t err_code; const es_slot_reg_t * p_reg = es_slot_get_registry(); m_non_conn_adv_active = true; if (p_reg->num_configured_slots > 0) { m_current_adv_interval = adv_interval; err_code = app_timer_start(m_es_adv_interval_timer, APP_TIMER_TICKS(m_current_adv_interval, APP_TIMER_PRESCALER), NULL); APP_ERROR_CHECK(err_code); adv_timing_set(); } }
/**@brief Timeout handler for the advertisement interval timer. */ static void adv_interval_timeout(void * p_context) { if (es_slot_get_registry()->num_configured_slots > 0) { // Trigger slot timeout for advertising the first slot. // Note: The slot number is not the index in the slot registry, it is the index of the active slots. adv_slot_timeout(NULL); } if(m_non_conn_adv_active) { uint32_t err_code = app_timer_start(m_es_adv_interval_timer, APP_TIMER_TICKS(m_current_adv_interval, APP_TIMER_PRESCALER), NULL); APP_ERROR_CHECK(err_code); } }
void es_adv_interval_set(nrf_ble_escs_adv_interval_t interval) { const es_slot_reg_t * p_reg = es_slot_get_registry(); uint16_t min_valid_adv_interval; bool eTLM_required = (p_reg->num_configured_eid_slots > 0) && (p_reg->tlm_configured); min_valid_adv_interval = eTLM_required ? \ p_reg->num_configured_slots * (APP_CONFIG_ADV_FRAME_SPACING_MS_MIN + \ APP_CONFIG_ADV_FRAME_ETLM_SPACING_MS) \ : \ p_reg->num_configured_slots * APP_CONFIG_ADV_FRAME_SPACING_MS_MIN; m_adv_interval = (interval > min_valid_adv_interval) ? interval : min_valid_adv_interval; #ifdef APP_CONFIG_ADV_INTERVAL_MS_MAX if (m_adv_interval > APP_CONFIG_ADV_INTERVAL_MS_MAX) { m_adv_interval = APP_CONFIG_ADV_INTERVAL_MS_MAX; } #endif // APP_CONFIG_ADV_INTERVAL_MS_MAX }
/**@brief Function handling events from @ref es_adv_timing.c. * * @param[in] p_evt Advertisement timing event. */ static void adv_timing_callback(const es_adv_timing_evt_t * p_evt) { ret_code_t err_code; ble_gap_adv_params_t non_connectable_adv_params; const es_slot_reg_t * p_reg = es_slot_get_registry(); // As new advertisement data will be loaded, stop advertising. err_code = sd_ble_gap_adv_stop(); if (err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_CHECK(err_code); } // If a non-eTLM frame is to be advertised. if (p_evt->evt_id == ES_ADV_TIMING_EVT_ADV_SLOT) { err_code = sd_ble_gap_tx_power_set(p_reg->slots[p_evt->slot_no].radio_tx_pwr); APP_ERROR_CHECK(err_code); es_adv_frame_fill_non_connectable_adv_data(p_evt->slot_no, false); } // If an eTLM frame is to be advertised else if (p_evt->evt_id == ES_ADV_TIMING_EVT_ADV_ETLM) { err_code = sd_ble_gap_tx_power_set(p_reg->slots[p_reg->tlm_slot].radio_tx_pwr); APP_ERROR_CHECK(err_code); es_adv_frame_fill_non_connectable_adv_data(p_evt->slot_no, true); } invoke_callback(ES_ADV_EVT_NON_CONN_ADV); get_adv_params(&non_connectable_adv_params, true, m_remain_connectable); adv_start(&non_connectable_adv_params); }