From f91f5e3cba24e04aeb90f2d77299c64e116667cb Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:29:35 +0200 Subject: [PATCH 01/44] rewrite of ZeigerEvalAnalogToDigitNeu added explizit test-cases for it. --- .../ClassFlowCNNGeneral.cpp | 86 +++++++++--------- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 8 +- .../ClassFlowDefineTypes.h | 1 + .../ClassFlowPostProcessing.cpp | 29 +++++- .../ClassFlowPostProcessing.h | 2 +- .../test_ZeigerEvalAnalogToDigitNeu.cpp | 88 +++++++++++++++++++ ...ow.cpp => test_flow_postrocess_helper.cpp} | 6 +- ...t_flow.h => test_flow_postrocess_helper.h} | 0 .../test_flow_pp_negative.cpp | 2 +- .../test_flowpostprocessing.cpp | 52 ++++++----- code/test/test_suite_flowcontroll.cpp | 9 +- sd-card/html/edit_config_param.html | 14 +++ 12 files changed, 215 insertions(+), 82 deletions(-) create mode 100644 code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp rename code/test/components/jomjol-flowcontroll/{test_flow.cpp => test_flow_postrocess_helper.cpp} (97%) rename code/test/components/jomjol-flowcontroll/{test_flow.h => test_flow_postrocess_helper.h} (100%) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 661ce729..908dc25a 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -10,7 +10,7 @@ static const char* TAG = "flow_analog"; -bool debugdetailgeneral = false; + ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG) { @@ -28,7 +28,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy flowpostalignment = _flowalign; } -string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog) +string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution, int prev, float _vorgaengerAnalog, float analogDigitalTransitionStart) { string result = ""; @@ -87,7 +87,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution { // prev = ZeigerEval(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev); if (_vorgaengerAnalog >= 0) - prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true); + prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, _vorgaengerAnalog, prev, true, analogDigitalTransitionStart); else prev = ZeigerEvalHybridNeu(GENERAL[_analog]->ROI[GENERAL[_analog]->ROI.size() - 1]->result_float, prev, prev); result = std::to_string(prev); @@ -127,7 +127,7 @@ string ClassFlowCNNGeneral::getReadout(int _analog = 0, bool _extendedResolution return result; } -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; @@ -147,7 +147,7 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, if (AnalogerVorgaenger) { - result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger); + result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger, digitalAnalogTransitionStart); if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - Analoger Vorgänger, Bewertung über ZeigerEvalAnalogNeu = " + std::to_string(result) + " zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); return result; @@ -201,55 +201,49 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, } -int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger) +int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart) { int result; int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10; 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; - } - - if (ziffer_vorgaenger <= 3 && eval_vorgaenger<9) // Nulldurchgang hat stattgefunden (!Bewertung über Prev_value und nicht Zahl!) --> hier aufrunden (2.8 --> 3, aber auch 3.1 --> 3) - // aber Sonderfall ziffer_vorgaeger = 0.1 vor_vorgaenger 9.9 => eval_vorgaenger ist 9, damit hat Nulldurchgang nicht stattgefunden. - { - if (ergebnis_nachkomma > 5) - result = (ergebnis_vorkomma + 1) % 10; - else - result = ergebnis_vorkomma; - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang hat stattgefunden = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); - return result; - } - - // 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; + // 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 { - // 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; + 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)); } - - if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - 9.0 --> noch kein Nulldurchgang = " + std::to_string(result) + - " zahl: " + std::to_string(zahl) + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe)); + + // Kein Nulldurchgang hat stattgefunden. + // Nur eval_vorgaenger verwendet, da ziffer_vorgaenger hier falsch sein könnte. + // ziffer_vorgaenger<=0.1 & eval_vorgaenger=9 entspricht analog wurde zurückgesetzt wegen vorhergehender analog, die noch nicht auf 0 sind. + if ((eval_vorgaenger>=9 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) + // digit läuft dem Analog vor. Darf aber erst passieren, wenn + // digit wirklich schnon los läuft, deshalb 9 + || (eval_vorgaenger>9 && ziffer_vorgaenger>analogDigitalTransitionStart && ergebnis_nachkomma<=1)) + + { + result = ((ergebnis_vorkomma+10) - 1) % 10; + if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu - Nulldurchgang noch nicht stattgefunden = " + std::to_string(result) + + " zahl: " + std::to_string(zahl) + + " ziffer_vorgaenger = " + std::to_string(ziffer_vorgaenger) + + " erg_nachkomma = " + std::to_string(ergebnis_nachkomma)); + + } + return result; + } int ClassFlowCNNGeneral::ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 055df5e3..03c48d8c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,6 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: + bool debugdetailgeneral = false; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; @@ -28,7 +29,6 @@ protected: float DigitalUnschaerfe = 0.2; int DigitalBand = 3; float DigitalAnalogerVorgaengerUebergangsbereich = 2; - // nicht mehr benötigt float DigitalUebergangsbereichVorgaengerAnalogToDigit = 1; // war vorher 2 float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7 float DigitalUebergangsbereichVorlauf = 9.7; // Vorlauf-Nulldurchgang passiert erst ab ca. 9.7 @@ -41,8 +41,8 @@ protected: bool SaveAllFiles; int ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger); - int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger); - int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false); + int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger, float analogDigitalTransitionStart); + int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false, float analogDigitalTransitionStart=9.2); @@ -58,7 +58,7 @@ 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, float analogDigitalTransitionStart=9.2); void DrawROI(CImageBasis *_zw); diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index c296ca27..c7ebc693 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -46,6 +46,7 @@ struct NumberPost { int AnzahlDigital; int DecimalShift; int DecimalShiftInitial; + float AnalogDigitalTransitionStart; // Wann ist das digit > x.1, also wann fängt es an zu kippen int Nachkomma; bool isExtendedResolution; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index e0b900eb..cb6bbb00 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -343,6 +343,29 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } } +void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, string _value) +{ + string _digit, _decpos; + int _pospunkt = _decsep.find_first_of("."); +// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); + if (_pospunkt > -1) + _digit = _decsep.substr(0, _pospunkt); + else + _digit = "default"; + + for (int j = 0; j < NUMBERS.size(); ++j) + { + float _zwdc = 9.2; + { + _zwdc = stof(_value); + } + if (_digit == "default" || NUMBERS[j]->name == _digit) // erstmal auf default setzen (falls sonst nichts gesetzt) + { + NUMBERS[j]->AnalogDigitalTransitionStart = _zwdc; + + } + } +} void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) @@ -447,6 +470,10 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { handleDecimalSeparator(zerlegt[0], zerlegt[1]); } + if ((toUpper(_param) == "ANALOG_DIGITAL_TRANSITION_START") && (zerlegt.size() > 1)) + { + handleAnalogDigitalTransitionStart(zerlegt[0], zerlegt[1]); + } if ((toUpper(_param) == "MAXRATEVALUE") && (zerlegt.size() > 1)) { handleMaxRateValue(zerlegt[0], zerlegt[1]); @@ -674,7 +701,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (NUMBERS[j]->digit_roi) { if (NUMBERS[j]->analog_roi) - NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float) + NUMBERS[j]->ReturnRawValue; + NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, false, previous_value, NUMBERS[j]->analog_roi->ROI[0]->result_float, NUMBERS[j]->AnalogDigitalTransitionStart) + NUMBERS[j]->ReturnRawValue; else NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 9d63804b..dac4d4f1 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -41,7 +41,7 @@ protected: void handleMaxRateValue(string _decsep, string _value); void handleDecimalExtendedResolution(string _decsep, string _value); void handleMaxRateType(string _decsep, string _value); - + void handleAnalogDigitalTransitionStart(string _decsep, string _value); diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp new file mode 100644 index 00000000..3e0c8fbb --- /dev/null +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -0,0 +1,88 @@ +#include +#include + +class UnderTestCNNGeneral : public ClassFlowCNNGeneral { + public: + UnderTestCNNGeneral( ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : + ClassFlowCNNGeneral(_flowalign, _cnntype) {}; + + using ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu; + + +}; + + +/** + * @brief + * + * Transition = x.8 - x.2 hier keine Transition in den Testfaellen + * Versatz = dig=x.n, ana= n.y: kein Versatz, da beide "n" gleich + */ +void test_analogToDigit_Standard() { + + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // 4.8 ist eine "hängende" 5. Heißt sie ist nicht bis auf 5.0 umgesprungen. + // ab Transition sollte trotzdem ein "hängendes Digit" gerundet werden. + // Transition = ja + // Versatz = nein + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu(4.8, 8.0, 8, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 + // Standard: dig=9.6, ana=6.8 => erg=9 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.6, 6.8, 6, 9.2)); + + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 + // Standard: dig=4.6, ana=6.2 => erg=4 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.6, 6.2, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Hängendes digit () + // Standard: dig=6.8, ana=8.6 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 + // Ebenfalls Hängendes digit () bei kleinem Zeiger nach 0-Durchlauf + // Standard: dig=6.8, ana=1.0 => erg=7 + // Transition = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + + +} + +void test_analogToDigit_Transition() { + UnderTestCNNGeneral* undertest = new UnderTestCNNGeneral(nullptr, Digital100); + + // https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1222672175 + // Standard: dig=3.9, ana=9.7 => erg=3 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + TEST_ASSERT_EQUAL_INT(3, undertest->ZeigerEvalAnalogToDigitNeu( 3.9, 9.7, 9, 9.2)); + + // ohne Referenz + // Standard: dig=4.0, ana=9.1 => erg=4 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit ist bei analog 9.1 noch nicht losgelaufen + TEST_ASSERT_EQUAL_INT(4, undertest->ZeigerEvalAnalogToDigitNeu( 4.0, 9.1, 9, 9.2)); + + // ohne Referenz + // Standard: dig=9.8, ana=0.1, ana_2=9.9 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: analog wird durch vorherigen analog wieder auf 9 gesetzt + TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.8, 0.1, 9, 9.2)); + + +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp similarity index 97% rename from code/test/components/jomjol-flowcontroll/test_flow.cpp rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 41d02a75..283e7fc3 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) @@ -42,7 +42,9 @@ std::string process_doFlow(std::vector analog, std::vector digits, // run test TEST_ASSERT_TRUE(_undertestPost->doFlow(time)); - return _undertestPost->getReadout(0); + std::string result = _undertestPost->getReadout(0); + delete _undertestPost; + return result; } diff --git a/code/test/components/jomjol-flowcontroll/test_flow.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h similarity index 100% rename from code/test/components/jomjol-flowcontroll/test_flow.h rename to code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h diff --git a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp index 6fd55da7..0a650deb 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_pp_negative.cpp @@ -1,4 +1,4 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index da9e001d..3d9082d8 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -1,9 +1,12 @@ -#include "test_flow.h" +#include "test_flow_postrocess_helper.h" /** + * ACHTUNG! Die Test laufen aktuell nur mit ausgeschaltetem Debug in ClassFlowCNNGeneral + * + * * @brief Testet die doFlow-Methode von ClassFlowPostprocessing * digits[] - enthält die liste der vom Model zurückgegebenen Ergebnisse (class100/cont) in der Reihenfolge von links nach rechts * analog[] - enthält die Liste der Zeiger vom Model, wie bei den digits @@ -29,7 +32,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issue-1344032217 * * Das Ergebnis sollte "376529.6" sein. */ @@ -40,7 +43,7 @@ void test_doFlow() { TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); /* - * https://github.com/jomjol/AI-on-the-edge-device/issues/921 + * https://github.com/jomjol/AI-on-the-edge-device/issues/921#issuecomment-1220365920 * * Das Ergebnis sollte "167734.6" sein. Bzw. 16.98 ohne Extended true */ @@ -81,13 +84,13 @@ void test_doFlow() { digits = { 1.1, 9.0, 4.0}; analogs = { 8.1, 2.6, 6.25, 9.7}; - expected = "193.8259"; + expected = "194.8259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); digits = { 1.1, 9.0, 4.0}; analogs = { 9.1, 2.6, 6.25, 9.7}; - expected = "193.9259"; + expected = "194.9259"; result = process_doFlow(analogs, digits); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); @@ -346,10 +349,10 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issue-1391153343 - digits = { 1.0, 4.0, 2.0}; // 142.9269 als falsches Ergebnis + digits = { 1.0, 4.0, 2.0}; // 141.9269 als falsches Ergebnis analogs = { 9.2, 2.5, 6.8, 9.0}; - expected = "141.9269"; - expected_extended= "141.92690"; + expected = "142.9269"; + expected_extended= "142.92690"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -364,8 +367,11 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388 digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis analogs = { 8.7}; - expected = "170.0528"; - expected_extended= "170.05287"; + // Aktuell nicht sicher, ob doch + expected = "170.0538"; + expected_extended= "170.05387"; + //expected = "170.0528"; + //expected_extended= "170.05287"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, -3); @@ -378,10 +384,10 @@ void test_doFlow() { // Fehler bei rolling post V12.0.1 // lokal watermeter1 - digits = { 0.0, 0.0, 9.0, 1.0}; //91.88174 als falsches Ergebnis + digits = { 0.0, 0.0, 9.0, 1.0}; //90.88174 als falsches Ergebnis analogs = {9.0, 8.0, 1.8, 7.4}; - expected = "90.8817"; - expected_extended= "90.88174"; + expected = "91.8817"; + expected_extended= "91.88174"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -426,9 +432,8 @@ void test_doFlow() { // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1274434805 digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + expected = "577.8649"; + expected_extended= "577.86490"; // extendResolution=false result = process_doFlow(analogs, digits, Digital100, false, false, 0); @@ -440,19 +445,18 @@ void test_doFlow() { // Fehler V12.0.1 "TODO 00211.03480 vs 00211.03580" - // Lokal - digits = { 4.9, 6.9, 6.8}; // 576.8649 als falsches Ergebnis - analogs = {8.6, 6.2, 5.0, 9.0}; - // fall unklar ob wirklich 577 oder 576, erst mal 577 - expected = "576.8649"; - expected_extended= "576.86490"; + // Lokal "Hängendes Digit" + digits = { 2.0, 1.0, 1.0, 0.0, 3.0, 4.8}; // 00211.03480 als falsches Ergebnis + analogs = {8.0}; + expected = "211.0358"; + expected_extended= "211.03580"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, 0); + result = process_doFlow(analogs, digits, Digital100, false, false, -3); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, 0); + result = process_doFlow(analogs, digits, Digital100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index de4343cc..9d096e84 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -1,8 +1,9 @@ #include -#include "components/jomjol-flowcontroll/test_flow.cpp" +#include "components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp" #include "components/jomjol-flowcontroll/test_flowpostprocessing.cpp" #include "components/jomjol-flowcontroll/test_flow_pp_negative.cpp" +#include "components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp" // SD-Card //////////////////// #include "nvs_flash.h" #include "esp_vfs_fat.h" @@ -104,8 +105,10 @@ extern "C" void app_main() Init_NVS_SDCard(); UNITY_BEGIN(); - RUN_TEST(testNegative); - RUN_TEST(test_doFlow); + RUN_TEST(test_analogToDigit_Standard); + RUN_TEST(test_analogToDigit_Transition); + //RUN_TEST(testNegative); + RUN_TEST(test_doFlow); UNITY_END(); } \ No newline at end of file diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index caf488b6..d5ef7007 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -489,6 +489,20 @@ textarea { Shift the digit separator within the digital digits (positiv and negativ) + + + + + + + + + + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. + Only used on combination of digits and analog pointers. + + + From 5d35df65f3c5231deb9ce8761c22355e8ccdecd7 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:29:50 +0200 Subject: [PATCH 02/44] add testNegative --- code/test/test_suite_flowcontroll.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/test/test_suite_flowcontroll.cpp b/code/test/test_suite_flowcontroll.cpp index 9d096e84..f91be40c 100644 --- a/code/test/test_suite_flowcontroll.cpp +++ b/code/test/test_suite_flowcontroll.cpp @@ -104,10 +104,11 @@ extern "C" void app_main() initGPIO(); Init_NVS_SDCard(); UNITY_BEGIN(); - + + RUN_TEST(testNegative); + RUN_TEST(test_analogToDigit_Standard); RUN_TEST(test_analogToDigit_Transition); - //RUN_TEST(testNegative); RUN_TEST(test_doFlow); UNITY_END(); From 426d6bae3ff31649d5c495234877ad9e5bd3c99f Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:37:15 +0200 Subject: [PATCH 03/44] fix name of ANALOGDIGITALTRANSITIONSTART --- code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index cb6bbb00..ac168c7f 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -470,7 +470,7 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph) { handleDecimalSeparator(zerlegt[0], zerlegt[1]); } - if ((toUpper(_param) == "ANALOG_DIGITAL_TRANSITION_START") && (zerlegt.size() > 1)) + if ((toUpper(_param) == "ANALOGDIGITALTRANSITIONSTART") && (zerlegt.size() > 1)) { handleAnalogDigitalTransitionStart(zerlegt[0], zerlegt[1]); } From e5649d03b29c8028e54cd4ff217b83b74afa8102 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:40:20 +0200 Subject: [PATCH 04/44] min and max of ANALOGDIGITALTRANSITIONSTART added --- sd-card/html/edit_config_param.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index d5ef7007..5cc65890 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -495,7 +495,7 @@ textarea { - + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. From ace1936a7822fdb921e4be69aa332ca6d2cd5da8 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 20:47:12 +0200 Subject: [PATCH 05/44] added AnalogDigitalTransitionStart to expert config --- sd-card/html/edit_config_param.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index 5cc65890..a3e12541 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -490,7 +490,7 @@ textarea { - + From be8598bcaa3fa306a7d09579cdc89b6b91cbc100 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 21:36:11 +0200 Subject: [PATCH 06/44] read and save config for AnalogDigitalTransitionStart --- sd-card/config/config.ini | 1 + sd-card/html/edit_config_param.html | 8 +++++--- sd-card/html/readconfigparam.js | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index ee7c75fc..138e9a72 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -42,6 +42,7 @@ main.ana4 155 328 92 92 false [PostProcessing] main.DecimalShift = 0 +main.AnalogDigitalTransitionStart = 9.2 PreValueUse = true PreValueAgeStartup = 720 AllowNegativeRates = false diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index a3e12541..bbd04232 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -490,16 +490,16 @@ textarea { - + - + If you have false Values, but the recognition is correct. Look for the start of changing of the first digit and note the analog pointer value behind. Set it here. - Only used on combination of digits and analog pointers. + Only used on combination of digits and analog pointers. Default=9.2 @@ -1684,6 +1684,7 @@ function UpdateInputIndividual() if (NUNBERSAkt != -1) { ReadParameter(param, "PostProcessing", "DecimalShift", true, NUNBERSAkt) + ReadParameter(param, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateValue", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "MaxRateType", true, NUNBERSAkt) ReadParameter(param, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt) @@ -1693,6 +1694,7 @@ function UpdateInputIndividual() var sel = document.getElementById("Numbers_value1"); NUNBERSAkt = sel.selectedIndex; WriteParameter(param, category, "PostProcessing", "DecimalShift", true, NUNBERSAkt); + WriteParameter(param, category, "PostProcessing", "AnalogDigitalTransitionStart", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateValue", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "MaxRateType", true, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "ExtendedResolution", true, NUNBERSAkt); diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index afbedc5d..9e7eb8b7 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -102,6 +102,7 @@ function ParseConfig() { category[catname]["found"] = false; param[catname] = new Object(); ParamAddValue(param, catname, "DecimalShift", 1, true); + ParamAddValue(param, catname, "AnalogDigitalTransitionStart", 1, true); ParamAddValue(param, catname, "PreValueUse"); ParamAddValue(param, catname, "PreValueAgeStartup"); ParamAddValue(param, catname, "AllowNegativeRates"); From bc46149573eda04ee7a86228f59731f7b1d1efca Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 22:22:47 +0200 Subject: [PATCH 07/44] init the analogDigitalTransitionStart with 9.2 if nothing set in config --- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- .../jomjol_flowcontroll/ClassFlowPostProcessing.cpp | 1 + .../test_ZeigerEvalAnalogToDigitNeu.cpp | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 03c48d8c..5731c0a2 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = false; + bool debugdetailgeneral = true; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index ac168c7f..d500a1ec 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -584,6 +584,7 @@ void ClassFlowPostProcessing::InitNUMBERS() _number->DecimalShift = 0; _number->DecimalShiftInitial = 0; _number->isExtendedResolution = false; + _number->AnalogDigitalTransitionStart=9.2; _number->FlowRateAct = 0; // m3 / min diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp index 3e0c8fbb..c3d79740 100644 --- a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -53,7 +53,7 @@ void test_analogToDigit_Standard() { // Standard: dig=6.8, ana=1.0 => erg=7 // Transition = nein // Versatz = nein - TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 8.6, 6, 9.2)); + TEST_ASSERT_EQUAL_INT(7, undertest->ZeigerEvalAnalogToDigitNeu( 6.8, 1.0, 1, 9.2)); } @@ -85,4 +85,12 @@ void test_analogToDigit_Transition() { TEST_ASSERT_EQUAL_INT(9, undertest->ZeigerEvalAnalogToDigitNeu( 9.8, 0.1, 9, 9.2)); + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1277425333 + // Standard: dig=5.9, ana=9.4 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: + TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu( 5.9, 9.4, 9, 9.2)); + } From fc0bbc57cb1466340ad7e5ed59a51624ec6d17af Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Mon, 17 Oct 2022 22:27:39 +0200 Subject: [PATCH 08/44] update changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index d25f3ca8..d2a0c7f1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ - Updated built environment to `espressif32@v5.2.0` - [#1176](https://github.com/jomjol/AI-on-the-edge-device/discussions/1176) accept minor negative values (-0.2) if extended resolution is enabled +- [#1143](https://github.com/jomjol/AI-on-the-edge-device/issues/1143) added config parameter AnalogDigitalTransitionStart. It can setup very early and very late digit transition starts. ### Fixed - [#1116](https://github.com/jomjol/AI-on-the-edge-device/issues/1116) precision problem at setting prevalue From 0e55fc7f7ed14160a716451194d324250b0368b1 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Tue, 18 Oct 2022 23:01:09 +0200 Subject: [PATCH 09/44] add @Plawasan test cases. Works now with setable analogdigitTransistionstart --- .../ClassFlowCNNGeneral.cpp | 2 +- .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- .../test_ZeigerEvalAnalogToDigitNeu.cpp | 8 +++ .../test_flow_postrocess_helper.cpp | 10 +++ .../test_flow_postrocess_helper.h | 8 +++ .../test_flowpostprocessing.cpp | 69 ++++++++++++++++--- 6 files changed, 89 insertions(+), 10 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 908dc25a..77e00d7c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -228,7 +228,7 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor // Kein Nulldurchgang hat stattgefunden. // Nur eval_vorgaenger verwendet, da ziffer_vorgaenger hier falsch sein könnte. // ziffer_vorgaenger<=0.1 & eval_vorgaenger=9 entspricht analog wurde zurückgesetzt wegen vorhergehender analog, die noch nicht auf 0 sind. - if ((eval_vorgaenger>=9 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) + if ((eval_vorgaenger>=6 && (ziffer_vorgaenger>analogDigitalTransitionStart || ziffer_vorgaenger<=0.2) && roundedUp) // digit läuft dem Analog vor. Darf aber erst passieren, wenn // digit wirklich schnon los läuft, deshalb 9 || (eval_vorgaenger>9 && ziffer_vorgaenger>analogDigitalTransitionStart && ergebnis_nachkomma<=1)) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 5731c0a2..03c48d8c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = true; + bool debugdetailgeneral = false; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; diff --git a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp index c3d79740..a118a74c 100644 --- a/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp +++ b/code/test/components/jomjol-flowcontroll/test_ZeigerEvalAnalogToDigitNeu.cpp @@ -93,4 +93,12 @@ void test_analogToDigit_Transition() { // Besonderheit: TEST_ASSERT_EQUAL_INT(5, undertest->ZeigerEvalAnalogToDigitNeu( 5.9, 9.4, 9, 9.2)); + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + // Standard: dig=1.8, ana=7.8 => erg=9 + // Transition = ja + // Nulldurchgang = nein + // Versatz = nein + // Besonderheit: Digit läuft mit Analog mit. Deshalb 1.8 (vs. 7.8) + TEST_ASSERT_EQUAL_INT(1, undertest->ZeigerEvalAnalogToDigitNeu( 1.8, 7.8, 7, 7.7)); + } diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 283e7fc3..c37e0577 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -142,3 +142,13 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) { } } } + +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart) { + if (_analogdigitTransistionStart!=0) { + std::vector* NUMBERS = _underTestPost->GetNumbers(); + for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { + printf("Setting decimal shift on number: %d to %f\n", _n, _analogdigitTransistionStart); + (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; + } + } +} diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h index e9f54262..6b103f25 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.h @@ -99,4 +99,12 @@ void setExtendedResolution(UnderTestPost* _UnderTestPost, bool _extendedResoluti */ void setDecimalShift(UnderTestPost* _UnderTestPost, int decimal_shift); +/** + * @brief Set the Analogdigit Transistion Start + * + * @param _underTestPost the testobject + * @param _analogdigitTransistionStart the analog to digit transition start + */ +void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analogdigitTransistionStart); + #endif // TEST_FLOW_H diff --git a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp index 3d9082d8..228ff4d8 100644 --- a/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flowpostprocessing.cpp @@ -366,21 +366,24 @@ void test_doFlow() { // Fehler bei V12.0.1 // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1262626388 digits = { 1.2, 6.8, 0.0, 0.0, 5.0, 2.8}; //170.05387 als falsches Ergebnis + // letztes digit läuft mit analog zeiger mit. Hier nur lösbar mit setAnalogdigitTransistionStart=7.7 analogs = { 8.7}; - // Aktuell nicht sicher, ob doch - expected = "170.0538"; - expected_extended= "170.05387"; - //expected = "170.0528"; - //expected_extended= "170.05287"; + expected = "170.0528"; + expected_extended= "170.05287"; // extendResolution=false - result = process_doFlow(analogs, digits, Digital100, false, false, -3); + UnderTestPost* undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; // checkConsistency=false und extendResolution=true - result = process_doFlow(analogs, digits, Digital100, false, true, -3); + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); - + delete undertestPost; // Fehler bei rolling post V12.0.1 // lokal watermeter1 @@ -459,7 +462,57 @@ void test_doFlow() { result = process_doFlow(analogs, digits, Digital100, false, true, -3); TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1143#issuecomment-1281231468 + digits = { 1.0, 1.9, 6.0}; // 125.923 als falsches Ergebnis + analogs = {9.3, 2.3, 3.1}; + expected = "126.923"; + expected_extended= "126.9231"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, 0); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, 0); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 3.0, 8.1, 5.9, 0.0, 5.0, 6.7}; // 386.05672 als richtiges Ergebnis. Letztes digit schein mit dem Analogzeiger mitzulaufen + analogs = {7.2}; + expected = "386.0567"; + expected_extended= "386.05672"; + + // extendResolution=false + result = process_doFlow(analogs, digits, Digital100, false, false, -3); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + + // checkConsistency=false und extendResolution=true + result = process_doFlow(analogs, digits, Digital100, false, true, -3); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + + // Fehler V12.0.1 + // https://github.com/jomjol/AI-on-the-edge-device/issues/1110#issuecomment-1282168030 + digits = { 1.2, 7.0, 1.2, 2.0, 4.0, 1.8}; // 171.24278 als falsches Ergebnis. + // Test ist nur erfolgreich mit Veränderung des AnalogdigitTransistionStart + analogs = {7.8}; + expected = "171.2417"; + expected_extended= "171.24178"; + + // extendResolution=false + undertestPost = init_do_flow(analogs, digits, Digital100, false, false, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected, result.c_str()); + delete undertestPost; + + // checkConsistency=false und extendResolution=true + undertestPost = init_do_flow(analogs, digits, Digital100, false, true, -3); + setAnalogdigitTransistionStart(undertestPost, 7.7); + result = process_doFlow(undertestPost); + TEST_ASSERT_EQUAL_STRING(expected_extended, result.c_str()); + delete undertestPost; } From 33b9a15f732dbbe5e4c796db1384fe329f189494 Mon Sep 17 00:00:00 2001 From: Frank Haverland Date: Tue, 18 Oct 2022 23:02:11 +0200 Subject: [PATCH 10/44] enable debug on CNNGeneral --- code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h index 03c48d8c..5731c0a2 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h @@ -20,7 +20,7 @@ class ClassFlowCNNGeneral : public ClassFlowImage { protected: - bool debugdetailgeneral = false; + bool debugdetailgeneral = true; t_CNNType CNNType; std::vector GENERAL; float CNNGoodThreshold; From cd2350140d0a02dc7972a99a0f2d69316b67d61c Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Wed, 19 Oct 2022 09:32:52 +0200 Subject: [PATCH 11/44] Fix for image logging + file deletion routines --- code/components/jomjol_flowcontroll/ClassFlowImage.cpp | 10 ++++++---- code/components/jomjol_helper/Helper.cpp | 2 +- code/components/jomjol_logfile/ClassLogFile.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index 8fd45139..a5c9ca54 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -65,7 +65,7 @@ void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, i else { sprintf(buf, "%.1f_", *resultFloat); - if (strcmp(buf, "10.0_")) + if (strcmp(buf, "10.0_") == 0) sprintf(buf, "0.0_"); } @@ -119,14 +119,16 @@ void ClassFlowImage::RemoveOldLogs() string folderPath = LogImageLocation + "/" + entry->d_name; if (entry->d_type == DT_DIR) { //ESP_LOGI(logTag, "Compare %s %s", entry->d_name, folderName.c_str()); - if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) < 0)) { - deleted += removeFolder(folderPath.c_str(), logTag); + if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) == 0)) { + removeFolder(folderPath.c_str(), logTag); + deleted++; } else { notDeleted ++; } } } - ESP_LOGI(logTag, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + ESP_LOGI(logTag, "%d image folder deleted. %d image folder not deleted.", deleted, notDeleted); + LogFile.WriteToFile("Image folder deleted: " + std::to_string(deleted) + ". Image folder not deleted: " + std::to_string(notDeleted)); closedir(dir); } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 2d543735..3c1bc20b 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -319,7 +319,7 @@ string getDirectory(string filename) string getFileType(string filename) { - size_t lastpos = filename.find(".", 0); + size_t lastpos = filename.rfind(".", filename.length()); size_t neu_pos; while ((neu_pos = filename.find(".", lastpos + 1)) > -1) { diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 3d3605d9..17507a42 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -176,7 +176,7 @@ void ClassLogFile::RemoveOld() 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)) { + if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) == 0)) { ESP_LOGI(TAG, "delete log file : %s", entry->d_name); std::string filepath = logroot + "/" + entry->d_name; if (unlink(filepath.c_str()) == 0) { @@ -189,7 +189,8 @@ void ClassLogFile::RemoveOld() } } } - ESP_LOGI(TAG, "%d older log files deleted. %d current log files not deleted.", deleted, notDeleted); + ESP_LOGI(TAG, "%d logfiles deleted. %d files not deleted (incl. leer.txt).", deleted, notDeleted); + LogFile.WriteToFile("logfiles deleted: " + std::to_string(deleted) + " files not deleted (incl. leer.txt): " + std::to_string(notDeleted)); closedir(dir); } From 83f638c64fc792782ee6b8f1df2228bab0f594f9 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Wed, 19 Oct 2022 20:23:15 +0200 Subject: [PATCH 12/44] start implementing direct data log --- .../ClassFlowCNNGeneral.cpp | 29 ++++++ .../jomjol_flowcontroll/ClassFlowCNNGeneral.h | 4 +- .../ClassFlowPostProcessing.cpp | 16 ++++ .../ClassFlowPostProcessing.h | 4 + .../jomjol_logfile/ClassLogFile.cpp | 93 ++++++++++++++++++- code/components/jomjol_logfile/ClassLogFile.h | 7 +- 6 files changed, 149 insertions(+), 4 deletions(-) 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(); }; From f10adb3383d9baa813f206a5b4eb4a7e4ca61d8d Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Wed, 19 Oct 2022 22:01:56 +0200 Subject: [PATCH 13/44] Update build.yaml (#1193) --- .github/workflows/build.yaml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a0fc41c4..66b5c3af 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,23 +10,25 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: recursive - name: Set Variables id: vars run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Cache PlatformIO - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.platformio key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: Install PlatformIO run: | python -m pip install --upgrade pip @@ -59,7 +61,7 @@ jobs: needs: build steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get generated files from cache uses: actions/cache@v3 @@ -74,7 +76,7 @@ jobs: - name: Set Variables id: vars run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Rename firmware file to contain versioning (old ota) run: | @@ -109,7 +111,7 @@ jobs: needs: build steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get generated files from cache uses: actions/cache@v3 @@ -124,7 +126,7 @@ jobs: - name: Set Variables id: vars run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Prepare update.zip artifact run: | @@ -177,7 +179,7 @@ jobs: needs: build steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get generated files from cache uses: actions/cache@v3 @@ -192,7 +194,7 @@ jobs: - name: Set Variables id: vars run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Prepare artifacts for release run: | @@ -231,7 +233,7 @@ jobs: if: startsWith(github.ref, 'refs/tags/') steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get generated files from cache uses: actions/cache@v3 @@ -262,7 +264,7 @@ jobs: - name: Set Variables id: vars run: | - echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Prepare artifacts for release From 8d4fb74173ac9a35d6fa449632fe436c964451d9 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:08:02 +0200 Subject: [PATCH 14/44] Implement data log --- .../ClassFlowCNNGeneral.cpp | 98 +++++++++---------- .../ClassFlowPostProcessing.cpp | 17 ++-- code/components/jomjol_helper/Helper.cpp | 7 ++ code/components/jomjol_helper/Helper.h | 2 + .../jomjol_logfile/ClassLogFile.cpp | 5 + 5 files changed, 69 insertions(+), 60 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 9f69027e..9eba7190 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/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 *_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; +} + diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 1a9f5ab7..bdcd3f41 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/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()); } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 3c1bc20b..ab18fa11 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/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()); +} diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index bf2929a7..a84fe8d1 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/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); diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index afd1ef1d..d5ade3d2 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/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"); } From c8d2d9d4fda0b57400fb344a88951ff58dcc399b Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Wed, 19 Oct 2022 22:27:26 +0200 Subject: [PATCH 15/44] Implement direct data log --- .../jomjol_flowcontroll/ClassFlowPostProcessing.cpp | 6 +++--- code/components/jomjol_logfile/ClassLogFile.cpp | 6 ++++-- code/components/jomjol_logfile/ClassLogFile.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index bdcd3f41..646582e5 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -848,11 +848,11 @@ void ClassFlowPostProcessing::WriteDataLog(int _analog) string analog = ""; string digital = ""; if (flowAnalog) - analog = flowAnalog->getReadout(_analog); + analog = flowAnalog->getReadoutRawString(_analog); if (flowDigit) - digital = flowDigit->getReadout(_analog); + digital = flowDigit->getReadoutRawString(_analog); // LogFile.WriteToFile(analog); - LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ErrorMessageText, digital, analog); + LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ReturnPreValue, 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()); } diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index d5ade3d2..34e5d1eb 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -62,7 +62,7 @@ std::string ClassLogFile::getESPHeapInfo(){ return espInfoResultStr; } -void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ErrorMessageText, std::string _digital, std::string _analog) +void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog) { printf("Start WriteToData\n"); time_t rawtime; @@ -95,12 +95,14 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo); - zwtime = std::string(buffer) + ":"; + zwtime = std::string(buffer) + ":\t"; fputs(zwtime.c_str(), pFile); fputs(_ReturnRawValue.c_str(), pFile); fputs("\t", pFile); fputs(_ReturnValue.c_str(), pFile); fputs("\t", pFile); + fputs(_ReturnPreValue.c_str(), pFile); + fputs("\t", pFile); fputs(_ErrorMessageText.c_str(), pFile); fputs("\t", pFile); fputs(_digital.c_str(), pFile); diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h index 2a722c6c..c04978a2 100644 --- a/code/components/jomjol_logfile/ClassLogFile.h +++ b/code/components/jomjol_logfile/ClassLogFile.h @@ -28,7 +28,7 @@ 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); + void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); std::string GetCurrentFileName(); From 485363d7a2ad423f16b2af11d9be02df5dac7800 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Fri, 21 Oct 2022 07:07:45 +0200 Subject: [PATCH 16/44] Update FeatureRequest.md --- FeatureRequest.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FeatureRequest.md b/FeatureRequest.md index 41cc261d..2d430380 100644 --- a/FeatureRequest.md +++ b/FeatureRequest.md @@ -11,6 +11,12 @@ ____ +#### #32 Add feature to correct misinterpreted value + +* If a value is misinterpreted, the user can manually correct the value. +* The misinterpreted ROIs would be saved in a "training data" -folder on the SD-card +* Stretch goal: make sending of saved training data as easy as pushing a button =) + #### #31 Implement InfluxDB v2.x interface * Currently only InfluxDB v1.x is supportet, extend to v2.x From 46daa4cb7927dd265363412cb8e85764c8596b7e Mon Sep 17 00:00:00 2001 From: George Ruinelli Date: Fri, 21 Oct 2022 20:54:38 +0200 Subject: [PATCH 17/44] replaced printf with ESP_LOGD --- code/main/server_main.cpp | 28 ++++++++++--------- .../test_flow_postrocess_helper.cpp | 16 ++++++----- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 7d24f2b0..d60b2aa1 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -14,6 +14,8 @@ #include "esp_wifi.h" #include "server_tflite.h" +#include "esp_log.h" + //#define DEBUG_DETAIL_ON @@ -38,11 +40,11 @@ esp_err_t info_get_handler(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAG_SERVERMAIN, "Query: %s", _query); if (httpd_query_key_value(_query, "type", _valuechar, 30) == ESP_OK) { - printf("type is found"); printf(_valuechar); printf("\n"); + ESP_LOGD(TAG_SERVERMAIN, "type is found: %s", _valuechar); _task = std::string(_valuechar); } }; @@ -153,7 +155,7 @@ esp_err_t hello_main_handler(httpd_req_t *req) #endif char filepath[50]; - printf("uri: %s\n", req->uri); + ESP_LOGD(TAG_SERVERMAIN, "uri: %s\n", req->uri); int _pos; esp_err_t res; @@ -162,7 +164,7 @@ esp_err_t hello_main_handler(httpd_req_t *req) const char *filename = get_path_from_uri(filepath, base_path, req->uri - 1, sizeof(filepath)); - printf("1 uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG_SERVERMAIN, "1 uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); if ((strcmp(req->uri, "/") == 0)) { @@ -180,13 +182,13 @@ esp_err_t hello_main_handler(httpd_req_t *req) } if (filetosend == "/sdcard/html/index.html" && isSetupModusActive()) { - printf("System is in setup mode --> index.html --> setup.html"); + ESP_LOGD(TAG_SERVERMAIN, "System is in setup mode --> index.html --> setup.html"); filetosend = "/sdcard/html/setup.html"; } - printf("Filename: %s\n", filename); + ESP_LOGD(TAG_SERVERMAIN, "Filename: %s", filename); - printf("File requested: %s\n", filetosend.c_str()); + ESP_LOGD(TAG_SERVERMAIN, "File requested: %s", filetosend.c_str()); if (!filename) { ESP_LOGE(TAG_SERVERMAIN, "Filename is too long"); @@ -216,17 +218,17 @@ esp_err_t hello_main_handler(httpd_req_t *req) esp_err_t img_tmp_handler(httpd_req_t *req) { char filepath[50]; - printf("uri: %s\n", req->uri); + ESP_LOGD(TAG_SERVERMAIN, "uri: %s", req->uri); char *base_path = (char*) req->user_ctx; std::string filetosend(base_path); const char *filename = get_path_from_uri(filepath, base_path, req->uri + sizeof("/img_tmp/") - 1, sizeof(filepath)); - printf("1 uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG_SERVERMAIN, "1 uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); filetosend = filetosend + "/img_tmp/" + std::string(filename); - printf("File to upload: %s\n", filetosend.c_str()); + ESP_LOGD(TAG_SERVERMAIN, "File to upload: %s", filetosend.c_str()); esp_err_t res = send_file(req, filetosend); if (res != ESP_OK) @@ -245,17 +247,17 @@ esp_err_t img_tmp_virtual_handler(httpd_req_t *req) char filepath[50]; - printf("uri: %s\n", req->uri); + ESP_LOGD(TAG_SERVERMAIN, "uri: %s", req->uri); char *base_path = (char*) req->user_ctx; std::string filetosend(base_path); const char *filename = get_path_from_uri(filepath, base_path, req->uri + sizeof("/img_tmp/") - 1, sizeof(filepath)); - printf("1 uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG_SERVERMAIN, "1 uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); filetosend = std::string(filename); - printf("File to upload: %s\n", filetosend.c_str()); + ESP_LOGD(TAG_SERVERMAIN, "File to upload: %s", filetosend.c_str()); if (filetosend == "raw.jpg") { diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index c37e0577..01656575 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -1,5 +1,7 @@ #include "test_flow_postrocess_helper.h" +#include "esp_log.h" +static const char *TAG_POSTPROC_HELPER = "test_flow_postproc_helper"; UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) { @@ -36,7 +38,7 @@ std::string process_doFlow(std::vector analog, std::vector digits, bool checkConsistency, bool extendedResolution, int decimal_shift) { // setup the classundertest UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift); - printf("SetupClassFlowPostprocessing completed.\n"); + ESP_LOGD(TAG_POSTPROC_HELPER, "SetupClassFlowPostprocessing completed."); string time; // run test @@ -81,7 +83,7 @@ UnderTestPost* init_do_flow(std::vector analog, std::vector digits gen_analog->ROI.push_back(anaROI); } } - printf("Setting up of ROIs completed.\n"); + ESP_LOGD(TAG_POSTPROC_HELPER, "Setting up of ROIs completed."); _undertestPost->InitNUMBERS(); @@ -95,7 +97,7 @@ UnderTestPost* init_do_flow(std::vector analog, std::vector digits void setPreValue(UnderTestPost* _underTestPost, double _preValue) { if (_preValue>0) { - printf("preValue=%f", _preValue); + ESP_LOGD(TAG_POSTPROC_HELPER, "preValue=%f", _preValue); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->PreValue = _preValue; @@ -104,7 +106,7 @@ void setPreValue(UnderTestPost* _underTestPost, double _preValue) { } void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) { - printf("checkConsistency=true\n"); + ESP_LOGD(TAG_POSTPROC_HELPER, "checkConsistency=true"); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->AllowNegativeRates = _allowNegatives; @@ -114,7 +116,7 @@ void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) { void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency) { if (_checkConsistency) { - printf("checkConsistency=true\n"); + ESP_LOGD(TAG_POSTPROC_HELPER, "checkConsistency=true"); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->checkDigitIncreaseConsistency = true; @@ -136,7 +138,7 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) { if (_decimal_shift!=0) { std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { - printf("Setting decimal shift on number: %d to %d\n", _n, _decimal_shift); + ESP_LOGD(TAG_POSTPROC_HELPER, "Setting decimal shift on number: %d to %d", _n, _decimal_shift); (*NUMBERS)[_n]->DecimalShift = _decimal_shift; (*NUMBERS)[_n]->DecimalShiftInitial = _decimal_shift; } @@ -147,7 +149,7 @@ void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analog if (_analogdigitTransistionStart!=0) { std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { - printf("Setting decimal shift on number: %d to %f\n", _n, _analogdigitTransistionStart); + ESP_LOGD(TAG_POSTPROC_HELPER, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart); (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; } } From 4f305a870524643b70d974dff6d16fcd4730586e Mon Sep 17 00:00:00 2001 From: George Ruinelli Date: Fri, 21 Oct 2022 21:33:05 +0200 Subject: [PATCH 18/44] . --- .../ClassControllCamera.cpp | 26 ++--- .../jomjol_controlcamera/server_camera.cpp | 23 ++-- .../jomjol_tfliteclass/server_tflite.cpp | 106 +++++++++--------- .../components/jomjol_time_sntp/time_sntp.cpp | 8 +- code/components/jomjol_wlan/read_wlanini.cpp | 10 +- code/main/main.cpp | 38 +++---- .../test_flow_postrocess_helper.cpp | 16 +-- 7 files changed, 116 insertions(+), 111 deletions(-) diff --git a/code/components/jomjol_controlcamera/ClassControllCamera.cpp b/code/components/jomjol_controlcamera/ClassControllCamera.cpp index 20a3ebab..4e0c08c0 100644 --- a/code/components/jomjol_controlcamera/ClassControllCamera.cpp +++ b/code/components/jomjol_controlcamera/ClassControllCamera.cpp @@ -249,7 +249,7 @@ void CCamera::SetQualitySize(int qual, framesize_t resol) void CCamera::EnableAutoExposure(int flashdauer) { - printf("EnableAutoExposure"); + ESP_LOGD(TAGCAMERACLASS, "EnableAutoExposure"); LEDOnOff(true); if (flashdauer > 0) LightOnOff(true); @@ -423,19 +423,19 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay) LEDOnOff(false); #ifdef DEBUG_DETAIL_ON - printf("w %d, h %d, size %d\n", fb->width, fb->height, fb->len); + ESP_LOGD(TAGCAMERACLASS, "w %d, h %d, size %d", fb->width, fb->height, fb->len); #endif nm = FormatFileName(nm); #ifdef DEBUG_DETAIL_ON - printf("Save Camera to : %s\n", nm.c_str()); + ESP_LOGD(TAGCAMERACLASS, "Save Camera to : %s", nm.c_str()); #endif ftype = toUpper(getFileType(nm)); #ifdef DEBUG_DETAIL_ON - printf("Filetype: %s\n", ftype.c_str()); + ESP_LOGD(TAGCAMERACLASS, "Filetype: %s", ftype.c_str()); #endif uint8_t * buf = NULL; @@ -551,20 +551,20 @@ void CCamera::LightOnOff(bool status) { GpioHandler* gpioHandler = gpio_handler_get(); if ((gpioHandler != NULL) && (gpioHandler->isEnabled())) { - printf("Use gpioHandler flashLigh\n"); + ESP_LOGD(TAGCAMERACLASS, "Use gpioHandler flashLigh"); gpioHandler->flashLightEnable(status); } else { #ifdef USE_PWM_LEDFLASH if (status) { - printf("Internal Flash-LED turn on with PWM %d\n", led_intensity); + ESP_LOGD(TAGCAMERACLASS, "Internal Flash-LED turn on with PWM %d", led_intensity); ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, led_intensity)); // Update duty to apply the new value ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); } else { - printf("Internal Flash-LED turn off PWM\n"); + ESP_LOGD(TAGCAMERACLASS, "Internal Flash-LED turn off PWM"); ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, 0)); ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL)); } @@ -608,11 +608,11 @@ void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAGCAMERACLASS, "Query: %s", _query); if (httpd_query_key_value(_query, "size", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Size: "); printf(_size); printf("\n"); + ESP_LOGD(TAGCAMERACLASS, "Size: %s", _size); #endif if (strcmp(_size, "QVGA") == 0) resol = FRAMESIZE_QVGA; // 320x240 @@ -630,7 +630,7 @@ void CCamera::GetCameraParameter(httpd_req_t *req, int &qual, framesize_t &resol if (httpd_query_key_value(_query, "quality", _qual, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Quality: "); printf(_qual); printf("\n"); + ESP_LOGD(TAGCAMERACLASS, "Quality: %s", _qual); #endif qual = atoi(_qual); @@ -663,7 +663,7 @@ framesize_t CCamera::TextToFramesize(const char * _size) CCamera::CCamera() { #ifdef DEBUG_DETAIL_ON - printf("CreateClassCamera\n"); + ESP_LOGD(TAGCAMERACLASS, "CreateClassCamera"); #endif brightness = -5; contrast = -5; @@ -675,7 +675,7 @@ CCamera::CCamera() esp_err_t CCamera::InitCam() { - printf("Init Camera\n"); + ESP_LOGD(TAGCAMERACLASS, "Init Camera"); ActualQuality = camera_config.jpeg_quality; ActualResolution = camera_config.frame_size; //initialize the camera @@ -694,6 +694,6 @@ void CCamera::SetLEDIntensity(float _intrel) _intrel = max(_intrel, (float) 0); _intrel = _intrel / 100; led_intensity = (int) (_intrel * 8191); - printf("Set led_intensity to %d of 8191\n", led_intensity); + ESP_LOGD(TAGCAMERACLASS, "Set led_intensity to %d of 8191", led_intensity); } diff --git a/code/components/jomjol_controlcamera/server_camera.cpp b/code/components/jomjol_controlcamera/server_camera.cpp index 09cef729..87c2c9d7 100644 --- a/code/components/jomjol_controlcamera/server_camera.cpp +++ b/code/components/jomjol_controlcamera/server_camera.cpp @@ -7,6 +7,9 @@ #include "ClassControllCamera.h" #include "ClassLogFile.h" +#include "esp_log.h" + +static const char *TAG = "server_cam"; #define SCRATCH_BUFSIZE2 8192 char scratch2[SCRATCH_BUFSIZE2]; @@ -37,7 +40,7 @@ esp_err_t handler_lightOn(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON LogFile.WriteHeapInfo("handler_lightOn - Start"); - printf("handler_lightOn uri:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAG, "handler_lightOn uri: %s", req->uri); #endif Camera.LightOnOff(true); @@ -55,7 +58,7 @@ esp_err_t handler_lightOff(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON LogFile.WriteHeapInfo("handler_lightOff - Start"); - printf("handler_lightOff uri:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAG, "handler_lightOff uri: %s", req->uri); #endif Camera.LightOnOff(false); const char* resp_str = (const char*) req->user_ctx; @@ -80,7 +83,7 @@ esp_err_t handler_capture(httpd_req_t *req) Camera.GetCameraParameter(req, quality, res); #ifdef DEBUG_DETAIL_ON - printf("Size: %d", res); printf(" Quality: %d\n", quality); + ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); #endif Camera.SetQualitySize(quality, res); @@ -110,11 +113,11 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAG, "Query: %s", _query); if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Delay: "); printf(_delay); printf("\n"); + ESP_LOGD(TAG, "Delay: %s", _delay); #endif delay = atoi(_delay); @@ -126,7 +129,7 @@ esp_err_t handler_capture_with_ligth(httpd_req_t *req) Camera.GetCameraParameter(req, quality, res); #ifdef DEBUG_DETAIL_ON - printf("Size: %d", res); printf(" Quality: %d\n", quality); + ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); #endif Camera.SetQualitySize(quality, res); @@ -166,12 +169,12 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAG, "Query: %s", _query); if (httpd_query_key_value(_query, "filename", filename, 100) == ESP_OK) { fn.append(filename); #ifdef DEBUG_DETAIL_ON - printf("Filename: "); printf(fn.c_str()); printf("\n"); + ESP_LOGD(TAG, "Filename: %s", fn.c_str()); #endif } else @@ -180,7 +183,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) if (httpd_query_key_value(_query, "delay", _delay, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Delay: "); printf(_delay); printf("\n"); + ESP_LOGD(TAG, "Delay: %s", _delay); #endif delay = atoi(_delay); @@ -194,7 +197,7 @@ esp_err_t handler_capture_save_to_file(httpd_req_t *req) Camera.GetCameraParameter(req, quality, res); #ifdef DEBUG_DETAIL_ON - printf("Size: %d", res); printf(" Quality: %d\n", quality); + ESP_LOGD(TAG, "Size: %d, Quality: %d", res, quality); #endif Camera.SetQualitySize(quality, res); diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 0cd7bc7f..736e4473 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -67,7 +67,7 @@ bool isSetupModusActive() { void KillTFliteTasks() { #ifdef DEBUG_DETAIL_ON - printf("Handle: xHandleblink_task_doFlow: %ld\n", (long) xHandleblink_task_doFlow); + ESP_LOGD(TAGTFLITE, "Handle: xHandleblink_task_doFlow: %ld", (long) xHandleblink_task_doFlow); #endif if (xHandleblink_task_doFlow != NULL) { @@ -75,12 +75,12 @@ void KillTFliteTasks() xHandleblink_task_doFlow = NULL; vTaskDelete(xHandleblink_task_doFlowTmp); #ifdef DEBUG_DETAIL_ON - printf("Killed: xHandleblink_task_doFlow\n"); + ESP_LOGD(TAGTFLITE, "Killed: xHandleblink_task_doFlow"); #endif } #ifdef DEBUG_DETAIL_ON - printf("Handle: xHandletask_autodoFlow: %ld\n", (long) xHandletask_autodoFlow); + ESP_LOGD(TAGTFLITE, "Handle: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow); #endif if (xHandletask_autodoFlow != NULL) { @@ -88,7 +88,7 @@ void KillTFliteTasks() xHandletask_autodoFlow = NULL; vTaskDelete(xHandletask_autodoFlowTmp); #ifdef DEBUG_DETAIL_ON - printf("Killed: xHandletask_autodoFlow\n"); + ESP_LOGD(TAGTFLITE, "Killed: xHandletask_autodoFlow"); #endif } @@ -97,11 +97,11 @@ void KillTFliteTasks() void doInit(void) { #ifdef DEBUG_DETAIL_ON - printf("Start tfliteflow.InitFlow(config);\n"); + ESP_LOGD(TAGTFLITE, "Start tfliteflow.InitFlow(config);"); #endif tfliteflow.InitFlow(CONFIG_FILE); #ifdef DEBUG_DETAIL_ON - printf("Finished tfliteflow.InitFlow(config);\n"); + ESP_LOGD(TAGTFLITE, "Finished tfliteflow.InitFlow(config);"); #endif } @@ -110,13 +110,13 @@ bool doflow(void) { std::string zw_time = gettimestring(LOGFILE_TIME_FORMAT); - printf("doflow - start %s\n", zw_time.c_str()); + ESP_LOGD(TAGTFLITE, "doflow - start %s", zw_time.c_str()); flowisrunning = true; tfliteflow.doFlow(zw_time); flowisrunning = false; #ifdef DEBUG_DETAIL_ON - printf("doflow - end %s\n", zw_time.c_str()); + ESP_LOGD(TAGTFLITE, "doflow - end %s", zw_time.c_str()); #endif return true; } @@ -124,7 +124,7 @@ bool doflow(void) void blink_task_doFlow(void *pvParameter) { #ifdef DEBUG_DETAIL_ON - printf("blink_task_doFlow\n"); + ESP_LOGD(TAGTFLITE, "blink_task_doFlow"); #endif if (!flowisrunning) { @@ -141,7 +141,7 @@ esp_err_t handler_init(httpd_req_t *req) { #ifdef DEBUG_DETAIL_ON LogFile.WriteHeapInfo("handler_init - Start"); - printf("handler_doinit uri:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_doinit uri: %s", req->uri); #endif const char* resp_str = "Init started
"; @@ -167,7 +167,7 @@ esp_err_t handler_doflow(httpd_req_t *req) LogFile.WriteHeapInfo("handler_doflow - Start"); #endif - printf("handler_doFlow uri: "); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_doFlow uri: %s", req->uri); if (flowisrunning) { @@ -199,7 +199,7 @@ esp_err_t handler_json(httpd_req_t *req) #endif - printf("handler_JSON uri:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_JSON uri: %s", req->uri); char _query[100]; // char _size[10]; @@ -236,18 +236,18 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) std::string _type = "value"; string zw; - printf("handler_wasserzaehler uri:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_wasserzaehler uri: %s", req->uri); char _query[100]; char _size[10]; if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { -// printf("Query: "); printf(_query); printf("\n"); +// ESP_LOGD(TAGTFLITE, "Query: %s", _query); if (httpd_query_key_value(_query, "all", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("all is found"); printf(_size); printf("\n"); + ESP_LOGD(TAGTFLITE, "all is found%s", _size); #endif _all = true; } @@ -255,7 +255,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) if (httpd_query_key_value(_query, "type", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("all is found"); printf(_size); printf("\n"); + ESP_LOGD(TAGTFLITE, "all is found: %s", _size); #endif _type = std::string(_size); } @@ -263,14 +263,14 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) if (httpd_query_key_value(_query, "rawvalue", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("rawvalue is found"); printf(_size); printf("\n"); + ESP_LOGD(TAGTFLITE, "rawvalue is found: %s", _size); #endif _rawValue = true; } if (httpd_query_key_value(_query, "noerror", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("noerror is found"); printf(_size); printf("\n"); + ESP_LOGD(TAGTFLITE, "noerror is found: %s", _size); #endif _noerror = true; } @@ -281,7 +281,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) if (_all) { httpd_resp_set_type(req, "text/plain"); - printf("TYPE: %s\n", _type.c_str()); + ESP_LOGD(TAGTFLITE, "TYPE: %s", _type.c_str()); int _intype = READOUT_TYPE_VALUE; if (_type == "prevalue") _intype = READOUT_TYPE_PREVALUE; @@ -292,7 +292,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) zw = tfliteflow.getReadoutAll(_intype); - printf("ZW: %s\n", zw.c_str()); + ESP_LOGD(TAGTFLITE, "ZW: %s", zw.c_str()); if (zw.length() > 0) httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); @@ -304,7 +304,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req) httpd_resp_sendstr_chunk(req, zw.c_str()); string query = std::string(_query); -// printf("Query: %s\n", query.c_str()); +// ESP_LOGD(TAGTFLITE, "Query: %s, query.c_str()); if (query.find("full") != std::string::npos) { string txt, zw; @@ -380,7 +380,7 @@ esp_err_t handler_editflow(httpd_req_t *req) LogFile.WriteHeapInfo("handler_editflow - Start"); #endif - printf("handler_editflow uri: "); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_editflow uri: %s", req->uri); char _query[200]; char _valuechar[30]; @@ -391,7 +391,7 @@ esp_err_t handler_editflow(httpd_req_t *req) if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("task is found: %s\n", _valuechar); + ESP_LOGD(TAGTFLITE, "task is found: %s", _valuechar); #endif _task = string(_valuechar); } @@ -399,7 +399,7 @@ esp_err_t handler_editflow(httpd_req_t *req) if (_task.compare("tflite") == 0) { - printf("Get tflite list\n"); + ESP_LOGD(TAGTFLITE, "Get tflite list"); return get_tflite_file_handler(req); } @@ -414,8 +414,8 @@ esp_err_t handler_editflow(httpd_req_t *req) out = string(_valuechar); #ifdef DEBUG_DETAIL_ON - printf("in: "); printf(in.c_str()); printf("\n"); - printf("out: "); printf(out.c_str()); printf("\n"); + ESP_LOGD(TAGTFLITE, "in: %s", in.c_str()); + ESP_LOGD(TAGTFLITE, "out: %s", out.c_str()); #endif in = "/sdcard" + in; @@ -456,12 +456,12 @@ esp_err_t handler_editflow(httpd_req_t *req) dy = stoi(zw); #ifdef DEBUG_DETAIL_ON - printf("in: "); printf(in.c_str()); printf("\n"); - printf("out: "); printf(out.c_str()); printf("\n"); - printf("x: "); printf(zw.c_str()); printf("\n"); - printf("y: "); printf(zw.c_str()); printf("\n"); - printf("dx: "); printf(zw.c_str()); printf("\n"); - printf("dy: "); printf(zw.c_str()); printf("\n"); + ESP_LOGD(TAGTFLITE, "in: %s", in.c_str()); + ESP_LOGD(TAGTFLITE, "out: %s", out.c_str()); + ESP_LOGD(TAGTFLITE, "x: %s", zw.c_str()); + ESP_LOGD(TAGTFLITE, "y: %s", zw.c_str()); + ESP_LOGD(TAGTFLITE, "dx: %s", zw.c_str()); + ESP_LOGD(TAGTFLITE, "dy: %s", zw.c_str()); #endif if (httpd_query_key_value(_query, "enhance", _valuechar, 10) == ESP_OK) @@ -529,11 +529,11 @@ esp_err_t handler_editflow(httpd_req_t *req) } -// printf("Parameter host: "); printf(_host.c_str()); printf("\n"); -// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str()); +// ESP_LOGD(TAGTFLITE, "Parameter host: %s", _host.c_str()); +// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAGTFLITE, zwzw.c_str()); Camera.SetBrightnessContrastSaturation(bri, con, sat); Camera.SetLEDIntensity(intens); - printf("test_take - vor MakeImage"); + ESP_LOGD(TAGTFLITE, "test_take - vor MakeImage"); std::string zw = tfliteflow.doSingleStep("[MakeImage]", _host); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_sendstr_chunk(req, zw.c_str()); @@ -546,9 +546,9 @@ esp_err_t handler_editflow(httpd_req_t *req) if (httpd_query_key_value(_query, "host", _valuechar, 30) == ESP_OK) { _host = std::string(_valuechar); } -// printf("Parameter host: "); printf(_host.c_str()); printf("\n"); +// ESP_LOGD(TAGTFLITE, "Parameter host: %s", _host.c_str()); -// string zwzw = "Do " + _task + " start\n"; printf(zwzw.c_str()); +// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAGTFLITE, zwzw.c_str()); std::string zw = tfliteflow.doSingleStep("[Alignment]", _host); httpd_resp_sendstr_chunk(req, zw.c_str()); } @@ -573,7 +573,7 @@ esp_err_t handler_statusflow(httpd_req_t *req) const char* resp_str; #ifdef DEBUG_DETAIL_ON - printf("handler_prevalue:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_prevalue: %s", req->uri); #endif string* zw = tfliteflow.getActStatus(); @@ -651,7 +651,7 @@ esp_err_t handler_prevalue(httpd_req_t *req) string zw; #ifdef DEBUG_DETAIL_ON - printf("handler_prevalue:\n"); printf(req->uri); printf("\n"); + ESP_LOGD(TAGTFLITE, "handler_prevalue: %s", req->uri); #endif char _query[100]; @@ -661,13 +661,13 @@ esp_err_t handler_prevalue(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAGTFLITE, "Query: %s", _query); #endif if (httpd_query_key_value(_query, "value", _size, 10) == ESP_OK) { #ifdef DEBUG_DETAIL_ON - printf("Value: "); printf(_size); printf("\n"); + ESP_LOGD(TAGTFLITE, "Value: %s", _size); #endif } @@ -703,7 +703,7 @@ void task_autodoFlow(void *pvParameter) { int64_t fr_start, fr_delta_ms; - printf("task_autodoFlow: start\r\n"); + ESP_LOGD(TAGTFLITE, "task_autodoFlow: start"); doInit(); gpio_handler_init(); @@ -718,24 +718,24 @@ void task_autodoFlow(void *pvParameter) { std::string _zw = "task_autodoFlow - next round - Round #" + std::to_string(++countRounds); LogFile.WriteToFile(_zw); - printf("Autoflow: start\n"); + ESP_LOGD(TAGTFLITE, "Autoflow: start"); fr_start = esp_timer_get_time(); if (flowisrunning) { #ifdef DEBUG_DETAIL_ON - printf("Autoflow: doFlow is already running!\n"); + ESP_LOGD(TAGTFLITE, "Autoflow: doFlow is already running!"); #endif } else { #ifdef DEBUG_DETAIL_ON - printf("Autoflow: doFlow is started\n"); + ESP_LOGD(TAGTFLITE, "Autoflow: doFlow is started"); #endif flowisrunning = true; doflow(); #ifdef DEBUG_DETAIL_ON - printf("Remove older log files\n"); + ESP_LOGD(TAGTFLITE, "Remove older log files"); #endif LogFile.RemoveOld(); } @@ -747,18 +747,18 @@ void task_autodoFlow(void *pvParameter) stream << std::fixed << std::setprecision(1) << cputmp; string zwtemp = "CPU Temperature: " + stream.str(); LogFile.WriteToFile(zwtemp); - printf("CPU Temperature: %.2f\n", cputmp); + ESP_LOGD(TAGTFLITE, "CPU Temperature: %.2f", cputmp); fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000; if (auto_intervall > fr_delta_ms) { const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS; - printf("Autoflow: sleep for : %ldms\n", (long) xDelay); + ESP_LOGD(TAGTFLITE, "Autoflow: sleep for : %ldms", (long) xDelay); vTaskDelay( xDelay ); } } vTaskDelete(NULL); //Delete this task if it exits from the loop above xHandletask_autodoFlow = NULL; - printf("task_autodoFlow: end\r\n"); + ESP_LOGD(TAGTFLITE, "task_autodoFlow: end"); } void TFliteDoAutoStart() @@ -767,17 +767,17 @@ void TFliteDoAutoStart() int _i = configMINIMAL_STACK_SIZE; - printf("task_autodoFlow configMINIMAL_STACK_SIZE: %d\n", _i); - printf("getESPHeapInfo: %s\n", getESPHeapInfo().c_str()); + ESP_LOGD(TAGTFLITE, "task_autodoFlow configMINIMAL_STACK_SIZE: %d", _i); + ESP_LOGD(TAGTFLITE, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); xReturned = xTaskCreate(&task_autodoFlow, "task_autodoFlow", configMINIMAL_STACK_SIZE * 35, NULL, tskIDLE_PRIORITY+1, &xHandletask_autodoFlow); if( xReturned != pdPASS ) { //Memory: 64 --> 48 --> 35 --> 25 - printf("ERROR task_autodoFlow konnte nicht erzeugt werden !!\r\n"); + ESP_LOGD(TAGTFLITE, "ERROR task_autodoFlow konnte nicht erzeugt werden!"); } - printf("getESPHeapInfo: %s\n", getESPHeapInfo().c_str()); + ESP_LOGD(TAGTFLITE, "getESPHeapInfo: %s", getESPHeapInfo().c_str()); } diff --git a/code/components/jomjol_time_sntp/time_sntp.cpp b/code/components/jomjol_time_sntp/time_sntp.cpp index 240a36d9..c4fcae82 100644 --- a/code/components/jomjol_time_sntp/time_sntp.cpp +++ b/code/components/jomjol_time_sntp/time_sntp.cpp @@ -78,14 +78,14 @@ void setup_time() ESP_LOGI(TAG, "The current date/time in Berlin is: %s", strftime_buf); std::string zw = gettimestring("%Y%m%d-%H%M%S"); - printf("timeist %s\n", zw.c_str()); + ESP_LOGD(TAG, "timeist %s", zw.c_str()); } void setTimeZone(std::string _tzstring) { setenv("TZ", _tzstring.c_str(), 1); tzset(); - printf("TimeZone set to %s\n", _tzstring.c_str()); + ESP_LOGD(TAG, "TimeZone set to %s", _tzstring.c_str()); _tzstring = "Time zone set to " + _tzstring; LogFile.WriteToFile(_tzstring); } @@ -109,14 +109,14 @@ static void obtain_time(void) void reset_servername(std::string _servername) { - printf("Set SNTP-Server: %s\n", _servername.c_str()); + ESP_LOGD(TAG, "Set SNTP-Server: %s", _servername.c_str()); sntp_stop(); sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, _servername.c_str()); sntp_init(); obtain_time(); std::string zw = gettimestring("%Y%m%d-%H%M%S"); - printf("Time ist %s\n", zw.c_str()); + ESP_LOGD(TAG, "Time ist %s", zw.c_str()); } static void initialize_sntp(void) diff --git a/code/components/jomjol_wlan/read_wlanini.cpp b/code/components/jomjol_wlan/read_wlanini.cpp index b10a0ec4..e1a9f8c9 100644 --- a/code/components/jomjol_wlan/read_wlanini.cpp +++ b/code/components/jomjol_wlan/read_wlanini.cpp @@ -10,7 +10,9 @@ #include #include #include +#include "esp_log.h" +static const char *TAG = "read_wlanini"; std::vector ZerlegeZeileWLAN(std::string input, std::string _delimiter = "") { @@ -55,7 +57,7 @@ void LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_ho fn = FormatFileName(fn); pFile = OpenFileAndWait(fn.c_str(), "r"); - printf("file loaded\n"); + ESP_LOGD(TAG, "file loaded"); if (pFile == NULL) return; @@ -66,7 +68,7 @@ void LoadWlanFromFile(std::string fn, char *&_ssid, char *&_password, char *&_ho while ((line.size() > 0) || !(feof(pFile))) { -// printf("%s", line.c_str()); +// ESP_LOGD(TAG, "%s", line.c_str()); zerlegt = ZerlegeZeileWLAN(line, "="); zerlegt[0] = trim(zerlegt[0], " "); @@ -198,7 +200,7 @@ bool ChangeHostName(std::string fn, std::string _newhostname) fn = FormatFileName(fn); pFile = OpenFileAndWait(fn.c_str(), "r"); - printf("file loaded\n"); + ESP_LOGD(TAG, "file loaded\n"); if (pFile == NULL) return false; @@ -248,7 +250,7 @@ bool ChangeHostName(std::string fn, std::string _newhostname) fclose(pFile); - printf("*** Hostname update done ***\n"); + ESP_LOGD(TAG, "*** Hostname update done ***"); return true; } diff --git a/code/main/main.cpp b/code/main/main.cpp index 40fbb43b..6744d05c 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -126,7 +126,7 @@ void task_NoSDBlink(void *pvParameter) TickType_t xDelay; xDelay = 100 / portTICK_PERIOD_MS; - printf("SD-Card could not be inialized - STOP THE PROGRAMM HERE\n"); + ESP_LOGD(TAGMAIN, "SD-Card could not be inialized - STOP THE PROGRAMM HERE"); while (1) { @@ -146,15 +146,15 @@ extern "C" void app_main(void) string versionFormated = "Branch: '" + std::string(GIT_BRANCH) + "', Tag: '" + std::string(GIT_TAG) + \ "', Revision: " + std::string(GIT_REV) +", Date/Time: " + std::string(BUILD_TIME); - printf("=============================================================================================\n"); - printf("%s\n", versionFormated.c_str()); - printf("=============================================================================================\n"); + ESP_LOGD(TAGMAIN, "============================================================================================="); + ESP_LOGD(TAGMAIN, "%s", versionFormated.c_str()); + ESP_LOGD(TAGMAIN, "============================================================================================="); PowerResetCamera(); esp_err_t cam = Camera.InitCam(); Camera.LightOnOff(false); xDelay = 2000 / portTICK_PERIOD_MS; - printf("After camera initialization: sleep for : %ldms\n", (long) xDelay); + ESP_LOGD(TAGMAIN, "After camera initialization: sleep for : %ldms", (long) xDelay); vTaskDelay( xDelay ); @@ -171,30 +171,30 @@ extern "C" void app_main(void) if (ssid != NULL && passwd != NULL) #ifdef __HIDE_PASSWORD - printf("\nWLan: %s, XXXXXX\n", ssid); + ESP_LOGD(TAGMAIN, "WLan: %s, XXXXXX", ssid); #else - printf("\nWLan: %s, %s\n", ssid, passwd); + ESP_LOGD(TAGMAIN, "WLan: %s, %s", ssid, passwd); #endif else - printf("No SSID and PASSWORD set!!!"); + ESP_LOGD(TAGMAIN, "No SSID and PASSWORD set!!!"); if (hostname != NULL) - printf("Hostename: %s\n", hostname); + ESP_LOGD(TAGMAIN, "Hostename: %s", hostname); else - printf("Hostname not set.\n"); + ESP_LOGD(TAGMAIN, "Hostname not set"); if (ip != NULL && gateway != NULL && netmask != NULL) - printf("Fixed IP: %s, Gateway %s, Netmask %s\n", ip, gateway, netmask); + ESP_LOGD(TAGMAIN, "Fixed IP: %s, Gateway %s, Netmask %s", ip, gateway, netmask); if (dns != NULL) - printf("DNS IP: %s\n", dns); + ESP_LOGD(TAGMAIN, "DNS IP: %s", dns); wifi_init_sta(ssid, passwd, hostname, ip, gateway, netmask, dns); xDelay = 2000 / portTICK_PERIOD_MS; - printf("main: sleep for : %ldms\n", (long) xDelay); + ESP_LOGD(TAGMAIN, "main: sleep for : %ldms", (long) xDelay); vTaskDelay( xDelay ); setup_time(); setBootTime(); @@ -205,14 +205,14 @@ extern "C" void app_main(void) LogFile.SwitchOnOff(false); std::string zw = gettimestring("%Y%m%d-%H%M%S"); - printf("time %s\n", zw.c_str()); + ESP_LOGD(TAGMAIN, "time %s", zw.c_str()); size_t _hsize = getESPHeapSize(); if (_hsize < 4000000) { std::string _zws = "Not enough PSRAM available. Expected 4.194.304 MByte - available: " + std::to_string(_hsize); _zws = _zws + "\nEither not initialzed, too small (2MByte only) or not present at all. Firmware cannot start!!"; - printf(_zws.c_str()); + ESP_LOGD(TAGMAIN, "%s", _zws.c_str()); LogFile.SwitchOnOff(true); LogFile.WriteToFile(_zws); LogFile.SwitchOnOff(false); @@ -243,10 +243,10 @@ extern "C" void app_main(void) xDelay = 2000 / portTICK_PERIOD_MS; - printf("main: sleep for : %ldms\n", (long) xDelay*10); + ESP_LOGD(TAGMAIN, "main: sleep for : %ldms", (long) xDelay*10); vTaskDelay( xDelay ); - printf("starting server\n"); + ESP_LOGD(TAGMAIN, "starting server"); server = start_webserver(); register_server_camera_uri(server); @@ -256,10 +256,10 @@ extern "C" void app_main(void) gpio_handler_create(server); - printf("vor reg server main\n"); + ESP_LOGD(TAGMAIN, "vor reg server main"); register_server_main_uri(server, "/sdcard"); - printf("vor dotautostart\n"); + ESP_LOGD(TAGMAIN, "vor dotautostart"); TFliteDoAutoStart(); } diff --git a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp index 01656575..6e20e395 100644 --- a/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp +++ b/code/test/components/jomjol-flowcontroll/test_flow_postrocess_helper.cpp @@ -1,7 +1,7 @@ #include "test_flow_postrocess_helper.h" #include "esp_log.h" -static const char *TAG_POSTPROC_HELPER = "test_flow_postproc_helper"; +static const char *TAG = "test_flow_postproc_helper"; UnderTestPost* setUpClassFlowPostprocessing(t_CNNType digType, t_CNNType anaType) { @@ -38,7 +38,7 @@ std::string process_doFlow(std::vector analog, std::vector digits, bool checkConsistency, bool extendedResolution, int decimal_shift) { // setup the classundertest UnderTestPost* _undertestPost = init_do_flow(analog, digits, digType, checkConsistency, extendedResolution, decimal_shift); - ESP_LOGD(TAG_POSTPROC_HELPER, "SetupClassFlowPostprocessing completed."); + ESP_LOGD(TAG, "SetupClassFlowPostprocessing completed."); string time; // run test @@ -83,7 +83,7 @@ UnderTestPost* init_do_flow(std::vector analog, std::vector digits gen_analog->ROI.push_back(anaROI); } } - ESP_LOGD(TAG_POSTPROC_HELPER, "Setting up of ROIs completed."); + ESP_LOGD(TAG, "Setting up of ROIs completed."); _undertestPost->InitNUMBERS(); @@ -97,7 +97,7 @@ UnderTestPost* init_do_flow(std::vector analog, std::vector digits void setPreValue(UnderTestPost* _underTestPost, double _preValue) { if (_preValue>0) { - ESP_LOGD(TAG_POSTPROC_HELPER, "preValue=%f", _preValue); + ESP_LOGD(TAG, "preValue=%f", _preValue); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->PreValue = _preValue; @@ -106,7 +106,7 @@ void setPreValue(UnderTestPost* _underTestPost, double _preValue) { } void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) { - ESP_LOGD(TAG_POSTPROC_HELPER, "checkConsistency=true"); + ESP_LOGD(TAG, "checkConsistency=true"); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->AllowNegativeRates = _allowNegatives; @@ -116,7 +116,7 @@ void setAllowNegatives(UnderTestPost* _underTestPost, bool _allowNegatives) { void setConsitencyCheck(UnderTestPost* _underTestPost, bool _checkConsistency) { if (_checkConsistency) { - ESP_LOGD(TAG_POSTPROC_HELPER, "checkConsistency=true"); + ESP_LOGD(TAG, "checkConsistency=true"); std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { (*NUMBERS)[_n]->checkDigitIncreaseConsistency = true; @@ -138,7 +138,7 @@ void setDecimalShift(UnderTestPost* _underTestPost, int _decimal_shift) { if (_decimal_shift!=0) { std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { - ESP_LOGD(TAG_POSTPROC_HELPER, "Setting decimal shift on number: %d to %d", _n, _decimal_shift); + ESP_LOGD(TAG, "Setting decimal shift on number: %d to %d", _n, _decimal_shift); (*NUMBERS)[_n]->DecimalShift = _decimal_shift; (*NUMBERS)[_n]->DecimalShiftInitial = _decimal_shift; } @@ -149,7 +149,7 @@ void setAnalogdigitTransistionStart(UnderTestPost* _underTestPost, float _analog if (_analogdigitTransistionStart!=0) { std::vector* NUMBERS = _underTestPost->GetNumbers(); for (int _n = 0; _n < (*NUMBERS).size(); ++_n) { - ESP_LOGD(TAG_POSTPROC_HELPER, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart); + ESP_LOGD(TAG, "Setting decimal shift on number: %d to %f", _n, _analogdigitTransistionStart); (*NUMBERS)[_n]->AnalogDigitalTransitionStart = _analogdigitTransistionStart; } } From a512d82793b0054c4c3860b161709f39650831db Mon Sep 17 00:00:00 2001 From: George Ruinelli Date: Fri, 21 Oct 2022 22:13:13 +0200 Subject: [PATCH 19/44] . --- .../jomjol_configfile/configFile.cpp | 7 +- .../jomjol_controlGPIO/server_GPIO.cpp | 14 +-- .../jomjol_fileserver_ota/server_file.cpp | 96 ++++++++++--------- .../jomjol_fileserver_ota/server_ota.cpp | 47 ++++----- .../jomjol_flowcontroll/ClassFlow.cpp | 10 +- .../jomjol_image_proc/CImageBasis.cpp | 2 +- .../jomjol_tfliteclass/CTfLiteClass.cpp | 34 ++++--- .../jomjol_tfliteclass/server_tflite.cpp | 2 +- code/main/main.cpp | 6 +- 9 files changed, 111 insertions(+), 107 deletions(-) diff --git a/code/components/jomjol_configfile/configFile.cpp b/code/components/jomjol_configfile/configFile.cpp index ec1f5928..45647dd9 100644 --- a/code/components/jomjol_configfile/configFile.cpp +++ b/code/components/jomjol_configfile/configFile.cpp @@ -4,8 +4,9 @@ #include "Helper.h" #include "configFile.h" +#include -//static const char *TAGCONFIGFILE = "configFile"; +static const char *TAG = "configFile"; ConfigFile::ConfigFile(std::string filePath) { @@ -48,7 +49,7 @@ bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof) if (fgets(zw, 1024, pFile)) { - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); if ((strlen(zw) == 0) && feof(pFile)) { *rt = ""; @@ -67,7 +68,7 @@ bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof) while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph { fgets(zw, 1024, pFile); - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); if (feof(pFile)) { *rt = ""; diff --git a/code/components/jomjol_controlGPIO/server_GPIO.cpp b/code/components/jomjol_controlGPIO/server_GPIO.cpp index b6cb5a4c..0af942f9 100644 --- a/code/components/jomjol_controlGPIO/server_GPIO.cpp +++ b/code/components/jomjol_controlGPIO/server_GPIO.cpp @@ -210,10 +210,10 @@ GpioHandler::~GpioHandler() { void GpioHandler::init() { // TickType_t xDelay = 60000 / portTICK_PERIOD_MS; - // printf("wait before start %ldms\r\n", (long) xDelay); + // ESP_LOGD(TAG_SERVERGPIO, "wait before start %ldms", (long) xDelay); // vTaskDelay( xDelay ); - printf("*************** Start GPIOHandler_Init *****************\n"); + ESP_LOGD(TAG_SERVERGPIO, "*************** Start GPIOHandler_Init *****************"); if (gpioMap == NULL) { gpioMap = new std::map(); @@ -300,13 +300,13 @@ bool GpioHandler::readConfig() bool eof = false; gpio_num_t gpioExtLED = (gpio_num_t) 0; -// printf("readConfig - Start 1\n"); +// ESP_LOGD(TAG_SERVERGPIO, "readConfig - Start 1"); while ((!configFile.GetNextParagraph(line, disabledLine, eof) || (line.compare("[GPIO]") != 0)) && !eof) {} if (eof) return false; -// printf("readConfig - Start 2 line: %s, disabbledLine: %d\n", line.c_str(), (int) disabledLine); +// ESP_LOGD(TAG_SERVERGPIO, "readConfig - Start 2 line: %s, disabbledLine: %d", line.c_str(), (int) disabledLine); _isEnabled = !disabledLine; @@ -314,7 +314,7 @@ bool GpioHandler::readConfig() if (!_isEnabled) return false; -// printf("readConfig - Start 3\n"); +// ESP_LOGD(TAG_SERVERGPIO, "readConfig - Start 3"); // std::string mainTopicMQTT = ""; std::string mainTopicMQTT = GetMQTTMainTopic(); @@ -359,7 +359,7 @@ bool GpioHandler::readConfig() if (pinMode == GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X) { - printf("Set WS2812 to GPIO %d\n", gpioNr); + ESP_LOGD(TAG_SERVERGPIO, "Set WS2812 to GPIO %d", gpioNr); gpioExtLED = gpioNr; } @@ -403,7 +403,7 @@ bool GpioHandler::readConfig() // LogFile.WriteToFile("Startsequence 06"); // Nremove // vTaskDelay( xDelay ); // xDelay = 5000 / portTICK_PERIOD_MS; -// printf("main: sleep for : %ldms\n", (long) xDelay); +// ESP_LOGD(TAG_SERVERGPIO, "main: sleep for: %ldms", (long) xDelay); // SmartLed leds( LED_WS2812, 2, GPIO_NUM_12, 0, DoubleBuffer ); diff --git a/code/components/jomjol_fileserver_ota/server_file.cpp b/code/components/jomjol_fileserver_ota/server_file.cpp index 6b54f531..22e1b064 100644 --- a/code/components/jomjol_fileserver_ota/server_file.cpp +++ b/code/components/jomjol_fileserver_ota/server_file.cpp @@ -43,6 +43,8 @@ extern "C" { #include "Helper.h" #include "miniz.h" +static const char *TAG = "server_file"; + /* Max length a file path can have on storage */ // #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN) #define FILE_PATH_MAX (255) @@ -88,7 +90,7 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) size_t pos = 0; const char verz_name[] = "/sdcard/config"; - printf("Suche TFLITE in /sdcard/config/\n"); + ESP_LOGD(TAG, "Suche TFLITE in /sdcard/config/"); httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_set_type(req, "text/plain"); @@ -97,7 +99,7 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) while ((entry = readdir(dir)) != NULL) { _filename = std::string(entry->d_name); - printf("File: %s\t", _filename.c_str()); + ESP_LOGD(TAG, "File: %s", _filename.c_str()); // ignore all files with starting dot (hidden files) if (_filename.rfind(".", 0) == 0) { @@ -109,7 +111,7 @@ esp_err_t get_tflite_file_handler(httpd_req_t *req) if (pos != std::string::npos) _fileext = _fileext.erase(0, pos + 1); - printf(" Extension: %s\n", _fileext.c_str()); + ESP_LOGD(TAG, " Extension: %s", _fileext.c_str()); if ((_fileext == "tfl") || (_fileext == "tflite")) { @@ -147,11 +149,11 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const DIR *dir = opendir(dirpath_corrected); const size_t dirpath_len = strlen(dirpath); - printf("Dirpath: <%s>, Pathlength: %d\n", dirpath, dirpath_len); + ESP_LOGD(TAG, "Dirpath: <%s>, Pathlength: %d", dirpath, dirpath_len); /* Retrieve the base path of file storage to construct the full path */ strlcpy(entrypath, dirpath, sizeof(entrypath)); - printf("entrypath: <%s>\n", entrypath); + ESP_LOGD(TAG, "entrypath: <%s>", entrypath); if (!dir) { ESP_LOGE(TAG_FILESERVER, "Failed to stat dir : %s", dirpath); @@ -170,7 +172,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const size_t chunksize; do { chunksize = fread(chunk, 1, SCRATCH_BUFSIZE, fd); - // printf("Chunksize %d\n", chunksize); + // ESP_LOGD(TAG, "Chunksize %d", chunksize); if (chunksize > 0){ if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) { fclose(fd); @@ -211,7 +213,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const entrytype = (entry->d_type == DT_DIR ? "directory" : "file"); strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len); - printf("Entrypath: %s\n", entrypath); + ESP_LOGD(TAG, "Entrypath: %s", entrypath); if (stat(entrypath, &entry_stat) == -1) { ESP_LOGE(TAG_FILESERVER, "Failed to stat %s : %s", entrytype, entry->d_name); continue; @@ -266,11 +268,11 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req) char filepath[FILE_PATH_MAX]; FILE *fd = NULL; //struct stat file_stat; - printf("uri: %s\n", req->uri); + ESP_LOGD(TAG, "uri: %s", req->uri); const char* filename = "log_current.txt"; - printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); std::string currentfilename = LogFile.GetCurrentFileName(); @@ -331,12 +333,12 @@ static esp_err_t download_get_handler(httpd_req_t *req) char filepath[FILE_PATH_MAX]; FILE *fd = NULL; struct stat file_stat; - printf("uri: %s\n", req->uri); + ESP_LOGD(TAG, "uri: %s", req->uri); const char *filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, req->uri + sizeof("/fileserver") - 1, sizeof(filepath)); - printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); // filename = get_path_from_uri(filepath, ((struct file_server_data *)req->user_ctx)->base_path, // req->uri, sizeof(filepath)); @@ -366,7 +368,7 @@ static esp_err_t download_get_handler(httpd_req_t *req) } } - printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath); + ESP_LOGD(TAG, "uri: %s, filename: %s, filepath: %s", req->uri, filename, filepath); return http_resp_dir_html(req, filepath, filename, readonly); } @@ -541,12 +543,12 @@ static esp_err_t upload_post_handler(httpd_req_t *req) } int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); - printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found); + ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); directory = directory.substr(start_fn, found - start_fn + 1); - printf("Directory danach 1: %s\n", directory.c_str()); + ESP_LOGD(TAG, "Directory danach 1: %s", directory.c_str()); directory = "/fileserver" + directory; - printf("Directory danach 2: %s\n", directory.c_str()); + ESP_LOGD(TAG, "Directory danach 2: %s", directory.c_str()); /* Redirect onto root to see the updated file list */ httpd_resp_set_status(req, "303 See Other"); @@ -559,7 +561,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req) /* if (strcmp(filepath, CONFIG_FILE) == 0) { - printf("New config found. Reload handler."); + ESP_LOGD(TAG, "New config found. Reload handler."); gpio_handler_deinit(); MQTTdestroy(); } @@ -586,11 +588,11 @@ static esp_err_t delete_post_handler(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAG, "Query: %s", _query); if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) { - printf("task is found: "); printf(_valuechar); printf("\n"); + ESP_LOGD(TAG, "task is found: %s", _valuechar); _task = std::string(_valuechar); } } @@ -610,12 +612,12 @@ static esp_err_t delete_post_handler(httpd_req_t *req) zw = zw.substr(0, zw.length()-1); directory = "/fileserver" + zw + "/"; zw = "/sdcard" + zw; - printf("Directory to delete: %s\n", zw.c_str()); + ESP_LOGD(TAG, "Directory to delete: %s", zw.c_str()); delete_all_in_directory(zw); // directory = std::string(filepath); // directory = "/fileserver" + directory; - printf("Location after delete directory content: %s\n", directory.c_str()); + ESP_LOGD(TAG, "Location after delete directory content: %s", directory.c_str()); /* Redirect onto root to see the updated file list */ // httpd_resp_set_status(req, "303 See Other"); // httpd_resp_set_hdr(req, "Location", directory.c_str()); @@ -663,12 +665,12 @@ static esp_err_t delete_post_handler(httpd_req_t *req) } int start_fn = strlen(((struct file_server_data *)req->user_ctx)->base_path); - printf("Directory: %s, start_fn: %d, found: %d\n", directory.c_str(), start_fn, found); + ESP_LOGD(TAG, "Directory: %s, start_fn: %d, found: %d", directory.c_str(), start_fn, found); directory = directory.substr(start_fn, found - start_fn + 1); - printf("Directory danach 3: %s\n", directory.c_str()); + ESP_LOGD(TAG, "Directory danach 3: %s", directory.c_str()); directory = "/fileserver" + directory; - printf("Directory danach 4: %s\n", directory.c_str()); + ESP_LOGD(TAG, "Directory danach 4: %s", directory.c_str()); } @@ -722,18 +724,18 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st std::string directory = ""; // static const char* s_Test_archive_filename = "testhtml.zip"; - printf("miniz.c version: %s\n", MZ_VERSION); - printf("Zipfile: %s\n", _in_zip_file.c_str()); - printf("Target Dir ZIP: %s\n", _target_zip.c_str()); - printf("Target Dir BIN: %s\n", _target_bin.c_str()); - printf("Target Dir main: %s\n", _main.c_str()); + ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION); + ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); + ESP_LOGD(TAG, "Target Dir ZIP: %s", _target_zip.c_str()); + ESP_LOGD(TAG, "Target Dir BIN: %s", _target_bin.c_str()); + ESP_LOGD(TAG, "Target Dir main: %s", _main.c_str()); // Now try to open the archive. memset(&zip_archive, 0, sizeof(zip_archive)); status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); if (!status) { - printf("mz_zip_reader_init_file() failed!\n"); + ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!"); return ret; } @@ -745,7 +747,7 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0); if (!status) { - printf("mz_zip_reader_init_file() failed!\n"); + ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!"); return ret; } @@ -760,14 +762,14 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); if (!p) { - printf("mz_zip_reader_extract_file_to_heap() failed on file %s\n", archive_filename); + ESP_LOGD(TAG, "mz_zip_reader_extract_file_to_heap() failed on file %s", archive_filename); mz_zip_reader_end(&zip_archive); return ret; } // Save to File. zw = std::string(archive_filename); - printf("Rohfilename: %s\n", zw.c_str()); + ESP_LOGD(TAG, "Rohfilename: %s", zw.c_str()); if (getFileType(zw) == "BIN") { @@ -791,7 +793,7 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st string filename_zw = zw + SUFFIX_ZW; - printf("Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str()); + ESP_LOGD(TAG, "Filename to extract: %s, Zwischenfilename: %s", zw.c_str(), filename_zw.c_str()); // extrahieren in zwischendatei DeleteFile(filename_zw); @@ -803,8 +805,8 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st RenameFile(filename_zw, zw); DeleteFile(filename_zw); - printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size); - // printf("File data: \"%s\"\n", (const char*)p); + ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size); + // ESP_LOGD(TAG, "File data: \"%s\"", (const char*)p); // We're done. mz_free(p); @@ -815,7 +817,7 @@ std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::st mz_zip_reader_end(&zip_archive); } - printf("Success.\n"); + ESP_LOGD(TAG, "Success."); return ret; } @@ -829,16 +831,16 @@ void unzip(std::string _in_zip_file, std::string _target_directory){ std::string zw; // static const char* s_Test_archive_filename = "testhtml.zip"; - printf("miniz.c version: %s\n", MZ_VERSION); - printf("Zipfile: %s\n", _in_zip_file.c_str()); - printf("Target Dir: %s\n", _target_directory.c_str()); + ESP_LOGD(TAG, "miniz.c version: %s", MZ_VERSION); + ESP_LOGD(TAG, "Zipfile: %s", _in_zip_file.c_str()); + ESP_LOGD(TAG, "Target Dir: %s", _target_directory.c_str()); // Now try to open the archive. memset(&zip_archive, 0, sizeof(zip_archive)); status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0); if (!status) { - printf("mz_zip_reader_init_file() failed!\n"); + ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!"); return; } @@ -850,7 +852,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){ status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0); if (!status) { - printf("mz_zip_reader_init_file() failed!\n"); + ESP_LOGD(TAG, "mz_zip_reader_init_file() failed!"); return; } @@ -864,7 +866,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){ p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0); if (!p) { - printf("mz_zip_reader_extract_file_to_heap() failed!\n"); + ESP_LOGD(TAG, "mz_zip_reader_extract_file_to_heap() failed!"); mz_zip_reader_end(&zip_archive); return; } @@ -872,13 +874,13 @@ void unzip(std::string _in_zip_file, std::string _target_directory){ // Save to File. zw = std::string(archive_filename); zw = _target_directory + zw; - printf("Filename to extract: %s", zw.c_str()); + ESP_LOGD(TAG, "Filename to extract: %s", zw.c_str()); FILE* fpTargetFile = OpenFileAndWait(zw.c_str(), "wb"); fwrite(p, 1, (uint)uncomp_size, fpTargetFile); fclose(fpTargetFile); - printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size); - // printf("File data: \"%s\"\n", (const char*)p); + ESP_LOGD(TAG, "Successfully extracted file \"%s\", size %u", archive_filename, (uint)uncomp_size); + // ESP_LOGD(TAG, "File data: \"%s\"", (const char*)p); // We're done. mz_free(p); @@ -888,7 +890,7 @@ void unzip(std::string _in_zip_file, std::string _target_directory){ mz_zip_reader_end(&zip_archive); } - printf("Success.\n"); + ESP_LOGD(TAG, "Success."); } @@ -925,7 +927,7 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path) // strcpy(zw, serverprefix); // zw[strlen(serverprefix)] = '*'; // zw[strlen(serverprefix)+1] = '\0'; -// printf("zw: %s\n", zw); +// ESP_LOGD(TAG, "zw: %s", zw); httpd_uri_t file_download = { .uri = "/fileserver*", // Match all URIs of type /path/to/file .method = HTTP_GET, diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index e6f1c91f..2c781705 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -58,7 +58,7 @@ static void infinite_loop(void) int i = 0; ESP_LOGI(TAGPARTOTA, "When a new firmware is available on the server, press the reset button to download it"); while(1) { - ESP_LOGI(TAGPARTOTA, "Waiting for a new firmware ... %d", ++i); + ESP_LOGI(TAGPARTOTA, "Waiting for a new firmware... %d", ++i); vTaskDelay(2000 / portTICK_PERIOD_MS); } } @@ -219,8 +219,7 @@ static bool diagnostic(void) void CheckOTAUpdate(void) { - ESP_LOGI(TAGPARTOTA, "Start CheckOTAUpdateCheck ..."); - printf("Start CheckOTAUpdateCheck ...\n"); + ESP_LOGI(TAGPARTOTA, "Start CheckOTAUpdateCheck..."); uint8_t sha_256[HASH_LEN] = { 0 }; esp_partition_t partition; @@ -249,31 +248,29 @@ void CheckOTAUpdate(void) switch (res_stat_partition) { case ESP_OK: - printf("CheckOTAUpdate Partition: ESP_OK\n"); + ESP_LOGD(TAGPARTOTA, "CheckOTAUpdate Partition: ESP_OK"); if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) { // run diagnostic function ... bool diagnostic_is_ok = diagnostic(); if (diagnostic_is_ok) { - ESP_LOGI(TAGPARTOTA, "Diagnostics completed successfully! Continuing execution ..."); - printf("Diagnostics completed successfully! Continuing execution ...\n"); + ESP_LOGI(TAGPARTOTA, "Diagnostics completed successfully! Continuing execution..."); esp_ota_mark_app_valid_cancel_rollback(); } else { - ESP_LOGE(TAGPARTOTA, "Diagnostics failed! Start rollback to the previous version ..."); - printf("Diagnostics failed! Start rollback to the previous version ...\n"); + ESP_LOGE(TAGPARTOTA, "Diagnostics failed! Start rollback to the previous version..."); esp_ota_mark_app_invalid_rollback_and_reboot(); } } } break; case ESP_ERR_INVALID_ARG: - printf("CheckOTAUpdate Partition: ESP_ERR_INVALID_ARG\n"); + ESP_LOGD(TAGPARTOTA, "CheckOTAUpdate Partition: ESP_ERR_INVALID_ARG"); break; case ESP_ERR_NOT_SUPPORTED: - printf("CheckOTAUpdate Partition: ESP_ERR_NOT_SUPPORTED\n"); + ESP_LOGD(TAGPARTOTA, "CheckOTAUpdate Partition: ESP_ERR_NOT_SUPPORTED"); break; case ESP_ERR_NOT_FOUND: - printf("CheckOTAUpdate Partition: ESP_ERR_NOT_FOUND\n"); + ESP_LOGD(TAGPARTOTA, "CheckOTAUpdate Partition: ESP_ERR_NOT_FOUND"); break; } if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) { @@ -281,12 +278,10 @@ void CheckOTAUpdate(void) // run diagnostic function ... bool diagnostic_is_ok = diagnostic(); if (diagnostic_is_ok) { - ESP_LOGI(TAGPARTOTA, "Diagnostics completed successfully! Continuing execution ..."); - printf("Diagnostics completed successfully! Continuing execution ...\n"); + ESP_LOGI(TAGPARTOTA, "Diagnostics completed successfully! Continuing execution..."); esp_ota_mark_app_valid_cancel_rollback(); } else { - ESP_LOGE(TAGPARTOTA, "Diagnostics failed! Start rollback to the previous version ..."); - printf("Diagnostics failed! Start rollback to the previous version ...\n"); + ESP_LOGE(TAGPARTOTA, "Diagnostics failed! Start rollback to the previous version..."); esp_ota_mark_app_invalid_rollback_and_reboot(); } } @@ -311,24 +306,24 @@ esp_err_t handler_ota_update(httpd_req_t *req) if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK) { - printf("Query: "); printf(_query); printf("\n"); + ESP_LOGD(TAGPARTOTA, "Query: %s", _query); if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK) { - printf("task is found: "); printf(_valuechar); printf("\n"); + ESP_LOGD(TAGPARTOTA, "task is found: %s", _valuechar); _task = std::string(_valuechar); } if (httpd_query_key_value(_query, "file", _filename, 100) == ESP_OK) { fn.append(_filename); - printf("File: "); printf(fn.c_str()); printf("\n"); + ESP_LOGD(TAGPARTOTA, "File: %s", fn.c_str()); } if (httpd_query_key_value(_query, "delete", _filename, 100) == ESP_OK) { fn.append(_filename); _file_del = true; - printf("Delete Default File: "); printf(fn.c_str()); printf("\n"); + ESP_LOGD(TAGPARTOTA, "Delete Default File: %s", fn.c_str()); } }; @@ -394,7 +389,7 @@ esp_err_t handler_ota_update(httpd_req_t *req) std::string zw = "reboot\n"; httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); - printf("Send reboot\n"); + ESP_LOGD(TAGPARTOTA, "Send reboot"); return ESP_OK; } @@ -418,7 +413,7 @@ esp_err_t handler_ota_update(httpd_req_t *req) if (_task.compare("unziphtml") == 0) { - printf("Task unziphmtl\n"); + ESP_LOGD(TAGPARTOTA, "Task unziphtml"); std::string in, out, zw; in = "/sdcard/firmware/html.zip"; @@ -435,22 +430,22 @@ esp_err_t handler_ota_update(httpd_req_t *req) if (_file_del) { - printf("Delete !! _file_del: %s\n", fn.c_str()); + ESP_LOGD(TAGPARTOTA, "Delete !! _file_del: %s", fn.c_str()); struct stat file_stat; int _result = stat(fn.c_str(), &file_stat); - printf("Ergebnis %d\n", _result); + ESP_LOGD(TAGPARTOTA, "Ergebnis %d\n", _result); if (_result == 0) { - printf("Deleting file : %s\n", fn.c_str()); + ESP_LOGD(TAGPARTOTA, "Deleting file : %s", fn.c_str()); /* Delete file */ unlink(fn.c_str()); } else { - printf("File does not exist: %s\n", fn.c_str()); + ESP_LOGD(TAGPARTOTA, "File does not exist: %s", fn.c_str()); } /* Respond with an empty chunk to signal HTTP response completion */ std::string zw = "file deleted\n"; - printf((zw + "\n").c_str()); + ESP_LOGD(TAGPARTOTA, "%s", zw.c_str()); httpd_resp_send(req, zw.c_str(), strlen(zw.c_str())); httpd_resp_send_chunk(req, NULL, 0); return ESP_OK; diff --git a/code/components/jomjol_flowcontroll/ClassFlow.cpp b/code/components/jomjol_flowcontroll/ClassFlow.cpp index f15844d5..13dacbd4 100644 --- a/code/components/jomjol_flowcontroll/ClassFlow.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlow.cpp @@ -3,7 +3,9 @@ #include #include #include +#include "esp_log.h" +static const char *TAG = "class_flow"; void ClassFlow::SetInitialParameter(void) @@ -105,7 +107,7 @@ std::string ClassFlow::GetParameterName(std::string _input) { _param = _input; } -// printf("Parameter: %s, Pospunkt: %d\n", _param.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Parameter: %s, Pospunkt: %d", _param.c_str(), _pospunkt); return _param; } @@ -121,10 +123,10 @@ bool ClassFlow::getNextLine(FILE* pfile, string *rt) if (!fgets(zw, 1024, pfile)) { *rt = ""; - printf("END OF FILE\n"); + ESP_LOGD(TAG, "END OF FILE"); return false; } - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); *rt = zw; *rt = trim(*rt); while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph @@ -132,7 +134,7 @@ bool ClassFlow::getNextLine(FILE* pfile, string *rt) *rt = ""; if (!fgets(zw, 1024, pfile)) return false; - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); *rt = zw; *rt = trim(*rt); } diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index 67be8a75..46e341c7 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -29,7 +29,7 @@ uint8_t * CImageBasis::RGBImageLock(int _waitmaxsec) if (islocked) { #ifdef DEBUG_DETAIL_ON - printf("Image is locked: sleep for : %ds\n", _waitmaxsec); + ESP_LOGD(TAG, "Image is locked: sleep for: %ds", _waitmaxsec); #endif TickType_t xDelay; xDelay = 1000 / portTICK_PERIOD_MS; diff --git a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp index 1689f9c5..543f0069 100644 --- a/code/components/jomjol_tfliteclass/CTfLiteClass.cpp +++ b/code/components/jomjol_tfliteclass/CTfLiteClass.cpp @@ -1,11 +1,15 @@ #include "CTfLiteClass.h" #include "ClassLogFile.h" #include "Helper.h" +#include "esp_log.h" #include // #define DEBUG_DETAIL_ON + +static const char *TAG = "ctflite_class"; + float CTfLiteClass::GetOutputValue(int nr) { TfLiteTensor* output2 = this->interpreter->output(0); @@ -41,7 +45,7 @@ int CTfLiteClass::GetOutClassification(int _von, int _bis) return -1; int numeroutput = output2->dims->data[1]; - //printf("\n number output neurons: %d\n\n", numeroutput); + //ESP_LOGD(TAG, "number output neurons: %d", numeroutput); if (_bis == -1) _bis = numeroutput -1; @@ -51,7 +55,7 @@ int CTfLiteClass::GetOutClassification(int _von, int _bis) if (_bis >= numeroutput) { - printf("ANZAHL OUTPUT NEURONS passt nicht zu geforderter Classifizierung!"); + ESP_LOGD(TAG, "ANZAHL OUTPUT NEURONS passt nicht zu geforderter Classifizierung!"); return -1; } @@ -74,13 +78,13 @@ void CTfLiteClass::GetInputDimension(bool silent = false) TfLiteTensor* input2 = this->interpreter->input(0); int numdim = input2->dims->size; - if (!silent) printf("NumDimension: %d\n", numdim); + if (!silent) ESP_LOGD(TAG, "NumDimension: %d", numdim); int sizeofdim; for (int j = 0; j < numdim; ++j) { sizeofdim = input2->dims->data[j]; - if (!silent) printf("SizeOfDimension %d: %d\n", j, sizeofdim); + if (!silent) ESP_LOGD(TAG, "SizeOfDimension %d: %d", j, sizeofdim); if (j == 1) im_height = sizeofdim; if (j == 2) im_width = sizeofdim; if (j == 3) im_channel = sizeofdim; @@ -106,13 +110,13 @@ int CTfLiteClass::GetAnzOutPut(bool silent) TfLiteTensor* output2 = this->interpreter->output(0); int numdim = output2->dims->size; - if (!silent) printf("NumDimension: %d\n", numdim); + if (!silent) ESP_LOGD(TAG, "NumDimension: %d", numdim); int sizeofdim; for (int j = 0; j < numdim; ++j) { sizeofdim = output2->dims->data[j]; - if (!silent) printf("SizeOfDimension %d: %d\n", j, sizeofdim); + if (!silent) ESP_LOGD(TAG, "SizeOfDimension %d: %d", j, sizeofdim); } @@ -123,7 +127,7 @@ int CTfLiteClass::GetAnzOutPut(bool silent) for (int i = 0; i < numeroutput; ++i) { fo = output2->data.f[i]; - if (!silent) printf("Result %d: %f\n", i, fo); + if (!silent) ESP_LOGD(TAG, "Result %d: %f", i, fo); } return numeroutput; } @@ -143,7 +147,7 @@ bool CTfLiteClass::LoadInputImageBasis(CImageBasis *rs) unsigned int w = rs->width; unsigned int h = rs->height; unsigned char red, green, blue; -// printf("Image: %s size: %d x %d\n", _fn.c_str(), w, h); +// ESP_LOGD(TAG, "Image: %s size: %d x %d\n", _fn.c_str(), w, h); input_i = 0; float* input_data_ptr = (interpreter->input(0))->data.f; @@ -174,9 +178,9 @@ void CTfLiteClass::MakeAllocate() { static tflite::AllOpsResolver resolver; -// printf(LogFile.getESPHeapInfo().c_str()); printf("\n"); +// ESP_LOGD(TAG, "%s", LogFile.getESPHeapInfo().c_str()); this->interpreter = new tflite::MicroInterpreter(this->model, resolver, this->tensor_arena, this->kTensorArenaSize, this->error_reporter); -// printf(LogFile.getESPHeapInfo().c_str()); printf("\n"); +// ESP_LOGD(TAG, "%s", LogFile.getESPHeapInfo().c_str()); TfLiteStatus allocate_status = this->interpreter->AllocateTensors(); if (allocate_status != kTfLiteOk) { @@ -186,14 +190,14 @@ void CTfLiteClass::MakeAllocate() this->GetInputDimension(); return; } -// printf("Allocate Done.\n"); +// ESP_LOGD(TAG, "Allocate Done"); } void CTfLiteClass::GetInputTensorSize(){ #ifdef DEBUG_DETAIL_ON float *zw = this->input; int test = sizeof(zw); - printf("Input Tensor Dimension: %d\n", test); + ESP_LOGD(TAG, "Input Tensor Dimension: %d", test); #endif } @@ -213,7 +217,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn) if (size == -1) { - printf("\nFile doesn't exist.\n"); + ESP_LOGD(TAG, "File doesn't exist"); return NULL; } @@ -222,7 +226,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn) while (!result && (anz < 6)) // maximal 5x versuchen (= 5s) { #ifdef DEBUG_DETAIL_ON - printf("Speicher ist voll - Versuche es erneut: %d.\n", anz); + ESP_LOGD(TAG, "Speicher ist voll - Versuche es erneut: %d", anz); #endif result = (unsigned char*) malloc(size); anz++; @@ -234,7 +238,7 @@ unsigned char* CTfLiteClass::ReadFileToCharArray(std::string _fn) fread(result, 1, size, f); fclose(f); }else { - printf("\nNo free memory available.\n"); + ESP_LOGD(TAG, "No free memory available"); } diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 736e4473..3ffa9fb6 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -752,7 +752,7 @@ void task_autodoFlow(void *pvParameter) if (auto_intervall > fr_delta_ms) { const TickType_t xDelay = (auto_intervall - fr_delta_ms) / portTICK_PERIOD_MS; - ESP_LOGD(TAGTFLITE, "Autoflow: sleep for : %ldms", (long) xDelay); + ESP_LOGD(TAGTFLITE, "Autoflow: sleep for: %ldms", (long) xDelay); vTaskDelay( xDelay ); } } diff --git a/code/main/main.cpp b/code/main/main.cpp index 6744d05c..80993b27 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -154,7 +154,7 @@ extern "C" void app_main(void) esp_err_t cam = Camera.InitCam(); Camera.LightOnOff(false); xDelay = 2000 / portTICK_PERIOD_MS; - ESP_LOGD(TAGMAIN, "After camera initialization: sleep for : %ldms", (long) xDelay); + ESP_LOGD(TAGMAIN, "After camera initialization: sleep for: %ldms", (long) xDelay); vTaskDelay( xDelay ); @@ -194,7 +194,7 @@ extern "C" void app_main(void) xDelay = 2000 / portTICK_PERIOD_MS; - ESP_LOGD(TAGMAIN, "main: sleep for : %ldms", (long) xDelay); + ESP_LOGD(TAGMAIN, "main: sleep for: %ldms", (long) xDelay); vTaskDelay( xDelay ); setup_time(); setBootTime(); @@ -243,7 +243,7 @@ extern "C" void app_main(void) xDelay = 2000 / portTICK_PERIOD_MS; - ESP_LOGD(TAGMAIN, "main: sleep for : %ldms", (long) xDelay*10); + ESP_LOGD(TAGMAIN, "main: sleep for: %ldms", (long) xDelay*10); vTaskDelay( xDelay ); ESP_LOGD(TAGMAIN, "starting server"); From 0bf81827288925f287f7157323c4791907338f1f Mon Sep 17 00:00:00 2001 From: George Ruinelli Date: Fri, 21 Oct 2022 22:55:36 +0200 Subject: [PATCH 20/44] . --- .../ClassFlowAlignment.cpp | 8 +- .../ClassFlowCNNGeneral.cpp | 51 +++++------ .../jomjol_flowcontroll/ClassFlowControll.cpp | 22 ++--- .../jomjol_flowcontroll/ClassFlowImage.cpp | 4 +- .../jomjol_flowcontroll/ClassFlowInfluxDB.cpp | 9 +- .../jomjol_flowcontroll/ClassFlowMQTT.cpp | 12 +-- .../ClassFlowMakeImage.cpp | 5 +- .../ClassFlowPostProcessing.cpp | 87 ++++++++++--------- code/components/jomjol_helper/Helper.cpp | 27 +++--- .../jomjol_image_proc/CAlignAndCutImage.cpp | 11 ++- .../jomjol_image_proc/CFindTemplate.cpp | 22 +++-- .../jomjol_image_proc/CImageBasis.cpp | 30 +++---- .../jomjol_image_proc/CRotateImage.cpp | 4 +- .../jomjol_logfile/ClassLogFile.cpp | 8 +- code/components/jomjol_wlan/read_wlanini.cpp | 4 +- 15 files changed, 164 insertions(+), 140 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp index 532cd63f..e4ecf610 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp @@ -3,11 +3,13 @@ #include "ClassFlow.h" #include "CRotateImage.h" +#include "esp_log.h" #include "ClassLogFile.h" +static const char *TAG = "class_flow_alignment"; bool AlignmentExtendedDebugging = true; @@ -48,7 +50,7 @@ ClassFlowAlignment::ClassFlowAlignment(std::vector* lfc) if (!ImageBasis) // die Funktion Bilder aufnehmen existiert nicht --> muss erst erzeugt werden NUR ZU TESTZWECKEN { - if (AlignmentExtendedDebugging) printf("CImageBasis had to be created\n"); + if (AlignmentExtendedDebugging) ESP_LOGD(TAG, "CImageBasis had to be created"); ImageBasis = new CImageBasis(namerawimage); } } @@ -174,7 +176,7 @@ bool ClassFlowAlignment::doFlow(string time) } if (initialmirror){ - printf("do mirror\n"); + ESP_LOGD(TAG, "do mirror"); rt.Mirror(); if (SaveAllFiles) AlignAndCutImage->SaveToFile(FormatFileName("/sdcard/img_tmp/mirror.jpg")); } @@ -279,7 +281,7 @@ bool ClassFlowAlignment::LoadReferenceAlignmentValues(void) // LogFile.WriteToDedicatedFile("/sdcard/alignment.txt", "LoadReferenceAlignmentValues01"); fgets(zw, 1024, pFile); - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); // zwvalue = "LoadReferenceAlignmentValues Time: " + std::string(zw); diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 9eba7190..ba7ca83c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -7,6 +7,7 @@ #include "CTfLiteClass.h" #include "ClassLogFile.h" +#include "esp_log.h" static const char* TAG = "flow_analog"; @@ -311,7 +312,7 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph) { disabled = true; while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph)); - printf("[Analog/Digit] is disabled !!!\n"); + ESP_LOGD(TAG, "[Analog/Digit] is disabled!"); return true; } @@ -429,7 +430,7 @@ general* ClassFlowCNNGeneral::GetGENERAL(string _name, bool _create = true) _ret->ROI.push_back(neuroi); - printf("GetGENERAL - GENERAL %s - roi %s - CCW: %d\n", _analog.c_str(), _roi.c_str(), neuroi->CCW); + ESP_LOGD(TAG, "GetGENERAL - GENERAL %s - roi %s - CCW: %d", _analog.c_str(), _roi.c_str(), neuroi->CCW); return _ret; } @@ -488,7 +489,7 @@ bool ClassFlowCNNGeneral::doAlignAndCut(string time) for (int _ana = 0; _ana < GENERAL.size(); ++_ana) for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i) { - printf("General %d - Align&Cut\n", i); + ESP_LOGD(TAG, "General %d - Align&Cut", i); caic->CutAndSave(GENERAL[_ana]->ROI[i]->posx, GENERAL[_ana]->ROI[i]->posy, GENERAL[_ana]->ROI[i]->deltax, GENERAL[_ana]->ROI[i]->deltay, GENERAL[_ana]->ROI[i]->image_org); if (SaveAllFiles) @@ -545,9 +546,9 @@ bool ClassFlowCNNGeneral::getNetworkParameter() CTfLiteClass *tflite = new CTfLiteClass; string zwcnn = "/sdcard" + cnnmodelfile; zwcnn = FormatFileName(zwcnn); - printf(zwcnn.c_str());printf("\n"); + ESP_LOGD(TAG, "%s", zwcnn.c_str()); if (!tflite->LoadModel(zwcnn)) { - printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str()); + ESP_LOGD(TAG, "Can't read model file /sdcard%s", cnnmodelfile.c_str()); LogFile.WriteToFile("Cannot load model"); delete tflite; return false; @@ -566,37 +567,37 @@ bool ClassFlowCNNGeneral::getNetworkParameter() { case 2: CNNType = Analogue; - printf("TFlite-Type set to Analogue\n"); + ESP_LOGD(TAG, "TFlite-Type set to Analogue"); break; case 10: CNNType = DoubleHyprid10; - printf("TFlite-Type set to DoubleHyprid10\n"); + ESP_LOGD(TAG, "TFlite-Type set to DoubleHyprid10"); break; case 11: CNNType = Digital; - printf("TFlite-Type set to Digital\n"); + ESP_LOGD(TAG, "TFlite-Type set to Digital"); break; /* case 20: CNNType = DigitalHyprid10; - printf("TFlite-Type set to DigitalHyprid10\n"); + ESP_LOGD(TAG, "TFlite-Type set to DigitalHyprid10"); break; */ // case 22: // CNNType = DigitalHyprid; -// printf("TFlite-Type set to DigitalHyprid\n"); +// ESP_LOGD(TAG, "TFlite-Type set to DigitalHyprid"); // break; case 100: if (modelxsize==32 && modelysize == 32) { CNNType = Analogue100; - printf("TFlite-Type set to Analogue100\n"); + ESP_LOGD(TAG, "TFlite-Type set to Analogue100"); } else { CNNType = Digital100; - printf("TFlite-Type set to Digital\n"); + ESP_LOGD(TAG, "TFlite-Type set to Digital"); } break; default: LogFile.WriteToFile("ERROR ERROR ERROR - tflite passt nicht zur Firmware - ERROR ERROR ERROR (outout_dimension=" + std::to_string(_anzoutputdimensions) + ")"); - printf("ERROR ERROR ERROR - tflite passt nicht zur Firmware - ERROR ERROR ERROR\n"); + ESP_LOGD(TAG, "ERROR ERROR ERROR - tflite passt nicht zur Firmware - ERROR ERROR ERROR"); } } @@ -614,9 +615,9 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) CTfLiteClass *tflite = new CTfLiteClass; string zwcnn = "/sdcard" + cnnmodelfile; zwcnn = FormatFileName(zwcnn); - printf(zwcnn.c_str());printf("\n"); + ESP_LOGD(TAG, "%s", zwcnn.c_str()); if (!tflite->LoadModel(zwcnn)) { - printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str()); + ESP_LOGD(TAG, "Can't read model file /sdcard%s", cnnmodelfile.c_str()); LogFile.WriteToFile("Cannot load model"); delete tflite; @@ -628,7 +629,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i) { - printf("General %d - TfLite\n", i); + ESP_LOGD(TAG, "General %d - TfLite", i); switch (CNNType) { case Analogue: @@ -649,7 +650,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) else GENERAL[_ana]->ROI[i]->result_float = result * 10; - printf("Result General(Analog)%i - CCW: %d - %f\n", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float); + ESP_LOGD(TAG, "Result General(Analog)%i - CCW: %d - %f", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float); if (isLogImage) LogImage(logPath, GENERAL[_ana]->ROI[i]->name, &GENERAL[_ana]->ROI[i]->result_float, NULL, time, GENERAL[_ana]->ROI[i]->image_org); } break; @@ -658,7 +659,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) { GENERAL[_ana]->ROI[i]->result_klasse = 0; GENERAL[_ana]->ROI[i]->result_klasse = tflite->GetClassFromImageBasis(GENERAL[_ana]->ROI[i]->image); - printf("Result General(Digit)%i: %d\n", i, GENERAL[_ana]->ROI[i]->result_klasse); + ESP_LOGD(TAG, "Result General(Digit)%i: %d", i, GENERAL[_ana]->ROI[i]->result_klasse); if (isLogImage) { @@ -695,7 +696,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) else GENERAL[_ana]->ROI[i]->result_float = fmod((double) _num + (((double)_nachkomma)-5)/10 + (double) 10, 10); - printf("Result General(DigitalHyprid)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float); + ESP_LOGD(TAG, "Result General(DigitalHyprid)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float); _zwres = "Result General(DigitalHyprid)" + to_string(i) + ": " + to_string(GENERAL[_ana]->ROI[i]->result_float); if (debugdetailgeneral) LogFile.WriteToFile(_zwres); @@ -732,7 +733,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) GENERAL[_ana]->ROI[i]->result_float = fmod((double) _num + (((double)_nachkomma)-5)/10 + (double) 10, 10); - printf("Result General(DigitalHyprid)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float); + ESP_LOGD(TAG, "Result General(DigitalHyprid)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float); _zwres = "Result General(DigitalHyprid)" + to_string(i) + ": " + to_string(GENERAL[_ana]->ROI[i]->result_float); if (debugdetailgeneral) LogFile.WriteToFile(_zwres); @@ -792,7 +793,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) string zw = "_num (p, m): " + to_string(_num) + " " + to_string(_numplus) + " " + to_string(_numminus); zw = zw + " _val (p, m): " + to_string(_val) + " " + to_string(_valplus) + " " + to_string(_valminus); zw = zw + " result: " + to_string(result) + " _fit: " + to_string(_fit); - printf("details cnn: %s\n", zw.c_str()); + ESP_LOGD(TAG, "details cnn: %s", zw.c_str()); LogFile.WriteToFile(zw); @@ -804,7 +805,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) result = -1; _result_save_file+= 100; // Für den Fall, dass fit nicht ausreichend, soll trotzdem das Ergebnis mit "-10x.y" abgespeichert werden. string zw = "Value Rejected due to Threshold (Fit: " + to_string(_fit) + "Threshold: " + to_string(CNNGoodThreshold); - printf("Value Rejected due to Threshold (Fit: %f, Threshold: %f\n", _fit, CNNGoodThreshold); + ESP_LOGD(TAG, "Value Rejected due to Threshold (Fit: %f, Threshold: %f", _fit, CNNGoodThreshold); LogFile.WriteToFile(zw); } else @@ -814,7 +815,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) GENERAL[_ana]->ROI[i]->result_float = result; - printf("Result General(Analog)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float); + ESP_LOGD(TAG, "Result General(Analog)%i: %f", i, GENERAL[_ana]->ROI[i]->result_float); if (isLogImage) { @@ -852,7 +853,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) GENERAL[_ana]->ROI[i]->isReject = false; - printf("Result General(Analog)%i - CCW: %d - %f\n", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float); + ESP_LOGD(TAG, "Result General(Analog)%i - CCW: %d - %f", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float); if (isLogImage) { @@ -898,7 +899,7 @@ std::vector ClassFlowCNNGeneral::GetHTMLInfo() for (int _ana = 0; _ana < GENERAL.size(); ++_ana) for (int i = 0; i < GENERAL[_ana]->ROI.size(); ++i) { - printf("Image: %d\n", (int) GENERAL[_ana]->ROI[i]->image); + ESP_LOGD(TAG, "Image: %d", (int) GENERAL[_ana]->ROI[i]->image); if (GENERAL[_ana]->ROI[i]->image) { if (GENERAL[_ana]->name == "default") diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 615795c9..22982b7a 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -33,7 +33,7 @@ static const char* TAG = "flow_controll"; std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){ std::string _classname = ""; std::string result = ""; -// printf("_stepname: %s\n", _stepname.c_str()); +// ESP_LOGD(TAG, "_stepname: %s", _stepname.c_str()); if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){ _classname = "ClassFlowMakeImage"; } @@ -89,7 +89,7 @@ std::vector ClassFlowControll::GetAllDigital() { if (flowdigit) { - printf("ClassFlowControll::GetAllDigital - flowdigit != NULL\n"); + ESP_LOGD(TAG, "ClassFlowControll::GetAllDigital - flowdigit != NULL"); return flowdigit->GetHTMLInfo(); } @@ -230,7 +230,7 @@ void ClassFlowControll::InitFlow(std::string config) if (pFile != NULL) { fgets(zw, 1024, pFile); - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); line = std::string(zw); } @@ -239,7 +239,7 @@ void ClassFlowControll::InitFlow(std::string config) cfc = CreateClassFlow(line); if (cfc) { - printf("Start ReadParameter (%s)\n", line.c_str()); + ESP_LOGD(TAG, "Start ReadParameter (%s)", line.c_str()); cfc->ReadParameter(pFile, line); } else @@ -247,7 +247,7 @@ void ClassFlowControll::InitFlow(std::string config) line = ""; if (fgets(zw, 1024, pFile) && !feof(pFile)) { - printf("Read: %s", zw); + ESP_LOGD(TAG, "Read: %s", zw); line = std::string(zw); } } @@ -362,7 +362,7 @@ string ClassFlowControll::getReadoutAll(int _type) if (i < (*numbers).size()-1) out = out + "\r\n"; } - // printf("OUT: %s", out.c_str()); + // ESP_LOGD(TAG, "OUT: %s", out.c_str()); } return out; @@ -408,7 +408,7 @@ std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string char* p; _newvalue = trim(_newvalue); -// printf("Input UpdatePreValue: %s\n", _newvalue.c_str()); +// ESP_LOGD(TAG, "Input UpdatePreValue: %s", _newvalue.c_str()); if (_newvalue.compare("0.0") == 0) { @@ -493,7 +493,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) { // reboot notwendig damit die neue wlan.ini auch benutzt wird !!! fclose(pfile); - printf("do reboot\n"); + ESP_LOGD(TAG, "do reboot"); LogFile.SwitchOnOff(true); LogFile.WriteToFile("Reboot to activate new HOSTNAME."); esp_restart(); @@ -558,7 +558,7 @@ esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req) esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) { - printf("ClassFlowControll::GetJPGStream %s\n", _fn.c_str()); + ESP_LOGD(TAG, "ClassFlowControll::GetJPGStream %s", _fn.c_str()); CImageBasis *_send = NULL; esp_err_t result = ESP_FAIL; @@ -566,7 +566,7 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) if (flowalignment == NULL) { - printf("Can't continue, flowalignment is NULL\n"); + ESP_LOGD(TAG, "Can't continue, flowalignment is NULL"); return ESP_FAIL; } @@ -589,7 +589,7 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req) { std::vector htmlinfo; htmlinfo = GetAllDigital(); - printf("After getClassFlowControll::GetAllDigital\n"); + ESP_LOGD(TAG, "After getClassFlowControll::GetAllDigital"); for (int i = 0; i < htmlinfo.size(); ++i) { diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index a5c9ca54..c42c7cb0 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -14,6 +14,8 @@ extern "C" { #include "time_sntp.h" #include "ClassLogFile.h" #include "CImageBasis.h" +#include "esp_log.h" + ClassFlowImage::ClassFlowImage(const char* logTag) { @@ -79,7 +81,7 @@ void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, i nm = FormatFileName(nm); string output = "/sdcard/img_tmp/" + name + ".jpg"; output = FormatFileName(output); - printf("save to file: %s\n", nm.c_str()); + ESP_LOGD(logTag, "save to file: %s", nm.c_str()); _img->SaveToFile(nm); // CopyFile(output, nm); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp index 55b1f9ff..bbf78628 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp @@ -6,9 +6,12 @@ #include "time_sntp.h" #include "interface_influxdb.h" #include "ClassFlowPostProcessing.h" +#include "esp_log.h" #include +static const char* TAG = "class_flow_influxDb"; + void ClassFlowInfluxDB::SetInitialParameter(void) { uri = ""; @@ -76,7 +79,7 @@ bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph) while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) { - printf("while loop reading line: %s\n", aktparamgraph.c_str()); + ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str()); zerlegt = this->ZerlegeZeile(aktparamgraph); if ((toUpper(zerlegt[0]) == "USER") && (zerlegt.size() > 1)) { @@ -102,11 +105,11 @@ bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph) if ((uri.length() > 0) && (database.length() > 0) && (measurement.length() > 0)) { - printf("Init InfluxDB with uri: %s, measurement: %s, user: %s, password: %s\n", uri.c_str(), measurement.c_str(), user.c_str(), password.c_str()); + ESP_LOGD(TAG, "Init InfluxDB with uri: %s, measurement: %s, user: %s, password: %s", uri.c_str(), measurement.c_str(), user.c_str(), password.c_str()); InfluxDBInit(uri, database, measurement, user, password); InfluxDBenable = true; } else { - printf("InfluxDB init skipped as we are missing some parameters"); + ESP_LOGD(TAG, "InfluxDB init skipped as we are missing some parameters"); } return true; diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 8bd4cce4..2cfcaaca 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -12,6 +12,8 @@ #define __HIDE_PASSWORD +static const char *TAG = "class_flow_MQTT"; + void ClassFlowMQTT::SetInitialParameter(void) { uri = ""; @@ -120,19 +122,19 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) } #ifdef __HIDE_PASSWORD - printf("Init Read with uri: %s, clientname: %s, user: %s, password: XXXXXX, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str()); + ESP_LOGD(TAG, "Init Read with uri: %s, clientname: %s, user: %s, password: XXXXXX, maintopic: %s", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str()); #else - printf("Init Read with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str()); + ESP_LOGD(TAG, "Init Read with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str()); #endif if (!MQTTisConnected() && (uri.length() > 0) && (maintopic.length() > 0)) { - printf("InitMQTTInit\n"); + ESP_LOGD(TAG, "InitMQTTInit"); mainerrortopic = maintopic + "/connection"; #ifdef __HIDE_PASSWORD - printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: XXXXXXXX, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str()); + ESP_LOGD(TAG, "Init MQTT with uri: %s, clientname: %s, user: %s, password: XXXXXXXX, maintopic: %s", uri.c_str(), clientname.c_str(), user.c_str(), mainerrortopic.c_str()); #else - printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str()); + ESP_LOGD(TAG, "Init MQTT with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str()); #endif if (!MQTTInit(uri, clientname, user, password, mainerrortopic, keepAlive)) { // Failed diff --git a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp index 9e68a5f8..08fdfade 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMakeImage.cpp @@ -6,6 +6,7 @@ #include "ClassControllCamera.h" #include "esp_wifi.h" +#include "esp_log.h" #include @@ -30,7 +31,7 @@ void ClassFlowMakeImage::takePictureWithFlash(int flashdauer) rawImage->width = image_width; rawImage->height = image_height; ///////////////////////////////////////////////////////////////////////////////////// - printf("Flashdauer: %d\n", flashdauer); + ESP_LOGD(TAG, "Flashdauer: %d", flashdauer); Camera.CaptureToBasisImage(rawImage, flashdauer); time(&TimeImageTaken); localtime(&TimeImageTaken); @@ -145,7 +146,7 @@ bool ClassFlowMakeImage::ReadParameter(FILE* pfile, string& aktparamgraph) waitbeforepicture_store = waitbeforepicture; if (FixedExposure && (waitbeforepicture > 0)) { -// printf("Fixed Exposure enabled!\n"); +// ESP_LOGD(TAG, "Fixed Exposure enabled!"); int flashdauer = (int) (waitbeforepicture * 1000); Camera.EnableAutoExposure(flashdauer); waitbeforepicture = 0.2; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 646582e5..100f8895 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -9,6 +9,11 @@ #include #include "time_sntp.h" + +#include "esp_log.h" + +static const char* TAG = "class_flow_postproc"; + //#define SERIAL_DEBUG // testing debug on serial enabled @@ -72,10 +77,10 @@ string ClassFlowPostProcessing::GetPreValue(std::string _number) void ClassFlowPostProcessing::SetPreValue(double zw, string _numbers, bool _extern) { - printf("SetPrevalue: %f, %s\n", zw, _numbers.c_str()); + ESP_LOGD(TAG, "SetPrevalue: %f, %s", zw, _numbers.c_str()); for (int j = 0; j < NUMBERS.size(); ++j) { -// printf("Number %d, %s\n", j, NUMBERS[j]->name.c_str()); +// ESP_LOGD(TAG, "Number %d, %s", j, NUMBERS[j]->name.c_str()); if (NUMBERS[j]->name == _numbers) { NUMBERS[j]->PreValue = zw; @@ -86,7 +91,7 @@ void ClassFlowPostProcessing::SetPreValue(double zw, string _numbers, bool _exte time(&(NUMBERS[j]->lastvalue)); localtime(&(NUMBERS[j]->lastvalue)); } -// printf("Found %d! - set to %f\n", j, NUMBERS[j]->PreValue); +// ESP_LOGD(TAG, "Found %d! - set to %f", j, NUMBERS[j]->PreValue); } } UpdatePreValueINI = true; @@ -110,7 +115,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void) return false; fgets(zw, 1024, pFile); - printf("Read line Prevalue.ini: %s", zw); + ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); zwtime = trim(std::string(zw)); if (zwtime.length() == 0) return false; @@ -161,7 +166,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void) _done = true; else { - printf("Read line Prevalue.ini: %s", zw); + ESP_LOGD(TAG, "Read line Prevalue.ini: %s", zw); zerlegt = HelperZerlegeZeile(trim(std::string(zw)), "\t"); if (zerlegt.size() > 1) { @@ -177,7 +182,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void) { fgets(zw, 1024, pFile); fclose(pFile); - printf("%s", zw); + ESP_LOGD(TAG, "%s", zw); zwvalue = trim(std::string(zw)); NUMBERS[0]->PreValue = stod(zwvalue.c_str()); @@ -194,7 +199,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void) whenStart.tm_sec = ss; whenStart.tm_isdst = -1; - printf("TIME: %d, %d, %d, %d, %d, %d\n", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec); + ESP_LOGD(TAG, "TIME: %d, %d, %d, %d, %d, %d", whenStart.tm_year, whenStart.tm_mon, whenStart.tm_wday, whenStart.tm_hour, whenStart.tm_min, whenStart.tm_sec); NUMBERS[0]->lastvalue = mktime(&whenStart); @@ -236,10 +241,10 @@ void ClassFlowPostProcessing::SavePreValue() struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue); strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); NUMBERS[j]->timeStamp = std::string(buffer); -// printf("SaverPreValue %d, Value: %f, Nachkomma %d\n", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); +// ESP_LOGD(TAG, "SaverPreValue %d, Value: %f, Nachkomma %d", j, NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma) + "\n"; - printf("Write PreValue Zeile: %s\n", _zw.c_str()); + ESP_LOGD(TAG, "Write PreValue Zeile: %s", _zw.c_str()); if (pFile) { fputs(_zw.c_str(), pFile); } @@ -278,7 +283,7 @@ void ClassFlowPostProcessing::handleDecimalExtendedResolution(string _decsep, st { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); if (_pospunkt > -1) _digit = _decsep.substr(0, _pospunkt); else @@ -308,7 +313,7 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); if (_pospunkt > -1) _digit = _decsep.substr(0, _pospunkt); else @@ -324,7 +329,7 @@ void ClassFlowPostProcessing::handleDecimalSeparator(string _decsep, string _val } /* catch(const std::exception& e) { - printf("ERROR - Decimalshift is not a number: %s\n", _value.c_str()); + ESP_LOGD(TAG, "ERROR - Decimalshift is not a number: %s", _value.c_str()); } */ if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt) @@ -347,7 +352,7 @@ void ClassFlowPostProcessing::handleAnalogDigitalTransitionStart(string _decsep, { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); if (_pospunkt > -1) _digit = _decsep.substr(0, _pospunkt); else @@ -372,7 +377,7 @@ void ClassFlowPostProcessing::handleMaxRateType(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); if (_pospunkt > -1) _digit = _decsep.substr(0, _pospunkt); else @@ -404,7 +409,7 @@ void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) { string _digit, _decpos; int _pospunkt = _decsep.find_first_of("."); -// printf("Name: %s, Pospunkt: %d\n", _decsep.c_str(), _pospunkt); +// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt); if (_pospunkt > -1) _digit = _decsep.substr(0, _pospunkt); else @@ -418,7 +423,7 @@ void ClassFlowPostProcessing::handleMaxRateValue(string _decsep, string _value) } /* catch(const std::exception& e) { - printf("ERROR - MaxRateValue is not a number: %s\n", _value.c_str()); + ESP_LOGD(TAG, "ERROR - MaxRateValue is not a number: %s", _value.c_str()); } */ if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt) @@ -541,7 +546,7 @@ void ClassFlowPostProcessing::InitNUMBERS() flowAnalog->UpdateNameNumbers(&name_numbers); } - printf("Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d\n", name_numbers.size(), anzDIGIT, anzANALOG); + ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG); for (int _num = 0; _num < name_numbers.size(); ++_num) { @@ -597,7 +602,7 @@ void ClassFlowPostProcessing::InitNUMBERS() } for (int i = 0; i < NUMBERS.size(); ++i) { - printf("Number %s, Anz DIG: %d, Anz ANA %d\n", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog); + ESP_LOGD(TAG, "Number %s, Anz DIG: %d, Anz ANA %d", NUMBERS[i]->name.c_str(), NUMBERS[i]->AnzahlDigital, NUMBERS[i]->AnzahlAnalog); } } @@ -666,7 +671,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) strftime(strftime_buf, sizeof(strftime_buf), "%Y-%m-%dT%H:%M:%S", timeinfo); zwtime = std::string(strftime_buf); - printf("Anzahl NUMBERS: %d\n", NUMBERS.size()); + ESP_LOGD(TAG, "Anzahl NUMBERS: %d", NUMBERS.size()); for (int j = 0; j < NUMBERS.size(); ++j) { @@ -691,7 +696,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) } } #ifdef SERIAL_DEBUG - printf("After analog->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After analog->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue; @@ -704,12 +709,12 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt } #ifdef SERIAL_DEBUG - printf("After digital->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After digital->getReadout: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift); #ifdef SERIAL_DEBUG - printf("After ShiftDecimal: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After ShiftDecimal: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif if (IgnoreLeadingNaN) @@ -717,7 +722,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) NUMBERS[j]->ReturnRawValue.erase(0, 1); #ifdef SERIAL_DEBUG - printf("After IgnoreLeadingNaN: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After IgnoreLeadingNaN: ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue; @@ -734,17 +739,17 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) } } #ifdef SERIAL_DEBUG - printf("After findDelimiterPos: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After findDelimiterPos: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif // Lösche führende Nullen (außer es ist nur noch einen 0) while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0')) NUMBERS[j]->ReturnValue.erase(0, 1); #ifdef SERIAL_DEBUG - printf("After removeLeadingZeros: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str()); + ESP_LOGD(TAG, "After removeLeadingZeros: ReturnValue %s", NUMBERS[j]->ReturnRawValue.c_str()); #endif NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue); #ifdef SERIAL_DEBUG - printf("After setting the Value: Value %f and as double is %f\n", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue)); + ESP_LOGD(TAG, "After setting the Value: Value %f and as double is %f", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue)); #endif if (NUMBERS[j]->checkDigitIncreaseConsistency) @@ -752,20 +757,20 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if (flowDigit) { if (flowDigit->getCNNType() != Digital) - printf("checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)\n"); + ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)"); else NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue); } else { #ifdef SERIAL_DEBUG - printf("checkDigitIncreaseConsistency = true - no digital numbers defined!\n"); + ESP_LOGD(TAG, "checkDigitIncreaseConsistency = true - no digital numbers defined!"); #endif } } #ifdef SERIAL_DEBUG - printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value); + ESP_LOGD(TAG, "After checkDigitIncreaseConsistency: Value %f", NUMBERS[j]->Value); #endif @@ -774,7 +779,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) if ((NUMBERS[j]->Value < NUMBERS[j]->PreValue)) { #ifdef SERIAL_DEBUG - printf("Neg: value=%f, preValue=%f, preToll%f\n", NUMBERS[j]->Value, NUMBERS[j]->PreValue, + ESP_LOGD(TAG, "Neg: value=%f, preValue=%f, preToll%f", NUMBERS[j]->Value, NUMBERS[j]->PreValue, NUMBERS[j]->PreValue-(2/pow(10, NUMBERS[j]->Nachkomma)) ) ; #endif @@ -793,7 +798,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) } } #ifdef SERIAL_DEBUG - printf("After AllowNegativeRates: Value %f\n", NUMBERS[j]->Value); + ESP_LOGD(TAG, "After AllowNegativeRates: Value %f", NUMBERS[j]->Value); #endif double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden difference /= 60; @@ -819,7 +824,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) } } #ifdef SERIAL_DEBUG - printf("After MaxRateCheck: Value %f\n", NUMBERS[j]->Value); + ESP_LOGD(TAG, "After MaxRateCheck: Value %f", NUMBERS[j]->Value); #endif NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma); NUMBERS[j]->lastvalue = imagetime; @@ -834,7 +839,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()); + ESP_LOGD(TAG, "%s", zw.c_str()); LogFile.WriteToFile(_zw); WriteDataLog(j); } @@ -853,7 +858,7 @@ void ClassFlowPostProcessing::WriteDataLog(int _analog) digital = flowDigit->getReadoutRawString(_analog); // LogFile.WriteToFile(analog); LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ReturnPreValue, 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()); + ESP_LOGD(TAG, "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()); } @@ -863,7 +868,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() { if (NUMBERS[j]->digit_roi && !NUMBERS[j]->analog_roi) // es gibt nur digitale ziffern { -// printf("Nurdigital\n"); +// ESP_LOGD(TAG, "Nurdigital"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; if (NUMBERS[j]->isExtendedResolution && flowDigit->isExtendedResolution()) // extended resolution ist an und soll auch bei dieser Ziffer verwendet werden @@ -874,7 +879,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() if (!NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // es gibt nur analoge ziffern { -// printf("Nur analog\n"); +// ESP_LOGD(TAG, "Nur analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; if (NUMBERS[j]->isExtendedResolution && flowAnalog->isExtendedResolution()) // extended resolution ist an und soll auch bei dieser Ziffer verwendet werden NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShift-1; @@ -884,7 +889,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi) // digital + analog { -// printf("Nur digital + analog\n"); +// ESP_LOGD(TAG, "Nur digital + analog"); NUMBERS[j]->DecimalShift = NUMBERS[j]->DecimalShiftInitial; NUMBERS[j]->Nachkomma = NUMBERS[j]->analog_roi->ROI.size() - NUMBERS[j]->DecimalShift; @@ -894,7 +899,7 @@ void ClassFlowPostProcessing::UpdateNachkommaDecimalShift() } - printf("UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i\n", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift); + ESP_LOGD(TAG, "UpdateNachkommaDecShift NUMBER%i: Nachkomma %i, DecShift %i", j, NUMBERS[j]->Nachkomma,NUMBERS[j]->DecimalShift); } } @@ -916,7 +921,7 @@ string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, i string ClassFlowPostProcessing::RundeOutput(double _in, int _anzNachkomma){ std::stringstream stream; int _zw = _in; -// printf("AnzNachkomma: %d\n", _anzNachkomma); +// ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma); if (_anzNachkomma < 0) { _anzNachkomma = 0; @@ -981,7 +986,7 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams pot++; } #ifdef SERIAL_DEBUG - printf("checkDigitConsistency: pot=%d, decimalshift=%d\n", pot, _decilamshift); + ESP_LOGD(TAG, "checkDigitConsistency: pot=%d, decimalshift=%d", pot, _decilamshift); #endif pot_max = ((int) log10(input)) + 1; while (pot <= pot_max) @@ -1013,7 +1018,7 @@ float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilams } } #ifdef SERIAL_DEBUG - printf("checkDigitConsistency: input=%f", input); + ESP_LOGD(TAG, "checkDigitConsistency: input=%f", input); #endif pot++; } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index ab18fa11..c0b4c508 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -22,6 +22,8 @@ extern "C" { #include "ClassLogFile.h" //#include "ClassLogFile.h" +static const char* TAG = "helper"; + //#define ISWINDOWS_TRUE #define PATH_MAX_STRING_SIZE 256 @@ -90,13 +92,13 @@ FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec) { FILE *pfile; - printf("open file %s in mode %s\n", nm, _mode); + ESP_LOGD(TAG, "open file %s in mode %s", nm, _mode); if ((pfile = fopen(nm, _mode)) != NULL) { - printf("File %s successfully opened\n", nm); + ESP_LOGD(TAG, "File %s successfully opened", nm); } else { - printf("Error: file %s does not exist!\n", nm); + ESP_LOGD(TAG, "Error: file %s does not exist!", nm); return NULL; } @@ -106,8 +108,7 @@ FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec) TickType_t xDelay; xDelay = _waitsec * 1000 / portTICK_PERIOD_MS; std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec) + " seconds"; - printf(zw.c_str()); - printf("\n"); + ESP_LOGD(TAG, "%s", zw.c_str()); LogFile.WriteToFile(zw); vTaskDelay( xDelay ); pfile = fopen(nm, _mode); @@ -159,7 +160,7 @@ 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()); + ESP_LOGD(TAG, "Problem with MakeDir: %s", _what.c_str()); } @@ -233,7 +234,7 @@ void RenameFile(string from, string to) FILE* fpSourceFile = OpenFileAndWait(from.c_str(), "rb"); if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { - printf("DeleteFile: File %s existiert nicht!\n", from.c_str()); + ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", from.c_str()); return; } fclose(fpSourceFile); @@ -249,7 +250,7 @@ void DeleteFile(string fn) FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb"); if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { - printf("DeleteFile: File %s existiert nicht!\n", fn.c_str()); + ESP_LOGD(TAG, "DeleteFile: File %s existiert nicht!", fn.c_str()); return; } fclose(fpSourceFile); @@ -265,7 +266,7 @@ void CopyFile(string input, string output) if (toUpper(input).compare("/SDCARD/WLAN.INI") == 0) { - printf("wlan.ini kann nicht kopiert werden!\n"); + ESP_LOGD(TAG, "wlan.ini kann nicht kopiert werden!"); return; } @@ -273,7 +274,7 @@ void CopyFile(string input, string output) FILE* fpSourceFile = OpenFileAndWait(input.c_str(), "rb"); if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch! { - printf("File %s existiert nicht!\n", input.c_str()); + ESP_LOGD(TAG, "File %s existiert nicht!", input.c_str()); return; } @@ -291,7 +292,7 @@ void CopyFile(string input, string output) // Close The Files fclose(fpSourceFile); fclose(fpTargetFile); - printf("File copied: %s to %s", input.c_str(), output.c_str()); + ESP_LOGD(TAG, "File copied: %s to %s", input.c_str(), output.c_str()); } string getFileFullFileName(string filename) @@ -301,7 +302,7 @@ string getFileFullFileName(string filename) if (lastpos == string::npos) return ""; -// printf("Last position: %d\n", lastpos); +// ESP_LOGD(TAG, "Last position: %d", lastpos); string zw = filename.substr(lastpos + 1, filename.size() - lastpos); @@ -318,7 +319,7 @@ string getDirectory(string filename) if (lastpos == string::npos) return ""; -// printf("Directory: %d\n", lastpos); +// ESP_LOGD(TAG, "Directory: %d", lastpos); string zw = filename.substr(0, lastpos - 1); return zw; diff --git a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp index f96d4661..4ce07b3b 100644 --- a/code/components/jomjol_image_proc/CAlignAndCutImage.cpp +++ b/code/components/jomjol_image_proc/CAlignAndCutImage.cpp @@ -5,6 +5,9 @@ #define _USE_MATH_DEFINES #include #include +#include + +static const char* TAG = "c_align_and_cut_image"; //#define GET_MEMORY malloc #define GET_MEMORY(X) heap_caps_malloc(X, MALLOC_CAP_SPIRAM) @@ -43,14 +46,14 @@ bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2) r0_x = _temp1->target_x; r0_y = _temp1->target_y; - printf("Vor ft->FindTemplate(_temp1); %s\n", _temp1->image_file.c_str()); + ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp1); %s", _temp1->image_file.c_str()); isSimilar1 = ft->FindTemplate(_temp1); _temp1->width = ft->tpl_width; _temp1->height = ft->tpl_height; r1_x = _temp2->target_x; r1_y = _temp2->target_y; - printf("Vor ft->FindTemplate(_temp2); %s\n", _temp2->image_file.c_str()); + ESP_LOGD(TAG, "Vor ft->FindTemplate(_temp2); %s", _temp2->image_file.c_str()); isSimilar2 = ft->FindTemplate(_temp2); _temp2->width = ft->tpl_width; _temp2->height = ft->tpl_height; @@ -86,7 +89,7 @@ bool CAlignAndCutImage::Align(RefInfo *_temp1, RefInfo *_temp2) CRotateImage rt(this, ImageTMP); rt.Translate(dx, dy); rt.Rotate(d_winkel, _temp1->target_x, _temp1->target_y); - printf("Alignment: dx %d - dy %d - rot %f\n", dx, dy, d_winkel); + ESP_LOGD(TAG, "Alignment: dx %d - dy %d - rot %f", dx, dy, d_winkel); return (isSimilar1 && isSimilar2); } @@ -147,7 +150,7 @@ void CAlignAndCutImage::CutAndSave(int x1, int y1, int dx, int dy, CImageBasis * if ((_target->height != dy) || (_target->width != dx) || (_target->channels != channels)) { - printf("CAlignAndCutImage::CutAndSave - Image size does not match !!"); + ESP_LOGD(TAG, "CAlignAndCutImage::CutAndSave - Image size does not match!"); return; } diff --git a/code/components/jomjol_image_proc/CFindTemplate.cpp b/code/components/jomjol_image_proc/CFindTemplate.cpp index e3761431..66119167 100644 --- a/code/components/jomjol_image_proc/CFindTemplate.cpp +++ b/code/components/jomjol_image_proc/CFindTemplate.cpp @@ -2,6 +2,10 @@ #include "ClassLogFile.h" +#include + +static const char* TAG = "c_find_template"; + // #define DEBUG_DETAIL_ON @@ -9,7 +13,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) { uint8_t* rgb_template = stbi_load(_ref->image_file.c_str(), &tpl_width, &tpl_height, &tpl_bpp, channels); -// printf("FindTemplate 01\n"); +// ESP_LOGD(TAG, "FindTemplate 01"); int ow, ow_start, ow_stop; int oh, oh_start, oh_stop; @@ -45,7 +49,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) int min, max; bool isSimilar = false; -// printf("FindTemplate 02\n"); +// ESP_LOGD(TAG, "FindTemplate 02"); if ((_ref->alignment_algo == 2) && (_ref->fastalg_x > -1) && (_ref->fastalg_y > -1)) // für Testzwecke immer Berechnen { @@ -57,7 +61,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) #endif } -// printf("FindTemplate 03\n"); +// ESP_LOGD(TAG, "FindTemplate 03"); if (isSimilar) @@ -70,7 +74,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) return true; } -// printf("FindTemplate 04\n"); +// ESP_LOGD(TAG, "FindTemplate 04"); double aktSAD; @@ -78,7 +82,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) RGBImageLock(); -// printf("FindTemplate 05\n"); +// ESP_LOGD(TAG, "FindTemplate 05"); int xouter, youter, tpl_x, tpl_y, _ch; int _anzchannels = channels; if (_ref->alignment_algo == 0) // 0 = "Default" (nur R-Kanal) @@ -106,14 +110,14 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) } } -// printf("FindTemplate 06\n"); +// ESP_LOGD(TAG, "FindTemplate 06"); if (_ref->alignment_algo == 2) CalculateSimularities(rgb_template, _ref->found_x, _ref->found_y, ow, oh, min, avg, max, SAD, _ref->fastalg_SAD, _ref->fastalg_SAD_criteria); -// printf("FindTemplate 07\n"); +// ESP_LOGD(TAG, "FindTemplate 07"); _ref->fastalg_x = _ref->found_x; _ref->fastalg_y = _ref->found_y; @@ -132,7 +136,7 @@ bool CFindTemplate::FindTemplate(RefInfo *_ref) RGBImageRelease(); stbi_image_free(rgb_template); -// printf("FindTemplate 08\n"); +// ESP_LOGD(TAG, "FindTemplate 08"); return false; } @@ -173,7 +177,7 @@ bool CFindTemplate::CalculateSimularities(uint8_t* _rgb_tmpl, int _startx, int _ float _SADdif = abs(SAD - _SADold); - printf("Anzahl %ld, avgDifSum %fd, avg %f, SAD_neu: %fd, _SAD_old: %f, _SAD_crit:%f\n", anz, avgDifSum, avg, SAD, _SADold, _SADdif); + ESP_LOGD(TAG, "Anzahl %ld, avgDifSum %fd, avg %f, SAD_neu: %fd, _SAD_old: %f, _SAD_crit:%f", anz, avgDifSum, avg, SAD, _SADold, _SADdif); if (_SADdif <= _SADcrit) return true; diff --git a/code/components/jomjol_image_proc/CImageBasis.cpp b/code/components/jomjol_image_proc/CImageBasis.cpp index 46e341c7..f705de71 100644 --- a/code/components/jomjol_image_proc/CImageBasis.cpp +++ b/code/components/jomjol_image_proc/CImageBasis.cpp @@ -61,7 +61,7 @@ uint8_t * CImageBasis::RGBImageGet() void writejpghelp(void *context, void *data, int size) { -// printf("Size all: %d, size %d\n", ((ImageData*)context)->size, size); +// ESP_LOGD(TAG, "Size all: %d, size %d", ((ImageData*)context)->size, size); ImageData* _zw = (ImageData*) context; uint8_t *voidstart = _zw->data; uint8_t *datastart = (uint8_t*) data; @@ -146,7 +146,7 @@ bool CImageBasis::CopyFromMemory(uint8_t* _source, int _size) int gr = height * width * channels; if (gr != _size) // Größe passt nicht { - printf("Cannot copy image from memory - sizes do not match: should be %d, but is %d\n", _size, gr); + ESP_LOGD(TAG, "Cannot copy image from memory - sizes do not match: should be %d, but is %d", _size, gr); return false; } @@ -359,7 +359,7 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len) stbi_image_free(rgb_image); rgb_image = stbi_load_from_memory(_buffer, len, &width, &height, &channels, 3); bpp = channels; - printf("Image loaded from memory: %d, %d, %d\n", width, height, channels); + ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels); if ((width * height * channels) == 0) { ESP_LOGE(TAG, "Image with size 0 loaded --> reboot to be done! " @@ -392,7 +392,7 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat) int anz = 1; while (!rgb_image && (anz < _anzrepeat)) { - printf("Create Image from Copy - Memory is full - try again: %d.\n", anz); + ESP_LOGD(TAG, "Create Image from Copy - Memory is full - try again: %d", anz); rgb_image = (unsigned char*) malloc(memsize); anz++; } @@ -400,8 +400,8 @@ CImageBasis::CImageBasis(CImageBasis *_copyfrom, int _anzrepeat) if (!rgb_image) { - printf(getESPHeapInfo().c_str()); - printf("\nNo more free memory!! Needed: %d %d %d %d\n", width, height, channels, memsize); + ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str()); + ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize); RGBImageRelease(); return; } @@ -424,8 +424,8 @@ CImageBasis::CImageBasis(int _width, int _height, int _channels) rgb_image = (unsigned char*)GET_MEMORY(memsize); if (!rgb_image) { - printf(getESPHeapInfo().c_str()); - printf("\nNo more free memory!! Needed: %d %d %d %d\n", width, height, channels, memsize); + ESP_LOGD(TAG, "%s", getESPHeapInfo().c_str()); + ESP_LOGD(TAG, "No more free memory!! Needed: %d %d %d %d", width, height, channels, memsize); return; } } @@ -438,21 +438,21 @@ CImageBasis::CImageBasis(std::string _image) externalImage = false; filename = _image; long zwld = esp_get_free_heap_size(); - printf("freeheapsize before: %ld\n", zwld); + ESP_LOGD(TAG, "freeheapsize before: %ld", zwld); RGBImageLock(); rgb_image = stbi_load(_image.c_str(), &width, &height, &bpp, channels); RGBImageRelease(); zwld = esp_get_free_heap_size(); - printf("freeheapsize after : %ld\n", zwld); + ESP_LOGD(TAG, "freeheapsize after : %ld", zwld); - std::string zw = "Image Load failed:" + _image + "\n"; + std::string zw = "Image Load failed:" + _image; if (rgb_image == NULL) - printf(zw.c_str()); + ESP_LOGD(TAG, "%s", zw.c_str()); zw = "CImageBasis after load " + _image + "\n"; - printf(zw.c_str()); - printf("w %d, h %d, b %d, c %d\n", width, height, bpp, channels); + ESP_LOGD(TAG, "%s", zw.c_str()); + ESP_LOGD(TAG, "w %d, h %d, b %d, c %d", width, height, bpp, channels); } @@ -543,7 +543,7 @@ void CImageBasis::Resize(int _new_dx, int _new_dy, CImageBasis *_target) { if ((_target->height != _new_dy) || (_target->width != _new_dx) || (_target->channels != channels)) { - printf("CImageBasis::Resize - Target image size does not fit !!"); + ESP_LOGD(TAG, "CImageBasis::Resize - Target image size does not fit!"); return; } diff --git a/code/components/jomjol_image_proc/CRotateImage.cpp b/code/components/jomjol_image_proc/CRotateImage.cpp index 96eec7a0..821c4269 100644 --- a/code/components/jomjol_image_proc/CRotateImage.cpp +++ b/code/components/jomjol_image_proc/CRotateImage.cpp @@ -280,13 +280,13 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery) void CRotateImage::Rotate(float _angle) { -// printf("width %d, height %d\n", width, height); +// ESP_LOGD(TAG, "width %d, height %d", width, height); Rotate(_angle, width / 2, height / 2); } void CRotateImage::RotateAntiAliasing(float _angle) { -// printf("width %d, height %d\n", width, height); +// ESP_LOGD(TAG, "width %d, height %d", width, height); RotateAntiAliasing(_angle, width / 2, height / 2); } diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 34e5d1eb..84be1076 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -64,7 +64,7 @@ std::string ClassLogFile::getESPHeapInfo(){ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog) { - printf("Start WriteToData\n"); + ESP_LOGD(TAG, "Start WriteToData\n"); time_t rawtime; struct tm* timeinfo; char buffer[30]; @@ -82,7 +82,7 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV return; } - printf("Datalogfile: %s\n", logpath.c_str()); + ESP_LOGD(TAG, "Datalogfile: %s", logpath.c_str()); pFile = fopen(logpath.c_str(), "a+"); if (pFile!=NULL) { @@ -130,7 +130,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool // pFile = OpenFileAndWait(_fn.c_str(), "a"); pFile = fopen(_fn.c_str(), "a+"); -// printf("Logfile opened: %s\n", _fn.c_str()); +// ESP_LOGD(TAG, "Logfile opened: %s", _fn.c_str()); if (pFile!=NULL) { if (_time) @@ -186,7 +186,7 @@ void ClassLogFile::WriteToFile(std::string info, bool _time) std::string logpath = logroot + "/" + buffer; WriteToDedicatedFile(logpath, info, _time); - printf((info + "\n").c_str()); + ESP_LOGD(TAG, "%s", info.c_str()); } std::string ClassLogFile::GetCurrentFileName() diff --git a/code/components/jomjol_wlan/read_wlanini.cpp b/code/components/jomjol_wlan/read_wlanini.cpp index e1a9f8c9..07f2cbd4 100644 --- a/code/components/jomjol_wlan/read_wlanini.cpp +++ b/code/components/jomjol_wlan/read_wlanini.cpp @@ -211,7 +211,7 @@ bool ChangeHostName(std::string fn, std::string _newhostname) while ((line.size() > 0) || !(feof(pFile))) { - printf("%s", line.c_str()); + ESP_LOGD(TAG, "%s", line.c_str()); zerlegt = ZerlegeZeileWLAN(line, "="); zerlegt[0] = trim(zerlegt[0], " "); @@ -244,7 +244,7 @@ bool ChangeHostName(std::string fn, std::string _newhostname) for (int i = 0; i < neuesfile.size(); ++i) { - printf(neuesfile[i].c_str()); + ESP_LOGD(TAG, "%s", neuesfile[i].c_str()); fputs(neuesfile[i].c_str(), pFile); } From 4951fc9b803c2db498cb8462dc3b7d38b631a1b6 Mon Sep 17 00:00:00 2001 From: George Ruinelli Date: Fri, 21 Oct 2022 23:19:36 +0200 Subject: [PATCH 21/44] removed redundant log entries (some now are DEBUG isntread of INFO or ERROR) --- code/components/jomjol_fileserver_ota/server_ota.cpp | 1 - .../jomjol_flowcontroll/ClassFlowCNNGeneral.cpp | 9 +++------ .../components/jomjol_flowcontroll/ClassFlowControll.cpp | 3 +-- code/components/jomjol_flowcontroll/ClassFlowImage.cpp | 2 -- code/components/jomjol_helper/Helper.cpp | 3 +-- code/components/jomjol_logfile/ClassLogFile.cpp | 1 - code/components/jomjol_mqtt/interface_mqtt.cpp | 2 -- code/components/jomjol_tfliteclass/server_tflite.cpp | 2 -- code/components/jomjol_time_sntp/time_sntp.cpp | 1 - code/main/main.cpp | 5 ----- 10 files changed, 5 insertions(+), 24 deletions(-) diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp index 2c781705..3458595a 100644 --- a/code/components/jomjol_fileserver_ota/server_ota.cpp +++ b/code/components/jomjol_fileserver_ota/server_ota.cpp @@ -494,7 +494,6 @@ void task_reboot(void *pvParameter) void doReboot(){ LogFile.SwitchOnOff(true); LogFile.WriteToFile("Reboot triggered by Software (5s)."); - ESP_LOGI(TAGPARTOTA, "Reboot in 5sec"); LogFile.WriteToFile("Reboot in 5sec"); xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL); // KillTFliteTasks(); // kills itself diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index ba7ca83c..82869a1c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -548,8 +548,7 @@ bool ClassFlowCNNGeneral::getNetworkParameter() zwcnn = FormatFileName(zwcnn); ESP_LOGD(TAG, "%s", zwcnn.c_str()); if (!tflite->LoadModel(zwcnn)) { - ESP_LOGD(TAG, "Can't read model file /sdcard%s", cnnmodelfile.c_str()); - LogFile.WriteToFile("Cannot load model"); + LogFile.WriteToFile("Can't read model file /sdcard%s", cnnmodelfile.c_str()); delete tflite; return false; } @@ -617,8 +616,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) zwcnn = FormatFileName(zwcnn); ESP_LOGD(TAG, "%s", zwcnn.c_str()); if (!tflite->LoadModel(zwcnn)) { - ESP_LOGD(TAG, "Can't read model file /sdcard%s", cnnmodelfile.c_str()); - LogFile.WriteToFile("Cannot load model"); + LogFile.WriteToFile("Can't read model file /sdcard%s", cnnmodelfile.c_str()); delete tflite; return false; @@ -804,8 +802,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time) GENERAL[_ana]->ROI[i]->isReject = true; result = -1; _result_save_file+= 100; // Für den Fall, dass fit nicht ausreichend, soll trotzdem das Ergebnis mit "-10x.y" abgespeichert werden. - string zw = "Value Rejected due to Threshold (Fit: " + to_string(_fit) + "Threshold: " + to_string(CNNGoodThreshold); - ESP_LOGD(TAG, "Value Rejected due to Threshold (Fit: %f, Threshold: %f", _fit, CNNGoodThreshold); + string zw = "Value Rejected due to Threshold (Fit: " + to_string(_fit) + "Threshold: " + to_string(CNNGoodThreshold) + ")"; LogFile.WriteToFile(zw); } else diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp index 22982b7a..9c900844 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp @@ -493,9 +493,8 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph) { // reboot notwendig damit die neue wlan.ini auch benutzt wird !!! fclose(pfile); - ESP_LOGD(TAG, "do reboot"); LogFile.SwitchOnOff(true); - LogFile.WriteToFile("Reboot to activate new HOSTNAME."); + LogFile.WriteToFile("Rebooting to activate new HOSTNAME..."); esp_restart(); hard_restart(); doReboot(); diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp index c42c7cb0..bea7306c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp @@ -47,7 +47,6 @@ string ClassFlowImage::CreateLogFolder(string time) { string logPath = LogImageLocation + "/" + time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + time.LOGFILE_TIME_FORMAT_HOUR_EXTR; isLogImage = mkdir_r(logPath.c_str(), S_IRWXU) == 0; if (!isLogImage) { - ESP_LOGW(logTag, "Can't create log folder for analog images. Path %s", logPath.c_str()); LogFile.WriteToFile("Can't create log folder for analog images. Path " + logPath); } @@ -129,7 +128,6 @@ void ClassFlowImage::RemoveOldLogs() } } } - ESP_LOGI(logTag, "%d image folder deleted. %d image folder not deleted.", deleted, notDeleted); LogFile.WriteToFile("Image folder deleted: " + std::to_string(deleted) + ". Image folder not deleted: " + std::to_string(notDeleted)); closedir(dir); } diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index c0b4c508..1c826430 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -108,8 +108,7 @@ FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec) TickType_t xDelay; xDelay = _waitsec * 1000 / portTICK_PERIOD_MS; std::string zw = "File is locked: " + std::string(nm) + " - wait for " + std::to_string(_waitsec) + " seconds"; - ESP_LOGD(TAG, "%s", zw.c_str()); - LogFile.WriteToFile(zw); + LogFile.WriteToFile(zw); vTaskDelay( xDelay ); pfile = fopen(nm, _mode); } diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 84be1076..4dd6882f 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -248,7 +248,6 @@ void ClassLogFile::RemoveOld() } } } - ESP_LOGI(TAG, "%d logfiles deleted. %d files not deleted (incl. leer.txt).", deleted, notDeleted); LogFile.WriteToFile("logfiles deleted: " + std::to_string(deleted) + " files not deleted (incl. leer.txt): " + std::to_string(notDeleted)); closedir(dir); diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index 47c6a4bb..269a9f56 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -32,7 +32,6 @@ bool MQTTPublish(std::string _key, std::string _content, int retained_flag){ } zw = "MQTT - sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content; if (debugdetail) LogFile.WriteToFile(zw); - ESP_LOGD(TAG_INTERFACEMQTT, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str()); return true; } @@ -223,7 +222,6 @@ void MQTTconnected(){ if (subscribeFunktionMap != NULL) { for(std::map>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) { int msg_id = esp_mqtt_client_subscribe(client, it->first.c_str(), 0); - ESP_LOGD(TAG_INTERFACEMQTT, "topic %s subscribe successful, msg_id=%d", it->first.c_str(), msg_id); LogFile.WriteToFile("MQTT - topic " + it->first + " subscribe successful, msg_id=" + std::to_string(msg_id)); } } diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp index 3ffa9fb6..9064d138 100644 --- a/code/components/jomjol_tfliteclass/server_tflite.cpp +++ b/code/components/jomjol_tfliteclass/server_tflite.cpp @@ -718,7 +718,6 @@ void task_autodoFlow(void *pvParameter) { std::string _zw = "task_autodoFlow - next round - Round #" + std::to_string(++countRounds); LogFile.WriteToFile(_zw); - ESP_LOGD(TAGTFLITE, "Autoflow: start"); fr_start = esp_timer_get_time(); if (flowisrunning) @@ -747,7 +746,6 @@ void task_autodoFlow(void *pvParameter) stream << std::fixed << std::setprecision(1) << cputmp; string zwtemp = "CPU Temperature: " + stream.str(); LogFile.WriteToFile(zwtemp); - ESP_LOGD(TAGTFLITE, "CPU Temperature: %.2f", cputmp); fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000; if (auto_intervall > fr_delta_ms) { diff --git a/code/components/jomjol_time_sntp/time_sntp.cpp b/code/components/jomjol_time_sntp/time_sntp.cpp index c4fcae82..336ebd68 100644 --- a/code/components/jomjol_time_sntp/time_sntp.cpp +++ b/code/components/jomjol_time_sntp/time_sntp.cpp @@ -85,7 +85,6 @@ void setTimeZone(std::string _tzstring) { setenv("TZ", _tzstring.c_str(), 1); tzset(); - ESP_LOGD(TAG, "TimeZone set to %s", _tzstring.c_str()); _tzstring = "Time zone set to " + _tzstring; LogFile.WriteToFile(_tzstring); } diff --git a/code/main/main.cpp b/code/main/main.cpp index 80993b27..01be3146 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -212,15 +212,11 @@ extern "C" void app_main(void) { std::string _zws = "Not enough PSRAM available. Expected 4.194.304 MByte - available: " + std::to_string(_hsize); _zws = _zws + "\nEither not initialzed, too small (2MByte only) or not present at all. Firmware cannot start!!"; - ESP_LOGD(TAGMAIN, "%s", _zws.c_str()); LogFile.SwitchOnOff(true); LogFile.WriteToFile(_zws); LogFile.SwitchOnOff(false); } else { if (cam != ESP_OK) { - ESP_LOGE(TAGMAIN, "Failed to initialize camera module. " - "Check that your camera module is working and connected properly."); - LogFile.SwitchOnOff(true); LogFile.WriteToFile("Failed to initialize camera module. " "Check that your camera module is working and connected properly."); @@ -229,7 +225,6 @@ extern "C" void app_main(void) // Test Camera camera_fb_t * fb = esp_camera_fb_get(); if (!fb) { - ESP_LOGE(TAGMAIN, "esp_camera_fb_get: Camera Capture Failed"); LogFile.SwitchOnOff(true); LogFile.WriteToFile("Camera cannot be initialzed. " "System will reboot."); From e1f8ac59cbf08eb5e79ba9dbcf6b38aeef3ce288 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:11:11 +0200 Subject: [PATCH 22/44] Add SD Card Info to info.html --- code/components/jomjol_helper/CMakeLists.txt | 2 +- code/components/jomjol_helper/Helper.cpp | 235 ++++++++++++++++++- code/components/jomjol_helper/Helper.h | 12 +- code/main/main.cpp | 1 + code/main/server_main.cpp | 67 ++++++ sd-card/html/info.html | 78 ++++++ 6 files changed, 391 insertions(+), 4 deletions(-) diff --git a/code/components/jomjol_helper/CMakeLists.txt b/code/components/jomjol_helper/CMakeLists.txt index c57b54d3..8d9580d5 100644 --- a/code/components/jomjol_helper/CMakeLists.txt +++ b/code/components/jomjol_helper/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES tflite-lib jomjol_logfile) + REQUIRES tflite-lib jomjol_logfile fatfs sdmmc) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index ab18fa11..346062bd 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -20,13 +20,17 @@ extern "C" { #include "ClassLogFile.h" -//#include "ClassLogFile.h" + +#include "esp_vfs_fat.h" //#define ISWINDOWS_TRUE #define PATH_MAX_STRING_SIZE 256 using namespace std; +sdmmc_cid_t SDCardCid; +sdmmc_csd_t SDCardCsd; + ///////////////////////////////////////////////////////////////////////////////////////////// string getESPHeapInfo(){ string espInfoResultStr = ""; @@ -73,8 +77,100 @@ size_t getInternalESPHeapSize() { return aFreeInternalHeapSize; } +string getSDCardPartitionSize(){ + FATFS *fs; + uint32_t fre_clust, tot_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512); + + return std::to_string(tot_sect); +} + +string getSDCardFreeParitionSpace(){ + FATFS *fs; + uint32_t fre_clust, fre_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize); + + return std::to_string(fre_sect); +} + +string getSDCardParitionAllocationSize(){ + FATFS *fs; + uint32_t fre_clust, allocation_size; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + allocation_size = fs->ssize; + + printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + + return std::to_string(allocation_size); +} +void SaveSDCardInfo(sdmmc_card_t* card) { + SDCardCid = card->cid; + SDCardCsd = card->csd; +} + +string getSDCardManufacturer(){ + string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); + printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str()); + + return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); +} + +string getSDCardName(){ + char *SDCardName = SDCardCid.name; + printf("SD Card Name: %s\n", SDCardName); + + return std::string(SDCardName); +} + +string getSDCardCapacity(){ + int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str()); + + return std::to_string(SDCardCapacity); +} + +string getSDCardSectorSize(){ + int SDCardSectorSize = SDCardCsd.sector_size; + printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str()); + + return std::to_string(SDCardSectorSize); +} + +/* + int SDCardManu = card->cid.mfg_id; + printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); + + printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); + + int SDCardOEM = card->cid.oem_id; + printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); + + int SDCardRev = card->cid.revision; + printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); + + char *SDCardName = card->cid.name; + printf("SD Name: %s\n", SDCardName); + + int SDCardCSize = card->csd.sector_size; + printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); + + int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); +*/ /////////////////////////////////////////////////////////////////////////////////////////////// @@ -462,7 +558,6 @@ int removeFolder(const char* folderPath, const char* logTag) { } - std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "") { std::vector Output; @@ -487,3 +582,139 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter return Output; } + +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database { + string type; + int id; + 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[] = { + { + .type = "sd", + .id = 0x01, + .manufacturer = "Panasonic", + }, + { + .type = "sd", + .id = 0x02, + .manufacturer = "Toshiba/Kingston/Viking", + }, + { + .type = "sd", + .id = 0x03, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x08, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x18, + .manufacturer = "Infineon", + }, + { + .type = "sd", + .id = 0x1b, + .manufacturer = "Transcend/Samsung", + }, + { + .type = "sd", + .id = 0x1c, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1d, + .manufacturer = "Corsair/AData", + }, + { + .type = "sd", + .id = 0x1e, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1f, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x27, + .manufacturer = "Delkin/Phison", + }, + { + .type = "sd", + .id = 0x28, + .manufacturer = "Lexar", + }, + { + .type = "sd", + .id = 0x30, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x31, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x33, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x41, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x6f, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x74, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x76, + .manufacturer = "Patriot", + }, + { + .type = "sd", + .id = 0x82, + .manufacturer = "Gobe/Sony", + }, + { + .type = "sd", + .id = 0x89, + .manufacturer = "Unknown", + } +}; + +/* Parse SD Card Manufacturer Database */ +string SDCardParseManufacturerIDs(int id) +{ + unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); + string ret_val = ""; + + for (int i = 0; i < id_cnt; i++) { + if (database[i].id == id) { + return database[i].manufacturer; + } + else { + ret_val = "ID unknown (not in DB)"; + } + } + return ret_val; +} + diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index a84fe8d1..b530f446 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -2,7 +2,7 @@ #include #include #include - +#include "sdmmc_cmd.h" using namespace std; @@ -47,3 +47,13 @@ size_t getESPHeapSize(); string getESPHeapInfo(); ///////////////////////////// +string getSDCardPartitionSize(); +string getSDCardFreeParitionSpace(); +string getSDCardParitionAllocationSize(); + +void SaveSDCardInfo(sdmmc_card_t* card); +string SDCardParseManufacturerIDs(int); +string getSDCardManufacturer(); +string getSDCardName(); +string getSDCardCapacity(); +string getSDCardSectorSize(); diff --git a/code/main/main.cpp b/code/main/main.cpp index 40fbb43b..fd7f0611 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -112,6 +112,7 @@ bool Init_NVS_SDCard() return false; } sdmmc_card_print_info(stdout, card); + SaveSDCardInfo(card); return true; } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 7d24f2b0..d76c0b1f 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -15,6 +15,8 @@ #include "server_tflite.h" +#include "helper.h" + //#define DEBUG_DETAIL_ON @@ -134,6 +136,71 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } + if (_task.compare("SDCardPartitionSize") == 0) + { + std::string zw; + zw = getSDCardPartitionSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardFreeParitionSpace") == 0) + { + std::string zw; + zw = getSDCardFreeParitionSpace(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardPartitionSectorSize") == 0) + { + std::string zw; + zw = getSDCardParitionAllocationSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardManufacturer") == 0) + { + std::string zw; + zw = getSDCardManufacturer(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardName") == 0) + { + std::string zw; + zw = getSDCardName(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardCapacity") == 0) + { + std::string zw; + zw = getSDCardCapacity(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardSectorSize") == 0) + { + std::string zw; + zw = getSDCardSectorSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + + return ESP_OK; } diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 2ad7c351..ffcfad3c 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -77,6 +77,84 @@ div { + + +

SD Card Info

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ SD Card Manufacturer: + +
+ +
+
+ SD Card Name: + +
+ +
+
+ SD Card Size [MB]: + +
+ +
+
+ SD Card Sector Size [byte]: + +
+ +
+
+ Partition Size [MB]: + +
+ +
+
+ Partition Free Space [MB]: + +
+ +
+
+ Partition Allocation Size [byte]: + +
+ +
+
+ + +

Version Info

From 98bf7e5387ffc0c7672f1b351b58e7c1fd385cbb Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:17:02 +0200 Subject: [PATCH 23/44] Add SD Card Info to info.html --- code/components/jomjol_helper/Helper.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 346062bd..fd50953a 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -150,28 +150,6 @@ string getSDCardSectorSize(){ return std::to_string(SDCardSectorSize); } -/* - int SDCardManu = card->cid.mfg_id; - printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); - - printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); - - int SDCardOEM = card->cid.oem_id; - printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); - - int SDCardRev = card->cid.revision; - printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); - - char *SDCardName = card->cid.name; - printf("SD Name: %s\n", SDCardName); - - int SDCardCSize = card->csd.sector_size; - printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); - - int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); -*/ - /////////////////////////////////////////////////////////////////////////////////////////////// void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) From e308a1b5d9c56a8d1b05efe66da7b78993128870 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:30:37 +0200 Subject: [PATCH 24/44] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index d76c0b1f..28e78c8c 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -154,7 +154,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardPartitionSectorSize") == 0) + if (_task.compare("SDCardParitionAllocationSize") == 0) { std::string zw; zw = getSDCardParitionAllocationSize(); From f15b1e5dfc7f0fc32fdf84ed77441c756a2e4d89 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:35:51 +0200 Subject: [PATCH 25/44] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index ffcfad3c..4beda452 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -146,7 +146,7 @@ div { Partition Allocation Size [byte]: From c2b89dd1997f99d93940e74b8ad1b4e0dc5c8c67 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:27:21 +0200 Subject: [PATCH 26/44] Name adjustment --- code/components/jomjol_helper/Helper.cpp | 6 +++--- code/components/jomjol_helper/Helper.h | 4 ++-- code/main/server_main.cpp | 6 +++--- sd-card/html/info.html | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index fd50953a..66d95853 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -90,7 +90,7 @@ string getSDCardPartitionSize(){ return std::to_string(tot_sect); } -string getSDCardFreeParitionSpace(){ +string getSDCardFreePartitionSpace(){ FATFS *fs; uint32_t fre_clust, fre_sect; @@ -103,7 +103,7 @@ string getSDCardFreeParitionSpace(){ return std::to_string(fre_sect); } -string getSDCardParitionAllocationSize(){ +string getSDCardPartitionAllocationSize(){ FATFS *fs; uint32_t fre_clust, allocation_size; @@ -111,7 +111,7 @@ string getSDCardParitionAllocationSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); allocation_size = fs->ssize; - printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); return std::to_string(allocation_size); } diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index b530f446..8d7c2cf0 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -48,8 +48,8 @@ string getESPHeapInfo(); ///////////////////////////// string getSDCardPartitionSize(); -string getSDCardFreeParitionSpace(); -string getSDCardParitionAllocationSize(); +string getSDCardFreePartitionSpace(); +string getSDCardPartitionAllocationSize(); void SaveSDCardInfo(sdmmc_card_t* card); string SDCardParseManufacturerIDs(int); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 28e78c8c..3de34933 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -145,7 +145,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardFreeParitionSpace") == 0) + if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; zw = getSDCardFreeParitionSpace(); @@ -154,10 +154,10 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardParitionAllocationSize") == 0) + if (_task.compare("SDCardPartitionAllocationSize") == 0) { std::string zw; - zw = getSDCardParitionAllocationSize(); + zw = getSDCardPartitionAllocationSize(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 4beda452..7dbd7ee1 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -137,7 +137,7 @@ div { From 495b5de38c9492068ff2a45099e15a0a11665d70 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:29:32 +0200 Subject: [PATCH 27/44] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 3de34933..7bdbc481 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -148,7 +148,7 @@ esp_err_t info_get_handler(httpd_req_t *req) if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; - zw = getSDCardFreeParitionSpace(); + zw = getSDCardFreePartitionSpace(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; From e05085ddf0d5ad80304fbd6fef5c00baa38c06cc Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:31:17 +0200 Subject: [PATCH 28/44] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 7dbd7ee1..afd87843 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -136,7 +136,7 @@ div { Partition Free Space [MB]: From 98d35e0412098f48a759e956a61f830fb94e19e3 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sat, 22 Oct 2022 21:44:35 +0200 Subject: [PATCH 29/44] Revert "Merge pull request #1205 from Slider0007/Add-sdcard-info" This reverts commit 437e8e4d25185bae43ca70def24359fa1c1b2968, reversing changes made to 0a2b6b71cab68414eec8b3c8f8626e1db5c27f5e. --- code/components/jomjol_helper/CMakeLists.txt | 2 +- code/components/jomjol_helper/Helper.cpp | 213 +------------------ code/components/jomjol_helper/Helper.h | 12 +- code/main/main.cpp | 1 - code/main/server_main.cpp | 67 ------ sd-card/html/info.html | 78 ------- 6 files changed, 4 insertions(+), 369 deletions(-) diff --git a/code/components/jomjol_helper/CMakeLists.txt b/code/components/jomjol_helper/CMakeLists.txt index 8d9580d5..c57b54d3 100644 --- a/code/components/jomjol_helper/CMakeLists.txt +++ b/code/components/jomjol_helper/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES tflite-lib jomjol_logfile fatfs sdmmc) + REQUIRES tflite-lib jomjol_logfile) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index cf7b4d5e..1c826430 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -20,8 +20,7 @@ extern "C" { #include "ClassLogFile.h" - -#include "esp_vfs_fat.h" +//#include "ClassLogFile.h" static const char* TAG = "helper"; @@ -30,9 +29,6 @@ static const char* TAG = "helper"; using namespace std; -sdmmc_cid_t SDCardCid; -sdmmc_csd_t SDCardCsd; - ///////////////////////////////////////////////////////////////////////////////////////////// string getESPHeapInfo(){ string espInfoResultStr = ""; @@ -79,78 +75,8 @@ size_t getInternalESPHeapSize() { return aFreeInternalHeapSize; } -string getSDCardPartitionSize(){ - FATFS *fs; - uint32_t fre_clust, tot_sect; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - - printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512); - - return std::to_string(tot_sect); -} - -string getSDCardFreePartitionSpace(){ - FATFS *fs; - uint32_t fre_clust, fre_sect; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB - - printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize); - - return std::to_string(fre_sect); -} - -string getSDCardPartitionAllocationSize(){ - FATFS *fs; - uint32_t fre_clust, allocation_size; - - /* Get volume information and free clusters of drive 0 */ - f_getfree("0:", (DWORD *)&fre_clust, &fs); - allocation_size = fs->ssize; - - printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); - - return std::to_string(allocation_size); -} -void SaveSDCardInfo(sdmmc_card_t* card) { - SDCardCid = card->cid; - SDCardCsd = card->csd; -} - -string getSDCardManufacturer(){ - string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); - printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str()); - - return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); -} - -string getSDCardName(){ - char *SDCardName = SDCardCid.name; - printf("SD Card Name: %s\n", SDCardName); - - return std::string(SDCardName); -} - -string getSDCardCapacity(){ - int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str()); - - return std::to_string(SDCardCapacity); -} - -string getSDCardSectorSize(){ - int SDCardSectorSize = SDCardCsd.sector_size; - printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str()); - - return std::to_string(SDCardSectorSize); -} /////////////////////////////////////////////////////////////////////////////////////////////// @@ -536,6 +462,7 @@ int removeFolder(const char* folderPath, const char* logTag) { } + std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "") { std::vector Output; @@ -560,139 +487,3 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter return Output; } - -/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ -/* SD Card Manufacturer Database */ -struct SDCard_Manufacturer_database { - string type; - int id; - 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[] = { - { - .type = "sd", - .id = 0x01, - .manufacturer = "Panasonic", - }, - { - .type = "sd", - .id = 0x02, - .manufacturer = "Toshiba/Kingston/Viking", - }, - { - .type = "sd", - .id = 0x03, - .manufacturer = "SanDisk", - }, - { - .type = "sd", - .id = 0x08, - .manufacturer = "Silicon Power", - }, - { - .type = "sd", - .id = 0x18, - .manufacturer = "Infineon", - }, - { - .type = "sd", - .id = 0x1b, - .manufacturer = "Transcend/Samsung", - }, - { - .type = "sd", - .id = 0x1c, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x1d, - .manufacturer = "Corsair/AData", - }, - { - .type = "sd", - .id = 0x1e, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x1f, - .manufacturer = "Kingston", - }, - { - .type = "sd", - .id = 0x27, - .manufacturer = "Delkin/Phison", - }, - { - .type = "sd", - .id = 0x28, - .manufacturer = "Lexar", - }, - { - .type = "sd", - .id = 0x30, - .manufacturer = "SanDisk", - }, - { - .type = "sd", - .id = 0x31, - .manufacturer = "Silicon Power", - }, - { - .type = "sd", - .id = 0x33, - .manufacturer = "STMicroelectronics", - }, - { - .type = "sd", - .id = 0x41, - .manufacturer = "Kingston", - }, - { - .type = "sd", - .id = 0x6f, - .manufacturer = "STMicroelectronics", - }, - { - .type = "sd", - .id = 0x74, - .manufacturer = "Transcend", - }, - { - .type = "sd", - .id = 0x76, - .manufacturer = "Patriot", - }, - { - .type = "sd", - .id = 0x82, - .manufacturer = "Gobe/Sony", - }, - { - .type = "sd", - .id = 0x89, - .manufacturer = "Unknown", - } -}; - -/* Parse SD Card Manufacturer Database */ -string SDCardParseManufacturerIDs(int id) -{ - unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); - string ret_val = ""; - - for (int i = 0; i < id_cnt; i++) { - if (database[i].id == id) { - return database[i].manufacturer; - } - else { - ret_val = "ID unknown (not in DB)"; - } - } - return ret_val; -} - diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 8d7c2cf0..a84fe8d1 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -2,7 +2,7 @@ #include #include #include -#include "sdmmc_cmd.h" + using namespace std; @@ -47,13 +47,3 @@ size_t getESPHeapSize(); string getESPHeapInfo(); ///////////////////////////// -string getSDCardPartitionSize(); -string getSDCardFreePartitionSpace(); -string getSDCardPartitionAllocationSize(); - -void SaveSDCardInfo(sdmmc_card_t* card); -string SDCardParseManufacturerIDs(int); -string getSDCardManufacturer(); -string getSDCardName(); -string getSDCardCapacity(); -string getSDCardSectorSize(); diff --git a/code/main/main.cpp b/code/main/main.cpp index 5436c7c6..01be3146 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -112,7 +112,6 @@ bool Init_NVS_SDCard() return false; } sdmmc_card_print_info(stdout, card); - SaveSDCardInfo(card); return true; } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 9f679a6f..d60b2aa1 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -17,8 +17,6 @@ #include "esp_log.h" -#include "helper.h" - //#define DEBUG_DETAIL_ON @@ -138,71 +136,6 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardPartitionSize") == 0) - { - std::string zw; - zw = getSDCardPartitionSize(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardFreePartitionSpace") == 0) - { - std::string zw; - zw = getSDCardFreePartitionSpace(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardPartitionAllocationSize") == 0) - { - std::string zw; - zw = getSDCardPartitionAllocationSize(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardManufacturer") == 0) - { - std::string zw; - zw = getSDCardManufacturer(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardName") == 0) - { - std::string zw; - zw = getSDCardName(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardCapacity") == 0) - { - std::string zw; - zw = getSDCardCapacity(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - if (_task.compare("SDCardSectorSize") == 0) - { - std::string zw; - zw = getSDCardSectorSize(); - httpd_resp_sendstr_chunk(req, zw.c_str()); - httpd_resp_sendstr_chunk(req, NULL); - return ESP_OK; - } - - - return ESP_OK; } diff --git a/sd-card/html/info.html b/sd-card/html/info.html index afd87843..2ad7c351 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -77,84 +77,6 @@ div {
-
+
- +
-
+
- - -

SD Card Info

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- SD Card Manufacturer: - -
- -
-
- SD Card Name: - -
- -
-
- SD Card Size [MB]: - -
- -
-
- SD Card Sector Size [byte]: - -
- -
-
- Partition Size [MB]: - -
- -
-
- Partition Free Space [MB]: - -
- -
-
- Partition Allocation Size [byte]: - -
- -
-
- - -

Version Info

From 803e8f2bff1515918de6ec3ae46bd7c7e1e04e9a Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:11:11 +0200 Subject: [PATCH 30/44] Add SD Card Info to info.html --- code/components/jomjol_helper/CMakeLists.txt | 2 +- code/components/jomjol_helper/Helper.cpp | 235 ++++++++++++++++++- code/components/jomjol_helper/Helper.h | 12 +- code/main/main.cpp | 1 + code/main/server_main.cpp | 67 ++++++ sd-card/html/info.html | 78 ++++++ 6 files changed, 391 insertions(+), 4 deletions(-) diff --git a/code/components/jomjol_helper/CMakeLists.txt b/code/components/jomjol_helper/CMakeLists.txt index c57b54d3..8d9580d5 100644 --- a/code/components/jomjol_helper/CMakeLists.txt +++ b/code/components/jomjol_helper/CMakeLists.txt @@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*) idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "." - REQUIRES tflite-lib jomjol_logfile) + REQUIRES tflite-lib jomjol_logfile fatfs sdmmc) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 1c826430..57f97950 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -20,7 +20,8 @@ extern "C" { #include "ClassLogFile.h" -//#include "ClassLogFile.h" + +#include "esp_vfs_fat.h" static const char* TAG = "helper"; @@ -29,6 +30,9 @@ static const char* TAG = "helper"; using namespace std; +sdmmc_cid_t SDCardCid; +sdmmc_csd_t SDCardCsd; + ///////////////////////////////////////////////////////////////////////////////////////////// string getESPHeapInfo(){ string espInfoResultStr = ""; @@ -75,8 +79,100 @@ size_t getInternalESPHeapSize() { return aFreeInternalHeapSize; } +string getSDCardPartitionSize(){ + FATFS *fs; + uint32_t fre_clust, tot_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + tot_sect = ((fs->n_fatent - 2) * fs->csize) /1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB total drive space (Sector size [bytes]: %d)\n", (int)tot_sect, (int)fs->csize*512); + + return std::to_string(tot_sect); +} + +string getSDCardFreeParitionSpace(){ + FATFS *fs; + uint32_t fre_clust, fre_sect; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + fre_sect = (fre_clust * fs->csize) / 1024 /(1024/SDCardCsd.sector_size); //corrected by SD Card sector size (usually 512 bytes) and convert to MB + + printf("%d MB free drive space (Sector size [bytes]: %d)\n", (int)fre_sect, (int)fs->ssize); + + return std::to_string(fre_sect); +} + +string getSDCardParitionAllocationSize(){ + FATFS *fs; + uint32_t fre_clust, allocation_size; + + /* Get volume information and free clusters of drive 0 */ + f_getfree("0:", (DWORD *)&fre_clust, &fs); + allocation_size = fs->ssize; + + printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + + return std::to_string(allocation_size); +} +void SaveSDCardInfo(sdmmc_card_t* card) { + SDCardCid = card->cid; + SDCardCsd = card->csd; +} + +string getSDCardManufacturer(){ + string SDCardManufacturer = SDCardParseManufacturerIDs(SDCardCid.mfg_id); + printf("SD Card Manufactuer: %s\n", SDCardManufacturer.c_str()); + + return (SDCardManufacturer + " (ID: " + std::to_string(SDCardCid.mfg_id) + ")"); +} + +string getSDCardName(){ + char *SDCardName = SDCardCid.name; + printf("SD Card Name: %s\n", SDCardName); + + return std::string(SDCardName); +} + +string getSDCardCapacity(){ + int SDCardCapacity = SDCardCsd.capacity / (1024/SDCardCsd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Card Capacity: %s\n", std::to_string(SDCardCapacity).c_str()); + + return std::to_string(SDCardCapacity); +} + +string getSDCardSectorSize(){ + int SDCardSectorSize = SDCardCsd.sector_size; + printf("SD Card Sector Size: %s\n", std::to_string(SDCardSectorSize).c_str()); + + return std::to_string(SDCardSectorSize); +} + +/* + int SDCardManu = card->cid.mfg_id; + printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); + + printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); + + int SDCardOEM = card->cid.oem_id; + printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); + + int SDCardRev = card->cid.revision; + printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); + + char *SDCardName = card->cid.name; + printf("SD Name: %s\n", SDCardName); + + int SDCardCSize = card->csd.sector_size; + printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); + + int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) + printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); +*/ /////////////////////////////////////////////////////////////////////////////////////////////// @@ -462,7 +558,6 @@ int removeFolder(const char* folderPath, const char* logTag) { } - std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "") { std::vector Output; @@ -487,3 +582,139 @@ std::vector HelperZerlegeZeile(std::string input, std::string _delimiter return Output; } + +/* Source: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git/tree/lsmmc.c */ +/* SD Card Manufacturer Database */ +struct SDCard_Manufacturer_database { + string type; + int id; + 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[] = { + { + .type = "sd", + .id = 0x01, + .manufacturer = "Panasonic", + }, + { + .type = "sd", + .id = 0x02, + .manufacturer = "Toshiba/Kingston/Viking", + }, + { + .type = "sd", + .id = 0x03, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x08, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x18, + .manufacturer = "Infineon", + }, + { + .type = "sd", + .id = 0x1b, + .manufacturer = "Transcend/Samsung", + }, + { + .type = "sd", + .id = 0x1c, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1d, + .manufacturer = "Corsair/AData", + }, + { + .type = "sd", + .id = 0x1e, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x1f, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x27, + .manufacturer = "Delkin/Phison", + }, + { + .type = "sd", + .id = 0x28, + .manufacturer = "Lexar", + }, + { + .type = "sd", + .id = 0x30, + .manufacturer = "SanDisk", + }, + { + .type = "sd", + .id = 0x31, + .manufacturer = "Silicon Power", + }, + { + .type = "sd", + .id = 0x33, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x41, + .manufacturer = "Kingston", + }, + { + .type = "sd", + .id = 0x6f, + .manufacturer = "STMicroelectronics", + }, + { + .type = "sd", + .id = 0x74, + .manufacturer = "Transcend", + }, + { + .type = "sd", + .id = 0x76, + .manufacturer = "Patriot", + }, + { + .type = "sd", + .id = 0x82, + .manufacturer = "Gobe/Sony", + }, + { + .type = "sd", + .id = 0x89, + .manufacturer = "Unknown", + } +}; + +/* Parse SD Card Manufacturer Database */ +string SDCardParseManufacturerIDs(int id) +{ + unsigned int id_cnt = sizeof(database) / sizeof(struct SDCard_Manufacturer_database); + string ret_val = ""; + + for (int i = 0; i < id_cnt; i++) { + if (database[i].id == id) { + return database[i].manufacturer; + } + else { + ret_val = "ID unknown (not in DB)"; + } + } + return ret_val; +} + diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index a84fe8d1..b530f446 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -2,7 +2,7 @@ #include #include #include - +#include "sdmmc_cmd.h" using namespace std; @@ -47,3 +47,13 @@ size_t getESPHeapSize(); string getESPHeapInfo(); ///////////////////////////// +string getSDCardPartitionSize(); +string getSDCardFreeParitionSpace(); +string getSDCardParitionAllocationSize(); + +void SaveSDCardInfo(sdmmc_card_t* card); +string SDCardParseManufacturerIDs(int); +string getSDCardManufacturer(); +string getSDCardName(); +string getSDCardCapacity(); +string getSDCardSectorSize(); diff --git a/code/main/main.cpp b/code/main/main.cpp index 01be3146..5436c7c6 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -112,6 +112,7 @@ bool Init_NVS_SDCard() return false; } sdmmc_card_print_info(stdout, card); + SaveSDCardInfo(card); return true; } diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index d60b2aa1..555089ee 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -17,6 +17,8 @@ #include "esp_log.h" +#include "helper.h" + //#define DEBUG_DETAIL_ON @@ -136,6 +138,71 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } + if (_task.compare("SDCardPartitionSize") == 0) + { + std::string zw; + zw = getSDCardPartitionSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardFreeParitionSpace") == 0) + { + std::string zw; + zw = getSDCardFreeParitionSpace(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardPartitionSectorSize") == 0) + { + std::string zw; + zw = getSDCardParitionAllocationSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardManufacturer") == 0) + { + std::string zw; + zw = getSDCardManufacturer(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardName") == 0) + { + std::string zw; + zw = getSDCardName(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardCapacity") == 0) + { + std::string zw; + zw = getSDCardCapacity(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + if (_task.compare("SDCardSectorSize") == 0) + { + std::string zw; + zw = getSDCardSectorSize(); + httpd_resp_sendstr_chunk(req, zw.c_str()); + httpd_resp_sendstr_chunk(req, NULL); + return ESP_OK; + } + + + return ESP_OK; } diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 2ad7c351..ffcfad3c 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -77,6 +77,84 @@ div {
+ + +

SD Card Info

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ SD Card Manufacturer: + +
+ +
+
+ SD Card Name: + +
+ +
+
+ SD Card Size [MB]: + +
+ +
+
+ SD Card Sector Size [byte]: + +
+ +
+
+ Partition Size [MB]: + +
+ +
+
+ Partition Free Space [MB]: + +
+ +
+
+ Partition Allocation Size [byte]: + +
+ +
+
+ + +

Version Info

From 4150c31b984c71d5de99f2edcf98c7cfe403b425 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 13:17:02 +0200 Subject: [PATCH 31/44] Add SD Card Info to info.html --- code/components/jomjol_helper/Helper.cpp | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 57f97950..334444dd 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -152,28 +152,6 @@ string getSDCardSectorSize(){ return std::to_string(SDCardSectorSize); } -/* - int SDCardManu = card->cid.mfg_id; - printf("SD Manu: %s\n", std::to_string(SDCardManu).c_str()); - - printf("SD Manu (ASCII): %s\n", SDCardParseManufacturerIDs(card->cid.mfg_id).c_str()); - - int SDCardOEM = card->cid.oem_id; - printf("SD OEM: %s\n", std::to_string(SDCardOEM).c_str()); - - int SDCardRev = card->cid.revision; - printf("SD Rev: %s\n", std::to_string(SDCardRev).c_str()); - - char *SDCardName = card->cid.name; - printf("SD Name: %s\n", SDCardName); - - int SDCardCSize = card->csd.sector_size; - printf("SD C-Size: %s\n", std::to_string(SDCardCSize).c_str()); - - int SDCardCapa = card->csd.capacity / (1024/card->csd.sector_size) / 1024; // total sectors * sector size --> Byte to MB (1024*1024) - printf("SD Capa: %s\n", std::to_string(SDCardCapa).c_str()); -*/ - /////////////////////////////////////////////////////////////////////////////////////////////// void memCopyGen(uint8_t* _source, uint8_t* _target, int _size) From 2a54d9b8891d39db7d477c4708cb99f989a6dd7a Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:30:37 +0200 Subject: [PATCH 32/44] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 555089ee..abb8626d 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -156,7 +156,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardPartitionSectorSize") == 0) + if (_task.compare("SDCardParitionAllocationSize") == 0) { std::string zw; zw = getSDCardParitionAllocationSize(); From 0adfc45d36e300a054ef22a0eb5e5590b38cd3e3 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 19:35:51 +0200 Subject: [PATCH 33/44] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index ffcfad3c..4beda452 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -146,7 +146,7 @@ div { Partition Allocation Size [byte]: From 2b810ca32d77d07e8f1af66c33f497aabb311c57 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:27:21 +0200 Subject: [PATCH 34/44] Name adjustment --- code/components/jomjol_helper/Helper.cpp | 6 +++--- code/components/jomjol_helper/Helper.h | 4 ++-- code/main/server_main.cpp | 6 +++--- sd-card/html/info.html | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 334444dd..cf7b4d5e 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -92,7 +92,7 @@ string getSDCardPartitionSize(){ return std::to_string(tot_sect); } -string getSDCardFreeParitionSpace(){ +string getSDCardFreePartitionSpace(){ FATFS *fs; uint32_t fre_clust, fre_sect; @@ -105,7 +105,7 @@ string getSDCardFreeParitionSpace(){ return std::to_string(fre_sect); } -string getSDCardParitionAllocationSize(){ +string getSDCardPartitionAllocationSize(){ FATFS *fs; uint32_t fre_clust, allocation_size; @@ -113,7 +113,7 @@ string getSDCardParitionAllocationSize(){ f_getfree("0:", (DWORD *)&fre_clust, &fs); allocation_size = fs->ssize; - printf("SD Card Parition Allocation Size (bytes): %d)\n", allocation_size); + printf("SD Card Partition Allocation Size (bytes): %d)\n", allocation_size); return std::to_string(allocation_size); } diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index b530f446..8d7c2cf0 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -48,8 +48,8 @@ string getESPHeapInfo(); ///////////////////////////// string getSDCardPartitionSize(); -string getSDCardFreeParitionSpace(); -string getSDCardParitionAllocationSize(); +string getSDCardFreePartitionSpace(); +string getSDCardPartitionAllocationSize(); void SaveSDCardInfo(sdmmc_card_t* card); string SDCardParseManufacturerIDs(int); diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index abb8626d..bb519093 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -147,7 +147,7 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardFreeParitionSpace") == 0) + if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; zw = getSDCardFreeParitionSpace(); @@ -156,10 +156,10 @@ esp_err_t info_get_handler(httpd_req_t *req) return ESP_OK; } - if (_task.compare("SDCardParitionAllocationSize") == 0) + if (_task.compare("SDCardPartitionAllocationSize") == 0) { std::string zw; - zw = getSDCardParitionAllocationSize(); + zw = getSDCardPartitionAllocationSize(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 4beda452..7dbd7ee1 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -137,7 +137,7 @@ div { From dbf8e634d9a4a1242082edeff0f1c198395ec47c Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:29:32 +0200 Subject: [PATCH 35/44] Name adjustment --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index bb519093..9f679a6f 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -150,7 +150,7 @@ esp_err_t info_get_handler(httpd_req_t *req) if (_task.compare("SDCardFreePartitionSpace") == 0) { std::string zw; - zw = getSDCardFreeParitionSpace(); + zw = getSDCardFreePartitionSpace(); httpd_resp_sendstr_chunk(req, zw.c_str()); httpd_resp_sendstr_chunk(req, NULL); return ESP_OK; From d3e195df9fa590d4d08ad4a356c8e5bbc5222e90 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 20:31:17 +0200 Subject: [PATCH 36/44] Name adjustment --- sd-card/html/info.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd-card/html/info.html b/sd-card/html/info.html index 7dbd7ee1..afd87843 100644 --- a/sd-card/html/info.html +++ b/sd-card/html/info.html @@ -136,7 +136,7 @@ div { Partition Free Space [MB]: From 3a999358b90e3e497f61552950bee5e130e03c0d Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 23:14:44 +0200 Subject: [PATCH 37/44] correct case sensitivity of include --- code/main/server_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 9f679a6f..64a82e65 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -17,7 +17,7 @@ #include "esp_log.h" -#include "helper.h" +#include "Helper.h" //#define DEBUG_DETAIL_ON From f65b2850a22cc19ac075e389dd4f6387ab51f7c5 Mon Sep 17 00:00:00 2001 From: Slider0007 Date: Sat, 22 Oct 2022 23:14:44 +0200 Subject: [PATCH 38/44] correct case sensitivity of include --- code/main/server_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/code/main/server_main.cpp b/code/main/server_main.cpp index 64a82e65..b2a38307 100644 --- a/code/main/server_main.cpp +++ b/code/main/server_main.cpp @@ -16,7 +16,6 @@ #include "server_tflite.h" #include "esp_log.h" - #include "Helper.h" //#define DEBUG_DETAIL_ON From 63f28097bdb1595ad2887ac14893317f829889b8 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 09:39:16 +0200 Subject: [PATCH 39/44] Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 349247e8..fcc445ac 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ - added `/graph.html` to fetch measurements from the debug log and display them as a graph. Activate debug logging for this feature to work. - Added PreValue to `/json` ([#1154](https://github.com/jomjol/AI-on-the-edge-device/issues/1154)) - Show graph of values direct in the user interface (thanks to [@rdmueller](https://github.com/rdmueller)) +- SD card info into the "Info" Menue (thanks to [@Slider007]( https://github.com/Slider0007)) ### Changed From 3743ac18f58e88a1d9a784b79d0123121eab4aca Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 12:36:09 +0200 Subject: [PATCH 40/44] Implement direct data logging --- Changelog.md | 5 +++++ code/components/jomjol_helper/Helper.cpp | 7 +++---- .../components/jomjol_logfile/ClassLogFile.cpp | 18 ++++++++++++------ code/components/jomjol_logfile/ClassLogFile.h | 2 ++ code/main/main.cpp | 13 ++++++++++++- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Changelog.md b/Changelog.md index fcc445ac..691cbfbd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,11 @@ - Added PreValue to `/json` ([#1154](https://github.com/jomjol/AI-on-the-edge-device/issues/1154)) - Show graph of values direct in the user interface (thanks to [@rdmueller](https://github.com/rdmueller)) - SD card info into the "Info" Menue (thanks to [@Slider007]( https://github.com/Slider0007)) +- Added a logging of the values in a text table in `/log/data` - each measurement is one line + - Format: tabulator separated + - Content: time, raw-value, return-value, pre-value, error-text, cnn-digital, cnn-analog + - ATTENTION: format not fully fixed yet! + ### Changed diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index cf7b4d5e..69ef3e1d 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -230,10 +230,9 @@ 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)) - ESP_LOGD(TAG, "Problem with MakeDir: %s", _what.c_str()); +int mk_ret = mkdir(_what.c_str(), 0775); +if (mk_ret) + ESP_LOGD(TAG, "error with mkdir %s ret %d", _what.c_str(), mk_ret); } diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 4dd6882f..0d3e2b96 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -95,7 +95,7 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo); - zwtime = std::string(buffer) + ":\t"; + zwtime = std::string(buffer) + "\t"; fputs(zwtime.c_str(), pFile); fputs(_ReturnRawValue.c_str(), pFile); fputs("\t", pFile); @@ -104,11 +104,8 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV fputs(_ReturnPreValue.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); @@ -284,6 +281,17 @@ void ClassLogFile::RemoveOld() closedir(dir); } +void ClassLogFile::CreateLogDirectories() +{ + MakeDir("/sdcard/log"); + MakeDir("/sdcard/log/data"); + MakeDir("/sdcard/log/analog"); + MakeDir("/sdcard/log/digit"); + MakeDir("/sdcard/log/message"); + MakeDir("/sdcard/log/source"); +} + + ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::string _logdatapath, std::string _datafile) { logroot = _logroot; @@ -294,6 +302,4 @@ ClassLogFile::ClassLogFile(std::string _logroot, std::string _logfile, std::stri retentionInDays = 10; loglevel = 0; MakeDir("/sdcard/log/data"); - MakeDir("/sdcard/test"); - MakeDir("/test"); } diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h index c04978a2..76426db5 100644 --- a/code/components/jomjol_logfile/ClassLogFile.h +++ b/code/components/jomjol_logfile/ClassLogFile.h @@ -24,6 +24,8 @@ public: void SwitchOnOff(bool _doLogFile); void SetRetention(unsigned short _retentionInDays); + void CreateLogDirectories(); + void WriteToFile(std::string info, bool _time = true); void WriteToDedicatedFile(std::string _fn, std::string info, bool _time = true); void RemoveOld(); diff --git a/code/main/main.cpp b/code/main/main.cpp index 5436c7c6..f0a37ff8 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -111,9 +111,9 @@ bool Init_NVS_SDCard() } return false; } + sdmmc_card_print_info(stdout, card); SaveSDCardInfo(card); - return true; } @@ -167,6 +167,17 @@ extern "C" void app_main(void) CheckOTAUpdate(); + LogFile.CreateLogDirectories(); +/* + int mk_ret = mkdir("/sdcard/new_fd_mkdir", 0775); + ESP_LOGI(TAGMAIN, "mkdir ret %d", mk_ret); + mk_ret = mkdir("/sdcard/new_fd_mkdir/test", 0775); + ESP_LOGI(TAGMAIN, "mkdir ret %d", mk_ret); + MakeDir("/sdcard/test2"); + MakeDir("/sdcard/test2/intern"); +*/ + + char *ssid = NULL, *passwd = NULL, *hostname = NULL, *ip = NULL, *gateway = NULL, *netmask = NULL, *dns = NULL; LoadWlanFromFile("/sdcard/wlan.ini", ssid, passwd, hostname, ip, gateway, netmask, dns); From 6986f2186c592bd9eba8e4ac189691f525e5272c Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 13:50:02 +0200 Subject: [PATCH 41/44] Extented data logging --- Changelog.md | 2 +- .../ClassFlowPostProcessing.cpp | 21 +++++++++++++------ .../ClassFlowPostProcessing.h | 2 +- .../jomjol_logfile/ClassLogFile.cpp | 21 ++++++++----------- code/components/jomjol_logfile/ClassLogFile.h | 3 ++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Changelog.md b/Changelog.md index 691cbfbd..735ac1e7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,7 +10,7 @@ - SD card info into the "Info" Menue (thanks to [@Slider007]( https://github.com/Slider0007)) - Added a logging of the values in a text table in `/log/data` - each measurement is one line - Format: tabulator separated - - Content: time, raw-value, return-value, pre-value, error-text, cnn-digital, cnn-analog + - Content: time, name-of-number, raw-value, return-value, pre-value, change-rate, change-absolute, error-text, cnn-digital, cnn-analog - ATTENTION: format not fully fixed yet! diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 100f8895..319ca661 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -848,17 +848,26 @@ bool ClassFlowPostProcessing::doFlow(string zwtime) return true; } -void ClassFlowPostProcessing::WriteDataLog(int _analog) +void ClassFlowPostProcessing::WriteDataLog(int _index) { string analog = ""; string digital = ""; + string timezw = ""; + char buffer[80]; + struct tm* timeinfo = localtime(&NUMBERS[_index]->lastvalue); + strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo); + timezw = std::string(buffer); + if (flowAnalog) - analog = flowAnalog->getReadoutRawString(_analog); + analog = flowAnalog->getReadoutRawString(_index); if (flowDigit) - digital = flowDigit->getReadoutRawString(_analog); -// LogFile.WriteToFile(analog); - LogFile.WriteToData(NUMBERS[_analog]->ReturnRawValue, NUMBERS[_analog]->ReturnValue, NUMBERS[_analog]->ReturnPreValue, NUMBERS[_analog]->ErrorMessageText, digital, analog); - ESP_LOGD(TAG, "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()); + digital = flowDigit->getReadoutRawString(_index); + LogFile.WriteToData(timezw, NUMBERS[_index]->name, + NUMBERS[_index]->ReturnRawValue, NUMBERS[_index]->ReturnValue, NUMBERS[_index]->ReturnPreValue, + NUMBERS[_index]->ReturnRateValue, NUMBERS[_index]->ReturnChangeAbsolute, + NUMBERS[_index]->ErrorMessageText, + digital, analog); + ESP_LOGD(TAG, "WriteDataLog: %s, %s, %s, %s, %s", NUMBERS[_index]->ReturnRawValue.c_str(), NUMBERS[_index]->ReturnValue.c_str(), NUMBERS[_index]->ErrorMessageText.c_str(), digital.c_str(), analog.c_str()); } diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index 79075d01..f707f170 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -44,7 +44,7 @@ protected: void handleAnalogDigitalTransitionStart(string _decsep, string _value); std::string GetStringReadouts(general); - void WriteDataLog(int _analog); + void WriteDataLog(int _index); diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp index 0d3e2b96..82723067 100644 --- a/code/components/jomjol_logfile/ClassLogFile.cpp +++ b/code/components/jomjol_logfile/ClassLogFile.cpp @@ -62,7 +62,7 @@ std::string ClassLogFile::getESPHeapInfo(){ return espInfoResultStr; } -void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog) +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\n"); time_t rawtime; @@ -86,23 +86,20 @@ void ClassLogFile::WriteToData(std::string _ReturnRawValue, std::string _ReturnV 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) + "\t"; - fputs(zwtime.c_str(), pFile); + fputs(_timestamp.c_str(), pFile); + fputs("\t", pFile); + fputs(_name.c_str(), pFile); + fputs("\t", pFile); fputs(_ReturnRawValue.c_str(), pFile); fputs("\t", pFile); fputs(_ReturnValue.c_str(), pFile); fputs("\t", pFile); fputs(_ReturnPreValue.c_str(), pFile); fputs("\t", pFile); + fputs(_ReturnRateValue.c_str(), pFile); + fputs("\t", pFile); + fputs(_ReturnChangeAbsolute.c_str(), pFile); + fputs("\t", pFile); fputs(_ErrorMessageText.c_str(), pFile); fputs(_digital.c_str(), pFile); fputs(_analog.c_str(), pFile); diff --git a/code/components/jomjol_logfile/ClassLogFile.h b/code/components/jomjol_logfile/ClassLogFile.h index 76426db5..da33557f 100644 --- a/code/components/jomjol_logfile/ClassLogFile.h +++ b/code/components/jomjol_logfile/ClassLogFile.h @@ -30,7 +30,8 @@ public: void WriteToDedicatedFile(std::string _fn, std::string info, bool _time = true); void RemoveOld(); - void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); +// void WriteToData(std::string _ReturnRawValue, std::string _ReturnValue, std::string _ReturnPreValue, std::string _ErrorMessageText, std::string _digital, std::string _analog); + void 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); std::string GetCurrentFileName(); From b78929745bec650b87baf1712c9c48d35b47e5b9 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 16:12:34 +0200 Subject: [PATCH 42/44] Improve data logging --- .../ClassFlowCNNGeneral.cpp | 9 ++++-- .../ClassFlowPostProcessing.cpp | 3 ++ .../ClassFlowPostProcessing.h | 1 - code/components/jomjol_helper/Helper.cpp | 28 +++++++++++++++++++ code/components/jomjol_helper/Helper.h | 2 ++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index 82869a1c..e46078bb 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -980,17 +980,20 @@ string ClassFlowCNNGeneral::getReadoutRawString(int _analog) { if (CNNType == Analogue || CNNType == Analogue100) { - rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_float); + rt = rt + "\t" + RundeOutput(GENERAL[_analog]->ROI[i]->result_float, 1); } if (CNNType == Digital) { - rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_klasse); + if (GENERAL[_analog]->ROI[i]->result_klasse == 10) + rt = rt + "\tN"; + else + rt = rt + "\t" + RundeOutput(GENERAL[_analog]->ROI[i]->result_klasse, 0); } if ((CNNType == DoubleHyprid10) || (CNNType == Digital100)) { - rt = rt + "\t" + std::to_string(GENERAL[_analog]->ROI[i]->result_float); + rt = rt + "\t" + RundeOutput(GENERAL[_analog]->ROI[i]->result_float, 1); } } return rt; diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp index 319ca661..afe21a16 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp @@ -927,6 +927,8 @@ string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, i return NUMBERS[_number]->ReturnValue; } +/* Jetzt als globale Funktion in Helper.h + string ClassFlowPostProcessing::RundeOutput(double _in, int _anzNachkomma){ std::stringstream stream; int _zw = _in; @@ -949,6 +951,7 @@ string ClassFlowPostProcessing::RundeOutput(double _in, int _anzNachkomma){ return stream.str(); } +*/ string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue) diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h index f707f170..3c53bb82 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h +++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h @@ -34,7 +34,6 @@ protected: string ErsetzteN(string, double _prevalue); float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue); - string RundeOutput(double _in, int _anzNachkomma); void InitNUMBERS(); void handleDecimalSeparator(string _decsep, string _value); diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index 69ef3e1d..130cf69c 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #ifdef __cplusplus extern "C" { #endif @@ -695,3 +698,28 @@ string SDCardParseManufacturerIDs(int id) return ret_val; } + +string RundeOutput(double _in, int _anzNachkomma) +{ + std::stringstream stream; + int _zw = _in; +// ESP_LOGD(TAG, "AnzNachkomma: %d", _anzNachkomma); + + if (_anzNachkomma < 0) { + _anzNachkomma = 0; + } + + if (_anzNachkomma > 0) + { + stream << std::fixed << std::setprecision(_anzNachkomma) << _in; + return stream.str(); + } + else + { + stream << _zw; + } + + + return stream.str(); +} + diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h index 8d7c2cf0..9dcd333d 100644 --- a/code/components/jomjol_helper/Helper.h +++ b/code/components/jomjol_helper/Helper.h @@ -15,6 +15,8 @@ void RenameFile(string from, string to); void MakeDir(std::string _what); +string RundeOutput(double _in, int _anzNachkomma); + FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1); From 8e22bd06e9a0c696689c199e4d1805e796e70e44 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:09:05 +0200 Subject: [PATCH 43/44] Update ClassFlowCNNGeneral.cpp --- code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp index e46078bb..b1a2a559 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp @@ -976,7 +976,7 @@ string ClassFlowCNNGeneral::getReadoutRawString(int _analog) if (GENERAL[_analog]->ROI.size() == 0) return rt; - for (int i = GENERAL[_analog]->ROI.size() - 1; i >= 0; --i) + for (int i = 0; i < GENERAL[_analog]->ROI.size(); ++i) { if (CNNType == Analogue || CNNType == Analogue100) { From 716c23fed31beeed3aadbbef97a27cef726af633 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Sun, 23 Oct 2022 18:59:55 +0200 Subject: [PATCH 44/44] Update graph.html to data --- sd-card/html/graph.html | 18 ++++---- sd-card/html/graph_data.html | 82 ++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 sd-card/html/graph_data.html diff --git a/sd-card/html/graph.html b/sd-card/html/graph.html index c790b31a..d3e15026 100644 --- a/sd-card/html/graph.html +++ b/sd-card/html/graph.html @@ -26,21 +26,21 @@ console.log (hash); var d = new Date(); var options=""; for (var i=0; i<27; i++) { - var currentDate = new Date(d-i*60*60*24*1000); - var option = currentDate.getFullYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate() - options += "\n"; + var currentDate = new Date(d-i*60*60*24*1000); + var option = currentDate.getFullYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate() + options += "\n"; } document.getElementById("selector").innerHTML = options; var dateString = d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate(); if (hash!="") { - dateString = hash.substring(1); + dateString = hash.substring(1); } -fetch('/fileserver/log/message/log_'+dateString+'.txt') +fetch('/fileserver/log/data/data_'+dateString+'.txt') .then(response => { // handle the response if (response.status == 404) { - alert("no log data available for "+dateString); + alert("no log data available for "+dateString); } response.text() .then( result => { @@ -53,10 +53,10 @@ fetch('/fileserver/log/message/log_'+dateString+'.txt') var timex = 1; for (let line of lines) { - if (line.includes("PostProcessing - Raw")) { + { console.log(line); - var value = line.split(" ")[6]; - var time = line.split(" ")[0]; + var value = line.split("\t")[3]; + var time = line.split("\t")[0]; console.log("> "+time+" "+value+"\n"); if (value<1000) { trace.x.push(timex); diff --git a/sd-card/html/graph_data.html b/sd-card/html/graph_data.html new file mode 100644 index 00000000..c790b31a --- /dev/null +++ b/sd-card/html/graph_data.html @@ -0,0 +1,82 @@ + + + + + + + + +
+ + + + + + \ No newline at end of file
-
+
- +
-
+