Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79

This commit is contained in:
ishak jmilou.ishak
2024-09-18 13:26:57 +02:00
2 changed files with 18 additions and 5 deletions

5
.gitignore vendored
View File

@@ -1 +1,4 @@
.history
.history
src/C++/main.o
src/C++/progr
.vscode/settings.json

View File

@@ -1,11 +1,14 @@
//before running set right baudrate
//sudo stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb
#include <fstream>
#include <iostream>
#include <cstring>
#include <vector>
int main() {
char byte;
bool foundAA = false;
bool capture = false;
unsigned int buffer;
std::vector<char> 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<unsigned char>(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