/* Example use of Reed-Solomon library * * Copyright Henry Minsky (hqm@alum.mit.edu) 1991-2009 * * This software library is licensed under terms of the GNU GENERAL * PUBLIC LICENSE * * RSCODE 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. * * RSCODE 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 Rscode. If not, see . * Commercial licensing is available under a separate license, please * contact author for details. * * 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 #include #include "ecc.h" #include "dersol_code.h" #define ML (K_LENGTH + NPAR) unsigned char msg0[K_LENGTH] = {0xD4, 0xBA, 0xA1, 0x12, 0xF2, 0x74, 0x96,\ 0x30, 0x27, 0xD4, 0x88, 0x9C, 0x96, 0xE3,\ 0xA9, 0x52, 0xB3, 0x15, 0xAB, 0xFD, 0x92,\ 0x53, 0x07, 0x32, 0xC0, 0x62, 0x48, 0xF0,\ 0x19, 0x22, 0xE0, 0x91, 0x62, 0x1A, 0xC1}; unsigned char msg1[N_LENGTH]; unsigned char codeword[N_LENGTH], decodedword[N_LENGTH]; /* Some debugging routines to introduce errors or erasures into a codeword. */ /* Introduce a byte error at LOC */ void byte_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. */ void byte_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; } void fill_prefix(unsigned char msgori[], int data_size, unsigned char msgdst[]) { int i; unsigned char msg1[N_LENGTH]; /*FILL PREFIX WITH 0x00*/ for(i=0; i<(K_LENGTH-data_size); i++)msg1[i]=0x00; for(i=0; i