diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 4cfba7288..a137d97dd 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -39,52 +39,59 @@ unsigned int systemStatus = 0; sdmmc_cid_t SDCardCid; sdmmc_csd_t SDCardCsd; + +// #define DEBUG_DETAIL_ON + ///////////////////////////////////////////////////////////////////////////////////////////// string getESPHeapInfo(){ string espInfoResultStr = ""; char aMsgBuf[80]; - - multi_heap_info_t aMultiHead_info ; - heap_caps_get_info (&aMultiHead_info,MALLOC_CAP_8BIT); + size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); - size_t aMinFreeHeadSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT); - size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT); - size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT); - sprintf(aMsgBuf," Free Heap Size: %ld", (long) aFreeHeapSize); - size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM); - size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); - size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); - - sprintf(aMsgBuf," Heap: %ld", (long) aFreeHeapSize); + + size_t aFreeSPIHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aHeapIntLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + size_t aMinFreeHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM); + size_t aMinFreeInternalHeapSize = heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL); + + + sprintf(aMsgBuf,"Heap Total: %ld", (long) aFreeHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," Min Free: %ld", (long) aMinFreeHeapSize); + + sprintf(aMsgBuf," | SPI Free: %ld", (long) aFreeSPIHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," larg. Block: %ld", (long) aHeapLargestFreeBlockSize); + sprintf(aMsgBuf," | SPI Larg Block: %ld", (long) aHeapLargestFreeBlockSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," SPI Heap: %ld", (long) aFreeSPIHeapSize); + sprintf(aMsgBuf," | SPI Min Free: %ld", (long) aMinFreeHeapSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," Min Free Heap Size: %ld", (long) aMinFreeHeadSize); - sprintf(aMsgBuf," NOT_SPI Heap: %ld", (long) (aFreeHeapSize - aFreeSPIHeapSize)); + + sprintf(aMsgBuf," | Int Free: %ld", (long) (aFreeInternalHeapSize)); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," largest Block Size: %ld", (long) aHeapLargestFreeBlockSize); - sprintf(aMsgBuf," Internal Heap: %ld", (long) (aFreeInternalHeapSize)); + sprintf(aMsgBuf," | Int Larg Block: %ld", (long) aHeapIntLargestFreeBlockSize); espInfoResultStr += string(aMsgBuf); - sprintf(aMsgBuf," Internal Min Heap free: %ld", (long) (aMinFreeInternalHeapSize)); + sprintf(aMsgBuf," | Int Min Free: %ld", (long) (aMinFreeInternalHeapSize)); espInfoResultStr += string(aMsgBuf); + return espInfoResultStr; } -size_t getESPHeapSize(){ - size_t aFreeHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT); - return aFreeHeapSize; +size_t getESPHeapSize() +{ + return heap_caps_get_free_size(MALLOC_CAP_8BIT); } -size_t getInternalESPHeapSize() { - size_t aFreeInternalHeapSize = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); - return aFreeInternalHeapSize; + +size_t getInternalESPHeapSize() +{ + return heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL); } + string getSDCardPartitionSize(){ FATFS *fs; uint32_t fre_clust, tot_sect; @@ -98,6 +105,7 @@ string getSDCardPartitionSize(){ return std::to_string(tot_sect); } + string getSDCardFreePartitionSpace(){ FATFS *fs; uint32_t fre_clust, fre_sect; @@ -111,6 +119,7 @@ string getSDCardFreePartitionSpace(){ return std::to_string(fre_sect); } + string getSDCardPartitionAllocationSize(){ FATFS *fs; uint32_t fre_clust, allocation_size; @@ -130,6 +139,7 @@ void SaveSDCardInfo(sdmmc_card_t* card) { SDCardCsd = card->csd; } + string getSDCardManufacturer(){ string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); //ESP_LOGD(TAG, "SD Card Manufacturer: %s", SDCardManufacturer.c_str()); @@ -137,6 +147,7 @@ string getSDCardManufacturer(){ return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); } + string getSDCardName(){ char *SDCardName = SDCardCid.name; //ESP_LOGD(TAG, "SD Card Name: %s", SDCardName); @@ -144,6 +155,7 @@ string getSDCardName(){ return std::string(SDCardName); } + string getSDCardCapacity(){ int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) //ESP_LOGD(TAG, "SD Card Capacity: %s", std::to_string(SDCardCapacity).c_str()); @@ -151,6 +163,7 @@ string getSDCardCapacity(){ return std::to_string(SDCardCapacity); } + string getSDCardSectorSize(){ int SDCardSectorSize = SDCardCsd.sector_size; //ESP_LOGD(TAG, "SD Card Sector Size: %s bytes", std::to_string(SDCardSectorSize).c_str()); @@ -210,6 +223,7 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri } } + bool MakeDir(std::string _what) { int mk_ret = mkdir(_what.c_str(), 0775); @@ -222,7 +236,6 @@ bool MakeDir(std::string _what) } - bool ctype_space(const char c, string adddelimiter) { if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == 11) @@ -235,6 +248,7 @@ bool ctype_space(const char c, string adddelimiter) return false; } + string trim(string istring, string adddelimiter) { bool trimmed = false; @@ -261,6 +275,7 @@ string trim(string istring, string adddelimiter) } } + size_t findDelimiterPos(string input, string delimiter) { size_t pos = std::string::npos; @@ -301,6 +316,7 @@ bool RenameFile(string from, string to) return true; } + bool FileExists(string filename) { FILE* fpSourceFile = fopen(filename.c_str(), "rb"); @@ -367,6 +383,7 @@ bool CopyFile(string input, string output) return true; } + string getFileFullFileName(string filename) { size_t lastpos = filename.find_last_of('/'); @@ -381,6 +398,7 @@ string getFileFullFileName(string filename) return zw; } + string getDirectory(string filename) { size_t lastpos = filename.find('/'); @@ -397,6 +415,7 @@ string getDirectory(string filename) return zw; } + string getFileType(string filename) { size_t lastpos = filename.rfind(".", filename.length()); @@ -415,6 +434,7 @@ string getFileType(string filename) return zw; } + /* recursive mkdir */ int mkdir_r(const char *dir, const mode_t mode) { char tmp[FILE_PATH_MAX]; @@ -472,6 +492,7 @@ int mkdir_r(const char *dir, const mode_t mode) { return 0; } + string toUpper(string in) { for (int i = 0; i < in.length(); ++i) @@ -480,6 +501,7 @@ string toUpper(string in) return in; } + string toLower(string in) { for (int i = 0; i < in.length(); ++i) @@ -488,6 +510,7 @@ string toLower(string in) return in; } + // CPU Temp extern "C" uint8_t temprature_sens_read(); float temperatureRead() @@ -495,12 +518,14 @@ float temperatureRead() return (temprature_sens_read() - 32) / 1.8; } + time_t addDays(time_t startTime, int days) { struct tm* tm = localtime(&startTime); tm->tm_mday += days; return mktime(tm); } + int removeFolder(const char* folderPath, const char* logTag) { //ESP_LOGD(logTag, "Delete content in path %s", folderPath); @@ -548,7 +573,6 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter } - std::vector ZerlegeZeile(std::string input, std::string delimiter) { std::vector Output; @@ -612,6 +636,7 @@ struct SDCard_Manufacturer_database { string manufacturer; }; + /* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ /* SD Card Manufacturer Database */ struct SDCard_Manufacturer_database database[] = { @@ -722,6 +747,7 @@ struct SDCard_Manufacturer_database database[] = { } }; + /* Parse SD Card Manufacturer Database */ string SDCardParseManufacturerIDs(int id) { @@ -784,6 +810,7 @@ void setSystemStatusFlag(SystemStatusFlag_t flag) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); } + void clearSystemStatusFlag(SystemStatusFlag_t flag) { systemStatus = systemStatus | ~flag; // clear bit @@ -792,10 +819,12 @@ void clearSystemStatusFlag(SystemStatusFlag_t flag) { LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "New System Status: " + std::string(buf)); } + int getSystemStatus(void) { return systemStatus; } + bool isSetSystemStatusFlag(SystemStatusFlag_t flag) { //ESP_LOGE(TAG, "Flag (0x%08X) is set (0x%08X): %d", flag, systemStatus , ((systemStatus & flag) == flag)); @@ -835,6 +864,7 @@ string getResetReason(void) { return reasonText; } + /** * Returns the current uptime formated ad xxf xxh xxm [xxs] */ @@ -859,6 +889,7 @@ std::string getFormatedUptime(bool compact) { return std::string(buf); } + const char* get404(void) { return "
\n\n\n\n"
diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp
index 0a10e057c..e92ddbd53 100644
--- a/code/components/jomjol_logfile/ClassLogFile.cpp
+++ b/code/components/jomjol_logfile/ClassLogFile.cpp
@@ -21,50 +21,16 @@ static const char *TAG = "LOGFILE";
 
 ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt", "/sdcard/log/data", "data_%Y-%m-%d.csv");
 
+
 void ClassLogFile::WriteHeapInfo(std::string _id)
 {
-    std::string _zw = _id;
     if (loglevel >= ESP_LOG_DEBUG) {
-        _zw =  _zw + "\t" + getESPHeapInfo();
+        std::string _zw =  _id + "\t" + getESPHeapInfo();
         WriteToFile(ESP_LOG_DEBUG, "HEAP", _zw);
     }
 }
 
 
-std::string ClassLogFile::getESPHeapInfo(){
-	string espInfoResultStr = "";
-	char aMsgBuf[80];
-    
-	multi_heap_info_t aMultiHead_info ;
-	heap_caps_get_info (&aMultiHead_info,MALLOC_CAP_8BIT);
-	size_t aFreeHeapSize  = heap_caps_get_free_size(MALLOC_CAP_8BIT);
-	size_t aMinFreeHeadSize =  heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
-	size_t aMinFreeHeapSize =  heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT);
-	size_t aHeapLargestFreeBlockSize = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT);
-	sprintf(aMsgBuf,"Free Heap Size: \t%ld", (long) aFreeHeapSize);
-	size_t aFreeSPIHeapSize  = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_SPIRAM);
- 	size_t aFreeInternalHeapSize  = heap_caps_get_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
-	size_t aMinFreeInternalHeapSize =  heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT| MALLOC_CAP_INTERNAL);
-
-	sprintf(aMsgBuf,"\tHeap:\t%ld", (long) aFreeHeapSize);
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tMin Free:\t%ld", (long) aMinFreeHeapSize);
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tlarg. Block: \t%ld", (long) aHeapLargestFreeBlockSize);
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tSPI Heap:\t%ld", (long) aFreeSPIHeapSize);
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tMin Free Heap Size:\t%ld", (long) aMinFreeHeadSize);
-	sprintf(aMsgBuf,"\tNOT_SPI Heap:\t%ld", (long) (aFreeHeapSize - aFreeSPIHeapSize));
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tlargest Block Size: \t%ld", (long) aHeapLargestFreeBlockSize);
-	sprintf(aMsgBuf,"\tInternal Heap:\t%ld", (long) (aFreeInternalHeapSize));
-	espInfoResultStr += string(aMsgBuf);
-	sprintf(aMsgBuf,"\tInternal Min Heap free:\t%ld", (long) (aMinFreeInternalHeapSize));
-	espInfoResultStr += string(aMsgBuf);
-	return 	espInfoResultStr;
-}
-
 void ClassLogFile::WriteToData(std::string _timestamp, std::string _name, std::string  _ReturnRawValue, std::string  _ReturnValue, std::string  _ReturnPreValue, std::string  _ReturnRateValue, std::string  _ReturnChangeAbsolute, std::string  _ErrorMessageText, std::string  _digital, std::string  _analog)
 {
     ESP_LOGD(TAG, "Start WriteToData");
@@ -145,26 +111,30 @@ void ClassLogFile::setLogLevel(esp_log_level_t _logLevel){
     */
 }
 
+
 void ClassLogFile::SetLogFileRetention(unsigned short _LogFileRetentionInDays){
     logFileRetentionInDays = _LogFileRetentionInDays;
 }
 
+
 void ClassLogFile::SetDataLogRetention(unsigned short _DataLogRetentionInDays){
     dataLogRetentionInDays = _DataLogRetentionInDays;
 }
 
+
 void ClassLogFile::SetDataLogToSD(bool _doDataLogToSD){
     doDataLogToSD = _doDataLogToSD;
 }
 
+
 bool ClassLogFile::GetDataLogToSD(){
     return doDataLogToSD;
 }
 
+
 static FILE* logFileAppendHandle = NULL;
 std::string fileNameDate;
 
-
 void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::string message, bool _time)
 {
     time_t rawtime;
@@ -280,6 +250,7 @@ void ClassLogFile::WriteToFile(esp_log_level_t level, std::string tag, std::stri
     LogFile.WriteToFile(level, tag, message, true);
 }
 
+
 std::string ClassLogFile::GetCurrentFileNameData()
 {
     time_t rawtime;
@@ -311,6 +282,7 @@ std::string ClassLogFile::GetCurrentFileName()
     return logpath;
 }
 
+
 void ClassLogFile::RemoveOldLogFile()
 {
     if (logFileRetentionInDays == 0) {
diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h
index 7f663f8ae..b21e8a662 100644
--- a/code/components/jomjol_logfile/ClassLogFile.h
+++ b/code/components/jomjol_logfile/ClassLogFile.h
@@ -22,8 +22,6 @@ class ClassLogFile
 public:
     ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile);
 
-    std::string getESPHeapInfo();
-
     void WriteHeapInfo(std::string _id);
 
     void setLogLevel(esp_log_level_t _logLevel);