diff --git a/README.md b/README.md index e30b2bb6..c0a364bd 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571 ##### Rolling - (2020-09-11) +* Improved handling of PreValue +* Improved error handling for automated processflow (reduce spontaneous reboot - see Issues) * Support of spaces in WLan SSID or password 2020-09-10 diff --git a/code/lib/jomjol_fileserver_ota/server_ota.cpp b/code/lib/jomjol_fileserver_ota/server_ota.cpp index ecd17a44..11359885 100644 --- a/code/lib/jomjol_fileserver_ota/server_ota.cpp +++ b/code/lib/jomjol_fileserver_ota/server_ota.cpp @@ -400,18 +400,21 @@ void task_reboot(void *pvParameter) vTaskDelete(NULL); //Delete this task if it exits from the loop above } +void doReboot(){ + LogFile.WriteToFile("Reboot - now"); + KillTFliteTasks(); + xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL); +} + esp_err_t handler_reboot(httpd_req_t *req) { LogFile.WriteToFile("handler_reboot"); ESP_LOGI(TAGPARTOTA, "!!! System will restart within 5 sec!!!"); - const char* resp_str = "!!! System will restart within 5 sec!!!"; httpd_resp_send(req, resp_str, strlen(resp_str)); - KillTFliteTasks(); - - xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL); + doReboot(); return ESP_OK; } diff --git a/code/lib/jomjol_fileserver_ota/server_ota.h b/code/lib/jomjol_fileserver_ota/server_ota.h index 4d6df7d1..440cb67d 100644 --- a/code/lib/jomjol_fileserver_ota/server_ota.h +++ b/code/lib/jomjol_fileserver_ota/server_ota.h @@ -7,4 +7,5 @@ static const char *TAGPARTOTA = "server_ota"; void register_server_ota_sdcard_uri(httpd_handle_t server); -void CheckOTAUpdate(); \ No newline at end of file +void CheckOTAUpdate(); +void doReboot(); \ No newline at end of file diff --git a/code/lib/jomjol_flowcontroll/ClassFlowAlignment.cpp b/code/lib/jomjol_flowcontroll/ClassFlowAlignment.cpp index f14cc161..0618fa17 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowAlignment.cpp +++ b/code/lib/jomjol_flowcontroll/ClassFlowAlignment.cpp @@ -1,5 +1,7 @@ #include "ClassFlowAlignment.h" +#include "ClassLogFile.h" + ClassFlowAlignment::ClassFlowAlignment() { initalrotate = 0; @@ -83,11 +85,22 @@ bool ClassFlowAlignment::doFlow(string time) output = FormatFileName(output); output2 = FormatFileName(output2); - CRotate *rt; if (initalrotate != 0) { + CRotate *rt; rt = new CRotate(input); + if (!rt->ImageOkay()){ + LogFile.WriteToFile("ClassFlowAlignment::doFlow CRotate raw.jpg not okay!"); + delete rt; + LogFile.WriteToFile("ClassFlowAlignment::doFlow 1x reload."); + rt = new CRotate(input); + if (!rt->ImageOkay()){ + LogFile.WriteToFile("ClassFlowAlignment::doFlow Reload auch nicht erfolgreich!"); + delete rt; + return false; + } + } rt->Rotate(this->initalrotate); rt->SaveToFile(output); delete rt; diff --git a/code/lib/jomjol_flowcontroll/ClassFlowControll.cpp b/code/lib/jomjol_flowcontroll/ClassFlowControll.cpp index df54a29c..f9c49f2f 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/lib/jomjol_flowcontroll/ClassFlowControll.cpp @@ -3,6 +3,7 @@ #include "ClassLogFile.h" #include "time_sntp.h" #include "Helper.h" +#include "server_ota.h" std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){ bool found = false; @@ -144,13 +145,29 @@ bool ClassFlowControll::doFlow(string time) { bool result = true; std::string zw_time; + int repeat = 0; + for (int i = 0; i < FlowControll.size(); ++i) { zw_time = gettimestring("%Y%m%d-%H%M%S"); aktstatus = zw_time + ": " + FlowControll[i]->name(); string zw = "FlowControll.doFlow - " + FlowControll[i]->name(); LogFile.WriteToFile(zw); - result = result && FlowControll[i]->doFlow(time); + if (!FlowControll[i]->doFlow(time)){ + repeat++; + LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt"); + i = i-2; // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen) + result = false; + if (repeat > 5) { + LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot"); + doReboot(); + // Schritt wurde 5x wiederholt --> reboot + } + } + else + { + result = true; + } } zw_time = gettimestring("%Y%m%d-%H%M%S"); aktstatus = zw_time + ": Flow is done"; diff --git a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index ddce7ee5..e84c3ff9 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -56,6 +56,25 @@ bool ClassFlowPostProcessing::LoadPreValue(void) difference /= 60; if (difference > PreValueAgeStartup) return false; + + Value = PreValue; + ReturnValue = to_string(Value); + ReturnValueNoError = ReturnValue; + + // falls es Analog gibt, dann die Anzahl der Nachkommastellen feststellen und entsprechend runden: + for (int i = 0; i < ListFlowControll->size(); ++i) + { + if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0) + { + int AnzahlNachkomma = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs(); + std::stringstream stream; + stream << std::fixed << std::setprecision(AnzahlNachkomma) << Value; + ReturnValue = stream.str(); + ReturnValueNoError = ReturnValue; + } + } + + return true; } @@ -143,21 +162,6 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { PreValueUse = true; PreValueOkay = LoadPreValue(); - if (PreValueOkay) - { - Value = PreValue; - for (int i = 0; i < ListFlowControll->size(); ++i) - { - if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0) - { - int AnzahlNachkomma = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs(); - std::stringstream stream; - stream << std::fixed << std::setprecision(AnzahlNachkomma) << Value; - ReturnValue = stream.str(); - ReturnValueNoError = ReturnValue; - } - } - } } } if ((zerlegt[0] == "CheckDigitIncreaseConsistency") && (zerlegt.size() > 1)) @@ -235,17 +239,17 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) // isdigit = true; digit = "12N"; // isanalog = true; analog = "456"; + if (isdigit) + ReturnRawValue = digit; + if (isdigit && isanalog) + ReturnRawValue = ReturnRawValue + "."; + if (isanalog) + ReturnRawValue = ReturnRawValue + analog; if (!PreValueUse || !PreValueOkay) { - if (isdigit) - ReturnValue = digit; - if (isdigit && isanalog) - ReturnValue = ReturnValue + "."; - if (isanalog) - ReturnValue = ReturnValue + analog; - - ReturnRawValue = ReturnValue; + ReturnValue = ReturnRawValue; + ReturnValueNoError = ReturnRawValue; if ((findDelimiterPos(ReturnValue, "N") == std::string::npos) && (ReturnValue.length() > 0)) { @@ -254,19 +258,13 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) ReturnValue.erase(0, 1); } Value = std::stof(ReturnValue); + ReturnValueNoError = ReturnValue; + SavePreValue(Value, zwtime); } - return true; } - if (isdigit) - ReturnRawValue = digit; - if (isdigit && isanalog) - ReturnRawValue = ReturnRawValue + "."; - if (isanalog) - ReturnRawValue = ReturnRawValue + analog; - if (isdigit) { int lastanalog = -1; @@ -295,14 +293,16 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) stream << std::fixed << std::setprecision(AnzahlNachkomma) << Value; zwvalue = stream.str(); } - - if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue)) + else { - error = "Rate too high - Returned old value - read value: " + zwvalue; - Value = PreValue; - stream.str(""); - stream << std::fixed << std::setprecision(AnzahlNachkomma) << Value; - zwvalue = stream.str(); + if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue)) + { + error = "Rate too high - Returned old value - read value: " + zwvalue; + Value = PreValue; + stream.str(""); + stream << std::fixed << std::setprecision(AnzahlNachkomma) << Value; + zwvalue = stream.str(); + } } ReturnValueNoError = zwvalue; diff --git a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h index 2f527d23..b3fba529 100644 --- a/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -18,15 +18,14 @@ protected: bool checkDigitIncreaseConsistency; string FilePreValue; - float PreValue; - float Value; - string ReturnValue; - string ReturnRawValue; - string ReturnValueNoError; + float PreValue; // letzter Wert, der gut ausgelesen wurde + float Value; // letzer ausgelesener Wert, inkl. Korrekturen + string ReturnRawValue; // Rohwert (mit N & führenden 0) + string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung + string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung bool LoadPreValue(void); - string ErsetzteN(string, int lastvalueanalog); public: diff --git a/code/lib/jomjol_image_proc/CFindTemplate.cpp b/code/lib/jomjol_image_proc/CFindTemplate.cpp index db947129..9edaf088 100644 --- a/code/lib/jomjol_image_proc/CFindTemplate.cpp +++ b/code/lib/jomjol_image_proc/CFindTemplate.cpp @@ -374,6 +374,10 @@ CImageBasis::CImageBasis(std::string _image) // printf("w %d, h %d, b %d, c %d", this->width, this->height, this->bpp, this->channels); } +bool CImageBasis::ImageOkay(){ + return rgb_image != NULL; +} + CImageBasis::CImageBasis(uint8_t* _rgb_image, int _channels, int _width, int _height, int _bpp) { this->rgb_image = _rgb_image; diff --git a/code/lib/jomjol_image_proc/CFindTemplate.h b/code/lib/jomjol_image_proc/CFindTemplate.h index 58e5e840..c7b525af 100644 --- a/code/lib/jomjol_image_proc/CFindTemplate.h +++ b/code/lib/jomjol_image_proc/CFindTemplate.h @@ -36,6 +36,7 @@ class CImageBasis void drawCircle(int x1, int y1, int rad, int r, int g, int b, int thickness = 1); void setPixelColor(int x, int y, int r, int g, int b); void Contrast(float _contrast); + bool ImageOkay(); CImageBasis(); diff --git a/firmware/bootloader.bin b/firmware/bootloader.bin index af29e128..a62e024e 100644 Binary files a/firmware/bootloader.bin and b/firmware/bootloader.bin differ diff --git a/firmware/firmware.bin b/firmware/firmware.bin index 8bd8328d..96645355 100644 Binary files a/firmware/firmware.bin and b/firmware/firmware.bin differ