modified fec.c for c++ standard

This commit is contained in:
wangyu- 2017-09-14 07:01:39 -05:00
parent ffebe086ca
commit acebde7de5
5 changed files with 56 additions and 17 deletions

View File

@ -127,7 +127,7 @@ typedef unsigned short gf;
* Primitive polynomials - see Lin & Costello, Appendix A, * Primitive polynomials - see Lin & Costello, Appendix A,
* and Lee & Messerschmitt, p. 453. * and Lee & Messerschmitt, p. 453.
*/ */
static char *allPp[] = { /* GF_BITS polynomial */ static const char *allPp[] = { /* GF_BITS polynomial */
NULL, /* 0 no code */ NULL, /* 0 no code */
NULL, /* 1 no code */ NULL, /* 1 no code */
"111", /* 2 1+x+x^2 */ "111", /* 2 1+x+x^2 */
@ -148,6 +148,7 @@ static char *allPp[] = { /* GF_BITS polynomial */
}; };
/* /*
* To speed up computations, we have tables for logarithm, exponent * To speed up computations, we have tables for logarithm, exponent
* and inverse of a number. If GF_BITS <= 8, we use a table for * and inverse of a number. If GF_BITS <= 8, we use a table for
@ -239,7 +240,7 @@ gf_mul(x,y)
* one place. * one place.
*/ */
static void * static void *
my_malloc(int sz, char *err_string) my_malloc(int sz, const char *err_string)
{ {
void *p = malloc( sz ); void *p = malloc( sz );
if (p == NULL) { if (p == NULL) {
@ -260,7 +261,7 @@ generate_gf(void)
{ {
int i; int i;
gf mask; gf mask;
char *Pp = allPp[GF_BITS] ; const char *Pp = allPp[GF_BITS] ;
mask = 1; /* x ** 0 = 1 */ mask = 1; /* x ** 0 = 1 */
gf_exp[GF_BITS] = 0; /* will be updated at the end of the 1st loop */ gf_exp[GF_BITS] = 0; /* will be updated at the end of the 1st loop */
@ -427,9 +428,9 @@ invert_mat(gf *src, int k)
int irow, icol, row, col, i, ix ; int irow, icol, row, col, i, ix ;
int error = 1 ; int error = 1 ;
int *indxc = my_malloc(k*sizeof(int), "indxc"); int *indxc = (int*)my_malloc(k*sizeof(int), "indxc");
int *indxr = my_malloc(k*sizeof(int), "indxr"); int *indxr = (int*)my_malloc(k*sizeof(int), "indxr");
int *ipiv = my_malloc(k*sizeof(int), "ipiv"); int *ipiv = (int*)my_malloc(k*sizeof(int), "ipiv");
gf *id_row = NEW_GF_MATRIX(1, k); gf *id_row = NEW_GF_MATRIX(1, k);
gf *temp_row = NEW_GF_MATRIX(1, k); gf *temp_row = NEW_GF_MATRIX(1, k);
@ -644,10 +645,11 @@ struct fec_parms {
} ; } ;
void void
fec_free(struct fec_parms *p) fec_free(void *p0)
{ {
struct fec_parms *p= (struct fec_parms *) p0;
if (p==NULL || if (p==NULL ||
p->magic != ( ( (FEC_MAGIC ^ p->k) ^ p->n) ^ (int)(p->enc_matrix)) ) { p->magic != ( ( (FEC_MAGIC ^ p->k) ^ p->n) ^ (int)((long)p->enc_matrix)) ) {
fprintf(stderr, "bad parameters to fec_free\n"); fprintf(stderr, "bad parameters to fec_free\n");
return ; return ;
} }
@ -675,11 +677,11 @@ fec_new(int k, int n)
k, n, GF_SIZE ); k, n, GF_SIZE );
return NULL ; return NULL ;
} }
retval = my_malloc(sizeof(struct fec_parms), "new_code"); retval = (struct fec_parms *)my_malloc(sizeof(struct fec_parms), "new_code");
retval->k = k ; retval->k = k ;
retval->n = n ; retval->n = n ;
retval->enc_matrix = NEW_GF_MATRIX(n, k); retval->enc_matrix = NEW_GF_MATRIX(n, k);
retval->magic = ( ( FEC_MAGIC ^ k) ^ n) ^ (int)(retval->enc_matrix) ; retval->magic = ( ( FEC_MAGIC ^ k) ^ n) ^ (int)((long)retval->enc_matrix) ;
tmp_m = NEW_GF_MATRIX(n, k); tmp_m = NEW_GF_MATRIX(n, k);
/* /*
* fill the matrix with powers of field elements, starting from 0. * fill the matrix with powers of field elements, starting from 0.
@ -722,8 +724,12 @@ fec_new(int k, int n)
* with index "index". * with index "index".
*/ */
void void
fec_encode(struct fec_parms *code, gf *src[], gf *fec, int index, int sz) fec_encode(void *code0, void *src0[], void *fec0, int index, int sz)
//fec_encode(struct fec_parms *code0, gf *src[], gf *fec, int index, int sz)
{ {
struct fec_parms * code= (struct fec_parms *)code0;
gf **src=(gf**) src0;
gf* fec=(gf*)fec0;
int i, k = code->k ; int i, k = code->k ;
gf *p ; gf *p ;
@ -829,8 +835,11 @@ build_decode_matrix(struct fec_parms *code, gf *pkt[], int index[])
* sz: size of each packet * sz: size of each packet
*/ */
int int
fec_decode(struct fec_parms *code, gf *pkt[], int index[], int sz) fec_decode(void *code0, void *pkt0[], int index[], int sz)
//fec_decode(struct fec_parms *code, gf *pkt[], int index[], int sz)
{ {
struct fec_parms * code=(struct fec_parms*)code0;
gf **pkt=(gf**)pkt0;
gf *m_dec ; gf *m_dec ;
gf **new_pkt ; gf **new_pkt ;
int row, col , k = code->k ; int row, col , k = code->k ;
@ -847,10 +856,10 @@ fec_decode(struct fec_parms *code, gf *pkt[], int index[], int sz)
/* /*
* do the actual decoding * do the actual decoding
*/ */
new_pkt = my_malloc (k * sizeof (gf * ), "new pkt pointers" ); new_pkt = (gf** )my_malloc (k * sizeof (gf * ), "new pkt pointers" );
for (row = 0 ; row < k ; row++ ) { for (row = 0 ; row < k ; row++ ) {
if (index[row] >= k) { if (index[row] >= k) {
new_pkt[row] = my_malloc (sz * sizeof (gf), "new pkt buffer" ); new_pkt[row] = (gf*)my_malloc (sz * sizeof (gf), "new pkt buffer" );
bzero(new_pkt[row], sz * sizeof(gf) ) ; bzero(new_pkt[row], sz * sizeof(gf) ) ;
for (col = 0 ; col < k ; col++ ) for (col = 0 ; col < k ; col++ )
addmul(new_pkt[row], pkt[col], m_dec[row*k + col], sz) ; addmul(new_pkt[row], pkt[col], m_dec[row*k + col], sz) ;

8
lib/rs.c Normal file
View File

@ -0,0 +1,8 @@
/*
* rs.c
*
* Created on: Sep 14, 2017
* Author: root
*/

22
lib/rs.h Normal file
View File

@ -0,0 +1,22 @@
/*
* rs.h
*
* Created on: Sep 14, 2017
* Author: root
*/
#ifndef LIB_RS_H_
#define LIB_RS_H_
#include "fec.h"
int rs_encode(void *code,void *data[],int size);
int rs_recover_data(void *code,void *data[],int size);
int rs_recover_all(void *code,void *data[],int size);
#endif /* LIB_RS_H_ */

View File

@ -1,7 +1,7 @@
#include "common.h" #include "common.h"
#include "log.h" #include "log.h"
#include "git_version.h" #include "git_version.h"
#include "lib/rs.h"
using namespace std; using namespace std;
typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64 typedef unsigned long long u64_t; //this works on most platform,avoid using the PRId64

View File

@ -6,9 +6,9 @@ cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16.
#cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm #cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm
cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++ cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++
#cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ #cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
SOURCES=main.cpp log.cpp common.cpp SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c
NAME=speeder NAME=speeder
TARGETS=amd64 arm mips24kc_be x86 mips24kc_le TARGETS=amd64 arm mips24kc_be x86 mips24kc_le