GNU Radio Manual and C++ API Reference 3.7.14.0
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 * 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_CRC_H
23#define INCLUDED_DIGITAL_HEADER_FORMAT_CRC_H
24
27#include <pmt/pmt.h>
28#include <boost/crc.hpp>
29
30namespace gr {
31namespace digital {
32
33/*!
34 * \brief Header formatter that includes the payload length,
35 * packet number, and a CRC check on the header.
36 * \ingroup packet_operators_blk
37 *
38 * \details
39 *
40 * Child class of header_format_base. This version's header
41 * format looks like:
42 *
43 * \li length (12 bits): length of the payload
44 * \li number (12 bits): packet number
45 * \li CRC8 (8 bits): A CRC8 check on the header contents
46 *
47 * Instead of duplicating the payload length, we only add it once
48 * and use the CRC8 to make sure it's correctly received.
49 *
50 * \verbatim
51 | 0 -- 11 | 12 -- 23 | 24 -- 31 |
52 | len | pkt len | CRC8 |
53 \endverbatim
54 *
55 * Reimplements packet_header_default in the style of the
56 * header_format_base.
57 */
59{
60public:
61 header_format_crc(const std::string& len_key_name = "packet_len",
62 const std::string& num_key_name = "packet_num");
64
65 void set_header_num(unsigned header_num) { d_header_number = header_num; };
66
67 /*!
68 * \brief Encodes the header information in the given tags into
69 * bits and places them into \p out.
70 *
71 * \details
72 * Uses the following header format:
73 * - Bits 0-11: The packet length (what was stored in the tag with key \p
74 * len_tag_key)
75 * - Bits 12-23: The header number (counts up everytime this function is called)
76 * - Bit 24-31: 8-Bit CRC
77 */
78 virtual bool format(int nbytes_in,
79 const unsigned char* input,
80 pmt::pmt_t& output,
81 pmt::pmt_t& info);
82
83 virtual bool parse(int nbits_in,
84 const unsigned char* input,
85 std::vector<pmt::pmt_t>& info,
86 int& nbits_processed);
87
88 /*!
89 * Returns the length of the formatted header in bits.
90 */
91 virtual size_t header_nbits() const;
92
93 /*!
94 * Factory to create an async packet header formatter; returns
95 * an sptr to the object.
96 */
97 static sptr make(const std::string& len_key_name = "packet_len",
98 const std::string& num_key_name = "packet_num");
99
100protected:
104 boost::crc_optimal<8, 0x07, 0xFF, 0x00, false, false> d_crc_impl;
105
106 //! Verify that the header is valid
107 virtual bool header_ok();
108
109 /*! Get info from the header; return payload length and package
110 * rest of data in d_info dictionary.
111 */
112 virtual int header_payload();
113};
114
115} // namespace digital
116} // namespace gr
117
118#endif /* INCLUDED_DIGITAL_HEADER_FORMAT_CRC_H */
Base header formatter class.
Definition: header_format_base.h:125
boost::shared_ptr< header_format_base > sptr
Definition: header_format_base.h:127
Header formatter that includes the payload length, packet number, and a CRC check on the header.
Definition: header_format_crc.h:59
static sptr make(const std::string &len_key_name="packet_len", const std::string &num_key_name="packet_num")
virtual size_t header_nbits() const
pmt::pmt_t d_len_key_name
Definition: header_format_crc.h:102
virtual bool format(int nbytes_in, const unsigned char *input, pmt::pmt_t &output, pmt::pmt_t &info)
Encodes the header information in the given tags into bits and places them into out.
void set_header_num(unsigned header_num)
Definition: header_format_crc.h:65
pmt::pmt_t d_num_key_name
Definition: header_format_crc.h:103
header_format_crc(const std::string &len_key_name="packet_len", const std::string &num_key_name="packet_num")
boost::crc_optimal< 8, 0x07, 0xFF, 0x00, false, false > d_crc_impl
Definition: header_format_crc.h:104
virtual bool parse(int nbits_in, const unsigned char *input, std::vector< pmt::pmt_t > &info, int &nbits_processed)
virtual bool header_ok()
Verify that the header is valid.
uint16_t d_header_number
Definition: header_format_crc.h:101
#define DIGITAL_API
Definition: gr-digital/include/gnuradio/digital/api.h:30
Include this header to use the message passing features.
Definition: basic_block.h:45
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost....
Definition: pmt.h:56