GNU Radio Manual and C++ API Reference  3.8.1.0
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 <gnuradio/digital/api.h>
27 #include <pmt/pmt.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 {
64 public:
65  header_format_counter(const std::string& access_code, int threshold, int bps);
66  virtual ~header_format_counter();
67 
68  /*!
69  * Creates a header from the access code and packet length to
70  * build an output packet in the form:
71  *
72  * \verbatim
73  | access code | pkt len | pkt len | bps | counter |
74  \endverbatim
75  *
76  * \param nbytes_in The length (in bytes) of the \p input payload
77  * \param input An array of unsigned chars of the packet payload
78  * \param output A pmt::u8vector with the new header prepended
79  * onto the input data.
80  * \param info A pmt::dict containing meta data and info about
81  * the PDU (generally from the metadata portion of the
82  * input PDU). Data can be extracted from this for the
83  * header formatting or inserted.
84  */
85  virtual bool format(int nbytes_in,
86  const unsigned char* input,
87  pmt::pmt_t& output,
88  pmt::pmt_t& info);
89 
90  /*!
91  * Returns the length of the formatted header in bits.
92  */
93  virtual size_t header_nbits() const;
94 
95  /*!
96  * Factory to create an async packet header formatter; returns
97  * an sptr to the object.
98  *
99  * \param access_code An access code that is used to find and
100  * synchronize the start of a packet. Used in the parser and in
101  * other blocks like a corr_est block that helps trigger the
102  * receiver. Can be up to 64-bits long.
103  * \param threshold How many bits can be wrong in the access
104  * code and still count as correct.
105  * \param bps The number of bits/second used in the payload's
106  * modulator.
107  */
108  static sptr make(const std::string& access_code, int threshold, int bps);
109 
110 protected:
111  uint16_t d_counter; //!< keeps track of the number of packets transmitted
112 
113  //! Verify that the header is valid
114  bool header_ok();
115 
116  /*! Get info from the header; return payload length and package
117  * rest of data in d_info dictionary.
118  *
119  * Extracts the header of the form:
120  *
121  * \verbatim
122  | access code | pkt len | pkt len | bps | counter | payload |
123  \endverbatim
124  */
125  int header_payload();
126 };
127 
128 } // namespace digital
129 } // namespace gr
130 
131 #endif /* INCLUDED_DIGITAL_HEADER_FORMAT_COUNTER_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
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:30
Default header formatter for PDU formatting.
Definition: header_format_default.h:81
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
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
uint16_t d_counter
keeps track of the number of packets transmitted
Definition: header_format_counter.h:111