diff options
-rw-r--r-- | grc/blocks/Makefile.am | 4 | ||||
-rw-r--r-- | grc/blocks/blks2_variable_sink_x.xml | 77 | ||||
-rw-r--r-- | grc/blocks/block_tree.xml | 4 | ||||
-rw-r--r-- | grc/blocks/gr_probe_avg_mag_sqrd_x.xml | 22 | ||||
-rw-r--r-- | grc/blocks/gr_probe_density_b.xml | 15 | ||||
-rw-r--r-- | grc/blocks/gr_probe_mpsk_snr_c.xml | 39 | ||||
-rw-r--r-- | grc/blocks/gr_probe_signal_f.xml | 19 | ||||
-rw-r--r-- | grc/blocks/probe_function.xml | 44 | ||||
-rw-r--r-- | grc/blocks/variable_function_probe.xml | 51 | ||||
-rw-r--r-- | grc/grc_gnuradio/Makefile.am | 6 | ||||
-rw-r--r-- | grc/grc_gnuradio/blks2/__init__.py | 4 | ||||
-rw-r--r-- | grc/grc_gnuradio/blks2/probe.py | 123 | ||||
-rw-r--r-- | grc/grc_gnuradio/blks2/variable_sink.py | 64 |
13 files changed, 92 insertions, 380 deletions
diff --git a/grc/blocks/Makefile.am b/grc/blocks/Makefile.am index d9ec0896e..15c641fbc 100644 --- a/grc/blocks/Makefile.am +++ b/grc/blocks/Makefile.am @@ -60,7 +60,6 @@ dist_ourdata_DATA = \ blks2_tcp_sink.xml \ blks2_tcp_source.xml \ blks2_valve.xml \ - blks2_variable_sink_x.xml \ blks2_wfm_rcv.xml \ blks2_wfm_rcv_pll.xml \ blks2_wfm_tx.xml \ @@ -158,6 +157,7 @@ dist_ourdata_DATA = \ gr_probe_avg_mag_sqrd_x.xml \ gr_probe_density_b.xml \ gr_probe_mpsk_snr_c.xml \ + gr_probe_signal_f.xml \ gr_pwr_squelch_xx.xml \ gr_quadrature_demod_cf.xml \ gr_rational_resampler_base_xxx.xml \ @@ -201,7 +201,6 @@ dist_ourdata_DATA = \ pad_sink.xml \ pad_source.xml \ parameter.xml \ - probe_function.xml \ random_source_x.xml \ root_raised_cosine_filter.xml \ trellis_encoder_xx.xml \ @@ -221,6 +220,7 @@ dist_ourdata_DATA = \ usrp_simple_source_x.xml \ variable.xml \ variable_config.xml \ + variable_function_probe.xml \ virtual_sink.xml \ virtual_source.xml \ xmlrpc_client.xml \ diff --git a/grc/blocks/blks2_variable_sink_x.xml b/grc/blocks/blks2_variable_sink_x.xml deleted file mode 100644 index 5709c9f76..000000000 --- a/grc/blocks/blks2_variable_sink_x.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0"?> -<!-- -################################################### -##Variable Sink: Custom blks2 block -################################################### - --> -<block> - <name>Variable Sink</name> - <key>blks2_variable_sink_x</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.variable_sink_$(type.fcn)( - vlen=$vlen, - decim=$decim, - callback=self.set_$(variable()), -)</make> - <callback>set_decim($decim)</callback> - <param> - <name>Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>Complex</name> - <key>complex</key> - <opt>fcn:c</opt> - </option> - <option> - <name>Float</name> - <key>float</key> - <opt>fcn:f</opt> - </option> - <option> - <name>Int</name> - <key>int</key> - <opt>fcn:i</opt> - </option> - <option> - <name>Short</name> - <key>short</key> - <opt>fcn:s</opt> - </option> - <option> - <name>Byte</name> - <key>byte</key> - <opt>fcn:b</opt> - </option> - </param> - <param> - <name>Variable</name> - <key>variable</key> - <value></value> - <type>string</type> - </param> - <param> - <name>Decimation</name> - <key>decim</key> - <value>1</value> - <type>int</type> - </param> - <param> - <name>Vec Length</name> - <key>vlen</key> - <value>1</value> - <type>int</type> - </param> - <check>$vlen > 0</check> - <sink> - <name>in</name> - <type>$type</type> - <vlen>$vlen</vlen> - </sink> - <doc> -Read samples from the input stream and \ -write one in every decimation samples to the variable. - -The variable must be the id of an existing variable block. - </doc> -</block> diff --git a/grc/blocks/block_tree.xml b/grc/blocks/block_tree.xml index 50c463f55..e9a0c1591 100644 --- a/grc/blocks/block_tree.xml +++ b/grc/blocks/block_tree.xml @@ -26,7 +26,6 @@ </cat> <cat> <name>Sinks</name> - <block>blks2_variable_sink_x</block> <block>gr_vector_sink_x</block> <block>gr_null_sink</block> <block>gr_file_sink</block> @@ -261,7 +260,7 @@ <block>gr_probe_avg_mag_sqrd_x</block> <block>gr_probe_density_b</block> <block>gr_probe_mpsk_snr_c</block> - <block>probe_function</block> + <block>gr_probe_signal_f</block> </cat> <cat> <name>USRP</name> @@ -276,6 +275,7 @@ <name>Variables</name> <block>variable</block> <block>variable_config</block> + <block>variable_function_probe</block> <block>parameter</block> </cat> <cat> diff --git a/grc/blocks/gr_probe_avg_mag_sqrd_x.xml b/grc/blocks/gr_probe_avg_mag_sqrd_x.xml index eb855956a..ac409ad67 100644 --- a/grc/blocks/gr_probe_avg_mag_sqrd_x.xml +++ b/grc/blocks/gr_probe_avg_mag_sqrd_x.xml @@ -7,15 +7,10 @@ <block> <name>Probe Avg Mag^2</name> <key>gr_probe_avg_mag_sqrd_x</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.probe_avg_mag_sqrd_$(type)( - threshold=$threshold, - alpha=$alpha, - probe_rate=$probe_rate, -)</make> + <import>from gnuradio import gr</import> + <make>gr.probe_avg_mag_sqrd_$(type)($threshold, $alpha)</make> <callback>set_alpha($alpha)</callback> <callback>set_threshold($threshold)</callback> - <callback>set_probe_rate($probe_rate)</callback> <param> <name>Type</name> <key>type</key> @@ -43,18 +38,11 @@ <value>1</value> <type>real</type> </param> - <param> - <name>Probe Rate</name> - <key>probe_rate</key> - <value>10</value> - <type>real</type> - </param> <sink> <name>in</name> <type>$type.input</type> </sink> - <source> - <name>out</name> - <type>float</type> - </source> + <doc> +Available functions to probe: level + </doc> </block> diff --git a/grc/blocks/gr_probe_density_b.xml b/grc/blocks/gr_probe_density_b.xml index 74d3b0a2b..8e0e2c964 100644 --- a/grc/blocks/gr_probe_density_b.xml +++ b/grc/blocks/gr_probe_density_b.xml @@ -7,13 +7,9 @@ <block> <name>Probe Density</name> <key>gr_probe_density_b</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.probe_density_b( - alpha=$alpha, - probe_rate=$probe_rate, -)</make> + <import>from gnuradio import gr</import> + <make>gr.probe_density_b($alpha)</make> <callback>set_alpha($alpha)</callback> - <callback>set_probe_rate($probe_rate)</callback> <param> <name>Alpha</name> <key>alpha</key> @@ -30,8 +26,7 @@ <name>in</name> <type>byte</type> </sink> - <source> - <name>out</name> - <type>float</type> - </source> + <doc> +Available functions to probe: density + </doc> </block> diff --git a/grc/blocks/gr_probe_mpsk_snr_c.xml b/grc/blocks/gr_probe_mpsk_snr_c.xml index 7f562d2f3..38211b55f 100644 --- a/grc/blocks/gr_probe_mpsk_snr_c.xml +++ b/grc/blocks/gr_probe_mpsk_snr_c.xml @@ -7,49 +7,20 @@ <block> <name>Probe MPSK SNR</name> <key>gr_probe_mpsk_snr_c</key> - <import>from grc_gnuradio import blks2 as grc_blks2</import> - <make>grc_blks2.probe_mpsk_snr_c( - type='$type', - alpha=$alpha, - probe_rate=$probe_rate, -)</make> + <import>from gnuradio import gr</import> + <make>gr.probe_mpsk_snr_c($alpha)</make> <callback>set_alpha($alpha)</callback> - <callback>set_probe_rate($probe_rate)</callback> - <param> - <name>Type</name> - <key>type</key> - <type>enum</type> - <option> - <name>SNR</name> - <key>snr</key> - </option> - <option> - <name>Signal Mean</name> - <key>signal_mean</key> - </option> - <option> - <name>Noise Variance</name> - <key>noise_variance</key> - </option> - </param> <param> <name>Alpha</name> <key>alpha</key> <value>1</value> <type>real</type> </param> - <param> - <name>Probe Rate</name> - <key>probe_rate</key> - <value>10</value> - <type>real</type> - </param> <sink> <name>in</name> <type>complex</type> </sink> - <source> - <name>out</name> - <type>float</type> - </source> + <doc> +Available functions to probe: signal_mean, noise_variance + </doc> </block> diff --git a/grc/blocks/gr_probe_signal_f.xml b/grc/blocks/gr_probe_signal_f.xml new file mode 100644 index 000000000..e1847788a --- /dev/null +++ b/grc/blocks/gr_probe_signal_f.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Probe Signal +################################################### + --> +<block> + <name>Probe Signal</name> + <key>gr_probe_signal_f</key> + <import>from gnuradio import gr</import> + <make>gr.probe_signal_f()</make> + <sink> + <name>in</name> + <type>float</type> + </sink> + <doc> +Available functions to probe: level + </doc> +</block> diff --git a/grc/blocks/probe_function.xml b/grc/blocks/probe_function.xml deleted file mode 100644 index ac0b3dcde..000000000 --- a/grc/blocks/probe_function.xml +++ /dev/null @@ -1,44 +0,0 @@ -<?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()).$(function_name()), - 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> diff --git a/grc/blocks/variable_function_probe.xml b/grc/blocks/variable_function_probe.xml new file mode 100644 index 000000000..695d2f56c --- /dev/null +++ b/grc/blocks/variable_function_probe.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Variable function probe +################################################### + --> +<block> + <name>Function Probe</name> + <key>variable_function_probe</key> + <import>import time</import> + <import>import threading</import> + <var_make>self.$(id) = $(id) = $value</var_make> + <make>#slurp +def _$(id)_probe(): + while True: + self.set_$(id)(self.$(block_id()).$(function_name())()) + time.sleep(1.0/($poll_rate)) +_$(id)_thread = threading.Thread(target=_$(id)_probe) +_$(id)_thread.daemon = True +_$(id)_thread.start()</make> + <callback>self.set_$(id)($value)</callback> + <param> + <name>Value</name> + <key>value</key> + <value>0</value> + <type>raw</type> + </param> + <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>Poll Rate (Hz)</name> + <key>poll_rate</key> + <value>10</value> + <type>real</type> + </param> + <doc> +Periodically probe a function and set its value to this variable. + +To poll a stream for a level, use this with the probe signal block. + </doc> +</block> diff --git a/grc/grc_gnuradio/Makefile.am b/grc/grc_gnuradio/Makefile.am index c53d07b4e..c70972f59 100644 --- a/grc/grc_gnuradio/Makefile.am +++ b/grc/grc_gnuradio/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008 Free Software Foundation, Inc. +# Copyright 2008-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -31,10 +31,8 @@ blks2_python_PYTHON = \ blks2/__init__.py \ blks2/error_rate.py \ blks2/packet.py \ - blks2/probe.py \ blks2/selector.py \ - blks2/tcp.py \ - blks2/variable_sink.py + blks2/tcp.py usrp_pythondir = $(grc_gnuradio_prefix)/usrp usrp_python_PYTHON = \ diff --git a/grc/grc_gnuradio/blks2/__init__.py b/grc/grc_gnuradio/blks2/__init__.py index cb1196f25..fde76f256 100644 --- a/grc/grc_gnuradio/blks2/__init__.py +++ b/grc/grc_gnuradio/blks2/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2008, 2009 Free Software Foundation, Inc. +# Copyright 2008-2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,6 +23,4 @@ from packet import options, packet_encoder, packet_decoder, \ packet_mod_b, packet_mod_s, packet_mod_i, packet_mod_f, packet_mod_c, \ packet_demod_b, packet_demod_s, packet_demod_i, packet_demod_f, packet_demod_c from error_rate import error_rate -from probe import probe_function, probe_avg_mag_sqrd_c, probe_avg_mag_sqrd_f, probe_density_b, probe_mpsk_snr_c -from variable_sink import variable_sink_b, variable_sink_s, variable_sink_i, variable_sink_f, variable_sink_c from tcp import tcp_source, tcp_sink diff --git a/grc/grc_gnuradio/blks2/probe.py b/grc/grc_gnuradio/blks2/probe.py deleted file mode 100644 index 8db81f057..000000000 --- a/grc/grc_gnuradio/blks2/probe.py +++ /dev/null @@ -1,123 +0,0 @@ -# -# Copyright 2008 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. -# - -from gnuradio import gr -import threading -import numpy -import time - -####################################################################################### -## Probe: Function -####################################################################################### -class probe_function(gr.hier_block2, threading.Thread): - """ - The thread polls the function for values and writes to a message source. - """ - - def __init__(self, probe_callback, probe_rate): - #init hier block - gr.hier_block2.__init__( - self, 'probe_function', - gr.io_signature(0, 0, 0), - gr.io_signature(1, 1, gr.sizeof_float), - ) - self._probe_callback = probe_callback - self.set_probe_rate(probe_rate) - #create message source - message_source = gr.message_source(gr.sizeof_float, 1) - self._msgq = message_source.msgq() - #connect - self.connect(message_source, self) - #setup thread - threading.Thread.__init__(self) - self.setDaemon(True) - self.start() - - def run(self): - """ - Infinite polling loop. - """ - while True: - time.sleep(1.0/self._probe_rate) - arr = numpy.array(self._probe_callback(), numpy.float32) - msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1) - self._msgq.insert_tail(msg) - - 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 -####################################################################################### -class _probe_avg_mag_sqrd_base(_probe_base): - def __init__(self, threshold, alpha, probe_rate): - #create block - probe_block = self._probe_block_contructor[0](threshold, alpha) - #forward callbacks - self.set_alpha = probe_block.set_alpha - self.set_threshold = probe_block.set_threshold - #init - _probe_base.__init__(self, probe_block, probe_block.level, probe_rate) - -class probe_avg_mag_sqrd_c(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_c,) -class probe_avg_mag_sqrd_f(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_f,) - -####################################################################################### -## Probe: Density -####################################################################################### -class probe_density_b(_probe_base): - def __init__(self, alpha, probe_rate): - #create block - probe_block = gr.probe_density_b(alpha) - #forward callbacks - self.set_alpha = probe_block.set_alpha - #init - _probe_base.__init__(self, probe_block, probe_block.density, probe_rate) - -####################################################################################### -## Probe: MPSK SNR -####################################################################################### -class probe_mpsk_snr_c(_probe_base): - def __init__(self, type, alpha, probe_rate): - """ - Type can be "snr", "signal_mean", or "noise_variance" - """ - #create block - probe_block = gr.probe_mpsk_snr_c(alpha) - #forward callbacks - self.set_alpha = probe_block.set_alpha - #init - _probe_base.__init__(self, probe_block, getattr(probe_block, type), probe_rate) diff --git a/grc/grc_gnuradio/blks2/variable_sink.py b/grc/grc_gnuradio/blks2/variable_sink.py deleted file mode 100644 index cad3b8b04..000000000 --- a/grc/grc_gnuradio/blks2/variable_sink.py +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright 2009 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. -# - -from gnuradio import gr -import threading -import numpy - -class _variable_sink_base(gr.hier_block2, threading.Thread): - """ - The thread polls the message queue for values and writes to a callback. - """ - - def __init__(self, vlen, decim, callback): - self._vlen = vlen - self._callback = callback - self._item_size = self._size*self._vlen - #init hier block - gr.hier_block2.__init__( - self, 'variable_sink', - gr.io_signature(1, 1, self._item_size), - gr.io_signature(0, 0, 0), - ) - #create blocks - self._decimator = gr.keep_one_in_n(self._item_size, decim) - self._msgq = gr.msg_queue(2) - message_sink = gr.message_sink(self._item_size, self._msgq, False) - #connect - self.connect(self, self._decimator, message_sink) - #setup thread - threading.Thread.__init__(self) - self.setDaemon(True) - self.start() - - def set_decim(self, decim): self._decimator.set_n(decim) - - def run(self): - while True: #truncate to item size, convert to array, callback - msg = self._msgq.delete_head().to_string()[-self._item_size:] - arr = map(self._cast, numpy.fromstring(msg, self._numpy)) - self._callback(self._vlen > 1 and arr or arr[0]) - -class variable_sink_b(_variable_sink_base): _numpy, _size, _cast = numpy.int8, gr.sizeof_char, int -class variable_sink_s(_variable_sink_base): _numpy, _size, _cast = numpy.int16, gr.sizeof_short, int -class variable_sink_i(_variable_sink_base): _numpy, _size, _cast = numpy.int32, gr.sizeof_int, int -class variable_sink_f(_variable_sink_base): _numpy, _size, _cast = numpy.float32, gr.sizeof_float, float -class variable_sink_c(_variable_sink_base): _numpy, _size, _cast = numpy.complex64, gr.sizeof_gr_complex, complex |