Imported Upstream version 3.2.2
[debian/gnuradio] / gr-wxgui / src / python / constsink_gl.py
1 #
2 # Copyright 2008 Free Software Foundation, Inc.
3 #
4 # This file is part of GNU Radio
5 #
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)
9 # any later version.
10 #
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.
15 #
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.
20 #
21
22 ##################################################
23 # Imports
24 ##################################################
25 import const_window
26 import common
27 from gnuradio import gr, blks2
28 from pubsub import pubsub
29 from constants import *
30
31 ##################################################
32 # Constellation sink block (wrapper for old wxgui)
33 ##################################################
34 class const_sink_c(gr.hier_block2):
35         """
36         A constellation block with a gui window.
37         """
38
39         def __init__(
40                 self,
41                 parent,
42                 title='',
43                 sample_rate=1,
44                 size=const_window.DEFAULT_WIN_SIZE,
45                 frame_rate=const_window.DEFAULT_FRAME_RATE,
46                 const_size=const_window.DEFAULT_CONST_SIZE,
47                 #mpsk recv params
48                 M=4,
49                 theta=0,
50                 alpha=0.005,
51                 fmax=0.06,
52                 mu=0.5,
53                 gain_mu=0.005,
54                 symbol_rate=1,
55                 omega_limit=0.005,
56         ):
57                 #init
58                 gr.hier_block2.__init__(
59                         self,
60                         "const_sink",
61                         gr.io_signature(1, 1, gr.sizeof_gr_complex),
62                         gr.io_signature(0, 0, 0),
63                 )
64                 #blocks
65                 sd = blks2.stream_to_vector_decimator(
66                         item_size=gr.sizeof_gr_complex,
67                         sample_rate=sample_rate,
68                         vec_rate=frame_rate,
69                         vec_len=const_size,
70                 )
71                 beta = .25*alpha**2 #redundant, will be updated
72                 fmin = -fmax
73                 gain_omega = .25*gain_mu**2 #redundant, will be updated
74                 omega = 1 #set_sample_rate will update this
75                 # Costas frequency/phase recovery loop
76                 # Critically damped 2nd order PLL
77                 self._costas = gr.costas_loop_cc(alpha, beta, fmax, fmin, M)
78                 # Timing recovery loop
79                 # Critically damped 2nd order DLL
80                 self._retime = gr.clock_recovery_mm_cc(omega, gain_omega, mu, gain_mu, omega_limit)
81                 #sync = gr.mpsk_receiver_cc(
82                 #       M, #psk order
83                 #       theta,
84                 #       alpha,
85                 #       beta,
86                 #       fmin,
87                 #       fmax,
88                 #       mu,
89                 #       gain_mu,
90                 #       omega,
91                 #       gain_omega,
92                 #       omega_limit,
93                 #)
94                 agc = gr.feedforward_agc_cc(16, 1)
95                 msgq = gr.msg_queue(2)
96                 sink = gr.message_sink(gr.sizeof_gr_complex*const_size, msgq, True)
97                 #connect
98                 self.connect(self, self._costas, self._retime, agc, sd, sink)
99                 #controller
100                 def setter(p, k, x): p[k] = x
101                 self.controller = pubsub()
102                 self.controller.subscribe(ALPHA_KEY, self._costas.set_alpha)
103                 self.controller.publish(ALPHA_KEY, self._costas.alpha)
104                 self.controller.subscribe(BETA_KEY, self._costas.set_beta)
105                 self.controller.publish(BETA_KEY, self._costas.beta)
106                 self.controller.subscribe(GAIN_MU_KEY, self._retime.set_gain_mu)
107                 self.controller.publish(GAIN_MU_KEY, self._retime.gain_mu)
108                 self.controller.subscribe(OMEGA_KEY, self._retime.set_omega)
109                 self.controller.publish(OMEGA_KEY, self._retime.omega)
110                 self.controller.subscribe(GAIN_OMEGA_KEY, self._retime.set_gain_omega)
111                 self.controller.publish(GAIN_OMEGA_KEY, self._retime.gain_omega)
112                 self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate)
113                 self.controller.subscribe(SAMPLE_RATE_KEY, lambda x: setter(self.controller, OMEGA_KEY, float(x)/symbol_rate))
114                 self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate)
115                 #initial update
116                 self.controller[SAMPLE_RATE_KEY] = sample_rate
117                 #start input watcher
118                 common.input_watcher(msgq, self.controller, MSG_KEY)
119                 #create window
120                 self.win = const_window.const_window(
121                         parent=parent,
122                         controller=self.controller,
123                         size=size,
124                         title=title,
125                         msg_key=MSG_KEY,
126                         alpha_key=ALPHA_KEY,
127                         beta_key=BETA_KEY,
128                         gain_mu_key=GAIN_MU_KEY,
129                         gain_omega_key=GAIN_OMEGA_KEY,
130                         omega_key=OMEGA_KEY,
131                         sample_rate_key=SAMPLE_RATE_KEY,
132                 )
133                 common.register_access_methods(self, self.win)
134
135