Helper.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include "sdmmc_cmd.h"
  6. using namespace std;
  7. std::string FormatFileName(std::string input);
  8. std::size_t file_size(const std::string& file_name);
  9. void FindReplace(std::string& line, std::string& oldString, std::string& newString);
  10. bool CopyFile(string input, string output);
  11. bool DeleteFile(string fn);
  12. bool RenameFile(string from, string to);
  13. bool MakeDir(std::string _what);
  14. string RundeOutput(double _in, int _anzNachkomma);
  15. FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1, bool silent = true);
  16. size_t findDelimiterPos(string input, string delimiter);
  17. //string trim(string istring);
  18. string trim(string istring, string adddelimiter = "");
  19. bool ctype_space(const char c, string adddelimiter);
  20. string getFileType(string filename);
  21. string getFileFullFileName(string filename);
  22. string getDirectory(string filename);
  23. int mkdir_r(const char *dir, const mode_t mode);
  24. int removeFolder(const char* folderPath, const char* logTag);
  25. string toLower(string in);
  26. string toUpper(string in);
  27. float temperatureRead();
  28. time_t addDays(time_t startTime, int days);
  29. void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
  30. std::vector<string> HelperZerlegeZeile(std::string input, std::string _delimiter);
  31. std::vector<std::string> ZerlegeZeile(std::string input, std::string delimiter = " =, \t");
  32. ///////////////////////////
  33. size_t getInternalESPHeapSize();
  34. size_t getESPHeapSize();
  35. string getESPHeapInfo();
  36. /////////////////////////////
  37. string getSDCardPartitionSize();
  38. string getSDCardFreePartitionSpace();
  39. string getSDCardPartitionAllocationSize();
  40. void SaveSDCardInfo(sdmmc_card_t* card);
  41. string SDCardParseManufacturerIDs(int);
  42. string getSDCardManufacturer();
  43. string getSDCardName();
  44. string getSDCardCapacity();
  45. string getSDCardSectorSize();
  46. string getMac(void);
  47. /* Error bit fields
  48. One bit per error
  49. Make sure it matches https://github.com/jomjol/AI-on-the-edge-device/wiki/Error-Codes */
  50. enum SystemStatusFlag_t { // One bit per error
  51. // First Byte
  52. SYSTEM_STATUS_PSRAM_BAD = 1 << 0, // 1, Critical Error
  53. SYSTEM_STATUS_HEAP_TOO_SMALL = 1 << 1, // 2, Critical Error
  54. SYSTEM_STATUS_CAM_BAD = 1 << 2, // 4, Critical Error
  55. // Second Byte
  56. SYSTEM_STATUS_CAM_FB_BAD = 1 << (0+8), // 8, Flow still might work
  57. SYSTEM_STATUS_NTP_BAD = 1 << (1+8), // 9, Flow will work but time will be wrong
  58. };
  59. void setSystemStatusFlag(SystemStatusFlag_t flag);
  60. void clearSystemStatusFlag(SystemStatusFlag_t flag);
  61. int getSystemStatus(void);
  62. bool isSetSystemStatusFlag(SystemStatusFlag_t flag);
  63. string getResetReason(void);
  64. std::string getFormatedUptime(bool compact);
  65. const char* get404(void);