GNU Radio's SATELLITES Package
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 gr-satellites
6
*
7
* SPDX-License-Identifier: GPL-3.0-or-later
8
*
9
*/
10
11
#ifndef INCLUDED_SATELLITES_CRC_H
12
#define INCLUDED_SATELLITES_CRC_H
13
14
#include <
satellites/api.h
>
15
16
#include <stdint.h>
17
#include <array>
18
#include <vector>
19
20
namespace
gr
{
21
namespace
satellites {
22
23
/*!
24
* \brief Calculates a CRC
25
* \ingroup satellites
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
SATELLITES_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
(
const
std::vector<uint8_t> 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);
81
};
82
83
}
// namespace satellites
84
}
// namespace gr
85
86
#endif
/* INCLUDED_SATELLITES_CRC_H */
api.h
SATELLITES_API
#define SATELLITES_API
Definition
api.h:31
gr::satellites::crc
Calculates a CRC.
Definition
crc.h:33
gr::satellites::crc::compute
uint64_t compute(const uint8_t *data, std::size_t len)
Computes a CRC.
gr::satellites::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.
gr::satellites::crc::compute
uint64_t compute(const std::vector< uint8_t > data)
Computes a CRC.
Definition
crc.h:66
gr::satellites::crc::~crc
~crc()
gr
Definition
ax100_decode.h:17
include
satellites
crc.h
Generated by
1.9.8