Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate parameters #2023

Merged
merged 21 commits into from
Feb 21, 2023
8 changes: 4 additions & 4 deletions code/components/jomjol_flowcontroll/ClassFlowAlignment.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "ClassFlowAlignment.h"
#include "ClassFlowMakeImage.h"
#include "ClassFlowTakeImage.h"
#include "ClassFlow.h"
#include "server_tflite.h"

Expand Down Expand Up @@ -46,9 +46,9 @@ ClassFlowAlignment::ClassFlowAlignment(std::vector<ClassFlow*>* lfc)

for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
if (((*ListFlowControll)[i])->name().compare("ClassFlowTakeImage") == 0)
{
ImageBasis = ((ClassFlowMakeImage*) (*ListFlowControll)[i])->rawImage;
ImageBasis = ((ClassFlowTakeImage*) (*ListFlowControll)[i])->rawImage;
}
}

Expand All @@ -74,7 +74,7 @@ bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;

if (aktparamgraph.compare("[Alignment]") != 0) //Paragraph does not fit MakeImage
if (aktparamgraph.compare("[Alignment]") != 0) //Paragraph does not fit Alignment
return false;

while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
Expand Down
10 changes: 5 additions & 5 deletions code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNTy
CNNType = AutoDetect;
CNNType = _cnntype;
flowpostalignment = _flowalign;
logfileRetentionInDays = 5;
imagesRetention = 5;
}


Expand Down Expand Up @@ -324,9 +324,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
splitted = ZerlegeZeile(aktparamgraph);
if ((toUpper(splitted[0]) == "LOGIMAGELOCATION") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "ROIIMAGESLOCATION") && (splitted.size() > 1))
{
this->LogImageLocation = "/sdcard" + splitted[1];
this->imagesLocation = "/sdcard" + splitted[1];
this->isLogImage = true;
}
if ((toUpper(splitted[0]) == "LOGIMAGESELECT") && (splitted.size() > 1))
Expand All @@ -335,9 +335,9 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
isLogImageSelect = true;
}

if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "ROIIMAGESRETENTION") && (splitted.size() > 1))
{
this->logfileRetentionInDays = std::stoi(splitted[1]);
this->imagesRetention = std::stoi(splitted[1]);
}

if ((toUpper(splitted[0]) == "MODEL") && (splitted.size() > 1))
Expand Down
46 changes: 23 additions & 23 deletions code/components/jomjol_flowcontroll/ClassFlowControll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _

ESP_LOGD(TAG, "Step %s start", _stepname.c_str());

if ((_stepname.compare("[MakeImage]") == 0) || (_stepname.compare(";[MakeImage]") == 0)){
_classname = "ClassFlowMakeImage";
if ((_stepname.compare("[TakeImage]") == 0) || (_stepname.compare(";[TakeImage]") == 0)){
_classname = "ClassFlowTakeImage";
}
if ((_stepname.compare("[Alignment]") == 0) || (_stepname.compare(";[Alignment]") == 0)){
_classname = "ClassFlowAlignment";
Expand All @@ -64,7 +64,7 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _

for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare(_classname) == 0){
if (!(FlowControll[i]->name().compare("ClassFlowMakeImage") == 0)) // if it is a MakeImage, the image does not need to be included, this happens automatically with the html query.
if (!(FlowControll[i]->name().compare("ClassFlowTakeImage") == 0)) // if it is a TakeImage, the image does not need to be included, this happens automatically with the html query.
FlowControll[i]->doFlow("");
result = FlowControll[i]->getHTMLSingleStep(_host);
}
Expand All @@ -77,7 +77,7 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _

std::string ClassFlowControll::TranslateAktstatus(std::string _input)
{
if (_input.compare("ClassFlowMakeImage") == 0)
if (_input.compare("ClassFlowTakeImage") == 0)
return ("Take Image");
if (_input.compare("ClassFlowAlignment") == 0)
return ("Aligning");
Expand Down Expand Up @@ -171,7 +171,7 @@ bool ClassFlowControll::StartMQTTService() {
/* Start the MQTT service */
for (int i = 0; i < FlowControll.size(); ++i) {
if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) {
return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoIntervall);
return ((ClassFlowMQTT*) (FlowControll[i]))->Start(AutoInterval);
}
}
return false;
Expand All @@ -183,7 +183,7 @@ void ClassFlowControll::SetInitialParameter(void)
{
AutoStart = false;
SetupModeActive = false;
AutoIntervall = 10; // Minutes
AutoInterval = 10; // Minutes
flowdigit = NULL;
flowanalog = NULL;
flowpostprocessing = NULL;
Expand All @@ -193,9 +193,9 @@ void ClassFlowControll::SetInitialParameter(void)
}


bool ClassFlowControll::isAutoStart(long &_intervall)
bool ClassFlowControll::isAutoStart(long &_interval)
{
_intervall = AutoIntervall * 60 * 1000; // AutoInterval: minutes -> ms
_interval = AutoInterval * 60 * 1000; // AutoInterval: minutes -> ms
return AutoStart;
}

Expand All @@ -206,10 +206,10 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)

_type = trim(_type);

if (toUpper(_type).compare("[MAKEIMAGE]") == 0)
if (toUpper(_type).compare("[TAKEIMAGE]") == 0)
{
cfc = new ClassFlowMakeImage(&FlowControll);
flowmakeimage = (ClassFlowMakeImage*) cfc;
cfc = new ClassFlowTakeImage(&FlowControll);
flowtakeimage = (ClassFlowTakeImage*) cfc;
}
if (toUpper(_type).compare("[ALIGNMENT]") == 0)
{
Expand Down Expand Up @@ -322,13 +322,13 @@ void ClassFlowControll::setActStatus(std::string _aktstatus)
}


void ClassFlowControll::doFlowMakeImageOnly(string time)
void ClassFlowControll::doFlowTakeImageOnly(string time)
{
std::string zw_time;

for (int i = 0; i < FlowControll.size(); ++i)
{
if (FlowControll[i]->name() == "ClassFlowMakeImage") {
if (FlowControll[i]->name() == "ClassFlowTakeImage") {
zw_time = getCurrentTimeString("%H:%M:%S");
std::string flowStatus = TranslateAktstatus(FlowControll[i]->name());
aktstatus = flowStatus + " (" + zw_time + ")";
Expand Down Expand Up @@ -527,7 +527,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)


if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0) &&
(toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu MakeImage
(toUpper(aktparamgraph).compare("[SYSTEM]") != 0 && (toUpper(aktparamgraph).compare("[DATALOGGING]") != 0))) // Paragraph passt nicht zu Debug oder DataLogging
return false;

while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
Expand All @@ -541,9 +541,9 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
}
}

if ((toUpper(splitted[0]) == "INTERVALL") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "INTERVAL") && (splitted.size() > 1))
{
AutoIntervall = std::stof(splitted[1]);
AutoInterval = std::stof(splitted[1]);
}

if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1))
Expand All @@ -557,12 +557,12 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
}
}

if ((toUpper(splitted[0]) == "DATALOGRETENTIONINDAYS") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "DATAFILESRETENTION") && (splitted.size() > 1))
{
LogFile.SetDataLogRetention(std::stoi(splitted[1]));
}

if ((toUpper(splitted[0]) == "LOGFILE") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "LOGLEVEL") && (splitted.size() > 1))
{
/* matches esp_log_level_t */
if ((toUpper(splitted[1]) == "TRUE") || (toUpper(splitted[1]) == "2"))
Expand All @@ -582,20 +582,20 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
LogFile.setLogLevel(ESP_LOG_DEBUG);
}
}
if ((toUpper(splitted[0]) == "LOGFILERETENTIONINDAYS") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "LOGFILESRETENTION") && (splitted.size() > 1))
{
LogFile.SetLogFileRetention(std::stoi(splitted[1]));
}

/* TimeServer and TimeZone got already read from the config, see setupTime () */

if ((toUpper(splitted[0]) == "RSSITHREASHOLD") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "RSSITHRESHOLD") && (splitted.size() > 1))
{
if (ChangeRSSIThreashold(WLAN_CONFIG_FILE, atoi(splitted[1].c_str())))
if (ChangeRSSIThreshold(WLAN_CONFIG_FILE, atoi(splitted[1].c_str())))
{
// reboot necessary so that the new wlan.ini is also used !!!
fclose(pfile);
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new RSSITHREASHOLD ...");
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Rebooting to activate new RSSITHRESHOLD ...");
esp_restart();
hard_restart();
doReboot();
Expand Down Expand Up @@ -660,7 +660,7 @@ int ClassFlowControll::CleanTempFolder() {

esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
{
return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
return flowtakeimage != NULL ? flowtakeimage->SendRawJPG(req) : ESP_FAIL;
}


Expand Down
10 changes: 5 additions & 5 deletions code/components/jomjol_flowcontroll/ClassFlowControll.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>

#include "ClassFlow.h"
#include "ClassFlowMakeImage.h"
#include "ClassFlowTakeImage.h"
#include "ClassFlowAlignment.h"
#include "ClassFlowCNNGeneral.h"
#include "ClassFlowPostProcessing.h"
Expand All @@ -29,11 +29,11 @@ class ClassFlowControll :
ClassFlowCNNGeneral* flowanalog;
ClassFlowCNNGeneral* flowdigit;
// ClassFlowDigit* flowdigit;
ClassFlowMakeImage* flowmakeimage;
ClassFlowTakeImage* flowtakeimage;
ClassFlow* CreateClassFlow(std::string _type);

bool AutoStart;
float AutoIntervall;
float AutoInterval;
bool SetupModeActive;
void SetInitialParameter(void);
std::string aktstatus;
Expand All @@ -42,7 +42,7 @@ class ClassFlowControll :
public:
void InitFlow(std::string config);
bool doFlow(string time);
void doFlowMakeImageOnly(string time);
void doFlowTakeImageOnly(string time);
bool getStatusSetupModus(){return SetupModeActive;};
string getReadout(bool _rawvalue, bool _noerror);
string getReadoutAll(int _type);
Expand All @@ -68,7 +68,7 @@ class ClassFlowControll :

std::string doSingleStep(std::string _stepname, std::string _host);

bool isAutoStart(long &_intervall);
bool isAutoStart(long &_interval);

std::string* getActStatus();
void setActStatus(std::string _aktstatus);
Expand Down
20 changes: 10 additions & 10 deletions code/components/jomjol_flowcontroll/ClassFlowImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ ClassFlowImage::ClassFlowImage(const char* logTag)
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
this->imagesRetention = 5;
}

ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, const char* logTag) : ClassFlow(lfc)
{
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
this->imagesRetention = 5;
}

ClassFlowImage::ClassFlowImage(std::vector<ClassFlow*> * lfc, ClassFlow *_prev, const char* logTag) : ClassFlow(lfc, _prev)
{
this->logTag = logTag;
isLogImage = false;
disabled = false;
this->logfileRetentionInDays = 5;
this->imagesRetention = 5;
}


string ClassFlowImage::CreateLogFolder(string time) {
if (!isLogImage)
return "";

string logPath = LogImageLocation + "/" + time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + time.LOGFILE_TIME_FORMAT_HOUR_EXTR;
string logPath = imagesLocation + "/" + time.LOGFILE_TIME_FORMAT_DATE_EXTR + "/" + time.LOGFILE_TIME_FORMAT_HOUR_EXTR;
isLogImage = mkdir_r(logPath.c_str(), S_IRWXU) == 0;
if (!isLogImage) {
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Can't create log folder for analog images. Path " + logPath);
Expand Down Expand Up @@ -95,7 +95,7 @@ void ClassFlowImage::RemoveOldLogs()
return;

ESP_LOGD(TAG, "remove old images");
if (logfileRetentionInDays == 0) {
if (imagesRetention == 0) {
return;
}

Expand All @@ -104,25 +104,25 @@ void ClassFlowImage::RemoveOldLogs()
char cmpfilename[30];

time(&rawtime);
rawtime = addDays(rawtime, -logfileRetentionInDays + 1);
rawtime = addDays(rawtime, -1 * imagesRetention + 1);
timeinfo = localtime(&rawtime);
//ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", logfileRetentionInDays);
//ESP_LOGD(TAG, "ImagefileRetentionInDays: %d", imagesRetention);

strftime(cmpfilename, 30, LOGFILE_TIME_FORMAT, timeinfo);
//ESP_LOGD(TAG, "file name to compare: %s", cmpfilename);
string folderName = string(cmpfilename).LOGFILE_TIME_FORMAT_DATE_EXTR;

DIR *dir = opendir(LogImageLocation.c_str());
DIR *dir = opendir(imagesLocation.c_str());
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir: %s", LogImageLocation.c_str());
ESP_LOGE(TAG, "Failed to stat dir: %s", imagesLocation.c_str());
return;
}

struct dirent *entry;
int deleted = 0;
int notDeleted = 0;
while ((entry = readdir(dir)) != NULL) {
string folderPath = LogImageLocation + "/" + entry->d_name;
string folderPath = imagesLocation + "/" + entry->d_name;
if (entry->d_type == DT_DIR) {
//ESP_LOGD(TAG, "Compare %s to %s", entry->d_name, folderName.c_str());
if ((strlen(entry->d_name) == folderName.length()) && (strcmp(entry->d_name, folderName.c_str()) < 0)) {
Expand Down
4 changes: 2 additions & 2 deletions code/components/jomjol_flowcontroll/ClassFlowImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ using namespace std;
class ClassFlowImage : public ClassFlow
{
protected:
string LogImageLocation;
string imagesLocation;
bool isLogImage;
unsigned short logfileRetentionInDays;
unsigned short imagesRetention;
const char* logTag;

string CreateLogFolder(string time);
Expand Down
12 changes: 6 additions & 6 deletions code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void ClassFlowMQTT::SetInitialParameter(void)
flowpostprocessing = NULL;
user = "";
password = "";
SetRetainFlag = 0;
SetRetainFlag = false;
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
Expand Down Expand Up @@ -95,7 +95,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;

if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph does not fit MakeImage
if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph does not fit MQTT
return false;

while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
Expand All @@ -113,10 +113,10 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->uri = splitted[1];
}
if ((toUpper(splitted[0]) == "SETRETAINFLAG") && (splitted.size() > 1))
if ((toUpper(splitted[0]) == "RETAINMESSAGES") && (splitted.size() > 1))
{
if (toUpper(splitted[1]) == "TRUE") {
SetRetainFlag = 1;
SetRetainFlag = true;
setMqtt_Server_Retain(SetRetainFlag);
}
}
Expand Down Expand Up @@ -184,9 +184,9 @@ string ClassFlowMQTT::GetMQTTMainTopic()
}


bool ClassFlowMQTT::Start(float AutoIntervall)
bool ClassFlowMQTT::Start(float AutoInterval)
{
roundInterval = AutoIntervall; // Minutes
roundInterval = AutoInterval; // Minutes
keepAlive = roundInterval * 60 * 2.5; // Seconds, make sure it is greater thatn 2 rounds!

std::stringstream stream;
Expand Down
Loading