GNU Radio 3.5.1 C++ API
gr_ofdm_frame_sink2.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2007,2011 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_SINK2_H
00024 #define INCLUDED_GR_OFDM_FRAME_SINK2_H
00025 
00026 #include <gr_core_api.h>
00027 #include <gr_sync_block.h>
00028 #include <gr_msg_queue.h>
00029 #include <gr_constellation.h>
00030 
00031 class gr_ofdm_frame_sink2;
00032 typedef boost::shared_ptr<gr_ofdm_frame_sink2> gr_ofdm_frame_sink2_sptr;
00033 
00034 GR_CORE_API gr_ofdm_frame_sink2_sptr 
00035 gr_make_ofdm_frame_sink2 (gr_constellation_sptr constell,
00036                          gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00037                          float phase_gain=0.25, float freq_gain=0.25*0.25/4.0);
00038 
00039 /*!
00040  * \brief Takes an OFDM symbol in, demaps it into bits of 0's and 1's, packs
00041  * them into packets, and sends to to a message queue sink.
00042  * \ingroup sink_blk
00043  * \ingroup ofdm_blk
00044  *
00045  * NOTE: The mod input parameter simply chooses a pre-defined demapper/slicer. Eventually,
00046  * we want to be able to pass in a reference to an object to do the demapping and slicing
00047  * for a given modulation type.
00048  */
00049 class GR_CORE_API gr_ofdm_frame_sink2 : public gr_sync_block
00050 {
00051   friend GR_CORE_API gr_ofdm_frame_sink2_sptr 
00052   gr_make_ofdm_frame_sink2 (gr_constellation_sptr constell, 
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   gr_constellation_sptr      d_constell;
00081   std::vector<gr_complex>    d_dfe;
00082   unsigned int d_nbits;
00083 
00084   unsigned char d_resid;
00085   unsigned int d_nresid;
00086   float d_phase;
00087   float d_freq;
00088   float d_phase_gain;
00089   float d_freq_gain;
00090   float d_eq_gain;
00091 
00092   std::vector<int> d_subcarrier_map;
00093 
00094  protected:
00095   gr_ofdm_frame_sink2(gr_constellation_sptr constell,
00096                      gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00097                      float phase_gain, float freq_gain);
00098 
00099   void enter_search();
00100   void enter_have_sync();
00101   void enter_have_header();
00102   
00103   bool header_ok()
00104   {
00105     // confirm that two copies of header info are identical
00106     return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
00107   }
00108   
00109   unsigned char slicer(const gr_complex x);
00110   unsigned int demapper(const gr_complex *in,
00111                         unsigned char *out);
00112 
00113  public:
00114   ~gr_ofdm_frame_sink2();
00115 
00116   int work(int noutput_items,
00117            gr_vector_const_void_star &input_items,
00118            gr_vector_void_star &output_items);
00119 };
00120 
00121 #endif /* INCLUDED_GR_OFDM_FRAME_SINK2_H */