From 292daa389b0545145b3424e33ee7e1672315728a Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Mon, 2 Oct 2023 19:35:03 +0000 Subject: [PATCH] add tag_now parameter to retune*fft --- grc/iqtlabs_retune_fft.block.yml | 7 +++-- grc/iqtlabs_retune_pre_fft.block.yml | 6 ++-- include/gnuradio/iqtlabs/retune_fft.h | 2 +- include/gnuradio/iqtlabs/retune_pre_fft.h | 2 +- lib/base_impl.cc | 9 ++++++ lib/base_impl.h | 1 + lib/retune_fft_impl.cc | 29 ++++++++++--------- lib/retune_fft_impl.h | 3 +- lib/retune_pre_fft_impl.cc | 24 +++++++-------- lib/retune_pre_fft_impl.h | 3 +- python/iqtlabs/bindings/retune_fft_python.cc | 3 +- .../iqtlabs/bindings/retune_pre_fft_python.cc | 3 +- python/iqtlabs/qa_retune_fft.py | 2 ++ 13 files changed, 56 insertions(+), 38 deletions(-) diff --git a/grc/iqtlabs_retune_fft.block.yml b/grc/iqtlabs_retune_fft.block.yml index e7ab4ea3..5cdcf526 100644 --- a/grc/iqtlabs_retune_fft.block.yml +++ b/grc/iqtlabs_retune_fft.block.yml @@ -48,6 +48,7 @@ documentation: |- description: a string description to be included with each update. rotate_secs: if > 0, use a new epoch timestamped directory every N seconds. pre_fft: if True, tuning is controlled by the retune_pre_fft block. + tag_now: if True, send "tag:now" tag along with tuning message. example JSON output: { "ts": , "sweep start": , @@ -64,7 +65,7 @@ templates: iqtlabs.retune_fft(${tag}, ${vlen}, ${nfft}, ${samp_rate}, ${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, ${fft_min}, ${fft_max}, ${sdir}, ${write_step_fft}, ${bucket_range}, - ${tuning_ranges}, ${description}, ${rotate_secs}, ${pre_fft}) + ${tuning_ranges}, ${description}, ${rotate_secs}, ${pre_fft}, ${tag_now}) cpp_templates: includes: ['#include '] @@ -74,7 +75,7 @@ cpp_templates: ${samp_rate}, ${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, ${fft_min}, ${fft_max}, ${sdir}, ${write_step_fft}, ${bucket_range}, ${tuning_ranges}, ${description}, ${rotate_secs}, - ${pre_fft}); + ${pre_fft}, ${tag_now}); link: ['libgnuradio-iqtlabs.so'] asserts: @@ -121,6 +122,8 @@ parameters: dtype: string - id: rotate_secs dtype: int + - id: tag_now + dtype: bool inputs: - label: input diff --git a/grc/iqtlabs_retune_pre_fft.block.yml b/grc/iqtlabs_retune_pre_fft.block.yml index 4e33322d..0eb3731f 100644 --- a/grc/iqtlabs_retune_pre_fft.block.yml +++ b/grc/iqtlabs_retune_pre_fft.block.yml @@ -11,7 +11,7 @@ templates: ${nfft}, ${fft_batch_size}, ${tag}, ${freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, - ${tuning_ranges}) + ${tuning_ranges}, ${tag_now}) cpp_templates: includes: ['#include '] @@ -21,7 +21,7 @@ cpp_templates: ${nfft}, ${fft_batch_size}, ${tag}, {freq_start}, ${freq_end}, ${tune_step_hz}, ${tune_step_fft}, ${skip_tune_step_fft}, - ${tuning_ranges}); + ${tuning_ranges}, ${tag_now}); link: ['libgnuradio-iqtlabs.so'] parameters: @@ -44,6 +44,8 @@ parameters: dtype: int - id: tuning_ranges dtype: string + - id: tag_now + dtype: bool inputs: - label: input diff --git a/include/gnuradio/iqtlabs/retune_fft.h b/include/gnuradio/iqtlabs/retune_fft.h index 8bd92bf0..072d0876 100644 --- a/include/gnuradio/iqtlabs/retune_fft.h +++ b/include/gnuradio/iqtlabs/retune_fft.h @@ -235,7 +235,7 @@ class IQTLABS_API retune_fft : virtual public gr::block { const std::string &sdir, uint64_t write_step_fft, double bucket_range, const std::string &tuning_ranges, const std::string &description, uint64_t rotate_secs, - bool pre_fft); + bool pre_fft, bool tag_now); }; } // namespace iqtlabs diff --git a/include/gnuradio/iqtlabs/retune_pre_fft.h b/include/gnuradio/iqtlabs/retune_pre_fft.h index e165dfd9..b84c5dc4 100644 --- a/include/gnuradio/iqtlabs/retune_pre_fft.h +++ b/include/gnuradio/iqtlabs/retune_pre_fft.h @@ -233,7 +233,7 @@ class IQTLABS_API retune_pre_fft : virtual public gr::sync_decimator { uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft, - const std::string &tuning_ranges); + const std::string &tuning_ranges, bool tag_now); }; } // namespace iqtlabs diff --git a/lib/base_impl.cc b/lib/base_impl.cc index 59ff8925..c45e5f9d 100644 --- a/lib/base_impl.cc +++ b/lib/base_impl.cc @@ -316,5 +316,14 @@ void base_impl::get_tags(const pmt::pmt_t want_tag, } } } + +pmt::pmt_t base_impl::tune_rx_msg(uint64_t tune_freq, bool tag_now) { + pmt::pmt_t tune_rx = pmt::make_dict(); + tune_rx = pmt::dict_add(tune_rx, pmt::mp("freq"), pmt::from_long(tune_freq)); + if (tag_now) { + tune_rx = pmt::dict_add(tune_rx, pmt::mp("tag"), pmt::mp("now")); + } + return tune_rx; +} } /* namespace iqtlabs */ } /* namespace gr */ diff --git a/lib/base_impl.h b/lib/base_impl.h index 7b27fed8..559cb476 100644 --- a/lib/base_impl.h +++ b/lib/base_impl.h @@ -229,6 +229,7 @@ class base_impl { void get_tags(const pmt::pmt_t want_tag, const std::vector &all_tags, std::vector &rx_freq_tags, std::vector &rx_times, size_t in_count); + pmt::pmt_t tune_rx_msg(uint64_t tune_freq, bool tag_now); }; } /* namespace iqtlabs */ } /* namespace gr */ diff --git a/lib/retune_fft_impl.cc b/lib/retune_fft_impl.cc index 755c10b7..222ac230 100644 --- a/lib/retune_fft_impl.cc +++ b/lib/retune_fft_impl.cc @@ -218,17 +218,19 @@ const pmt::pmt_t JSON_KEY = pmt::mp("json"); const boost::iostreams::zstd_params zstd_params = boost::iostreams::zstd_params(boost::iostreams::zstd::default_compression); -retune_fft::sptr retune_fft::make( - const std::string &tag, size_t vlen, size_t nfft, uint64_t samp_rate, - uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, - uint64_t tune_step_fft, uint64_t skip_tune_step_fft, double fft_min, - double fft_max, const std::string &sdir, uint64_t write_step_fft, - double bucket_range, const std::string &tuning_ranges, - const std::string &description, uint64_t rotate_secs, bool pre_fft) { +retune_fft::sptr +retune_fft::make(const std::string &tag, size_t vlen, size_t nfft, + uint64_t samp_rate, uint64_t freq_start, uint64_t freq_end, + uint64_t tune_step_hz, uint64_t tune_step_fft, + uint64_t skip_tune_step_fft, double fft_min, double fft_max, + const std::string &sdir, uint64_t write_step_fft, + double bucket_range, const std::string &tuning_ranges, + const std::string &description, uint64_t rotate_secs, + bool pre_fft, bool tag_now) { return gnuradio::make_block_sptr( tag, vlen, nfft, samp_rate, freq_start, freq_end, tune_step_hz, tune_step_fft, skip_tune_step_fft, fft_min, fft_max, sdir, write_step_fft, - bucket_range, tuning_ranges, description, rotate_secs, pre_fft); + bucket_range, tuning_ranges, description, rotate_secs, pre_fft, tag_now); } retune_fft_impl::retune_fft_impl( @@ -237,7 +239,8 @@ retune_fft_impl::retune_fft_impl( uint64_t tune_step_fft, uint64_t skip_tune_step_fft, double fft_min, double fft_max, const std::string &sdir, uint64_t write_step_fft, double bucket_range, const std::string &tuning_ranges, - const std::string &description, uint64_t rotate_secs, bool pre_fft) + const std::string &description, uint64_t rotate_secs, bool pre_fft, + bool tag_now) : gr::block("retune_fft", gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, vlen * sizeof(input_type)), @@ -249,7 +252,8 @@ retune_fft_impl::retune_fft_impl( fft_min_(fft_min), fft_max_(fft_max), sample_(nfft), sample_count_(0), sdir_(sdir), write_step_fft_(write_step_fft), write_step_fft_count_(write_step_fft), bucket_range_(bucket_range), - description_(description), rotate_secs_(rotate_secs), pre_fft_(pre_fft) { + description_(description), rotate_secs_(rotate_secs), pre_fft_(pre_fft), + tag_now_(tag_now) { bucket_offset_ = round(float((vlen_ - round(bucket_range_ * vlen_)) / 2)); outbuf_p.reset(new boost::iostreams::filtering_ostream()); message_port_register_out(TUNE_KEY); @@ -286,10 +290,7 @@ void retune_fft_impl::close_() { void retune_fft_impl::send_retune_(uint64_t tune_freq) { d_logger->debug("retuning to {}", tune_freq); - pmt::pmt_t tune_rx = pmt::make_dict(); - tune_rx = pmt::dict_add(tune_rx, pmt::mp("freq"), pmt::from_long(tune_freq)); - tune_rx = pmt::dict_add(tune_rx, pmt::mp("tag"), pmt::mp("now")); - message_port_pub(TUNE_KEY, tune_rx); + message_port_pub(TUNE_KEY, tune_rx_msg(tune_freq, tag_now_)); } void retune_fft_impl::retune_now_() { diff --git a/lib/retune_fft_impl.h b/lib/retune_fft_impl.h index 99a03f86..854b8c39 100644 --- a/lib/retune_fft_impl.h +++ b/lib/retune_fft_impl.h @@ -247,6 +247,7 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl { std::string sdir_; std::string description_; bool pre_fft_; + bool tag_now_; double fft_min_; double fft_max_; @@ -268,7 +269,7 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl { const std::string &sdir, uint64_t write_step_fft, double bucket_range, const std::string &tuning_ranges, const std::string &description, uint64_t rotate_secs, - bool pre_fft); + bool pre_fft, bool tag_now); ~retune_fft_impl(); void forecast(int noutput_items, gr_vector_int &ninput_items_required); int general_work(int noutput_items, gr_vector_int &ninput_items, diff --git a/lib/retune_pre_fft_impl.cc b/lib/retune_pre_fft_impl.cc index 3c5c91f4..e2c821b6 100644 --- a/lib/retune_pre_fft_impl.cc +++ b/lib/retune_pre_fft_impl.cc @@ -216,19 +216,17 @@ retune_pre_fft::make(size_t nfft, size_t fft_batch_size, const std::string &tag, uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft, - const std::string &tuning_ranges) { + const std::string &tuning_ranges, bool tag_now) { return gnuradio::make_block_sptr( nfft, fft_batch_size, tag, freq_start, freq_end, tune_step_hz, - tune_step_fft, skip_tune_step_fft, tuning_ranges); + tune_step_fft, skip_tune_step_fft, tuning_ranges, tag_now); } -retune_pre_fft_impl::retune_pre_fft_impl(size_t nfft, size_t fft_batch_size, - const std::string &tag, - uint64_t freq_start, uint64_t freq_end, - uint64_t tune_step_hz, - uint64_t tune_step_fft, - uint64_t skip_tune_step_fft, - const std::string &tuning_ranges) +retune_pre_fft_impl::retune_pre_fft_impl( + size_t nfft, size_t fft_batch_size, const std::string &tag, + uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, + uint64_t tune_step_fft, uint64_t skip_tune_step_fft, + const std::string &tuning_ranges, bool tag_now) : gr::sync_decimator( "retune_pre_fft", gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */, @@ -238,7 +236,8 @@ retune_pre_fft_impl::retune_pre_fft_impl(size_t nfft, size_t fft_batch_size, nfft * fft_batch_size /*<+decimation+>*/), retuner_impl(freq_start, freq_end, tune_step_hz, tune_step_fft, skip_tune_step_fft, tuning_ranges), - nfft_(nfft), fft_batch_size_(fft_batch_size), tag_(pmt::intern(tag)) { + nfft_(nfft), fft_batch_size_(fft_batch_size), tag_(pmt::intern(tag)), + tag_now_(tag_now) { message_port_register_out(TUNE_KEY); } @@ -246,10 +245,7 @@ retune_pre_fft_impl::~retune_pre_fft_impl() {} void retune_pre_fft_impl::send_retune_(uint64_t tune_freq) { d_logger->debug("retuning to {}", tune_freq); - pmt::pmt_t tune_rx = pmt::make_dict(); - tune_rx = pmt::dict_add(tune_rx, pmt::mp("freq"), pmt::from_long(tune_freq)); - tune_rx = pmt::dict_add(tune_rx, pmt::mp("tag"), pmt::mp("now")); - message_port_pub(TUNE_KEY, tune_rx); + message_port_pub(TUNE_KEY, tune_rx_msg(tune_freq, tag_now_)); } void retune_pre_fft_impl::retune_now_() { diff --git a/lib/retune_pre_fft_impl.h b/lib/retune_pre_fft_impl.h index c633b7f9..a5ac000b 100644 --- a/lib/retune_pre_fft_impl.h +++ b/lib/retune_pre_fft_impl.h @@ -220,13 +220,14 @@ class retune_pre_fft_impl : public retune_pre_fft, base_impl, retuner_impl { size_t nfft_; size_t fft_batch_size_; pmt::pmt_t tag_; + bool tag_now_; public: retune_pre_fft_impl(size_t nfft, size_t fft_batch_size, const std::string &tag, uint64_t freq_start, uint64_t freq_end, uint64_t tune_step_hz, uint64_t tune_step_fft, uint64_t skip_tune_step_fft, - const std::string &tuning_ranges); + const std::string &tuning_ranges, bool tag_now); ~retune_pre_fft_impl(); int work(int noutput_items, gr_vector_const_void_star &input_items, diff --git a/python/iqtlabs/bindings/retune_fft_python.cc b/python/iqtlabs/bindings/retune_fft_python.cc index d15f46f2..e31817d1 100644 --- a/python/iqtlabs/bindings/retune_fft_python.cc +++ b/python/iqtlabs/bindings/retune_fft_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(retune_fft.h) */ -/* BINDTOOL_HEADER_FILE_HASH(291a634c39f0e6860211913645932d56) */ +/* BINDTOOL_HEADER_FILE_HASH(b28088ca33ba5c42293eb74f6c90de2b) */ /***********************************************************************************/ #include @@ -55,6 +55,7 @@ void bind_retune_fft(py::module& m) py::arg("description"), py::arg("rotate_secs"), py::arg("pre_fft"), + py::arg("tag_now"), D(retune_fft, make)) diff --git a/python/iqtlabs/bindings/retune_pre_fft_python.cc b/python/iqtlabs/bindings/retune_pre_fft_python.cc index 2c455099..885ae46a 100644 --- a/python/iqtlabs/bindings/retune_pre_fft_python.cc +++ b/python/iqtlabs/bindings/retune_pre_fft_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(retune_pre_fft.h) */ -/* BINDTOOL_HEADER_FILE_HASH(a9b4051c99f17cef5206780055ededed) */ +/* BINDTOOL_HEADER_FILE_HASH(8b85264423963500dfd62650d0c0055a) */ /***********************************************************************************/ #include @@ -46,6 +46,7 @@ void bind_retune_pre_fft(py::module& m) py::arg("tune_step_fft"), py::arg("skip_tune_step_fft"), py::arg("tuning_ranges"), + py::arg("tag_now"), D(retune_pre_fft, make)) diff --git a/python/iqtlabs/qa_retune_fft.py b/python/iqtlabs/qa_retune_fft.py index 153bb94e..0b0a2f68 100755 --- a/python/iqtlabs/qa_retune_fft.py +++ b/python/iqtlabs/qa_retune_fft.py @@ -295,6 +295,7 @@ def retune_fft(self, fft_roll): tune_step_fft, skip_tune_step_fft, tuning_ranges, + False, ) iqtlabs_retune_fft_0 = retune_fft( @@ -316,6 +317,7 @@ def retune_fft(self, fft_roll): "a text description", 3600, True, + False, ) pdu_decoder_0 = pdu_decoder() fft_vxx_0 = fft.fft_vcc(points, True, [], fft_roll, 1)