Refactor is_nr_p7_request_in_window function for clarity and efficiency
The function now utilizes simpler variable names and logic to determine if a given NR P7 request falls within the timing window. The logic for determining if a request is within the timing window is as follows: - The function calculates the absolute difference between the current and received SFN slots, taking into account the possibility of wraparound. - If the absolute difference is greater than half of the maximum SFN slot value, it subtracts this difference from the maximum SFN slot value to get the actual difference. - The function then checks if this difference is less than or equal to the specified timing window. If it is, the request is considered to be within the window. Additionally, the commit updates the function signature to return a boolean value for better readability and consistency. Changes made: - Simplified variable names for readability - Improved logic for handling wraparound scenarios - Updated function signature to return a boolean value Co-authored-by: Rúben Soares Silva <rsilva@allbesmart.pt>
This commit is contained in:
committed by
Robert Schmidt
co-authored by
Rúben Soares Silva
parent
267be0afc1
commit
195b23bdc4
@@ -1309,86 +1309,21 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// return 1 if in window
|
||||
// return 0 if out of window
|
||||
|
||||
uint8_t is_nr_p7_request_in_window(uint16_t sfn,uint16_t slot, const char* name, pnf_p7_t* phy)
|
||||
bool is_nr_p7_request_in_window(const uint16_t sfn, const uint16_t slot, const char* name, const pnf_p7_t* phy)
|
||||
{
|
||||
uint32_t recv_sfn_slot_dec = NFAPI_SFNSLOT2DEC(sfn,slot);
|
||||
uint32_t current_sfn_slot_dec = NFAPI_SFNSLOT2DEC(phy->sfn,phy->slot);
|
||||
//printf("p7_msg_sfn: %d, p7_msg_slot: %d, phy_sfn:%d , phy_slot:%d \n",sfn,slot,phy->sfn,phy->slot);
|
||||
uint8_t in_window = 0;
|
||||
uint8_t timing_window = phy->_public.slot_buffer_size;
|
||||
|
||||
// if(recv_sfn_slot_dec <= current_sfn_slot_dec)
|
||||
// {
|
||||
// // Need to check for wrap in window
|
||||
// if(((recv_sfn_slot_dec + timing_window) % NFAPI_MAX_SFNSLOTDEC) < recv_sfn_slot_dec)
|
||||
// {
|
||||
// if(current_sfn_slot_dec > ((recv_sfn_slot_dec + timing_window) % NFAPI_MAX_SFNSLOTDEC))
|
||||
// {
|
||||
// // out of window
|
||||
// NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is late %d (with wrap)\n", current_sfn_slot_dec, name, recv_sfn_slot_dec);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // ok
|
||||
// //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d (with wrap)\n", current_sfn_sf_dec, name, recv_sfn_sf_dec);
|
||||
// in_window = 1;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if((current_sfn_slot_dec - recv_sfn_slot_dec) <= timing_window)
|
||||
// {
|
||||
// // in window
|
||||
// //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec);
|
||||
// in_window = 1;
|
||||
// }
|
||||
// //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in late %d (delta:%d)\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (current_sfn_slot_dec - recv_sfn_slot_dec));
|
||||
// }
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Need to check it is in window
|
||||
// if((recv_sfn_slot_dec - current_sfn_slot_dec) <= timing_window)
|
||||
// {
|
||||
// // in window
|
||||
// //NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_sf_dec, name, recv_sfn_sf_dec);
|
||||
// in_window = 1;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // too far in the future
|
||||
// NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (recv_sfn_slot_dec - current_sfn_slot_dec), timing_window);
|
||||
// }
|
||||
|
||||
// }
|
||||
if(current_sfn_slot_dec <= recv_sfn_slot_dec + timing_window){
|
||||
in_window = 1;
|
||||
//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec);
|
||||
}
|
||||
else if(current_sfn_slot_dec + NFAPI_MAX_SFNSLOTDEC <= recv_sfn_slot_dec + timing_window){ //checking for wrap
|
||||
in_window = 1;
|
||||
//NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is in window %d\n", current_sfn_slot_dec, name, recv_sfn_slot_dec);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", current_sfn_slot_dec, name, recv_sfn_slot_dec, (current_sfn_slot_dec - recv_sfn_slot_dec), timing_window);
|
||||
|
||||
}//Need to add more cases
|
||||
|
||||
|
||||
return in_window;
|
||||
const uint32_t recv = NFAPI_SFNSLOT2DEC(sfn, slot); // unpack sfn/slot
|
||||
const uint32_t curr = NFAPI_SFNSLOT2DEC(phy->sfn, phy->slot);
|
||||
const uint8_t timing_window = phy->_public.slot_buffer_size;
|
||||
uint32_t diff = curr < recv ? recv - curr : curr - recv;
|
||||
if (diff > NFAPI_MAX_SFNSLOTDEC / 2)
|
||||
diff = NFAPI_MAX_SFNSLOTDEC - diff;
|
||||
if (diff > timing_window) {
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", curr, name, recv, diff, timing_window);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy)
|
||||
{
|
||||
uint32_t recv_sfn_sf_dec = NFAPI_SFNSF2DEC(sfnsf);
|
||||
|
||||
Reference in New Issue
Block a user