From 125747ae4ab0be3a46e56d4a4a9434154e4cc190 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Thu, 27 Feb 2020 16:31:07 +0100 Subject: [PATCH] Added external C to phy_common header and ACK/NACK feedack mode parser --- lib/include/srslte/phy/common/phy_common.h | 18 ++++++++++++++- lib/src/phy/common/phy_common.c | 26 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/include/srslte/phy/common/phy_common.h b/lib/include/srslte/phy/common/phy_common.h index 78350252f..18aec4952 100644 --- a/lib/include/srslte/phy/common/phy_common.h +++ b/lib/include/srslte/phy/common/phy_common.h @@ -35,6 +35,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #include "srslte/config.h" #define SRSLTE_NOF_SF_X_FRAME 10 @@ -123,7 +127,7 @@ typedef enum { SRSLTE_SF_NORM = 0, SRSLTE_SF_MBSFN } srslte_sf_t; #define SRSLTE_SF_LEN_MAX (SRSLTE_SF_LEN(SRSLTE_SYMBOL_SZ_MAX)) #define SRSLTE_SLOT_LEN_PRB(nof_prb) (SRSLTE_SLOT_LEN(srslte_symbol_sz(nof_prb))) -#define SRSLTE_SF_LEN_PRB(nof_prb) (SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb))) +#define SRSLTE_SF_LEN_PRB(nof_prb) ((uint32_t)SRSLTE_SF_LEN(srslte_symbol_sz(nof_prb))) #define SRSLTE_SLOT_LEN_RE(nof_prb, cp) (nof_prb * SRSLTE_NRE * SRSLTE_CP_NSYMB(cp)) #define SRSLTE_SF_LEN_RE(nof_prb, cp) (2 * SRSLTE_SLOT_LEN_RE(nof_prb, cp)) @@ -481,4 +485,16 @@ bool srslte_psbch_is_symbol(srslte_sl_symbol_t type, srslte_sl_tm_t tm, uint32_t */ SRSLTE_API const char* srslte_ack_nack_feedback_mode_string(srslte_ack_nack_feedback_mode_t ack_nack_feedback_mode); +/** + * Returns a constant string pointer with the ACK/NACK feedback mode + * + * @param ack_nack_feedback_mode Mode + * @return Returns constant pointer with the text of the mode if succesful, `error` otherwise + */ +SRSLTE_API srslte_ack_nack_feedback_mode_t srslte_string_ack_nack_feedback_mode(const char* str); + +#ifdef __cplusplus +} +#endif + #endif // SRSLTE_PHY_COMMON_H diff --git a/lib/src/phy/common/phy_common.c b/lib/src/phy/common/phy_common.c index 2b55fd711..772536b7b 100644 --- a/lib/src/phy/common/phy_common.c +++ b/lib/src/phy/common/phy_common.c @@ -869,3 +869,29 @@ const char* srslte_ack_nack_feedback_mode_string(srslte_ack_nack_feedback_mode_t return "error"; } } + +srslte_ack_nack_feedback_mode_t srslte_string_ack_nack_feedback_mode(const char* str) +{ + int i = 0; + char str2[8] = {}; + + // Copy string in local buffer + strncpy(str2, str, sizeof(str2)); + + // Convert to lower case + while (str2[i] |= ' ', str2[++i]) + ; + + // Format 1b with channel selection + if (strcmp(str2, "cs") == 0) { + return SRSLTE_PUCCH_ACK_NACK_FEEDBACK_MODE_CS; + } + + // Detect PUCCH3 + if (strcmp(str2, "pucch3") == 0) { + return SRSLTE_PUCCH_ACK_NACK_FEEDBACK_MODE_PUCCH3; + } + + // Otherwise Normal + return SRSLTE_PUCCH_ACK_NACK_FEEDBACK_MODE_NORMAL; +}