2010-08-19 20:33:31 +00:00
|
|
|
//
|
2014-01-24 15:17:42 +00:00
|
|
|
// Copyright 2010-2012,2014 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2010-08-19 20:33:31 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2010-08-19 20:33:31 +00:00
|
|
|
//
|
|
|
|
|
|
2014-10-27 15:17:15 +00:00
|
|
|
#include "wavetable.hpp"
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <uhd/exception.hpp>
|
|
|
|
|
#include <uhd/usrp/multi_usrp.hpp>
|
2010-08-19 20:33:31 +00:00
|
|
|
#include <uhd/utils/safe_main.hpp>
|
2010-08-31 19:17:48 +00:00
|
|
|
#include <uhd/utils/static.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <uhd/utils/thread.hpp>
|
2016-03-15 22:09:06 +00:00
|
|
|
#include <stdint.h>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
#include <chrono>
|
2021-06-18 22:06:52 +00:00
|
|
|
#include <cmath>
|
2011-03-11 20:17:46 +00:00
|
|
|
#include <csignal>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <iostream>
|
2017-06-28 02:06:50 +00:00
|
|
|
#include <string>
|
2018-04-26 16:30:48 +00:00
|
|
|
#include <thread>
|
2010-08-19 20:33:31 +00:00
|
|
|
|
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
2011-06-07 17:05:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Signal handlers
|
|
|
|
|
**********************************************************************/
|
2011-03-11 20:17:46 +00:00
|
|
|
static bool stop_signal_called = false;
|
2019-01-14 18:35:25 +00:00
|
|
|
void sig_int_handler(int)
|
|
|
|
|
{
|
|
|
|
|
stop_signal_called = true;
|
|
|
|
|
}
|
2011-03-11 20:17:46 +00:00
|
|
|
|
2011-06-07 17:05:31 +00:00
|
|
|
/***********************************************************************
|
|
|
|
|
* Main function
|
|
|
|
|
**********************************************************************/
|
2019-01-14 18:35:25 +00:00
|
|
|
int UHD_SAFE_MAIN(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
// variables to be set by po
|
2015-08-21 23:36:03 +00:00
|
|
|
std::string args, wave_type, ant, subdev, ref, pps, otw, channel_list;
|
2018-02-19 22:16:24 +00:00
|
|
|
uint64_t total_num_samps;
|
|
|
|
|
size_t spb;
|
2020-04-06 18:56:15 +00:00
|
|
|
double rate, freq, gain, power, wave_freq, bw, lo_offset;
|
2011-01-12 03:46:45 +00:00
|
|
|
float ampl;
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// setup the program options
|
2010-08-19 20:33:31 +00:00
|
|
|
po::options_description desc("Allowed options");
|
2019-01-10 23:19:48 +00:00
|
|
|
// clang-format off
|
2010-08-19 20:33:31 +00:00
|
|
|
desc.add_options()
|
|
|
|
|
("help", "help message")
|
2010-09-20 23:59:44 +00:00
|
|
|
("args", po::value<std::string>(&args)->default_value(""), "single uhd device address args")
|
2018-02-19 22:16:24 +00:00
|
|
|
("spb", po::value<size_t>(&spb)->default_value(0), "samples per buffer, 0 for default")
|
2016-03-15 22:09:06 +00:00
|
|
|
("nsamps", po::value<uint64_t>(&total_num_samps)->default_value(0), "total number of samples to transmit")
|
2011-03-11 20:17:46 +00:00
|
|
|
("rate", po::value<double>(&rate), "rate of outgoing samples")
|
|
|
|
|
("freq", po::value<double>(&freq), "RF center frequency in Hz")
|
2019-01-09 19:35:52 +00:00
|
|
|
("lo-offset", po::value<double>(&lo_offset)->default_value(0.0),
|
|
|
|
|
"Offset for frontend LO in Hz (optional)")
|
2011-10-11 00:48:46 +00:00
|
|
|
("ampl", po::value<float>(&l)->default_value(float(0.3)), "amplitude of the waveform [0 to 0.7]")
|
2011-03-11 20:17:46 +00:00
|
|
|
("gain", po::value<double>(&gain), "gain for the RF chain")
|
2020-04-06 18:56:15 +00:00
|
|
|
("power", po::value<double>(&power), "Transmit power (if USRP supports it)")
|
2014-12-12 10:37:53 +00:00
|
|
|
("ant", po::value<std::string>(&ant), "antenna selection")
|
|
|
|
|
("subdev", po::value<std::string>(&subdev), "subdevice specification")
|
|
|
|
|
("bw", po::value<double>(&bw), "analog frontend filter bandwidth in Hz")
|
2010-08-31 19:17:48 +00:00
|
|
|
("wave-type", po::value<std::string>(&wave_type)->default_value("CONST"), "waveform type (CONST, SQUARE, RAMP, SINE)")
|
2010-08-19 20:33:31 +00:00
|
|
|
("wave-freq", po::value<double>(&wave_freq)->default_value(0), "waveform frequency in Hz")
|
examples: Remove default --ref and --pps values
This changes the behaviour of the examples in a way that leaving
out the --ref argument will not force it to be 'internal'. Previously,
the following command:
rx_samples_to_file --args type=xxx,clock_source=external
would still use the internal reference, because the default value for
--ref was internal, and no other value for --ref was provided. Even
worse, the following command:
rx_samples_to_file --args \
type=xxx,clock_source=external,time_source=external
might throw errors/warnings, because internal clock source plus external
time source is generally not supported, and the example would force the
clock source to be internal unless `--ref internal` was also provided.
For all cases that `clock_source` or `time_source` were not given as
a device argument, this is a no-op because `internal` is the default
value anyway.
In two examples, this includes minor code changes:
- In rfnoc_radio_loopback, if both --ref and --pps were given, we now
use set_sync_source() to speed up setting the reference sources. On
the N310/N300 series in particular, this saves a few seconds at
initialization over the previous implementation (which set clock and
time reference separately).
- In test_dboard_coercion, the code would fail without a default value
for --ref, so we no longer require such a default value.
2023-05-17 08:12:12 +00:00
|
|
|
("ref", po::value<std::string>(&ref), "clock reference (internal, external, mimo, gpsdo)")
|
2015-08-21 23:36:03 +00:00
|
|
|
("pps", po::value<std::string>(&pps), "PPS source (internal, external, mimo, gpsdo)")
|
2012-02-12 22:38:35 +00:00
|
|
|
("otw", po::value<std::string>(&otw)->default_value("sc16"), "specify the over-the-wire sample mode")
|
2013-08-26 20:51:30 +00:00
|
|
|
("channels", po::value<std::string>(&channel_list)->default_value("0"), "which channels to use (specify \"0\", \"1\", \"0,1\", etc)")
|
2014-01-24 15:17:42 +00:00
|
|
|
("int-n", "tune USRP with integer-N tuning")
|
2010-08-19 20:33:31 +00:00
|
|
|
;
|
2019-01-10 23:19:48 +00:00
|
|
|
// clang-format on
|
2010-08-19 20:33:31 +00:00
|
|
|
po::variables_map vm;
|
|
|
|
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
|
|
|
|
po::notify(vm);
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// print the help message
|
|
|
|
|
if (vm.count("help")) {
|
2010-08-19 20:33:31 +00:00
|
|
|
std::cout << boost::format("UHD TX Waveforms %s") % desc << std::endl;
|
|
|
|
|
return ~0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// create a usrp device
|
2010-08-19 20:33:31 +00:00
|
|
|
std::cout << std::endl;
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << boost::format("Creating the usrp device with: %s...") % args
|
|
|
|
|
<< std::endl;
|
2011-02-01 02:01:27 +00:00
|
|
|
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);
|
2011-03-11 20:17:46 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// always select the subdevice first, the channel mapping affects the other settings
|
|
|
|
|
if (vm.count("subdev"))
|
|
|
|
|
usrp->set_tx_subdev_spec(subdev);
|
2018-06-11 19:48:13 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// detect which channels to use
|
2013-08-26 20:51:30 +00:00
|
|
|
std::vector<std::string> channel_strings;
|
|
|
|
|
std::vector<size_t> channel_nums;
|
|
|
|
|
boost::split(channel_strings, channel_list, boost::is_any_of("\"',"));
|
2019-01-14 18:35:25 +00:00
|
|
|
for (size_t ch = 0; ch < channel_strings.size(); ch++) {
|
2017-06-28 02:06:50 +00:00
|
|
|
size_t chan = std::stoi(channel_strings[ch]);
|
2019-01-14 18:35:25 +00:00
|
|
|
if (chan >= usrp->get_tx_num_channels())
|
2013-08-26 20:51:30 +00:00
|
|
|
throw std::runtime_error("Invalid channel(s) specified.");
|
2014-04-25 11:29:00 +00:00
|
|
|
else
|
2017-06-28 02:06:50 +00:00
|
|
|
channel_nums.push_back(std::stoi(channel_strings[ch]));
|
2013-08-26 20:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// Lock mboard clocks
|
2019-11-22 23:53:02 +00:00
|
|
|
if (vm.count("ref")) {
|
|
|
|
|
usrp->set_clock_source(ref);
|
|
|
|
|
}
|
2011-09-16 17:47:54 +00:00
|
|
|
|
2011-02-01 02:01:27 +00:00
|
|
|
std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// set the sample rate
|
|
|
|
|
if (not vm.count("rate")) {
|
2011-03-11 20:17:46 +00:00
|
|
|
std::cerr << "Please specify the sample rate with --rate" << std::endl;
|
|
|
|
|
return ~0;
|
|
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << boost::format("Setting TX Rate: %f Msps...") % (rate / 1e6) << std::endl;
|
2023-10-03 20:46:43 +00:00
|
|
|
for (std::size_t channel : channel_nums) {
|
|
|
|
|
usrp->set_tx_rate(rate, channel);
|
|
|
|
|
std::cout << boost::format("Actual TX Rate: %f Msps...")
|
|
|
|
|
% (usrp->get_tx_rate(channel) / 1e6)
|
|
|
|
|
<< std::endl
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// set the center frequency
|
|
|
|
|
if (not vm.count("freq")) {
|
2011-03-11 20:17:46 +00:00
|
|
|
std::cerr << "Please specify the center frequency with --freq" << std::endl;
|
|
|
|
|
return ~0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 18:56:15 +00:00
|
|
|
// for the const wave, set the wave freq for small samples per period
|
|
|
|
|
if (wave_freq == 0) {
|
|
|
|
|
if (wave_type == "CONST") {
|
2023-10-03 20:46:43 +00:00
|
|
|
wave_freq = usrp->get_tx_rate(channel_nums.front()) / 2;
|
2020-04-06 18:56:15 +00:00
|
|
|
} else {
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"wave freq cannot be 0 with wave type other than CONST");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pre-compute the waveform values
|
|
|
|
|
const wave_table_class wave_table(wave_type, ampl);
|
2023-10-03 20:46:43 +00:00
|
|
|
const size_t step =
|
|
|
|
|
std::lround(wave_freq / usrp->get_tx_rate(channel_nums.front()) * wave_table_len);
|
|
|
|
|
size_t index = 0;
|
2020-04-06 18:56:15 +00:00
|
|
|
|
2024-05-21 15:22:21 +00:00
|
|
|
// Defer setting the frequency and LO offset until synchronization setup is complete,
|
|
|
|
|
// configuring here only gains, bandwidth, and antenna
|
2023-10-03 20:46:43 +00:00
|
|
|
for (std::size_t channel : channel_nums) {
|
2019-01-14 18:35:25 +00:00
|
|
|
// set the rf gain
|
2020-04-06 18:56:15 +00:00
|
|
|
if (vm.count("power")) {
|
2023-10-03 20:46:43 +00:00
|
|
|
if (!usrp->has_tx_power_reference(channel)) {
|
2020-04-06 18:56:15 +00:00
|
|
|
std::cout << "ERROR: USRP does not have a reference power API on channel "
|
2023-10-03 20:46:43 +00:00
|
|
|
<< channel << "!" << std::endl;
|
2020-04-06 18:56:15 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "Setting TX output power: " << power << " dBm..." << std::endl;
|
2023-10-03 20:46:43 +00:00
|
|
|
usrp->set_tx_power_reference(power - wave_table.get_power(), channel);
|
2020-04-06 18:56:15 +00:00
|
|
|
std::cout << "Actual TX output power: "
|
2023-10-03 20:46:43 +00:00
|
|
|
<< usrp->get_tx_power_reference(channel) + wave_table.get_power()
|
2020-04-06 18:56:15 +00:00
|
|
|
<< " dBm..." << std::endl;
|
|
|
|
|
if (vm.count("gain")) {
|
|
|
|
|
std::cout << "WARNING: If you specify both --power and --gain, "
|
|
|
|
|
" the latter will be ignored."
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
} else if (vm.count("gain")) {
|
2011-05-26 03:00:12 +00:00
|
|
|
std::cout << boost::format("Setting TX Gain: %f dB...") % gain << std::endl;
|
2023-10-03 20:46:43 +00:00
|
|
|
usrp->set_tx_gain(gain, channel);
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << boost::format("Actual TX Gain: %f dB...")
|
2023-10-03 20:46:43 +00:00
|
|
|
% usrp->get_tx_gain(channel)
|
2019-01-14 18:35:25 +00:00
|
|
|
<< std::endl
|
|
|
|
|
<< std::endl;
|
2011-05-26 03:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// set the analog frontend filter bandwidth
|
|
|
|
|
if (vm.count("bw")) {
|
|
|
|
|
std::cout << boost::format("Setting TX Bandwidth: %f MHz...") % bw
|
|
|
|
|
<< std::endl;
|
2023-10-03 20:46:43 +00:00
|
|
|
usrp->set_tx_bandwidth(bw, channel);
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << boost::format("Actual TX Bandwidth: %f MHz...")
|
2023-10-03 20:46:43 +00:00
|
|
|
% usrp->get_tx_bandwidth(channel)
|
2019-01-14 18:35:25 +00:00
|
|
|
<< std::endl
|
|
|
|
|
<< std::endl;
|
2011-05-26 03:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// set the antenna
|
|
|
|
|
if (vm.count("ant"))
|
2023-10-03 20:46:43 +00:00
|
|
|
usrp->set_tx_antenna(ant, channel);
|
2011-03-11 20:17:46 +00:00
|
|
|
}
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// error when the waveform is not possible to generate
|
|
|
|
|
if (std::abs(wave_freq) > usrp->get_tx_rate() / 2) {
|
2010-08-19 20:33:31 +00:00
|
|
|
throw std::runtime_error("wave freq out of Nyquist zone");
|
|
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
if (usrp->get_tx_rate() / std::abs(wave_freq) > wave_table_len / 2) {
|
2011-06-07 17:05:31 +00:00
|
|
|
throw std::runtime_error("wave freq too small for table");
|
2010-08-31 19:17:48 +00:00
|
|
|
}
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// create a transmit streamer
|
|
|
|
|
// linearly map channels (index0 = channel0, index1 = channel1, ...)
|
2012-02-12 22:38:35 +00:00
|
|
|
uhd::stream_args_t stream_args("fc32", otw);
|
2019-01-14 18:35:25 +00:00
|
|
|
stream_args.channels = channel_nums;
|
2011-10-06 16:25:54 +00:00
|
|
|
uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
|
2011-10-05 18:59:27 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// allocate a buffer which we re-use for each channel
|
2018-02-19 22:16:24 +00:00
|
|
|
if (spb == 0) {
|
2019-01-14 18:35:25 +00:00
|
|
|
spb = tx_stream->get_max_num_samps() * 10;
|
2018-02-19 22:16:24 +00:00
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
std::vector<std::complex<float>> buff(spb);
|
|
|
|
|
std::vector<std::complex<float>*> buffs(channel_nums.size(), &buff.front());
|
2011-05-26 03:00:12 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// pre-fill the buffer with the waveform
|
|
|
|
|
for (size_t n = 0; n < buff.size(); n++) {
|
2018-12-21 18:54:05 +00:00
|
|
|
buff[n] = wave_table(index += step);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 17:05:31 +00:00
|
|
|
std::cout << boost::format("Setting device timestamp to 0...") << std::endl;
|
2019-01-14 18:35:25 +00:00
|
|
|
if (channel_nums.size() > 1) {
|
2015-08-21 23:36:03 +00:00
|
|
|
// Sync times
|
2019-01-14 18:35:25 +00:00
|
|
|
if (pps == "mimo") {
|
2015-08-21 23:36:03 +00:00
|
|
|
UHD_ASSERT_THROW(usrp->get_num_mboards() == 2);
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// make mboard 1 a slave over the MIMO Cable
|
2015-08-21 23:36:03 +00:00
|
|
|
usrp->set_time_source("mimo", 1);
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// set time on the master (mboard 0)
|
2015-08-21 23:36:03 +00:00
|
|
|
usrp->set_time_now(uhd::time_spec_t(0.0), 0);
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// sleep a bit while the slave locks its time to the master
|
2018-04-26 16:30:48 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
2019-01-14 18:35:25 +00:00
|
|
|
} else {
|
2015-08-21 23:36:03 +00:00
|
|
|
if (pps == "internal" or pps == "external" or pps == "gpsdo")
|
|
|
|
|
usrp->set_time_source(pps);
|
|
|
|
|
usrp->set_time_unknown_pps(uhd::time_spec_t(0.0));
|
2019-01-14 18:35:25 +00:00
|
|
|
std::this_thread::sleep_for(
|
|
|
|
|
std::chrono::seconds(1)); // wait for pps sync pulse
|
2015-08-21 23:36:03 +00:00
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
} else {
|
2015-08-21 23:36:03 +00:00
|
|
|
usrp->set_time_now(0.0);
|
2015-07-13 23:53:35 +00:00
|
|
|
}
|
2011-06-07 17:05:31 +00:00
|
|
|
|
2024-06-05 10:27:39 +00:00
|
|
|
// Now, that clock sync setup is complete do timed tuning of LOs and NCOs
|
|
|
|
|
std::cout << boost::format("Setting TX Freq: %f MHz...") % (freq / 1e6) << std::endl;
|
|
|
|
|
std::cout << boost::format("Setting TX LO Offset: %f MHz...") % (lo_offset / 1e6)
|
|
|
|
|
<< std::endl;
|
2024-06-25 09:43:14 +00:00
|
|
|
|
|
|
|
|
// use timed tuning for more that one channel on all devices except X410
|
|
|
|
|
// X410 does not yet support timed tuning
|
|
|
|
|
const bool timed_tuning = usrp->get_mboard_name() != "x410"
|
|
|
|
|
and channel_nums.size() > 1;
|
|
|
|
|
const float cmd_time_offset = 0.1;
|
|
|
|
|
|
|
|
|
|
if (timed_tuning) {
|
|
|
|
|
const uhd::time_spec_t now = usrp->get_time_now();
|
|
|
|
|
const uhd::time_spec_t cmd_time = now + uhd::time_spec_t(cmd_time_offset);
|
|
|
|
|
usrp->set_command_time(cmd_time);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 10:27:39 +00:00
|
|
|
for (std::size_t channel : channel_nums) {
|
|
|
|
|
uhd::tune_request_t tune_request(freq, lo_offset);
|
|
|
|
|
if (vm.count("int-n"))
|
|
|
|
|
tune_request.args = uhd::device_addr_t("mode_n=integer");
|
|
|
|
|
usrp->set_tx_freq(tune_request, channel);
|
|
|
|
|
}
|
2024-06-25 09:43:14 +00:00
|
|
|
|
|
|
|
|
// clear command time and wait to finish for timed tuning
|
|
|
|
|
if (timed_tuning) {
|
|
|
|
|
usrp->clear_command_time();
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(int64_t(
|
|
|
|
|
1e3 * cmd_time_offset))); // wait until the command time has passed for sure
|
|
|
|
|
}
|
2024-06-05 10:27:39 +00:00
|
|
|
|
|
|
|
|
for (std::size_t channel : channel_nums) {
|
|
|
|
|
std::cout << boost::format("Actual TX Freq: %f MHz...")
|
|
|
|
|
% (usrp->get_tx_freq(channel) / 1e6)
|
|
|
|
|
<< std::endl
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-28 09:53:54 +00:00
|
|
|
// Allow for some setup time: In particular, LOs and other tuning-related
|
|
|
|
|
// components might need some time to lock. 1 second is way more than enough
|
|
|
|
|
// time. If there were no sleep time at all, we might see LO lock errors
|
|
|
|
|
// as the following check does not include a polling loop.
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// Check Ref and LO Lock detect
|
2011-09-16 17:47:54 +00:00
|
|
|
std::vector<std::string> sensor_names;
|
2017-06-28 02:06:50 +00:00
|
|
|
const size_t tx_sensor_chan = channel_nums.empty() ? 0 : channel_nums[0];
|
2019-01-14 18:35:25 +00:00
|
|
|
sensor_names = usrp->get_tx_sensor_names(tx_sensor_chan);
|
|
|
|
|
if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked")
|
|
|
|
|
!= sensor_names.end()) {
|
2016-08-11 16:59:24 +00:00
|
|
|
uhd::sensor_value_t lo_locked = usrp->get_tx_sensor("lo_locked", tx_sensor_chan);
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << boost::format("Checking TX: %s ...") % lo_locked.to_pp_string()
|
|
|
|
|
<< std::endl;
|
2011-09-16 17:47:54 +00:00
|
|
|
UHD_ASSERT_THROW(lo_locked.to_bool());
|
|
|
|
|
}
|
2016-08-11 16:59:24 +00:00
|
|
|
const size_t mboard_sensor_idx = 0;
|
2019-01-14 18:35:25 +00:00
|
|
|
sensor_names = usrp->get_mboard_sensor_names(mboard_sensor_idx);
|
|
|
|
|
if ((ref == "mimo")
|
|
|
|
|
and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked")
|
2022-11-17 14:32:49 +00:00
|
|
|
!= sensor_names.end())) {
|
2019-01-14 18:35:25 +00:00
|
|
|
uhd::sensor_value_t mimo_locked =
|
|
|
|
|
usrp->get_mboard_sensor("mimo_locked", mboard_sensor_idx);
|
|
|
|
|
std::cout << boost::format("Checking TX: %s ...") % mimo_locked.to_pp_string()
|
|
|
|
|
<< std::endl;
|
2011-09-16 17:47:54 +00:00
|
|
|
UHD_ASSERT_THROW(mimo_locked.to_bool());
|
|
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
if ((ref == "external")
|
|
|
|
|
and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked")
|
2022-11-17 14:32:49 +00:00
|
|
|
!= sensor_names.end())) {
|
2019-01-14 18:35:25 +00:00
|
|
|
uhd::sensor_value_t ref_locked =
|
|
|
|
|
usrp->get_mboard_sensor("ref_locked", mboard_sensor_idx);
|
|
|
|
|
std::cout << boost::format("Checking TX: %s ...") % ref_locked.to_pp_string()
|
|
|
|
|
<< std::endl;
|
2011-09-16 17:47:54 +00:00
|
|
|
UHD_ASSERT_THROW(ref_locked.to_bool());
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 20:17:46 +00:00
|
|
|
std::signal(SIGINT, &sig_int_handler);
|
|
|
|
|
std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
|
|
|
|
|
|
2015-07-13 23:53:35 +00:00
|
|
|
// Set up metadata. We start streaming a bit in the future
|
|
|
|
|
// to allow MIMO operation:
|
|
|
|
|
uhd::tx_metadata_t md;
|
|
|
|
|
md.start_of_burst = true;
|
|
|
|
|
md.end_of_burst = false;
|
|
|
|
|
md.has_time_spec = true;
|
2019-01-14 18:35:25 +00:00
|
|
|
md.time_spec = usrp->get_time_now() + uhd::time_spec_t(0.1);
|
2015-07-13 23:53:35 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// send data until the signal handler gets called
|
|
|
|
|
// or if we accumulate the number of samples specified (unless it's 0)
|
2016-03-15 22:09:06 +00:00
|
|
|
uint64_t num_acc_samps = 0;
|
2019-01-14 18:35:25 +00:00
|
|
|
while (true) {
|
2018-12-21 18:27:42 +00:00
|
|
|
// Break on the end of duration or CTRL-C
|
|
|
|
|
if (stop_signal_called) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Break when we've received nsamps
|
|
|
|
|
if (total_num_samps > 0 and num_acc_samps >= total_num_samps) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-03-15 22:09:06 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// send the entire contents of the buffer
|
|
|
|
|
num_acc_samps += tx_stream->send(buffs, buff.size(), md);
|
2011-05-26 03:00:12 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// fill the buffer with the waveform
|
|
|
|
|
for (size_t n = 0; n < buff.size(); n++) {
|
2018-12-21 18:54:05 +00:00
|
|
|
buff[n] = wave_table(index += step);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 17:05:31 +00:00
|
|
|
md.start_of_burst = false;
|
2019-01-14 18:35:25 +00:00
|
|
|
md.has_time_spec = false;
|
2010-08-20 22:35:25 +00:00
|
|
|
}
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// send a mini EOB packet
|
2011-06-07 17:05:31 +00:00
|
|
|
md.end_of_burst = true;
|
2011-10-05 18:59:27 +00:00
|
|
|
tx_stream->send("", 0, md);
|
2010-08-19 20:33:31 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// finished
|
2010-08-19 20:33:31 +00:00
|
|
|
std::cout << std::endl << "Done!" << std::endl << std::endl;
|
2012-10-18 22:33:07 +00:00
|
|
|
return EXIT_SUCCESS;
|
2024-06-25 09:43:14 +00:00
|
|
|
}
|