From 91ace5a39a171ec7367c4030a1739d2f709eaed6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 22 Sep 2011 20:03:47 -0700 Subject: uhd: added documentation and tag implementations --- gr-uhd/lib/gr_uhd_usrp_sink.cc | 85 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 9 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_sink.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index ce9d89d8d..56b2800c1 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -21,8 +21,13 @@ #include #include +#include #include +static const pmt::pmt_t SOB_KEY = pmt::pmt_string_to_symbol("tx_sob"); +static const pmt::pmt_t EOB_KEY = pmt::pmt_string_to_symbol("tx_eob"); +static const pmt::pmt_t TIME_KEY = pmt::pmt_string_to_symbol("tx_time"); + /*********************************************************************** * UHD Multi USRP Sink Impl **********************************************************************/ @@ -39,8 +44,7 @@ public: gr_make_io_signature(0, 0, 0) ), _type(io_type), - _nchan(num_channels), - _has_time_spec(_nchan > 1) + _nchan(num_channels) { _dev = uhd::usrp::multi_usrp::make(device_addr); } @@ -176,17 +180,22 @@ public: * Work **********************************************************************/ int work( - int noutput_items, + int ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ //send a mid-burst packet with time spec _metadata.start_of_burst = false; _metadata.end_of_burst = false; - _metadata.has_time_spec = _has_time_spec; - size_t num_sent = _dev->get_device()->send( - input_items, noutput_items, _metadata, + //collect tags in this work() + const uint64_t samp0_count = nitems_read(0); + get_tags_in_range(_tags, 0, samp0_count, samp0_count + ninput_items); + if (not _tags.empty()) tag_work(ninput_items); + + //send all ninput_items with metadata + const size_t num_sent = _dev->get_device()->send( + input_items, ninput_items, _metadata, _type, uhd::device::SEND_MODE_FULL_BUFF, 1.0 ); @@ -195,12 +204,68 @@ public: return num_sent; } +/*********************************************************************** + * Tag Work + **********************************************************************/ + inline void tag_work(int &ninput_items){ + //the for loop below assumes tags sorted by count low -> high + std::sort(_tags.begin(), _tags.end(), gr_tags::nitems_compare); + + //extract absolute sample counts + const pmt::pmt_t &tag0 = _tags.front(); + const uint64_t tag0_count = gr_tags::get_nitems(tag0); + const uint64_t samp0_count = nitems_read(0); + + //only transmit nsamples from 0 to the first tag + //this ensures that the next work starts on a tag + if (samp0_count != tag0_count){ + ninput_items = tag0_count - samp0_count; + return; + } + + //time will not be set unless a time tag is found + _metadata.has_time_spec = false; + + //process all of the tags found with the same count as tag0 + BOOST_FOREACH(const pmt::pmt_t &my_tag, _tags){ + const uint64_t my_tag_count = gr_tags::get_nitems(my_tag); + + //determine how many samples to send... + //from zero until the next tag or end of work + if (my_tag_count != tag0_count){ + ninput_items = my_tag_count - samp0_count; + break; + } + + //handle end of burst with a mini end of burst packet + else if (pmt::pmt_equal(gr_tags::get_key(my_tag), EOB_KEY)){ + _metadata.end_of_burst = pmt::pmt_to_bool(my_tag); + ninput_items = 1; + return; + } + + //set the start of burst flag in the metadata + else if (pmt::pmt_equal(gr_tags::get_key(my_tag), SOB_KEY)){ + _metadata.start_of_burst = pmt::pmt_to_bool(my_tag); + } + + //set the time specification in the metadata + else if (pmt::pmt_equal(gr_tags::get_key(my_tag), TIME_KEY)){ + _metadata.has_time_spec = true; + _metadata.time_spec = uhd::time_spec_t( + pmt::pmt_to_uint64(pmt_tuple_ref(my_tag, 0)), + pmt::pmt_to_double(pmt_tuple_ref(my_tag, 1)) + ); + } + } + } + //Send an empty start-of-burst packet to begin streaming. //Set at a time in the near future to avoid late packets. bool start(void){ _metadata.start_of_burst = true; _metadata.end_of_burst = false; - _metadata.has_time_spec = _has_time_spec; + _metadata.has_time_spec = _nchan > 1; _metadata.time_spec = get_time_now() + uhd::time_spec_t(0.01); _dev->get_device()->send( @@ -224,13 +289,15 @@ public: return true; } -protected: +private: 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; + + //stream tags related stuff + std::vector _tags; }; /*********************************************************************** -- cgit From 7da9d688406db097f518b3eed2047fde60e1aa0e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 23 Sep 2011 13:51:31 -0700 Subject: uhd: tweaks + tested working tags implementation --- gr-uhd/lib/gr_uhd_usrp_sink.cc | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_sink.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index 56b2800c1..852a730db 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -191,7 +191,7 @@ public: //collect tags in this work() const uint64_t samp0_count = nitems_read(0); get_tags_in_range(_tags, 0, samp0_count, samp0_count + ninput_items); - if (not _tags.empty()) tag_work(ninput_items); + if (not _tags.empty()) this->tag_work(ninput_items); //send all ninput_items with metadata const size_t num_sent = _dev->get_device()->send( @@ -214,7 +214,7 @@ public: //extract absolute sample counts const pmt::pmt_t &tag0 = _tags.front(); const uint64_t tag0_count = gr_tags::get_nitems(tag0); - const uint64_t samp0_count = nitems_read(0); + const uint64_t samp0_count = this->nitems_read(0); //only transmit nsamples from 0 to the first tag //this ensures that the next work starts on a tag @@ -229,6 +229,8 @@ public: //process all of the tags found with the same count as tag0 BOOST_FOREACH(const pmt::pmt_t &my_tag, _tags){ const uint64_t my_tag_count = gr_tags::get_nitems(my_tag); + const pmt::pmt_t &key = gr_tags::get_key(my_tag); + const pmt::pmt_t &value = gr_tags::get_value(my_tag); //determine how many samples to send... //from zero until the next tag or end of work @@ -238,23 +240,23 @@ public: } //handle end of burst with a mini end of burst packet - else if (pmt::pmt_equal(gr_tags::get_key(my_tag), EOB_KEY)){ - _metadata.end_of_burst = pmt::pmt_to_bool(my_tag); + else if (pmt::pmt_equal(key, EOB_KEY)){ + _metadata.end_of_burst = pmt::pmt_to_bool(value); ninput_items = 1; return; } //set the start of burst flag in the metadata - else if (pmt::pmt_equal(gr_tags::get_key(my_tag), SOB_KEY)){ - _metadata.start_of_burst = pmt::pmt_to_bool(my_tag); + else if (pmt::pmt_equal(key, SOB_KEY)){ + _metadata.start_of_burst = pmt::pmt_to_bool(value); } //set the time specification in the metadata - else if (pmt::pmt_equal(gr_tags::get_key(my_tag), TIME_KEY)){ + else if (pmt::pmt_equal(key, TIME_KEY)){ _metadata.has_time_spec = true; _metadata.time_spec = uhd::time_spec_t( - pmt::pmt_to_uint64(pmt_tuple_ref(my_tag, 0)), - pmt::pmt_to_double(pmt_tuple_ref(my_tag, 1)) + pmt::pmt_to_uint64(pmt_tuple_ref(value, 0)), + pmt::pmt_to_double(pmt_tuple_ref(value, 1)) ); } } -- cgit From ab2d7789629cdbfc7091100bfbe8ef02a05aec7e Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 26 Sep 2011 08:30:08 -0700 Subject: uhd: tweaks for some minor details --- gr-uhd/lib/gr_uhd_usrp_sink.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_sink.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index 852a730db..e22b5840e 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -180,10 +180,12 @@ public: * Work **********************************************************************/ int work( - int ninput_items, + int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ + const int ninput_items = noutput_items; //cuz its a sync block + //send a mid-burst packet with time spec _metadata.start_of_burst = false; _metadata.end_of_burst = false; -- cgit From dd63208289584f764ad69f36fbd552def3c761e5 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 26 Sep 2011 13:17:39 -0400 Subject: uhd: can't be const to go into tag_work, which might change it. --- gr-uhd/lib/gr_uhd_usrp_sink.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gr-uhd/lib/gr_uhd_usrp_sink.cc') diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index e22b5840e..a780f0551 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -184,8 +184,8 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items ){ - const int ninput_items = noutput_items; //cuz its a sync block - + int ninput_items = noutput_items; //cuz its a sync block + //send a mid-burst packet with time spec _metadata.start_of_burst = false; _metadata.end_of_burst = false; -- cgit