mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
start kobuki driver
This commit is contained in:
40
src/C++/main.cpp
Normal file
40
src/C++/main.cpp
Normal 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
BIN
src/C++/main.o
Normal file
Binary file not shown.
18
src/C++/makefile
Normal file
18
src/C++/makefile
Normal 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
BIN
src/C++/progr
Executable file
Binary file not shown.
Reference in New Issue
Block a user