2014-03-03 19:09:26 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* \section COPYRIGHT
|
|
|
|
*
|
2015-11-13 12:22:33 +00:00
|
|
|
* Copyright 2013-2015 Software Radio Systems Limited
|
2014-03-03 19:09:26 +00:00
|
|
|
*
|
|
|
|
* \section LICENSE
|
|
|
|
*
|
2015-03-18 12:31:13 +00:00
|
|
|
* This file is part of the srsLTE library.
|
2014-03-03 19:09:26 +00:00
|
|
|
*
|
2015-03-18 12:31:13 +00:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 15:05:40 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-03-03 19:09:26 +00:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-18 12:31:13 +00:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-03-03 19:09:26 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 15:05:40 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-03-03 19:09:26 +00:00
|
|
|
*
|
2015-05-08 15:05:40 +00:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-03-03 19:09:26 +00:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-02-13 16:54:51 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <sys/time.h>
|
2015-09-27 19:51:10 +00:00
|
|
|
#include <signal.h>
|
2014-08-01 21:26:28 +00:00
|
|
|
|
2014-02-13 16:54:51 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-03-18 12:31:13 +00:00
|
|
|
#include "srslte/srslte.h"
|
2014-02-13 16:54:51 +00:00
|
|
|
|
2017-05-18 07:48:24 +00:00
|
|
|
#include "srslte/phy/rf/rf_utils.h"
|
2014-08-02 21:55:12 +00:00
|
|
|
|
|
|
|
|
2015-12-07 17:06:56 +00:00
|
|
|
#ifndef DISABLE_RF
|
2017-05-18 07:48:24 +00:00
|
|
|
#include "srslte/phy/rf/rf.h"
|
2014-02-13 16:54:51 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-22 14:56:56 +00:00
|
|
|
#define MHZ 1000000
|
|
|
|
#define SAMP_FREQ 1920000
|
|
|
|
#define FLEN 9600
|
|
|
|
#define FLEN_PERIOD 0.005
|
2014-02-13 16:54:51 +00:00
|
|
|
|
2014-08-01 23:36:34 +00:00
|
|
|
#define MAX_EARFCN 1000
|
|
|
|
|
2014-02-13 16:54:51 +00:00
|
|
|
|
2014-07-22 14:56:56 +00:00
|
|
|
int band = -1;
|
2014-02-13 16:54:51 +00:00
|
|
|
int earfcn_start=-1, earfcn_end = -1;
|
2014-11-16 19:40:41 +00:00
|
|
|
|
2016-04-08 15:04:01 +00:00
|
|
|
|
|
|
|
cell_search_cfg_t cell_detect_config = {
|
2016-04-14 18:45:46 +00:00
|
|
|
SRSLTE_DEFAULT_MAX_FRAMES_PBCH,
|
|
|
|
SRSLTE_DEFAULT_MAX_FRAMES_PSS,
|
|
|
|
SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES,
|
2016-04-08 15:04:01 +00:00
|
|
|
0
|
|
|
|
};
|
2014-02-13 16:54:51 +00:00
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
struct cells {
|
|
|
|
srslte_cell_t cell;
|
|
|
|
float freq;
|
|
|
|
int dl_earfcn;
|
|
|
|
float power;
|
|
|
|
};
|
|
|
|
struct cells results[1024];
|
2014-02-13 16:54:51 +00:00
|
|
|
|
2015-12-10 10:11:57 +00:00
|
|
|
float rf_gain = 70.0;
|
|
|
|
char *rf_args="";
|
2014-02-13 16:54:51 +00:00
|
|
|
|
|
|
|
void usage(char *prog) {
|
2014-08-01 23:36:34 +00:00
|
|
|
printf("Usage: %s [agsendtvb] -b band\n", prog);
|
2015-12-10 10:11:57 +00:00
|
|
|
printf("\t-a RF args [Default %s]\n", rf_args);
|
|
|
|
printf("\t-g RF gain [Default %.2f dB]\n", rf_gain);
|
2014-06-17 09:11:41 +00:00
|
|
|
printf("\t-s earfcn_start [Default All]\n");
|
|
|
|
printf("\t-e earfcn_end [Default All]\n");
|
2014-08-01 23:36:34 +00:00
|
|
|
printf("\t-n nof_frames_total [Default 100]\n");
|
2015-03-18 18:14:24 +00:00
|
|
|
printf("\t-v [set srslte_verbose to debug, default none]\n");
|
2014-02-13 16:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void parse_args(int argc, char **argv) {
|
2014-06-17 09:11:41 +00:00
|
|
|
int opt;
|
2016-04-08 15:04:01 +00:00
|
|
|
while ((opt = getopt(argc, argv, "agsendvb")) != -1) {
|
2014-06-17 09:11:41 +00:00
|
|
|
switch(opt) {
|
2014-07-22 14:56:56 +00:00
|
|
|
case 'a':
|
2015-12-10 10:11:57 +00:00
|
|
|
rf_args = argv[optind];
|
2014-07-22 14:56:56 +00:00
|
|
|
break;
|
2014-06-17 09:11:41 +00:00
|
|
|
case 'b':
|
|
|
|
band = atoi(argv[optind]);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
earfcn_start = atoi(argv[optind]);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
earfcn_end = atoi(argv[optind]);
|
|
|
|
break;
|
2014-08-01 23:36:34 +00:00
|
|
|
case 'n':
|
2016-04-08 15:04:01 +00:00
|
|
|
cell_detect_config.max_frames_pss = atoi(argv[optind]);
|
2014-06-17 09:11:41 +00:00
|
|
|
break;
|
|
|
|
case 'g':
|
2015-12-10 10:11:57 +00:00
|
|
|
rf_gain = atof(argv[optind]);
|
2014-06-17 09:11:41 +00:00
|
|
|
break;
|
|
|
|
case 'v':
|
2015-03-18 18:14:24 +00:00
|
|
|
srslte_verbose++;
|
2014-06-17 09:11:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 14:56:56 +00:00
|
|
|
if (band == -1) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(-1);
|
2014-06-17 09:11:41 +00:00
|
|
|
}
|
2014-02-13 16:54:51 +00:00
|
|
|
}
|
|
|
|
|
2017-02-17 08:58:37 +00:00
|
|
|
int srslte_rf_recv_wrapper(void *h, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t *t) {
|
2014-12-11 23:04:21 +00:00
|
|
|
DEBUG(" ---- Receive %d samples ---- \n", nsamples);
|
2017-02-17 08:58:37 +00:00
|
|
|
void *ptr[SRSLTE_MAX_PORTS];
|
|
|
|
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
|
2017-02-13 12:29:20 +00:00
|
|
|
ptr[i] = data[i];
|
|
|
|
}
|
|
|
|
return srslte_rf_recv_with_time_multi((srslte_rf_t*) h, ptr, nsamples, 1, NULL, NULL);
|
2014-12-11 23:04:21 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
bool go_exit = false;
|
|
|
|
|
|
|
|
void sig_int_handler(int signo)
|
|
|
|
{
|
2015-10-01 08:47:01 +00:00
|
|
|
printf("SIGINT received. Exiting...\n");
|
2015-09-27 19:51:10 +00:00
|
|
|
if (signo == SIGINT) {
|
|
|
|
go_exit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 17:02:25 +00:00
|
|
|
double srslte_rf_set_rx_gain_wrapper(void *h, double f) {
|
|
|
|
return srslte_rf_set_rx_gain((srslte_rf_t*) h, f);
|
2015-12-10 10:11:57 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 16:54:51 +00:00
|
|
|
int main(int argc, char **argv) {
|
2014-08-01 23:36:34 +00:00
|
|
|
int n;
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_t rf;
|
2015-03-18 18:14:24 +00:00
|
|
|
srslte_ue_cellsearch_t cs;
|
|
|
|
srslte_ue_cellsearch_result_t found_cells[3];
|
2014-08-01 23:36:34 +00:00
|
|
|
int nof_freqs;
|
2015-03-18 12:59:29 +00:00
|
|
|
srslte_earfcn_t channels[MAX_EARFCN];
|
2014-08-01 23:36:34 +00:00
|
|
|
uint32_t freq;
|
2015-09-27 19:51:10 +00:00
|
|
|
uint32_t n_found_cells=0;
|
2014-10-18 16:26:21 +00:00
|
|
|
|
2014-08-01 23:36:34 +00:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
2015-12-17 08:30:49 +00:00
|
|
|
printf("Opening RF device...\n");
|
|
|
|
if (srslte_rf_open(&rf, rf_args)) {
|
|
|
|
fprintf(stderr, "Error opening rf\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2016-04-08 15:04:01 +00:00
|
|
|
if (!cell_detect_config.init_agc) {
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_set_rx_gain(&rf, rf_gain);
|
2015-09-27 19:51:10 +00:00
|
|
|
} else {
|
2015-12-17 08:30:49 +00:00
|
|
|
printf("Starting AGC thread...\n");
|
|
|
|
if (srslte_rf_start_gain_thread(&rf, false)) {
|
2015-12-10 10:11:57 +00:00
|
|
|
fprintf(stderr, "Error opening rf\n");
|
2015-09-27 19:51:10 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_set_rx_gain(&rf, 50);
|
2015-09-27 19:51:10 +00:00
|
|
|
}
|
2015-10-01 08:11:44 +00:00
|
|
|
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_set_master_clock_rate(&rf, 30.72e6);
|
2015-10-01 08:11:44 +00:00
|
|
|
|
2015-12-10 10:11:57 +00:00
|
|
|
// Supress RF messages
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_suppress_stdout(&rf);
|
2014-08-01 23:36:34 +00:00
|
|
|
|
2015-03-18 12:59:29 +00:00
|
|
|
nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
|
2014-07-22 14:56:56 +00:00
|
|
|
if (nof_freqs < 0) {
|
|
|
|
fprintf(stderr, "Error getting EARFCN list\n");
|
2014-06-17 09:11:41 +00:00
|
|
|
exit(-1);
|
|
|
|
}
|
2015-09-27 19:51:10 +00:00
|
|
|
|
2015-10-01 08:47:01 +00:00
|
|
|
sigset_t sigset;
|
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, SIGINT);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
2015-09-27 19:51:10 +00:00
|
|
|
signal(SIGINT, sig_int_handler);
|
|
|
|
|
2017-09-01 11:29:11 +00:00
|
|
|
if (srslte_ue_cellsearch_init_multi(&cs, cell_detect_config.max_frames_pss, srslte_rf_recv_wrapper, 1, (void*) &rf)) {
|
|
|
|
fprintf(stderr, "Error initiating UE cell detect\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cell_detect_config.max_frames_pss) {
|
|
|
|
srslte_ue_cellsearch_set_nof_valid_frames(&cs, cell_detect_config.nof_valid_pss_frames);
|
|
|
|
}
|
|
|
|
if (cell_detect_config.init_agc) {
|
|
|
|
srslte_ue_sync_start_agc(&cs.ue_sync, srslte_rf_set_rx_gain_wrapper, cell_detect_config.init_agc);
|
|
|
|
}
|
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
for (freq=0;freq<nof_freqs && !go_exit;freq++) {
|
2014-08-01 23:36:34 +00:00
|
|
|
|
2015-12-10 10:11:57 +00:00
|
|
|
/* set rf_freq */
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_set_rx_freq(&rf, (double) channels[freq].fd * MHZ);
|
|
|
|
srslte_rf_rx_wait_lo_locked(&rf);
|
2015-12-10 10:11:57 +00:00
|
|
|
INFO("Set rf_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000);
|
2014-07-22 14:56:56 +00:00
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS.\n", freq, nof_freqs,
|
|
|
|
channels[freq].id, channels[freq].fd);fflush(stdout);
|
2014-08-01 23:36:34 +00:00
|
|
|
|
2015-03-18 18:14:24 +00:00
|
|
|
if (SRSLTE_VERBOSE_ISINFO()) {
|
2014-08-01 23:36:34 +00:00
|
|
|
printf("\n");
|
2014-06-17 09:11:41 +00:00
|
|
|
}
|
2014-12-11 23:04:21 +00:00
|
|
|
|
2015-03-18 18:14:24 +00:00
|
|
|
bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t));
|
2015-01-21 07:55:40 +00:00
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000);
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_set_rx_srate(&rf, SRSLTE_CS_SAMP_FREQ);
|
2015-01-21 07:55:40 +00:00
|
|
|
INFO("Starting receiver...\n", 0);
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_start_rx_stream(&rf);
|
2015-01-21 07:55:40 +00:00
|
|
|
|
2015-03-18 18:14:24 +00:00
|
|
|
n = srslte_ue_cellsearch_scan(&cs, found_cells, NULL);
|
2014-08-01 23:36:34 +00:00
|
|
|
if (n < 0) {
|
|
|
|
fprintf(stderr, "Error searching cell\n");
|
|
|
|
exit(-1);
|
2015-09-27 19:51:10 +00:00
|
|
|
} else if (n > 0) {
|
2014-08-02 01:05:54 +00:00
|
|
|
for (int i=0;i<3;i++) {
|
2016-04-08 15:04:01 +00:00
|
|
|
if (found_cells[i].psr > 10.0) {
|
2015-09-27 19:51:10 +00:00
|
|
|
srslte_cell_t cell;
|
2015-01-21 07:55:40 +00:00
|
|
|
cell.id = found_cells[i].cell_id;
|
|
|
|
cell.cp = found_cells[i].cp;
|
2017-02-13 12:29:20 +00:00
|
|
|
int ret = rf_mib_decoder(&rf, 1, &cell_detect_config, &cell, NULL);
|
2015-01-21 07:55:40 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Error decoding MIB\n");
|
2014-08-02 01:05:54 +00:00
|
|
|
exit(-1);
|
2014-12-11 23:04:21 +00:00
|
|
|
}
|
2015-03-18 18:14:24 +00:00
|
|
|
if (ret == SRSLTE_UE_MIB_FOUND) {
|
2014-12-11 23:04:21 +00:00
|
|
|
printf("Found CELL ID %d. %d PRB, %d ports\n",
|
2015-09-27 19:51:10 +00:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
2014-08-02 01:05:54 +00:00
|
|
|
}
|
2014-08-01 23:36:34 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-17 09:11:41 +00:00
|
|
|
}
|
2017-09-01 11:29:11 +00:00
|
|
|
|
2015-09-27 19:51:10 +00:00
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-14 12:46:58 +00:00
|
|
|
printf("\nBye\n");
|
2017-09-01 11:29:11 +00:00
|
|
|
|
|
|
|
srslte_ue_cellsearch_free(&cs);
|
2015-12-16 17:02:25 +00:00
|
|
|
srslte_rf_close(&rf);
|
2014-06-17 09:11:41 +00:00
|
|
|
exit(0);
|
2014-02-13 16:54:51 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 23:36:34 +00:00
|
|
|
|