From 6d34bace870748e4def6cd6b1ec526eff3d4aac7 Mon Sep 17 00:00:00 2001 From: Thomas Tsou Date: Wed, 22 Jun 2011 13:24:15 -0700 Subject: [PATCH] transceiver: reinsert digital gain scaling Commit e161523c (transceiver: simplify transmit power control) changed transmit gain control to RF setting only. This was appropriate for a WBX board with 25 dB of gain control, but inappropriate for an RFX with fixed transmit gain. RFX boards will regain the ability to set transmit attenuation. Since gain is set on the RF side first, reintroducing digital gain settings should have limited overall effect on non-RFX daughterboards. Signed-off-by: Thomas Tsou --- public-trunk/Transceiver/radioInterface.cpp | 13 +++++++-- public-trunk/Transceiver/radioInterface.h | 2 ++ .../Transceiver52M/radioInterface.cpp | 27 +++++++++++++++---- public-trunk/Transceiver52M/radioInterface.h | 5 +++- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/public-trunk/Transceiver/radioInterface.cpp b/public-trunk/Transceiver/radioInterface.cpp index d38fb30..d3b5ec8 100644 --- a/public-trunk/Transceiver/radioInterface.cpp +++ b/public-trunk/Transceiver/radioInterface.cpp @@ -58,6 +58,7 @@ RadioInterface::RadioInterface(RadioDevice *wUsrp, receiveOffset = wReceiveOffset; samplesPerSymbol = wSamplesPerSymbol; mClock.set(wStartTime); + powerScaling = 1.0; } RadioInterface::~RadioInterface(void) { @@ -81,7 +82,15 @@ double RadioInterface::fullScaleOutputValue(void) { void RadioInterface::setPowerAttenuation(double atten) { - usrp->setTxGain(usrp->maxTxGain() - atten); + double rfAtten, digAtten; + + rfAtten = usrp->setTxGain(usrp->maxTxGain() - atten); + digAtten = atten - rfAtten; + + if (digAtten < 1.0) + powerScaling = 1.0; + else + powerScaling = 1.0/sqrt(pow(10, (digAtten/10.0))); } short *RadioInterface::USRPifyVector(signalVector &wVector) @@ -149,7 +158,7 @@ void RadioInterface::pushBuffer(void) { delete inputVector; // Set transmit gain and power here. - scaleVector(*resampledVector, usrp->fullScaleInputValue()); + scaleVector(*resampledVector, powerScaling * usrp->fullScaleInputValue()); short *resampledVectorShort = USRPifyVector(*resampledVector); diff --git a/public-trunk/Transceiver/radioInterface.h b/public-trunk/Transceiver/radioInterface.h index 94d0166..e2d4336 100644 --- a/public-trunk/Transceiver/radioInterface.h +++ b/public-trunk/Transceiver/radioInterface.h @@ -142,6 +142,8 @@ private: bool mOn; ///< indicates radio is on + float powerScaling; + /** format samples to USRP */ short *USRPifyVector(signalVector &wVector); diff --git a/public-trunk/Transceiver52M/radioInterface.cpp b/public-trunk/Transceiver52M/radioInterface.cpp index add4c3c..5a4ad20 100644 --- a/public-trunk/Transceiver52M/radioInterface.cpp +++ b/public-trunk/Transceiver52M/radioInterface.cpp @@ -91,6 +91,7 @@ RadioInterface::RadioInterface(RadioDevice *wRadio, receiveOffset = wReceiveOffset; samplesPerSymbol = wRadioOversampling; mClock.set(wStartTime); + powerScaling = 1.0; } RadioInterface::~RadioInterface(void) { @@ -108,10 +109,21 @@ double RadioInterface::fullScaleOutputValue(void) { void RadioInterface::setPowerAttenuation(double atten) { - mRadio->setTxGain(mRadio->maxTxGain() - atten); + double rfAtten, digAtten; + + rfAtten = mRadio->setTxGain(mRadio->maxTxGain() - atten); + digAtten = atten - rfAtten; + + if (digAtten < 1.0) + powerScaling = 1.0; + else + powerScaling = 1.0/sqrt(pow(10, (digAtten/10.0))); } -short *RadioInterface::radioifyVector(signalVector &wVector, short *retVector, bool zeroOut) +short *RadioInterface::radioifyVector(signalVector &wVector, + short *retVector, + float scale, + bool zeroOut) { signalVector::iterator itr = wVector.begin(); short *shortItr = retVector; @@ -121,8 +133,13 @@ short *RadioInterface::radioifyVector(signalVector &wVector, short *retVector, b *shortItr++ = 0; itr++; } - } - else { + } else if (scale != 1.0) { + while (itr < wVector.end()) { + *shortItr++ = (short) (itr->real() * scale); + *shortItr++ = (short) (itr->imag() * scale); + itr++; + } + } else { while (itr < wVector.end()) { *shortItr++ = (short) (itr->real()); *shortItr++ = (short) (itr->imag()); @@ -238,7 +255,7 @@ void RadioInterface::driveTransmitRadio(signalVector &radioBurst, bool zeroBurst if (!mOn) return; - radioifyVector(radioBurst, sendBuffer+sendCursor, zeroBurst); + radioifyVector(radioBurst, sendBuffer+sendCursor, powerScaling, zeroBurst); sendCursor += (radioBurst.size()*2); diff --git a/public-trunk/Transceiver52M/radioInterface.h b/public-trunk/Transceiver52M/radioInterface.h index b9ae608..27dfc14 100644 --- a/public-trunk/Transceiver52M/radioInterface.h +++ b/public-trunk/Transceiver52M/radioInterface.h @@ -161,7 +161,10 @@ private: double powerScaling; /** format samples to USRP */ - short *radioifyVector(signalVector &wVector, short *shortVector, bool zeroOut); + short *radioifyVector(signalVector &wVector, + short *shortVector, + float scale, + bool zeroOut); /** format samples from USRP */ void unRadioifyVector(short *shortVector, signalVector &wVector);