Hi, I noticed that on the UHD repository examples there isn’t an example that
shows how to setup a TX streaming using RFNoC. There is the example for the RX
but not the one with TX.
There’s an example for the replay block, but it can’t be used for transmitting
a big file for instance.
I searched through the mailing list and found some posts of user that attached
some rfnoc_tx_from_file, but they did it in 2018 and it was on UHD 3, it
obviously doesn’t work on UHD 4.
Could someone post a simple example of transmitting from file using RFNoC 4?
Maybe it is considered trivial, but it could help as a reference.
Personally
I tried to write a sample code, but as I stated in another thread I’m not sure
it is working correctly.
Could anyone help here?
#include <iostream>
#include <uhd/types/tune_request.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/utils/thread.hpp>
#include <uhd/rfnoc/block_id.hpp>
#include <uhd/rfnoc/duc_block_control.hpp>
#include <uhd/rfnoc/mb_controller.hpp>
#include <uhd/rfnoc/radio_control.hpp>
#include <uhd/rfnoc/replay_block_control.hpp>
#include <uhd/rfnoc_graph.hpp>
#include <fstream>
#define BUFFERSIZE 8192
using namespace std;
int UHD_SAFE_MAIN(int argc, char* argv[])
{
const double rate = 6.25e6; // Sample rate
const double freq = 868.5e6; // Center frequency
const double gain = 10; // TX gain
const string device_addr = "type=x300,addr=192.168.40.2"; // Default (first device)
const string filename = "rawiq.sc16";
uhd::rfnoc::rfnoc_graph::sptr graph;
uhd::rfnoc::block_id_t radio_control_id;
uhd::rfnoc::radio_control::sptr radio_control ;
uhd::rfnoc::block_id_t duc_control_id;
uhd::rfnoc::duc_block_control::sptr duc_control ;
graph = uhd::rfnoc::rfnoc_graph::make(device_addr.c_str());
radio_control_id = uhd::rfnoc::block_id_t(0, "Radio", 1) ;
radio_control = graph->get_block<uhd::rfnoc::radio_control>(radio_control_id) ;
radio_control->set_tx_gain(gain,0);
radio_control->set_tx_frequency(freq,0);
if( !radio_control ) {
cout << "ERROR: Failed to find Radio Block Controller!" << endl ;
}
cout << "Using radio " << radio_control_id << endl ;
// DUC Block Controller
duc_control_id = uhd::rfnoc::block_id_t(0, "DUC", 1) ;
duc_control = graph->get_block<uhd::rfnoc::duc_block_control>(duc_control_id) ;
if( !duc_control ) {
cout << "ERROR: Failed to find DUC Block Controller!" << endl ;
}
cout << "Using duc " << duc_control_id << endl ;
duc_control->set_output_rate(200e6,0);
duc_control->set_freq(0,0);
duc_control->set_input_rate(rate,0);
uhd::stream_args_t stream_args("sc16", "sc16");
auto tx_stream = graph->create_tx_streamer(1, stream_args);
graph->connect(tx_stream,0,duc_control->get_unique_id(),0);
graph->commit();
std::this_thread::sleep_for(std::chrono::seconds(1));
int k = 0;
ifstream *infile;
infile = new ifstream(filename, std::ios::binary);
uhd::tx_metadata_t md;
md.start_of_burst = true; // Start of burst
md.end_of_burst = false; // We will stop this later
md.has_time_spec = false;
std::vector<std::complex<short>> buff(BUFFERSIZE);
cout << "Starting transmission" << endl;
while (!infile->eof()) {
infile->read(reinterpret_cast<char*>(&buff.front()), BUFFERSIZE * sizeof(complex<short>));
size_t samples_read = infile->gcount() / sizeof(complex<short>);
if (samples_read == 0)
{
cout<<"No samples read\r\n";
break;
}
tx_stream->send(&buff.front(), samples_read, md);
md.start_of_burst = false;
}
md.end_of_burst = true;
tx_stream->send("", 0, md);
infile->close();
cout << "Transmission complete." << endl;
return 0;
}
_______________________________________________
USRP-users mailing list -- usrp-users@lists.ettus.com
To unsubscribe send an email to usrp-users-le...@lists.ettus.com