diff options
author | jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5> | 2007-09-18 18:59:00 +0000 |
---|---|---|
committer | jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5> | 2007-09-18 18:59:00 +0000 |
commit | e692e71305ecd71d3681fe37f3d76f350d67e276 (patch) | |
tree | dc320c9261303aa9a92f4d12bdba85f82720d1bf /gnuradio-examples/python/digital | |
parent | 6ad04a094ced626e46c210b9847eae46a1ae8e67 (diff) |
Merge r6461:6464 from jcorgan/t162-staging into trunk.
* Final gr.top_block and gr.hier_block2 implementation inside
gnuradio-core/src/lib/runtime
* Implementation of gr.hier_block2 versions of all the old-style blocks
in blks. These live in blks2.
* Addition of gr.hier_block2 based versions of gr-wxgui blocks
* Conversion of all the example code in gnuradio-examples to use this
new code
* Conversion of all the gr-utils scripts to use the new code
The OFDM examples and related hierarchical blocks have not yet been
converted. Code in the rest of the tree that is outside the core
and example components has also not yet been converted.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6466 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-examples/python/digital')
-rw-r--r-- | gnuradio-examples/python/digital/Makefile.am | 5 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_loopback.py | 40 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_rx.py | 19 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/benchmark_tx.py | 24 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/receive_path.py | 32 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/receive_path_lb.py | 30 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/rx_voice.py | 29 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/transmit_path.py | 25 | ||||
-rw-r--r-- | gnuradio-examples/python/digital/transmit_path_lb.py | 27 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/tunnel.py | 52 | ||||
-rwxr-xr-x | gnuradio-examples/python/digital/tx_voice.py | 37 |
11 files changed, 173 insertions, 147 deletions
diff --git a/gnuradio-examples/python/digital/Makefile.am b/gnuradio-examples/python/digital/Makefile.am index 1db2f8470c..ed941e4f78 100644 --- a/gnuradio-examples/python/digital/Makefile.am +++ b/gnuradio-examples/python/digital/Makefile.am @@ -23,17 +23,22 @@ include $(top_srcdir)/Makefile.common EXTRA_DIST = \ README \ + benchmark_loopback.py \ benchmark_rx.py \ benchmark_tx.py \ fusb_options.py \ gen_whitener.py \ pick_bitrate.py \ receive_path.py \ + receive_path_lb.py \ rx_voice.py \ run_length.py \ transmit_path.py \ + transmit_path_lb.py \ tunnel.py \ tx_voice.py ourdatadir = $(exampledir)/digital ourdata_DATA = $(EXTRA_DIST) + +MOSTLYCLEANFILES = *.pyc *.pyo *~ diff --git a/gnuradio-examples/python/digital/benchmark_loopback.py b/gnuradio-examples/python/digital/benchmark_loopback.py index 34d25812e1..7dd36b9868 100755 --- a/gnuradio-examples/python/digital/benchmark_loopback.py +++ b/gnuradio-examples/python/digital/benchmark_loopback.py @@ -32,10 +32,13 @@ from transmit_path_lb import transmit_path from receive_path_lb import receive_path import fusb_options -class awgn_channel(gr.hier_block): - def __init__(self, fg, sample_rate, noise_voltage, frequency_offset, seed=False): - self.input = gr.add_const_cc(0) # dummy input device - +class awgn_channel(gr.hier_block2): + def __init__(self, sample_rate, noise_voltage, frequency_offset, seed=False): + + gr.hier_block2.__init__(self, "awgn_channel", + gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature + gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature + # Create the Gaussian noise source if not seed: self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_voltage) @@ -51,16 +54,15 @@ class awgn_channel(gr.hier_block): self.mixer = gr.multiply_cc() # Connect the components - fg.connect(self.input, (self.mixer, 0)) - fg.connect(self.offset, (self.mixer, 1)) - fg.connect(self.mixer, (self.adder, 0)) - fg.connect(self.noise, (self.adder, 1)) - - gr.hier_block.__init__(self, fg, self.input, self.adder) + 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.flow_graph): +class my_top_block(gr.top_block): def __init__(self, mod_class, demod_class, rx_callback, options): - gr.flow_graph.__init__(self) + gr.top_block.__init__(self) channelon = True; @@ -71,12 +73,12 @@ class my_graph(gr.flow_graph): noise_power = power_in_signal/SNR noise_voltage = math.sqrt(noise_power) - self.txpath = transmit_path(self, mod_class, options) + self.txpath = transmit_path(mod_class, options) self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate) - self.rxpath = receive_path(self, demod_class, rx_callback, options) + self.rxpath = receive_path(demod_class, rx_callback, options) if channelon: - self.channel = awgn_channel(self, options.sample_rate, noise_voltage, + self.channel = awgn_channel(options.sample_rate, noise_voltage, frequency_offset, options.seed) if options.discontinuous: @@ -121,7 +123,7 @@ def main(): # print payload[2:len(payload)] def send_pkt(payload='', eof=False): - return fg.txpath.send_pkt(payload, eof) + return tb.txpath.send_pkt(payload, eof) mods = modulation_utils.type_1_mods() @@ -171,8 +173,8 @@ def main(): print "Warning: failed to enable realtime scheduling" # Create an instance of a hierarchical block - fg = my_graph(mods[options.modulation], demods[options.modulation], rx_callback, options) - fg.start() + tb = my_top_block(mods[options.modulation], demods[options.modulation], rx_callback, options) + tb.start() # generate and send packets nbytes = int(1e6 * options.megabytes) @@ -187,7 +189,7 @@ def main(): send_pkt(eof=True) - fg.wait() + tb.wait() if __name__ == '__main__': try: diff --git a/gnuradio-examples/python/digital/benchmark_rx.py b/gnuradio-examples/python/digital/benchmark_rx.py index e375bc0f5b..be18395773 100755 --- a/gnuradio-examples/python/digital/benchmark_rx.py +++ b/gnuradio-examples/python/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,12 +38,11 @@ import fusb_options #print os.getpid() #raw_input('Attach and press enter: ') - -class my_graph(gr.flow_graph): - - def __init__(self, demod_class, rx_callback, options): - gr.flow_graph.__init__(self) - self.rxpath = receive_path(self, demod_class, rx_callback, options) +class my_top_block(gr.top_block): + def __init__(self, demodulator, rx_callback, options): + gr.top_block.__init__(self) + self.rxpath = receive_path(demodulator, rx_callback, options) + self.connect(self.rxpath) # ///////////////////////////////////////////////////////////////////////////// # main @@ -98,14 +97,14 @@ def main(): # build the graph - fg = my_graph(demods[options.modulation], rx_callback, options) + tb = my_top_block(demods[options.modulation], rx_callback, options) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: Failed to enable realtime scheduling." - fg.start() # start flow graph - fg.wait() # wait for it to finish + tb.start() # start flow graph + tb.wait() # wait for it to finish if __name__ == '__main__': try: diff --git a/gnuradio-examples/python/digital/benchmark_tx.py b/gnuradio-examples/python/digital/benchmark_tx.py index d2cba4fd93..a0a10d7830 100755 --- a/gnuradio-examples/python/digital/benchmark_tx.py +++ b/gnuradio-examples/python/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,12 +36,11 @@ import fusb_options #print os.getpid() #raw_input('Attach and press enter') - -class my_graph(gr.flow_graph): - def __init__(self, modulator_class, options): - gr.flow_graph.__init__(self) - self.txpath = transmit_path(self, modulator_class, options) - +class my_top_block(gr.top_block): + def __init__(self, modulator, options): + gr.top_block.__init__(self) + self.txpath = transmit_path(modulator, options) + self.connect(self.txpath) # ///////////////////////////////////////////////////////////////////////////// # main @@ -50,7 +49,7 @@ class my_graph(gr.flow_graph): def main(): def send_pkt(payload='', eof=False): - return fg.txpath.send_pkt(payload, eof) + return tb.txpath.send_pkt(payload, eof) def rx_callback(ok, payload): print "ok = %r, payload = '%s'" % (ok, payload) @@ -95,14 +94,14 @@ def main(): source_file = open(options.from_file, 'r') # build the graph - fg = my_graph(mods[options.modulation], options) + tb = my_top_block(mods[options.modulation], options) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" - fg.start() # start flow graph - + tb.start() # start flow graph + # generate and send packets nbytes = int(1e6 * options.megabytes) n = 0 @@ -126,7 +125,8 @@ def main(): pktno += 1 send_pkt(eof=True) - fg.wait() # wait for it to finish + + tb.wait() # wait for it to finish if __name__ == '__main__': try: diff --git a/gnuradio-examples/python/digital/receive_path.py b/gnuradio-examples/python/digital/receive_path.py index 5cf4e59eed..29f1f834dd 100644 --- a/gnuradio-examples/python/digital/receive_path.py +++ b/gnuradio-examples/python/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 # @@ -20,7 +20,7 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, blks +from gnuradio import gr, gru, blks2 from gnuradio import usrp from gnuradio import eng_notation import copy @@ -33,8 +33,12 @@ from pick_bitrate import pick_rx_bitrate # receive path # ///////////////////////////////////////////////////////////////////////////// -class receive_path(gr.hier_block): - def __init__(self, fg, demod_class, rx_callback, options): +class receive_path(gr.hier_block2): + 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 options = copy.copy(options) # make a copy so we can destructively modify @@ -96,11 +100,10 @@ class receive_path(gr.hier_block): # receiver self.packet_receiver = \ - blks.demod_pkts(fg, - self._demod_class(fg, **demod_kwargs), - access_code=None, - callback=self._rx_callback, - threshold=-1) + blks2.demod_pkts(self._demod_class(**demod_kwargs), + access_code=None, + callback=self._rx_callback, + threshold=-1) # Carrier Sensing Blocks alpha = 0.001 @@ -109,17 +112,16 @@ class receive_path(gr.hier_block): if options.log_rx_power == True: self.probe = gr.probe_avg_mag_sqrd_cf(thresh,alpha) self.power_sink = gr.file_sink(gr.sizeof_float, "rxpower.dat") - fg.connect(self.chan_filt, self.probe, self.power_sink) + self.connect(self.chan_filt, self.probe, self.power_sink) else: self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) - fg.connect(self.chan_filt, self.probe) + self.connect(self.chan_filt, self.probe) # Display some information about the setup if self._verbose: self._print_verbage() - fg.connect(self.u, self.chan_filt, self.packet_receiver) - gr.hier_block.__init__(self, fg, None, None) + self.connect(self.u, self.chan_filt, self.packet_receiver) def _setup_usrp_source(self): self.u = usrp.source_c (fusb_block_size=self._fusb_block_size, @@ -246,6 +248,10 @@ class receive_path(gr.hier_block): print "decim: %3d" % (self._decim) print "Rx Frequency: %s" % (eng_notation.num_to_str(self._rx_freq)) # print "Rx Frequency: %f" % (self._rx_freq) + + def __del__(self): + # Avoid weak reference error + del self.subdev def add_freq_option(parser): """ diff --git a/gnuradio-examples/python/digital/receive_path_lb.py b/gnuradio-examples/python/digital/receive_path_lb.py index 17643c6c01..a6bffeeac4 100644 --- a/gnuradio-examples/python/digital/receive_path_lb.py +++ b/gnuradio-examples/python/digital/receive_path_lb.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 # @@ -20,7 +20,7 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, blks +from gnuradio import gr, gru, blks2 from gnuradio import eng_notation import copy import sys @@ -29,8 +29,12 @@ import sys # receive path # ///////////////////////////////////////////////////////////////////////////// -class receive_path(gr.hier_block): - def __init__(self, fg, demod_class, rx_callback, options): +class receive_path(gr.hier_block2): + def __init__(self, demod_class, rx_callback, options): + gr.hier_block2.__init__(self, "receive_path", + gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature + gr.io_signature(0, 0, 0)) # Output signature + options = copy.copy(options) # make a copy so we can destructively modify @@ -55,11 +59,10 @@ class receive_path(gr.hier_block): # receiver self.packet_receiver = \ - blks.demod_pkts(fg, - self._demod_class(fg, **demod_kwargs), - access_code=None, - callback=self._rx_callback, - threshold=-1) + blks2.demod_pkts(self._demod_class(**demod_kwargs), + access_code=None, + callback=self._rx_callback, + threshold=-1) # Carrier Sensing Blocks alpha = 0.001 @@ -70,13 +73,14 @@ class receive_path(gr.hier_block): if self._verbose: self._print_verbage() + # connect block input to channel filter + self.connect(self, self.channel_filter) + # connect the channel input filter to the carrier power detector - fg.connect(self.channel_filter, self.probe) + self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver - fg.connect(self.channel_filter, self.packet_receiver) - - gr.hier_block.__init__(self, fg, self.channel_filter, None) + self.connect(self.channel_filter, self.packet_receiver) def bitrate(self): return self._bitrate diff --git a/gnuradio-examples/python/digital/rx_voice.py b/gnuradio-examples/python/digital/rx_voice.py index c9c33c3d56..b3280d432c 100755 --- a/gnuradio-examples/python/digital/rx_voice.py +++ b/gnuradio-examples/python/digital/rx_voice.py @@ -31,6 +31,7 @@ from gnuradio.vocoder import gsm_full_rate import random import struct +import sys # from current dir from receive_path import receive_path @@ -41,27 +42,30 @@ import fusb_options #raw_input('Attach and press enter') -class audio_tx(gr.hier_block): - def __init__(self, fg, audio_output_dev): +class audio_tx(gr.hier_block2): + def __init__(self, audio_output_dev): + gr.hier_block2.__init__(self, "audio_tx", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(0, 0, 0)) # Output signature + self.packet_src = gr.message_source(33) voice_decoder = gsm_full_rate.decode_ps() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) audio_sink = audio.sink(8000, audio_output_dev) - fg.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink) - gr.hier_block.__init__(self, fg, self.packet_src, audio_sink) + self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink) def msgq(self): return self.packet_src.msgq() -class my_graph(gr.flow_graph): - +class my_top_block(gr.top_block): def __init__(self, demod_class, rx_callback, options): - gr.flow_graph.__init__(self) - self.rxpath = receive_path(self, demod_class, rx_callback, options) - self.audio_tx = audio_tx(self, options.audio_output) - + gr.top_block.__init__(self) + self.rxpath = receive_path(demod_class, rx_callback, options) + self.audio_tx = audio_tx(options.audio_output) + self.connect(self.rxpath) + self.connect(self.audio_tx) # ///////////////////////////////////////////////////////////////////////////// # main @@ -120,14 +124,13 @@ def main(): # build the graph - fg = my_graph(demods[options.modulation], rx_callback, options) + tb = my_top_block(demods[options.modulation], rx_callback, options) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: Failed to enable realtime scheduling." - fg.start() # start flow graph - fg.wait() # wait for it to finish + tb.run() if __name__ == '__main__': try: diff --git a/gnuradio-examples/python/digital/transmit_path.py b/gnuradio-examples/python/digital/transmit_path.py index d8bdd0391a..4adf0577d0 100644 --- a/gnuradio-examples/python/digital/transmit_path.py +++ b/gnuradio-examples/python/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 # @@ -19,7 +19,7 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, blks +from gnuradio import gr, gru, blks2 from gnuradio import usrp from gnuradio import eng_notation @@ -33,11 +33,14 @@ from pick_bitrate import pick_tx_bitrate # transmit path # ///////////////////////////////////////////////////////////////////////////// -class transmit_path(gr.hier_block): - def __init__(self, fg, modulator_class, options): +class transmit_path(gr.hier_block2): + 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 options = copy.copy(options) # make a copy so we can destructively modify @@ -77,12 +80,11 @@ class transmit_path(gr.hier_block): # transmitter self.packet_transmitter = \ - blks.mod_pkts(fg, - self._modulator_class(fg, **mod_kwargs), - access_code=None, - msgq_limit=4, - pad_for_usrp=True, - use_whitener_offset=options.use_whitener_offset) + blks2.mod_pkts(self._modulator_class(**mod_kwargs), + access_code=None, + msgq_limit=4, + pad_for_usrp=True, + use_whitener_offset=options.use_whitener_offset) # Set the USRP for maximum transmit gain @@ -100,8 +102,7 @@ class transmit_path(gr.hier_block): self._print_verbage() # Create and setup transmit path flow graph - fg.connect(self.packet_transmitter, self.amp, self.u) - gr.hier_block.__init__(self, fg, None, None) + self.connect(self.packet_transmitter, self.amp, self.u) def _setup_usrp_sink(self): """ diff --git a/gnuradio-examples/python/digital/transmit_path_lb.py b/gnuradio-examples/python/digital/transmit_path_lb.py index 322d46af3c..49f53076e6 100644 --- a/gnuradio-examples/python/digital/transmit_path_lb.py +++ b/gnuradio-examples/python/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 # @@ -19,7 +19,7 @@ # Boston, MA 02110-1301, USA. # -from gnuradio import gr, gru, blks +from gnuradio import gr, gru, blks2 from gnuradio import eng_notation import copy @@ -29,11 +29,14 @@ import sys # transmit path # ///////////////////////////////////////////////////////////////////////////// -class transmit_path(gr.hier_block): - def __init__(self, fg, modulator_class, options): +class transmit_path(gr.hier_block2): + 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(1, 1, gr.sizeof_gr_complex)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify @@ -48,12 +51,14 @@ class transmit_path(gr.hier_block): mod_kwargs = self._modulator_class.extract_kwargs_from_options(options) # transmitter + print self._modulator_class + print mod_kwargs + modulator = self._modulator_class(**mod_kwargs) self.packet_transmitter = \ - blks.mod_pkts(fg, - self._modulator_class(fg, **mod_kwargs), - access_code=None, - msgq_limit=4, - pad_for_usrp=True) + blks2.mod_pkts(modulator, + access_code=None, + msgq_limit=4, + pad_for_usrp=True) self.amp = gr.multiply_const_cc(1) self.set_tx_amplitude(self._tx_amplitude) @@ -63,9 +68,7 @@ class transmit_path(gr.hier_block): self._print_verbage() # Connect components in the flowgraph - fg.connect(self.packet_transmitter, self.amp) - - gr.hier_block.__init__(self, fg, None, self.amp) + self.connect(self.packet_transmitter, self.amp, self) def set_tx_amplitude(self, ampl): """ diff --git a/gnuradio-examples/python/digital/tunnel.py b/gnuradio-examples/python/digital/tunnel.py index 7d17ff958a..111ed0db42 100755 --- a/gnuradio-examples/python/digital/tunnel.py +++ b/gnuradio-examples/python/digital/tunnel.py @@ -86,14 +86,14 @@ def open_tun_interface(tun_device_filename): # the flow graph # ///////////////////////////////////////////////////////////////////////////// -class my_graph(gr.flow_graph): +class my_top_block(gr.top_block): def __init__(self, mod_class, demod_class, rx_callback, options): - gr.flow_graph.__init__(self) - self.txpath = transmit_path(self, mod_class, options) - self.rxpath = receive_path(self, demod_class, rx_callback, options) + gr.top_block.__init__(self) + self.txpath = transmit_path(mod_class, options) + self.rxpath = receive_path(demod_class, rx_callback, options) def send_pkt(self, payload='', eof=False): return self.txpath.send_pkt(payload, eof) @@ -123,10 +123,10 @@ class cs_mac(object): def __init__(self, tun_fd, verbose=False): self.tun_fd = tun_fd # file descriptor for TUN/TAP interface self.verbose = verbose - self.fg = None # flow graph (access to PHY) + self.tb = None # top block (access to PHY) - def set_flow_graph(self, fg): - self.fg = fg + def set_top_block(self, tb): + self.tb = tb def phy_rx_callback(self, ok, payload): """ @@ -152,20 +152,20 @@ class cs_mac(object): while 1: payload = os.read(self.tun_fd, 10*1024) if not payload: - self.fg.send_pkt(eof=True) + self.tb.send_pkt(eof=True) break if self.verbose: print "Tx: len(payload) = %4d" % (len(payload),) delay = min_delay - while self.fg.carrier_sensed(): + while self.tb.carrier_sensed(): sys.stderr.write('B') time.sleep(delay) if delay < 0.050: delay = delay * 2 # exponential back-off - self.fg.send_pkt(payload) + self.tb.send_pkt(payload) # ///////////////////////////////////////////////////////////////////////////// @@ -243,26 +243,26 @@ def main(): # build the graph (PHY) - fg = my_graph(mods[options.modulation], - demods[options.modulation], - mac.phy_rx_callback, - options) + tb = my_top_block(mods[options.modulation], + demods[options.modulation], + mac.phy_rx_callback, + options) - mac.set_flow_graph(fg) # give the MAC a handle for the PHY + mac.set_top_block(tb) # give the MAC a handle for the PHY - if fg.txpath.bitrate() != fg.rxpath.bitrate(): + if tb.txpath.bitrate() != tb.rxpath.bitrate(): print "WARNING: Transmit bitrate = %sb/sec, Receive bitrate = %sb/sec" % ( - eng_notation.num_to_str(fg.txpath.bitrate()), - eng_notation.num_to_str(fg.rxpath.bitrate())) + eng_notation.num_to_str(tb.txpath.bitrate()), + eng_notation.num_to_str(tb.rxpath.bitrate())) print "modulation: %s" % (options.modulation,) print "freq: %s" % (eng_notation.num_to_str(options.tx_freq)) - print "bitrate: %sb/sec" % (eng_notation.num_to_str(fg.txpath.bitrate()),) - print "samples/symbol: %3d" % (fg.txpath.samples_per_symbol(),) - #print "interp: %3d" % (fg.txpath.interp(),) - #print "decim: %3d" % (fg.rxpath.decim(),) + print "bitrate: %sb/sec" % (eng_notation.num_to_str(tb.txpath.bitrate()),) + print "samples/symbol: %3d" % (tb.txpath.samples_per_symbol(),) + #print "interp: %3d" % (tb.txpath.interp(),) + #print "decim: %3d" % (tb.rxpath.decim(),) - fg.rxpath.set_carrier_threshold(options.carrier_threshold) + tb.rxpath.set_carrier_threshold(options.carrier_threshold) print "Carrier sense threshold:", options.carrier_threshold, "dB" print @@ -275,12 +275,12 @@ def main(): print - fg.start() # Start executing the flow graph (runs in separate threads) + tb.start() # Start executing the flow graph (runs in separate threads) mac.main_loop() # don't expect this to return... - fg.stop() # but if it does, tell flow graph to stop. - fg.wait() # wait for it to finish + tb.stop() # but if it does, tell flow graph to stop. + tb.wait() # wait for it to finish if __name__ == '__main__': diff --git a/gnuradio-examples/python/digital/tx_voice.py b/gnuradio-examples/python/digital/tx_voice.py index 09b1c58470..c97e2f084a 100755 --- a/gnuradio-examples/python/digital/tx_voice.py +++ b/gnuradio-examples/python/digital/tx_voice.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 # @@ -43,8 +43,11 @@ import fusb_options #raw_input('Attach and press enter') -class audio_rx(gr.hier_block): - def __init__(self, fg, audio_input_dev): +class audio_rx(gr.hier_block2): + def __init__(self, audio_input_dev): + gr.hier_block2.__init__(self, "audio_rx", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(0, 0, 0)) # Output signature sample_rate = 8000 src = audio.source(sample_rate, audio_input_dev) src_scale = gr.multiply_const_ff(32767) @@ -52,20 +55,20 @@ class audio_rx(gr.hier_block): voice_coder = gsm_full_rate.encode_sp() self.packets_from_encoder = gr.msg_queue() packet_sink = gr.message_sink(33, self.packets_from_encoder, False) - fg.connect(src, src_scale, f2s, voice_coder, packet_sink) - gr.hier_block.__init__(self, fg, src, packet_sink) + self.connect(src, src_scale, f2s, voice_coder, packet_sink) def get_encoded_voice_packet(self): return self.packets_from_encoder.delete_head() -class my_graph(gr.flow_graph): +class my_top_block(gr.top_block): def __init__(self, modulator_class, options): - gr.flow_graph.__init__(self) - self.txpath = transmit_path(self, modulator_class, options) - self.audio_rx = audio_rx(self, options.audio_input) - + gr.top_block.__init__(self) + self.txpath = transmit_path(modulator_class, options) + self.audio_rx = audio_rx(options.audio_input) + self.connect(self.txpath) + self.connect(self.audio_rx) # ///////////////////////////////////////////////////////////////////////////// @@ -75,7 +78,7 @@ class my_graph(gr.flow_graph): def main(): def send_pkt(payload='', eof=False): - return fg.txpath.send_pkt(payload, eof) + return tb.txpath.send_pkt(payload, eof) def rx_callback(ok, payload): print "ok = %r, payload = '%s'" % (ok, payload) @@ -115,14 +118,14 @@ def main(): # build the graph - fg = my_graph(mods[options.modulation], options) + tb = my_top_block(mods[options.modulation], options) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" - fg.start() # start flow graph + tb.start() # start flow graph # generate and send packets nbytes = int(1e6 * options.megabytes) @@ -130,7 +133,7 @@ def main(): pktno = 0 while nbytes == 0 or n < nbytes: - packet = fg.audio_rx.get_encoded_voice_packet() + packet = tb.audio_rx.get_encoded_voice_packet() s = packet.to_string() send_pkt(s) n += len(s) @@ -138,12 +141,12 @@ def main(): pktno += 1 send_pkt(eof=True) - fg.wait() # wait for it to finish - fg.txpath.set_auto_tr(False) + tb.wait() # wait for it to finish + tb.txpath.set_auto_tr(False) if __name__ == '__main__': try: main() except KeyboardInterrupt: - pass + pass
\ No newline at end of file |