updated to vectors

This commit is contained in:
2024-09-18 13:19:34 +02:00
parent 03f1d2d8d0
commit 423799ffbd

View File

@@ -1,11 +1,14 @@
//before running set right baudrate
//sudo stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include <vector>
int main() { int main() {
char byte; char byte;
bool foundAA = false; bool foundAA = false;
bool capture = false; std::vector<char> buffer;
unsigned int buffer;
std::ifstream f("/dev/ttyUSB0", std::ios::binary); std::ifstream f("/dev/ttyUSB0", std::ios::binary);
if (!f.is_open()) { if (!f.is_open()) {
std::cerr << "Failed to open the file" << std::endl; std::cerr << "Failed to open the file" << std::endl;
@@ -14,11 +17,12 @@ int main() {
while (f.read(&byte, 1)) { while (f.read(&byte, 1)) {
unsigned char ubyte = static_cast<unsigned char>(byte); unsigned char ubyte = static_cast<unsigned char>(byte);
buffer.push_back(ubyte);
if (foundAA) { if (foundAA) {
if (ubyte == 0b01010101) { // 0x55 if (ubyte == 0b01010101) { // 0x55
std::cout << "Found 0xAA followed by 0x55" << std::endl; std::cout << "Found 0xAA followed by 0x55" << std::endl;
std::cout << buffer.sizeof << std::endl; std::cout << buffer.size() << std::endl; //display size of buffer
buffer = 0; buffer.clear();
foundAA = false; // Reset the state foundAA = false; // Reset the state
} else { } else {
foundAA = false; // Reset the state if the next byte is not 0x55 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 //Tomorrow
//Try to use vectors and store every byte in its own array object by dividing the buffer into 8 bits //Try to use vectors and store every byte in its own array object by dividing the buffer into 8 bits