64 lines
1.6 KiB
Arduino
64 lines
1.6 KiB
Arduino
|
#include "RS-FEC.h"
|
||
|
|
||
|
const int msglen = 60;
|
||
|
const uint8_t ECC_LENGTH = 10; //Max message lenght, and "gurdian bytes", Max corrected bytes ECC_LENGTH/2
|
||
|
//char message_frame[msglen]; // The message size would be different, so need a container
|
||
|
char repaired[msglen];
|
||
|
char encoded[msglen + ECC_LENGTH];
|
||
|
|
||
|
RS::ReedSolomon<msglen, ECC_LENGTH> rs;
|
||
|
|
||
|
void setup() {
|
||
|
Serial.begin(1200);
|
||
|
}
|
||
|
|
||
|
//void loop() {
|
||
|
// if(Serial.available()) {
|
||
|
// //Serial.print(char(Serial.read()));
|
||
|
//
|
||
|
// encoded =
|
||
|
//
|
||
|
// rs.Decode(encoded, repaired);
|
||
|
//
|
||
|
//
|
||
|
//
|
||
|
// Serial.println(repaired);
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
void loop() {
|
||
|
static String received_data = ""; // Static variable to hold received data
|
||
|
while (Serial.available()) {
|
||
|
char received_char = Serial.read(); // Read a character from serial port
|
||
|
|
||
|
// Check for newline character or received_data is too long
|
||
|
if (received_char == '\n' || received_data.length() > 128) {
|
||
|
|
||
|
Serial.println("========= Received data =========");
|
||
|
//Serial.println(received_data); // Print the received data
|
||
|
|
||
|
//rs.Decode(myCharArray, repaired);
|
||
|
|
||
|
//Serial.println(repaired);
|
||
|
|
||
|
// convert String to char array of encoded data that has to be decoded with predefinied lenght
|
||
|
received_data.toCharArray(encoded, msglen + ECC_LENGTH);
|
||
|
|
||
|
|
||
|
|
||
|
Serial.println(encoded);
|
||
|
|
||
|
rs.Decode(encoded, repaired);
|
||
|
|
||
|
Serial.println(repaired);
|
||
|
|
||
|
Serial.println("---------------------------------");
|
||
|
|
||
|
|
||
|
|
||
|
received_data = ""; // Reset the input buffer
|
||
|
} else {
|
||
|
received_data += received_char; // Append the received character to the buffer
|
||
|
}
|
||
|
}
|
||
|
}
|