From 992c9bd1cea410e2dd42ce7566299104b5648aff Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 8 Jun 2020 13:44:24 +0200 Subject: [PATCH] radioInterface: Operate on real Tx power attenuation rather than on device specific gains All the Tx gain related APIs are left out of reach from radioInterface, and in there we simply interact with radioDevice passing the attenuation received from TRXC. Prior gain logic is moved in base radiodevice class, with the idea that the setTxGain() and related functions will be dropped over time in each sublcass in favour of an specific implementation of the SetPowerAttenuation API. Change-Id: I4f8a1bcbed74aa9310306b97b0b1bfb02f7855e6 --- Transceiver52M/device/common/radioDevice.h | 33 ++++++++++++++-------- Transceiver52M/device/lms/LMSDevice.h | 27 +++++++++--------- Transceiver52M/device/uhd/UHDDevice.h | 10 +++---- Transceiver52M/device/usrp1/USRPDevice.h | 24 ++++++++-------- Transceiver52M/radioInterface.cpp | 11 ++------ Transceiver52M/radioInterface.h | 8 ++---- Transceiver52M/radioInterfaceMulti.cpp | 7 ++--- 7 files changed, 59 insertions(+), 61 deletions(-) diff --git a/Transceiver52M/device/common/radioDevice.h b/Transceiver52M/device/common/radioDevice.h index 8dd8f49d..e51527d2 100644 --- a/Transceiver52M/device/common/radioDevice.h +++ b/Transceiver52M/device/common/radioDevice.h @@ -125,21 +125,9 @@ class RadioDevice { /** return minimum Rx Gain **/ virtual double minRxGain(void) = 0; - /** sets the transmit chan gain, returns the gain setting **/ - virtual double setTxGain(double dB, size_t chan = 0) = 0; - /** returns the Nominal transmit output power of the transceiver in dBm, negative on error **/ virtual int getNominalTxPower(size_t chan = 0) = 0; - /** get transmit gain */ - virtual double getTxGain(size_t chan = 0) = 0; - - /** return maximum Tx Gain **/ - virtual double maxTxGain(void) = 0; - - /** return minimum Tx Gain **/ - virtual double minTxGain(void) = 0; - /** sets the RX path to use, returns true if successful and false otherwise */ virtual bool setRxAntenna(const std::string &ant, size_t chan = 0) = 0; @@ -163,6 +151,18 @@ class RadioDevice { virtual double getRxFreq(size_t chan = 0) = 0; virtual double getSampleRate()=0; + /* Default backward-compatible implementation based on TxGain APIs. New + implementations should be based on getNominalTxPower() once implemented for + the specific backend. */ + virtual double setPowerAttenuation(int atten, size_t chan) { + double rfGain; + rfGain = setTxGain(maxTxGain() - atten, chan); + return maxTxGain() - rfGain; + } + virtual double getPowerAttenuation(size_t chan=0) { + return maxTxGain() - getTxGain(chan); + } + protected: size_t tx_sps, rx_sps; InterfaceType iface; @@ -171,6 +171,15 @@ class RadioDevice { std::vector tx_paths, rx_paths; std::vector m_ctr; + /** sets the transmit chan gain, returns the gain setting **/ + virtual double setTxGain(double dB, size_t chan = 0) = 0; + + /** get transmit gain */ + virtual double getTxGain(size_t chan = 0) = 0; + + /** return maximum Tx Gain **/ + virtual double maxTxGain(void) = 0; + RadioDevice(size_t tx_sps, size_t rx_sps, InterfaceType type, size_t chan_num, double offset, const std::vector& tx_paths, const std::vector& rx_paths): diff --git a/Transceiver52M/device/lms/LMSDevice.h b/Transceiver52M/device/lms/LMSDevice.h index 78fd62a2..c83fed26 100644 --- a/Transceiver52M/device/lms/LMSDevice.h +++ b/Transceiver52M/device/lms/LMSDevice.h @@ -77,6 +77,19 @@ private: void update_stream_stats_rx(size_t chan, bool *overrun); void update_stream_stats_tx(size_t chan, bool *underrun); bool do_clock_src_freq(enum ReferenceType ref, double freq); + /** sets the transmit chan gain, returns the gain setting **/ + double setTxGain(double dB, size_t chan = 0); + + /** get transmit gain */ + double getTxGain(size_t chan = 0) { + return tx_gains[chan]; + } + + /** return maximum Tx Gain **/ + double maxTxGain(void); + + /** return minimum Rx Gain **/ + double minTxGain(void); public: @@ -165,20 +178,6 @@ public: /** return minimum Rx Gain **/ double minRxGain(void); - /** sets the transmit chan gain, returns the gain setting **/ - double setTxGain(double dB, size_t chan = 0); - - /** get transmit gain */ - double getTxGain(size_t chan = 0) { - return tx_gains[chan]; - } - - /** return maximum Tx Gain **/ - double maxTxGain(void); - - /** return minimum Rx Gain **/ - double minTxGain(void); - int getNominalTxPower(size_t chan = 0); /** sets the RX path to use, returns true if successful and false otherwise */ diff --git a/Transceiver52M/device/uhd/UHDDevice.h b/Transceiver52M/device/uhd/UHDDevice.h index 8a2d5926..d87caf27 100644 --- a/Transceiver52M/device/uhd/UHDDevice.h +++ b/Transceiver52M/device/uhd/UHDDevice.h @@ -101,11 +101,6 @@ public: double maxRxGain(void) { return rx_gain_max; } double minRxGain(void) { return rx_gain_min; } - 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; } - int getNominalTxPower(size_t chan = 0); double getTxFreq(size_t chan); @@ -136,6 +131,11 @@ 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; } + uhd::usrp::multi_usrp::sptr usrp_dev; uhd::tx_streamer::sptr tx_stream; uhd::rx_streamer::sptr rx_stream; diff --git a/Transceiver52M/device/usrp1/USRPDevice.h b/Transceiver52M/device/usrp1/USRPDevice.h index 05491920..1c1b3bea 100644 --- a/Transceiver52M/device/usrp1/USRPDevice.h +++ b/Transceiver52M/device/usrp1/USRPDevice.h @@ -85,6 +85,18 @@ private: int writeSamplesControl(std::vector &bufs, int len, bool *underrun, TIMESTAMP timestamp = 0xffffffff, bool isControl = false); + /** sets the transmit chan gain, returns the gain setting **/ + double setTxGain(double dB, size_t chan = 0); + + /** get transmit gain */ + double getTxGain(size_t chan = 0) { return txGain; } + + /** return maximum Tx Gain **/ + double maxTxGain(void); + + /** return minimum Rx Gain **/ + double minTxGain(void); + #ifdef SWLOOPBACK short loopbackBuffer[1000000]; int loopbackBufferSize; @@ -168,18 +180,6 @@ private: /** return minimum Rx Gain **/ double minRxGain(void); - /** sets the transmit chan gain, returns the gain setting **/ - double setTxGain(double dB, size_t chan = 0); - - /** get transmit gain */ - double getTxGain(size_t chan = 0) { return txGain; } - - /** return maximum Tx Gain **/ - double maxTxGain(void); - - /** return minimum Rx Gain **/ - double minTxGain(void); - int getNominalTxPower(size_t chan = 0); /** sets the RX path to use, returns true if successful and false otherwise */ diff --git a/Transceiver52M/radioInterface.cpp b/Transceiver52M/radioInterface.cpp index fb724d25..adc2ee7a 100644 --- a/Transceiver52M/radioInterface.cpp +++ b/Transceiver52M/radioInterface.cpp @@ -103,7 +103,7 @@ double RadioInterface::fullScaleOutputValue(void) { int RadioInterface::setPowerAttenuation(int atten, size_t chan) { - double rfGain, digAtten; + double rfAtten, digAtten; if (chan >= mChans) { LOG(ALERT) << "Invalid channel requested"; @@ -113,8 +113,8 @@ int RadioInterface::setPowerAttenuation(int atten, size_t chan) if (atten < 0.0) atten = 0.0; - rfGain = setTxGain(mDevice->maxTxGain() - (double) atten, chan); - digAtten = (double) atten - mDevice->maxTxGain() + rfGain; + rfAtten = mDevice->setPowerAttenuation((double) atten, chan); + digAtten = (double) atten - rfAtten; if (digAtten < 1.0) powerScaling[chan] = 1.0; @@ -318,11 +318,6 @@ double RadioInterface::setRxGain(double dB, size_t chan) return mDevice->setRxGain(dB, chan); } -double RadioInterface::setTxGain(double dB, size_t chan) -{ - return mDevice->setTxGain(dB, chan); -} - /* Receive a timestamped chunk from the device */ int RadioInterface::pullBuffer() { diff --git a/Transceiver52M/radioInterface.h b/Transceiver52M/radioInterface.h index eb7ed3bc..8e5f4c17 100644 --- a/Transceiver52M/radioInterface.h +++ b/Transceiver52M/radioInterface.h @@ -116,7 +116,8 @@ public: /** drive reception of GSM bursts. -1: Error. 0: Radio off. 1: Received something. */ int driveReceiveRadio(); - int setPowerAttenuation(int atten, size_t chan = 0); + /** set transmit power attenuation */ + virtual int setPowerAttenuation(int atten, size_t chan = 0); int getNominalTxPower(size_t chan = 0); /** returns the full-scale transmit amplitude **/ @@ -135,9 +136,6 @@ protected: /** drive synchronization of Tx/Rx of USRP */ void alignRadio(); - /** set transmit gain */ - virtual double setTxGain(double dB, size_t chan = 0); - friend void *AlignRadioServiceLoopAdapter(RadioInterface*); }; @@ -167,7 +165,7 @@ private: bool pushBuffer(); int pullBuffer(); bool verify_arfcn_consistency(double freq, size_t chan, bool tx); - virtual double setTxGain(double dB, size_t chan); + virtual int setPowerAttenuation(int atten, size_t chan = 0); signalVector *outerSendBuffer; signalVector *outerRecvBuffer; diff --git a/Transceiver52M/radioInterfaceMulti.cpp b/Transceiver52M/radioInterfaceMulti.cpp index a0c24b5b..29f85ca0 100644 --- a/Transceiver52M/radioInterfaceMulti.cpp +++ b/Transceiver52M/radioInterfaceMulti.cpp @@ -437,11 +437,8 @@ double RadioInterfaceMulti::setRxGain(double db, size_t chan) return mDevice->getRxGain(); } -double RadioInterfaceMulti::setTxGain(double dB, size_t chan) +int RadioInterfaceMulti::setPowerAttenuation(int atten, size_t chan) { - if (chan == 0) - return mDevice->setTxGain(dB); - else - return mDevice->getTxGain(); + return RadioInterface::setPowerAttenuation(atten, 0); }