3 * Copyright 2006 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
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_ofdm_bpsk_demapper.h>
28 #include <gr_io_signature.h>
30 gr_ofdm_bpsk_demapper_sptr
31 gr_make_ofdm_bpsk_demapper (unsigned int occupied_carriers)
33 return gr_ofdm_bpsk_demapper_sptr (new gr_ofdm_bpsk_demapper (occupied_carriers));
36 gr_ofdm_bpsk_demapper::gr_ofdm_bpsk_demapper (unsigned occupied_carriers)
37 : gr_block ("ofdm_bpsk_demapper",
38 gr_make_io_signature (1, 1, sizeof(gr_complex)*occupied_carriers),
39 gr_make_io_signature (1, 1, sizeof(unsigned char))),
40 d_occupied_carriers(occupied_carriers),
41 d_byte_offset(0), d_partial_byte(0)
45 gr_ofdm_bpsk_demapper::~gr_ofdm_bpsk_demapper(void)
49 unsigned char gr_ofdm_bpsk_demapper::slicer(gr_complex x)
51 return (unsigned char)(x.real() > 0 ? 1 : 0);
55 gr_ofdm_bpsk_demapper::forecast (int noutput_items, gr_vector_int &ninput_items_required)
57 unsigned ninputs = ninput_items_required.size ();
58 for (unsigned i = 0; i < ninputs; i++)
59 ninput_items_required[i] = 1;
63 gr_ofdm_bpsk_demapper::general_work(int noutput_items,
64 gr_vector_int &ninput_items,
65 gr_vector_const_void_star &input_items,
66 gr_vector_void_star &output_items)
68 const gr_complex *in = (const gr_complex *)input_items[0];
69 unsigned char *out = (unsigned char *) output_items[0];
71 unsigned int i=0, bytes_produced=0;
73 while(i < d_occupied_carriers) {
75 while((d_byte_offset < 8) && (i < d_occupied_carriers)) {
76 //fprintf(stderr, "%f+j%f\n", in[i].real(), in[i].imag());
77 d_partial_byte |= slicer(in[i++]) << (d_byte_offset++);
80 if(d_byte_offset == 8) {
81 out[bytes_produced++] = d_partial_byte;
88 printf("demod out: ");
89 for(i = 0; i < bytes_produced; i++) {
90 printf("%4x", out[i]);
92 printf(" \tlen: %d\n", i);
96 return bytes_produced;