2 # Copyright 2008 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
22 from gnuradio import gr
27 class _probe_base(gr.hier_block2, threading.Thread):
29 A hier2 block with float output and probe input.
30 The thread polls the prope for values and writes to a message source.
33 def __init__(self, probe_block, probe_callback, probe_rate):
35 gr.hier_block2.__init__(
37 gr.io_signature(1, 1, probe_block.input_signature().sizeof_stream_items()[0]),
38 gr.io_signature(1, 1, gr.sizeof_float),
40 self._probe_callback = probe_callback
41 self.set_probe_rate(probe_rate)
42 #create message source
43 message_source = gr.message_source(gr.sizeof_float, 1)
44 self._msgq = message_source.msgq()
46 self.connect(self, probe_block)
47 self.connect(message_source, self)
49 threading.Thread.__init__(self)
55 Infinite polling loop.
58 time.sleep(1.0/self._probe_rate)
59 arr = numpy.array(self._probe_callback(), numpy.float32)
60 msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1)
61 self._msgq.insert_tail(msg)
63 def set_probe_rate(self, probe_rate):
64 self._probe_rate = probe_rate
66 #######################################################################################
67 ## Probe: Average Magnitude Squared
68 #######################################################################################
69 class _probe_avg_mag_sqrd_base(_probe_base):
70 def __init__(self, threshold, alpha, probe_rate):
72 probe_block = self._probe_block_contructor[0](threshold, alpha)
74 self.set_alpha = probe_block.set_alpha
75 self.set_threshold = probe_block.set_threshold
77 _probe_base.__init__(self, probe_block, probe_block.level, probe_rate)
79 class probe_avg_mag_sqrd_c(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_c,)
80 class probe_avg_mag_sqrd_f(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_f,)
82 #######################################################################################
84 #######################################################################################
85 class probe_density_b(_probe_base):
86 def __init__(self, alpha, probe_rate):
88 probe_block = gr.probe_density_b(alpha)
90 self.set_alpha = probe_block.set_alpha
92 _probe_base.__init__(self, probe_block, probe_block.density, probe_rate)
94 #######################################################################################
96 #######################################################################################
97 class probe_mpsk_snr_c(_probe_base):
98 def __init__(self, type, alpha, probe_rate):
100 Type can be "snr", "signal_mean", or "noise_variance"
103 probe_block = gr.probe_mpsk_snr_c(alpha)
105 self.set_alpha = probe_block.set_alpha
107 _probe_base.__init__(self, probe_block, getattr(probe_block, type), probe_rate)