HardFOC Vortex V1 HAL
Unified HAL API for the HardFOC Vortex motor-control platform (ESP32-C6, TMC9660)
Loading...
Searching...
No Matches
VortexBootReport.h
Go to the documentation of this file.
1
14#ifndef VORTEX_BOOT_REPORT_H_
15#define VORTEX_BOOT_REPORT_H_
16
17#include <array>
18#include <cstddef>
19
21public:
23 static constexpr size_t kCapacity = 12;
24
26 void Clear() noexcept {
27 failed_count_ = 0;
29 dropped_ = 0;
30 }
31
37 bool AddFailed(const char* component) noexcept { return Add(failed_, failed_count_, component); }
38
44 bool AddWarning(const char* text) noexcept { return Add(warnings_, warning_count_, text); }
45
46 [[nodiscard]] size_t FailedCount() const noexcept { return failed_count_; }
47 [[nodiscard]] size_t WarningCount() const noexcept { return warning_count_; }
48 [[nodiscard]] size_t Dropped() const noexcept { return dropped_; }
49 [[nodiscard]] const char* Failed(size_t i) const noexcept { return i < failed_count_ ? failed_[i] : nullptr; }
50 [[nodiscard]] const char* Warning(size_t i) const noexcept { return i < warning_count_ ? warnings_[i] : nullptr; }
51
53 size_t CopyFailed(const char* out[], size_t max) const noexcept { return Copy(failed_, failed_count_, out, max); }
54
56 size_t CopyWarnings(const char* out[], size_t max) const noexcept {
57 return Copy(warnings_, warning_count_, out, max);
58 }
59
60private:
61 using List = std::array<const char*, kCapacity>;
62
63 bool Add(List& list, size_t& count, const char* text) noexcept {
64 if (text == nullptr) {
65 return false;
66 }
67 for (size_t i = 0; i < count; ++i) {
68 if (list[i] == text) {
69 return true;
70 }
71 }
72 if (count >= list.size()) {
73 ++dropped_;
74 return false;
75 }
76 list[count++] = text;
77 return true;
78 }
79
80 static size_t Copy(const List& list, size_t count, const char* out[], size_t max) noexcept {
81 if (out == nullptr) {
82 return 0;
83 }
84 const size_t n = count < max ? count : max;
85 for (size_t i = 0; i < n; ++i) {
86 out[i] = list[i];
87 }
88 return n;
89 }
90
93 size_t failed_count_{0};
94 size_t warning_count_{0};
95 size_t dropped_{0};
96};
97
98#endif // VORTEX_BOOT_REPORT_H_
Definition VortexBootReport.h:20
List warnings_
Definition VortexBootReport.h:92
const char * Warning(size_t i) const noexcept
Definition VortexBootReport.h:50
size_t WarningCount() const noexcept
Definition VortexBootReport.h:47
size_t failed_count_
Definition VortexBootReport.h:93
size_t CopyFailed(const char *out[], size_t max) const noexcept
Copy up to max failed-component names into out.
Definition VortexBootReport.h:53
std::array< const char *, kCapacity > List
Definition VortexBootReport.h:61
size_t FailedCount() const noexcept
Definition VortexBootReport.h:46
size_t CopyWarnings(const char *out[], size_t max) const noexcept
Copy up to max warnings into out.
Definition VortexBootReport.h:56
static size_t Copy(const List &list, size_t count, const char *out[], size_t max) noexcept
Definition VortexBootReport.h:80
bool AddFailed(const char *component) noexcept
Record a component that failed to initialise.
Definition VortexBootReport.h:37
List failed_
Definition VortexBootReport.h:91
size_t Dropped() const noexcept
Definition VortexBootReport.h:48
static constexpr size_t kCapacity
Capacity of each list (one entry per manager is enough for failures).
Definition VortexBootReport.h:23
size_t dropped_
Definition VortexBootReport.h:95
bool AddWarning(const char *text) noexcept
Record a warning (a degraded subsystem or an unusual condition that did not fail init).
Definition VortexBootReport.h:44
const char * Failed(size_t i) const noexcept
Definition VortexBootReport.h:49
size_t warning_count_
Definition VortexBootReport.h:94
bool Add(List &list, size_t &count, const char *text) noexcept
Definition VortexBootReport.h:63
void Clear() noexcept
Forget every entry (start of a new initialisation attempt).
Definition VortexBootReport.h:26