Skip to content

Commit ddbfe5d

Browse files
committed
Revert "Logging Test"
This reverts commit fb6586f.
1 parent bc3f227 commit ddbfe5d

1 file changed

Lines changed: 60 additions & 81 deletions

File tree

src/main.cpp

Lines changed: 60 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "2026Core/CommonConfig.hpp" // Include after NacelleConfig due to macro precednece
1919
#include "2026Core/Net/Net-Application/NTP.hpp"
2020
// #include "2026Core/Net/Net-Application/OTA.hpp"
21-
#include "2026Core/Logging.hpp"
2221
#include "2026Core/Net/Net-Link/AdapterESPNow.hpp"
2322
#include "2026Core/Net/Net-Phy/AdapterWLAN.hpp"
2423
#include "LoadContainer.hpp"
@@ -55,15 +54,15 @@ LoadFSM loadFSM(load);
5554
// todo: move
5655
bool configureLoad() {
5756
if (!loadDevice.begin()) {
58-
LOGE_LOCKED(TAG, "Failed to initialize MCP23008T device at 0x%02X",
59-
loadDevice.getAddress());
57+
ESP_LOGE(TAG, "Failed to initialize MCP23008T device at 0x%02X",
58+
loadDevice.getAddress());
6059
return false;
6160
}
6261

6362
// First six pins outputs, made last two inputs as that's the default
6463
if (!loadDevice.setIODir(0b1100'0000)) {
65-
LOGE_LOCKED(TAG, "Failed to set IODIR on MCP23008T at 0x%02X",
66-
loadDevice.getAddress());
64+
ESP_LOGE(TAG, "Failed to set IODIR on MCP23008T at 0x%02X",
65+
loadDevice.getAddress());
6766
return false;
6867
}
6968

@@ -75,8 +74,8 @@ bool configureLoad() {
7574

7675
// Set all outputs low, note that pin 0 is inverted
7776
if (!loadDevice.setGPIO(0b0000'0000)) {
78-
LOGE_LOCKED(TAG, "Failed to set GPIO on MCP23008T at 0x%02X",
79-
loadDevice.getAddress());
77+
ESP_LOGE(TAG, "Failed to set GPIO on MCP23008T at 0x%02X",
78+
loadDevice.getAddress());
8079
return false;
8180
}
8281

@@ -106,11 +105,10 @@ inline bool showLEDsIfReady() {
106105
void setup() {
107106
static bool serialInitialized = false;
108107
if (!serialInitialized) {
108+
Serial.begin(115200);
109109
size_t txBuffer = Serial.setTxBufferSize(1024);
110-
Serial.begin(460800);
111110
ESP_LOGI(TAG, "Serial initialized @ %d baud w/ buffer size %d",
112111
Serial.baudRate(), txBuffer);
113-
Logging::initLoggingMutex();
114112
serialInitialized = true;
115113
}
116114

@@ -240,7 +238,7 @@ void setup() {
240238
if (result != pdPASS) {
241239
ESP_LOGE(TAG, "Failed to create task %s", taskDesc->name);
242240
} else {
243-
ESP_LOGE(
241+
ESP_LOGD(
244242
TAG,
245243
"Created task %s with priority %u and stack size %u bytes",
246244
taskDesc->name, taskDesc->priority,
@@ -284,10 +282,10 @@ vTaskUpdateFSM([[maybe_unused]] void *pvParameters) { // NOSONAR
284282
while (true) {
285283
// LoadFSM::UPDATE_RESULT result = loadFSM.updateState();
286284
// if (result == LoadFSM::UPDATE_RESULT::STATE_CHANGED) {
287-
// LOGI_LOCKED(TAG, "FSM State Changed: %d",
285+
// ESP_LOGI(TAG, "FSM State Changed: %d",
288286
// loadFSM.getCurrentState());
289287
// } else if (result == LoadFSM::UPDATE_RESULT::ERROR) {
290-
// LOGE_LOCKED(TAG, "Error updating FSM state");
288+
// ESP_LOGE(TAG, "Error updating FSM state");
291289
// }
292290
delay(RUN::TASK_INTERVALS::TI_FSM_mS);
293291
}
@@ -310,7 +308,7 @@ vTaskPollSensors([[maybe_unused]] void *pvParameters) { // NOSONAR
310308
vTaskAdjustLoad([[maybe_unused]] void *pvParameters) { // NOSONAR
311309
while (true) {
312310
static int i = 0;
313-
// LOGI_LOCKED(TAG, "Pitch PID Output: %f",
311+
// ESP_LOGI(TAG, "Pitch PID Output: %f",
314312
// pitchPIDController.compute(
315313
// i)); // todo - just a quick performances test
316314
i += 20;
@@ -384,10 +382,10 @@ vTaskConfigure([[maybe_unused]] void *pvParameters) { // NOSONAR
384382
while (true) {
385383
// if (!loadConfigured) {
386384
// if (loadDevice.begin()) { // FIXME!
387-
// LOGI_LOCKED(TAG, "MCP23008T initialized successfully.");
385+
// ESP_LOGI(TAG, "MCP23008T initialized successfully.");
388386
// loadConfigured = true;
389387
// } else {
390-
// LOGE_LOCKED(
388+
// ESP_LOGE(
391389
// TAG,
392390
// "Failed to initialize MCP23008T. Retrying in 5
393391
// seconds...");
@@ -425,7 +423,7 @@ vTaskConfigure([[maybe_unused]] void *pvParameters) { // NOSONAR
425423
[[noreturn]] void
426424
vTaskStatusLED([[maybe_unused]] void *pvParameters) { // NOSONAR
427425
while (true) {
428-
LOGV_LOCKED(TAG, "vTSL");
426+
ESP_LOGV(TAG, "vTSL");
429427
leds.setPixelColor(0, 0x00, 0xFF, 0x00); // Green
430428
if (leds.canShow()) {
431429
leds.show();
@@ -481,27 +479,26 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS =
481479
// continue;
482480
// }
483481

484-
LOGD_LOCKED(TAG, "Logging Data:");
482+
ESP_LOGD(TAG, "Logging Data:");
485483

486-
LOGI_LOCKED(TAG, "FreeRTOS Tasks: %u", uxTaskGetNumberOfTasks());
484+
ESP_LOGI(TAG, "FreeRTOS Tasks: %u", uxTaskGetNumberOfTasks());
487485

488486
constexpr uint_fast8_t REC_BYTES_PER_TASK = 40;
489487
constexpr uint_fast8_t NUM_ESP_TASKS =
490488
11; // TODO: Why was this set to 8 and why did I need to increase it
491489
// by 3?
492490
constexpr uint_fast16_t STATS_BUFFER_SIZE =
493491
REC_BYTES_PER_TASK * (NUM_MAIN_TASKS + NUM_ESP_TASKS);
494-
static char statsBuffer[STATS_BUFFER_SIZE] = {'\0'};
492+
char statsBuffer[STATS_BUFFER_SIZE] = {'\0'};
495493
if (uxTaskGetNumberOfTasks() > NUM_MAIN_TASKS + NUM_ESP_TASKS) {
496-
LOGE_LOCKED(
494+
ESP_LOGE(
497495
TAG,
498496
"Number of tasks (%d) exceeds expected max (%d), skipping to "
499497
"prevent memory corruption",
500498
uxTaskGetNumberOfTasks(), NUM_MAIN_TASKS + NUM_ESP_TASKS);
501-
// Serial.flush();
502499
delay(LOG_ITEM_INTERVAL_MS);
503-
// } else {
504-
} else if (statsBuffer[0] == '\0') {
500+
} else {
501+
// } else if (statsBuffer[0] == '\0') {
505502
// Refresh stats buffer
506503

507504
// TODO: Not recommended in production
@@ -510,78 +507,61 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS =
510507
'\0'; // hard cap, avoid over-read
511508
// uxTaskGetSystemState();
512509
size_t usedBytes = strnlen(statsBuffer, STATS_BUFFER_SIZE);
513-
LOGD_LOCKED(TAG, "Task Buffer Used (%): %d",
514-
usedBytes * 100 / sizeof(statsBuffer));
515-
LOGD_LOCKED(TAG, "Stats Buffer Used: %d bytes", usedBytes);
516-
LOGD_LOCKED(TAG, "Stats Buffer Free: %d bytes",
517-
sizeof(statsBuffer) - usedBytes);
518-
LOGD_LOCKED(TAG, "Stats Buffer Size: %d", sizeof(statsBuffer));
519-
// LOGI_LOCKED(TAG, "Task Run Time Stats:\n%s", statsBuffer);
510+
ESP_LOGD(TAG, "Task Buffer Used (%): %d",
511+
usedBytes * 100 / sizeof(statsBuffer));
512+
ESP_LOGD(TAG, "Stats Buffer Used: %d bytes", usedBytes);
513+
ESP_LOGD(TAG, "Stats Buffer Free: %d bytes",
514+
sizeof(statsBuffer) - usedBytes);
515+
ESP_LOGD(TAG, "Stats Buffer Size: %d", sizeof(statsBuffer));
516+
ESP_LOGI(TAG, "Task Run Time Stats:\n%s", statsBuffer);
520517
// Serial.flush();
521518
delay(LOG_ITEM_INTERVAL_MS);
522519

523-
// for (TaskInfo *taskDesc : load.mainTaskDescriptions) {
524-
// if (taskDesc == nullptr) {
525-
// LOGE_LOCKED(TAG, "Caught null task description
526-
// pointer!"); continue;
527-
// }
528-
529-
// if (taskDesc->pxHandle == nullptr) {
530-
// LOGE_LOCKED(TAG, "Caught null task handle!");
531-
// continue;
532-
// }
533-
534-
// taskDesc->minFreeStack_Bytes =
535-
// uxTaskGetStackHighWaterMark(taskDesc->pxHandle);
536-
// LOGI_LOCKED(TAG, "T: %s, U: %u, F: %u", taskDesc->name,
537-
// taskDesc->stackSize_bytes -
538-
// taskDesc->minFreeStack_Bytes,
539-
// taskDesc->minFreeStack_Bytes);
540-
// // Serial.flush();
541-
// delay(LOG_ITEM_INTERVAL_MS);
542-
// }
543-
// Serial.flush();
544-
delay(LOG_ITEM_INTERVAL_MS);
545-
} else {
546-
// Print buffer
547-
char *saveptr = nullptr;
548-
char *line = strtok_r(statsBuffer, "\n", &saveptr);
549-
delay(LOG_ITEM_INTERVAL_MS);
550-
LOGI_LOCKED(TAG, "Task Info: %s:", line);
551-
while (line != nullptr) {
552-
line = strtok_r(nullptr, "\n", &saveptr);
553-
LOGI_LOCKED(TAG, "Task Info: %s:", line);
554-
}
555-
delay(LOG_ITEM_INTERVAL_MS);
556-
557-
statsBuffer[0] = '\0';
558-
559520
for (TaskInfo *taskDesc : load.mainTaskDescriptions) {
560521
if (taskDesc == nullptr) {
561-
LOGE_LOCKED(TAG, "Caught null task description pointer!");
522+
ESP_LOGE(TAG, "Caught null task description pointer!");
562523
continue;
563524
}
564525

565526
if (taskDesc->pxHandle == nullptr) {
566-
LOGE_LOCKED(TAG, "Caught null task handle!");
527+
ESP_LOGE(TAG, "Caught null task handle!");
567528
continue;
568529
}
569530

570531
taskDesc->minFreeStack_Bytes =
571532
uxTaskGetStackHighWaterMark(taskDesc->pxHandle);
572-
LOGI_LOCKED(TAG, "T: %s, U: %u, F: %u", taskDesc->name,
573-
taskDesc->stackSize_bytes -
574-
taskDesc->minFreeStack_Bytes,
575-
taskDesc->minFreeStack_Bytes);
576-
// Serial.flush();
577-
delay(LOG_ITEM_INTERVAL_MS);
533+
ESP_LOGI(TAG, "T: %s, U: %u, F: %u", taskDesc->name,
534+
taskDesc->stackSize_bytes -
535+
taskDesc->minFreeStack_Bytes,
536+
taskDesc->minFreeStack_Bytes);
578537
}
538+
// Serial.flush();
579539
delay(LOG_ITEM_INTERVAL_MS);
580540
}
541+
// else {
542+
// // Print buffer
543+
// char *saveptr = nullptr;
544+
// char *line = strtok_r(statsBuffer, "\n", &saveptr);
545+
// delay(LOG_ITEM_INTERVAL_MS);
546+
// ESP_LOGI(TAG, "Task Info: %s:", line);
547+
// while (line != nullptr) {
548+
// line = strtok_r(nullptr, "\n", &saveptr);
549+
// ESP_LOGI(TAG, "Task Info: %s:", line);
550+
// }
551+
// delay(LOG_ITEM_INTERVAL_MS);
552+
553+
// for (TaskInfo *taskDesc : load.mainTaskDescriptions) {
554+
// taskDesc->minFreeStack_Bytes =
555+
// uxTaskGetStackHighWaterMark(taskDesc->pxHandle);
556+
// ESP_LOGI(TAG, "T: %s, U: %u, F: %u", taskDesc->name,
557+
// taskDesc->stackSize_bytes -
558+
// taskDesc->minFreeStack_Bytes,
559+
// taskDesc->minFreeStack_Bytes);
560+
// }
561+
// delay(LOG_ITEM_INTERVAL_MS);
562+
// }
581563

582-
LOGI_LOCKED(TAG, "Min, free heap: %u b",
583-
esp_get_minimum_free_heap_size());
584-
// Serial.flush();
564+
ESP_LOGI(TAG, "Min, free heap: %u b", esp_get_minimum_free_heap_size());
585565
delay(LOG_ITEM_INTERVAL_MS);
586566

587567
// Enable temperature sensor
@@ -594,13 +574,12 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS =
594574
constexpr int32_t MAX_EXT_TEMP = 105;
595575
constexpr int32_t MIN_EXT_TEMP = -40;
596576
if (tempTrunc_C > MAX_EXT_TEMP || tempTrunc_C < MIN_EXT_TEMP) {
597-
LOGE_LOCKED(TAG, "Temp. out of bounds: %d dC", tempTrunc_C);
577+
ESP_LOGE(TAG, "Temp. out of bounds: %d dC", tempTrunc_C);
598578
} else {
599-
LOGI_LOCKED(TAG, "Temp.: %d dC", tempTrunc_C);
579+
ESP_LOGI(TAG, "Temp.: %d dC", tempTrunc_C);
600580
}
601581
// Disable the temperature sensor if it is not needed and save the power
602582
ESP_ERROR_CHECK(temperature_sensor_disable(tempSensHandle));
603-
// Serial.flush();
604583
delay(LOG_ITEM_INTERVAL_MS);
605584

606585
// esp_wifi_get_bandwidth
@@ -613,6 +592,6 @@ constexpr uint32_t LOG_ITEM_INTERVAL_MS =
613592
* Arduino: put your main code here, to run repeatedly:
614593
*/
615594
void loop() {
616-
// LOGI_LOCKED(TAG, "Time: %llu", SyncedClock::getSystemTimer());
595+
// ESP_LOGI(TAG, "Time: %llu", SyncedClock::getSystemTimer());
617596
delay(1000);
618597
}

0 commit comments

Comments
 (0)