summaryrefslogtreecommitdiff
path: root/gr-uhd
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd')
-rw-r--r--gr-uhd/include/gr_uhd_usrp_source.h16
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc38
2 files changed, 47 insertions, 7 deletions
diff --git a/gr-uhd/include/gr_uhd_usrp_source.h b/gr-uhd/include/gr_uhd_usrp_source.h
index 8a799b397..23373e6fa 100644
--- a/gr-uhd/include/gr_uhd_usrp_source.h
+++ b/gr-uhd/include/gr_uhd_usrp_source.h
@@ -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
*
@@ -460,10 +460,22 @@ public:
* Convenience function for finite data acquisition.
* This is not to be used with the scheduler; rather,
* one can request samples from the USRP in python.
- * //TODO multi-channel
* //TODO assumes fc32
+ * \param nsamps the number of samples
+ * \return a vector of complex float samples
*/
virtual std::vector<std::complex<float> > finite_acquisition(const size_t nsamps) = 0;
+
+ /*!
+ * Convenience function for finite data acquisition.
+ * This is the multi-channel version of finite_acquisition;
+ * This is not to be used with the scheduler; rather,
+ * one can request samples from the USRP in python.
+ * //TODO assumes fc32
+ * \param nsamps the number of samples per channel
+ * \return a vector of buffers, where each buffer represents a channel
+ */
+ virtual std::vector<std::vector<std::complex<float> > > finite_acquisition_v(const size_t nsamps) = 0;
};
#endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */
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