GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
header_format_ofdm.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /* Copyright 2016 Free Software Foundation, Inc.
3  *
4  * This file is part of GNU Radio
5  *
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H
23 #define INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H
24 
25 #include <gnuradio/digital/api.h>
27 #include <pmt/pmt.h>
28 #include <boost/crc.hpp>
29 
30 namespace gr {
31 namespace digital {
32 
33 /*!
34  * \brief Header formatter that includes the payload length,
35  * packet number, and a CRC check on the header.
36  * \ingroup packet_operators_blk
37  *
38  * \details
39  *
40  * Child class of header_format_base. This version's header
41  * format looks like:
42  *
43  * \li length (12 bits): length of the payload
44  * \li number (12 bits): packet number
45  * \li CRC8 (8 bits): A CRC8 check on the header contents
46  *
47  * Instead of duplicating the payload length, we only add it once
48  * and use the CRC8 to make sure it's correctly received.
49  *
50  * \verbatim
51  | 0 -- 11 | 12 -- 23 | 24 -- 31 |
52  | len | pkt len | CRC8 |
53  \endverbatim
54  *
55  * Reimplements packet_header_default in the style of the
56  * header_format_base.
57  */
59 {
60 public:
61  header_format_ofdm(const std::vector<std::vector<int>>& occupied_carriers,
62  int n_syms,
63  const std::string& len_key_name = "packet_len",
64  const std::string& frame_key_name = "frame_len",
65  const std::string& num_key_name = "packet_num",
66  int bits_per_header_sym = 1,
67  int bits_per_payload_sym = 1,
68  bool scramble_header = false);
69  virtual ~header_format_ofdm();
70 
71  /*!
72  * \brief Encodes the header information in the given tags into
73  * bits and places them into \p out.
74  *
75  * \details
76  * Uses the following header format:
77  * - Bits 0-11: The packet length (what was stored in the tag with key \p
78  * len_tag_key)
79  * - Bits 12-23: The header number (counts up everytime this function is called)
80  * - Bit 24-31: 8-Bit CRC
81  */
82  virtual bool format(int nbytes_in,
83  const unsigned char* input,
84  pmt::pmt_t& output,
85  pmt::pmt_t& info);
86 
87  virtual bool parse(int nbits_in,
88  const unsigned char* input,
89  std::vector<pmt::pmt_t>& info,
90  int& nbits_processed);
91 
92  /*!
93  * Returns the length of the formatted header in bits.
94  */
95  virtual size_t header_nbits() const;
96 
97  /*!
98  * Factory to create an async packet header formatter; returns
99  * an sptr to the object.
100  */
101  static sptr make(const std::vector<std::vector<int>>& occupied_carriers,
102  int n_syms,
103  const std::string& len_key_name = "packet_len",
104  const std::string& frame_key_name = "frame_len",
105  const std::string& num_key_name = "packet_num",
106  int bits_per_header_sym = 1,
107  int bits_per_payload_sym = 1,
108  bool scramble_header = false);
109 
110 protected:
111  pmt::pmt_t d_frame_key_name; //!< Tag key of the additional frame length tag
112  const std::vector<std::vector<int>>
113  d_occupied_carriers; //!< Which carriers/symbols carry data
114  int d_syms_per_set; //!< Helper variable: Total number of elements in
115  //!< d_occupied_carriers
117  std::vector<uint8_t> d_scramble_mask; //!< Bits are xor'd with this before tx'ing
118  size_t d_header_len;
119 
120  /*! Get info from the header; return payload length and package
121  * rest of data in d_info dictionary.
122  */
123  virtual int header_payload();
124 };
125 
126 } // namespace digital
127 } // namespace gr
128 
129 #endif /* INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H */
boost::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:96
std::vector< uint8_t > d_scramble_mask
Bits are xor&#39;d with this before tx&#39;ing.
Definition: header_format_ofdm.h:117
Header formatter that includes the payload length, packet number, and a CRC check on the header...
Definition: header_format_crc.h:58
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:30
int d_syms_per_set
Helper variable: Total number of elements in d_occupied_carriers.
Definition: header_format_ofdm.h:114
int d_bits_per_payload_sym
Definition: header_format_ofdm.h:116
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
pmt::pmt_t d_frame_key_name
Tag key of the additional frame length tag.
Definition: header_format_ofdm.h:111
Header formatter that includes the payload length, packet number, and a CRC check on the header...
Definition: header_format_ofdm.h:58
size_t d_header_len
Definition: header_format_ofdm.h:118
const std::vector< std::vector< int > > d_occupied_carriers
Which carriers/symbols carry data.
Definition: header_format_ofdm.h:113
boost::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:127