GNU Radio Manual and C++ API Reference  3.7.13.4
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  * 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_COUNTER_H
23 #define INCLUDED_DIGITAL_HEADER_FORMAT_COUNTER_H
24 
25 #include <pmt/pmt.h>
26 #include <gnuradio/digital/api.h>
28 
29 namespace gr {
30  namespace digital {
31 
32  /*!
33  * \brief Header formatter that adds the payload bits/symbol
34  * format and a packet number counter.
35  * \ingroup packet_operators_blk
36  *
37  * \details
38  *
39  * Child class of header_format_default. This version adds two
40  * fields to the header:
41  *
42  * \li bps (16 bits): bits/symbol used when modulating the payload.
43  * \li count (16 bits): a counter for the packet number.
44  *
45  * Like the default packet formatter, the length is encoded as a
46  * 16-bit value repeated twice. The full packet looks like:
47  * \verbatim
48  | access code | hdr | payload |
49  \endverbatim
50  *
51  * Where the access code is <= 64 bits and hdr is:
52  * \verbatim
53  | 0 -- 15 | 16 -- 31 |
54  | pkt len | pkt len |
55  | bits/sym | counter |
56  \endverbatim
57  *
58  * The access code and header are formatted for network byte order.
59  *
60  * \sa header_format_default
61  */
63  : public header_format_default
64  {
65  public:
66  header_format_counter(const std::string &access_code,
67  int threshold, int bps);
68  virtual ~header_format_counter();
69 
70  /*!
71  * Creates a header from the access code and packet length to
72  * build an output packet in the form:
73  *
74  * \verbatim
75  | access code | pkt len | pkt len | bps | counter |
76  \endverbatim
77  *
78  * \param nbytes_in The length (in bytes) of the \p input payload
79  * \param input An array of unsigned chars of the packet payload
80  * \param output A pmt::u8vector with the new header prepended
81  * onto the input data.
82  * \param info A pmt::dict containing meta data and info about
83  * the PDU (generally from the metadata portion of the
84  * input PDU). Data can be extracted from this for the
85  * header formatting or inserted.
86  */
87  virtual bool format(int nbytes_in,
88  const unsigned char *input,
89  pmt::pmt_t &output,
90  pmt::pmt_t &info);
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  * \param access_code An access code that is used to find and
102  * synchronize the start of a packet. Used in the parser and in
103  * other blocks like a corr_est block that helps trigger the
104  * receiver. Can be up to 64-bits long.
105  * \param threshold How many bits can be wrong in the access
106  * code and still count as correct.
107  * \param bps The number of bits/second used in the payload's
108  * modulator.
109  */
110  static sptr make(const std::string &access_code,
111  int threshold, int bps);
112 
113  protected:
114  uint16_t d_counter; //!< keeps track of the number of packets transmitted
115 
116  //! Verify that the header is valid
117  bool header_ok();
118 
119  /*! Get info from the header; return payload length and package
120  * rest of data in d_info dictionary.
121  *
122  * Extracts the header of the form:
123  *
124  * \verbatim
125  | access code | pkt len | pkt len | bps | counter | payload |
126  \endverbatim
127  */
128  int header_payload();
129  };
130 
131  } // namespace digital
132 } // namespace gr
133 
134 #endif /* INCLUDED_DIGITAL_HEADER_FORMAT_COUNTER_H */
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:30
Default header formatter for PDU formatting.
Definition: header_format_default.h:81
Include this header to use the message passing features.
Definition: logger.h:695
Header formatter that adds the payload bits/symbol format and a packet number counter.
Definition: header_format_counter.h:62
boost::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:127
boost::intrusive_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:56
uint16_t d_counter
keeps track of the number of packets transmitted
Definition: header_format_counter.h:114