From 5bfbb00d2c30c059fd8028a6ceb14b2b61559dd8 Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani <velumani@eurecom.fr>
Date: Wed, 3 Jun 2020 14:49:26 +0200
Subject: [PATCH] bugfix for UE init sync

---
 executables/nr-ue.c                   | 7 ++++---
 openair1/PHY/MODULATION/slot_fep_nr.c | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index dbee6f1e6fc..761420a7039 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -634,7 +634,7 @@ void syncInFrame(PHY_VARS_NR_UE *UE, openair0_timestamp *timestamp) {
 
 int computeSamplesShift(PHY_VARS_NR_UE *UE) {
   if (IS_SOFTMODEM_RFSIM) {
-    LOG_E(PHY,"SET rx_offset %d \n",UE->rx_offset);
+    LOG_D(PHY,"SET rx_offset %d \n",UE->rx_offset);
     //UE->rx_offset_diff=0;
     return 0;
   }
@@ -857,8 +857,9 @@ void *UE_thread(void *arg) {
       usleep(200);
     }
 
-    if (  decoded_frame_rx != curMsg->proc.frame_rx &&
-          ((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != curMsg->proc.frame_rx )
+    if (  (decoded_frame_rx != curMsg->proc.frame_rx) &&
+          (((decoded_frame_rx+1) % MAX_FRAME_NUMBER) != curMsg->proc.frame_rx) &&
+          (((decoded_frame_rx+2) % MAX_FRAME_NUMBER) != curMsg->proc.frame_rx))
       LOG_E(PHY,"Decoded frame index (%d) is not compatible with current context (%d), UE should go back to synch mode\n",
             decoded_frame_rx, curMsg->proc.frame_rx  );
 
diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c
index 7fe8437c4e6..108a36a679a 100644
--- a/openair1/PHY/MODULATION/slot_fep_nr.c
+++ b/openair1/PHY/MODULATION/slot_fep_nr.c
@@ -339,7 +339,7 @@ int nr_slot_fep_init_sync(PHY_VARS_NR_UE *ue,
 #endif
 
 
-        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
+        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][rx_offset],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
 #if UE_TIMING_TRACE
         stop_meas(&ue->rx_dft_stats);
@@ -363,7 +363,7 @@ int nr_slot_fep_init_sync(PHY_VARS_NR_UE *ue,
         dft(dftsize,(int16_t *)tmp_dft_in,
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       } else { // use dft input from RX buffer directly
-        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][(rx_offset) % frame_length_samples],
+        dft(dftsize,(int16_t *) &common_vars->rxdata[aa][rx_offset],
             (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1);
       }
 #if UE_TIMING_TRACE
-- 
GitLab