GNU Radio 3.4.2 C++ API
gr_ofdm_frame_sink.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_OFDM_FRAME_SINK_H
00024 #define INCLUDED_GR_OFDM_FRAME_SINK_H
00025 
00026 #include <gr_sync_block.h>
00027 #include <gr_msg_queue.h>
00028 
00029 class gr_ofdm_frame_sink;
00030 typedef boost::shared_ptr<gr_ofdm_frame_sink> gr_ofdm_frame_sink_sptr;
00031 
00032 gr_ofdm_frame_sink_sptr 
00033 gr_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 
00034                          const std::vector<unsigned char> &sym_value_out,
00035                          gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00036                          float phase_gain=0.25, float freq_gain=0.25*0.25/4.0);
00037 
00038 /*!
00039  * \brief Takes an OFDM symbol in, demaps it into bits of 0's and 1's, packs
00040  * them into packets, and sends to to a message queue sink.
00041  * \ingroup sink_blk
00042  * \ingroup ofdm_blk
00043  *
00044  * NOTE: The mod input parameter simply chooses a pre-defined demapper/slicer. Eventually,
00045  * we want to be able to pass in a reference to an object to do the demapping and slicing
00046  * for a given modulation type.
00047  */
00048 class gr_ofdm_frame_sink : public gr_sync_block
00049 {
00050   friend gr_ofdm_frame_sink_sptr 
00051   gr_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 
00052                            const std::vector<unsigned char> &sym_value_out,
00053                            gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00054                            float phase_gain, float freq_gain);
00055 
00056  private:
00057   enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
00058 
00059   static const int MAX_PKT_LEN    = 4096;
00060   static const int HEADERBYTELEN   = 4;
00061 
00062   gr_msg_queue_sptr  d_target_queue;            // where to send the packet when received
00063   state_t            d_state;
00064   unsigned int       d_header;                  // header bits
00065   int                d_headerbytelen_cnt;       // how many so far
00066 
00067   unsigned char      *d_bytes_out;              // hold the current bytes produced by the demapper    
00068 
00069   unsigned int       d_occupied_carriers;
00070   unsigned int       d_byte_offset;
00071   unsigned int       d_partial_byte;
00072 
00073   unsigned char      d_packet[MAX_PKT_LEN];     // assembled payload
00074   int                d_packetlen;               // length of packet
00075   int                d_packet_whitener_offset;  // offset into whitener string to use
00076   int                d_packetlen_cnt;           // how many so far
00077 
00078   gr_complex * d_derotated_output;  // Pointer to output stream to send deroated symbols out
00079 
00080   std::vector<gr_complex>    d_sym_position;
00081   std::vector<unsigned char> d_sym_value_out;
00082   std::vector<gr_complex>    d_dfe;
00083   unsigned int d_nbits;
00084 
00085   unsigned char d_resid;
00086   unsigned int d_nresid;
00087   float d_phase;
00088   float d_freq;
00089   float d_phase_gain;
00090   float d_freq_gain;
00091   float d_eq_gain;
00092 
00093   std::vector<int> d_subcarrier_map;
00094 
00095  protected:
00096   gr_ofdm_frame_sink(const std::vector<gr_complex> &sym_position, 
00097                      const std::vector<unsigned char> &sym_value_out,
00098                      gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00099                      float phase_gain, float freq_gain);
00100 
00101   void enter_search();
00102   void enter_have_sync();
00103   void enter_have_header();
00104   
00105   bool header_ok()
00106   {
00107     // confirm that two copies of header info are identical
00108     return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
00109   }
00110   
00111   unsigned char slicer(const gr_complex x);
00112   unsigned int demapper(const gr_complex *in,
00113                         unsigned char *out);
00114 
00115   bool set_sym_value_out(const std::vector<gr_complex> &sym_position, 
00116                          const std::vector<unsigned char> &sym_value_out);
00117 
00118  public:
00119   ~gr_ofdm_frame_sink();
00120 
00121   int work(int noutput_items,
00122            gr_vector_const_void_star &input_items,
00123            gr_vector_void_star &output_items);
00124 };
00125 
00126 #endif /* INCLUDED_GR_OFDM_FRAME_SINK_H */