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
|
|
|
|
|
|
|
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
|
|
|
|
RemoteDebug Debug;
|
|
|
|
String IpAddress2String(const IPAddress &ipAddress);
|
|
|
|
void processCmdRemoteDebug();
|
|
|
|
void RemoteDebug_formatCFG();
|
|
|
|
void RemoteDebug_formatPersistence();
|
|
|
|
void RemotDebug_printSystemInfo();
|
|
|
|
void RemoteDebug_printWifiInfo();
|
|
|
|
void RemoteDebug_CheckEEPOM();
|
|
|
|
void RemoteDebug_dumpConfig();
|
|
|
|
void RemoteDebug_dumpPersistance();
|
|
|
|
void RemoteDebug_ShowDTCs();
|
|
|
|
void RemoteDebug_dumpGlobals();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void initDebugger()
|
|
|
|
{
|
2023-02-24 00:05:51 +01:00
|
|
|
DebuggerStatus[dbg_Serial] = disabled;
|
|
|
|
DebuggerStatus[dbg_Webui] = disabled;
|
2023-02-23 23:14:58 +01:00
|
|
|
|
|
|
|
Serial.setDebugOutput(false);
|
|
|
|
|
|
|
|
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
|
|
|
|
Debug.begin(globals.DeviceName);
|
|
|
|
Debug.setResetCmdEnabled(true);
|
|
|
|
Debug.showProfiler(false);
|
|
|
|
Debug.showColors(true);
|
|
|
|
Debug.setPassword(QUOTE(ADMIN_PASSWORD));
|
|
|
|
Debug.setSerialEnabled(true);
|
|
|
|
Debug.showDebugLevel(true);
|
|
|
|
|
|
|
|
Debug.setHelpProjectsCmds(helpCmd);
|
|
|
|
Debug.setCallBackProjectCmds(&processCmdRemoteDebug);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debugger_Process()
|
|
|
|
{
|
|
|
|
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
|
|
|
|
Debug.handle();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-02-24 00:05:51 +01:00
|
|
|
void SetDebugportStatus(DebugPorts_t port, DebugStatus_t status)
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-02-24 00:05:51 +01:00
|
|
|
if (status == disabled)
|
|
|
|
Debug_pushMessage("disable DebugPort %s", sDebugPorts[port]);
|
|
|
|
|
|
|
|
DebuggerStatus[port] = status;
|
2023-02-23 23:14:58 +01:00
|
|
|
|
2023-02-24 00:05:51 +01:00
|
|
|
if (status == enabled)
|
|
|
|
Debug_pushMessage("enabled DebugPort %s", sDebugPorts[port]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Debug_pushMessage(const char *format, ...)
|
|
|
|
{
|
|
|
|
if ((DebuggerStatus[dbg_Serial] == enabled) || (DebuggerStatus[dbg_Webui] == enabled))
|
2023-02-23 23:14:58 +01:00
|
|
|
{
|
2023-02-24 00:05:51 +01:00
|
|
|
char buff[64];
|
|
|
|
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));
|
|
|
|
}
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
{
|
|
|
|
char buff[100];
|
|
|
|
char *p = buff;
|
|
|
|
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
|
|
|
|
|
|
|
if (DebuggerStatus[dbg_Serial] == enabled)
|
|
|
|
{
|
|
|
|
Serial.print(buff);
|
|
|
|
}
|
|
|
|
if (DebuggerStatus[dbg_Webui] == enabled)
|
|
|
|
{
|
|
|
|
Websocket_PushLiveDebug(String(buff));
|
|
|
|
}
|
2023-02-23 23:14:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
|
|
|
|
void processCmdRemoteDebug()
|
|
|
|
{
|
|
|
|
String lastCmd = Debug.getLastCommand();
|
|
|
|
|
|
|
|
if (lastCmd == "sysinfo")
|
|
|
|
RemotDebug_printSystemInfo();
|
|
|
|
else if (lastCmd == "netinfo")
|
|
|
|
RemoteDebug_printWifiInfo();
|
|
|
|
else if (lastCmd == "formatCFG")
|
|
|
|
RemoteDebug_formatCFG();
|
|
|
|
else if (lastCmd == "formatPDS")
|
|
|
|
RemoteDebug_formatPersistence();
|
|
|
|
else if (lastCmd == "checkEE")
|
|
|
|
RemoteDebug_CheckEEPOM();
|
|
|
|
else if (lastCmd == "dumpEE1k")
|
|
|
|
dumpEEPROM(0, 1024);
|
|
|
|
else if (lastCmd == "dumpEE")
|
|
|
|
dumpEEPROM(0, EEPROM_SIZE_BYTES);
|
|
|
|
else if (lastCmd == "resetPageEE")
|
|
|
|
MovePersistencePage_EEPROM(true);
|
|
|
|
else if (lastCmd == "dumpCFG")
|
|
|
|
RemoteDebug_dumpConfig();
|
|
|
|
else if (lastCmd == "dumpPDS")
|
|
|
|
RemoteDebug_dumpPersistance();
|
|
|
|
else if (lastCmd == "saveEE")
|
|
|
|
globals.requestEEAction = EE_ALL_SAVE;
|
|
|
|
else if (lastCmd == "showdtc")
|
|
|
|
RemoteDebug_ShowDTCs();
|
|
|
|
else if (lastCmd == "dumpGlobals")
|
|
|
|
RemoteDebug_dumpGlobals();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_formatCFG()
|
|
|
|
{
|
|
|
|
debugA("Formatting Config-EEPROM and reseting to default");
|
|
|
|
FormatConfig_EEPROM();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_formatPersistence()
|
|
|
|
{
|
|
|
|
debugA("Formatting Persistence-EEPROM and reseting to default");
|
|
|
|
FormatPersistence_EEPROM();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemotDebug_printSystemInfo()
|
|
|
|
{
|
|
|
|
debugA("Souko's ChainOiler Mk1");
|
|
|
|
debugA("Hostname: %s", globals.DeviceName);
|
|
|
|
|
|
|
|
FlashMode_t ideMode = ESP.getFlashChipMode();
|
|
|
|
debugA("Sdk version: %s", ESP.getSdkVersion());
|
|
|
|
debugA("Core Version: %s", ESP.getCoreVersion().c_str());
|
|
|
|
debugA("Boot Version: %u", ESP.getBootVersion());
|
|
|
|
debugA("Boot Mode: %u", ESP.getBootMode());
|
|
|
|
debugA("CPU Frequency: %u MHz", ESP.getCpuFreqMHz());
|
|
|
|
debugA("Reset reason: %s", ESP.getResetReason().c_str());
|
|
|
|
debugA("Flash Size: %d", ESP.getFlashChipRealSize());
|
|
|
|
debugA("Flash Size IDE: %d", ESP.getFlashChipSize());
|
|
|
|
debugA("Flash ide mode: %s", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT"
|
|
|
|
: ideMode == FM_DIO ? "DIO"
|
|
|
|
: ideMode == FM_DOUT ? "DOUT"
|
|
|
|
: "UNKNOWN"));
|
|
|
|
debugA("OTA-Pass: %s", QUOTE(ADMIN_PASSWORD));
|
|
|
|
debugA("Git-Revison: %s", GIT_REV);
|
|
|
|
debugA("Sw-Version: %s", QUOTE(SW_VERSION));
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_dumpConfig()
|
|
|
|
{
|
|
|
|
debugA("DistancePerLube_Default: %d", LubeConfig.DistancePerLube_Default);
|
|
|
|
debugA("DistancePerLube_Rain: %d", LubeConfig.DistancePerLube_Rain);
|
|
|
|
debugA("tankCapacity_ml: %d", LubeConfig.tankCapacity_ml);
|
|
|
|
debugA("amountPerDose_microL: %d", LubeConfig.amountPerDose_microL);
|
|
|
|
debugA("TankRemindAtPercentage: %d", LubeConfig.TankRemindAtPercentage);
|
|
|
|
debugA("PulsePerRevolution: %d", LubeConfig.PulsePerRevolution);
|
|
|
|
debugA("TireWidth_mm: %d", LubeConfig.TireWidth_mm);
|
|
|
|
debugA("TireWidthHeight_Ratio: %d", LubeConfig.TireWidth_mm);
|
|
|
|
debugA("RimDiameter_Inch: %d", LubeConfig.RimDiameter_Inch);
|
|
|
|
debugA("DistancePerRevolution_mm: %d", LubeConfig.DistancePerRevolution_mm);
|
|
|
|
debugA("BleedingPulses: %d", LubeConfig.BleedingPulses);
|
|
|
|
debugA("SpeedSource: %d", LubeConfig.SpeedSource);
|
|
|
|
#ifdef FEATURE_ENABLE_GPS
|
|
|
|
debugA("GPSBaudRate: %d", LubeConfig.GPSBaudRate);
|
|
|
|
#endif
|
|
|
|
#ifdef FEATURE_ENABLE_CAN
|
|
|
|
debugA("CANSource: %d", LubeConfig.CANSource);
|
|
|
|
#endif
|
|
|
|
debugA("checksum: 0x%08X", LubeConfig.checksum);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_dumpGlobals()
|
|
|
|
{
|
|
|
|
debugA("systemStatus: %d", globals.systemStatus);
|
|
|
|
debugA("resumeStatus: %d", globals.resumeStatus);
|
|
|
|
debugA("systemStatustxt: %s", globals.systemStatustxt);
|
|
|
|
debugA("purgePulses: %d", globals.purgePulses);
|
|
|
|
debugA("requestEEAction: %d", globals.requestEEAction);
|
|
|
|
debugA("DeviceName: %s", globals.DeviceName);
|
|
|
|
debugA("FlashVersion: %s", globals.FlashVersion);
|
|
|
|
debugA("eePersistanceAdress: %d", globals.eePersistanceAdress);
|
|
|
|
debugA("TankPercentage: %d", globals.TankPercentage);
|
|
|
|
debugA("hasDTC: %d", globals.hasDTC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_dumpPersistance()
|
|
|
|
{
|
|
|
|
debugA("writeCycleCounter: %d", PersistenceData.writeCycleCounter);
|
|
|
|
debugA("tankRemain_microL: %d", PersistenceData.tankRemain_microL);
|
|
|
|
debugA("TravelDistance_highRes_mm: %d", PersistenceData.TravelDistance_highRes_mm);
|
|
|
|
debugA("checksum: %d", PersistenceData.checksum);
|
|
|
|
debugA("PSD Adress: 0x%04X", globals.eePersistanceAdress);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_printWifiInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_CheckEEPOM()
|
|
|
|
{
|
|
|
|
uint32_t checksum = PersistenceData.checksum;
|
|
|
|
PersistenceData.checksum = 0;
|
|
|
|
|
|
|
|
if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) == checksum)
|
|
|
|
{
|
|
|
|
debugA("PersistenceData EEPROM Checksum OK\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debugA("PersistenceData EEPROM Checksum BAD\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
PersistenceData.checksum = checksum;
|
|
|
|
|
|
|
|
checksum = LubeConfig.checksum;
|
|
|
|
LubeConfig.checksum = 0;
|
|
|
|
|
|
|
|
if (Checksum_EEPROM((uint8_t *)&LubeConfig, sizeof(LubeConfig)) == checksum)
|
|
|
|
{
|
|
|
|
debugA("LubeConfig EEPROM Checksum OK\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debugA("LubeConfig EEPROM Checksum BAD\n");
|
|
|
|
}
|
|
|
|
LubeConfig.checksum = checksum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoteDebug_ShowDTCs()
|
|
|
|
{
|
|
|
|
char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx
|
|
|
|
char buff_active[9];
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < MAX_DTC_STORAGE; i++)
|
|
|
|
{
|
|
|
|
if (DTCStorage[i].Number < DTC_LAST_DTC)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
debugA("%s \t %6d \t %s", buff_timestamp, DTCStorage[i].Number, buff_active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|