GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
packet_header_default.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /* Copyright 2012 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_PACKET_HEADER_DEFAULT_H
23 #define INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H
24 
25 #include <gnuradio/tags.h>
26 #include <gnuradio/digital/api.h>
27 #include <boost/enable_shared_from_this.hpp>
28 #include <boost/crc.hpp>
29 
30 namespace gr {
31  namespace digital {
32 
33  /*!
34  * \brief Default header formatter for digital packet transmission.
35  * \ingroup packet_operators_blk
36  *
37  * \details
38  * For bursty/packetized digital transmission, packets are usually prepended
39  * with a packet header, containing the number of bytes etc.
40  * This class is not a block, but a tool to create these packet header.
41  *
42  * This is a default packet header (see header_formatter()) for a description
43  * on the header format). To create other header, derive packet header creator
44  * classes from this function.
45  *
46  * gr::digital::packet_headergenerator_bb uses header generators derived from
47  * this class to create packet headers from data streams.
48  */
50  : public boost::enable_shared_from_this<gr::digital::packet_header_default>
51  {
52  public:
53  typedef boost::shared_ptr<packet_header_default> sptr;
54 
55  packet_header_default(long header_len,
56  const std::string &len_tag_key="packet_len",
57  const std::string &num_tag_key="packet_num",
58  int bits_per_byte=1);
59  virtual ~packet_header_default();
60 
61  sptr base() { return shared_from_this(); };
62  sptr formatter() { return shared_from_this(); };
63 
64  void set_header_num(unsigned header_num) { d_header_number = header_num; };
65  long header_len() { return d_header_len; };
66  pmt::pmt_t len_tag_key() { return d_len_tag_key; };
67 
68  /*!
69  * \brief Encodes the header information in the given tags into bits and places them into \p out
70  *
71  * Uses the following header format:
72  * Bits 0-11: The packet length (what was stored in the tag with key \p len_tag_key)
73  * Bits 12-23: The header number (counts up everytime this function is called)
74  * Bit 24-31: 8-Bit CRC
75  * All other bits: Are set to zero
76  *
77  * If the header length is smaller than 32, bits are simply left out. For this
78  * reason, they always start with the LSB.
79  *
80  * However, it is recommended to stay above 32 Bits, in order to have a working
81  * CRC.
82  */
83  virtual bool header_formatter(long packet_len,
84  unsigned char *out,
85  const std::vector<tag_t> &tags=std::vector<tag_t>());
86 
87  /*!
88  * \brief Inverse function to header_formatter().
89  *
90  * Reads the bit stream in \p header and writes a corresponding tag into \p tags.
91  */
92  virtual bool header_parser(
93  const unsigned char *header,
94  std::vector<tag_t> &tags);
95 
96  static sptr make(long header_len,
97  const std::string &len_tag_key="packet_len",
98  const std::string &num_tag_key="packet_num",
99  int bits_per_byte=1);
100 
101  protected:
106  unsigned d_header_number;
107  unsigned d_mask;
108  boost::crc_optimal<8, 0x07, 0xFF, 0x00, false, false> d_crc_impl;
109  };
110 
111  } // namespace digital
112 } // namespace gr
113 
114 #endif /* INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H */
long header_len()
Definition: packet_header_default.h:65
boost::crc_optimal< 8, 0x07, 0xFF, 0x00, false, false > d_crc_impl
Definition: packet_header_default.h:108
sptr base()
Definition: packet_header_default.h:61
sptr formatter()
Definition: packet_header_default.h:62
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:30
void set_header_num(unsigned header_num)
Definition: packet_header_default.h:64
unsigned d_mask
Definition: packet_header_default.h:107
pmt::pmt_t d_len_tag_key
Definition: packet_header_default.h:103
Include this header to use the message passing features.
Definition: logger.h:131
boost::shared_ptr< packet_header_default > sptr
Definition: packet_header_default.h:53
pmt::pmt_t d_num_tag_key
Definition: packet_header_default.h:104
int d_bits_per_byte
Definition: packet_header_default.h:105
unsigned d_header_number
Definition: packet_header_default.h:106
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
long d_header_len
Definition: packet_header_default.h:102
Default header formatter for digital packet transmission.
Definition: packet_header_default.h:49
pmt::pmt_t len_tag_key()
Definition: packet_header_default.h:66