From 7954c7dbfe5267cc3504598410b8ea73bef34fe5 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 16 Mar 2012 15:38:11 -0700 Subject: uhd: added multi-finite-aquisition --- gr-uhd/lib/gr_uhd_usrp_source.cc | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 2244238bd..33596e37b 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 Free Software Foundation, Inc. + * Copyright 2010-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -410,17 +410,45 @@ public: } std::vector > finite_acquisition(const size_t nsamps){ + if (_nchan != 1) throw std::runtime_error("finite_acquisition: usrp source has multiple channels, call finite_acquisition_v"); + return finite_acquisition_v(nsamps).front(); + } + + std::vector > > finite_acquisition_v(const size_t nsamps){ #ifdef GR_UHD_USE_STREAM_API + + //kludgy way to ensure rx streamer exsists + if (!_rx_stream){ + this->start(); + this->stop(); + } + + //create a multi-dimensional container to hold an array of sample buffers + std::vector > > samps(_nchan, std::vector >(nsamps)); + + //load the void* vector of buffer pointers + std::vector buffs(_nchan); + for (size_t i = 0; i < _nchan; i++){ + buffs[i] = &samps[i].front(); + } + + //tell the device to stream a finite amount uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); cmd.num_samps = nsamps; - cmd.stream_now = true; + cmd.stream_now = _stream_now; + static const double reasonable_delay = 0.1; //order of magnitude over RTT + cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay); _dev->issue_stream_cmd(cmd); - std::vector > samps(nsamps); + //receive samples until timeout const size_t actual_num_samps = _rx_stream->recv( - &samps.front(), nsamps, _metadata, 0.1 + buffs, nsamps, _metadata, 0.1 ); - samps.resize(actual_num_samps); + + //resize the resulting sample buffers + for (size_t i = 0; i < _nchan; i++){ + samps[i].resize(actual_num_samps); + } return samps; #else -- cgit