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 3, 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>
32
gr_ofdm_insert_preamble_sptr
33
gr_make_ofdm_insert_preamble(int fft_length,
34
const std::vector<std::vector<gr_complex> > &preamble)
36
return gr_ofdm_insert_preamble_sptr(new gr_ofdm_insert_preamble(fft_length,
40
gr_ofdm_insert_preamble::gr_ofdm_insert_preamble
42
const std::vector<std::vector<gr_complex> > &preamble)
43
: gr_block("ofdm_insert_preamble",
44
gr_make_io_signature2(2, 2,
45
sizeof(gr_complex)*fft_length,
47
gr_make_io_signature2(1, 2,
48
sizeof(gr_complex)*fft_length,
50
d_fft_length(fft_length),
56
// sanity check preamble symbols
57
for (size_t i = 0; i < d_preamble.size(); i++){
58
if (d_preamble[i].size() != (size_t) d_fft_length)
59
throw std::invalid_argument("gr_ofdm_insert_preamble: invalid length for preamble symbol");
66
gr_ofdm_insert_preamble::~gr_ofdm_insert_preamble()
71
gr_ofdm_insert_preamble::general_work (int noutput_items,
72
gr_vector_int &ninput_items_v,
73
gr_vector_const_void_star &input_items,
74
gr_vector_void_star &output_items)
76
int ninput_items = std::min(ninput_items_v[0], ninput_items_v[1]);
77
const gr_complex *in_sym = (const gr_complex *) input_items[0];
78
const unsigned char *in_flag = (const unsigned char *) input_items[1];
80
gr_complex *out_sym = (gr_complex *) output_items[0];
81
unsigned char *out_flag = 0;
82
if (output_items.size() == 2)
83
out_flag = (unsigned char *) output_items[1];
86
int no = 0; // number items output
87
int ni = 0; // number items read from input
90
#define write_out_flag() \
92
out_flag[no] = d_pending_flag; \
97
while (no < noutput_items && ni < ninput_items){
100
if (in_flag[ni] & 0x1) // this is first symbol of new payload
103
ni++; // eat one input symbol
107
assert(in_flag[ni] & 0x1);
108
if (d_nsymbols_output >= (int) d_preamble.size()){
109
// we've output all the preamble
110
enter_first_payload();
113
memcpy(&out_sym[no * d_fft_length],
114
&d_preamble[d_nsymbols_output][0],
115
d_fft_length*sizeof(gr_complex));
123
case ST_FIRST_PAYLOAD:
124
// copy first payload symbol from input to output
125
memcpy(&out_sym[no * d_fft_length],
126
&in_sym[ni * d_fft_length],
127
d_fft_length * sizeof(gr_complex));
136
if (in_flag[ni] & 0x1){ // this is first symbol of a new payload
141
// copy a symbol from input to output
142
memcpy(&out_sym[no * d_fft_length],
143
&in_sym[ni * d_fft_length],
144
d_fft_length * sizeof(gr_complex));
152
std::cerr << "gr_ofdm_insert_preamble: (can't happen) invalid state, resetting\n";
162
gr_ofdm_insert_preamble::enter_idle()
165
d_nsymbols_output = 0;
170
gr_ofdm_insert_preamble::enter_preamble()
172
d_state = ST_PREAMBLE;
173
d_nsymbols_output = 0;
178
gr_ofdm_insert_preamble::enter_first_payload()
180
d_state = ST_FIRST_PAYLOAD;
184
gr_ofdm_insert_preamble::enter_payload()
186
d_state = ST_PAYLOAD;