diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index a0e90e4f..cf5726ec 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -15,124 +15,129 @@ static const char* TAG = "POSTPROC"; -std::string ClassFlowPostProcessing::getNumbersName() -{ +std::string ClassFlowPostProcessing::getNumbersName() { std::string ret=""; - for (int i = 0; i < NUMBERS.size(); ++i) - { + for (int i = 0; i < NUMBERS.size(); ++i) { ret += NUMBERS[i]->name; - if (i < NUMBERS.size()-1) + + if (i < NUMBERS.size()-1) { ret = ret + "\t"; + } } -// ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str()); + // ESP_LOGI(TAG, "Result ClassFlowPostProcessing::getNumbersName: %s", ret.c_str()); return ret; } -std::string ClassFlowPostProcessing::GetJSON(std::string _lineend) -{ +std::string ClassFlowPostProcessing::GetJSON(std::string _lineend) { std::string json="{" + _lineend; - for (int i = 0; i < NUMBERS.size(); ++i) - { + for (int i = 0; i < NUMBERS.size(); ++i) { json += "\"" + NUMBERS[i]->name + "\":" + _lineend; - json += getJsonFromNumber(i, _lineend) + _lineend; - if ((i+1) < NUMBERS.size()) + if ((i+1) < NUMBERS.size()) { json += "," + _lineend; + } } + json += "}"; return json; } - string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _lineend) { - std::string json = ""; + std::string json = ""; - json += " {" + _lineend; + json += " {" + _lineend; - if (NUMBERS[i]->ReturnValue.length() > 0) - json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend; - else - json += " \"value\": \"\"," + _lineend; + if (NUMBERS[i]->ReturnValue.length() > 0) { + json += " \"value\": \"" + NUMBERS[i]->ReturnValue + "\"," + _lineend; + } + else { + json += " \"value\": \"\"," + _lineend; + } - json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend; - json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend; - json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend; + json += " \"raw\": \"" + NUMBERS[i]->ReturnRawValue + "\"," + _lineend; + json += " \"pre\": \"" + NUMBERS[i]->ReturnPreValue + "\"," + _lineend; + json += " \"error\": \"" + NUMBERS[i]->ErrorMessageText + "\"," + _lineend; - if (NUMBERS[i]->ReturnRateValue.length() > 0) - json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend; - else - json += " \"rate\": \"\"," + _lineend; + if (NUMBERS[i]->ReturnRateValue.length() > 0) { + json += " \"rate\": \"" + NUMBERS[i]->ReturnRateValue + "\"," + _lineend; + } + else { + json += " \"rate\": \"\"," + _lineend; + } - json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend; - json += " }" + _lineend; + json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend; + json += " }" + _lineend; - return json; + return json; } - -string ClassFlowPostProcessing::GetPreValue(std::string _number) -{ +string ClassFlowPostProcessing::GetPreValue(std::string _number) { std::string result; int index = -1; - if (_number == "") - _number = "default"; + if (_number == "") { + _number = "default"; + } - for (int i = 0; i < NUMBERS.size(); ++i) - if (NUMBERS[i]->name == _number) + for (int i = 0; i < NUMBERS.size(); ++i) { + if (NUMBERS[i]->name == _number) { index = i; + } + } - if (index == -1) + if (index == -1) { return std::string(""); + } result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma); return result; } - -bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern) -{ +bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, bool _extern) { //ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str()); for (int j = 0; j < NUMBERS.size(); ++j) { //ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str()); + if (NUMBERS[j]->name == _numbers) { - if (_newvalue >= 0) { // if new value posivive, use provided value to preset PreValue + if (_newvalue >= 0) { + // if new value posivive, use provided value to preset PreValue NUMBERS[j]->PreValue = _newvalue; } - else { // if new value negative, use last raw value to preset PreValue + else { + // if new value negative, use last raw value to preset PreValue char* p; double ReturnRawValueAsDouble = strtod(NUMBERS[j]->ReturnRawValue.c_str(), &p); + if (ReturnRawValueAsDouble == 0) { - LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: " - + NUMBERS[j]->ReturnRawValue); + LogFile.WriteToFile(ESP_LOG_WARN, TAG, "SetPreValue: RawValue not a valid value for further processing: " + NUMBERS[j]->ReturnRawValue); return false; } + NUMBERS[j]->PreValue = ReturnRawValueAsDouble; } NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue); NUMBERS[j]->PreValueOkay = true; - if (_extern) - { + if (_extern) { time(&(NUMBERS[j]->lastvalue)); localtime(&(NUMBERS[j]->lastvalue)); } + //ESP_LOGD(TAG, "Found %d! - set to %.8f", j, NUMBERS[j]->PreValue); UpdatePreValueINI = true; // Only update prevalue file if a new value is set SavePreValue(); - LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " + - std::to_string(NUMBERS[j]->PreValue)); + LogFile.WriteToFile(ESP_LOG_INFO, TAG, "SetPreValue: PreValue for " + NUMBERS[j]->name + " set to " + std::to_string(NUMBERS[j]->PreValue)); return true; } } @@ -141,9 +146,7 @@ bool ClassFlowPostProcessing::SetPreValue(double _newvalue, string _numbers, boo return false; // No new value was set (e.g. wrong numbersname, no numbers at all) } - -bool ClassFlowPostProcessing::LoadPreValue(void) -{ +bool ClassFlowPostProcessing::LoadPreValue(void) { std::vector splitted; FILE* pFile; char zw[1024]; @@ -152,30 +155,31 @@ bool ClassFlowPostProcessing::LoadPreValue(void) UpdatePreValueINI = false; // Conversion to the new format - pFile = fopen(FilePreValue.c_str(), "r"); - if (pFile == NULL) + + if (pFile == NULL) { return false; + } fgets(zw, 1024, pFile); ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); zwtime = trim(std::string(zw)); - if (zwtime.length() == 0) + + if (zwtime.length() == 0) { return false; + } splitted = HelperZerlegeZeile(zwtime, "\t"); - if (splitted.size() > 1) // Conversion to the new format - { - while ((splitted.size() > 1) && !_done) - { + + // Conversion to the new format + if (splitted.size() > 1) { + while ((splitted.size() > 1) && !_done) { name = trim(splitted[0]); zwtime = trim(splitted[1]); zwvalue = trim(splitted[2]); - for (int j = 0; j < NUMBERS.size(); ++j) - { - if (NUMBERS[j]->name == name) - { + for (int j = 0; j < NUMBERS.size(); ++j) { + 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). @@ -198,21 +202,24 @@ bool ClassFlowPostProcessing::LoadPreValue(void) localtime(&tStart); double difference = difftime(tStart, NUMBERS[j]->lastvalue); difference /= 60; - if (difference > PreValueAgeStartup) + + if (difference > PreValueAgeStartup) { NUMBERS[j]->PreValueOkay = false; - else + } + else { NUMBERS[j]->PreValueOkay = true; + } } } - if (!fgets(zw, 1024, pFile)) + if (!fgets(zw, 1024, pFile)) { _done = true; - else - { + } + else { ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); splitted = HelperZerlegeZeile(trim(std::string(zw)), "\t"); - if (splitted.size() > 1) - { + + if (splitted.size() > 1) { name = trim(splitted[0]); zwtime = trim(splitted[1]); zwvalue = trim(splitted[2]); @@ -221,8 +228,8 @@ bool ClassFlowPostProcessing::LoadPreValue(void) } fclose(pFile); } - else // Old Format - { + else { + // Old Format fgets(zw, 1024, pFile); fclose(pFile); ESP_LOGD(TAG, "%s", zw); @@ -250,14 +257,15 @@ bool ClassFlowPostProcessing::LoadPreValue(void) localtime(&tStart); double difference = difftime(tStart, NUMBERS[0]->lastvalue); difference /= 60; - if (difference > PreValueAgeStartup) + + if (difference > PreValueAgeStartup) { return false; + } NUMBERS[0]->Value = NUMBERS[0]->PreValue; NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value); - if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi) - { + if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi) { NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->Nachkomma); } @@ -268,27 +276,28 @@ bool ClassFlowPostProcessing::LoadPreValue(void) return true; } -void ClassFlowPostProcessing::SavePreValue() -{ +void ClassFlowPostProcessing::SavePreValue() { FILE* pFile; string _zw; - if (!UpdatePreValueINI) // PreValues unchanged --> File does not have to be rewritten + // PreValues unchanged --> File does not have to be rewritten + if (!UpdatePreValueINI) { return; + } pFile = fopen(FilePreValue.c_str(), "w"); - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { char buffer[80]; struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue); strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); NUMBERS[j]->timeStamp = std::string(buffer); NUMBERS[j]->timeStampTimeUTC = NUMBERS[j]->lastvalue; -// ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); + // 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"; ESP_LOGD(TAG, "Write PreValue line: %s", _zw.c_str()); + if (pFile) { fputs(_zw.c_str(), pFile); } @@ -299,9 +308,7 @@ void ClassFlowPostProcessing::SavePreValue() fclose(pFile); } - -ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) -{ +ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) { PreValueUse = false; PreValueAgeStartup = 30; ErrorMessage = false; @@ -314,76 +321,57 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc, C flowAnalog = _analog; flowDigit = _digit; - for (int i = 0; i < ListFlowControll->size(); ++i) - { - if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) - { + for (int i = 0; i < ListFlowControll->size(); ++i) { + if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0) { flowTakeImage = (ClassFlowTakeImage*) (*ListFlowControll)[i]; } } } -void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) - _digit = _decsep.substr(0, _pospunkt); - else - _digit = "default"; + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - for (int j = 0; j < NUMBERS.size(); ++j) - { + if (_pospunkt > -1) { + _digit = _decsep.substr(0, _pospunkt); + } + else { + _digit = "default"; + } + + for (int j = 0; j < NUMBERS.size(); ++j) { bool _zwdc = false; - if (toUpper(_value) == "TRUE") + if (toUpper(_value) == "TRUE") { _zwdc = true; - - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->isExtendedResolution = _zwdc; } - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->isExtendedResolution = _zwdc; } } } - -void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { int _zwdc = 0; + _zwdc = stoi(_value); -// try - { - _zwdc = stoi(_value); - } -/* catch(const std::exception& e) - { - ESP_LOGD(TAG, "ERROR - Decimalshift is not a number: %s", _value.c_str()); - } -*/ - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->DecimalShift = _zwdc; - NUMBERS[j]->DecimalShiftInitial = _zwdc; - } - - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->DecimalShift = _zwdc; NUMBERS[j]->DecimalShiftInitial = _zwdc; } @@ -392,209 +380,180 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } } -void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { float _zwdc = 9.2; - { - _zwdc = stof(_value); - } - if (_digit == "default" || NUMBERS[j]->name == _digit) // Set to default first (if nothing else is set) - { + _zwdc = stof(_value); + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc; } } } -void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleAllowNegativeRate(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { bool _rt = false; - if (toUpper(_value) == "TRUE") + if (toUpper(_value) == "TRUE") { _rt = true; - - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->AllowNegativeRates = _rt; } - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->AllowNegativeRates = _rt; } } } - - -void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; + } - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { t_RateType _rt = AbsoluteChange; - if (toUpper(_value) == "RATECHANGE") + if (toUpper(_value) == "RATECHANGE") { _rt = RateChange; - - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->RateType = _rt; } - if (NUMBERS[j]->name == _digit) - { + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->RateType = _rt; } } } - - - -void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) -{ +void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); - if (_pospunkt > -1) + // ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); + + if (_pospunkt > -1) { _digit = _decsep.substr(0, _pospunkt); - else + } + else { _digit = "default"; - for (int j = 0; j < NUMBERS.size(); ++j) - { + } + + for (int j = 0; j < NUMBERS.size(); ++j) { float _zwdc = 1; -// try - { - _zwdc = stof(_value); - } -/* catch(const std::exception& e) - { - ESP_LOGD(TAG, "ERROR - MaxRateValue is not a number: %s", _value.c_str()); - } -*/ - if (_digit == "default") // Set to default first (if nothing else is set) - { - NUMBERS[j]->useMaxRateValue = true; - NUMBERS[j]->MaxRateValue = _zwdc; - } - if (NUMBERS[j]->name == _digit) - { + _zwdc = stof(_value); + + // Set to default first (if nothing else is set) + if ((_digit == "default") || (NUMBERS[j]->name == _digit)) { NUMBERS[j]->useMaxRateValue = true; NUMBERS[j]->MaxRateValue = _zwdc; } } } - -bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) -{ +bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { std::vector splitted; int _n; aktparamgraph = trim(aktparamgraph); - if (aktparamgraph.size() == 0) - if (!this->GetNextParagraph(pfile, aktparamgraph)) + if (aktparamgraph.size() == 0) { + if (!this->GetNextParagraph(pfile, aktparamgraph)) { return false; + } + } - - if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph does not fit PostProcessing + // Paragraph does not fit PostProcessing + if (aktparamgraph.compare("[PostProcessing]") != 0) { return false; + } InitNUMBERS(); - - while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) - { + while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { splitted = ZerlegeZeile(aktparamgraph); std::string _param = GetParameterName(splitted[0]); - if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1)) - { + if ((toUpper(_param) == "EXTENDEDRESOLUTION") && (splitted.size() > 1)) { handleDecimalExtendedResolution(splitted[0], splitted[1]); } - if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1)) - { + if ((toUpper(_param) == "DECIMALSHIFT") && (splitted.size() > 1)) { handleDecimalSeparator(splitted[0], splitted[1]); } - if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (splitted.size() > 1)) - { + + if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (splitted.size() > 1)) { handleAnalogDigitalTransitionStart(splitted[0], splitted[1]); } - if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1)) - { + + if ((toUpper(_param) == "MAXRATEVALUE") && (splitted.size() > 1)) { handleMaxRateValue(splitted[0], splitted[1]); } - if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1)) - { + + if ((toUpper(_param) == "MAXRATETYPE") && (splitted.size() > 1)) { handleMaxRateType(splitted[0], splitted[1]); } - - if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - { + + if ((toUpper(_param) == "PREVALUEUSE") && (splitted.size() > 1)) { + if (toUpper(splitted[1]) == "TRUE") { PreValueUse = true; } } - if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") - for (_n = 0; _n < NUMBERS.size(); ++_n) + + if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (splitted.size() > 1)) { + if (toUpper(splitted[1]) == "TRUE") { + for (_n = 0; _n < NUMBERS.size(); ++_n) { NUMBERS[_n]->checkDigitIncreaseConsistency = true; - } - if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) - { + } + } + } + + if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (splitted.size() > 1)) { handleAllowNegativeRate(splitted[0], splitted[1]); -/* Updated to allow individual Settings - if (toUpper(splitted[1]) == "TRUE") - for (_n = 0; _n < NUMBERS.size(); ++_n) - NUMBERS[_n]->AllowNegativeRates = true; -*/ } - if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") + + if ((toUpper(_param) == "ERRORMESSAGE") && (splitted.size() > 1)) { + if (toUpper(splitted[1]) == "TRUE") { ErrorMessage = true; + } } - if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) - { - if (toUpper(splitted[1]) == "TRUE") + + if ((toUpper(_param) == "IGNORELEADINGNAN") && (splitted.size() > 1)) { + if (toUpper(splitted[1]) == "TRUE") { IgnoreLeadingNaN = true; + } } - - if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) - { + if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (splitted.size() > 1)) { PreValueAgeStartup = std::stoi(splitted[1]); } } @@ -606,49 +565,53 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) return true; } -void ClassFlowPostProcessing::InitNUMBERS() -{ +void ClassFlowPostProcessing::InitNUMBERS() { int anzDIGIT = 0; int anzANALOG = 0; std::vector name_numbers; - if (flowDigit) - { + if (flowDigit) { anzDIGIT = flowDigit->getNumberGENERAL(); flowDigit->UpdateNameNumbers(&name_numbers); } - if (flowAnalog) - { + + if (flowAnalog) { anzANALOG = flowAnalog->getNumberGENERAL(); flowAnalog->UpdateNameNumbers(&name_numbers); } ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG); - for (int _num = 0; _num < name_numbers.size(); ++_num) - { + for (int _num = 0; _num < name_numbers.size(); ++_num) { NumberPost *_number = new NumberPost; _number->name = name_numbers[_num]; _number->digit_roi = NULL; - if (flowDigit) + + if (flowDigit) { _number->digit_roi = flowDigit->FindGENERAL(name_numbers[_num]); + } - if (_number->digit_roi) + if (_number->digit_roi) { _number->AnzahlDigital = _number->digit_roi->ROI.size(); - else + } + else { _number->AnzahlDigital = 0; + } _number->analog_roi = NULL; - if (flowAnalog) + + if (flowAnalog) { _number->analog_roi = flowAnalog->FindGENERAL(name_numbers[_num]); + } - - if (_number->analog_roi) + if (_number->analog_roi) { _number->AnzahlAnalog = _number->analog_roi->ROI.size(); - else + } + else { _number->AnzahlAnalog = 0; + } _number->ReturnRawValue = ""; // Raw value (with N & leading 0). _number->ReturnValue = ""; // corrected return value, possibly with error message @@ -665,7 +628,6 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->isExtendedResolution = false; _number->AnalogDigitalTransitionStart=9.2; - _number->FlowRateAct = 0; // m3 / min _number->PreValue = 0; // last value read out well _number->Value = 0; // last value read out, incl. corrections @@ -681,38 +643,39 @@ void ClassFlowPostProcessing::InitNUMBERS() 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]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog); } - } -string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ - - if (_decShift == 0){ +string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) { + if (_decShift == 0) { return in; } int _pos_dec_org, _pos_dec_neu; _pos_dec_org = findDelimiterPos(in, "."); + if (_pos_dec_org == std::string::npos) { _pos_dec_org = in.length(); } - else - { + else { in = in.erase(_pos_dec_org, 1); } _pos_dec_neu = _pos_dec_org + _decShift; - if (_pos_dec_neu <= 0) { // comma is before the first digit - for (int i = 0; i > _pos_dec_neu; --i){ + // comma is before the first digit + if (_pos_dec_neu <= 0) { + for (int i = 0; i > _pos_dec_neu; --i) { in = in.insert(0, "0"); } + in = "0." + in; return in; } - if (_pos_dec_neu > in.length()){ // Comma should be after string (123 --> 1230) - for (int i = in.length(); i < _pos_dec_neu; ++i){ + // Comma should be after string (123 --> 1230) + if (_pos_dec_neu > in.length()) { + for (int i = in.length(); i < _pos_dec_neu; ++i) { in = in.insert(in.length(), "0"); } return in; @@ -726,8 +689,7 @@ string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ return zw; } -bool ClassFlowPostProcessing::doFlow(string zwtime) -{ +bool ClassFlowPostProcessing::doFlow(string zwtime) { string result = ""; string digit = ""; string analog = ""; @@ -739,8 +701,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) // Update decimal point, as the decimal places can also change when changing from CNNType Auto --> xyz: imagetime = flowTakeImage->getTimeImageTaken(); - if (imagetime == 0) + + if (imagetime == 0) { time(&imagetime); + } struct tm* timeinfo; timeinfo = localtime(&imagetime); @@ -750,8 +714,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) ESP_LOGD(TAG, "Quantity NUMBERS: %d", NUMBERS.size()); - for (int j = 0; j < NUMBERS.size(); ++j) - { + for (int j = 0; j < NUMBERS.size(); ++j) { NUMBERS[j]->ReturnRawValue = ""; NUMBERS[j]->ReturnRateValue = ""; NUMBERS[j]->ReturnValue = ""; @@ -759,66 +722,73 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) NUMBERS[j]->ErrorMessageText = ""; NUMBERS[j]->Value = -1; - /* calculate time difference BEFORE we overwrite the 'lastvalue' */ + // calculate time difference BEFORE we overwrite the 'lastvalue' double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in seconds - /* TODO: - * We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down. - * But we should check nothing breaks! */ + // TODO: + // We could call `NUMBERS[j]->lastvalue = imagetime;` here and remove all other such calls further down. + // But we should check nothing breaks! UpdateNachkommaDecimalShift(); int previous_value = -1; - if (NUMBERS[j]->analog_roi) - { - NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution); - if (NUMBERS[j]->ReturnRawValue.length() > 0) - { + if (NUMBERS[j]->analog_roi) { + NUMBERS[j]->ReturnRawValue = flowAnalog->getReadout(j, NUMBERS[j]->isExtendedResolution); + + if (NUMBERS[j]->ReturnRawValue.length() > 0) { char zw = NUMBERS[j]->ReturnRawValue[0]; - if (zw >= 48 && zw <=57) + + if (zw >= 48 && zw <=57) { previous_value = zw - 48; + } } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif - if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue; - if (NUMBERS[j]->digit_roi) - { - if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; - else - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits + if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { + NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue; } + + if (NUMBERS[j]->digit_roi) { + if (NUMBERS[j]->analog_roi) { + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; + } + else { + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution only if there are no analogue digits + } + } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift); #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif - if (IgnoreLeadingNaN) - while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) + if (IgnoreLeadingNaN) { + while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N')) { NUMBERS[j]->ReturnRawValue.erase(0, 1); + } + } #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue; - if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos) - { - if (PreValueUse && NUMBERS[j]->PreValueOkay) - { + if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos) { + if (PreValueUse && NUMBERS[j]->PreValueOkay) { NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue); } - else - { + else { string _zw = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText; LogFile.WriteToFile(ESP_LOG_INFO, TAG, _zw); /* TODO to be discussed, see https://github.com/jomjol/AI-on-the-edge-device/issues/1617 */ @@ -828,31 +798,36 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) continue; // there is no number because there is still an N. } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + // Delete leading zeros (unless there is only one 0 left) - while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) + while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) { NUMBERS[j]->ReturnValue.erase(0, 1); + } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif + NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue); + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue)); #endif - if (NUMBERS[j]->checkDigitIncreaseConsistency) - { - if (flowDigit) - { - if (flowDigit->getCNNType() != Digital) + if (NUMBERS[j]->checkDigitIncreaseConsistency) { + if (flowDigit) { + if (flowDigit->getCNNType() != Digital) { ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)"); - else + } + else { NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue); + } } - else - { + else { #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!"); #endif @@ -863,11 +838,10 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value); #endif - if (!NUMBERS[j]->AllowNegativeRates) - { + if (!NUMBERS[j]->AllowNegativeRates) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handleAllowNegativeRate for device: " + NUMBERS[j]->name); - if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) - { + + if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) { // more debug if extended resolution is on, see #2447 if (NUMBERS[j]->isExtendedResolution) { LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Neg: value=" + std::to_string(NUMBERS[j]->Value) @@ -875,7 +849,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) + ", preToll=" + std::to_string(NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma)))); } - // Include inaccuracy of 0.2 for isExtendedResolution. + // Include inaccuracy of 0.2 for isExtendedResolution. if ((NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma))) && NUMBERS[j]->isExtendedResolution) // not extended resolution allows -1 on the lowest digit || (NUMBERS[j]->Value >= (NUMBERS[j]->PreValue-(1/pow(10, NUMBERS[j]->Nachkomma))) && !NUMBERS[j]->isExtendedResolution)) { @@ -893,7 +867,6 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) WriteDataLog(j); continue; } - } } @@ -905,16 +878,17 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference; NUMBERS[j]->ReturnRateValue = to_string(NUMBERS[j]->FlowRateAct); - if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay) - { - double _ratedifference; - if (NUMBERS[j]->RateType == RateChange) + if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay) { + double _ratedifference; + + if (NUMBERS[j]->RateType == RateChange) { _ratedifference = NUMBERS[j]->FlowRateAct; - else + } + else { _ratedifference = (NUMBERS[j]->Value - NUMBERS[j]->PreValue); + } - if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue)) - { + if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue)) { NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + RundeOutput(_ratedifference, NUMBERS[j]->Nachkomma); NUMBERS[j]->Value = NUMBERS[j]->PreValue; NUMBERS[j]->ReturnValue = ""; @@ -952,9 +926,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) return true; } -void ClassFlowPostProcessing::WriteDataLog(int _index) -{ - if (!LogFile.GetDataLogToSD()){ +void ClassFlowPostProcessing::WriteDataLog(int _index) { + if (!LogFile.GetDataLogToSD()) { return; } @@ -966,10 +939,14 @@ void ClassFlowPostProcessing::WriteDataLog(int _index) strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); timezw = std::string(buffer); - if (flowAnalog) + if (flowAnalog) { analog = flowAnalog->getReadoutRawString(_index); - if (flowDigit) + } + + if (flowDigit) { digital = flowDigit->getReadoutRawString(_index); + } + LogFile.WriteToData(timezw, NUMBERS[_index]->name, NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue, NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, @@ -978,78 +955,78 @@ void ClassFlowPostProcessing::WriteDataLog(int _index) ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str()); } - -void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() -{ - for (int j = 0; j < NUMBERS.size(); ++j) - { - if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // There are only digital digits - { -// ESP_LOGD(TAG, "Nurdigital"); +void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() { + for (int j = 0; j < NUMBERS.size(); ++j) { + // There are only digital digits + if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nurdigital"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; - if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // Extended resolution is on and should also be used for this digit. + // Extended resolution is on and should also be used for this digit. + if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1; + } NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift; } - if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) - { -// ESP_LOGD(TAG, "Nur analog"); + if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nur analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) + + if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1; + } NUMBERS[j]->Nachkomma = -NUMBERS[j]->DecimalShift; } - if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog - { -// ESP_LOGD(TAG, "Nur digital + analog"); + // digital + analog + if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) { + // ESP_LOGD(TAG, "Nur digital + analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift; - if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // Extended resolution is on and should also be used for this digit. + // Extended resolution is on and should also be used for this digit. + if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) { NUMBERS[j]->Nachkomma = NUMBERS[j]->Nachkomma+1; - + } } ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift); } } - -string ClassFlowPostProcessing::getReadout(int _number) -{ +string ClassFlowPostProcessing::getReadout(int _number) { return NUMBERS[_number]->ReturnValue; } -string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number) -{ - if (_rawValue) +string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number) { + if (_rawValue) { return NUMBERS[_number]->ReturnRawValue; - if (_noerror) + } + + if (_noerror) { return NUMBERS[_number]->ReturnValue; + } + return NUMBERS[_number]->ReturnValue; } - -string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) -{ +string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) { int posN, posPunkt; int pot, ziffer; float zw; posN = findDelimiterPos(input, "N"); posPunkt = findDelimiterPos(input, "."); - if (posPunkt == std::string::npos){ + + if (posPunkt == std::string::npos) { posPunkt = input.length(); } - while (posN != std::string::npos) - { + while (posN != std::string::npos) { if (posN < posPunkt) { pot = posPunkt - posN - 1; } @@ -1067,7 +1044,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) return input; } -float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){ +float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue) { int aktdigit, olddigit; int aktdigit_before, olddigit_before; int pot, pot_max; @@ -1075,16 +1052,19 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams bool no_nulldurchgang = false; pot = _decilamshift; - if (!_isanalog) // if there are no analogue values, the last one cannot be evaluated - { + + // if there are no analogue values, the last one cannot be evaluated + if (!_isanalog) { pot++; } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift); #endif + pot_max = ((int) log10(input)) + 1; - while (pot <= pot_max) - { + + while (pot <= pot_max) { zw = input / pow(10, pot-1); aktdigit_before = ((int) zw) % 10; zw = _preValue / pow(10, pot-1); @@ -1097,43 +1077,36 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams no_nulldurchgang = (olddigit_before <= aktdigit_before); - if (no_nulldurchgang) - { - if (aktdigit != olddigit) - { + if (no_nulldurchgang) { + if (aktdigit != olddigit) { input = input + ((float) (olddigit - aktdigit)) * pow(10, pot); // New Digit is replaced by old Digit; } } - else - { - if (aktdigit == olddigit) // despite zero crossing, digit was not incremented --> add 1 - { + else { + // despite zero crossing, digit was not incremented --> add 1 + if (aktdigit == olddigit) { input = input + ((float) (1)) * pow(10, pot); // add 1 at the point } } + #ifdef SERIAL_DEBUG ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input); #endif + pot++; } return input; } -string ClassFlowPostProcessing::getReadoutRate(int _number) -{ +string ClassFlowPostProcessing::getReadoutRate(int _number) { return std::to_string(NUMBERS[_number]->FlowRateAct); } -string ClassFlowPostProcessing::getReadoutTimeStamp(int _number) -{ +string ClassFlowPostProcessing::getReadoutTimeStamp(int _number) { return NUMBERS[_number]->timeStamp; } - -string ClassFlowPostProcessing::getReadoutError(int _number) -{ +string ClassFlowPostProcessing::getReadoutError(int _number) { return NUMBERS[_number]->ErrorMessageText; } - -