diff options
-rw-r--r-- | host/examples/benchmark_rate.cpp | 31 | ||||
-rw-r--r-- | host/examples/latency_test.cpp | 17 | ||||
-rw-r--r-- | host/examples/rx_ascii_art_dft.cpp | 10 | ||||
-rw-r--r-- | host/examples/rx_multi_samples.cpp | 15 | ||||
-rw-r--r-- | host/examples/rx_samples_to_file.cpp | 17 | ||||
-rw-r--r-- | host/examples/rx_samples_to_udp.cpp | 12 | ||||
-rw-r--r-- | host/examples/rx_timed_samples.cpp | 12 | ||||
-rw-r--r-- | host/examples/test_messages.cpp | 75 | ||||
-rw-r--r-- | host/examples/tx_bursts.cpp | 14 | ||||
-rw-r--r-- | host/examples/tx_samples_from_file.cpp | 17 | ||||
-rw-r--r-- | host/examples/tx_timed_samples.cpp | 17 | ||||
-rw-r--r-- | host/examples/tx_waveforms.cpp | 18 |
12 files changed, 128 insertions, 127 deletions
diff --git a/host/examples/benchmark_rate.cpp b/host/examples/benchmark_rate.cpp index 774b240d4..7862bd44b 100644 --- a/host/examples/benchmark_rate.cpp +++ b/host/examples/benchmark_rate.cpp @@ -43,6 +43,10 @@ unsigned long long num_seq_errors = 0; void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp){ uhd::set_thread_priority_safe(); + //create a receive streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + //print pre-test summary std::cout << boost::format( "Testing receive rate %f Msps" @@ -50,7 +54,7 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp){ //setup variables and allocate buffer uhd::rx_metadata_t md; - const size_t max_samps_per_packet = usrp->get_device()->get_max_recv_samps_per_packet(); + const size_t max_samps_per_packet = rx_stream->get_max_num_samps(); std::vector<std::complex<float> > buff(max_samps_per_packet); bool had_an_overflow = false; uhd::time_spec_t last_time; @@ -58,10 +62,8 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp){ usrp->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); while (not boost::this_thread::interruption_requested()){ - num_rx_samps += usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET + num_rx_samps += rx_stream->recv( + &buff.front(), buff.size(), md ); //handle the error codes @@ -95,6 +97,10 @@ void benchmark_rx_rate(uhd::usrp::multi_usrp::sptr usrp){ void benchmark_tx_rate(uhd::usrp::multi_usrp::sptr usrp){ uhd::set_thread_priority_safe(); + //create a transmit streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //print pre-test summary std::cout << boost::format( "Testing transmit rate %f Msps" @@ -103,23 +109,16 @@ void benchmark_tx_rate(uhd::usrp::multi_usrp::sptr usrp){ //setup variables and allocate buffer uhd::tx_metadata_t md; md.has_time_spec = false; - const size_t max_samps_per_packet = usrp->get_device()->get_max_send_samps_per_packet(); + const size_t max_samps_per_packet = tx_stream->get_max_num_samps(); std::vector<std::complex<float> > buff(max_samps_per_packet); while (not boost::this_thread::interruption_requested()){ - num_tx_samps += usrp->get_device()->send( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_ONE_PACKET - ); + num_tx_samps += tx_stream->send(&buff.front(), buff.size(), md); } //send a mini EOB packet - md.end_of_burst = true; - usrp->get_device()->send("", 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + md.end_of_burst = true; + tx_stream->send("", 0, md); } void benchmark_tx_rate_async_helper(uhd::usrp::multi_usrp::sptr usrp){ diff --git a/host/examples/latency_test.cpp b/host/examples/latency_test.cpp index 85ac73567..b995b0433 100644 --- a/host/examples/latency_test.cpp +++ b/host/examples/latency_test.cpp @@ -83,6 +83,11 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //allocate a buffer to use std::vector<std::complex<float> > buffer(nsamps); + //create RX and TX streamers + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //initialize result counts int time_error = 0; int ack = 0; @@ -104,10 +109,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ * Receive the requested packet **************************************************************/ uhd::rx_metadata_t rx_md; - size_t num_rx_samps = usrp->get_device()->recv( - &buffer.front(), buffer.size(), rx_md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF + size_t num_rx_samps = rx_stream->recv( + &buffer.front(), buffer.size(), rx_md ); if(verbose) std::cout << boost::format("Got packet: %u samples, %u full secs, %f frac secs") @@ -121,10 +124,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ tx_md.end_of_burst = true; tx_md.has_time_spec = true; tx_md.time_spec = rx_md.time_spec + uhd::time_spec_t(rtt); - size_t num_tx_samps = usrp->get_device()->send( - &buffer.front(), buffer.size(), tx_md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF + size_t num_tx_samps = tx_stream->send( + &buffer.front(), buffer.size(), tx_md ); if(verbose) std::cout << boost::format("Sent %d samples") % num_tx_samps << std::endl; diff --git a/host/examples/rx_ascii_art_dft.cpp b/host/examples/rx_ascii_art_dft.cpp index 11a0ccc24..14b83fb65 100644 --- a/host/examples/rx_ascii_art_dft.cpp +++ b/host/examples/rx_ascii_art_dft.cpp @@ -147,6 +147,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ UHD_ASSERT_THROW(ref_locked.to_bool()); } + //create a receive streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + //allocate recv buffer and metatdata uhd::rx_metadata_t md; std::vector<std::complex<float> > buff(num_bins); @@ -162,10 +166,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //------------------------------------------------------------------ while (true){ //read a buffer's worth of samples every iteration - size_t num_rx_samps = usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF + size_t num_rx_samps = rx_stream->recv( + &buff.front(), buff.size(), md ); if (num_rx_samps != buff.size()) continue; diff --git a/host/examples/rx_multi_samples.cpp b/host/examples/rx_multi_samples.cpp index 8f6d7c939..56aed60af 100644 --- a/host/examples/rx_multi_samples.cpp +++ b/host/examples/rx_multi_samples.cpp @@ -111,6 +111,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ boost::this_thread::sleep(boost::posix_time::milliseconds(100)); } + //create a receive streamer + //linearly map channels (index0 = channel0, index1 = channel1, ...) + uhd::streamer_args stream_args("fc32"); //complex floats + for (size_t chan = 0; chan < usrp->get_rx_num_channels(); chan++) + stream_args.channels.push_back(chan); //linear mapping + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + //setup streaming std::cout << std::endl; std::cout << boost::format( @@ -126,7 +133,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::rx_metadata_t md; //allocate buffers to receive with samples (one buffer per channel) - size_t samps_per_buff = usrp->get_device()->get_max_recv_samps_per_packet(); + const size_t samps_per_buff = rx_stream->get_max_num_samps(); std::vector<std::vector<std::complex<float> > > buffs( usrp->get_rx_num_channels(), std::vector<std::complex<float> >(samps_per_buff) ); @@ -141,10 +148,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ size_t num_acc_samps = 0; //number of accumulated samples while(num_acc_samps < total_num_samps){ //receive a single packet - size_t num_rx_samps = usrp->get_device()->recv( - buff_ptrs, samps_per_buff, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, timeout + size_t num_rx_samps = rx_stream->recv( + buff_ptrs, samps_per_buff, md, timeout ); //use a small timeout for subsequent packets diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index 1e213c83a..58bd158a5 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -34,20 +34,21 @@ void sig_int_handler(int){stop_signal_called = true;} template<typename samp_type> void recv_to_file( uhd::usrp::multi_usrp::sptr usrp, - const uhd::io_type_t &io_type, + const std::string &cpu_format, const std::string &file, size_t samps_per_buff ){ + //create a receive streamer + uhd::streamer_args stream_args(cpu_format); + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + uhd::rx_metadata_t md; std::vector<samp_type> buff(samps_per_buff); std::ofstream outfile(file.c_str(), std::ofstream::binary); bool overflow_message = true; while(not stop_signal_called){ - size_t num_rx_samps = usrp->get_device()->recv( - &buff.front(), buff.size(), md, io_type, - uhd::device::RECV_MODE_FULL_BUFF - ); + size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md); if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break; if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW){ @@ -205,9 +206,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ } //recv to file - if (type == "double") recv_to_file<std::complex<double> >(usrp, uhd::io_type_t::COMPLEX_FLOAT64, file, spb); - else if (type == "float") recv_to_file<std::complex<float> >(usrp, uhd::io_type_t::COMPLEX_FLOAT32, file, spb); - else if (type == "short") recv_to_file<std::complex<short> >(usrp, uhd::io_type_t::COMPLEX_INT16, file, spb); + if (type == "double") recv_to_file<std::complex<double> >(usrp, "fc64", file, spb); + else if (type == "float") recv_to_file<std::complex<float> >(usrp, "fc32", file, spb); + else if (type == "short") recv_to_file<std::complex<short> >(usrp, "sc16", file, spb); else throw std::runtime_error("Unknown type " + type); //finished diff --git a/host/examples/rx_samples_to_udp.cpp b/host/examples/rx_samples_to_udp.cpp index d06f1bc6e..3db436ad5 100644 --- a/host/examples/rx_samples_to_udp.cpp +++ b/host/examples/rx_samples_to_udp.cpp @@ -130,6 +130,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ UHD_ASSERT_THROW(ref_locked.to_bool()); } + //create a receive streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + //setup streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); stream_cmd.num_samps = total_num_samps; @@ -139,14 +143,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //loop until total number of samples reached size_t num_acc_samps = 0; //number of accumulated samples uhd::rx_metadata_t md; - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_recv_samps_per_packet()); + std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); uhd::transport::udp_simple::sptr udp_xport = uhd::transport::udp_simple::make_connected(addr, port); while(num_acc_samps < total_num_samps){ - size_t num_rx_samps = usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET + size_t num_rx_samps = rx_stream->recv( + &buff.front(), buff.size(), md ); //handle the error codes diff --git a/host/examples/rx_timed_samples.cpp b/host/examples/rx_timed_samples.cpp index 05cc0717b..6389375d9 100644 --- a/host/examples/rx_timed_samples.cpp +++ b/host/examples/rx_timed_samples.cpp @@ -70,6 +70,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Setting device timestamp to 0...") << std::endl; usrp->set_time_now(uhd::time_spec_t(0.0)); + //create a receive streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + //setup streaming std::cout << std::endl; std::cout << boost::format( @@ -85,7 +89,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::rx_metadata_t md; //allocate buffer to receive with samples - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_recv_samps_per_packet()); + std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); //the first call to recv() will block this many seconds before receiving double timeout = seconds_in_future + 0.1; //timeout (delay before receive + padding) @@ -93,10 +97,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ size_t num_acc_samps = 0; //number of accumulated samples while(num_acc_samps < total_num_samps){ //receive a single packet - size_t num_rx_samps = usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_ONE_PACKET, timeout + size_t num_rx_samps = rx_stream->recv( + &buff.front(), buff.size(), md, timeout ); //use a small timeout for subsequent packets diff --git a/host/examples/test_messages.cpp b/host/examples/test_messages.cpp index 60d108184..668f25ef3 100644 --- a/host/examples/test_messages.cpp +++ b/host/examples/test_messages.cpp @@ -36,24 +36,22 @@ namespace po = boost::program_options; * Issue a stream command with a time that is in the past. * We expect to get an inline late command message. */ -bool test_late_command_message(uhd::usrp::multi_usrp::sptr usrp){ +bool test_late_command_message(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr rx_stream, uhd::tx_streamer::sptr){ std::cout << "Test late command message... " << std::flush; usrp->set_time_now(uhd::time_spec_t(200.0)); //set time uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); - stream_cmd.num_samps = usrp->get_device()->get_max_recv_samps_per_packet(); + stream_cmd.num_samps = rx_stream->get_max_num_samps(); stream_cmd.stream_now = false; stream_cmd.time_spec = uhd::time_spec_t(100.0); //time in the past usrp->issue_stream_cmd(stream_cmd); - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_recv_samps_per_packet()); + std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); uhd::rx_metadata_t md; - const size_t nsamps = usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF + const size_t nsamps = rx_stream->recv( + &buff.front(), buff.size(), md ); switch(md.error_code){ @@ -85,27 +83,23 @@ bool test_late_command_message(uhd::usrp::multi_usrp::sptr usrp){ * Issue a stream command with num samps and more. * We expect to get an inline broken chain message. */ -bool test_broken_chain_message(uhd::usrp::multi_usrp::sptr usrp){ +bool test_broken_chain_message(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr rx_stream, uhd::tx_streamer::sptr){ std::cout << "Test broken chain message... " << std::flush; uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_MORE); stream_cmd.stream_now = true; - stream_cmd.num_samps = usrp->get_device()->get_max_recv_samps_per_packet(); + stream_cmd.num_samps = rx_stream->get_max_num_samps(); usrp->issue_stream_cmd(stream_cmd); - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_recv_samps_per_packet()); + std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); uhd::rx_metadata_t md; - usrp->get_device()->recv( //once for the requested samples - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF + rx_stream->recv( //once for the requested samples + &buff.front(), buff.size(), md ); - usrp->get_device()->recv( //again for the inline message - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF + rx_stream->recv( //again for the inline message + &buff.front(), buff.size(), md ); switch(md.error_code){ @@ -137,7 +131,7 @@ bool test_broken_chain_message(uhd::usrp::multi_usrp::sptr usrp){ * Send a burst of many samples that will fragment internally. * We expect to get an burst ack async message. */ -bool test_burst_ack_message(uhd::usrp::multi_usrp::sptr usrp){ +bool test_burst_ack_message(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr, uhd::tx_streamer::sptr tx_stream){ std::cout << "Test burst ack message... " << std::flush; uhd::tx_metadata_t md; @@ -146,12 +140,10 @@ bool test_burst_ack_message(uhd::usrp::multi_usrp::sptr usrp){ md.has_time_spec = false; //3 times max-sps guarantees a SOB, no burst, and EOB packet - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_send_samps_per_packet()*3); + std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps()*3); - usrp->get_device()->send( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF + tx_stream->send( + &buff.front(), buff.size(), md ); uhd::async_metadata_t async_md; @@ -185,7 +177,7 @@ bool test_burst_ack_message(uhd::usrp::multi_usrp::sptr usrp){ * Send a start of burst packet with no following end of burst. * We expect to get an underflow(within a burst) async message. */ -bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp){ +bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr, uhd::tx_streamer::sptr tx_stream){ std::cout << "Test underflow message... " << std::flush; uhd::tx_metadata_t md; @@ -193,10 +185,7 @@ bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp){ md.end_of_burst = false; md.has_time_spec = false; - usrp->get_device()->send("", 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send("", 0, md); uhd::async_metadata_t async_md; if (not usrp->get_device()->recv_async_msg(async_md, 1)){ @@ -229,7 +218,7 @@ bool test_underflow_message(uhd::usrp::multi_usrp::sptr usrp){ * Send a burst packet that occurs at a time in the past. * We expect to get a time error async message. */ -bool test_time_error_message(uhd::usrp::multi_usrp::sptr usrp){ +bool test_time_error_message(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::sptr, uhd::tx_streamer::sptr tx_stream){ std::cout << "Test time error message... " << std::flush; uhd::tx_metadata_t md; @@ -240,10 +229,7 @@ bool test_time_error_message(uhd::usrp::multi_usrp::sptr usrp){ usrp->set_time_now(uhd::time_spec_t(200.0)); //time at 200s - usrp->get_device()->send("", 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send("", 0, md); uhd::async_metadata_t async_md; if (not usrp->get_device()->recv_async_msg(async_md)){ @@ -276,16 +262,12 @@ void flush_async(uhd::usrp::multi_usrp::sptr usrp){ while (usrp->get_device()->recv_async_msg(async_md)){} } -void flush_recv(uhd::usrp::multi_usrp::sptr usrp){ - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_recv_samps_per_packet()); +void flush_recv(uhd::rx_streamer::sptr rx_stream){ + std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); uhd::rx_metadata_t md; do{ - usrp->get_device()->recv( - &buff.front(), buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::RECV_MODE_FULL_BUFF - ); + rx_stream->recv(&buff.front(), buff.size(), md); } while (md.error_code != uhd::rx_metadata_t::ERROR_CODE_TIMEOUT); } @@ -319,10 +301,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl; + //create RX and TX streamers + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::rx_streamer::sptr rx_stream = usrp->get_rx_streamer(stream_args); + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //------------------------------------------------------------------ // begin messages test //------------------------------------------------------------------ - static const uhd::dict<std::string, boost::function<bool(uhd::usrp::multi_usrp::sptr)> > + static const 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) @@ -342,9 +329,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::srand(uhd::time_spec_t::get_system_time().get_full_secs()); for (size_t n = 0; n < ntests; n++){ std::string key = tests.keys()[std::rand() % tests.size()]; - bool pass = tests[key](usrp); + bool pass = tests[key](usrp, rx_stream, tx_stream); flush_async(usrp); - flush_recv(usrp); + flush_recv(rx_stream); //store result if (pass) successes[key]++; diff --git a/host/examples/tx_bursts.cpp b/host/examples/tx_bursts.cpp index a66fb85b6..98853ce20 100644 --- a/host/examples/tx_bursts.cpp +++ b/host/examples/tx_bursts.cpp @@ -93,15 +93,19 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Setting device timestamp to 0...") << std::endl; usrp->set_time_now(uhd::time_spec_t(0.0)); + //create a transmit streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //allocate buffer with data to send - size_t spb = usrp->get_device()->get_max_send_samps_per_packet(); + const size_t spb = tx_stream->get_max_num_samps(); std::vector<std::complex<float> *> buffs; for(size_t i=0; i < usrp->get_num_mboards(); i++) { buffs.push_back(new std::complex<float>[spb]); for(size_t n=0; n < spb; n++) buffs.back()[n] = std::complex<float>(ampl, ampl); - } + }; std::signal(SIGINT, &sig_int_handler); if(repeat) std::cout << "Press Ctrl + C to quit..." << std::endl; @@ -127,10 +131,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ md.end_of_burst = samps_to_send < spb; //send a single packet - size_t num_tx_samps = usrp->get_device()->send( - buffs, samps_to_send, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_ONE_PACKET, timeout + size_t num_tx_samps = tx_stream->send( + buffs, samps_to_send, md, timeout ); //do not use time spec for subsequent packets diff --git a/host/examples/tx_samples_from_file.cpp b/host/examples/tx_samples_from_file.cpp index 03fc4c8d4..09939183b 100644 --- a/host/examples/tx_samples_from_file.cpp +++ b/host/examples/tx_samples_from_file.cpp @@ -29,10 +29,14 @@ namespace po = boost::program_options; template<typename samp_type> void send_from_file( uhd::usrp::multi_usrp::sptr usrp, - const uhd::io_type_t &io_type, + const std::string &cpu_format, const std::string &file, size_t samps_per_buff ){ + //create a transmit streamer + uhd::streamer_args stream_args(cpu_format); + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + uhd::tx_metadata_t md; md.start_of_burst = false; md.end_of_burst = false; @@ -47,10 +51,7 @@ template<typename samp_type> void send_from_file( md.end_of_burst = infile.eof(); - usrp->get_device()->send( - &buff.front(), num_tx_samps, md, io_type, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send(&buff.front(), num_tx_samps, md); } infile.close(); @@ -172,9 +173,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ } //send from file - if (type == "double") send_from_file<std::complex<double> >(usrp, uhd::io_type_t::COMPLEX_FLOAT64, file, spb); - else if (type == "float") send_from_file<std::complex<float> >(usrp, uhd::io_type_t::COMPLEX_FLOAT32, file, spb); - else if (type == "short") send_from_file<std::complex<short> >(usrp, uhd::io_type_t::COMPLEX_INT16, file, spb); + if (type == "double") send_from_file<std::complex<double> >(usrp, "fc64", file, spb); + else if (type == "float") send_from_file<std::complex<float> >(usrp, "fc32", file, spb); + else if (type == "short") send_from_file<std::complex<short> >(usrp, "sc16", file, spb); else throw std::runtime_error("Unknown type " + type); //finished diff --git a/host/examples/tx_timed_samples.cpp b/host/examples/tx_timed_samples.cpp index 1c222d414..3daf1974a 100644 --- a/host/examples/tx_timed_samples.cpp +++ b/host/examples/tx_timed_samples.cpp @@ -73,8 +73,12 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << boost::format("Setting device timestamp to 0...") << std::endl; usrp->set_time_now(uhd::time_spec_t(0.0)); + //create a transmit streamer + uhd::streamer_args stream_args("fc32"); //complex floats + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //allocate buffer with data to send - std::vector<std::complex<float> > buff(usrp->get_device()->get_max_send_samps_per_packet(), std::complex<float>(ampl, ampl)); + std::vector<std::complex<float> > buff(tx_stream->get_max_num_samps(), std::complex<float>(ampl, ampl)); //setup metadata for the first packet uhd::tx_metadata_t md; @@ -91,10 +95,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ size_t samps_to_send = std::min(total_num_samps - num_acc_samps, buff.size()); //send a single packet - size_t num_tx_samps = usrp->get_device()->send( - &buff.front(), samps_to_send, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_ONE_PACKET, timeout + size_t num_tx_samps = tx_stream->send( + &buff.front(), samps_to_send, md, timeout ); //do not use time spec for subsequent packets @@ -108,10 +110,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //send a mini EOB packet md.end_of_burst = true; - usrp->get_device()->send("", 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send("", 0, md); std::cout << std::endl << "Waiting for async burst ACK... " << std::flush; uhd::async_metadata_t async_md; diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp index 6e5c53642..9aa3ec71f 100644 --- a/host/examples/tx_waveforms.cpp +++ b/host/examples/tx_waveforms.cpp @@ -202,6 +202,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ const double cps = wave_freq/usrp->get_tx_rate(); double theta = 0; + //create a transmit streamer + //linearly map channels (index0 = channel0, index1 = channel1, ...) + uhd::streamer_args stream_args("fc32"); + for (size_t chan = 0; chan < usrp->get_tx_num_channels(); chan++) + stream_args.channels.push_back(chan); //linear mapping + uhd::tx_streamer::sptr tx_stream = usrp->get_tx_streamer(stream_args); + //allocate a buffer which we re-use for each channel std::vector<std::complex<float> > buff(spb); std::vector<std::complex<float> *> buffs(usrp->get_tx_num_channels(), &buff.front()); @@ -250,11 +257,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ theta = std::fmod(theta, 1); //send the entire contents of the buffer - usrp->get_device()->send( - buffs, buff.size(), md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send(buffs, buff.size(), md); md.start_of_burst = false; md.has_time_spec = false; @@ -262,10 +265,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //send a mini EOB packet md.end_of_burst = true; - usrp->get_device()->send("", 0, md, - uhd::io_type_t::COMPLEX_FLOAT32, - uhd::device::SEND_MODE_FULL_BUFF - ); + tx_stream->send("", 0, md); //finished std::cout << std::endl << "Done!" << std::endl << std::endl; |