diff options
author | Johnathan Corgan | 2011-10-27 13:03:31 -0700 |
---|---|---|
committer | Johnathan Corgan | 2011-10-29 11:02:32 -0700 |
commit | 7a439372b9fff02859af19cc6cb156a1cb4158c8 (patch) | |
tree | 706002f3e07c66c040a5acb9c3ae4843a586b234 /gr-pager | |
parent | b4aa46b77c37932efb25d736f73f6fcf563242e0 (diff) | |
download | gnuradio-7a439372b9fff02859af19cc6cb156a1cb4158c8.tar.gz gnuradio-7a439372b9fff02859af19cc6cb156a1cb4158c8.tar.bz2 gnuradio-7a439372b9fff02859af19cc6cb156a1cb4158c8.zip |
pager: update full band demodulator to use gr-uhd
Diffstat (limited to 'gr-pager')
-rwxr-xr-x | gr-pager/apps/usrp_flex_all.py | 129 |
1 files changed, 93 insertions, 36 deletions
diff --git a/gr-pager/apps/usrp_flex_all.py b/gr-pager/apps/usrp_flex_all.py index 14f9151de..71a0a398e 100755 --- a/gr-pager/apps/usrp_flex_all.py +++ b/gr-pager/apps/usrp_flex_all.py @@ -20,79 +20,136 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, usrp, optfir, eng_notation, blks2, pager +from gnuradio import gr, gru, uhd, optfir, eng_notation, blks2, pager from gnuradio.eng_option import eng_option from optparse import OptionParser from string import split, join, printable -import time +import sys class app_top_block(gr.top_block): def __init__(self, options, queue): gr.top_block.__init__(self, "usrp_flex_all") if options.from_file is not None: - src = gr.file_source(gr.sizeof_gr_complex, options.from_file) + self.u = gr.file_source(gr.sizeof_gr_complex, options.from_file) + self.nchan = options.nchan if options.verbose: print "Reading samples from file", options.from_file + print "User specified file contains", options.nchan, "25 KHz channels." + else: - src = usrp.source_c() - if options.rx_subdev_spec is None: - options.rx_subdev_spec = usrp.pick_rx_subdevice(src) - subdev = usrp.selected_subdev(src, options.rx_subdev_spec) - src.set_mux(usrp.determine_rx_mux_value(src, options.rx_subdev_spec)) - src.set_decim_rate(20) - result = usrp.tune(src, 0, subdev, 930.5125e6+options.calibration) + # Set up USRP source + self.u = uhd.usrp_source(device_addr=options.address, + io_type=uhd.io_type.COMPLEX_FLOAT32, + num_channels=1) + + # Tune daughterboard + r = self.u.set_center_freq(options.freq+options.calibration, 0) + if not r: + frange = self.u.get_freq_range() + sys.stderr.write(("\nRequested frequency (%f) out or range [%f, %f]\n") % \ + (freq, frange.start(), frange.stop())) + sys.exit(1) + + if options.verbose: + print "Tuned to center frequency", (options.freq+options.calibration)/1e6, "MHz" + + # if no gain was specified, use the mid-point in dB + if options.rx_gain is None: + grange = self.u.get_gain_range() + options.rx_gain = float(grange.start()+grange.stop())/2.0 + print "\nNo gain specified." + print "Setting gain to %f (from [%f, %f])" % \ + (options.rx_gain, grange.start(), grange.stop()) + + self.u.set_gain(options.rx_gain, 0) + + # Grab >=3 MHz of spectrum, evenly divisible by 25 KHz channels + # (A UHD facility to get sample rate range and granularity would be useful) + + self.u.set_samp_rate(3.125e6) # Works if USRP is 100 Msps and can decimate by 32 + rate = self.u.get_samp_rate() + + if rate != 3.125e6: + self.u.set_samp_rate(3.2e6) # Works if USRP is 64 Msps and can decimate by 20 + rate = self.u.get_samp_rate() + if (rate != 3.2e6): + print "Unable to set required sample rate for >= 3MHz of 25 KHz channels." + sys.exit(1) + + self.nchan = int(rate/25e3) if options.verbose: - print "Using", subdev.name(), " for receiving." - print "Tuned USRP to", 930.5125e6+options.calibration - + print "\nReceiving", rate/1e6, "MHz of bandwidth containing", self.nchan, "baseband channels." + taps = gr.firdes.low_pass(1.0, 1.0, - 1.0/128.0*0.4, - 1.0/128.0*0.1, + 1.0/self.nchan*0.4, + 1.0/self.nchan*0.1, gr.firdes.WIN_HANN) if options.verbose: print "Channel filter has", len(taps), "taps" - bank = blks2.analysis_filterbank(128, taps) - self.connect(src, bank) + self.bank = blks2.analysis_filterbank(self.nchan, taps) + self.connect(self.u, self.bank) if options.log and options.from_file == None: src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat') - self.connect(src, src_sink) + self.connect(self.u, src_sink) - for i in range(128): - if i < 64: + mid_chan = int(self.nchan/2) + for i in range(self.nchan): + if i < mid_chan: freq = 930.5e6+i*25e3 else: - freq = 928.9e6+(i-64)*25e3 + freq = 930.5e6-(self.nchan-i)*25e3 if (freq < 929.0e6 or freq > 932.0e6): - self.connect((bank, i), gr.null_sink(gr.sizeof_gr_complex)) + self.connect((self.bank, i), gr.null_sink(gr.sizeof_gr_complex)) else: - self.connect((bank, i), pager.flex_demod(queue, freq, options.verbose, options.log)) + self.connect((self.bank, i), pager.flex_demod(queue, freq, options.verbose, options.log)) if options.log: - self.connect((bank, i), gr.file_sink(gr.sizeof_gr_complex, 'chan_'+'%3.3f'%(freq/1e6)+'.dat')) + self.connect((self.bank, i), gr.file_sink(gr.sizeof_gr_complex, 'chan_'+'%3.3f'%(freq/1e6)+'.dat')) -def main(): + +def get_options(): parser = OptionParser(option_class=eng_option) - parser.add_option("-R", "--rx-subdev-spec", type="subdev", - help="select USRP Rx side A or B (default=first daughterboard found)") - parser.add_option("-c", "--calibration", type="eng_float", default=0.0, + + parser.add_option('-f', '--freq', type="eng_float", default=929.5125e6, + help="Set receive frequency to FREQ [default=%default]", + metavar="FREQ") + parser.add_option("-a", "--address", type="string", default="addr=192.168.10.2", + help="Address of UHD device, [default=%default]") + parser.add_option("-A", "--antenna", type="string", default=None, + help="select Rx Antenna where appropriate") + parser.add_option("", "--rx-gain", type="eng_float", default=None, + help="set receive gain in dB (default is midpoint)") + parser.add_option("-c", "--calibration", type="eng_float", default=0.0, help="set frequency offset to Hz", metavar="Hz") - parser.add_option("-g", "--gain", type="int", - help="set RF gain", metavar="dB") - parser.add_option("-F", "--from-file", default=None, - help="Read from file instead of USRP") + parser.add_option("-v", "--verbose", action="store_true", default=False) parser.add_option("-l", "--log", action="store_true", default=False, help="log flowgraph to files (LOTS of data)") - parser.add_option("-v", "--verbose", action="store_true", default=False, - help="display debug output") + parser.add_option("-F", "--from-file", default=None, + help="read samples from file instead of USRP") + parser.add_option("", "--nchan", type="int", default=None, + help="set to number of channels in capture file", metavar="nchan") + (options, args) = parser.parse_args() - if options.verbose: - print options + if len(args) > 0: + print "Run 'usrp_flex_all.py -h' for options." + sys.exit(1) + + if options.nchan is None and options.from_file is not None: + print "You must specify the number of baseband channels with --nchan when reading from a file" + sys.exit(1) + + return (options, args) + + +def main(): + + (options, args) = get_options() queue = gr.msg_queue() tb = app_top_block(options, queue) |