aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples/transport_hammer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/examples/transport_hammer.cpp')
-rw-r--r--host/examples/transport_hammer.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/host/examples/transport_hammer.cpp b/host/examples/transport_hammer.cpp
index ff35ceb21..a44e81a82 100644
--- a/host/examples/transport_hammer.cpp
+++ b/host/examples/transport_hammer.cpp
@@ -41,15 +41,9 @@ unsigned long long num_seq_errors = 0;
/***********************************************************************
* RX Hammer
**********************************************************************/
-void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, const std::string &rx_otw){
+void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, uhd::rx_streamer::sptr rx_stream){
uhd::set_thread_priority_safe();
- //create a receive streamer
- uhd::stream_args_t stream_args(rx_cpu, rx_otw);
- for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
- stream_args.channels.push_back(ch);
- uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
-
//print pre-test summary
std::cout << boost::format(
"Testing receive rate %f Msps"
@@ -60,7 +54,7 @@ void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, cons
const size_t max_samps_per_packet = rx_stream->get_max_num_samps();
std::vector<char> buff(max_samps_per_packet*uhd::convert::get_bytes_per_item(rx_cpu));
std::vector<void *> buffs;
- for (size_t ch = 0; ch < stream_args.channels.size(); ch++)
+ for (size_t ch = 0; ch < rx_stream->get_num_channels(); ch++)
buffs.push_back(&buff.front()); //same buffer for each channel
bool had_an_overflow = false;
uhd::time_spec_t last_time;
@@ -74,7 +68,7 @@ void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, cons
while (not boost::this_thread::interruption_requested()){
cmd.num_samps = rand() % 100000;
- usrp->issue_stream_cmd(cmd);
+ rx_stream->issue_stream_cmd(cmd);
num_rx_samps += rx_stream->recv(buffs, max_samps_per_packet, md, timeout, true);
//handle the error codes
@@ -103,16 +97,15 @@ void rx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &rx_cpu, cons
/***********************************************************************
* TX Hammer
**********************************************************************/
-void tx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_cpu, const std::string &tx_otw){
+void tx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_cpu, uhd::tx_streamer::sptr tx_stream){
uhd::set_thread_priority_safe();
- //create a transmit streamer
- uhd::stream_args_t stream_args(tx_cpu, tx_otw);
- for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
- stream_args.channels.push_back(ch);
- uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
uhd::tx_metadata_t md;
- std::vector<std::complex<float> > buff(10000);
+ const size_t max_samps_per_packet = tx_stream->get_max_num_samps();
+ std::vector<char> buff(max_samps_per_packet*uhd::convert::get_bytes_per_item(tx_cpu));
+ std::vector<void *> buffs;
+ for (size_t ch = 0; ch < tx_stream->get_num_channels(); ch++)
+ buffs.push_back(&buff.front()); //same buffer for each channel
//print pre-test summary
std::cout << boost::format(
@@ -130,7 +123,7 @@ void tx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_cpu, cons
while(num_acc_samps < total_num_samps){
//send a single packet
- num_tx_samps += tx_stream->send(&buff, tx_stream->get_max_num_samps(), md, timeout);
+ num_tx_samps += tx_stream->send(buffs, max_samps_per_packet, md, timeout);
num_acc_samps += std::min(total_num_samps-num_acc_samps, tx_stream->get_max_num_samps());
}
@@ -140,13 +133,13 @@ void tx_hammer(uhd::usrp::multi_usrp::sptr usrp, const std::string &tx_cpu, cons
}
}
-void tx_hammer_async_helper(uhd::usrp::multi_usrp::sptr usrp){
+void tx_hammer_async_helper(uhd::tx_streamer::sptr tx_stream){
//setup variables and allocate buffer
uhd::async_metadata_t async_md;
while (not boost::this_thread::interruption_requested()){
- if (not usrp->get_device()->recv_async_msg(async_md)) continue;
+ if (not tx_stream->recv_async_msg(async_md)) continue;
//handle the error codes
switch(async_md.event_code){
@@ -239,14 +232,24 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//spawn the receive test thread
if (vm.count("rx_rate")){
usrp->set_rx_rate(rx_rate);
- thread_group.create_thread(boost::bind(&rx_hammer, usrp, rx_cpu, rx_otw));
+ //create a receive streamer
+ uhd::stream_args_t stream_args(rx_cpu, rx_otw);
+ for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
+ stream_args.channels.push_back(ch);
+ uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
+ thread_group.create_thread(boost::bind(&rx_hammer, usrp, rx_cpu, rx_stream));
}
//spawn the transmit test thread
if (vm.count("tx_rate")){
usrp->set_tx_rate(tx_rate);
- thread_group.create_thread(boost::bind(&tx_hammer, usrp, tx_cpu, tx_otw));
- thread_group.create_thread(boost::bind(&tx_hammer_async_helper, usrp));
+ //create a transmit streamer
+ uhd::stream_args_t stream_args(tx_cpu, tx_otw);
+ for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) //linear channel mapping
+ stream_args.channels.push_back(ch);
+ uhd::tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args);
+ thread_group.create_thread(boost::bind(&tx_hammer, usrp, tx_cpu, tx_stream));
+ thread_group.create_thread(boost::bind(&tx_hammer_async_helper, tx_stream));
}
//sleep for the required duration