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, common.wxgui_hb):
36 An decimator block with a number window display
49 number_rate=number_window.DEFAULT_NUMBER_RATE,
53 size=number_window.DEFAULT_WIN_SIZE,
56 **kwargs #catchall for backwards compatibility
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.controller = pubsub()
86 self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate)
87 self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate)
88 self.controller[AVERAGE_KEY] = average
89 self.controller[AVG_ALPHA_KEY] = avg_alpha
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)
94 self.controller.subscribe(AVERAGE_KEY, update_avg)
95 self.controller.subscribe(AVG_ALPHA_KEY, update_avg)
97 common.input_watcher(msgq, self.controller, MSG_KEY)
99 self.win = number_window.number_window(
101 controller=self.controller,
108 decimal_places=decimal_places,
109 show_gauge=show_gauge,
110 average_key=AVERAGE_KEY,
111 avg_alpha_key=AVG_ALPHA_KEY,
114 sample_rate_key=SAMPLE_RATE_KEY,
116 common.register_access_methods(self, self.controller)
117 #backwards compadibility
118 self.set_show_gauge = self.win.show_gauges
120 self.wxgui_connect(self, sd, mult, add, avg, sink)
122 class number_sink_f(_number_sink_base):
123 _item_size = gr.sizeof_float
126 class number_sink_c(_number_sink_base):
127 _item_size = gr.sizeof_gr_complex
130 # ----------------------------------------------------------------
131 # Standalone test app
132 # ----------------------------------------------------------------
135 from gnuradio.wxgui import stdgui2
137 class test_app_flow_graph (stdgui2.std_top_block):
138 def __init__(self, frame, panel, vbox, argv):
139 stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
141 # build our flow graph
144 # Generate a real and complex sinusoids
145 src1 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)
146 src2 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 2.21e3, 1)
148 # We add these throttle blocks so that this demo doesn't
149 # suck down all the CPU available. Normally you wouldn't use these.
150 thr1 = gr.throttle(gr.sizeof_float, input_rate)
151 thr2 = gr.throttle(gr.sizeof_gr_complex, input_rate)
153 sink1 = number_sink_f (panel, unit='V',label="Real Data", avg_alpha=0.001,
154 sample_rate=input_rate, minval=-1, maxval=1,
155 ref_level=0, decimal_places=3)
156 vbox.Add (sink1.win, 1, wx.EXPAND)
157 sink2 = number_sink_c (panel, unit='V',label="Complex Data", avg_alpha=0.001,
158 sample_rate=input_rate, minval=-1, maxval=1,
159 ref_level=0, decimal_places=3)
160 vbox.Add (sink2.win, 1, wx.EXPAND)
162 self.connect (src1, thr1, sink1)
163 self.connect (src2, thr2, sink2)
166 app = stdgui2.stdapp (test_app_flow_graph, "Number Sink Test App")
169 if __name__ == '__main__':