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
28 from pubsub import pubsub
29 from constants import *
31 ##################################################
32 # Scope sink block (wrapper for old wxgui)
33 ##################################################
34 class _scope_sink_base(gr.hier_block2, common.prop_setter):
36 A scope block with a gui window.
44 size=scope_window.DEFAULT_WIN_SIZE,
45 frame_decim=None, #ignore (old wrapper)
46 v_scale=scope_window.DEFAULT_V_SCALE,
51 frame_rate=scope_window.DEFAULT_FRAME_RATE,
53 if t_scale is None: t_scale = 0.001
55 gr.hier_block2.__init__(
58 gr.io_signature(num_inputs, num_inputs, self._item_size),
59 gr.io_signature(0, 0, 0),
62 msgq = gr.msg_queue(2)
63 scope = gr.oscope_sink_f(sample_rate, msgq)
66 for i in range(num_inputs):
67 self.connect((self, i), (scope, i))
69 for i in range(num_inputs):
70 c2f = gr.complex_to_float()
71 self.connect((self, i), c2f)
72 self.connect((c2f, 0), (scope, 2*i+0))
73 self.connect((c2f, 1), (scope, 2*i+1))
76 self.controller = pubsub()
77 self.controller.subscribe(SAMPLE_RATE_KEY, scope.set_sample_rate)
78 self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate)
79 def set_trigger_level(level):
80 if level == '': scope.set_trigger_level_auto()
81 else: scope.set_trigger_level(level)
82 self.controller.subscribe(SCOPE_TRIGGER_LEVEL_KEY, set_trigger_level)
83 def set_trigger_mode(mode):
84 if mode == 0: mode = gr.gr_TRIG_AUTO
85 elif mode < 0: mode = gr.gr_TRIG_NEG_SLOPE
86 elif mode > 0: mode = gr.gr_TRIG_POS_SLOPE
88 scope.set_trigger_mode(mode)
89 self.controller.subscribe(SCOPE_TRIGGER_MODE_KEY, set_trigger_mode)
90 self.controller.subscribe(SCOPE_TRIGGER_CHANNEL_KEY, scope.set_trigger_channel)
92 def setter(p, k, x): # lambdas can't have assignments :(
94 common.input_watcher(msgq, lambda x: setter(self.controller, MSG_KEY, x))
96 self.win = scope_window.scope_window(
98 controller=self.controller,
101 frame_rate=frame_rate,
102 num_inputs=num_inputs,
103 sample_rate_key=SAMPLE_RATE_KEY,
108 scope_trigger_level_key=SCOPE_TRIGGER_LEVEL_KEY,
109 scope_trigger_mode_key=SCOPE_TRIGGER_MODE_KEY,
110 scope_trigger_channel_key=SCOPE_TRIGGER_CHANNEL_KEY,
113 #register callbacks from window for external use
114 for attr in filter(lambda a: a.startswith('set_'), dir(self.win)):
115 setattr(self, attr, getattr(self.win, attr))
116 self._register_set_prop(self.controller, SAMPLE_RATE_KEY)
117 #backwards compadibility
118 self.win.set_format_line = lambda: setter(self.win, MARKER_KEY, None)
119 self.win.set_format_dot = lambda: setter(self.win, MARKER_KEY, 2.0)
120 self.win.set_format_plus = lambda: setter(self.win, MARKER_KEY, 3.0)
122 class scope_sink_f(_scope_sink_base):
123 _item_size = gr.sizeof_float
126 class scope_sink_c(_scope_sink_base):
127 _item_size = gr.sizeof_gr_complex
130 #backwards compadible wrapper (maybe only grc uses this)
131 class constellation_sink(scope_sink_c):
132 def __init__(self, **kwargs):
133 kwargs['xy_mode'] = True
134 scope_sink_c.__init__(self, **kwargs)
136 # ----------------------------------------------------------------
137 # Stand-alone test application
138 # ----------------------------------------------------------------
141 from gnuradio.wxgui import stdgui2
143 class test_top_block (stdgui2.std_top_block):
144 def __init__(self, frame, panel, vbox, argv):
145 stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
148 frame_decim = int(argv[1])
153 v_scale = float(argv[2]) # start up at this v_scale value
155 v_scale = None # start up in autorange mode, default
158 t_scale = float(argv[3]) # start up at this t_scale value
160 t_scale = .00003 # old behavior
162 print "frame decim %s v_scale %s t_scale %s" % (frame_decim,v_scale,t_scale)
166 # Generate a complex sinusoid
167 self.src0 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 25.1e3, 1e3)
169 # We add this throttle block so that this demo doesn't suck down
170 # all the CPU available. You normally wouldn't use it...
171 self.thr = gr.throttle(gr.sizeof_gr_complex, input_rate)
173 scope = scope_sink_c (panel,"Secret Data",sample_rate=input_rate,
174 frame_decim=frame_decim,
175 v_scale=v_scale, t_scale=t_scale)
176 vbox.Add (scope.win, 1, wx.EXPAND)
178 # Ultimately this will be
179 # self.connect("src0 throttle scope")
180 self.connect(self.src0, self.thr, scope)
183 app = stdgui2.stdapp (test_top_block, "O'Scope Test App")
186 if __name__ == '__main__':