new debugger and websockets

This commit is contained in:
2023-02-23 23:14:58 +01:00
parent c9a6e4c870
commit 77a94de2eb
14 changed files with 516 additions and 283 deletions

View File

@@ -17,6 +17,7 @@
#include "webui.h"
#include "config.h"
#include "globals.h"
#include "debugger.h"
#ifdef FEATURE_ENABLE_CAN
#include "can.h"
#endif
@@ -25,14 +26,6 @@
#endif
#include "dtc.h"
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
#include <RemoteDebug.h>
#include "rmtdbghelp.h"
#else
#define debugV Serial.println
#define debugE Serial.println
#endif
#ifdef FEATURE_ENABLE_WIFI_CLIENT
#include <ESP8266WiFiMulti.h>
@@ -44,8 +37,6 @@ ESP8266WiFiMulti wifiMulti;
#endif
bool startSetupMode = false;
Globals_t globals;
volatile uint32_t wheel_pulse = 0;
CRGB leds[1];
@@ -62,22 +53,6 @@ void toggleWiFiAP(boolean shutdown = false);
void SystemShutdown();
uint32_t Process_Impulse_WheelSpeed();
void EEPROMCyclicPDS_callback();
void initGlobals();
#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
#ifdef FEATURE_ENABLE_WIFI_CLIENT
void wifiMaintainConnectionTicker_callback();
@@ -103,8 +78,6 @@ void setup()
#endif
Serial.begin(115200);
Serial.setDebugOutput(false);
Serial.println("\n\nSouko's ChainLube Mk1");
Serial.println(globals.DeviceName);
@@ -137,26 +110,13 @@ void setup()
break;
#endif
default:
debugE("Source Setting N/A");
Debug_pushMessage("Source Setting N/A");
break;
}
pinMode(GPIO_BUTTON, INPUT_PULLUP);
pinMode(GPIO_PUMP, OUTPUT);
#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
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(globals.DeviceName);
ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
@@ -232,11 +192,11 @@ void loop()
Button_Process();
LED_Process();
EEPROM_Process();
Webserver_Process();
Debugger_Process();
ArduinoOTA.handle();
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
Debug.handle();
#endif
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.update();
#endif
@@ -253,163 +213,6 @@ String IpAddress2String(const IPAddress &ipAddress)
String(ipAddress[3]);
}
void initGlobals()
{
globals.purgePulses = 0;
globals.requestEEAction = EE_IDLE;
globals.resumeStatus = sysStat_Normal;
globals.systemStatus = sysStat_Startup;
}
#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;
}
#endif
#ifdef FEATURE_ENABLE_WIFI_CLIENT
void wifiMaintainConnectionTicker_callback()
{
@@ -428,7 +231,7 @@ void wifiMaintainConnectionTicker_callback()
}
else
{
debugV("WiFi not connected! - Start AP");
Debug_pushMessage("WiFi not connected! - Start AP");
toggleWiFiAP();
}
}
@@ -474,7 +277,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
if (LED_Status != LED_Override)
{
LED_ResumeOverrideStatus = LED_Status;
debugV("Override LED_Status");
Debug_pushMessage("Override LED_Status");
}
LED_Status = LED_Override;
LED_override_color = SetColor;
@@ -485,7 +288,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
if (LED_Status == LED_Override)
{
LED_Status = LED_ResumeOverrideStatus;
debugV("Resume LED_Status");
Debug_pushMessage("Resume LED_Status");
}
}
@@ -495,25 +298,25 @@ void LED_Process(uint8_t override, CRGB SetColor)
{
case sysStat_Startup:
LED_Status = LED_Startup;
debugV("sysStat: Startup");
Debug_pushMessage("sysStat: Startup");
break;
case sysStat_Normal:
timestamp = timer + 3500;
LED_Status = LED_Confirm_Normal;
debugV("sysStat: Normal");
Debug_pushMessage("sysStat: Normal");
break;
case sysStat_Rain:
timestamp = timer + 3500;
LED_Status = LED_Confirm_Rain;
debugV("sysStat: Rain");
Debug_pushMessage("sysStat: Rain");
break;
case sysStat_Purge:
LED_Status = LED_Purge;
debugV("sysStat: Purge");
Debug_pushMessage("sysStat: Purge");
break;
case sysStat_Error:
LED_Status = LED_Error;
debugV("sysStat: Error");
Debug_pushMessage("sysStat: Error");
break;
case sysStat_Shutdown:
default:
@@ -540,7 +343,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
{
LED_Status = LED_Normal;
FastLED.setBrightness(64);
debugV("LED_Status: Confirm -> Normal");
Debug_pushMessage("LED_Status: Confirm -> Normal");
}
break;
@@ -564,7 +367,7 @@ void LED_Process(uint8_t override, CRGB SetColor)
{
LED_Status = LED_Rain;
FastLED.setBrightness(64);
debugV("LED_Status: Confirm -> Rain");
Debug_pushMessage("LED_Status: Confirm -> Rain");
}
break;
@@ -694,13 +497,13 @@ void Button_Process()
{
case BTN_TOGGLEWIFI:
toggleWiFiAP();
debugV("Starting WiFi AP");
Debug_pushMessage("Starting WiFi AP");
break;
case BTN_STARTPURGE:
globals.systemStatus = sysStat_Purge;
globals.purgePulses = LubeConfig.BleedingPulses;
debugV("Starting Purge");
Debug_pushMessage("Starting Purge");
break;
case BTN_TOGGLEMODE:
@@ -718,12 +521,12 @@ void Button_Process()
default:
break;
}
debugV("Toggling Mode");
Debug_pushMessage("Toggling Mode");
break;
case BTN_NOTHING:
default:
debugV("Nothing or invalid");
Debug_pushMessage("Nothing or invalid");
break;
}
LED_Process(2);
@@ -738,7 +541,7 @@ void toggleWiFiAP(boolean shutdown)
if (WiFi.getMode() != WIFI_OFF)
{
WiFi.mode(WIFI_OFF);
debugV("WiFi turned off");
Debug_pushMessage("WiFi turned off");
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
#endif
@@ -750,9 +553,9 @@ void toggleWiFiAP(boolean shutdown)
WiFi.softAP(globals.DeviceName, QUOTE(WIFI_AP_PASSWORD));
#ifdef FEATURE_ENABLE_WIFI_CLIENT
WiFiMaintainConnectionTicker.stop();
debugV("WiFi AP started, stopped Maintain-Timer");
Debug_pushMessage("WiFi AP started, stopped Maintain-Timer");
#else
debugV("WiFi AP started");
Debug_pushMessage("WiFi AP started");
#endif
}
}
@@ -784,32 +587,3 @@ uint32_t Process_Impulse_WheelSpeed()
return add_milimeters;
}
#ifdef FEATURE_ENABLE_REMOTE_DEBUG
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