2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @file debugger.cpp
|
|
|
|
* @brief Implementation of debugging functions for monitoring and diagnostics.
|
|
|
|
*
|
|
|
|
* This file contains the implementation of various debugging functions to monitor
|
|
|
|
* and diagnose the system. It includes functions to print system information, WiFi
|
|
|
|
* details, EEPROM status, dump configuration settings, dump persistence data, show
|
|
|
|
* Diagnostic Trouble Codes (DTCs), and more.
|
|
|
|
*
|
|
|
|
* @author Marcel Peterkau
|
|
|
|
* @date 09.04.2024
|
|
|
|
*/
|
|
|
|
|
2023-02-23 23:14:58 +01:00
|
|
|
#include "debugger.h"
|
|
|
|
|
2023-02-24 00:05:51 +01:00
|
|
|
DebugStatus_t DebuggerStatus[dbg_cntElements];
|
2023-02-23 23:14:58 +01:00
|
|
|
|
|
|
|
String IpAddress2String(const IPAddress &ipAddress);
|
2023-03-14 23:30:26 +01:00
|
|
|
void processCmdDebug(String command);
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_formatCFG();
|
|
|
|
void Debug_formatPersistence();
|
|
|
|
void Debug_printSystemInfo();
|
|
|
|
void Debug_printWifiInfo();
|
|
|
|
void Debug_CheckEEPOM();
|
|
|
|
void Debug_dumpConfig();
|
|
|
|
void Debug_dumpPersistance();
|
|
|
|
void Debug_ShowDTCs();
|
|
|
|
void Debug_dumpGlobals();
|
2023-03-14 23:30:26 +01:00
|
|
|
void Debug_printHelp();
|
2023-02-23 23:14:58 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Initializes the debugger by setting the initial status for different debug ports.
|
|
|
|
* Serial debug output is turned off.
|
|
|
|
*/
|
2023-02-23 23:14:58 +01:00
|
|
|
void initDebugger()
|
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Set the initial status of debug ports
|
2023-02-24 00:05:51 +01:00
|
|
|
DebuggerStatus[dbg_Serial] = disabled;
|
|
|
|
DebuggerStatus[dbg_Webui] = disabled;
|
2023-02-23 23:14:58 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Disable serial debug output
|
2023-02-23 23:14:58 +01:00
|
|
|
Serial.setDebugOutput(false);
|
|
|
|
}
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Processes incoming debug commands from the Serial interface.
|
|
|
|
* It reads characters from Serial and interprets them as commands.
|
|
|
|
* The recognized commands are processed accordingly.
|
|
|
|
*/
|
2023-03-14 23:30:26 +01:00
|
|
|
void Debug_Process()
|
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Enumeration for tracking the state of input processing
|
2023-03-14 23:30:26 +01:00
|
|
|
typedef enum InputProcessed_e
|
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
IDLE, ///< No command processing is in progress
|
|
|
|
CMD_COMPLETE, ///< Received a complete command
|
|
|
|
CMD_ABORT, ///< Received an abort command (Esc)
|
|
|
|
CMD_OVERFLOW ///< Input buffer overflow occurred
|
2023-03-14 23:30:26 +01:00
|
|
|
} InputProcessed_t;
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
static unsigned int inputCnt = 0; ///< Counter for characters in the input buffer
|
|
|
|
static char inputBuffer[32]; ///< Buffer to store the received characters
|
|
|
|
InputProcessed_t InputProcessed = IDLE; ///< State variable for input processing
|
2023-03-14 23:30:26 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check if there are characters available in the Serial input buffer
|
2023-03-14 23:30:26 +01:00
|
|
|
if (Serial.available())
|
|
|
|
{
|
|
|
|
char inputChar = Serial.read();
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Process the received character based on its value
|
2023-03-14 23:30:26 +01:00
|
|
|
switch (inputChar)
|
|
|
|
{
|
|
|
|
case '\n':
|
|
|
|
inputBuffer[inputCnt] = 0; // terminate the String
|
|
|
|
inputCnt = 0;
|
|
|
|
InputProcessed = CMD_COMPLETE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1B: // Esc
|
|
|
|
inputBuffer[0] = 0;
|
|
|
|
inputCnt = 0;
|
|
|
|
InputProcessed = CMD_ABORT;
|
|
|
|
break;
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
case 0x21 ... 0x7E: // it's a real letter or sign and not some control-chars
|
2023-03-14 23:30:26 +01:00
|
|
|
inputBuffer[inputCnt] = inputChar;
|
|
|
|
inputCnt++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check for input buffer overflow
|
2023-03-14 23:30:26 +01:00
|
|
|
if (inputCnt > sizeof(inputBuffer))
|
|
|
|
{
|
|
|
|
inputCnt = 0;
|
|
|
|
inputBuffer[sizeof(inputBuffer) - 1] = 0; // terminate the String
|
|
|
|
InputProcessed = CMD_OVERFLOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Process the command based on the detected state of input processing
|
2023-03-14 23:30:26 +01:00
|
|
|
switch (InputProcessed)
|
|
|
|
{
|
|
|
|
case CMD_ABORT:
|
|
|
|
Debug_pushMessage("Abort\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_COMPLETE:
|
|
|
|
processCmdDebug(String(inputBuffer));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_OVERFLOW:
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Input buffer overflow\n");
|
2023-03-14 23:30:26 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
InputProcessed = IDLE;
|
|
|
|
}
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Sets the status of a specific debug port (Serial or WebUI).
|
|
|
|
* Updates the status in the DebuggerStatus array and provides debug messages.
|
|
|
|
*
|
|
|
|
* @param port The debug port to set the status for (dbg_Serial or dbg_Webui).
|
|
|
|
* @param status The status to set (enabled or disabled).
|
|
|
|
*/
|
2023-02-24 00:05:51 +01:00
|
|
|
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status)
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Display a debug message based on the provided status
|
2023-02-24 00:05:51 +01:00
|
|
|
if (status == disabled)
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Disable DebugPort %s\n", sDebugPorts[port]);
|
2023-02-24 00:52:51 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Update the status in the DebuggerStatus array
|
2023-02-24 00:05:51 +01:00
|
|
|
DebuggerStatus[port] = status;
|
2023-02-23 23:14:58 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Display a debug message based on the updated status
|
2023-02-24 00:05:51 +01:00
|
|
|
if (status == enabled)
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Enabled DebugPort %s\n", sDebugPorts[port]);
|
2023-02-24 00:05:51 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Pushes a formatted debug message to the enabled debug ports (Serial or WebUI).
|
|
|
|
*
|
|
|
|
* @param format The format string for the debug message.
|
|
|
|
* @param ... Additional arguments for formatting the message.
|
|
|
|
*/
|
2023-02-24 00:05:51 +01:00
|
|
|
void Debug_pushMessage(const char *format, ...)
|
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check if either the Serial or WebUI debug port is enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
char buff[64]; // Buffer to hold the formatted message
|
|
|
|
va_list arg; // Variable argument list for vsnprintf
|
2023-02-24 00:05:51 +01:00
|
|
|
va_start(arg, format);
|
2024-01-09 12:54:05 +01:00
|
|
|
|
|
|
|
// Format the message and store it in the buffer
|
2023-02-24 00:05:51 +01:00
|
|
|
vsnprintf(buff, sizeof(buff), format, arg);
|
|
|
|
va_end(arg);
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Send the message to the Serial debug port if enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if (DebuggerStatus[dbg_Serial] == enabled)
|
|
|
|
{
|
|
|
|
Serial.print(buff);
|
|
|
|
}
|
2024-01-09 12:54:05 +01:00
|
|
|
|
|
|
|
// Push the message to the WebUI debug port if enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if (DebuggerStatus[dbg_Webui] == enabled)
|
|
|
|
{
|
|
|
|
Websocket_PushLiveDebug(String(buff));
|
|
|
|
}
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Pushes a formatted CAN debug message to the enabled debug ports (Serial or WebUI).
|
|
|
|
*
|
|
|
|
* @param id CAN message ID.
|
|
|
|
* @param dlc Data Length Code of the CAN message.
|
|
|
|
* @param data Pointer to the data array of the CAN message.
|
|
|
|
*/
|
2023-02-24 00:05:51 +01:00
|
|
|
void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check if either the Serial or WebUI debug port is enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
char buff[100]; // Buffer to hold the formatted message
|
|
|
|
char *p = buff; // Pointer to navigate the buffer
|
|
|
|
|
|
|
|
// Format the CAN message information into the buffer
|
2023-02-23 23:14:58 +01:00
|
|
|
p += snprintf(p, sizeof(buff), "CAN: 0x%08X | %d | ", id, dlc);
|
|
|
|
for (int i = 0; i < dlc; i++)
|
|
|
|
{
|
|
|
|
p += snprintf(p, sizeof(buff) - (p - buff), "%02X ", data[i]);
|
|
|
|
}
|
|
|
|
*(p++) = '\n';
|
|
|
|
*p = '\0';
|
2023-02-24 00:05:51 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Send the formatted CAN message to the Serial debug port if enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if (DebuggerStatus[dbg_Serial] == enabled)
|
|
|
|
{
|
|
|
|
Serial.print(buff);
|
|
|
|
}
|
2024-01-09 12:54:05 +01:00
|
|
|
|
|
|
|
// Push the formatted CAN message to the WebUI debug port if enabled
|
2023-02-24 00:05:51 +01:00
|
|
|
if (DebuggerStatus[dbg_Webui] == enabled)
|
|
|
|
{
|
|
|
|
Websocket_PushLiveDebug(String(buff));
|
|
|
|
}
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Processes a debug command and performs corresponding actions.
|
|
|
|
*
|
|
|
|
* @param command The debug command to be processed.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void processCmdDebug(String command)
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check the received command and execute corresponding actions
|
2023-03-14 23:30:26 +01:00
|
|
|
if (command == "help")
|
|
|
|
Debug_printHelp();
|
|
|
|
else if (command == "sysinfo")
|
2023-02-24 00:52:51 +01:00
|
|
|
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();
|
|
|
|
else if (command == "dumpEE1k")
|
2023-02-23 23:14:58 +01:00
|
|
|
dumpEEPROM(0, 1024);
|
2023-02-24 00:52:51 +01:00
|
|
|
else if (command == "dumpEE")
|
2023-02-23 23:14:58 +01:00
|
|
|
dumpEEPROM(0, EEPROM_SIZE_BYTES);
|
2023-02-24 00:52:51 +01:00
|
|
|
else if (command == "resetPageEE")
|
2023-02-23 23:14:58 +01:00
|
|
|
MovePersistencePage_EEPROM(true);
|
2023-02-24 00:52:51 +01:00
|
|
|
else if (command == "dumpCFG")
|
|
|
|
Debug_dumpConfig();
|
|
|
|
else if (command == "dumpPDS")
|
|
|
|
Debug_dumpPersistance();
|
|
|
|
else if (command == "saveEE")
|
2023-02-23 23:14:58 +01:00
|
|
|
globals.requestEEAction = EE_ALL_SAVE;
|
2023-02-24 00:52:51 +01:00
|
|
|
else if (command == "dumpGlobals")
|
|
|
|
Debug_dumpGlobals();
|
2023-03-14 23:30:26 +01:00
|
|
|
else if (command == "sdbg")
|
|
|
|
SetDebugportStatus(dbg_Serial, enabled);
|
2023-12-04 02:18:16 +01:00
|
|
|
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());
|
2023-03-14 23:30:26 +01:00
|
|
|
else
|
|
|
|
Debug_pushMessage("unknown Command\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Formats the Config-EEPROM and resets it to default values.
|
|
|
|
* Prints a debug message after formatting.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_formatCFG()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Formatting Config-EEPROM and resetting to default\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
FormatConfig_EEPROM();
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Formats the Persistence-EEPROM and resets it to default values.
|
|
|
|
* Prints a debug message after formatting.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_formatPersistence()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Formatting Persistence-EEPROM and resetting to default\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
FormatPersistence_EEPROM();
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Prints system information and status to the debug output.
|
|
|
|
*/
|
2023-03-14 23:30:26 +01:00
|
|
|
void Debug_printSystemInfo()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("Souko's ChainOiler Mk1\n");
|
|
|
|
Debug_pushMessage("Hostname: %s\n", globals.DeviceName);
|
2023-02-23 23:14:58 +01:00
|
|
|
|
|
|
|
FlashMode_t ideMode = ESP.getFlashChipMode();
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("Sdk version: %s\n", ESP.getSdkVersion());
|
|
|
|
Debug_pushMessage("Core Version: %s\n", ESP.getCoreVersion().c_str());
|
|
|
|
Debug_pushMessage("Boot Version: %u\n", ESP.getBootVersion());
|
|
|
|
Debug_pushMessage("Boot Mode: %u\n", ESP.getBootMode());
|
|
|
|
Debug_pushMessage("CPU Frequency: %u MHz\n", ESP.getCpuFreqMHz());
|
|
|
|
Debug_pushMessage("Reset reason: %s\n", ESP.getResetReason().c_str());
|
|
|
|
Debug_pushMessage("Flash Size: %d\n", ESP.getFlashChipRealSize());
|
|
|
|
Debug_pushMessage("Flash Size IDE: %d\n", ESP.getFlashChipSize());
|
|
|
|
Debug_pushMessage("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
|
2023-12-04 02:18:16 +01:00
|
|
|
: ideMode == FM_DIO ? "DIO"
|
|
|
|
: ideMode == FM_DOUT ? "DOUT"
|
|
|
|
: "UNKNOWN"));
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("OTA-Pass: %s\n", QUOTE(ADMIN_PASSWORD));
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("Git-Revision: %s\n", constants.GitHash);
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("Sw-Version: %d.%02d\n", constants.FW_Version_major, constants.FW_Version_minor);
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Dumps the current configuration parameters to the debug output.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_dumpConfig()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("DistancePerLube_Default: %d\n", LubeConfig.DistancePerLube_Default);
|
|
|
|
Debug_pushMessage("DistancePerLube_Rain: %d\n", LubeConfig.DistancePerLube_Rain);
|
|
|
|
Debug_pushMessage("tankCapacity_ml: %d\n", LubeConfig.tankCapacity_ml);
|
|
|
|
Debug_pushMessage("amountPerDose_microL: %d\n", LubeConfig.amountPerDose_microL);
|
|
|
|
Debug_pushMessage("TankRemindAtPercentage: %d\n", LubeConfig.TankRemindAtPercentage);
|
|
|
|
Debug_pushMessage("PulsePerRevolution: %d\n", LubeConfig.PulsePerRevolution);
|
|
|
|
Debug_pushMessage("TireWidth_mm: %d\n", LubeConfig.TireWidth_mm);
|
2024-01-09 12:54:05 +01:00
|
|
|
Debug_pushMessage("TireWidthHeight_Ratio: %d\n", LubeConfig.TireWidthHeight_Ratio);
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("RimDiameter_Inch: %d\n", LubeConfig.RimDiameter_Inch);
|
|
|
|
Debug_pushMessage("DistancePerRevolution_mm: %d\n", LubeConfig.DistancePerRevolution_mm);
|
|
|
|
Debug_pushMessage("BleedingPulses: %d\n", LubeConfig.BleedingPulses);
|
|
|
|
Debug_pushMessage("SpeedSource: %d\n", LubeConfig.SpeedSource);
|
|
|
|
Debug_pushMessage("GPSBaudRate: %d\n", LubeConfig.GPSBaudRate);
|
|
|
|
Debug_pushMessage("CANSource: %d\n", LubeConfig.CANSource);
|
|
|
|
Debug_pushMessage("checksum: 0x%08X\n", LubeConfig.checksum);
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Dumps the global variables and their values to the debug output.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_dumpGlobals()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("systemStatus: %d\n", globals.systemStatus);
|
|
|
|
Debug_pushMessage("resumeStatus: %d\n", globals.resumeStatus);
|
|
|
|
Debug_pushMessage("systemStatustxt: %s\n", globals.systemStatustxt);
|
|
|
|
Debug_pushMessage("purgePulses: %d\n", globals.purgePulses);
|
|
|
|
Debug_pushMessage("requestEEAction: %d\n", globals.requestEEAction);
|
|
|
|
Debug_pushMessage("DeviceName: %s\n", globals.DeviceName);
|
|
|
|
Debug_pushMessage("FlashVersion: %s\n", globals.FlashVersion);
|
|
|
|
Debug_pushMessage("eePersistanceAdress: %d\n", globals.eePersistanceAdress);
|
|
|
|
Debug_pushMessage("TankPercentage: %d\n", globals.TankPercentage);
|
|
|
|
Debug_pushMessage("hasDTC: %d\n", globals.hasDTC);
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Dumps the persistence data variables and their values to the debug output.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_dumpPersistance()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage("writeCycleCounter: %d\n", PersistenceData.writeCycleCounter);
|
|
|
|
Debug_pushMessage("tankRemain_microL: %d\n", PersistenceData.tankRemain_microL);
|
|
|
|
Debug_pushMessage("TravelDistance_highRes_mm: %d\n", PersistenceData.TravelDistance_highRes_mm);
|
|
|
|
Debug_pushMessage("checksum: %d\n", PersistenceData.checksum);
|
|
|
|
Debug_pushMessage("PSD Adress: 0x%04X\n", globals.eePersistanceAdress);
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Prints information related to WiFi to the debug output.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_printWifiInfo()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Add relevant code here if needed
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Checks the EEPROM data integrity by calculating and comparing checksums.
|
|
|
|
* Prints the result to the debug output.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_CheckEEPOM()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check PersistenceData EEPROM checksum
|
2023-02-23 23:14:58 +01:00
|
|
|
uint32_t checksum = PersistenceData.checksum;
|
|
|
|
PersistenceData.checksum = 0;
|
|
|
|
|
|
|
|
if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) == checksum)
|
|
|
|
{
|
2023-02-24 00:52:51 +01:00
|
|
|
Debug_pushMessage("PersistenceData EEPROM Checksum OK\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-24 00:52:51 +01:00
|
|
|
Debug_pushMessage("PersistenceData EEPROM Checksum BAD\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PersistenceData.checksum = checksum;
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Check LubeConfig EEPROM checksum
|
2023-02-23 23:14:58 +01:00
|
|
|
checksum = LubeConfig.checksum;
|
|
|
|
LubeConfig.checksum = 0;
|
|
|
|
|
|
|
|
if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) == checksum)
|
|
|
|
{
|
2023-02-24 00:52:51 +01:00
|
|
|
Debug_pushMessage("LubeConfig EEPROM Checksum OK\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-24 00:52:51 +01:00
|
|
|
Debug_pushMessage("LubeConfig EEPROM Checksum BAD\n");
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
LubeConfig.checksum = checksum;
|
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Displays Diagnostic Trouble Codes (DTCs) along with their timestamps,
|
|
|
|
* status, and severity in a formatted manner.
|
|
|
|
*/
|
2023-02-24 00:52:51 +01:00
|
|
|
void Debug_ShowDTCs()
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
|
|
|
char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
|
|
|
|
char buff_active[9];
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Header for the DTC display
|
2023-03-18 15:20:16 +01:00
|
|
|
Debug_pushMessage("\n timestamp | DTC-Nr. | status | severity\n");
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Iterate through DTCStorage and display each entry
|
2023-02-23 23:14:58 +01:00
|
|
|
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
|
|
|
|
{
|
|
|
|
if (DTCStorage[i].Number < DTC_LAST_DTC)
|
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Format timestamp
|
2023-02-23 23:14:58 +01:00
|
|
|
sprintf(buff_timestamp, "%02d-%02d:%02d:%02d:%03d",
|
|
|
|
DTCStorage[i].timestamp / 86400000, // Days
|
|
|
|
DTCStorage[i].timestamp / 360000 % 24, // Hours
|
|
|
|
DTCStorage[i].timestamp / 60000 % 60, // Minutes
|
|
|
|
DTCStorage[i].timestamp / 1000 % 60, // Seconds
|
2024-01-09 12:54:05 +01:00
|
|
|
DTCStorage[i].timestamp % 1000); // Milliseconds
|
2023-02-23 23:14:58 +01:00
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Determine DTC status
|
2023-02-23 23:14:58 +01:00
|
|
|
if (DTCStorage[i].active == DTC_ACTIVE)
|
|
|
|
strcpy(buff_active, "active");
|
|
|
|
else if (DTCStorage[i].active == DTC_PREVIOUS)
|
|
|
|
strcpy(buff_active, "previous");
|
|
|
|
else
|
|
|
|
strcpy(buff_active, "none");
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Display DTC information
|
2023-09-27 19:13:54 +02:00
|
|
|
Debug_pushMessage("%s %7d %8s %8d\n", buff_timestamp, DTCStorage[i].Number, buff_active);
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-14 23:30:26 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
/**
|
|
|
|
* @brief Displays the help commands for debugging through Serial or WebUI.
|
|
|
|
* Each command is printed individually in a formatted manner.
|
|
|
|
*/
|
2023-03-14 23:30:26 +01:00
|
|
|
void Debug_printHelp()
|
|
|
|
{
|
|
|
|
char buff[64];
|
|
|
|
|
2024-01-09 12:54:05 +01:00
|
|
|
// Iterate through helpCmd and display each command
|
|
|
|
for (unsigned int i = 0; i < sizeof(helpCmd) / 63; i++)
|
2023-03-14 23:30:26 +01:00
|
|
|
{
|
2024-01-09 12:54:05 +01:00
|
|
|
// Copy a portion of helpCmd to buff for display
|
2023-03-14 23:30:26 +01:00
|
|
|
memcpy_P(buff, (helpCmd + (i * 63)), 63);
|
|
|
|
buff[63] = 0;
|
2024-01-09 12:54:05 +01:00
|
|
|
|
|
|
|
// Display the help command
|
2023-03-14 23:30:26 +01:00
|
|
|
Debug_pushMessage(buff);
|
|
|
|
}
|
2024-01-09 12:54:05 +01:00
|
|
|
}
|