first commit, transmitter - reed solomon working, receiver - reed solomon not working. only receiving
This commit is contained in:
parent
1707de5ec6
commit
9e26b7da84
64
arduino ir transmitter receiver/arduino ir receiver.ino
Normal file
64
arduino ir transmitter receiver/arduino ir receiver.ino
Normal file
@ -0,0 +1,64 @@
|
||||
#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
|
||||
}
|
||||
}
|
||||
}
|
43
arduino ir transmitter receiver/arduino ir transmitter.ino
Normal file
43
arduino ir transmitter receiver/arduino ir transmitter.ino
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include "RS-FEC.h"
|
||||
|
||||
char message[] = "Amogus is very suspicious creature!";
|
||||
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;
|
||||
|
||||
#define ir_mod_pin 12
|
||||
|
||||
void setup() {
|
||||
pinMode(ir_mod_pin, OUTPUT);
|
||||
tone(ir_mod_pin, 38000);
|
||||
|
||||
Serial.begin(1200);
|
||||
while (!Serial); // wait for serial to initialize
|
||||
|
||||
memset(message_frame, 0, sizeof(message_frame)); // Clear the array
|
||||
|
||||
for(int i = 0; i <= msglen; i++) {
|
||||
message_frame[i] = message[i];
|
||||
} // Fill with the message
|
||||
|
||||
rs.Encode(message_frame, encoded);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
for(int i = 0; i < sizeof(encoded); i++) {
|
||||
Serial.print(encoded[i]);
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
|
||||
delay(2500);
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user