53#include "handlers/logger/Logger.h"
172 std::array<ManagerDiagnostic, kFluxManagerCount>
managers{};
256 [[nodiscard]]
size_t GetFailedComponents(const
char* out[],
size_t max_count) const noexcept;
264 [[nodiscard]]
size_t GetSystemWarnings(const
char* out[],
size_t max_count) const noexcept;
289 return last_error_.load(std::memory_order_acquire);
442#define FLUX_API Flux::GetInstance()
444#define FLUX_API_INIT() (Flux::GetInstance().EnsureInitialized(), Flux::GetInstance())
constexpr size_t kFluxManagerCount
Number of Flux subsystem managers exposed on Flux (incl. NVS).
Definition Flux.h:65
Flux & GetFlux() noexcept
Convenience accessor — equivalent to Flux::GetInstance().
Definition Flux.h:433
Version information for the HardFOC Flux V1 HAL.
Singleton manager for all analogue-to-digital channels on Flux V1.
Definition AdcManager.h:87
Singleton managing all board communication channels for Flux V1.
Definition CommChannelsManager.h:134
Unified singleton entry point for the HardFOC Flux V1 platform.
Definition Flux.h:200
flux::hal::ManagerError GetLastError() const noexcept
Why the last EnsureInitialized() failed: the error of the first required manager that did not come up...
Definition Flux.h:288
bool CollectDiagnostics(FluxHalDiagnostics &out) const noexcept
Fill the board-level bring-up snapshot (managers in init order, part readiness).
Definition Flux.cpp:339
bool InitializeAllComponents() noexcept
Definition Flux.cpp:132
size_t GetSystemWarnings(const char *out[], size_t max_count) const noexcept
Get accumulated system warnings.
Definition Flux.cpp:512
AdcManager & adc
ADC channels (NTC, VBUS)
Definition Flux.h:300
std::atomic< bool > comms_initialized_
Definition Flux.h:401
uint32_t GetLargestFreeHeapBlock() const noexcept
Largest contiguous free block in the default heap.
Definition Flux.cpp:282
const char * GetSystemVersion() const noexcept
Get the Flux HAL semantic version string.
Definition Flux.cpp:435
const char * system_warnings_[kMaxSystemWarnings]
Definition Flux.h:415
static constexpr size_t kMaxFailedComponents
Definition Flux.h:410
void SystemRestart() const noexcept
Trigger a software reset of the MCU. Does not return on success.
Definition Flux.cpp:273
bool Shutdown() noexcept
Shut down all subsystems in reverse initialisation order.
Definition Flux.cpp:472
std::atomic< uint64_t > initialization_start_time_
Definition Flux.h:397
bool InitializeTemperature() noexcept
Definition Flux.cpp:224
static constexpr size_t kMaxSystemWarnings
Definition Flux.h:414
static Flux & GetInstance() noexcept
Access the singleton instance (Meyers singleton, thread-safe).
Definition Flux.cpp:68
uint64_t GetInitializationTimeMs() const noexcept
Time in ms that the initialisation sequence took to complete.
Definition Flux.cpp:259
bool InitializeLeds() noexcept
Definition Flux.cpp:216
size_t system_warnings_count_
Definition Flux.h:416
std::atomic< bool > initialized_
Definition Flux.h:395
bool CollectManagerHealth(ManagerHealthSnapshot &snapshot) noexcept
Collect per-manager error health into a unified snapshot.
Definition Flux.cpp:286
size_t failed_components_count_
Definition Flux.h:412
bool EnsureInitialized() noexcept
Ensure all Flux subsystems are properly initialized.
Definition Flux.cpp:94
const char * failed_components_[kMaxFailedComponents]
Definition Flux.h:411
TemperatureManager & temp
Temperature sensors.
Definition Flux.h:302
std::atomic< bool > temp_initialized_
Definition Flux.h:406
GpioManager & gpio
ESP32 GPIO pins.
Definition Flux.h:298
uint64_t GetSystemUptimeMs() const noexcept
Milliseconds elapsed since EnsureInitialized() completed.
Definition Flux.cpp:255
CommChannelsManager & comms
SPI, CAN, UART (I²C not used on Flux V1)
Definition Flux.h:296
bool PerformHealthCheck() noexcept
Run a quick health check across all managers.
Definition Flux.cpp:408
bool InitializeComms() noexcept
Definition Flux.cpp:184
Flux(const Flux &)=delete
std::atomic< bool > leds_initialized_
Definition Flux.h:405
bool InitializeAdc() noexcept
Definition Flux.cpp:208
ValveManager & valves
Solenoid + proportional valve control.
Definition Flux.h:299
bool InitializeNvs() noexcept
Definition Flux.cpp:176
bool GetSystemDiagnostics(FluxSystemDiagnostics &diagnostics) const noexcept
Populate a full system diagnostics snapshot.
Definition Flux.cpp:236
std::array< bool, kFluxManagerCount > GetComponentInitializationStatus() const noexcept
Per-component init status as a bool array.
Definition Flux.cpp:243
std::atomic< bool > nvs_initialized_
Definition Flux.h:400
bool InitializeGpio() noexcept
Definition Flux.cpp:192
bool IsInitialized() const noexcept
Check whether the system is fully initialised.
Definition Flux.h:229
FluxSystemDiagnostics diagnostics_
Definition Flux.h:408
void UpdateSystemDiagnostics() noexcept
Definition Flux.cpp:439
uint32_t GetFreeHeapBytes() const noexcept
Free bytes available in the default heap.
Definition Flux.cpp:278
std::atomic< bool > valves_initialized_
Definition Flux.h:403
void DumpSystemStatistics() const noexcept
Log a comprehensive system summary to the console.
Definition Flux.cpp:385
uint32_t GetLastResetReason() const noexcept
Reset reason of the previous boot, opaque to callers.
Definition Flux.cpp:269
void AddSystemWarning(const char *warning) noexcept
Definition Flux.h:418
std::atomic< bool > gpio_initialized_
Definition Flux.h:402
LedManager & leds
WS2812 status LED.
Definition Flux.h:301
std::atomic< bool > adc_initialized_
Definition Flux.h:404
Flux & operator=(Flux &&)=delete
NvsManager & nvs
NVS (flux / flux_cal / flux_cfg)
Definition Flux.h:297
size_t GetFailedComponents(const char *out[], size_t max_count) const noexcept
Get the list of components that failed initialization.
Definition Flux.cpp:504
std::atomic< flux::hal::ManagerError > last_error_
Definition Flux.h:396
std::atomic< uint64_t > initialization_end_time_
Definition Flux.h:398
Flux & operator=(const Flux &)=delete
bool InitializeValves() noexcept
Definition Flux.cpp:200
Singleton that manages all MCU GPIO pins defined in the X-MACRO pin config.
Definition GpioManager.h:81
Singleton that drives the on-board WS2812 status LED.
Definition LedManager.h:202
Singleton owning the Flux board's persistent-storage namespaces.
Definition NvsManager.h:35
Singleton manager for all temperature sensors on Flux V1.
Definition TemperatureManager.h:168
Unified singleton for controlling all valve channels on the Flux board.
Definition ValveManager.h:296
Shared HAL types for Flux V1: the manager error catalog and the facade result.
ManagerError
Lifecycle / bind failure catalog shared by every manager (GetManagerError()).
Definition flux_hal_types.hpp:37
@ NotInitialized
Manager not initialised (or shut down)
Definition flux_hal_types.hpp:29
Board-level bring-up snapshot: every manager's state and every fitted part's readiness.
Definition Flux.h:165
bool die_temp_ready
MCU die sensor came up.
Definition Flux.h:180
bool can_ready
CAN controller object exists.
Definition Flux.h:179
bool ntc_ready
Board NTC came up.
Definition Flux.h:181
bool initialized
Flux::EnsureInitialized() succeeded (every required manager up)
Definition Flux.h:166
bool all_healthy
... and none reports an error (none degraded)
Definition Flux.h:168
bool all_managers_up
Every manager, required and optional, is initialised.
Definition Flux.h:167
bool mcp9700_ready
MCP9700 on the ADS7952 came up.
Definition Flux.h:182
bool max22200_ready
MAX22200 solenoid driver came up.
Definition Flux.h:174
bool ads7952_ready
ADS7952 device 0 came up.
Definition Flux.h:177
bool pressure_bus_ready
ADS7952 SPI bus and chip select are up.
Definition Flux.h:176
bool internal_adc_ready
MCU ADC (NTC, VBUS) came up.
Definition Flux.h:178
const char * first_error_manager
Manager that reported it.
Definition Flux.h:170
bool status_led_ready
WS2812 status LED came up.
Definition Flux.h:183
bool tle92466_ready
TLE92466ED proportional driver came up.
Definition Flux.h:175
std::array< ManagerDiagnostic, kFluxManagerCount > managers
In initialisation order.
Definition Flux.h:172
flux::hal::ManagerError first_error
First error in init order.
Definition Flux.h:169
Complete system diagnostics snapshot for the Flux API.
Definition Flux.h:72
bool valves_initialized
ValveManager ready.
Definition Flux.h:77
bool gpio_initialized
GpioManager ready.
Definition Flux.h:76
static constexpr size_t kMaxDiagEntries
Max failed-component names.
Definition Flux.h:89
bool comms_initialized
CommChannelsManager ready.
Definition Flux.h:75
const char * failed_components_list[kMaxDiagEntries]
Names of failed components.
Definition Flux.h:90
bool nvs_initialized
NvsManager ready.
Definition Flux.h:74
bool temp_initialized
TemperatureManager ready.
Definition Flux.h:80
uint64_t initialization_time_ms
Time taken to initialise all components.
Definition Flux.h:86
bool system_healthy
true when all components are initialised.
Definition Flux.h:73
size_t failed_components_list_count
Count of entries in list.
Definition Flux.h:91
uint32_t total_components
Total number of managed components (kFluxManagerCount).
Definition Flux.h:82
bool adc_initialized
AdcManager ready.
Definition Flux.h:78
FluxSystemDiagnostics() noexcept
Default constructor — all fields zeroed / false.
Definition Flux.h:94
uint32_t initialized_components
Components that initialised successfully.
Definition Flux.h:83
uint32_t failed_components
Components that failed to initialise.
Definition Flux.h:84
bool leds_initialized
LedManager ready.
Definition Flux.h:79
uint64_t system_uptime_ms
Milliseconds since first initialisation.
Definition Flux.h:87
One manager's lifecycle state in FluxHalDiagnostics.
Definition Flux.h:152
flux::hal::ManagerError error
GetManagerError()
Definition Flux.h:156
bool required
Its failure fails Flux::EnsureInitialized()
Definition Flux.h:154
const char * name
Manager class name.
Definition Flux.h:153
bool initialized
IsInitialized()
Definition Flux.h:155
Per-manager health entry for unified error aggregation.
Definition Flux.h:109
uint8_t last_error_code
Last error code (0 = success, enum-specific otherwise)
Definition Flux.h:113
bool has_error
Whether last error is non-zero.
Definition Flux.h:112
bool initialized
Whether manager is initialized.
Definition Flux.h:111
const char * name
Manager name (string literal)
Definition Flux.h:110
ManagerHealthEntry() noexcept
Definition Flux.h:115
Aggregated health snapshot across all Flux managers.
Definition Flux.h:135
static constexpr size_t kMaxManagers
Definition Flux.h:136
size_t managers_with_errors
Count of managers reporting errors.
Definition Flux.h:140
ManagerHealthSnapshot() noexcept
Definition Flux.h:143
ManagerHealthEntry entries[kMaxManagers]
Per-manager entries.
Definition Flux.h:138
bool all_healthy
True if no errors and all initialized.
Definition Flux.h:141
size_t count
Number of populated entries.
Definition Flux.h:139