From 06c0374ec809a4793c3db1c23d0f1186fa78d009 Mon Sep 17 00:00:00 2001 From: Roberto Rosca Date: Mon, 2 Sep 2024 16:59:22 +0300 Subject: [PATCH] Added UE support for position coordinates taken from conf files --- CMakeLists.txt | 1 + executables/nr-ue.c | 2 ++ executables/position_interface.c | 33 +++++++++++++++++ executables/position_interface.h | 38 ++++++++++++++++++++ openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c | 8 +++-- targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf | 6 ++++ 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 executables/position_interface.c create mode 100644 executables/position_interface.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e6147ce3fb..681c727dfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2079,6 +2079,7 @@ add_executable(nr-uesoftmodem ${rrc_h} ${s1ap_h} ${OPENAIR_DIR}/executables/nr-uesoftmodem.c + ${OPENAIR_DIR}/executables/position_interface.c ${OPENAIR_DIR}/executables/nr-ue.c ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR_DIR}/radio/COMMON/common_lib.c diff --git a/executables/nr-ue.c b/executables/nr-ue.c index e2882b4224..49deb85456 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -41,6 +41,7 @@ #include "PHY/MODULATION/nr_modulation.h" #include "instrumentation.h" #include "common/utils/threadPool/notified_fifo.h" +#include "position_interface.h" /* * NR SLOT PROCESSING SEQUENCE @@ -157,6 +158,7 @@ void init_nr_ue_vars(PHY_VARS_NR_UE *ue, uint8_t UE_id) ue->target_Nid_cell = -1; ue->timing_advance = ue->frame_parms.samples_per_subframe * get_nrUE_params()->ntn_ta_common; + check_position(UE_id); // initialize all signal buffers init_nr_ue_signal(ue, nb_connected_gNB); diff --git a/executables/position_interface.c b/executables/position_interface.c new file mode 100644 index 0000000000..3d6bbe3094 --- /dev/null +++ b/executables/position_interface.c @@ -0,0 +1,33 @@ +#include "position_interface.h" + +extern uint16_t NB_UE_INST; +static position_t **positionArray = 0; + +position_t *check_position(int Mod_id) +{ + AssertFatal(Mod_id < NB_UE_INST, "Mod_id must be less than NB_UE_INST. Mod_id:%d NB_UE_INST:%d", Mod_id, NB_UE_INST); + if (positionArray == NULL) { + positionArray = (position_t **)calloc(1, sizeof(position_t *) * NB_UE_INST); + } + if (!positionArray[Mod_id]) { + char positionName[64]; + sprintf(positionName, "position%d", Mod_id); + positionArray[Mod_id] = (void *)init_position(positionName); + } + return (position_t *)positionArray[Mod_id]; +} + +position_t *init_position(char *sectionName) +{ + position_t *position = (position_t *)calloc(sizeof(position_t), 1); + paramdef_t position_params[] = POSITION_CONFIG_PARAMS_DEF; + int ret = config_get(config_get_if(), position_params, sizeofArray(position_params), sectionName); + AssertFatal(ret >= 0, "configuration couldn't be performed for position name: %s", sectionName); + + return position; +} + +position_t *get_position(int Mod_id) +{ + return positionArray[Mod_id]; +} \ No newline at end of file diff --git a/executables/position_interface.h b/executables/position_interface.h new file mode 100644 index 0000000000..a645961f7e --- /dev/null +++ b/executables/position_interface.h @@ -0,0 +1,38 @@ +#ifndef __POSITION_INTERFACE__H__ +#define __POSITION_INTERFACE__H__ + +#include +#include +#include "PHY/defs_nr_UE.h" +#include "executables/nr-uesoftmodem.h" + +/* position configuration parameters name */ +#define CONFIG_STRING_POSITION_X "x" +#define CONFIG_STRING_POSITION_Y "y" +#define CONFIG_STRING_POSITION_Z "z" + +#define HELP_STRING_POSITION "Postion coordinates (x, y, z) config params" + +// Position parameters config +/*----------------------------------------------------------------------------------------------------------------------------------------------------*/ +/* position configuration parameters */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/*----------------------------------------------------------------------------------------------------------------------------------------------------*/ +// clang-format off +#define POSITION_CONFIG_PARAMS_DEF { \ + {CONFIG_STRING_POSITION_X, HELP_STRING_POSITION, 0, .dblptr=&(position->positionX), .defuintval=0, TYPE_DOUBLE, 0}, \ + {CONFIG_STRING_POSITION_Y, HELP_STRING_POSITION, 0, .dblptr=&(position->positionY), .defuintval=0, TYPE_DOUBLE, 0}, \ + {CONFIG_STRING_POSITION_Z, HELP_STRING_POSITION, 0, .dblptr=&(position->positionZ), .defuintval=0, TYPE_DOUBLE, 0} \ +} +// clang-format on + +typedef struct { + double positionX; + double positionY; + double positionZ; +} position_t; + +position_t *check_position(int Mod_id); +position_t *init_position(char *sectionName); +position_t *get_position(int Mod_id); +#endif \ No newline at end of file diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 3eabec0249..dd98495fe0 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -41,10 +41,14 @@ #include #include "openair2/LAYER2/RLC/rlc.h" +#include "nr-uesoftmodem.h" + static double get_ta_Common_ms(NR_NTN_Config_r17_t *ntn_Config_r17) { - if (ntn_Config_r17 && ntn_Config_r17->ta_Info_r17) - return ntn_Config_r17->ta_Info_r17->ta_Common_r17 * 4.072e-6; // ta_Common_r17 is in units of 4.072e-3 µs + if (ntn_Config_r17 && ntn_Config_r17->ta_Info_r17) { + // ta_Common_r17 is in units of 4.072e-3 µs + return (ntn_Config_r17->ta_Info_r17->ta_Common_r17 * 4.072e-6 + get_nrUE_params()->ntn_ta_common) * 2; + } return 0.0; } diff --git a/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf b/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf index 545b44f888..955b7b1253 100644 --- a/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf +++ b/targets/PROJECTS/GENERIC-NR-5GC/CONF/ue.conf @@ -6,3 +6,9 @@ dnn= "oai"; nssai_sst=1; nssai_sd=1; } + +position0 = { + x = 0.0; + y = 0.0; + z = 6371400.0; +} \ No newline at end of file