3 * Copyright 2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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 2, or (at your option)
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <gr_ofdm_insert_preamble.h>
27 #include <gr_io_signature.h>
31 gr_ofdm_insert_preamble_sptr
32 gr_make_ofdm_insert_preamble(int fft_length,
33 const std::vector<std::vector<gr_complex> > &preamble)
35 return gr_ofdm_insert_preamble_sptr(new gr_ofdm_insert_preamble(fft_length,
39 gr_ofdm_insert_preamble::gr_ofdm_insert_preamble
41 const std::vector<std::vector<gr_complex> > &preamble)
42 : gr_block("ofdm_insert_preamble",
43 gr_make_io_signature2(2, 2,
44 sizeof(gr_complex)*fft_length,
46 gr_make_io_signature2(1, 2,
47 sizeof(gr_complex)*fft_length,
49 d_fft_length(fft_length),
55 // sanity check preamble symbols
56 for (size_t i = 0; i < d_preamble.size(); i++){
57 if (d_preamble[i].size() != (size_t) d_fft_length)
58 throw std::invalid_argument("gr_ofdm_insert_preamble: invalid length for preamble symbol");
65 gr_ofdm_insert_preamble::~gr_ofdm_insert_preamble()
70 gr_ofdm_insert_preamble::general_work (int noutput_items,
71 gr_vector_int &ninput_items_v,
72 gr_vector_const_void_star &input_items,
73 gr_vector_void_star &output_items)
75 int ninput_items = std::min(ninput_items_v[0], ninput_items_v[1]);
76 const gr_complex *in_sym = (const gr_complex *) input_items[0];
77 const unsigned char *in_flag = (const unsigned char *) input_items[1];
79 gr_complex *out_sym = (gr_complex *) output_items[0];
80 unsigned char *out_flag = 0;
81 if (output_items.size() == 2)
82 out_flag = (unsigned char *) output_items[1];
85 int no = 0; // number items output
86 int ni = 0; // number items read from input
89 #define write_out_flag() \
91 out_flag[no] = d_pending_flag; \
96 while (no < noutput_items && ni < ninput_items){
99 if (in_flag[ni] & 0x1) // this is first symbol of new payload
102 ni++; // eat one input symbol
106 assert(in_flag[ni] & 0x1);
107 if (d_nsymbols_output >= (int) d_preamble.size()){
108 // we've output all the preamble
109 enter_first_payload();
112 memcpy(&out_sym[no * d_fft_length],
113 &d_preamble[d_nsymbols_output][0],
114 d_fft_length*sizeof(gr_complex));
122 case ST_FIRST_PAYLOAD:
123 // copy first payload symbol from input to output
124 memcpy(&out_sym[no * d_fft_length],
125 &in_sym[ni * d_fft_length],
126 d_fft_length * sizeof(gr_complex));
135 if (in_flag[ni] & 0x1){ // this is first symbol of a new payload
140 // copy a symbol from input to output
141 memcpy(&out_sym[no * d_fft_length],
142 &in_sym[ni * d_fft_length],
143 d_fft_length * sizeof(gr_complex));
151 std::cerr << "gr_ofdm_insert_preamble: (can't happen) invalid state, resetting\n";
161 gr_ofdm_insert_preamble::enter_idle()
164 d_nsymbols_output = 0;
169 gr_ofdm_insert_preamble::enter_preamble()
171 d_state = ST_PREAMBLE;
172 d_nsymbols_output = 0;
177 gr_ofdm_insert_preamble::enter_first_payload()
179 d_state = ST_FIRST_PAYLOAD;
183 gr_ofdm_insert_preamble::enter_payload()
185 d_state = ST_PAYLOAD;