Integrate companion-chip status into GET /api/health (fw 0.6.0).

Expose Si4684, ADAU1701, and BT1035 boot flags via CompanionChipStatus after
HardwareBootstrap; update API manual schema for Slice 8.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 17:15:17 +02:00
co-authored by Cursor
parent 6efd6e36f7
commit 98518c5424
13 changed files with 191 additions and 42 deletions
@@ -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
@@ -18,6 +18,9 @@
#pragma once
#include "core/FirmwareVersion.hpp"
#include "core/CompanionChipStatus.hpp"
#include <optional>
namespace core {
@@ -64,6 +67,21 @@ public:
*/
[[nodiscard]] static HealthStatus ok(FirmwareVersion firmware);
/**
* @brief ok — build health response including companion-chip flags.
*
* @dname ok
* @param firmware Active firmware version to report.
* @param chips Si4684 / ADAU1701 / BT1035 boot snapshot.
* @return HealthStatus with HealthState::Ok and chips populated.
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] static HealthStatus ok(FirmwareVersion firmware,
CompanionChipStatus chips);
/**
* @brief state — read the health indicator.
*
@@ -88,11 +106,28 @@ public:
*/
[[nodiscard]] const FirmwareVersion& firmware() const noexcept;
/**
* @brief chips — optional companion-chip boot flags.
*
* @dname chips
* @return Chip status when set by ok(..., chips); otherwise nullopt.
* @pubstate reads chips_.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] const std::optional<CompanionChipStatus>& chips() const
noexcept;
private:
explicit HealthStatus(HealthState state, FirmwareVersion firmware);
explicit HealthStatus(HealthState state, FirmwareVersion firmware,
CompanionChipStatus chips);
HealthState state_;
FirmwareVersion firmware_;
std::optional<CompanionChipStatus> chips_;
};
} // namespace core
+20 -5
View File
@@ -7,11 +7,6 @@
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* @author Michele Bigi
* @date 2026-07-06
*/
@@ -25,9 +20,24 @@ HealthStatus HealthStatus::ok(FirmwareVersion firmware)
return HealthStatus(HealthState::Ok, std::move(firmware));
}
HealthStatus HealthStatus::ok(FirmwareVersion firmware,
CompanionChipStatus chips)
{
return HealthStatus(HealthState::Ok, std::move(firmware), chips);
}
HealthStatus::HealthStatus(HealthState state, FirmwareVersion firmware)
: state_(state)
, firmware_(std::move(firmware))
, chips_(std::nullopt)
{
}
HealthStatus::HealthStatus(HealthState state, FirmwareVersion firmware,
CompanionChipStatus chips)
: state_(state)
, firmware_(std::move(firmware))
, chips_(chips)
{
}
@@ -41,4 +51,9 @@ const FirmwareVersion& HealthStatus::firmware() const noexcept
return firmware_;
}
const std::optional<CompanionChipStatus>& HealthStatus::chips() const noexcept
{
return chips_;
}
} // namespace core
@@ -18,21 +18,13 @@
#include "core/HealthStatusJson.hpp"
#include <optional>
#include <string>
namespace core {
namespace {
/**
* @brief healthStateToken — map HealthState to the API status string.
*
* @dname healthStateToken
* @param state Health indicator to encode.
* @return JSON string token without quotes (e.g. ok).
* @pubstate none
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] const char* healthStateToken(HealthState state) noexcept
{
switch (state) {
@@ -46,8 +38,16 @@ namespace {
std::string serializeHealthStatusJson(const HealthStatus& status)
{
return std::string("{\"status\":\"") + healthStateToken(status.state())
+ "\",\"fw\":\"" + std::string(status.firmware().value()) + "\"}";
std::string json = std::string("{\"status\":\"") + healthStateToken(status.state())
+ "\",\"fw\":\"" + std::string(status.firmware().value()) + "\"";
if (const std::optional<CompanionChipStatus>& chips = status.chips(); chips) {
json += std::string(",\"chips\":{")
+ "\"si4684\":" + (chips->si4684Ready ? "true" : "false")
+ ",\"adau1701\":" + (chips->adau1701Ready ? "true" : "false")
+ ",\"bt1035\":" + (chips->bt1035Ready ? "true" : "false") + "}";
}
json += '}';
return json;
}
} // namespace core
@@ -17,6 +17,7 @@
*/
#include "core/FirmwareVersion.hpp"
#include "core/CompanionChipStatus.hpp"
#include "core/HealthStatus.hpp"
#include "core/HealthStatusJson.hpp"
@@ -85,5 +86,22 @@ namespace {
*/
int main()
{
return runHealthStatusJsonTest();
if (runHealthStatusJsonTest() != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
const core::HealthStatus withChips = core::HealthStatus::ok(
core::FirmwareVersion("0.6.0"),
core::CompanionChipStatus{
.si4684Ready = true,
.adau1701Ready = true,
.bt1035Ready = true,
});
const std::string chipsJson = core::serializeHealthStatusJson(withChips);
if (!expectEqual(
chipsJson,
R"({"status":"ok","fw":"0.6.0","chips":{"si4684":true,"adau1701":true,"bt1035":true}})")) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}