| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <inttypes.h> |
| 18 |
#include <errno.h> |
| 19 |
#include <sys/types.h> |
| 20 |
#include <sys/stat.h> |
| 21 |
#include <fcntl.h> |
| 22 |
#include <stdio.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <unistd.h> |
| 25 |
#include <string.h> |
| 26 |
#include <fec.h> |
| 27 |
|
| 28 |
#define FEC_RSM 255 |
| 29 |
#define FEC_ROOTS 16 |
| 30 |
#define FEC_RSN (FEC_RSM - FEC_ROOTS) |
| 31 |
#define FEC_PARAMS(roots) \ |
| 32 |
8, 0x11d, 0, 1, (roots), 0 |
| 33 |
|
| 34 |
int main() |
| 35 |
{ |
| 36 |
uint8_t data[FEC_RSM]; |
| 37 |
uint8_t dupl[FEC_RSM]; |
| 38 |
uint8_t corr[FEC_RSM]; |
| 39 |
int i, rc, neras, errors; |
| 40 |
int erasures[FEC_RSM]; |
| 41 |
void *rs; |
| 42 |
|
| 43 |
memset(data, 0x00, sizeof(data)); |
| 44 |
memset(corr, 0x00, sizeof(corr)); |
| 45 |
|
| 46 |
rs = init_rs_char(FEC_PARAMS(FEC_ROOTS)); |
| 47 |
|
| 48 |
if (!rs) { |
| 49 |
perror("init_rs_char"); |
| 50 |
exit(1); |
| 51 |
} |
| 52 |
|
| 53 |
encode_rs_char(rs, data, &corr[FEC_RSN]); |
| 54 |
|
| 55 |
for (neras = 1; neras <= FEC_ROOTS; ++neras) { |
| 56 |
printf("%d errors\n", neras); |
| 57 |
|
| 58 |
for (i = 0; i < neras; ++i) { |
| 59 |
corr[i] = 0xFD; |
| 60 |
erasures[i] = i; |
| 61 |
} |
| 62 |
|
| 63 |
memcpy(dupl, corr, sizeof(corr)); |
| 64 |
|
| 65 |
rc = decode_rs_char(rs, corr, NULL, 0); |
| 66 |
|
| 67 |
printf("\tno erasures: %d\n", rc); |
| 68 |
|
| 69 |
errors = 0; |
| 70 |
for (i = 0; i < FEC_RSN; ++i) { |
| 71 |
if (corr[i] != 0x00) { |
| 72 |
printf("\t\terror at %d (%02x)\n", i, corr[i]); |
| 73 |
++errors; |
| 74 |
} |
| 75 |
} |
| 76 |
printf("\t\t%d errors in output\n", errors); |
| 77 |
|
| 78 |
rc = decode_rs_char(rs, dupl, erasures, neras); |
| 79 |
|
| 80 |
printf("\terasures: %d\n", rc); |
| 81 |
|
| 82 |
errors = 0; |
| 83 |
for (i = 0; i < FEC_RSN; ++i) { |
| 84 |
if (dupl[i] != 0x00) { |
| 85 |
printf("\t\terror at %d (%02x)\n", i, dupl[i]); |
| 86 |
++errors; |
| 87 |
} |
| 88 |
} |
| 89 |
printf("\t\t%d errors in output\n", errors); |
| 90 |
} |
| 91 |
|
| 92 |
exit(0); |
| 93 |
} |