Add integration startup service and fix Doxygen (fw 0.8.1).

Replace the services stub with IntegrationService for boot preset recall and tune orchestration, persist last preset in NVS, and remove invalid @return tags that broke CI on T4 metadata headers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-07 00:17:13 +02:00
co-authored by Cursor
parent 0fc714e431
commit d13012ce4b
24 changed files with 858 additions and 92 deletions
+3 -3
View File
@@ -2,8 +2,8 @@
Open-source Hi-Fi DAB+/FM receiver firmware for the ESP32-S3. Open-source Hi-Fi DAB+/FM receiver firmware for the ESP32-S3.
**Status:** fw **0.8.0**RDS/DLS now-playing metadata in tuner status; **Status:** fw **0.8.1**integration service for preset recall + audio;
preset reorder, CI on `main` (host tests, Doxygen, manual sync). RDS/DLS metadata; CI on `main`.
See [`docs/TODO.md`](docs/TODO.md) for the agent task list. See [`docs/TODO.md`](docs/TODO.md) for the agent task list.
## Quick start ## Quick start
@@ -39,7 +39,7 @@ Manual PDF (design + HTTP API + class reference):
cd docs/manual && latexmk -lualatex manual.tex cd docs/manual && latexmk -lualatex manual.tex
``` ```
## HTTP API (fw 0.8.0) ## HTTP API (fw 0.8.1)
| Method | Path | Purpose | | Method | Path | Purpose |
|--------|------|---------| |--------|------|---------|
@@ -38,7 +38,6 @@ public:
* @brief reset — discard accumulated DLS segments. * @brief reset — discard accumulated DLS segments.
* *
* @dname reset * @dname reset
* @return n/a
* @pubstate clears buffer and segment flags. * @pubstate clears buffer and segment flags.
* *
* @author Michele Bigi * @author Michele Bigi
@@ -53,7 +52,6 @@ public:
* @param segmentIndex Zero-based segment index from the chip. * @param segmentIndex Zero-based segment index from the chip.
* @param segmentCount Total segments advertised for this label. * @param segmentCount Total segments advertised for this label.
* @param payload Raw UTF-8 bytes for this segment. * @param payload Raw UTF-8 bytes for this segment.
* @return n/a
* @pubstate copies payload into buffer_ at the computed offset. * @pubstate copies payload into buffer_ at the computed offset.
* *
* @author Michele Bigi * @author Michele Bigi
@@ -20,6 +20,7 @@
#include "core/StoreError.hpp" #include "core/StoreError.hpp"
#include "core/WifiCredentials.hpp" #include "core/WifiCredentials.hpp"
#include <cstdint>
#include <expected> #include <expected>
#include <string> #include <string>
#include <string_view> #include <string_view>
@@ -157,6 +158,58 @@ public:
*/ */
[[nodiscard]] virtual std::expected<void, StoreError> [[nodiscard]] virtual std::expected<void, StoreError>
clearStationList() = 0; clearStationList() = 0;
/**
* @brief hasLastPresetIndex — check whether a last-recalled preset exists.
*
* @dname hasLastPresetIndex
* @return true when loadLastPresetIndex would succeed.
* @pubstate reads backing storage via implementation.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] virtual bool hasLastPresetIndex() const = 0;
/**
* @brief saveLastPresetIndex — persist the last recalled preset index.
*
* @dname saveLastPresetIndex
* @param index Zero-based preset list position (019).
* @return Ok on success, or StoreError::IoFailed.
* @pubstate writes backing storage via implementation.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] virtual std::expected<void, StoreError>
saveLastPresetIndex(std::uint8_t index) = 0;
/**
* @brief loadLastPresetIndex — read the last recalled preset index.
*
* @dname loadLastPresetIndex
* @return Preset index on success, or StoreError.
* @pubstate reads backing storage via implementation.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] virtual std::expected<std::uint8_t, StoreError>
loadLastPresetIndex() const = 0;
/**
* @brief clearLastPresetIndex — erase the last-recalled preset marker.
*
* @dname clearLastPresetIndex
* @return Ok on success, or StoreError::IoFailed.
* @pubstate clears backing storage via implementation.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] virtual std::expected<void, StoreError>
clearLastPresetIndex() = 0;
}; };
} // namespace core } // namespace core
@@ -0,0 +1,34 @@
/**
* @file IntegrationError.hpp
* @brief Typed errors for application integration flows.
*
* 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 IntegrationError — failure causes for preset recall orchestration.
*
* @dname IntegrationError
* @return n/a (type)
* @pubstate n/a
*
* @author Michele Bigi
* @date 2026-07-06
*/
enum class IntegrationError {
StoreFailed, ///< NVS load/save failed during startup or recall.
PresetNotFound, ///< Preset index out of range.
TuneFailed, ///< Tuner could not recall the preset target.
AudioFailed, ///< ADAU1701 profile could not be applied.
};
} // namespace core
@@ -36,7 +36,6 @@ public:
* @brief reset — clear accumulated PS and radiotext. * @brief reset — clear accumulated PS and radiotext.
* *
* @dname reset * @dname reset
* @return n/a
* @pubstate clears internal buffers. * @pubstate clears internal buffers.
* *
* @author Michele Bigi * @author Michele Bigi
@@ -52,7 +51,6 @@ public:
* @param blockB RDS block B (group type and address). * @param blockB RDS block B (group type and address).
* @param blockC RDS block C (text payload). * @param blockC RDS block C (text payload).
* @param blockD RDS block D (text payload for RT). * @param blockD RDS block D (text payload for RT).
* @return n/a
* @pubstate updates PS/RT buffers for group types 0A and 2A. * @pubstate updates PS/RT buffers for group types 0A and 2A.
* *
* @author Michele Bigi * @author Michele Bigi
@@ -104,3 +104,19 @@ add_test(NAME bt1035_at_test COMMAND bt1035_at_test)
add_executable(broadcast_metadata_test broadcast_metadata_test.cpp) add_executable(broadcast_metadata_test broadcast_metadata_test.cpp)
target_link_libraries(broadcast_metadata_test PRIVATE digiradio_core) target_link_libraries(broadcast_metadata_test PRIVATE digiradio_core)
add_test(NAME broadcast_metadata_test COMMAND broadcast_metadata_test) add_test(NAME broadcast_metadata_test COMMAND broadcast_metadata_test)
add_executable(integration_service_test integration_service_test.cpp)
target_include_directories(integration_service_test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/integration/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/station/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/tuner/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/audio/include"
)
target_sources(integration_service_test PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/integration/src/IntegrationService.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/station/src/StationService.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/tuner/src/TunerService.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../services/audio/src/AudioService.cpp"
)
target_link_libraries(integration_service_test PRIVATE digiradio_core)
add_test(NAME integration_service_test COMMAND integration_service_test)
@@ -0,0 +1,286 @@
/**
* @file integration_service_test.cpp
* @brief Host tests for IntegrationService preset recall flow.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-06
*/
#include "audio/AudioService.hpp"
#include "core/FrequencyKHz.hpp"
#include "core/IDsp.hpp"
#include "core/ISecureStore.hpp"
#include "core/StationName.hpp"
#include "core/TunerBand.hpp"
#include "integration/IntegrationService.hpp"
#include "station/StationService.hpp"
#include "tuner/TunerService.hpp"
#include <cstdlib>
#include <iostream>
#include <optional>
#include <string>
namespace {
class FakeDsp final : public core::IDsp {
public:
std::size_t applyProfileCalls{0U};
[[nodiscard]] std::expected<void, core::DspError> applyProfile(
const core::AudioProfile&) override
{
++applyProfileCalls;
return {};
}
[[nodiscard]] std::expected<void, core::DspError> applyMixer(
const core::MixerState&) override
{
return {};
}
[[nodiscard]] std::expected<void, core::DspError> applyEq(
const core::EqProfile&) override
{
return {};
}
[[nodiscard]] std::expected<void, core::DspError> setInputVolume(
core::MixSource, core::GainDb, core::GainDb) override
{
return {};
}
[[nodiscard]] std::expected<void, core::DspError> setMasterVolume(
core::GainDb, core::GainDb) override
{
return {};
}
[[nodiscard]] std::expected<void, core::DspError> setEqBand(
core::EqBandIndex, core::GainDb, core::FrequencyHz, float) override
{
return {};
}
};
class TrackingTuner final : public core::ITuner {
public:
bool tunedFm{false};
[[nodiscard]] std::expected<void, core::TunerError> boot(
core::TunerBand) override
{
return {};
}
[[nodiscard]] std::expected<core::TunerBand, core::TunerError> currentBand()
const override
{
return core::TunerBand::Fm;
}
[[nodiscard]] std::expected<core::TunerStatus, core::TunerError> readStatus()
override
{
core::TunerStatus status = {};
status.booted = true;
status.band = core::TunerBand::Fm;
status.locked = true;
status.volume = 40;
return status;
}
[[nodiscard]] std::expected<void, core::TunerError> tuneDab(
std::uint8_t) override
{
return {};
}
[[nodiscard]] std::expected<void, core::TunerError> tuneFm(
core::FrequencyKHz) override
{
tunedFm = true;
return {};
}
[[nodiscard]] std::expected<core::FrequencyKHz, core::TunerError> seekFm(
core::SeekDirection) override
{
return std::unexpected(core::TunerError::WrongBand);
}
[[nodiscard]] std::expected<std::vector<core::TunerServiceEntry>,
core::TunerError>
listDabServices() override
{
return std::vector<core::TunerServiceEntry>{};
}
[[nodiscard]] std::expected<void, core::TunerError> playDabService(
std::uint32_t, std::uint32_t) override
{
return {};
}
[[nodiscard]] std::expected<void, core::TunerError> setVolume(
std::uint8_t) override
{
return {};
}
};
class FakeSecureStore final : public core::ISecureStore {
public:
[[nodiscard]] bool hasWifiCredentials() const override
{
return false;
}
[[nodiscard]] std::expected<void, core::StoreError> saveWifiCredentials(
const core::WifiCredentials&) override
{
return std::unexpected(core::StoreError::IoFailed);
}
[[nodiscard]] std::expected<core::WifiCredentials, core::StoreError>
loadWifiCredentials() const override
{
return std::unexpected(core::StoreError::NotFound);
}
[[nodiscard]] std::expected<void, core::StoreError> clearWifiCredentials()
override
{
return {};
}
[[nodiscard]] bool hasStationList() const override
{
return stationJson_.has_value();
}
[[nodiscard]] std::expected<void, core::StoreError> saveStationListJson(
std::string_view json) override
{
stationJson_ = std::string(json);
return {};
}
[[nodiscard]] std::expected<std::string, core::StoreError>
loadStationListJson() const override
{
if (!stationJson_) {
return std::unexpected(core::StoreError::NotFound);
}
return *stationJson_;
}
[[nodiscard]] std::expected<void, core::StoreError> clearStationList()
override
{
stationJson_.reset();
return {};
}
[[nodiscard]] bool hasLastPresetIndex() const override
{
return lastPresetIndex_.has_value();
}
[[nodiscard]] std::expected<void, core::StoreError> saveLastPresetIndex(
std::uint8_t index) override
{
lastPresetIndex_ = index;
return {};
}
[[nodiscard]] std::expected<std::uint8_t, core::StoreError>
loadLastPresetIndex() const override
{
if (!lastPresetIndex_) {
return std::unexpected(core::StoreError::NotFound);
}
return *lastPresetIndex_;
}
[[nodiscard]] std::expected<void, core::StoreError> clearLastPresetIndex()
override
{
lastPresetIndex_.reset();
return {};
}
private:
std::optional<std::string> stationJson_;
std::optional<std::uint8_t> lastPresetIndex_;
};
[[nodiscard]] core::Station makeFmStation(const char* name, std::uint32_t khz)
{
return core::Station(
*core::StationName::tryFrom(name),
core::TunerBand::Fm,
0U,
std::nullopt,
std::nullopt,
*core::FrequencyKHz::tryFromKhz(khz),
std::nullopt);
}
[[nodiscard]] int runRecallPresetTest()
{
FakeSecureStore store;
TrackingTuner tunerHw;
FakeDsp dsp;
tuner::TunerService tunerService(tunerHw);
audio::AudioService audioService(dsp, nullptr);
station::StationService stationService(store, tunerService);
integration::IntegrationService integration(
store, tunerService, audioService, stationService);
if (auto added = stationService.add(makeFmStation("Jazz", 101500U)); !added) {
std::cerr << "add preset failed\n";
return EXIT_FAILURE;
}
if (auto recalled = integration.recallPreset(0U); !recalled) {
std::cerr << "recallPreset failed\n";
return EXIT_FAILURE;
}
if (!tunerHw.tunedFm || dsp.applyProfileCalls == 0U
|| !store.hasLastPresetIndex()) {
std::cerr << "recallPreset side effects missing\n";
return EXIT_FAILURE;
}
tunerHw.tunedFm = false;
dsp.applyProfileCalls = 0U;
integration::IntegrationService rebooted(
store, tunerService, audioService, stationService);
if (auto started = rebooted.startup(); !started) {
std::cerr << "startup failed\n";
return EXIT_FAILURE;
}
if (!tunerHw.tunedFm || dsp.applyProfileCalls == 0U) {
std::cerr << "startup did not recall last preset\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
} // namespace
int main()
{
if (runRecallPresetTest() != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
@@ -143,8 +143,37 @@ public:
return {}; return {};
} }
[[nodiscard]] bool hasLastPresetIndex() const override
{
return lastPresetIndex_.has_value();
}
[[nodiscard]] std::expected<void, core::StoreError> saveLastPresetIndex(
std::uint8_t index) override
{
lastPresetIndex_ = index;
return {};
}
[[nodiscard]] std::expected<std::uint8_t, core::StoreError>
loadLastPresetIndex() const override
{
if (!lastPresetIndex_) {
return std::unexpected(core::StoreError::NotFound);
}
return *lastPresetIndex_;
}
[[nodiscard]] std::expected<void, core::StoreError> clearLastPresetIndex()
override
{
lastPresetIndex_.reset();
return {};
}
private: private:
std::optional<std::string> stationJson_; std::optional<std::string> stationJson_;
std::optional<std::uint8_t> lastPresetIndex_;
}; };
[[nodiscard]] core::Station makeFmStation(const char* name, std::uint32_t khz) [[nodiscard]] core::Station makeFmStation(const char* name, std::uint32_t khz)
+1 -1
View File
@@ -7,7 +7,7 @@ idf_component_register(
"src/NetBootstrap.cpp" "src/NetBootstrap.cpp"
INCLUDE_DIRS "include" INCLUDE_DIRS "include"
EMBED_FILES "www/index.html.gz" EMBED_FILES "www/index.html.gz"
REQUIRES core esp_wifi esp_netif esp_event nvs_flash esp_http_server tuner audio bluetooth station bt1035 REQUIRES core esp_wifi esp_netif esp_event nvs_flash esp_http_server tuner audio bluetooth station integration bt1035
) )
target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23) target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23)
@@ -40,6 +40,10 @@ namespace station {
class StationService; class StationService;
} // namespace station } // namespace station
namespace integration {
class IntegrationService;
} // namespace integration
namespace tuner { namespace tuner {
class TunerService; class TunerService;
} // namespace tuner } // namespace tuner
@@ -68,6 +72,7 @@ public:
* @param audio Audio service exposed by the HTTP API. * @param audio Audio service exposed by the HTTP API.
* @param bluetooth Bluetooth pairing service for REST routes. * @param bluetooth Bluetooth pairing service for REST routes.
* @param stations Station preset service for REST routes. * @param stations Station preset service for REST routes.
* @param integration Application orchestration for preset recall.
* @param companionChips Boot flags exposed on GET /api/health. * @param companionChips Boot flags exposed on GET /api/health.
* @return NetBootstrap on success, or a NetError. * @return NetBootstrap on success, or a NetError.
* @pubstate none * @pubstate none
@@ -79,6 +84,7 @@ public:
start(core::ISecureStore& store, tuner::TunerService& tuner, start(core::ISecureStore& store, tuner::TunerService& tuner,
audio::AudioService& audio, bluetooth::BluetoothService& bluetooth, audio::AudioService& audio, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips); core::CompanionChipStatus companionChips);
NetBootstrap(const NetBootstrap&) = delete; NetBootstrap(const NetBootstrap&) = delete;
@@ -38,6 +38,10 @@ namespace station {
class StationService; class StationService;
} // namespace station } // namespace station
namespace integration {
class IntegrationService;
} // namespace integration
namespace tuner { namespace tuner {
class TunerService; class TunerService;
} // namespace tuner } // namespace tuner
@@ -63,6 +67,7 @@ struct HttpRouteContext {
audio::AudioService* audio; ///< Audio service for ADAU1701 REST routes. audio::AudioService* audio; ///< Audio service for ADAU1701 REST routes.
bluetooth::BluetoothService* bluetooth; ///< Bluetooth pairing REST routes. bluetooth::BluetoothService* bluetooth; ///< Bluetooth pairing REST routes.
station::StationService* stations; ///< Preset list REST routes. station::StationService* stations; ///< Preset list REST routes.
integration::IntegrationService* integration; ///< Preset recall orchestration.
core::CompanionChipStatus companionChips; ///< Boot flags for /api/health. core::CompanionChipStatus companionChips; ///< Boot flags for /api/health.
}; };
@@ -139,6 +144,7 @@ public:
* @param audio Audio service for the audio REST routes. * @param audio Audio service for the audio REST routes.
* @param bluetooth Bluetooth service for pairing REST routes. * @param bluetooth Bluetooth service for pairing REST routes.
* @param stations Station preset service for list REST routes. * @param stations Station preset service for list REST routes.
* @param integration Application orchestration for preset recall.
* @param companionChips Boot flags for GET /api/health. * @param companionChips Boot flags for GET /api/health.
* @return Ok on success, or NetError::HttpServerStartFailed. * @return Ok on success, or NetError::HttpServerStartFailed.
* @pubstate writes server_, store_, netState_, and service pointers on success. * @pubstate writes server_, store_, netState_, and service pointers on success.
@@ -151,6 +157,7 @@ public:
tuner::TunerService& tuner, audio::AudioService& audio, tuner::TunerService& tuner, audio::AudioService& audio,
bluetooth::BluetoothService& bluetooth, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips); core::CompanionChipStatus companionChips);
private: private:
@@ -161,6 +168,7 @@ private:
audio::AudioService* audio_; audio::AudioService* audio_;
bluetooth::BluetoothService* bluetooth_; bluetooth::BluetoothService* bluetooth_;
station::StationService* stations_; station::StationService* stations_;
integration::IntegrationService* integration_;
HttpRouteContext routeContext_; HttpRouteContext routeContext_;
}; };
+7 -4
View File
@@ -105,6 +105,7 @@ startSetupMode(core::ISecureStore& store, tuner::TunerService& tuner,
audio::AudioService& audio, audio::AudioService& audio,
bluetooth::BluetoothService& bluetooth, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips) core::CompanionChipStatus companionChips)
{ {
esp_netif_create_default_wifi_ap(); esp_netif_create_default_wifi_ap();
@@ -117,7 +118,7 @@ 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,
bluetooth, stations, companionChips); bluetooth, stations, integration, companionChips);
!webResult) { !webResult) {
return std::unexpected(webResult.error()); return std::unexpected(webResult.error());
} }
@@ -143,6 +144,7 @@ startStaMode(core::ISecureStore& store, tuner::TunerService& tuner,
audio::AudioService& audio, audio::AudioService& audio,
bluetooth::BluetoothService& bluetooth, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips) core::CompanionChipStatus companionChips)
{ {
auto credsResult = store.loadWifiCredentials(); auto credsResult = store.loadWifiCredentials();
@@ -161,7 +163,7 @@ 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,
bluetooth, stations, companionChips); bluetooth, stations, integration, companionChips);
!webResult) { !webResult) {
return std::unexpected(webResult.error()); return std::unexpected(webResult.error());
} }
@@ -178,6 +180,7 @@ NetBootstrap::start(core::ISecureStore& store, tuner::TunerService& tuner,
audio::AudioService& audio, audio::AudioService& audio,
bluetooth::BluetoothService& bluetooth, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips) core::CompanionChipStatus companionChips)
{ {
if (auto platform = initPlatform(); !platform) { if (auto platform = initPlatform(); !platform) {
@@ -190,14 +193,14 @@ NetBootstrap::start(core::ISecureStore& store, tuner::TunerService& tuner,
if (store.hasWifiCredentials()) { if (store.hasWifiCredentials()) {
auto staResult = startStaMode(store, tuner, audio, bluetooth, stations, auto staResult = startStaMode(store, tuner, audio, bluetooth, stations,
companionChips); integration, 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, bluetooth, stations, return startSetupMode(store, tuner, audio, bluetooth, stations, integration,
companionChips); companionChips);
} }
+42 -16
View File
@@ -25,6 +25,7 @@
#include "core/FirmwareVersion.hpp" #include "core/FirmwareVersion.hpp"
#include "core/HealthStatus.hpp" #include "core/HealthStatus.hpp"
#include "core/HealthStatusJson.hpp" #include "core/HealthStatusJson.hpp"
#include "core/IntegrationError.hpp"
#include "core/ParseError.hpp" #include "core/ParseError.hpp"
#include "core/SeekDirection.hpp" #include "core/SeekDirection.hpp"
#include "core/StationListJson.hpp" #include "core/StationListJson.hpp"
@@ -35,6 +36,7 @@
#include "audio/AudioService.hpp" #include "audio/AudioService.hpp"
#include "bluetooth/BluetoothService.hpp" #include "bluetooth/BluetoothService.hpp"
#include "station/StationService.hpp" #include "station/StationService.hpp"
#include "integration/IntegrationService.hpp"
#include "bt1035/Bt1035Error.hpp" #include "bt1035/Bt1035Error.hpp"
#include "esp_http_server.h" #include "esp_http_server.h"
@@ -50,7 +52,7 @@ namespace net {
namespace { namespace {
constexpr char kTag[] = "SetupWebServer"; constexpr char kTag[] = "SetupWebServer";
constexpr char kFirmwareVersion[] = "0.8.0"; constexpr char kFirmwareVersion[] = "0.8.1";
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(
@@ -136,6 +138,22 @@ void rebootTask(void* arg)
return "tuner_error"; return "tuner_error";
} }
[[nodiscard]] const char* integrationErrorToken(
core::IntegrationError error) noexcept
{
switch (error) {
case core::IntegrationError::StoreFailed:
return "store_failed";
case core::IntegrationError::PresetNotFound:
return "not_found";
case core::IntegrationError::TuneFailed:
return "tune_failed";
case core::IntegrationError::AudioFailed:
return "audio_failed";
}
return "integration_error";
}
[[nodiscard]] const char* bt1035ErrorToken(bt1035::Bt1035Error error) noexcept [[nodiscard]] const char* bt1035ErrorToken(bt1035::Bt1035Error error) noexcept
{ {
switch (error) { switch (error) {
@@ -831,7 +849,7 @@ esp_err_t stationsReorderPostHandler(httpd_req_t* req)
esp_err_t stationsTunePostHandler(httpd_req_t* req) esp_err_t stationsTunePostHandler(httpd_req_t* req)
{ {
auto* ctx = routeContextFrom(req); auto* ctx = routeContextFrom(req);
if (ctx == nullptr || ctx->stations == nullptr || ctx->tuner == nullptr) { if (ctx == nullptr || ctx->integration == nullptr) {
httpd_resp_set_status(req, "503 Service Unavailable"); httpd_resp_set_status(req, "503 Service Unavailable");
return httpd_resp_send(req, nullptr, 0); return httpd_resp_send(req, nullptr, 0);
} }
@@ -848,17 +866,14 @@ esp_err_t stationsTunePostHandler(httpd_req_t* req)
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());
} }
if (parsed->index >= ctx->stations->list().stations().size()) { if (auto tuned = ctx->integration->recallPreset(parsed->index); !tuned) {
const std::string json = const std::string json = core::serializeTunerErrorJson(
core::serializeStationListErrorJson("not_found"); integrationErrorToken(tuned.error()));
if (tuned.error() == core::IntegrationError::PresetNotFound) {
httpd_resp_set_status(req, "404 Not Found"); httpd_resp_set_status(req, "404 Not Found");
httpd_resp_set_type(req, "application/json"); } else {
return httpd_resp_send(req, json.c_str(), json.size());
}
if (auto tuned = ctx->stations->tuneToIndex(parsed->index); !tuned) {
const std::string json =
core::serializeTunerErrorJson(tunerErrorToken(tuned.error()));
httpd_resp_set_status(req, "500 Internal Server Error"); httpd_resp_set_status(req, "500 Internal Server Error");
}
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());
} }
@@ -876,7 +891,8 @@ SetupWebServer::SetupWebServer()
, audio_(nullptr) , audio_(nullptr)
, bluetooth_(nullptr) , bluetooth_(nullptr)
, stations_(nullptr) , stations_(nullptr)
, routeContext_{nullptr, nullptr, nullptr, nullptr, nullptr, {}} , integration_(nullptr)
, routeContext_{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, {}}
{ {
} }
@@ -888,6 +904,7 @@ SetupWebServer::SetupWebServer(SetupWebServer&& other) noexcept
, audio_(other.audio_) , audio_(other.audio_)
, bluetooth_(other.bluetooth_) , bluetooth_(other.bluetooth_)
, stations_(other.stations_) , stations_(other.stations_)
, integration_(other.integration_)
, routeContext_(other.routeContext_) , routeContext_(other.routeContext_)
{ {
other.server_ = nullptr; other.server_ = nullptr;
@@ -897,7 +914,9 @@ SetupWebServer::SetupWebServer(SetupWebServer&& other) noexcept
other.audio_ = nullptr; other.audio_ = nullptr;
other.bluetooth_ = nullptr; other.bluetooth_ = nullptr;
other.stations_ = nullptr; other.stations_ = nullptr;
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, {}}; other.integration_ = nullptr;
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, {}};
} }
SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
@@ -913,6 +932,7 @@ SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
audio_ = other.audio_; audio_ = other.audio_;
bluetooth_ = other.bluetooth_; bluetooth_ = other.bluetooth_;
stations_ = other.stations_; stations_ = other.stations_;
integration_ = other.integration_;
routeContext_ = other.routeContext_; routeContext_ = other.routeContext_;
other.server_ = nullptr; other.server_ = nullptr;
other.store_ = nullptr; other.store_ = nullptr;
@@ -921,7 +941,9 @@ SetupWebServer& SetupWebServer::operator=(SetupWebServer&& other) noexcept
other.audio_ = nullptr; other.audio_ = nullptr;
other.bluetooth_ = nullptr; other.bluetooth_ = nullptr;
other.stations_ = nullptr; other.stations_ = nullptr;
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, {}}; other.integration_ = nullptr;
other.routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, {}};
} }
return *this; return *this;
} }
@@ -932,7 +954,7 @@ SetupWebServer::~SetupWebServer()
httpd_stop(server_); httpd_stop(server_);
server_ = nullptr; server_ = nullptr;
} }
routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, {}}; routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, {}};
} }
std::expected<void, NetError> SetupWebServer::start( std::expected<void, NetError> SetupWebServer::start(
@@ -942,6 +964,7 @@ std::expected<void, NetError> SetupWebServer::start(
audio::AudioService& audio, audio::AudioService& audio,
bluetooth::BluetoothService& bluetooth, bluetooth::BluetoothService& bluetooth,
station::StationService& stations, station::StationService& stations,
integration::IntegrationService& integration,
core::CompanionChipStatus companionChips) core::CompanionChipStatus companionChips)
{ {
if (server_ != nullptr) { if (server_ != nullptr) {
@@ -954,11 +977,13 @@ std::expected<void, NetError> SetupWebServer::start(
audio_ = &audio; audio_ = &audio;
bluetooth_ = &bluetooth; bluetooth_ = &bluetooth;
stations_ = &stations; stations_ = &stations;
integration_ = &integration;
routeContext_.store = &store; routeContext_.store = &store;
routeContext_.tuner = &tuner; routeContext_.tuner = &tuner;
routeContext_.audio = &audio; routeContext_.audio = &audio;
routeContext_.bluetooth = &bluetooth; routeContext_.bluetooth = &bluetooth;
routeContext_.stations = &stations; routeContext_.stations = &stations;
routeContext_.integration = &integration;
routeContext_.companionChips = companionChips; routeContext_.companionChips = companionChips;
httpd_config_t config = HTTPD_DEFAULT_CONFIG(); httpd_config_t config = HTTPD_DEFAULT_CONFIG();
@@ -967,7 +992,8 @@ 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, nullptr, nullptr, {}}; routeContext_ = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
{}};
return std::unexpected(NetError::HttpServerStartFailed); return std::unexpected(NetError::HttpServerStartFailed);
} }
@@ -111,6 +111,17 @@ public:
[[nodiscard]] std::expected<void, core::StoreError> [[nodiscard]] std::expected<void, core::StoreError>
clearStationList() override; clearStationList() override;
[[nodiscard]] bool hasLastPresetIndex() const override;
[[nodiscard]] std::expected<void, core::StoreError>
saveLastPresetIndex(std::uint8_t index) override;
[[nodiscard]] std::expected<std::uint8_t, core::StoreError>
loadLastPresetIndex() const override;
[[nodiscard]] std::expected<void, core::StoreError>
clearLastPresetIndex() override;
}; };
} // namespace secure_store } // namespace secure_store
@@ -31,6 +31,7 @@ constexpr char kNamespace[] = "digiradio";
constexpr char kSsidKey[] = "wifi_ssid"; constexpr char kSsidKey[] = "wifi_ssid";
constexpr char kPasswordKey[] = "wifi_pwd"; constexpr char kPasswordKey[] = "wifi_pwd";
constexpr char kStationListKey[] = "station_list"; constexpr char kStationListKey[] = "station_list";
constexpr char kLastPresetKey[] = "last_preset";
} // namespace } // namespace
bool NvsSecureStore::hasWifiCredentials() const bool NvsSecureStore::hasWifiCredentials() const
@@ -229,4 +230,75 @@ std::expected<void, core::StoreError> NvsSecureStore::clearStationList()
return {}; return {};
} }
bool NvsSecureStore::hasLastPresetIndex() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return false;
}
std::uint8_t value = 0U;
const esp_err_t err = nvs_get_u8(handle, kLastPresetKey, &value);
nvs_close(handle);
return err == ESP_OK;
}
std::expected<void, core::StoreError>
NvsSecureStore::saveLastPresetIndex(std::uint8_t index)
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READWRITE, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
esp_err_t err = nvs_set_u8(handle, kLastPresetKey, index);
if (err == ESP_OK) {
err = nvs_commit(handle);
}
nvs_close(handle);
if (err != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
return {};
}
std::expected<std::uint8_t, core::StoreError>
NvsSecureStore::loadLastPresetIndex() const
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READONLY, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::NotFound);
}
std::uint8_t value = 0U;
const esp_err_t err = nvs_get_u8(handle, kLastPresetKey, &value);
nvs_close(handle);
if (err != ESP_OK) {
return std::unexpected(core::StoreError::NotFound);
}
return value;
}
std::expected<void, core::StoreError> NvsSecureStore::clearLastPresetIndex()
{
nvs_handle_t handle = 0;
if (nvs_open(kNamespace, NVS_READWRITE, &handle) != ESP_OK) {
return std::unexpected(core::StoreError::IoFailed);
}
esp_err_t err = nvs_erase_key(handle, kLastPresetKey);
if (err == ESP_OK || err == ESP_ERR_NVS_NOT_FOUND) {
err = nvs_commit(handle);
}
nvs_close(handle);
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) {
return std::unexpected(core::StoreError::IoFailed);
}
return {};
}
} // namespace secure_store } // namespace secure_store
@@ -1,6 +1,8 @@
idf_component_register( idf_component_register(
SRCS "src/component_stub.cpp" SRCS
"src/IntegrationService.cpp"
INCLUDE_DIRS "include" INCLUDE_DIRS "include"
REQUIRES core tuner audio station
) )
target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23) target_compile_features(${COMPONENT_LIB} PUBLIC cxx_std_23)
@@ -0,0 +1,132 @@
/**
* @file IntegrationService.hpp
* @brief Orchestrates tuner, audio, and preset recall for app_main.
*
* 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
#include "audio/AudioService.hpp"
#include "core/IntegrationError.hpp"
#include "core/ISecureStore.hpp"
#include "station/StationService.hpp"
#include "tuner/TunerService.hpp"
#include <cstddef>
#include <expected>
namespace integration {
/**
* @brief IntegrationService — end-to-end radio listening orchestration.
*
* @dname IntegrationService
* @return n/a (type)
* @pubstate Borrows store, tuner, audio, and stations for process lifetime.
* Called from app_main for startup and from HTTP for preset recall.
*
* @author Michele Bigi
* @date 2026-07-06
*/
class IntegrationService {
public:
/**
* @brief IntegrationService — bind application services.
*
* @dname IntegrationService
* @param store Secure persistence for presets and last recall index.
* @param tuner Tuner orchestration.
* @param audio ADAU1701 profile orchestration.
* @param stations Preset list CRUD and tune delegation.
* @pubstate stores references; no side effects until startup().
*
* @author Michele Bigi
* @date 2026-07-06
*/
IntegrationService(core::ISecureStore& store,
tuner::TunerService& tuner,
audio::AudioService& audio,
station::StationService& stations);
/**
* @brief startup — load presets and recall the last station if stored.
*
* @dname startup
* @return Ok on success, or IntegrationError when recall fails.
* @pubstate loads station list; may tune and refresh the audio profile.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] std::expected<void, core::IntegrationError> startup();
/**
* @brief recallPreset — tune a preset and apply the saved audio profile.
*
* @dname recallPreset
* @param index Zero-based preset list position.
* @return Ok on success, or IntegrationError.
* @pubstate tunes via StationService, safeloads AudioProfile, persists index.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] std::expected<void, core::IntegrationError> recallPreset(
std::size_t index);
/**
* @brief stations — access the preset list service.
*
* @dname stations
* @return Reference to the injected StationService.
* @pubstate reads stations_.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] station::StationService& stations() noexcept;
/**
* @brief tuner — access the tuner service.
*
* @dname tuner
* @return Reference to the injected TunerService.
* @pubstate reads tuner_.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] tuner::TunerService& tuner() noexcept;
/**
* @brief audio — access the audio service.
*
* @dname audio
* @return Reference to the injected AudioService.
* @pubstate reads audio_.
*
* @author Michele Bigi
* @date 2026-07-06
*/
[[nodiscard]] audio::AudioService& audio() noexcept;
private:
[[nodiscard]] std::expected<void, core::IntegrationError>
applyStoredAudioProfile();
[[nodiscard]] std::expected<void, core::StoreError> persistLastPreset(
std::size_t index);
core::ISecureStore& store_;
tuner::TunerService& tuner_;
audio::AudioService& audio_;
station::StationService& stations_;
};
} // namespace integration
@@ -0,0 +1,109 @@
/**
* @file IntegrationService.cpp
* @brief IntegrationService implementation.
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* Copyright 2026 Michele Bigi
* SPDX-License-Identifier: Apache-2.0
*
* @author Michele Bigi
* @date 2026-07-06
*/
#include "integration/IntegrationService.hpp"
namespace integration {
IntegrationService::IntegrationService(core::ISecureStore& store,
tuner::TunerService& tuner,
audio::AudioService& audio,
station::StationService& stations)
: store_(store)
, tuner_(tuner)
, audio_(audio)
, stations_(stations)
{
}
std::expected<void, core::IntegrationError> IntegrationService::startup()
{
if (auto loaded = stations_.loadFromStore(); !loaded) {
return std::unexpected(core::IntegrationError::StoreFailed);
}
if (!store_.hasLastPresetIndex()) {
return {};
}
const auto index = store_.loadLastPresetIndex();
if (!index) {
return std::unexpected(core::IntegrationError::StoreFailed);
}
if (*index >= stations_.list().stations().size()) {
(void)store_.clearLastPresetIndex();
return {};
}
(void)recallPreset(*index);
return {};
}
std::expected<void, core::IntegrationError> IntegrationService::recallPreset(
std::size_t index)
{
if (index >= stations_.list().stations().size()) {
return std::unexpected(core::IntegrationError::PresetNotFound);
}
if (auto tuned = stations_.tuneToIndex(index); !tuned) {
return std::unexpected(core::IntegrationError::TuneFailed);
}
if (auto applied = applyStoredAudioProfile(); !applied) {
return applied;
}
if (auto saved = persistLastPreset(index); !saved) {
return std::unexpected(core::IntegrationError::StoreFailed);
}
return {};
}
station::StationService& IntegrationService::stations() noexcept
{
return stations_;
}
tuner::TunerService& IntegrationService::tuner() noexcept
{
return tuner_;
}
audio::AudioService& IntegrationService::audio() noexcept
{
return audio_;
}
std::expected<void, core::IntegrationError>
IntegrationService::applyStoredAudioProfile()
{
if (auto applied = audio_.applyProfile(audio_.currentProfile(), false);
!applied) {
return std::unexpected(core::IntegrationError::AudioFailed);
}
return {};
}
std::expected<void, core::StoreError> IntegrationService::persistLastPreset(
std::size_t index)
{
if (index > 255U) {
return std::unexpected(core::StoreError::InvalidData);
}
return store_.saveLastPresetIndex(static_cast<std::uint8_t>(index));
}
} // namespace integration
@@ -1,33 +0,0 @@
/**
* @file component_stub.cpp
* @brief Application services placeholder (Slice 7).
*
* DigiRadio firmware — https://github.com/manvalan/DigiRadio
*
* 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
*/
namespace services::detail {
/**
* @brief servicesComponentLinked — ensures the services component links.
*
* @dname servicesComponentLinked
* @return n/a (type)
* @pubstate n/a
*
* @author Michele Bigi
* @date 2026-07-06
*/
void servicesComponentLinked() noexcept {}
} // namespace services::detail
+8 -14
View File
@@ -12,15 +12,15 @@ errors, no plaintext secrets.
Working directory for all commands is `Software/`. Working directory for all commands is `Software/`.
**Current firmware:** `0.8.0`broadcast metadata (RDS PS/RT, DAB DLS), **Current firmware:** `0.8.1`integration service (preset recall +
preset reorder, CI gate (Doxygen + host tests + manual sync). audio profile), RDS/DLS metadata, CI gate.
--- ---
## Completed (fw 0.7.00.7.2) ## Completed (fw 0.7.00.7.2)
- **Broadcast metadata (T4)** — RDS PS/RT and DAB DLS in - **Integration service (T5)** — preset recall with audio profile re-apply,
`/api/tuner/status`, core parsers, Si4684 driver hook, UI lines. last-preset NVS, \texttt{app\_main} orchestration.
- **BT1035 pairing** — `AT+PAIR`, `AT+A2DPSTAT`, `AT+A2DPDISC`, - **BT1035 pairing** — `AT+PAIR`, `AT+A2DPSTAT`, `AT+A2DPDISC`,
`BluetoothService`, REST + UI (not numbered below; landed with Slice 7). `BluetoothService`, REST + UI (not numbered below; landed with Slice 7).
@@ -50,16 +50,10 @@ status and preset save, UI Up/Dn, host tests. **Remaining:** device HIL
`BroadcastLabel`, RDS accumulator, DAB DLS accumulator, driver `BroadcastLabel`, RDS accumulator, DAB DLS accumulator, driver
`readDabServiceData`, status JSON fields, UI now-playing lines, host tests. `readDabServiceData`, status JSON fields, UI now-playing lines, host tests.
### T5. Remove the services stub — integration service ### T5. Remove the services stub — integration service — **DONE (fw 0.8.1)**
**Why:** `components/services/src/component_stub.cpp` is a Slice-7 `integration::IntegrationService` orchestrates startup, preset recall,
placeholder. Tuner and Audio services exist separately but nothing audio profile re-apply, and last-preset NVS. Stub removed; `app_main` and
orchestrates them together. `POST /api/stations/tune` delegate here.
**What:** implement the integration layer that binds `TunerService`,
`AudioService`, the station list, and the network layer into the
application flow (e.g. "select a preset → tune → apply the stored audio
profile"). Replace the stub file.
**Done when:** `app_main` drives a real end-to-end flow through this
service; the stub is gone; a manual section documents the new class.
--- ---
+9 -5
View File
@@ -36,7 +36,7 @@ Returns a health-check DTO serialised by
\begin{drnote}[Response schema] \begin{drnote}[Response schema]
\begin{drcode}[JSON] \begin{drcode}[JSON]
{"status":"ok","fw":"0.8.0", {"status":"ok","fw":"0.8.1",
"chips":{"si4684":true,"adau1701":true,"bt1035":true}} "chips":{"si4684":true,"adau1701":true,"bt1035":true}}
\end{drcode} \end{drcode}
\begin{itemize} \begin{itemize}
@@ -320,13 +320,16 @@ Reorders presets using \texttt{StationList::move()}. Body:
\subsection{\texttt{POST /api/stations/tune}} \subsection{\texttt{POST /api/stations/tune}}
\label{sec:api-stations-tune} \label{sec:api-stations-tune}
Recalls a preset via \texttt{station::StationService::tuneToIndex()}. Recalls a preset via \texttt{integration::IntegrationService::recallPreset()}
(tune, re-apply saved audio profile, persist last index).
\section{Boot and network state machine} \section{Boot and network state machine}
\label{sec:api-boot-flow} \label{sec:api-boot-flow}
At boot, \texttt{net::NetBootstrap::start(store, tuner, audio, bluetooth, At boot, \texttt{integration::IntegrationService::startup()} loads presets
stations)} consults \texttt{ISecureStore::hasWifiCredentials()}: and best-effort recalls the last station. Then
\texttt{net::NetBootstrap::start(store, tuner, audio, bluetooth, stations,
integration)} consults \texttt{ISecureStore::hasWifiCredentials()}:
\begin{enumerate} \begin{enumerate}
\item \textbf{Credentials present} --- create STA netif, connect via \item \textbf{Credentials present} --- create STA netif, connect via
@@ -346,7 +349,8 @@ Wi-Fi credentials are stored in NVS namespace \texttt{digiradio}, keys
\texttt{wifi\_ssid} and \texttt{wifi\_pwd}. Audio profiles (non-secret) use \texttt{wifi\_ssid} and \texttt{wifi\_pwd}. Audio profiles (non-secret) use
the same namespace, key \texttt{audio\_profile\_json}, via the same namespace, key \texttt{audio\_profile\_json}, via
\texttt{secure\_store::NvsAudioProfileStore}. Station presets use key \texttt{secure\_store::NvsAudioProfileStore}. Station presets use key
\texttt{station\_list} (JSON blob). Passwords are wrapped in \texttt{station\_list} (JSON blob). The last recalled preset index is stored
as \texttt{last\_preset} (u8). Passwords are wrapped in
\texttt{core::Secret} in RAM and are never logged or returned by the API. \texttt{core::Secret} in RAM and are never logged or returned by the API.
\begin{drcaution}[Encryption at rest] \begin{drcaution}[Encryption at rest]
+6
View File
@@ -261,6 +261,12 @@ Application service loading/saving presets from NVS and recalling them via
\texttt{TunerService}. Exposed on \texttt{/api/stations/*} and the Presets \texttt{TunerService}. Exposed on \texttt{/api/stations/*} and the Presets
web UI section. web UI section.
\section{IntegrationService}\label{cls:IntegrationService}
End-to-end orchestration at boot and on preset recall: loads the station
list, reapplies the saved \texttt{AudioProfile} after tune, and persists
the last preset index (NVS key \texttt{last\_preset}). Used by
\texttt{app\_main} and \texttt{POST /api/stations/tune}.
\section{BluetoothService}\label{cls:BluetoothService} \section{BluetoothService}\label{cls:BluetoothService}
Application service for BT1035 pairing and A2DP status Application service for BT1035 pairing and A2DP status
(Chapter~\ref{ch:bt1035}). Delegates to \texttt{Bt1035Driver}; tracks (Chapter~\ref{ch:bt1035}). Delegates to \texttt{Bt1035Driver}; tracks
+1 -1
View File
@@ -3,5 +3,5 @@ idf_component_register(
"main.cpp" "main.cpp"
"hardware_bootstrap.cpp" "hardware_bootstrap.cpp"
INCLUDE_DIRS "." INCLUDE_DIRS "."
REQUIRES core net secure_store adau1701 si4684 tuner audio bt1035 bluetooth station REQUIRES core net secure_store adau1701 si4684 tuner audio bt1035 bluetooth station integration
) )
+20 -8
View File
@@ -13,6 +13,7 @@
#include "hardware_bootstrap.hpp" #include "hardware_bootstrap.hpp"
#include "bluetooth/BluetoothService.hpp" #include "bluetooth/BluetoothService.hpp"
#include "integration/IntegrationService.hpp"
#include "net/NetBootstrap.hpp" #include "net/NetBootstrap.hpp"
#include "secure_store/NvsSecureStore.hpp" #include "secure_store/NvsSecureStore.hpp"
#include "station/StationService.hpp" #include "station/StationService.hpp"
@@ -42,14 +43,14 @@ void heartbeatTask(void* arg)
* @brief app_main — ESP-IDF entry point for DigiRadio firmware. * @brief app_main — ESP-IDF entry point for DigiRadio firmware.
* *
* @dname app_main * @dname app_main
* @pubstate boots companion chips, network stack, and heartbeat task. * @pubstate boots companion chips, integration layer, network, and heartbeat.
* *
* @author Michele Bigi * @author Michele Bigi
* @date 2026-07-06 * @date 2026-07-06
*/ */
extern "C" void app_main() extern "C" void app_main()
{ {
ESP_LOGI(kTag, "DigiRadio firmware boot — Slice 7"); ESP_LOGI(kTag, "DigiRadio firmware boot");
auto hwResult = hardware::HardwareBootstrap::boot(); auto hwResult = hardware::HardwareBootstrap::boot();
if (!hwResult) { if (!hwResult) {
@@ -57,22 +58,33 @@ extern "C" void app_main()
return; return;
} }
static secure_store::NvsSecureStore store;
static tuner::TunerService tunerService( static tuner::TunerService tunerService(
hardware::HardwareBootstrap::si4684Tuner()); hardware::HardwareBootstrap::si4684Tuner());
static secure_store::NvsSecureStore store;
static station::StationService stationService(store, tunerService); static station::StationService stationService(store, tunerService);
if (auto loaded = stationService.loadFromStore(); !loaded) {
ESP_LOGW(kTag, "station list load failed"); static integration::IntegrationService integration(
store,
tunerService,
hardware::HardwareBootstrap::audioService(),
stationService);
if (auto started = integration.startup(); !started) {
ESP_LOGW(kTag, "integration startup failed — continuing without recall");
} }
static bluetooth::BluetoothService bluetoothService( static bluetooth::BluetoothService bluetoothService(
hardware::HardwareBootstrap::bt1035Driver()); hardware::HardwareBootstrap::bt1035Driver());
auto netResult = net::NetBootstrap::start( auto netResult = net::NetBootstrap::start(
store, tunerService, hardware::HardwareBootstrap::audioService(), store,
bluetoothService, stationService, tunerService,
hardware::HardwareBootstrap::audioService(),
bluetoothService,
stationService,
integration,
hardware::HardwareBootstrap::companionChipStatus()); hardware::HardwareBootstrap::companionChipStatus());
if (!netResult) { if (!netResult) {
ESP_LOGE(kTag, "network bootstrap failed"); ESP_LOGE(kTag, "network bootstrap failed");