|
8 | 8 | #include "LoadTasks.hpp" |
9 | 9 | #include "MCP23008T.hpp" |
10 | 10 | #include <Adafruit_INA260.h> |
| 11 | +#include <atomic> |
11 | 12 |
|
12 | 13 | /** |
13 | 14 | * @brief Class to manage the container for load data |
@@ -84,12 +85,47 @@ class LoadContainer { |
84 | 85 | return this->angularAccell_RPMPS; |
85 | 86 | } |
86 | 87 |
|
| 88 | + static constexpr uint_fast8_t LOG_STRING_SIZE = |
| 89 | + 3 + 7 + 5 + 5 + 10 + 5 + 6 + |
| 90 | + 1; // TODO - improve this and null terminator may not be needed |
| 91 | + /** |
| 92 | + * @brief Get at string that describes the current state of the PID instance |
| 93 | + * @returns the current state of the PID instance as a string |
| 94 | + */ |
| 95 | + etl::string<LOG_STRING_SIZE> getLogString() { |
| 96 | + etl::string<LOG_STRING_SIZE> logString(TAG); // 3 chars |
| 97 | + (void)logString.append(": RPM: "); // 7 chars |
| 98 | + |
| 99 | + etl::format_spec decFormatA; |
| 100 | + (void)decFormatA.width(5).fill('0'); // [5 chars] |
| 101 | + /** |
| 102 | + * @details I don't think we need strong guarantees on logging data |
| 103 | + * @see |
| 104 | + * https://stackoverflow.com/questions/12346487/what-do-each-memory-order-mean |
| 105 | + * @see https://en.cppreference.com/cpp/atomic/memory_order |
| 106 | + */ |
| 107 | + etl::to_string(currentRPM.load(std::memory_order::relaxed), logString, |
| 108 | + decFormatA, true); // 5 chars |
| 109 | + (void)logString.append(", dRPM/s: "); // 10 chars |
| 110 | + |
| 111 | + etl::to_string(getAngularAccell_RPMPS(), logString, decFormatA, |
| 112 | + true); // 5 chars |
| 113 | + |
| 114 | + (void)logString.append(", SF: "); // 6 chars |
| 115 | + |
| 116 | + etl::format_spec decFormatB; |
| 117 | + decFormatB.width(1).fill('0'); // [1 chars] |
| 118 | + etl::to_string(static_cast<uint_fast8_t>(getSafetyFlag()), logString, |
| 119 | + decFormatB, true); // 1 char |
| 120 | + |
| 121 | + return logString; |
| 122 | + } |
| 123 | + |
87 | 124 | private: |
88 | 125 | MCP23008T &loadDevice; |
89 | 126 | ESTOP_TYPE_FAST safetyFlag = ESTOP_TYPE_FAST::NONE; // todo - make atomic? |
90 | 127 | LoadComms &loadComms; |
91 | 128 | // bool powerPositive = false; |
92 | | - int_fast16_t currentRPM = 0; // todo |
93 | 129 | int_fast16_t angularAccell_RPMPS = 0; // todo |
94 | 130 |
|
95 | 131 | /** |
@@ -132,5 +168,5 @@ class LoadContainer { |
132 | 168 | // static_assert(std::atomic<int_fast16_t>::is_always_lock_free, |
133 | 169 | // "Atomic operations on int_fast16_t are not lock-free on " |
134 | 170 | // "this platform."); |
135 | | - // std::atomic<int_fast16_t> currentRPM = 0; |
| 171 | + std::atomic<int_fast16_t> currentRPM = 0; // todo |
136 | 172 | }; |
0 commit comments