Fix long standing hang when exiting due to blocking read in gr-pager.
[debian/gnuradio] / gr-pager / src / flex_demod.py
1 #
2 # Copyright 2006,2007 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 2, 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 from gnuradio import gr, gru, optfir, blks
23 from math import pi
24 import pager_swig
25
26 chan_rate = 16000
27
28 class flex_demod:
29     """
30     FLEX pager protocol demodulation block.
31
32     This block demodulates a band-limited, complex down-converted baseband 
33     channel into FLEX protocol frames.
34
35     Flow graph (so far):
36
37     RSAMP    - Resample incoming stream to 16000 sps
38     QUAD     - Quadrature demodulator converts FSK to baseband amplitudes  
39     LPF      - Low pass filter to remove noise prior to slicer
40     SLICER   - Converts input to one of four symbols (0, 1, 2, 3)
41     SYNC     - Converts symbol stream to four phases of FLEX blocks
42     DEINTx   - Deinterleaves FLEX blocks into datawords
43     PARSEx   - Parse a single FLEX phase worth of data words into pages
44     ---
45
46     @param fg: flowgraph
47     @param channel_rate:  incoming sample rate of the baseband channel
48     @type sample_rate: integer
49     """
50
51
52     def __init__(self, fg, channel_rate, queue):
53         k = chan_rate/(2*pi*4800)        # 4800 Hz max deviation
54         QUAD = gr.quadrature_demod_cf(k)
55         self.INPUT = QUAD
56                         
57         if channel_rate != chan_rate:
58                 interp = gru.lcm(channel_rate, chan_rate)/channel_rate
59                 decim  = gru.lcm(channel_rate, chan_rate)/chan_rate
60                 RESAMP = blks.rational_resampler_ccf(fg, interp, decim)
61                 self.INPUT = RESAMP
62                         
63         taps = optfir.low_pass(1.0, chan_rate, 3200, 6400, 0.1, 60)
64         LPF = gr.fir_filter_fff(1, taps)
65         SLICER = pager_swig.slicer_fb(.001, .00001) # Attack, decay
66         SYNC = pager_swig.flex_sync(chan_rate)
67
68         if channel_rate != chan_rate:
69             fg.connect(RESAMP, QUAD, LPF, SLICER, SYNC)
70         else:
71             fg.connect(QUAD, LPF, SLICER, SYNC)
72
73         DEINTA = pager_swig.flex_deinterleave()
74         PARSEA = pager_swig.flex_parse(queue)
75
76         DEINTB = pager_swig.flex_deinterleave()
77         PARSEB = pager_swig.flex_parse(queue)
78
79         DEINTC = pager_swig.flex_deinterleave()
80         PARSEC = pager_swig.flex_parse(queue)
81
82         DEINTD = pager_swig.flex_deinterleave()
83         PARSED = pager_swig.flex_parse(queue)
84         
85         fg.connect((SYNC, 0), DEINTA, PARSEA)
86         fg.connect((SYNC, 1), DEINTB, PARSEB)
87         fg.connect((SYNC, 2), DEINTC, PARSEC)
88         fg.connect((SYNC, 3), DEINTD, PARSED)