feat: multi-board HAL guards, RFRemote subsystem, Player/OTA improvements

Multi-board variant support:
- variants/vesper.hpp: enable HAS_RF=1, define RF_RX_PIN=22
- variants/agnus.hpp: enable HAS_RF=1, RF_RX_PIN=22, correct HAS_RTC=0
- main.cpp, Player, HealthMonitor, OTAManager, ConfigManager: wrap all
  RTC/SD/RF-dependent code in #if HAS_RTC / HAS_SD_CARD / HAS_RF guards
  so Agnus builds cleanly without those peripherals

RFRemote subsystem (new):
- src/RFRemote/: RF receiver driver (GPIO RF_RX_PIN) + command handler
- Registered with HealthMonitor and CommunicationRouter when HAS_RF=1

Player improvements:
- uid -> pid rename throughout (Player, BuiltInMelodies, api-reference)
- loadMelodyInRAM() now returns bool
- playerControlTaskFn task added — defers stop/pause/resume out of
  timer callback (Tmr Svc) to avoid stack overflows
- setDependencies() accepts nullptr FileManager for SD-less boards

OTAManager:
- Consume download_url from server metadata response instead of
  constructing firmware path locally
- HTTP redirect following enabled (setFollowRedirects)
- HAS_RTC guards on TimeKeeper references

platformio.ini:
- Add rc-switch library for RF remote support
- Remove BOARD_TYPE/BOARD_NAME/BOARD_VERSION flags (moved to variant headers)
- MQTT_SECRET placeholders only — no secrets in source

Docs:
- docs/architecture/codebase-refactor-plan.md: new migration strategy doc
- docs/reference/api-reference.md: updated for pid, note_assignments, download_url
- Remove stale docs: ota-telemetry-api.md, platformio-commands.md, firmware-variants.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 17:02:01 +02:00
co-authored by Claude Sonnet 4.6
parent 37b65cc15a
commit a4d071d5d5
31 changed files with 2431 additions and 891 deletions
@@ -15,7 +15,9 @@
#include "../../Logging/Logging.hpp"
#include "../../Player/Player.hpp"
#include "../../FileManager/FileManager.hpp"
#if HAS_RTC
#include "../../TimeKeeper/TimeKeeper.hpp"
#endif
#include "../../FirmwareValidator/FirmwareValidator.hpp"
#include "../../Telemetry/Telemetry.hpp"
#include "../../HealthMonitor/HealthMonitor.hpp"
@@ -24,14 +26,19 @@
// Domain handlers
#include "../Handlers/PlaybackHandler/PlaybackHandler.hpp"
#include "../Handlers/RelayHandler/RelayHandler.hpp"
#if HAS_RTC
#include "../Handlers/ClockHandler/ClockHandler.hpp"
#include "../Handlers/SystemHandler/SystemHandler.hpp"
#endif
#include "../Handlers/FirmwareHandler/FirmwareHandler.hpp"
#include "../Handlers/NetworkHandler/NetworkHandler.hpp"
#include "../Handlers/FileHandler/FileHandler.hpp"
#include "../Handlers/LoggingHandler/LoggingHandler.hpp"
#include "../Handlers/TelemetryHandler/TelemetryHandler.hpp"
#include "../Handlers/MQTTHandler/MQTTHandler.hpp"
#if HAS_RF
#include "../../RFRemote/RFRemoteHandler.hpp"
#endif
// ─────────────────────────────────────────────────────────────────────────────
// Constructor
@@ -169,9 +176,11 @@ void CommunicationRouter::setFileManagerReference(FileManager* fm) {
}
}
#if HAS_RTC
void CommunicationRouter::setTimeKeeperReference(Timekeeper* tk) {
_timeKeeper = tk;
}
#endif
void CommunicationRouter::setFirmwareValidatorReference(FirmwareValidator* fv) {
_firmwareValidator = fv;
@@ -189,6 +198,12 @@ void CommunicationRouter::setOutputManagerReference(OutputManager* om) {
_outputManager = om;
}
#if HAS_RF
void CommunicationRouter::setRFRemoteReference(RFRemote* rf) {
_rfRemote = rf;
}
#endif
// ─────────────────────────────────────────────────────────────────────────────
// registerHandlers()
// ─────────────────────────────────────────────────────────────────────────────
@@ -197,7 +212,9 @@ void CommunicationRouter::registerHandlers() {
// Log any missing optional dependencies so issues surface at boot, not later.
if (!_player) LOG_ERROR(TAG, "registerHandlers: _player is null — PlaybackHandler, RelayHandler, FirmwareHandler, SystemHandler skipped");
if (!_fileManager) LOG_ERROR(TAG, "registerHandlers: _fileManager is null — FileHandler skipped");
#if HAS_RTC
if (!_timeKeeper) LOG_ERROR(TAG, "registerHandlers: _timeKeeper is null — ClockHandler skipped");
#endif
if (!_firmwareValidator) LOG_ERROR(TAG, "registerHandlers: _firmwareValidator is null — FirmwareHandler skipped");
if (!_telemetry) LOG_ERROR(TAG, "registerHandlers: _telemetry is null — TelemetryHandler and SystemHandler skipped");
if (!_healthMonitor) LOG_WARNING(TAG, "registerHandlers: _healthMonitor is null — system.health unavailable");
@@ -213,17 +230,21 @@ void CommunicationRouter::registerHandlers() {
_bus.registerHandler(std::make_unique<RelayHandler>(_configManager, *_outputManager, *_player));
}
#if HAS_RTC
// Clock
if (_timeKeeper) {
_bus.registerHandler(std::make_unique<ClockHandler>(_configManager, *_timeKeeper));
}
#endif
// System — requires player, telemetry, healthMonitor, timeKeeper, clientManager
#if HAS_RTC
if (_player && _telemetry && _healthMonitor && _timeKeeper) {
_bus.registerHandler(std::make_unique<SystemHandler>(
_configManager, *_player, *_telemetry, *_healthMonitor,
*_timeKeeper, _clientManager));
}
#endif
// Firmware / OTA
if (_firmwareValidator && _player) {
@@ -250,6 +271,13 @@ void CommunicationRouter::registerHandlers() {
// MQTT control (enable / disable)
_bus.registerHandler(std::make_unique<MQTTHandler>(_configManager, _mqttClient));
#if HAS_RF
// RF remote control
if (_rfRemote) {
_bus.registerHandler(std::make_unique<RFRemoteHandler>(*_rfRemote));
}
#endif
LOG_INFO(TAG, "All domain handlers registered on CommandBus");
}
@@ -323,11 +351,19 @@ size_t CommunicationRouter::getWebSocketClientCount() const {
}
bool CommunicationRouter::isHealthy() const {
if (!_player || !_fileManager || !_timeKeeper) {
LOG_WARNING(TAG, "Unhealthy — missing subsystem references (player=%d fileManager=%d timeKeeper=%d)",
_player != nullptr, _fileManager != nullptr, _timeKeeper != nullptr);
#if HAS_RTC
if (!_player || !_timeKeeper) {
LOG_WARNING(TAG, "Unhealthy — missing subsystem references (player=%d timeKeeper=%d)",
_player != nullptr, _timeKeeper != nullptr);
return false;
}
#else
if (!_player) {
LOG_WARNING(TAG, "Unhealthy — missing subsystem references (player=%d)",
_player != nullptr);
return false;
}
#endif
if (!_networking.isConnected()) {
LOG_WARNING(TAG, "Unhealthy — no network connection");
return false;
@@ -37,12 +37,17 @@ class ConfigManager;
class OTAManager;
class Player;
class FileManager;
#if HAS_RTC
class Timekeeper;
#endif
class Networking;
class FirmwareValidator;
class Telemetry;
class HealthMonitor;
class OutputManager;
#if HAS_RF
class RFRemote;
#endif
class CommunicationRouter {
public:
@@ -64,11 +69,16 @@ public:
// setXxxReference() calls have been made.
void setPlayerReference(Player* player);
void setFileManagerReference(FileManager* fm);
#if HAS_RTC
void setTimeKeeperReference(Timekeeper* tk);
#endif
void setFirmwareValidatorReference(FirmwareValidator* fv);
void setTelemetryReference(Telemetry* telemetry);
void setHealthMonitorReference(HealthMonitor* hm);
void setOutputManagerReference(OutputManager* om);
#if HAS_RF
void setRFRemoteReference(RFRemote* rf);
#endif
// UDP discovery (called by main.cpp)
void setupUdpDiscovery();
@@ -133,11 +143,16 @@ private:
// Late-bound (set via setXxxReference after construction)
Player* _player = nullptr;
FileManager* _fileManager = nullptr;
#if HAS_RTC
Timekeeper* _timeKeeper = nullptr;
#endif
FirmwareValidator* _firmwareValidator = nullptr;
Telemetry* _telemetry = nullptr;
HealthMonitor* _healthMonitor = nullptr;
OutputManager* _outputManager = nullptr;
#if HAS_RF
RFRemote* _rfRemote = nullptr;
#endif
// ── Underlying protocol objects (owned) ─────────────────────────────────
MQTTDriver _mqttClient;
@@ -1,3 +1,4 @@
#if HAS_RTC
#include "ClockHandler.hpp"
#include "../../../ConfigManager/ConfigManager.hpp"
#include "../../../TimeKeeper/TimeKeeper.hpp"
@@ -245,3 +246,5 @@ CommandResult ClockHandler::handleGetConfig(const CommandEnvelope& e) {
doc["night_off"] = cc.nighttimeSilenceOffTime;
return CommandResult::ok("clock.get_config", doc);
}
#endif // HAS_RTC
@@ -1,5 +1,7 @@
#pragma once
#if HAS_RTC
#include <vector>
#include "../ICommandHandler.hpp"
@@ -34,3 +36,5 @@ private:
CommandResult handleGetFace(const CommandEnvelope& e);
CommandResult handleGetConfig(const CommandEnvelope& e);
};
#endif // HAS_RTC
@@ -1,3 +1,4 @@
#if HAS_RTC
#include "SystemHandler.hpp"
#include "../../../ConfigManager/ConfigManager.hpp"
#include "../../../Player/Player.hpp"
@@ -202,3 +203,5 @@ CommandResult SystemHandler::handleRestart(const CommandEnvelope& e) {
}, "restartTask", 1024, nullptr, 1, nullptr);
return CommandResult::ok("system.restart", "Device will restart in 2 seconds");
}
#endif // HAS_RTC
@@ -1,5 +1,7 @@
#pragma once
#if HAS_RTC
#include <vector>
#include "../ICommandHandler.hpp"
@@ -37,3 +39,5 @@ private:
CommandResult handleFactoryReset(const CommandEnvelope& e);
CommandResult handleRestart(const CommandEnvelope& e);
};
#endif // HAS_RTC