diff options
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_sink.cc | 29 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_single_usrp_source.cc | 28 |
2 files changed, 38 insertions, 19 deletions
diff --git a/gr-uhd/lib/uhd_single_usrp_sink.cc b/gr-uhd/lib/uhd_single_usrp_sink.cc index 8cb3726d1..96f86c8db 100644 --- a/gr-uhd/lib/uhd_single_usrp_sink.cc +++ b/gr-uhd/lib/uhd_single_usrp_sink.cc @@ -41,7 +41,7 @@ public: const std::string &args, const uhd::io_type_t &type, size_t num_channels - ) : uhd_single_usrp_sink(gr_make_io_signature(num_channels, num_channels, type.size)), _type(type) + ) : uhd_single_usrp_sink(gr_make_io_signature(num_channels, num_channels, type.size)), _type(type), _nchan(num_channels) { _dev = uhd::usrp::single_usrp::make(args); } @@ -134,9 +134,36 @@ public: ); } + //Send an empty start-of-burst packet to begin streaming. + //This is not necessary since all packets are marked SOB. + bool start(void){ + uhd::tx_metadata_t metadata; + metadata.start_of_burst = true; + + _dev->get_device()->send( + gr_vector_const_void_star(_nchan), 0, metadata, + _type, uhd::device::SEND_MODE_ONE_PACKET + ); + return true; + } + + //Send an empty end-of-burst packet to end streaming. + //Ending the burst avoids an underflow error on stop. + bool stop(void){ + uhd::tx_metadata_t metadata; + metadata.end_of_burst = true; + + _dev->get_device()->send( + gr_vector_const_void_star(_nchan), 0, metadata, + _type, uhd::device::SEND_MODE_ONE_PACKET + ); + return true; + } + protected: uhd::usrp::single_usrp::sptr _dev; const uhd::io_type_t _type; + size_t _nchan; }; /*********************************************************************** diff --git a/gr-uhd/lib/uhd_single_usrp_source.cc b/gr-uhd/lib/uhd_single_usrp_source.cc index ff9ba0653..b5e39b5a4 100644 --- a/gr-uhd/lib/uhd_single_usrp_source.cc +++ b/gr-uhd/lib/uhd_single_usrp_source.cc @@ -46,11 +46,6 @@ public: ) : uhd_single_usrp_source(gr_make_io_signature(num_channels, num_channels, type.size)), _type(type) { _dev = uhd::usrp::single_usrp::make(args); - set_streaming(false); - } - - ~uhd_single_usrp_source_impl(void){ - set_streaming(false); } void set_subdev_spec(const std::string &spec){ @@ -128,10 +123,6 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - //conditionally start streaming in the work call - //this prevents streaming before the runtime is ready - if (not _is_streaming) set_streaming(true); - uhd::rx_metadata_t metadata; //not passed out of this block size_t num_samps = _dev->get_device()->recv( @@ -155,18 +146,19 @@ public: } } + bool start(void){ + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); + return true; + } + + bool stop(void){ + _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); + return true; + } + private: uhd::usrp::single_usrp::sptr _dev; const uhd::io_type_t _type; - bool _is_streaming; - - void set_streaming(bool enb){ - if (enb) - _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS); - else - _dev->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); - _is_streaming = enb; - } }; |