From b6bf8d992feaccacb8cb82086d411255fb0c47c3 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 22 Aug 2022 10:31:25 +0200 Subject: [PATCH 1/2] Test case for postprocessing --- code/main/version.cpp | 6 +- .../test_cnnflowcontroll.cpp | 18 +--- .../test_flowpostprocessing.cpp | 98 +++++++++++++++++++ code/test/test_suite_flowcontroll.cpp | 75 ++++++++++++++ code/version.cpp | 6 +- 5 files changed, 182 insertions(+), 21 deletions(-) create mode 100644 code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp diff --git a/code/main/version.cpp b/code/main/version.cpp index 49b8a186..530c3b0e 100644 --- a/code/main/version.cpp +++ b/code/main/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="bfe8d3b"; +const char* GIT_REV="7315f9a+"; const char* GIT_TAG=""; -const char* GIT_BRANCH="master"; -const char* BUILD_TIME="2022-08-13 14:22"; \ No newline at end of file +const char* GIT_BRANCH="analogtodig_as_float"; +const char* BUILD_TIME="2022-08-21 15:32"; \ No newline at end of file diff --git a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp index 79332eea..ab57c800 100644 --- a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp +++ b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp @@ -1,7 +1,7 @@ #include #include -class UnderTest : public ClassFlowCNNGeneral { +class UnderTestCNN : public ClassFlowCNNGeneral { public: using ClassFlowCNNGeneral::ZeigerEval; using ClassFlowCNNGeneral::ZeigerEvalHybrid; @@ -10,25 +10,13 @@ class UnderTest : public ClassFlowCNNGeneral { }; -void setUp(void) -{ - // set stuff up here -} - -void tearDown(void) -{ - // clean stuff up here -} - - - /** * @brief test if all combinations of digit * evaluation are running correctly */ void test_ZeigerEval() { - UnderTest undertest = UnderTest(nullptr, Digital100); + UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100); // the 5.2 is already above 5.0 and the previous digit too (3) int result = undertest.ZeigerEval(5.2, 3); @@ -51,7 +39,7 @@ void test_ZeigerEval() * evaluation are running correctly */ void test_ZeigerEvalHybrid() { - UnderTest undertest = UnderTest(nullptr, Digital100); + UnderTestCNN undertest = UnderTestCNN(nullptr, Digital100); // the 5.2 and no previous should round down TEST_ASSERT_EQUAL(5, undertest.ZeigerEvalHybrid(5.2, 0, -1)); diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp new file mode 100644 index 00000000..47ddc9f0 --- /dev/null +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include + + +ClassFlowCNNGeneral* _analog; +ClassFlowCNNGeneral* _digit; +std::vector FlowControll; +ClassFlowMakeImage* flowmakeimage; + + +class UnderTestPost : public ClassFlowPostProcessing { + public: + UnderTestPost(std::vector* lfc, ClassFlowCNNGeneral *_analog, ClassFlowCNNGeneral *_digit) + : ClassFlowPostProcessing::ClassFlowPostProcessing(lfc, _analog, _digit) {} + using ClassFlowPostProcessing::InitNUMBERS; +}; + +UnderTestPost* undertestPost; + + +void setUpClassFlowPostprocessing(void) +{ + + // wird im doFlow verwendet + flowmakeimage = new ClassFlowMakeImage(&FlowControll); + FlowControll.push_back(flowmakeimage); + + // Die Modeltypen werden gesetzt, da keine Modelle verwendet werden. + _analog = new ClassFlowCNNGeneral(nullptr, Analogue100); + + _digit = new ClassFlowCNNGeneral(nullptr, Digital100); + + undertestPost = new UnderTestPost(&FlowControll, _analog, _digit); + +} + + +/** + * @brief getestet wird das Ergebnis von + * digit1 = 1.2 + * digit2 = 6.7 + * analog1 = 9.5 + * analog2 = 8.4 + * + * Das Ergebnis sollte "16.984" sein. + */ +void test_doFlow() { + // setup the classundertest + setUpClassFlowPostprocessing(); + + printf("SetupClassFlowPostprocessing completed.\n"); + + general* gen_digit = _digit->GetGENERAL("default", true); + // digit1 + roi* digit1 = new roi(); + digit1->name = "digit1"; + digit1->result_float = 1.2; + gen_digit->ROI.push_back(digit1); + // digit2 + roi* digit2 = new roi(); + digit2->name = "digit2"; + digit2->result_float = 6.7; + gen_digit->ROI.push_back(digit2); + + general* gen_analog = _analog->GetGENERAL("default", true); + // analog1 + roi* analog1 = new roi(); + analog1->name = "analog1"; + analog1->result_float = 9.5; + gen_analog->ROI.push_back(analog1); + + // analog2 + roi* analog2 = new roi(); + analog2->name = "analog2"; + analog2->result_float = 8.4; + gen_analog->ROI.push_back(analog2); + + printf("Setup ROIs completed.\n"); + + undertestPost->InitNUMBERS(); + + + string time; + // run test + TEST_ASSERT_TRUE(undertestPost->doFlow(time)); + + printf("DoFlow completed.\n"); + + + TEST_ASSERT_EQUAL_STRING("0000", undertestPost->getReadout(0).c_str()); + +} + + + diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index 48b2993e..a981ec39 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -1,5 +1,78 @@ #include #include "components/jomjol-flowcontroll/test_cnnflowcontroll.cpp" +#include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp" +// SD-Card //////////////////// +#include "nvs_flash.h" +#include "esp_vfs_fat.h" +#include "sdmmc_cmd.h" +#include "driver/sdmmc_host.h" +#include "driver/sdmmc_defs.h" +static const char *TAGMAIN = "main"; + +bool Init_NVS_SDCard() +{ + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } +//////////////////////////////////////////////// + + ESP_LOGI(TAGMAIN, "Using SDMMC peripheral"); + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + + // This initializes the slot without card detect (CD) and write protect (WP) signals. + // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. + sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); + + // To use 1-line SD mode, uncomment the following line: + +#ifdef __SD_USE_ONE_LINE_MODE__ + slot_config.width = 1; +#endif + + // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups. + // Internal pull-ups are not sufficient. However, enabling internal pull-ups + // does make a difference some boards, so we do that here. + gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes + gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes +#ifndef __SD_USE_ONE_LINE_MODE__ + gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only + gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only +#endif + gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes + + // Options for mounting the filesystem. + // If format_if_mount_failed is set to true, SD card will be partitioned and + // formatted in case when mounting fails. + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .format_if_mount_failed = false, + .max_files = 5, + .allocation_unit_size = 16 * 1024 + }; + + // Use settings defined above to initialize SD card and mount FAT filesystem. + // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function. + // Please check its source code and implement error recovery when developing + // production applications. + sdmmc_card_t* card; + ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card); + + if (ret != ESP_OK) { + if (ret == ESP_FAIL) { + ESP_LOGE(TAGMAIN, "Failed to mount filesystem. " + "If you want the card to be formatted, set format_if_mount_failed = true."); + } else { + ESP_LOGE(TAGMAIN, "Failed to initialize the card (%s). " + "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret)); + } + return false; + } + sdmmc_card_print_info(stdout, card); + + return true; +} + /** * @brief startup the test. Like a test-suite @@ -7,10 +80,12 @@ */ extern "C" void app_main() { + Init_NVS_SDCard(); UNITY_BEGIN(); RUN_TEST(test_ZeigerEval); RUN_TEST(test_ZeigerEvalHybrid); + RUN_TEST(test_doFlow); UNITY_END(); } \ No newline at end of file diff --git a/code/version.cpp b/code/version.cpp index 49b8a186..530c3b0e 100644 --- a/code/version.cpp +++ b/code/version.cpp @@ -1,4 +1,4 @@ -const char* GIT_REV="bfe8d3b"; +const char* GIT_REV="7315f9a+"; const char* GIT_TAG=""; -const char* GIT_BRANCH="master"; -const char* BUILD_TIME="2022-08-13 14:22"; \ No newline at end of file +const char* GIT_BRANCH="analogtodig_as_float"; +const char* BUILD_TIME="2022-08-21 15:32"; \ No newline at end of file From 974044adf003b0c6af2e10c984073b4ccc6b3fa6 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 22 Aug 2022 16:10:07 +0200 Subject: [PATCH 2/2] last analog result_float as Readout parameter, testcases for #921, #919 --- .../ClassFlowPostProcessing.cpp | 11 +- .../test_cnnflowcontroll.cpp | 2 +- .../test_flowpostprocessing.cpp | 134 ++++++++++++------ 3 files changed, 100 insertions(+), 47 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 30dcbe0c..9d0f85c5 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -238,8 +238,9 @@ void ClassFlowPostProcessing::SavePreValue() _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n"; printf("Write PreValue Zeile: %s\n", _zw.c_str()); - - fputs(_zw.c_str(), pFile); + if (pFile) { + fputs(_zw.c_str(), pFile); + } } UpdatePreValueINI = false; @@ -568,8 +569,10 @@ void ClassFlowPostProcessing::InitNUMBERS() NUMBERS.push_back(_number); } - for (int i = 0; i < NUMBERS.size(); ++i) + for (int i = 0; i < NUMBERS.size(); ++i) { printf("Number %s, Anz DIG: %d, Anz ANA %d\n", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog); + } + } string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){ @@ -667,7 +670,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (NUMBERS[j]->digit_roi) { if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, previous_value) + NUMBERS[j]->ReturnRawValue; + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float) + NUMBERS[j]->ReturnRawValue; else NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } diff --git a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp index ab57c800..5b9f1fca 100644 --- a/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp +++ b/code/test/components/jomjol-flowcontroll/test_cnnflowcontroll.cpp @@ -83,7 +83,7 @@ void test_ZeigerEvalHybrid() { // pre = 9.9 (0.0 raw) // zahl = 1.8 - TEST_ASSERT_EQUAL(1, undertest.ZeigerEvalHybrid(1.8, 9.0, 9)); + TEST_ASSERT_EQUAL(2, undertest.ZeigerEvalHybrid(1.8, 9.0, 9)); // if a digit have an early transition and the pointer is < 9.0 // prev (pointer) = 6.2, but on digital readout = 6.0 (prev is int parameter) diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 47ddc9f0..4e07efef 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -4,6 +4,8 @@ #include #include +void setUpClassFlowPostprocessing(void); +string process_doFlow(std::vector analog, std::vector digits); ClassFlowCNNGeneral* _analog; ClassFlowCNNGeneral* _digit; @@ -21,6 +23,67 @@ class UnderTestPost : public ClassFlowPostProcessing { UnderTestPost* undertestPost; +/** + * @brief Testet die doFlow-Methode von ClassFlowPostprocessing + * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts + * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits + * expected - enthält das erwartete Ergebnis, wobei der Dezimalpunkt genau zwischen digits und analog ist. + * + */ +void test_doFlow() { + /* + * + * digit1 = 1.2 + * digit2 = 6.7 + * analog1 = 9.5 + * analog2 = 8.4 + * + * Das Ergebnis sollte "16.984" sein. Bzw. 16.98 ohne Extended true + */ + std::vector digits = { 1.2, 6.7}; + std::vector analogs = { 9.5, 8.4}; + const char* expected = "16.98"; + std::string result = process_doFlow(analogs, digits); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + /* + * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * + * Das Ergebnis sollte "376529.6" sein. Bzw. 16.98 ohne Extended true + */ + digits = { 3.0, 7.0, 6.0, 5.0, 2.5, 9.6}; + analogs = { 6.4}; + expected = "376529.6"; + result = process_doFlow(analogs, digits); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + /* + * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * + * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true + */ + digits = { 1.1, 6.0, 7.0, 7.0, 3.0, 4.6}; + analogs = { 6.2}; + expected = "167734.6"; + result = process_doFlow(analogs, digits); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + /* + * https://github.com/jomjol/AI-on-the-edge-device/issues/919 + * + * Das Ergebnis sollte "58.96889" sein. Bzw. 16.98 ohne Extended true + */ + digits = { 5.0, 8.6}; + analogs = { 9.8, 6.7, 8.9, 8.6, 9.8}; + expected = "58.96889"; + result = process_doFlow(analogs, digits); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + +} + + + void setUpClassFlowPostprocessing(void) { @@ -38,61 +101,48 @@ void setUpClassFlowPostprocessing(void) } -/** - * @brief getestet wird das Ergebnis von - * digit1 = 1.2 - * digit2 = 6.7 - * analog1 = 9.5 - * analog2 = 8.4 - * - * Das Ergebnis sollte "16.984" sein. - */ -void test_doFlow() { +std::string process_doFlow(std::vector analog, std::vector digits) { // setup the classundertest setUpClassFlowPostprocessing(); printf("SetupClassFlowPostprocessing completed.\n"); - general* gen_digit = _digit->GetGENERAL("default", true); - // digit1 - roi* digit1 = new roi(); - digit1->name = "digit1"; - digit1->result_float = 1.2; - gen_digit->ROI.push_back(digit1); - // digit2 - roi* digit2 = new roi(); - digit2->name = "digit2"; - digit2->result_float = 6.7; - gen_digit->ROI.push_back(digit2); - - general* gen_analog = _analog->GetGENERAL("default", true); - // analog1 - roi* analog1 = new roi(); - analog1->name = "analog1"; - analog1->result_float = 9.5; - gen_analog->ROI.push_back(analog1); - - // analog2 - roi* analog2 = new roi(); - analog2->name = "analog2"; - analog2->result_float = 8.4; - gen_analog->ROI.push_back(analog2); - + // digits + if (digits.size()>0) { + general* gen_digit = _digit->GetGENERAL("default", true); + gen_digit->ROI.clear(); + + for (int i = 0; iname = name; + digitROI->result_float = digits[i]; + gen_digit->ROI.push_back(digitROI); + } + } + + // analog + if (analog.size()>0) { + general* gen_analog = _analog->GetGENERAL("default", true); + gen_analog->ROI.clear(); + + for (int i = 0; iname = name; + anaROI->result_float = analog[i]; + gen_analog->ROI.push_back(anaROI); + } + } printf("Setup ROIs completed.\n"); undertestPost->InitNUMBERS(); - string time; // run test TEST_ASSERT_TRUE(undertestPost->doFlow(time)); - printf("DoFlow completed.\n"); - - - TEST_ASSERT_EQUAL_STRING("0000", undertestPost->getReadout(0).c_str()); + return undertestPost->getReadout(0); } - -