refactor(comms): clean up Communication folder structure
- Delete dead code: CommandHandler (700-line God Class) and
HTTPRequestHandler — both replaced by new architecture in Stage 4
- Create Drivers/ group for the three low-level protocol drivers,
mirroring the Transport/ pattern:
MQTTAsyncClient → Drivers/MQTTDriver (class: MQTTDriver)
WebSocketServer → Drivers/WebSocketDriver (class: WebSocketDriver)
UARTCommandHandler → Drivers/UARTDriver (class: UARTDriver)
- Update all includes and type references across CommunicationRouter,
all three Transport wrappers, and MQTTHandler
- Add -std=gnu++14 + build_unflags to platformio.ini so std::make_unique
compiles on ESP32 (required by CommunicationRouter::registerHandlers)
Build: passing
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#define TAG "MQTTTransport"
|
||||
#include "../../../Logging/Logging.hpp"
|
||||
|
||||
MQTTTransport::MQTTTransport(MQTTAsyncClient& mqttClient, CommandBus& bus)
|
||||
MQTTTransport::MQTTTransport(MQTTDriver& mqttClient, CommandBus& bus)
|
||||
: _mqtt(mqttClient)
|
||||
, _bus(bus) {
|
||||
}
|
||||
@@ -31,7 +31,7 @@ bool MQTTTransport::isHealthy() const {
|
||||
}
|
||||
|
||||
void MQTTTransport::broadcast(const String& message) {
|
||||
_mqtt.publish("", message); // MQTTAsyncClient::publish() routes "" → _dataTopic
|
||||
_mqtt.publish("", message); // MQTTDriver::publish() routes "" → _dataTopic
|
||||
}
|
||||
|
||||
void MQTTTransport::onNetworkConnected() {
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../ITransport.hpp"
|
||||
#include "../../MQTTAsyncClient/MQTTAsyncClient.hpp"
|
||||
#include "../../Drivers/MQTTDriver/MQTTDriver.hpp"
|
||||
|
||||
class CommandBus;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// MQTTTransport
|
||||
//
|
||||
// ITransport wrapper around the existing MQTTAsyncClient.
|
||||
// ITransport wrapper around the existing MQTTDriver.
|
||||
//
|
||||
// Responsibilities:
|
||||
// - Delegates connection lifecycle to MQTTAsyncClient
|
||||
// - Delegates connection lifecycle to MQTTDriver
|
||||
// - Parses incoming MQTT JSON messages into CommandEnvelopes
|
||||
// - Injects a reply lambda that publishes the response to the data topic
|
||||
// - Dispatches to the CommandBus
|
||||
// - broadcast() publishes to the device data topic (telemetry, events)
|
||||
//
|
||||
// The underlying MQTTAsyncClient (and its timers, heartbeat, reconnect logic)
|
||||
// The underlying MQTTDriver (and its timers, heartbeat, reconnect logic)
|
||||
// is unchanged — this transport just owns the bus glue.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
class MQTTTransport : public ITransport {
|
||||
public:
|
||||
MQTTTransport(MQTTAsyncClient& mqttClient, CommandBus& bus);
|
||||
MQTTTransport(MQTTDriver& mqttClient, CommandBus& bus);
|
||||
|
||||
void begin() override;
|
||||
void loop() override; // no-op — AsyncMqttClient is fully async
|
||||
@@ -40,9 +40,9 @@ public:
|
||||
void onNetworkDisconnected();
|
||||
|
||||
private:
|
||||
MQTTAsyncClient& _mqtt;
|
||||
MQTTDriver& _mqtt;
|
||||
CommandBus& _bus;
|
||||
|
||||
// Invoked by MQTTAsyncClient's message callback
|
||||
// Invoked by MQTTDriver's message callback
|
||||
void onMessage(const String& topic, const String& payload);
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ const size_t UARTTransport::WHITELIST_SIZE =
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
UARTTransport::UARTTransport(UARTCommandHandler& uart, CommandBus& bus)
|
||||
UARTTransport::UARTTransport(UARTDriver& uart, CommandBus& bus)
|
||||
: _uart(uart)
|
||||
, _bus(bus) {
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../ITransport.hpp"
|
||||
#include "../../UARTCommandHandler/UARTCommandHandler.hpp"
|
||||
#include "../../Drivers/UARTDriver/UARTDriver.hpp"
|
||||
|
||||
class CommandBus;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UARTTransport
|
||||
//
|
||||
// ITransport wrapper around the existing UARTCommandHandler.
|
||||
// ITransport wrapper around the existing UARTDriver.
|
||||
//
|
||||
// The UART port talks to a slave LCD/button board. Only a small whitelist of
|
||||
// commands are accepted from this transport to prevent feedback loops and
|
||||
@@ -31,10 +31,10 @@ class CommandBus;
|
||||
|
||||
class UARTTransport : public ITransport {
|
||||
public:
|
||||
UARTTransport(UARTCommandHandler& uart, CommandBus& bus);
|
||||
UARTTransport(UARTDriver& uart, CommandBus& bus);
|
||||
|
||||
void begin() override;
|
||||
void loop() override; // polls UARTCommandHandler::loop()
|
||||
void loop() override; // polls UARTDriver::loop()
|
||||
bool isHealthy() const override;
|
||||
String name() const override { return "UART"; }
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void broadcast(const String& message) override;
|
||||
|
||||
private:
|
||||
UARTCommandHandler& _uart;
|
||||
UARTDriver& _uart;
|
||||
CommandBus& _bus;
|
||||
|
||||
// Commands the UART slave is allowed to issue
|
||||
@@ -51,6 +51,6 @@ private:
|
||||
|
||||
bool isWhitelisted(const String& command) const;
|
||||
|
||||
// Invoked by UARTCommandHandler's message callback
|
||||
// Invoked by UARTDriver's message callback
|
||||
void onMessage(JsonDocument& doc);
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define TAG "WebSocketTransport"
|
||||
#include "../../../Logging/Logging.hpp"
|
||||
|
||||
WebSocketTransport::WebSocketTransport(WebSocketServer& wsServer, CommandBus& bus)
|
||||
WebSocketTransport::WebSocketTransport(WebSocketDriver& wsServer, CommandBus& bus)
|
||||
: _ws(wsServer)
|
||||
, _bus(bus) {
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "../ITransport.hpp"
|
||||
#include "../../WebSocketServer/WebSocketServer.hpp"
|
||||
#include "../../Drivers/WebSocketDriver/WebSocketDriver.hpp"
|
||||
|
||||
class CommandBus;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WebSocketTransport
|
||||
//
|
||||
// ITransport wrapper around the existing WebSocketServer.
|
||||
// ITransport wrapper around the existing WebSocketDriver.
|
||||
//
|
||||
// Responsibilities:
|
||||
// - Delegates connection lifecycle and client management to WebSocketServer
|
||||
// - Delegates connection lifecycle and client management to WebSocketDriver
|
||||
// - Parses incoming WebSocket JSON messages into CommandEnvelopes
|
||||
// - Injects a reply lambda that sends the response back to the originating client
|
||||
// - Dispatches to the CommandBus
|
||||
@@ -24,7 +24,7 @@ class CommandBus;
|
||||
|
||||
class WebSocketTransport : public ITransport {
|
||||
public:
|
||||
WebSocketTransport(WebSocketServer& wsServer, CommandBus& bus);
|
||||
WebSocketTransport(WebSocketDriver& wsServer, CommandBus& bus);
|
||||
|
||||
void begin() override;
|
||||
void loop() override; // no-op — AsyncWebServer is event-driven
|
||||
@@ -45,9 +45,9 @@ public:
|
||||
size_t getClientCount() const;
|
||||
|
||||
private:
|
||||
WebSocketServer& _ws;
|
||||
WebSocketDriver& _ws;
|
||||
CommandBus& _bus;
|
||||
|
||||
// Invoked by WebSocketServer's message callback
|
||||
// Invoked by WebSocketDriver's message callback
|
||||
void onMessage(uint32_t clientId, const JsonDocument& doc);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user