summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Gilbert <jacob.gilbert@protonmail.com>2021-03-29 20:48:45 -0600
committermormj <34754695+mormj@users.noreply.github.com>2021-04-05 07:28:48 -0400
commitdeb4c4dd97cb668b399496d8edab2cfa8d69f85b (patch)
tree9aea07f580eaee0891649a8c55d08a7e5f7b84d7
parentd2680c18d36148cd87582ec4adc6f38b27e249db (diff)
gr-uhd: fix command tuning
Command tuning has seen several updates recently and incomplete regression testing. One issue introduced is that when tuning without a direction key will result in the tune applied in the TX direction instead of the block direction (intended). This fixes that by adding member getters for block direction and putting the logic to get the command direction in a common function. Signed-off-by: Jacob Gilbert <jacob.gilbert@protonmail.com>
-rw-r--r--gr-uhd/lib/usrp_block_impl.cc92
-rw-r--r--gr-uhd/lib/usrp_block_impl.h6
-rw-r--r--gr-uhd/lib/usrp_sink_impl.h2
-rw-r--r--gr-uhd/lib/usrp_source_impl.h2
4 files changed, 41 insertions, 61 deletions
diff --git a/gr-uhd/lib/usrp_block_impl.cc b/gr-uhd/lib/usrp_block_impl.cc
index 6586a757b6..973aa96c80 100644
--- a/gr-uhd/lib/usrp_block_impl.cc
+++ b/gr-uhd/lib/usrp_block_impl.cc
@@ -298,8 +298,7 @@ void usrp_block_impl::_set_center_freq_from_internals_allchans()
while (_tx_chans_to_tune.any()) {
// This resets() bits, so this loop should not run indefinitely
chan = _tx_chans_to_tune.find_first();
- _set_center_freq_from_internals(_tx_chans_to_tune.find_first(),
- ant_direction_tx());
+ _set_center_freq_from_internals(chan, ant_direction_tx());
_tx_chans_to_tune.reset(chan);
}
}
@@ -528,16 +527,8 @@ void usrp_block_impl::msg_handler_command(pmt::pmt_t msg)
pmt::from_long(-1) // Default to all chans
)));
- /// 3) See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX will default to the
- // messaged block direction"
- );
- // if the a direction symbol was provided, force a tune
- _force_tune = pmt::is_symbol(direction);
-
+ /// 3) If a direction key was specified, force the block to tune - see issue #1814
+ _force_tune = pmt::dict_has_key(msg, cmd_direction_key());
/// 4) Loop through all the values
GR_LOG_DEBUG(d_debug_logger, boost::format("Processing command message %s") % msg);
@@ -618,13 +609,8 @@ void usrp_block_impl::_cmd_handler_freq(const pmt::pmt_t& freq_,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX will default to the
- // messaged block direction"
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
double freq = pmt::to_double(freq_);
::uhd::tune_request_t new_tune_request(freq);
@@ -641,13 +627,8 @@ void usrp_block_impl::_cmd_handler_looffset(const pmt::pmt_t& lo_offset,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX" will default to the
- // messaged block direction
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
if (pmt::dict_has_key(msg, cmd_freq_key())) {
// Then it's already taken care of
@@ -673,13 +654,8 @@ void usrp_block_impl::_cmd_handler_gain(const pmt::pmt_t& gain_,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX will default to the
- // messaged block direction"
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
double gain = pmt::to_double(gain_);
if (chan == -1) {
@@ -780,13 +756,8 @@ void usrp_block_impl::_cmd_handler_tune(const pmt::pmt_t& tune,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX" will default to the
- // messaged block direction
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
double freq = pmt::to_double(pmt::car(tune));
double lo_offset = pmt::to_double(pmt::cdr(tune));
@@ -798,13 +769,8 @@ void usrp_block_impl::_cmd_handler_mtune(const pmt::pmt_t& tune,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX" will default to the
- // messaged block direction
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
::uhd::tune_request_t new_tune_request;
if (pmt::dict_has_key(tune, pmt::mp("dsp_freq"))) {
@@ -868,13 +834,8 @@ void usrp_block_impl::_cmd_handler_lofreq(const pmt::pmt_t& lofreq,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX will default to the
- // messaged block direction"
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
if (chan == -1) {
for (size_t i = 0; i < _nchan; i++) {
@@ -905,13 +866,8 @@ void usrp_block_impl::_cmd_handler_dspfreq(const pmt::pmt_t& dspfreq,
int chan,
const pmt::pmt_t& msg)
{
- // See if a direction was specified
- pmt::pmt_t direction =
- pmt::dict_ref(msg,
- cmd_direction_key(),
- pmt::PMT_NIL // Anything except "TX" or "RX will default to the
- // messaged block direction"
- );
+ // Get the direction key
+ const pmt::pmt_t direction = get_cmd_or_default_direction(msg);
if (pmt::dict_has_key(msg, cmd_lo_freq_key())) {
// Then it's already dealt with
@@ -938,3 +894,17 @@ void usrp_block_impl::_cmd_handler_dspfreq(const pmt::pmt_t& dspfreq,
_update_curr_tune_req(new_tune_request, chan, direction);
}
+
+const pmt::pmt_t
+usrp_block_impl::get_cmd_or_default_direction(const pmt::pmt_t& cmd) const
+{
+ const pmt::pmt_t dir = pmt::dict_ref(cmd, cmd_direction_key(), pmt::PMT_NIL);
+
+ // if the direction key exists and is either "TX" or "RX", return that
+ if (pmt::is_symbol(dir) &&
+ (pmt::eqv(dir, ant_direction_rx()) || pmt::eqv(dir, ant_direction_tx()))) {
+ return dir;
+ }
+ // otherwise return the direction key for the block that received the cmd
+ return _direction();
+}
diff --git a/gr-uhd/lib/usrp_block_impl.h b/gr-uhd/lib/usrp_block_impl.h
index 664ef4c417..b9bf6d3acf 100644
--- a/gr-uhd/lib/usrp_block_impl.h
+++ b/gr-uhd/lib/usrp_block_impl.h
@@ -227,6 +227,12 @@ protected:
//! Stores the individual command handlers
::uhd::dict<pmt::pmt_t, cmd_handler_t> _msg_cmd_handlers;
+
+ //! Will check a command for a direction key, if it does not exist this will use
+ // the default value for the block via _direction() defined below
+ const pmt::pmt_t get_cmd_or_default_direction(const pmt::pmt_t& cmd) const;
+ //! Block direction overloaded by block impl to return "RX"/"TX" for source/sink
+ virtual const pmt::pmt_t _direction() const = 0;
};
} /* namespace uhd */
diff --git a/gr-uhd/lib/usrp_sink_impl.h b/gr-uhd/lib/usrp_sink_impl.h
index 18507ffe89..45b2723569 100644
--- a/gr-uhd/lib/usrp_sink_impl.h
+++ b/gr-uhd/lib/usrp_sink_impl.h
@@ -142,6 +142,8 @@ private:
bool _async_event_loop_running;
void async_event_loop();
gr::thread::thread _async_event_thread;
+
+ const pmt::pmt_t _direction() const override { return ant_direction_tx(); };
};
} /* namespace uhd */
diff --git a/gr-uhd/lib/usrp_source_impl.h b/gr-uhd/lib/usrp_source_impl.h
index 53e3387b71..f0ab1490e8 100644
--- a/gr-uhd/lib/usrp_source_impl.h
+++ b/gr-uhd/lib/usrp_source_impl.h
@@ -146,6 +146,8 @@ private:
double _samp_rate;
std::recursive_mutex d_mutex;
+
+ const pmt::pmt_t _direction() const override { return ant_direction_rx(); };
};
} /* namespace uhd */