X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gnuradio-examples%2Fpython%2Fusrp%2Ffm_tx4.py;h=a51668dde8c8b60d2630937a020845eb80900ac5;hb=refs%2Ftags%2Fupstream%2F3.2.2;hp=a9201b3f4d5e8a517827ba277fea30d074c39663;hpb=09a1e803a9e6587c78d20cdf16891e5295874668;p=debian%2Fgnuradio diff --git a/gnuradio-examples/python/usrp/fm_tx4.py b/gnuradio-examples/python/usrp/fm_tx4.py index a9201b3f..a51668dd 100755 --- a/gnuradio-examples/python/usrp/fm_tx4.py +++ b/gnuradio-examples/python/usrp/fm_tx4.py @@ -1,4 +1,24 @@ #!/usr/bin/env python +# +# Copyright 2005,2006,2007 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 3, 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., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# """ Transmit N simultaneous narrow band FM signals. @@ -15,27 +35,30 @@ audio_to_file.py from gnuradio import gr, eng_notation from gnuradio import usrp from gnuradio import audio -from gnuradio import blks +from gnuradio import blks2 from gnuradio.eng_option import eng_option from optparse import OptionParser -import usrp_dbid +from usrpm import usrp_dbid import math import sys -from gnuradio.wxgui import stdgui, fftsink -from gnuradio import tx_debug_gui +from gnuradio.wxgui import stdgui2, fftsink2 +#from gnuradio import tx_debug_gui import wx ######################################################## # instantiate one transmit chain for each call -class pipeline(gr.hier_block): - def __init__(self, fg, filename, lo_freq, audio_rate, if_rate): +class pipeline(gr.hier_block2): + def __init__(self, filename, lo_freq, audio_rate, if_rate): + + gr.hier_block2.__init__(self, "pipeline", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature src = gr.file_source (gr.sizeof_float, filename, True) - fmtx = blks.nbfm_tx (fg, audio_rate, if_rate, - max_dev=5e3, tau=75e-6) + fmtx = blks2.nbfm_tx (audio_rate, if_rate, max_dev=5e3, tau=75e-6) # Local oscillator lo = gr.sig_source_c (if_rate, # sample rate @@ -45,17 +68,14 @@ class pipeline(gr.hier_block): 0) # DC Offset mixer = gr.multiply_cc () - fg.connect (src, fmtx, (mixer, 0)) - fg.connect (lo, (mixer, 1)) - - gr.hier_block.__init__(self, fg, src, mixer) - - + self.connect (src, fmtx, (mixer, 0)) + self.connect (lo, (mixer, 1)) + self.connect (mixer, self) -class fm_tx_graph (stdgui.gui_flow_graph): +class fm_tx_block(stdgui2.std_top_block): def __init__(self, frame, panel, vbox, argv): MAX_CHANNELS = 7 - stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) parser = OptionParser (option_class=eng_option) parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=None, @@ -64,8 +84,8 @@ class fm_tx_graph (stdgui.gui_flow_graph): help="set Tx frequency to FREQ [required]", metavar="FREQ") parser.add_option("-n", "--nchannels", type="int", default=4, help="number of Tx channels [1,4]") - parser.add_option("","--debug", action="store_true", default=False, - help="Launch Tx debugger") + #parser.add_option("","--debug", action="store_true", default=False, + # help="Launch Tx debugger") (options, args) = parser.parse_args () if len(args) != 0: @@ -104,7 +124,13 @@ class fm_tx_graph (stdgui.gui_flow_graph): print "Using TX d'board %s" % (self.subdev.side_and_name(),) self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx gain - self.set_freq(options.freq) + if not self.set_freq(options.freq): + freq_range = self.subdev.freq_range() + print "Failed to set frequency to %s. Daughterboard supports %s to %s" % ( + eng_notation.num_to_str(options.freq), + eng_notation.num_to_str(freq_range[0]), + eng_notation.num_to_str(freq_range[1])) + raise SystemExit self.subdev.set_enable(True) # enable transmitter sum = gr.add_cc () @@ -113,9 +139,9 @@ class fm_tx_graph (stdgui.gui_flow_graph): step = 25e3 offset = (0 * step, 1 * step, -1 * step, 2 * step, -2 * step, 3 * step, -3 * step) for i in range (options.nchannels): - t = pipeline (self, "audio-%d.dat" % (i % 4), offset[i], - self.audio_rate, self.usrp_rate) - self.connect (t, (sum, i)) + t = pipeline("audio-%d.dat" % (i % 4), offset[i], + self.audio_rate, self.usrp_rate) + self.connect(t, (sum, i)) gain = gr.multiply_const_cc (4000.0 / options.nchannels) @@ -125,16 +151,16 @@ class fm_tx_graph (stdgui.gui_flow_graph): # plot an FFT to verify we are sending what we want if 1: - post_mod = fftsink.fft_sink_c(self, panel, title="Post Modulation", - fft_size=512, sample_rate=self.usrp_rate, - y_per_div=20, ref_level=40) + post_mod = fftsink2.fft_sink_c(panel, title="Post Modulation", + fft_size=512, sample_rate=self.usrp_rate, + y_per_div=20, ref_level=40) self.connect (sum, post_mod) vbox.Add (post_mod.win, 1, wx.EXPAND) - if options.debug: - self.debugger = tx_debug_gui.tx_debug_gui(self.subdev) - self.debugger.Show(True) + #if options.debug: + # self.debugger = tx_debug_gui.tx_debug_gui(self.subdev) + # self.debugger.Show(True) def set_freq(self, target_freq): @@ -151,7 +177,7 @@ class fm_tx_graph (stdgui.gui_flow_graph): any residual_freq to the s/w freq translater. """ - r = self.u.tune(self.subdev._which, self.subdev, target_freq) + r = self.u.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) @@ -164,7 +190,7 @@ class fm_tx_graph (stdgui.gui_flow_graph): return False def main (): - app = stdgui.stdapp (fm_tx_graph, "Multichannel FM Tx") + app = stdgui2.stdapp(fm_tx_block, "Multichannel FM Tx", nstatus=1) app.MainLoop () if __name__ == '__main__':