From 75c53194d36b4c3b02373b4feb916e6a9ad69b83 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 28 Feb 2011 17:03:47 -0800 Subject: uhd: only set has_time_spec when nchan > 1 Its important for multi-channel continuous, but not wanted in single-channel non-continuous. --- gr-uhd/lib/gr_uhd_usrp_sink.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gr-uhd') diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index 4598e54c2..b8b99a41a 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -45,7 +45,8 @@ public: num_channels, num_channels, io_type.size )), _type(io_type), - _nchan(num_channels) + _nchan(num_channels), + _has_time_spec(_nchan > 1) { _dev = uhd::usrp::multi_usrp::make(device_addr); } @@ -172,7 +173,7 @@ public: //send a mid-burst packet with time spec _metadata.start_of_burst = false; _metadata.end_of_burst = false; - _metadata.has_time_spec = true; + _metadata.has_time_spec = _has_time_spec; size_t num_sent = _dev->get_device()->send( input_items, noutput_items, _metadata, @@ -189,7 +190,7 @@ public: bool start(void){ _metadata.start_of_burst = true; _metadata.end_of_burst = false; - _metadata.has_time_spec = true; + _metadata.has_time_spec = _has_time_spec; _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01); _dev->get_device()->send( @@ -217,6 +218,7 @@ protected: uhd::usrp::multi_usrp::sptr _dev; const uhd::io_type_t _type; size_t _nchan; + bool _has_time_spec; uhd::tx_metadata_t _metadata; double _sample_rate; }; -- cgit From 75538e12300cb0d593792a986841ba2df9997c54 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 1 Mar 2011 16:31:14 -0800 Subject: uhd: work on gr_uhd_source work() function to reduce latency Wait on a single packet to become ready, then receive available packets without timeout. --- gr-uhd/lib/gr_uhd_usrp_source.cc | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'gr-uhd') diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 09cced567..1234ed7fe 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -46,7 +46,10 @@ public: uhd_usrp_source(gr_make_io_signature( num_channels, num_channels, io_type.size )), - _type(io_type) + _type(io_type), + _nchan(num_channels), + _stream_now(_nchan == 1), + _tmp_buffs(_nchan) { _dev = uhd::usrp::multi_usrp::make(device_addr); } @@ -169,16 +172,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 +190,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(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 +227,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; }; -- cgit From 7e2bd5adbf9828e6ca671ff5a176bff7ab48c557 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 7 Mar 2011 12:52:02 -0800 Subject: uhd: fix generation typo on uhd grc blocks io direction --- gr-uhd/grc/gen_uhd_usrp_blocks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gr-uhd') diff --git a/gr-uhd/grc/gen_uhd_usrp_blocks.py b/gr-uhd/grc/gen_uhd_usrp_blocks.py index 831d69fc4..8596e14a6 100644 --- a/gr-uhd/grc/gen_uhd_usrp_blocks.py +++ b/gr-uhd/grc/gen_uhd_usrp_blocks.py @@ -65,7 +65,7 @@ self.\$(id).set_bandwidth(\$bw$(n), $n) set_bandwidth(\$bw$(n), $n) #end for - Input Type + $(direction.title())put Type type enum