Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / general / gr_ofdm_frame_sink.h @ c7dbfcc7

History | View | Annotate | Download (3.5 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2005,2006 Free Software Foundation, Inc.
4
 * 
5
 * This file is part of GNU Radio
6
 * 
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)
10
 * any later version.
11
 * 
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.
16
 * 
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.
21
 */
22
23
#ifndef INCLUDED_GR_OFDM_FRAME_SINK_H
24
#define INCLUDED_GR_OFDM_FRAME_SINK_H
25
26
#include <gr_sync_block.h>
27
#include <gr_msg_queue.h>
28
29
class gr_ofdm_frame_sink;
30
typedef boost::shared_ptr<gr_ofdm_frame_sink> gr_ofdm_frame_sink_sptr;
31
32
gr_ofdm_frame_sink_sptr 
33
gr_make_ofdm_frame_sink (gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
34
35
/*!
36
 * \brief Given a stream of bits and access_code flags, assemble packets.
37
 * \ingroup sink
38
 *
39
 * input: stream of bytes from gr_correlate_access_code_bb
40
 * output: none.  Pushes assembled packet into target queue
41
 *
42
 * The framer expects a fixed length header of 2 16-bit shorts
43
 * containing the payload length, followed by the payload.  If the 
44
 * 2 16-bit shorts are not identical, this packet is ignored.  Better
45
 * algs are welcome.
46
 *
47
 * The input data consists of bytes that have two bits used.
48
 * Bit 0, the LSB, contains the data bit.
49
 * Bit 1 if set, indicates that the corresponding bit is the
50
 * the first bit of the packet.  That is, this bit is the first
51
 * one after the access code.
52
 */
53
class gr_ofdm_frame_sink : public gr_sync_block
54
{
55
  friend gr_ofdm_frame_sink_sptr 
56
  gr_make_ofdm_frame_sink (gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
57
58
 private:
59
  enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
60
61
  static const int MAX_PKT_LEN    = 4096;
62
  static const int HEADERBYTELEN   = 4;
63
64
  gr_msg_queue_sptr  d_target_queue;                // where to send the packet when received
65
  state_t            d_state;
66
  unsigned int       d_header;                        // header bits
67
  int                     d_headerbytelen_cnt;        // how many so far
68
69
  unsigned char      *d_bytes_out;              // hold the current bytes produced by the demapper    
70
71
  unsigned int       d_occupied_carriers;
72
  unsigned int       d_byte_offset;
73
  unsigned int       d_partial_byte;
74
75
  unsigned char      d_packet[MAX_PKT_LEN];        // assembled payload
76
  int                      d_packetlen;                // length of packet
77
  int                d_packet_whitener_offset;  // offset into whitener string to use
78
  int                     d_packetlen_cnt;                // how many so far
79
80
 protected:
81
  gr_ofdm_frame_sink(gr_msg_queue_sptr target_queue, unsigned int occupied_tones);
82
83
  void enter_search();
84
  void enter_have_sync();
85
  void enter_have_header();
86
  
87
  bool header_ok()
88
  {
89
    // confirm that two copies of header info are identical
90
    return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
91
  }
92
93
  unsigned char bpsk_slicer(gr_complex x);
94
  unsigned int bpsk_demapper(const gr_complex *in,
95
                             unsigned char *out);  
96
97
 public:
98
  ~gr_ofdm_frame_sink();
99
100
  int work(int noutput_items,
101
           gr_vector_const_void_star &input_items,
102
           gr_vector_void_star &output_items);
103
};
104
105
#endif /* INCLUDED_GR_OFDM_FRAME_SINK_H */