diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 661ce729..64dc63cc 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -127,6 +127,35 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } + +string ClassFlowCNNGeneral::getReadoutRawString(int _analog) +{ + string rt = ""; + + if (GENERAL[_analog]->ROI.size() == 0) + return rt; + + for (int i = GENERAL[_analog]->ROI.size() - 1; i >= 0; --i) + { + if (CNNType == Analogue || CNNType == Analogue100) + { + rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_float); + } + + if (CNNType == Digital) + { + rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_klasse); + } + + if ((CNNType == DoubleHyprid10) || (CNNType == Digital100)) + { + rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_float); + } + } + return rt; +} + + int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger) { int result; diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 055df5e3..20b9ea8f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -58,7 +58,9 @@ public: bool doFlow(string time); string getHTMLSingleStep(string host); - string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1); + string getReadout(int _analog, bool _extendedResolution = false, int prev = -1, float _vorgaengerAnalog = -1); + + string getReadoutRawString(int _analog); void DrawROI(CImageBasis *_zw); diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index e0b900eb..8990b687 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -803,12 +803,26 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) string _zw = "PostProcessing - Raw: " + NUMBERS[j]->ReturnRawValue + " Value: " + NUMBERS[j]->ReturnValue + " Error: " + NUMBERS[j]->ErrorMessageText; LogFile.WriteToFile(_zw); + WriteDataLog(j); } SavePreValue(); return true; } +void ClassFlowPostProcessing::WriteDataLog(int _analog) +{ + string analog = ""; + string digital = ""; + if (flowAnalog) + analog = flowAnalog->getReadout(_analog); + if (flowDigit) + digital = flowDigit->getReadout(_analog); +// LogFile.WriteToFile(analog); + LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ErrorMessageText, digital, analog); + +} + void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() { @@ -989,3 +1003,5 @@ string ClassFlowPostProcessing::getReadoutError(int _number) { return NUMBERS[_number]->ErrorMessageText; } + + diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 9d63804b..66e1d0bc 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -42,6 +42,10 @@ protected: void handleDecimalExtendedResolution(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value); + std::string GetStringReadouts(general); + + void WriteDataLog(int _analog); + diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 3d3605d9..826d3c4f 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -16,7 +16,7 @@ extern "C" { static const char *TAG = "log"; -ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt"); +ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt", "/sdcard/log/data", "data_%Y-%m-%d.txt"); void ClassLogFile::WriteHeapInfo(std::string _id) { @@ -62,6 +62,59 @@ std::string ClassLogFile::getESPHeapInfo(){ return espInfoResultStr; } +void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ErrorMessageText, std::string _digital, std::string _analog) +{ + time_t rawtime; + struct tm* timeinfo; + char buffer[30]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 30, datafile.c_str(), timeinfo); + std::string logpath = dataroot + "/" + buffer; + + FILE* pFile; + std::string zwtime; + + if (!doLogFile){ + return; + } + + pFile = fopen(logpath.c_str(), "a+"); + + if (pFile!=NULL) { + time_t rawtime; + struct tm* timeinfo; + char buffer[80]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo); + + zwtime = std::string(buffer) + ":"; + fputs(zwtime.c_str(), pFile); + fputs(_ReturnRawValue.c_str(), pFile); + fputs("\t", pFile); + fputs(_ReturnValue.c_str(), pFile); + fputs("\t", pFile); + fputs(_ErrorMessageText.c_str(), pFile); + fputs("\t", pFile); + fputs(_digital.c_str(), pFile); + fputs("\t", pFile); + fputs(_analog.c_str(), pFile); + fputs("\t", pFile); + fputs("\n", pFile); + + fclose(pFile); + } else { + ESP_LOGI(TAG, "Can't open data file %s", logpath.c_str()); + } + +} + + void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool _time) { FILE* pFile; @@ -161,6 +214,8 @@ void ClassLogFile::RemoveOld() rawtime = addDays(rawtime, -retentionInDays); timeinfo = localtime(&rawtime); + +////////////////////// message ///////////////////////////////////////// strftime(cmpfilename, 30, logfile.c_str(), timeinfo); //ESP_LOGE(TAG, "log file name to compare: %s", cmpfilename); @@ -191,12 +246,46 @@ void ClassLogFile::RemoveOld() } ESP_LOGI(TAG, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); closedir(dir); + + +////////////////////// data ///////////////////////////////////////// + strftime(cmpfilename, 30, datafile.c_str(), timeinfo); + //ESP_LOGE(TAG, "log file name to compare: %s", cmpfilename); + + dir = opendir(dataroot.c_str()); + if (!dir) { + ESP_LOGI(TAG, "Failed to stat dir : %s", dataroot.c_str()); + return; + } + + deleted = 0; + notDeleted = 0; + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_REG) { + //ESP_LOGI(TAG, "list log file : %s %s", entry->d_name, cmpfilename); + if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) { + ESP_LOGI(TAG, "delete data file : %s", entry->d_name); + std::string filepath = logroot + "/" + entry->d_name; + if (unlink(filepath.c_str()) == 0) { + deleted ++; + } else { + ESP_LOGE(TAG, "can't delete file : %s", entry->d_name); + } + } else { + notDeleted ++; + } + } + } + ESP_LOGI(TAG, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + closedir(dir); } -ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile) +ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::string _logdatapath, std::string _datafile) { logroot = _logroot; logfile = _logfile; + datafile = _datafile; + dataroot = _logdatapath; doLogFile = true; retentionInDays = 10; loglevel = 0; diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h index 02401ab6..2a722c6c 100644 --- a/code/components/jomjol_logfile/ClassLogFile.h +++ b/code/components/jomjol_logfile/ClassLogFile.h @@ -7,11 +7,13 @@ class ClassLogFile private: std::string logroot; std::string logfile; + std::string dataroot; + std::string datafile; bool doLogFile; unsigned short retentionInDays; int loglevel; public: - ClassLogFile(std::string _logpath, std::string _logfile); + ClassLogFile(std::string _logpath, std::string _logfile, std::string _logdatapath, std::string _datafile); std::string getESPHeapInfo(); @@ -26,6 +28,9 @@ public: void WriteToDedicatedFile(std::string _fn, std::string info, bool _time = true); void RemoveOld(); + void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); + + std::string GetCurrentFileName(); };