GNU Radio C++ API Reference
3.10.12.0
The Free & Open Software Radio Ecosystem
crc.h
Go to the documentation of this file.
1
/* -*- c++ -*- */
2
/*
3
* Copyright 2022 Daniel Estevez <daniel@destevez.net>
4
*
5
* This file is part of GNU Radio
6
*
7
* SPDX-License-Identifier: GPL-3.0-or-later
8
*
9
*/
10
11
#ifndef INCLUDED_DIGITAL_CRC_H
12
#define INCLUDED_DIGITAL_CRC_H
13
14
#include <
gnuradio/digital/api.h
>
15
16
#include <stdint.h>
17
#include <array>
18
#include <vector>
19
20
namespace
gr
{
21
namespace
digital {
22
23
/*!
24
* \brief Calculates a CRC
25
* \ingroup packet_operators_blk
26
*
27
* \details
28
* This class calculates a CRC with configurable parameters.
29
* A table-driven byte-by-byte approach is used in the CRC
30
* computation.
31
*/
32
class
DIGITAL_API
crc
33
{
34
public
:
35
/*!
36
* \brief Construct a CRC calculator instance.
37
*
38
* \param num_bits CRC size in bits
39
* \param poly CRC polynomial, in MSB-first notation
40
* \param initial_value Initial register value
41
* \param final_xor Final XOR value
42
* \param input_reflected true if the input is LSB-first, false if not
43
* \param result_reflected true if the output is LSB-first, false if not
44
*/
45
crc
(
unsigned
num_bits,
46
uint64_t poly,
47
uint64_t initial_value,
48
uint64_t final_xor,
49
bool
input_reflected,
50
bool
result_reflected);
51
~crc
();
52
53
/*!
54
* \brief Computes a CRC
55
*
56
* \param data the input data for the CRC calculation
57
* \param len the length in bytes of the data
58
*/
59
uint64_t
compute
(
const
uint8_t* data, std::size_t len);
60
61
/*!
62
* \brief Computes a CRC
63
*
64
* \param data the input data for the CRC calculation
65
*/
66
uint64_t
compute
(std::vector<uint8_t>
const
& data)
67
{
68
return
compute(data.data(), data.size());
69
}
70
71
private
:
72
std::array<uint64_t, 256> d_table;
73
unsigned
d_num_bits;
74
uint64_t d_mask;
75
uint64_t d_initial_value;
76
uint64_t d_final_xor;
77
bool
d_input_reflected;
78
bool
d_result_reflected;
79
80
uint64_t reflect(uint64_t word)
const
;
81
};
82
83
}
// namespace digital
84
}
// namespace gr
85
86
#endif
/* INCLUDED_DIGITAL_CRC_H */
gr::digital::crc::compute
uint64_t compute(std::vector< uint8_t > const &data)
Computes a CRC.
Definition:
crc.h:66
gr::digital::crc::~crc
~crc()
gr::digital::crc
Calculates a CRC.
Definition:
crc.h:33
gr::digital::crc::crc
crc(unsigned num_bits, uint64_t poly, uint64_t initial_value, uint64_t final_xor, bool input_reflected, bool result_reflected)
Construct a CRC calculator instance.
DIGITAL_API
#define DIGITAL_API
Definition:
gr-digital/include/gnuradio/digital/api.h:18
api.h
gr::digital::crc::compute
uint64_t compute(const uint8_t *data, std::size_t len)
Computes a CRC.
gr
GNU Radio logging wrapper.
Definition:
basic_block.h:29
gr-digital
include
gnuradio
digital
crc.h
Generated by
1.8.20