Added gr-pager component to trunk by merging from r3474:r3537 in
[debian/gnuradio] / gr-pager / src / pager_flex_deframer.h
1 /*
2  * Copyright 2006 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 #ifndef INCLUDED_PAGER_FLEX_DEFRAMER_H
23 #define INCLUDED_PAGER_FLEX_DEFRAMER_H
24
25 #include <gr_block.h>
26
27 class pager_flex_deframer;
28 typedef boost::shared_ptr<pager_flex_deframer> pager_flex_deframer_sptr;
29 typedef std::vector<gr_int64> gr_int64_vector;
30
31 pager_flex_deframer_sptr pgr_make_flex_deframer(int rate);
32
33 /*!
34  * \brief flex deframer description
35  * \ingroup block
36  */
37
38 class pager_flex_deframer : public gr_block
39 {
40 private:
41     // Constructors
42     friend pager_flex_deframer_sptr pager_make_flex_deframer(int rate);
43     pager_flex_deframer(int rate);
44    
45     // State machine transitions
46     void enter_idle();
47     void enter_syncing();
48     void enter_sync1();
49     void enter_sync2();
50     void enter_data();
51     void enter_output();
52
53     int index_avg(int start, int end);
54     bool test_sync(unsigned char sym);
55     void accumulate_frames(unsigned char sym);
56     void output_codeword(gr_int32 *out);
57     
58     // Simple state machine
59     enum state_t { ST_IDLE, ST_SYNCING, ST_SYNC1, ST_SYNC2, ST_DATA, ST_OUTPUT };
60     state_t d_state;     
61
62     int d_rate;     // Incoming sample rate
63     int d_index;    // Index into current baud
64     int d_start;    // Start of good sync 
65     int d_center;   // Center of bit
66     int d_end;      // End of good sync
67     int d_count;    // Bit counter
68
69     int d_mode;     // Current packet mode
70     int d_baudrate; // Current decoding baud rate
71     int d_levels;   // Current decoding levels
72     int d_spb;      // Current samples per baud
73     bool d_hibit;   // Current bit is high bit when 3200 baud
74
75     gr_int64_vector d_sync; // Trial synchronizers
76
77     int d_cdi;      // 0-7 code word index for deinterleave
78     int d_cdw;      // 0-87 code word index for frame
79     int d_blk;      // 0-10 block index
80
81     int d_output_phase; // Indexes d_frames[][] during output
82     int d_output_index; // indexes d_frames[][] during output
83
84     gr_int32 d_frames[4][88]; // Frame accumulators for each phase
85
86 public:
87     void forecast(int noutput_items, gr_vector_int &inputs_required);
88
89     int general_work(int noutput_items,
90                      gr_vector_int &ninput_items,
91                      gr_vector_const_void_star &input_items, 
92                      gr_vector_void_star &output_items);
93 };
94
95 #endif /* INCLUDED_PAGER_FLEX_DEFRAMER_H */