#ifndef MAIN_H #define MAIN_H #include "assert.h" #include "portmacro.h" #include #include #include #include #include #include #include #include #include #include #define MASTER_MODE_PIN GPIO_NUM_23 // Jumper-Erkennungspin #define BROADCAST_INTERVAL_MS 500 #define CLIENT_TIMEOUT_MS 5000 // 5 Sekunden Timeout #define CHECK_INTERVAL_MS 1000 // Jede Sekunde überprüfen uint8_t broadcast_address[ESP_NOW_ETH_ALEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; #define IS_BROADCAST_ADDR(addr) \ (memcmp(addr, broadcast_address, ESP_NOW_ETH_ALEN) == 0) typedef enum { BroadCastPage, StatusPage, PingPage, RegisterPage, } CommandPages; typedef struct { uint32_t uptime; uint8_t status; } StatusPayload; typedef struct { uint32_t timestamp; } PingPayload; typedef struct { } BroadCastPayload; typedef struct { bool familierClient; } RegisterPayload; typedef union { StatusPayload status_payload; PingPayload ping_payload; BroadCastPayload broadcast_payload; RegisterPayload register_payload; } PayloadUnion; typedef struct { uint16_t version; CommandPages commandPage; uint16_t length; PayloadUnion payload; } BaseMessage; static_assert(sizeof(BaseMessage) <= 255, "BaseMessage darf nicht größer als 255 sein"); QueueHandle_t messageQueue; // Warteschlange für empfangene Nachrichten typedef struct { uint8_t macAddr[ESP_NOW_ETH_ALEN]; int rssi; bool isAvailable; TickType_t lastSuccessfullPing; } ClientInfo; #define MAX_CLIENTS 19 ClientInfo clients[MAX_CLIENTS]; size_t numClients = 0; size_t activeClients = 0; bool hasMaster = false; #endif