⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example.c

📁 RS译码器的C源代码,采用了BM算法
💻 C
字号:
/* Example use of Reed-Solomon library  * * (C) Universal Access Inc. 1996 * * This same code demonstrates the use of the encodier and  * decoder/error-correction routines.  * * We are assuming we have at least four bytes of parity (NPAR >= 4). *  * This gives us the ability to correct up to two errors, or  * four erasures.  * * In general, with E errors, and K erasures, you will need * 2E + K bytes of parity to be able to correct the codeword * back to recover the original message data. * * You could say that each error 'consumes' two bytes of the parity, * whereas each erasure 'consumes' one byte. * * Thus, as demonstrated below, we can inject one error (location unknown) * and two erasures (with their locations specified) and the  * error-correction routine will be able to correct the codeword * back to the original message. * */ #include <stdio.h>#include <stdlib.h>#include "ecc.h" //unsigned char msg[] ="000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";//"Nervously I loaded the twin ducks aboard the revolving platform.";

//unsigned char msg[] ="000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";//"Nervously I loaded the twin ducks aboard the revolving platform.";
unsigned char msg[] ="000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";//"Nervously I loaded the twin ducks aboard the revolving platform.";

unsigned char codeword[256]; /* Some debugging routines to introduce errors or erasures   into a codeword.    *//* Introduce a byte error at LOC */voidbyte_err (int err, int loc, unsigned char *dst){  printf("Adding Error at loc %d, data %#x\n", loc, dst[loc-1]);  dst[loc-1] ^= err;}/* Pass in location of error (first byte position is   labeled starting at 1, not 0), and the codeword.*/voidbyte_erasure (int loc, unsigned char dst[], int cwsize, int erasures[]) {  printf("Erasure at loc %d, data %#x\n", loc, dst[loc-1]);  dst[loc-1] = 0;}voidmain (int argc, char *argv[]){   int erasures[32];  int nerasures = 0;
  //int i;  /* Initialization the ECC library */   initialize_ecc ();
  /* ************** */   /* Encode data into codeword, adding NPAR parity bytes */  encode_data(msg, sizeof(msg), codeword);
 /*printf("Encoded data is: \"%s\"\n", codeword);
    for(i=0;i<256;i++)
	  printf("Encoded data is: %d\n", codeword[i]); */#define ML (sizeof (msg) + NPAR)  byte_err(0x35, 16, codeword);
  byte_err(0x35, 17, codeword);  byte_err(0x23, 18, codeword);  byte_err(0x34, 19, codeword);
  byte_err(0x35, 20, codeword);
  byte_err(0x23, 21, codeword);
  byte_err(0x34, 22, codeword);
  byte_err(0x35, 23, codeword);
  byte_err(0x35, 50, codeword);
  byte_err(0x35, 51, codeword);
  byte_err(0x23, 52, codeword);
  byte_err(0x34, 53, codeword);
  byte_err(0x35, 54, codeword);
  byte_err(0x23, 55, codeword);
  byte_err(0x34, 56, codeword);
  byte_err(0x35, 57, codeword);
  byte_err(0x35, 90, codeword);
  byte_err(0x23, 91, codeword);
  byte_err(0x34, 92, codeword);
  byte_err(0x35, 93, codeword);
  byte_err(0x23, 94, codeword);
  byte_err(0x34, 95, codeword);
  byte_err(0x23, 96, codeword);
  byte_err(0x23, 120, codeword);

  byte_err(0x34, 150, codeword);
  byte_err(0x35, 151, codeword);
  byte_err(0x23, 152, codeword);
  byte_err(0x34, 180, codeword);
  byte_err(0x34, 181, codeword);
  byte_err(0x34, 188, codeword);
  byte_err(0x35, 189, codeword);
  byte_err(0x35, 190, codeword);
  byte_err(0x35, 191, codeword);

 

  



  printf("with some errors: \"%s\"\n", codeword);  /* We need to indicate the position of the erasures.  Eraseure     positions are indexed (1 based) from the end of the message... */ /* for(i=0;i<256;i++)
	  printf("Encoded data is: %d\n", codeword[i]);   /* Now decode -- encoded codeword size must be passed */  decode_data(codeword, ML);  /* check if syndrome is all zeros */  if (check_syndrome () != 0) {    correct_errors_erasures (codeword, 			     ML,			     nerasures, 			     erasures);     printf("Corrected codeword: \"%s\"\n", codeword);  }   exit(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -