Added DTC for LittleFS-Image Version mismatch

This commit is contained in:
2022-08-22 14:26:37 +02:00
parent bd4c1d9d53
commit 6ffe239cae
4 changed files with 27 additions and 15 deletions

View File

@@ -20,7 +20,12 @@ void initWebUI()
return;
}
globals.FlashVersion = GetFlashVersion();
GetFlashVersion(globals.FlashVersion, sizeof(globals.FlashVersion));
if (!strcmp(globals.FlashVersion, QUOTE(FLASH_FS_VERSION))
{
MaintainDTC(DTC_FLASHFS_VERSION_ERROR, DTC_WARN, true);
}
MDNS.begin(globals.DeviceName);
MDNS.addService("telnet", "tcp", 23);
@@ -312,20 +317,21 @@ void WebserverNotFound_Callback(AsyncWebServerRequest *request)
request->send(404, "text/html", "Not found");
}
uint32_t GetFlashVersion()
void GetFlashVersion(char *buff, size_t buff_size)
{
char buffer[20];
File this_file = LittleFS.open("version", "r");
if (!this_file)
{ // failed to open the file, retrn empty result
return 0;
}
if (this_file.available())
{
this_file.readBytesUntil('\r', buffer, sizeof(buffer));
}
this_file.close();
return atoi(buffer);
File this_file = LittleFS.open("version", "r");
if (!this_file)
{ // failed to open the file, retrn empty result
buff[0] = '\0';
return;
}
if (this_file.available())
{
int bytes_read;
bytes_read = this_file.readBytesUntil('\r', buff, buff_size-1);
buff[bytes_read] = '\0';
}
this_file.close();
}
void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)