summaryrefslogtreecommitdiff
path: root/gr-uhd/lib/gr_uhd_usrp_source.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/lib/gr_uhd_usrp_source.cc')
-rw-r--r--gr-uhd/lib/gr_uhd_usrp_source.cc55
1 files changed, 35 insertions, 20 deletions
diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc
index 09cced567d..fed8e66240 100644
--- a/gr-uhd/lib/gr_uhd_usrp_source.cc
+++ b/gr-uhd/lib/gr_uhd_usrp_source.cc
@@ -26,14 +26,6 @@
#include <boost/format.hpp>
/***********************************************************************
- * UHD Multi USRP Source
- **********************************************************************/
-uhd_usrp_source::uhd_usrp_source(gr_io_signature_sptr sig)
-:gr_sync_block("gr uhd usrp source", gr_make_io_signature(0, 0, 0), sig){
- /* NOP */
-}
-
-/***********************************************************************
* UHD Multi USRP Source Impl
**********************************************************************/
class uhd_usrp_source_impl : public uhd_usrp_source{
@@ -43,10 +35,15 @@ public:
const uhd::io_type_t &io_type,
size_t num_channels
):
- uhd_usrp_source(gr_make_io_signature(
- num_channels, num_channels, io_type.size
- )),
- _type(io_type)
+ gr_sync_block(
+ "gr uhd usrp source",
+ gr_make_io_signature(0, 0, 0),
+ gr_make_io_signature(num_channels, num_channels, io_type.size)
+ ),
+ _type(io_type),
+ _nchan(num_channels),
+ _stream_now(_nchan == 1),
+ _tmp_buffs(_nchan)
{
_dev = uhd::usrp::multi_usrp::make(device_addr);
}
@@ -169,16 +166,16 @@ public:
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items
){
- uhd::rx_metadata_t metadata; //not passed out of this block
-
+ //wait for a packet to become available
size_t num_samps = _dev->get_device()->recv(
- output_items, noutput_items, metadata,
- _type, uhd::device::RECV_MODE_FULL_BUFF, 1.0
+ output_items, noutput_items, _metadata,
+ _type, uhd::device::RECV_MODE_ONE_PACKET, 1.0
);
- switch(metadata.error_code){
+ //handle possible errors conditions
+ switch(_metadata.error_code){
case uhd::rx_metadata_t::ERROR_CODE_NONE:
- return num_samps;
+ break;
case uhd::rx_metadata_t::ERROR_CODE_OVERFLOW:
//ignore overflows and try work again
@@ -187,16 +184,30 @@ public:
default:
std::cout << boost::format(
"UHD source block got error code 0x%x"
- ) % metadata.error_code << std::endl;
+ ) % _metadata.error_code << std::endl;
return num_samps;
}
+
+ //advance the pointers and count by num_samps
+ noutput_items -= num_samps;
+ for (size_t i = 0; i < _nchan; i++){
+ _tmp_buffs[i] = static_cast<char *>(output_items[i]) + num_samps*_type.size;
+ }
+
+ //receive all available packets without timeout
+ num_samps += _dev->get_device()->recv(
+ _tmp_buffs, noutput_items, _metadata,
+ _type, uhd::device::RECV_MODE_FULL_BUFF, 0.0
+ );
+
+ return num_samps;
}
bool start(void){
//setup a stream command that starts streaming slightly in the future
static const double reasonable_delay = 0.1; //order of magnitude over RTT
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
- stream_cmd.stream_now = false;
+ stream_cmd.stream_now = _stream_now;
stream_cmd.time_spec = get_time_now() + uhd::time_spec_t(reasonable_delay);
_dev->issue_stream_cmd(stream_cmd);
return true;
@@ -210,6 +221,10 @@ public:
private:
uhd::usrp::multi_usrp::sptr _dev;
const uhd::io_type_t _type;
+ size_t _nchan;
+ bool _stream_now;
+ gr_vector_void_star _tmp_buffs;
+ uhd::rx_metadata_t _metadata;
};