summaryrefslogtreecommitdiff
path: root/grc/src/grc_gnuradio
diff options
context:
space:
mode:
authorjblum2008-10-08 03:48:33 +0000
committerjblum2008-10-08 03:48:33 +0000
commit4df03f7bb6c99bb22f41d21e6c65c1b41e00ff05 (patch)
tree80c4906ca3ec7f0461df9adda38fcbb0fcb559f4 /grc/src/grc_gnuradio
parent2eaf1be5c1702498d8b857eaa77e695fffc60834 (diff)
downloadgnuradio-4df03f7bb6c99bb22f41d21e6c65c1b41e00ff05.tar.gz
gnuradio-4df03f7bb6c99bb22f41d21e6c65c1b41e00ff05.tar.bz2
gnuradio-4df03f7bb6c99bb22f41d21e6c65c1b41e00ff05.zip
probe hier wrappers
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9741 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/grc_gnuradio')
-rw-r--r--grc/src/grc_gnuradio/blks2/Makefile.am1
-rw-r--r--grc/src/grc_gnuradio/blks2/__init__.py1
-rw-r--r--grc/src/grc_gnuradio/blks2/probe.py107
-rw-r--r--grc/src/grc_gnuradio/blks2/queue.py2
-rw-r--r--grc/src/grc_gnuradio/blks2/selector.py1
5 files changed, 110 insertions, 2 deletions
diff --git a/grc/src/grc_gnuradio/blks2/Makefile.am b/grc/src/grc_gnuradio/blks2/Makefile.am
index e3a0b8a38..528697bd9 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 a26228f88..a66988d47 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 000000000..28721422d
--- /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 25ea1c616..1bb9fe743 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 0997a5ce7..2a3c64193 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.
#