From 09c6077bc9ef1214babcfeccebc344b02fd70483 Mon Sep 17 00:00:00 2001 From: ismagom Date: Sun, 27 Sep 2015 21:51:10 +0200 Subject: [PATCH] Fixed an error in cell_search. Increased estimation time. Improved results presentation --- srslte/examples/cell_search.c | 93 ++++++++++++++++++++++++------ srslte/include/srslte/cuhd/cuhd.h | 2 + srslte/lib/common/src/phy_common.c | 2 +- srslte/lib/cuhd/src/cuhd_imp.cpp | 10 ++-- srslte/lib/ue/src/ue_cell_search.c | 8 ++- 5 files changed, 89 insertions(+), 26 deletions(-) diff --git a/srslte/examples/cell_search.c b/srslte/examples/cell_search.c index 4d211e218..57601f840 100644 --- a/srslte/examples/cell_search.c +++ b/srslte/examples/cell_search.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -55,10 +56,22 @@ int band = -1; int earfcn_start=-1, earfcn_end = -1; -cell_search_cfg_t config = {100, 10, 10.0, 50}; +cell_search_cfg_t config = { + 50, // maximum number of 5ms frames to capture for MIB decoding + 50, // maximum number of 5ms frames to capture for PSS correlation + 4.0, // early-stops cell detection if mean PSR is above this value + 0 // 0 or negative to disable AGC +}; +struct cells { + srslte_cell_t cell; + float freq; + int dl_earfcn; + float power; +}; +struct cells results[1024]; -float uhd_gain = 60.0; +float uhd_gain = 70.0; char *uhd_args=""; void usage(char *prog) { @@ -116,6 +129,15 @@ int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t return cuhd_recv(h, data, nsamples, 1); } +bool go_exit = false; + +void sig_int_handler(int signo) +{ + if (signo == SIGINT) { + go_exit = true; + } +} + int main(int argc, char **argv) { int n; void *uhd; @@ -124,31 +146,45 @@ int main(int argc, char **argv) { int nof_freqs; srslte_earfcn_t channels[MAX_EARFCN]; uint32_t freq; + uint32_t n_found_cells=0; parse_args(argc, argv); - printf("Opening UHD device...\n"); - if (cuhd_open(uhd_args, &uhd)) { - fprintf(stderr, "Error opening uhd\n"); - exit(-1); - } - cuhd_set_rx_gain(uhd, uhd_gain); + if (!config.init_agc) { + printf("Opening UHD device...\n"); + if (cuhd_open(uhd_args, &uhd)) { + fprintf(stderr, "Error opening uhd\n"); + exit(-1); + } + cuhd_set_rx_gain(uhd, uhd_gain); + } else { + printf("Opening UHD device with threaded RX Gain control ...\n"); + if (cuhd_open_th(uhd_args, &uhd, false)) { + fprintf(stderr, "Error opening uhd\n"); + exit(-1); + } + cuhd_set_rx_gain(uhd, 50); + } + // Supress UHD messages + cuhd_supress_stdout(); nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN); if (nof_freqs < 0) { fprintf(stderr, "Error getting EARFCN list\n"); exit(-1); } - - for (freq=0;freq 0) { for (int i=0;i<3;i++) { - if (found_cells[i].peak > config.threshold/2) { - srslte_cell_t cell; + if (found_cells[i].psr > config.threshold/2) { + srslte_cell_t cell; cell.id = found_cells[i].cell_id; cell.cp = found_cells[i].cp; int ret = cuhd_mib_decoder(uhd, &config, &cell); @@ -193,13 +229,34 @@ int main(int argc, char **argv) { } if (ret == SRSLTE_UE_MIB_FOUND) { printf("Found CELL ID %d. %d PRB, %d ports\n", - cell.id, cell.nof_prb, cell.nof_ports); - } + cell.id, + cell.nof_prb, + cell.nof_ports); + if (cell.nof_ports > 0) { + memcpy(&results[n_found_cells].cell, &cell, sizeof(srslte_cell_t)); + results[n_found_cells].freq = channels[freq].fd; + results[n_found_cells].dl_earfcn = channels[freq].id; + results[n_found_cells].power = found_cells[i].peak; + n_found_cells++; + } + } } } } } + printf("\n\nFound %d cells\n", n_found_cells); + for (int i=0;iusrp = uhd::usrp::multi_usrp::make(_args + ", master_clock_rate=30720000, recv_frame_size=7696,num_recv_frames=64,send_frame_size=7696,num_send_frames=64"); handler->usrp->set_clock_source("internal"); - -#ifdef HIDE_MESSAGES - uhd::msg::register_handler(my_handler); -#endif - + std::string otw, cpu; otw = "sc16"; cpu = "fc32"; diff --git a/srslte/lib/ue/src/ue_cell_search.c b/srslte/lib/ue/src/ue_cell_search.c index bc00e9ea0..7773bf75a 100644 --- a/srslte/lib/ue/src/ue_cell_search.c +++ b/srslte/lib/ue/src/ue_cell_search.c @@ -183,7 +183,9 @@ static void get_cell(srslte_ue_cellsearch_t * q, uint32_t nof_detected_frames, s * Saves in the pointer max_N_id_2 the N_id_2 index of the cell with the highest PSR * Returns the number of found cells or a negative number if error */ -int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t * q, srslte_ue_cellsearch_result_t found_cells[3], uint32_t *max_N_id_2) +int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t * q, + srslte_ue_cellsearch_result_t found_cells[3], + uint32_t *max_N_id_2) { int ret = 0; float max_peak_value = -1.0; @@ -208,7 +210,9 @@ int srslte_ue_cellsearch_scan(srslte_ue_cellsearch_t * q, srslte_ue_cellsearch_r /** Finds a cell for a given N_id_2 and stores ID and CP in the structure pointed by found_cell. * Returns 1 if the cell is found, 0 if not or -1 on error */ -int srslte_ue_cellsearch_scan_N_id_2(srslte_ue_cellsearch_t * q, uint32_t N_id_2, srslte_ue_cellsearch_result_t *found_cell) +int srslte_ue_cellsearch_scan_N_id_2(srslte_ue_cellsearch_t * q, + uint32_t N_id_2, + srslte_ue_cellsearch_result_t *found_cell) { int ret = SRSLTE_ERROR_INVALID_INPUTS; cf_t *sf_buffer = NULL;