#!/usr/bin/env python # # Copyright 2004 Free Software Foundation, Inc. # # This file is part of GNU Radio # # GNU Radio is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # GNU Radio is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Radio; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # from gnuradio import gr, gru, gr_unittest, usrp import rad import os import types def dbgit(): import os fname = '/var/run/qa_rad.pid' f = open( fname, 'w') f.write(str(os.getpid())); f.close() print 'Blocked waiting for GDB attach (pid=%d in %s)' % (os.getpid(),fname) raw_input('Press ENTER to continue:') def pick_subdevice(u): """ The user didn't specify a subdevice on the command line. If there's a daughterboard on A, select A. If there's a daughterboard on B, select B. Otherwise, select A. """ if u.db[0][0].dbid() >= 0: # dbid is < 0 if there's no d'board or a problem return (0, 0) if u.db[1][0].dbid() >= 0: return (1, 0) return (0, 0) class qa_lee (gr_unittest.TestCase): def setUp (self): self.fg = gr.flow_graph () def tearDown (self): self.fg = None def test_002_rad (self): #dbgit() ofile = '../../../dat/output.dat' ifile = '../../../dat/test_pulse2.dat'; Ns = 20; Dr = 49999; ifile = '../../../dat/test_pulse.dat'; Ns = 100000; Dr = 0; ifile = '../../../dat/test_pulse.dat'; Ns = 12500; Dr = 27500; ifile = '../../../dat/test_pulse_ramp.dat'; Ns = 100; Dr = 0; ifile = '../../../dat/test_wav.dat'; Ns = 40; Dr = 0; ifile = '../../../dat/test_rcos.dat'; Ns = 1016; Dr = 0; ifile = '../../../dat/test_const.dat'; Ns = 40; Dr = 0; ifile = '../../../dat/test_imp.dat'; Ns = 201; Dr = 0; ifile = '../../../dat/test_bark5.dat'; Ns = 1375; Dr = 0; tx_interp = 32 rx_decim = 16 use_tx = 1 use_rx = 1 use_auto = 0 use_tune = 0 side = 'A' rx_antenna = 'TX/RX' rx_antenna = 'RX2' N = -1 D = 1000000 D = 0 src = rad.wvfm_source_c( ifile, N, D); #src = gr.file_source( gr.sizeof_gr_complex, ifile, 1); #src = gr.sig_source_c ( 4e6, gr.GR_SIN_WAVE, 100.123e3, 32000, 0); #dst = rad.wvfm_sink_c( ofile, src, 0, Dr, Ns) dst = gr.file_sink( gr.sizeof_gr_complex , ofile); rf_freq = 450e6 rf_freq = 2400e6 if not use_tune: rf_freq = rf_freq - 4e6 pick_subdev = 0 if side == 'A': subdev_spec = (0,0) elif side == 'B': subdev_spec = (1,0) else: pick_subdev = 1 #src = gr.sig_source_c ( 128e6/tx_interp, gr.GR_CONST_WAVE, 100.12345e3, 32000, 0.0) if use_tx: u_snk = usrp.sink_c(interp_rate=tx_interp) #u_snk.set_nchannels(1) if pick_subdev: tx_subdev_spec = pick_subdevice(u_snk) else: tx_subdev_spec = subdev_spec mux_val = usrp.determine_tx_mux_value(u_snk, tx_subdev_spec) u_snk.set_mux( mux_val) subdev = usrp.selected_subdev(u_snk, tx_subdev_spec) subdev.set_enable(True) print "TX using", subdev.name() print "TX spec ", tx_subdev_spec subdev.set_gain( subdev.gain_range()[1] ) if use_auto: subdev.set_auto_tr(True) if use_tune: tune = u_snk.tune(0, subdev, rf_freq) if tune: print "Tx baseband: %g" % tune.baseband_freq print "Tx ddc : %g" % tune.dxc_freq print "Tx residual: %g" % tune.residual_freq print "Tx invert : %g" % tune.inverted else: (success,actual_freq) = subdev.set_freq( rf_freq) if not success: print "Failed on Tx. RF frequency ", rf_freq print "Tx. RF Frequency: %s" % actual_freq print "Tx DAC freq = ", u_snk.dac_freq() if use_rx: #rf_freq = rf_freq + 8e6 u_src = usrp.source_c(decim_rate=rx_decim) if pick_subdev: rx_subdev_spec = pick_subdevice(u_src) else: rx_subdev_spec = subdev_spec u_src.set_mux(usrp.determine_rx_mux_value(u_src, rx_subdev_spec)) subdev = usrp.selected_subdev(u_src, rx_subdev_spec) print "RX using", subdev.name() print "RX spec ", rx_subdev_spec subdev.select_rx_antenna( rx_antenna) if use_auto: subdev.set_auto_tr(True) g = subdev.gain_range() gain = float(g[0]+g[1])/2 print "Rx. Gain Range: ", g subdev.set_gain(g[1]) if use_tune: tune = u_src.tune(0, subdev, rf_freq) if tune: print "Rx baseband: %g" % tune.baseband_freq print "Rx ddc : %g" % tune.dxc_freq print "Rx residual: %g" % tune.residual_freq print "Rx invert : %g" % tune.inverted else: (success,actual_freq) = subdev.set_freq( rf_freq) if not success: print "Failed on Rx. RF frequency ", rf_freq print "Rx. RF Frequency: %s" % actual_freq print "Rx ADC freq = ", u_src.adc_freq() fg = gr.flow_graph () if use_tx or use_rx: if use_tx: fg.connect ( src, u_snk) if use_rx: fg.connect ( u_src, dst) else: fg.connect ( src, dst) fg.run() return if __name__ == '__main__': gr_unittest.main ()