Helper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. #ifndef HELPER_H
  3. #define HELPER_H
  4. #include <string>
  5. #include <fstream>
  6. #include <vector>
  7. #include "sdmmc_cmd.h"
  8. using namespace std;
  9. std::string FormatFileName(std::string input);
  10. std::size_t file_size(const std::string& file_name);
  11. void FindReplace(std::string& line, std::string& oldString, std::string& newString);
  12. bool CopyFile(string input, string output);
  13. bool DeleteFile(string filename);
  14. bool RenameFile(string from, string to);
  15. bool RenameFolder(string from, string to);
  16. bool MakeDir(std::string _what);
  17. bool FileExists(string filename);
  18. string RundeOutput(double _in, int _anzNachkomma);
  19. size_t findDelimiterPos(string input, string delimiter);
  20. //string trim(string istring);
  21. string trim(string istring, string adddelimiter = "");
  22. bool ctype_space(const char c, string adddelimiter);
  23. string getFileType(string filename);
  24. string getFileFullFileName(string filename);
  25. string getDirectory(string filename);
  26. int mkdir_r(const char *dir, const mode_t mode);
  27. int removeFolder(const char* folderPath, const char* logTag);
  28. string toLower(string in);
  29. string toUpper(string in);
  30. float temperatureRead();
  31. std::string intToHexString(int _valueInt);
  32. time_t addDays(time_t startTime, int days);
  33. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
  34. std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
  35. ///////////////////////////
  36. struct ESPHeapStats
  37. {
  38. size_t totalFree;
  39. size_t externalFree;
  40. size_t externalLargestFreeBlock;
  41. size_t externalMinFree;
  42. size_t internalFree;
  43. size_t internalLargestFreeBlock;
  44. size_t internalMinFree;
  45. };
  46. ESPHeapStats getESPHeapStats();
  47. size_t getESPHeapSize();
  48. string getESPHeapInfo();
  49. struct SDCardDetails
  50. {
  51. bool cardAvailable;
  52. bool partitionAvailable;
  53. std::string manufacturer;
  54. std::string name;
  55. std::string capacityMB;
  56. std::string sectorSizeBytes;
  57. std::string partitionSizeMB;
  58. std::string partitionFreeMB;
  59. std::string partitionAllocationSizeBytes;
  60. };
  61. SDCardDetails getSDCardDetails();
  62. /////////////////////////////
  63. string getSDCardPartitionSize();
  64. string getSDCardFreePartitionSpace();
  65. string getSDCardPartitionAllocationSize();
  66. void SaveSDCardInfo(sdmmc_card_t* card);
  67. string SDCardParseManufacturerIDs(int);
  68. string getSDCardManufacturer();
  69. string getSDCardName();
  70. string getSDCardCapacity();
  71. string getSDCardSectorSize();
  72. /* Error bit fields
  73. One bit per error
  74. Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */
  75. enum SystemStatusFlag_t { // One bit per error
  76. // First Byte
  77. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  78. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  79. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  80. SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error
  81. SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error
  82. // Second Byte
  83. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
  84. SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
  85. };
  86. void setSystemStatusFlag(SystemStatusFlag_t flag);
  87. void clearSystemStatusFlag(SystemStatusFlag_t flag);
  88. int getSystemStatus(void);
  89. bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
  90. time_t getUpTime(void);
  91. string getResetReason(void);
  92. std::string getFormatedUptime(bool compact);
  93. const char* get404(void);
  94. std::string UrlDecode(const std::string& value);
  95. void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith);
  96. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith);
  97. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt);
  98. bool isInString(std::string& s, std::string const& toFind);
  99. bool isStringNumeric(std::string &input);
  100. bool isStringAlphabetic(std::string &input);
  101. bool isStringAlphanumeric(std::string &input);
  102. bool alphanumericToBoolean(std::string &input);
  103. int clipInt(int input, int high, int low);
  104. bool numericStrToBool(std::string input);
  105. bool stringToBoolean(std::string input);
  106. string getMac(void);
  107. #endif //HELPER_H