test_suite_flowcontroll.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #include <unity.h>
  2. // SD-Card ////////////////////
  3. #include "nvs_flash.h"
  4. #include "esp_vfs_fat.h"
  5. #include "sdmmc_cmd.h"
  6. #include "driver/sdmmc_host.h"
  7. #include "driver/sdmmc_defs.h"
  8. //static const char *TAG = "MAIN TEST";
  9. #define __SD_USE_ONE_LINE_MODE__
  10. #include "server_GPIO.h"
  11. //*****************************************************************************
  12. // Include files with functions to test
  13. //*****************************************************************************
  14. #include "components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp"
  15. #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp"
  16. #include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp"
  17. #include "components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp"
  18. #include "components/jomjol-flowcontroll/test_getReadoutRawString.cpp"
  19. #include "components/jomjol-flowcontroll/test_cnnflowcontroll.cpp"
  20. #include "components/openmetrics/test_openmetrics.cpp"
  21. #include "components/jomjol_mqtt/test_server_mqtt.cpp"
  22. bool Init_NVS_SDCard()
  23. {
  24. esp_err_t ret = nvs_flash_init();
  25. if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
  26. ESP_ERROR_CHECK(nvs_flash_erase());
  27. ret = nvs_flash_init();
  28. }
  29. ////////////////////////////////////////////////
  30. ESP_LOGI(TAG, "Using SDMMC peripheral");
  31. sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  32. // This initializes the slot without card detect (CD) and write protect (WP) signals.
  33. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
  34. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
  35. // To use 1-line SD mode, uncomment the following line:
  36. #ifdef __SD_USE_ONE_LINE_MODE__
  37. slot_config.width = 1;
  38. #endif
  39. // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
  40. // Internal pull-ups are not sufficient. However, enabling internal pull-ups
  41. // does make a difference some boards, so we do that here.
  42. gpio_set_pull_mode(GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
  43. gpio_set_pull_mode(GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
  44. #ifndef __SD_USE_ONE_LINE_MODE__
  45. gpio_set_pull_mode(GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
  46. gpio_set_pull_mode(GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
  47. #endif
  48. gpio_set_pull_mode(GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
  49. // Options for mounting the filesystem.
  50. // If format_if_mount_failed is set to true, SD card will be partitioned and
  51. // formatted in case when mounting fails.
  52. esp_vfs_fat_sdmmc_mount_config_t mount_config = {
  53. .format_if_mount_failed = false,
  54. .max_files = 7, // anstatt 5 (2022-09-21)
  55. .allocation_unit_size = 16 * 1024
  56. };
  57. // Use settings defined above to initialize SD card and mount FAT filesystem.
  58. // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
  59. // Please check its source code and implement error recovery when developing
  60. // production applications.
  61. sdmmc_card_t* card;
  62. ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
  63. if (ret != ESP_OK) {
  64. if (ret == ESP_FAIL) {
  65. ESP_LOGE(TAG, "Failed to mount filesystem. "
  66. "If you want the card to be formatted, set format_if_mount_failed = true.");
  67. } else {
  68. ESP_LOGE(TAG, "Failed to initialize the card (%s). "
  69. "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
  70. }
  71. return false;
  72. }
  73. sdmmc_card_print_info(stdout, card);
  74. SaveSDCardInfo(card);
  75. return true;
  76. }
  77. void initGPIO()
  78. {
  79. gpio_config_t io_conf;
  80. //set as output mode
  81. io_conf.mode = gpio_mode_t::GPIO_MODE_INPUT;
  82. //bit mask of the pins that you want to set,e.g.GPIO18/19
  83. io_conf.pull_down_en = gpio_pulldown_t::GPIO_PULLDOWN_ENABLE;
  84. //set pull-up mode
  85. io_conf.pull_up_en = gpio_pullup_t::GPIO_PULLUP_DISABLE;
  86. //configure GPIO with the given settings
  87. gpio_config(&io_conf);
  88. }
  89. /**
  90. * @brief startup the test. Like a test-suite
  91. * all test methods must be called here
  92. */
  93. void task_UnityTesting(void *pvParameter)
  94. {
  95. vTaskDelay( 5000 / portTICK_PERIOD_MS ); // 5s delay to ensure established serial connection
  96. UNITY_BEGIN();
  97. RUN_TEST(test_getReadoutRawString);
  98. printf("---------------------------------------------------------------------------\n");
  99. RUN_TEST(test_ZeigerEval);
  100. printf("---------------------------------------------------------------------------\n");
  101. RUN_TEST(test_ZeigerEvalHybrid);
  102. printf("---------------------------------------------------------------------------\n");
  103. RUN_TEST(testNegative_Issues);
  104. printf("---------------------------------------------------------------------------\n");
  105. RUN_TEST(testNegative);
  106. printf("---------------------------------------------------------------------------\n");
  107. RUN_TEST(test_analogToDigit_Standard);
  108. printf("---------------------------------------------------------------------------\n");
  109. RUN_TEST(test_analogToDigit_Transition);
  110. printf("---------------------------------------------------------------------------\n");
  111. RUN_TEST(test_doFlowPP);
  112. printf("---------------------------------------------------------------------------\n");
  113. RUN_TEST(test_doFlowPP1);
  114. printf("---------------------------------------------------------------------------\n");
  115. RUN_TEST(test_doFlowPP2);
  116. printf("---------------------------------------------------------------------------\n");
  117. RUN_TEST(test_doFlowPP3);
  118. printf("---------------------------------------------------------------------------\n");
  119. RUN_TEST(test_doFlowPP4);
  120. UNITY_END();
  121. while(1);
  122. }
  123. /**
  124. * @brief main task
  125. */
  126. extern "C" void app_main()
  127. {
  128. initGPIO();
  129. Init_NVS_SDCard();
  130. esp_log_level_set("*", ESP_LOG_ERROR); // set all components to ERROR level
  131. UNITY_BEGIN();
  132. RUN_TEST(testNegative_Issues);
  133. RUN_TEST(testNegative);
  134. RUN_TEST(test_analogToDigit_Standard);
  135. RUN_TEST(test_analogToDigit_Transition);
  136. RUN_TEST(test_doFlowPP);
  137. RUN_TEST(test_doFlowPP1);
  138. RUN_TEST(test_doFlowPP2);
  139. RUN_TEST(test_doFlowPP3);
  140. RUN_TEST(test_doFlowPP4);
  141. // getReadoutRawString test
  142. RUN_TEST(test_getReadoutRawString);
  143. RUN_TEST(test_openmetrics);
  144. RUN_TEST(test_mqtt);
  145. UNITY_END();
  146. }