]> git.gag.com Git - debian/gnuradio/blob - gnuradio-core/src/lib/general/gr_ofdm_frame_sink.h
f1c9b76feae50e727fbaf1fba17f8baabeb59313
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_ofdm_frame_sink.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_GR_OFDM_FRAME_SINK_H
24 #define INCLUDED_GR_OFDM_FRAME_SINK_H
25
26 #include <gr_sync_block.h>
27 #include <gr_msg_queue.h>
28
29 class gr_ofdm_frame_sink;
30 typedef boost::shared_ptr<gr_ofdm_frame_sink> gr_ofdm_frame_sink_sptr;
31
32 gr_ofdm_frame_sink_sptr 
33 gr_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 
34                          const std::vector<unsigned char> &sym_value_out,
35                          gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
36
37 /*!
38  * \brief Takes an OFDM symbol in, demaps it into bits of 0's and 1's, packs
39  * them into packets, and sends to to a message queue sink.
40
41  * NOTE: The mod input parameter simply chooses a pre-defined demapper/slicer. Eventually,
42  * we want to be able to pass in a reference to an object to do the demapping and slicing
43  * for a given modulation type.
44  */
45 class gr_ofdm_frame_sink : public gr_sync_block
46 {
47   friend gr_ofdm_frame_sink_sptr 
48   gr_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 
49                            const std::vector<unsigned char> &sym_value_out,
50                            gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
51
52  private:
53   enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
54
55   static const int MAX_PKT_LEN    = 4096;
56   static const int HEADERBYTELEN   = 4;
57
58   gr_msg_queue_sptr  d_target_queue;            // where to send the packet when received
59   state_t            d_state;
60   unsigned int       d_header;                  // header bits
61   int                d_headerbytelen_cnt;       // how many so far
62
63   unsigned char      *d_bytes_out;              // hold the current bytes produced by the demapper    
64
65   unsigned int       d_occupied_carriers;
66   unsigned int       d_byte_offset;
67   unsigned int       d_partial_byte;
68
69   unsigned char      d_packet[MAX_PKT_LEN];     // assembled payload
70   int                d_packetlen;               // length of packet
71   int                d_packet_whitener_offset;  // offset into whitener string to use
72   int                d_packetlen_cnt;           // how many so far
73
74   std::vector<gr_complex>    d_sym_position;
75   std::vector<unsigned char> d_sym_value_out;
76   unsigned int d_nbits;
77
78   unsigned char d_resid;
79   unsigned int d_nresid;
80
81  protected:
82   gr_ofdm_frame_sink(const std::vector<gr_complex> &sym_position, 
83                      const std::vector<unsigned char> &sym_value_out,
84                      gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
85
86   void enter_search();
87   void enter_have_sync();
88   void enter_have_header();
89   
90   bool header_ok()
91   {
92     // confirm that two copies of header info are identical
93     return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
94   }
95   
96   unsigned char slicer(const gr_complex x);
97   unsigned int demapper(const gr_complex *in,
98                         unsigned char *out);
99
100   bool set_sym_value_out(const std::vector<gr_complex> &sym_position, 
101                          const std::vector<unsigned char> &sym_value_out);
102
103  public:
104   ~gr_ofdm_frame_sink();
105
106   int work(int noutput_items,
107            gr_vector_const_void_star &input_items,
108            gr_vector_void_star &output_items);
109 };
110
111 #endif /* INCLUDED_GR_OFDM_FRAME_SINK_H */