From d4e3c5d384805557054b6d447a41a86694f079c8 Mon Sep 17 00:00:00 2001 From: francescomani Date: Fri, 19 Dec 2025 09:59:36 +0100 Subject: [PATCH] define speed of light in utils to avoid multiple local definitions --- common/platform_constants.h | 1 + openair1/PHY/NR_UE_TRANSPORT/nr_ntn_l1.c | 2 -- openair1/SIMULATION/TOOLS/random_channel.c | 3 +-- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 3 +-- radio/rfsimulator/apply_channelmod.c | 2 +- radio/rfsimulator/simulator.cpp | 4 ++-- 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/common/platform_constants.h b/common/platform_constants.h index 4000ffb001..2faadc3dcd 100644 --- a/common/platform_constants.h +++ b/common/platform_constants.h @@ -100,4 +100,5 @@ // SDAP #define MAX_QOS_FLOWS 64 +#define SPEED_OF_LIGHT 299792458 // in m/s #endif /* __PLATFORM_CONSTANTS_H__ */ diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ntn_l1.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ntn_l1.c index 51031d5449..deae817a36 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ntn_l1.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ntn_l1.c @@ -48,8 +48,6 @@ void fix_ntn_epoch_hfn(PHY_VARS_NR_UE *UE, int hfn, int frame) LOG_I(PHY, "setting epoch_hfn = %d\n", *epoch_hfn); } -#define SPEED_OF_LIGHT 299792458 - // calculate TA and Doppler based on the NTN-Config, if abs_subframe_tx < 0 then apply only Doppler void apply_ntn_timing_advance_and_doppler(PHY_VARS_NR_UE *UE, const NR_DL_FRAME_PARMS *fp, int abs_subframe_tx) { diff --git a/openair1/SIMULATION/TOOLS/random_channel.c b/openair1/SIMULATION/TOOLS/random_channel.c index 92e191b2dc..cf973f5d84 100644 --- a/openair1/SIMULATION/TOOLS/random_channel.c +++ b/openair1/SIMULATION/TOOLS/random_channel.c @@ -462,8 +462,7 @@ void get_cexp_doppler(struct complexd *cexp_doppler, channel_desc_t *chan_desc, // TS 38.104 - Table G.3-1 uint16_t Dmin = 2; uint16_t Ds = 300; - double c = 299792458; - double v = chan_desc->max_Doppler * (c / (double)chan_desc->center_freq); + double v = chan_desc->max_Doppler * ((double) SPEED_OF_LIGHT / (double)chan_desc->center_freq); #ifdef DOPPLER_DEBUG printf("v = %f\n", v); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index c3cc4088ed..5f80703c21 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -1542,8 +1542,7 @@ static void nr_generate_Msg2(module_id_t module_idP, float T_c_ns = 0.509; int numerology = ul_bwp->scs; float rtt_ns = T_c_ns * 16 * 64 / (1 << numerology) * ra->timing_offset; - float speed_of_light_in_meters_per_second = 299792458.0f; - float distance_in_meters = speed_of_light_in_meters_per_second * rtt_ns / 1000 / 1000 / 1000 / 2; + float distance_in_meters = (float) SPEED_OF_LIGHT * rtt_ns / 1000 / 1000 / 1000 / 2; LOG_A(NR_MAC, "UE %04x: %d.%d Generating RA-Msg2 DCI, RA RNTI 0x%x, state %d, preamble_index(RAPID) %d, " "timing_offset = %d (estimated distance %.1f [m])\n", diff --git a/radio/rfsimulator/apply_channelmod.c b/radio/rfsimulator/apply_channelmod.c index 3f2e8d85c1..d1d1042451 100644 --- a/radio/rfsimulator/apply_channelmod.c +++ b/radio/rfsimulator/apply_channelmod.c @@ -65,7 +65,7 @@ void update_channel_model(channel_desc_t *channelDesc, uint64_t TS) const double pos_ue_y = 0; const double pos_ue_z = radius_earth; - const double c = 299792458; // m/s + const double c = (double) SPEED_OF_LIGHT; if (channelDesc->is_uplink) { const double dir_ue_sat_x = pos_sat_x - pos_ue_x; diff --git a/radio/rfsimulator/simulator.cpp b/radio/rfsimulator/simulator.cpp index 65e32216c4..ef6be135e6 100644 --- a/radio/rfsimulator/simulator.cpp +++ b/radio/rfsimulator/simulator.cpp @@ -713,7 +713,7 @@ static int rfsimu_setdistance_cmd(char *buff, int debug, telnet_printfunc_t prnt rfsimulator_state_t *t = (rfsimulator_state_t *)arg; const double sample_rate = t->sample_rate; - const double c = 299792458; /* 3e8 */ + const double c = (double) SPEED_OF_LIGHT; const uint64_t new_offset = (double)distance * sample_rate / c; const double new_distance = (double)new_offset * c / sample_rate; @@ -749,7 +749,7 @@ static int rfsimu_getdistance_cmd(char *buff, int debug, telnet_printfunc_t prnt rfsimulator_state_t *t = (rfsimulator_state_t *)arg; const double sample_rate = t->sample_rate; - const double c = 299792458; /* 3e8 */ + const double c = (double) SPEED_OF_LIGHT; for (int i = 0; i < MAX_FD_RFSIMU; i++) { buffer_t *b = &t->buf[i];