Update on Overleaf.
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* @file CompanionChipStatus.hpp
|
||||||
|
* @brief Boot-ready flags for Si4684, ADAU1701, and FSC-BT1035.
|
||||||
|
*
|
||||||
|
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
|
||||||
|
*
|
||||||
|
* Copyright 2026 Michele Bigi
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* @author Michele Bigi
|
||||||
|
* @date 2026-07-06
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CompanionChipStatus — companion-chip boot snapshot for /api/health.
|
||||||
|
*
|
||||||
|
* @dname CompanionChipStatus
|
||||||
|
* @return n/a (type)
|
||||||
|
* @pubstate Immutable aggregate; all true after successful HardwareBootstrap.
|
||||||
|
*
|
||||||
|
* @author Michele Bigi
|
||||||
|
* @date 2026-07-06
|
||||||
|
*/
|
||||||
|
struct CompanionChipStatus {
|
||||||
|
bool si4684Ready; ///< Si4684 HOST_LOAD completed.
|
||||||
|
bool adau1701Ready; ///< ADAU1701 SigmaStudio download completed.
|
||||||
|
bool bt1035Ready; ///< BT1035 Line-In init (AT+AUXCFG=1) completed.
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace core
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/CompanionChipStatus.hpp"
|
||||||
#include "core/ISecureStore.hpp"
|
#include "core/ISecureStore.hpp"
|
||||||
#include "net/NetError.hpp"
|
#include "net/NetError.hpp"
|
||||||
#include "net/NetState.hpp"
|
#include "net/NetState.hpp"
|
||||||
@@ -65,7 +66,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] static std::expected<NetBootstrap, NetError>
|
[[nodiscard]] static std::expected<NetBootstrap, NetError>
|
||||||
start(core::ISecureStore& store, tuner::TunerService& tuner,
|
start(core::ISecureStore& store, tuner::TunerService& tuner,
|
||||||
audio::AudioService& audio);
|
audio::AudioService& audio,
|
||||||
|
core::CompanionChipStatus companionChips);
|
||||||
|
|
||||||
NetBootstrap(const NetBootstrap&) = delete;
|
NetBootstrap(const NetBootstrap&) = delete;
|
||||||
NetBootstrap& operator=(const NetBootstrap&) = delete;
|
NetBootstrap& operator=(const NetBootstrap&) = delete;
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ constexpr char kTag[] = "NetBootstrap";
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] std::expected<NetBootstrap, NetError>
|
[[nodiscard]] std::expected<NetBootstrap, NetError>
|
||||||
startSetupMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
startSetupMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
||||||
audio::AudioService& audio)
|
audio::AudioService& audio,
|
||||||
|
core::CompanionChipStatus companionChips)
|
||||||
{
|
{
|
||||||
esp_netif_create_default_wifi_ap();
|
esp_netif_create_default_wifi_ap();
|
||||||
|
|
||||||
@@ -111,7 +112,8 @@ startSetupMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
|||||||
|
|
||||||
SetupWebServer webServer;
|
SetupWebServer webServer;
|
||||||
if (auto webResult =
|
if (auto webResult =
|
||||||
webServer.start(store, NetState::SoftApSetup, tuner, audio);
|
webServer.start(store, NetState::SoftApSetup, tuner, audio,
|
||||||
|
companionChips);
|
||||||
!webResult) {
|
!webResult) {
|
||||||
return std::unexpected(webResult.error());
|
return std::unexpected(webResult.error());
|
||||||
}
|
}
|
||||||
@@ -134,7 +136,8 @@ startSetupMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
|||||||
*/
|
*/
|
||||||
[[nodiscard]] std::expected<NetBootstrap, NetError>
|
[[nodiscard]] std::expected<NetBootstrap, NetError>
|
||||||
startStaMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
startStaMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
||||||
audio::AudioService& audio)
|
audio::AudioService& audio,
|
||||||
|
core::CompanionChipStatus companionChips)
|
||||||
{
|
{
|
||||||
auto credsResult = store.loadWifiCredentials();
|
auto credsResult = store.loadWifiCredentials();
|
||||||
if (!credsResult) {
|
if (!credsResult) {
|
||||||
@@ -151,7 +154,8 @@ startStaMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
|||||||
|
|
||||||
SetupWebServer webServer;
|
SetupWebServer webServer;
|
||||||
if (auto webResult =
|
if (auto webResult =
|
||||||
webServer.start(store, NetState::StaConnected, tuner, audio);
|
webServer.start(store, NetState::StaConnected, tuner, audio,
|
||||||
|
companionChips);
|
||||||
!webResult) {
|
!webResult) {
|
||||||
return std::unexpected(webResult.error());
|
return std::unexpected(webResult.error());
|
||||||
}
|
}
|
||||||
@@ -165,7 +169,8 @@ startStaMode(core::ISecureStore& store, tuner::TunerService& tuner,
|
|||||||
|
|
||||||
std::expected<NetBootstrap, NetError>
|
std::expected<NetBootstrap, NetError>
|
||||||
NetBootstrap::start(core::ISecureStore& store, tuner::TunerService& tuner,
|
NetBootstrap::start(core::ISecureStore& store, tuner::TunerService& tuner,
|
||||||
audio::AudioService& audio)
|
audio::AudioService& audio,
|
||||||
|
core::CompanionChipStatus companionChips)
|
||||||
{
|
{
|
||||||
if (auto platform = initPlatform(); !platform) {
|
if (auto platform = initPlatform(); !platform) {
|
||||||
return std::unexpected(platform.error());
|
return std::unexpected(platform.error());
|
||||||
@@ -176,14 +181,14 @@ NetBootstrap::start(core::ISecureStore& store, tuner::TunerService& tuner,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (store.hasWifiCredentials()) {
|
if (store.hasWifiCredentials()) {
|
||||||
auto staResult = startStaMode(store, tuner, audio);
|
auto staResult = startStaMode(store, tuner, audio, companionChips);
|
||||||
if (staResult) {
|
if (staResult) {
|
||||||
return staResult;
|
return staResult;
|
||||||
}
|
}
|
||||||
ESP_LOGW(kTag, "STA join failed — falling back to setup SoftAP");
|
ESP_LOGW(kTag, "STA join failed — falling back to setup SoftAP");
|
||||||
}
|
}
|
||||||
|
|
||||||
return startSetupMode(store, tuner, audio);
|
return startSetupMode(store, tuner, audio, companionChips);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetBootstrap::NetBootstrap(std::optional<SoftApHost> softAp,
|
NetBootstrap::NetBootstrap(std::optional<SoftApHost> softAp,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "core/AudioProfile.hpp"
|
#include "core/AudioProfile.hpp"
|
||||||
#include "core/AudioProfileJson.hpp"
|
#include "core/AudioProfileJson.hpp"
|
||||||
|
#include "core/CompanionChipStatus.hpp"
|
||||||
#include "core/FirmwareVersion.hpp"
|
#include "core/FirmwareVersion.hpp"
|
||||||
#include "core/HealthStatus.hpp"
|
#include "core/HealthStatus.hpp"
|
||||||
#include "core/HealthStatusJson.hpp"
|
#include "core/HealthStatusJson.hpp"
|
||||||
@@ -44,7 +45,7 @@ namespace net {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr char kTag[] = "SetupWebServer";
|
constexpr char kTag[] = "SetupWebServer";
|
||||||
constexpr char kFirmwareVersion[] = "0.5.0";
|
constexpr char kFirmwareVersion[] = "0.6.0";
|
||||||
constexpr unsigned kRebootDelaySec = 3;
|
constexpr unsigned kRebootDelaySec = 3;
|
||||||
|
|
||||||
extern const uint8_t www_index_html_gz_start[] asm(
|
extern const uint8_t www_index_html_gz_start[] asm(
|
||||||
@@ -165,8 +166,17 @@ template <std::size_t N>
|
|||||||
*/
|
*/
|
||||||
esp_err_t healthGetHandler(httpd_req_t* req)
|
esp_err_t healthGetHandler(httpd_req_t* req)
|
||||||
{
|
{
|
||||||
const core::HealthStatus status =
|
auto* ctx = routeContextFrom(req);
|
||||||
core::HealthStatus::ok(core::FirmwareVersion(kFirmwareVersion));
|
const core::CompanionChipStatus chips =
|
||||||
|
ctx != nullptr
|
||||||
|
? ctx->companionChips
|
||||||
|
: core::CompanionChipStatus{
|
||||||
|
.si4684Ready = false,
|
||||||
|
.adau1701Ready = false,
|
||||||
|
.bt1035Ready = false,
|
||||||
|
};
|
||||||
|
const core::HealthStatus status = core::HealthStatus::ok(
|
||||||
|
core::FirmwareVersion(kFirmwareVersion), chips);
|
||||||
const std::string json = core::serializeHealthStatusJson(status);
|
const std::string json = core::serializeHealthStatusJson(status);
|
||||||
httpd_resp_set_type(req, "application/json");
|
httpd_resp_set_type(req, "application/json");
|
||||||
return httpd_resp_send(req, json.c_str(), json.size());
|
return httpd_resp_send(req, json.c_str(), json.size());
|
||||||
@@ -622,7 +632,7 @@ SetupWebServer::SetupWebServer()
|
|||||||
, netState_(NetState::Uninitialized)
|
, netState_(NetState::Uninitialized)
|
||||||
, tuner_(nullptr)
|
, tuner_(nullptr)
|
||||||
, audio_(nullptr)
|
, audio_(nullptr)
|
||||||
, routeContext_{nullptr, nullptr, nullptr}
|
, routeContext_{nullptr, nullptr, nullptr, {}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,7 +649,7 @@ SetupWebServer::SetupWebServer(SetupWebServer&& other) noexcept
|
|||||||
other.netState_ = NetState::Uninitialized;
|
other.netState_ = NetState::Uninitialized;
|
||||||
other.tuner_ = nullptr;
|
other.tuner_ = nullptr;
|
||||||
other.audio_ = nullptr;
|
other.audio_ = nullptr;
|
||||||
other.routeContext_ = {nullptr, nullptr, nullptr};
|
other.routeContext_ = {nullptr, nullptr, nullptr, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
|
SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
|
||||||
@@ -659,7 +669,7 @@ SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
|
|||||||
other.netState_ = NetState::Uninitialized;
|
other.netState_ = NetState::Uninitialized;
|
||||||
other.tuner_ = nullptr;
|
other.tuner_ = nullptr;
|
||||||
other.audio_ = nullptr;
|
other.audio_ = nullptr;
|
||||||
other.routeContext_ = {nullptr, nullptr, nullptr};
|
other.routeContext_ = {nullptr, nullptr, nullptr, {}};
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -670,14 +680,15 @@ SetupWebServer::~SetupWebServer()
|
|||||||
httpd_stop(server_);
|
httpd_stop(server_);
|
||||||
server_ = nullptr;
|
server_ = nullptr;
|
||||||
}
|
}
|
||||||
routeContext_ = {nullptr, nullptr, nullptr};
|
routeContext_ = {nullptr, nullptr, nullptr, {}};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::expected<void, NetError> SetupWebServer::start(
|
std::expected<void, NetError> SetupWebServer::start(
|
||||||
core::ISecureStore& store,
|
core::ISecureStore& store,
|
||||||
NetState netState,
|
NetState netState,
|
||||||
tuner::TunerService& tuner,
|
tuner::TunerService& tuner,
|
||||||
audio::AudioService& audio)
|
audio::AudioService& audio,
|
||||||
|
core::CompanionChipStatus companionChips)
|
||||||
{
|
{
|
||||||
if (server_ != nullptr) {
|
if (server_ != nullptr) {
|
||||||
return {};
|
return {};
|
||||||
@@ -690,6 +701,7 @@ std::expected<void, NetError> SetupWebServer::start(
|
|||||||
routeContext_.store = &store;
|
routeContext_.store = &store;
|
||||||
routeContext_.tuner = &tuner;
|
routeContext_.tuner = &tuner;
|
||||||
routeContext_.audio = &audio;
|
routeContext_.audio = &audio;
|
||||||
|
routeContext_.companionChips = companionChips;
|
||||||
|
|
||||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||||
config.server_port = 80;
|
config.server_port = 80;
|
||||||
@@ -697,7 +709,7 @@ std::expected<void, NetError> SetupWebServer::start(
|
|||||||
|
|
||||||
if (httpd_start(&server_, &config) != ESP_OK) {
|
if (httpd_start(&server_, &config) != ESP_OK) {
|
||||||
ESP_LOGE(kTag, "httpd_start failed");
|
ESP_LOGE(kTag, "httpd_start failed");
|
||||||
routeContext_ = {nullptr, nullptr, nullptr};
|
routeContext_ = {nullptr, nullptr, nullptr, {}};
|
||||||
return std::unexpected(NetError::HttpServerStartFailed);
|
return std::unexpected(NetError::HttpServerStartFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user