Skip to content

Commit

Permalink
Merge pull request #147 from anarkiwi/holddown
Browse files Browse the repository at this point in the history
Hold down outputting samples until bad power observed.
  • Loading branch information
anarkiwi authored Nov 24, 2023
2 parents cb869d9 + 946dd55 commit 418e6fd
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 11 deletions.
10 changes: 8 additions & 2 deletions grc/iqtlabs_retune_fft.block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ documentation: |-
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.
low_power_hold_down: if True, suppress samples between sending a retune
message and observing low power (Ettus retune delay
workaround).
example JSON output:
{ "ts": <epoch time>, "sweep start": <epoch time>,
Expand All @@ -65,7 +68,8 @@ 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}, ${tag_now})
${tuning_ranges}, ${description}, ${rotate_secs}, ${pre_fft}, ${tag_now},
${low_power_hold_down))
cpp_templates:
includes: ['#include <gnuradio/iqtlabs/retune_fft.h>']
Expand All @@ -75,7 +79,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}, ${tag_now});
${pre_fft}, ${tag_now}, ${low_power_hold_down));
link: ['libgnuradio-iqtlabs.so']

asserts:
Expand Down Expand Up @@ -124,6 +128,8 @@ parameters:
dtype: int
- id: tag_now
dtype: bool
- id: low_power_hold_down
dtype: bool

inputs:
- label: input
Expand Down
2 changes: 1 addition & 1 deletion include/gnuradio/iqtlabs/retune_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 tag_now);
bool pre_fft, bool tag_now, bool low_power_hold_down);
};

} // namespace iqtlabs
Expand Down
29 changes: 25 additions & 4 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,12 @@ retune_fft::make(const std::string &tag, size_t vlen, size_t nfft,
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) {
bool pre_fft, bool tag_now, bool low_power_hold_down) {
return gnuradio::make_block_sptr<retune_fft_impl>(
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, tag_now);
bucket_range, tuning_ranges, description, rotate_secs, pre_fft, tag_now,
low_power_hold_down);
}

retune_fft_impl::retune_fft_impl(
Expand All @@ -240,7 +241,7 @@ retune_fft_impl::retune_fft_impl(
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)
bool tag_now, bool low_power_hold_down)
: gr::block("retune_fft",
gr::io_signature::make(1 /* min inputs */, 1 /* max inputs */,
vlen * sizeof(input_type)),
Expand All @@ -255,14 +256,18 @@ retune_fft_impl::retune_fft_impl(
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),
tag_now_(tag_now) {
tag_now_(tag_now), low_power_hold_down_(low_power_hold_down),
in_hold_down_(false) {
bucket_offset_ = round(float((vlen_ - round(bucket_range_ * vlen_)) / 2));
outbuf_p.reset(new boost::iostreams::filtering_ostream());
message_port_register_out(TUNE_KEY);
message_port_register_out(JSON_KEY);
message_port_register_in(CMD_KEY);
set_msg_handler(CMD_KEY,
[this](const pmt::pmt_t &msg) { next_retune_(host_now_()); });
if (low_power_hold_down_ && !stare_mode_) {
set_tag_propagation_policy(TPP_DONT);
}
}

retune_fft_impl::~retune_fft_impl() { close_(); }
Expand Down Expand Up @@ -299,6 +304,9 @@ void retune_fft_impl::retune_now_() {
const double host_now = host_now_();
send_retune_(tune_freq_);
next_retune_(host_now);
if (low_power_hold_down_ && !stare_mode_) {
in_hold_down_ = true;
}
}

void retune_fft_impl::write_items_(const input_type *in) {
Expand Down Expand Up @@ -328,6 +336,19 @@ size_t retune_fft_impl::process_items_(size_t c, const input_type *&in,
// avoids having to use a static skip_fft_count setting.
input_type in_max = *std::max_element(in, in + nfft_);
if (in_max < fft_min_) {
if (in_hold_down_) {
in_hold_down_ = false;
std::stringstream str;
str << name() << unique_id();
pmt::pmt_t _id = pmt::string_to_symbol(str.str());
this->add_item_tag(1, nitems_written(1), RX_TIME_KEY,
make_rx_time_key_(last_rx_time_), _id);
this->add_item_tag(1, nitems_written(1), RX_FREQ_KEY,
pmt::from_double(last_rx_freq_), _id);
}
continue;
}
if (in_hold_down_ && total_tune_count_ > 1) {
continue;
}
std::memcpy((void *)fft_output, (const void *)in,
Expand Down
4 changes: 3 additions & 1 deletion lib/retune_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl {
std::string description_;
bool pre_fft_;
bool tag_now_;
bool low_power_hold_down_;

double fft_min_;
double fft_max_;
Expand All @@ -259,6 +260,7 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl {
size_t sample_count_;
uint64_t write_step_fft_count_;
size_t bucket_offset_;
bool in_hold_down_;

boost::scoped_ptr<boost::iostreams::filtering_ostream> outbuf_p;
std::string file_;
Expand All @@ -271,7 +273,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 tag_now);
bool pre_fft, bool tag_now, bool low_power_hold_down);
~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,
Expand Down
5 changes: 3 additions & 2 deletions lib/retuner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,18 @@ void retuner_impl::parse_tuning_ranges_(const std::string &tuning_ranges) {
}
}
tune_freq_ = tuning_ranges_[0].freq_start;
stare_mode_ = tuning_ranges_[0].steps == 1;
}

void retuner_impl::next_retune_(double host_now) {
++total_tune_count_;
++pending_retune_;
last_tuning_range_ = tuning_range_;
size_t range_steps = tuning_ranges_[tuning_range_].steps;
if (range_steps == 1) {
if (stare_mode_) {
last_sweep_start_ = host_now;
return;
}
size_t range_steps = tuning_ranges_[tuning_range_].steps;
tune_freq_ = std::min(tune_freq_ + tune_step_hz_,
tuning_ranges_[tuning_range_].freq_end);
++tuning_range_step_;
Expand Down
1 change: 1 addition & 0 deletions lib/retuner_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ class retuner_impl {
size_t pending_retune_;
size_t total_tune_count_;
std::vector<tuning_range_t> tuning_ranges_;
bool stare_mode_;
};
} /* namespace iqtlabs */
} /* namespace gr */
3 changes: 2 additions & 1 deletion python/iqtlabs/bindings/retune_fft_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(retune_fft.h) */
/* BINDTOOL_HEADER_FILE_HASH(b28088ca33ba5c42293eb74f6c90de2b) */
/* BINDTOOL_HEADER_FILE_HASH(a0d87e48b777867c4c76b31277fd6403) */
/***********************************************************************************/

#include <pybind11/complex.h>
Expand Down Expand Up @@ -56,6 +56,7 @@ void bind_retune_fft(py::module& m)
py::arg("rotate_secs"),
py::arg("pre_fft"),
py::arg("tag_now"),
py::arg("low_power_hold_down"),
D(retune_fft, make))


Expand Down
1 change: 1 addition & 0 deletions python/iqtlabs/qa_retune_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def retune_fft(self, fft_roll):
3600,
True,
False,
False,
)
pdu_decoder_0 = pdu_decoder()
fft_vxx_0 = fft.fft_vcc(points, True, [], fft_roll, 1)
Expand Down

0 comments on commit 418e6fd

Please sign in to comment.