From 07d5b2fb81f0b683eb8e92e0ecc98e89b8f1ca83 Mon Sep 17 00:00:00 2001 From: bonamin Date: Fri, 10 Jul 2026 19:53:54 +0300 Subject: [PATCH] feat(F-038,F-039): bell and clock test fire commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit relay.test_bell — fire bell N using configured output + duration, non-blocking relay.test_batch — fire a list of bells simultaneously (single melody step) clock.test_c1 — fire C1 (ODD) clock output using pulse_duration clock.test_c2 — fire C2 (EVEN) clock output using pulse_duration All four bypass bellsEnabled guard intentionally — test commands always fire. ClockHandler now accepts an optional OutputManager* for the test commands. CommunicationRouter passes _outputManager to ClockHandler. Feature catalog updated: F-038 and F-039 added. Co-Authored-By: Claude Sonnet 4.6 --- docs/features/feature-catalog.md | 34 ++++++++++ .../CommunicationRouter.cpp | 2 +- .../Handlers/ClockHandler/ClockHandler.cpp | 36 ++++++++++- .../Handlers/ClockHandler/ClockHandler.hpp | 6 +- .../Handlers/RelayHandler/RelayHandler.cpp | 62 ++++++++++++++++++- .../Handlers/RelayHandler/RelayHandler.hpp | 2 + 6 files changed, 136 insertions(+), 6 deletions(-) diff --git a/docs/features/feature-catalog.md b/docs/features/feature-catalog.md index b095785..a0a0448 100644 --- a/docs/features/feature-catalog.md +++ b/docs/features/feature-catalog.md @@ -47,6 +47,8 @@ Every feature — user-facing or significant internal mechanism — is listed he | F-035 | System aggregate commands (`system.get_config`, `system.get_all`, `system.get_telemetry`) | v2.1.0 | Stable | | F-036 | Per-subsystem config getters (`log.get_config`, `mqtt.get_config`, `bells.get_config`) | v2.1.0 | Stable | | F-037 | Network status extended (SSID + MAC in `network.status`) | v2.1.0 | Stable | +| F-038 | Bell test fire commands (`relay.test_bell` / `relay.test_batch`) | v2.1.0 | Stable | +| F-039 | Clock output test fire commands (`clock.test_c1` / `clock.test_c2`) | v2.1.0 | Stable | --- @@ -492,3 +494,35 @@ Subsystem: `src/Communication/Handlers/LoggingHandler/`, `src/Communication/Hand - `hostname`: device hostname from `NetworkConfig` Subsystem: `src/Communication/Handlers/NetworkHandler/NetworkHandler.cpp` + +--- + +### F-038 — Bell test fire commands (`relay.test_bell` / `relay.test_batch`) + +Two non-blocking test commands for firing bells on demand, bypassing the `bellsEnabled` guard (manual tests always work regardless of the master switch): + +| Command | Behaviour | +|---|---| +| `relay.test_bell` | Fire bell channel N using its configured output and duration. Non-blocking — OutputManager timer handles the shutoff. Can be sent in rapid succession like piano keys. | +| `relay.test_batch` | Fire a list of bell channels simultaneously (like a single melody step). Each bell fires for its own configured duration. | + +Both commands read output and duration from `ConfigManager` (same values as real playback). Returns the resolved output and duration so the caller can confirm what was fired. + +Subsystem: `src/Communication/Handlers/RelayHandler/RelayHandler.cpp` + +--- + +### F-039 — Clock output test fire commands (`clock.test_c1` / `clock.test_c2`) + +Two test commands for verifying clock relay wiring without waiting for the next scheduled clock strike: + +| Command | Behaviour | +|---|---| +| `clock.test_c1` | Fire the C1 (ODD) clock output immediately for `pulse_duration` ms | +| `clock.test_c2` | Fire the C2 (EVEN) clock output immediately for `pulse_duration` ms | + +Both use `OutputManager::fireClockOutput()` which resolves the physical pin from `ClockConfig`. Returns the output name and actual duration used. + +`ClockHandler` constructor now accepts an optional `OutputManager*` (defaults to `nullptr`); the router passes `_outputManager` so the test commands are live when the output manager is registered. + +Subsystem: `src/Communication/Handlers/ClockHandler/ClockHandler.cpp` diff --git a/src/Communication/CommunicationRouter/CommunicationRouter.cpp b/src/Communication/CommunicationRouter/CommunicationRouter.cpp index 0e29779..6b521ca 100644 --- a/src/Communication/CommunicationRouter/CommunicationRouter.cpp +++ b/src/Communication/CommunicationRouter/CommunicationRouter.cpp @@ -254,7 +254,7 @@ void CommunicationRouter::registerHandlers() { #if HAS_RTC // Clock if (_timeKeeper) { - _bus.registerHandler(std::make_unique(_configManager, *_timeKeeper)); + _bus.registerHandler(std::make_unique(_configManager, *_timeKeeper, _outputManager)); } #endif diff --git a/src/Communication/Handlers/ClockHandler/ClockHandler.cpp b/src/Communication/Handlers/ClockHandler/ClockHandler.cpp index b06d2ab..96c71d7 100644 --- a/src/Communication/Handlers/ClockHandler/ClockHandler.cpp +++ b/src/Communication/Handlers/ClockHandler/ClockHandler.cpp @@ -2,12 +2,13 @@ #include "ClockHandler.hpp" #include "../../../ConfigManager/ConfigManager.hpp" #include "../../../TimeKeeper/TimeKeeper.hpp" +#include "../../../OutputManager/OutputManager.hpp" #include "../../../Logging/Logging.hpp" #define TAG "ClockHandler" -ClockHandler::ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper) - : _configManager(configManager), _timeKeeper(timeKeeper) {} +ClockHandler::ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper, OutputManager* outputManager) + : _configManager(configManager), _timeKeeper(timeKeeper), _outputManager(outputManager) {} std::vector ClockHandler::commands() const { return { @@ -17,7 +18,8 @@ std::vector ClockHandler::commands() const { "clock.set_timezone", "clock.get_timezone", "clock.sync_ntp", "clock.enable", "clock.disable", "clock.pause", "clock.resume", - "clock.get_face", "clock.get_config" + "clock.get_face", "clock.get_config", + "clock.test_c1", "clock.test_c2" }; } @@ -38,6 +40,8 @@ CommandResult ClockHandler::execute(const CommandEnvelope& envelope) { if (envelope.command == "clock.resume") return handleResume(envelope); if (envelope.command == "clock.get_face") return handleGetFace(envelope); if (envelope.command == "clock.get_config") return handleGetConfig(envelope); + if (envelope.command == "clock.test_c1") return handleTestC1(envelope); + if (envelope.command == "clock.test_c2") return handleTestC2(envelope); return CommandResult::err(envelope.command, "Unknown clock command"); } @@ -247,4 +251,30 @@ CommandResult ClockHandler::handleGetConfig(const CommandEnvelope& e) { return CommandResult::ok("clock.get_config", doc); } +CommandResult ClockHandler::handleTestC1(const CommandEnvelope& e) { + if (!_outputManager) { + return CommandResult::err("clock.test_c1", "OutputManager not available"); + } + uint16_t durationMs = _configManager.getClockPulseDuration(); + _outputManager->fireClockOutput(0, durationMs); + LOG_INFO(TAG, "Test C1 fired for %d ms", durationMs); + JsonDocument doc; + doc["output"] = "C1"; + doc["duration_ms"] = durationMs; + return CommandResult::ok("clock.test_c1", doc); +} + +CommandResult ClockHandler::handleTestC2(const CommandEnvelope& e) { + if (!_outputManager) { + return CommandResult::err("clock.test_c2", "OutputManager not available"); + } + uint16_t durationMs = _configManager.getClockPulseDuration(); + _outputManager->fireClockOutput(1, durationMs); + LOG_INFO(TAG, "Test C2 fired for %d ms", durationMs); + JsonDocument doc; + doc["output"] = "C2"; + doc["duration_ms"] = durationMs; + return CommandResult::ok("clock.test_c2", doc); +} + #endif // HAS_RTC diff --git a/src/Communication/Handlers/ClockHandler/ClockHandler.hpp b/src/Communication/Handlers/ClockHandler/ClockHandler.hpp index 8031145..7b4e4ef 100644 --- a/src/Communication/Handlers/ClockHandler/ClockHandler.hpp +++ b/src/Communication/Handlers/ClockHandler/ClockHandler.hpp @@ -7,10 +7,11 @@ class ConfigManager; class Timekeeper; +class OutputManager; class ClockHandler : public ICommandHandler { public: - ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper); + ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper, OutputManager* outputManager = nullptr); std::vector commands() const override; CommandResult execute(const CommandEnvelope& envelope) override; @@ -18,6 +19,7 @@ public: private: ConfigManager& _configManager; Timekeeper& _timeKeeper; + OutputManager* _outputManager; CommandResult handleSetOutputs(const CommandEnvelope& e); CommandResult handleSetTimings(const CommandEnvelope& e); @@ -35,6 +37,8 @@ private: CommandResult handleResume(const CommandEnvelope& e); CommandResult handleGetFace(const CommandEnvelope& e); CommandResult handleGetConfig(const CommandEnvelope& e); + CommandResult handleTestC1(const CommandEnvelope& e); + CommandResult handleTestC2(const CommandEnvelope& e); }; #endif // HAS_RTC diff --git a/src/Communication/Handlers/RelayHandler/RelayHandler.cpp b/src/Communication/Handlers/RelayHandler/RelayHandler.cpp index 29ebac7..f867f2e 100644 --- a/src/Communication/Handlers/RelayHandler/RelayHandler.cpp +++ b/src/Communication/Handlers/RelayHandler/RelayHandler.cpp @@ -10,7 +10,10 @@ RelayHandler::RelayHandler(ConfigManager& configManager, OutputManager& outputMa : _configManager(configManager), _outputManager(outputManager), _player(player) {} std::vector RelayHandler::commands() const { - return { "relay.set_durations", "relay.set_outputs", "relay.get_config", "relay.test_output" }; + return { + "relay.set_durations", "relay.set_outputs", "relay.get_config", + "relay.test_output", "relay.test_bell", "relay.test_batch" + }; } CommandResult RelayHandler::execute(const CommandEnvelope& envelope) { @@ -18,6 +21,8 @@ CommandResult RelayHandler::execute(const CommandEnvelope& envelope) { if (envelope.command == "relay.set_outputs") return handleSetOutputs(envelope); if (envelope.command == "relay.get_config") return handleGetConfig(envelope); if (envelope.command == "relay.test_output") return handleTestOutput(envelope); + if (envelope.command == "relay.test_bell") return handleTestBell(envelope); + if (envelope.command == "relay.test_batch") return handleTestBatch(envelope); return CommandResult::err(envelope.command, "Unknown relay command"); } @@ -89,3 +94,58 @@ CommandResult RelayHandler::handleTestOutput(const CommandEnvelope& e) { return CommandResult::ok("relay.test_output", "Output " + String(output) + " fired for " + String(durationMs) + " ms"); } + +CommandResult RelayHandler::handleTestBell(const CommandEnvelope& e) { + if (!e.contents["bell"].is()) { + return CommandResult::err("relay.test_bell", "Missing required field: bell (0-based bell index)"); + } + int bell = e.contents["bell"].as(); + if (bell < 0 || bell > 15) { + return CommandResult::err("relay.test_bell", "bell must be 0-15"); + } + + uint8_t output = (uint8_t)_configManager.getBellOutput(bell); + uint16_t durationMs = _configManager.getBellDuration(bell); + + _outputManager.fireOutputForDuration(output, durationMs); + LOG_INFO(TAG, "Test bell %d → output %d for %d ms", bell, output, durationMs); + + JsonDocument doc; + doc["bell"] = bell; + doc["output"] = output; + doc["duration_ms"] = durationMs; + return CommandResult::ok("relay.test_bell", doc); +} + +CommandResult RelayHandler::handleTestBatch(const CommandEnvelope& e) { + if (!e.contents["bells"].is()) { + return CommandResult::err("relay.test_batch", "Missing required field: bells (array of 0-based bell indices)"); + } + + JsonArrayConst bellArr = e.contents["bells"].as(); + if (bellArr.size() == 0) { + return CommandResult::err("relay.test_batch", "bells array must not be empty"); + } + + // Fire each bell for its configured duration — non-blocking (OutputManager handles timers) + // Bypasses bellsEnabled intentionally: test commands always fire + int fired = 0; + for (JsonVariantConst v : bellArr) { + if (!v.is()) continue; + int bell = v.as(); + if (bell < 0 || bell > 15) continue; + uint8_t output = (uint8_t)_configManager.getBellOutput((uint8_t)bell); + uint16_t durationMs = _configManager.getBellDuration((uint8_t)bell); + _outputManager.fireOutputForDuration(output, durationMs); + fired++; + } + + if (fired == 0) { + return CommandResult::err("relay.test_batch", "No valid bell indices in array"); + } + + LOG_INFO(TAG, "Test batch: %d bells fired", fired); + JsonDocument doc; + doc["fired"] = fired; + return CommandResult::ok("relay.test_batch", doc); +} diff --git a/src/Communication/Handlers/RelayHandler/RelayHandler.hpp b/src/Communication/Handlers/RelayHandler/RelayHandler.hpp index 74e32a9..66d7ed9 100644 --- a/src/Communication/Handlers/RelayHandler/RelayHandler.hpp +++ b/src/Communication/Handlers/RelayHandler/RelayHandler.hpp @@ -23,4 +23,6 @@ private: CommandResult handleSetOutputs(const CommandEnvelope& e); CommandResult handleGetConfig(const CommandEnvelope& e); CommandResult handleTestOutput(const CommandEnvelope& e); + CommandResult handleTestBell(const CommandEnvelope& e); + CommandResult handleTestBatch(const CommandEnvelope& e); };