diff options
Diffstat (limited to 'gnuradio-examples/python')
28 files changed, 128 insertions, 322 deletions
diff --git a/gnuradio-examples/python/hier/audio/dial_tone2.py b/gnuradio-examples/python/hier/audio/dial_tone2.py index cbb187a36..3511fdba7 100755 --- a/gnuradio-examples/python/hier/audio/dial_tone2.py +++ b/gnuradio-examples/python/hier/audio/dial_tone2.py @@ -27,32 +27,20 @@ from optparse import OptionParser # Top-level block creating a dial tone # Derives from new class gr.hier_block2 -class dial_tone(gr.hier_block2): +class dial_tone(gr.top_block): def __init__(self, sample_rate, # Audio output sample rate (int) audio_output, # Audio output device amplitude): # Output volume (0.0-1.0) - # Call hierarchical block constructor - # Top-level blocks have no inputs or outputs - gr.hier_block2.__init__(self, - "dial_tone", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "dial_tone") - # Hierarchical blocks have a set of 'components' (which may - # be themselves hierarchical blocks), mapped to names. - # 'define_component' takes a string and either a hierarchical - # block or an instance of a 'leaf node' (gr_block) block + src0 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 350, amplitude) + src1 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 440, amplitude) + dst = audio.sink(sample_rate, audio_output) - # Give names to two sine wave sources and an audio sink - self.define_component("src0", gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude)) - self.define_component("src1", gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude)) - self.define_component("dst", audio.sink(sample_rate, audio_output)) - - # Wire up outputs to inputs. (TODO: convenience functions) - self.connect("src0", 0, "dst", 0) - self.connect("src1", 0, "dst", 1) + self.connect(src0, (dst, 0)) + self.connect(src1, (dst, 1)) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) @@ -68,13 +56,13 @@ if __name__ == '__main__': raise SystemExit, 1 # Create an instance of a hierarchical block - top_block = dial_tone(int(options.sample_rate), - options.audio_output, - options.amplitude) + top = dial_tone(int(options.sample_rate), + options.audio_output, + options.amplitude) # Create an instance of a runtime, passing it the top block # to process - runtime = gr.runtime(top_block) + runtime = gr.runtime(top) try: # Run forever diff --git a/gnuradio-examples/python/hier/dect/README b/gnuradio-examples/python/hier/dect/README index 231b1af67..c8853f185 100644 --- a/gnuradio-examples/python/hier/dect/README +++ b/gnuradio-examples/python/hier/dect/README @@ -5,6 +5,7 @@ digital cordless phone base stations and handsets. Status ------ +2007 Apr 27 - Converted to new hier_block2 format 2007 Apr 03 - Development on hold. 2007 Feb 11 - Added GMSK demodulation and option to log to file 2007 Feb 10 - Able to tune and log filtered baseband to file diff --git a/gnuradio-examples/python/hier/dect/dect_receiver.py b/gnuradio-examples/python/hier/dect/dect_receiver.py index 491159a31..f0ec7ba0c 100644 --- a/gnuradio-examples/python/hier/dect/dect_receiver.py +++ b/gnuradio-examples/python/hier/dect/dect_receiver.py @@ -30,19 +30,15 @@ _dect_channel_bandwidth = 1.728e6 # Top-level hierarchical block that implements DECT demodulation and # decoding. -class dect_receiver(gr.hier_block2): +class dect_receiver(gr.top_block): def __init__(self, options): - gr.hier_block2.__init__(self, - "dect_receiver", # Block typename - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "dect_receiver") self._options = options # Need greater than 2 samples per symbol. This makes a decimation # rate of 26 and a samples per symbol of 2.136752 if_rate = 2.461538e6 - self._usrp = usrp_source_c(self, - which=0, + self._usrp = usrp_source_c(which=0, subdev_spec=options.rx_subdev_spec, if_rate=if_rate, gain=options.gain, @@ -67,25 +63,19 @@ class dect_receiver(gr.hier_block2): self._demod = gmsk2_demod(samples_per_symbol=if_rate/_dect_symbol_rate, verbose=options.verbose) - # Define and connect components - self.define_component("usrp", self._usrp) - self.define_component("channel", self._channel_filter) - self.define_component("demod", self._demod) - self.define_component("sink", gr.null_sink(gr.sizeof_char)) - self.connect("usrp", 0, "channel", 0) - self.connect("channel", 0, "demod", 0) - self.connect("demod", 0, "sink", 0) + self._sink = gr.null_sink(gr.sizeof_char) + self.connect(self._usrp, self._channel_filter, self._demod, self._sink) # Log baseband to file if requested if options.log_baseband is not None: if options.verbose: print "Logging baseband to file", options.log_baseband - self.define_component("baseband_log", gr.file_sink(gr.sizeof_gr_complex, options.log_baseband)) - self.connect("channel", 0, "baseband_log", 0) + self.baseband_log = gr.file_sink(gr.sizeof_gr_complex, options.log_baseband) + self.connect(self._channel_filter, self.baseband_log) # Log demodulator output to file if requested if options.log_demod is not None: if options.verbose: print "Logging demodulator to file", options.log_demod - self.define_component("demod_log", gr.file_sink(gr.sizeof_char, options.log_demod)) - self.connect("demod", 0, "demod_log", 0) + self.demod_log = gr.file_sink(gr.sizeof_char, options.log_demod) + self.connect(self._demod, self.demod_log) diff --git a/gnuradio-examples/python/hier/dect/gmsk2.py b/gnuradio-examples/python/hier/dect/gmsk2.py index 578873eed..f7107241f 100644 --- a/gnuradio-examples/python/hier/dect/gmsk2.py +++ b/gnuradio-examples/python/hier/dect/gmsk2.py @@ -106,14 +106,7 @@ class gmsk2_mod(gr.hier_block2): if verbose: self._print_verbage() - # Define and connect components - self.define_component("nrz", self.nrz) - self.define_component("filter", self.gaussian_filter) - self.define_component("fmmod", self.fmmod) - self.connect("self", 0, "nrz", 0) - self.connect("nrz", 0, "filter", 0) - self.connect("filter", 0, "fmmod", 0) - self.connect("fmmod", 0, "self", 0) + self.connect(self, self.nrz, self.gaussian_filter, self.fmmod, self) if log: self._setup_logging() @@ -125,7 +118,6 @@ class gmsk2_mod(gr.hier_block2): return 1 bits_per_symbol = staticmethod(bits_per_symbol) # make it a static method. - def _print_verbage(self): print "bits per symbol = %d" % self.bits_per_symbol() print "Gaussian filter bt = %.2f" % self._bt @@ -133,12 +125,9 @@ class gmsk2_mod(gr.hier_block2): def _setup_logging(self): print "Modulation logging turned on." - self.define_component("nrz_log", gr.file_sink(gr.sizeof_float, "nrz.dat")) - self.define_component("filter_log", gr.file_sink(gr.sizeof_float, "gaussian_filter.dat")) - self.define_component("fmmod_log", gr.file_sink(gr.sizeof_gr_complex, "fmmod.dat")) - self.connect("nrz", 0, "nrz_log", 0) - self.connect("filter", 0, "filter_log", 0) - self.connect("fmmod", 0, "fmmod_log", 0) + self.connect(self.nrz, gr.file_sink(gr.sizeof_float, "nrz.dat")) + self.connect(self.gaussian_filter, gr.file_sink(gr.sizeof_float, "gaussian_filter.dat")) + self.connect(self.fmmod, gr.file_sink(gr.sizeof_gr_complex, "fmmod.dat")) def add_options(parser): """ @@ -232,14 +221,7 @@ class gmsk2_demod(gr.hier_block2): if verbose: self._print_verbage() - # Define and connect components - self.define_component("fmdemod", self.fmdemod) - self.define_component("clock_recovery", self.clock_recovery) - self.define_component("slicer", self.slicer) - self.connect("self", 0, "fmdemod", 0) - self.connect("fmdemod", 0, "clock_recovery", 0) - self.connect("clock_recovery", 0, "slicer", 0) - self.connect("slicer", 0, "self", 0) + self.connect(self, self.fmdemod, self.clock_recovery, self.slicer, self) if log: self._setup_logging() @@ -251,7 +233,6 @@ class gmsk2_demod(gr.hier_block2): return 1 bits_per_symbol = staticmethod(bits_per_symbol) # make it a static method. - def _print_verbage(self): print "bits per symbol = %d" % self.bits_per_symbol() print "M&M clock recovery omega = %f" % self._omega @@ -263,12 +244,9 @@ class gmsk2_demod(gr.hier_block2): def _setup_logging(self): print "Demodulation logging turned on." - self.define_component("fmdemod_log", gr.file_sink(gr.sizeof_float, "fmdemod.dat")) - self.define_component("clock_recovery_log", gr.file_sink(gr.sizeof_float, "clock_recovery.dat")) - self.define_component("slicer_log", gr.file_sink(gr.sizeof_char, "slicer.dat")) - self.connect("fmdemod", 0, "fmdemod_log", 0) - self.connect("clock_recovery", 0, "clock_recovery_log", 0) - self.connect("slicer", 0, "slicer_log", 0) + self.connect(fmdemod, gr.file_sink(gr.sizeof_float, "fmdemod.dat")) + self.connect(clock_recovery, gr.file_sink(gr.sizeof_float, "clock_recovery.dat")) + self.connect(slicer, gr.file_sink(gr.sizeof_char, "slicer.dat")) def add_options(parser): """ diff --git a/gnuradio-examples/python/hier/dect/usrp_source.py b/gnuradio-examples/python/hier/dect/usrp_source.py index 16949998b..9226f9206 100644 --- a/gnuradio-examples/python/hier/dect/usrp_source.py +++ b/gnuradio-examples/python/hier/dect/usrp_source.py @@ -47,9 +47,7 @@ class usrp_source_c(gr.hier_block2): self.set_gain(gain) self.set_calibration(calibration) self.tune(freq) - - self.define_component("usrp", self._u) - self.connect("usrp", 0, "self", 0) + self.connect(self._u, self) def set_subdev(self, subdev_spec): if subdev_spec is None: diff --git a/gnuradio-examples/python/hier/digital/Makefile.am b/gnuradio-examples/python/hier/digital/Makefile.am index 9cdbc7121..5a098eea7 100644 --- a/gnuradio-examples/python/hier/digital/Makefile.am +++ b/gnuradio-examples/python/hier/digital/Makefile.am @@ -33,3 +33,5 @@ EXTRA_DIST = \ transmit_path_lb.py \ tunnel.py \ tx_voice.py + +MOSTLYCLEANFILES = *~ *.pyc *.dat diff --git a/gnuradio-examples/python/hier/digital/benchmark_loopback.py b/gnuradio-examples/python/hier/digital/benchmark_loopback.py index 92a7bb072..f560468d7 100755 --- a/gnuradio-examples/python/hier/digital/benchmark_loopback.py +++ b/gnuradio-examples/python/hier/digital/benchmark_loopback.py @@ -1,7 +1,7 @@ #!/usr/bin/env python #!/usr/bin/env python # -# Copyright 2005, 2006 Free Software Foundation, Inc. +# Copyright 2005, 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -45,27 +45,23 @@ class awgn_channel(gr.hier_block2): else: rseed = int(time.time()) self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage, rseed) - self.define_component("noise", self.noise) - self.define_component("adder", gr.add_cc()) + self.adder = gr.add_cc() # Create the frequency offset - self.define_component("offset", gr.sig_source_c((sample_rate*1.0), gr.GR_SIN_WAVE, - frequency_offset, 1.0, 0.0)) - self.define_component("mixer", gr.multiply_cc()) + self.offset = gr.sig_source_c((sample_rate*1.0), gr.GR_SIN_WAVE, frequency_offset, 1.0, 0.0) + self.mixer = gr.multiply_cc() # Connect the components - self.connect("self", 0, "mixer", 0) - self.connect("offset", 0, "mixer", 1) - self.connect("mixer", 0, "adder", 0) - self.connect("noise", 0, "adder", 1) - self.connect("adder", 0, "self", 0) + self.connect(self, (self.mixer, 0)) + self.connect(self.offset, (self.mixer, 1)) + self.connect(self.mixer, (self.adder, 0)) + self.connect(self.noise, (self.adder, 1)) + self.connect(self.adder, self) -class my_graph(gr.hier_block2): +class my_graph(gr.top_block): def __init__(self, mod_class, demod_class, rx_callback, options): - gr.hier_block2.__init__(self, "my_graph", - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "my_graph") channelon = True; @@ -82,27 +78,9 @@ class my_graph(gr.hier_block2): if channelon: self.channel = awgn_channel(options.sample_rate, noise_voltage, frequency_offset, options.seed) - - # Define the components - self.define_component("txpath", self.txpath) - self.define_component("throttle", self.throttle) - self.define_component("channel", self.channel) - self.define_component("rxpath", self.rxpath) - - # Connect components - self.connect("txpath", 0, "throttle", 0) - self.connect("throttle", 0, "channel", 0) - self.connect("channel", 0, "rxpath", 0) + self.connect(self.txpath, self.throttle, self.channel, self.rxpath) else: - # Define the components - self.define_component("txpath", self.txpath) - self.define_component("throttle", self.throttle) - self.define_component("rxpath", self.rxpath) - - # Connect components - self.connect("txpath", 0, "throttle", 0) - self.connect("throttle", 0, "rxpath", 0) - + self.connect(self.txpath, self.throttle, self.rxpath) # ///////////////////////////////////////////////////////////////////////////// # main diff --git a/gnuradio-examples/python/hier/digital/benchmark_rx.py b/gnuradio-examples/python/hier/digital/benchmark_rx.py index f65a634a3..3de328a3d 100755 --- a/gnuradio-examples/python/hier/digital/benchmark_rx.py +++ b/gnuradio-examples/python/hier/digital/benchmark_rx.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2005,2006 Free Software Foundation, Inc. +# Copyright 2005,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -38,16 +38,6 @@ import fusb_options #print os.getpid() #raw_input('Attach and press enter: ') - -class my_graph(gr.hier_block2): - def __init__(self, demod_class, rx_callback, options): - gr.hier_block2.__init__(self, "my_graph", - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - self.rxpath = receive_path(demod_class, rx_callback, options) - self.define_component("rxpath", self.rxpath) - - # ///////////////////////////////////////////////////////////////////////////// # main # ///////////////////////////////////////////////////////////////////////////// @@ -104,7 +94,7 @@ def main(): print "Warning: Failed to enable realtime scheduling." # Create an instance of a hierarchical block - top_block = my_graph(demods[options.modulation], rx_callback, options) + top_block = receive_path(demods[options.modulation], rx_callback, options) # Create an instance of a runtime, passing it the top block runtime = gr.runtime(top_block) diff --git a/gnuradio-examples/python/hier/digital/benchmark_tx.py b/gnuradio-examples/python/hier/digital/benchmark_tx.py index 627c92b3a..df4a2005d 100755 --- a/gnuradio-examples/python/hier/digital/benchmark_tx.py +++ b/gnuradio-examples/python/hier/digital/benchmark_tx.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2005, 2006 Free Software Foundation, Inc. +# Copyright 2005, 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -36,15 +36,6 @@ import fusb_options #print os.getpid() #raw_input('Attach and press enter') -class my_graph(gr.hier_block2): - def __init__(self, mod_class, options): - gr.hier_block2.__init__(self, "my_graph", - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - self.txpath = transmit_path(mod_class, options) - self.define_component("txpath", self.txpath) - - # ///////////////////////////////////////////////////////////////////////////// # main # ///////////////////////////////////////////////////////////////////////////// @@ -52,7 +43,7 @@ class my_graph(gr.hier_block2): def main(): def send_pkt(payload='', eof=False): - return top_block.txpath.send_pkt(payload, eof) + return top_block.send_pkt(payload, eof) def rx_callback(ok, payload): print "ok = %r, payload = '%s'" % (ok, payload) @@ -96,7 +87,7 @@ def main(): print "Warning: failed to enable realtime scheduling" # Create an instance of a hierarchical block - top_block = my_graph(mods[options.modulation], options) + top_block = transmit_path(mods[options.modulation], options) # Create an instance of a runtime, passing it the top block runtime = gr.runtime(top_block) diff --git a/gnuradio-examples/python/hier/digital/receive_path.py b/gnuradio-examples/python/hier/digital/receive_path.py index 64a547dce..fce7db162 100644 --- a/gnuradio-examples/python/hier/digital/receive_path.py +++ b/gnuradio-examples/python/hier/digital/receive_path.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2005,2006 Free Software Foundation, Inc. +# Copyright 2005,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -33,12 +33,9 @@ from pick_bitrate import pick_rx_bitrate # receive path # ///////////////////////////////////////////////////////////////////////////// -class receive_path(gr.hier_block2): +class receive_path(gr.top_block): def __init__(self, demod_class, rx_callback, options): - gr.hier_block2.__init__(self, "receive_path", - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - + gr.top_block.__init__(self, "receive_path") options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose @@ -112,18 +109,13 @@ class receive_path(gr.hier_block2): if self._verbose: self._print_verbage() - # Define the components - self.define_component("usrp", self.u) - self.define_component("channel_filter", gr.fft_filter_ccc(sw_decim, chan_coeffs)) - self.define_component("channel_probe", self.probe) - self.define_component("packet_receiver", self.packet_receiver) + self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) # connect the channel input filter to the carrier power detector - self.connect("usrp", 0, "channel_filter", 0) - self.connect("channel_filter", 0, "channel_probe", 0) + self.connect(self.u, self.channel_filter, self.probe) # connect channel filter to the packet receiver - self.connect("channel_filter", 0, "packet_receiver", 0) + self.connect(self.channel_filter, self.packet_receiver) def _setup_usrp_source(self): diff --git a/gnuradio-examples/python/hier/digital/receive_path_lb.py b/gnuradio-examples/python/hier/digital/receive_path_lb.py index fada441ff..69d721df3 100644 --- a/gnuradio-examples/python/hier/digital/receive_path_lb.py +++ b/gnuradio-examples/python/hier/digital/receive_path_lb.py @@ -71,17 +71,13 @@ class receive_path(gr.hier_block2): if self._verbose: self._print_verbage() - # Define the components - self.define_component("channel_filter", gr.fft_filter_ccc(sw_decim, chan_coeffs)) - self.define_component("channel_probe", self.probe) - self.define_component("packet_receiver", self.packet_receiver) + self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) # connect the channel input filter to the carrier power detector - self.connect("self", 0, "channel_filter", 0) - self.connect("channel_filter", 0, "channel_probe", 0) + self.connect(self, self.channel_filter, self.probe) # connect channel filter to the packet receiver - self.connect("channel_filter", 0, "packet_receiver", 0) + self.connect(self.channel_filter, self.packet_receiver) def bitrate(self): return self._bitrate diff --git a/gnuradio-examples/python/hier/digital/transmit_path.py b/gnuradio-examples/python/hier/digital/transmit_path.py index c517210ae..4ed477ea1 100644 --- a/gnuradio-examples/python/hier/digital/transmit_path.py +++ b/gnuradio-examples/python/hier/digital/transmit_path.py @@ -1,5 +1,5 @@ # -# Copyright 2005,2006 Free Software Foundation, Inc. +# Copyright 2005,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -33,16 +33,13 @@ from pick_bitrate import pick_tx_bitrate # transmit path # ///////////////////////////////////////////////////////////////////////////// -class transmit_path(gr.hier_block2): +class transmit_path(gr.top_block): def __init__(self, modulator_class, options): ''' See below for what options should hold ''' - gr.hier_block2.__init__(self, "transmit_path", - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - + gr.top_block.__init__(self, "transmit_path") options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose @@ -99,14 +96,7 @@ class transmit_path(gr.hier_block2): if self._verbose: self._print_verbage() - # Define the components - self.define_component("packet_transmitter", self.packet_transmitter) - self.define_component("amp", self.amp) - self.define_component("usrp", self.u) - - # Connect components in the flowgraph; set amp component to the output of this block - self.connect("packet_transmitter", 0, "amp", 0) - self.connect("amp", 0, "usrp", 0) + self.connect(self.packet_transmitter, self.amp, self.u) def _setup_usrp_sink(self): """ diff --git a/gnuradio-examples/python/hier/digital/transmit_path_lb.py b/gnuradio-examples/python/hier/digital/transmit_path_lb.py index 7bf4b6057..424eafdee 100644 --- a/gnuradio-examples/python/hier/digital/transmit_path_lb.py +++ b/gnuradio-examples/python/hier/digital/transmit_path_lb.py @@ -1,5 +1,5 @@ # -# Copyright 2005,2006 Free Software Foundation, Inc. +# Copyright 2005,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -65,13 +65,8 @@ class transmit_path(gr.hier_block2): if self._verbose: self._print_verbage() - # Define the components - self.define_component("packet_transmitter", self.packet_transmitter) - self.define_component("amp", self.amp) - - # Connect components in the flowgraph; set amp component to the output of this block - self.connect("packet_transmitter", 0, "amp", 0) - self.connect("amp", 0, "self", 0) + # Connect blocks in the flowgraph; set amp component to the output of this block + self.connect(self.packet_transmitter, self.amp, self) def set_tx_amplitude(self, ampl): """ diff --git a/gnuradio-examples/python/hier/networking/audio_sink.py b/gnuradio-examples/python/hier/networking/audio_sink.py index 1b182e97e..4e5f64760 100755 --- a/gnuradio-examples/python/hier/networking/audio_sink.py +++ b/gnuradio-examples/python/hier/networking/audio_sink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -24,18 +24,12 @@ from gnuradio import gr, audio from gnuradio.eng_option import eng_option from optparse import OptionParser -class audio_sink(gr.hier_block2): +class audio_sink(gr.top_block): def __init__(self, src, port, pkt_size, sample_rate): - gr.hier_block2.__init__(self, - "audio_sink", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - - - self.define_component("src", gr.udp_source(gr.sizeof_float, src, port, pkt_size)) - self.define_component("dst", audio.sink(sample_rate)) - - self.connect("src", 0, "dst", 0) + gr.top_block.__init__(self, "audio_sink") + src = gr.udp_source(gr.sizeof_float, src, port, pkt_size) + dst = audio.sink(sample_rate) + self.connect(src, dst) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/networking/audio_source.py b/gnuradio-examples/python/hier/networking/audio_source.py index 24186895a..168e1cba9 100755 --- a/gnuradio-examples/python/hier/networking/audio_source.py +++ b/gnuradio-examples/python/hier/networking/audio_source.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -24,16 +24,12 @@ from gnuradio import gr, audio from gnuradio.eng_option import eng_option from optparse import OptionParser -class audio_source(gr.hier_block2): +class audio_source(gr.top_block): def __init__(self, src, dst, port, pkt_size, sample_rate): - gr.hier_block2.__init__(self, - "audio_source", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - - self.define_component("src", audio.source(sample_rate)) - self.define_component("dst", gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size)) - self.connect("src", 0, "dst", 0) + gr.top_block.__init__(self, "audio_source") + self.audio = audio.source(sample_rate) + self.sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) + self.connect(self.audio, self.sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/networking/dial_tone_sink.py b/gnuradio-examples/python/hier/networking/dial_tone_sink.py index 95419fbc9..de0db14d8 100755 --- a/gnuradio-examples/python/hier/networking/dial_tone_sink.py +++ b/gnuradio-examples/python/hier/networking/dial_tone_sink.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -24,18 +24,12 @@ from gnuradio import gr, audio from gnuradio.eng_option import eng_option from optparse import OptionParser -class dial_tone_sink(gr.hier_block2): +class dial_tone_sink(gr.top_block): def __init__(self, src, port, pkt_size, sample_rate): - gr.hier_block2.__init__(self, - "dial_tone_sink", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - - - self.define_component("src", gr.udp_source(gr.sizeof_float, src, port, pkt_size)) - self.define_component("dst", audio.sink(sample_rate)) - - self.connect("src", 0, "dst", 0) + gr.top_block.__init__(self, "dial_tone_sink") + udp = gr.udp_source(gr.sizeof_float, src, port, pkt_size) + sink = audio.sink(sample_rate) + self.connect(udp, sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/networking/dial_tone_source.py b/gnuradio-examples/python/hier/networking/dial_tone_source.py index 40cb93553..5ef4f25d6 100755 --- a/gnuradio-examples/python/hier/networking/dial_tone_source.py +++ b/gnuradio-examples/python/hier/networking/dial_tone_source.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2006 Free Software Foundation, Inc. +# Copyright 2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -24,30 +24,21 @@ from gnuradio import gr from gnuradio.eng_option import eng_option from optparse import OptionParser -class dial_tone_source(gr.hier_block2): +class dial_tone_source(gr.top_block): def __init__(self, src, dst, port, pkt_size, sample_rate): - gr.hier_block2.__init__(self, - "dial_tone_source", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "dial_tone_source") amplitude = 0.3 - self.define_component("src0", gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, - 350, amplitude)) - self.define_component("src1", gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, - 440, amplitude)) - self.define_component("add", gr.add_ff()) + src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, amplitude) + src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, amplitude) + add = gr.add_ff() # Throttle needed here to account for the other side's audio card sampling rate - self.define_component("thr", gr.throttle(gr.sizeof_float, sample_rate)) - self.define_component("dst", gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size)) - - self.connect("src0", 0, "add", 0) - self.connect("src1", 0, "add", 1) - self.connect("add", 0, "thr", 0) - self.connect("thr", 0, "dst", 0) - - + thr = gr.throttle(gr.sizeof_float, sample_rate) + sink = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) + self.connect(src0, (add, 0)) + self.connect(src1, (add, 1)) + self.connect(add, thr, sink) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/networking/vector_sink.py b/gnuradio-examples/python/hier/networking/vector_sink.py index 54578078f..35ea36e63 100755 --- a/gnuradio-examples/python/hier/networking/vector_sink.py +++ b/gnuradio-examples/python/hier/networking/vector_sink.py @@ -24,19 +24,13 @@ from gnuradio import gr from gnuradio.eng_option import eng_option from optparse import OptionParser -class vector_sink(gr.hier_block2): +class vector_sink(gr.top_block): def __init__(self, src, port, pkt_size): - gr.hier_block2.__init__(self, - "vector_sink", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "vector_sink") udp = gr.udp_source(gr.sizeof_float, src, port, pkt_size) - - self.define_component("src", udp) - self.define_component("dst", gr.file_sink(gr.sizeof_float, "received.dat")) - - self.connect("src", 0, "dst", 0) + sink = gr.file_sink(gr.sizeof_float, "received.dat") + self.connect(udp, sink) if __name__ == "__main__": parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/networking/vector_source.py b/gnuradio-examples/python/hier/networking/vector_source.py index d31a0baa2..ad3c31be7 100755 --- a/gnuradio-examples/python/hier/networking/vector_source.py +++ b/gnuradio-examples/python/hier/networking/vector_source.py @@ -24,20 +24,13 @@ from gnuradio import gr from gnuradio.eng_option import eng_option from optparse import OptionParser -class vector_source(gr.hier_block2): +class vector_source(gr.top_block): def __init__(self, src, dst, port, pkt_size): - gr.hier_block2.__init__(self, - "vector_source", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - + gr.top_block.__init__(self, "vector_source") data = [i*0.01 for i in range(1000)] - self.define_component("data", gr.vector_source_f(data, True)) - + vec = gr.vector_source_f(data, True) udp = gr.udp_sink(gr.sizeof_float, src, 0, dst, port, pkt_size) - self.define_component("dst", udp) - - self.connect("data", 0, "dst", 0) + self.connect(vec, udp) if __name__ == '__main__': parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/sounder/Makefile.am b/gnuradio-examples/python/hier/sounder/Makefile.am index ecbbb4718..1d26e0cb7 100644 --- a/gnuradio-examples/python/hier/sounder/Makefile.am +++ b/gnuradio-examples/python/hier/sounder/Makefile.am @@ -27,4 +27,4 @@ EXTRA_DIST = \ sounder_rx.py \ sounder_tx.py -MOSTLYCLEANFILES = *.pyc *~ +MOSTLYCLEANFILES = *.pyc *~ *.dat diff --git a/gnuradio-examples/python/hier/sounder/sounder_rx.py b/gnuradio-examples/python/hier/sounder/sounder_rx.py index 336e604a3..e1b64001b 100644 --- a/gnuradio-examples/python/hier/sounder/sounder_rx.py +++ b/gnuradio-examples/python/hier/sounder/sounder_rx.py @@ -50,6 +50,4 @@ class sounder_rx(gr.hier_block2): print "Using PN sequence of degree", self._degree, "length", self._length print "Sequence repetition rate is", n2s(self._rep_rate), "per sec" - self.define_component("corr", gr.pn_correlator_cc(self._degree)) - self.connect("self", 0, "corr", 0) - self.connect("corr", 0, "self", 0) + self.connect(self, gr.pn_correlator_cc(self._degree), self) diff --git a/gnuradio-examples/python/hier/sounder/sounder_tx.py b/gnuradio-examples/python/hier/sounder/sounder_tx.py index 7d91f36e1..c6810b01a 100644 --- a/gnuradio-examples/python/hier/sounder/sounder_tx.py +++ b/gnuradio-examples/python/hier/sounder/sounder_tx.py @@ -42,5 +42,4 @@ class sounder_tx(gr.hier_block2): self._length = 2**degree-1 # Connect PN source to block output - self.define_component("glfsr", gr.glfsr_source_f(degree)) - self.connect("glfsr", 0, "self", 0) + self.connect(gr.glfsr_source_f(degree), self) diff --git a/gnuradio-examples/python/hier/sounder/usrp_sink.py b/gnuradio-examples/python/hier/sounder/usrp_sink.py index 000b831f5..03a987d41 100644 --- a/gnuradio-examples/python/hier/sounder/usrp_sink.py +++ b/gnuradio-examples/python/hier/sounder/usrp_sink.py @@ -46,10 +46,7 @@ class usrp_sink_c(gr.hier_block2): self.set_if_rate(if_rate) self.set_calibration(calibration) self.tune(freq) - - self.define_component("usrp", self._u) - self.connect("self", 0, "usrp", 0) - + self.connect(self, self._u) def set_subdev(self, subdev_spec): if subdev_spec is None: diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py index 72ebeccfa..094ae4bcd 100755 --- a/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py +++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_rx.py @@ -28,12 +28,9 @@ from sounder_rx import sounder_rx n2s = eng_notation.num_to_str -class usrp_sounder_rx(gr.hier_block2): +class usrp_sounder_rx(gr.top_block): def __init__(self, options): - gr.hier_block2.__init__(self, "usrp_sounder_rx", - gr.io_signature(0,0,0), - gr.io_signature(0,0,0)) - + gr.top_block.__init__(self, "usrp_sounder_rx") self._options = options self._u = usrp_source_c(0, self._options.rx_subdev_spec, @@ -50,22 +47,14 @@ class usrp_sounder_rx(gr.hier_block2): samples = 100 * self._length**2 - self.define_component("usrp", self._u) - self.define_component("head", gr.head(gr.sizeof_gr_complex, samples)) - self.define_component("rx", self._receiver) - self.define_component("c2m", gr.complex_to_mag()) - self.define_component("s2v", gr.stream_to_vector(gr.sizeof_float, self._length)) - self.define_component("lpf", gr.single_pole_iir_filter_ff(self._options.alpha, self._length)) - self.define_component("v2s", gr.vector_to_stream(gr.sizeof_float, self._length)) - self.define_component("sink", gr.file_sink(gr.sizeof_float, "impulse.dat")) + head = gr.head(gr.sizeof_gr_complex, samples) + c2m = gr.complex_to_mag() + s2v = gr.stream_to_vector(gr.sizeof_float, self._length) + lpf = gr.single_pole_iir_filter_ff(self._options.alpha, self._length) + v2s = gr.vector_to_stream(gr.sizeof_float, self._length) + sink = gr.file_sink(gr.sizeof_float, "impulse.dat") - self.connect("usrp", 0, "head", 0) - self.connect("head", 0, "rx", 0) - self.connect("rx", 0, "c2m", 0) - self.connect("c2m", 0, "s2v", 0) - self.connect("s2v", 0, "lpf", 0) - self.connect("lpf", 0, "v2s", 0) - self.connect("v2s", 0, "sink", 0) + self.connect(self._u, head, self._receiver, c2m, s2v, lpf, v2s, sink) if self._options.verbose: print "Chip rate is", n2s(self._options.chip_rate), "chips/sec" diff --git a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py index 00146146c..e1ee5b844 100755 --- a/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py +++ b/gnuradio-examples/python/hier/sounder/usrp_sounder_tx.py @@ -28,16 +28,12 @@ from sounder_tx import sounder_tx n2s = eng_notation.num_to_str -class usrp_sounder_tx(gr.hier_block2): +class usrp_sounder_tx(gr.top_block): def __init__(self, subdev_spec, freq, cal, verbose, degree, chip_rate, amplitude): # Call hierarchical block constructor # Top-level blocks have no inputs or outputs - gr.hier_block2.__init__(self, - "usrp_sounder_tx", # Block typename - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature - + gr.top_block.__init__(self, "usrp_sounder_tx") self._freq = freq self._cal = cal self._verbose = verbose @@ -46,12 +42,12 @@ class usrp_sounder_tx(gr.hier_block2): self._amplitude = amplitude self._u = usrp_sink_c(0, subdev_spec, chip_rate, self._freq, self._cal, self._verbose) - self.define_component("usrp", self._u) self._chip_rate = self._u._if_rate self._max_time = float(self._length)/self._chip_rate - self.define_component("pn", sounder_tx(self._degree, self._chip_rate, self._verbose)) - self.define_component("gain", gr.multiply_const_ff(amplitude)); - self.define_component("f2c", gr.float_to_complex()) + self._pn = sounder_tx(self._degree, self._chip_rate, self._verbose) + self._gain = gr.multiply_const_ff(amplitude) + self._f2c = gr.float_to_complex() + self.connect(self._pn, self._gain, self._f2c, self._u) if self._verbose: print "Chip rate is", n2s(self._chip_rate), "chips/sec" @@ -60,11 +56,6 @@ class usrp_sounder_tx(gr.hier_block2): print "Maximum measurable impulse response is", n2s(self._max_time), "sec" print "Output amplitude is", amplitude - # Ultimately this will be - # self.connect("pn gain f2c usrp") - self.connect("pn", 0, "gain", 0) - self.connect("gain", 0, "f2c", 0) - self.connect("f2c", 0, "usrp", 0) def main(): parser = OptionParser(option_class=eng_option) diff --git a/gnuradio-examples/python/hier/sounder/usrp_source.py b/gnuradio-examples/python/hier/sounder/usrp_source.py index 0ba9e6161..9dc471d9e 100644 --- a/gnuradio-examples/python/hier/sounder/usrp_source.py +++ b/gnuradio-examples/python/hier/sounder/usrp_source.py @@ -47,9 +47,7 @@ class usrp_source_c(gr.hier_block2): self.set_gain(gain) self.set_calibration(calibration) self.tune(freq) - - self.define_component("usrp", self._u) - self.connect("usrp", 0, "self", 0) + self.connect(self._u, self) def set_subdev(self, subdev_spec): if subdev_spec is None: diff --git a/gnuradio-examples/python/hier/usrp/usrp_fft.py b/gnuradio-examples/python/hier/usrp/usrp_fft.py index 5cd5c1482..b31213004 100755 --- a/gnuradio-examples/python/hier/usrp/usrp_fft.py +++ b/gnuradio-examples/python/hier/usrp/usrp_fft.py @@ -74,7 +74,6 @@ class app_top_block(stdgui2.std_top_block): self.show_debug_info = True self.u = usrp.source_c(decim_rate=options.decim) - self.define_component("usrp", self.u) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) @@ -99,11 +98,8 @@ class app_top_block(stdgui2.std_top_block): self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate) else: self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate) - self.define_component("scope", self.scope) - # Ultimately this will be - # self.connect("usrp scope") - self.connect("usrp", 0, "scope", 0) + self.connect(self.u, self.scope) self._build_gui(vbox) diff --git a/gnuradio-examples/python/hier/usrp/usrp_siggen.py b/gnuradio-examples/python/hier/usrp/usrp_siggen.py index 28f80a822..f1eb2a6bc 100755 --- a/gnuradio-examples/python/hier/usrp/usrp_siggen.py +++ b/gnuradio-examples/python/hier/usrp/usrp_siggen.py @@ -7,15 +7,9 @@ from gnuradio import eng_notation from optparse import OptionParser import sys - -class my_graph(gr.hier_block2): +class my_graph(gr.top_block): def __init__ (self, type, ampl, wfreq, offset, subdev_spec, interp, rf_freq): - # Call hierarchical block constructor - # Top-level blocks have no inputs or outputs - gr.hier_block2.__init__(self, - "usrp_siggen", # Block type - gr.io_signature(0,0,0), # Input signature - gr.io_signature(0,0,0)) # Output signature + gr.top_block.__init__(self, "usrp_siggen") # controllable values self.interp = interp @@ -40,28 +34,21 @@ class my_graph(gr.hier_block2): sys.stderr.write('Failed to set RF frequency\n') raise SystemExit - self.define_component("usrp", self.u) - if type == gr.GR_SIN_WAVE or type == gr.GR_CONST_WAVE: self.src = gr.sig_source_c (self.usb_freq (), gr.GR_SIN_WAVE, self.waveform_freq, self.waveform_ampl, self.waveform_offset) - self.define_component("src", self.src) elif type == gr.GR_UNIFORM or type == gr.GR_GAUSSIAN: self.src = gr.noise_source_c (gr.GR_UNIFORM, self.waveform_ampl) - self.define_component("src", self.src) - + else: raise ValueError, type - # self.file_sink = gr.file_sink (gr.sizeof_gr_complex, "siggen.dat") - # self.define_component("file_sink", self.file_sink) - - self.connect ("src", 0, "usrp", 0) + self.connect (self.src, self.u) def usb_freq (self): |