diff options
author | Josh Blum | 2012-03-16 15:38:11 -0700 |
---|---|---|
committer | Josh Blum | 2012-03-23 14:10:04 -0700 |
commit | 7954c7dbfe5267cc3504598410b8ea73bef34fe5 (patch) | |
tree | c05d708d2b7ed65cfceac852027c72c6f0c7a52d /gr-uhd/lib/gr_uhd_usrp_source.cc | |
parent | 708b7e46a9407710f9aab9444561d464fa56c9b9 (diff) | |
download | gnuradio-7954c7dbfe5267cc3504598410b8ea73bef34fe5.tar.gz gnuradio-7954c7dbfe5267cc3504598410b8ea73bef34fe5.tar.bz2 gnuradio-7954c7dbfe5267cc3504598410b8ea73bef34fe5.zip |
uhd: added multi-finite-aquisition
Diffstat (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc')
-rw-r--r-- | gr-uhd/lib/gr_uhd_usrp_source.cc | 38 |
1 files changed, 33 insertions, 5 deletions
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<std::complex<float> > 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<std::vector<std::complex<float> > > 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<std::vector<std::complex<float> > > samps(_nchan, std::vector<std::complex<float> >(nsamps)); + + //load the void* vector of buffer pointers + std::vector<void *> 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<std::complex<float> > 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 |