massive Update

This commit is contained in:
2025-06-02 09:02:19 +02:00
parent 125fc17c39
commit dd34bfe645
11 changed files with 491 additions and 419 deletions

View File

@@ -11,7 +11,10 @@
* @date 09.04.2024
*/
#include "debugger.h"
#include "debugger.h"
#include <map>
#include <functional>
#include <vector>
DebugStatus_t DebuggerStatus[dbg_cntElements];
@@ -94,12 +97,11 @@ void Debug_Process()
}
// Check for input buffer overflow
if (inputCnt > sizeof(inputBuffer))
{
if (inputCnt >= sizeof(inputBuffer) - 1) {
inputBuffer[sizeof(inputBuffer) - 1] = '\0';
inputCnt = 0;
inputBuffer[sizeof(inputBuffer) - 1] = 0; // terminate the String
InputProcessed = CMD_OVERFLOW;
}
}
}
// Process the command based on the detected state of input processing
@@ -147,6 +149,29 @@ 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))
{
char buff[128];
va_list arg;
va_start(arg, format);
vsnprintf(buff, sizeof(buff), format, arg);
va_end(arg);
if (DebuggerStatus[dbg_Serial] == enabled)
{
Serial.print(buff);
}
if (DebuggerStatus[dbg_Webui] == enabled)
{
Websocket_PushLiveDebug(String(buff));
}
}
}
/**
* @brief Pushes a formatted debug message to the enabled debug ports (Serial or WebUI).
*
@@ -218,68 +243,99 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
}
}
/**
* @brief Processes a debug command and performs corresponding actions.
*
* @param command The debug command to be processed.
*/
void processCmdDebug(String command)
// === splitArgs Helper ===
std::vector<String> splitArgs(const String &input)
{
// Check the received command and execute corresponding actions
if (command == "help")
Debug_printHelp();
else if (command == "sysinfo")
Debug_printSystemInfo();
else if (command == "netinfo")
Debug_printWifiInfo();
else if (command == "formatCFG")
Debug_formatCFG();
else if (command == "formatPDS")
Debug_formatPersistence();
else if (command == "checkEE")
Debug_CheckEEPOM(false);
else if (command == "checkEEfix")
Debug_CheckEEPOM(true);
else if (command == "dumpEE1k")
dumpEEPROM(0, 1024);
else if (command == "dumpEE")
dumpEEPROM(0, EEPROM_SIZE_BYTES);
else if (command == "resetPageEE")
MovePersistencePage_EEPROM(true);
else if (command == "dumpCFG")
Debug_dumpConfig();
else if (command == "dumpPDS")
Debug_dumpPersistance();
else if (command == "saveEE")
globals.requestEEAction = EE_ALL_SAVE;
else if (command == "dumpGlobals")
Debug_dumpGlobals();
else if (command == "sdbg")
SetDebugportStatus(dbg_Serial, enabled);
else if (command == "dtc_show")
Debug_ShowDTCs();
else if (command == "dtc_clear")
ClearAllDTC();
else if (command == "dtc_crit")
MaintainDTC(DTC_FAKE_DTC_CRIT, true, millis());
else if (command == "dtc_warn")
MaintainDTC(DTC_FAKE_DTC_WARN, true, millis());
else if (command == "dtc_info")
MaintainDTC(DTC_FAKE_DTC_INFO, true, millis());
else if (command == "notify_error")
Websocket_PushNotification("Debug Error Notification", error);
else if (command == "notify_warning")
Websocket_PushNotification("Debug Warning Notification", warning);
else if (command == "notify_success")
Websocket_PushNotification("Debug Success Notification", success);
else if (command == "notify_info")
Websocket_PushNotification("Debug Info Notification", info);
else if (command == "purge")
Debug_Purge();
else if (command == "toggle_wifi")
globals.toggle_wifi = true;
std::vector<String> tokens;
int start = 0, end = 0;
while ((end = input.indexOf(' ', start)) != -1)
{
tokens.push_back(input.substring(start, end));
start = 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 = "")
{
if (index < args.size())
return args[index];
return defaultVal;
}
// === Command Handler Map ===
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 &) {
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) {
int start = 0, len = EEPROM_SIZE_BYTES;
auto tokens = splitArgs(args);
if (tokens.size() >= 2)
{
start = tokens[0].toInt();
len = tokens[1].toInt();
}
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) {
auto tokens = splitArgs(args);
if (!tokens.empty())
{
int code = tokens[0].toInt();
MaintainDTC((DTCNum_t)code, true, millis());
}
}}
};
return cmdMap;
}
void processCmdDebug(String input)
{
input.trim();
int splitIndex = input.indexOf(' ');
String command = splitIndex == -1 ? input : input.substring(0, splitIndex);
String args = splitIndex == -1 ? "" : input.substring(splitIndex + 1);
auto &cmdMap = getCmdMap();
auto it = cmdMap.find(command);
if (it != cmdMap.end())
it->second(args);
else
Debug_pushMessage("unknown Command\n");
Debug_log(LOG_WARN, "Unknown command: '%s'\n", command.c_str());
}
/**
@@ -473,25 +529,6 @@ void Debug_ShowDTCs()
}
}
/**
* @brief Displays the help commands for debugging through Serial or WebUI.
* Each command is printed individually in a formatted manner.
*/
void Debug_printHelp()
{
char buff[64];
// Iterate through helpCmd and display each command
for (unsigned int i = 0; i < sizeof(helpCmd) / 63; i++)
{
// Copy a portion of helpCmd to buff for display
memcpy_P(buff, (helpCmd + (i * 63)), 63);
buff[63] = 0;
// Display the help command
Debug_pushMessage(buff);
}
}
/**
* @brief Start purging for 10 pulses.