Hi,

sure, find the cpp attached.

Thanks and best regards,
Daniel

On 26.09.2018 16:56, Brian Padalino wrote:
On Wed, Sep 26, 2018 at 10:36 AM Daniel Rauschen via USRP-users <usrp-users@lists.ettus.com <mailto:usrp-users@lists.ettus.com>> wrote:

    Hi all,

    I have a question regarding a RFNoC loopback in plain UHD.

    I am familiar with [1] and I have a working solution with gr-ettus
    and
    python. The problem is, I can not figure out how to connect the
    blocks
    in plain UHD. Does anyone have a working example in UHD for a RFNoC
    loopback?

    Connecting in UHD/c++ fails with following error: "Error:
    RuntimeError:
    On node 0/Radio_0, output port 0 is already connected."...

    Any help is highly appreciated :)


You didn't show us how you tried to connect them?  Can you attach your source file?

Brian

//
// Copyright 2014 Ettus Research LLC
//
// 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/>.
//

// This is a simple example for RFNoC apps written in UHD.
// It connects a null source block to any other block on the
// crossbar (provided it has stream-through capabilities)
// and then streams the result to the host, writing it into a file.

#include <uhd/device3.hpp>
#include <uhd/types/tune_request.hpp>
#include <uhd/utils/thread.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/exception.hpp>
#include <uhd/rfnoc/block_ctrl.hpp>
#include <uhd/rfnoc/radio_ctrl.hpp>
#include <uhd/rfnoc/null_block_ctrl.hpp>
#include <uhd/rfnoc/window_block_ctrl.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <iostream>
#include <fstream>
#include <csignal>
#include <complex>

#define FFT_SIZE 1024
#define CENTER_FREQ 2.45e9
#define RX_GAIN 0
#define TX_GAIN 0

namespace po = boost::program_options;

// ***********************************************************************************************************
void pretty_print_flow_graph(std::vector<std::string> blocks) {
	std::string sep_str = "==>";
	std::cout << std::endl;
	// Line 1
	for (size_t n = 0; n < blocks.size(); n++) {
		const std::string name = blocks[n];
		std::cout << "+";
		for (size_t i = 0; i < name.size() + 2; i++) {
			std::cout << "-";
		}
		std::cout << "+";
		if (n == blocks.size() - 1) {
			break;
		}
		for (size_t i = 0; i < sep_str.size(); i++) {
			std::cout << " ";
		}
	}
	std::cout << std::endl;
	// Line 2
	for (size_t n = 0; n < blocks.size(); n++) {
		const std::string name = blocks[n];
		std::cout << "| " << name << " |";
		if (n == blocks.size() - 1) {
			break;
		}
		std::cout << sep_str;
	}
	std::cout << std::endl;
	// Line 3
	for (size_t n = 0; n < blocks.size(); n++) {
		const std::string name = blocks[n];
		std::cout << "+";
		for (size_t i = 0; i < name.size() + 2; i++) {
			std::cout << "-";
		}
		std::cout << "+";
		if (n == blocks.size() - 1) {
			break;
		}
		for (size_t i = 0; i < sep_str.size(); i++) {
			std::cout << " ";
		}
	}
	std::cout << std::endl << std::endl;
}

// ***********************************************************************************************************
int UHD_SAFE_MAIN(int argc, char *argv[]){
	uhd::set_thread_priority_safe();

	//variables to be set by po
	std::string args, file, format;
	size_t total_num_samps, spb, spp;
	double rate, total_time, setup_time, block_rate;

	//setup the program options
	po::options_description desc("Allowed options");
	desc.add_options()("help", "help message")("args", po::value<std::string>(&args)->default_value("type=x300, master_clock_rate=120e6, num_recv_frames=1024"), "multi uhd device address args")
#if (JGEN == true)
	("file", po::value<std::string>(&file)->default_value("sig_resp_fpga.dat"), "name of the file to write binary samples to, set to stdout to print")
#else
	("file", po::value<std::string>(&file)->default_value("sig.dat"), "name of the file to write binary samples to, set to stdout to print")
#endif
	("null", "run without writing to file")("nsamps", po::value<size_t>(&total_num_samps)->default_value(FFT_SIZE * 234375), "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(1024 * 10), "samples per buffer")("spp", po::value<size_t>(&spp)->default_value(FFT_SIZE), "samples per packet (on FPGA and wire)")("block_rate", po::value<double>(&block_rate)->default_value(120e6), "The clock rate of the processing block.")(
			"rate", po::value<double>(&rate)->default_value(120e6), "rate at which samples are produced in the radio 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");
	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);

	//print the help message
	if (vm.count("help")) {
		std::cout << boost::format("[RFNOC] Connect a null source to another (processing) block, and stream the result to file %s.") % desc << std::endl;
		return ~0;
	}

	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 << boost::format("Creating the USRP device with: %s...") % args << std::endl;
	uhd::device3::sptr usrp = uhd::device3::make(std::string("type=x300,master_clock_rate=120e6,addr=192.168.10.2,spp=1024"));

	boost::this_thread::sleep(boost::posix_time::seconds(setup_time)); //allow for some setup time
	usrp->clear();
	uhd::rfnoc::graph::sptr rx_graph = usrp->create_graph("rx_graph");

	/////////////////////////////////////////////////////////////////////////
	//////// 2. Get block control objects ///////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
	std::vector<std::string> blocks;

	// Create handle for radio object and configure radio.
	uhd::rfnoc::block_id_t radio_ctrl_id0(0, "Radio",0);
	uhd::rfnoc::radio_ctrl::sptr radio_ctrl = usrp->get_block_ctrl<uhd::rfnoc::radio_ctrl>(radio_ctrl_id0);


	blocks.push_back(radio_ctrl->get_block_id());
	std::cout << "\n____________________________________\n";
	std::cout << "\nRadio0 FIFO Size:" << radio_ctrl->get_fifo_size(0) << "/" << radio_ctrl->get_fifo_size(1) << "\n";
	std::cout << "\nRadio0 Params port 0:\n" << radio_ctrl->get_args(0).to_pp_string();
	std::cout << "\nRadio0 Params port 1:\n" << radio_ctrl->get_args(1).to_pp_string();
	std::cout << "\n____________________________________\n";

	//***********************************************************************************************************************
	uhd::rfnoc::block_ctrl_base::sptr fft_ctrl0, fft_ctrl1, dmafifo_ctrl;
	uhd::rfnoc::window_block_ctrl::sptr window_ctrl;

	//***********************************************************************************************************************
	//b=blackman(1024);dlmwrite('blackman1024.csv',b',',')
	static const int arr[] = { 0, 0, 0, 1, -2, 3, -4, 5, -7, 9, -11, 13, -16, 19, -22, 25, -29, 32, -36, 40, -45, 49, -54, 59, -65, 70, -76, 82, -88, 95, -101, 108, -115, 123, -131, 139, -147, 155, -164, 173, -182, 191, -201, 211, -221, 231, -242, 253, -264, 276, -287, 299, -312, 324, -337, 350,
			-363, 377, -391, 405, -420, 434, -449, 465, -480, 496, -512, 529, -546, 563, -580, 598, -616, 634, -653, 672, -691, 711, -730, 751, -771, 792, -813, 835, -856, 879, -901, 924, -947, 971, -995, 1019, -1043, 1068, -1094, 1119, -1145, 1172, -1198, 1226, -1253, 1281, -1309, 1338, -1367,
			1396, -1426, 1456, -1486, 1517, -1549, 1580, -1612, 1645, -1678, 1711, -1745, 1779, -1813, 1848, -1884, 1920, -1956, 1992, -2030, 2067, -2105, 2143, -2182, 2221, -2261, 2301, -2342, 2383, -2424, 2466, -2508, 2551, -2594, 2638, -2682, 2727, -2772, 2818, -2864, 2910, -2957, 3004, -3052,
			3101, -3150, 3199, -3249, 3299, -3350, 3401, -3453, 3505, -3558, 3611, -3665, 3719, -3774, 3829, -3885, 3941, -3998, 4055, -4113, 4171, -4230, 4289, -4349, 4409, -4470, 4531, -4593, 4655, -4718, 4782, -4846, 4910, -4975, 5040, -5106, 5172, -5239, 5307, -5375, 5443, -5512, 5582, -5652,
			5722, -5793, 5865, -5937, 6010, -6083, 6157, -6231, 6305, -6381, 6456, -6532, 6609, -6686, 6764, -6842, 6921, -7000, 7080, -7160, 7241, -7323, 7404, -7487, 7569, -7653, 7736, -7821, 7905, -7991, 8076, -8163, 8249, -8337, 8424, -8512, 8601, -8690, 8780, -8870, 8960, -9051, 9143, -9235,
			9327, -9420, 9513, -9607, 9701, -9796, 9891, -9986, 10082, -10179, 10276, -10373, 10470, -10569, 10667, -10766, 10865, -10965, 11065, -11166, 11267, -11368, 11470, -11572, 11674, -11777, 11880, -11984, 12088, -12192, 12297, -12402, 12507, -12613, 12719, -12825, 12932, -13039, 13146,
			-13253, 13361, -13470, 13578, -13687, 13796, -13905, 14015, -14125, 14235, -14346, 14456, -14567, 14679, -14790, 14902, -15014, 15126, -15238, 15351, -15463, 15576, -15689, 15803, -15916, 16030, -16144, 16258, -16372, 16486, -16601, 16715, -16830, 16945, -17060, 17175, -17290, 17405,
			-17520, 17636, -17751, 17867, -17982, 18098, -18214, 18330, -18445, 18561, -18677, 18793, -18909, 19025, -19141, 19256, -19372, 19488, -19604, 19719, -19835, 19951, -20066, 20182, -20297, 20412, -20527, 20643, -20758, 20872, -20987, 21102, -21216, 21330, -21445, 21559, -21672, 21786,
			-21899, 22013, -22126, 22239, -22351, 22464, -22576, 22688, -22799, 22911, -23022, 23133, -23243, 23354, -23464, 23573, -23683, 23792, -23901, 24009, -24117, 24225, -24332, 24439, -24546, 24652, -24758, 24864, -24969, 25073, -25178, 25282, -25385, 25488, -25590, 25693, -25794, 25895,
			-25996, 26096, -26196, 26295, -26394, 26492, -26589, 26686, -26783, 26879, -26975, 27069, -27164, 27258, -27351, 27443, -27535, 27627, -27718, 27808, -27897, 27986, -28075, 28162, -28249, 28336, -28422, 28507, -28591, 28675, -28758, 28840, -28922, 29002, -29083, 29162, -29241, 29319,
			-29396, 29473, -29548, 29624, -29698, 29771, -29844, 29916, -29987, 30057, -30127, 30196, -30264, 30331, -30397, 30463, -30528, 30591, -30654, 30717, -30778, 30838, -30898, 30957, -31015, 31072, -31128, 31183, -31237, 31291, -31343, 31395, -31446, 31496, -31545, 31593, -31640, 31686,
			-31732, 31776, -31819, 31862, -31903, 31944, -31984, 32022, -32060, 32097, -32133, 32168, -32202, 32235, -32267, 32298, -32328, 32357, -32385, 32412, -32438, 32463, -32487, 32510, -32532, 32554, -32574, 32593, -32611, 32628, -32644, 32660, -32674, 32687, -32699, 32710, -32720, 32729,
			-32738, 32745, -32751, 32756, -32760, 32763, -32765, 32766, -32766, 32765, -32763, 32760, -32756, 32751, -32745, 32738, -32729, 32720, -32710, 32699, -32687, 32674, -32660, 32644, -32628, 32611, -32593, 32574, -32554, 32532, -32510, 32487, -32463, 32438, -32412, 32385, -32357, 32328,
			-32298, 32267, -32235, 32202, -32168, 32133, -32097, 32060, -32022, 31984, -31944, 31903, -31862, 31819, -31776, 31732, -31686, 31640, -31593, 31545, -31496, 31446, -31395, 31343, -31291, 31237, -31183, 31128, -31072, 31015, -30957, 30898, -30838, 30778, -30717, 30654, -30591, 30528,
			-30463, 30397, -30331, 30264, -30196, 30127, -30057, 29987, -29916, 29844, -29771, 29698, -29624, 29548, -29473, 29396, -29319, 29241, -29162, 29083, -29002, 28922, -28840, 28758, -28675, 28591, -28507, 28422, -28336, 28249, -28162, 28075, -27986, 27897, -27808, 27718, -27627, 27535,
			-27443, 27351, -27258, 27164, -27069, 26975, -26879, 26783, -26686, 26589, -26492, 26394, -26295, 26196, -26096, 25996, -25895, 25794, -25693, 25590, -25488, 25385, -25282, 25178, -25073, 24969, -24864, 24758, -24652, 24546, -24439, 24332, -24225, 24117, -24009, 23901, -23792, 23683,
			-23573, 23464, -23354, 23243, -23133, 23022, -22911, 22799, -22688, 22576, -22464, 22351, -22239, 22126, -22013, 21899, -21786, 21672, -21559, 21445, -21330, 21216, -21102, 20987, -20872, 20758, -20643, 20527, -20412, 20297, -20182, 20066, -19951, 19835, -19719, 19604, -19488, 19372,
			-19256, 19141, -19025, 18909, -18793, 18677, -18561, 18445, -18330, 18214, -18098, 17982, -17867, 17751, -17636, 17520, -17405, 17290, -17175, 17060, -16945, 16830, -16715, 16601, -16486, 16372, -16258, 16144, -16030, 15916, -15803, 15689, -15576, 15463, -15351, 15238, -15126, 15014,
			-14902, 14790, -14679, 14567, -14456, 14346, -14235, 14125, -14015, 13905, -13796, 13687, -13578, 13470, -13361, 13253, -13146, 13039, -12932, 12825, -12719, 12613, -12507, 12402, -12297, 12192, -12088, 11984, -11880, 11777, -11674, 11572, -11470, 11368, -11267, 11166, -11065, 10965,
			-10865, 10766, -10667, 10569, -10470, 10373, -10276, 10179, -10082, 9986, -9891, 9796, -9701, 9607, -9513, 9420, -9327, 9235, -9143, 9051, -8960, 8870, -8780, 8690, -8601, 8512, -8424, 8337, -8249, 8163, -8076, 7991, -7905, 7821, -7736, 7653, -7569, 7487, -7404, 7323, -7241, 7160, -7080,
			7000, -6921, 6842, -6764, 6686, -6609, 6532, -6456, 6381, -6305, 6231, -6157, 6083, -6010, 5937, -5865, 5793, -5722, 5652, -5582, 5512, -5443, 5375, -5307, 5239, -5172, 5106, -5040, 4975, -4910, 4846, -4782, 4718, -4655, 4593, -4531, 4470, -4409, 4349, -4289, 4230, -4171, 4113, -4055,
			3998, -3941, 3885, -3829, 3774, -3719, 3665, -3611, 3558, -3505, 3453, -3401, 3350, -3299, 3249, -3199, 3150, -3101, 3052, -3004, 2957, -2910, 2864, -2818, 2772, -2727, 2682, -2638, 2594, -2551, 2508, -2466, 2424, -2383, 2342, -2301, 2261, -2221, 2182, -2143, 2105, -2067, 2030, -1992,
			1956, -1920, 1884, -1848, 1813, -1779, 1745, -1711, 1678, -1645, 1612, -1580, 1549, -1517, 1486, -1456, 1426, -1396, 1367, -1338, 1309, -1281, 1253, -1226, 1198, -1172, 1145, -1119, 1094, -1068, 1043, -1019, 995, -971, 947, -924, 901, -879, 856, -835, 813, -792, 771, -751, 730, -711,
			691, -672, 653, -634, 616, -598, 580, -563, 546, -529, 512, -496, 480, -465, 449, -434, 420, -405, 391, -377, 363, -350, 337, -324, 312, -299, 287, -276, 264, -253, 242, -231, 221, -211, 201, -191, 182, -173, 164, -155, 147, -139, 131, -123, 115, -108, 101, -95, 88, -82, 76, -70, 65,
			-59, 54, -49, 45, -40, 36, -32, 29, -25, 22, -19, 16, -13, 11, -9, 7, -5, 4, -3, 2, -1, 0, 0, 0 };
	std::vector<int> coeffs(arr, arr + sizeof(arr) / sizeof(arr[0]));
	window_ctrl = usrp->get_block_ctrl<uhd::rfnoc::window_block_ctrl>((std::string) "Window_0");
	window_ctrl->set_arg("spp", FFT_SIZE);
	window_ctrl->set_window(coeffs);
	blocks.push_back(window_ctrl->get_block_id());
	std::cout << "\nWindow Params:\n" << window_ctrl->get_args().to_pp_string();
	std::cout << "\n____________________________________\n";

	//***********************************************************************************************************************
	fft_ctrl0 = usrp->get_block_ctrl((std::string) "FFT_0");
	fft_ctrl0->set_arg("magnitude_out", (std::string)"COMPLEX", 0);
	fft_ctrl0->set_arg("spp", FFT_SIZE, 0);
	fft_ctrl0->set_arg("direction", (std::string)"forward", 0);
	fft_ctrl0->set_arg("shift", (std::string)"natural", 0);
	fft_ctrl0->set_arg("scaling", 1706);
	blocks.push_back(fft_ctrl0->get_block_id());
	std::cout << "\nFFT Params:\n" << fft_ctrl0->get_args().to_pp_string();
	std::cout << "\n____________________________________\n";

	//***********************************************************************************************************************
	fft_ctrl1 = usrp->get_block_ctrl((std::string) "FFT_1");
	fft_ctrl1->set_arg("magnitude_out", (std::string)"COMPLEX", 0);
	fft_ctrl1->set_arg("spp", FFT_SIZE, 0);
	fft_ctrl1->set_arg("direction", (std::string)"reverse", 0);
	fft_ctrl1->set_arg("shift", (std::string)"natural", 0);
	fft_ctrl1->set_arg("scaling", 85);
	blocks.push_back(fft_ctrl1->get_block_id());
	std::cout << "\nFFT Params:\n" << fft_ctrl1->get_args().to_pp_string();
	std::cout << "\n____________________________________\n";

	//***********************************************************************************************************************
	dmafifo_ctrl = usrp->get_block_ctrl((std::string) "DmaFIFO");
	dmafifo_ctrl->set_arg("base_addr", 0, 0);
	dmafifo_ctrl->set_arg("depth", 33554432, 0);
	dmafifo_ctrl->set_arg("base_addr", 33554432, 1);
	dmafifo_ctrl->set_arg("depth", 33554432, 1);
	blocks.push_back(dmafifo_ctrl->get_block_id());
	std::cout << "\nDmaFIFO Params port 0:\n" << dmafifo_ctrl->get_args(0).to_pp_string();
	std::cout << "\nDmaFIFO Params port 1:\n" << dmafifo_ctrl->get_args(1).to_pp_string();
	std::cout << "\n____________________________________\n";

	pretty_print_flow_graph(blocks);

	/////////////////////////////////////////////////////////////////////////
	//////// 4. Configure blocks
	/////////////////////////////////////////////////////////////////////////
	//set the center frequency
	std::cout << boost::format("Setting RX Freq: %f MHz...") % (CENTER_FREQ / 1e6) << std::endl;

	radio_ctrl->set_rx_frequency(CENTER_FREQ, 0);
	radio_ctrl->set_tx_frequency(CENTER_FREQ, 0);

	std::cout << boost::format("Actual RX Freq: %f MHz...") % (radio_ctrl->get_rx_frequency(0) / 1e6) << std::endl << std::endl;
	std::cout << boost::format("Actual TX Freq: %f MHz...") % (radio_ctrl->get_tx_frequency(0) / 1e6) << std::endl << std::endl;

	radio_ctrl->set_rx_gain(RX_GAIN, 0);
	radio_ctrl->set_rx_gain(TX_GAIN, 0);

	std::cout << boost::format("Actual RX Gain: %f dB...") % radio_ctrl->get_rx_gain(0) << std::endl << std::endl;
	std::cout << boost::format("Actual TX Gain: %f dB...") % radio_ctrl->get_tx_gain(0) << std::endl << std::endl;

	radio_ctrl->set_rate(120e6);
	radio_ctrl->set_clock_source("internal");

//	radio_ctrl_rx->set_rate(120e6);
//	radio_ctrl_rx->set_clock_source("internal");

	radio_ctrl->set_rx_antenna("RX2", 0);
	radio_ctrl->set_tx_antenna("TX/RX", 0);

	radio_ctrl->set_rx_streamer(true, 0);

	/////////////////////////////////////////////////////////////////////////
	//////// 5. Connect blocks //////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////
	std::cout << "Connecting blocks..." << std::endl;

	rx_graph->connect(radio_ctrl->get_block_id(), 0, window_ctrl->get_block_id(), 0, FFT_SIZE);
	rx_graph->connect(window_ctrl->get_block_id(), 0, fft_ctrl0->get_block_id(), 0, FFT_SIZE);
	rx_graph->connect(fft_ctrl0->get_block_id(), 0, fft_ctrl1->get_block_id(), 0, FFT_SIZE);
	rx_graph->connect(fft_ctrl1->get_block_id(), 0, dmafifo_ctrl->get_block_id(), 0, FFT_SIZE);
	rx_graph->connect(dmafifo_ctrl->get_block_id(), 0, radio_ctrl->get_block_id(), 0, FFT_SIZE);

	/////////////////////////////////////////////////////////////////////////
	//////// 6. Spawn receiver //////////////////////////////////////////////
	/////////////////////////////////////////////////////////////////////////

	uhd::stream_args_t stream_args("sc16","sc16");
	stream_args.args["block_id"] = radio_ctrl->get_block_id().to_string();
	stream_args.args["port"] = "0";
	stream_args.args["spp"] = "1024";

	uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);

	uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
	stream_cmd.stream_now = true;

	std::cout << "Issuing start rx/tx stream cmd" << std::endl;

	rx_stream->issue_stream_cmd(stream_cmd);

	usleep(5000000);

	uhd::stream_cmd_t stream_stop_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);

	rx_stream->issue_stream_cmd(stream_stop_cmd);
	std::cout << "Issuing stop rx/tx stream cmd" << std::endl;

	usleep(2000000);


	return EXIT_SUCCESS;
}

_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com

Reply via email to