Skip to content

Commit

Permalink
Fixed issues jomjol#2857
Browse files Browse the repository at this point in the history
The main reason was a wrong digital / analog sync,
if decimal shifts were != 0.

Also fixed hanging digits for late transition, which
happened at my own installation only.

Also reverted back to the improved unit test system of Slider0007,
which seemed to be mistakenly overwritten by someone.
  • Loading branch information
rainman110 committed Feb 11, 2024
1 parent 80a6fc1 commit b31a613
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 34 deletions.
35 changes: 26 additions & 9 deletions code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,18 +776,21 @@ bool inRange(float val, float min, float max)
*
* @return The synchronized values as a string
*/
std::string syncDigitalAnalog(const std::string& value, const std::string& digitalPrecision,
double analogDigitalShift)
std::string syncDigitalAnalog(const std::string& invalue, const std::string& digitalPrecision,
double analogDigitalShift, int decimalShift)
{
if (digitalPrecision.empty())
{
return value;
return invalue;
}

// temporarily revert decimal shift
std::string value = ClassFlowPostProcessing::ShiftDecimal(invalue, -decimalShift);

const auto pos = value.find('.');
if (pos == std::string::npos)
{
return value;
return invalue;
}

// disassemble value into pre and post comma part
Expand All @@ -804,13 +807,19 @@ std::string syncDigitalAnalog(const std::string& value, const std::string& digit
// Determine phase
const bool inTransition = digitalPostComma > 0. && digitalPostComma < 10.;
const bool postTransition = !inTransition && inRange(analogPostComma*10., analogDigitalShift, wrapAround(analogDigitalShift + 5.));
const bool preTransition = !inTransition && inRange(analogPostComma*10., 0, analogDigitalShift);
const bool preTransition = inRange(analogPostComma*10., 0, analogDigitalShift);


if (inRange(analogDigitalShift, 0.5, 5.))
{
// prevent hanging digit
if (digitalPostComma >= 9.0)
{
digitalPreComma += 1;
}

// late transition, last digit starts transition, when analog is between [0.5, 5)
if (inTransition || preTransition)
if ((digitalPostComma > 0. && digitalPostComma < 9.) || preTransition)
{
ESP_LOGD("syncDigitalAnalog", "Late digital transition. Increase digital value by 1.");
digitalPreComma += 1;
Expand All @@ -830,18 +839,25 @@ std::string syncDigitalAnalog(const std::string& value, const std::string& digit
if (inTransition && analogPostComma < 0.5) {
digitalPreComma += 1;
}
else if (analogPostComma*10 < analogDigitalShift && digitalPostComma >= 9.)
{
// hanging digit
digitalPreComma += 1;
}
}
else
{
return value;
return invalue;
}

// assemble result into string again, pad with zeros
auto preCommaNew = std::to_string(digitalPreComma);
for (size_t i = preCommaNew.size(); i < nPreComma; ++i)
preCommaNew = "0" + preCommaNew;

const std::string result = preCommaNew + "." + postComma;
// apply again decimal shift
const std::string result = ClassFlowPostProcessing::ShiftDecimal(preCommaNew + "." + postComma,
decimalShift);

#if debugSync
ESP_LOGD("syncDigitalAnalog", "result: %s", result.c_str());
Expand Down Expand Up @@ -977,7 +993,8 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
{
// Synchronize potential misalignment between analog and digital part
NUMBERS[j]->ReturnValue = syncDigitalAnalog(NUMBERS[j]->ReturnValue, digitalPrecision, NUMBERS[j]->AnalogDigitalTransitionStart);
NUMBERS[j]->ReturnValue = syncDigitalAnalog(NUMBERS[j]->ReturnValue, digitalPrecision, NUMBERS[j]->AnalogDigitalTransitionStart,
NUMBERS[j]->DecimalShift);
}

#ifdef SERIAL_DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ClassFlowPostProcessing :
ClassFlowTakeImage *flowTakeImage;

bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);

string ErsetzteN(string, double _prevalue);
float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
Expand Down Expand Up @@ -78,6 +77,8 @@ class ClassFlowPostProcessing :
std::vector<NumberPost*>* GetNumbers(){return &NUMBERS;};

string name(){return "ClassFlowPostProcessing";};

static string ShiftDecimal(string in, int _decShift);
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,13 @@ void test_doFlowPP4() {

std::string postProcess(std::vector<float> digits,
std::vector<float> analogs,
float analog2DigitalTransition=0.0)
float analog2DigitalTransition=0.0,
int decimalShift=0)
{
std::unique_ptr<UnderTestPost> undertestPost(init_do_flow(std::move(analogs),
std::move(digits),
Digital100,
false, false));
false, false, decimalShift));

setAnalogdigitTransistionStart(undertestPost.get(), analog2DigitalTransition);
return process_doFlow(undertestPost.get());
Expand Down Expand Up @@ -600,5 +601,62 @@ void test_doFlowEarlyTransition()

}

void test_doFlowIssue2857()
{
// reported by gec75
float a2dt = 9.2;
int decimalShift = 3;
TEST_ASSERT_EQUAL_STRING("252090.0", postProcess({ 2.0, 5.0, 1.9}, { 0.8, 8.8, 9.9, 0.1},
a2dt, decimalShift).c_str());

// reported by Kornelius777
decimalShift = 0;
TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 7.0}, { 8.2, 0.9, 9.9, 9.8},
a2dt, decimalShift).c_str());

// with hanging digit
TEST_ASSERT_EQUAL_STRING("1017.8099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8},
a2dt, decimalShift).c_str());

// and deccimal shift
decimalShift = -2;
TEST_ASSERT_EQUAL_STRING("10.178099", postProcess({ 0.0, 1.0, 0.0, 1.0, 6.9}, { 8.2, 0.9, 9.9, 9.8},
a2dt, decimalShift).c_str());



// reported by marcniedersachsen
decimalShift = 0;
TEST_ASSERT_EQUAL_STRING("778.1480", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5},
a2dt, decimalShift).c_str());

decimalShift = 3;
TEST_ASSERT_EQUAL_STRING("778148.0", postProcess({ 0.0, 7.0, 7.0, 7.9}, { 1.4, 4.7, 8.0, 0.5},
a2dt, decimalShift).c_str());

// reported by ohkaja
decimalShift = 0;
TEST_ASSERT_EQUAL_STRING("1052.6669", postProcess({ 0.0, 1.0, 10.0, 4.9, 2.0}, { 6.7, 6.7, 6.9, 9.1},
a2dt, decimalShift).c_str());


}


void test_doFlowLateTransitionHanging()
{
float a2dt = 3.6;

// meter shows 012.4210 , this is after transition
TEST_ASSERT_EQUAL_STRING("12.4210", postProcess({0.0, 1.0, 1.9}, {4.3, 2.2, 1.0, 0.0}, a2dt).c_str());

TEST_ASSERT_EQUAL_STRING("12.6210", postProcess({0.0, 1.0, 1.9}, {6.3, 2.2, 1.0, 0.0}, a2dt).c_str());

TEST_ASSERT_EQUAL_STRING("13.1210", postProcess({0.0, 1.0, 1.9}, {1.2, 2.2, 1.0, 0.0}, a2dt).c_str());

TEST_ASSERT_EQUAL_STRING("13.3610", postProcess({0.0, 1.0, 2.5}, {3.5, 6.2, 1.0, 0.0}, a2dt).c_str());

TEST_ASSERT_EQUAL_STRING("13.4510", postProcess({0.0, 1.0, 3.0}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str());

TEST_ASSERT_EQUAL_STRING("13.4510", postProcess({0.0, 1.0, 2.9}, {4.5, 5.2, 1.0, 0.0}, a2dt).c_str());
}
37 changes: 15 additions & 22 deletions code/test/test_suite_flowcontroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ void task_UnityTesting(void *pvParameter)
RUN_TEST(test_doFlowPP3);
printf("---------------------------------------------------------------------------\n");
RUN_TEST(test_doFlowPP4);
printf("---------------------------------------------------------------------------\n");
RUN_TEST(test_doFlowLateTransition);
printf("---------------------------------------------------------------------------\n");
RUN_TEST(test_doFlowEarlyTransition);
printf("---------------------------------------------------------------------------\n");
RUN_TEST(test_doFlowIssue2857);
printf("---------------------------------------------------------------------------\n");
RUN_TEST(test_doFlowLateTransitionHanging);
UNITY_END();

while(1);
Expand All @@ -149,26 +157,11 @@ void task_UnityTesting(void *pvParameter)
*/
extern "C" void app_main()
{
initGPIO();
Init_NVS_SDCard();
esp_log_level_set("*", ESP_LOG_DEBUG); // set all components to ERROR level

UNITY_BEGIN();
RUN_TEST(testNegative_Issues);
RUN_TEST(testNegative);
/*
RUN_TEST(test_analogToDigit_Standard);
RUN_TEST(test_analogToDigit_Transition);
RUN_TEST(test_doFlowPP);
RUN_TEST(test_doFlowPP1);
RUN_TEST(test_doFlowPP2);
RUN_TEST(test_doFlowPP3);
RUN_TEST(test_doFlowPP4);
RUN_TEST(test_doFlowLateTransition);
RUN_TEST(test_doFlowEarlyTransition);
// getReadoutRawString test
RUN_TEST(test_getReadoutRawString);
*/
UNITY_END();
initGPIO();
Init_NVS_SDCard();
esp_log_level_set("*", ESP_LOG_DEBUG); // set all components to DEBUG level

// Create dedicated testing task (heap size can be configured - large enough to handle a lot of testing cases)
// ********************************************
xTaskCreate(&task_UnityTesting, "task_UnityTesting", 12 * 1024, NULL, tskIDLE_PRIORITY+2, NULL);
}

0 comments on commit b31a613

Please sign in to comment.