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
#######################################################################################
29
#######################################################################################
30
class probe_function(gr.hier_block2, threading.Thread):
32
The thread polls the function for values and writes to a message source.
35
def __init__(self, probe_callback, probe_rate):
37
gr.hier_block2.__init__(
38
self, 'probe_function',
39
gr.io_signature(0, 0, 0),
40
gr.io_signature(1, 1, gr.sizeof_float),
42
self._probe_callback = probe_callback
43
self.set_probe_rate(probe_rate)
44
#create message source
45
message_source = gr.message_source(gr.sizeof_float, 1)
46
self._msgq = message_source.msgq()
48
self.connect(message_source, self)
50
threading.Thread.__init__(self)
56
Infinite polling loop.
59
time.sleep(1.0/self._probe_rate)
60
arr = numpy.array(self._probe_callback(), numpy.float32)
61
msg = gr.message_from_string(arr.tostring(), 0, gr.sizeof_float, 1)
62
self._msgq.insert_tail(msg)
64
def set_probe_rate(self, probe_rate):
65
self._probe_rate = probe_rate
67
class _probe_base(gr.hier_block2):
68
def __init__(self, probe_block, probe_callback, probe_rate):
70
gr.hier_block2.__init__(
72
gr.io_signature(1, 1, probe_block.input_signature().sizeof_stream_items()[0]),
73
gr.io_signature(1, 1, gr.sizeof_float),
75
probe_function_block = probe_function(probe_callback, probe_rate)
77
self.set_probe_rate = probe_function_block.set_probe_rate
79
self.connect(self, probe_block)
80
self.connect(probe_function_block, self)
82
#######################################################################################
83
## Probe: Average Magnitude Squared
84
#######################################################################################
85
class _probe_avg_mag_sqrd_base(_probe_base):
86
def __init__(self, threshold, alpha, probe_rate):
88
probe_block = self._probe_block_contructor[0](threshold, alpha)
90
self.set_alpha = probe_block.set_alpha
91
self.set_threshold = probe_block.set_threshold
93
_probe_base.__init__(self, probe_block, probe_block.level, probe_rate)
95
class probe_avg_mag_sqrd_c(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_c,)
96
class probe_avg_mag_sqrd_f(_probe_avg_mag_sqrd_base): _probe_block_contructor = (gr.probe_avg_mag_sqrd_f,)
98
#######################################################################################
100
#######################################################################################
101
class probe_density_b(_probe_base):
102
def __init__(self, alpha, probe_rate):
104
probe_block = gr.probe_density_b(alpha)
106
self.set_alpha = probe_block.set_alpha
108
_probe_base.__init__(self, probe_block, probe_block.density, probe_rate)
110
#######################################################################################
112
#######################################################################################
113
class probe_mpsk_snr_c(_probe_base):
114
def __init__(self, type, alpha, probe_rate):
116
Type can be "snr", "signal_mean", or "noise_variance"
119
probe_block = gr.probe_mpsk_snr_c(alpha)
121
self.set_alpha = probe_block.set_alpha
123
_probe_base.__init__(self, probe_block, getattr(probe_block, type), probe_rate)