diff --git a/srslte/examples/cell_measurement.c b/srslte/examples/cell_measurement.c index e4f0b08dd..1a6ab2059 100644 --- a/srslte/examples/cell_measurement.c +++ b/srslte/examples/cell_measurement.c @@ -236,6 +236,8 @@ int main(int argc, char **argv) { } cuhd_start_rx_stream(uhd); + + float rx_gain_offset = 0; /* Main loop */ while (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) { @@ -301,16 +303,26 @@ int main(int argc, char **argv) { snr = SRSLTE_VEC_EMA(srslte_chest_dl_get_snr(&chest),snr,0.05); nframes++; - } + } + + + if ((nframes%100) == 0 || rx_gain_offset == 0) { + if (cuhd_has_rssi(uhd)) { + rx_gain_offset = 10*log10(rssi)-cuhd_get_rssi(uhd); + } else { + rx_gain_offset = cuhd_get_rx_gain(uhd); + } + } // Plot and Printf if ((nframes%10) == 0) { + printf("CFO: %+8.4f KHz, SFO: %+8.4f Khz, RSSI: %5.1f dBm, RSSI/ref-symbol: %+5.1f dBm, " "RSRP: %+5.1f dBm, RSRQ: %5.1f dB, SNR: %5.1f dB\r", srslte_ue_sync_get_cfo(&ue_sync)/1000, srslte_ue_sync_get_sfo(&ue_sync)/1000, - 10*log10(rssi*1000) - cuhd_get_rx_gain(uhd), - 10*log10(rssi_utra*1000)- cuhd_get_rx_gain(uhd), - 10*log10(rsrp*1000)- cuhd_get_rx_gain(uhd), + 10*log10(rssi*1000) - rx_gain_offset, + 10*log10(rssi_utra*1000)- rx_gain_offset, + 10*log10(rsrp*1000) - rx_gain_offset, 10*log10(rsrq), 10*log10(snr)); if (srslte_verbose != SRSLTE_VERBOSE_NONE) { printf("\n"); diff --git a/srslte/include/srslte/cuhd/cuhd.h b/srslte/include/srslte/cuhd/cuhd.h index dceb9029f..67d1472ee 100644 --- a/srslte/include/srslte/cuhd/cuhd.h +++ b/srslte/include/srslte/cuhd/cuhd.h @@ -53,6 +53,10 @@ SRSLTE_API int cuhd_stop_rx_stream(void *h); SRSLTE_API void cuhd_flush_buffer(void *h); +SRSLTE_API bool cuhd_has_rssi(void *h); + +SRSLTE_API float cuhd_get_rssi(void *h); + SRSLTE_API bool cuhd_rx_wait_lo_locked(void *h); SRSLTE_API void cuhd_set_master_clock_rate(void *h, diff --git a/srslte/lib/cuhd/src/cuhd_imp.cpp b/srslte/lib/cuhd/src/cuhd_imp.cpp index c0212f2a2..cc5425df4 100644 --- a/srslte/lib/cuhd/src/cuhd_imp.cpp +++ b/srslte/lib/cuhd/src/cuhd_imp.cpp @@ -108,6 +108,27 @@ void cuhd_flush_buffer(void *h) } while (n > 0); } +bool cuhd_has_rssi(void *h) { + cuhd_handler *handler = static_cast < cuhd_handler * >(h); + std::vector < std::string > mb_sensors = handler->usrp->get_mboard_sensor_names(); + std::vector < std::string > rx_sensors = handler->usrp->get_rx_sensor_names(0); + if (std::find(rx_sensors.begin(), rx_sensors.end(), "rssi") != rx_sensors.end()) { + return true; + } else { + return false; + } +} + +float cuhd_get_rssi(void *h) { + cuhd_handler *handler = static_cast < cuhd_handler * >(h); + if (cuhd_has_rssi(h)) { + uhd::sensor_value_t value = handler->usrp->get_rx_sensor("rssi"); + return value.to_real(); + } else { + return 0; + } +} + int cuhd_start_rx_stream_nsamples(void *h, uint32_t nsamples) { cuhd_handler *handler = static_cast < cuhd_handler * >(h);