feat(comms): Stage 2 — all 10 domain handlers implemented
Adds the complete set of v2 command handlers. Old CommandHandler is
untouched — handlers are standalone and not yet wired to anything.
Handlers added:
PlaybackHandler — playback (1 dependency)
LoggingHandler — log.set_serial/sd/mqtt
FileHandler — files.list/list_builtin/download/delete
TelemetryHandler — telemetry.get_strikes/reset_strikes/get_loads
RelayHandler — relay.set_durations/set_outputs/get_config/test_output
FirmwareHandler — firmware.status/commit/rollback + ota.update/custom
NetworkHandler — network.info/status/set_config
MQTTHandler — mqtt.enable/disable
SystemHandler — ping/identify + system.* commands (8 total)
ClockHandler — 16 clock.* commands
Notable fixes vs. original CommandHandler:
- clock.set_timings now sets pulseDuration/pauseDuration correctly
(original called updateClockOutputs — was a bug)
- system.restart uses a deferred FreeRTOS task (no blocking delay)
- relay.test_output safety-gated: player must be fully stopped
- Timekeeper class name (lowercase k) corrected throughout
Two compile-time fixes applied during build:
- JsonVariantConst → const_cast<JsonDocument&>().as<JsonVariant>()
(ConfigManager methods take non-const JsonVariant)
- class TimeKeeper → class Timekeeper (actual class name in header)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,247 @@
|
|||||||
|
#include "ClockHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../TimeKeeper/TimeKeeper.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "ClockHandler"
|
||||||
|
|
||||||
|
ClockHandler::ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper)
|
||||||
|
: _configManager(configManager), _timeKeeper(timeKeeper) {}
|
||||||
|
|
||||||
|
std::vector<String> ClockHandler::commands() const {
|
||||||
|
return {
|
||||||
|
"clock.set_outputs", "clock.set_timings", "clock.set_alerts",
|
||||||
|
"clock.set_backlight", "clock.set_silence",
|
||||||
|
"clock.set_time", "clock.set_face",
|
||||||
|
"clock.set_timezone", "clock.get_timezone", "clock.sync_ntp",
|
||||||
|
"clock.enable", "clock.disable",
|
||||||
|
"clock.pause", "clock.resume",
|
||||||
|
"clock.get_face", "clock.get_config"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "clock.set_outputs") return handleSetOutputs(envelope);
|
||||||
|
if (envelope.command == "clock.set_timings") return handleSetTimings(envelope);
|
||||||
|
if (envelope.command == "clock.set_alerts") return handleSetAlerts(envelope);
|
||||||
|
if (envelope.command == "clock.set_backlight") return handleSetBacklight(envelope);
|
||||||
|
if (envelope.command == "clock.set_silence") return handleSetSilence(envelope);
|
||||||
|
if (envelope.command == "clock.set_time") return handleSetTime(envelope);
|
||||||
|
if (envelope.command == "clock.set_face") return handleSetFace(envelope);
|
||||||
|
if (envelope.command == "clock.set_timezone") return handleSetTimezone(envelope);
|
||||||
|
if (envelope.command == "clock.get_timezone") return handleGetTimezone(envelope);
|
||||||
|
if (envelope.command == "clock.sync_ntp") return handleSyncNtp(envelope);
|
||||||
|
if (envelope.command == "clock.enable") return handleEnable(envelope);
|
||||||
|
if (envelope.command == "clock.disable") return handleDisable(envelope);
|
||||||
|
if (envelope.command == "clock.pause") return handlePause(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);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown clock command");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetOutputs(const CommandEnvelope& e) {
|
||||||
|
_configManager.updateClockOutputs(const_cast<JsonDocument&>(e.contents).as<JsonVariant>());
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.set_outputs", "Updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_outputs", "Clock outputs updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetTimings(const CommandEnvelope& e) {
|
||||||
|
// Note: original code called updateClockOutputs for timings — that was a bug.
|
||||||
|
// ClockConfig has pulseDuration and pauseDuration fields which should be set directly.
|
||||||
|
bool changed = false;
|
||||||
|
JsonVariantConst c = e.contents.as<JsonVariantConst>();
|
||||||
|
if (c["pulse_duration"].is<int>()) {
|
||||||
|
_configManager.setClockPulseDuration(c["pulse_duration"].as<uint16_t>());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (c["pause_duration"].is<int>()) {
|
||||||
|
_configManager.setClockPauseDuration(c["pause_duration"].as<uint16_t>());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (!changed) {
|
||||||
|
return CommandResult::err("clock.set_timings",
|
||||||
|
"No timing fields provided (pulse_duration, pause_duration)");
|
||||||
|
}
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.set_timings", "Updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_timings", "Clock timings updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetAlerts(const CommandEnvelope& e) {
|
||||||
|
_configManager.updateClockAlerts(const_cast<JsonDocument&>(e.contents).as<JsonVariant>());
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.set_alerts", "Updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_alerts", "Clock alerts updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetBacklight(const CommandEnvelope& e) {
|
||||||
|
_configManager.updateClockBacklight(const_cast<JsonDocument&>(e.contents).as<JsonVariant>());
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.set_backlight", "Updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_backlight", "Clock backlight updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetSilence(const CommandEnvelope& e) {
|
||||||
|
_configManager.updateClockSilence(const_cast<JsonDocument&>(e.contents).as<JsonVariant>());
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.set_silence", "Updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_silence", "Clock silence periods updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetTime(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["timestamp"].is<unsigned long>()) {
|
||||||
|
return CommandResult::err("clock.set_time", "Missing required field: timestamp");
|
||||||
|
}
|
||||||
|
unsigned long timestamp = e.contents["timestamp"].as<unsigned long>();
|
||||||
|
if (timestamp == 0) {
|
||||||
|
return CommandResult::err("clock.set_time", "Invalid timestamp value");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.contents["timezone_offset"].is<long>() && e.contents["dst_offset"].is<long>()) {
|
||||||
|
long tzOffset = e.contents["timezone_offset"].as<long>();
|
||||||
|
long dstOffset = e.contents["dst_offset"].as<long>();
|
||||||
|
long baseGmt = tzOffset - dstOffset;
|
||||||
|
_configManager.updateTimeConfig(baseGmt, dstOffset);
|
||||||
|
_timeKeeper.setTimeWithLocalTimestamp(timestamp + tzOffset);
|
||||||
|
LOG_INFO(TAG, "RTC time + timezone updated");
|
||||||
|
} else {
|
||||||
|
_timeKeeper.setTime(timestamp);
|
||||||
|
LOG_INFO(TAG, "RTC time updated (legacy path, no timezone)");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long verify = _timeKeeper.getTime();
|
||||||
|
if (verify == 0) {
|
||||||
|
return CommandResult::err("clock.set_time", "RTC time set but verification failed");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.set_time", "RTC time updated successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetFace(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["hour"].is<int>() || !e.contents["minute"].is<int>()) {
|
||||||
|
return CommandResult::err("clock.set_face", "Missing required fields: hour, minute");
|
||||||
|
}
|
||||||
|
int hour = e.contents["hour"].as<int>();
|
||||||
|
int minute = e.contents["minute"].as<int>();
|
||||||
|
if (hour < 0 || hour > 23) {
|
||||||
|
return CommandResult::err("clock.set_face", "hour must be 0-23");
|
||||||
|
}
|
||||||
|
if (minute < 0 || minute > 59) {
|
||||||
|
return CommandResult::err("clock.set_face", "minute must be 0-59");
|
||||||
|
}
|
||||||
|
|
||||||
|
int clockHour = hour % 12;
|
||||||
|
if (clockHour == 0) clockHour = 12;
|
||||||
|
|
||||||
|
_configManager.setPhysicalClockHour(clockHour);
|
||||||
|
_configManager.setPhysicalClockMinute(minute);
|
||||||
|
_configManager.setLastSyncTime(millis() / 1000);
|
||||||
|
|
||||||
|
if (!_configManager.saveClockState()) {
|
||||||
|
return CommandResult::err("clock.set_face", "Face set but failed to save to SD");
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG, "Physical clock face set to %02d:%02d", hour, minute);
|
||||||
|
return CommandResult::ok("clock.set_face", "Physical clock face updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSetTimezone(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["gmt_offset_sec"].is<long>()) {
|
||||||
|
return CommandResult::err("clock.set_timezone", "Missing required field: gmt_offset_sec");
|
||||||
|
}
|
||||||
|
long gmtOffset = e.contents["gmt_offset_sec"].as<long>();
|
||||||
|
int dstOffset = e.contents["dst_offset_sec"] | 0;
|
||||||
|
_configManager.updateTimeConfig(gmtOffset, dstOffset);
|
||||||
|
if (!_configManager.saveTimeConfig()) {
|
||||||
|
return CommandResult::err("clock.set_timezone", "Timezone updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG, "Timezone set: GMT%+ld DST%+d", gmtOffset / 3600, dstOffset / 3600);
|
||||||
|
return CommandResult::ok("clock.set_timezone", "Timezone updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleGetTimezone(const CommandEnvelope& e) {
|
||||||
|
const auto& tc = _configManager.getTimeConfig();
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["gmt_offset_sec"] = tc.gmtOffsetSec;
|
||||||
|
doc["dst_offset_sec"] = tc.daylightOffsetSec;
|
||||||
|
doc["ntp_server"] = tc.ntpServer;
|
||||||
|
return CommandResult::ok("clock.get_timezone", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleSyncNtp(const CommandEnvelope& e) {
|
||||||
|
_timeKeeper.syncTimeWithNTP();
|
||||||
|
LOG_INFO(TAG, "NTP sync triggered via command");
|
||||||
|
return CommandResult::ok("clock.sync_ntp", "NTP sync initiated");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleEnable(const CommandEnvelope& e) {
|
||||||
|
_configManager.setClockEnabled(true);
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.enable", "Enabled but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.enable", "Clock enabled and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleDisable(const CommandEnvelope& e) {
|
||||||
|
_configManager.setClockEnabled(false);
|
||||||
|
if (!_configManager.saveClockConfig()) {
|
||||||
|
return CommandResult::err("clock.disable", "Disabled but failed to save to SD");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("clock.disable", "Clock disabled and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handlePause(const CommandEnvelope& e) {
|
||||||
|
_timeKeeper.pauseClockUpdates();
|
||||||
|
return CommandResult::ok("clock.pause", "Clock updates paused");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleResume(const CommandEnvelope& e) {
|
||||||
|
_timeKeeper.resumeClockUpdates();
|
||||||
|
return CommandResult::ok("clock.resume", "Clock updates resumed");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleGetFace(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["clock_hour"] = _configManager.getPhysicalClockHour();
|
||||||
|
doc["clock_minute"] = _configManager.getPhysicalClockMinute();
|
||||||
|
doc["last_sync_time"] = _configManager.getLastSyncTime();
|
||||||
|
doc["next_output_is_c1"] = _configManager.getNextOutputIsC1();
|
||||||
|
return CommandResult::ok("clock.get_face", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult ClockHandler::handleGetConfig(const CommandEnvelope& e) {
|
||||||
|
const auto& cc = _configManager.getClockConfig();
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["enabled"] = cc.enabled;
|
||||||
|
doc["c1output"] = cc.c1output;
|
||||||
|
doc["c2output"] = cc.c2output;
|
||||||
|
doc["pulse_duration"] = cc.pulseDuration;
|
||||||
|
doc["pause_duration"] = cc.pauseDuration;
|
||||||
|
doc["physical_hour"] = cc.physicalHour;
|
||||||
|
doc["physical_minute"] = cc.physicalMinute;
|
||||||
|
doc["next_is_c1"] = cc.nextOutputIsC1;
|
||||||
|
doc["last_sync_time"] = cc.lastSyncTime;
|
||||||
|
doc["alert_type"] = cc.alertType;
|
||||||
|
doc["alert_interval"] = cc.alertRingInterval;
|
||||||
|
doc["hour_bell"] = cc.hourBell;
|
||||||
|
doc["half_bell"] = cc.halfBell;
|
||||||
|
doc["quarter_bell"] = cc.quarterBell;
|
||||||
|
doc["backlight"] = cc.backlight;
|
||||||
|
doc["backlight_output"] = cc.backlightOutput;
|
||||||
|
doc["backlight_on"] = cc.backlightOnTime;
|
||||||
|
doc["backlight_off"] = cc.backlightOffTime;
|
||||||
|
doc["daytime_silence"] = cc.daytimeSilenceEnabled;
|
||||||
|
doc["daytime_on"] = cc.daytimeSilenceOnTime;
|
||||||
|
doc["daytime_off"] = cc.daytimeSilenceOffTime;
|
||||||
|
doc["night_silence"] = cc.nighttimeSilenceEnabled;
|
||||||
|
doc["night_on"] = cc.nighttimeSilenceOnTime;
|
||||||
|
doc["night_off"] = cc.nighttimeSilenceOffTime;
|
||||||
|
return CommandResult::ok("clock.get_config", doc);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
class Timekeeper;
|
||||||
|
|
||||||
|
class ClockHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
ClockHandler(ConfigManager& configManager, Timekeeper& timeKeeper);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
Timekeeper& _timeKeeper;
|
||||||
|
|
||||||
|
CommandResult handleSetOutputs(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetTimings(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetAlerts(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetBacklight(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetSilence(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetTime(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetFace(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetTimezone(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetTimezone(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSyncNtp(const CommandEnvelope& e);
|
||||||
|
CommandResult handleEnable(const CommandEnvelope& e);
|
||||||
|
CommandResult handleDisable(const CommandEnvelope& e);
|
||||||
|
CommandResult handlePause(const CommandEnvelope& e);
|
||||||
|
CommandResult handleResume(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetFace(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetConfig(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
#include "FileHandler.hpp"
|
||||||
|
#include "../../../FileManager/FileManager.hpp"
|
||||||
|
#include "../../../BuiltInMelodies/BuiltInMelodies.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "FileHandler"
|
||||||
|
|
||||||
|
FileHandler::FileHandler(FileManager& fileManager) : _fileManager(fileManager) {}
|
||||||
|
|
||||||
|
std::vector<String> FileHandler::commands() const {
|
||||||
|
return { "files.list", "files.list_builtin", "files.download", "files.delete" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FileHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "files.list") return handleList(envelope);
|
||||||
|
if (envelope.command == "files.list_builtin") return handleListBuiltin(envelope);
|
||||||
|
if (envelope.command == "files.download") return handleDownload(envelope);
|
||||||
|
if (envelope.command == "files.delete") return handleDelete(envelope);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown files command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FileHandler::handleList(const CommandEnvelope& e) {
|
||||||
|
String fileListJson = _fileManager.listFilesAsJson("/melodies");
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError err = deserializeJson(doc, fileListJson);
|
||||||
|
if (err) {
|
||||||
|
LOG_ERROR(TAG, "Failed to parse file list JSON: %s", err.c_str());
|
||||||
|
return CommandResult::err("files.list", "Failed to read melody list");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonDocument result;
|
||||||
|
result["files"] = doc["files"];
|
||||||
|
return CommandResult::ok("files.list", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FileHandler::handleListBuiltin(const CommandEnvelope& e) {
|
||||||
|
String builtinJson = BuiltInMelodies::getBuiltInMelodiesJSON();
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError err = deserializeJson(doc, builtinJson);
|
||||||
|
if (err) {
|
||||||
|
LOG_ERROR(TAG, "Failed to parse built-in melodies JSON: %s", err.c_str());
|
||||||
|
return CommandResult::err("files.list_builtin", "Failed to read built-in melody list");
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandResult::ok("files.list_builtin", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FileHandler::handleDownload(const CommandEnvelope& e) {
|
||||||
|
bool ok = _fileManager.addMelody(const_cast<JsonDocument&>(e.contents).as<JsonVariant>());
|
||||||
|
String uid = e.contents["melodys_uid"] | e.contents["name"] | String("unknown");
|
||||||
|
if (ok) return CommandResult::ok("files.download", "Melody downloaded: " + uid);
|
||||||
|
return CommandResult::err("files.download", "Failed to download melody: " + uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FileHandler::handleDelete(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["name"].is<const char*>()) {
|
||||||
|
return CommandResult::err("files.delete", "Missing required field: name");
|
||||||
|
}
|
||||||
|
String name = e.contents["name"].as<String>();
|
||||||
|
bool ok = _fileManager.deleteFile("/melodies/" + name);
|
||||||
|
if (ok) return CommandResult::ok("files.delete", "Melody deleted: " + name);
|
||||||
|
return CommandResult::err("files.delete", "Failed to delete melody: " + name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class FileManager;
|
||||||
|
|
||||||
|
class FileHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
explicit FileHandler(FileManager& fileManager);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FileManager& _fileManager;
|
||||||
|
|
||||||
|
CommandResult handleList(const CommandEnvelope& e);
|
||||||
|
CommandResult handleListBuiltin(const CommandEnvelope& e);
|
||||||
|
CommandResult handleDownload(const CommandEnvelope& e);
|
||||||
|
CommandResult handleDelete(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
#include "FirmwareHandler.hpp"
|
||||||
|
#include "../../../FirmwareValidator/FirmwareValidator.hpp"
|
||||||
|
#include "../../../OTAManager/OTAManager.hpp"
|
||||||
|
#include "../../../Player/Player.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "FirmwareHandler"
|
||||||
|
|
||||||
|
FirmwareHandler::FirmwareHandler(FirmwareValidator& firmwareValidator,
|
||||||
|
OTAManager& otaManager,
|
||||||
|
Player& player)
|
||||||
|
: _firmwareValidator(firmwareValidator)
|
||||||
|
, _otaManager(otaManager)
|
||||||
|
, _player(player) {}
|
||||||
|
|
||||||
|
std::vector<String> FirmwareHandler::commands() const {
|
||||||
|
return {
|
||||||
|
"firmware.status", "firmware.commit", "firmware.rollback",
|
||||||
|
"ota.update", "ota.custom"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "firmware.status") return handleFirmwareStatus(envelope);
|
||||||
|
if (envelope.command == "firmware.commit") return handleCommit(envelope);
|
||||||
|
if (envelope.command == "firmware.rollback") return handleRollback(envelope);
|
||||||
|
if (envelope.command == "ota.update") return handleOtaUpdate(envelope);
|
||||||
|
if (envelope.command == "ota.custom") return handleOtaCustom(envelope);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown firmware command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::handleFirmwareStatus(const CommandEnvelope& e) {
|
||||||
|
auto validationState = _firmwareValidator.getValidationState();
|
||||||
|
auto currentInfo = _firmwareValidator.getCurrentFirmwareInfo();
|
||||||
|
auto config = _firmwareValidator.getValidationConfig();
|
||||||
|
|
||||||
|
static const char* stateNames[] = {
|
||||||
|
"UNKNOWN", "STARTUP_PENDING", "STARTUP_RUNNING", "RUNTIME_TESTING",
|
||||||
|
"VALIDATED", "FAILED_STARTUP", "FAILED_RUNTIME", "ROLLED_BACK"
|
||||||
|
};
|
||||||
|
const char* stateStr = stateNames[static_cast<int>(validationState)];
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["validation_state"] = stateStr;
|
||||||
|
doc["current_version"] = currentInfo.version;
|
||||||
|
doc["is_testing"] = currentInfo.isTesting;
|
||||||
|
doc["is_valid"] = currentInfo.isValid;
|
||||||
|
doc["boot_count"] = currentInfo.bootCount;
|
||||||
|
doc["build_date"] = currentInfo.buildDate;
|
||||||
|
|
||||||
|
bool inTesting = _firmwareValidator.isInTestingMode();
|
||||||
|
doc["can_commit"] = inTesting;
|
||||||
|
doc["can_rollback"] = (validationState != FirmwareValidationState::VALIDATED);
|
||||||
|
if (inTesting) doc["runtime_timeout_ms"] = config.runtimeTimeoutMs;
|
||||||
|
|
||||||
|
return CommandResult::ok("firmware.status", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::handleCommit(const CommandEnvelope& e) {
|
||||||
|
if (!_firmwareValidator.isInTestingMode()) {
|
||||||
|
return CommandResult::err("firmware.commit", "No firmware validation in progress");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
_firmwareValidator.commitFirmware();
|
||||||
|
LOG_INFO(TAG, "Firmware manually committed");
|
||||||
|
return CommandResult::ok("firmware.commit", "Firmware committed successfully");
|
||||||
|
} catch (...) {
|
||||||
|
return CommandResult::err("firmware.commit", "Failed to commit firmware");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::handleRollback(const CommandEnvelope& e) {
|
||||||
|
try {
|
||||||
|
_firmwareValidator.rollbackFirmware();
|
||||||
|
LOG_WARNING(TAG, "Firmware rollback initiated");
|
||||||
|
return CommandResult::ok("firmware.rollback", "Firmware rollback initiated — device will reboot");
|
||||||
|
} catch (...) {
|
||||||
|
return CommandResult::err("firmware.rollback", "Failed to initiate firmware rollback");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::handleOtaUpdate(const CommandEnvelope& e) {
|
||||||
|
if (_player.isCurrentlyPlaying()) {
|
||||||
|
return CommandResult::err("ota.update", "Cannot update while playback is active");
|
||||||
|
}
|
||||||
|
String channel = e.contents["channel"] | String("stable");
|
||||||
|
LOG_WARNING(TAG, "OTA update requested, channel: %s", channel.c_str());
|
||||||
|
|
||||||
|
// Reply is sent before the update begins so the client gets a response
|
||||||
|
// (the device may reboot mid-update)
|
||||||
|
_otaManager.performManualUpdate(channel);
|
||||||
|
return CommandResult::ok("ota.update", "OTA update started from channel: " + channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult FirmwareHandler::handleOtaCustom(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["firmware_url"].is<const char*>()) {
|
||||||
|
return CommandResult::err("ota.custom", "Missing required field: firmware_url");
|
||||||
|
}
|
||||||
|
if (_player.isCurrentlyPlaying()) {
|
||||||
|
return CommandResult::err("ota.custom", "Cannot update while playback is active");
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = e.contents["firmware_url"].as<String>();
|
||||||
|
String checksum = e.contents["checksum"] | String("");
|
||||||
|
size_t fileSize = e.contents["file_size"] | 0;
|
||||||
|
uint16_t version = e.contents["version"] | 0;
|
||||||
|
|
||||||
|
LOG_WARNING(TAG, "Custom OTA update: %s", url.c_str());
|
||||||
|
_otaManager.performCustomUpdate(url, checksum, fileSize, version);
|
||||||
|
return CommandResult::ok("ota.custom", "Custom OTA update started");
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class FirmwareValidator;
|
||||||
|
class OTAManager;
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
class FirmwareHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
FirmwareHandler(FirmwareValidator& firmwareValidator, OTAManager& otaManager, Player& player);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FirmwareValidator& _firmwareValidator;
|
||||||
|
OTAManager& _otaManager;
|
||||||
|
Player& _player;
|
||||||
|
|
||||||
|
CommandResult handleFirmwareStatus(const CommandEnvelope& e);
|
||||||
|
CommandResult handleCommit(const CommandEnvelope& e);
|
||||||
|
CommandResult handleRollback(const CommandEnvelope& e);
|
||||||
|
CommandResult handleOtaUpdate(const CommandEnvelope& e);
|
||||||
|
CommandResult handleOtaCustom(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#include "LoggingHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "LoggingHandler"
|
||||||
|
|
||||||
|
LoggingHandler::LoggingHandler(ConfigManager& configManager)
|
||||||
|
: _configManager(configManager) {}
|
||||||
|
|
||||||
|
std::vector<String> LoggingHandler::commands() const {
|
||||||
|
return { "log.set_serial", "log.set_sd", "log.set_mqtt" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult LoggingHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "log.set_serial") return handleSetLevel(envelope, "serial");
|
||||||
|
if (envelope.command == "log.set_sd") return handleSetLevel(envelope, "sd");
|
||||||
|
if (envelope.command == "log.set_mqtt") return handleSetLevel(envelope, "mqtt");
|
||||||
|
return CommandResult::err(envelope.command, "Unknown log command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult LoggingHandler::handleSetLevel(const CommandEnvelope& e, const String& channel) {
|
||||||
|
if (!e.contents["level"].is<uint8_t>()) {
|
||||||
|
return CommandResult::err("log.set_" + channel, "Missing or invalid 'level' (0-5 required)");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t level = e.contents["level"].as<uint8_t>();
|
||||||
|
bool saved = false;
|
||||||
|
|
||||||
|
if (channel == "serial") {
|
||||||
|
if (!_configManager.setSerialLogLevel(level))
|
||||||
|
return CommandResult::err("log.set_serial", "Invalid log level (must be 0-5)");
|
||||||
|
Logging::setLevel((Logging::LogLevel)level);
|
||||||
|
saved = _configManager.saveGeneralConfig();
|
||||||
|
} else if (channel == "sd") {
|
||||||
|
if (!_configManager.setSdLogLevel(level))
|
||||||
|
return CommandResult::err("log.set_sd", "Invalid log level (must be 0-5)");
|
||||||
|
Logging::setSdLevel((Logging::LogLevel)level);
|
||||||
|
saved = _configManager.saveGeneralConfig();
|
||||||
|
} else if (channel == "mqtt") {
|
||||||
|
if (!_configManager.setMqttLogLevel(level))
|
||||||
|
return CommandResult::err("log.set_mqtt", "Invalid log level (must be 0-5)");
|
||||||
|
Logging::setMqttLogLevel((Logging::LogLevel)level);
|
||||||
|
saved = _configManager.saveGeneralConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!saved) {
|
||||||
|
return CommandResult::err("log.set_" + channel, "Level applied but failed to save to SD");
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO(TAG, "%s log level set to %d", channel.c_str(), level);
|
||||||
|
return CommandResult::ok("log.set_" + channel,
|
||||||
|
channel + " log level set to " + String(level) + " and saved");
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
|
||||||
|
class LoggingHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
explicit LoggingHandler(ConfigManager& configManager);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
|
||||||
|
CommandResult handleSetLevel(const CommandEnvelope& e, const String& channel);
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include "MQTTHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../Communication/MQTTAsyncClient/MQTTAsyncClient.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "MQTTHandler"
|
||||||
|
|
||||||
|
MQTTHandler::MQTTHandler(ConfigManager& configManager, MQTTAsyncClient& mqttClient)
|
||||||
|
: _configManager(configManager), _mqttClient(mqttClient) {}
|
||||||
|
|
||||||
|
std::vector<String> MQTTHandler::commands() const {
|
||||||
|
return { "mqtt.enable", "mqtt.disable" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult MQTTHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
bool enable = (envelope.command == "mqtt.enable");
|
||||||
|
|
||||||
|
_configManager.setMqttEnabled(enable);
|
||||||
|
if (!_configManager.saveGeneralConfig()) {
|
||||||
|
return CommandResult::err(envelope.command,
|
||||||
|
"MQTT state changed but failed to save to SD");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
_mqttClient.connect();
|
||||||
|
} else {
|
||||||
|
_mqttClient.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO(TAG, "MQTT %s by user command", enable ? "enabled" : "disabled");
|
||||||
|
return CommandResult::ok(envelope.command,
|
||||||
|
String("MQTT ") + (enable ? "enabled" : "disabled") + " and saved");
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
|
||||||
|
// Forward declare the transport so we don't pull in all of MQTT yet.
|
||||||
|
// In Stage 3 this will be MQTTTransport; for now it wraps MQTTAsyncClient.
|
||||||
|
class MQTTAsyncClient;
|
||||||
|
|
||||||
|
class MQTTHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
MQTTHandler(ConfigManager& configManager, MQTTAsyncClient& mqttClient);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
MQTTAsyncClient& _mqttClient;
|
||||||
|
};
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
#include "NetworkHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../Networking/Networking.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
#define TAG "NetworkHandler"
|
||||||
|
|
||||||
|
NetworkHandler::NetworkHandler(ConfigManager& configManager, Networking& networking)
|
||||||
|
: _configManager(configManager), _networking(networking) {}
|
||||||
|
|
||||||
|
std::vector<String> NetworkHandler::commands() const {
|
||||||
|
return { "network.info", "network.status", "network.set_config" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult NetworkHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "network.info") return handleInfo(envelope);
|
||||||
|
if (envelope.command == "network.status") return handleStatus(envelope);
|
||||||
|
if (envelope.command == "network.set_config") return handleSetConfig(envelope);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown network command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult NetworkHandler::handleInfo(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["ip"] = WiFi.localIP().toString();
|
||||||
|
doc["gateway"] = WiFi.gatewayIP().toString();
|
||||||
|
doc["dns"] = WiFi.dnsIP().toString();
|
||||||
|
return CommandResult::ok("network.info", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult NetworkHandler::handleStatus(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["connected"] = _networking.isConnected();
|
||||||
|
doc["ip"] = _networking.getLocalIP();
|
||||||
|
doc["ap_mode"] = _networking.isInAPMode();
|
||||||
|
doc["rssi"] = WiFi.RSSI();
|
||||||
|
|
||||||
|
const char* stateStr = "UNKNOWN";
|
||||||
|
switch (_networking.getState()) {
|
||||||
|
case NetworkState::DISCONNECTED: stateStr = "DISCONNECTED"; break;
|
||||||
|
case NetworkState::CONNECTING_WIFI: stateStr = "CONNECTING"; break;
|
||||||
|
case NetworkState::CONNECTED_WIFI: stateStr = "CONNECTED_WIFI"; break;
|
||||||
|
case NetworkState::CONNECTED_ETHERNET: stateStr = "CONNECTED_ETHERNET"; break;
|
||||||
|
case NetworkState::RECONNECTING: stateStr = "RECONNECTING"; break;
|
||||||
|
case NetworkState::AP_MODE_PERMANENT: stateStr = "AP_MODE"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
doc["state"] = stateStr;
|
||||||
|
|
||||||
|
const char* typeStr = "NONE";
|
||||||
|
switch (_networking.getActiveConnection()) {
|
||||||
|
case ConnectionType::WIFI: typeStr = "WIFI"; break;
|
||||||
|
case ConnectionType::ETHERNET: typeStr = "ETHERNET"; break;
|
||||||
|
case ConnectionType::AP: typeStr = "AP"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
doc["type"] = typeStr;
|
||||||
|
|
||||||
|
return CommandResult::ok("network.status", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult NetworkHandler::handleSetConfig(const CommandEnvelope& e) {
|
||||||
|
bool hasHostname = e.contents["hostname"].is<const char*>();
|
||||||
|
bool hasStaticIPCfg = e.contents["useStaticIP"].is<bool>();
|
||||||
|
|
||||||
|
if (!hasHostname && !hasStaticIPCfg) {
|
||||||
|
return CommandResult::err("network.set_config", "No network parameters provided");
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& current = _configManager.getNetworkConfig();
|
||||||
|
bool useStatic = current.useStaticIP;
|
||||||
|
IPAddress ip = current.ip, gateway = current.gateway;
|
||||||
|
IPAddress subnet = current.subnet, dns1 = current.dns1, dns2 = current.dns2;
|
||||||
|
String hostname = current.hostname;
|
||||||
|
|
||||||
|
if (hasHostname) {
|
||||||
|
String h = e.contents["hostname"].as<String>();
|
||||||
|
if (h.isEmpty() || h.length() > 32) {
|
||||||
|
return CommandResult::err("network.set_config", "Hostname must be 1-32 characters");
|
||||||
|
}
|
||||||
|
hostname = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasStaticIPCfg) {
|
||||||
|
useStatic = e.contents["useStaticIP"].as<bool>();
|
||||||
|
if (useStatic) {
|
||||||
|
if (!e.contents["ip"].is<const char*>() ||
|
||||||
|
!e.contents["gateway"].is<const char*>() ||
|
||||||
|
!e.contents["subnet"].is<const char*>()) {
|
||||||
|
return CommandResult::err("network.set_config",
|
||||||
|
"Static IP requires: ip, gateway, subnet");
|
||||||
|
}
|
||||||
|
if (!ip.fromString(e.contents["ip"].as<String>())) {
|
||||||
|
return CommandResult::err("network.set_config", "Invalid IP address format");
|
||||||
|
}
|
||||||
|
if (!gateway.fromString(e.contents["gateway"].as<String>())) {
|
||||||
|
return CommandResult::err("network.set_config", "Invalid gateway format");
|
||||||
|
}
|
||||||
|
if (!subnet.fromString(e.contents["subnet"].as<String>())) {
|
||||||
|
return CommandResult::err("network.set_config", "Invalid subnet format");
|
||||||
|
}
|
||||||
|
if (e.contents["dns1"].is<const char*>()) dns1.fromString(e.contents["dns1"].as<String>());
|
||||||
|
if (e.contents["dns2"].is<const char*>()) dns2.fromString(e.contents["dns2"].as<String>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_configManager.updateNetworkConfig(hostname, useStatic, ip, gateway, subnet, dns1, dns2);
|
||||||
|
LOG_INFO(TAG, "Network config updated — restart required to apply");
|
||||||
|
return CommandResult::ok("network.set_config",
|
||||||
|
"Network configuration saved. Restart device to apply changes.");
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
class Networking;
|
||||||
|
|
||||||
|
class NetworkHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
NetworkHandler(ConfigManager& configManager, Networking& networking);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
Networking& _networking;
|
||||||
|
|
||||||
|
CommandResult handleInfo(const CommandEnvelope& e);
|
||||||
|
CommandResult handleStatus(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetConfig(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#include "PlaybackHandler.hpp"
|
||||||
|
#include "../../../Player/Player.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "PlaybackHandler"
|
||||||
|
|
||||||
|
PlaybackHandler::PlaybackHandler(Player& player) : _player(player) {}
|
||||||
|
|
||||||
|
std::vector<String> PlaybackHandler::commands() const {
|
||||||
|
return { "playback" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult PlaybackHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
bool ok = _player.command(const_cast<JsonDocument&>(envelope.contents).as<JsonVariant>());
|
||||||
|
if (ok) return CommandResult::ok("playback", "Playback command executed");
|
||||||
|
return CommandResult::err("playback", "Playback command failed");
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
class PlaybackHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
explicit PlaybackHandler(Player& player);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Player& _player;
|
||||||
|
};
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "RelayHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../OutputManager/OutputManager.hpp"
|
||||||
|
#include "../../../Player/Player.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "RelayHandler"
|
||||||
|
|
||||||
|
RelayHandler::RelayHandler(ConfigManager& configManager, OutputManager& outputManager, Player& player)
|
||||||
|
: _configManager(configManager), _outputManager(outputManager), _player(player) {}
|
||||||
|
|
||||||
|
std::vector<String> RelayHandler::commands() const {
|
||||||
|
return { "relay.set_durations", "relay.set_outputs", "relay.get_config", "relay.test_output" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult RelayHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "relay.set_durations") return handleSetDurations(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);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown relay command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult RelayHandler::handleSetDurations(const CommandEnvelope& e) {
|
||||||
|
JsonVariant contents = const_cast<JsonDocument&>(e.contents).as<JsonVariant>();
|
||||||
|
if (contents["bells"].isNull()) {
|
||||||
|
return CommandResult::err("relay.set_durations", "Missing or invalid 'bells' object");
|
||||||
|
}
|
||||||
|
_configManager.updateBellDurations(contents);
|
||||||
|
if (!_configManager.saveBellDurations()) {
|
||||||
|
return CommandResult::err("relay.set_durations", "Durations updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG, "Bell durations updated and saved");
|
||||||
|
return CommandResult::ok("relay.set_durations", "Bell durations updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult RelayHandler::handleSetOutputs(const CommandEnvelope& e) {
|
||||||
|
JsonVariant contents = const_cast<JsonDocument&>(e.contents).as<JsonVariant>();
|
||||||
|
if (contents["bells"].isNull()) {
|
||||||
|
return CommandResult::err("relay.set_outputs", "Missing or invalid 'bells' object");
|
||||||
|
}
|
||||||
|
_configManager.updateBellOutputs(contents);
|
||||||
|
if (!_configManager.saveBellOutputs()) {
|
||||||
|
return CommandResult::err("relay.set_outputs", "Outputs updated but failed to save to SD");
|
||||||
|
}
|
||||||
|
LOG_INFO(TAG, "Bell outputs updated and saved");
|
||||||
|
return CommandResult::ok("relay.set_outputs", "Bell outputs updated and saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult RelayHandler::handleGetConfig(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
JsonObject durations = doc["durations"].to<JsonObject>();
|
||||||
|
JsonObject outputs = doc["outputs"].to<JsonObject>();
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
durations[String(i)] = _configManager.getBellDuration(i);
|
||||||
|
outputs[String(i)] = _configManager.getBellOutput(i);
|
||||||
|
}
|
||||||
|
return CommandResult::ok("relay.get_config", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult RelayHandler::handleTestOutput(const CommandEnvelope& e) {
|
||||||
|
if (!e.contents["output"].is<int>()) {
|
||||||
|
return CommandResult::err("relay.test_output", "Missing required field: output");
|
||||||
|
}
|
||||||
|
if (!e.contents["duration_ms"].is<int>()) {
|
||||||
|
return CommandResult::err("relay.test_output", "Missing required field: duration_ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_player.isCurrentlyStopped()) {
|
||||||
|
return CommandResult::err("relay.test_output", "Player must be stopped before testing outputs");
|
||||||
|
}
|
||||||
|
|
||||||
|
int output = e.contents["output"].as<int>();
|
||||||
|
int durationMs = e.contents["duration_ms"].as<int>();
|
||||||
|
|
||||||
|
if (output < 0 || output > 31) {
|
||||||
|
return CommandResult::err("relay.test_output", "output must be 0-31");
|
||||||
|
}
|
||||||
|
if (durationMs < 1 || durationMs > 5000) {
|
||||||
|
return CommandResult::err("relay.test_output", "duration_ms must be 1-5000");
|
||||||
|
}
|
||||||
|
|
||||||
|
_outputManager.fireOutputForDuration((uint8_t)output, (uint16_t)durationMs);
|
||||||
|
LOG_INFO(TAG, "Test output %d fired for %d ms", output, durationMs);
|
||||||
|
return CommandResult::ok("relay.test_output",
|
||||||
|
"Output " + String(output) + " fired for " + String(durationMs) + " ms");
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
class OutputManager;
|
||||||
|
class Player;
|
||||||
|
|
||||||
|
class RelayHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
RelayHandler(ConfigManager& configManager, OutputManager& outputManager, Player& player);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
OutputManager& _outputManager;
|
||||||
|
Player& _player;
|
||||||
|
|
||||||
|
CommandResult handleSetDurations(const CommandEnvelope& e);
|
||||||
|
CommandResult handleSetOutputs(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetConfig(const CommandEnvelope& e);
|
||||||
|
CommandResult handleTestOutput(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
#include "SystemHandler.hpp"
|
||||||
|
#include "../../../ConfigManager/ConfigManager.hpp"
|
||||||
|
#include "../../../Player/Player.hpp"
|
||||||
|
#include "../../../Telemetry/Telemetry.hpp"
|
||||||
|
#include "../../../HealthMonitor/HealthMonitor.hpp"
|
||||||
|
#include "../../../TimeKeeper/TimeKeeper.hpp"
|
||||||
|
#include "../../../ClientManager/ClientManager.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define TAG "SystemHandler"
|
||||||
|
|
||||||
|
SystemHandler::SystemHandler(ConfigManager& configManager, Player& player,
|
||||||
|
Telemetry& telemetry, HealthMonitor& healthMonitor,
|
||||||
|
Timekeeper& timeKeeper, ClientManager& clientManager)
|
||||||
|
: _configManager(configManager)
|
||||||
|
, _player(player)
|
||||||
|
, _telemetry(telemetry)
|
||||||
|
, _healthMonitor(healthMonitor)
|
||||||
|
, _timeKeeper(timeKeeper)
|
||||||
|
, _clientManager(clientManager) {}
|
||||||
|
|
||||||
|
std::vector<String> SystemHandler::commands() const {
|
||||||
|
return {
|
||||||
|
"ping", "identify",
|
||||||
|
"system.status", "system.get_time", "system.get_settings",
|
||||||
|
"system.get_device_info", "system.health",
|
||||||
|
"system.factory_reset", "system.restart"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "ping") return handlePing(envelope);
|
||||||
|
if (envelope.command == "identify") return handleIdentify(envelope);
|
||||||
|
if (envelope.command == "system.status") return handleStatus(envelope);
|
||||||
|
if (envelope.command == "system.get_time") return handleGetTime(envelope);
|
||||||
|
if (envelope.command == "system.get_settings") return handleGetSettings(envelope);
|
||||||
|
if (envelope.command == "system.get_device_info") return handleGetDeviceInfo(envelope);
|
||||||
|
if (envelope.command == "system.health") return handleHealth(envelope);
|
||||||
|
if (envelope.command == "system.factory_reset") return handleFactoryReset(envelope);
|
||||||
|
if (envelope.command == "system.restart") return handleRestart(envelope);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown system command");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handlePing(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["type"] = "pong";
|
||||||
|
return CommandResult::ok("pong");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleIdentify(const CommandEnvelope& e) {
|
||||||
|
if (e.transport != CommandEnvelope::Transport::WEBSOCKET) {
|
||||||
|
return CommandResult::err("identify", "identify is only available via WebSocket");
|
||||||
|
}
|
||||||
|
if (!e.contents["device_type"].is<const char*>()) {
|
||||||
|
return CommandResult::err("identify", "Missing required field: device_type");
|
||||||
|
}
|
||||||
|
|
||||||
|
String deviceTypeStr = e.contents["device_type"].as<String>();
|
||||||
|
ClientManager::DeviceType deviceType = ClientManager::DeviceType::UNKNOWN;
|
||||||
|
if (deviceTypeStr == "master") deviceType = ClientManager::DeviceType::MASTER;
|
||||||
|
if (deviceTypeStr == "secondary") deviceType = ClientManager::DeviceType::SECONDARY;
|
||||||
|
|
||||||
|
if (deviceType == ClientManager::DeviceType::UNKNOWN) {
|
||||||
|
return CommandResult::err("identify", "Invalid device_type. Use 'master' or 'secondary'");
|
||||||
|
}
|
||||||
|
|
||||||
|
_clientManager.updateClientType(e.clientId, deviceType);
|
||||||
|
LOG_INFO(TAG, "Client #%u identified as %s", e.clientId, deviceTypeStr.c_str());
|
||||||
|
return CommandResult::ok("identify", "Device identified as " + deviceTypeStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleStatus(const CommandEnvelope& e) {
|
||||||
|
PlayerStatus playerStatus = _player.getStatus();
|
||||||
|
uint32_t timeElapsedMs = 0;
|
||||||
|
uint64_t projectedRunTime = 0;
|
||||||
|
|
||||||
|
if (playerStatus == PlayerStatus::PLAYING ||
|
||||||
|
playerStatus == PlayerStatus::PAUSED ||
|
||||||
|
playerStatus == PlayerStatus::STOPPING) {
|
||||||
|
timeElapsedMs = (uint32_t)(millis() - _player.startTime);
|
||||||
|
}
|
||||||
|
projectedRunTime = _player.calculateProjectedRunTime();
|
||||||
|
|
||||||
|
uint32_t strikeCounters[16] = {0};
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
strikeCounters[i] = _telemetry.getStrikeCount(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegate to ResponseBuilder which already handles this format
|
||||||
|
// We build the result directly here to keep the handler self-contained
|
||||||
|
JsonDocument doc;
|
||||||
|
const char* statusStr = "STOPPED";
|
||||||
|
switch (playerStatus) {
|
||||||
|
case PlayerStatus::PLAYING: statusStr = "PLAYING"; break;
|
||||||
|
case PlayerStatus::PAUSED: statusStr = "PAUSED"; break;
|
||||||
|
case PlayerStatus::STOPPING: statusStr = "STOPPING"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
doc["player_status"] = statusStr;
|
||||||
|
doc["time_elapsed_ms"] = timeElapsedMs;
|
||||||
|
doc["projected_run_time"] = projectedRunTime;
|
||||||
|
JsonObject strikes = doc["strike_counters"].to<JsonObject>();
|
||||||
|
for (uint8_t i = 0; i < 16; i++) strikes[String(i)] = strikeCounters[i];
|
||||||
|
|
||||||
|
return CommandResult::ok("system.status", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleGetTime(const CommandEnvelope& e) {
|
||||||
|
unsigned long localTimestamp = _timeKeeper.getTime();
|
||||||
|
const auto& timeConfig = _configManager.getTimeConfig();
|
||||||
|
long totalOffset = timeConfig.gmtOffsetSec + timeConfig.daylightOffsetSec;
|
||||||
|
unsigned long utcTimestamp = localTimestamp - totalOffset;
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["local_timestamp"] = localTimestamp;
|
||||||
|
doc["utc_timestamp"] = utcTimestamp;
|
||||||
|
doc["rtc_available"] = (localTimestamp > 0);
|
||||||
|
|
||||||
|
time_t rawTime = (time_t)localTimestamp;
|
||||||
|
struct tm* ti = gmtime(&rawTime);
|
||||||
|
doc["year"] = ti->tm_year + 1900;
|
||||||
|
doc["month"] = ti->tm_mon + 1;
|
||||||
|
doc["day"] = ti->tm_mday;
|
||||||
|
doc["hour"] = ti->tm_hour;
|
||||||
|
doc["minute"] = ti->tm_min;
|
||||||
|
doc["second"] = ti->tm_sec;
|
||||||
|
|
||||||
|
return CommandResult::ok("system.get_time", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleGetSettings(const CommandEnvelope& e) {
|
||||||
|
String settingsJson = _configManager.getAllSettingsAsJson();
|
||||||
|
JsonDocument doc;
|
||||||
|
DeserializationError err = deserializeJson(doc, settingsJson);
|
||||||
|
if (err) {
|
||||||
|
LOG_ERROR(TAG, "Failed to parse settings JSON: %s", err.c_str());
|
||||||
|
return CommandResult::err("system.get_settings", "Failed to serialize settings");
|
||||||
|
}
|
||||||
|
return CommandResult::ok("system.get_settings", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleGetDeviceInfo(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["uid"] = _configManager.getDeviceUID();
|
||||||
|
doc["hw_type"] = _configManager.getHwType();
|
||||||
|
doc["hw_version"] = _configManager.getHwVersion();
|
||||||
|
doc["fw_version"] = _configManager.getFwVersion();
|
||||||
|
doc["uptime_ms"] = millis();
|
||||||
|
doc["free_heap"] = (uint32_t)ESP.getFreeHeap();
|
||||||
|
doc["min_free_heap"] = (uint32_t)ESP.getMinFreeHeap();
|
||||||
|
return CommandResult::ok("system.get_device_info", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleHealth(const CommandEnvelope& e) {
|
||||||
|
_healthMonitor.performFullHealthCheck();
|
||||||
|
const auto& subsystems = _healthMonitor.getAllSubsystemHealth();
|
||||||
|
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["critical_count"] = _healthMonitor.getCriticalFailureCount();
|
||||||
|
doc["warning_count"] = _healthMonitor.getWarningCount();
|
||||||
|
doc["firmware_stable"] = _healthMonitor.isFirmwareStable();
|
||||||
|
|
||||||
|
JsonArray arr = doc["subsystems"].to<JsonArray>();
|
||||||
|
for (const auto& pair : subsystems) {
|
||||||
|
JsonObject obj = arr.add<JsonObject>();
|
||||||
|
obj["name"] = pair.second.name;
|
||||||
|
const char* s = "HEALTHY";
|
||||||
|
switch (pair.second.status) {
|
||||||
|
case HealthStatus::WARNING: s = "WARNING"; break;
|
||||||
|
case HealthStatus::CRITICAL: s = "CRITICAL"; break;
|
||||||
|
case HealthStatus::FAILED: s = "FAILED"; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
obj["status"] = s;
|
||||||
|
if (!pair.second.lastError.isEmpty()) obj["error"] = pair.second.lastError;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandResult::ok("system.health", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleFactoryReset(const CommandEnvelope& e) {
|
||||||
|
LOG_WARNING(TAG, "Factory reset requested");
|
||||||
|
bool ok = _configManager.resetAllToDefaults();
|
||||||
|
if (ok) {
|
||||||
|
return CommandResult::ok("system.factory_reset",
|
||||||
|
"Factory reset complete. Restart device to apply.");
|
||||||
|
}
|
||||||
|
return CommandResult::err("system.factory_reset",
|
||||||
|
"Factory reset partially applied — some settings may not have saved");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult SystemHandler::handleRestart(const CommandEnvelope& e) {
|
||||||
|
LOG_WARNING(TAG, "Device restart requested via command");
|
||||||
|
// Response is sent before restart via the reply lambda in the transport
|
||||||
|
// We schedule the restart after a brief delay so the reply gets out first
|
||||||
|
xTaskCreate([](void*) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||||
|
ESP.restart();
|
||||||
|
}, "restartTask", 1024, nullptr, 1, nullptr);
|
||||||
|
return CommandResult::ok("system.restart", "Device will restart in 2 seconds");
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class ConfigManager;
|
||||||
|
class Player;
|
||||||
|
class Telemetry;
|
||||||
|
class HealthMonitor;
|
||||||
|
class Timekeeper;
|
||||||
|
class ClientManager;
|
||||||
|
|
||||||
|
class SystemHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
SystemHandler(ConfigManager& configManager, Player& player,
|
||||||
|
Telemetry& telemetry, HealthMonitor& healthMonitor,
|
||||||
|
Timekeeper& timeKeeper, ClientManager& clientManager);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConfigManager& _configManager;
|
||||||
|
Player& _player;
|
||||||
|
Telemetry& _telemetry;
|
||||||
|
HealthMonitor& _healthMonitor;
|
||||||
|
Timekeeper& _timeKeeper;
|
||||||
|
ClientManager& _clientManager;
|
||||||
|
|
||||||
|
CommandResult handlePing(const CommandEnvelope& e);
|
||||||
|
CommandResult handleIdentify(const CommandEnvelope& e);
|
||||||
|
CommandResult handleStatus(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetTime(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetSettings(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetDeviceInfo(const CommandEnvelope& e);
|
||||||
|
CommandResult handleHealth(const CommandEnvelope& e);
|
||||||
|
CommandResult handleFactoryReset(const CommandEnvelope& e);
|
||||||
|
CommandResult handleRestart(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#include "TelemetryHandler.hpp"
|
||||||
|
#include "../../../Telemetry/Telemetry.hpp"
|
||||||
|
#include "../../../Logging/Logging.hpp"
|
||||||
|
|
||||||
|
#define TAG "TelemetryHandler"
|
||||||
|
|
||||||
|
TelemetryHandler::TelemetryHandler(Telemetry& telemetry) : _telemetry(telemetry) {}
|
||||||
|
|
||||||
|
std::vector<String> TelemetryHandler::commands() const {
|
||||||
|
return { "telemetry.get_strikes", "telemetry.reset_strikes", "telemetry.get_loads" };
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult TelemetryHandler::execute(const CommandEnvelope& envelope) {
|
||||||
|
if (envelope.command == "telemetry.get_strikes") return handleGetStrikes(envelope);
|
||||||
|
if (envelope.command == "telemetry.reset_strikes") return handleResetStrikes(envelope);
|
||||||
|
if (envelope.command == "telemetry.get_loads") return handleGetLoads(envelope);
|
||||||
|
return CommandResult::err(envelope.command, "Unknown telemetry command");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult TelemetryHandler::handleGetStrikes(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
JsonObject strikes = doc["strikes"].to<JsonObject>();
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
strikes[String(i)] = _telemetry.getStrikeCount(i);
|
||||||
|
}
|
||||||
|
return CommandResult::ok("telemetry.get_strikes", doc);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult TelemetryHandler::handleResetStrikes(const CommandEnvelope& e) {
|
||||||
|
// Telemetry currently supports resetting all counters at once.
|
||||||
|
// Per-bell reset via contents["bell"] is planned for a future Telemetry API extension.
|
||||||
|
_telemetry.resetStrikeCounters();
|
||||||
|
LOG_INFO(TAG, "All strike counts reset");
|
||||||
|
return CommandResult::ok("telemetry.reset_strikes", "All strike counts reset");
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandResult TelemetryHandler::handleGetLoads(const CommandEnvelope& e) {
|
||||||
|
JsonDocument doc;
|
||||||
|
JsonObject loads = doc["loads"].to<JsonObject>();
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
loads[String(i)] = _telemetry.getBellLoad(i);
|
||||||
|
}
|
||||||
|
doc["cooling_active"] = _telemetry.isCoolingActive();
|
||||||
|
|
||||||
|
JsonArray overloaded = doc["overloaded"].to<JsonArray>();
|
||||||
|
for (uint8_t i = 0; i < 16; i++) {
|
||||||
|
if (_telemetry.isOverloaded(i)) overloaded.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandResult::ok("telemetry.get_loads", doc);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include "../ICommandHandler.hpp"
|
||||||
|
|
||||||
|
class Telemetry;
|
||||||
|
|
||||||
|
class TelemetryHandler : public ICommandHandler {
|
||||||
|
public:
|
||||||
|
explicit TelemetryHandler(Telemetry& telemetry);
|
||||||
|
|
||||||
|
std::vector<String> commands() const override;
|
||||||
|
CommandResult execute(const CommandEnvelope& envelope) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Telemetry& _telemetry;
|
||||||
|
|
||||||
|
CommandResult handleGetStrikes(const CommandEnvelope& e);
|
||||||
|
CommandResult handleResetStrikes(const CommandEnvelope& e);
|
||||||
|
CommandResult handleGetLoads(const CommandEnvelope& e);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user