Skip to content

Commit

Permalink
Merge pull request #210 from anarkiwi/sst
Browse files Browse the repository at this point in the history
add samples since tag.
  • Loading branch information
anarkiwi authored Feb 6, 2024
2 parents 608b3f3 + 910eb1e commit 9d8634b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ Command a source block with PMT tuning messages to sweep over a set of frequency

### [retune_fft](grc/iqtlabs_retune_fft.block.yml)

Command a source block with PMT tuning messages to sweep over a set of frequency ranges, retuning after a configurable nunber of FFT points are received over a configurable threshold
(while validating power values are in a valid range).
Command a source block with PMT tuning messages to sweep over a set of frequency ranges, retuning after a configurable nunber of FFT points are received over a configurable threshold (while validating power values are in a valid range).

### [tuneable_test_source](grc/iqtlabs_tuneable_test_source.block.yml)

Expand Down
9 changes: 6 additions & 3 deletions lib/iq_inference_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ iq_inference_impl::iq_inference_impl(const std::string &tag, size_t vlen,
min_peak_points_(min_peak_points), model_server_(model_server),
confidence_(confidence), n_inference_(n_inference), samp_rate_(samp_rate),
inference_count_(0), running_(true), last_rx_freq_(0), last_rx_time_(0),
inference_connected_(false) {
inference_connected_(false), samples_since_tag_(0) {
samples_lookback_.reset(new gr_complex[vlen * sample_buffer]);
unsigned int alignment = volk_get_alignment();
total_.reset((float *)volk_malloc(sizeof(float), alignment));
Expand Down Expand Up @@ -422,7 +422,8 @@ void iq_inference_impl::forecast(int noutput_items,
void iq_inference_impl::process_items_(size_t power_in_count,
uint64_t &power_read,
const float *&power_in) {
for (size_t i = 0; i < power_in_count; ++i, power_in += vlen_) {
for (size_t i = 0; i < power_in_count;
++i, power_in += vlen_, samples_since_tag_ += vlen_) {
size_t j = (power_read + i) % sample_buffer_;
volk_32f_index_max_16u(max_.get(), power_in, vlen_);
float power_max = power_in[*max_];
Expand All @@ -436,7 +437,8 @@ void iq_inference_impl::process_items_(size_t power_in_count,
continue;
}
output_item_type output_item;
output_item.rx_time = last_rx_time_;
output_item.rx_time =
last_rx_time_ + (samples_since_tag_ / TIME_T(samp_rate_));
output_item.rx_freq = last_rx_freq_;
output_item.sample_count = vlen_;
output_item.samples = new gr_complex[output_item.sample_count];
Expand Down Expand Up @@ -509,6 +511,7 @@ int iq_inference_impl::general_work(int noutput_items,
d_logger->debug("new rx_freq tag: {}", rx_freq);
last_rx_freq_ = rx_freq;
last_rx_time_ = rx_time;
samples_since_tag_ = 0;
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/iq_inference_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class iq_inference_impl : public iq_inference, base_impl {
size_t n_inference_;
int samp_rate_;
size_t inference_count_;
size_t samples_since_tag_;
boost::lockfree::spsc_queue<output_item_type> inference_q_{MAX_INFERENCE};
boost::lockfree::spsc_queue<std::string> json_q_{MAX_INFERENCE};
bool running_;
Expand Down
11 changes: 8 additions & 3 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,14 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in,
slew_samples_ += nfft_;
continue;
}
// Discard windows where max power, is less than requested minimum.
// Ettus radios periodically output low power after retuning. This
// avoids having to use a static skip_fft_count setting.
// Implement the low power hold down workaround (typically for Ettus).
// When retuning the radio, typically the radio responds relatively quickly
// with new rx_time and rx_freq tags acknowledging the request. However,
// we continue to observe samples for the previous frequency for some time.
// Then, we receive all complex 0's for a time, and then we receive samples
// for actual frequency requested. We detect the all-zeros condition (by
// observing implausibly low power) condition and move the rx_time and
// rx_freq tags to this position.
volk_32f_index_max_16u(in_max_pos_.get(), in, nfft_);
float in_max = in[*in_max_pos_];
if (in_max < fft_min_) {
Expand Down
7 changes: 7 additions & 0 deletions lib/retune_pre_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ void retune_pre_fft_impl::process_items_(size_t c, const block_type *&in,
continue;
}
bool all_zeros = all_zeros_(in);
// Implement the low power hold down workaround (typically for Ettus).
// When retuning the radio, typically the radio responds relatively
// quickly with new rx_time and rx_freq tags acknowledging the request.
// However, we continue to observe samples for the previous frequency for
// some time. Then, we receive all complex 0's for a time, and then we
// receive samples for actual frequency requested. We detect the all-zeros
// condition and move the rx_time and rx_freq tags to this position.
if (in_hold_down_) {
if (all_zeros) {
in_hold_down_ = false;
Expand Down
6 changes: 6 additions & 0 deletions lib/retuner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ void retuner_impl::next_retune_(TIME_T host_now) {
slew_samples_ = 0;
}

// Attempt to account for elapsed time since tuning tag was received,
// but before samples are passed on to subsequent blocks. The accuracy
// of the timestamp itself is not known, since it is the host's gnuradio
// driver that adds the tag and some number of samples may have been in
// flight from the radio
// (https://github.com/gnuradio/gnuradio/blob/fe048a9874d2604d48d396d2b39925a0cf2c3c70/gr-uhd/lib/usrp_source_impl.cc#L636).
TIME_T retuner_impl::apply_rx_time_slew_(TIME_T rx_time) {
if (slew_rx_time_) {
TIME_T slew_time = slew_samples_ / TIME_T(samp_rate_);
Expand Down

0 comments on commit 9d8634b

Please sign in to comment.