feat: introduce udp state machine

This commit is contained in:
2025-09-24 21:23:00 +02:00
parent 921eec3848
commit 51bd7bd909
2 changed files with 169 additions and 99 deletions

View File

@@ -7,6 +7,8 @@
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <map>
#include <vector>
#include <functional>
class ClusterManager {
public:
@@ -26,4 +28,22 @@ public:
private:
NodeContext& ctx;
TaskManager& taskManager;
enum class ListenState { WAITING_FOR_PACKET, MESSAGE_RECEIVED, DISPATCHING, DONE };
struct MessageHandler {
bool (*predicate)(const char*);
std::function<void(const char*)> handle;
const char* name;
};
void initMessageHandlers();
void handleIncomingMessage(const char* incoming);
static bool isDiscoveryMsg(const char* msg);
static bool isHeartbeatMsg(const char* msg);
static bool isResponseMsg(const char* msg);
static bool isNodeInfoMsg(const char* msg);
void onDiscovery(const char* msg);
void onHeartbeat(const char* msg);
void onResponse(const char* msg);
void onNodeInfo(const char* msg);
ListenState listenState = ListenState::WAITING_FOR_PACKET;
std::vector<MessageHandler> messageHandlers;
};