From b36fa03407f43dfc8e93a719186264b8d3e6db52 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Fri, 8 Jan 2021 13:12:34 +0100 Subject: uhd: Fix radio_control-related method constness The const-ness of some radio_control differed between base class and implementation. This fixes the consistency, but also makes sure these methods follow the rules for when to make methods 'const'. The following rules apply: - Methods that query static capabilities are const. Here, we made get_tx_lo_sources() const (the RX version was already const). - Getters that may have to interact with the device (e.g., peek a register) are not const, because the act of peeking is usually also non-const. Here, we changed get_rx_lo_export_enabled() to non-const. - All base classes are fixed such that the derived classes and the base classes have the same const-ness. Clang was warning about differences. This can cause very tricky bugs, where the radio_control_impl version can get called instead of the intended child class. --- host/include/uhd/rfnoc/rf_control/core_iface.hpp | 5 ++--- host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp | 5 ++--- host/lib/rfnoc/radio_control_impl.cpp | 4 ++-- host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp | 6 +++--- host/lib/usrp/dboard/magnesium/magnesium_radio_control.hpp | 9 +++++---- host/lib/usrp/dboard/rhodium/rhodium_radio_control.hpp | 4 ++-- host/lib/usrp/x300/x300_radio_control.cpp | 3 +-- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/host/include/uhd/rfnoc/rf_control/core_iface.hpp b/host/include/uhd/rfnoc/rf_control/core_iface.hpp index 9b780b3c8..ff7ec3550 100644 --- a/host/include/uhd/rfnoc/rf_control/core_iface.hpp +++ b/host/include/uhd/rfnoc/rf_control/core_iface.hpp @@ -326,8 +326,7 @@ public: * \param name the name of the LO stage to query * \param chan the channel index 0 to N-1 */ - virtual bool get_rx_lo_export_enabled( - const std::string& name, const size_t chan) const = 0; + virtual bool get_rx_lo_export_enabled(const std::string& name, const size_t chan) = 0; /*! * Set the RX LO frequency (Advanced). @@ -365,7 +364,7 @@ public: * \return a vector of strings for possible settings */ virtual std::vector get_tx_lo_sources( - const std::string& name, const size_t chan) = 0; + const std::string& name, const size_t chan) const = 0; /*! * Get the LO frequency range of the tx LO. diff --git a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp index ba11e50bf..7d9ce6ec2 100644 --- a/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp +++ b/host/lib/include/uhdlib/rfnoc/radio_control_impl.hpp @@ -131,14 +131,13 @@ public: const std::string& name, const size_t chan) override; void set_rx_lo_export_enabled( bool enabled, const std::string& name, const size_t chan) override; - bool get_rx_lo_export_enabled( - const std::string& name, const size_t chan) const override; + bool get_rx_lo_export_enabled(const std::string& name, const size_t chan) override; double set_rx_lo_freq( double freq, const std::string& name, const size_t chan) override; double get_rx_lo_freq(const std::string& name, const size_t chan) override; std::vector get_tx_lo_names(const size_t chan) const override; std::vector get_tx_lo_sources( - const std::string& name, const size_t chan) override; + const std::string& name, const size_t chan) const override; freq_range_t get_tx_lo_freq_range( const std::string& name, const size_t chan) override; void set_tx_lo_source( diff --git a/host/lib/rfnoc/radio_control_impl.cpp b/host/lib/rfnoc/radio_control_impl.cpp index 00cdd12ae..709bbd87d 100644 --- a/host/lib/rfnoc/radio_control_impl.cpp +++ b/host/lib/rfnoc/radio_control_impl.cpp @@ -689,7 +689,7 @@ void radio_control_impl::set_rx_lo_export_enabled(bool, const std::string&, cons "set_rx_lo_export_enabled is not supported on this radio"); } -bool radio_control_impl::get_rx_lo_export_enabled(const std::string&, const size_t) const +bool radio_control_impl::get_rx_lo_export_enabled(const std::string&, const size_t) { return false; } @@ -709,7 +709,7 @@ std::vector radio_control_impl::get_tx_lo_names(const size_t) const } std::vector radio_control_impl::get_tx_lo_sources( - const std::string&, const size_t) + const std::string&, const size_t) const { return {"internal"}; } diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp index 3881c9285..b84fcee6d 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.cpp @@ -767,7 +767,7 @@ void magnesium_radio_control_impl::set_rx_lo_source( const std::string magnesium_radio_control_impl::get_rx_lo_source( const std::string& name, const size_t /*chan*/ -) const +) { if (name == MAGNESIUM_LO1) { // TODO: should we use this from cache? @@ -1073,7 +1073,7 @@ eeprom_map_t magnesium_radio_control_impl::get_db_eeprom() /************************************************************************** * Sensor API *************************************************************************/ -std::vector magnesium_radio_control_impl::get_rx_sensor_names(size_t) +std::vector magnesium_radio_control_impl::get_rx_sensor_names(size_t) const { auto sensor_names = _rpcc->request_with_token>( this->_rpc_prefix + "get_sensors", "RX"); @@ -1092,7 +1092,7 @@ sensor_value_t magnesium_radio_control_impl::get_rx_sensor( _rpc_prefix + "get_sensor", "RX", name, chan)); } -std::vector magnesium_radio_control_impl::get_tx_sensor_names(size_t) +std::vector magnesium_radio_control_impl::get_tx_sensor_names(size_t) const { auto sensor_names = _rpcc->request_with_token>( this->_rpc_prefix + "get_sensors", "TX"); diff --git a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.hpp b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.hpp index 897e00868..f80f75f00 100644 --- a/host/lib/usrp/dboard/magnesium/magnesium_radio_control.hpp +++ b/host/lib/usrp/dboard/magnesium/magnesium_radio_control.hpp @@ -116,13 +116,14 @@ public: const std::string& name, const size_t chan) const override; void set_rx_lo_source( const std::string& src, const std::string& name, const size_t chan) override; - const std::string get_rx_lo_source(const std::string& name, const size_t chan) const; + const std::string get_rx_lo_source( + const std::string& name, const size_t chan) override; double set_rx_lo_freq( double freq, const std::string& name, const size_t chan) override; double get_rx_lo_freq(const std::string& name, const size_t chan) override; std::vector get_tx_lo_names(const size_t chan) const override; std::vector get_tx_lo_sources( - const std::string& name, const size_t chan) const; + const std::string& name, const size_t chan) const override; freq_range_t get_tx_lo_freq_range( const std::string& name, const size_t chan) override; void set_tx_lo_source( @@ -150,9 +151,9 @@ public: /************************************************************************** * Sensor API *************************************************************************/ - std::vector get_rx_sensor_names(size_t chan); + std::vector get_rx_sensor_names(size_t chan) const override; uhd::sensor_value_t get_rx_sensor(const std::string& name, size_t chan) override; - std::vector get_tx_sensor_names(size_t chan); + std::vector get_tx_sensor_names(size_t chan) const override; uhd::sensor_value_t get_tx_sensor(const std::string& name, size_t chan) override; /************************************************************************** diff --git a/host/lib/usrp/dboard/rhodium/rhodium_radio_control.hpp b/host/lib/usrp/dboard/rhodium/rhodium_radio_control.hpp index 4d5ce2cbd..696f81c85 100644 --- a/host/lib/usrp/dboard/rhodium/rhodium_radio_control.hpp +++ b/host/lib/usrp/dboard/rhodium/rhodium_radio_control.hpp @@ -107,7 +107,7 @@ public: double get_rx_lo_freq(const std::string& name, const size_t chan) override; std::vector get_tx_lo_names(const size_t chan) const override; std::vector get_tx_lo_sources( - const std::string& name, const size_t chan) const; + const std::string& name, const size_t chan) const override; freq_range_t get_tx_lo_freq_range( const std::string& name, const size_t chan) override; void set_tx_lo_source( @@ -123,7 +123,7 @@ public: void set_rx_lo_export_enabled( const bool enabled, const std::string& name, const size_t chan) override; bool get_tx_lo_export_enabled(const std::string& name, const size_t chan) override; - bool get_rx_lo_export_enabled(const std::string& name, const size_t chan); + bool get_rx_lo_export_enabled(const std::string& name, const size_t chan) override; /************************************************************************** * GPIO Controls diff --git a/host/lib/usrp/x300/x300_radio_control.cpp b/host/lib/usrp/x300/x300_radio_control.cpp index 3ab60e661..c6750e397 100644 --- a/host/lib/usrp/x300/x300_radio_control.cpp +++ b/host/lib/usrp/x300/x300_radio_control.cpp @@ -696,8 +696,7 @@ public: } } - bool get_rx_lo_export_enabled( - const std::string& name, const size_t chan) const override + bool get_rx_lo_export_enabled(const std::string& name, const size_t chan) override { fs_path rx_fe_fe_root = get_db_path("rx", chan); -- cgit v1.2.3