diff --git a/src/C++/main.cpp b/src/C++/main.cpp new file mode 100644 index 0000000..8567ca7 --- /dev/null +++ b/src/C++/main.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +int main() { + char byte; + bool foundAA = false; + bool capture = false; + char buffer[200]; + std::ifstream f("/dev/ttyUSB0", std::ios::binary); + if (!f.is_open()) { + std::cerr << "Failed to open the file" << std::endl; + return 1; + } + + while (f.read(&byte, 1)) { + unsigned char ubyte = static_cast(byte); + if (foundAA) { + capture = true; + if (ubyte == 0b01010101) { // 0x55 + std::cout << "Found 0xAA followed by 0x55" << std::endl; + memset(buffer, 0, sizeof(buffer)); // Clear the buffer + foundAA = false; // Reset the state + } else { + foundAA = false; // Reset the state if the next byte is not 0x55 + capture = false; // Stop capturing + } + } else if (ubyte == 0b10101010) { // 0xAA + foundAA = true; + } + if (capture) { + std::cout << buffer[200] << std::endl; + } + } + + f.close(); + return 0; +} + + +void \ No newline at end of file diff --git a/src/C++/main.o b/src/C++/main.o new file mode 100644 index 0000000..aafde35 Binary files /dev/null and b/src/C++/main.o differ diff --git a/src/C++/makefile b/src/C++/makefile new file mode 100644 index 0000000..af7de6e --- /dev/null +++ b/src/C++/makefile @@ -0,0 +1,18 @@ +#clean this up for seperate build folder +CPPFLAGS = -Wall -I./include +CC=g++ + +#target : main.o +# g++ * -Wall +progr: main.o + $(CC) $^ $(CPPFLAGS) -o progr #S^ stands for all dependencies + @echo "ready" + +main.o: main.cpp #may be omitted (implicit rule) + $(CC) $(CPPFLAGS) -c -o main.o main.cpp + +clean: + rm progr + rm *.o + + diff --git a/src/C++/progr b/src/C++/progr new file mode 100755 index 0000000..f4ed328 Binary files /dev/null and b/src/C++/progr differ