Helper.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. #ifndef HELPER_H
  3. #define HELPER_H
  4. #include "sdkconfig.h"
  5. #include <string>
  6. #include <fstream>
  7. #include <vector>
  8. #include "sdmmc_cmd.h"
  9. #include "defines.h"
  10. #ifdef CONFIG_SOC_TEMP_SENSOR_SUPPORTED
  11. #include <driver/temperature_sensor.h>
  12. #endif
  13. #if (ESP_IDF_VERSION_MAJOR >= 5)
  14. #include "soc/periph_defs.h"
  15. #include "esp_private/periph_ctrl.h"
  16. #include "soc/gpio_sig_map.h"
  17. #include "soc/gpio_periph.h"
  18. #include "soc/io_mux_reg.h"
  19. #include "esp_rom_gpio.h"
  20. #define gpio_pad_select_gpio esp_rom_gpio_pad_select_gpio
  21. #define gpio_matrix_in(a, b, c) esp_rom_gpio_connect_in_signal(a, b, c)
  22. #define gpio_matrix_out(a, b, c, d) esp_rom_gpio_connect_out_signal(a, b, c, d)
  23. #define ets_delay_us(a) esp_rom_delay_us(a)
  24. #endif
  25. using namespace std;
  26. /* Error bit fields
  27. One bit per error
  28. Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */
  29. enum SystemStatusFlag_t
  30. { // One bit per error
  31. // First Byte
  32. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  33. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  34. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  35. SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error
  36. SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error
  37. // Second Byte
  38. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0 + 8), // 8, Flow still might work
  39. SYSTEM_STATUS_NTP_BAD = 1 << (1 + 8), // 9, Flow will work but time will be wrong
  40. };
  41. void string_to_ip4(const char *ip, int &a, int &b, int &c, int &d);
  42. std::string bssid_to_string(const char *c);
  43. std::string format_filename(std::string input);
  44. std::size_t file_size(const std::string &file_name);
  45. void find_replace(std::string &line, std::string &oldString, std::string &newString);
  46. bool copy_file(string input, string output);
  47. bool delete_file(string filename);
  48. bool rename_file(string from, string to);
  49. bool rename_folder(string from, string to);
  50. bool make_dir(std::string _what);
  51. bool file_exists(string filename);
  52. bool folder_exists(string foldername);
  53. string round_output(double _in, int _anzNachkomma);
  54. size_t find_delimiter_pos(string input, string delimiter);
  55. std::string trim_string_left_right(std::string istring, std::string adddelimiter = "");
  56. std::string trim_string_left(std::string istring, std::string adddelimiter = "");
  57. std::string trim_string_right(std::string istring, std::string adddelimiter = "");
  58. bool ctype_space(const char c, string adddelimiter);
  59. string get_file_type(string filename);
  60. string get_file_full_filename(string filename);
  61. string get_directory(string filename);
  62. int mkdir_r(const char *dir, const mode_t mode);
  63. int remove_folder(const char *folderPath, const char *logTag);
  64. string to_lower(string in);
  65. string to_upper(string in);
  66. static float temp_sens_value = -1;
  67. #ifdef CONFIG_SOC_TEMP_SENSOR_SUPPORTED
  68. void init_tempsensor(void);
  69. #endif
  70. float read_tempsensor(void);
  71. time_t add_days(time_t startTime, int days);
  72. void mem_copy_gen(uint8_t *_source, uint8_t *_target, int _size);
  73. std::vector<std::string> split_string(const std::string &str);
  74. std::vector<std::string> split_line(std::string input, std::string _delimiter = "=");
  75. ///////////////////////////
  76. size_t get_internal_heapsize();
  77. size_t get_heapsize();
  78. string get_heapinfo();
  79. /////////////////////////////
  80. string get_sd_card_partition_size();
  81. string get_sd_card_free_partition_space();
  82. string get_sd_card_partition_allocation_size();
  83. void save_sd_card_info(sdmmc_card_t *card);
  84. string sd_card_parse_manufacturer_ids(int);
  85. string get_sd_card_manufacturer();
  86. string get_sd_card_name();
  87. string get_sd_card_capacity();
  88. string get_sd_card_sector_size();
  89. string get_mac(void);
  90. void set_system_statusflag(SystemStatusFlag_t flag);
  91. void clear_system_statusflag(SystemStatusFlag_t flag);
  92. int get_system_status(void);
  93. bool is_set_system_statusflag(SystemStatusFlag_t flag);
  94. time_t get_uptime(void);
  95. string get_reset_reason(void);
  96. std::string get_formated_uptime(bool compact);
  97. const char *get404(void);
  98. std::string url_decode(const std::string &value);
  99. void replace_all(std::string &s, const std::string &toReplace, const std::string &replaceWith);
  100. bool replace_string(std::string &s, std::string const &toReplace, std::string const &replaceWith);
  101. bool replace_string(std::string &s, std::string const &toReplace, std::string const &replaceWith, bool logIt);
  102. std::string encrypt_decrypt_string(std::string toEncrypt);
  103. std::string encrypt_pw_string(std::string toEncrypt);
  104. std::string decrypt_pw_string(std::string toDecrypt);
  105. esp_err_t encrypt_decrypt_pw_on_sd(bool _encrypt, std::string filename);
  106. bool is_in_string(std::string &s, std::string const &toFind);
  107. bool is_string_numeric(std::string &input);
  108. bool is_string_alphabetic(std::string &input);
  109. bool is_string_alphanumeric(std::string &input);
  110. bool alphanumeric_to_boolean(std::string &input);
  111. int clip_int(int input, int high, int low);
  112. bool numeric_str_to_boolean(std::string input);
  113. bool string_to_boolean(std::string input);
  114. #endif // HELPER_H