Renaming & cleanup of some modules / functions in source code (#2265)

* Rename module tag name

* Rename server_tflite.cpp -> MainFlowControl.cpp

* Remove redundandant MQTTMainTopic function

* Update

* Remove obsolete GetMQTTMainTopic
This commit is contained in:
Slider0007
2023-03-30 21:56:45 +02:00
committed by GitHub
parent 0e3a50d0c1
commit e995d6c498
19 changed files with 84 additions and 110 deletions

View File

@@ -8,8 +8,6 @@
#include "esp_system.h"
#include "esp_event.h"
#include "server_tflite.h"
#include "esp_log.h"
#include <sys/stat.h>
@@ -22,8 +20,10 @@
#include "ClassLogFile.h"
#include "configFile.h"
#include "Helper.h"
#ifdef ENABLE_MQTT
#include "interface_mqtt.h"
#include "interface_mqtt.h"
#include "server_mqtt.h"
#endif //ENABLE_MQTT
@@ -331,7 +331,7 @@ bool GpioHandler::readConfig()
#ifdef ENABLE_MQTT
// std::string mainTopicMQTT = "";
std::string mainTopicMQTT = GetMQTTMainTopic();
std::string mainTopicMQTT = mqttServer_getMainTopic();
if (mainTopicMQTT.length() > 0)
{
mainTopicMQTT = mainTopicMQTT + "/GPIO";

View File

@@ -28,7 +28,7 @@
#include "esp_camera.h"
#include "driver/ledc.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
static const char *TAG = "CAM";

View File

@@ -36,7 +36,7 @@ extern "C" {
#include "../../include/defines.h"
#include "ClassLogFile.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "server_help.h"
#ifdef ENABLE_MQTT
@@ -74,7 +74,7 @@ static esp_err_t send_datafile(httpd_req_t *req, bool send_full_file);
esp_err_t get_numbers_file_handler(httpd_req_t *req)
{
std::string ret = tfliteflow.getNumbersName();
std::string ret = flowctrl.getNumbersName();
// ESP_LOGI(TAG, "Result get_numbers_file_handler: %s", ret.c_str());

View File

@@ -26,7 +26,7 @@
#include <sys/stat.h>
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "server_file.h"
#include "server_GPIO.h"
#ifdef ENABLE_MQTT
@@ -467,7 +467,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
{
const char* resp_str;
KillTFliteTasks();
DeleteMainFlowTask();
gpio_handler_deinit();
if (ota_update_task(fn))
{
@@ -546,7 +546,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
/*
const char* resp_str;
KillTFliteTasks();
DeleteMainFlowTask();
gpio_handler_deinit();
if (ota_update_task(fn))
{
@@ -576,7 +576,7 @@ void hard_restart()
}
void task_reboot(void *KillAutoFlow)
void task_reboot(void *DeleteMainFlow)
{
// write a reboot, to identify a reboot by purpouse
FILE* pfile = fopen("/sdcard/reboot.txt", "w");
@@ -586,8 +586,8 @@ void task_reboot(void *KillAutoFlow)
vTaskDelay(3000 / portTICK_PERIOD_MS);
if ((bool)KillAutoFlow) {
KillTFliteTasks(); // Kill autoflow task if executed in extra task, if not don't kill parent task
if ((bool)DeleteMainFlow) {
DeleteMainFlowTask(); // Kill autoflow task if executed in extra task, if not don't kill parent task
}
Camera.LightOnOff(false);

View File

@@ -1,7 +1,7 @@
#include "ClassFlowAlignment.h"
#include "ClassFlowTakeImage.h"
#include "ClassFlow.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "CRotateImage.h"
#include "esp_log.h"
@@ -256,8 +256,8 @@ bool ClassFlowAlignment::doFlow(string time)
if(References[0].alignment_algo != 3){
DrawRef(ImageTMP);
}
tfliteflow.DigitalDrawROI(ImageTMP);
tfliteflow.AnalogDrawROI(ImageTMP);
flowctrl.DigitalDrawROI(ImageTMP);
flowctrl.AnalogDrawROI(ImageTMP);
ImageTMP->writeToMemoryAsJPG((ImageData*)AlgROI, 90);
}
#endif

View File

@@ -25,10 +25,10 @@ extern "C" {
#endif //ENABLE_MQTT
#include "server_help.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "../../include/defines.h"
static const char* TAG = "CTRL";
static const char* TAG = "FLOWCTRL";
//#define DEBUG_DETAIL_ON
@@ -162,16 +162,8 @@ void ClassFlowControll::AnalogDrawROI(CImageBasis *_zw)
#ifdef ENABLE_MQTT
string ClassFlowControll::GetMQTTMainTopic()
bool ClassFlowControll::StartMQTTService()
{
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0)
return ((ClassFlowMQTT*) (FlowControll[i]))->GetMQTTMainTopic();
return "";
}
bool ClassFlowControll::StartMQTTService() {
/* Start the MQTT service */
for (int i = 0; i < FlowControll.size(); ++i) {
if (FlowControll[i]->name().compare("ClassFlowMQTT") == 0) {

View File

@@ -55,10 +55,6 @@ public:
string TranslateAktstatus(std::string _input);
#ifdef ENABLE_MQTT
string GetMQTTMainTopic();
#endif //ENABLE_MQTT
#ifdef ALGROI_LOAD_FROM_MEM_AS_JPG
void DigitalDrawROI(CImageBasis *_zw);
void AnalogDrawROI(CImageBasis *_zw);

View File

@@ -17,7 +17,8 @@ extern "C" {
#include "esp_log.h"
#include "../../include/defines.h"
static const char* TAG = "IMG";
static const char* TAG = "FLOWIMAGE";
ClassFlowImage::ClassFlowImage(const char* logTag)
{

View File

@@ -15,7 +15,7 @@
#include <time.h>
static const char* TAG = "class_flow_influxDb";
static const char* TAG = "INFLUXDB";
void ClassFlowInfluxDB::SetInitialParameter(void)
{

View File

@@ -15,7 +15,7 @@
#include <time.h>
static const char* TAG = "class_flow_influxDbv2";
static const char* TAG = "INFLUXDBV2";
void ClassFlowInfluxDBv2::SetInitialParameter(void)
{

View File

@@ -183,12 +183,6 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
}
string ClassFlowMQTT::GetMQTTMainTopic()
{
return maintopic;
}
bool ClassFlowMQTT::Start(float AutoInterval)
{
roundInterval = AutoInterval; // Minutes

View File

@@ -31,7 +31,6 @@ public:
ClassFlowMQTT(std::vector<ClassFlow*>* lfc);
ClassFlowMQTT(std::vector<ClassFlow*>* lfc, ClassFlow *_prev);
string GetMQTTMainTopic();
bool Start(float AutoInterval);
bool ReadParameter(FILE* pfile, string& aktparamgraph);

View File

@@ -15,7 +15,7 @@
// #define WIFITURNOFF
static const char* TAG = "flow_make_image";
static const char* TAG = "TAKEIMAGE";
esp_err_t ClassFlowTakeImage::camera_capture(){
string nm = namerawimage;

View File

@@ -1,4 +1,4 @@
#include "server_tflite.h"
#include "MainFlowControl.h"
#include <string>
#include <vector>
@@ -28,7 +28,7 @@
#include "psram.h"
ClassFlowControll tfliteflow;
ClassFlowControll flowctrl;
TaskHandle_t xHandletask_autodoFlow = NULL;
@@ -41,7 +41,8 @@ bool auto_isrunning = false;
int countRounds = 0;
bool isPlannedReboot = false;
static const char *TAG = "TFLITE SERVER";
static const char *TAG = "MAINCTRL";
//#define DEBUG_DETAIL_ON
@@ -75,26 +76,26 @@ int getCountFlowRounds()
esp_err_t GetJPG(std::string _filename, httpd_req_t *req)
{
return tfliteflow.GetJPGStream(_filename, req);
return flowctrl.GetJPGStream(_filename, req);
}
esp_err_t GetRawJPG(httpd_req_t *req)
{
return tfliteflow.SendRawJPG(req);
return flowctrl.SendRawJPG(req);
}
bool isSetupModusActive() {
return tfliteflow.getStatusSetupModus();
return false;
bool isSetupModusActive()
{
return flowctrl.getStatusSetupModus();
}
void KillTFliteTasks()
void DeleteMainFlowTask()
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "KillTFliteTasks: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow);
ESP_LOGD(TAG, "DeleteMainFlowTask: xHandletask_autodoFlow: %ld", (long) xHandletask_autodoFlow);
#endif
if( xHandletask_autodoFlow != NULL )
{
@@ -110,18 +111,18 @@ void KillTFliteTasks()
void doInit(void)
{
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Start tfliteflow.InitFlow(config);");
ESP_LOGD(TAG, "Start flowctrl.InitFlow(config);");
#endif
tfliteflow.InitFlow(CONFIG_FILE);
flowctrl.InitFlow(CONFIG_FILE);
#ifdef DEBUG_DETAIL_ON
ESP_LOGD(TAG, "Finished tfliteflow.InitFlow(config);");
ESP_LOGD(TAG, "Finished flowctrl.InitFlow(config);");
#endif
/* GPIO handler has to be initialized before MQTT init to ensure proper topic subscription */
gpio_handler_init();
#ifdef ENABLE_MQTT
tfliteflow.StartMQTTService();
flowctrl.StartMQTTService();
#endif //ENABLE_MQTT
}
@@ -131,7 +132,7 @@ bool doflow(void)
std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
ESP_LOGD(TAG, "doflow - start %s", zw_time.c_str());
flowisrunning = true;
tfliteflow.doFlow(zw_time);
flowctrl.doFlow(zw_time);
flowisrunning = false;
#ifdef DEBUG_DETAIL_ON
@@ -278,7 +279,7 @@ esp_err_t handler_json(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_set_type(req, "application/json");
std::string zw = tfliteflow.getJSON();
std::string zw = flowctrl.getJSON();
if (zw.length() > 0)
{
httpd_resp_send(req, zw.c_str(), zw.length());
@@ -371,7 +372,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
_intype = READOUT_TYPE_ERROR;
zw = tfliteflow.getReadoutAll(_intype);
zw = flowctrl.getReadoutAll(_intype);
ESP_LOGD(TAG, "ZW: %s", zw.c_str());
if (zw.length() > 0)
httpd_resp_send(req, zw.c_str(), zw.length());
@@ -380,7 +381,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
}
std::string *status = tfliteflow.getActStatus();
std::string *status = flowctrl.getActStatus();
string query = std::string(_query);
// ESP_LOGD(TAG, "Query: %s, query.c_str());
if (query.find("full") != std::string::npos)
@@ -398,8 +399,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
httpd_resp_sendstr_chunk(req, txt.c_str());
}
zw = tfliteflow.getReadout(_rawValue, _noerror, 0);
zw = flowctrl.getReadout(_rawValue, _noerror, 0);
if (zw.length() > 0)
httpd_resp_sendstr_chunk(req, zw.c_str());
@@ -418,11 +418,11 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
std::vector<HTMLInfo*> htmlinfodig;
htmlinfodig = tfliteflow.GetAllDigital();
htmlinfodig = flowctrl.GetAllDigital();
for (int i = 0; i < htmlinfodig.size(); ++i)
{
if (tfliteflow.GetTypeDigital() == Digital)
if (flowctrl.GetTypeDigital() == Digital)
{
if (htmlinfodig[i]->val == 10)
zw = "NaN";
@@ -453,7 +453,7 @@ esp_err_t handler_wasserzaehler(httpd_req_t *req)
txt += "<table style=\"border-spacing: 5px\"><tr style=\"text-align: center; vertical-align: top;\">\n";
std::vector<HTMLInfo*> htmlinfoana;
htmlinfoana = tfliteflow.GetAllAnalog();
htmlinfoana = flowctrl.GetAllAnalog();
for (int i = 0; i < htmlinfoana.size(); ++i)
{
std::stringstream stream;
@@ -675,7 +675,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
Camera.SetBrightnessContrastSaturation(bri, con, sat);
Camera.SetLEDIntensity(intens);
ESP_LOGD(TAG, "test_take - vor TakeImage");
std::string zw = tfliteflow.doSingleStep("[TakeImage]", _host);
std::string zw = flowctrl.doSingleStep("[TakeImage]", _host);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), zw.length());
}
@@ -690,7 +690,7 @@ esp_err_t handler_editflow(httpd_req_t *req)
// ESP_LOGD(TAG, "Parameter host: %s", _host.c_str());
// string zwzw = "Do " + _task + " start\n"; ESP_LOGD(TAG, zwzw.c_str());
std::string zw = tfliteflow.doSingleStep("[Alignment]", _host);
std::string zw = flowctrl.doSingleStep("[Alignment]", _host);
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
httpd_resp_send(req, zw.c_str(), zw.length());
}
@@ -718,7 +718,7 @@ esp_err_t handler_statusflow(httpd_req_t *req)
ESP_LOGD(TAG, "handler_statusflow: %s", req->uri);
#endif
string* zw = tfliteflow.getActStatusWithTime();
string* zw = flowctrl.getActStatusWithTime();
resp_str = zw->c_str();
httpd_resp_send(req, resp_str, HTTPD_RESP_USE_STRLEN);
@@ -848,7 +848,7 @@ esp_err_t handler_prevalue(httpd_req_t *req)
}
if (strlen(_value) == 0) { // If no value is povided --> return actual PreValue
sReturnMessage = tfliteflow.GetPrevalue(std::string(_numbersname));
sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
if (sReturnMessage.empty()) {
sReturnMessage = "E92: Numbers name not found";
@@ -860,14 +860,14 @@ esp_err_t handler_prevalue(httpd_req_t *req)
// New value is positive: Set PreValue to provided value and return value
// New value is negative and actual RAW value is a valid number: Set PreValue to RAW value and return value
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "REST API handler_prevalue called: numbersname: " + std::string(_numbersname) +
", value: " + std::string(_value));
if (!tfliteflow.UpdatePrevalue(_value, _numbersname, true)) {
", value: " + std::string(_value));
if (!flowctrl.UpdatePrevalue(_value, _numbersname, true)) {
sReturnMessage = "E93: Update request rejected. Please check device logs for more details";
httpd_resp_send(req, sReturnMessage.c_str(), sReturnMessage.length());
return ESP_FAIL;
}
sReturnMessage = tfliteflow.GetPrevalue(std::string(_numbersname));
sReturnMessage = flowctrl.GetPrevalue(std::string(_numbersname));
if (sReturnMessage.empty()) {
sReturnMessage = "E94: Numbers name not found";
@@ -894,7 +894,7 @@ void task_autodoFlow(void *pvParameter)
if (!isPlannedReboot && (esp_reset_reason() == ESP_RST_PANIC))
{
tfliteflow.setActStatus("Initialization (delayed)");
flowctrl.setActStatus("Initialization (delayed)");
//#ifdef ENABLE_MQTT
//MQTTPublish(mqttServer_getMainTopic() + "/" + "status", "Initialization (delayed)", false); // Right now, not possible -> MQTT Service is going to be started later
//#endif //ENABLE_MQTT
@@ -904,13 +904,13 @@ void task_autodoFlow(void *pvParameter)
ESP_LOGD(TAG, "task_autodoFlow: start");
doInit();
auto_isrunning = tfliteflow.isAutoStart(auto_interval);
auto_isrunning = flowctrl.isAutoStart(auto_interval);
if (isSetupModusActive())
{
auto_isrunning = false;
std::string zw_time = getCurrentTimeString(LOGFILE_TIME_FORMAT);
tfliteflow.doFlowTakeImageOnly(zw_time);
flowctrl.doFlowTakeImageOnly(zw_time);
}
while (auto_isrunning)
@@ -981,7 +981,7 @@ void task_autodoFlow(void *pvParameter)
}
void TFliteDoAutoStart()
void StartMainFlowTask()
{
BaseType_t xReturned;
@@ -998,17 +998,9 @@ void TFliteDoAutoStart()
}
#ifdef ENABLE_MQTT
std::string GetMQTTMainTopic()
void register_server_main_flow_task_uri(httpd_handle_t server)
{
return tfliteflow.GetMQTTMainTopic();
}
#endif//ENABLE_MQTT
void register_server_tflite_uri(httpd_handle_t server)
{
ESP_LOGI(TAG, "server_part_camera - Registering URI handlers");
ESP_LOGI(TAG, "server_main_flow_task - Registering URI handlers");
httpd_uri_t camuri = { };
camuri.method = HTTP_GET;

View File

@@ -1,7 +1,7 @@
#pragma once
#ifndef SERVERTFLITE_H
#define SERVERTFLITE_H
#ifndef MAINFLOWCONTROL_H
#define MAINFLOWCONTROL_H
#include <esp_log.h>
#include <string>
@@ -10,25 +10,25 @@
#include "CImageBasis.h"
#include "ClassFlowControll.h"
//#include "ClassControllCamera.h"
extern ClassFlowControll flowctrl;
extern ClassFlowControll tfliteflow;
void register_server_tflite_uri(httpd_handle_t server);
void KillTFliteTasks();
void TFliteDoAutoStart();
bool isSetupModusActive();
int getCountFlowRounds();
void register_server_main_flow_task_uri(httpd_handle_t server);
void CheckIsPlannedReboot();
bool getIsPlannedReboot();
esp_err_t GetJPG(std::string _filename, httpd_req_t *req);
esp_err_t GetRawJPG(httpd_req_t *req);
void StartMainFlowTask();
void DeleteMainFlowTask();
bool isSetupModusActive();
int getCountFlowRounds();
#ifdef ENABLE_MQTT
std::string GetMQTTMainTopic();
esp_err_t MQTTCtrlFlowStart(std::string);
esp_err_t MQTTCtrlFlowStart(std::string _topic);
#endif //ENABLE_MQTT
#endif //SERVERTFLITE_H
esp_err_t GetRawJPG(httpd_req_t *req);
esp_err_t GetJPG(std::string _filename, httpd_req_t *req);
#endif //MAINFLOWCONTROL_H

View File

@@ -5,7 +5,7 @@
#include "connect_wlan.h"
#include "mqtt_client.h"
#include "ClassLogFile.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "cJSON.h"
#include "../../include/defines.h"
@@ -366,7 +366,7 @@ bool mqtt_handler_set_prevalue(std::string _topic, char* _data, int _data_len)
if (cJSON_IsNumber(value)) { // Check if value is a number
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "handler_set_prevalue called: numbersname: " + std::string(numbersname->valuestring) +
", value: " + std::to_string(value->valuedouble));
if (tfliteflow.UpdatePrevalue(std::to_string(value->valuedouble), std::string(numbersname->valuestring), true))
if (flowctrl.UpdatePrevalue(std::to_string(value->valuedouble), std::string(numbersname->valuestring), true))
return ESP_OK;
}
else {

View File

@@ -2,6 +2,6 @@ FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
idf_component_register(SRCS ${app_sources}
INCLUDE_DIRS "."
REQUIRES jomjol_image_proc jomjol_logfile esp_http_server esp32-camera jomjol_controlcamera jomjol_flowcontroll jomjol_helper)
REQUIRES jomjol_image_proc jomjol_logfile jomjol_flowcontroll jomjol_helper)

View File

@@ -30,7 +30,7 @@
#include "read_wlanini.h"
#include "server_main.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "server_file.h"
#include "server_ota.h"
#include "time_sntp.h"
@@ -462,7 +462,7 @@ extern "C" void app_main(void)
server = start_webserver();
register_server_camera_uri(server);
register_server_tflite_uri(server);
register_server_main_flow_task_uri(server);
register_server_file_uri(server, "/sdcard");
register_server_ota_sdcard_uri(server);
#ifdef ENABLE_MQTT
@@ -482,12 +482,12 @@ extern "C" void app_main(void)
// ********************************************
if (getSystemStatus() == 0) { // No error flag is set
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Initialization completed successfully! Starting flow task ...");
TFliteDoAutoStart();
StartMainFlowTask();
}
else if (isSetSystemStatusFlag(SYSTEM_STATUS_CAM_FB_BAD) || // Non critical errors occured, we try to continue...
isSetSystemStatusFlag(SYSTEM_STATUS_NTP_BAD)) {
LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Initialization completed with errors! Starting flow task ...");
TFliteDoAutoStart();
StartMainFlowTask();
}
else { // Any other error is critical and makes running the flow impossible. Init is going to abort.
LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Initialization failed. Flow task start aborted. Loading reduced web interface...");

View File

@@ -14,7 +14,7 @@
#include "esp_wifi.h"
#include "server_tflite.h"
#include "MainFlowControl.h"
#include "esp_log.h"
#include <stdio.h>