Reorganisation

This commit is contained in:
2024-09-24 15:10:42 +02:00
parent 4bef1a61fe
commit 92ca442431
8 changed files with 6 additions and 79 deletions

View File

@@ -12,7 +12,7 @@ if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "")
set(CMAKE_INSTALL_CONFIG_NAME "DEBUG")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()

BIN
src/C++/Socket/a.out Executable file

Binary file not shown.

33
src/C++/Socket/main.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <cstring>
#include <iostream>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
int serverSocket = socket(AF_INET, SOCK_STREAM, 0);
using namespace std;
int main()
{
sockaddr_in serverAddress;
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(4204);
serverAddress.sin_addr.s_addr = INADDR_ANY;
bind(serverSocket, (struct sockaddr *)&serverAddress, sizeof(serverAddress));
listen(serverSocket, 5);
int clientSocket = accept(serverSocket, nullptr, nullptr);
char buffer[1024] = {0};
recv(clientSocket, buffer, sizeof(buffer), 0);
cout << "Message from client: " << buffer << endl;
close(serverSocket);
return 0;
}
// https://www.geeksforgeeks.org/socket-programming-in-cpp/

View File

@@ -1,60 +0,0 @@
//before running set right baudrate
//sudo stty -F /dev/ttyUSB0 speed 115200 cs8 -cstopb -parenb
//TODO: Fix the first output of the buffer
#include <fstream>
#include <iostream>
#include <cstring>
#include <vector>
#include <iomanip>
int main() {
char byte;
bool foundAA = false;
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;
return 1;
}
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 size" << buffer.size() << std::endl << std::endl;
// Print the buffer in hex values
for (int i = 0; i < 4; i++) {
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(static_cast<unsigned char>(buffer[i])) << " ";
}
//reset buffer after new 0XAA and 0x55 is found
buffer.clear();
foundAA = false; // Reset the state
if (ubyte == 0b10101010)
foundAA = true;
} else {
foundAA = false; // Reset the state if the next byte is not 0x55
}
} else if (ubyte == 0b10101010) { // 0xAA
foundAA = true;
}
}
f.close();
return 0;
}
//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

Binary file not shown.

View File

@@ -1,18 +0,0 @@
#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

Binary file not shown.