diff options
author | Josh Blum | 2011-10-19 16:37:33 -0700 |
---|---|---|
committer | Josh Blum | 2011-10-19 16:37:33 -0700 |
commit | be300d920fe1b7a3eb738565cddd10624ec62a75 (patch) | |
tree | 45bb49c4a4acd7c93bb218c84b94de4c90f198c5 /gr-pager/apps | |
parent | a57f7484a1b1ba18b66334675ce6458b00d40626 (diff) | |
parent | e30b824e9165bff69f09121631c3d5a706cbbd39 (diff) | |
download | gnuradio-be300d920fe1b7a3eb738565cddd10624ec62a75.tar.gz gnuradio-be300d920fe1b7a3eb738565cddd10624ec62a75.tar.bz2 gnuradio-be300d920fe1b7a3eb738565cddd10624ec62a75.zip |
Merge branch 'next' of http://gnuradio.org/git/gnuradio into next
Diffstat (limited to 'gr-pager/apps')
-rwxr-xr-x | gr-pager/apps/usrp_flex.py | 125 | ||||
-rwxr-xr-x | gr-pager/apps/usrp_flex_band.py | 106 |
2 files changed, 128 insertions, 103 deletions
diff --git a/gr-pager/apps/usrp_flex.py b/gr-pager/apps/usrp_flex.py index f8d9d25b1..7c90d9296 100755 --- a/gr-pager/apps/usrp_flex.py +++ b/gr-pager/apps/usrp_flex.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007,2009 Free Software Foundation, Inc. +# Copyright 2006,2007,2009,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -20,32 +20,11 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, usrp, optfir, eng_notation, pager +from gnuradio import gr, gru, uhd, optfir, eng_notation, pager from gnuradio.eng_option import eng_option from optparse import OptionParser import time, os, sys -""" -This example application demonstrates receiving and demodulating the -FLEX pager protocol. - -The following are required command line parameters: - --f FREQ USRP receive frequency - -The following are optional command line parameters: - --R SUBDEV Daughter board specification, defaults to first found --F FILE Read samples from a file instead of USRP. --c FREQ Calibration offset. Gets added to receive frequency. - Defaults to 0.0 Hz. --g GAIN Daughterboard gain setting. Defaults to mid-range. --l Log flow graph to files (LOTS of data) --v Verbose output - -Once the program is running, ctrl-break (Ctrl-C) stops operation. -""" - class app_top_block(gr.top_block): def __init__(self, options, queue): gr.top_block.__init__(self, "usrp_flex") @@ -55,43 +34,46 @@ class app_top_block(gr.top_block): self.verbose = options.verbose if options.from_file is None: - # Set up USRP source with specified RX daughterboard - self.src = usrp.source_c() - if options.rx_subdev_spec == None: - options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src) - self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) - self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) - - # Grab 250 KHz of spectrum (sample rate becomes 250 ksps complex) - self.src.set_decim_rate(256) - - # If no gain specified, set to midrange - if options.gain is None: - g = self.subdev.gain_range() - options.gain = (g[0]+g[1])/2.0 - self.subdev.set_gain(options.gain) - + # Set up USRP source + self.u = uhd.usrp_source(device_addr=options.address, + io_type=uhd.io_type.COMPLEX_FLOAT32, + num_channels=1) + + # Grab 250 KHz of spectrum + # (A UHD facility to get sample rate range and granularity would be useful) + self.u.set_samp_rate(250e3) + rate = self.u.get_samp_rate() + if rate != 250e3: + print "Unable to set required sample rate of 250 Ksps (got %f)" % rate + sys.exit(1) + # Tune daughterboard - actual_frequency = options.frequency+options.calibration - tune_result = usrp.tune(self.src, 0, self.subdev, actual_frequency) - if not tune_result: - sys.stderr.write("Failed to set center frequency to "+`actual_frequency`+"\n") + 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 "Using RX daughterboard", self.subdev.side_and_name() - print "USRP gain is", options.gain - print "USRP tuned to", actual_frequency - + # 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) + else: # Use supplied file as source of samples - self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file) + self.u = gr.file_source(gr.sizeof_gr_complex, options.from_file) if options.verbose: print "Reading samples from", options.from_file if options.log and not options.from_file: usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat') - self.connect(self.src, usrp_sink) + self.connect(self.u, usrp_sink) # Set up 22KHz-wide bandpass about center frequency. Decimate by 10 # to get channel rate of 25Ksps @@ -115,9 +97,9 @@ class app_top_block(gr.top_block): self.connect(self.chan, chan_sink) # FLEX protocol demodulator - self.flex = pager.flex_demod(queue, options.frequency, options.verbose, options.log) + self.flex = pager.flex_demod(queue, options.freq, options.verbose, options.log) - self.connect(self.src, self.chan, self.flex) + self.connect(self.u, self.chan, self.flex) def freq_offset(self): return self.flex.dc_offset()*1600 @@ -130,30 +112,42 @@ class app_top_block(gr.top_block): if self.verbose: print "Channel frequency offset (Hz):", int(self.offset) -def main(): + +def get_options(): parser = OptionParser(option_class=eng_option) - parser.add_option("-f", "--frequency", type="eng_float", default=None, - help="set receive frequency to Hz", metavar="Hz") - parser.add_option("-R", "--rx-subdev-spec", type="subdev", - help="select USRP Rx side A or B", metavar="SUBDEV") + + parser.add_option('-f', '--freq', type="eng_float", default=None, + 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", default=None, - help="set RF gain", metavar="dB") + 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") + (options, args) = parser.parse_args() - if len(args) > 0 or (options.frequency == None and options.from_file == None): + if len(args) > 0: print "Run 'usrp_flex.py -h' for options." sys.exit(1) - if options.frequency == None: - options.frequency = 0.0 + if (options.freq is None): + sys.stderr.write("You must specify -f FREQ or --freq FREQ\n") + sys.exit(1) + + return (options, args) + +if __name__ == "__main__": + + (options, args) = get_options() # Flow graph emits pages into message queue queue = gr.msg_queue() @@ -167,6 +161,3 @@ def main(): runner.end() - -if __name__ == "__main__": - main() diff --git a/gr-pager/apps/usrp_flex_band.py b/gr-pager/apps/usrp_flex_band.py index 06c2488c0..8ea76c229 100755 --- a/gr-pager/apps/usrp_flex_band.py +++ b/gr-pager/apps/usrp_flex_band.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006,2007,2009 Free Software Foundation, Inc. +# Copyright 2006,2007,2009,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -20,32 +20,52 @@ # 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 +import sys class app_top_block(gr.top_block): def __init__(self, options, queue): gr.top_block.__init__(self, "usrp_flex_all") - self.subdev = None if options.from_file is not None: - self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file) + self.u = gr.file_source(gr.sizeof_gr_complex, options.from_file) if options.verbose: print "Reading samples from file", options.from_file else: - self.src = usrp.source_c() - if options.rx_subdev_spec is None: - options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src) - self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) - self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) - self.src.set_decim_rate(64) - frequency = options.frequency+options.calibration - result = usrp.tune(self.src, 0, self.subdev, frequency) - if options.verbose: - print "Using", self.subdev.name(), " for receiving." - print "Tuned USRP to", frequency + # Set up USRP source + self.u = uhd.usrp_source(device_addr=options.address, + io_type=uhd.io_type.COMPLEX_FLOAT32, + num_channels=1) + + # Grab 1 MHz of spectrum + # (A UHD facility to get sample rate range and granularity would be useful) + self.u.set_samp_rate(1e6) + rate = self.u.get_samp_rate() + if rate != 1e6: + print "Unable to set required sample rate of 1 Msps (got %f)" % rate + sys.exit(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 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) + + taps = gr.firdes.low_pass(1.0, 1.0, 1.0/40.0*0.4, @@ -56,43 +76,59 @@ class app_top_block(gr.top_block): print "Channel filter has", len(taps), "taps" bank = blks2.analysis_filterbank(40, taps) - self.connect(self.src, bank) + self.connect(self.u, bank) if options.log and options.from_file == None: src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat') - self.connect(self.src, src_sink) + self.connect(self.u, src_sink) for i in range(40): if i < 20: - freq = options.frequency+i*25e3 + freq = options.freq+i*25e3 else: - freq = options.frequency-0.5e6+(i-20)*25e3 + freq = options.freq-0.5e6+(i-20)*25e3 self.connect((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')) -def main(): +def get_options(): parser = OptionParser(option_class=eng_option) - parser.add_option("-f", "--frequency", type="eng_float", default=929.5e6, - help="set receive center frequency to Hz", metavar="Hz") - 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=None, + 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") + (options, args) = parser.parse_args() - if options.verbose: - print options + if len(args) > 0: + print "Run 'usrp_flex_band.py -h' for options." + sys.exit(1) + + if (options.freq is None): + sys.stderr.write("You must specify -f FREQ or --freq FREQ\n") + sys.exit(1) + + return (options, args) + + +if __name__ == "__main__": + + (options, args) = get_options() queue = gr.msg_queue() tb = app_top_block(options, queue) @@ -105,6 +141,4 @@ def main(): runner.end() - -if __name__ == "__main__": - main() + |