Compare commits

..

No commits in common. "a6f5b4ef6586102c0954d75586c1e34714dd0e77" and "a6ae30d65535694cf91ca9984e752c2223c81dcb" have entirely different histories.

8 changed files with 54 additions and 72 deletions

View File

@ -4,6 +4,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>KTM CAN Chain Oiler</title> <title>KTM CAN Chain Oiler</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="static/css/bootstrap.min.css"> <link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/custom.css"> <link rel="stylesheet" href="static/css/custom.css">
@ -46,7 +47,7 @@
</div> </div>
</nav> </nav>
<main class="container"> <main role="main" class="container">
<!-- Tabs Content --> <!-- Tabs Content -->
<div class="tab-content"> <div class="tab-content">
@ -75,9 +76,9 @@
<table class="table"> <table class="table">
<tbody> <tbody>
<tr> <tr>
<th class="col-md-4" scope="col">Timestamp</th> <th class="col-md-4" scope="col">Timestamp</td>
<th class="col-md-4" scope="col">DTC</th> <th class="col-md-4" scope="col">DTC</td>
<th class="col-md-4" scope="col">active</th> <th class="col-md-4" scope="col">active</td>
</tr> </tr>
%DTC_TABLE% %DTC_TABLE%
</tbody> </tbody>
@ -453,6 +454,7 @@
<h3>Firmware Update</h3> <h3>Firmware Update</h3>
<hr> <hr>
<h4>Version-Info</h4> <h4>Version-Info</h4>
<p>
<table class="table"> <table class="table">
<tbody> <tbody>
<tr> <tr>
@ -464,9 +466,10 @@
<td>%FS_VERSION%</td> <td>%FS_VERSION%</td>
</tr> </tr>
</table> </table>
</p>
<hr> <hr>
<h4>Firmware-Update</h4> <h4>Firmware-Update</h4>
<p>
<form method='POST' action='/doUpdate' enctype='multipart/form-data'> <form method='POST' action='/doUpdate' enctype='multipart/form-data'>
<div class="form-group"> <div class="form-group">
<label for="fw-update-file" class="col-sm-2 col-form-label">Firmware-File</label> <label for="fw-update-file" class="col-sm-2 col-form-label">Firmware-File</label>
@ -482,6 +485,7 @@
</div> </div>
</div> </div>
</form> </form>
</p>
</div> </div>
<!-- Div Tab Firmware Update--> <!-- Div Tab Firmware Update-->
</div> </div>

View File

@ -35,8 +35,6 @@
#define OTA_DELAY 50 // ticks -> 10ms / tick #define OTA_DELAY 50 // ticks -> 10ms / tick
#endif #endif
#define SHUTDOWN_DELAY_MS 5000
#define ATOMIC_FS_UPDATE #define ATOMIC_FS_UPDATE
#ifndef ADMIN_PASSWORD #ifndef ADMIN_PASSWORD

View File

@ -4,6 +4,7 @@ I2C_eeprom ee(0x50, EEPROM_SIZE_BYTES);
LubeConfig_t LubeConfig; LubeConfig_t LubeConfig;
persistenceData_t PersistenceData; persistenceData_t PersistenceData;
uint16_t eePersistenceMarker = 0;
const uint16_t eeVersion = 1; // inc const uint16_t eeVersion = 1; // inc
boolean eeAvailable = false; boolean eeAvailable = false;
@ -92,6 +93,11 @@ void GetConfig_EEPROM()
LubeConfig.checksum = checksum; LubeConfig.checksum = checksum;
} }
uint16_t getPersistanceAddress()
{
return startofPersistence + eePersistenceMarker;
}
void StorePersistence_EEPROM() void StorePersistence_EEPROM()
{ {
if (PersistenceData.writeCycleCounter >= 0xFFF0) if (PersistenceData.writeCycleCounter >= 0xFFF0)
@ -105,7 +111,7 @@ void StorePersistence_EEPROM()
if (!checkEEPROMavailable()) if (!checkEEPROMavailable())
return; return;
ee.updateBlock(globals.eePersistanceAdress, (uint8_t *)&PersistenceData, sizeof(PersistenceData)); ee.updateBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
} }
void GetPersistence_EEPROM() void GetPersistence_EEPROM()
@ -113,18 +119,8 @@ void GetPersistence_EEPROM()
if (!checkEEPROMavailable()) if (!checkEEPROMavailable())
return; return;
ee.readBlock(0, (uint8_t *)&globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress)); eePersistenceMarker = (ee.readByte(0) << 8) | ee.readByte(1);
// if we got the StartAdress of Persistance and it's out of Range - we Reset it and store defaults ee.readBlock(getPersistanceAddress(), (uint8_t *)&PersistenceData, sizeof(PersistenceData));
// otherwise we Read from eeprom and check if everything is correct
if (globals.eePersistanceAdress < startofPersistence || globals.eePersistanceAdress > ee.getDeviceSize())
{
MovePersistencePage_EEPROM(true);
FormatPersistence_EEPROM();
MaintainDTC(DTC_EEPROM_PDSADRESS_BAD, true);
}
else
{
ee.readBlock(globals.eePersistanceAdress, (uint8_t *)&PersistenceData, sizeof(PersistenceData));
uint32_t checksum = PersistenceData.checksum; uint32_t checksum = PersistenceData.checksum;
PersistenceData.checksum = 0; PersistenceData.checksum = 0;
@ -132,9 +128,9 @@ void GetPersistence_EEPROM()
if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum) if (Checksum_EEPROM((uint8_t *)&PersistenceData, sizeof(PersistenceData)) != checksum)
{ {
MaintainDTC(DTC_EEPROM_PDS_BAD, true); MaintainDTC(DTC_EEPROM_PDS_BAD, true);
FormatPersistence_EEPROM();
} }
PersistenceData.checksum = checksum; PersistenceData.checksum = checksum;
}
} }
void FormatConfig_EEPROM() void FormatConfig_EEPROM()
@ -149,6 +145,7 @@ void FormatPersistence_EEPROM()
{ {
persistenceData_t defaults; persistenceData_t defaults;
PersistenceData = defaults; PersistenceData = defaults;
eePersistenceMarker = 0;
StorePersistence_EEPROM(); StorePersistence_EEPROM();
} }
@ -157,16 +154,17 @@ void MovePersistencePage_EEPROM(boolean reset)
if (!checkEEPROMavailable()) if (!checkEEPROMavailable())
return; return;
globals.eePersistanceAdress = +sizeof(PersistenceData); eePersistenceMarker = eePersistenceMarker + sizeof(PersistenceData);
PersistenceData.writeCycleCounter = 0; PersistenceData.writeCycleCounter = 0;
// check if we reached the End of the EEPROM and Startover at the beginning // check if we reached the End of the EEPROM and Startover at the beginning
if ((globals.eePersistanceAdress + sizeof(PersistenceData)) > ee.getDeviceSize() || reset) // if ((startofPersistence + eePersistenceMarker + sizeof(PersistenceData)) > ee.getDeviceSize() || reset)
{ // {
globals.eePersistanceAdress = startofPersistence; // eePersistenceMarker = 0;
} // }
ee.updateBlock(0, (uint8_t *)&globals.eePersistanceAdress, sizeof(globals.eePersistanceAdress)); ee.updateByte(0, (uint8_t)(eePersistenceMarker >> 8));
ee.updateByte(1, (uint8_t)(eePersistenceMarker & 0xFF));
} }
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len) uint32_t Checksum_EEPROM(uint8_t const *data, size_t len)

View File

@ -105,6 +105,7 @@ void FormatPersistence_EEPROM();
uint32_t Checksum_EEPROM(uint8_t const *data, size_t len); uint32_t Checksum_EEPROM(uint8_t const *data, size_t len);
void dumpEEPROM(uint16_t memoryAddress, uint16_t length); void dumpEEPROM(uint16_t memoryAddress, uint16_t length);
void MovePersistencePage_EEPROM(boolean reset); void MovePersistencePage_EEPROM(boolean reset);
uint16_t getPersistanceAddress();
extern LubeConfig_t LubeConfig; extern LubeConfig_t LubeConfig;
extern persistenceData_t PersistenceData; extern persistenceData_t PersistenceData;

View File

@ -11,7 +11,6 @@ typedef enum DTCNums_e
DTC_NO_EEPROM_FOUND, DTC_NO_EEPROM_FOUND,
DTC_EEPROM_CFG_BAD, DTC_EEPROM_CFG_BAD,
DTC_EEPROM_PDS_BAD, DTC_EEPROM_PDS_BAD,
DTC_EEPROM_PDSADRESS_BAD,
DTC_EEPROM_VERSION_BAD, DTC_EEPROM_VERSION_BAD,
DTC_FLASHFS_ERROR, DTC_FLASHFS_ERROR,
#ifdef FEATURE_ENABLE_GPS #ifdef FEATURE_ENABLE_GPS

View File

@ -31,8 +31,6 @@ typedef struct Globals_s
uint8_t purgePulses = 0; uint8_t purgePulses = 0;
eEERequest requestEEAction = EE_IDLE; eEERequest requestEEAction = EE_IDLE;
char DeviceName[33]; char DeviceName[33];
uint32_t FlashVersion;
uint16_t eePersistanceAdress;
} Globals_t; } Globals_t;
extern Globals_t globals; extern Globals_t globals;

View File

@ -354,7 +354,7 @@ void RemoteDebug_dumpPersistance()
debugA("tankRemain_µl: %d", PersistenceData.tankRemain_µl); debugA("tankRemain_µl: %d", PersistenceData.tankRemain_µl);
debugA("TravelDistance_highRes_mm: %d", PersistenceData.TravelDistance_highRes_mm); debugA("TravelDistance_highRes_mm: %d", PersistenceData.TravelDistance_highRes_mm);
debugA("checksum: %d", PersistenceData.checksum); debugA("checksum: %d", PersistenceData.checksum);
debugA("PSD Adress: 0x%04X", globals.eePersistanceAdress); debugA("PSD Adress: 0x%04X", getPersistanceAddress());
} }
void RemoteDebug_printWifiInfo() void RemoteDebug_printWifiInfo()
@ -735,19 +735,8 @@ void toggleWiFiAP(boolean shutdown)
void SystemShutdown() void SystemShutdown()
{ {
static uint32_t shutdown_delay = 0;
if (shutdown_delay == 0)
{
shutdown_delay = millis() + SHUTDOWN_DELAY_MS;
Serial.printf("Shutdown requested - Restarting in %d seconds\n", SHUTDOWN_DELAY_MS);
}
if (shutdown_delay < millis())
{
StoreConfig_EEPROM(); StoreConfig_EEPROM();
StorePersistence_EEPROM();
ESP.restart(); ESP.restart();
}
} }
uint32_t Process_Impulse_WheelSpeed() uint32_t Process_Impulse_WheelSpeed()

View File

@ -20,8 +20,6 @@ void initWebUI()
return; return;
} }
globals.FlashVersion = GetFlashVersion();
MDNS.begin(globals.DeviceName); MDNS.begin(globals.DeviceName);
MDNS.addService("telnet", "tcp", 23); MDNS.addService("telnet", "tcp", 23);
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
@ -66,17 +64,13 @@ String processor(const String &var)
return String(LubeConfig.BleedingPulses); return String(LubeConfig.BleedingPulses);
if (var == "SPEED_SOURCE") if (var == "SPEED_SOURCE")
return String(SpeedSourceString[LubeConfig.SpeedSource]); return String(SpeedSourceString[LubeConfig.SpeedSource]);
if (var == "GPS_BAUD")
#ifdef FEATURE_ENABLE_GPS #ifdef FEATURE_ENABLE_GPS
if (var == "GPS_BAUD")
return String(GPSBaudRateString[LubeConfig.GPSBaudRate]); return String(GPSBaudRateString[LubeConfig.GPSBaudRate]);
#else
return "Feature N/A";
#endif #endif
if (var == "CAN_SOURCE")
#ifdef FEATURE_ENABLE_CAN #ifdef FEATURE_ENABLE_CAN
if (var == "CAN_SOURCE")
return String(CANSourceString[LubeConfig.CANSource]); return String(CANSourceString[LubeConfig.CANSource]);
#else
return "Feature N/A";
#endif #endif
if (var == "CONFIG_CHECKSUM") if (var == "CONFIG_CHECKSUM")
{ {
@ -87,7 +81,7 @@ String processor(const String &var)
if (var == "WRITE_CYCLE_COUNT") if (var == "WRITE_CYCLE_COUNT")
return String(PersistenceData.writeCycleCounter); return String(PersistenceData.writeCycleCounter);
if (var == "PERSISTENCE_MARKER") if (var == "PERSISTENCE_MARKER")
return String(globals.eePersistanceAdress); return String(getPersistanceAddress());
if (var == "TANK_REMAIN_UL") if (var == "TANK_REMAIN_UL")
return String(PersistenceData.tankRemain_µl); return String(PersistenceData.tankRemain_µl);
if (var == "TRAVEL_DISTANCE_HIGHRES") if (var == "TRAVEL_DISTANCE_HIGHRES")
@ -196,7 +190,7 @@ String processor(const String &var)
return String(buffer); return String(buffer);
} }
if (var == "FS_VERSION") if (var == "FS_VERSION")
return String(globals.FlashVersion); return String(GetFlashVersion());
if (var == "PLACEHOLDER") if (var == "PLACEHOLDER")
return "placeholder"; return "placeholder";
@ -300,13 +294,14 @@ void WebserverNotFound_Callback(AsyncWebServerRequest *request)
uint32_t GetFlashVersion() uint32_t GetFlashVersion()
{ {
char buffer[20]; char buffer[20];
File this_file = LittleFS.open("version", "r"); File this_file = LittleFS.open("version", "r");
if (!this_file) if (!this_file)
{ // failed to open the file, retrn empty result { // failed to open the file, retrn empty result
return 0; return 0;
} }
if (this_file.available()) while (this_file.available())
{ {
this_file.readBytesUntil('\r', buffer, sizeof(buffer)); this_file.readBytesUntil('\r', buffer, sizeof(buffer));
} }
@ -353,7 +348,7 @@ void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const Stri
{ {
Serial.println("Update complete"); Serial.println("Update complete");
Serial.flush(); Serial.flush();
globals.systemStatus = sysStat_Shutdown; ESP.restart();
} }
} }
} }