rfnoc: examples: Porting examples to new RFNoC

rfnoc_nullsource_ce_rx, rfnoc_rx_to_file:

These examples are modified so they can be run with the new RFNoC API.

test_messages:

Fixes failures in the time test when it is executed immediately after an
underrun test. The DUC considers time specs on a per burst basis, so
when the underrun test leaves a burst unfinished, a time spec on the
next burst is ignored.
This commit is contained in:
Brent Stapleton 2019-06-06 14:37:44 -07:00 committed by Martin Braun
parent c256b9df65
commit 9d27486550
3 changed files with 202 additions and 205 deletions

View File

@ -1,5 +1,5 @@
//
// Copyright 2014 Ettus Research LLC
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@ -22,8 +22,9 @@
#include <uhd/device3.hpp>
#include <uhd/exception.hpp>
#include <uhd/rfnoc/block_ctrl.hpp>
#include <uhd/rfnoc/null_block_ctrl.hpp>
#include <uhd/rfnoc/block_control.hpp>
#include <uhd/rfnoc/null_block_control.hpp>
#include <uhd/rfnoc_graph.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/utils/thread.hpp>
#include <boost/format.hpp>
@ -48,7 +49,6 @@ template <typename samp_type>
void recv_to_file(uhd::rx_streamer::sptr rx_stream,
const std::string& file,
size_t samps_per_buff,
unsigned long long num_requested_samples,
double time_requested = 0.0,
bool bw_summary = false,
bool stats = false,
@ -65,10 +65,8 @@ void recv_to_file(uhd::rx_streamer::sptr rx_stream,
bool overflow_message = true;
// setup streaming
uhd::stream_cmd_t stream_cmd((num_requested_samples == 0)
? uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS
: uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
stream_cmd.num_samps = num_requested_samples;
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
stream_cmd.num_samps = 0;
stream_cmd.stream_now = true;
stream_cmd.time_spec = uhd::time_spec_t();
std::cout << "Issuing start stream cmd" << std::endl;
@ -85,7 +83,6 @@ void recv_to_file(uhd::rx_streamer::sptr rx_stream,
unsigned long long last_update_samps = 0;
while (not stop_signal_called
and (num_requested_samples != num_total_samps or num_requested_samples == 0)
and (time_requested == 0.0 or std::chrono::steady_clock::now() <= stop_time)) {
const auto now = std::chrono::steady_clock::now();
@ -207,9 +204,9 @@ void pretty_print_flow_graph(std::vector<std::string> blocks)
int UHD_SAFE_MAIN(int argc, char* argv[])
{
// variables to be set by po
std::string args, file, format, nullid, blockid, blockid2;
size_t total_num_samps, spb, spp;
double rate, total_time, setup_time, block_rate;
std::string args, file, format, nullid;
size_t spb, spp, throttle_cycles;
double rate, total_time;
// setup the program options
po::options_description desc("Allowed options");
@ -217,22 +214,18 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
desc.add_options()
("help", "help message")
("args", po::value<std::string>(&args)->default_value("type=x300"), "multi uhd device address args")
("file", po::value<std::string>(&file)->default_value("usrp_samples.dat"), "name of the file to write binary samples to, set to stdout to print")
("file", po::value<std::string>(&file)->default_value("graph_samples.dat"), "name of the file to write binary samples to, set to stdout to print")
("null", "run without writing to file")
("nsamps", po::value<size_t>(&total_num_samps)->default_value(0), "total number of samples to receive")
("time", po::value<double>(&total_time)->default_value(0), "total number of seconds to receive")
("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer")
("spp", po::value<size_t>(&spp)->default_value(64), "samples per packet (on FPGA and wire)")
("block_rate", po::value<double>(&block_rate)->default_value(160e6), "The clock rate of the processing block.")
("throttle-cycles", po::value<size_t>(&throttle_cycles)->default_value(0), "Number of cycles to force in between packets")
("rate", po::value<double>(&rate)->default_value(1e6), "rate at which samples are produced in the null source")
("setup", po::value<double>(&setup_time)->default_value(1.0), "seconds of setup time")
("format", po::value<std::string>(&format)->default_value("sc16"), "File sample type: sc16, fc32, or fc64")
("progress", "periodically display short-term bandwidth")
("stats", "show average bandwidth on exit")
("continue", "don't abort on a bad packet")
("nullid", po::value<std::string>(&nullid)->default_value("0/NullSrcSink_0"), "The block ID for the null source.")
("blockid", po::value<std::string>(&blockid)->default_value("FIFO"), "The block ID for the processing block.")
("blockid2", po::value<std::string>(&blockid2)->default_value(""), "Optional: The block ID for the 2nd processing block.")
("nullid", po::value<std::string>(&nullid)->default_value("0/NullSrcSink#0"), "The block ID for the null source.")
;
// clang-format on
po::variables_map vm;
@ -256,36 +249,16 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
std::cout << "Must specify a valid block ID for the null source." << std::endl;
return ~0;
}
if (not uhd::rfnoc::block_id_t::is_valid_block_id(blockid)) {
std::cout << "Must specify a valid block ID for the processing block."
<< std::endl;
return ~0;
}
if (not blockid2.empty()) {
if (not uhd::rfnoc::block_id_t::is_valid_block_id(blockid2)) {
std::cout << "Invalid block ID for the 2nd processing block." << std::endl;
return ~0;
}
}
// Set up SIGINT handler. For indefinite streaming, display info on how to stop.
std::signal(SIGINT, &sig_int_handler);
if (total_num_samps == 0) {
std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
}
/////////////////////////////////////////////////////////////////////////
//////// 1. Setup a USRP device /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
std::cout << std::endl;
std::cout << "Creating the USRP device with args: " << args << std::endl;
uhd::device3::sptr usrp = uhd::device3::make(args);
std::this_thread::sleep_for( // allow for some setup time
std::chrono::milliseconds(int64_t(setup_time * 1000)));
// Reset device streaming state
usrp->clear();
uhd::rfnoc::graph::sptr rx_graph = usrp->create_graph("rx_graph");
uhd::rfnoc::rfnoc_graph::sptr graph = uhd::rfnoc::rfnoc_graph::make(args);
/////////////////////////////////////////////////////////////////////////
//////// 2. Get block control objects ///////////////////////////////////
@ -293,28 +266,16 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
std::vector<std::string> blocks;
// For the null source control, we want to use the subclassed access,
// so we create a null_block_ctrl:
uhd::rfnoc::null_block_ctrl::sptr null_src_ctrl;
if (usrp->has_block<uhd::rfnoc::null_block_ctrl>(nullid)) {
null_src_ctrl = usrp->get_block_ctrl<uhd::rfnoc::null_block_ctrl>(nullid);
// so we create a null_block_control:
uhd::rfnoc::null_block_control::sptr null_src_ctrl;
if (graph->has_block<uhd::rfnoc::null_block_control>(nullid)) {
null_src_ctrl = graph->get_block<uhd::rfnoc::null_block_control>(nullid);
blocks.push_back(null_src_ctrl->get_block_id());
} else {
std::cout << "Error: Device has no null block." << std::endl;
return ~0;
}
// For the processing blocks, we don't care what type the block is,
// so we make it a block_ctrl_base (default):
uhd::rfnoc::block_ctrl_base::sptr proc_block_ctrl, proc_block_ctrl2;
if (usrp->has_block(blockid)) {
proc_block_ctrl = usrp->get_block_ctrl(blockid);
blocks.push_back(proc_block_ctrl->get_block_id());
}
if (not blockid2.empty() and usrp->has_block(blockid2)) {
proc_block_ctrl2 = usrp->get_block_ctrl(blockid2);
blocks.push_back(proc_block_ctrl2->get_block_id());
}
blocks.push_back("HOST");
pretty_print_flow_graph(blocks);
@ -322,77 +283,52 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
//////// 3. Set channel definitions /////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
uhd::device_addr_t stream_args_args;
//
// Here, we define that there is only 1 channel, and it points
// to the final processing block.
if (proc_block_ctrl2 and proc_block_ctrl) {
stream_args_args["block_id"] = blockid2;
} else if (proc_block_ctrl) {
stream_args_args["block_id"] = blockid;
} else {
stream_args_args["block_id"] = nullid;
}
stream_args_args["block_id"] = nullid;
/////////////////////////////////////////////////////////////////////////
//////// 4. Configure blocks (packet size and rate) /////////////////////
/////////////////////////////////////////////////////////////////////////
std::cout << "Samples per packet coming from null source: " << spp << std::endl;
// To access properties, there's two ways. You can access args as defined
// in the XML file:
const size_t BYTES_PER_SAMPLE = 4;
null_src_ctrl->set_arg<int>("bpp", int(spp * BYTES_PER_SAMPLE));
if (null_src_ctrl->get_arg<int>("bpp") != int(spp * BYTES_PER_SAMPLE)) {
null_src_ctrl->set_bytes_per_packet(uint32_t(spp * BYTES_PER_SAMPLE));
if (null_src_ctrl->get_bytes_per_packet() != uint32_t(spp * BYTES_PER_SAMPLE)) {
std::cout << "[ERROR] Could not set samples per packet!" << std::endl;
return ~0;
}
// Or, if our block has its own getters + setters, you can call those:
std::cout << str(boost::format("Requesting rate: %.2f Msps (%.2f MByte/s).")
% (rate / 1e6) % (rate * 4 / 1e6))
<< std::endl;
const size_t SAMPLES_PER_LINE = 2;
null_src_ctrl->set_line_rate(rate / SAMPLES_PER_LINE, block_rate);
// Now, it's possible that this requested rate is not available.
// Let's read back the true rate with the getter:
double actual_rate_mega =
null_src_ctrl->get_line_rate(block_rate) / 1e6 * SAMPLES_PER_LINE;
std::cout << str(boost::format("Actually got rate: %.2f Msps (%.2f MByte/s).")
% actual_rate_mega % (actual_rate_mega * BYTES_PER_SAMPLE))
<< std::endl;
null_src_ctrl->set_throttle_cycles(throttle_cycles);
/////////////////////////////////////////////////////////////////////////
//////// 5. Connect blocks //////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
std::cout << "Connecting blocks..." << std::endl;
if (proc_block_ctrl) {
rx_graph->connect( // Yes, it's that easy!
null_src_ctrl->get_block_id(),
proc_block_ctrl->get_block_id());
}
if (proc_block_ctrl2 and proc_block_ctrl) {
rx_graph->connect(
proc_block_ctrl->get_block_id(), proc_block_ctrl2->get_block_id());
}
/////////////////////////////////////////////////////////////////////////
//////// 6. Spawn receiver //////////////////////////////////////////////
//////// 5. Spawn receiver //////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
uhd::stream_args_t stream_args(format, "sc16");
stream_args.args = stream_args_args;
stream_args.args["spp"] = std::to_string(spp);
UHD_LOGGER_DEBUG("RFNOC") << "Using streamer args: " << stream_args.args.to_string()
<< std::endl;
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
uhd::rx_streamer::sptr rx_stream = graph->create_rx_streamer(1, stream_args);
#define recv_to_file_args() \
(rx_stream, \
file, \
spb, \
total_num_samps, \
total_time, \
bw_summary, \
stats, \
/////////////////////////////////////////////////////////////////////////
//////// 6. Connect blocks //////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
std::cout << "Connecting blocks..." << std::endl;
graph->connect( // Yes, it's that easy!
null_src_ctrl->get_block_id(),
0,
rx_stream,
0);
graph->commit();
if (total_time == 0) {
std::cout << "Press Ctrl + C to stop streaming..." << std::endl;
}
#define recv_to_file_args() \
(rx_stream, \
vm.count("null") ? "" : file, \
spb, \
total_time, \
bw_summary, \
stats, \
continue_on_bad_packet)
// recv to file
if (format == "fc64")

View File

@ -1,24 +1,16 @@
//
// Copyright 2014-2016 Ettus Research LLC
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/device3.hpp>
#include <uhd/exception.hpp>
#include <uhd/rfnoc/radio_ctrl.hpp>
#include <uhd/rfnoc/source_block_ctrl_base.hpp>
#include <uhd/rfnoc/ddc_block_control.hpp>
#include <uhd/rfnoc/defaults.hpp>
#include <uhd/rfnoc/mb_controller.hpp>
#include <uhd/rfnoc/radio_control.hpp>
#include <uhd/rfnoc_graph.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/types/tune_request.hpp>
#include <uhd/utils/safe_main.hpp>
@ -232,9 +224,9 @@ bool check_locked_sensor(std::vector<std::string> sensor_names,
int UHD_SAFE_MAIN(int argc, char* argv[])
{
// variables to be set by po
std::string args, file, format, ant, subdev, ref, wirefmt, streamargs, radio_args,
block_id, block_args;
size_t total_num_samps, spb, radio_id, radio_chan;
std::string args, file, format, ant, subdev, ref, wirefmt, streamargs, block_id,
block_args;
size_t total_num_samps, spb, spp, radio_id, radio_chan;
double rate, freq, gain, bw, total_time, setup_time;
// setup the program options
@ -247,6 +239,7 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
("duration", po::value<double>(&total_time)->default_value(0), "total number of seconds to receive")
("nsamps", po::value<size_t>(&total_num_samps)->default_value(0), "total number of samples to receive")
("spb", po::value<size_t>(&spb)->default_value(10000), "samples per buffer")
("spp", po::value<size_t>(&spp)->default_value(64), "samples per packet (on FPGA and wire)")
("streamargs", po::value<std::string>(&streamargs)->default_value(""), "stream args")
("progress", "periodically display short-term bandwidth")
("stats", "show average bandwidth on exit")
@ -259,7 +252,6 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
("radio-id", po::value<size_t>(&radio_id)->default_value(0), "Radio ID to use (0 or 1).")
("radio-chan", po::value<size_t>(&radio_chan)->default_value(0), "Radio channel")
("radio-args", po::value<std::string>(&radio_args), "Radio channel")
("rate", po::value<double>(&rate)->default_value(1e6), "RX rate of the radio block")
("freq", po::value<double>(&freq)->default_value(0.0), "RF center frequency in Hz")
("gain", po::value<double>(&gain), "gain for the RF chain")
@ -309,24 +301,57 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
* Create device and block controls
***********************************************************************/
std::cout << std::endl;
std::cout << boost::format("Creating the USRP device with: %s...") % args
std::cout << boost::format("Creating the RFNoC graph with args: %s...") % args
<< std::endl;
uhd::device3::sptr usrp = uhd::device3::make(args);
uhd::rfnoc::rfnoc_graph::sptr graph = uhd::rfnoc::rfnoc_graph::make(args);
// Create handle for radio object
uhd::rfnoc::block_id_t radio_ctrl_id(0, "Radio", radio_id);
// This next line will fail if the radio is not actually available
uhd::rfnoc::radio_ctrl::sptr radio_ctrl =
usrp->get_block_ctrl<uhd::rfnoc::radio_ctrl>(radio_ctrl_id);
uhd::rfnoc::radio_control::sptr radio_ctrl =
graph->get_block<uhd::rfnoc::radio_control>(radio_ctrl_id);
std::cout << "Using radio " << radio_id << ", channel " << radio_chan << std::endl;
// Enumerate blocks in the chain
auto edges = graph->enumerate_static_connections();
std::string source_block = radio_ctrl->get_block_id();
size_t source_port = radio_chan;
auto chain = std::vector<uhd::rfnoc::graph_edge_t>();
uhd::rfnoc::ddc_block_control::sptr ddc_ctrl;
size_t ddc_chan = 0;
while (true) {
std::cout << "Looking for source block " << source_block << ", port "
<< source_port << std::endl;
bool src_found = false;
for (auto& edge : edges) {
if (edge.src_blockid == source_block && edge.src_port == source_port) {
auto blockid = uhd::rfnoc::block_id_t(source_block);
if (blockid.match("DDC")) {
ddc_ctrl = graph->get_block<uhd::rfnoc::ddc_block_control>(blockid);
ddc_chan = edge.src_port;
}
src_found = true;
chain.push_back(edge);
source_block = edge.dst_blockid;
source_port = edge.dst_port;
}
}
if (not src_found) {
std::cerr << "ERROR: Failed to find target source block" << std::endl;
break;
}
if (uhd::rfnoc::block_id_t(source_block).match(uhd::rfnoc::NODE_ID_SEP)) {
break;
}
}
/************************************************************************
* Set up radio
***********************************************************************/
radio_ctrl->set_args(radio_args);
// Lock mboard clocks
if (vm.count("ref")) {
radio_ctrl->set_clock_source(ref);
graph->get_mb_controller(0)->set_clock_source(ref);
}
// set the sample rate
@ -335,10 +360,19 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
return EXIT_FAILURE;
}
std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl;
radio_ctrl->set_rate(rate);
std::cout << boost::format("Actual RX Rate: %f Msps...")
% (radio_ctrl->get_rate() / 1e6)
<< std::endl
double radio_rate = radio_ctrl->get_rate();
if (ddc_ctrl) {
std::cout << "DDC block found" << std::endl;
int decim = (int)(radio_rate / rate);
std::cout << boost::format("Setting decimation value to %d") % decim << std::endl;
ddc_ctrl->set_property<int>("decim", decim, ddc_chan);
decim = ddc_ctrl->get_property<int>("decim", ddc_chan);
std::cout << boost::format("Actual decimation value is %d") % decim << std::endl;
rate = radio_rate / decim;
} else {
rate = radio_ctrl->set_rate(rate);
}
std::cout << boost::format("Actual RX Rate: %f Msps...") % (rate / 1e6) << std::endl
<< std::endl;
// set the center frequency
@ -392,53 +426,68 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
// setup_time);
}
size_t spp = radio_ctrl->get_arg<int>("spp");
std::cout << "Setting samples per packet to: " << spp << std::endl;
radio_ctrl->set_property<int>("spp", spp, 0);
spp = radio_ctrl->get_property<int>("spp", 0);
std::cout << "Actual samples per packet = " << spp << std::endl;
/************************************************************************
* Set up streaming
***********************************************************************/
uhd::device_addr_t streamer_args(streamargs);
uhd::rfnoc::graph::sptr rx_graph = usrp->create_graph("rfnoc_rx_to_file");
usrp->clear();
// Set the stream args on the radio:
if (block_id.empty()) {
// If no extra block is required, connect to the radio:
streamer_args["block_id"] = radio_ctrl_id.to_string();
streamer_args["block_port"] = str(boost::format("%d") % radio_chan);
} else {
// Otherwise, see if the requested block exists and connect it to the radio:
if (not usrp->has_block(block_id)) {
std::cout << "Block does not exist on current device: " << block_id
<< std::endl;
return EXIT_FAILURE;
}
uhd::rfnoc::source_block_ctrl_base::sptr blk_ctrl =
usrp->get_block_ctrl<uhd::rfnoc::source_block_ctrl_base>(block_id);
if (not block_args.empty()) {
// Set the block args on the other block:
blk_ctrl->set_args(uhd::device_addr_t(block_args));
}
// Connect:
std::cout << "Connecting " << radio_ctrl_id << " ==> " << blk_ctrl->get_block_id()
<< std::endl;
rx_graph->connect(
radio_ctrl_id, radio_chan, blk_ctrl->get_block_id(), uhd::rfnoc::ANY_PORT);
streamer_args["block_id"] = blk_ctrl->get_block_id().to_string();
spp = blk_ctrl->get_args().cast<size_t>("spp", spp);
}
// create a receive streamer
std::cout << "Samples per packet: " << spp << std::endl;
// std::cout << "Samples per packet: " << spp << std::endl;
uhd::stream_args_t stream_args(
format, "sc16"); // We should read the wire format from the blocks
stream_args.args = streamer_args;
stream_args.args["spp"] = boost::lexical_cast<std::string>(spp);
stream_args.args = streamer_args;
// TODO?
// stream_args.args["spp"] = boost::lexical_cast<std::string>(spp);
std::cout << "Using streamer args: " << stream_args.args.to_string() << std::endl;
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
uhd::rx_streamer::sptr rx_stream = graph->create_rx_streamer(1, stream_args);
// Set the stream args on the radio:
// if (block_id.empty()) {
// // If no extra block is required, connect to the radio:
// streamer_args["block_id"] = radio_ctrl_id.to_string();
// streamer_args["block_port"] = str(boost::format("%d") % radio_chan);
//} else {
// // Otherwise, see if the requested block exists and connect it to the radio:
// if (not usrp->has_block(block_id)) {
// std::cout << "Block does not exist on current device: " << block_id
// << std::endl;
// return EXIT_FAILURE;
// }
// uhd::rfnoc::source_block_ctrl_base::sptr blk_ctrl =
// usrp->get_block_ctrl<uhd::rfnoc::source_block_ctrl_base>(block_id);
// if (not block_args.empty()) {
// // Set the block args on the other block:
// blk_ctrl->set_args(uhd::device_addr_t(block_args));
// }
// // Connect:
// std::cout << "Connecting " << radio_ctrl_id << " ==> " <<
// blk_ctrl->get_block_id()
// << std::endl;
// rx_graph->connect(
// radio_ctrl_id, radio_chan, blk_ctrl->get_block_id(), uhd::rfnoc::ANY_PORT);
// streamer_args["block_id"] = blk_ctrl->get_block_id().to_string();
// spp = blk_ctrl->get_args().cast<size_t>("spp", spp);
//}
// Connect blocks and commit the graph
for (auto& edge : chain) {
if (uhd::rfnoc::block_id_t(edge.dst_blockid).match(uhd::rfnoc::NODE_ID_SEP)) {
graph->connect(edge.src_blockid, edge.src_port, rx_stream, 0);
} else {
graph->connect(
edge.src_blockid, edge.src_port, edge.dst_blockid, edge.dst_port);
}
}
graph->commit();
if (total_num_samps == 0) {
std::signal(SIGINT, &sig_int_handler);

View File

@ -1,6 +1,7 @@
//
// Copyright 2010-2013 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
@ -48,14 +49,14 @@ bool test_late_command_message(uhd::usrp::multi_usrp::sptr usrp,
switch (md.error_code) {
case uhd::rx_metadata_t::ERROR_CODE_LATE_COMMAND:
std::cout << boost::format("success:\n"
" Got error code late command message.\n")
std::cout << "success:\n"
<< " Got error code late command message.\n"
<< std::endl;
return true;
case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT:
std::cout << boost::format("failed:\n"
" Inline message recv timed out.\n")
std::cout << "failed:\n"
<< " Inline message recv timed out.\n"
<< std::endl;
return false;
@ -141,16 +142,16 @@ bool test_burst_ack_message(
uhd::async_metadata_t async_md;
if (not tx_stream->recv_async_msg(async_md)) {
std::cout << boost::format("failed:\n"
" Async message recv timed out.\n")
std::cout << "failed:\n"
<< " Async message recv timed out.\n"
<< std::endl;
return false;
}
switch (async_md.event_code) {
case uhd::async_metadata_t::EVENT_CODE_BURST_ACK:
std::cout << boost::format("success:\n"
" Got event code burst ack message.\n")
std::cout << "success:\n"
<< " Got event code burst ack message.\n"
<< std::endl;
return true;
@ -182,27 +183,35 @@ bool test_underflow_message(
tx_stream->send(&buff.front(), buff.size(), md);
uhd::async_metadata_t async_md;
bool result = false;
if (not tx_stream->recv_async_msg(async_md, 1)) {
std::cout << boost::format("failed:\n"
" Async message recv timed out.\n")
<< std::endl;
return false;
} else {
switch (async_md.event_code) {
case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW:
std::cout << boost::format("success:\n"
" Got event code underflow message.\n")
<< std::endl;
result = true;
break;
default:
std::cout << boost::format("failed:\n"
" Got unexpected event code 0x%x.\n")
% async_md.event_code
<< std::endl;
break;
}
}
switch (async_md.event_code) {
case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW:
std::cout << boost::format("success:\n"
" Got event code underflow message.\n")
<< std::endl;
return true;
default:
std::cout << boost::format("failed:\n"
" Got unexpected event code 0x%x.\n")
% async_md.event_code
<< std::endl;
return false;
}
// Finish the burst to avoid affecting other tests. The DUC only considers
// time specs from the beginning of a burst, if other tests need a time
// spec they would be affected by an unfinished burst.
md.end_of_burst = true;
tx_stream->send(&buff.front(), buff.size(), md);
return result;
}
/*!
@ -314,12 +323,15 @@ int UHD_SAFE_MAIN(int argc, char* argv[])
//------------------------------------------------------------------
// begin messages test
//------------------------------------------------------------------
static uhd::dict<std::string,
boost::function<bool(
uhd::usrp::multi_usrp::sptr, uhd::rx_streamer::sptr, uhd::tx_streamer::sptr)>>
tests = boost::assign::map_list_of("Test Burst ACK ", &test_burst_ack_message)(
"Test Underflow ", &test_underflow_message)("Test Time Error",
&test_time_error_message)("Test Late Command", &test_late_command_message);
using test_executor_fn = std::function<bool(
uhd::usrp::multi_usrp::sptr, uhd::rx_streamer::sptr, uhd::tx_streamer::sptr)>;
// clang-format off
uhd::dict<std::string, test_executor_fn> tests = boost::assign::map_list_of
("Test Burst ACK ", &test_burst_ack_message)
("Test Underflow ", &test_underflow_message)
("Test Time Error", &test_time_error_message)
("Test Late Command", &test_late_command_message);
// clang-format on
if (vm.count("test-chain")) {
tests["Test Broken Chain"] = &test_broken_chain_message;