diff --git a/lib/include/srsran/phy/common/phy_common_nr.h b/lib/include/srsran/phy/common/phy_common_nr.h index 4db58736c..1fb15d410 100644 --- a/lib/include/srsran/phy/common/phy_common_nr.h +++ b/lib/include/srsran/phy/common/phy_common_nr.h @@ -594,6 +594,13 @@ SRSRAN_API int srsran_carrier_to_cell(const srsran_carrier_nr_t* carrier, srsran */ SRSRAN_API uint32_t srsran_csi_meas_info(const srsran_csi_trs_measurements_t* meas, char* str, uint32_t str_len); +/** + * @brief Converts a given string into a subcarrier spacing + * @param str Provides the string + * @return A valid subcarrier if the string is valid, srsran_subcarrier_spacing_invalid otherwise + */ +SRSRAN_API srsran_subcarrier_spacing_t srsran_subcarrier_spacing_from_str(const char* str); + #ifdef __cplusplus } #endif diff --git a/lib/src/phy/common/phy_common_nr.c b/lib/src/phy/common/phy_common_nr.c index bc829d0e6..2f206ef62 100644 --- a/lib/src/phy/common/phy_common_nr.c +++ b/lib/src/phy/common/phy_common_nr.c @@ -12,6 +12,7 @@ #include "srsran/phy/common/phy_common_nr.h" #include "srsran/phy/utils/vector.h" +#include #include const char* srsran_rnti_type_str(srsran_rnti_type_t rnti_type) @@ -321,3 +322,32 @@ uint32_t srsran_csi_meas_info(const srsran_csi_trs_measurements_t* meas, char* s meas->cfo_hz, meas->delay_us); } + +srsran_subcarrier_spacing_t srsran_subcarrier_spacing_from_str(const char* str) +{ + if (str == NULL) { + return srsran_subcarrier_spacing_invalid; + } + + uint32_t scs = (uint32_t)roundf(strtof(str, NULL)); + switch (scs) { + case 15: + case 15000: + return srsran_subcarrier_spacing_15kHz; + case 30: + case 30000: + return srsran_subcarrier_spacing_30kHz; + case 60: + case 60000: + return srsran_subcarrier_spacing_60kHz; + case 120: + case 120000: + return srsran_subcarrier_spacing_120kHz; + case 240: + case 240000: + return srsran_subcarrier_spacing_240kHz; + default:; // Do nothing + } + + return srsran_subcarrier_spacing_invalid; +}