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.
203 lines
5.0 KiB
C
203 lines
5.0 KiB
C
11 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
|
* Copyright 2013-2014 The libLTE Developers. See the
|
||
|
* COPYRIGHT file at the top-level directory of this distribution.
|
||
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the libLTE library.
|
||
|
*
|
||
|
* libLTE is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Lesser General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* libLTE is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Lesser General Public License can be found in
|
||
|
* 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>
|
||
10 years ago
|
|
||
11 years ago
|
#include <unistd.h>
|
||
|
|
||
11 years ago
|
#include "liblte/phy/phy.h"
|
||
11 years ago
|
|
||
10 years ago
|
#include "cell_search_utils.h"
|
||
|
|
||
|
|
||
11 years ago
|
#ifndef DISABLE_UHD
|
||
11 years ago
|
#include "liblte/cuhd/cuhd.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
|
int nof_frames_total = 50;
|
||
|
int nof_frames_detected = 10;
|
||
10 years ago
|
float threshold = CS_FIND_THRESHOLD;
|
||
11 years ago
|
|
||
|
|
||
10 years ago
|
float uhd_gain = 60.0;
|
||
|
char *uhd_args="";
|
||
11 years ago
|
|
||
|
void usage(char *prog) {
|
||
10 years ago
|
printf("Usage: %s [agsendtvb] -b band\n", prog);
|
||
10 years ago
|
printf("\t-a UHD args [Default %s]\n", uhd_args);
|
||
|
printf("\t-g UHD gain [Default %.2f dB]\n", uhd_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");
|
||
|
printf("\t-d nof_frames_detected [Default 10]\n");
|
||
|
printf("\t-t threshold [Default %.2f]\n",threshold);
|
||
11 years ago
|
printf("\t-v [set verbose to debug, default none]\n");
|
||
11 years ago
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
11 years ago
|
int opt;
|
||
10 years ago
|
while ((opt = getopt(argc, argv, "agsendtvb")) != -1) {
|
||
11 years ago
|
switch(opt) {
|
||
10 years ago
|
case 'a':
|
||
|
uhd_args = argv[optind];
|
||
|
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':
|
||
|
nof_frames_total = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'd':
|
||
|
nof_frames_detected = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 't':
|
||
|
threshold = atof(argv[optind]);
|
||
11 years ago
|
break;
|
||
|
case 'g':
|
||
|
uhd_gain = atof(argv[optind]);
|
||
|
break;
|
||
|
case 'v':
|
||
|
verbose++;
|
||
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
if (band == -1) {
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
10 years ago
|
int n;
|
||
10 years ago
|
void *uhd;
|
||
10 years ago
|
ue_celldetect_t s;
|
||
10 years ago
|
ue_celldetect_result_t found_cells[3];
|
||
10 years ago
|
int nof_freqs;
|
||
|
lte_earfcn_t channels[MAX_EARFCN];
|
||
|
uint32_t freq;
|
||
10 years ago
|
uint8_t bch_payload[BCH_PAYLOAD_LEN];
|
||
|
uint32_t nof_tx_ports;
|
||
|
|
||
10 years ago
|
parse_args(argc, argv);
|
||
|
|
||
10 years ago
|
printf("Opening UHD device...\n");
|
||
|
if (cuhd_open(uhd_args, &uhd)) {
|
||
|
fprintf(stderr, "Error opening uhd\n");
|
||
11 years ago
|
exit(-1);
|
||
10 years ago
|
}
|
||
10 years ago
|
cuhd_set_rx_gain(uhd, uhd_gain);
|
||
10 years ago
|
|
||
10 years ago
|
nof_freqs = lte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
|
||
|
if (nof_freqs < 0) {
|
||
|
fprintf(stderr, "Error getting EARFCN list\n");
|
||
11 years ago
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
|
||
|
if (ue_celldetect_init(&s)) {
|
||
|
fprintf(stderr, "Error initiating UE sync module\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
if (threshold > 0) {
|
||
|
ue_celldetect_set_threshold(&s, threshold);
|
||
|
}
|
||
|
|
||
|
if (nof_frames_total > 0) {
|
||
|
ue_celldetect_set_nof_frames_total(&s, nof_frames_total);
|
||
|
}
|
||
|
if (nof_frames_detected > 0) {
|
||
|
ue_celldetect_set_nof_frames_detected(&s, nof_frames_detected);
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
for (freq=0;freq<nof_freqs;freq+=10) {
|
||
|
|
||
|
/* set uhd_freq */
|
||
10 years ago
|
cuhd_set_rx_freq(uhd, (double) channels[freq].fd * MHZ);
|
||
|
cuhd_rx_wait_lo_locked(uhd);
|
||
|
usleep(10000);
|
||
10 years ago
|
INFO("Set uhd_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000);
|
||
10 years ago
|
|
||
10 years ago
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS. \r", freq, nof_freqs,
|
||
10 years ago
|
channels[freq].id, channels[freq].fd);fflush(stdout);
|
||
10 years ago
|
|
||
|
if (VERBOSE_ISINFO()) {
|
||
|
printf("\n");
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
n = find_all_cells(uhd, found_cells);
|
||
10 years ago
|
if (n < 0) {
|
||
|
fprintf(stderr, "Error searching cell\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
if (n == CS_CELL_DETECTED) {
|
||
10 years ago
|
for (int i=0;i<3;i++) {
|
||
|
if (found_cells[i].peak > threshold/2) {
|
||
10 years ago
|
if (decode_pbch(uhd, &found_cells[i], nof_frames_total, bch_payload, &nof_tx_ports, NULL)) {
|
||
10 years ago
|
fprintf(stderr, "Error decoding PBCH\n");
|
||
|
exit(-1);
|
||
10 years ago
|
} else {
|
||
|
printf("Cell found with %d ports. Decoded MIB: \n", nof_tx_ports);
|
||
|
vec_fprint_hex(stdout, bch_payload, BCH_PAYLOAD_LEN);
|
||
|
}
|
||
10 years ago
|
}
|
||
10 years ago
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
10 years ago
|
|
||
|
printf("\nBye\n");
|
||
10 years ago
|
|
||
|
ue_celldetect_free(&s);
|
||
10 years ago
|
cuhd_close(uhd);
|
||
11 years ago
|
exit(0);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
|