Commit d0ca8602 authored by Marwan Hammouda's avatar Marwan Hammouda

[Develop]: code cleaned/updated

parent 4135d77b
......@@ -129,12 +129,11 @@
#define CONFIG_HLP_FI_ScalingFD "Set the I scaling factor (denominator) of the PID controller for the Doppler compensation at UE side"
#define CONFIG_HLP_FD_ScalingFN "Set the D scaling factor (numerator) of the PID controller for the Doppler compensation at UE side"
#define CONFIG_HLP_FD_ScalingFD "Set the D scaling factor (denominator) of the PID controller for the Doppler compensation at UE side"
#define CONFIG_HLP_FO_PScaling "set P scaling factor of the PID controller for the frequency offset compensation"
#define CONFIG_HLP_FO_IScaling "set I scaling factor of the PID controller for the frequency offset compensation"
#define CONFIG_HLP_TP_Scaling "set scaling P for TO"
#define CONFIG_HLP_TI_Scaling "set scaling I for TO"
#define CONFIG_HLP_TO_Iinit "Init the I part of the PI controller for timing offset compensation"
/*--------------------------------------------------------------------------------------------------------------------------------*/
/* command line parameters for LOG utility */
......@@ -195,6 +194,7 @@ extern int tdriftComp; // flag to activate/deactivate continous timing d
extern int32_t fdopplerPrePost; //pre/post compensation of the Doppler shift at the gNB side
extern double FO_PScaling; // P scaling factor of the PID controller for the Doppler compensation at UE side
extern double FO_IScaling; // I scaling factor of the PID controller for the Doppler compensation at UE side
extern int TO_IScalingInit; // initializing the accumulative part (I part) of the PI controller for the timing offset compensation
extern double TO_PScaling;
extern double TO_IScaling;
......
......@@ -578,6 +578,7 @@ uint16_t pathStartingTime = 1050;
uint16_t pathEndingTime = 1280;
int uePosY = 0;
int tdriftComp = 1;
int TO_IScalingInit = 0;
int32_t fdopplerPrePost = 0; //pre/post compensation of the Doppler shift at the gNB side
int commonDoppler = 0; // common doppler to be compensated at UE, but set here to avoid linking error
......
......@@ -35,13 +35,13 @@
{"P" , CONFIG_HLP_PROPD, 0, .u64ptr=&RFsim_PropDelay, .defintval=0, TYPE_UINT64, 0}, \
{"gnb_k2" , CONFIG_HLP_GNBK2, 0, .u16ptr=&NTN_gNB_k2, .defintval=0, TYPE_UINT16, 0}, \
{"ul_sched_f" , CONFIG_HLP_ULSCHEDF, 0, .u16ptr=&max_ul_sched_frame, .defintval=1, TYPE_UINT16, 0}, \
{"FD" , CONFIG_HLP_FDoppler, 0, .iptr=&fdoppler, .defintval=0, TYPE_INT, 0}, \
{"FD" , CONFIG_HLP_FDoppler, 0, .iptr=&fdoppler, .defintval=1, TYPE_INT, 0}, \
{"TD" , CONFIG_HLP_TDRIFT, 0, .iptr=&RFsim_DriftPerFrame, .defintval=0, TYPE_INT, 0}, \
{"PST" , CONFIG_HLP_PathStart, 0, .u16ptr=&pathStartingTime, .defintval=1050, TYPE_UINT16, 0}, \
{"PET" , CONFIG_HLP_PathEnd, 0, .u16ptr=&pathEndingTime, .defintval=1280, TYPE_UINT16, 0}, \
{"ue_PosY" , CONFIG_HLP_uePosY, 0, .iptr=&uePosY, .defintval=0, TYPE_INT, 0}, \
{"FDC" , CONFIG_HLP_FDopplerPrePost, 0, .iptr=&fdopplerPrePost, .defintval=0, TYPE_INT32, 0}, \
{"FC" , CONFIG_HLP_FDopplerComp, 0, .iptr=&fdopplerComp, .defintval=0, TYPE_INT32, 0} \
{"PST" , CONFIG_HLP_PathStart, 0, .u16ptr=&pathStartingTime, .defintval=1050, TYPE_UINT16, 0}, \
{"PET" , CONFIG_HLP_PathEnd, 0, .u16ptr=&pathEndingTime, .defintval=1280, TYPE_UINT16, 0}, \
{"ue_PosY" , CONFIG_HLP_uePosY, 0, .iptr=&uePosY, .defintval=0, TYPE_INT, 0}, \
{"FDC" , CONFIG_HLP_FDopplerPrePost,0, .iptr=&fdopplerPrePost, .defintval=0, TYPE_INT32, 0}, \
{"FC" , CONFIG_HLP_FDopplerComp, 0, .iptr=&fdopplerComp, .defintval=0, TYPE_INT32, 0} \
}
// clang-format on
......
......@@ -872,10 +872,17 @@ void *UE_thread(void *arg)
int readBlockSize, writeBlockSize;
rx_offset_slot = UE->rx_offset_TO * UE->rx_offset_slot / nb_slot_frame - UE->rx_offset_comp;
UE->rx_offset_comp += rx_offset_slot;
UE->rx_offset_slot++;
UL_TO_Tx_ofs += 2*rx_offset_slot; //to adapt the UE's transmission time in order to get aligned at gNB
extern int tdriftComp;
if (tdriftComp == 1)
{
rx_offset_slot = UE->rx_offset_TO * UE->rx_offset_slot / nb_slot_frame - UE->rx_offset_comp;
UE->rx_offset_comp += rx_offset_slot;
UE->rx_offset_slot++;
UL_TO_Tx_ofs += 2*rx_offset_slot; //to adapt the UE's transmission time in order to get aligned at gNB
}
LOG_I(PHY, "diff: %d, PI_Out: %d, offset_slot: %d, offset_UL: %d, TA: %d, TO_PScal: %f, TO_IScal: %f\n",
UE->rx_offset, UE->rx_offset_TO, rx_offset_slot, UL_TO_Tx_ofs, UE->timing_advance, TO_PScaling, TO_IScaling);
readBlockSize=get_readBlockSize(slot_nr, &UE->frame_parms) + rx_offset_slot;
writeBlockSize=UE->frame_parms.get_samples_per_slot((slot_nr + DURATION_RX_TO_TX) % nb_slot_frame, &UE->frame_parms);
......@@ -911,18 +918,38 @@ void *UE_thread(void *arg)
LOG_E(PHY,"can't compensate: diff =%d\n", first_symbols);
}
printf("**** Option: 4 Activated \n");
//timing_advance += 1*rx_offset_slot;
//timing_advance += 2*rx_offset_slot;
//UE->timing_advance += 1*rx_offset_slot;
UE->timing_advance += 2*rx_offset_slot;
// use previous timing_advance value to compute writeTimestamp
writeTimestamp = timestamp +
UE->frame_parms.get_samples_slot_timestamp(slot_nr,&UE->frame_parms,DURATION_RX_TO_TX)
- firstSymSamp - openair0_cfg[0].tx_sample_advance -
UE->N_TA_offset - timing_advance;
//timing_advance += 1*rx_offset_slot;
//timing_advance += 2*rx_offset_slot;
//UE->timing_advance += 1*rx_offset_slot;
//UE->timing_advance += 2*rx_offset_slot;
// but use current UE->timing_advance value to compute writeBlockSize
if (UE->timing_advance != timing_advance) {
writeBlockSize -= UE->timing_advance - timing_advance;
timing_advance = UE->timing_advance;
}
//timing_advance += 1*rx_offset_slot;
//timing_advance += 2*rx_offset_slot;
//UE->timing_advance += 1*rx_offset_slot;
//UE->timing_advance += 2*rx_offset_slot;
if (curMsg.proc.nr_slot_tx == 0)
nr_ue_rrc_timer_trigger(UE->Mod_id, curMsg.proc.frame_tx, curMsg.proc.gNB_id);
......
......@@ -440,6 +440,7 @@ double FO_IScaling = 0.5; // I scaling factor of the PID controller for the D
double TO_PScaling = 1;
double TO_IScaling = 0.1;
int TO_IScalingInit = 0;
int commonDoppler = 0; //421528;
......
......@@ -66,7 +66,7 @@
{"P" , CONFIG_HLP_PROPD, 0, .u64ptr=&RFsim_PropDelay, .defintval=0, TYPE_UINT64, 0}, \
{"ue_slot_Rx_Tx" , CONFIG_HLP_UESLOTRXTX, 0, .u16ptr=&NTN_UE_slot_Rx_to_Tx, .defintval=0, TYPE_UINT16, 0}, \
{"ue_k2" , CONFIG_HLP_UEK2, 0, .u16ptr=&NTN_UE_k2, .defintval=0, TYPE_UINT16, 0}, \
{"FD" , CONFIG_HLP_FDoppler, 0, .iptr=&fdoppler, .defintval=0, TYPE_INT, 0}, \
{"FD" , CONFIG_HLP_FDoppler, 0, .iptr=&fdoppler, .defintval=1, TYPE_INT, 0}, \
{"FC" , CONFIG_HLP_FDopplerComp, 0, .iptr=&fdopplerComp, .defintval=1, TYPE_INT, 0}, \
{"TD" , CONFIG_HLP_TDRIFT, 0, .iptr=&RFsim_DriftPerFrame, .defintval=0, TYPE_INT, 0}, \
{"PST" , CONFIG_HLP_PathStart, 0, .u16ptr=&pathStartingTime, .defintval=1050, TYPE_UINT16, 0}, \
......@@ -76,7 +76,8 @@
{"FOP" , CONFIG_HLP_FO_PScaling, 0, .dblptr=&FO_PScaling, .defdblval=0.33, TYPE_DOUBLE, 0}, \
{"FOI" , CONFIG_HLP_FO_IScaling, 0, .dblptr=&FO_IScaling, .defdblval=0.5, TYPE_DOUBLE, 0}, \
{"TOP" , CONFIG_HLP_TP_Scaling, 0, .dblptr=&TO_PScaling, .defdblval=1.0, TYPE_DOUBLE, 0}, \
{"TOI" , CONFIG_HLP_TI_Scaling, 0, .dblptr=&TO_IScaling, .defdblval=0.1, TYPE_DOUBLE, 0} \
{"TOI" , CONFIG_HLP_TI_Scaling, 0, .dblptr=&TO_IScaling, .defdblval=0.1, TYPE_DOUBLE, 0}, \
{"TOII", CONFIG_HLP_TO_Iinit, 0, .iptr=&TO_IScalingInit, .defintval=0, TYPE_INT, 0}, \
}
// clang-format on
......
......@@ -50,9 +50,9 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
int max_val = 0, max_pos = 0;
const int sync_pos = 0;
//uint8_t sync_offset = 0;
static int flagInitIScaling = 0;
static int64_t TO_I_Ctrl = 0; //Integral controller for TO
int I_ScalingF = 10; //Scaling factor for the I controller, can be adjusted
static int frameLast = 0; //frame number of last call of nr_adjust_synch_ue()
static int FirstFlag = 1; //indicate the first call of nr_adjust_synch_ue()
......@@ -97,10 +97,15 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
diff /= FrameDiff; //scaled by the frame number
frameLast = frame; //save the last frame number
if ( (((diff < -4) || (diff > 4)) && (flagInitIScaling == 0)))
{
TO_I_Ctrl = TO_IScalingInit/TO_IScaling;
flagInitIScaling = 1;
}
TO_I_Ctrl += diff; //integral of all offsets
ue->rx_offset = diff;
//ue->rx_offset_TO = diff+TO_I_Ctrl/I_ScalingF; //PI controller
ue->rx_offset_TO = (TO_PScaling*diff) + (TO_I_Ctrl*TO_IScaling); //PI controller
ue->rx_offset_slot = 1;
ue->rx_offset_comp = 0;
......@@ -115,6 +120,8 @@ void nr_adjust_synch_ue(NR_DL_FRAME_PARMS *frame_parms,
ue->rx_offset_comp = 0;
}
LOG_I(PHY, "Frame: %u, diff: %d, rx_offset_TO: %d, PScaling: %f, IScaling: %f, TA: %d, TO_I_Ctrl: %ld \n", frame, ue->rx_offset, ue->rx_offset_TO, TO_PScaling, TO_IScaling, ue->timing_advance, TO_I_Ctrl);
if(abs(diff)<5)
count_max_pos_ok ++;
else
......
......@@ -619,7 +619,7 @@ static int rfsimulator_write_internal(rfsimulator_state_t *t, openair0_timestamp
static int64_t TO_sim_shift = 0;
static uint64_t TO_TS = 0;
if (RFsim_DriftPerFrame!=0) {
if ( TO_gNB_flag) { //a UE is active
if ( TO_gNB_flag) { //a gNB is active
if ( TO_wait_flag ) { //for the first write when a UE is connected
TO_wait_flag=0;
TO_TS = timestamp+samples_per_slot*nb_slot_per_fram*300+samples_per_slot*5; //start drifting 300 frames after a UE is active, trying to skip all the "trash" frames (5 trash frames currently)
......@@ -971,9 +971,9 @@ static int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimest
currDoppler = (currDopplerTmp - initDoppler) ;
}
//RFsim_PropDelay = (2 * norm_d / c) * fsamp;
printf("**** counter: %lu, RFsim_PropDelay[Samp]: %lu , Doppler: %d, freqScale: %f ***** \n ", counter, RFsim_PropDelay, currDoppler, freqScale);
RFsim_PropDelay = (2 * norm_d / c) * fsamp;
//printf("**** counter: %lu, RFsim_PropDelay[Samp]: %lu , Doppler: %d, freqScale: %f ***** \n ", counter, RFsim_PropDelay, currDoppler, freqScale);
//LOG_I(HW, "nbAnt_tx %d\n",nbAnt_tx);
for (int i=0; i < nsamps; i++) {//loop over nsamps
......
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