# run_l_dfetest_lte20_lab1b
# this lab shows the generate test script radio framework.
# it requires file management, to update specific files, and scripts
#  
echo Start RFSDK with JESD loopback to illustrate loading BBTx, unloading BBRx files

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

# capture method = 1 (csv - 4K), = 2 (bin - 10ms)
CAPTUREMETHOD=1

if [ "CAPTUREMETHOD" == "1" ]
then
   # erase previous test results
   cd /srv/www/data/
   rm -f dsp_psd_dfe*.csv
   rm -f dsp_dfe*.csv

   cd /usr/share/radio/tests/rf-verif
   rm -f dsp_rx*.csv
   rm -f dsp_psd_rx*.csv
elif [ "CAPTUREMETHOD" == "2" ]
then
   # erase previous bin files
   cd /srv/www/data/
   rm -f dsp_bbrx*.bin
fi

# start the test 
radio reset
echo selecting 2x2-2xLTE20 Tx0->Rx0, Tx1->Rx1 JESD loopback
echo doesnt test feedback
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 this is JESD loopback..
radio on $RFSDK_UPLINK_CN $RFSDK_DOWNLINK_CN

echo load single tone at center frequency 1Mhz on TX1 and -2Mhz TX2, scaled to -7dbfs
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

read -p "use RFSDK webpage to look at the DFE Tx, DFE Rx, and DSP Rx graphs, then depress Enter to capture bbrx" 

echo reading the BB Power meter
radio pmread

echo capture BBRx data from the JESD loopback
# collects the BBRx data from the DSP and saves to file

if [ "CAPTUREMETHOD" == "1" ]
then 
   radio capture_dsp /usr/share/radio/tests/rf-verif
   # copy data for analysis
   cp /usr/share/radio/tests/rf-verif/dsp_rx1.csv /srv/www/data/dsp_dfe0rx1.csv
   cp /usr/share/radio/tests/rf-verif/dsp_rx2.csv /srv/www/data/dsp_dfe0rx2.csv
   cp /usr/share/radio/tests/rf-verif/dsp_psd_rx1.csv /srv/www/data/dsp_psd_dfe0rx1.csv
   cp /usr/share/radio/tests/rf-verif/dsp_psd_rx2.csv /srv/www/data/dsp_psd_dfe0rx2.csv
elif [ "CAPTUREMETHOD" == "2" ]
then
   # note the second 1 and 2 are the Axc# + 1
   playback capture 
   playback save 1 1 /srv/www/data/dsp_bbrx0.bin
   playback save 1 2 /srv/www/data/dsp_bbrx1.bin
fi

read -p "depress Enter when complete" 

playback stop
radio off