Merge pull request #4031 from SybexX/test_mh

Test mh
This commit is contained in:
SybexXx
2026-01-18 05:53:11 +01:00
committed by GitHub
17 changed files with 185 additions and 160 deletions

View File

@@ -71,7 +71,7 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol
if (CNNType == Analogue || CNNType == Analogue100)
{
float number = GENERAL[_number]->ROI[GENERAL[_number]->ROI.size() - 1]->result_float;
int result_after_decimal_point = ((int)floor(number * 10) + 10) % 10;
int result_after_decimal_point = ((int)floor(number * 10.0f) + 10) % 10;
prev = PointerEvalAnalog(GENERAL[_number]->ROI[GENERAL[_number]->ROI.size() - 1]->result_float, prev);
result = std::to_string(prev);
@@ -114,7 +114,7 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol
// is only set if it is the first digit (no analogue before!)
if (_extendedResolution)
{
int result_after_decimal_point = ((int)floor(number * 10)) % 10;
int result_after_decimal_point = ((int)floor(number * 10.0f)) % 10;
int result_before_decimal_point = ((int)floor(number)) % 10;
result = std::to_string(result_before_decimal_point) + std::to_string(result_after_decimal_point);
@@ -193,7 +193,7 @@ std::string ClassFlowCNNGeneral::getReadout(int _number = 0, bool _extendedResol
int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predecessors, int eval_predecessors, bool Analog_Predecessors, float digitAnalogTransitionStart)
{
int result = -1;
int result_after_decimal_point = ((int)floor(number * 10)) % 10;
int result_after_decimal_point = ((int)floor(number * 10.0f)) % 10;
int result_before_decimal_point = ((int)floor(number) + 10) % 10;
if (eval_predecessors < 0)
@@ -203,8 +203,7 @@ int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predece
// add precisition of 2 digits and round before trunc
// a number greater than 9.994999 is returned as 10, this leads to an error during the decimal shift because the NUMBERS[j]->ReturnRawValue is one digit longer.
// To avoid this, an additional test must be carried out, see "if ((CNNType == DoubleHyprid10) || (CNNType == Digit100))" check in getReadout()
// Another alternative would be "result = (int) ((int) trunc(round((number+10 % 10)*1000))) / 1000;", which could, however, lead to other errors?
result = (int)((int)trunc(round((number + 10 % 10) * 100))) / 100;
result = (int) (trunc(round((float)((int)(number + 10.0f) % 10) * 100.0f)) / 100.0f);
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalHybrid - No predecessor - Result = " + std::to_string(result) + " number: " + std::to_string(number) + " number_of_predecessors = " + std::to_string(number_of_predecessors) + " eval_predecessors = " + std::to_string(eval_predecessors) + " Digit_Uncertainty = " + std::to_string(Digit_Uncertainty));
return result;
@@ -277,14 +276,14 @@ int ClassFlowCNNGeneral::PointerEvalHybrid(float number, float number_of_predece
int ClassFlowCNNGeneral::PointerEvalAnalogToDigit(float number, float numeral_preceder, int eval_predecessors, float AnalogToDigitTransitionStart)
{
int result = -1;
int result_after_decimal_point = ((int)floor(number * 10)) % 10;
int result_after_decimal_point = ((int)floor(number * 10.0f)) % 10;
int result_before_decimal_point = ((int)floor(number) + 10) % 10;
bool roundedUp = false;
// Within the digit inequalities
// Band around the digit --> Round off, as digit reaches inaccuracy in the frame
if ((result_after_decimal_point >= (10 - Digit_Uncertainty * 10)) || (eval_predecessors <= 4 && result_after_decimal_point >= 6))
{
if ((result_after_decimal_point >= (10 - (int)(Digit_Uncertainty * 10.0f))) || (eval_predecessors <= 4 && result_after_decimal_point >= 6))
{
// or digit runs after (analogue =0..4, digit >=6)
result = (int)(round(number) + 10) % 10;
roundedUp = true;
@@ -322,8 +321,8 @@ int ClassFlowCNNGeneral::PointerEvalAnalog(float number, int numeral_preceder)
return result;
}
float number_min = number - Analog_error / 10.0;
float number_max = number + Analog_error / 10.0;
float number_min = number - (float)Analog_error / 10.0f;
float number_max = number + (float)Analog_error / 10.0f;
if ((int)floor(number_max) - (int)floor(number_min) != 0)
{
@@ -333,7 +332,7 @@ int ClassFlowCNNGeneral::PointerEvalAnalog(float number, int numeral_preceder)
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalog - number ambiguous, correction upwards - result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder) + " Analog_error = " + std::to_string(Analog_error));
return result;
}
if (numeral_preceder >= 10 - Analog_error)
if (numeral_preceder >= (10 - Analog_error))
{
result = ((int)floor(number_min) + 10) % 10;
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "PointerEvalAnalog - number ambiguous, downward correction - result = " + std::to_string(result) + " number: " + std::to_string(number) + " numeral_preceder = " + std::to_string(numeral_preceder) + " Analog_error = " + std::to_string(Analog_error));
@@ -369,7 +368,8 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE *pfile, std::string &aktparamgraph)
if (aktparamgraph[0] == ';')
{
disabled = true;
while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph));
while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph))
;
ESP_LOGD(TAG, "[Analog/Digit] is disabled!");
return true;
@@ -581,35 +581,35 @@ bool ClassFlowCNNGeneral::doAlignAndCut(std::string time_value)
CAlignAndCutImage *caic = flowpostalignment->GetAlignAndCutImage();
for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
for (int _number = 0; _number < GENERAL.size(); ++_number)
{
for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi)
{
ESP_LOGD(TAG, "General %d - Align&Cut", i);
ESP_LOGD(TAG, "General %d - Align&Cut", _roi);
caic->CutAndSave(GENERAL[_ana]->ROI[i]->pos_x, GENERAL[_ana]->ROI[i]->pos_y, GENERAL[_ana]->ROI[i]->delta_x, GENERAL[_ana]->ROI[i]->delta_y, GENERAL[_ana]->ROI[i]->image_org);
caic->CutAndSave(GENERAL[_number]->ROI[_roi]->pos_x, GENERAL[_number]->ROI[_roi]->pos_y, GENERAL[_number]->ROI[_roi]->delta_x, GENERAL[_number]->ROI[_roi]->delta_y, GENERAL[_number]->ROI[_roi]->image_org);
if (Camera.SaveAllFiles)
{
if (GENERAL[_ana]->name == "default")
if (GENERAL[_number]->name == "default")
{
GENERAL[_ana]->ROI[i]->image_org->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image_org->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
else
{
GENERAL[_ana]->ROI[i]->image_org->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image_org->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
}
GENERAL[_ana]->ROI[i]->image_org->Resize(model_x_size, model_y_size, GENERAL[_ana]->ROI[i]->image);
GENERAL[_number]->ROI[_roi]->image_org->Resize(model_x_size, model_y_size, GENERAL[_number]->ROI[_roi]->image);
if (Camera.SaveAllFiles)
{
if (GENERAL[_ana]->name == "default")
if (GENERAL[_number]->name == "default")
{
GENERAL[_ana]->ROI[i]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
else
{
GENERAL[_ana]->ROI[i]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
}
}
@@ -630,12 +630,12 @@ void ClassFlowCNNGeneral::DrawROI(CImageBasis *Image)
for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
{
for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
for (int _roi = 0; _roi < GENERAL[_ana]->ROI.size(); ++_roi)
{
Image->drawRect(GENERAL[_ana]->ROI[i]->pos_x, GENERAL[_ana]->ROI[i]->pos_y, GENERAL[_ana]->ROI[i]->delta_x, GENERAL[_ana]->ROI[i]->delta_y, r, g, b, 1);
Image->drawEllipse((int)(GENERAL[_ana]->ROI[i]->pos_x + GENERAL[_ana]->ROI[i]->delta_x / 2), (int)(GENERAL[_ana]->ROI[i]->pos_y + GENERAL[_ana]->ROI[i]->delta_y / 2), (int)(GENERAL[_ana]->ROI[i]->delta_x / 2), (int)(GENERAL[_ana]->ROI[i]->delta_y / 2), r, g, b, 2);
Image->drawLine((int)(GENERAL[_ana]->ROI[i]->pos_x + GENERAL[_ana]->ROI[i]->delta_x / 2), (int)GENERAL[_ana]->ROI[i]->pos_y, (int)(GENERAL[_ana]->ROI[i]->pos_x + GENERAL[_ana]->ROI[i]->delta_x / 2), (int)(GENERAL[_ana]->ROI[i]->pos_y + GENERAL[_ana]->ROI[i]->delta_y), r, g, b, 2);
Image->drawLine((int)GENERAL[_ana]->ROI[i]->pos_x, (int)(GENERAL[_ana]->ROI[i]->pos_y + GENERAL[_ana]->ROI[i]->delta_y / 2), (int)GENERAL[_ana]->ROI[i]->pos_x + GENERAL[_ana]->ROI[i]->delta_x, (int)(GENERAL[_ana]->ROI[i]->pos_y + GENERAL[_ana]->ROI[i]->delta_y / 2), r, g, b, 2);
Image->drawRect(GENERAL[_ana]->ROI[_roi]->pos_x, GENERAL[_ana]->ROI[_roi]->pos_y, GENERAL[_ana]->ROI[_roi]->delta_x, GENERAL[_ana]->ROI[_roi]->delta_y, r, g, b, 1);
Image->drawEllipse((int)(GENERAL[_ana]->ROI[_roi]->pos_x + GENERAL[_ana]->ROI[_roi]->delta_x / 2), (int)(GENERAL[_ana]->ROI[_roi]->pos_y + GENERAL[_ana]->ROI[_roi]->delta_y / 2), (int)(GENERAL[_ana]->ROI[_roi]->delta_x / 2), (int)(GENERAL[_ana]->ROI[_roi]->delta_y / 2), r, g, b, 2);
Image->drawLine((int)(GENERAL[_ana]->ROI[_roi]->pos_x + GENERAL[_ana]->ROI[_roi]->delta_x / 2), (int)GENERAL[_ana]->ROI[_roi]->pos_y, (int)(GENERAL[_ana]->ROI[_roi]->pos_x + GENERAL[_ana]->ROI[_roi]->delta_x / 2), (int)(GENERAL[_ana]->ROI[_roi]->pos_y + GENERAL[_ana]->ROI[_roi]->delta_y), r, g, b, 2);
Image->drawLine((int)GENERAL[_ana]->ROI[_roi]->pos_x, (int)(GENERAL[_ana]->ROI[_roi]->pos_y + GENERAL[_ana]->ROI[_roi]->delta_y / 2), (int)GENERAL[_ana]->ROI[_roi]->pos_x + GENERAL[_ana]->ROI[_roi]->delta_x, (int)(GENERAL[_ana]->ROI[_roi]->pos_y + GENERAL[_ana]->ROI[_roi]->delta_y / 2), r, g, b, 2);
}
}
}
@@ -643,9 +643,9 @@ void ClassFlowCNNGeneral::DrawROI(CImageBasis *Image)
{
for (int _dig = 0; _dig < GENERAL.size(); ++_dig)
{
for (int i = 0; i < GENERAL[_dig]->ROI.size(); ++i)
for (int _roi = 0; _roi < GENERAL[_dig]->ROI.size(); ++_roi)
{
Image->drawRect(GENERAL[_dig]->ROI[i]->pos_x, GENERAL[_dig]->ROI[i]->pos_y, GENERAL[_dig]->ROI[i]->delta_x, GENERAL[_dig]->ROI[i]->delta_y, 0, 0, (255 - _dig * 100), 2);
Image->drawRect(GENERAL[_dig]->ROI[_roi]->pos_x, GENERAL[_dig]->ROI[_roi]->pos_y, GENERAL[_dig]->ROI[_roi]->delta_x, GENERAL[_dig]->ROI[_roi]->delta_y, 0, 0, (255 - _dig * 100), 2);
}
}
}
@@ -779,7 +779,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value)
int start_roi = 0;
if ((numbers[j]->useMaxFlowRate) && (numbers[j]->PreValueOkay) && (numbers[j]->timeStampLastValue == numbers[j]->timeStampLastPreValue))
if ((numbers[j]->useMaxFlowRate) && (numbers[j]->PreValueValid) && (numbers[j]->timeStampLastValue == numbers[j]->timeStampLastPreValue))
{
int _AnzahlDigit = numbers[j]->AnzahlDigit;
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "doNeuralNetwork, _AnzahlDigit: " + std::to_string(_AnzahlDigit));
@@ -916,15 +916,15 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value)
float _value1 = tflite->GetOutputValue(0);
float _value2 = tflite->GetOutputValue(1);
float _result = fmod(atan2(_value1, _value2) / (M_PI * 2) + 2, 1);
float _result = fmod((atan2(_value1, _value2) / (M_PI * 2.0f) + 2.0f), 1.0f);
if (GENERAL[j]->ROI[i]->ccw)
{
_result = 10 - (_result * 10);
_result = 10.0f - (_result * 10.0f);
}
else
{
_result = _result * 10;
_result = _result * 10.0f;
}
if (i >= start_roi)
@@ -1092,11 +1092,11 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(std::string time_value)
if (GENERAL[j]->ROI[i]->ccw)
{
_result = 10 - ((float)_num / 10.0);
_result = 10.0f - ((float)_num / 10.0f);
}
else
{
_result = (float)_num / 10.0;
_result = (float)_num / 10.0f;
}
if (i >= start_roi)
@@ -1160,46 +1160,46 @@ std::vector<HTMLInfo *> ClassFlowCNNGeneral::GetHTMLInfo(void)
{
std::vector<HTMLInfo *> result;
for (int _ana = 0; _ana < GENERAL.size(); ++_ana)
for (int _number = 0; _number < GENERAL.size(); ++_number)
{
for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i)
for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi)
{
ESP_LOGD(TAG, "Image: %d", (int)GENERAL[_ana]->ROI[i]->image);
if (GENERAL[_ana]->ROI[i]->image)
ESP_LOGD(TAG, "Image: %d", (int)GENERAL[_number]->ROI[_roi]->image);
if (GENERAL[_number]->ROI[_roi]->image)
{
if (GENERAL[_ana]->name == "default")
if (GENERAL[_number]->name == "default")
{
GENERAL[_ana]->ROI[i]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
else
{
GENERAL[_ana]->ROI[i]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg"));
GENERAL[_number]->ROI[_roi]->image->SaveToFile(format_filename("/sdcard/img_tmp/" + GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name + ".jpg"));
}
}
HTMLInfo *temp_info = new HTMLInfo;
if (GENERAL[_ana]->name == "default")
if (GENERAL[_number]->name == "default")
{
temp_info->filename = GENERAL[_ana]->ROI[i]->name + ".jpg";
temp_info->filename_org = GENERAL[_ana]->ROI[i]->name + ".jpg";
temp_info->filename = GENERAL[_number]->ROI[_roi]->name + ".jpg";
temp_info->filename_org = GENERAL[_number]->ROI[_roi]->name + ".jpg";
}
else
{
temp_info->filename = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg";
temp_info->filename_org = GENERAL[_ana]->name + "_" + GENERAL[_ana]->ROI[i]->name + ".jpg";
temp_info->filename = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name + ".jpg";
temp_info->filename_org = GENERAL[_number]->name + "_" + GENERAL[_number]->ROI[_roi]->name + ".jpg";
}
if (CNNType == Digit)
{
temp_info->val = (float)GENERAL[_ana]->ROI[i]->raw_result_klasse;
temp_info->val = (float)GENERAL[_number]->ROI[_roi]->raw_result_klasse;
}
else
{
temp_info->val = GENERAL[_ana]->ROI[i]->raw_result_float;
temp_info->val = GENERAL[_number]->ROI[_roi]->raw_result_float;
}
temp_info->image = GENERAL[_ana]->ROI[i]->image;
temp_info->image_org = GENERAL[_ana]->ROI[i]->image_org;
temp_info->image = GENERAL[_number]->ROI[_roi]->image;
temp_info->image_org = GENERAL[_number]->ROI[_roi]->image_org;
result.push_back(temp_info);
}
@@ -1235,14 +1235,14 @@ general *ClassFlowCNNGeneral::GetGENERAL(int _number)
void ClassFlowCNNGeneral::UpdateNameNumbers(std::vector<std::string> *_name_numbers)
{
for (int _dig = 0; _dig < GENERAL.size(); _dig++)
for (int _number = 0; _number < GENERAL.size(); ++_number)
{
std::string _name = GENERAL[_dig]->name;
std::string _name = GENERAL[_number]->name;
bool found = false;
for (int i = 0; i < (*_name_numbers).size(); ++i)
for (int _roi = 0; _roi < (*_name_numbers).size(); ++_roi)
{
if ((*_name_numbers)[i] == _name)
if ((*_name_numbers)[_roi] == _name)
{
found = true;
}
@@ -1263,41 +1263,41 @@ std::string ClassFlowCNNGeneral::getReadoutRawString(int _number)
return temp_string;
}
for (int i = 0; i < GENERAL[_number]->ROI.size(); ++i)
for (int _roi = 0; _roi < GENERAL[_number]->ROI.size(); ++_roi)
{
if (CNNType == Analogue || CNNType == Analogue100)
{
if ((GENERAL[_number]->ROI[i]->raw_result_float < 0.0f) || (GENERAL[_number]->ROI[i]->raw_result_float >= 10.0f))
if ((GENERAL[_number]->ROI[_roi]->raw_result_float < 0.0f) || (GENERAL[_number]->ROI[_roi]->raw_result_float >= 10.0f))
{
temp_string = temp_string + ",N";
}
else
{
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[i]->raw_result_float, 1);
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[_roi]->raw_result_float, 1);
}
}
else if (CNNType == Digit)
{
if ((GENERAL[_number]->ROI[i]->raw_result_klasse < 0) || (GENERAL[_number]->ROI[i]->raw_result_klasse >= 10))
if ((GENERAL[_number]->ROI[_roi]->raw_result_klasse < 0) || (GENERAL[_number]->ROI[_roi]->raw_result_klasse >= 10))
{
temp_string = temp_string + ",N";
}
else
{
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[i]->raw_result_klasse, 0);
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[_roi]->raw_result_klasse, 0);
}
}
else if ((CNNType == DoubleHyprid10) || (CNNType == Digit100))
{
if ((GENERAL[_number]->ROI[i]->raw_result_float < 0.0f) || (GENERAL[_number]->ROI[i]->raw_result_float >= 10.0f))
if ((GENERAL[_number]->ROI[_roi]->raw_result_float < 0.0f) || (GENERAL[_number]->ROI[_roi]->raw_result_float >= 10.0f))
{
temp_string = temp_string + ",N";
}
else
{
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[i]->raw_result_float, 1);
temp_string = temp_string + "," + round_output(GENERAL[_number]->ROI[_roi]->raw_result_float, 1);
}
}
}

View File

@@ -454,7 +454,7 @@ std::string ClassFlowControll::getReadoutAll(int _type)
case READOUT_TYPE_PREVALUE:
if (flowpostprocessing->PreValueUse)
{
if ((*numbers)[i]->PreValueOkay)
if ((*numbers)[i]->PreValueValid)
{
out = out + (*numbers)[i]->ReturnPreValue;
}

View File

@@ -41,9 +41,8 @@ struct NumberPost
float MaxRateValue; // maxRate; upper bound for the difference between two consecutive readings; affected by maxRateType;
bool useMaxRateValue; // consistencyChecksEnabled; enables consistency checks; uses maxRate and maxRateType
t_RateType MaxRateType; // maxRateType; affects how the value of maxRate is used for comparing the current and previous value
bool ErrorMessage; // FIXME: not used; can be removed
int ChangeRateThreshold; // threshold parameter for negative rate detection
bool PreValueOkay; // previousValueValid; indicates that the reading of the previous round has no errors
bool PreValueValid; // previousValueValid; indicates that the reading of the previous round has no errors
bool AllowNegativeRates; // allowNegativeRate; defines if the consistency checks allow negative rates between consecutive meter readings.
bool IgnoreLeadingNaN; //
time_t timeStampLastValue; // Timestamp for the last read value; is used for the log
@@ -58,6 +57,7 @@ struct NumberPost
string ReturnRawValue; // rawValueStr; Raw value (with N & leading 0)
string ReturnValue; // valueStr; corrected return value, if necessary with error message
string ReturnPreValue; // lastValidValueStr; corrected return value without error message
bool ErrorMessage; //
string ErrorMessageText; // errorMessage; Error message for consistency checks
int AnzahlAnalog; // numAnalogRoi; number of analog ROIs used in this sequence
int AnzahlDigit; // numDigitRoi; number of digit ROIs used in this sequence

View File

@@ -13,7 +13,7 @@
#include "Helper.h"
#include "time_sntp.h"
static const char *TAG = "POSTPROCESS";
static const char *TAG = "POSTPROC";
std::string ClassFlowPostProcessing::getNumbersName()
{
@@ -141,7 +141,7 @@ bool ClassFlowPostProcessing::SetPreValue(double _newvalue, std::string _numbers
}
NUMBERS[j]->ReturnPreValue = std::to_string(NUMBERS[j]->PreValue);
NUMBERS[j]->PreValueOkay = true;
NUMBERS[j]->PreValueValid = true;
if (_extern)
{
@@ -149,8 +149,6 @@ bool ClassFlowPostProcessing::SetPreValue(double _newvalue, std::string _numbers
localtime(&(NUMBERS[j]->timeStampLastPreValue));
}
// 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();
@@ -228,11 +226,11 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
if (difference > PreValueAgeStartup)
{
NUMBERS[j]->PreValueOkay = false;
NUMBERS[j]->PreValueValid = false;
}
else
{
NUMBERS[j]->PreValueOkay = true;
NUMBERS[j]->PreValueValid = true;
}
}
}
@@ -344,7 +342,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow *> *lfc,
{
PreValueUse = false;
PreValueAgeStartup = 30;
ErrorMessage = false;
SkipErrorMessage = false;
ListFlowControll = NULL;
FilePreValue = format_filename("/sdcard/config/prevalue.ini");
ListFlowControll = lfc;
@@ -670,9 +668,9 @@ bool ClassFlowPostProcessing::ReadParameter(FILE *pFile, std::string &aktparamgr
PreValueAgeStartup = std::stoi(splitted[1]);
}
}
else if (_param == "ERRORMESSAGE")
else if (_param == "SKIPERRORMESSAGE")
{
ErrorMessage = alphanumeric_to_boolean(splitted[1]);
SkipErrorMessage = alphanumeric_to_boolean(splitted[1]);
}
else if (_param == "ALLOWNEGATIVERATES")
{
@@ -776,27 +774,28 @@ void ClassFlowPostProcessing::InitNUMBERS()
_number->AnzahlAnalog = 0;
}
_number->PreValue = 0; // last value read out well
_number->PreValue = 0.0f; // last value read out well
_number->ReturnPreValue = "";
_number->PreValueOkay = false;
_number->PreValueValid = false;
_number->ErrorMessage = false;
_number->ErrorMessageText = ""; // Error message for consistency check
_number->AllowNegativeRates = false;
_number->DecimalShift = 0;
_number->DecimalShiftInitial = 0;
_number->AnalogToDigitTransitionStart = 9.2;
_number->MaxFlowRate = 4.0;
_number->AnalogToDigitTransitionStart = 9.2f;
_number->MaxFlowRate = 4.0f;
_number->useMaxFlowRate = false;
_number->MaxRateValue = 0.1;
_number->MaxRateValue = 0.1f;
_number->MaxRateType = AbsoluteChange;
_number->useMaxRateValue = false;
_number->ChangeRateThreshold = 2;
_number->isExtendedResolution = false;
_number->IgnoreLeadingNaN = false;
_number->Value = 0; // last value read out, incl. corrections
_number->Value = 0.0f; // last value read out, incl. corrections
_number->ReturnValue = ""; // corrected return value, possibly with error message
_number->ReturnRawValue = ""; // raw value (with N & leading 0)
_number->FlowRateAct = 0; // m3 / min
_number->FlowRateAct = 0.0f; // m3 / min
_number->Nachkomma = _number->AnzahlAnalog;
@@ -871,22 +870,42 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time)
for (int j = 0; j < NUMBERS.size(); ++j)
{
NUMBERS[j]->ReturnRawValue = "";
NUMBERS[j]->ReturnRateValue = "";
NUMBERS[j]->ReturnValue = "";
NUMBERS[j]->ReturnChangeAbsolute = round_output(0.0, NUMBERS[j]->Nachkomma); // always reset change absolute
NUMBERS[j]->ErrorMessage = false;
NUMBERS[j]->ErrorMessageText = "";
NUMBERS[j]->Value = -1;
if (SkipErrorMessage)
{
NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue);
NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnValue;
}
else
{
NUMBERS[j]->ReturnValue = "";
NUMBERS[j]->ReturnRawValue = "";
}
NUMBERS[j]->FlowRateAct = 0.0f;
NUMBERS[j]->ReturnRateValue = round_output(0.0f, NUMBERS[j]->Nachkomma);
NUMBERS[j]->ReturnChangeAbsolute = NUMBERS[j]->ReturnRateValue;
// calculate time difference
double LastValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastValue) / 60; // in minutes
double LastValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastValue) / 60; // in minutes
double LastPreValueTimeDifference = difftime(imagetime, NUMBERS[j]->timeStampLastPreValue) / 60; // in minutes
if (!flowctrl.AlignmentOk)
{
NUMBERS[j]->ErrorMessageText = "alignment failed";
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, NUMBERS[j]->ErrorMessageText);
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->ErrorMessage = true;
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Alignment failed - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
WriteDataLog(j);
continue;
}
@@ -934,34 +953,52 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time)
}
}
NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
std::string TempValue = NUMBERS[j]->ReturnRawValue;
if (find_delimiter_pos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
if (find_delimiter_pos(TempValue, "N") != std::string::npos)
{
if (PreValueUse && NUMBERS[j]->PreValueOkay)
if (PreValueUse && NUMBERS[j]->PreValueValid)
{
NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue);
TempValue = ErsetzteN(TempValue, NUMBERS[j]->PreValue);
}
else
{
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->ErrorMessage = true;
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "PreValue not valid - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
NUMBERS[j]->ReturnValue = "";
NUMBERS[j]->timeStampLastValue = imagetime;
WriteDataLog(j);
continue; // there is no number because there is still an N.
}
}
// Delete leading zeros (unless there is only one 0 left)
while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
while ((TempValue.length() > 1) && (TempValue[0] == '0'))
{
NUMBERS[j]->ReturnValue.erase(0, 1);
TempValue.erase(0, 1);
}
NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
NUMBERS[j]->Value = std::stod(TempValue);
if (PreValueUse && NUMBERS[j]->PreValueOkay)
NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
NUMBERS[j]->FlowRateAct = std::stod(round_output(((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / LastPreValueTimeDifference), NUMBERS[j]->Nachkomma));
if (NUMBERS[j]->MaxRateType == RateChange)
{
NUMBERS[j]->ReturnRateValue = std::to_string(NUMBERS[j]->FlowRateAct);
}
else
{
// Difference per round, as a safeguard in case a reading error(Neg. Rate - Read: or Rate too high - Read:) occurs in the meantime
NUMBERS[j]->ReturnRateValue = round_output((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / ((int)(round(LastPreValueTimeDifference / LastValueTimeDifference))), NUMBERS[j]->Nachkomma);
}
if (PreValueUse && NUMBERS[j]->PreValueValid)
{
if ((NUMBERS[j]->Nachkomma > 0) && (NUMBERS[j]->ChangeRateThreshold > 0))
{
@@ -971,7 +1008,6 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time)
if ((NUMBERS[j]->Value >= _difference1) && (NUMBERS[j]->Value <= _difference2))
{
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->ReturnValue = std::to_string(NUMBERS[j]->PreValue);
}
}
@@ -981,63 +1017,53 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time)
if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue))
{
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " ";
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->ReturnValue = "";
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->ErrorMessage = true;
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
WriteDataLog(j);
continue;
}
}
NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / LastPreValueTimeDifference;
NUMBERS[j]->ReturnRateValue = std::to_string(NUMBERS[j]->FlowRateAct);
if ((NUMBERS[j]->useMaxRateValue) && (NUMBERS[j]->Value != NUMBERS[j]->PreValue))
{
double _ratedifference;
if (NUMBERS[j]->MaxRateType == RateChange)
if (abs(std::stod(NUMBERS[j]->ReturnRateValue)) > abs(NUMBERS[j]->MaxRateValue))
{
_ratedifference = NUMBERS[j]->FlowRateAct;
}
else
{
// Difference per round, as a safeguard in case a reading error(Neg. Rate - Read: or Rate too high - Read:) occurs in the meantime
_ratedifference = ((NUMBERS[j]->Value - NUMBERS[j]->PreValue) / ((int)(round(LastPreValueTimeDifference / LastValueTimeDifference))));
}
if (abs(_ratedifference) > abs(NUMBERS[j]->MaxRateValue))
{
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + round_output(_ratedifference, NUMBERS[j]->Nachkomma);
NUMBERS[j]->Value = NUMBERS[j]->PreValue;
NUMBERS[j]->ReturnValue = "";
NUMBERS[j]->ReturnRateValue = "";
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->ErrorMessage = true;
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, temp_string);
WriteDataLog(j);
continue;
}
}
}
NUMBERS[j]->ReturnChangeAbsolute = round_output(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
NUMBERS[j]->PreValue = NUMBERS[j]->Value;
NUMBERS[j]->PreValueOkay = true;
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->timeStampLastPreValue = imagetime;
NUMBERS[j]->PreValue = NUMBERS[j]->Value;
NUMBERS[j]->PreValueValid = true;
UpdatePreValueINI = true;
NUMBERS[j]->ReturnValue = round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
NUMBERS[j]->ReturnPreValue = round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
NUMBERS[j]->ErrorMessageText = "no error";
UpdatePreValueINI = true;
NUMBERS[j]->timeStampLastValue = imagetime;
NUMBERS[j]->timeStampLastPreValue = imagetime;
NUMBERS[j]->ErrorMessage = false;
NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "no error - Read: " + round_output(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + round_output(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " - Rate: " + NUMBERS[j]->ReturnRateValue;
std::string temp_string = NUMBERS[j]->name + ": Raw: " + NUMBERS[j]->ReturnRawValue + ", Value: " + NUMBERS[j]->ReturnValue + ", Status: " + NUMBERS[j]->ErrorMessageText;
LogFile.WriteToFile(ESP_LOG_INFO, TAG, temp_string);
@@ -1045,6 +1071,7 @@ bool ClassFlowPostProcessing::doFlow(std::string temp_time)
}
SavePreValue();
return true;
}
@@ -1074,11 +1101,11 @@ void ClassFlowPostProcessing::WriteDataLog(int _index)
std::string analog = "";
std::string digit = "";
std::string temp_time = "";
char buffer[80];
struct tm *timeinfo = localtime(&NUMBERS[_index]->timeStampLastValue);
strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
temp_time = std::string(buffer);
std::string temp_time = std::string(buffer);
if (flowAnalog)
{

View File

@@ -16,7 +16,7 @@ protected:
bool UpdatePreValueINI;
int PreValueAgeStartup;
bool ErrorMessage;
bool SkipErrorMessage;
ClassFlowCNNGeneral *flowAnalog;
ClassFlowCNNGeneral *flowDigit;

View File

@@ -13,8 +13,8 @@
#include "../stb/stb_image.h"
#include "../stb/stb_image_write.h"
// #include "../stb/deprecated/stb_image_resize.h"
#include "../stb/stb_image_resize.h"
#include "../stb/deprecated/stb_image_resize.h"
// #include "../stb/stb_image_resize.h"
#include "esp_heap_caps.h"

View File

@@ -24,5 +24,5 @@
#include "../stb/stb_image_write.h"
#define STB_IMAGE_RESIZE_IMPLEMENTATION
// #include "../stb/deprecated/stb_image_resize.h"
#include "../stb/stb_image_resize.h"
#include "../stb/deprecated/stb_image_resize.h"
// #include "../stb/stb_image_resize.h"

View File

@@ -33,9 +33,8 @@ Antialiasing
AlignmentAlgo
CNNGoodThreshold
PreValueAgeStartup
ErrorMessage
SkipErrorMessage
MaxFlowRate
ProcessAlgoNew
CACert
ClientCert
ClientKey

View File

@@ -1,5 +1,5 @@
# Parameter `ErrorMessage`
Default Value: `true`
# Parameter `SkipErrorMessage`
Default Value: `false`
!!! Warning
This is an **Expert Parameter**! Only change it if you understand what it does!

View File

@@ -67,17 +67,16 @@ main.ana4 155 328 92 92 false
[PostProcessing]
PreValueUse = true
PreValueAgeStartup = 720
ErrorMessage = true
SkipErrorMessage = false
main.AllowNegativeRates = false
main.DecimalShift = 0
main.AnalogToDigitTransitionStart = 9.8
;main.MaxFlowRate = 4.0
main.MaxFlowRate = 4.0
main.MaxRateValue = 0.05
main.MaxRateType = AbsoluteChange
main.ChangeRateThreshold = 2
main.ExtendedResolution = false
main.IgnoreLeadingNaN = false
main.ProcessAlgoNew = false
;[MQTT]
;Uri = mqtt://IP-ADRESS:1883

View File

@@ -250,9 +250,9 @@
<div id="divall" style="display:none">
<table class="table">
<colgroup>
<col span="1" style="width:290px">
<col span="1" style="width:300px;">
<col span="1">
<col span="1" style="width:45%;">
<col span="1" style="width:45%;">
<col span="1" style="width:10%;">
</colgroup>
<tr style="border-bottom: 2px solid lightgray;">
@@ -774,7 +774,7 @@
<option value="false" selected>disabled (false)</option>
</select>
</td>
<td>$TOOLTIP_Alignment_Antialiasing</td>
<td class="tooltip" style="display:none;"></td>
</tr>
<tr class="expert">
@@ -930,15 +930,15 @@
<tr class="expert">
<td class="indent1">
<class id="PostProcessing_ErrorMessage_text" style="color:black;">Skip Messages on Error</class>
<class id="PostProcessing_SkipErrorMessage_text" style="color:black;">Skip Messages on Error</class>
</td>
<td>
<select id="PostProcessing_ErrorMessage_value1">
<select id="PostProcessing_SkipErrorMessage_value1">
<option value="true">enabled (true)</option>
<option value="false" selected>disabled (false)</option>
</select>
</td>
<td>$TOOLTIP_PostProcessing_ErrorMessage</td>
<td>$TOOLTIP_PostProcessing_SkipErrorMessage</td>
</tr>
<tr style="margin-top:12px">
@@ -1219,7 +1219,7 @@
<td>
<input required type="text" id="MQTT_DiscoveryPrefix_value1">
</td>
<td>$TOOLTIP_MQTT_DiscoveryPrefix</td>
<td class="tooltip" style="display:none;"></td>
</tr>
<tr class="MQTTItem">
@@ -2405,7 +2405,7 @@ function UpdateInput() {
WriteParameter(param, category, "PostProcessing", "PreValueUse", false);
WriteParameter(param, category, "PostProcessing", "PreValueAgeStartup", true);
WriteParameter(param, category, "PostProcessing", "ErrorMessage", false);
WriteParameter(param, category, "PostProcessing", "SkipErrorMessage", false);
WriteParameter(param, category, "MQTT", "Uri", true);
WriteParameter(param, category, "MQTT", "MainTopic", true);
@@ -2579,7 +2579,7 @@ function ReadParameterAll() {
ReadParameter(param, "PostProcessing", "PreValueUse", false);
ReadParameter(param, "PostProcessing", "PreValueAgeStartup", true);
ReadParameter(param, "PostProcessing", "ErrorMessage", false);
ReadParameter(param, "PostProcessing", "SkipErrorMessage", false);
ReadParameter(param, "MQTT", "Uri", true);
ReadParameter(param, "MQTT", "MainTopic", true);

View File

@@ -160,11 +160,11 @@
<table style="width: 100%">
<colgroup>
<col span="1" style="width: 12%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 22%;">
<col span="1" style="width: 25%;">
<col span="1" style="width: 3%;">
<col span="1" style="width: 18%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 22%;">
<col span="1" style="width: 25%;">
<col span="1" style="width: 3%;">
</colgroup>

View File

@@ -253,7 +253,7 @@ function ParseConfig() {
// ParamAddValue(param, catname, "PreValueUse", 1, true, "true");
ParamAddValue(param, catname, "PreValueUse", 1, false, "true");
ParamAddValue(param, catname, "PreValueAgeStartup", 1, false, "720");
ParamAddValue(param, catname, "ErrorMessage", 1, false, "true");
ParamAddValue(param, catname, "SkipErrorMessage", 1, false, "false");
ParamAddValue(param, catname, "AllowNegativeRates", 1, true, "false");
ParamAddValue(param, catname, "DecimalShift", 1, true, "0");
ParamAddValue(param, catname, "AnalogToDigitTransitionStart", 1, true, "9.2");