Fixed an error in cell_search. Increased estimation time. Improved results presentation

master
ismagom 9 years ago
parent 0b048dd601
commit 09c6077bc9

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/time.h>
#include <signal.h>
#include <unistd.h> #include <unistd.h>
@ -55,10 +56,22 @@
int band = -1; int band = -1;
int earfcn_start=-1, earfcn_end = -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=""; char *uhd_args="";
void usage(char *prog) { 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); 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 main(int argc, char **argv) {
int n; int n;
void *uhd; void *uhd;
@ -124,31 +146,45 @@ int main(int argc, char **argv) {
int nof_freqs; int nof_freqs;
srslte_earfcn_t channels[MAX_EARFCN]; srslte_earfcn_t channels[MAX_EARFCN];
uint32_t freq; uint32_t freq;
uint32_t n_found_cells=0;
parse_args(argc, argv); parse_args(argc, argv);
printf("Opening UHD device...\n"); if (!config.init_agc) {
if (cuhd_open(uhd_args, &uhd)) { printf("Opening UHD device...\n");
fprintf(stderr, "Error opening uhd\n"); if (cuhd_open(uhd_args, &uhd)) {
exit(-1); fprintf(stderr, "Error opening uhd\n");
} exit(-1);
cuhd_set_rx_gain(uhd, uhd_gain); }
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); nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
if (nof_freqs < 0) { if (nof_freqs < 0) {
fprintf(stderr, "Error getting EARFCN list\n"); fprintf(stderr, "Error getting EARFCN list\n");
exit(-1); exit(-1);
} }
for (freq=0;freq<nof_freqs;freq++) { signal(SIGINT, sig_int_handler);
for (freq=0;freq<nof_freqs && !go_exit;freq++) {
/* set uhd_freq */ /* set uhd_freq */
cuhd_set_rx_freq(uhd, (double) channels[freq].fd * MHZ); cuhd_set_rx_freq(uhd, (double) channels[freq].fd * MHZ);
cuhd_rx_wait_lo_locked(uhd); cuhd_rx_wait_lo_locked(uhd);
INFO("Set uhd_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000); INFO("Set uhd_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000);
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS. \n", freq, nof_freqs, printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS.\n", freq, nof_freqs,
channels[freq].id, channels[freq].fd); channels[freq].id, channels[freq].fd);fflush(stdout);
if (SRSLTE_VERBOSE_ISINFO()) { if (SRSLTE_VERBOSE_ISINFO()) {
printf("\n"); printf("\n");
@ -171,7 +207,7 @@ int main(int argc, char **argv) {
srslte_ue_sync_start_agc(&cs.ue_sync, cuhd_set_rx_gain, config.init_agc); srslte_ue_sync_start_agc(&cs.ue_sync, cuhd_set_rx_gain, config.init_agc);
} }
INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000); INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000);
cuhd_set_rx_srate(uhd, SRSLTE_CS_SAMP_FREQ); cuhd_set_rx_srate(uhd, SRSLTE_CS_SAMP_FREQ);
INFO("Starting receiver...\n", 0); INFO("Starting receiver...\n", 0);
cuhd_start_rx_stream(uhd); cuhd_start_rx_stream(uhd);
@ -180,10 +216,10 @@ int main(int argc, char **argv) {
if (n < 0) { if (n < 0) {
fprintf(stderr, "Error searching cell\n"); fprintf(stderr, "Error searching cell\n");
exit(-1); exit(-1);
} else if (n == 1) { } else if (n > 0) {
for (int i=0;i<3;i++) { for (int i=0;i<3;i++) {
if (found_cells[i].peak > config.threshold/2) { if (found_cells[i].psr > config.threshold/2) {
srslte_cell_t cell; srslte_cell_t cell;
cell.id = found_cells[i].cell_id; cell.id = found_cells[i].cell_id;
cell.cp = found_cells[i].cp; cell.cp = found_cells[i].cp;
int ret = cuhd_mib_decoder(uhd, &config, &cell); int ret = cuhd_mib_decoder(uhd, &config, &cell);
@ -193,13 +229,34 @@ int main(int argc, char **argv) {
} }
if (ret == SRSLTE_UE_MIB_FOUND) { if (ret == SRSLTE_UE_MIB_FOUND) {
printf("Found CELL ID %d. %d PRB, %d ports\n", 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;i<n_found_cells;i++) {
printf("Found CELL %.1f MHz, EARFCN=%d, PHYID=%d, %d PRB, %d ports, PSS power=%.1f dBm\n",
results[i].freq,
results[i].dl_earfcn,
results[i].cell.id,
results[i].cell.nof_prb,
results[i].cell.nof_ports,
10*log10(results[i].power));
}
printf("\nBye\n"); printf("\nBye\n");
cuhd_close(uhd); cuhd_close(uhd);

@ -80,6 +80,8 @@ SRSLTE_API double cuhd_get_rx_gain(void *h);
SRSLTE_API double cuhd_get_tx_gain(void *h); SRSLTE_API double cuhd_get_tx_gain(void *h);
SRSLTE_API void cuhd_supress_stdout();
SRSLTE_API double cuhd_set_rx_freq(void *h, SRSLTE_API double cuhd_set_rx_freq(void *h,
double freq); double freq);

@ -36,7 +36,7 @@
#include "srslte/common/sequence.h" #include "srslte/common/sequence.h"
//#define USE_REDUCED_SAMPLING_RATES #define USE_REDUCED_SAMPLING_RATES

@ -179,6 +179,10 @@ float cuhd_get_rx_gain_offset(void *h) {
return 15; return 15;
} }
void cuhd_supress_stdout() {
uhd::msg::register_handler(my_handler);
}
int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx) int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_rx)
{ {
uhd::set_thread_priority_safe(); uhd::set_thread_priority_safe();
@ -186,11 +190,7 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_
std::string _args = std::string(args); std::string _args = std::string(args);
handler->usrp = 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 = 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"); handler->usrp->set_clock_source("internal");
#ifdef HIDE_MESSAGES
uhd::msg::register_handler(my_handler);
#endif
std::string otw, cpu; std::string otw, cpu;
otw = "sc16"; otw = "sc16";
cpu = "fc32"; cpu = "fc32";

@ -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 * 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 * 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; int ret = 0;
float max_peak_value = -1.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. /** 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 * 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; int ret = SRSLTE_ERROR_INVALID_INPUTS;
cf_t *sf_buffer = NULL; cf_t *sf_buffer = NULL;

Loading…
Cancel
Save