From 5e4fb481842a57c7ca27196b3d9bb4484610cd99 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Mon, 25 Jun 2018 14:51:54 +0200 Subject: [PATCH] Refactored CQI reporting logging in UE. Fixes #199 --- lib/include/srslte/phy/phch/cqi.h | 5 +- lib/src/phy/phch/cqi.c | 81 +++++++++++++++++++++++++++++++ srsue/hdr/phy/phch_worker.h | 1 + srsue/src/phy/phch_worker.cc | 23 ++++----- 4 files changed, 98 insertions(+), 12 deletions(-) diff --git a/lib/include/srslte/phy/phch/cqi.h b/lib/include/srslte/phy/phch/cqi.h index 4363ccaa7..481fce494 100644 --- a/lib/include/srslte/phy/phch/cqi.h +++ b/lib/include/srslte/phy/phch/cqi.h @@ -43,7 +43,7 @@ #define SRSLTE_CQI_MAX_BITS 64 #define SRSLTE_DIF_CQI_MAX_BITS 3 #define SRSLTE_PMI_MAX_BITS 4 -#define SRSLTE_CQI_STR_MAX_CHAR 32 +#define SRSLTE_CQI_STR_MAX_CHAR 64 typedef struct { bool configured; @@ -150,6 +150,9 @@ SRSLTE_API int srslte_cqi_format2_subband_pack(srslte_cqi_format2_subband_t *msg SRSLTE_API int srslte_cqi_value_unpack(uint8_t buff[SRSLTE_CQI_MAX_BITS], srslte_cqi_value_t *value); +SRSLTE_API int srslte_cqi_value_tostring(srslte_cqi_value_t *value, char *buff, uint32_t buff_len); + + SRSLTE_API int srslte_cqi_hl_subband_unpack(uint8_t buff[SRSLTE_CQI_MAX_BITS], srslte_cqi_hl_subband_t *msg); diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index 683144439..7c945850a 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -234,6 +234,87 @@ int srslte_cqi_value_unpack(uint8_t buff[SRSLTE_CQI_MAX_BITS], srslte_cqi_value_ return -1; } +/******************************************************* + * TO STRING FUNCTIONS * + *******************************************************/ + +static int srslte_cqi_format2_wideband_tostring(srslte_cqi_format2_wideband_t *msg, char *buff, uint32_t buff_len) { + int n = 0; + + n += snprintf(buff + n, buff_len - n, ", cqi=%d", msg->wideband_cqi); + + if (msg->pmi_present) { + if (msg->rank_is_not_one) { + n += snprintf(buff + n, buff_len - n, ", diff_cqi=%d", msg->spatial_diff_cqi); + } + n += snprintf(buff + n, buff_len - n, ", pmi=%d", msg->pmi); + } + + return n; +} + +static int srslte_cqi_format2_subband_tostring(srslte_cqi_format2_subband_t *msg, char *buff, uint32_t buff_len) { + int n = 0; + + n += snprintf(buff + n, buff_len - n, ", cqi=%d", msg->subband_cqi); + n += snprintf(buff + n, buff_len - n, ", label=%d", msg->subband_label); + + return n; +} + +static int srslte_cqi_ue_subband_tostring(srslte_cqi_ue_subband_t *msg, char *buff, uint32_t buff_len) { + int n = 0; + + n += snprintf(buff + n, buff_len - n, ", cqi=%d", msg->wideband_cqi); + n += snprintf(buff + n, buff_len - n, ", diff_cqi=%d", msg->subband_diff_cqi); + n += snprintf(buff + n, buff_len - n, ", L=%d", msg->L); + + return n; +} + +static int srslte_cqi_hl_subband_tostring(srslte_cqi_hl_subband_t *msg, char *buff, uint32_t buff_len) { + int n = 0; + + n += snprintf(buff + n, buff_len - n, ", cqi=%d", msg->wideband_cqi_cw0); + n += snprintf(buff + n, buff_len - n, ", diff=%d", msg->subband_diff_cqi_cw0); + + if (msg->rank_is_not_one) { + n += snprintf(buff + n, buff_len - n, ", cqi1=%d", msg->wideband_cqi_cw1); + n += snprintf(buff + n, buff_len - n, ", diff1=%d", msg->subband_diff_cqi_cw1); + } + + if (msg->pmi_present) { + n += snprintf(buff + n, buff_len - n, ", pmi=%d", msg->pmi); + } + + n += snprintf(buff + n, buff_len - n, ", N=%d", msg->N); + + return n; +} + +int srslte_cqi_value_tostring(srslte_cqi_value_t *value, char *buff, uint32_t buff_len) { + int ret = -1; + + switch (value->type) { + case SRSLTE_CQI_TYPE_WIDEBAND: + ret = srslte_cqi_format2_wideband_tostring(&value->wideband, buff, buff_len); + break; + case SRSLTE_CQI_TYPE_SUBBAND: + ret = srslte_cqi_format2_subband_tostring(&value->subband, buff, buff_len); + break; + case SRSLTE_CQI_TYPE_SUBBAND_UE: + ret = srslte_cqi_ue_subband_tostring(&value->subband_ue, buff, buff_len); + break; + case SRSLTE_CQI_TYPE_SUBBAND_HL: + ret = srslte_cqi_hl_subband_tostring(&value->subband_hl, buff, buff_len); + break; + default: + /* Do nothing */; + } + + return ret; +} + int srslte_cqi_size(srslte_cqi_value_t *value) { int size = 0; diff --git a/srsue/hdr/phy/phch_worker.h b/srsue/hdr/phy/phch_worker.h index ce53e8833..244657975 100644 --- a/srsue/hdr/phy/phch_worker.h +++ b/srsue/hdr/phy/phch_worker.h @@ -162,6 +162,7 @@ private: srslte_ue_ul_t ue_ul; srslte_timestamp_t tx_time; srslte_uci_data_t uci_data; + srslte_cqi_value_t cqi_report; uint16_t ul_rnti; // UL configuration parameters diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 64e3a9e5e..43a31ba0e 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -1032,7 +1032,8 @@ bool phch_worker::decode_pdcch_ul(mac_interface_phy::mac_grant_t* grant) void phch_worker::reset_uci() { - bzero(&uci_data, sizeof(srslte_uci_data_t)); + ZERO_OBJECT(uci_data); + ZERO_OBJECT(cqi_report); } void phch_worker::set_uci_ack(bool ack[SRSLTE_MAX_CODEWORDS], bool tb_en[SRSLTE_MAX_CODEWORDS]) @@ -1082,7 +1083,6 @@ void phch_worker::set_uci_periodic_cqi() compute_ri(NULL, NULL, NULL); phy->last_pmi = (uint8_t) ue_dl.pmi[phy->last_ri % SRSLTE_MAX_LAYERS]; - srslte_cqi_value_t cqi_report; ZERO_OBJECT(cqi_report); if (period_cqi.format_is_subband) { @@ -1137,7 +1137,6 @@ void phch_worker::set_uci_aperiodic_cqi() reported RI. For other transmission modes they are reported conditioned on rank 1. */ if (rnti_is_set) { - srslte_cqi_value_t cqi_report; ZERO_OBJECT(cqi_report); cqi_report.type = SRSLTE_CQI_TYPE_SUBBAND_HL; @@ -1291,11 +1290,13 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui #endif char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); + if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { + srslte_cqi_value_tostring(&cqi_report, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); + } uint8_t dummy[2] = {0,0}; log_h->info_hex(payload, grant->mcs.tbs/8, - "PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s%s\n", + "PUSCH: tti_tx=%d, alloc=(%d,%d), tbs=%d, mcs=%d, rv=%d%s%s%s, cfo=%.1f KHz%s%s\n", (tti + HARQ_DELAY_MS) % 10240, grant->n_prb[0], grant->n_prb[0] + grant->L_prb, grant->mcs.tbs / 8, grant->mcs.idx, rv, @@ -1303,7 +1304,6 @@ void phch_worker::encode_pusch(srslte_ra_ul_grant_t *grant, uint8_t *payload, ui uci_data.uci_ack_len > 1 ? (uci_data.uci_ack_2 ? "1" : "0") : "", uci_data.uci_ri_len > 0 ? (uci_data.uci_ri ? ", ri=1" : ", ri=0") : "", cfo * 15, timestr, - uci_data.uci_cqi_len > 0 ? ", cqi=" : "", uci_data.uci_cqi_len > 0 ? cqi_str : ""); // Store metrics @@ -1345,17 +1345,18 @@ void phch_worker::encode_pucch() float tx_power = srslte_ue_ul_pucch_power(&ue_ul, phy->pathloss, ue_ul.last_pucch_format, uci_data.uci_cqi_len, uci_data.uci_ack_len); float gain = set_power(tx_power); - char str_cqi[SRSLTE_CQI_STR_MAX_CHAR] = ""; - srslte_cqi_to_str(uci_data.uci_cqi, uci_data.uci_cqi_len, str_cqi, SRSLTE_CQI_STR_MAX_CHAR); + char cqi_str[SRSLTE_CQI_STR_MAX_CHAR] = ""; + if (log_h->get_level() >= srslte::LOG_LEVEL_INFO) { + srslte_cqi_value_tostring(&cqi_report, cqi_str, SRSLTE_CQI_STR_MAX_CHAR); + } - Info("PUCCH: tti_tx=%d, n_pucch=%d, n_prb=%d, ack=%s%s%s%s%s, sr=%s, cfo=%.1f KHz%s\n", + Info("PUCCH: tti_tx=%d, n_pucch=%d, n_prb=%d, ack=%s%s%s%s, sr=%s, cfo=%.1f KHz%s\n", (tti + 4) % 10240, ue_ul.pucch.last_n_pucch, ue_ul.pucch.last_n_prb, uci_data.uci_ack_len > 0 ? (uci_data.uci_ack ? "1" : "0") : "no", uci_data.uci_ack_len > 1 ? (uci_data.uci_ack_2 ? "1" : "0") : "", uci_data.uci_ri_len > 0 ? (uci_data.uci_ri ? ", ri=1" : ", ri=0") : "", - uci_data.uci_cqi_len > 0 ? ", cqi=" : "", - uci_data.uci_cqi_len > 0 ? str_cqi : "", + uci_data.uci_cqi_len > 0 ? cqi_str : "", uci_data.scheduling_request ? "yes" : "no", cfo * 15, timestr); }