1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2011,2012 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_DIGITAL_OFDM_FRAME_SINK_IMPL_H
24 #define INCLUDED_DIGITAL_OFDM_FRAME_SINK_IMPL_H
25 
26 #include <gnuradio/digital/ofdm_frame_sink.h>
27 
28 namespace gr {
29 namespace digital {
30 
31 class ofdm_frame_sink_impl : public ofdm_frame_sink
32 {
33 private:
34     enum state_t { STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER };
35 
36     static const int MAX_PKT_LEN = 4096;
37     static const int HEADERBYTELEN = 4;
38 
39     msg_queue::sptr d_target_queue; // where to send the packet when received
40     state_t d_state;
41     unsigned int d_header;   // header bits
42     int d_headerbytelen_cnt; // how many so far
43 
44     char* d_bytes_out; // hold the current bytes produced by the demapper
45 
46     int d_occupied_carriers;
47     unsigned int d_byte_offset;
48     unsigned int d_partial_byte;
49 
50     char d_packet[MAX_PKT_LEN];   // assembled payload
51     int d_packetlen;              // length of packet
52     int d_packet_whitener_offset; // offset into whitener string to use
53     int d_packetlen_cnt;          // how many so far
54 
55     gr_complex*
56         d_derotated_output; // Pointer to output stream to send deroated symbols out
57 
58     std::vector<gr_complex> d_sym_position;
59     std::vector<char> d_sym_value_out;
60     std::vector<gr_complex> d_dfe;
61     unsigned int d_nbits;
62 
63     char d_resid;
64     unsigned int d_nresid;
65     float d_phase;
66     float d_freq;
67     float d_phase_gain;
68     float d_freq_gain;
69     float d_eq_gain;
70 
71     std::vector<int> d_subcarrier_map;
72 
73 protected:
74     void enter_search();
75     void enter_have_sync();
76     void enter_have_header();
77 
header_ok()78     bool header_ok()
79     {
80         // confirm that two copies of header info are identical
81         return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
82     }
83 
84     char slicer(const gr_complex x);
85     unsigned int demapper(const gr_complex* in, char* out);
86 
87     bool set_sym_value_out(const std::vector<gr_complex>& sym_position,
88                            const std::vector<char>& sym_value_out);
89 
90 public:
91     ofdm_frame_sink_impl(const std::vector<gr_complex>& sym_position,
92                          const std::vector<char>& sym_value_out,
93                          msg_queue::sptr target_queue,
94                          int occupied_tones,
95                          float phase_gain = 0.25,
96                          float freq_gain = 0.25 * 0.25 / 4);
97     ~ofdm_frame_sink_impl();
98 
99     int work(int noutput_items,
100              gr_vector_const_void_star& input_items,
101              gr_vector_void_star& output_items);
102 };
103 
104 } /* namespace digital */
105 } /* namespace gr */
106 
107 #endif /* INCLUDED_GR_OFDM_FRAME_SINK_IMPL_H */
108