From e7a634266fa2b406057b346adaa9a5efb7e479e2 Mon Sep 17 00:00:00 2001 From: jblum Date: Wed, 8 Oct 2008 05:18:19 +0000 Subject: [PATCH] probe function block git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9745 221aa14e-8319-0410-a670-987f0aec2ac5 --- grc/data/platforms/python/block_tree.xml | 1 + grc/data/platforms/python/blocks/Makefile.am | 1 + .../python/blocks/gr_probe_mpsk_snr_c.xml | 2 +- .../python/blocks/probe_function.xml | 44 +++++++++++++++++++ grc/src/grc_gnuradio/blks2/__init__.py | 2 +- grc/src/grc_gnuradio/blks2/probe.py | 30 ++++++++++--- grc/src/platforms/python/Generator.py | 3 +- grc/todo.txt | 2 + 8 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 grc/data/platforms/python/blocks/probe_function.xml diff --git a/grc/data/platforms/python/block_tree.xml b/grc/data/platforms/python/block_tree.xml index 5e2d8f50..4cd1ca21 100644 --- a/grc/data/platforms/python/block_tree.xml +++ b/grc/data/platforms/python/block_tree.xml @@ -241,6 +241,7 @@ gr_probe_avg_mag_sqrd_x gr_probe_density_b gr_probe_mpsk_snr_c + probe_function USRP diff --git a/grc/data/platforms/python/blocks/Makefile.am b/grc/data/platforms/python/blocks/Makefile.am index 1e4d3f7f..de679260 100644 --- a/grc/data/platforms/python/blocks/Makefile.am +++ b/grc/data/platforms/python/blocks/Makefile.am @@ -184,6 +184,7 @@ dist_ourdata_DATA = \ pad_source.xml \ parameter.xml \ preferences.xml \ + probe_function.xml \ random_source_x.xml \ trellis_encoder_xx.xml \ trellis_metrics_x.xml \ diff --git a/grc/data/platforms/python/blocks/gr_probe_mpsk_snr_c.xml b/grc/data/platforms/python/blocks/gr_probe_mpsk_snr_c.xml index 655eb7c0..8b427076 100644 --- a/grc/data/platforms/python/blocks/gr_probe_mpsk_snr_c.xml +++ b/grc/data/platforms/python/blocks/gr_probe_mpsk_snr_c.xml @@ -9,7 +9,7 @@ gr_probe_mpsk_snr_c from grc_gnuradio import blks2 as grc_blks2 grc_blks2.probe_mpsk_snr_c( - type="$type", + type="$type", alpha=$alpha, probe_rate=$probe_rate, ) diff --git a/grc/data/platforms/python/blocks/probe_function.xml b/grc/data/platforms/python/blocks/probe_function.xml new file mode 100644 index 00000000..d4687852 --- /dev/null +++ b/grc/data/platforms/python/blocks/probe_function.xml @@ -0,0 +1,44 @@ + + + + Probe Function + probe_function + from grc_gnuradio import blks2 as grc_blks2 + grc_blks2.probe_function( + probe_callback=self.$(block_id.eval).$(function_name.eval), + probe_rate=$probe_rate, +) + set_probe_rate($probe_rate) + + Block ID + block_id + my_block_0 + string + + + Function Name + function_name + get_number + string + + + Probe Rate + probe_rate + 10 + real + + + out + float + + +Polls a function of an arbitrary block and writes the value to the output port. \ +The block id is the id of another block in the flow graph. \ +The function name is the name of a function in the said block. \ +The function should take no arguments and return a floating point or integer number. + + diff --git a/grc/src/grc_gnuradio/blks2/__init__.py b/grc/src/grc_gnuradio/blks2/__init__.py index a66988d4..0e94dbb9 100644 --- a/grc/src/grc_gnuradio/blks2/__init__.py +++ b/grc/src/grc_gnuradio/blks2/__init__.py @@ -25,4 +25,4 @@ from queue import queue_source_c, queue_source_f, queue_source_i, queue_source_s from selector import selector, valve from packet import packet_encoder, packet_decoder from error_rate import error_rate -from probe import probe_avg_mag_sqrd_c, probe_avg_mag_sqrd_f, probe_density_b, probe_mpsk_snr_c +from probe import probe_function, probe_avg_mag_sqrd_c, probe_avg_mag_sqrd_f, probe_density_b, probe_mpsk_snr_c diff --git a/grc/src/grc_gnuradio/blks2/probe.py b/grc/src/grc_gnuradio/blks2/probe.py index 28721422..8db81f05 100644 --- a/grc/src/grc_gnuradio/blks2/probe.py +++ b/grc/src/grc_gnuradio/blks2/probe.py @@ -24,17 +24,19 @@ import threading import numpy import time -class _probe_base(gr.hier_block2, threading.Thread): +####################################################################################### +## Probe: Function +####################################################################################### +class probe_function(gr.hier_block2, threading.Thread): """ - A hier2 block with float output and probe input. - The thread polls the prope for values and writes to a message source. + The thread polls the function for values and writes to a message source. """ - def __init__(self, probe_block, probe_callback, probe_rate): + def __init__(self, probe_callback, probe_rate): #init hier block gr.hier_block2.__init__( - self, 'probe', - gr.io_signature(1, 1, probe_block.input_signature().sizeof_stream_items()[0]), + self, 'probe_function', + gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_float), ) self._probe_callback = probe_callback @@ -43,7 +45,6 @@ class _probe_base(gr.hier_block2, threading.Thread): message_source = gr.message_source(gr.sizeof_float, 1) self._msgq = message_source.msgq() #connect - self.connect(self, probe_block) self.connect(message_source, self) #setup thread threading.Thread.__init__(self) @@ -63,6 +64,21 @@ class _probe_base(gr.hier_block2, threading.Thread): def set_probe_rate(self, probe_rate): self._probe_rate = probe_rate +class _probe_base(gr.hier_block2): + def __init__(self, probe_block, probe_callback, probe_rate): + #init hier block + gr.hier_block2.__init__( + self, 'probe', + gr.io_signature(1, 1, probe_block.input_signature().sizeof_stream_items()[0]), + gr.io_signature(1, 1, gr.sizeof_float), + ) + probe_function_block = probe_function(probe_callback, probe_rate) + #forward callbacks + self.set_probe_rate = probe_function_block.set_probe_rate + #connect + self.connect(self, probe_block) + self.connect(probe_function_block, self) + ####################################################################################### ## Probe: Average Magnitude Squared ####################################################################################### diff --git a/grc/src/platforms/python/Generator.py b/grc/src/platforms/python/Generator.py index bd3d69cc..7879fdfc 100644 --- a/grc/src/platforms/python/Generator.py +++ b/grc/src/platforms/python/Generator.py @@ -81,7 +81,8 @@ class Generator(object): controls = filter(lambda v: v.get_key().startswith('variable_'), variables) #list of blocks not including variables and imports and parameters and disabled blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id())) - blocks = filter(lambda b: b not in (imports + parameters + variables), blocks) + probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list + blocks = filter(lambda b: b not in (imports + parameters + variables + probes), blocks) + probes #list of connections where each endpoint is enabled connections = self._flow_graph.get_enabled_connections() #list of variable names diff --git a/grc/todo.txt b/grc/todo.txt index d9025b66..bce1028e 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -6,6 +6,8 @@ -controlled step block -throttle with sink only (source is nulled) -simplify simple usrp +-numbersink: update wrapper for newer api +-probe: also non-float outputs ################################################## # Features -- 2.47.2