used ChatGPT to add comments and proper Headers to all SourceFiles
This commit is contained in:
@@ -1,3 +1,16 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
#include "debugger.h"
|
||||
|
||||
DebugStatus_t DebuggerStatus[dbg_cntElements];
|
||||
@@ -15,32 +28,45 @@ void Debug_ShowDTCs();
|
||||
void Debug_dumpGlobals();
|
||||
void Debug_printHelp();
|
||||
|
||||
/**
|
||||
* @brief Initializes the debugger by setting the initial status for different debug ports.
|
||||
* Serial debug output is turned off.
|
||||
*/
|
||||
void initDebugger()
|
||||
{
|
||||
// Set the initial status of debug ports
|
||||
DebuggerStatus[dbg_Serial] = disabled;
|
||||
DebuggerStatus[dbg_Webui] = disabled;
|
||||
|
||||
// Disable serial debug output
|
||||
Serial.setDebugOutput(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
void Debug_Process()
|
||||
{
|
||||
// Enumeration for tracking the state of input processing
|
||||
typedef enum InputProcessed_e
|
||||
{
|
||||
IDLE,
|
||||
CMD_COMPLETE,
|
||||
CMD_ABORT,
|
||||
CMD_OVERFLOW
|
||||
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
|
||||
} InputProcessed_t;
|
||||
|
||||
static unsigned int inputCnt = 0;
|
||||
static char inputBuffer[32];
|
||||
InputProcessed_t InputProcessed = IDLE;
|
||||
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
|
||||
|
||||
// Check if there are characters available in the Serial input buffer
|
||||
if (Serial.available())
|
||||
{
|
||||
char inputChar = Serial.read();
|
||||
|
||||
// Process the received character based on its value
|
||||
switch (inputChar)
|
||||
{
|
||||
case '\n':
|
||||
@@ -55,7 +81,7 @@ void Debug_Process()
|
||||
InputProcessed = CMD_ABORT;
|
||||
break;
|
||||
|
||||
case 0x21 ... 0x7E: // its a real letter or sign and not some control-chars
|
||||
case 0x21 ... 0x7E: // it's a real letter or sign and not some control-chars
|
||||
inputBuffer[inputCnt] = inputChar;
|
||||
inputCnt++;
|
||||
break;
|
||||
@@ -64,6 +90,7 @@ void Debug_Process()
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for input buffer overflow
|
||||
if (inputCnt > sizeof(inputBuffer))
|
||||
{
|
||||
inputCnt = 0;
|
||||
@@ -72,6 +99,7 @@ void Debug_Process()
|
||||
}
|
||||
}
|
||||
|
||||
// Process the command based on the detected state of input processing
|
||||
switch (InputProcessed)
|
||||
{
|
||||
case CMD_ABORT:
|
||||
@@ -83,7 +111,7 @@ void Debug_Process()
|
||||
break;
|
||||
|
||||
case CMD_OVERFLOW:
|
||||
Debug_pushMessage("input Buffer overflow\n");
|
||||
Debug_pushMessage("Input buffer overflow\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -91,32 +119,53 @@ void Debug_Process()
|
||||
}
|
||||
InputProcessed = IDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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).
|
||||
*/
|
||||
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status)
|
||||
{
|
||||
// Display a debug message based on the provided status
|
||||
if (status == disabled)
|
||||
Debug_pushMessage("disable DebugPort %s\n", sDebugPorts[port]);
|
||||
Debug_pushMessage("Disable DebugPort %s\n", sDebugPorts[port]);
|
||||
|
||||
// Update the status in the DebuggerStatus array
|
||||
DebuggerStatus[port] = status;
|
||||
|
||||
// Display a debug message based on the updated status
|
||||
if (status == enabled)
|
||||
Debug_pushMessage("enabled DebugPort %s\n", sDebugPorts[port]);
|
||||
Debug_pushMessage("Enabled DebugPort %s\n", sDebugPorts[port]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
void Debug_pushMessage(const char *format, ...)
|
||||
{
|
||||
// Check if either the Serial or WebUI debug port is enabled
|
||||
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
|
||||
{
|
||||
char buff[64];
|
||||
va_list arg;
|
||||
char buff[64]; // Buffer to hold the formatted message
|
||||
va_list arg; // Variable argument list for vsnprintf
|
||||
va_start(arg, format);
|
||||
|
||||
// Format the message and store it in the buffer
|
||||
vsnprintf(buff, sizeof(buff), format, arg);
|
||||
va_end(arg);
|
||||
|
||||
// Send the message to the Serial debug port if enabled
|
||||
if (DebuggerStatus[dbg_Serial] == enabled)
|
||||
{
|
||||
Serial.print(buff);
|
||||
}
|
||||
|
||||
// Push the message to the WebUI debug port if enabled
|
||||
if (DebuggerStatus[dbg_Webui] == enabled)
|
||||
{
|
||||
Websocket_PushLiveDebug(String(buff));
|
||||
@@ -124,12 +173,22 @@ void Debug_pushMessage(const char *format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
|
||||
{
|
||||
// Check if either the Serial or WebUI debug port is enabled
|
||||
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
|
||||
{
|
||||
char buff[100];
|
||||
char *p = buff;
|
||||
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
|
||||
p += snprintf(p, sizeof(buff), "CAN: 0x%08X | %d | ", id, dlc);
|
||||
for (int i = 0; i < dlc; i++)
|
||||
{
|
||||
@@ -138,10 +197,13 @@ void pushCANDebug(uint32_t id, uint8_t dlc, uint8_t *data)
|
||||
*(p++) = '\n';
|
||||
*p = '\0';
|
||||
|
||||
// Send the formatted CAN message to the Serial debug port if enabled
|
||||
if (DebuggerStatus[dbg_Serial] == enabled)
|
||||
{
|
||||
Serial.print(buff);
|
||||
}
|
||||
|
||||
// Push the formatted CAN message to the WebUI debug port if enabled
|
||||
if (DebuggerStatus[dbg_Webui] == enabled)
|
||||
{
|
||||
Websocket_PushLiveDebug(String(buff));
|
||||
@@ -149,8 +211,14 @@ 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)
|
||||
{
|
||||
// Check the received command and execute corresponding actions
|
||||
if (command == "help")
|
||||
Debug_printHelp();
|
||||
else if (command == "sysinfo")
|
||||
@@ -193,18 +261,29 @@ void processCmdDebug(String command)
|
||||
Debug_pushMessage("unknown Command\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Formats the Config-EEPROM and resets it to default values.
|
||||
* Prints a debug message after formatting.
|
||||
*/
|
||||
void Debug_formatCFG()
|
||||
{
|
||||
Debug_pushMessage("Formatting Config-EEPROM and reseting to default\n");
|
||||
Debug_pushMessage("Formatting Config-EEPROM and resetting to default\n");
|
||||
FormatConfig_EEPROM();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Formats the Persistence-EEPROM and resets it to default values.
|
||||
* Prints a debug message after formatting.
|
||||
*/
|
||||
void Debug_formatPersistence()
|
||||
{
|
||||
Debug_pushMessage("Formatting Persistence-EEPROM and reseting to default\n");
|
||||
Debug_pushMessage("Formatting Persistence-EEPROM and resetting to default\n");
|
||||
FormatPersistence_EEPROM();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prints system information and status to the debug output.
|
||||
*/
|
||||
void Debug_printSystemInfo()
|
||||
{
|
||||
Debug_pushMessage("Souko's ChainOiler Mk1\n");
|
||||
@@ -224,10 +303,13 @@ void Debug_printSystemInfo()
|
||||
: ideMode == FM_DOUT ? "DOUT"
|
||||
: "UNKNOWN"));
|
||||
Debug_pushMessage("OTA-Pass: %s\n", QUOTE(ADMIN_PASSWORD));
|
||||
Debug_pushMessage("Git-Revison: %s\n", constants.GitHash);
|
||||
Debug_pushMessage("Git-Revision: %s\n", constants.GitHash);
|
||||
Debug_pushMessage("Sw-Version: %d.%02d\n", constants.FW_Version_major, constants.FW_Version_minor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dumps the current configuration parameters to the debug output.
|
||||
*/
|
||||
void Debug_dumpConfig()
|
||||
{
|
||||
Debug_pushMessage("DistancePerLube_Default: %d\n", LubeConfig.DistancePerLube_Default);
|
||||
@@ -237,7 +319,7 @@ void Debug_dumpConfig()
|
||||
Debug_pushMessage("TankRemindAtPercentage: %d\n", LubeConfig.TankRemindAtPercentage);
|
||||
Debug_pushMessage("PulsePerRevolution: %d\n", LubeConfig.PulsePerRevolution);
|
||||
Debug_pushMessage("TireWidth_mm: %d\n", LubeConfig.TireWidth_mm);
|
||||
Debug_pushMessage("TireWidthHeight_Ratio: %d\n", LubeConfig.TireWidth_mm);
|
||||
Debug_pushMessage("TireWidthHeight_Ratio: %d\n", LubeConfig.TireWidthHeight_Ratio);
|
||||
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);
|
||||
@@ -247,6 +329,9 @@ void Debug_dumpConfig()
|
||||
Debug_pushMessage("checksum: 0x%08X\n", LubeConfig.checksum);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dumps the global variables and their values to the debug output.
|
||||
*/
|
||||
void Debug_dumpGlobals()
|
||||
{
|
||||
Debug_pushMessage("systemStatus: %d\n", globals.systemStatus);
|
||||
@@ -261,6 +346,9 @@ void Debug_dumpGlobals()
|
||||
Debug_pushMessage("hasDTC: %d\n", globals.hasDTC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dumps the persistence data variables and their values to the debug output.
|
||||
*/
|
||||
void Debug_dumpPersistance()
|
||||
{
|
||||
Debug_pushMessage("writeCycleCounter: %d\n", PersistenceData.writeCycleCounter);
|
||||
@@ -270,12 +358,21 @@ void Debug_dumpPersistance()
|
||||
Debug_pushMessage("PSD Adress: 0x%04X\n", globals.eePersistanceAdress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prints information related to WiFi to the debug output.
|
||||
*/
|
||||
void Debug_printWifiInfo()
|
||||
{
|
||||
// Add relevant code here if needed
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks the EEPROM data integrity by calculating and comparing checksums.
|
||||
* Prints the result to the debug output.
|
||||
*/
|
||||
void Debug_CheckEEPOM()
|
||||
{
|
||||
// Check PersistenceData EEPROM checksum
|
||||
uint32_t checksum = PersistenceData.checksum;
|
||||
PersistenceData.checksum = 0;
|
||||
|
||||
@@ -290,6 +387,7 @@ void Debug_CheckEEPOM()
|
||||
|
||||
PersistenceData.checksum = checksum;
|
||||
|
||||
// Check LubeConfig EEPROM checksum
|
||||
checksum = LubeConfig.checksum;
|
||||
LubeConfig.checksum = 0;
|
||||
|
||||
@@ -304,24 +402,32 @@ void Debug_CheckEEPOM()
|
||||
LubeConfig.checksum = checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Displays Diagnostic Trouble Codes (DTCs) along with their timestamps,
|
||||
* status, and severity in a formatted manner.
|
||||
*/
|
||||
void Debug_ShowDTCs()
|
||||
{
|
||||
char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
|
||||
char buff_active[9];
|
||||
|
||||
// Header for the DTC display
|
||||
Debug_pushMessage("\n timestamp | DTC-Nr. | status | severity\n");
|
||||
|
||||
// Iterate through DTCStorage and display each entry
|
||||
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
|
||||
{
|
||||
if (DTCStorage[i].Number < DTC_LAST_DTC)
|
||||
{
|
||||
// Format timestamp
|
||||
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
|
||||
DTCStorage[i].timestamp % 1000); // milliseconds
|
||||
DTCStorage[i].timestamp % 1000); // Milliseconds
|
||||
|
||||
// Determine DTC status
|
||||
if (DTCStorage[i].active == DTC_ACTIVE)
|
||||
strcpy(buff_active, "active");
|
||||
else if (DTCStorage[i].active == DTC_PREVIOUS)
|
||||
@@ -329,19 +435,28 @@ void Debug_ShowDTCs()
|
||||
else
|
||||
strcpy(buff_active, "none");
|
||||
|
||||
// Display DTC information
|
||||
Debug_pushMessage("%s %7d %8s %8d\n", buff_timestamp, DTCStorage[i].Number, buff_active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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];
|
||||
|
||||
for (unsigned int i = sizeof(helpCmd) / 63; i < sizeof(helpCmd) / 63; i++)
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user