GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
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  * SPDX-License-Identifier: GPL-3.0-or-later
7  *
8  */
9 
10 #ifndef INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H
11 #define INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H
12 
13 #include <gnuradio/digital/api.h>
15 #include <pmt/pmt.h>
16 #include <boost/crc.hpp>
17 
18 namespace gr {
19 namespace digital {
20 
21 /*!
22  * \brief Header formatter that includes the payload length,
23  * packet number, and a CRC check on the header.
24  * \ingroup packet_operators_blk
25  *
26  * \details
27  *
28  * Child class of header_format_base. This version's header
29  * format looks like:
30  *
31  * \li length (12 bits): length of the payload
32  * \li number (12 bits): packet number
33  * \li CRC8 (8 bits): A CRC8 check on the header contents
34  *
35  * Instead of duplicating the payload length, we only add it once
36  * and use the CRC8 to make sure it's correctly received.
37  *
38  * \verbatim
39  | 0 -- 11 | 12 -- 23 | 24 -- 31 |
40  | len | pkt len | CRC8 |
41  \endverbatim
42  *
43  * Reimplements packet_header_default in the style of the
44  * header_format_base.
45  */
47 {
48 public:
49  typedef std::shared_ptr<header_format_ofdm> sptr;
50  header_format_ofdm(const std::vector<std::vector<int>>& occupied_carriers,
51  int n_syms,
52  const std::string& len_key_name = "packet_len",
53  const std::string& frame_key_name = "frame_len",
54  const std::string& num_key_name = "packet_num",
55  int bits_per_header_sym = 1,
56  int bits_per_payload_sym = 1,
57  bool scramble_header = false);
58  ~header_format_ofdm() override;
59 
60  /*!
61  * \brief Encodes the header information in the given tags into
62  * bits and places them into \p out.
63  *
64  * \details
65  * Uses the following header format:
66  * - Bits 0-11: The packet length (what was stored in the tag with key \p
67  * len_tag_key)
68  * - Bits 12-23: The header number (counts up everytime this function is called)
69  * - Bit 24-31: 8-Bit CRC
70  */
71  bool format(int nbytes_in,
72  const unsigned char* input,
73  pmt::pmt_t& output,
74  pmt::pmt_t& info) override;
75 
76  bool parse(int nbits_in,
77  const unsigned char* input,
78  std::vector<pmt::pmt_t>& info,
79  int& nbits_processed) override;
80 
81  /*!
82  * Returns the length of the formatted header in bits.
83  */
84  size_t header_nbits() const override;
85 
86  /*!
87  * Factory to create an async packet header formatter; returns
88  * an sptr to the object.
89  */
90  static sptr make(const std::vector<std::vector<int>>& occupied_carriers,
91  int n_syms,
92  const std::string& len_key_name = "packet_len",
93  const std::string& frame_key_name = "frame_len",
94  const std::string& num_key_name = "packet_num",
95  int bits_per_header_sym = 1,
96  int bits_per_payload_sym = 1,
97  bool scramble_header = false);
98 
99 protected:
100  pmt::pmt_t d_frame_key_name; //!< Tag key of the additional frame length tag
101  const std::vector<std::vector<int>>
102  d_occupied_carriers; //!< Which carriers/symbols carry data
103  int d_syms_per_set; //!< Helper variable: Total number of elements in
104  //!< d_occupied_carriers
106  std::vector<uint8_t> d_scramble_mask; //!< Bits are xor'd with this before tx'ing
107  size_t d_header_len;
108 
109  /*! Get info from the header; return payload length and package
110  * rest of data in d_info dictionary.
111  */
112  int header_payload() override;
113 };
114 
115 } // namespace digital
116 } // namespace gr
117 
118 #endif /* INCLUDED_DIGITAL_HEADER_FORMAT_OFDM_H */
std::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:114
Header formatter that includes the payload length, packet number, and a CRC check on the header.
Definition: header_format_crc.h:47
Header formatter that includes the payload length, packet number, and a CRC check on the header.
Definition: header_format_ofdm.h:47
int d_syms_per_set
Helper variable: Total number of elements in d_occupied_carriers.
Definition: header_format_ofdm.h:103
size_t header_nbits() const override
std::shared_ptr< header_format_ofdm > sptr
Definition: header_format_ofdm.h:49
bool parse(int nbits_in, const unsigned char *input, std::vector< pmt::pmt_t > &info, int &nbits_processed) override
header_format_ofdm(const std::vector< std::vector< int >> &occupied_carriers, int n_syms, const std::string &len_key_name="packet_len", const std::string &frame_key_name="frame_len", const std::string &num_key_name="packet_num", int bits_per_header_sym=1, int bits_per_payload_sym=1, bool scramble_header=false)
pmt::pmt_t d_frame_key_name
Tag key of the additional frame length tag.
Definition: header_format_ofdm.h:100
int d_bits_per_payload_sym
Definition: header_format_ofdm.h:105
const std::vector< std::vector< int > > d_occupied_carriers
Which carriers/symbols carry data.
Definition: header_format_ofdm.h:102
std::vector< uint8_t > d_scramble_mask
Bits are xor'd with this before tx'ing.
Definition: header_format_ofdm.h:106
static sptr make(const std::vector< std::vector< int >> &occupied_carriers, int n_syms, const std::string &len_key_name="packet_len", const std::string &frame_key_name="frame_len", const std::string &num_key_name="packet_num", int bits_per_header_sym=1, int bits_per_payload_sym=1, bool scramble_header=false)
size_t d_header_len
Definition: header_format_ofdm.h:107
bool format(int nbytes_in, const unsigned char *input, pmt::pmt_t &output, pmt::pmt_t &info) override
Encodes the header information in the given tags into bits and places them into out.
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:18
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
std::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting).
Definition: pmt.h:84