Commit a81e7bbd authored by hsum's avatar hsum Committed by Robert Schmidt

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
parent 9d99f1e9
...@@ -1264,86 +1264,21 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf) ...@@ -1264,86 +1264,21 @@ int pnf_p7_subframe_ind(pnf_p7_t* pnf_p7, uint16_t phy_id, uint16_t sfn_sf)
return 0; return 0;
} }
bool is_nr_p7_request_in_window(uint16_t sfn, uint16_t slot, const char* name, pnf_p7_t* phy)
// 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)
{ {
uint32_t recv_sfn_slot_dec = NFAPI_SFNSLOT2DEC(sfn,slot); uint32_t recv = NFAPI_SFNSLOT2DEC(sfn, slot); // unpack sfn/slot
uint32_t current_sfn_slot_dec = NFAPI_SFNSLOT2DEC(phy->sfn,phy->slot); uint32_t curr = 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 timing_window = phy->_public.slot_buffer_size;
uint8_t in_window = 0; uint32_t diff = abs(curr - recv);
uint8_t timing_window = phy->_public.slot_buffer_size; if (diff > NFAPI_MAX_SFNSLOTDEC / 2)
diff = NFAPI_MAX_SFNSLOTDEC - diff;
// if(recv_sfn_slot_dec <= current_sfn_slot_dec) if (diff > timing_window) {
// { NFAPI_TRACE(NFAPI_TRACE_NOTE, "[%d] %s is out of window %d (delta:%d) [max:%d]\n", curr, name, recv, diff, timing_window);
// // Need to check for wrap in window return false;
// if(((recv_sfn_slot_dec + timing_window) % NFAPI_MAX_SFNSLOTDEC) < recv_sfn_slot_dec) }
// { return true;
// 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;
} }
uint8_t is_p7_request_in_window(uint16_t sfnsf, const char* name, pnf_p7_t* phy) 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); uint32_t recv_sfn_sf_dec = NFAPI_SFNSF2DEC(sfnsf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment