--- /dev/null
+<?xml version="1.0"?>
+<!--
+###################################################
+##Probe Function
+###################################################
+ -->
+<block>
+ <name>Probe Function</name>
+ <key>probe_function</key>
+ <import>from grc_gnuradio import blks2 as grc_blks2</import>
+ <make>grc_blks2.probe_function(
+ probe_callback=self.$(block_id.eval).$(function_name.eval),
+ probe_rate=$probe_rate,
+)</make>
+ <callback>set_probe_rate($probe_rate)</callback>
+ <param>
+ <name>Block ID</name>
+ <key>block_id</key>
+ <value>my_block_0</value>
+ <type>string</type>
+ </param>
+ <param>
+ <name>Function Name</name>
+ <key>function_name</key>
+ <value>get_number</value>
+ <type>string</type>
+ </param>
+ <param>
+ <name>Probe Rate</name>
+ <key>probe_rate</key>
+ <value>10</value>
+ <type>real</type>
+ </param>
+ <source>
+ <name>out</name>
+ <type>float</type>
+ </source>
+ <doc>
+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.
+ </doc>
+</block>
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
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)
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
#######################################################################################
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