#!/usr/bin/env python # This program reads waveform data from the file "bbc_tx.dat" and sends # it to the USRP for broadcast. # This file was derived from the usrp_siggen.py file that came with # GNU Radio. It was stripped to just the essentials needed to transmit # a baseband signal from a complex file source. # The file format is complex IQ data pairs where both values are IEEE # single-precision floating point numbers in little endian format. # The first value is I and the second value is Q. The data is present # only on the I data. The Q data is all zeros. from gnuradio import gr, gru from gnuradio import usrp from gnuradio.eng_option import eng_option from gnuradio import eng_notation from optparse import OptionParser import sys class bbc_tx_graph(gr.flow_graph): def __init__ (self): gr.flow_graph.__init__(self) #default interpolator rate self.interp = 64 was_running = self.is_running () if was_running: self.stop () # Configure flow graph self.disconnect_all () self.txfile = gr.file_source (gr.sizeof_gr_complex, "usrp.srp", 1) self.usrp = usrp.sink_c (0, self.interp) self.connect (self.txfile, self.usrp) if was_running: self.start () def usb_freq (self): return self.usrp.dac_freq() / self.interp def usb_throughput (self): return self.usb_freq () * 4 def set_interpolator (self, interp): self.interp = interp self.usrp.set_interp_rate (interp) def set_freq(self, target_freq): """ Set the center frequency we're interested in. @param target_freq: frequency in Hz @rypte: bool Tuning is a two step process. First we ask the front-end to tune as close to the desired frequency as it can. Then we use the result of that operation and our target_frequency to determine the value for the digital up converter. """ r = self.usrp.tune(self.subdev._which, self.subdev, target_freq) if r: print "r.baseband_freq =", eng_notation.num_to_str(r.baseband_freq) print "r.dxc_freq =", eng_notation.num_to_str(r.dxc_freq) print "r.residual_freq =", eng_notation.num_to_str(r.residual_freq) print "r.inverted =", r.inverted return True return False def main (): parser = OptionParser (option_class=eng_option) parser.add_option ("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Tx side A or B (may also use A:0 or A:1 format)") parser.add_option ("-f", "--rf-freq", type="eng_float", default=None, help="set RF center frequency to FREQ") parser.add_option ("-i", "--interp", type="int", default=64, help="set fgpa interpolation rate to INTERP") (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() raise SystemExit if options.rf_freq is None: sys.stderr.write("usrp_siggen: must specify RF center frequency with -f RF_FREQ\n") parser.print_help() raise SystemExit fg = bbc_tx_graph() fg.set_interpolator (options.interp) # determine the daughterboard subdevice we're using if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(fg.u) m = usrp.determine_tx_mux_value(fg.usrp, options.tx_subdev_spec) #print "mux = %#04x" % (m,) fg.usrp.set_mux(m) fg.subdev = usrp.selected_subdev(fg.usrp, options.tx_subdev_spec) print "Using TX d'board %s" % (fg.subdev.side_and_name(),) fg.subdev.set_gain(fg.subdev.gain_range()[1]) # set max Tx gain if not fg.set_freq(options.rf_freq): sys.stderr.write('Failed to set RF frequency\n') raise SystemExit fg.subdev.set_enable(True) # enable transmitter try: fg.run() except KeyboardInterrupt: pass if __name__ == '__main__': main ()