From ba2de75e143d26dbd5c338d2bb0abb7cfe595794 Mon Sep 17 00:00:00 2001 From: Josh Bailey Date: Tue, 6 Feb 2024 05:56:27 +0000 Subject: [PATCH] hotfix - GET_FREQ() to safely get rx_freq tag. --- lib/base_impl.cc | 3 ++- lib/base_impl.h | 5 ++++- lib/image_inference_impl.cc | 2 +- lib/iq_inference_impl.cc | 2 +- lib/retune_fft_impl.cc | 2 +- lib/retune_pre_fft_impl.cc | 2 +- lib/retuner_impl.h | 4 ++-- lib/tuneable_test_source_impl.cc | 10 ++++------ lib/tuneable_test_source_impl.h | 2 +- lib/write_freq_samples_impl.cc | 2 +- 10 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/base_impl.cc b/lib/base_impl.cc index a611a9a0..2f3d5ffe 100644 --- a/lib/base_impl.cc +++ b/lib/base_impl.cc @@ -317,8 +317,9 @@ 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 base_impl::tune_rx_msg(FREQ_T tune_freq, bool tag_now) { pmt::pmt_t tune_rx = pmt::make_dict(); + // freq has to be a long in a PMT message. 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")); diff --git a/lib/base_impl.h b/lib/base_impl.h index edbf140e..8dbbf0bd 100644 --- a/lib/base_impl.h +++ b/lib/base_impl.h @@ -222,9 +222,12 @@ const pmt::pmt_t RX_FREQ_KEY = pmt::string_to_symbol("rx_freq"); this->add_item_tag(stream, nitems_written(stream) + offset, RX_TIME_KEY, \ make_rx_time_key_(rx_time), _id); \ this->add_item_tag(stream, nitems_written(stream) + offset, RX_FREQ_KEY, \ - pmt::from_uint64(rx_freq), _id); \ + pmt::from_double((double)rx_freq), _id); \ } +// A driver block might give us float style (e.g. 2.5e9) or unsigned lon. +#define GET_FREQ(tag) (FREQ_T) pmt::to_double(tag.value) + class base_impl { public: std::string get_prefix_file_(const std::string &file, diff --git a/lib/image_inference_impl.cc b/lib/image_inference_impl.cc index 633fc6fd..ac9d69cd 100644 --- a/lib/image_inference_impl.cc +++ b/lib/image_inference_impl.cc @@ -691,7 +691,7 @@ int image_inference_impl::general_work(int noutput_items, process_items_(rel, in); } - FREQ_T rx_freq = pmt::to_uint64(tag.value); + FREQ_T rx_freq = GET_FREQ(tag); if (rx_freq != last_rx_freq_) { create_image_(true); } diff --git a/lib/iq_inference_impl.cc b/lib/iq_inference_impl.cc index 27d692d4..47ae31a8 100644 --- a/lib/iq_inference_impl.cc +++ b/lib/iq_inference_impl.cc @@ -505,7 +505,7 @@ int iq_inference_impl::general_work(int noutput_items, process_items_(rel, power_read, power_in); } - const FREQ_T rx_freq = pmt::to_uint64(tag.value); + const FREQ_T rx_freq = GET_FREQ(tag); d_logger->debug("new rx_freq tag: {}", rx_freq); last_rx_freq_ = rx_freq; last_rx_time_ = rx_time; diff --git a/lib/retune_fft_impl.cc b/lib/retune_fft_impl.cc index 079a4826..69dd38d9 100644 --- a/lib/retune_fft_impl.cc +++ b/lib/retune_fft_impl.cc @@ -506,7 +506,7 @@ void retune_fft_impl::process_tags_(const input_type *in, size_t in_count, process_items_(rel, in, fft_output, produced); } - const uint64_t rx_freq = pmt::to_uint64(tag.value); + const FREQ_T rx_freq = GET_FREQ(tag); if (!reset_tags_) { add_output_tags_(rx_time, rx_freq, produced); } diff --git a/lib/retune_pre_fft_impl.cc b/lib/retune_pre_fft_impl.cc index ebfc5f20..8b835edd 100644 --- a/lib/retune_pre_fft_impl.cc +++ b/lib/retune_pre_fft_impl.cc @@ -339,7 +339,7 @@ int retune_pre_fft_impl::general_work(int noutput_items, // abstraction like VkFFT const auto &tag = rx_freq_tags[0]; const TIME_T rx_time = rx_times[0]; - const FREQ_T rx_freq = pmt::to_uint64(tag.value); + const FREQ_T rx_freq = GET_FREQ(tag); // Discard trailing samples up to new tag (i.e. between retune // request/response). d_logger->debug("new rx_freq tag: {}, last {}", rx_freq, last_rx_freq_); diff --git a/lib/retuner_impl.h b/lib/retuner_impl.h index 6d19932c..26d92bc8 100644 --- a/lib/retuner_impl.h +++ b/lib/retuner_impl.h @@ -219,8 +219,8 @@ namespace iqtlabs { } typedef struct { - uint64_t freq_start; - uint64_t freq_end; + FREQ_T freq_start; + FREQ_T freq_end; size_t steps; } tuning_range_t; diff --git a/lib/tuneable_test_source_impl.cc b/lib/tuneable_test_source_impl.cc index a80dd5f2..7e06f78c 100644 --- a/lib/tuneable_test_source_impl.cc +++ b/lib/tuneable_test_source_impl.cc @@ -217,13 +217,11 @@ tuneable_test_source_impl::tuneable_test_source_impl(float freq_divisor) : gr::sync_block("tuneable_test_source", gr::io_signature::make(0, 0, 0), gr::io_signature::make(1 /* min outputs */, 1 /*max outputs */, - sizeof(output_type))) { + sizeof(output_type))), + d_freq_divisor(freq_divisor), last_freq(0), last_sample(gr_complex(0, 0)), + tag_now(false) { message_port_register_in(CMD_KEY); set_msg_handler(CMD_KEY, [this](const pmt::pmt_t &msg) { recv_cmd(msg); }); - d_freq_divisor = freq_divisor; - last_freq = 0; - last_sample = gr_complex(0, 0); - tag_now = false; } tuneable_test_source_impl::~tuneable_test_source_impl() {} @@ -245,7 +243,7 @@ void tuneable_test_source_impl::recv_cmd(pmt::pmt_t msg) { auto val = pmt::cdr(item); if (key == FREQ_KEY) { if (pmt::is_number(val)) { - last_freq = pmt::to_double(val); + last_freq = (TIME_T)pmt::to_double(val); tag_now = true; } } diff --git a/lib/tuneable_test_source_impl.h b/lib/tuneable_test_source_impl.h index 7449be7f..04bbcc24 100644 --- a/lib/tuneable_test_source_impl.h +++ b/lib/tuneable_test_source_impl.h @@ -214,7 +214,7 @@ namespace iqtlabs { class tuneable_test_source_impl : public tuneable_test_source, base_impl { private: double d_freq_divisor; - double last_freq; + FREQ_T last_freq; gr_complex last_sample; bool tag_now; diff --git a/lib/write_freq_samples_impl.cc b/lib/write_freq_samples_impl.cc index 901017b0..222fd495 100644 --- a/lib/write_freq_samples_impl.cc +++ b/lib/write_freq_samples_impl.cc @@ -314,7 +314,7 @@ int write_freq_samples_impl::general_work( write_samples_(rel, in); } - const FREQ_T rx_freq = pmt::to_uint64(tag.value); + const FREQ_T rx_freq = GET_FREQ(tag); d_logger->debug("new rx_freq tag: {}, last {}", rx_freq, last_rx_freq_); last_rx_freq_ = rx_freq; skip_tune_step_samples_count_ = skip_tune_step_samples_;