diff --git a/srslte/examples/usrp_txrx.c b/srslte/examples/usrp_txrx.c index 298aa30ee..33c21be9f 100644 --- a/srslte/examples/usrp_txrx.c +++ b/srslte/examples/usrp_txrx.c @@ -40,23 +40,26 @@ uint32_t nof_prb = 25; uint32_t nof_frames = 20; +float tone_offset_hz = 0; float uhd_rx_gain=40, uhd_tx_gain=40, uhd_freq=2.4e9; char *uhd_args=""; char *output_filename = NULL; char *input_filename = NULL; void usage(char *prog) { - printf("Usage: %s -i [tx_signal_file] -o [rx_signal_file]\n", prog); + printf("Usage: %s -o [rx_signal_file]\n", prog); printf("\t-a UHD args [Default %s]\n", uhd_args); printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6); printf("\t-g UHD RX gain [Default %.1f dB]\n", uhd_rx_gain); printf("\t-G UHD TX gain [Default %.1f dB]\n", uhd_tx_gain); + printf("\t-t Single tone offset (Hz) [Default %f]\n", tone_offset_hz); + printf("\t-i File name to read signal from [Default single tone]\n"); printf("\t-p Number of UL RB [Default %d]\n", nof_prb); } void parse_args(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "ioafgp")) != -1) { + while ((opt = getopt(argc, argv, "ioafgpt")) != -1) { switch (opt) { case 'a': uhd_args = argv[optind]; @@ -67,6 +70,9 @@ void parse_args(int argc, char **argv) { case 'i': input_filename = argv[optind]; break; + case 't': + tone_offset_hz = atof(argv[optind]); + break; case 'f': uhd_freq = atof(argv[optind]); break; @@ -88,7 +94,7 @@ void parse_args(int argc, char **argv) { exit(-1); } } - if (!input_filename || !output_filename) { + if (!output_filename) { usage(argv[0]); exit(-1); } @@ -127,17 +133,33 @@ int main(int argc, char **argv) { exit(-1); } cuhd_set_master_clock_rate(uhd, 30.72e6); + + int srate = srslte_sampling_freq_hz(nof_prb); + if (srate < 10e6) { + cuhd_set_master_clock_rate(uhd, 4*srate); + } else { + cuhd_set_master_clock_rate(uhd, srate); + } + cuhd_set_rx_srate(uhd, (double) srate); + cuhd_set_tx_srate(uhd, (double) srate); printf("Subframe len: %d samples\n", flen); - printf("Set TX/RX rate: %.2f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000); + printf("Set TX/RX rate: %.2f MHz\n", (float) srate / 1000000); printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_rx_gain)); printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_tx_gain)); printf("Set TX/RX freq: %.2f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000); - cuhd_set_tx_srate(uhd, srslte_sampling_freq_hz(nof_prb)); + cuhd_set_tx_freq_offset(uhd, uhd_freq, 8e6); sleep(1); - srslte_vec_load_file(input_filename, &tx_buffer[nsamples_adv], flen*sizeof(cf_t)); + if (input_filename) { + srslte_vec_load_file(input_filename, &tx_buffer[nsamples_adv], flen*sizeof(cf_t)); + } else { + for (int i=0;i