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.
202 lines
5.6 KiB
C
202 lines
5.6 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
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* 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
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Affero 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/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <unistd.h>
|
||
|
#include <math.h>
|
||
|
#include <time.h>
|
||
|
#include <complex.h>
|
||
|
|
||
8 years ago
|
#include "srslte/phy/rf/rf.h"
|
||
10 years ago
|
#include "srslte/srslte.h"
|
||
|
|
||
9 years ago
|
uint32_t nof_prb = 25;
|
||
10 years ago
|
uint32_t nof_frames = 20;
|
||
|
|
||
9 years ago
|
int time_adv_samples = 0;
|
||
|
float tone_offset_hz = 1e6;
|
||
9 years ago
|
float rf_rx_gain=40, srslte_rf_tx_gain=40, rf_freq=2.4e9;
|
||
9 years ago
|
char *rf_args="";
|
||
10 years ago
|
char *output_filename = NULL;
|
||
|
char *input_filename = NULL;
|
||
|
|
||
|
void usage(char *prog) {
|
||
9 years ago
|
printf("Usage: %s -o [rx_signal_file]\n", prog);
|
||
9 years ago
|
printf("\t-a RF args [Default %s]\n", rf_args);
|
||
|
printf("\t-f RF TX/RX frequency [Default %.2f MHz]\n", rf_freq/1e6);
|
||
|
printf("\t-g RF RX gain [Default %.1f dB]\n", rf_rx_gain);
|
||
9 years ago
|
printf("\t-G RF TX gain [Default %.1f dB]\n", srslte_rf_tx_gain);
|
||
9 years ago
|
printf("\t-t Single tone offset (Hz) [Default %f]\n", tone_offset_hz);
|
||
|
printf("\t-T Time advance samples [Default %d]\n", time_adv_samples);
|
||
9 years ago
|
printf("\t-i File name to read signal from [Default single tone]\n");
|
||
10 years ago
|
printf("\t-p Number of UL RB [Default %d]\n", nof_prb);
|
||
|
}
|
||
|
|
||
|
void parse_args(int argc, char **argv) {
|
||
|
int opt;
|
||
9 years ago
|
while ((opt = getopt(argc, argv, "ioafgGptT")) != -1) {
|
||
10 years ago
|
switch (opt) {
|
||
|
case 'a':
|
||
9 years ago
|
rf_args = argv[optind];
|
||
10 years ago
|
break;
|
||
|
case 'o':
|
||
|
output_filename = argv[optind];
|
||
|
break;
|
||
|
case 'i':
|
||
|
input_filename = argv[optind];
|
||
|
break;
|
||
9 years ago
|
case 't':
|
||
|
tone_offset_hz = atof(argv[optind]);
|
||
|
break;
|
||
9 years ago
|
case 'T':
|
||
|
time_adv_samples = atoi(argv[optind]);
|
||
|
break;
|
||
10 years ago
|
case 'f':
|
||
9 years ago
|
rf_freq = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'g':
|
||
9 years ago
|
rf_rx_gain = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'G':
|
||
9 years ago
|
srslte_rf_tx_gain = atof(argv[optind]);
|
||
10 years ago
|
break;
|
||
|
case 'p':
|
||
|
nof_prb = atoi(argv[optind]);
|
||
|
if (!srslte_nofprb_isvalid(nof_prb)) {
|
||
|
fprintf(stderr, "Invalid number of UL RB %d\n", nof_prb);
|
||
|
exit(-1);
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
|
}
|
||
9 years ago
|
if (!output_filename) {
|
||
10 years ago
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
if (time_adv_samples < 0) {
|
||
|
printf("Time advance must be positive\n");
|
||
|
usage(argv[0]);
|
||
|
exit(-1);
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
parse_args(argc, argv);
|
||
|
|
||
|
uint32_t flen = srslte_sampling_freq_hz(nof_prb)/1000;
|
||
9 years ago
|
|
||
10 years ago
|
cf_t *rx_buffer = malloc(sizeof(cf_t)*flen*nof_frames);
|
||
|
if (!rx_buffer) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
|
|
||
9 years ago
|
cf_t *tx_buffer = malloc(sizeof(cf_t)*(flen+time_adv_samples));
|
||
10 years ago
|
if (!tx_buffer) {
|
||
|
perror("malloc");
|
||
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
bzero(tx_buffer, sizeof(cf_t)*(flen+time_adv_samples));
|
||
10 years ago
|
|
||
10 years ago
|
cf_t *zeros = calloc(sizeof(cf_t),flen);
|
||
|
if (!zeros) {
|
||
|
perror("calloc");
|
||
|
exit(-1);
|
||
|
}
|
||
9 years ago
|
|
||
|
float time_adv_sec = (float) time_adv_samples/srslte_sampling_freq_hz(nof_prb);
|
||
10 years ago
|
|
||
9 years ago
|
// Send through RF
|
||
9 years ago
|
srslte_rf_t rf;
|
||
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
|
|
||
|
int srate = srslte_sampling_freq_hz(nof_prb);
|
||
|
if (srate < 10e6) {
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, 4*srate);
|
||
9 years ago
|
} else {
|
||
9 years ago
|
srslte_rf_set_master_clock_rate(&rf, srate);
|
||
9 years ago
|
}
|
||
9 years ago
|
srslte_rf_set_rx_srate(&rf, (double) srate);
|
||
|
srslte_rf_set_tx_srate(&rf, (double) srate);
|
||
9 years ago
|
|
||
|
|
||
10 years ago
|
printf("Subframe len: %d samples\n", flen);
|
||
9 years ago
|
printf("Time advance: %f us\n",time_adv_sec*1e6);
|
||
9 years ago
|
printf("Set TX/RX rate: %.2f MHz\n", (float) srate / 1000000);
|
||
9 years ago
|
printf("Set RX gain: %.1f dB\n", srslte_rf_set_rx_gain(&rf, rf_rx_gain));
|
||
|
printf("Set TX gain: %.1f dB\n", srslte_rf_set_tx_gain(&rf, srslte_rf_tx_gain));
|
||
|
printf("Set TX/RX freq: %.2f MHz\n", srslte_rf_set_rx_freq(&rf, rf_freq) / 1000000);
|
||
|
srslte_rf_set_tx_freq(&rf, rf_freq);
|
||
9 years ago
|
|
||
10 years ago
|
sleep(1);
|
||
|
|
||
9 years ago
|
if (input_filename) {
|
||
9 years ago
|
srslte_vec_load_file(input_filename, &tx_buffer[time_adv_samples], flen*sizeof(cf_t));
|
||
9 years ago
|
} else {
|
||
9 years ago
|
for (int i=0;i<flen-time_adv_samples;i++) {
|
||
|
tx_buffer[i+time_adv_samples] = 0.3*cexpf(_Complex_I*2*M_PI*tone_offset_hz*((float) i/(float) srate));
|
||
9 years ago
|
}
|
||
9 years ago
|
srslte_vec_save_file("srslte_rf_txrx_tone", tx_buffer, flen*sizeof(cf_t));
|
||
9 years ago
|
}
|
||
10 years ago
|
|
||
|
srslte_timestamp_t tstamp;
|
||
|
|
||
9 years ago
|
srslte_rf_start_rx_stream(&rf);
|
||
10 years ago
|
uint32_t nframe=0;
|
||
|
|
||
10 years ago
|
|
||
10 years ago
|
while(nframe<nof_frames) {
|
||
|
printf("Rx subframe %d\n", nframe);
|
||
9 years ago
|
srslte_rf_recv_with_time(&rf, &rx_buffer[flen*nframe], flen, true, &tstamp.full_secs, &tstamp.frac_secs);
|
||
10 years ago
|
nframe++;
|
||
9 years ago
|
if (nframe==9) {
|
||
|
srslte_timestamp_add(&tstamp, 0, 2e-3-time_adv_sec);
|
||
9 years ago
|
srslte_rf_send_timed2(&rf, tx_buffer, flen+time_adv_samples, tstamp.full_secs, tstamp.frac_secs, true, true);
|
||
9 years ago
|
printf("Transmitting Signal\n");
|
||
10 years ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
srslte_vec_save_file(output_filename, &rx_buffer[10*flen], flen*sizeof(cf_t));
|
||
|
|
||
|
free(tx_buffer);
|
||
|
free(rx_buffer);
|
||
|
|
||
|
printf("Done\n");
|
||
|
exit(0);
|
||
|
}
|