mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
7.4 KiB
C
277 lines
7.4 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
11 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
10 years ago
|
* This file is part of the srsLTE library.
|
||
11 years ago
|
*
|
||
10 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
10 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
11 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
10 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
11 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
11 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
11 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
11 years ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
#include <unistd.h>
|
||
|
#include <math.h>
|
||
|
#include <sys/time.h>
|
||
9 years ago
|
#include <signal.h>
|
||
10 years ago
|
|
||
11 years ago
|
#include <unistd.h>
|
||
|
|
||
10 years ago
|
#include "srslte/srslte.h"
|
||
11 years ago
|
|
||
8 years ago
|
#include "srslte/phy/rf/rf_utils.h"
|
||
10 years ago
|
|
||
|
|
||
9 years ago
|
#ifndef DISABLE_RF
|
||
8 years ago
|
#include "srslte/phy/rf/rf.h"
|
||
11 years ago
|
#endif
|
||
|
|
||
10 years ago
|
#define MHZ 1000000
|
||
|
#define SAMP_FREQ 1920000
|
||
|
#define FLEN 9600
|
||
|
#define FLEN_PERIOD 0.005
|
||
11 years ago
|
|
||
10 years ago
|
#define MAX_EARFCN 1000
|
||
|
|
||
11 years ago
|
|
||
10 years ago
|
int band = -1;
|
||
11 years ago
|
int earfcn_start=-1, earfcn_end = -1;
|
||
10 years ago
|
|
||
9 years ago
|
|
||
|
cell_search_cfg_t cell_detect_config = {
|
||
9 years ago
|
SRSLTE_DEFAULT_MAX_FRAMES_PBCH,
|
||
|
SRSLTE_DEFAULT_MAX_FRAMES_PSS,
|
||
|
SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES,
|
||
9 years ago
|
0
|
||
|
};
|
||
11 years ago
|
|
||
9 years ago
|
struct cells {
|
||
|
srslte_cell_t cell;
|
||
|
float freq;
|
||
|
int dl_earfcn;
|
||
|
float power;
|
||
|
};
|
||
|
struct cells results[1024];
|
||
11 years ago
|
|
||
9 years ago
|
float rf_gain = 70.0;
|
||
|
char *rf_args="";
|
||
11 years ago
|
|
||
|
void usage(char *prog) {
|
||
10 years ago
|
printf("Usage: %s [agsendtvb] -b band\n", prog);
|
||
9 years ago
|
printf("\t-a RF args [Default %s]\n", rf_args);
|
||
|
printf("\t-g RF gain [Default %.2f dB]\n", rf_gain);
|
||
11 years ago
|
printf("\t-s earfcn_start [Default All]\n");
|
||
|
printf("\t-e earfcn_end [Default All]\n");
|
||
10 years ago
|
printf("\t-n nof_frames_total [Default 100]\n");
|
||
10 years ago
|
printf("\t-v [set srslte_verbose to debug, default none]\n");
|
||
11 years ago
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
11 years ago
|
int opt;
|
||
9 years ago
|
while ((opt = getopt(argc, argv, "agsendvb")) != -1) {
|
||
11 years ago
|
switch(opt) {
|
||
10 years ago
|
case 'a':
|
||
9 years ago
|
rf_args = argv[optind];
|
||
10 years ago
|
break;
|
||
11 years ago
|
case 'b':
|
||
|
band = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 's':
|
||
|
earfcn_start = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'e':
|
||
|
earfcn_end = atoi(argv[optind]);
|
||
|
break;
|
||
10 years ago
|
case 'n':
|
||
9 years ago
|
cell_detect_config.max_frames_pss = atoi(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'g':
|
||
9 years ago
|
rf_gain = atof(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'v':
|
||
10 years ago
|
srslte_verbose++;
|
||
11 years ago
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
if (band == -1) {
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
int srslte_rf_recv_wrapper(void *h, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t *t) {
|
||
10 years ago
|
DEBUG(" ---- Receive %d samples ---- \n", nsamples);
|
||
8 years ago
|
void *ptr[SRSLTE_MAX_PORTS];
|
||
|
for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
|
||
8 years ago
|
ptr[i] = data[i];
|
||
|
}
|
||
|
return srslte_rf_recv_with_time_multi((srslte_rf_t*) h, ptr, nsamples, 1, NULL, NULL);
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
bool go_exit = false;
|
||
|
|
||
|
void sig_int_handler(int signo)
|
||
|
{
|
||
9 years ago
|
printf("SIGINT received. Exiting...\n");
|
||
9 years ago
|
if (signo == SIGINT) {
|
||
|
go_exit = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
double srslte_rf_set_rx_gain_wrapper(void *h, double f) {
|
||
|
return srslte_rf_set_rx_gain((srslte_rf_t*) h, f);
|
||
9 years ago
|
}
|
||
|
|
||
11 years ago
|
int main(int argc, char **argv) {
|
||
10 years ago
|
int n;
|
||
9 years ago
|
srslte_rf_t rf;
|
||
10 years ago
|
srslte_ue_cellsearch_t cs;
|
||
|
srslte_ue_cellsearch_result_t found_cells[3];
|
||
10 years ago
|
int nof_freqs;
|
||
10 years ago
|
srslte_earfcn_t channels[MAX_EARFCN];
|
||
10 years ago
|
uint32_t freq;
|
||
9 years ago
|
uint32_t n_found_cells=0;
|
||
10 years ago
|
|
||
10 years ago
|
parse_args(argc, argv);
|
||
|
|
||
9 years ago
|
printf("Opening RF device...\n");
|
||
|
if (srslte_rf_open(&rf, rf_args)) {
|
||
|
fprintf(stderr, "Error opening rf\n");
|
||
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
if (!cell_detect_config.init_agc) {
|
||
9 years ago
|
srslte_rf_set_rx_gain(&rf, rf_gain);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
printf("Starting AGC thread...\n");
|
||
|
if (srslte_rf_start_gain_thread(&rf, false)) {
|
||
9 years ago
|
fprintf(stderr, "Error opening rf\n");
|
||
9 years ago
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
srslte_rf_set_rx_gain(&rf, 50);
|
||
9 years ago
|
}
|
||
9 years ago
|
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, 30.72e6);
|
||
9 years ago
|
|
||
9 years ago
|
// Supress RF messages
|
||
9 years ago
|
srslte_rf_suppress_stdout(&rf);
|
||
10 years ago
|
|
||
10 years ago
|
nof_freqs = srslte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
|
||
10 years ago
|
if (nof_freqs < 0) {
|
||
|
fprintf(stderr, "Error getting EARFCN list\n");
|
||
11 years ago
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
sigset_t sigset;
|
||
|
sigemptyset(&sigset);
|
||
|
sigaddset(&sigset, SIGINT);
|
||
|
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||
9 years ago
|
signal(SIGINT, sig_int_handler);
|
||
|
|
||
|
for (freq=0;freq<nof_freqs && !go_exit;freq++) {
|
||
10 years ago
|
|
||
9 years ago
|
/* set rf_freq */
|
||
9 years ago
|
srslte_rf_set_rx_freq(&rf, (double) channels[freq].fd * MHZ);
|
||
|
srslte_rf_rx_wait_lo_locked(&rf);
|
||
9 years ago
|
INFO("Set rf_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000);
|
||
10 years ago
|
|
||
9 years ago
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS.\n", freq, nof_freqs,
|
||
|
channels[freq].id, channels[freq].fd);fflush(stdout);
|
||
10 years ago
|
|
||
10 years ago
|
if (SRSLTE_VERBOSE_ISINFO()) {
|
||
10 years ago
|
printf("\n");
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t));
|
||
10 years ago
|
|
||
8 years ago
|
if (srslte_ue_cellsearch_init_multi(&cs, cell_detect_config.max_frames_pss, srslte_rf_recv_wrapper, 1, (void*) &rf)) {
|
||
10 years ago
|
fprintf(stderr, "Error initiating UE cell detect\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
9 years ago
|
if (cell_detect_config.max_frames_pss) {
|
||
|
srslte_ue_cellsearch_set_nof_valid_frames(&cs, cell_detect_config.nof_valid_pss_frames);
|
||
10 years ago
|
}
|
||
9 years ago
|
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);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000);
|
||
9 years ago
|
srslte_rf_set_rx_srate(&rf, SRSLTE_CS_SAMP_FREQ);
|
||
10 years ago
|
INFO("Starting receiver...\n", 0);
|
||
9 years ago
|
srslte_rf_start_rx_stream(&rf);
|
||
10 years ago
|
|
||
10 years ago
|
n = srslte_ue_cellsearch_scan(&cs, found_cells, NULL);
|
||
8 years ago
|
srslte_ue_cellsearch_free(&cs);
|
||
10 years ago
|
if (n < 0) {
|
||
|
fprintf(stderr, "Error searching cell\n");
|
||
|
exit(-1);
|
||
9 years ago
|
} else if (n > 0) {
|
||
10 years ago
|
for (int i=0;i<3;i++) {
|
||
9 years ago
|
if (found_cells[i].psr > 10.0) {
|
||
9 years ago
|
srslte_cell_t cell;
|
||
10 years ago
|
cell.id = found_cells[i].cell_id;
|
||
|
cell.cp = found_cells[i].cp;
|
||
8 years ago
|
int ret = rf_mib_decoder(&rf, 1, &cell_detect_config, &cell, NULL);
|
||
10 years ago
|
if (ret < 0) {
|
||
|
fprintf(stderr, "Error decoding MIB\n");
|
||
10 years ago
|
exit(-1);
|
||
10 years ago
|
}
|
||
10 years ago
|
if (ret == SRSLTE_UE_MIB_FOUND) {
|
||
10 years ago
|
printf("Found CELL ID %d. %d PRB, %d ports\n",
|
||
9 years ago
|
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++;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
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));
|
||
|
|
||
|
}
|
||
|
|
||
10 years ago
|
printf("\nBye\n");
|
||
10 years ago
|
|
||
9 years ago
|
srslte_rf_close(&rf);
|
||
11 years ago
|
exit(0);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
|