# run_l_dfetest_lte20_lab1c
# this lab shows the generate test script radio framework.
# it requires file management, to update specific files, and scripts
# we load BBTx data with a specific gain, we adjust the digital gains using the dfe set 
# commands.
#    BBTx gain
#    SumChain gain 
#    PreCFR gain
#    PostCFR gain
#    Rx gain not adjusted currently - could adjust Rx equalizer impulse tap magnitude and sum
#    Feedback to CB gain not normally used - DPD has software gain
#    BBRx gain
#
# note: in the standard small cell configurations, -6.5dbfs is the std CFR clipping point, so its best
# to not exceed -6.5db unless CFR is desired.   CFR CircLim setpoint is -6dbfs
# 
echo Start DFE BBGain test on Lamarr EVM in JESD Loopback in LTE20

# jesd loopback doesn't care about RF, but needs a value
RFSDK_UPLINK_CN=2140.0
RFSDK_DOWNLINK_CN=2140.0

# start the test 
radio reset
echo selecting 2x2-2xLTE20 Tx0->Rx0, Tx1->Rx1 JESD loopback
radio select 2x2-2xLTE20-SC-JESD3b-SD-Rxlb-jesdlpbk 
radio init

echo Starting the DSP
playback program 
playback start
sleep 3

echo Turning the radio on in JESD loopback..
radio on $RFSDK_UPLINK_CN $RFSDK_DOWNLINK_CN

echo load single tone at center frequency 1Mhz on TX1 and TX2
playback load 1 1 /usr/share/radio/patterns/onetoneIQ_30p72_1_m7_10ms.bin
playback load 1 2 /usr/share/radio/patterns/onetoneIQ_30p72_m2_m7_10ms.bin
sleep 1

echo initial gain values for test these are overriden from .tgtcfg
radio set dfe.baseband.tx[0].gain 0.0
radio set dfe.baseband.tx[1].gain 0.0
radio set dfe.baseband.rx[0].gain 0.0
radio set dfe.baseband.rx[1].gain 0.0
radio set dfe.stream[0].summerGain 0.0
radio set dfe.stream[1].summerGain 0.0
radio set dfe.stream[0].cfr.preGain 0.0
radio set dfe.stream[0].cfr.preGain 0.0
radio set dfe.stream[0].cfr.postGain 0.0
radio set dfe.stream[0].cfr.postGain 0.0

read -p "depress Enter to read power meter, after gain loading"
radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the difference for BBTx gain compare the two Axcs BBRx, and the web page peak values for Tx stream

radio set dfe.baseband.tx[0].gain -2.0

radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the difference for sumchain gain compare the two Axc BBRx, and the web page peak values for Tx stream

radio set dfe.baseband.tx[0].gain 0.0
radio set dfe.stream[1].summerGain -6.0

radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the difference for preCFRgain compare the two Axc BBRx, and the web page peak values for Tx stream

radio set dfe.stream[1].summerGain 0.0
radio set dfe.stream[0].cfr.preGain -3.0

radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the difference for postCFRgain compare the two Axc BBRx, and the web page peak values for Tx stream

radio set dfe.stream[0].cfr.preGain 0.0
radio set dfe.stream[1].cfr.postGain -4.0

radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1" 

echo in the next test, we can check the difference for BBRx gain from attenuated Tx streams compare the two Axc BBRx, and the web page peak values for Tx stream

radio set dfe.stream[0].cfr.postGain -6.0
radio set dfe.stream[1].cfr.postGain -6.0

radio pmread

echo now we adjust the BBRx gain to a positive gain value

radio set dfe.baseband.rx[0].gain 9.0
radio set dfe.baseband.rx[1].gain 9.0

radio pmread

read -p "use RFSDK webpage to look at the DFE BBTx, Tx, and BBRx for BBRx0 and BBRx1"

playback stop
radio off
