From 423799ffbd5a275a3c8f1820eb54c5c7d65ec913 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Wed, 18 Sep 2024 13:19:34 +0200 Subject: [PATCH] updated to vectors --- src/C++/main.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/C++/main.cpp b/src/C++/main.cpp index 2494251..5065b0f 100644 --- a/src/C++/main.cpp +++ b/src/C++/main.cpp @@ -1,11 +1,14 @@ +//before running set right baudrate +//sudo stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb #include #include #include +#include + int main() { char byte; bool foundAA = false; - bool capture = false; - unsigned int buffer; + std::vector buffer; std::ifstream f("/dev/ttyUSB0", std::ios::binary); if (!f.is_open()) { std::cerr << "Failed to open the file" << std::endl; @@ -14,11 +17,12 @@ int main() { while (f.read(&byte, 1)) { unsigned char ubyte = static_cast(byte); + buffer.push_back(ubyte); if (foundAA) { if (ubyte == 0b01010101) { // 0x55 std::cout << "Found 0xAA followed by 0x55" << std::endl; - std::cout << buffer.sizeof << std::endl; - buffer = 0; + std::cout << buffer.size() << std::endl; //display size of buffer + buffer.clear(); foundAA = false; // Reset the state } else { foundAA = false; // Reset the state if the next byte is not 0x55 @@ -36,5 +40,11 @@ int main() { +//Tomorrow +//Try to use vectors and store every byte in its own array object by dividing the buffer into 8 bits + + + + //Tomorrow //Try to use vectors and store every byte in its own array object by dividing the buffer into 8 bits \ No newline at end of file