-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Hi,
I don't know much about the reed Solomon coding but i have to implement one of the error correction method for my data on UART.
Maximum data length is 32 bytes.
I kept the minimum distance 32,polynomial 0x1f5 and it looks like it is able to recover up to 16 bytes of corrupted data.Can you please confirm if the behaviour is correct or not. also is it possible to increase the error correction rate from 16 byte to more?
#include "correct.h"
#include <stdint.h>
#include <stdio.h>
#include<string.h>
#include <time.h>
#include <stdlib.h>
#define ERROR -1
#define MIN_DISTANCE 32U
int EncodeBuffer(uint8_t * original_buff,uint8_t *encodedBuff,uint8_t len);
int DecodeBuffer(uint8_t * encoded_buff,uint8_t *original_buff,uint8_t len);
/Globals/
uint8_t msg[32];
uint8_t msg_out[64];
uint8_t msg_in[32];
int main(void)
{
#if 1
srand(time(NULL));
//Writing dummy data to buffers
while(1){
printf("======================================================START======================================================\n");
for (int i = 0; i < sizeof(msg); i++)
msg[i] = i;
printf("Original MSG\n");
for(int i=0;i<sizeof(msg);i++)
printf("%X ",msg[i]);
printf("\n");
EncodeBuffer(msg,msg_out,sizeof(msg));
//curropting the encoded buffer
#if 0
int r =0;
for(int i=0;i<16;i++)
{
r = rand() % 32;
//printf("random num =%d ",r);
msg_out[r] = ~msg_out[r];//0xff;
}
#endif
printf("error MSG\n");
for(int i=0;i<sizeof(msg_out);i++)
printf("%X ", msg_out[i]);
printf("\n");
if(ERROR == DecodeBuffer(msg_out,msg_in,sizeof(msg_out)))
{
printf("UNABLE TO DECODE\n");
}
else
{
printf("MSG decoded successfully\n");
for(int i=0;i<sizeof(msg_in);i++)
printf("%X ", msg_in[i]);
printf("\n");
}
memset(msg,0x00,sizeof(msg));
memset(msg_out,0x00,sizeof(msg_out));
memset(msg_in,0x00,sizeof(msg_in));
printf("======================================================END======================================================\n");
sleep(2);
}
#endif
return 0;
}
int EncodeBuffer(uint8_t * original_buff,uint8_t *encodedBuff,uint8_t len)
{
int code = 0;
correct_reed_solomon *rs = correct_reed_solomon_create(0x1f5, 6,1, MIN_DISTANCE);
code = correct_reed_solomon_encode(rs, original_buff, len, encodedBuff);
//print encoded msg
printf("MSG Encoded\n");
for(int i=0;i<sizeof(msg_out);i++){
printf("%X ", encodedBuff[i]);}
printf("\n");
correct_reed_solomon_destroy(rs);
return code;
}
int DecodeBuffer(uint8_t * encoded_buff,uint8_t *original_buff,uint8_t len)
{
int code = 0;
correct_reed_solomon *rs = correct_reed_solomon_create(0x1f5, 6,1, MIN_DISTANCE);
code = correct_reed_solomon_decode(rs, encoded_buff, len, original_buff);
printf("No of bytes decoded = %d \n",code);
printf("\n");
correct_reed_solomon_destroy(rs);
return code;
}
///////////////////////////////////////////OUTPUT
======================================================START======================================================
Original MSG
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
MSG Encoded
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 4A 9D 11 9 28 61 FC AE A4 AF 8D FA 4D C6 D7 97 46 56 76 30 CE D8 4C 3A C6 63 9B FB C7 53 8E 58
error MSG
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 4A 9D 11 9 28 61 FC AE A4 AF 8D FA 4D C6 D7 97 46 56 76 30 CE D8 4C 3A C6 63 9B FB C7 53 8E 58
No of bytes decoded = 32
MSG decoded successfully
0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
======================================================END======================================================