GNU Radio Manual and C++ API Reference 3.8.5.0
The Free & Open Software Radio Ecosystem
 
Loading...
Searching...
No Matches
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
26#include <gnuradio/tags.h>
27#include <boost/crc.hpp>
28#include <boost/enable_shared_from_this.hpp>
29
30namespace gr {
31namespace 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{
52public:
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);
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
70 * into \p out
71 *
72 * Uses the following header format:
73 * Bits 0-11: The packet length (what was stored in the tag with key \p len_tag_key)
74 * Bits 12-23: The header number (counts up every time this function is called)
75 * Bit 24-31: 8-Bit CRC
76 * All other bits: Are set to zero
77 *
78 * If the header length is smaller than 32, bits are simply left out. For this
79 * reason, they always start with the LSB.
80 *
81 * However, it is recommended to stay above 32 Bits, in order to have a working
82 * CRC.
83 */
84 virtual bool header_formatter(long packet_len,
85 unsigned char* out,
86 const std::vector<tag_t>& tags = std::vector<tag_t>());
87
88 /*!
89 * \brief Inverse function to header_formatter().
90 *
91 * Reads the bit stream in \p header and writes a corresponding tag into \p tags.
92 */
93 virtual bool header_parser(const unsigned char* header, std::vector<tag_t>& tags);
94
95 static sptr make(long header_len,
96 const std::string& len_tag_key = "packet_len",
97 const std::string& num_tag_key = "packet_num",
98 int bits_per_byte = 1);
99
100protected:
106 unsigned d_mask;
107 boost::crc_optimal<8, 0x07, 0xFF, 0x00, false, false> d_crc_impl;
108};
109
110} // namespace digital
111} // namespace gr
112
113#endif /* INCLUDED_DIGITAL_PACKET_HEADER_DEFAULT_H */
Default header formatter for digital packet transmission.
Definition packet_header_default.h:51
long header_len()
Definition packet_header_default.h:65
pmt::pmt_t d_num_tag_key
Definition packet_header_default.h:103
pmt::pmt_t d_len_tag_key
Definition packet_header_default.h:102
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:64
pmt::pmt_t len_tag_key()
Definition packet_header_default.h:66
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:101
sptr formatter()
Definition packet_header_default.h:62
boost::crc_optimal< 8, 0x07, 0xFF, 0x00, false, false > d_crc_impl
Definition packet_header_default.h:107
sptr base()
Definition packet_header_default.h:61
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:106
unsigned d_header_number
Definition packet_header_default.h:105
int d_bits_per_byte
Definition packet_header_default.h:104
boost::shared_ptr< packet_header_default > sptr
Definition packet_header_default.h:53
#define DIGITAL_API
Definition gr-digital/include/gnuradio/digital/api.h:30
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition basic_block.h:46
boost::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost....
Definition pmt.h:96