Helper.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
  35. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
  36. std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
  37. ///////////////////////////
  38. size_t getInternalESPHeapSize();
  39. size_t getESPHeapSize();
  40. string getESPHeapInfo();
  41. /////////////////////////////
  42. string getSDCardPartitionSize();
  43. string getSDCardFreePartitionSpace();
  44. string getSDCardPartitionAllocationSize();
  45. void SaveSDCardInfo(sdmmc_card_t* card);
  46. string SDCardParseManufacturerIDs(int);
  47. string getSDCardManufacturer();
  48. string getSDCardName();
  49. string getSDCardCapacity();
  50. string getSDCardSectorSize();
  51. string getMac(void);
  52. /* Error bit fields
  53. One bit per error
  54. Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */
  55. enum SystemStatusFlag_t { // One bit per error
  56. // First Byte
  57. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  58. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  59. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  60. SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error
  61. SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error
  62. // Second Byte
  63. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
  64. SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
  65. };
  66. void setSystemStatusFlag(SystemStatusFlag_t flag);
  67. void clearSystemStatusFlag(SystemStatusFlag_t flag);
  68. int getSystemStatus(void);
  69. bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
  70. time_t getUpTime(void);
  71. string getResetReason(void);
  72. std::string getFormatedUptime(bool compact);
  73. const char* get404(void);
  74. std::string UrlDecode(const std::string& value);
  75. void replaceAll(std::string& s, const std::string& toReplace, const std::string& replaceWith);
  76. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith);
  77. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt);
  78. bool isInString(std::string& s, std::string const& toFind);
  79. bool isStringNumeric(std::string &input);
  80. bool isStringAlphabetic(std::string &input);
  81. bool isStringAlphanumeric(std::string &input);
  82. bool alphanumericToBoolean(std::string &input);
  83. int clipInt(int input, int high, int low);
  84. bool numericStrToBool(std::string input);
  85. bool stringToBoolean(std::string input);
  86. #endif //HELPER_H