diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-06-08 14:49:33 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2020-06-15 10:41:16 +0200 |
commit | b899c19f1f5f6154a77e672e2b0d2b1709168b3c (patch) | |
tree | e7b2f9633c632d07a4d7677b9b70784b4c38649e | |
parent | 992c9bd1cea410e2dd42ce7566299104b5648aff (diff) |
UHDDevice: Compute TxGain on UHD API based on expected Tx output power
Right now, according to a few measurements taken on B210, we expect the
Tx Gain at UHD level to relate 1:1 with the slope in Tx output power
given a specific band.
If more fine-grained results are wanted or some device doesn't follow a
1:1 slope relationship, functions TxGain2TxPower and TxPower2TxGain need
to be adapted/improved.
Change-Id: I6f432465dce5c6ec1f1bc4653f6149efb18c3f43
-rw-r--r-- | Transceiver52M/device/uhd/UHDDevice.cpp | 88 | ||||
-rw-r--r-- | Transceiver52M/device/uhd/UHDDevice.h | 11 |
2 files changed, 55 insertions, 44 deletions
diff --git a/Transceiver52M/device/uhd/UHDDevice.cpp b/Transceiver52M/device/uhd/UHDDevice.cpp index 93dde4b..d1f61d3 100644 --- a/Transceiver52M/device/uhd/UHDDevice.cpp +++ b/Transceiver52M/device/uhd/UHDDevice.cpp @@ -212,12 +212,23 @@ static void uhd_msg_handler(uhd::msg::type_t type, const std::string &msg) } #endif +/* So far measurements done for B210 show really close to linear relationship + * between gain and real output power, so we simply adjust the measured offset + */ +static double TxGain2TxPower(const dev_band_desc &desc, double tx_gain_db) +{ + return desc.nom_out_tx_power - (desc.nom_uhd_tx_gain - tx_gain_db); +} +static double TxPower2TxGain(const dev_band_desc &desc, double tx_power_dbm) +{ + return desc.nom_uhd_tx_gain - (desc.nom_out_tx_power - tx_power_dbm); +} + uhd_device::uhd_device(size_t tx_sps, size_t rx_sps, InterfaceType iface, size_t chan_num, double lo_offset, const std::vector<std::string>& tx_paths, const std::vector<std::string>& rx_paths) : RadioDevice(tx_sps, rx_sps, iface, chan_num, lo_offset, tx_paths, rx_paths), - tx_gain_min(0.0), tx_gain_max(0.0), rx_gain_min(0.0), rx_gain_max(0.0), band((enum gsm_band)0), tx_spp(0), rx_spp(0), started(false), aligned(false), drop_cnt(0), @@ -256,6 +267,7 @@ void uhd_device::get_dev_band_desc(dev_band_desc& desc) void uhd_device::init_gains() { + double tx_gain_min, tx_gain_max; uhd::gain_range_t range; if (dev_type == UMTRX) { @@ -320,13 +332,43 @@ void uhd_device::set_rates() LOGC(DDEV, INFO) << "Rates configured for " << desc.str; } -double uhd_device::setTxGain(double db, size_t chan) +double uhd_device::setRxGain(double db, size_t chan) { + if (chan >= rx_gains.size()) { + LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; + return 0.0f; + } + + usrp_dev->set_rx_gain(db, chan); + rx_gains[chan] = usrp_dev->get_rx_gain(chan); + + LOGC(DDEV, INFO) << "Set RX gain to " << rx_gains[chan] << "dB (asked for " << db << "dB)"; + + return rx_gains[chan]; +} + +double uhd_device::getRxGain(size_t chan) +{ + if (chan >= rx_gains.size()) { + LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; + return 0.0f; + } + + return rx_gains[chan]; +} + +double uhd_device::setPowerAttenuation(int atten, size_t chan) { + double db; + dev_band_desc desc; + if (chan >= tx_gains.size()) { LOGC(DDEV, ALERT) << "Requested non-existent channel" << chan; return 0.0f; } + get_dev_band_desc(desc); + db = TxPower2TxGain(desc, desc.nom_out_tx_power - atten); + if (dev_type == UMTRX) { std::vector<std::string> gain_stages = usrp_dev->get_tx_gain_names(0); if (gain_stages[0] == "VGA" || gain_stages[0] == "PA") { @@ -348,42 +390,17 @@ double uhd_device::setTxGain(double db, size_t chan) LOGC(DDEV, INFO) << "Set TX gain to " << tx_gains[chan] << "dB (asked for " << db << "dB)"; - return tx_gains[chan]; + return desc.nom_out_tx_power - TxGain2TxPower(desc, tx_gains[chan]); } - -double uhd_device::setRxGain(double db, size_t chan) -{ - if (chan >= rx_gains.size()) { - LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; - return 0.0f; - } - - usrp_dev->set_rx_gain(db, chan); - rx_gains[chan] = usrp_dev->get_rx_gain(chan); - - LOGC(DDEV, INFO) << "Set RX gain to " << rx_gains[chan] << "dB (asked for " << db << "dB)"; - - return rx_gains[chan]; -} - -double uhd_device::getRxGain(size_t chan) -{ - if (chan >= rx_gains.size()) { - LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; - return 0.0f; - } - - return rx_gains[chan]; -} - -double uhd_device::getTxGain(size_t chan) -{ +double uhd_device::getPowerAttenuation(size_t chan) { + dev_band_desc desc; if (chan >= tx_gains.size()) { LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; return 0.0f; } - return tx_gains[chan]; + get_dev_band_desc(desc); + return desc.nom_out_tx_power - TxGain2TxPower(desc, tx_gains[chan]); } int uhd_device::getNominalTxPower(size_t chan) @@ -1007,7 +1024,6 @@ bool uhd_device::setTxFreq(double wFreq, size_t chan) { uint16_t req_arfcn; enum gsm_band req_band; - dev_band_desc desc; if (chan >= tx_freqs.size()) { LOGC(DDEV, ALERT) << "Requested non-existent channel " << chan; @@ -1036,12 +1052,6 @@ bool uhd_device::setTxFreq(double wFreq, size_t chan) return false; band = req_band; - - /* Update Max Tx Gain */ - get_dev_band_desc(desc); - tx_gain_max = desc.nom_uhd_tx_gain; - LOGCHAN(chan, DDEV, INFO) << "Updating max Gain to " << tx_gain_max - << " dB based on GSM band information"; return true; } diff --git a/Transceiver52M/device/uhd/UHDDevice.h b/Transceiver52M/device/uhd/UHDDevice.h index d87caf2..2c428ca 100644 --- a/Transceiver52M/device/uhd/UHDDevice.h +++ b/Transceiver52M/device/uhd/UHDDevice.h @@ -101,6 +101,9 @@ public: double maxRxGain(void) { return rx_gain_max; } double minRxGain(void) { return rx_gain_min; } + double setPowerAttenuation(int atten, size_t chan); + double getPowerAttenuation(size_t chan = 0); + int getNominalTxPower(size_t chan = 0); double getTxFreq(size_t chan); @@ -131,10 +134,9 @@ public: }; private: - double setTxGain(double db, size_t chan); - double getTxGain(size_t chan = 0); - double maxTxGain(void) { return tx_gain_max; } - double minTxGain(void) { return tx_gain_min; } + double setTxGain(double db, size_t chan) {OSMO_ASSERT(false); return 0.0f; } + double getTxGain(size_t chan = 0) { OSMO_ASSERT(false); return 0.0f; }; + double maxTxGain(void) { OSMO_ASSERT(false); return 0.0f; }; uhd::usrp::multi_usrp::sptr usrp_dev; uhd::tx_streamer::sptr tx_stream; @@ -144,7 +146,6 @@ private: double tx_rate, rx_rate; - double tx_gain_min, tx_gain_max; double rx_gain_min, rx_gain_max; std::vector<double> tx_gains, rx_gains; |