some tweaks regarding washMode and Debugger

This commit is contained in:
2025-06-15 21:17:32 +02:00
parent 68d571a747
commit b6f9de2894
5 changed files with 193 additions and 89 deletions

View File

@@ -11,12 +11,11 @@
* @date 09.04.2024
*/
#include "debugger.h"
#include <map>
#include <functional>
#include <vector>
DebugStatus_t DebuggerStatus[dbg_cntElements];
#include "debugger.h"
#include <map>
#include <functional>
#include <vector>
#include <type_traits>
void processCmdDebug(String command);
void Debug_formatCFG();
@@ -32,6 +31,9 @@ void Debug_printHelp();
void Debug_Purge();
void Debug_refillTank();
const char *uint32_to_binary_string(uint32_t num);
template<typename T>
void RegisterDebugPrintAuto(const T* ptr, const String& name, uint32_t interval_ms, uint32_t duration_ms);
void Debug_UpdateWatches();
/**
* @brief Initializes the debugger by setting the initial status for different debug ports.
@@ -98,11 +100,12 @@ void Debug_Process()
}
// Check for input buffer overflow
if (inputCnt >= sizeof(inputBuffer) - 1) {
if (inputCnt >= sizeof(inputBuffer) - 1)
{
inputBuffer[sizeof(inputBuffer) - 1] = '\0';
inputCnt = 0;
InputProcessed = CMD_OVERFLOW;
}
}
}
// Process the command based on the detected state of input processing
@@ -128,7 +131,11 @@ void Debug_Process()
Serial.print(">");
InputProcessed = IDLE;
Debug_UpdateWatches();
}
/**
* @brief Sets the status of a specific debug port (Serial or WebUI).
* Updates the status in the DebuggerStatus array and provides debug messages.
@@ -150,8 +157,6 @@ void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status)
Debug_pushMessage("Enabled DebugPort %s\n", sDebugPorts[port]);
}
void Debug_log(LogLevel level, const char *format, ...)
{
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
@@ -248,17 +253,22 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
std::vector<String> splitArgs(const String &input)
{
std::vector<String> tokens;
int start = 0, end = 0;
while ((end = input.indexOf(' ', start)) != -1)
size_t start = 0;
while (true)
{
int end = input.indexOf(' ', start);
if (end == -1) break;
tokens.push_back(input.substring(start, end));
start = end + 1;
start = static_cast<size_t>(end) + 1;
}
if (start < input.length())
tokens.push_back(input.substring(start));
return tokens;
}
// === getArg helper ===
String getArg(const std::vector<String> &args, size_t index, const String &defaultVal = "")
{
@@ -273,19 +283,28 @@ typedef std::function<void(const String &args)> DebugCmdHandler;
static const std::map<String, DebugCmdHandler> &getCmdMap()
{
static const std::map<String, DebugCmdHandler> cmdMap = {
{"help", [](const String &) {
{"help", [](const String &)
{
Debug_log(LOG_INFO, "Available commands:\n");
for (const auto &entry : getCmdMap())
Debug_log(LOG_INFO, " - %s\n", entry.first.c_str());
}},
{"sysinfo", [](const String &) { Debug_printSystemInfo(); }},
{"netinfo", [](const String &) { Debug_printWifiInfo(); }},
{"formatCFG", [](const String &) { Debug_formatCFG(); }},
{"formatPDS", [](const String &) { Debug_formatPersistence(); }},
{"checkEE", [](const String &) { Debug_CheckEEPOM(false); }},
{"checkEEfix", [](const String &) { Debug_CheckEEPOM(true); }},
{"dumpEE1k", [](const String &) { dumpEEPROM(0, 1024); }},
{"dumpEE", [](const String &args) {
{"sysinfo", [](const String &)
{ Debug_printSystemInfo(); }},
{"netinfo", [](const String &)
{ Debug_printWifiInfo(); }},
{"formatCFG", [](const String &)
{ Debug_formatCFG(); }},
{"formatPDS", [](const String &)
{ Debug_formatPersistence(); }},
{"checkEE", [](const String &)
{ Debug_CheckEEPOM(false); }},
{"checkEEfix", [](const String &)
{ Debug_CheckEEPOM(true); }},
{"dumpEE1k", [](const String &)
{ dumpEEPROM(0, 1024); }},
{"dumpEE", [](const String &args)
{
int start = 0, len = EEPROM_SIZE_BYTES;
auto tokens = splitArgs(args);
if (tokens.size() >= 2)
@@ -295,24 +314,42 @@ static const std::map<String, DebugCmdHandler> &getCmdMap()
}
dumpEEPROM(start, len);
}},
{"resetPageEE", [](const String &) { MovePersistencePage_EEPROM(true); }},
{"dumpCFG", [](const String &) { Debug_dumpConfig(); }},
{"dumpPDS", [](const String &) { Debug_dumpPersistance(); }},
{"saveEE", [](const String &) { globals.requestEEAction = EE_ALL_SAVE; }},
{"dumpGlobals", [](const String &) { Debug_dumpGlobals(); }},
{"sdbg", [](const String &) { SetDebugportStatus(dbg_Serial, enabled); }},
{"dtc_show", [](const String &) { Debug_ShowDTCs(); }},
{"dtc_clear", [](const String &) { ClearAllDTC(); }},
{"dtc_crit", [](const String &) { MaintainDTC(DTC_FAKE_DTC_CRIT, true, millis()); }},
{"dtc_warn", [](const String &) { MaintainDTC(DTC_FAKE_DTC_WARN, true, millis()); }},
{"dtc_info", [](const String &) { MaintainDTC(DTC_FAKE_DTC_INFO, true, millis()); }},
{"notify_error", [](const String &) { Websocket_PushNotification("Debug Error Notification", error); }},
{"notify_warning", [](const String &) { Websocket_PushNotification("Debug Warning Notification", warning); }},
{"notify_success", [](const String &) { Websocket_PushNotification("Debug Success Notification", success); }},
{"notify_info", [](const String &) { Websocket_PushNotification("Debug Info Notification", info); }},
{"purge", [](const String &) { Debug_Purge(); }},
{"toggle_wifi", [](const String &) { globals.toggle_wifi = true; }},
{"dtc_add", [](const String &args) {
{"resetPageEE", [](const String &)
{ MovePersistencePage_EEPROM(true); }},
{"dumpCFG", [](const String &)
{ Debug_dumpConfig(); }},
{"dumpPDS", [](const String &)
{ Debug_dumpPersistance(); }},
{"saveEE", [](const String &)
{ globals.requestEEAction = EE_ALL_SAVE; }},
{"dumpGlobals", [](const String &)
{ Debug_dumpGlobals(); }},
{"sdbg", [](const String &)
{ SetDebugportStatus(dbg_Serial, enabled); }},
{"dtc_show", [](const String &)
{ Debug_ShowDTCs(); }},
{"dtc_clear", [](const String &)
{ ClearAllDTC(); }},
{"dtc_crit", [](const String &)
{ MaintainDTC(DTC_FAKE_DTC_CRIT, true, millis()); }},
{"dtc_warn", [](const String &)
{ MaintainDTC(DTC_FAKE_DTC_WARN, true, millis()); }},
{"dtc_info", [](const String &)
{ MaintainDTC(DTC_FAKE_DTC_INFO, true, millis()); }},
{"notify_error", [](const String &)
{ Websocket_PushNotification("Debug Error Notification", error); }},
{"notify_warning", [](const String &)
{ Websocket_PushNotification("Debug Warning Notification", warning); }},
{"notify_success", [](const String &)
{ Websocket_PushNotification("Debug Success Notification", success); }},
{"notify_info", [](const String &)
{ Websocket_PushNotification("Debug Info Notification", info); }},
{"purge", [](const String &)
{ Debug_Purge(); }},
{"toggle_wifi", [](const String &)
{ globals.toggle_wifi = true; }},
{"dtc_add", [](const String &args)
{
auto tokens = splitArgs(args);
if (!tokens.empty())
{
@@ -320,7 +357,12 @@ static const std::map<String, DebugCmdHandler> &getCmdMap()
MaintainDTC((DTCNum_t)code, true, millis());
}
}},
{"tank_refill", [](const String &) { Debug_refillTank(); }},
{"tank_refill", [](const String &)
{ Debug_refillTank(); }},
{"isr_debug", [](const String &)
{
RegisterDebugPrintAuto(&globals.isr_debug, "isr_debug", 100, 20000);
}},
};
return cmdMap;
}
@@ -531,7 +573,6 @@ void Debug_ShowDTCs()
}
}
/**
* @brief Start purging for 10 pulses.
*/
@@ -578,4 +619,77 @@ const char *uint32_to_binary_string(uint32_t num)
}
binary_str[j] = '\0'; // Null terminator
return binary_str;
}
}
DebugStatus_t DebuggerStatus[dbg_cntElements];
struct DebugWatchEntry
{
const void *ptr;
String name;
uint32_t interval_ms;
uint32_t duration_ms;
uint32_t lastPrint_ms;
uint32_t start_ms;
std::function<void(const void*, const String&)> printer;
};
#define MAX_DEBUG_WATCHES 8
DebugWatchEntry debugWatches[MAX_DEBUG_WATCHES];
// === Typabhängige Druckfunktion ===
template<typename T>
void debugPrinterImpl(const void* ptr, const String& name) {
const T* typed = static_cast<const T*>(ptr);
if constexpr (std::is_same<T, bool>::value) {
Debug_pushMessage("%s = %s\n", name.c_str(), *typed ? "true" : "false");
} else if constexpr (std::is_floating_point<T>::value) {
Debug_pushMessage("%s = %.3f\n", name.c_str(), *typed);
} else if constexpr (std::is_signed<T>::value) {
Debug_pushMessage("%s = %ld\n", name.c_str(), static_cast<long>(*typed));
} else if constexpr (std::is_unsigned<T>::value) {
Debug_pushMessage("%s = %lu\n", name.c_str(), static_cast<unsigned long>(*typed));
}
}
// === Automatisches DebugPrint-Register ===
template<typename T>
void RegisterDebugPrintAuto(const T* ptr, const String& name, uint32_t interval_ms, uint32_t duration_ms)
{
for (int i = 0; i < MAX_DEBUG_WATCHES; ++i) {
if (debugWatches[i].ptr == nullptr) {
debugWatches[i] = {
ptr,
name,
interval_ms,
duration_ms,
0,
millis(),
debugPrinterImpl<T>
};
Debug_pushMessage("Registered Watch: %s\n", name.c_str());
return;
}
}
Debug_pushMessage("Debug Watch list full!\n");
}
// Debug-Ausgabe in Debug_Process():
void Debug_UpdateWatches() {
uint32_t now = millis();
for (int i = 0; i < MAX_DEBUG_WATCHES; ++i) {
auto& w = debugWatches[i];
if (!w.ptr) continue;
if (now - w.start_ms >= w.duration_ms) {
Debug_pushMessage("Watch expired: %s\n", w.name.c_str());
w.ptr = nullptr;
continue;
}
if (now - w.lastPrint_ms >= w.interval_ms) {
w.lastPrint_ms = now;
if (w.printer) w.printer(w.ptr, w.name);
}
}
}