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:
@@ -13,7 +13,9 @@ OTAManager::OTAManager(ConfigManager& configManager)
|
||||
: _configManager(configManager)
|
||||
, _fileManager(nullptr)
|
||||
, _player(nullptr)
|
||||
#if HAS_RTC
|
||||
, _timeKeeper(nullptr)
|
||||
#endif
|
||||
, _telemetry(nullptr)
|
||||
, _status(Status::IDLE)
|
||||
, _lastError(ErrorCode::NONE)
|
||||
@@ -130,9 +132,11 @@ void OTAManager::setPlayer(Player* player) {
|
||||
_player = player;
|
||||
}
|
||||
|
||||
#if HAS_RTC
|
||||
void OTAManager::setTimeKeeper(Timekeeper* tk) {
|
||||
_timeKeeper = tk;
|
||||
}
|
||||
#endif
|
||||
|
||||
void OTAManager::setTelemetry(Telemetry* telemetry) {
|
||||
_telemetry = telemetry;
|
||||
@@ -317,6 +321,7 @@ bool OTAManager::checkVersion(const String& channel) {
|
||||
|
||||
HTTPClient http;
|
||||
http.setTimeout(updateConfig.timeout);
|
||||
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
http.begin(metadataUrl.c_str());
|
||||
|
||||
int retryCount = 0;
|
||||
@@ -353,8 +358,9 @@ bool OTAManager::checkVersion(const String& channel) {
|
||||
const char* minVersionStr = doc["min_fw_version"] | "";
|
||||
_minVersion = (strlen(minVersionStr) > 0) ? SemVer::parse(String(minVersionStr)) : SemVer{0, 0, 0};
|
||||
|
||||
_availableChecksum = doc["sha256"] | "";
|
||||
_expectedFileSize = doc["size"] | (size_t)0;
|
||||
_availableChecksum = doc["sha256"] | "";
|
||||
_expectedFileSize = doc["size"] | (size_t)0;
|
||||
_availableDownloadPath = doc["download_url"] | "";
|
||||
|
||||
// update_type: "optional" | "mandatory" | "emergency"
|
||||
// This is the urgency of the release — completely separate from the channel.
|
||||
@@ -418,8 +424,16 @@ bool OTAManager::downloadAndInstall(const String& channel) {
|
||||
String toVersion = _availableVersion.toString();
|
||||
|
||||
for (size_t serverIndex = 0; serverIndex < servers.size(); serverIndex++) {
|
||||
String baseUrl = servers[serverIndex];
|
||||
String firmwareUrl = buildFirmwareUrl(baseUrl, hwType, channel, toVersion);
|
||||
String baseUrl = servers[serverIndex];
|
||||
|
||||
// Prefer the download_url returned by the server (relative path prepended with baseUrl).
|
||||
// Fall back to constructing the URL locally if the server didn't return one.
|
||||
String firmwareUrl;
|
||||
if (_availableDownloadPath.length() > 0) {
|
||||
firmwareUrl = baseUrl + _availableDownloadPath;
|
||||
} else {
|
||||
firmwareUrl = buildFirmwareUrl(baseUrl, hwType, channel, toVersion);
|
||||
}
|
||||
|
||||
LOG_INFO(TAG, "OTA: Trying firmware download from server %d/%d: %s",
|
||||
serverIndex + 1, servers.size(), firmwareUrl.c_str());
|
||||
@@ -442,6 +456,7 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
LOG_INFO(TAG, "OTA: Starting direct-to-flash download (bypassing SD card)");
|
||||
|
||||
HTTPClient http;
|
||||
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
http.begin(url.c_str());
|
||||
http.setTimeout(30000); // 30 seconds
|
||||
|
||||
@@ -479,9 +494,11 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
LOG_INFO(TAG, "OTA: Entering freeze mode - pausing TimeKeeper and Telemetry");
|
||||
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) {
|
||||
_timeKeeper->pauseClockUpdates();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_telemetry) {
|
||||
_telemetry->pause();
|
||||
@@ -494,7 +511,9 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
http.end();
|
||||
|
||||
// Resume systems
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) _timeKeeper->resumeClockUpdates();
|
||||
#endif
|
||||
if (_telemetry) _telemetry->resume();
|
||||
|
||||
return false;
|
||||
@@ -506,7 +525,7 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
|
||||
// Stream directly to flash with periodic watchdog feeding
|
||||
WiFiClient* stream = http.getStreamPtr();
|
||||
uint8_t buffer[4096]; // 4KB buffer for efficient transfer
|
||||
static uint8_t buffer[4096]; // 4KB buffer — static to avoid blowing the 8KB task stack
|
||||
size_t written = 0;
|
||||
size_t lastLoggedPercent = 0;
|
||||
unsigned long lastWatchdogReset = millis();
|
||||
@@ -527,7 +546,9 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
http.end();
|
||||
|
||||
// Resume systems
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) _timeKeeper->resumeClockUpdates();
|
||||
#endif
|
||||
if (_telemetry) _telemetry->resume();
|
||||
|
||||
setStatus(Status::FAILED, ErrorCode::WRITE_FAILED);
|
||||
@@ -544,6 +565,11 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
lastLoggedPercent = currentPercent;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No data available yet — block for 1ms so IDLE0 can run and reset its watchdog.
|
||||
// yield()/vPortYield() is cooperative and doesn't release the CPU long enough;
|
||||
// vTaskDelay(1) actually suspends this task for one tick (~1ms).
|
||||
vTaskDelay(1);
|
||||
}
|
||||
|
||||
// Feed watchdog every 500ms to prevent timeout
|
||||
@@ -551,9 +577,6 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
esp_task_wdt_reset();
|
||||
lastWatchdogReset = millis();
|
||||
}
|
||||
|
||||
// Small yield to prevent tight loop
|
||||
yield();
|
||||
}
|
||||
|
||||
http.end();
|
||||
@@ -563,9 +586,11 @@ bool OTAManager::downloadDirectToFlash(const String& url, size_t expectedSize, c
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
LOG_INFO(TAG, "OTA: Exiting freeze mode - resuming TimeKeeper and Telemetry");
|
||||
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) {
|
||||
_timeKeeper->resumeClockUpdates();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_telemetry) {
|
||||
_telemetry->resume();
|
||||
@@ -667,9 +692,11 @@ bool OTAManager::downloadToSD(const String& url, const String& expectedChecksum,
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
LOG_INFO(TAG, "OTA: Entering freeze mode - pausing TimeKeeper and Telemetry");
|
||||
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) {
|
||||
_timeKeeper->pauseClockUpdates();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_telemetry) {
|
||||
_telemetry->pause();
|
||||
@@ -679,7 +706,9 @@ bool OTAManager::downloadToSD(const String& url, const String& expectedChecksum,
|
||||
LOG_INFO(TAG, "OTA: Acquiring SD card mutex for safe file operations");
|
||||
if (!SDCardMutex::getInstance().lock(10000)) { // 10 second timeout
|
||||
LOG_ERROR(TAG, "OTA: Failed to acquire SD card mutex!");
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) _timeKeeper->resumeClockUpdates();
|
||||
#endif
|
||||
if (_telemetry) _telemetry->resume();
|
||||
setStatus(Status::FAILED, ErrorCode::DOWNLOAD_FAILED);
|
||||
http.end();
|
||||
@@ -702,7 +731,9 @@ bool OTAManager::downloadToSD(const String& url, const String& expectedChecksum,
|
||||
|
||||
// Release mutex and resume systems before returning
|
||||
SDCardMutex::getInstance().unlock();
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) _timeKeeper->resumeClockUpdates();
|
||||
#endif
|
||||
if (_telemetry) _telemetry->resume();
|
||||
|
||||
setStatus(Status::FAILED, ErrorCode::DOWNLOAD_FAILED);
|
||||
@@ -737,7 +768,9 @@ bool OTAManager::downloadToSD(const String& url, const String& expectedChecksum,
|
||||
SDCardMutex::getInstance().unlock();
|
||||
http.end();
|
||||
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) _timeKeeper->resumeClockUpdates();
|
||||
#endif
|
||||
if (_telemetry) _telemetry->resume();
|
||||
|
||||
setStatus(Status::FAILED, ErrorCode::WRITE_FAILED);
|
||||
@@ -790,9 +823,11 @@ bool OTAManager::downloadToSD(const String& url, const String& expectedChecksum,
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
LOG_INFO(TAG, "OTA: Exiting freeze mode - resuming TimeKeeper and Telemetry");
|
||||
|
||||
#if HAS_RTC
|
||||
if (_timeKeeper) {
|
||||
_timeKeeper->resumeClockUpdates();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_telemetry) {
|
||||
_telemetry->resume();
|
||||
|
||||
Reference in New Issue
Block a user