John Medrano john.d.medrano at gmail.com
Wed Nov 8 12:31:57 EST 2017


We have implemented in Python and it worked. Now we are trying to implement
the following code in CPP.

We would like to directly communicate with RFNOC in CPP. We have generated
the following code to implement RFNOC SIGGEN->DUC->RADIO.

When we enable SIGGEN the TX/RX will toggle, but we get no output.

#include <uhd/types/tune_request.hpp>
#include <uhd/types/sensors.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/device3.hpp>
#include <uhd/rfnoc/radio_ctrl.hpp>
#include <uhd/rfnoc/source_block_ctrl_base.hpp>
#include <uhd/rfnoc/siggen_block_ctrl.hpp>
#include <uhd/exception.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <boost/thread.hpp>
#include <iostream>
#include <fstream>
#include <csignal>
#include <complex>
#include <cmath>
#include <ctime>

namespace po = boost::program_options;

int UHD_SAFE_MAIN(int argc, char *argv[]){

    //variables to be set by po
    std::string args, file, format, ant, subdev, ref, wirefmt, streamargs,
duc_args, spreader_args, pn_seed, pn_poly;
    size_t total_num_samps, radio_id;
    double freq, gain, setup_time;
    int pn_len;

    //setup the program options
    po::options_description desc("Allowed options");
        ("help", "help message")
po::value<size_t>(&total_num_samps)->default_value(10000), "total number of
samples to transmit")
        ("args", po::value<std::string>(&args)->default_value(""), "USRP
device address args")
        ("setup", po::value<double>(&setup_time)->default_value(1.0),
"seconds of setup time")
        ("radio-id", po::value<size_t>(&radio_id)->default_value(0), "Radio
ID to use (0 or 1).")
        ("freq", po::value<double>(&freq)->default_value(0.0), "RF center
frequency in Hz")
        ("gain", po::value<double>(&gain), "gain for the RF chain")
        ("ant", po::value<std::string>(&ant)->default_value("TX/RX"),
"antenna selection")
        ("ref", po::value<std::string>(&ref), "reference source (internal,
external, mimo)")
        ("duc-args", po::value<std::string>(&duc_args)->default_value(""),
"These args are passed straight to the block.")
po::value<std::string>(&streamargs)->default_value(""), "additional stream
    po::variables_map vm;
    po::store(po::parse_command_line(argc, argv, desc), vm);

    //print the help message
    if (vm.count("help")) {
        std::cout << boost::format("RFNoC SigGen %s") % desc << std::endl;
            << std::endl
            << "This application generates signals using rfnoc siggen\n"
            << std::endl;
        return ~0;

     * Create device and block controls

    std::cout << std::endl;
    std::cout << boost::format("Creating the USRP device with: %s...") %
args << std::endl;
    uhd::usrp::multi_usrp::sptr usrp_temp =
    uhd::device3::sptr usrp = usrp_temp->get_device3();
    // 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);
    std::cout << "Using radio 0" << ", channel " << radio_id << std::endl;

     * Set up radio


    //Setting clock reference for the device
    if (vm.count("ref")) {

    //set the center frequency
    if (vm.count("freq")) {
        std::cout << boost::format("Setting TX Freq: %f MHz...") %
(freq/1e6) << std::endl;
        uhd::tune_request_t tune_request(freq);
        radio_ctrl->set_tx_frequency(freq, radio_id);
        std::cout << boost::format("Actual TX Freq: %f MHz...") %
(radio_ctrl->get_tx_frequency(radio_id)/1e6) << std::endl << std::endl;

    //set the rf gain
    if (vm.count("gain")) {
        std::cout << boost::format("Setting TX Gain: %f dB...") % gain <<
        radio_ctrl->set_tx_gain(gain, radio_id);
        std::cout << boost::format("Actual TX Gain: %f dB...") %
radio_ctrl->get_tx_gain(radio_id) << std::endl << std::endl;

    //set the antenna
    if (vm.count("ant")) {
        radio_ctrl->set_tx_antenna(ant, radio_id);

//allow for some setup time

     * Set up streaming

    uhd::device_addr_t streamer_args(streamargs);

    uhd::rfnoc::graph::sptr tx_graph = usrp->create_graph("rfnoc_spreader");
    // Setting the PN sequence properties and connecting the Spreader block
    std::string duc_id("0/DUC_0");
    std::string siggen_id("0/SigGen_0");

    uhd::rfnoc::siggen_block_ctrl::sptr siggen_ctrl =
    // Set up SigGen
    siggen_ctrl->sr_write("PKT_SIZE", 364);
    siggen_ctrl->sr_write("WAVEFORM", 2); // Generate noise waveform

    uhd::rfnoc::sink_block_ctrl_base::sptr duc_ctrl =

    std::cout << "Connecting " << duc_ctrl->get_block_id() <<" ==> " <<
radio_ctrl_id << std::endl;
    tx_graph->connect(duc_ctrl->get_block_id(), uhd::rfnoc::ANY_PORT,
radio_ctrl_id, radio_id);
    std::cout << "Connecting " << siggen_ctrl->get_block_id() << " ==> "
<<  duc_ctrl->get_block_id();
    tx_graph->connect(siggen_ctrl->get_block_id(), uhd::rfnoc::ANY_PORT,
duc_ctrl->get_block_id(), uhd::rfnoc::ANY_PORT);
    streamer_args["block_id"] = siggen_ctrl->get_block_id().to_string();

    //Creating a transmit streamer
    uhd::stream_args_t stream_args("fc32", "sc16"); // We should read the
wire format from the blocks
    stream_args.args = streamer_args;
    //UHD_MSG(status) << "Using streamer args: " <<
stream_args.args.to_string() << std::endl;
    uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);

    int user_input = 0;
    int tx_enable = 0;
    while (user_input != 2) {
        std::cout << "1. Toggle enable" << std::endl;
        std::cout << "2. To exit" << std::endl;
        std::cin >> user_input;
        if (user_input == 1) {
        tx_enable = !tx_enable;
        siggen_ctrl->sr_write("ENABLE", tx_enable);

//allow for some setup time

    std::cout << std::endl << "Done!" << std::endl << std::endl;

    return EXIT_SUCCESS;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ettus.com/pipermail/usrp-users_lists.ettus.com/attachments/20171108/985f8120/attachment-0002.html>

More information about the USRP-users mailing list