Helper.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 fn);
  14. bool RenameFile(string from, string to);
  15. bool MakeDir(std::string _what);
  16. bool FileExists(string filename);
  17. string RundeOutput(double _in, int _anzNachkomma);
  18. size_t findDelimiterPos(string input, string delimiter);
  19. //string trim(string istring);
  20. string trim(string istring, string adddelimiter = "");
  21. bool ctype_space(const char c, string adddelimiter);
  22. string getFileType(string filename);
  23. string getFileFullFileName(string filename);
  24. string getDirectory(string filename);
  25. int mkdir_r(const char *dir, const mode_t mode);
  26. int removeFolder(const char* folderPath, const char* logTag);
  27. string toLower(string in);
  28. string toUpper(string in);
  29. float temperatureRead();
  30. time_t addDays(time_t startTime, int days);
  31. void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
  32. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
  33. std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
  34. ///////////////////////////
  35. size_t getInternalESPHeapSize();
  36. size_t getESPHeapSize();
  37. string getESPHeapInfo();
  38. /////////////////////////////
  39. string getSDCardPartitionSize();
  40. string getSDCardFreePartitionSpace();
  41. string getSDCardPartitionAllocationSize();
  42. void SaveSDCardInfo(sdmmc_card_t* card);
  43. string SDCardParseManufacturerIDs(int);
  44. string getSDCardManufacturer();
  45. string getSDCardName();
  46. string getSDCardCapacity();
  47. string getSDCardSectorSize();
  48. string getMac(void);
  49. /* Error bit fields
  50. One bit per error
  51. Make sure it matches https://jomjol.github.io/AI-on-the-edge-device-docs/Error-Codes */
  52. enum SystemStatusFlag_t { // One bit per error
  53. // First Byte
  54. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  55. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  56. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  57. SYSTEM_STATUS_SDCARD_CHECK_BAD = 1 << 3, // 8, Critical Error
  58. SYSTEM_STATUS_FOLDER_CHECK_BAD = 1 << 4, // 16, Critical Error
  59. // Second Byte
  60. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
  61. SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
  62. };
  63. void setSystemStatusFlag(SystemStatusFlag_t flag);
  64. void clearSystemStatusFlag(SystemStatusFlag_t flag);
  65. int getSystemStatus(void);
  66. bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
  67. time_t getUpTime(void);
  68. string getResetReason(void);
  69. std::string getFormatedUptime(bool compact);
  70. const char* get404(void);
  71. std::string UrlDecode(const std::string& value);
  72. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith);
  73. bool replaceString(std::string& s, std::string const& toReplace, std::string const& replaceWith, bool logIt);
  74. bool isInString(std::string& s, std::string const& toFind);
  75. #endif //HELPER_H