EEPROM Backup and Restore works
This commit is contained in:
parent
83e288fdcf
commit
6221262dbf
@ -477,29 +477,84 @@ void WebserverFirmwareUpdate_Callback(AsyncWebServerRequest *request, const Stri
|
||||
|
||||
void WebserverEERestore_Callback(AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final)
|
||||
{
|
||||
|
||||
bool ee_done = false;
|
||||
bool validext = false;
|
||||
static bool validext = false;
|
||||
static char *buffer = NULL;
|
||||
static uint32_t read_ptr = 0;
|
||||
DeserializationError error;
|
||||
|
||||
if (!index)
|
||||
{
|
||||
Debug_pushMessage("EEPROM restore\n");
|
||||
// size_t content_len = request->contentLength();
|
||||
validext = (filename.indexOf(".ee.json") > -1);
|
||||
}
|
||||
|
||||
if (validext)
|
||||
{
|
||||
Debug_pushMessage("Restoring EEPROM-Stuff\n");
|
||||
#warning "please implement EEPROM-Restore"
|
||||
buffer = (char *)malloc(1536);
|
||||
read_ptr = 0;
|
||||
if (buffer == NULL)
|
||||
Debug_pushMessage("malloc() failed for EEPROM-Restore");
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer != NULL)
|
||||
{
|
||||
memcpy(buffer + read_ptr, data, len);
|
||||
read_ptr = read_ptr + len;
|
||||
}
|
||||
|
||||
if (final)
|
||||
{
|
||||
if (buffer != NULL)
|
||||
{
|
||||
Serial.print(buffer);
|
||||
StaticJsonDocument<1536> doc;
|
||||
error = deserializeJson(doc, buffer);
|
||||
if (error)
|
||||
{
|
||||
Debug_pushMessage("deserializeJson() failed: %s\n", error.f_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
LubeConfig.DistancePerLube_Default = doc["config"]["DistancePerLube_Default"].as<uint32_t>();
|
||||
LubeConfig.DistancePerLube_Rain = doc["config"]["DistancePerLube_Rain"].as<uint32_t>();
|
||||
LubeConfig.tankCapacity_ml = doc["config"]["tankCapacity_ml"].as<uint32_t>();
|
||||
LubeConfig.amountPerDose_microL = doc["config"]["amountPerDose_microL"].as<uint32_t>();
|
||||
LubeConfig.TankRemindAtPercentage = doc["config"]["TankRemindAtPercentage"].as<uint8_t>();
|
||||
LubeConfig.PulsePerRevolution = doc["config"]["PulsePerRevolution"].as<uint8_t>();
|
||||
LubeConfig.TireWidth_mm = doc["config"]["TireWidth_mm"].as<uint32_t>();
|
||||
LubeConfig.TireWidthHeight_Ratio = doc["config"]["TireWidthHeight_Ratio"].as<uint32_t>();
|
||||
LubeConfig.RimDiameter_Inch = doc["config"]["RimDiameter_Inch"].as<uint32_t>();
|
||||
LubeConfig.DistancePerRevolution_mm = doc["config"]["DistancePerRevolution_mm"].as<uint32_t>();
|
||||
LubeConfig.BleedingPulses = doc["config"]["BleedingPulses"].as<uint16_t>();
|
||||
LubeConfig.SpeedSource = (SpeedSource_t)doc["config"]["SpeedSource"].as<int>();
|
||||
#ifdef FEATURE_ENABLE_GPS
|
||||
LubeConfig.GPSBaudRate = (GPSBaudRate_t)doc["config"]["GPSBaudRate"].as<int>();
|
||||
#endif
|
||||
#ifdef FEATURE_ENABLE_CAN
|
||||
LubeConfig.CANSource = (CANSource_t)doc["config"]["CANSource"].as<int>();
|
||||
#endif
|
||||
LubeConfig.LED_Mode_Flash = doc["config"]["LED_Mode_Flash"].as<bool>();
|
||||
LubeConfig.LED_Max_Brightness = doc["config"]["LED_Max_Brightness"].as<uint8_t>();
|
||||
LubeConfig.LED_Min_Brightness = doc["config"]["LED_Min_Brightness"].as<uint8_t>();
|
||||
|
||||
PersistenceData.writeCycleCounter = doc["persis"]["writeCycleCounter"].as<uint16_t>();
|
||||
PersistenceData.tankRemain_microL = doc["persis"]["tankRemain_microL"].as<uint32_t>();
|
||||
PersistenceData.TravelDistance_highRes_mm = doc["persis"]["TravelDistance_highRes_mm"].as<uint32_t>();
|
||||
PersistenceData.odometer_mm = doc["persis"]["odometer_mm"].as<uint32_t>();
|
||||
PersistenceData.odometer = doc["persis"]["odometer"].as<uint32_t>();
|
||||
PersistenceData.checksum = doc["persis"]["checksum"].as<uint32_t>();
|
||||
|
||||
ee_done = true;
|
||||
}
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", "Please wait while the device reboots");
|
||||
response->addHeader("Refresh", "20");
|
||||
response->addHeader("Location", "/");
|
||||
request->send(response);
|
||||
|
||||
if (ee_done)
|
||||
{
|
||||
Debug_pushMessage("Update complete");
|
||||
@ -520,10 +575,11 @@ void WebServerEEJSON_Callback(AsyncWebServerRequest *request)
|
||||
char buffer[16];
|
||||
|
||||
fwinfo["DeviceName"] = globals.DeviceName;
|
||||
sprintf(buffer, "%d.%02d", constants.Flash_Version_major, constants.Flash_Version_minor);
|
||||
sprintf(buffer, "%d.%02d", constants.Required_Flash_Version_major, constants.Required_Flash_Version_minor);
|
||||
fwinfo["FW-Version"] = buffer;
|
||||
fwinfo["FS-Version"] = globals.FlashVersion;
|
||||
fwinfo["Git-Hash"] = constants.GitHash;
|
||||
snprintf_P(buffer, sizeof(buffer), "%s", constants.GitHash);
|
||||
fwinfo["Git-Hash"] = buffer;
|
||||
|
||||
JsonObject config = json.createNestedObject("config");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user