diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2019-08-07 21:45:12 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2019-08-09 23:04:28 +0200 |
commit | f7bbf2c1d8d780294f3e016aff239ca35eb6516e (patch) | |
tree | e09ab6112e02b2215b2d59ac24d3d6ea2edac745 /gr-uhd/examples/c++ | |
parent | 78431dc6941e3acc67c858277dfe4a0ed583643c (diff) |
Tree: clang-format without the include sorting
Diffstat (limited to 'gr-uhd/examples/c++')
-rw-r--r-- | gr-uhd/examples/c++/tag_sink_demo.h | 46 | ||||
-rw-r--r-- | gr-uhd/examples/c++/tag_source_demo.h | 104 | ||||
-rw-r--r-- | gr-uhd/examples/c++/tags_demo.cc | 71 |
3 files changed, 116 insertions, 105 deletions
diff --git a/gr-uhd/examples/c++/tag_sink_demo.h b/gr-uhd/examples/c++/tag_sink_demo.h index e96cd9ec3c..8919a2d6b5 100644 --- a/gr-uhd/examples/c++/tag_sink_demo.h +++ b/gr-uhd/examples/c++/tag_sink_demo.h @@ -29,37 +29,37 @@ class tag_sink_demo : public gr::sync_block { public: - - tag_sink_demo(void): - sync_block( - "uhd tag sink demo", - gr::io_signature::make(1, 1, sizeof(std::complex<float>)), - gr::io_signature::make(0, 0, 0) - ) + tag_sink_demo(void) + : sync_block("uhd tag sink demo", + gr::io_signature::make(1, 1, sizeof(std::complex<float>)), + gr::io_signature::make(0, 0, 0)) { - //NOP + // NOP } - int work( - int ninput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items - ){ - //grab all "rx time" tags in this work call + int work(int ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) + { + // grab all "rx time" tags in this work call const uint64_t samp0_count = this->nitems_read(0); std::vector<gr::tag_t> rx_time_tags; - get_tags_in_range(rx_time_tags, 0, samp0_count, samp0_count + ninput_items, pmt::string_to_symbol("rx_time")); + get_tags_in_range(rx_time_tags, + 0, + samp0_count, + samp0_count + ninput_items, + pmt::string_to_symbol("rx_time")); - //print all tags - BOOST_FOREACH(const gr::tag_t &rx_time_tag, rx_time_tags){ + // print all tags + BOOST_FOREACH (const gr::tag_t& rx_time_tag, rx_time_tags) { const uint64_t offset = rx_time_tag.offset; - const pmt::pmt_t &value = rx_time_tag.value; + const pmt::pmt_t& value = rx_time_tag.value; - std::cout << boost::format("Full seconds %u, Frac seconds %f, abs sample offset %u") - % pmt::to_uint64(pmt::tuple_ref(value, 0)) - % pmt::to_double(pmt::tuple_ref(value, 1)) - % offset - << std::endl; + std::cout << boost::format( + "Full seconds %u, Frac seconds %f, abs sample offset %u") % + pmt::to_uint64(pmt::tuple_ref(value, 0)) % + pmt::to_double(pmt::tuple_ref(value, 1)) % offset + << std::endl; } return ninput_items; diff --git a/gr-uhd/examples/c++/tag_source_demo.h b/gr-uhd/examples/c++/tag_source_demo.h index 1690553882..e176da828d 100644 --- a/gr-uhd/examples/c++/tag_source_demo.h +++ b/gr-uhd/examples/c++/tag_source_demo.h @@ -29,42 +29,37 @@ class tag_source_demo : public gr::sync_block { public: - - tag_source_demo( - const uint64_t start_secs, - const double start_fracs, - const double samp_rate, - const double idle_duration, - const double burst_duration, - const std::string &length_tag_name = "" - ): - sync_block( - "uhd tag source demo", - gr::io_signature::make(0, 0, 0), - gr::io_signature::make(1, 1, sizeof(std::complex<float>)) - ), - _time_secs(start_secs), - _time_fracs(start_fracs), - _samp_rate(samp_rate), - _samps_per_burst(samp_rate*burst_duration), - _cycle_duration(idle_duration + burst_duration), - _samps_left_in_burst(1), //immediate EOB - _do_new_burst(false), - _firstrun(!length_tag_name.empty()), - _length_tag_key(length_tag_name.empty() ? pmt::PMT_NIL : pmt::string_to_symbol(length_tag_name)) + tag_source_demo(const uint64_t start_secs, + const double start_fracs, + const double samp_rate, + const double idle_duration, + const double burst_duration, + const std::string& length_tag_name = "") + : sync_block("uhd tag source demo", + gr::io_signature::make(0, 0, 0), + gr::io_signature::make(1, 1, sizeof(std::complex<float>))), + _time_secs(start_secs), + _time_fracs(start_fracs), + _samp_rate(samp_rate), + _samps_per_burst(samp_rate * burst_duration), + _cycle_duration(idle_duration + burst_duration), + _samps_left_in_burst(1), // immediate EOB + _do_new_burst(false), + _firstrun(!length_tag_name.empty()), + _length_tag_key(length_tag_name.empty() + ? pmt::PMT_NIL + : pmt::string_to_symbol(length_tag_name)) { - //NOP + // NOP } void make_time_tag(const uint64_t tag_count) { const pmt::pmt_t key = pmt::string_to_symbol("tx_time"); - const pmt::pmt_t value = pmt::make_tuple( - pmt::from_uint64(_time_secs), - pmt::from_double(_time_fracs) - ); + const pmt::pmt_t value = + pmt::make_tuple(pmt::from_uint64(_time_secs), pmt::from_double(_time_fracs)); const pmt::pmt_t srcid = pmt::string_to_symbol(this->name()); - this->add_item_tag(0/*chan0*/, tag_count, key, value, srcid); + this->add_item_tag(0 /*chan0*/, tag_count, key, value, srcid); } void make_sob_tag(const uint64_t tag_count) @@ -72,7 +67,7 @@ public: const pmt::pmt_t key = pmt::string_to_symbol("tx_sob"); const pmt::pmt_t value = pmt::PMT_T; const pmt::pmt_t srcid = pmt::string_to_symbol(this->name()); - this->add_item_tag(0/*chan0*/, tag_count, key, value, srcid); + this->add_item_tag(0 /*chan0*/, tag_count, key, value, srcid); } void make_eob_tag(const uint64_t tag_count) @@ -80,36 +75,36 @@ public: const pmt::pmt_t key = pmt::string_to_symbol("tx_eob"); const pmt::pmt_t value = pmt::PMT_T; const pmt::pmt_t srcid = pmt::string_to_symbol(this->name()); - this->add_item_tag(0/*chan0*/, tag_count, key, value, srcid); + 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 (pmt::is_null(_length_tag_key)) { - //no length_tag was specified at initialization; make a tx_sob tag instead + // 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 = _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); + this->add_item_tag(0 /*chan0*/, tag_count, key, value, srcid); } - int work( - int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + int work(int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) { - //load the output with a constant - std::complex<float> *output = reinterpret_cast<std::complex<float> *>(output_items[0]); + // load the output with a constant + std::complex<float>* output = + reinterpret_cast<std::complex<float>*>(output_items[0]); for (size_t i = 0; i < size_t(noutput_items); i++) { output[i] = std::complex<float>(0.7, 0.7); } - //Handle the start of burst condition. - //Tag a start of burst and timestamp. - //Increment the time for the next burst. + // Handle the start of burst condition. + // Tag a start of burst and timestamp. + // Increment the time for the next burst. if (_do_new_burst) { _do_new_burst = false; _samps_left_in_burst = _samps_per_burst; @@ -120,27 +115,29 @@ public: #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)); + // 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; - double intpart; //normalize + double intpart; // normalize _time_fracs = std::modf(_time_fracs, &intpart); _time_secs += uint64_t(intpart); } - //Handle the end of burst condition. - //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)){ + // Handle the end of burst condition. + // 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)) { if (pmt::is_null(_length_tag_key)) this->make_eob_tag(this->nitems_written(0) + _samps_left_in_burst - 1); - else if (_firstrun){ + else if (_firstrun) { _firstrun = false; this->make_length_tag(this->nitems_written(0), 1); } @@ -162,5 +159,4 @@ private: bool _do_new_burst; bool _firstrun; const pmt::pmt_t _length_tag_key; - }; diff --git a/gr-uhd/examples/c++/tags_demo.cc b/gr-uhd/examples/c++/tags_demo.cc index 73c8b48d1f..e6da6a2600 100644 --- a/gr-uhd/examples/c++/tags_demo.cc +++ b/gr-uhd/examples/c++/tags_demo.cc @@ -37,39 +37,51 @@ namespace po = boost::program_options; * Signal handlers **********************************************************************/ static bool stop_signal_called = false; -void sig_int_handler(int){stop_signal_called = true;} +void sig_int_handler(int) { stop_signal_called = true; } /*********************************************************************** * Main w/ program options **********************************************************************/ -int UHD_SAFE_MAIN(int argc, char *argv[]){ +int UHD_SAFE_MAIN(int argc, char* argv[]) +{ std::string device_addr, length_tag; double center_freq, samp_rate, burst_dur, idle_dur; - //setup the program options + // setup the program options po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value<std::string>(&device_addr)->default_value(""), "the device address in string format") - ("rate", po::value<double>(&samp_rate)->default_value(1e6), "the sample rate in samples per second") - ("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") - ; + desc.add_options()("help", "help message")( + "addr", + po::value<std::string>(&device_addr)->default_value(""), + "the device address in string format")( + "rate", + po::value<double>(&samp_rate)->default_value(1e6), + "the sample rate in samples per second")( + "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); po::notify(vm); - //print the help message - if (vm.count("help")){ - std::cout - << boost::format("UHD Tags Demo %s") % desc << std::endl - << "The tags sink demo block will print USRP source time stamps." << std::endl - << "The tags source demo block will send bursts to the USRP sink." << std::endl - << "Look at the USRP output on a scope to see the timed bursts." << std::endl - << std::endl; + // print the help message + if (vm.count("help")) { + std::cout << boost::format("UHD Tags Demo %s") % desc << std::endl + << "The tags sink demo block will print USRP source time stamps." + << std::endl + << "The tags source demo block will send bursts to the USRP sink." + << std::endl + << "Look at the USRP output on a scope to see the timed bursts." + << std::endl + << std::endl; return ~0; } @@ -81,8 +93,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //------------------------------------------------------------------ //-- make the usrp source test blocks //------------------------------------------------------------------ - gr::uhd::usrp_source::sptr usrp_source = gr::uhd::usrp_source::make - (device_addr, uhd::stream_args_t("fc32")); + gr::uhd::usrp_source::sptr usrp_source = + gr::uhd::usrp_source::make(device_addr, uhd::stream_args_t("fc32")); usrp_source->set_samp_rate(samp_rate); usrp_source->set_center_freq(center_freq); @@ -96,17 +108,20 @@ int UHD_SAFE_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"), length_tag); + gr::uhd::usrp_sink::sptr usrp_sink = + gr::uhd::usrp_sink::make(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 - actual_samp_rate, idle_dur, burst_dur, length_tag - ); + time_now.get_full_secs() + 1, + time_now.get_frac_secs(), // time now + 1 second + actual_samp_rate, + idle_dur, + burst_dur, + length_tag); //------------------------------------------------------------------ //-- connect the usrp sink test blocks @@ -124,7 +139,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //------------------------------------------------------------------ std::signal(SIGINT, &sig_int_handler); std::cout << "press ctrl + c to exit" << std::endl; - while (not stop_signal_called){ + while (not stop_signal_called) { boost::this_thread::sleep(boost::posix_time::milliseconds(100)); } |