aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/include/uhd/usrp/multi_usrp.hpp57
-rw-r--r--host/lib/usrp/multi_usrp.cpp51
2 files changed, 108 insertions, 0 deletions
diff --git a/host/include/uhd/usrp/multi_usrp.hpp b/host/include/uhd/usrp/multi_usrp.hpp
index 2362ebcd7..cebfda5a2 100644
--- a/host/include/uhd/usrp/multi_usrp.hpp
+++ b/host/include/uhd/usrp/multi_usrp.hpp
@@ -26,6 +26,7 @@
#define UHD_USRP_MULTI_USRP_BW_RANGE_API
#define UHD_USRP_MULTI_USRP_USER_REGS_API
#define UHD_USRP_MULTI_USRP_GET_USRP_INFO_API
+#define UHD_USRP_MULTI_USRP_NORMALIZED_GAIN
#include <uhd/config.hpp>
#include <uhd/device.hpp>
@@ -495,6 +496,24 @@ public:
}
/*!
+ * Set the normalized RX gain value.
+ *
+ * The normalized gain is a value in [0, 1], where 0 is the
+ * smallest gain value available, and 1 is the largest, independent
+ * of the device. In between, gains are linearly interpolated.
+ *
+ * Check the individual device manual for notes on the gain range.
+ *
+ * Note that it is not possible to specify a gain name for
+ * this function, it will always set the overall gain.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual void set_normalized_rx_gain(double gain, size_t chan = 0) = 0;
+
+ /*!
* Get the RX gain value for the specified gain element.
* For an empty name, sum across all gain elements.
* \param name the name of the gain element
@@ -509,6 +528,19 @@ public:
}
/*!
+ * Return the normalized RX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion of normalized
+ * gains.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \returns The normalized gain (in [0, 1])
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual double get_normalized_rx_gain(size_t chan = 0) = 0;
+
+ /*!
* Get the RX gain range for the specified gain element.
* For an empty name, calculate the overall gain range.
* \param name the name of the gain element
@@ -733,6 +765,18 @@ public:
}
/*!
+ * Set the normalized TX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion on normalized
+ * gains.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual void set_normalized_tx_gain(double gain, size_t chan = 0) = 0;
+
+ /*!
* Get the TX gain value for the specified gain element.
* For an empty name, sum across all gain elements.
* \param name the name of the gain element
@@ -747,6 +791,19 @@ public:
}
/*!
+ * Return the normalized TX gain value.
+ *
+ * See set_normalized_rx_gain() for a discussion of normalized
+ * gains.
+ *
+ * \param gain the normalized gain value
+ * \param chan the channel index 0 to N-1
+ * \returns The normalized gain (in [0, 1])
+ * \throws A uhd::runtime_error if the gain value is outside [0, 1].
+ */
+ virtual double get_normalized_tx_gain(size_t chan = 0) = 0;
+
+ /*!
* Get the TX gain range for the specified gain element.
* For an empty name, calculate the overall gain range.
* \param name the name of the gain element
diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp
index e97787785..eab8c5283 100644
--- a/host/lib/usrp/multi_usrp.cpp
+++ b/host/lib/usrp/multi_usrp.cpp
@@ -831,6 +831,16 @@ public:
}
}
+ void set_normalized_rx_gain(double gain, size_t chan = 0)
+ {
+ if (gain > 1.0 || gain < 0.0) {
+ throw uhd::runtime_error("Normalized gain out of range, must be in [0, 1].");
+ }
+ gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan);
+ double abs_gain = (gain * (gain_range.stop() - gain_range.start())) + gain_range.start();
+ set_rx_gain(abs_gain, ALL_GAINS, chan);
+ }
+
double get_rx_gain(const std::string &name, size_t chan){
try {
return rx_gain_group(chan)->get_value(name);
@@ -839,6 +849,21 @@ public:
}
}
+ double get_normalized_rx_gain(size_t chan)
+ {
+ gain_range_t gain_range = get_rx_gain_range(ALL_GAINS, chan);
+ double gain_range_width = gain_range.stop() - gain_range.start();
+ // In case we have a device without a range of gains:
+ if (gain_range_width == 0.0) {
+ return 0;
+ }
+ double norm_gain = (get_rx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width;
+ // Avoid rounding errors:
+ if (norm_gain > 1.0) return 1.0;
+ if (norm_gain < 0.0) return 0.0;
+ return norm_gain;
+ }
+
gain_range_t get_rx_gain_range(const std::string &name, size_t chan){
try {
return rx_gain_group(chan)->get_range(name);
@@ -1032,6 +1057,17 @@ public:
}
}
+ void set_normalized_tx_gain(double gain, size_t chan = 0)
+ {
+ if (gain > 1.0 || gain < 0.0) {
+ throw uhd::runtime_error("Normalized gain out of range, must be in [0, 1].");
+ }
+ gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan);
+ double abs_gain = (gain * (gain_range.stop() - gain_range.start())) + gain_range.start();
+ set_tx_gain(abs_gain, ALL_GAINS, chan);
+ }
+
+
double get_tx_gain(const std::string &name, size_t chan){
try {
return tx_gain_group(chan)->get_value(name);
@@ -1040,6 +1076,21 @@ public:
}
}
+ double get_normalized_tx_gain(size_t chan)
+ {
+ gain_range_t gain_range = get_tx_gain_range(ALL_GAINS, chan);
+ double gain_range_width = gain_range.stop() - gain_range.start();
+ // In case we have a device without a range of gains:
+ if (gain_range_width == 0.0) {
+ return 0.0;
+ }
+ double norm_gain = (get_rx_gain(ALL_GAINS, chan) - gain_range.start()) / gain_range_width;
+ // Avoid rounding errors:
+ if (norm_gain > 1.0) return 1.0;
+ if (norm_gain < 0.0) return 0.0;
+ return norm_gain;
+ }
+
gain_range_t get_tx_gain_range(const std::string &name, size_t chan){
try {
return tx_gain_group(chan)->get_range(name);