start kobuki driver

This commit is contained in:
2024-09-17 16:01:06 +02:00
parent dad976d776
commit d4b3beda6f
4 changed files with 58 additions and 0 deletions

40
src/C++/main.cpp Normal file
View File

@@ -0,0 +1,40 @@
#include <fstream>
#include <iostream>
#include <cstring>
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<unsigned char>(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

BIN
src/C++/main.o Normal file

Binary file not shown.

18
src/C++/makefile Normal file
View File

@@ -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

BIN
src/C++/progr Executable file

Binary file not shown.