Helper.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. bool FolderExists(string foldername);
  19. string RundeOutput(double _in, int _anzNachkomma);
  20. size_t findDelimiterPos(string input, string delimiter);
  21. //string trim(string istring);
  22. string trim(string istring, string adddelimiter = "");
  23. bool ctype_space(const char c, string adddelimiter);
  24. string getFileType(string filename);
  25. string getFileFullFileName(string filename);
  26. string getDirectory(string filename);
  27. int mkdir_r(const char *dir, const mode_t mode);
  28. int removeFolder(const char* folderPath, const char* logTag);
  29. string toLower(string in);
  30. string toUpper(string in);
  31. float temperatureRead();
  32. std::string intToHexString(int _valueInt);
  33. time_t addDays(time_t startTime, int days);
  34. bool copy_string(char *dst, size_t dst_size, const char *src);
  35. void mem_copy(uint8_t *_target, uint8_t *_source, int _size);
  36. void mem_copy32(void *_target, const void *_source, size_t size);
  37. float fast_atan2(float y, float x);
  38. double pow10_double(int pot); // faster than pow(10, pot)
  39. uint32_t pow10_int(int pot); // faster than pow(10, pot)
  40. void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
  41. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
  42. std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
  43. ///////////////////////////
  44. size_t getInternalESPHeapSize();
  45. size_t getESPHeapSize();
  46. string getESPHeapInfo();
  47. /////////////////////////////
  48. string getSDCardPartitionSize();
  49. string getSDCardFreePartitionSpace();
  50. string getSDCardPartitionAllocationSize();
  51. void SaveSDCardInfo(sdmmc_card_t* card);
  52. string SDCardParseManufacturerIDs(int);
  53. string getSDCardManufacturer();
  54. string getSDCardName();
  55. string getSDCardCapacity();
  56. string getSDCardSectorSize();
  57. string getMac(void);
  58. /* Error bit fields
  59. One bit per error
  60. Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */
  61. enum SystemStatusFlag_t { // One bit per error
  62. // First Byte
  63. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  64. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  65. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  66. SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error
  67. SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error
  68. // Second Byte
  69. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
  70. SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
  71. };
  72. void setSystemStatusFlag(SystemStatusFlag_t flag);
  73. void clearSystemStatusFlag(SystemStatusFlag_t flag);
  74. int getSystemStatus(void);
  75. bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
  76. time_t getUpTime(void);
  77. string getResetReason(void);
  78. std::string getFormatedUptime(bool compact);
  79. const char* get404(void);
  80. std::string UrlDecode(const std::string& value);
  81. void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith);
  82. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith);
  83. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt);
  84. bool isInString(std::string& s, std::string const& toFind);
  85. bool isStringNumeric(std::string &input);
  86. bool isStringAlphabetic(std::string &input);
  87. bool isStringAlphanumeric(std::string &input);
  88. bool alphanumericToBoolean(std::string &input);
  89. int clipInt(int input, int high, int low);
  90. bool numericStrToBool(std::string input);
  91. bool stringToBoolean(std::string input);
  92. #endif //HELPER_H