GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
header_format_crc.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/* Copyright 2016 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_HEADER_FORMAT_CRC_H
11#define INCLUDED_DIGITAL_HEADER_FORMAT_CRC_H
12
16#include <pmt/pmt.h>
17
18namespace gr {
19namespace digital {
20
21/*!
22 * \brief Header formatter that includes the payload length,
23 * packet number, and a CRC check on the header.
24 * \ingroup packet_operators_blk
25 *
26 * \details
27 *
28 * Child class of header_format_base. This version's header
29 * format looks like:
30 *
31 * \li length (12 bits): length of the payload
32 * \li number (12 bits): packet number
33 * \li CRC8 (8 bits): A CRC8 check on the header contents
34 *
35 * Instead of duplicating the payload length, we only add it once
36 * and use the CRC8 to make sure it's correctly received.
37 *
38 * \verbatim
39 | 0 -- 11 | 12 -- 23 | 24 -- 31 |
40 | len | pkt len | CRC8 |
41 \endverbatim
42 *
43 * Reimplements packet_header_default in the style of the
44 * header_format_base.
45 */
47{
48public:
49 typedef std::shared_ptr<header_format_crc> sptr;
50 header_format_crc(const std::string& len_key_name = "packet_len",
51 const std::string& num_key_name = "packet_num");
53
54 void set_header_num(unsigned header_num) { d_header_number = header_num; };
55
56 /*!
57 * \brief Encodes the header information in the given tags into
58 * bits and places them into \p out.
59 *
60 * \details
61 * Uses the following header format:
62 * - Bits 0-11: The packet length (what was stored in the tag with key \p
63 * len_tag_key)
64 * - Bits 12-23: The header number (counts up every time this function is called)
65 * - Bit 24-31: 8-Bit CRC
66 */
67 bool format(int nbytes_in,
68 const unsigned char* input,
69 pmt::pmt_t& output,
70 pmt::pmt_t& info) override;
71
72 bool parse(int nbits_in,
73 const unsigned char* input,
74 std::vector<pmt::pmt_t>& info,
75 int& nbits_processed) override;
76
77 /*!
78 * Returns the length of the formatted header in bits.
79 */
80 size_t header_nbits() const override;
81
82 /*!
83 * Factory to create an async packet header formatter; returns
84 * an sptr to the object.
85 */
86 static sptr make(const std::string& len_key_name = "packet_len",
87 const std::string& num_key_name = "packet_num");
88
89protected:
94
95 //! Verify that the header is valid
96 bool header_ok() override;
97
98 /*! Get info from the header; return payload length and package
99 * rest of data in d_info dictionary.
100 */
101 int header_payload() override;
102};
103
104} // namespace digital
105} // namespace gr
106
107#endif /* INCLUDED_DIGITAL_HEADER_FORMAT_CRC_H */
Calculates a CRC.
Definition: crc.h:33
Base header formatter class.
Definition: header_format_base.h:112
std::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:114
Header formatter that includes the payload length, packet number, and a CRC check on the header.
Definition: header_format_crc.h:47
bool parse(int nbits_in, const unsigned char *input, std::vector< pmt::pmt_t > &info, int &nbits_processed) override
bool header_ok() override
Verify that the header is valid.
static sptr make(const std::string &len_key_name="packet_len", const std::string &num_key_name="packet_num")
bool format(int nbytes_in, const unsigned char *input, pmt::pmt_t &output, pmt::pmt_t &info) override
Encodes the header information in the given tags into bits and places them into out.
pmt::pmt_t d_len_key_name
Definition: header_format_crc.h:91
size_t header_nbits() const override
void set_header_num(unsigned header_num)
Definition: header_format_crc.h:54
pmt::pmt_t d_num_key_name
Definition: header_format_crc.h:92
header_format_crc(const std::string &len_key_name="packet_len", const std::string &num_key_name="packet_num")
crc d_crc_impl
Definition: header_format_crc.h:93
std::shared_ptr< header_format_crc > sptr
Definition: header_format_crc.h:49
uint16_t d_header_number
Definition: header_format_crc.h:90
#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