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.
171 lines
4.2 KiB
C
171 lines
4.2 KiB
C
10 years ago
|
/**
|
||
|
*
|
||
|
* \section COPYRIGHT
|
||
|
*
|
||
9 years ago
|
* Copyright 2013-2015 Software Radio Systems Limited
|
||
10 years ago
|
*
|
||
|
* \section LICENSE
|
||
|
*
|
||
|
* This file is part of the srsLTE library.
|
||
|
*
|
||
|
* 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
|
||
10 years ago
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
|
* srsLTE 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
|
||
10 years ago
|
* GNU Affero General Public License for more details.
|
||
10 years ago
|
*
|
||
10 years ago
|
* A copy of the GNU Affero General Public License can be found in
|
||
10 years ago
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <signal.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <strings.h>
|
||
|
#include <unistd.h>
|
||
|
#include <math.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
#include "srslte/srslte.h"
|
||
8 years ago
|
#include "srslte/phy/rf/rf.h"
|
||
|
#include "srslte/phy/io/filesink.h"
|
||
10 years ago
|
|
||
|
static bool keep_running = true;
|
||
|
char *output_file_name;
|
||
9 years ago
|
char *rf_args="";
|
||
|
float rf_gain=40.0, rf_freq=-1.0, rf_rate=0.96e6;
|
||
10 years ago
|
int nof_samples = -1;
|
||
|
|
||
|
void int_handler(int dummy) {
|
||
|
keep_running = false;
|
||
|
}
|
||
|
|
||
|
void usage(char *prog) {
|
||
|
printf("Usage: %s [agrnv] -f rx_frequency_hz -o output_file\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);
|
||
|
printf("\t-r RF Rate [Default %.6f Hz]\n", rf_rate);
|
||
10 years ago
|
printf("\t-n nof_samples [Default %d]\n", nof_samples);
|
||
|
printf("\t-v srslte_verbose\n");
|
||
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
|
int opt;
|
||
10 years ago
|
while ((opt = getopt(argc, argv, "agrnvfo")) != -1) {
|
||
10 years ago
|
switch (opt) {
|
||
|
case 'o':
|
||
|
output_file_name = argv[optind];
|
||
|
break;
|
||
|
case 'a':
|
||
9 years ago
|
rf_args = argv[optind];
|
||
10 years ago
|
break;
|
||
|
case 'g':
|
||
9 years ago
|
rf_gain = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'r':
|
||
9 years ago
|
rf_rate = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'f':
|
||
9 years ago
|
rf_freq = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'n':
|
||
|
nof_samples = atoi(argv[optind]);
|
||
|
break;
|
||
|
case 'v':
|
||
|
srslte_verbose++;
|
||
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
9 years ago
|
if (rf_freq < 0) {
|
||
10 years ago
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
cf_t *buffer;
|
||
|
int sample_count, n;
|
||
9 years ago
|
srslte_rf_t rf;
|
||
10 years ago
|
srslte_filesink_t sink;
|
||
|
int32_t buflen;
|
||
|
|
||
|
signal(SIGINT, int_handler);
|
||
|
|
||
|
parse_args(argc, argv);
|
||
|
|
||
|
buflen = 4800;
|
||
|
sample_count = 0;
|
||
|
|
||
|
buffer = malloc(sizeof(cf_t) * buflen);
|
||
|
if (!buffer) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
srslte_filesink_init(&sink, output_file_name, SRSLTE_COMPLEX_FLOAT_BIN);
|
||
|
|
||
9 years ago
|
printf("Opening RF device...\n");
|
||
9 years ago
|
if (srslte_rf_open(&rf, rf_args)) {
|
||
9 years ago
|
fprintf(stderr, "Error opening rf\n");
|
||
10 years ago
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, 30.72e6);
|
||
9 years ago
|
|
||
9 years ago
|
sigset_t sigset;
|
||
|
sigemptyset(&sigset);
|
||
|
sigaddset(&sigset, SIGINT);
|
||
|
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||
|
|
||
9 years ago
|
printf("Set RX freq: %.2f MHz\n", srslte_rf_set_rx_freq(&rf, rf_freq) / 1000000);
|
||
|
printf("Set RX gain: %.2f dB\n", srslte_rf_set_rx_gain(&rf, rf_gain));
|
||
|
float srate = srslte_rf_set_rx_srate(&rf, rf_rate);
|
||
9 years ago
|
if (srate != rf_rate) {
|
||
9 years ago
|
if (srate < 10e6) {
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, 4*rf_rate);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, rf_rate);
|
||
9 years ago
|
}
|
||
9 years ago
|
srate = srslte_rf_set_rx_srate(&rf, rf_rate);
|
||
9 years ago
|
if (srate != rf_rate) {
|
||
|
fprintf(stderr, "Errror setting samplign frequency %.2f MHz\n", rf_rate*1e-6);
|
||
9 years ago
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
printf("Correctly RX rate: %.2f MHz\n", srate*1e-6);
|
||
9 years ago
|
srslte_rf_rx_wait_lo_locked(&rf);
|
||
|
srslte_rf_start_rx_stream(&rf);
|
||
10 years ago
|
|
||
|
|
||
|
while((sample_count < nof_samples || nof_samples == -1)
|
||
|
&& keep_running){
|
||
9 years ago
|
n = srslte_rf_recv(&rf, buffer, buflen, 1);
|
||
10 years ago
|
if (n < 0) {
|
||
|
fprintf(stderr, "Error receiving samples\n");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
|
srslte_filesink_write(&sink, buffer, buflen);
|
||
|
sample_count += buflen;
|
||
|
}
|
||
|
|
||
|
srslte_filesink_free(&sink);
|
||
|
free(buffer);
|
||
9 years ago
|
srslte_rf_close(&rf);
|
||
10 years ago
|
|
||
|
printf("Ok - wrote %d samples\n", sample_count);
|
||
|
exit(0);
|
||
|
}
|