GNU Radio 3.5.3.2 C++ API
|
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_DIGITAL_OFDM_FRAME_SINK_H 00024 #define INCLUDED_DIGITAL_OFDM_FRAME_SINK_H 00025 00026 #include <digital_api.h> 00027 #include <gr_sync_block.h> 00028 #include <gr_msg_queue.h> 00029 00030 class digital_ofdm_frame_sink; 00031 typedef boost::shared_ptr<digital_ofdm_frame_sink> digital_ofdm_frame_sink_sptr; 00032 00033 DIGITAL_API digital_ofdm_frame_sink_sptr 00034 digital_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 00035 const std::vector<unsigned char> &sym_value_out, 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 DIGITAL_API digital_ofdm_frame_sink : public gr_sync_block 00050 { 00051 friend DIGITAL_API digital_ofdm_frame_sink_sptr 00052 digital_make_ofdm_frame_sink (const std::vector<gr_complex> &sym_position, 00053 const std::vector<unsigned char> &sym_value_out, 00054 gr_msg_queue_sptr target_queue, unsigned int occupied_tones, 00055 float phase_gain, float freq_gain); 00056 00057 private: 00058 enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER}; 00059 00060 static const int MAX_PKT_LEN = 4096; 00061 static const int HEADERBYTELEN = 4; 00062 00063 gr_msg_queue_sptr d_target_queue; // where to send the packet when received 00064 state_t d_state; 00065 unsigned int d_header; // header bits 00066 int d_headerbytelen_cnt; // how many so far 00067 00068 unsigned char *d_bytes_out; // hold the current bytes produced by the demapper 00069 00070 unsigned int d_occupied_carriers; 00071 unsigned int d_byte_offset; 00072 unsigned int d_partial_byte; 00073 00074 unsigned char d_packet[MAX_PKT_LEN]; // assembled payload 00075 int d_packetlen; // length of packet 00076 int d_packet_whitener_offset; // offset into whitener string to use 00077 int d_packetlen_cnt; // how many so far 00078 00079 gr_complex * d_derotated_output; // Pointer to output stream to send deroated symbols out 00080 00081 std::vector<gr_complex> d_sym_position; 00082 std::vector<unsigned char> d_sym_value_out; 00083 std::vector<gr_complex> d_dfe; 00084 unsigned int d_nbits; 00085 00086 unsigned char d_resid; 00087 unsigned int d_nresid; 00088 float d_phase; 00089 float d_freq; 00090 float d_phase_gain; 00091 float d_freq_gain; 00092 float d_eq_gain; 00093 00094 std::vector<int> d_subcarrier_map; 00095 00096 protected: 00097 digital_ofdm_frame_sink(const std::vector<gr_complex> &sym_position, 00098 const std::vector<unsigned char> &sym_value_out, 00099 gr_msg_queue_sptr target_queue, unsigned int occupied_tones, 00100 float phase_gain, float freq_gain); 00101 00102 void enter_search(); 00103 void enter_have_sync(); 00104 void enter_have_header(); 00105 00106 bool header_ok() 00107 { 00108 // confirm that two copies of header info are identical 00109 return ((d_header >> 16) ^ (d_header & 0xffff)) == 0; 00110 } 00111 00112 unsigned char slicer(const gr_complex x); 00113 unsigned int demapper(const gr_complex *in, 00114 unsigned char *out); 00115 00116 bool set_sym_value_out(const std::vector<gr_complex> &sym_position, 00117 const std::vector<unsigned char> &sym_value_out); 00118 00119 public: 00120 ~digital_ofdm_frame_sink(); 00121 00122 int work(int noutput_items, 00123 gr_vector_const_void_star &input_items, 00124 gr_vector_void_star &output_items); 00125 }; 00126 00127 #endif /* INCLUDED_GR_OFDM_FRAME_SINK_H */