RadioLib
Universal wireless communication library for Arduino
FEC.h
1 #if !defined(_RADIOLIB_FEC_H)
2 #define _RADIOLIB_FEC_H
3 
4 #include "../TypeDef.h"
5 #include "../Module.h"
6 
7 // BCH(31, 21) code constants
8 #define RADIOLIB_PAGER_BCH_N (31)
9 #define RADIOLIB_PAGER_BCH_K (21)
10 #define RADIOLIB_PAGER_BCH_PRIMITIVE_POLY (0x25)
11 
12 #if RADIOLIB_STATIC_ONLY
13 #define RADIOLIB_BCH_MAX_N (63)
14 #define RADIOLIB_BCH_MAX_K (31)
15 #endif
16 
23 class RadioLibBCH {
24  public:
28  RadioLibBCH();
29 
33  ~RadioLibBCH();
34 
41  void begin(uint8_t n, uint8_t k, uint32_t poly);
42 
49  uint32_t encode(uint32_t dataword);
50 
51  private:
52  uint8_t n = 0;
53  uint8_t k = 0;
54  uint32_t poly = 0;
55  uint8_t m = 0;
56 
57  #if RADIOLIB_STATIC_ONLY
58  int32_t alphaTo[RADIOLIB_BCH_MAX_N + 1] = { 0 };
59  int32_t indexOf[RADIOLIB_BCH_MAX_N + 1] = { 0 };
60  int32_t generator[RADIOLIB_BCH_MAX_N - RADIOLIB_BCH_MAX_K + 1] = { 0 };
61  #else
62  int32_t* alphaTo = nullptr;
63  int32_t* indexOf = nullptr;
64  int32_t* generator = nullptr;
65  #endif
66 };
67 
68 // the global singleton
69 extern RadioLibBCH RadioLibBCHInstance;
70 
111  public:
116 
121  void begin(uint8_t rt);
122 
133  int16_t encode(const uint8_t* in, size_t in_bits, uint8_t* out, size_t* out_bits = NULL);
134 
135  private:
136  uint8_t enc_state = 0;
137  uint8_t rate = 0;
138 };
139 
140 // each 32-bit word stores 8 values, one per each nibble
141 static const uint32_t ConvCodeTable1_3[16] = {
142  0x07347043, 0x61521625, 0x16256152, 0x70430734,
143  0x43703407, 0x25165261, 0x52612516, 0x34074370,
144  0x70430734, 0x16256152, 0x61521625, 0x07347043,
145  0x34074370, 0x52612516, 0x25165261, 0x43703407,
146 };
147 
148 static const uint32_t ConvCodeTable1_2[4] = {
149  0x03122130, 0x21300312, 0x30211203, 0x12033021,
150 };
151 
152 extern RadioLibConvCode RadioLibConvCodeInstance;
153 
154 #endif
Class to calculate Bose–Chaudhuri–Hocquenghem (BCH) class of forward error correction codes....
Definition: FEC.h:23
RadioLibBCH()
Default constructor.
Definition: FEC.cpp:4
void begin(uint8_t n, uint8_t k, uint32_t poly)
Initialization method.
Definition: FEC.cpp:21
~RadioLibBCH()
Default destructor.
Definition: FEC.cpp:8
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
Class to perform convolutional coding with variable rates. Only 1/2 and 1/3 rate is currently support...
Definition: FEC.h:110
RadioLibConvCode()
Default constructor.
Definition: FEC.cpp:311
int16_t encode(const uint8_t *in, size_t in_bits, uint8_t *out, size_t *out_bits=NULL)
Encoding method.
Definition: FEC.cpp:320
void begin(uint8_t rt)
Initialization method.
Definition: FEC.cpp:315