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 ##################################################
24 ##################################################
27 from gnuradio import gr, blks2
28 from pubsub import pubsub
29 from constants import *
31 ##################################################
32 # Number sink block (wrapper for old wxgui)
33 ##################################################
34 class _number_sink_base(gr.hier_block2):
36 An decimator block with a number window display
43 base_value=None, #ignore (old wrapper)
50 number_rate=number_window.DEFAULT_NUMBER_RATE,
54 size=number_window.DEFAULT_WIN_SIZE,
59 if avg_alpha is None: avg_alpha = 2.0/number_rate
61 gr.hier_block2.__init__(
64 gr.io_signature(1, 1, self._item_size),
65 gr.io_signature(0, 0, 0),
68 sd = blks2.stream_to_vector_decimator(
69 item_size=self._item_size,
70 sample_rate=sample_rate,
75 mult = gr.multiply_const_ff(factor)
76 add = gr.add_const_ff(ref_level)
77 avg = gr.single_pole_iir_filter_ff(1.0)
79 mult = gr.multiply_const_cc(factor)
80 add = gr.add_const_cc(ref_level)
81 avg = gr.single_pole_iir_filter_cc(1.0)
82 msgq = gr.msg_queue(2)
83 sink = gr.message_sink(self._item_size, msgq, True)
85 self.connect(self, sd, mult, add, avg, sink)
87 self.controller = pubsub()
88 self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate)
89 self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate)
90 def update_avg(*args):
91 if self.controller[AVERAGE_KEY]: avg.set_taps(self.controller[AVG_ALPHA_KEY])
92 else: avg.set_taps(1.0)
93 self.controller.subscribe(AVERAGE_KEY, update_avg)
94 self.controller.subscribe(AVG_ALPHA_KEY, update_avg)
95 self.controller[AVERAGE_KEY] = average
96 self.controller[AVG_ALPHA_KEY] = avg_alpha
98 common.input_watcher(msgq, self.controller, MSG_KEY)
100 self.win = number_window.number_window(
102 controller=self.controller,
109 decimal_places=decimal_places,
110 show_gauge=show_gauge,
111 average_key=AVERAGE_KEY,
112 avg_alpha_key=AVG_ALPHA_KEY,
115 sample_rate_key=SAMPLE_RATE_KEY,
117 common.register_access_methods(self, self.controller)
118 #backwards compadibility
119 self.set_show_gauge = self.win.show_gauges
121 class number_sink_f(_number_sink_base):
122 _item_size = gr.sizeof_float
125 class number_sink_c(_number_sink_base):
126 _item_size = gr.sizeof_gr_complex
129 # ----------------------------------------------------------------
130 # Standalone test app
131 # ----------------------------------------------------------------
134 from gnuradio.wxgui import stdgui2
136 class test_app_flow_graph (stdgui2.std_top_block):
137 def __init__(self, frame, panel, vbox, argv):
138 stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
140 # build our flow graph
143 # Generate a real and complex sinusoids
144 src1 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)
145 src2 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)
147 # We add these throttle blocks so that this demo doesn't
148 # suck down all the CPU available. Normally you wouldn't use these.
149 thr1 = gr.throttle(gr.sizeof_float, input_rate)
150 thr2 = gr.throttle(gr.sizeof_gr_complex, input_rate)
152 sink1 = number_sink_f (panel, unit='V',label="Real Data", avg_alpha=0.001,
153 sample_rate=input_rate, minval=-1, maxval=1,
154 ref_level=0, decimal_places=3)
155 vbox.Add (sink1.win, 1, wx.EXPAND)
156 sink2 = number_sink_c (panel, unit='V',label="Complex Data", avg_alpha=0.001,
157 sample_rate=input_rate, minval=-1, maxval=1,
158 ref_level=0, decimal_places=3)
159 vbox.Add (sink2.win, 1, wx.EXPAND)
161 self.connect (src1, thr1, sink1)
162 self.connect (src2, thr2, sink2)
165 app = stdgui2.stdapp (test_app_flow_graph, "Number Sink Test App")
168 if __name__ == '__main__':