diff options
author | Sean Nowlan <sean.nowlan@gtri.gatech.edu> | 2014-02-23 23:02:32 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2014-04-26 23:31:54 +0200 |
commit | e05164d15e8921760ff3649ae058517cab9dee40 (patch) | |
tree | d7d83840a61dcfa2a093ad3694de2dd153188ae5 /gr-uhd/examples/c++ | |
parent | 754cfa70bc7441642f7c04e8998d0582b482d95c (diff) |
gr-uhd: added tagged stream support
Diffstat (limited to 'gr-uhd/examples/c++')
-rw-r--r-- | gr-uhd/examples/c++/tag_source_demo.h | 42 | ||||
-rw-r--r-- | gr-uhd/examples/c++/tags_demo.cc | 8 |
2 files changed, 43 insertions, 7 deletions
diff --git a/gr-uhd/examples/c++/tag_source_demo.h b/gr-uhd/examples/c++/tag_source_demo.h index 71fb94482a..904087cf9b 100644 --- a/gr-uhd/examples/c++/tag_source_demo.h +++ b/gr-uhd/examples/c++/tag_source_demo.h @@ -35,7 +35,8 @@ public: const double start_fracs, const double samp_rate, const double idle_duration, - const double burst_duration + const double burst_duration, + const std::string &length_tag_key = "" ): sync_block( "uhd tag source demo", @@ -48,7 +49,9 @@ public: _samps_per_burst(samp_rate*burst_duration), _cycle_duration(idle_duration + burst_duration), _samps_left_in_burst(1), //immediate EOB - _do_new_burst(false) + _do_new_burst(false), + _firstrun(not length_tag_key.empty()), + _length_tag_key(length_tag_key) { //NOP } @@ -80,6 +83,19 @@ public: this->add_item_tag(0/*chan0*/, tag_count, key, value, srcid); } + void make_length_tag(const uint64_t tag_count, const uint64_t burst_len) + { + if (_length_tag_key.empty()){ + //no length_tag was specified at initialization; make a tx_sob tag instead + this->make_sob_tag(tag_count); + return; + } + const pmt::pmt_t key = pmt::string_to_symbol(_length_tag_key); + const pmt::pmt_t value = pmt::from_long((long)burst_len); + const pmt::pmt_t srcid = pmt::string_to_symbol(this->name()); + this->add_item_tag(0/*chan0*/, tag_count, key, value, srcid); + } + int work( int noutput_items, gr_vector_const_void_star &input_items, @@ -98,7 +114,18 @@ public: _do_new_burst = false; _samps_left_in_burst = _samps_per_burst; - this->make_sob_tag(this->nitems_written(0)); + if (_length_tag_key.empty()) + this->make_sob_tag(this->nitems_written(0)); + else +#if 1 + this->make_length_tag(this->nitems_written(0), _samps_left_in_burst); +#else + //Test usrp_sink's ability to cancel remainder of burst if new length_tag is found early + //sets burst time to 10% greater than the cycle duration to guarantee early length_tag + //In a real implementation the user should guard against this so that the number of + //samples promised by the length_tag are actually processed by the usrp_sink. + this->make_length_tag(this->nitems_written(0), uint64_t(1.1 * _samp_rate * _cycle_duration)); +#endif this->make_time_tag(this->nitems_written(0)); _time_fracs += _cycle_duration; @@ -111,7 +138,12 @@ public: //Tag an end of burst and return early. //the next work call will be a start of burst. if (_samps_left_in_burst < size_t(noutput_items)){ - this->make_eob_tag(this->nitems_written(0) + _samps_left_in_burst - 1); + if (_length_tag_key.empty()) + this->make_eob_tag(this->nitems_written(0) + _samps_left_in_burst - 1); + else if (_firstrun){ + _firstrun = false; + this->make_length_tag(this->nitems_written(0), 1); + } _do_new_burst = true; noutput_items = _samps_left_in_burst; } @@ -128,5 +160,7 @@ private: const double _cycle_duration; uint64_t _samps_left_in_burst; bool _do_new_burst; + bool _firstrun; + const std::string _length_tag_key; }; diff --git a/gr-uhd/examples/c++/tags_demo.cc b/gr-uhd/examples/c++/tags_demo.cc index 0f87109109..a4e23175c1 100644 --- a/gr-uhd/examples/c++/tags_demo.cc +++ b/gr-uhd/examples/c++/tags_demo.cc @@ -43,7 +43,7 @@ void sig_int_handler(int){stop_signal_called = true;} **********************************************************************/ int main(int argc, char *argv[]){ - std::string device_addr; + std::string device_addr, length_tag; double center_freq, samp_rate, burst_dur, idle_dur; //setup the program options @@ -55,6 +55,7 @@ int main(int argc, char *argv[]){ ("freq", po::value<double>(¢er_freq)->default_value(10e6), "the center frequency in Hz") ("burst", po::value<double>(&burst_dur)->default_value(0.1), "the duration of each burst in seconds") ("idle", po::value<double>(&idle_dur)->default_value(0.05), "idle time between bursts in seconds") + ("length_tag", po::value<std::string>(&length_tag)->default_value(""), "the length tag key name") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -95,14 +96,15 @@ int main(int argc, char *argv[]){ //-- make the usrp sink test blocks //------------------------------------------------------------------ gr::uhd::usrp_sink::sptr usrp_sink = gr::uhd::usrp_sink::make - (device_addr, uhd::stream_args_t("fc32")); + (device_addr, uhd::stream_args_t("fc32"), length_tag); usrp_sink->set_samp_rate(samp_rate); usrp_sink->set_center_freq(center_freq); const uhd::time_spec_t time_now = usrp_sink->get_time_now(); + const double actual_samp_rate = usrp_sink->get_samp_rate(); boost::shared_ptr<tag_source_demo> tag_source = boost::make_shared<tag_source_demo>( time_now.get_full_secs() + 1, time_now.get_frac_secs(), //time now + 1 second - samp_rate, idle_dur, burst_dur + actual_samp_rate, idle_dur, burst_dur ); //------------------------------------------------------------------ |