Răsfoiți Sursa

Implement data log

jomjol 3 ani în urmă
părinte
comite
8d4fb74173

+ 44 - 54
code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp

@@ -127,36 +127,7 @@ 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 ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger, float digitalAnalogTransitionStart)
 {
     int result;
     int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
@@ -237,12 +208,21 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor
     int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10;
     bool roundedUp = false;
 
-    if (ziffer_vorgaenger < 0)
-    {
-        result = (int) floor(zahl);
-        if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - kein Vorgänger - Ergebnis = " + std::to_string(result) +
-                                                    " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " AnalogFehler = " +  std::to_string(AnalogFehler));
-        return result;
+    // Innerhalb der digitalen Unschaefe 
+    if (ergebnis_nachkomma >= (10-DigitalUnschaerfe * 10))  {   // Band um die Ziffer --> Runden, da Ziffer im Rahmen Ungenauigkeit erreicht
+        result = (int) (round(zahl) + 10) % 10;
+        roundedUp = true;
+        // vor/nachkomma neu berechnen, da wir anhand der Unschaefe die Zahl anpassen.
+        ergebnis_nachkomma = ((int) floor(result * 10)) % 10;
+        ergebnis_vorkomma = ((int) floor(result) + 10) % 10;
+        if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - digitaleUnschaerfe - Ergebnis = " + std::to_string(result) +
+                                                    " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger: " + std::to_string(ziffer_vorgaenger) +
+                                                    " erg_vorkomma: " + std::to_string(ergebnis_vorkomma) + 
+                                                    " erg_nachkomma: " + std::to_string(ergebnis_nachkomma));
+    } else {
+        result = (int) ((int) trunc(zahl) + 10) % 10;
+        if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - KEINE digitaleUnschaerfe - Ergebnis = " + std::to_string(result) +
+                                                    " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger));
     }
 
     // Kein Nulldurchgang hat stattgefunden.
@@ -260,24 +240,6 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor
                                     " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + 
                                     " erg_nachkomma = " +  std::to_string(ergebnis_nachkomma));
 
-    // Vorlauf ziffer_vorgaenger <=9.9 und ergebnis_nachkomma >=0..1 (digits drehen nach umschalten nicht gleich weiter)
-    // Beispiel dig=4.0, ana=9.1 ==> dig=3
-
-    // Nachlauf ziffer_vorgaenger 0..2 und ergebnis_nachkomma 8..9
-    // Beispiel dig=6.8, ana=2.2 ==> dig=7
-    // dig=4.8, ana=5.5 => dig=4
-
-    // Vorlauf bei ergebnis_nachkomma >=0..1 und ziffer_vorgaenger 8..9
-    if (ergebnis_nachkomma <= 1 &&  ziffer_vorgaenger>=8)  {
-        result =  (ergebnis_vorkomma - 1 + 10) % 10;
-    } else {
-        // Ziffer bleibt bei x.8 oder x.9 "hängen", kommt also nicht richtig auf x.0
-        // muss eine Rundung erfolgen
-        // jedoch nicht im während der Transition (ziffer_vorgaenger>=8)
-         if (eval_vorgaenger<9 && ziffer_vorgaenger<8 && ergebnis_nachkomma >= 8)   
-            result = ((int) round(zahl) + 10) % 10;
-        else
-            result = ergebnis_vorkomma;
     }
 
     return result;
@@ -1008,3 +970,31 @@ void ClassFlowCNNGeneral::UpdateNameNumbers(std::vector<std::string> *_name_numb
             (*_name_numbers).push_back(_name);
     }
 }
+
+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;
+}
+

+ 11 - 6
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -362,7 +362,7 @@ void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep,
         if (_digit == "default" || NUMBERS[j]->name == _digit)  // erstmal auf default setzen (falls sonst nichts gesetzt)
         {
             NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc;
-            
+
         }
     }
 }
@@ -399,6 +399,7 @@ void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value)
 
 
 
+
 void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
 {
     string _digit, _decpos;
@@ -408,11 +409,9 @@ void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
         _digit = _decsep.substr(0, _pospunkt);
     else
         _digit = "default";
-
     for (int j = 0; j < NUMBERS.size(); ++j)
     {
         float _zwdc = 1;
-
 //        try
         {
             _zwdc = stof(_value);
@@ -422,13 +421,11 @@ void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value)
             printf("ERROR - MaxRateValue is not a number: %s\n", _value.c_str());
         }
 */
-
         if (_digit == "default")                        // erstmal auf default setzen (falls sonst nichts gesetzt)
         {
             NUMBERS[j]->useMaxRateValue = true;
             NUMBERS[j]->MaxRateValue = _zwdc;
         }
-
         if (NUMBERS[j]->name == _digit)
         {
             NUMBERS[j]->useMaxRateValue = true;
@@ -727,9 +724,14 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
         if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
         {
             if (PreValueUse && NUMBERS[j]->PreValueOkay)
+            {
                 NUMBERS[j]->ReturnValue = ErsetzteN(NUMBERS[j]->ReturnValue, NUMBERS[j]->PreValue); 
+            }
             else
+            {
+                WriteDataLog(j);
                 continue; // es gibt keinen Zahl, da noch ein N vorhanden ist.
+            }
         }
         #ifdef SERIAL_DEBUG
             printf("After findDelimiterPos: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str());  
@@ -784,6 +786,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
                     NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + " "; 
                     NUMBERS[j]->Value = NUMBERS[j]->PreValue;
                     NUMBERS[j]->ReturnValue = "";
+                    WriteDataLog(j);
                     continue;
                 }
                 
@@ -811,6 +814,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
                 NUMBERS[j]->Value = NUMBERS[j]->PreValue;
                 NUMBERS[j]->ReturnValue = "";
                 NUMBERS[j]->ReturnRateValue = "";
+                WriteDataLog(j);
                 continue;
             }
         }
@@ -830,6 +834,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
         UpdatePreValueINI = true;
 
         string _zw = "PostProcessing - Raw: " + NUMBERS[j]->ReturnRawValue + " Value: " + NUMBERS[j]->ReturnValue + " Error: " + NUMBERS[j]->ErrorMessageText;
+        printf("%s\n", zw.c_str());
         LogFile.WriteToFile(_zw);
         WriteDataLog(j);
     }
@@ -848,7 +853,7 @@ void ClassFlowPostProcessing::WriteDataLog(int _analog)
         digital = flowDigit->getReadout(_analog);
 //    LogFile.WriteToFile(analog);
     LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ErrorMessageText, digital, analog);
-
+    printf("WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_analog]->ReturnRawValue.c_str(), NUMBERS[_analog]->ReturnValue.c_str(), NUMBERS[_analog]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str());
 }
 
 

+ 7 - 0
code/components/jomjol_helper/Helper.cpp

@@ -154,6 +154,13 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
     }
 }
 
+void MakeDir(std::string _what)
+{
+//	chdir(_where.c_str());
+
+	if (mkdir(_what.c_str(), S_IRWXU|S_IRWXG|S_IROTH))
+		printf("Problem with MakeDir: %s \n", _what.c_str());
+}
 
 
 

+ 2 - 0
code/components/jomjol_helper/Helper.h

@@ -12,6 +12,8 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
 void CopyFile(string input, string output);
 void DeleteFile(string fn);
 void RenameFile(string from, string to);
+void MakeDir(std::string _what);
+
 
 
 FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1);

+ 5 - 0
code/components/jomjol_logfile/ClassLogFile.cpp

@@ -64,6 +64,7 @@ std::string ClassLogFile::getESPHeapInfo(){
 
 void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ErrorMessageText, std::string _digital, std::string _analog)
 {
+    printf("Start WriteToData\n");
     time_t rawtime;
     struct tm* timeinfo;
     char buffer[30];
@@ -81,6 +82,7 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV
         return;
     }
 
+    printf("Datalogfile: %s\n", logpath.c_str());
     pFile = fopen(logpath.c_str(), "a+");
 
     if (pFile!=NULL) {
@@ -290,4 +292,7 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri
     doLogFile = true;
     retentionInDays = 10;
     loglevel = 0;
+    MakeDir("/sdcard/log/data");
+    MakeDir("/sdcard/test");
+    MakeDir("/test");
 }