📄 rs.h
字号:
//License: GNU
//
//
//
//
//
// Copyright (C) 2007 Jonti Olds
//
//
//
// This program is free software: you can redistribute it and/or modify
//
// it under the terms of the GNU General Public License as published by
//
// the Free Software Foundation, either version 3 of the License, or
//
// (at your option) any later version.
//
//
//
// This program is distributed in the hope that it will be useful,
//
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
// GNU General Public License for more details.
//
//
//
// You should have received a copy of the GNU General Public License
//
// along with this program. If not, see <http://www.gnu.org/licenses/>
//---------------------------------------------------------------------------
#ifndef RSH
#define RSH
//---------------------------------------------------------------------------
#include <vector>
#include <stdlib.h>
#include <math.h>
//#include "InterleaverConv.h"
/* This is one of 14 irreducible polynomials
* of degree 8 and cycle length 255. (Ch 5, pp. 275, Magnetic Recording) * The high order 1 bit is implicit *//* x^8 + x^4 + x^3 + x^2 + 1 */#define PPOLY 0x1D
#define TRUE 1
#define FALSE 0
typedef unsigned long BIT32;
typedef unsigned short BIT16;
class RS
{
public:
__fastcall RS();
__fastcall ~RS();
void __fastcall encode_data(unsigned char msg[], int nbytes, unsigned char dst[]);
void __fastcall decode_data(unsigned char data[], int nbytes);
void __fastcall decode_data(int data[], int nbytes);
void __fastcall encode_data(int msg[], int nbytes);
void __fastcall build_codeword(int msg[], int nbytes, int dst[]);
int __fastcall correct_errors_erasures(int codeword[], int csize);
int __fastcall check_syndrome();
int __fastcall correct_errors_erasures(unsigned char codeword[], int csize, int nerasures, int erasures[]);
__property int NumberOfParityBytes = { read=NPAR , write=initialize_ecc };
__property int GetNErrors = { read=NErrors };
__property bool IsCodewordUncorrectable = { read=UncorrectableCodeword };
private:
void __fastcall initialize_ecc(int NumberOfParityBytes);
void __fastcall init_galois_tables();
void __fastcall init_exp_table();
int __fastcall gmult(int a, int b);
int __fastcall ginv(int elt);
void __fastcall compute_genpoly(int nbytes, int genpoly[]);
void __fastcall mult_polys(int dst[], int p1[], int p2[]);
void __fastcall zero_poly(int poly[]);
void __fastcall copy_poly(int dst[], int src[]);
void __fastcall build_codeword(unsigned char msg[], int nbytes, unsigned char dst[]);
void __fastcall Modified_Berlekamp_Massey();
void __fastcall compute_modified_omega();
void __fastcall init_gamma(int gamma[]);
int __fastcall compute_discrepancy(int lambda[], int S[], int L, int n);
void __fastcall add_polys(int dst[], int src[]);
void __fastcall scale_poly(int k, int poly[]);
void __fastcall mul_z_poly(int src[]);
void __fastcall Find_Roots();
int NPAR,MAXDEG;
/* Encoder parity bytes */
//int pBytes[MAXDEG];int *pBytes;/* Decoder syndrome bytes *///int synBytes[MAXDEG];int *synBytes;/* generator polynomial *///int genPoly[MAXDEG*2];int *genPoly;int DEBUG;
int gexp[512];
int glog[256];
/* erasure flags */
int ErasureLocs[256];int NErasures;
/* error locations found using Chien's search*/
int ErrorLocs[256];int NErrors;
/* The Error Locator Polynomial, also known as Lambda or Sigma. Lambda[0] == 1 */
//static int Lambda[MAXDEG];int *Lambda;/* The Error Evaluator Polynomial *///static int Omega[MAXDEG];
int *Omega;
bool UncorrectableCodeword;
};
//
class RSWrapper : RS
{
public:
__fastcall RSWrapper();
void __fastcall LoadCharToEncode(int Value);
int __fastcall GetEncodedChar();
bool NeedCharToEncode;
bool GotEncodedChar;
void __fastcall LoadCharToDecode(int Value);
int __fastcall GetDecodedChar();
bool NeedCharToDecode;
bool GotDecodedChar;
bool GotError;
void __fastcall SetNumberOfParityBytes(int Value);
void __fastcall SetEnCodedTotalBlockSize(int Value);
void __fastcall ResetDeCodedDataBuffer();
void __fastcall ResetEnCodedDataBuffer();
int EnCodedDataPtr;
int EnCodedDataSize;
int DeCodedDataPtr;
int DeCodedDataSize;
private:
//public:
std::vector<int> EnCodeingBuffers[2];
int EnCodeingBuffersPtr;
int EnCodeingDataPtr;
void __fastcall SwitchEncodeBuffers();
int *EnCodedData;
int DeCodeingDataPtr;
std::vector<int> DeCodeingBuffers[2];
int DeCodeingBuffersPtr;
void __fastcall SwitchDecodeBuffers();
int *DeCodedData;
};
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -