90 lines
1.9 KiB
C
90 lines
1.9 KiB
C
#ifndef MAIN_H
|
|
#define MAIN_H
|
|
|
|
#include "assert.h"
|
|
#include "portmacro.h"
|
|
#include <esp_event.h>
|
|
#include <esp_now.h>
|
|
#include <esp_wifi.h>
|
|
#include <freertos/FreeRTOS.h>
|
|
#include <freertos/queue.h>
|
|
#include <freertos/task.h>
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.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;
|
|
|
|
#endif
|