diff options
author | Jason Abele <jason@ettus.com> | 2011-11-28 18:52:36 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-11-28 22:01:28 -0500 |
commit | 6b46d2ce6e2038e57b1ea23df4d37edee6f58ccc (patch) | |
tree | f5fbee6ccc2c05bd1735e8404c04b66ec199c536 /host/examples/rx_samples_to_file.cpp | |
parent | 5574e1ec084bf6bc9b18e0c63880fbff96301396 (diff) | |
download | uhd-6b46d2ce6e2038e57b1ea23df4d37edee6f58ccc.tar.gz uhd-6b46d2ce6e2038e57b1ea23df4d37edee6f58ccc.tar.bz2 uhd-6b46d2ce6e2038e57b1ea23df4d37edee6f58ccc.zip |
rx_samples_to_file is not streaming the correct nsamps
"innovations" in rx_streamer cause it to clear stream commands
move stream command to be issued after rx_streamer is created
Diffstat (limited to 'host/examples/rx_samples_to_file.cpp')
-rw-r--r-- | host/examples/rx_samples_to_file.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/host/examples/rx_samples_to_file.cpp b/host/examples/rx_samples_to_file.cpp index 130009851..79f90c1ab 100644 --- a/host/examples/rx_samples_to_file.cpp +++ b/host/examples/rx_samples_to_file.cpp @@ -36,8 +36,10 @@ template<typename samp_type> void recv_to_file( uhd::usrp::multi_usrp::sptr usrp, const std::string &cpu_format, const std::string &file, - size_t samps_per_buff + size_t samps_per_buff, + int num_requested_samples ){ + int num_total_samps = 0; //create a receive streamer uhd::stream_args_t stream_args(cpu_format); uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args); @@ -47,10 +49,23 @@ template<typename samp_type> void recv_to_file( std::ofstream outfile(file.c_str(), std::ofstream::binary); bool overflow_message = true; - while(not stop_signal_called){ - size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md); + //setup streaming + uhd::stream_cmd_t stream_cmd((num_requested_samples == 0)? + uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: + uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE + ); + stream_cmd.num_samps = num_requested_samples; + stream_cmd.stream_now = true; + stream_cmd.time_spec = uhd::time_spec_t(); + usrp->issue_stream_cmd(stream_cmd); - if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) break; + while(not stop_signal_called and (num_requested_samples != num_total_samps or num_requested_samples == 0)){ + size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, 3.0); + + if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_TIMEOUT) { + std::cout << boost::format("Timeout while streaming") << std::endl; + break; + } if (md.error_code == uhd::rx_metadata_t::ERROR_CODE_OVERFLOW){ if (overflow_message){ overflow_message = false; @@ -70,6 +85,8 @@ template<typename samp_type> void recv_to_file( ) % md.error_code)); } + num_total_samps += num_rx_samps; + outfile.write((const char*)&buff.front(), num_rx_samps*sizeof(samp_type)); } @@ -181,23 +198,15 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ UHD_ASSERT_THROW(ref_locked.to_bool()); } - //setup streaming - uhd::stream_cmd_t stream_cmd((total_num_samps == 0)? - uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS: - uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE - ); - stream_cmd.num_samps = total_num_samps; - stream_cmd.stream_now = true; - usrp->issue_stream_cmd(stream_cmd); if (total_num_samps == 0){ std::signal(SIGINT, &sig_int_handler); std::cout << "Press Ctrl + C to stop streaming..." << std::endl; } //recv to file - 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); + if (type == "double") recv_to_file<std::complex<double> >(usrp, "fc64", file, spb, total_num_samps); + else if (type == "float") recv_to_file<std::complex<float> >(usrp, "fc32", file, spb, total_num_samps); + else if (type == "short") recv_to_file<std::complex<short> >(usrp, "sc16", file, spb, total_num_samps); else throw std::runtime_error("Unknown type " + type); //finished |