# RadioLib: src/utils/FEC.h Source File

FEC.h
#if !defined(_RADIOLIB_FEC_H)
#define _RADIOLIB_FEC_H
#include "../TypeDef.h"
#include "../Module.h"
#if defined(RADIOLIB_BUILD_ARDUINO)
#include "../ArduinoHal.h"
#endif
// BCH(31, 21) code constants
#define RADIOLIB_PAGER_BCH_N (31)
#define RADIOLIB_PAGER_BCH_K (21)
#define RADIOLIB_PAGER_BCH_PRIMITIVE_POLY (0x25)
#if RADIOLIB_STATIC_ONLY
#define RADIOLIB_BCH_MAX_N (63)
#define RADIOLIB_BCH_MAX_K (31)
#endif
class RadioLibBCH {
public:
RadioLibBCH();
~RadioLibBCH();
void begin(uint8_t n, uint8_t k, uint32_t poly);
uint32_t encode(uint32_t dataword);
private:
uint8_t n = 0;
uint8_t k = 0;
uint32_t poly = 0;
uint8_t m = 0;
#if RADIOLIB_STATIC_ONLY
int32_t alphaTo[RADIOLIB_BCH_MAX_N + 1] = { 0 };
int32_t indexOf[RADIOLIB_BCH_MAX_N + 1] = { 0 };
int32_t generator[RADIOLIB_BCH_MAX_N - RADIOLIB_BCH_MAX_K + 1] = { 0 };
#else
int32_t* alphaTo = nullptr;
int32_t* indexOf = nullptr;
int32_t* generator = nullptr;
#endif
};
// the global singleton
extern RadioLibBCH RadioLibBCHInstance;
// macros to access bits in byte array, from http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html
#define SET_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] |= (1 << ((k)%8)) )
#define CLEAR_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] &= ~(1 << ((k)%8)) )
#define TEST_BIT_IN_ARRAY_MSB(A, k) ( A[((k)/8)] & (1 << ((k)%8)) )
#define GET_BIT_IN_ARRAY_MSB(A, k) ( (A[((k)/8)] & (1 << ((k)%8))) ? 1 : 0 )
#endif
RadioLibBCH
Class to calculate Bose–Chaudhuri–Hocquenghem (BCH) class of forward error correction codes....
Definition: FEC.h:26
RadioLibBCH::RadioLibBCH
RadioLibBCH()
Default constructor.
Definition: FEC.cpp:4
RadioLibBCH::begin
void begin(uint8_t n, uint8_t k, uint32_t poly)
Initialization method.
Definition: FEC.cpp:21
RadioLibBCH::~RadioLibBCH
~RadioLibBCH()
Default detructor.
Definition: FEC.cpp:8
RadioLibBCH::encode
uint32_t encode(uint32_t dataword)
Encoding method - encodes one data word (without check bits) into a code word (with check bits).
Definition: FEC.cpp:200