Просмотр исходного кода

Implementation of DecimalShift

jomjol 5 лет назад
Родитель
Сommit
d70beb57fc

+ 6 - 1
README.md

@@ -29,8 +29,13 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 
 
 
 
 
-##### Rolling - (2020-09-12)
+##### Rolling - (2020-09-13)
 
 
+* Implementation of decimal shift (New Parameter "DecimalShift = 1" in [PostProcessing])
+DecimalShift = 1 --> Result: 123.456 --> 1234.56
+  DecimalShift = -1 --> Result: 12.3456
+  The shift is done at the very first step of merging digital and analog, so all following number already will work on the shifted number.
+  
 * based on v2.0.0 (2020-09-12)
 * based on v2.0.0 (2020-09-12)
 
 
   
   

+ 62 - 10
code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -135,6 +135,7 @@ ClassFlowPostProcessing::ClassFlowPostProcessing()
     PreValueOkay = false;
     PreValueOkay = false;
     useMaxRateValue = false;
     useMaxRateValue = false;
     checkDigitIncreaseConsistency = false;
     checkDigitIncreaseConsistency = false;
+    DecimalShift = 0;
     FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
     FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
 }
 }
 
 
@@ -148,11 +149,13 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector<ClassFlow*>* lfc)
     ListFlowControll = NULL;
     ListFlowControll = NULL;
     PreValueOkay = false;
     PreValueOkay = false;
     useMaxRateValue = false;
     useMaxRateValue = false;
-    checkDigitIncreaseConsistency = false;    
+    checkDigitIncreaseConsistency = false;
+    DecimalShift = 0;    
     FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
     FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
     ListFlowControll = lfc;
     ListFlowControll = lfc;
 }
 }
 
 
+
 bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
 bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
 {
 {
     std::vector<string> zerlegt;
     std::vector<string> zerlegt;
@@ -170,34 +173,39 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
     while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
     while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
     {
     {
         zerlegt = this->ZerlegeZeile(aktparamgraph);
         zerlegt = this->ZerlegeZeile(aktparamgraph);
-        if ((zerlegt[0] == "PreValueUse") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "DECIMALSHIFT") && (zerlegt.size() > 1))
         {
         {
-            if ((zerlegt[1] == "True") || (zerlegt[1] == "true"))
+            DecimalShift = stoi(zerlegt[1]);
+        }
+
+        if ((toUpper(zerlegt[0]) == "PREVALUEUSE") && (zerlegt.size() > 1))
+        {
+            if (toUpper(zerlegt[1]) == "TRUE")
             {
             {
                 PreValueUse = true;
                 PreValueUse = true;
                 PreValueOkay = LoadPreValue();
                 PreValueOkay = LoadPreValue();
             }
             }
         }
         }
-        if ((zerlegt[0] == "CheckDigitIncreaseConsistency") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
         {
         {
             if (toUpper(zerlegt[1]) == "TRUE")
             if (toUpper(zerlegt[1]) == "TRUE")
                 checkDigitIncreaseConsistency = true;
                 checkDigitIncreaseConsistency = true;
         }        
         }        
-        if ((zerlegt[0] == "AllowNegativeRates") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
         {
         {
             if (toUpper(zerlegt[1]) == "TRUE")
             if (toUpper(zerlegt[1]) == "TRUE")
                 AllowNegativeRates = true;
                 AllowNegativeRates = true;
         }
         }
-        if ((zerlegt[0] == "ErrorMessage") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "ERRORMESSAGE") && (zerlegt.size() > 1))
         {
         {
             if (toUpper(zerlegt[1]) == "TRUE")
             if (toUpper(zerlegt[1]) == "TRUE")
                 ErrorMessage = true;
                 ErrorMessage = true;
         }
         }
-        if ((zerlegt[0] == "PreValueAgeStartup") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
         {
         {
             PreValueAgeStartup = std::stoi(zerlegt[1]);
             PreValueAgeStartup = std::stoi(zerlegt[1]);
         }
         }
-        if ((zerlegt[0] == "MaxRateValue") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "MAXRATEVALUE") && (zerlegt.size() > 1))
         {
         {
             useMaxRateValue = true;
             useMaxRateValue = true;
             MaxRateValue = std::stof(zerlegt[1]);
             MaxRateValue = std::stof(zerlegt[1]);
@@ -206,6 +214,48 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
     return true;
     return true;
 }
 }
 
 
+string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
+
+    if (_decShift == 0){
+        return in;
+    }
+
+    int _pos_dec_org, _pos_dec_neu;
+
+    _pos_dec_org = findDelimiterPos(in, ".");
+    if (_pos_dec_org == std::string::npos) {
+        _pos_dec_org = in.length();
+    }
+    else
+    {
+        in = in.erase(_pos_dec_org, 1);
+    }
+    
+    _pos_dec_neu = _pos_dec_org + _decShift;
+
+    if (_pos_dec_neu <= 0) {        // Komma ist vor der ersten Ziffer
+        for (int i = 0; i > _pos_dec_neu; --i){
+            in = in.insert(0, "0");
+        }
+        in = "0." + in;
+        return in;
+    }
+
+    if (_pos_dec_neu > in.length()){    // Komma soll hinter String (123 --> 1230)
+        for (int i = in.length(); i < _pos_dec_neu; ++i){
+            in = in.insert(in.length(), "0");
+        }  
+        return in;      
+    }
+
+    string zw;
+    zw = in.substr(0, _pos_dec_neu);
+    zw = zw + ".";
+    zw = zw + in.substr(_pos_dec_neu, in.length() - _pos_dec_neu);
+
+    return zw;
+}
+
 bool ClassFlowPostProcessing::doFlow(string zwtime)
 bool ClassFlowPostProcessing::doFlow(string zwtime)
 {
 {
     string result = "";
     string result = "";
@@ -258,7 +308,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
     if (isdigit && isanalog)
     if (isdigit && isanalog)
         ReturnRawValue = ReturnRawValue + ".";
         ReturnRawValue = ReturnRawValue + ".";
     if (isanalog)
     if (isanalog)
-        ReturnRawValue = ReturnRawValue + analog;    
+        ReturnRawValue = ReturnRawValue + analog; 
+
+    ReturnRawValue = ShiftDecimal(ReturnRawValue, DecimalShift);   
 
 
     if (!PreValueUse || !PreValueOkay)
     if (!PreValueUse || !PreValueOkay)
     {
     {
@@ -374,7 +426,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, int lastvalueanalog = -1
     if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
     if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
     {
     {
         int zifferIST;
         int zifferIST;
-        int substrakt = 0;
+//        int substrakt = 0;
         bool lastcorrected = false;
         bool lastcorrected = false;
         for (int i = input.length() - 1; i >= 0; --i)
         for (int i = input.length() - 1; i >= 0; --i)
         {
         {

+ 2 - 0
code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h

@@ -16,6 +16,7 @@ protected:
     bool ErrorMessage;
     bool ErrorMessage;
     bool PreValueOkay;
     bool PreValueOkay;
     bool checkDigitIncreaseConsistency;
     bool checkDigitIncreaseConsistency;
+    int DecimalShift;
 
 
     string FilePreValue;
     string FilePreValue;
     float PreValue;             // letzter Wert, der gut ausgelesen wurde
     float PreValue;             // letzter Wert, der gut ausgelesen wurde
@@ -25,6 +26,7 @@ protected:
     string ReturnValueNoError;  // korrigierter Rückgabewert ohne Fehlermeldung
     string ReturnValueNoError;  // korrigierter Rückgabewert ohne Fehlermeldung
 
 
     bool LoadPreValue(void);
     bool LoadPreValue(void);
+    string ShiftDecimal(string in, int _decShift);
 
 
     string ErsetzteN(string, int lastvalueanalog);
     string ErsetzteN(string, int lastvalueanalog);
 
 

BIN
firmware/firmware.bin


BIN
firmware/html.zip


+ 1 - 0
sd-card/config/config.ini

@@ -31,6 +31,7 @@ analog3, 294, 369, 92, 92
 analog4, 168, 326, 92, 92
 analog4, 168, 326, 92, 92
 
 
 [PostProcessing]
 [PostProcessing]
+DecimalShift = 0
 PreValueUse = True
 PreValueUse = True
 PreValueAgeStartup = 30
 PreValueAgeStartup = 30
 AllowNegativeRates = False
 AllowNegativeRates = False