Skip to content

Commit

Permalink
Merge pull request #209 from anarkiwi/cl6
Browse files Browse the repository at this point in the history
hotfix - GET_FREQ() to safely get rx_freq tag.
  • Loading branch information
anarkiwi authored Feb 6, 2024
2 parents b6046f6 + ba2de75 commit 608b3f3
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion lib/base_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
5 changes: 4 additions & 1 deletion lib/base_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/image_inference_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/iq_inference_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/retune_pre_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
4 changes: 2 additions & 2 deletions lib/retuner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 4 additions & 6 deletions lib/tuneable_test_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tuneable_test_source_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/write_freq_samples_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit 608b3f3

Please sign in to comment.