Skip to content

Commit bcd86f7

Browse files
committed
Improved logging
1 parent edb6e28 commit bcd86f7

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

include/LoadContainer.hpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "LoadTasks.hpp"
99
#include "MCP23008T.hpp"
1010
#include <Adafruit_INA260.h>
11+
#include <atomic>
1112

1213
/**
1314
* @brief Class to manage the container for load data
@@ -84,12 +85,47 @@ class LoadContainer {
8485
return this->angularAccell_RPMPS;
8586
}
8687

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+
87124
private:
88125
MCP23008T &loadDevice;
89126
ESTOP_TYPE_FAST safetyFlag = ESTOP_TYPE_FAST::NONE; // todo - make atomic?
90127
LoadComms &loadComms;
91128
// bool powerPositive = false;
92-
int_fast16_t currentRPM = 0; // todo
93129
int_fast16_t angularAccell_RPMPS = 0; // todo
94130

95131
/**
@@ -132,5 +168,5 @@ class LoadContainer {
132168
// static_assert(std::atomic<int_fast16_t>::is_always_lock_free,
133169
// "Atomic operations on int_fast16_t are not lock-free on "
134170
// "this platform.");
135-
// std::atomic<int_fast16_t> currentRPM = 0;
171+
std::atomic<int_fast16_t> currentRPM = 0; // todo
136172
};

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,9 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS = RUN::TASK_INTERVALS::TI_LOG_DATA_ms;
657657
// TODO: Improve logging, check ESTOP logic
658658

659659
ESP_LOGI(TAG, "%s", INA260::getLogString().c_str());
660+
ESP_LOGI(TAG, "Current State: %d", loadFSM.getCurrentState());
661+
ESP_LOGI(TAG, "%S", load.getLogString().c_str());
662+
ESP_LOGI(TAG, "%s", loadDevice.getLogString().c_str());
660663

661664
static unsigned int prevTime_us = 0;
662665
static LoadComms::LogData lastLogData = {0};

0 commit comments

Comments
 (0)