From 4df03f7bb6c99bb22f41d21e6c65c1b41e00ff05 Mon Sep 17 00:00:00 2001 From: jblum Date: Wed, 8 Oct 2008 03:48:33 +0000 Subject: [PATCH] probe hier wrappers git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9741 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_avg_mag_sqrd_x.xml | 30 ++--- .../python/blocks/gr_probe_density_b.xml | 28 ++--- .../python/blocks/gr_probe_mpsk_snr_c.xml | 48 +++++--- .../python/blocks/gr_probe_signal_f.xml | 31 ----- .../python/blocks/wxgui_numbersink2.xml | 2 +- grc/src/grc_gnuradio/blks2/Makefile.am | 1 + grc/src/grc_gnuradio/blks2/__init__.py | 1 + grc/src/grc_gnuradio/blks2/probe.py | 107 ++++++++++++++++++ grc/src/grc_gnuradio/blks2/queue.py | 2 +- grc/src/grc_gnuradio/blks2/selector.py | 1 - grc/todo.txt | 7 +- 13 files changed, 177 insertions(+), 83 deletions(-) delete mode 100644 grc/data/platforms/python/blocks/gr_probe_signal_f.xml create mode 100644 grc/src/grc_gnuradio/blks2/probe.py diff --git a/grc/data/platforms/python/block_tree.xml b/grc/data/platforms/python/block_tree.xml index a234001d..5e2d8f50 100644 --- a/grc/data/platforms/python/block_tree.xml +++ b/grc/data/platforms/python/block_tree.xml @@ -241,7 +241,6 @@ gr_probe_avg_mag_sqrd_x gr_probe_density_b gr_probe_mpsk_snr_c - gr_probe_signal_f USRP diff --git a/grc/data/platforms/python/blocks/Makefile.am b/grc/data/platforms/python/blocks/Makefile.am index 2d4eec56..1e4d3f7f 100644 --- a/grc/data/platforms/python/blocks/Makefile.am +++ b/grc/data/platforms/python/blocks/Makefile.am @@ -141,7 +141,6 @@ 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 \ diff --git a/grc/data/platforms/python/blocks/gr_probe_avg_mag_sqrd_x.xml b/grc/data/platforms/python/blocks/gr_probe_avg_mag_sqrd_x.xml index cbd8446c..eb855956 100644 --- a/grc/data/platforms/python/blocks/gr_probe_avg_mag_sqrd_x.xml +++ b/grc/data/platforms/python/blocks/gr_probe_avg_mag_sqrd_x.xml @@ -7,19 +7,15 @@ Probe Avg Mag^2 gr_probe_avg_mag_sqrd_x - from gnuradio import gr - import threading - import time - gr.probe_avg_mag_sqrd_$(type)($threshold, $alpha) -def _$(id)_run(): - while True: - time.sleep($update_interval) - print "$(id) Level:", self.$(id).level() -_$(id)_thread = threading.Thread(target=_$(id)_run) -_$(id)_thread.setDaemon(True) -_$(id)_thread.start() + from grc_gnuradio import blks2 as grc_blks2 + grc_blks2.probe_avg_mag_sqrd_$(type)( + threshold=$threshold, + alpha=$alpha, + probe_rate=$probe_rate, +) set_alpha($alpha) set_threshold($threshold) + set_probe_rate($probe_rate) Type type @@ -38,21 +34,27 @@ _$(id)_thread.start() Threshold (dB) threshold + 0 real Alpha alpha + 1 real - Update Interval (s) - update_interval - 1.0 + Probe Rate + probe_rate + 10 real in $type.input + + out + float + diff --git a/grc/data/platforms/python/blocks/gr_probe_density_b.xml b/grc/data/platforms/python/blocks/gr_probe_density_b.xml index 4c5b9e2f..74d3b0a2 100644 --- a/grc/data/platforms/python/blocks/gr_probe_density_b.xml +++ b/grc/data/platforms/python/blocks/gr_probe_density_b.xml @@ -7,31 +7,31 @@ Probe Density gr_probe_density_b - from gnuradio import gr - import threading - import time - gr.probe_density_b($alpha) -def _$(id)_run(): - while True: - time.sleep($update_interval) - print "$(id) Density:", self.$(id).density() -_$(id)_thread = threading.Thread(target=_$(id)_run) -_$(id)_thread.setDaemon(True) -_$(id)_thread.start() + from grc_gnuradio import blks2 as grc_blks2 + grc_blks2.probe_density_b( + alpha=$alpha, + probe_rate=$probe_rate, +) set_alpha($alpha) + set_probe_rate($probe_rate) Alpha alpha + 1 real - Update Interval (s) - update_interval - 1.0 + Probe Rate + probe_rate + 10 real in byte + + out + float + 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 ec80d092..655eb7c0 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 @@ -7,33 +7,49 @@ Probe MPSK SNR gr_probe_mpsk_snr_c - from gnuradio import gr - import threading - import time - gr.probe_mpsk_snr_c($alpha) -def _$(id)_run(): - while True: - time.sleep($update_interval) - print "$(id) Signal Mean:", self.$(id).signal_mean() - print "$(id) Noise Variance:", self.$(id).noise_variance() - print "$(id) SNR:", self.$(id).snr() -_$(id)_thread = threading.Thread(target=_$(id)_run) -_$(id)_thread.setDaemon(True) -_$(id)_thread.start() + from grc_gnuradio import blks2 as grc_blks2 + grc_blks2.probe_mpsk_snr_c( + type="$type", + alpha=$alpha, + probe_rate=$probe_rate, +) set_alpha($alpha) + set_probe_rate($probe_rate) + + Type + type + enum + + + + Alpha alpha + 1 real - Update Interval (s) - update_interval - 1.0 + Probe Rate + probe_rate + 10 real in complex + + out + float + diff --git a/grc/data/platforms/python/blocks/gr_probe_signal_f.xml b/grc/data/platforms/python/blocks/gr_probe_signal_f.xml deleted file mode 100644 index 688887f4..00000000 --- a/grc/data/platforms/python/blocks/gr_probe_signal_f.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - Probe Signal - gr_probe_signal_f - from gnuradio import gr - import threading - import time - gr.probe_signal_f() -def _$(id)_run(): - while True: - time.sleep($update_interval) - print "$(id) Level:", self.$(id).level() -_$(id)_thread = threading.Thread(target=_$(id)_run) -_$(id)_thread.setDaemon(True) -_$(id)_thread.start() - - Update Interval (s) - update_interval - 1.0 - real - - - in - float - - diff --git a/grc/data/platforms/python/blocks/wxgui_numbersink2.xml b/grc/data/platforms/python/blocks/wxgui_numbersink2.xml index e54da3e6..c3a8c52b 100644 --- a/grc/data/platforms/python/blocks/wxgui_numbersink2.xml +++ b/grc/data/platforms/python/blocks/wxgui_numbersink2.xml @@ -102,7 +102,7 @@ self.GridAdd(self.$(id).win, $grid_pos[0], $grid_pos[1], $grid_pos[2], $grid_pos Reference Level ref_level - 50 + 0 real diff --git a/grc/src/grc_gnuradio/blks2/Makefile.am b/grc/src/grc_gnuradio/blks2/Makefile.am index e3a0b8a3..528697bd 100644 --- a/grc/src/grc_gnuradio/blks2/Makefile.am +++ b/grc/src/grc_gnuradio/blks2/Makefile.am @@ -27,5 +27,6 @@ ourpython_PYTHON = \ __init__.py \ error_rate.py \ packet.py \ + probe.py \ queue.py \ selector.py diff --git a/grc/src/grc_gnuradio/blks2/__init__.py b/grc/src/grc_gnuradio/blks2/__init__.py index a26228f8..a66988d4 100644 --- a/grc/src/grc_gnuradio/blks2/__init__.py +++ b/grc/src/grc_gnuradio/blks2/__init__.py @@ -25,3 +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 diff --git a/grc/src/grc_gnuradio/blks2/probe.py b/grc/src/grc_gnuradio/blks2/probe.py new file mode 100644 index 00000000..28721422 --- /dev/null +++ b/grc/src/grc_gnuradio/blks2/probe.py @@ -0,0 +1,107 @@ +# +# 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 + +class _probe_base(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. + """ + + 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), + ) + 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(self, probe_block) + 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 + +####################################################################################### +## 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/src/grc_gnuradio/blks2/queue.py b/grc/src/grc_gnuradio/blks2/queue.py index 25ea1c61..1bb9fe74 100644 --- a/grc/src/grc_gnuradio/blks2/queue.py +++ b/grc/src/grc_gnuradio/blks2/queue.py @@ -140,7 +140,7 @@ class _queue_source_base(gr.hier_block2): gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, self._item_size*self._vlen) # Output signature ) - #create message sink + #create message source message_source = gr.message_source(self._item_size*self._vlen, 1) self._msgq = message_source.msgq() #connect diff --git a/grc/src/grc_gnuradio/blks2/selector.py b/grc/src/grc_gnuradio/blks2/selector.py index 0997a5ce..2a3c6419 100644 --- a/grc/src/grc_gnuradio/blks2/selector.py +++ b/grc/src/grc_gnuradio/blks2/selector.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python # # Copyright 2008 Free Software Foundation, Inc. # diff --git a/grc/todo.txt b/grc/todo.txt index 71a38314..d9025b66 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -6,7 +6,6 @@ -controlled step block -throttle with sink only (source is nulled) -simplify simple usrp --probe blocks needs better polling mechanism ################################################## # Features @@ -20,7 +19,7 @@ -zoom in/out (cairo vector graphics) (use scroll wheel as control) -search for blocks -click and drag on whitespace to scroll --expand preferences, allow for custome prefs, prefs dialog should infer structure +-expand preferences, allow for custom prefs, prefs dialog should infer structure ################################################## # Problems @@ -29,7 +28,9 @@ -auto clean hier library -add hier blocks to tree without restart? -dont hide vlen controller when vlen > 1 --dont generate py files in cwd, add preference for user to choose +-dont generate py files in .grc file dir +-save/restore cwd +-check for .grc file readonly, ro message in window, no save option ################################################## # External -- 2.47.2