Refactored main.h
This commit is contained in:
parent
e211e708a3
commit
c7b86f96d8
85
main/main.c
85
main/main.c
@ -1,4 +1,3 @@
|
|||||||
#include "assert.h"
|
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
@ -8,92 +7,8 @@
|
|||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "hal/uart_types.h"
|
#include "hal/uart_types.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.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>
|
|
||||||
|
|
||||||
#include "main.h"
|
#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
|
// return any inactive client field for new usage
|
||||||
int getNextFreeClientId() {
|
int getNextFreeClientId() {
|
||||||
for (int i = 0; i < numClients; i++) {
|
for (int i = 0; i < numClients; i++) {
|
||||||
|
|||||||
85
main/main.h
85
main/main.h
@ -1,4 +1,89 @@
|
|||||||
#ifndef MAIN_H
|
#ifndef MAIN_H
|
||||||
#define 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
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user