GNU Radio's CCSDS Package
ReedSolomon.h
Go to the documentation of this file.
1 /*
2  * The Reed Solomon codec class
3  * ----------------------------
4  * This class implements Reed Solomon coder and decoder as specified by the
5  * CCSDS TM SYNCHRONIZATION AND CHANNEL CODING blue book standard (August 2011).
6  * The class is based on the original Reed Solomon codec implemented by Phil Karn
7  * Author : Moses Browne Mwakyanjala
8  * Date : Feb 18th, 2018
9  * Institue : Lulea University of Technology
10  * E-mail : moses.browne.mwakyanjala@ltu.se
11  */
12 
13 #ifndef REEDSOLOMON_H
14 #define REEDSOLOMON_H
15 #include <vector>
16 #include "ReedSolomon_CCSDS.h"
17 
18 /* Class variables
19  * ---------------
20  * data_t - a typedef for the data symbol
21  * data_t data[] - array of NN data and parity symbols to be corrected in place
22  * retval - an integer lvalue into which the decoder's return code is written
23  * NROOTS - the number of roots in the RS code generator polynomial,
24  * which is the same as the number of parity symbols in a block.
25  Integer variable or literal.
26  * NN - the total number of symbols in a RS block. Integer variable or literal.
27  * PAD - the number of pad symbols in a block. Integer variable or literal.
28  * ALPHA_TO - The address of an array of NN elements to convert Galois field
29  * elements in index (log) form to polynomial form. Read only.
30  * INDEX_OF - The address of an array of NN elements to convert Galois field
31  * elements in polynomial form to index (log) form. Read only.
32  * MODNN - a function to reduce its argument modulo NN. May be inline or a macro.
33  * FCR - An integer literal or variable specifying the first consecutive root of the
34  * Reed-Solomon generator polynomial. Integer variable or literal.
35  * PRIM - The primitive root of the generator poly. Integer variable or literal.
36  * DEBUG - If set to 1 or more, do various internal consistency checking. Leave this
37  * undefined for production code
38  * The memset(), memmove(), and memcpy() functions are used. The appropriate header
39  * file declaring these functions (usually <string.h>) must be included by the calling
40  * program.*/
41 
42 class ReedSolomon {
43  public:
44  /* Class constructor
45  -----------------
46  @param E : Number of errors.
47  - Valid values
48  [1] E = 16 corresponding to RS(255,223)
49  [2] E = 8 corresponding to RS(255,239)
50  @param I : Interleave depth
51  - Valid values
52  ~~ 1, 2, 3, 4, 5 and 8
53  @param D : Dual-basis representation
54  - Valid values
55  [1] true : Dual-basis representation
56  [2] false: Conventional representation
57  --------------------------------------------------
58  */
59  ReedSolomon(int E, int I,bool D);
60 
61  /* Class destructor
62  ----------------
63  Frees memory located for ALPHA_TO, INDEX_OF and GENPOLY arrays
64  --------------------------------------------------------------
65  */
66  ~ReedSolomon();
67 
68  /* Encode_RS function
69  ------------------
70  @param data : A std::vector<unsigned char> with raw data
71  --------------------------------------------------------
72  */
73 
74  void Encode_RS(std::vector<unsigned char> &data);
75 
76  /* Decode_RS function
77  -------------------
78  @param data : A std::vector<unsigned char> with RS data
79  @param num_errors : Number of errors corrected
80  -------------------------------------------------------
81  */
82  void Decode_RS(std::vector<unsigned char> &data, std::vector<int> &num_errors);
83 
84  /* Success function
85  ----------------
86  @param errors : A std::vector<int> with error report
87  -------------------------------------------------------
88  */
89  bool Success(std::vector<int> errors);
90 
91  //protected:
92  //Convenient std::vector wrappers
93  void vector_encode_rs_8(std::vector<unsigned char> &data);
94  void vector_decode_rs_8(std::vector<unsigned char> &data, int &num_errors);
95  //C Reed Solomon encoder and decoder
96  void encode_rs_8(data_t *data, data_t *parity,int pad);
97  int decode_rs_8(data_t *data, int *eras_pos, int no_eras, int pad);
98  //Miscellaneous functions
99  int MODNN(int x);
100  int MINNN(int a, int b);
101  private:
102  bool dual;
103  int interleave_depth;
104  int MM;
105  int NN;
106  int NROOTS;
107  int FCR;
108  int PRIM;
109  int IPRIM;
110  data_t A0;
111  data_t* ALPHA_TO;
112  data_t* INDEX_OF;
113  data_t* GENPOLY;
114 };
115 #endif
116 
void Encode_RS(std::vector< unsigned char > &data)
void vector_decode_rs_8(std::vector< unsigned char > &data, int &num_errors)
void vector_encode_rs_8(std::vector< unsigned char > &data)
int MODNN(int x)
Definition: older/ReedSolomon.h:42
bool Success(std::vector< int > errors)
ReedSolomon(int E, int I, bool D)
void encode_rs_8(data_t *data, data_t *parity, int pad)
int decode_rs_8(data_t *data, int *eras_pos, int no_eras, int pad)
void data_t
Definition: rs.h:10
int MINNN(int a, int b)
void Decode_RS(std::vector< unsigned char > &data, int &num_errors)