|
@@ -4,6 +4,10 @@
|
|
|
|
|
|
|
|
#include <iomanip>
|
|
#include <iomanip>
|
|
|
#include <sstream>
|
|
#include <sstream>
|
|
|
|
|
+#include <new>
|
|
|
|
|
+#include <memory>
|
|
|
|
|
+#include <cerrno>
|
|
|
|
|
+#include <cstdlib>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
#include <time.h>
|
|
|
|
|
|
|
@@ -150,102 +154,127 @@ bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, boo
|
|
|
|
|
|
|
|
bool ClassFlowPostProcessing::LoadPreValue(void) {
|
|
bool ClassFlowPostProcessing::LoadPreValue(void) {
|
|
|
std::vector<string> splitted;
|
|
std::vector<string> splitted;
|
|
|
- FILE* pFile;
|
|
|
|
|
- char zw[1024];
|
|
|
|
|
|
|
+ char zw[1024] = {};
|
|
|
string zwtime, zwvalue, name;
|
|
string zwtime, zwvalue, name;
|
|
|
- bool _done = false;
|
|
|
|
|
|
|
|
|
|
UpdatePreValueINI = false; // Conversion to the new format
|
|
UpdatePreValueINI = false; // Conversion to the new format
|
|
|
|
|
|
|
|
- pFile = fopen(FilePreValue.c_str(), "r");
|
|
|
|
|
-
|
|
|
|
|
- if (pFile == NULL) {
|
|
|
|
|
|
|
+ // Close the descriptor on every return path, including empty or malformed files.
|
|
|
|
|
+ std::unique_ptr<FILE, int(*)(FILE*)> pFile(fopen(FilePreValue.c_str(), "r"), fclose);
|
|
|
|
|
+ if (!pFile) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Makes sure that an empty file is treated as such.
|
|
|
|
|
- zw[0] = '\0';
|
|
|
|
|
-
|
|
|
|
|
- fgets(zw, 1024, pFile);
|
|
|
|
|
|
|
+ if (fgets(zw, sizeof(zw), pFile.get()) == NULL) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
|
|
ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
|
|
|
zwtime = trim(std::string(zw));
|
|
zwtime = trim(std::string(zw));
|
|
|
-
|
|
|
|
|
- if (zwtime.length() == 0) {
|
|
|
|
|
|
|
+ if (zwtime.empty()) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
splitted = HelperZerlegeZeile(zwtime, "\t");
|
|
splitted = HelperZerlegeZeile(zwtime, "\t");
|
|
|
-
|
|
|
|
|
- // Conversion to the new format
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // Conversion to the current tab-separated format: name, timestamp, value.
|
|
|
if (splitted.size() > 1) {
|
|
if (splitted.size() > 1) {
|
|
|
- while ((splitted.size() > 1) && !_done) {
|
|
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ if (splitted.size() < 3) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid PreValue entry: expected name, timestamp and value");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
name = trim(splitted[0]);
|
|
name = trim(splitted[0]);
|
|
|
zwtime = trim(splitted[1]);
|
|
zwtime = trim(splitted[1]);
|
|
|
zwvalue = trim(splitted[2]);
|
|
zwvalue = trim(splitted[2]);
|
|
|
|
|
+ if (name.empty() || !isStringNumeric(zwvalue)) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid PreValue entry for '" + name + "'");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ char* valueEnd = NULL;
|
|
|
|
|
+ errno = 0;
|
|
|
|
|
+ const double parsedValue = strtod(zwvalue.c_str(), &valueEnd);
|
|
|
|
|
+ if (valueEnd == zwvalue.c_str() || *valueEnd != '\0' || errno == ERANGE) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid numeric PreValue for '" + name + "'");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int yy = 0, month = 0, dd = 0, hh = 0, mm = 0, ss = 0;
|
|
|
|
|
+ struct tm whenStart = {};
|
|
|
|
|
+ if (sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT,
|
|
|
|
|
+ &yy, &month, &dd, &hh, &mm, &ss) != 6) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid PreValue timestamp for '" + name + "'");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ whenStart.tm_year = yy - 1900;
|
|
|
|
|
+ whenStart.tm_mon = month - 1;
|
|
|
|
|
+ whenStart.tm_mday = dd;
|
|
|
|
|
+ whenStart.tm_hour = hh;
|
|
|
|
|
+ whenStart.tm_min = mm;
|
|
|
|
|
+ whenStart.tm_sec = ss;
|
|
|
|
|
+ whenStart.tm_isdst = -1;
|
|
|
|
|
+ const time_t parsedTime = mktime(&whenStart);
|
|
|
|
|
+ if (parsedTime == static_cast<time_t>(-1)) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Unable to parse PreValue timestamp for '" + name + "'");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
for (int j = 0; j < NUMBERS.size(); ++j) {
|
|
for (int j = 0; j < NUMBERS.size(); ++j) {
|
|
|
if (NUMBERS[j]->name == name) {
|
|
if (NUMBERS[j]->name == name) {
|
|
|
- NUMBERS[j]->PreValue = stod(zwvalue.c_str());
|
|
|
|
|
- NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // To be on the safe side, 1 digit more, as Exgtended Resolution may be on (will only be set during the first run).
|
|
|
|
|
|
|
+ NUMBERS[j]->PreValue = parsedValue;
|
|
|
|
|
+ NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1);
|
|
|
|
|
+ NUMBERS[j]->timeStampLastPreValue = parsedTime;
|
|
|
|
|
|
|
|
time_t tStart;
|
|
time_t tStart;
|
|
|
- int yy, month, dd, hh, mm, ss;
|
|
|
|
|
- struct tm whenStart;
|
|
|
|
|
-
|
|
|
|
|
- sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
|
|
|
|
|
- whenStart.tm_year = yy - 1900;
|
|
|
|
|
- whenStart.tm_mon = month - 1;
|
|
|
|
|
- whenStart.tm_mday = dd;
|
|
|
|
|
- whenStart.tm_hour = hh;
|
|
|
|
|
- whenStart.tm_min = mm;
|
|
|
|
|
- whenStart.tm_sec = ss;
|
|
|
|
|
- whenStart.tm_isdst = -1;
|
|
|
|
|
-
|
|
|
|
|
- NUMBERS[j]->timeStampLastPreValue = mktime(&whenStart);
|
|
|
|
|
-
|
|
|
|
|
time(&tStart);
|
|
time(&tStart);
|
|
|
- localtime(&tStart);
|
|
|
|
|
- double difference = difftime(tStart, NUMBERS[j]->timeStampLastPreValue);
|
|
|
|
|
- difference /= 60;
|
|
|
|
|
-
|
|
|
|
|
- if (difference > PreValueAgeStartup) {
|
|
|
|
|
- NUMBERS[j]->PreValueOkay = false;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- NUMBERS[j]->PreValueOkay = true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const double difference = difftime(tStart, parsedTime) / 60.0;
|
|
|
|
|
+ NUMBERS[j]->PreValueOkay = (difference <= PreValueAgeStartup);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!fgets(zw, 1024, pFile)) {
|
|
|
|
|
- _done = true;
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
|
|
|
|
|
- splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t");
|
|
|
|
|
-
|
|
|
|
|
- if (splitted.size() > 1) {
|
|
|
|
|
- name = trim(splitted[0]);
|
|
|
|
|
- zwtime = trim(splitted[1]);
|
|
|
|
|
- zwvalue = trim(splitted[2]);
|
|
|
|
|
|
|
+ std::string nextLine;
|
|
|
|
|
+ bool haveNextLine = false;
|
|
|
|
|
+ while (fgets(zw, sizeof(zw), pFile.get()) != NULL) {
|
|
|
|
|
+ nextLine = trim(std::string(zw));
|
|
|
|
|
+ if (!nextLine.empty()) {
|
|
|
|
|
+ haveNextLine = true;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (!haveNextLine) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw);
|
|
|
|
|
+ splitted = HelperZerlegeZeile(nextLine, "\t");
|
|
|
}
|
|
}
|
|
|
- fclose(pFile);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
else {
|
|
else {
|
|
|
- // Old Format
|
|
|
|
|
- fgets(zw, 1024, pFile);
|
|
|
|
|
- fclose(pFile);
|
|
|
|
|
|
|
+ // Old format stores the timestamp in the first line and the value in the second.
|
|
|
|
|
+ if (NUMBERS.empty() || fgets(zw, sizeof(zw), pFile.get()) == NULL) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
ESP_LOGD(TAG, "%s", zw);
|
|
ESP_LOGD(TAG, "%s", zw);
|
|
|
zwvalue = trim(std::string(zw));
|
|
zwvalue = trim(std::string(zw));
|
|
|
- NUMBERS[0]->PreValue = stod(zwvalue.c_str());
|
|
|
|
|
-
|
|
|
|
|
- time_t tStart;
|
|
|
|
|
- int yy, month, dd, hh, mm, ss;
|
|
|
|
|
- struct tm whenStart;
|
|
|
|
|
|
|
+ if (!isStringNumeric(zwvalue)) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid legacy PreValue number");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ char* valueEnd = NULL;
|
|
|
|
|
+ errno = 0;
|
|
|
|
|
+ const double parsedValue = strtod(zwvalue.c_str(), &valueEnd);
|
|
|
|
|
+ if (valueEnd == zwvalue.c_str() || *valueEnd != '\0' || errno == ERANGE) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid numeric legacy PreValue");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
|
|
|
|
|
|
|
+ int yy = 0, month = 0, dd = 0, hh = 0, mm = 0, ss = 0;
|
|
|
|
|
+ struct tm whenStart = {};
|
|
|
|
|
+ if (sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT,
|
|
|
|
|
+ &yy, &month, &dd, &hh, &mm, &ss) != 6) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Invalid legacy PreValue timestamp");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
whenStart.tm_year = yy - 1900;
|
|
whenStart.tm_year = yy - 1900;
|
|
|
whenStart.tm_mon = month - 1;
|
|
whenStart.tm_mon = month - 1;
|
|
|
whenStart.tm_mday = dd;
|
|
whenStart.tm_mday = dd;
|
|
@@ -254,19 +283,21 @@ bool ClassFlowPostProcessing::LoadPreValue(void) {
|
|
|
whenStart.tm_sec = ss;
|
|
whenStart.tm_sec = ss;
|
|
|
whenStart.tm_isdst = -1;
|
|
whenStart.tm_isdst = -1;
|
|
|
|
|
|
|
|
- ESP_LOGD(TAG, "TIME: %d, %d, %d, %d, %d, %d", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec);
|
|
|
|
|
-
|
|
|
|
|
- NUMBERS[0]->timeStampLastPreValue = mktime(&whenStart);
|
|
|
|
|
|
|
+ const time_t parsedTime = mktime(&whenStart);
|
|
|
|
|
+ if (parsedTime == static_cast<time_t>(-1)) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Unable to parse legacy PreValue timestamp");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ time_t tStart;
|
|
|
time(&tStart);
|
|
time(&tStart);
|
|
|
- localtime(&tStart);
|
|
|
|
|
- double difference = difftime(tStart, NUMBERS[0]->timeStampLastPreValue);
|
|
|
|
|
- difference /= 60;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const double difference = difftime(tStart, parsedTime) / 60.0;
|
|
|
if (difference > PreValueAgeStartup) {
|
|
if (difference > PreValueAgeStartup) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ NUMBERS[0]->PreValue = parsedValue;
|
|
|
|
|
+ NUMBERS[0]->timeStampLastPreValue = parsedTime;
|
|
|
NUMBERS[0]->Value = NUMBERS[0]->PreValue;
|
|
NUMBERS[0]->Value = NUMBERS[0]->PreValue;
|
|
|
NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
|
|
NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
|
|
|
|
|
|
|
@@ -274,15 +305,16 @@ bool ClassFlowPostProcessing::LoadPreValue(void) {
|
|
|
NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
|
|
NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- UpdatePreValueINI = true; // Conversion to the new format
|
|
|
|
|
|
|
+ // Close the input before rewriting the file in the current format.
|
|
|
|
|
+ pFile.reset();
|
|
|
|
|
+ UpdatePreValueINI = true;
|
|
|
SavePreValue();
|
|
SavePreValue();
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ClassFlowPostProcessing::SavePreValue() {
|
|
void ClassFlowPostProcessing::SavePreValue() {
|
|
|
- FILE* pFile;
|
|
|
|
|
string _zw;
|
|
string _zw;
|
|
|
|
|
|
|
|
// PreValues unchanged --> File does not have to be rewritten
|
|
// PreValues unchanged --> File does not have to be rewritten
|
|
@@ -290,27 +322,43 @@ void ClassFlowPostProcessing::SavePreValue() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pFile = fopen(FilePreValue.c_str(), "w");
|
|
|
|
|
|
|
+ FILE* rawFile = fopen(FilePreValue.c_str(), "w");
|
|
|
|
|
+ if (rawFile == NULL) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SavePreValue: unable to open " + FilePreValue);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ std::unique_ptr<FILE, int(*)(FILE*)> pFile(rawFile, fclose);
|
|
|
|
|
+ bool writeOkay = true;
|
|
|
|
|
|
|
|
for (int j = 0; j < NUMBERS.size(); ++j) {
|
|
for (int j = 0; j < NUMBERS.size(); ++j) {
|
|
|
- char buffer[80];
|
|
|
|
|
|
|
+ char buffer[80] = {};
|
|
|
struct tm* timeinfo = localtime(&NUMBERS[j]->timeStampLastPreValue);
|
|
struct tm* timeinfo = localtime(&NUMBERS[j]->timeStampLastPreValue);
|
|
|
- strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
|
|
|
|
|
|
|
+ if (timeinfo == NULL || strftime(buffer, sizeof(buffer), PREVALUE_TIME_FORMAT_OUTPUT, timeinfo) == 0) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SavePreValue: unable to format timestamp");
|
|
|
|
|
+ writeOkay = false;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
NUMBERS[j]->timeStamp = std::string(buffer);
|
|
NUMBERS[j]->timeStamp = std::string(buffer);
|
|
|
NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->timeStampLastPreValue;
|
|
NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->timeStampLastPreValue;
|
|
|
- // ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
|
|
|
|
|
|
|
|
|
|
- _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n";
|
|
|
|
|
|
|
+ _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" +
|
|
|
|
|
+ RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n";
|
|
|
ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str());
|
|
ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str());
|
|
|
-
|
|
|
|
|
- if (pFile) {
|
|
|
|
|
- fputs(_zw.c_str(), pFile);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (fputs(_zw.c_str(), pFile.get()) < 0) {
|
|
|
|
|
+ writeOkay = false;
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- UpdatePreValueINI = false;
|
|
|
|
|
-
|
|
|
|
|
- fclose(pFile);
|
|
|
|
|
|
|
+ if (fclose(pFile.release()) != 0) {
|
|
|
|
|
+ writeOkay = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (writeOkay) {
|
|
|
|
|
+ UpdatePreValueINI = false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "SavePreValue: failed while writing " + FilePreValue);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) {
|
|
ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) {
|
|
@@ -593,7 +641,14 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- InitNUMBERS();
|
|
|
|
|
|
|
+ if (!InitNUMBERS()) {
|
|
|
|
|
+ disabled = true;
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Post-processing initialization failed; disabling this step and skipping its configuration");
|
|
|
|
|
+ // InitFlow() advances using aktparamgraph. Consume this entire section so a failed
|
|
|
|
|
+ // allocation cannot leave the parser on [PostProcessing] and recreate the flow forever.
|
|
|
|
|
+ while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) {}
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) {
|
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) {
|
|
|
splitted = ZerlegeZeile(aktparamgraph);
|
|
splitted = ZerlegeZeile(aktparamgraph);
|
|
@@ -661,7 +716,20 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void ClassFlowPostProcessing::InitNUMBERS() {
|
|
|
|
|
|
|
+ClassFlowPostProcessing::~ClassFlowPostProcessing() {
|
|
|
|
|
+ for (NumberPost* number : NUMBERS) {
|
|
|
|
|
+ delete number;
|
|
|
|
|
+ }
|
|
|
|
|
+ NUMBERS.clear();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool ClassFlowPostProcessing::InitNUMBERS() {
|
|
|
|
|
+ // The configuration can be reloaded; release any previous per-number state first.
|
|
|
|
|
+ for (NumberPost* number : NUMBERS) {
|
|
|
|
|
+ delete number;
|
|
|
|
|
+ }
|
|
|
|
|
+ NUMBERS.clear();
|
|
|
|
|
+
|
|
|
int anzDIGIT = 0;
|
|
int anzDIGIT = 0;
|
|
|
int anzANALOG = 0;
|
|
int anzANALOG = 0;
|
|
|
std::vector<std::string> name_numbers;
|
|
std::vector<std::string> name_numbers;
|
|
@@ -677,9 +745,21 @@ void ClassFlowPostProcessing::InitNUMBERS() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG);
|
|
ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG);
|
|
|
|
|
+ if (name_numbers.empty()) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "No digit or analog numbers are available for post-processing");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
for (int _num = 0; _num < name_numbers.size(); ++_num) {
|
|
for (int _num = 0; _num < name_numbers.size(); ++_num) {
|
|
|
- NumberPost *_number = new NumberPost;
|
|
|
|
|
|
|
+ NumberPost *_number = new (std::nothrow) NumberPost;
|
|
|
|
|
+ if (_number == NULL) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Unable to allocate post-processing state for number " + name_numbers[_num]);
|
|
|
|
|
+ for (NumberPost* number : NUMBERS) {
|
|
|
|
|
+ delete number;
|
|
|
|
|
+ }
|
|
|
|
|
+ NUMBERS.clear();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
_number->name = name_numbers[_num];
|
|
_number->name = name_numbers[_num];
|
|
|
|
|
|
|
@@ -739,6 +819,7 @@ void ClassFlowPostProcessing::InitNUMBERS() {
|
|
|
for (int i = 0; i < NUMBERS.size(); ++i) {
|
|
for (int i = 0; i < NUMBERS.size(); ++i) {
|
|
|
ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigit, NUMBERS[i]->AnzahlAnalog);
|
|
ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigit, NUMBERS[i]->AnzahlAnalog);
|
|
|
}
|
|
}
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) {
|
|
string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) {
|
|
@@ -786,6 +867,7 @@ string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool ClassFlowPostProcessing::doFlow(string zwtime) {
|
|
bool ClassFlowPostProcessing::doFlow(string zwtime) {
|
|
|
|
|
+ if (disabled) return true;
|
|
|
std::lock_guard<std::mutex> lock(preValueMutex);
|
|
std::lock_guard<std::mutex> lock(preValueMutex);
|
|
|
string zwvalue;
|
|
string zwvalue;
|
|
|
time_t imagetime = flowTakeImage->getTimeImageTaken();
|
|
time_t imagetime = flowTakeImage->getTimeImageTaken();
|