GNU Radio 3.6.5 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  *
00043  * NOTE: The mod input parameter simply chooses a pre-defined demapper/slicer. Eventually,
00044  * we want to be able to pass in a reference to an object to do the demapping and slicing
00045  * for a given modulation type.
00046  */
00047 class GR_CORE_API gr_ofdm_frame_sink2 : public gr_sync_block
00048 {
00049   friend GR_CORE_API gr_ofdm_frame_sink2_sptr
00050   gr_make_ofdm_frame_sink2 (gr_constellation_sptr constell,
00051                            gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00052                            float phase_gain, float freq_gain);
00053 
00054  private:
00055   enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
00056 
00057   static const int MAX_PKT_LEN    = 4096;
00058   static const int HEADERBYTELEN   = 4;
00059 
00060   gr_msg_queue_sptr  d_target_queue;            // where to send the packet when received
00061   state_t            d_state;
00062   unsigned int       d_header;                  // header bits
00063   int                d_headerbytelen_cnt;       // how many so far
00064 
00065   unsigned char      *d_bytes_out;              // hold the current bytes produced by the demapper
00066 
00067   unsigned int       d_occupied_carriers;
00068   unsigned int       d_byte_offset;
00069   unsigned int       d_partial_byte;
00070 
00071   unsigned char      d_packet[MAX_PKT_LEN];     // assembled payload
00072   int                d_packetlen;               // length of packet
00073   int                d_packet_whitener_offset;  // offset into whitener string to use
00074   int                d_packetlen_cnt;           // how many so far
00075 
00076   gr_complex * d_derotated_output;  // Pointer to output stream to send deroated symbols out
00077 
00078   gr_constellation_sptr      d_constell;
00079   std::vector<gr_complex>    d_dfe;
00080   unsigned int d_nbits;
00081 
00082   unsigned char d_resid;
00083   unsigned int d_nresid;
00084   float d_phase;
00085   float d_freq;
00086   float d_phase_gain;
00087   float d_freq_gain;
00088   float d_eq_gain;
00089 
00090   std::vector<int> d_subcarrier_map;
00091 
00092  protected:
00093   gr_ofdm_frame_sink2(gr_constellation_sptr constell,
00094                      gr_msg_queue_sptr target_queue, unsigned int occupied_tones,
00095                      float phase_gain, float freq_gain);
00096 
00097   void enter_search();
00098   void enter_have_sync();
00099   void enter_have_header();
00100 
00101   bool header_ok()
00102   {
00103     // confirm that two copies of header info are identical
00104     return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
00105   }
00106 
00107   unsigned char slicer(const gr_complex x);
00108   unsigned int demapper(const gr_complex *in,
00109                         unsigned char *out);
00110 
00111  public:
00112   ~gr_ofdm_frame_sink2();
00113 
00114   int work(int noutput_items,
00115            gr_vector_const_void_star &input_items,
00116            gr_vector_void_star &output_items);
00117 };
00118 
00119 #endif /* INCLUDED_GR_OFDM_FRAME_SINK2_H */