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