From 9e26b7da84e76e7a377f2e5cae1a3a4a3ddedfd0 Mon Sep 17 00:00:00 2001 From: Looki2000 Date: Sun, 12 Mar 2023 15:49:33 +0100 Subject: [PATCH] first commit, transmitter - reed solomon working, receiver - reed solomon not working. only receiving --- .../arduino ir receiver.ino | 64 +++++++++++++++++++ .../arduino ir transmitter.ino | 43 +++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 arduino ir transmitter receiver/arduino ir receiver.ino create mode 100644 arduino ir transmitter receiver/arduino ir transmitter.ino diff --git a/arduino ir transmitter receiver/arduino ir receiver.ino b/arduino ir transmitter receiver/arduino ir receiver.ino new file mode 100644 index 0000000..994e337 --- /dev/null +++ b/arduino ir transmitter receiver/arduino ir receiver.ino @@ -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 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 + } + } +} \ No newline at end of file diff --git a/arduino ir transmitter receiver/arduino ir transmitter.ino b/arduino ir transmitter receiver/arduino ir transmitter.ino new file mode 100644 index 0000000..a908874 --- /dev/null +++ b/arduino ir transmitter receiver/arduino ir transmitter.ino @@ -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 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); + + +} \ No newline at end of file