GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
header_format_counter.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /* Copyright 2015-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_COUNTER_H
11 #define INCLUDED_DIGITAL_HEADER_FORMAT_COUNTER_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 adds the payload bits/symbol
22  * format and a packet number counter.
23  * \ingroup packet_operators_blk
24  *
25  * \details
26  *
27  * Child class of header_format_default. This version adds two
28  * fields to the header:
29  *
30  * \li bps (16 bits): bits/symbol used when modulating the payload.
31  * \li count (16 bits): a counter for the packet number.
32  *
33  * Like the default packet formatter, the length is encoded as a
34  * 16-bit value repeated twice. The full packet looks like:
35  * \verbatim
36  | access code | hdr | payload |
37  \endverbatim
38  *
39  * Where the access code is <= 64 bits and hdr is:
40  * \verbatim
41  | 0 -- 15 | 16 -- 31 |
42  | pkt len | pkt len |
43  | bits/sym | counter |
44  \endverbatim
45  *
46  * The access code and header are formatted for network byte order.
47  *
48  * \sa header_format_default
49  */
51 {
52 public:
53  typedef std::shared_ptr<header_format_counter> sptr;
54 
55  header_format_counter(const std::string& access_code, int threshold, int bps);
57 
58  /*!
59  * Creates a header from the access code and packet length to
60  * build an output packet in the form:
61  *
62  * \verbatim
63  | access code | pkt len | pkt len | bps | counter |
64  \endverbatim
65  *
66  * \param nbytes_in The length (in bytes) of the \p input payload
67  * \param input An array of unsigned chars of the packet payload
68  * \param output A pmt::u8vector with the new header prepended
69  * onto the input data.
70  * \param info A pmt::dict containing meta data and info about
71  * the PDU (generally from the metadata portion of the
72  * input PDU). Data can be extracted from this for the
73  * header formatting or inserted.
74  */
75  bool format(int nbytes_in,
76  const unsigned char* input,
77  pmt::pmt_t& output,
78  pmt::pmt_t& info) 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  * \param access_code An access code that is used to find and
90  * synchronize the start of a packet. Used in the parser and in
91  * other blocks like a corr_est block that helps trigger the
92  * receiver. Can be up to 64-bits long.
93  * \param threshold How many bits can be wrong in the access
94  * code and still count as correct.
95  * \param bps The number of bits/second used in the payload's
96  * modulator.
97  */
98  static sptr make(const std::string& access_code, int threshold, int bps);
99 
100 protected:
101  uint16_t d_counter; //!< keeps track of the number of packets transmitted
102 
103  //! Verify that the header is valid
104  bool header_ok() override;
105 
106  /*! Get info from the header; return payload length and package
107  * rest of data in d_info dictionary.
108  *
109  * Extracts the header of the form:
110  *
111  * \verbatim
112  | access code | pkt len | pkt len | bps | counter | payload |
113  \endverbatim
114  */
115  int header_payload() override;
116 };
117 
118 } // namespace digital
119 } // namespace gr
120 
121 #endif /* INCLUDED_DIGITAL_HEADER_FORMAT_COUNTER_H */
std::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:114
Header formatter that adds the payload bits/symbol format and a packet number counter.
Definition: header_format_counter.h:51
size_t header_nbits() const override
uint16_t d_counter
keeps track of the number of packets transmitted
Definition: header_format_counter.h:101
bool format(int nbytes_in, const unsigned char *input, pmt::pmt_t &output, pmt::pmt_t &info) override
bool header_ok() override
Verify that the header is valid.
std::shared_ptr< header_format_counter > sptr
Definition: header_format_counter.h:53
static sptr make(const std::string &access_code, int threshold, int bps)
header_format_counter(const std::string &access_code, int threshold, int bps)
Default header formatter for PDU formatting.
Definition: header_format_default.h:69
#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