diff --git a/main/main.c b/main/main.c index 36f10f7..f27e699 100644 --- a/main/main.c +++ b/main/main.c @@ -1,4 +1,3 @@ -#include "assert.h" #include "driver/gpio.h" #include "driver/uart.h" #include "esp_log.h" @@ -8,92 +7,8 @@ #include "esp_wifi.h" #include "hal/uart_types.h" #include "nvs_flash.h" -#include "portmacro.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include "main.h" - -#define MASTER_MODE_PIN GPIO_NUM_23 // Jumper-Erkennungspin -#define MASTER_UART UART_NUM_2 -#define BROADCAST_INTERVAL_MS 500 - -#define BUF_SIZE (1024) -#define TXD_PIN (GPIO_NUM_17) -#define RXD_PIN (GPIO_NUM_16) - -#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 -const char *TAG = "ALOX"; - -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; - // return any inactive client field for new usage int getNextFreeClientId() { for (int i = 0; i < numClients; i++) { diff --git a/main/main.h b/main/main.h index ebfa484..5294a12 100644 --- a/main/main.h +++ b/main/main.h @@ -1,4 +1,89 @@ #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 MASTER_UART UART_NUM_2 +#define BROADCAST_INTERVAL_MS 500 + +#define BUF_SIZE (1024) +#define TXD_PIN (GPIO_NUM_17) +#define RXD_PIN (GPIO_NUM_16) + +#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 +const char *TAG = "ALOX"; + +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