GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
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 * SPDX-License-Identifier: GPL-3.0-or-later
7 *
8 */
9
10#ifndef INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H
11#define INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H
12
15#include <gnuradio/tags.h>
16
17namespace gr {
18namespace digital {
19
20/*!
21 * \brief Default header formatter for digital packet transmission.
22 * \ingroup packet_operators_blk
23 *
24 * \details
25 * For bursty/packetized digital transmission, packets are usually prepended
26 * with a packet header, containing the number of bytes etc.
27 * This class is not a block, but a tool to create these packet header.
28 *
29 * This is a default packet header (see header_formatter()) for a description
30 * on the header format). To create other header, derive packet header creator
31 * classes from this function.
32 *
33 * gr::digital::packet_headergenerator_bb uses header generators derived from
34 * this class to create packet headers from data streams.
35 */
37 : public std::enable_shared_from_this<gr::digital::packet_header_default>
38{
39public:
40 typedef std::shared_ptr<packet_header_default> sptr;
41
42 packet_header_default(long header_len,
43 const std::string& len_tag_key = "packet_len",
44 const std::string& num_tag_key = "packet_num",
45 int bits_per_byte = 1);
47
48 sptr base() { return shared_from_this(); };
49 sptr formatter() { return shared_from_this(); };
50
51 void set_header_num(unsigned header_num) { d_header_number = header_num; };
52 long header_len() { return d_header_len; };
53 pmt::pmt_t len_tag_key() { return d_len_tag_key; };
54
55 /*!
56 * \brief Encodes the header information in the given tags into bits and places them
57 * into \p out
58 *
59 * Uses the following header format:
60 * Bits 0-11: The packet length (what was stored in the tag with key \p len_tag_key)
61 * Bits 12-23: The header number (counts up every time this function is called)
62 * Bit 24-31: 8-Bit CRC
63 * All other bits: Are set to zero
64 *
65 * If the header length is smaller than 32, bits are simply left out. For this
66 * reason, they always start with the LSB.
67 *
68 * However, it is recommended to stay above 32 Bits, in order to have a working
69 * CRC.
70 */
71 virtual bool header_formatter(long packet_len,
72 unsigned char* out,
73 const std::vector<tag_t>& tags = std::vector<tag_t>());
74
75 /*!
76 * \brief Inverse function to header_formatter().
77 *
78 * Reads the bit stream in \p header and writes a corresponding tag into \p tags.
79 */
80 virtual bool header_parser(const unsigned char* header, std::vector<tag_t>& tags);
81
82 static sptr make(long header_len,
83 const std::string& len_tag_key = "packet_len",
84 const std::string& num_tag_key = "packet_num",
85 int bits_per_byte = 1);
86
87protected:
93 unsigned d_mask;
95};
96
97} // namespace digital
98} // namespace gr
99
100#endif /* INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H */
Calculates a CRC.
Definition: crc.h:33
Default header formatter for digital packet transmission.
Definition: packet_header_default.h:38
long header_len()
Definition: packet_header_default.h:52
pmt::pmt_t d_num_tag_key
Definition: packet_header_default.h:90
pmt::pmt_t d_len_tag_key
Definition: packet_header_default.h:89
virtual bool header_parser(const unsigned char *header, std::vector< tag_t > &tags)
Inverse function to header_formatter().
void set_header_num(unsigned header_num)
Definition: packet_header_default.h:51
pmt::pmt_t len_tag_key()
Definition: packet_header_default.h:53
packet_header_default(long header_len, const std::string &len_tag_key="packet_len", const std::string &num_tag_key="packet_num", int bits_per_byte=1)
static sptr make(long header_len, const std::string &len_tag_key="packet_len", const std::string &num_tag_key="packet_num", int bits_per_byte=1)
long d_header_len
Definition: packet_header_default.h:88
crc d_crc_impl
Definition: packet_header_default.h:94
std::shared_ptr< packet_header_default > sptr
Definition: packet_header_default.h:40
sptr formatter()
Definition: packet_header_default.h:49
sptr base()
Definition: packet_header_default.h:48
virtual bool header_formatter(long packet_len, unsigned char *out, const std::vector< tag_t > &tags=std::vector< tag_t >())
Encodes the header information in the given tags into bits and places them into out.
unsigned d_mask
Definition: packet_header_default.h:93
unsigned d_header_number
Definition: packet_header_default.h:92
int d_bits_per_byte
Definition: packet_header_default.h:91
#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