📄 rsencoder.h
字号:
#ifndef _RSENC
#define _RSENC
#include "GF.h"
#include "Polynom.h"
#include "RSParam.h"
#include "EncodeCores.h"
/*
为程序的可复用性,将编码器分为编码器“外壳”和编码器“核心”两部分。
编码器“外壳”的功能是:根据给定的RS码参数,将接收到的待编码字节流转换为码元序列,当存满
K个码元时即交给编码器“核心”提供的编码函数计算,得到输出码字后,再整理为输出字节流;
而编码器“核心”则负责具体的编码算法,不必考虑字节流与码字序列间的转换问题,只需给出如下三个函数即可:
*/
/*编码器核心编码函数:给定K个码元,输出N个编码后码元。所用到的其它参数还有表示RS码参数的结构体,及算法核心可能用到的寄存器结构体*/
typedef void (*EncodeFunc)(GFE* codeword, const GFE* msgword, const RSCodeParam& rsp, void* encore);
/*编码器核心初始化函数:编码器核心算法可能会用到一些数组,需要编码器内核的设计者定义一个结构体将这些寄存器全部放进去。初始化函数负责其内存的分配*/
typedef void (*InitEncCoreFunc)(void*, const RSCodeParam&);
/*编码器核心资源释放函数:负责寄存器所占内存的释放*/
typedef void (*CloseEncCoreFunc)(void*);
/*每个编码器核心必须提供给编码器外壳的“接口”*/
struct EncCoreInterface {
InitEncCoreFunc InitEncCore; //初始化函数
CloseEncCoreFunc CloseEncCore; //资源释放函数
EncodeFunc EncodeOneWord; //核心编码函数
int EncCoreSize; //寄存器结构体所占内存的大小,单位是字节
};
/*标志编码器具体编码方法的枚举类型*/
enum EncCore {
Systemetic, //系统码编码方式
MsgPoly, //多项式求值方式
VoidEnc //无编码补零方式(仅为测试用)
};
/*各编码器核心接口数组。新的编码器核心要将接口中的四项按顺序填入此数组中*/
static EncCoreInterface EncCores[]= {
//{InitFunc, CloseFunc, EncodeFunc, EncCoreSize}
{InitSysEncCore, CloseSysEncCore, EncodeOneWord_Sys, sizeof(SysEncRegs)},
{NULL, NULL, EncodeOneWord_Poly, 0},
{NULL, NULL, EncodeOneWord_Void, 0}
};
struct RSEncoder {
RSCodeParam rsp;//RS码的参数
byte *codeblock;
int ib;//输出编码码字的字节块,及其指针
GFE maskw, masktop;
byte masko; //maskw:用于码元的掩码; masko:用于输出字节流的掩码
GFE *mword, *cword; //存放输入的信息位码元和输出的码字码元的数组
int im; //指示当前存放信息码元位置的指针
void* EncCoreRegs; //指向编码器核心寄存器结构体的指针
EncodeFunc EncodeOneWord; //
InitEncCoreFunc InitEncCore; //
CloseEncCoreFunc CloseEncCore;
};
extern void ResetRSEncoder(RSEncoder& enc);
extern RSCodeParam InitRSEncoder(RSEncoder& enc, int m, int m0, int D, EncCore ec);
extern void CloseRSEncoder(RSEncoder& enc);
extern int EncodeOneByte(byte b, byte*& outblockp, RSEncoder& enc);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -