#include "esp_http_server.h"
+#include "defines.h"
#include "ClassLogFile.h"
#include "server_help.h"
+#include "interface_mqtt.h"
+#include "server_GPIO.h"
#include "Helper.h"
#include "miniz.h"
@@ -53,17 +56,17 @@ struct file_server_data {
char scratch[SCRATCH_BUFSIZE];
};
-static const char *TAG = "file_server";
+static const char *TAG_FILESERVER = "file_server";
/* Handler to redirect incoming GET request for /index.html to /
* This can be overridden by uploading file with same name */
-static esp_err_t index_html_get_handler(httpd_req_t *req)
-{
- httpd_resp_set_status(req, "307 Temporary Redirect");
- httpd_resp_set_hdr(req, "Location", "/");
- httpd_resp_send(req, NULL, 0); // Response body can be empty
- return ESP_OK;
-}
+// static esp_err_t index_html_get_handler(httpd_req_t *req)
+// {
+// httpd_resp_set_status(req, "307 Temporary Redirect");
+// httpd_resp_set_hdr(req, "Location", "/");
+// httpd_resp_send(req, NULL, 0); // Response body can be empty
+// return ESP_OK;
+// }
/* Send HTTP response with a run-time generated html consisting of
* a list of all files and folders under the requested path.
@@ -95,7 +98,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
printf("entrypath: <%s>\n", entrypath);
if (!dir) {
- ESP_LOGE(TAG, "Failed to stat dir : %s", dirpath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat dir : %s", dirpath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "Directory does not exist");
return ESP_FAIL;
@@ -115,7 +118,7 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
if (chunksize > 0){
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
return ESP_FAIL;
}
}
@@ -154,11 +157,11 @@ static esp_err_t http_resp_dir_html(httpd_req_t *req, const char *dirpath, const
strlcpy(entrypath + dirpath_len, entry->d_name, sizeof(entrypath) - dirpath_len);
printf("Entrypath: %s\n", entrypath);
if (stat(entrypath, &entry_stat) == -1) {
- ESP_LOGE(TAG, "Failed to stat %s : %s", entrytype, entry->d_name);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat %s : %s", entrytype, entry->d_name);
continue;
}
sprintf(entrysize, "%ld", entry_stat.st_size);
- ESP_LOGI(TAG, "Found %s : %s (%s bytes)", entrytype, entry->d_name, entrysize);
+ ESP_LOGI(TAG_FILESERVER, "Found %s : %s (%s bytes)", entrytype, entry->d_name, entrysize);
/* Send chunk of HTML file containing table entries with file name and size */
httpd_resp_sendstr_chunk(req, "uri);
- const char filename = 'log_current.txt';
+ const char* filename = "log_current.txt";
- printf("uri: %s, filename: %s, filepath: %s\n", req->uri, &filename, filepath);
+ printf("uri: %s, filename: %s, filepath: %s\n", req->uri, filename, filepath);
std::string currentfilename = LogFile.GetCurrentFileName();
fd = OpenFileAndWait(currentfilename.c_str(), "r");
if (!fd) {
- ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
@@ -226,8 +229,8 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
-// ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
- set_content_type_from_file(req, &filename);
+// ESP_LOGI(TAG_FILESERVER, "Sending file : %s (%ld bytes)...", &filename, file_stat.st_size);
+ set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
char *chunk = ((struct file_server_data *)req->user_ctx)->scratch;
@@ -239,7 +242,7 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
@@ -252,7 +255,7 @@ static esp_err_t logfileact_get_handler(httpd_req_t *req)
/* Close file after sending complete */
fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
+ ESP_LOGI(TAG_FILESERVER, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -284,7 +287,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
if (!filename) {
- ESP_LOGE(TAG, "Filename is too long");
+ ESP_LOGE(TAG_FILESERVER, "Filename is too long");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Filename too long");
return ESP_FAIL;
@@ -297,11 +300,11 @@ static esp_err_t download_get_handler(httpd_req_t *req)
if (buf_len > 1) {
char buf[buf_len];
if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query => %s", buf);
+ ESP_LOGI(TAG_FILESERVER, "Found URL query => %s", buf);
char param[32];
/* Get value of expected key from query string */
if (httpd_query_key_value(buf, "readonly", param, sizeof(param)) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query parameter => readonly=%s", param);
+ ESP_LOGI(TAG_FILESERVER, "Found URL query parameter => readonly=%s", param);
readonly = param && strcmp(param,"true")==0;
}
}
@@ -316,7 +319,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* If file not present on SPIFFS check if URI
* corresponds to one of the hardcoded paths */
- ESP_LOGE(TAG, "Failed to stat file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat file : %s", filepath);
/* Respond with 404 Not Found */
httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist");
return ESP_FAIL;
@@ -324,7 +327,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
fd = OpenFileAndWait(filepath, "r");
if (!fd) {
- ESP_LOGE(TAG, "Failed to read existing file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to read existing file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to read existing file");
return ESP_FAIL;
@@ -332,7 +335,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
- ESP_LOGI(TAG, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
+ ESP_LOGI(TAG_FILESERVER, "Sending file : %s (%ld bytes)...", filename, file_stat.st_size);
set_content_type_from_file(req, filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
@@ -345,7 +348,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Send the buffer contents as HTTP response chunk */
if (httpd_resp_send_chunk(req, chunk, chunksize) != ESP_OK) {
fclose(fd);
- ESP_LOGE(TAG, "File sending failed!");
+ ESP_LOGE(TAG_FILESERVER, "File sending failed!");
/* Abort sending file */
httpd_resp_sendstr_chunk(req, NULL);
/* Respond with 500 Internal Server Error */
@@ -358,7 +361,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
/* Close file after sending complete */
fclose(fd);
- ESP_LOGI(TAG, "File sending complete");
+ ESP_LOGI(TAG_FILESERVER, "File sending complete");
/* Respond with an empty chunk to signal HTTP response completion */
httpd_resp_send_chunk(req, NULL, 0);
@@ -385,13 +388,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') {
- ESP_LOGE(TAG, "Invalid filename : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "Invalid filename : %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
return ESP_FAIL;
}
if (stat(filepath, &file_stat) == 0) {
- ESP_LOGE(TAG, "File already exists : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "File already exists : %s", filepath);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File already exists");
return ESP_FAIL;
@@ -399,7 +402,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* File cannot be larger than a limit */
if (req->content_len > MAX_FILE_SIZE) {
- ESP_LOGE(TAG, "File too large : %d bytes", req->content_len);
+ ESP_LOGE(TAG_FILESERVER, "File too large : %d bytes", req->content_len);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
"File size must be less than "
@@ -411,13 +414,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fd = OpenFileAndWait(filepath, "w");
if (!fd) {
- ESP_LOGE(TAG, "Failed to create file : %s", filepath);
+ ESP_LOGE(TAG_FILESERVER, "Failed to create file : %s", filepath);
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file");
return ESP_FAIL;
}
- ESP_LOGI(TAG, "Receiving file : %s...", filename);
+ ESP_LOGI(TAG_FILESERVER, "Receiving file : %s...", filename);
/* Retrieve the pointer to scratch buffer for temporary storage */
char *buf = ((struct file_server_data *)req->user_ctx)->scratch;
@@ -429,7 +432,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
while (remaining > 0) {
- ESP_LOGI(TAG, "Remaining size : %d", remaining);
+ ESP_LOGI(TAG_FILESERVER, "Remaining size : %d", remaining);
/* Receive the file part by part into a buffer */
if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
if (received == HTTPD_SOCK_ERR_TIMEOUT) {
@@ -442,7 +445,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fclose(fd);
unlink(filepath);
- ESP_LOGE(TAG, "File reception failed!");
+ ESP_LOGE(TAG_FILESERVER, "File reception failed!");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to receive file");
return ESP_FAIL;
@@ -455,7 +458,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
fclose(fd);
unlink(filepath);
- ESP_LOGE(TAG, "File write failed!");
+ ESP_LOGE(TAG_FILESERVER, "File write failed!");
/* Respond with 500 Internal Server Error */
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to write file to storage");
return ESP_FAIL;
@@ -468,7 +471,7 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
/* Close file upon upload completion */
fclose(fd);
- ESP_LOGI(TAG, "File reception complete");
+ ESP_LOGI(TAG_FILESERVER, "File reception complete");
std::string directory = std::string(filepath);
size_t zw = directory.find("/");
@@ -496,6 +499,13 @@ static esp_err_t upload_post_handler(httpd_req_t *req)
httpd_resp_set_status(req, "303 See Other");
httpd_resp_set_hdr(req, "Location", directory.c_str());
httpd_resp_sendstr(req, "File uploaded successfully");
+
+ if (strcmp(filepath, CONFIG_FILE) == 0) {
+ printf("New config foung. Reload handler.");
+ gpio_handler_deinit();
+ MQTTdestroy();
+ }
+
return ESP_OK;
}
@@ -567,19 +577,19 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
/* Filename cannot have a trailing '/' */
if (filename[strlen(filename) - 1] == '/') {
- ESP_LOGE(TAG, "Invalid filename : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "Invalid filename : %s", filename);
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Invalid filename");
return ESP_FAIL;
}
if (stat(filepath, &file_stat) == -1) {
- ESP_LOGE(TAG, "File does not exist : %s", filename);
+ ESP_LOGE(TAG_FILESERVER, "File does not exist : %s", filename);
/* Respond with 400 Bad Request */
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST, "File does not exist");
return ESP_FAIL;
}
- ESP_LOGI(TAG, "Deleting file : %s", filename);
+ ESP_LOGI(TAG_FILESERVER, "Deleting file : %s", filename);
/* Delete file */
unlink(filepath);
@@ -623,7 +633,7 @@ void delete_all_in_directory(std::string _directory)
std::string filename;
if (!dir) {
- ESP_LOGE(TAG, "Failed to stat dir : %s", _directory.c_str());
+ ESP_LOGE(TAG_FILESERVER, "Failed to stat dir : %s", _directory.c_str());
return;
}
@@ -632,7 +642,7 @@ void delete_all_in_directory(std::string _directory)
if (!(entry->d_type == DT_DIR)){
if (strcmp("wlan.ini", entry->d_name) != 0){ // auf wlan.ini soll nicht zugegriffen werden !!!
filename = _directory + "/" + std::string(entry->d_name);
- ESP_LOGI(TAG, "Deleting file : %s", filename.c_str());
+ ESP_LOGI(TAG_FILESERVER, "Deleting file : %s", filename.c_str());
/* Delete file */
unlink(filename.c_str());
}
@@ -722,19 +732,19 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
/* Validate file storage base path */
if (!base_path) {
// if (!base_path || strcmp(base_path, "/spiffs") != 0) {
- ESP_LOGE(TAG, "File server base_path not set");
+ ESP_LOGE(TAG_FILESERVER, "File server base_path not set");
// return ESP_ERR_INVALID_ARG;
}
if (server_data) {
- ESP_LOGE(TAG, "File server already started");
+ ESP_LOGE(TAG_FILESERVER, "File server already started");
// return ESP_ERR_INVALID_STATE;
}
/* Allocate memory for server data */
server_data = (file_server_data *) calloc(1, sizeof(struct file_server_data));
if (!server_data) {
- ESP_LOGE(TAG, "Failed to allocate memory for server data");
+ ESP_LOGE(TAG_FILESERVER, "Failed to allocate memory for server data");
// return ESP_ERR_NO_MEM;
}
strlcpy(server_data->base_path, base_path,
diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp
index 6c69ae1e..39f4d7e9 100644
--- a/code/components/jomjol_fileserver_ota/server_ota.cpp
+++ b/code/components/jomjol_fileserver_ota/server_ota.cpp
@@ -12,7 +12,7 @@
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
-#include "esp_event_loop.h"
+#include "esp_event.h"
#include "esp_log.h"
#include
#include "esp_http_client.h"
@@ -28,6 +28,7 @@
#include "server_tflite.h"
#include "server_file.h"
+#include "server_GPIO.h"
#include "ClassLogFile.h"
@@ -46,6 +47,7 @@ static char ota_write_data[BUFFSIZE + 1] = { 0 };
#define OTA_URL_SIZE 256
+static const char *TAGPARTOTA = "server_ota";
static void infinite_loop(void)
@@ -60,14 +62,14 @@ static void infinite_loop(void)
-static bool ota_example_task(std::string fn)
+static bool ota_update_task(std::string fn)
{
esp_err_t err;
/* update handle : set by esp_ota_begin(), must be freed via esp_ota_end() */
esp_ota_handle_t update_handle = 0 ;
const esp_partition_t *update_partition = NULL;
- ESP_LOGI(TAGPARTOTA, "Starting OTA example");
+ ESP_LOGI(TAGPARTOTA, "Starting OTA update");
const esp_partition_t *configured = esp_ota_get_boot_partition();
const esp_partition_t *running = esp_ota_get_running_partition();
@@ -374,7 +376,9 @@ esp_err_t handler_ota_update(httpd_req_t *req)
const char* resp_str;
- if (ota_example_task(fn))
+ KillTFliteTasks();
+ gpio_handler_deinit();
+ if (ota_update_task(fn))
{
resp_str = "Firmware Update Successfull!
You can restart now.";
}
@@ -400,8 +404,6 @@ void hard_restart() {
void task_reboot(void *pvParameter)
{
-
-
while(1)
{
vTaskDelay(5000 / portTICK_PERIOD_MS);
@@ -413,12 +415,14 @@ void task_reboot(void *pvParameter)
}
void doReboot(){
- LogFile.WriteToFile("Reboot - now");
- KillTFliteTasks();
+ 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
+ gpio_handler_destroy();
vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_restart();
- hard_restart();
+ hard_restart();
}
diff --git a/code/components/jomjol_fileserver_ota/server_ota.h b/code/components/jomjol_fileserver_ota/server_ota.h
index e227d146..415e5fd9 100644
--- a/code/components/jomjol_fileserver_ota/server_ota.h
+++ b/code/components/jomjol_fileserver_ota/server_ota.h
@@ -4,8 +4,6 @@
//#include "ClassControllCamera.h"
-static const char *TAGPARTOTA = "server_ota";
-
void register_server_ota_sdcard_uri(httpd_handle_t server);
void CheckOTAUpdate();
void doReboot();
diff --git a/code/components/jomjol_flowcontroll/ClassFlow.cpp b/code/components/jomjol_flowcontroll/ClassFlow.cpp
index 3ee76cfb..ab03d72c 100644
--- a/code/components/jomjol_flowcontroll/ClassFlow.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlow.cpp
@@ -94,6 +94,23 @@ string ClassFlow::getReadout()
return string();
}
+std::string ClassFlow::GetParameterName(std::string _input)
+{
+ string _param;
+ int _pospunkt = _input.find_first_of(".");
+ if (_pospunkt > -1)
+ {
+ _param = _input.substr(_pospunkt+1, _input.length() - _pospunkt - 1);
+ }
+ else
+ {
+ _param = _input;
+ }
+// printf("Parameter: %s, Pospunkt: %d\n", _param.c_str(), _pospunkt);
+ return _param;
+}
+
+
bool ClassFlow::getNextLine(FILE* pfile, string *rt)
{
char zw[1024];
@@ -102,24 +119,23 @@ bool ClassFlow::getNextLine(FILE* pfile, string *rt)
*rt = "";
return false;
}
- fgets(zw, 1024, pfile);
- printf("%s", zw);
- if ((strlen(zw) == 0) && feof(pfile))
+ if (!fgets(zw, 1024, pfile))
{
*rt = "";
+ printf("END OF FILE\n");
return false;
}
+ printf("%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
{
- fgets(zw, 1024, pfile);
- printf("%s", zw);
- if (feof(pfile))
+ if (!fgets(zw, 1024, pfile))
{
*rt = "";
return false;
}
+ printf("%s", zw);
*rt = zw;
*rt = trim(*rt);
}
diff --git a/code/components/jomjol_flowcontroll/ClassFlow.h b/code/components/jomjol_flowcontroll/ClassFlow.h
index bcad7b4f..4df4777c 100644
--- a/code/components/jomjol_flowcontroll/ClassFlow.h
+++ b/code/components/jomjol_flowcontroll/ClassFlow.h
@@ -37,6 +37,8 @@ protected:
virtual void SetInitialParameter(void);
+ std::string GetParameterName(std::string _input);
+
bool disabled;
public:
diff --git a/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp b/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
index a23d8b42..91cf5fc6 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowAnalog.cpp
@@ -1,7 +1,7 @@
#include "ClassFlowAnalog.h"
#include
-#include
+#include
#include
#include // std::stringstream
@@ -46,9 +46,9 @@ ClassFlowAnalog::ClassFlowAnalog(std::vector* lfc) : ClassFlowImage(
}
-int ClassFlowAnalog::AnzahlROIs()
+int ClassFlowAnalog::AnzahlROIs(int _analog = 0)
{
- int zw = ROI.size();
+ int zw = ANALOG[_analog]->ROI.size();
if (extendedResolution)
zw++;
@@ -56,27 +56,27 @@ int ClassFlowAnalog::AnzahlROIs()
}
-string ClassFlowAnalog::getReadout()
+string ClassFlowAnalog::getReadout(int _analog = 0)
{
string result = "";
- if (ROI.size() == 0)
+ if (ANALOG[_analog]->ROI.size() == 0)
return result;
- float zahl = ROI[ROI.size() - 1]->result;
+ float zahl = ANALOG[_analog]->ROI[ANALOG[_analog]->ROI.size() - 1]->result;
int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
int prev = -1;
- prev = ZeigerEval(ROI[ROI.size() - 1]->result, prev);
+ prev = ZeigerEval(ANALOG[_analog]->ROI[ANALOG[_analog]->ROI.size() - 1]->result, prev);
result = std::to_string(prev);
if (extendedResolution)
result = result + std::to_string(ergebnis_nachkomma);
- for (int i = ROI.size() - 2; i >= 0; --i)
+ for (int i = ANALOG[_analog]->ROI.size() - 2; i >= 0; --i)
{
- prev = ZeigerEval(ROI[i]->result, prev);
+ prev = ZeigerEval(ANALOG[_analog]->ROI[i]->result, prev);
result = std::to_string(prev) + result;
}
@@ -153,8 +153,8 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
}
if (zerlegt.size() >= 5)
{
- roianalog* neuroi = new roianalog;
- neuroi->name = zerlegt[0];
+ analog* _analog = GetANALOG(zerlegt[0], true);
+ roianalog* neuroi = _analog->ROI[_analog->ROI.size()-1];
neuroi->posx = std::stoi(zerlegt[1]);
neuroi->posy = std::stoi(zerlegt[2]);
neuroi->deltax = std::stoi(zerlegt[3]);
@@ -162,7 +162,7 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->result = -1;
neuroi->image = NULL;
neuroi->image_org = NULL;
- ROI.push_back(neuroi);
+// ROI.push_back(neuroi);
}
if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
@@ -178,15 +178,76 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
}
}
- for (int i = 0; i < ROI.size(); ++i)
- {
- ROI[i]->image = new CImageBasis(modelxsize, modelysize, 3);
- ROI[i]->image_org = new CImageBasis(ROI[i]->deltax, ROI[i]->deltay, 3);
- }
+ for (int _ana = 0; _ana < ANALOG.size(); ++_ana)
+ for (int i = 0; i < ANALOG[_ana]->ROI.size(); ++i)
+ {
+ ANALOG[_ana]->ROI[i]->image = new CImageBasis(modelxsize, modelysize, 3);
+ ANALOG[_ana]->ROI[i]->image_org = new CImageBasis(ANALOG[_ana]->ROI[i]->deltax, ANALOG[_ana]->ROI[i]->deltay, 3);
+ }
return true;
}
+analog* ClassFlowAnalog::FindANALOG(string _name_number)
+{
+ analog *_ret = NULL;
+
+ for (int i = 0; i < ANALOG.size(); ++i)
+ {
+ if (ANALOG[i]->name == _name_number)
+ return ANALOG[i];
+ }
+
+ return NULL;
+}
+
+
+
+analog* ClassFlowAnalog::GetANALOG(string _name, bool _create = true)
+{
+ string _analog, _roi;
+ int _pospunkt = _name.find_first_of(".");
+// printf("Name: %s, Pospunkt: %d\n", _name.c_str(), _pospunkt);
+ if (_pospunkt > -1)
+ {
+ _analog = _name.substr(0, _pospunkt);
+ _roi = _name.substr(_pospunkt+1, _name.length() - _pospunkt - 1);
+ }
+ else
+ {
+ _analog = "default";
+ _roi = _name;
+ }
+
+ analog *_ret = NULL;
+
+ for (int i = 0; i < ANALOG.size(); ++i)
+ {
+ if (ANALOG[i]->name == _analog)
+ _ret = ANALOG[i];
+ }
+
+ if (!_create) // nicht gefunden und soll auch nicht erzeugt werden
+ return _ret;
+
+
+ if (_ret == NULL)
+ {
+ _ret = new analog;
+ _ret->name = _analog;
+ ANALOG.push_back(_ret);
+ }
+
+ roianalog* neuroi = new roianalog;
+ neuroi->name = _roi;
+ _ret->ROI.push_back(neuroi);
+
+ printf("GetANALOG - ANALOG %s - roi %s\n", _analog.c_str(), _roi.c_str());
+
+ return _ret;
+}
+
+
string ClassFlowAnalog::getHTMLSingleStep(string host)
{
@@ -238,16 +299,29 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
CAlignAndCutImage *caic = flowpostalignment->GetAlignAndCutImage();
- for (int i = 0; i < ROI.size(); ++i)
- {
- printf("Analog %d - Align&Cut\n", i);
-
- caic->CutAndSave(ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay, ROI[i]->image_org);
- if (SaveAllFiles) ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ROI[i]->name + ".jpg"));
+ for (int _ana = 0; _ana < ANALOG.size(); ++_ana)
+ for (int i = 0; i < ANALOG[_ana]->ROI.size(); ++i)
+ {
+ printf("Analog %d - Align&Cut\n", i);
+
+ caic->CutAndSave(ANALOG[_ana]->ROI[i]->posx, ANALOG[_ana]->ROI[i]->posy, ANALOG[_ana]->ROI[i]->deltax, ANALOG[_ana]->ROI[i]->deltay, ANALOG[_ana]->ROI[i]->image_org);
+ if (SaveAllFiles)
+ {
+ if (ANALOG[_ana]->name == "default")
+ ANALOG[_ana]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->ROI[i]->name + ".jpg"));
+ else
+ ANALOG[_ana]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->name + "_" + ANALOG[_ana]->ROI[i]->name + ".jpg"));
+ }
- ROI[i]->image_org->Resize(modelxsize, modelysize, ROI[i]->image);
- if (SaveAllFiles) ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ROI[i]->name + ".bmp"));
- }
+ ANALOG[_ana]->ROI[i]->image_org->Resize(modelxsize, modelysize, ANALOG[_ana]->ROI[i]->image);
+ if (SaveAllFiles)
+ {
+ if (ANALOG[_ana]->name == "default")
+ ANALOG[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->ROI[i]->name + ".bmp"));
+ else
+ ANALOG[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->name + "_" + ANALOG[_ana]->ROI[i]->name + ".bmp"));
+ }
+ }
return true;
}
@@ -258,13 +332,14 @@ void ClassFlowAnalog::DrawROI(CImageBasis *_zw)
int g = 255;
int b = 0;
- for (int i = 0; i < ROI.size(); ++i)
- {
- _zw->drawRect(ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay, r, g, b, 1);
- _zw->drawCircle((int) (ROI[i]->posx + ROI[i]->deltax/2), (int) (ROI[i]->posy + ROI[i]->deltay/2), (int) (ROI[i]->deltax/2), r, g, b, 2);
- _zw->drawLine((int) (ROI[i]->posx + ROI[i]->deltax/2), (int) ROI[i]->posy, (int) (ROI[i]->posx + ROI[i]->deltax/2), (int) (ROI[i]->posy + ROI[i]->deltay), r, g, b, 2);
- _zw->drawLine((int) ROI[i]->posx, (int) (ROI[i]->posy + ROI[i]->deltay/2), (int) ROI[i]->posx + ROI[i]->deltax, (int) (ROI[i]->posy + ROI[i]->deltay/2), r, g, b, 2);
- }
+ for (int _ana = 0; _ana < ANALOG.size(); ++_ana)
+ for (int i = 0; i < ANALOG[_ana]->ROI.size(); ++i)
+ {
+ _zw->drawRect(ANALOG[_ana]->ROI[i]->posx, ANALOG[_ana]->ROI[i]->posy, ANALOG[_ana]->ROI[i]->deltax, ANALOG[_ana]->ROI[i]->deltay, r, g, b, 1);
+ _zw->drawCircle((int) (ANALOG[_ana]->ROI[i]->posx + ANALOG[_ana]->ROI[i]->deltax/2), (int) (ANALOG[_ana]->ROI[i]->posy + ANALOG[_ana]->ROI[i]->deltay/2), (int) (ANALOG[_ana]->ROI[i]->deltax/2), r, g, b, 2);
+ _zw->drawLine((int) (ANALOG[_ana]->ROI[i]->posx + ANALOG[_ana]->ROI[i]->deltax/2), (int) ANALOG[_ana]->ROI[i]->posy, (int) (ANALOG[_ana]->ROI[i]->posx + ANALOG[_ana]->ROI[i]->deltax/2), (int) (ANALOG[_ana]->ROI[i]->posy + ANALOG[_ana]->ROI[i]->deltay), r, g, b, 2);
+ _zw->drawLine((int) ANALOG[_ana]->ROI[i]->posx, (int) (ANALOG[_ana]->ROI[i]->posy + ANALOG[_ana]->ROI[i]->deltay/2), (int) ANALOG[_ana]->ROI[i]->posx + ANALOG[_ana]->ROI[i]->deltax, (int) (ANALOG[_ana]->ROI[i]->posy + ANALOG[_ana]->ROI[i]->deltay/2), r, g, b, 2);
+ }
}
bool ClassFlowAnalog::doNeuralNetwork(string time)
@@ -284,43 +359,46 @@ bool ClassFlowAnalog::doNeuralNetwork(string time)
string zwcnn = "/sdcard" + cnnmodelfile;
zwcnn = FormatFileName(zwcnn);
printf(zwcnn.c_str());printf("\n");
- tflite->LoadModel(zwcnn);
+ if (!tflite->LoadModel(zwcnn)) {
+ printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str());
+ delete tflite;
+ return false;
+ }
tflite->MakeAllocate();
#endif
- for (int i = 0; i < ROI.size(); ++i)
+ for (int _ana = 0; _ana < ANALOG.size(); ++_ana)
{
- printf("Analog %d - TfLite\n", i);
- ioresize = "/sdcard/img_tmp/ra" + std::to_string(i) + ".bmp";
- ioresize = FormatFileName(ioresize);
-
-
- float f1, f2;
- f1 = 0; f2 = 0;
-
-#ifndef OHNETFLITE
-// LogFile.WriteToFile("ClassFlowAnalog::doNeuralNetwork vor CNN tflite->LoadInputImage(ioresize)");
-// tflite->LoadInputImage(ioresize);
- tflite->LoadInputImageBasis(ROI[i]->image);
- tflite->Invoke();
- if (debugdetailanalog) LogFile.WriteToFile("Nach Invoke");
-
-
- f1 = tflite->GetOutputValue(0);
- f2 = tflite->GetOutputValue(1);
-#endif
-
- float result = fmod(atan2(f1, f2) / (M_PI * 2) + 2, 1);
-// printf("Result sin, cos, ziffer: %f, %f, %f\n", f1, f2, result);
- ROI[i]->result = result * 10;
-
- printf("Result Analog%i: %f\n", i, ROI[i]->result);
-
- if (isLogImage)
+ for (int i = 0; i < ANALOG[_ana]->ROI.size(); ++i)
{
- LogImage(logPath, ROI[i]->name, &ROI[i]->result, NULL, time, ROI[i]->image_org);
+ printf("Analog %d - TfLite\n", i);
+
+ float f1, f2;
+ f1 = 0; f2 = 0;
+
+ #ifndef OHNETFLITE
+ tflite->LoadInputImageBasis(ANALOG[_ana]->ROI[i]->image);
+ tflite->Invoke();
+ if (debugdetailanalog) LogFile.WriteToFile("Nach Invoke");
+
+
+ f1 = tflite->GetOutputValue(0);
+ f2 = tflite->GetOutputValue(1);
+ #endif
+
+ float result = fmod(atan2(f1, f2) / (M_PI * 2) + 2, 1);
+ // printf("Result sin, cos, ziffer: %f, %f, %f\n", f1, f2, result);
+ ANALOG[_ana]->ROI[i]->result = result * 10;
+
+ printf("Result Analog%i: %f\n", i, ANALOG[_ana]->ROI[i]->result);
+
+ if (isLogImage)
+ {
+ LogImage(logPath, ANALOG[_ana]->ROI[i]->name, &ANALOG[_ana]->ROI[i]->result, NULL, time, ANALOG[_ana]->ROI[i]->image_org);
+ }
}
}
+
#ifndef OHNETFLITE
delete tflite;
#endif
@@ -333,18 +411,78 @@ std::vector ClassFlowAnalog::GetHTMLInfo()
{
std::vector result;
- for (int i = 0; i < ROI.size(); ++i)
- {
- HTMLInfo *zw = new HTMLInfo;
- zw->filename = ROI[i]->name + ".bmp";
- zw->filename_org = ROI[i]->name + ".jpg";
- zw->val = ROI[i]->result;
- zw->image = ROI[i]->image;
- zw->image_org = ROI[i]->image_org;
- result.push_back(zw);
- }
+ for (int _ana = 0; _ana < ANALOG.size(); ++_ana)
+ for (int i = 0; i < ANALOG[_ana]->ROI.size(); ++i)
+ {
+ if (ANALOG[_ana]->name == "default")
+ ANALOG[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->ROI[i]->name + ".bmp"));
+ else
+ ANALOG[_ana]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ANALOG[_ana]->name + "_" + ANALOG[_ana]->ROI[i]->name + ".bmp"));
+
+
+ HTMLInfo *zw = new HTMLInfo;
+ if (ANALOG[_ana]->name == "default")
+ {
+ zw->filename = ANALOG[_ana]->ROI[i]->name + ".bmp";
+ zw->filename_org = ANALOG[_ana]->ROI[i]->name + ".jpg";
+ }
+ else
+ {
+ zw->filename = ANALOG[_ana]->name + "_" + ANALOG[_ana]->ROI[i]->name + ".bmp";
+ zw->filename_org = ANALOG[_ana]->name + "_" + ANALOG[_ana]->ROI[i]->name + ".jpg";
+ }
+
+ zw->val = ANALOG[_ana]->ROI[i]->result;
+ zw->image = ANALOG[_ana]->ROI[i]->image;
+ zw->image_org = ANALOG[_ana]->ROI[i]->image_org;
+
+ result.push_back(zw);
+ }
return result;
}
+
+int ClassFlowAnalog::getAnzahlANALOG()
+{
+ return ANALOG.size();
+}
+
+string ClassFlowAnalog::getNameANALOG(int _analog)
+{
+ if (_analog < ANALOG.size())
+ return ANALOG[_analog]->name;
+
+ return "ANALOG DOES NOT EXIST";
+}
+
+analog* ClassFlowAnalog::GetANALOG(int _analog)
+{
+ if (_analog < ANALOG.size())
+ return ANALOG[_analog];
+
+ return NULL;
+}
+
+
+
+void ClassFlowAnalog::UpdateNameNumbers(std::vector *_name_numbers)
+{
+ for (int _dig = 0; _dig < ANALOG.size(); _dig++)
+ {
+ std::string _name = ANALOG[_dig]->name;
+ bool found = false;
+ for (int i = 0; i < (*_name_numbers).size(); ++i)
+ {
+ if ((*_name_numbers)[i] == _name)
+ found = true;
+ }
+ if (!found)
+ (*_name_numbers).push_back(_name);
+ }
+}
+
+
+
+
diff --git a/code/components/jomjol_flowcontroll/ClassFlowAnalog.h b/code/components/jomjol_flowcontroll/ClassFlowAnalog.h
index 08a29be7..bd9af089 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowAnalog.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowAnalog.h
@@ -10,12 +10,19 @@ struct roianalog {
string name;
};
+struct analog {
+ string name;
+ std::vector ROI;
+};
+
class ClassFlowAnalog :
public ClassFlowImage
{
protected:
- std::vector ROI;
+// std::vector ROI;
+ std::vector ANALOG;
+
string cnnmodelfile;
int modelxsize, modelysize;
int ZeigerEval(float zahl, int ziffer_vorgaenger);
@@ -24,7 +31,8 @@ protected:
ClassFlowAlignment* flowpostalignment;
- void SetInitialParameter(void);
+ void SetInitialParameter(void);
+
public:
bool extendedResolution;
@@ -34,14 +42,23 @@ public:
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
- string getReadout();
+ string getReadout(int _analog);
void DrawROI(CImageBasis *_zw);
bool doNeuralNetwork(string time);
bool doAlignAndCut(string time);
std::vector GetHTMLInfo();
- int AnzahlROIs();
+ int AnzahlROIs(int _analog);
+
+ int getAnzahlANALOG();
+ analog* GetANALOG(int _analog);
+ analog* GetANALOG(string _name, bool _create);
+ analog* FindANALOG(string _name_number);
+ string getNameANALOG(int _analog);
+
+ void UpdateNameNumbers(std::vector *_name_numbers);
+
string name(){return "ClassFlowAnalog";};
};
diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
index 7399aa23..7cc091e1 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowControll.cpp
@@ -120,6 +120,7 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
}
if (toUpper(_type).compare("[MQTT]") == 0)
cfc = new ClassFlowMQTT(&FlowControll);
+
if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
{
cfc = new ClassFlowPostProcessing(&FlowControll);
@@ -209,7 +210,7 @@ bool ClassFlowControll::doFlow(string time)
int repeat = 0;
#ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow - Start");
+ LogFile.WriteHeapInfo("ClassFlowControll::doFlow - Start");
#endif
for (int i = 0; i < FlowControll.size(); ++i)
@@ -238,7 +239,7 @@ bool ClassFlowControll::doFlow(string time)
}
#ifdef DEBUG_DETAIL_ON
- LogFile.WriteHeapInfo("ClassFlowAnalog::doFlow");
+ LogFile.WriteHeapInfo("ClassFlowControll::doFlow");
#endif
}
@@ -262,6 +263,38 @@ void ClassFlowControll::UpdateAktStatus(std::string _flow)
}
+string ClassFlowControll::getReadoutAll(int _type)
+{
+ std::vector numbers = flowpostprocessing->GetNumbers();
+ std::string out = "";
+
+ for (int i = 0; i < numbers.size(); ++i)
+ {
+ out = out + numbers[i]->name + "\t";
+ switch (_type) {
+ case READOUT_TYPE_VALUE:
+ out = out + numbers[i]->ReturnValue;
+ break;
+ case READOUT_TYPE_PREVALUE:
+ out = out + numbers[i]->ReturnPreValue;
+ break;
+ case READOUT_TYPE_RAWVALUE:
+ out = out + numbers[i]->ReturnRawValue;
+ break;
+ case READOUT_TYPE_ERROR:
+ out = out + numbers[i]->ErrorMessageText;
+ break;
+ }
+ if (i < numbers.size()-1)
+ out = out + "\r\n";
+ }
+
+// printf("OUT: %s", out.c_str());
+
+ return out;
+}
+
+
string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
{
if (flowpostprocessing)
@@ -285,17 +318,17 @@ string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = fal
return result;
}
-string ClassFlowControll::GetPrevalue()
+string ClassFlowControll::GetPrevalue(std::string _number)
{
if (flowpostprocessing)
{
- return flowpostprocessing->GetPreValue();
+ return flowpostprocessing->GetPreValue(_number);
}
return std::string();
}
-std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
+std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue, std::string _numbers)
{
float zw;
char* p;
@@ -317,7 +350,7 @@ std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
if (flowpostprocessing)
{
- flowpostprocessing->SavePreValue(zw);
+ flowpostprocessing->SetPreValue(zw, _numbers);
return _newvalue;
}
@@ -442,7 +475,7 @@ int ClassFlowControll::CleanTempFolder() {
esp_err_t ClassFlowControll::SendRawJPG(httpd_req_t *req)
{
- return flowmakeimage->SendRawJPG(req);
+ return flowmakeimage != NULL ? flowmakeimage->SendRawJPG(req) : ESP_FAIL;
}
@@ -454,6 +487,12 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
esp_err_t result = ESP_FAIL;
bool Dodelete = false;
+ if (flowalignment == NULL)
+ {
+ printf("Can't continue, flowalignment is NULL\n");
+ return ESP_FAIL;
+ }
+
if (_fn == "alg.jpg")
{
_send = flowalignment->ImageBasis;
@@ -485,7 +524,9 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
+ delete htmlinfo[i];
}
+ htmlinfo.clear();
htmlinfo = GetAllAnalog();
for (int i = 0; i < htmlinfo.size(); ++i)
@@ -500,7 +541,9 @@ esp_err_t ClassFlowControll::GetJPGStream(std::string _fn, httpd_req_t *req)
if (htmlinfo[i]->image_org)
_send = htmlinfo[i]->image_org;
}
+ delete htmlinfo[i];
}
+ htmlinfo.clear();
if (_send)
{
diff --git a/code/components/jomjol_flowcontroll/ClassFlowControll.h b/code/components/jomjol_flowcontroll/ClassFlowControll.h
index 6ef26a2c..7a21406b 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowControll.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowControll.h
@@ -11,6 +11,12 @@
#include "ClassFlowMQTT.h"
+#define READOUT_TYPE_VALUE 0
+#define READOUT_TYPE_PREVALUE 1
+#define READOUT_TYPE_RAWVALUE 2
+#define READOUT_TYPE_ERROR 3
+
+
class ClassFlowControll :
public ClassFlow
{
@@ -38,8 +44,9 @@ public:
void doFlowMakeImageOnly(string time);
bool getStatusSetupModus(){return SetupModeActive;};
string getReadout(bool _rawvalue, bool _noerror);
- string UpdatePrevalue(std::string _newvalue);
- string GetPrevalue();
+ string getReadoutAll(int _type);
+ string UpdatePrevalue(std::string _newvalue, std::string _numbers);
+ string GetPrevalue(std::string _number = "");
bool ReadParameter(FILE* pfile, string& aktparamgraph);
esp_err_t GetJPGStream(std::string _fn, httpd_req_t *req);
diff --git a/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp b/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
index 6e37cc0b..0c214a63 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowDigit.cpp
@@ -64,16 +64,16 @@ ClassFlowDigit::ClassFlowDigit(std::vector* lfc, ClassFlow *_prev) :
}
}
-string ClassFlowDigit::getReadout()
+string ClassFlowDigit::getReadout(int _digit = 0)
{
string rst = "";
- for (int i = 0; i < ROI.size(); ++i)
+ for (int i = 0; i < DIGIT[_digit]->ROI.size(); ++i)
{
- if (ROI[i]->resultklasse == 10)
+ if (DIGIT[_digit]->ROI[i]->resultklasse == 10)
rst = rst + "N";
else
- rst = rst + std::to_string(ROI[i]->resultklasse);
+ rst = rst + std::to_string(DIGIT[_digit]->ROI[i]->resultklasse);
}
return rst;
@@ -91,18 +91,11 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
printf("aktparamgraph: %s\n", aktparamgraph.c_str());
-
-/*
- if ((aktparamgraph.compare("[Digits]") != 0) && (aktparamgraph.compare(";[Digits]") != 0)) // Paragraph passt nich zu MakeImage
- return false;
-*/
-
if ((aktparamgraph.compare(0, 7, "[Digits") != 0) && (aktparamgraph.compare(0, 8, ";[Digits") != 0)) // Paragraph passt nich zu MakeImage
return false;
int _pospkt = aktparamgraph.find_first_of(".");
int _posklammerzu = aktparamgraph.find_first_of("]");
-// printf("Pos: %d, %d\n", _pospkt, _posklammerzu);
if (_pospkt > -1)
NameDigit = aktparamgraph.substr(_pospkt+1, _posklammerzu - _pospkt-1);
else
@@ -137,8 +130,8 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
}
if (zerlegt.size() >= 5)
{
- roi* neuroi = new roi;
- neuroi->name = zerlegt[0];
+ digit* _digit = GetDIGIT(zerlegt[0], true);
+ roi* neuroi = _digit->ROI[_digit->ROI.size()-1];
neuroi->posx = std::stoi(zerlegt[1]);
neuroi->posy = std::stoi(zerlegt[2]);
neuroi->deltax = std::stoi(zerlegt[3]);
@@ -146,7 +139,6 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->resultklasse = -1;
neuroi->image = NULL;
neuroi->image_org = NULL;
- ROI.push_back(neuroi);
}
if ((toUpper(zerlegt[0]) == "SAVEALLFILES") && (zerlegt.size() > 1))
@@ -157,15 +149,74 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
}
- for (int i = 0; i < ROI.size(); ++i)
- {
- ROI[i]->image = new CImageBasis(modelxsize, modelysize, 3);
- ROI[i]->image_org = new CImageBasis(ROI[i]->deltax, ROI[i]->deltay, 3);
- }
+ for (int _dig = 0; _dig < DIGIT.size(); ++_dig)
+ for (int i = 0; i < DIGIT[_dig]->ROI.size(); ++i)
+ {
+ DIGIT[_dig]->ROI[i]->image = new CImageBasis(modelxsize, modelysize, 3);
+ DIGIT[_dig]->ROI[i]->image_org = new CImageBasis(DIGIT[_dig]->ROI[i]->deltax, DIGIT[_dig]->ROI[i]->deltay, 3);
+ }
return true;
}
+digit* ClassFlowDigit::FindDIGIT(string _name_number)
+{
+ digit *_ret = NULL;
+
+ for (int i = 0; i < DIGIT.size(); ++i)
+ {
+ if (DIGIT[i]->name == _name_number)
+ return DIGIT[i];
+ }
+
+ return NULL;
+}
+
+
+digit* ClassFlowDigit::GetDIGIT(string _name, bool _create = true)
+{
+ string _digit, _roi;
+ int _pospunkt = _name.find_first_of(".");
+// printf("Name: %s, Pospunkt: %d\n", _name.c_str(), _pospunkt);
+ if (_pospunkt > -1)
+ {
+ _digit = _name.substr(0, _pospunkt);
+ _roi = _name.substr(_pospunkt+1, _name.length() - _pospunkt - 1);
+ }
+ else
+ {
+ _digit = "default";
+ _roi = _name;
+ }
+
+ digit *_ret = NULL;
+
+ for (int i = 0; i < DIGIT.size(); ++i)
+ {
+ if (DIGIT[i]->name == _digit)
+ _ret = DIGIT[i];
+ }
+
+ if (!_create) // nicht gefunden und soll auch nicht erzeugt werden, ggf. geht eine NULL zurück
+ return _ret;
+
+ if (_ret == NULL)
+ {
+ _ret = new digit;
+ _ret->name = _digit;
+ DIGIT.push_back(_ret);
+ }
+
+ roi* neuroi = new roi;
+ neuroi->name = _roi;
+ _ret->ROI.push_back(neuroi);
+
+ printf("GetDIGIT - digit %s - roi %s\n", _digit.c_str(), _roi.c_str());
+
+ return _ret;
+}
+
+
string ClassFlowDigit::getHTMLSingleStep(string host)
{
@@ -216,17 +267,32 @@ bool ClassFlowDigit::doAlignAndCut(string time)
CAlignAndCutImage *caic = flowpostalignment->GetAlignAndCutImage();
- for (int i = 0; i < ROI.size(); ++i)
+ for (int _dig = 0; _dig < DIGIT.size(); ++_dig)
{
- printf("DigitalDigit %d - Align&Cut\n", i);
-
- caic->CutAndSave(ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay, ROI[i]->image_org);
- if (SaveAllFiles) ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ROI[i]->name + ".jpg"));
+ printf("DIGIT[_dig]->ROI.size() %d\n", DIGIT[_dig]->ROI.size());
+ for (int i = 0; i < DIGIT[_dig]->ROI.size(); ++i)
+ {
+ printf("DigitalDigit %d - Align&Cut\n", i);
+
+ caic->CutAndSave(DIGIT[_dig]->ROI[i]->posx, DIGIT[_dig]->ROI[i]->posy, DIGIT[_dig]->ROI[i]->deltax, DIGIT[_dig]->ROI[i]->deltay, DIGIT[_dig]->ROI[i]->image_org);
+ if (SaveAllFiles)
+ {
+ if (DIGIT[_dig]->name == "default")
+ DIGIT[_dig]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->ROI[i]->name + ".jpg"));
+ else
+ DIGIT[_dig]->ROI[i]->image_org->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->name + "_" + DIGIT[_dig]->ROI[i]->name + ".jpg"));
+ }
- ROI[i]->image_org->Resize(modelxsize, modelysize, ROI[i]->image);
- if (SaveAllFiles) ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + ROI[i]->name + ".bmp"));
+ DIGIT[_dig]->ROI[i]->image_org->Resize(modelxsize, modelysize, DIGIT[_dig]->ROI[i]->image);
+ if (SaveAllFiles)
+ {
+ if (DIGIT[_dig]->name == "default")
+ DIGIT[_dig]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->ROI[i]->name + ".bmp"));
+ else
+ DIGIT[_dig]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->name + "_" + DIGIT[_dig]->ROI[i]->name + ".bmp"));
+ }
+ }
}
-
return true;
}
@@ -241,26 +307,32 @@ bool ClassFlowDigit::doNeuralNetwork(string time)
CTfLiteClass *tflite = new CTfLiteClass;
string zwcnn = FormatFileName("/sdcard" + cnnmodelfile);
printf(zwcnn.c_str());printf("\n");
- tflite->LoadModel(zwcnn);
+ if (!tflite->LoadModel(zwcnn)) {
+ printf("Can't read model file /sdcard%s\n", cnnmodelfile.c_str());
+ delete tflite;
+ return false;
+ }
+
tflite->MakeAllocate();
#endif
- for (int i = 0; i < ROI.size(); ++i)
- {
- printf("DigitalDigit %d - TfLite\n", i);
-
- ROI[i]->resultklasse = 0;
-#ifndef OHNETFLITE
- ROI[i]->resultklasse = tflite->GetClassFromImageBasis(ROI[i]->image);
-
-#endif
- printf("Result Digit%i: %d\n", i, ROI[i]->resultklasse);
-
- if (isLogImage)
+ for (int _dig = 0; _dig < DIGIT.size(); ++_dig)
+ for (int i = 0; i < DIGIT[_dig]->ROI.size(); ++i)
{
- LogImage(logPath, ROI[i]->name, NULL, &ROI[i]->resultklasse, time, ROI[i]->image_org);
+ printf("DigitalDigit %d - TfLite\n", i);
+
+ DIGIT[_dig]->ROI[i]->resultklasse = 0;
+ #ifndef OHNETFLITE
+ DIGIT[_dig]->ROI[i]->resultklasse = tflite->GetClassFromImageBasis(DIGIT[_dig]->ROI[i]->image);
+
+ #endif
+ printf("Result Digit%i: %d\n", i, DIGIT[_dig]->ROI[i]->resultklasse);
+
+ if (isLogImage)
+ {
+ LogImage(logPath, DIGIT[_dig]->ROI[i]->name, NULL, &DIGIT[_dig]->ROI[i]->resultklasse, time, DIGIT[_dig]->ROI[i]->image_org);
+ }
}
- }
#ifndef OHNETFLITE
delete tflite;
#endif
@@ -269,25 +341,82 @@ bool ClassFlowDigit::doNeuralNetwork(string time)
void ClassFlowDigit::DrawROI(CImageBasis *_zw)
{
- for (int i = 0; i < ROI.size(); ++i)
- _zw->drawRect(ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay, 0, 0, 255, 2);
+ for (int _dig = 0; _dig < DIGIT.size(); ++_dig)
+ for (int i = 0; i < DIGIT[_dig]->ROI.size(); ++i)
+ _zw->drawRect(DIGIT[_dig]->ROI[i]->posx, DIGIT[_dig]->ROI[i]->posy, DIGIT[_dig]->ROI[i]->deltax, DIGIT[_dig]->ROI[i]->deltay, 0, 0, (255 - _dig*100), 2);
}
std::vector ClassFlowDigit::GetHTMLInfo()
{
std::vector result;
- for (int i = 0; i < ROI.size(); ++i)
- {
- HTMLInfo *zw = new HTMLInfo;
- zw->filename = ROI[i]->name + ".bmp";
- zw->filename_org = ROI[i]->name + ".jpg";
- zw->val = ROI[i]->resultklasse;
- zw->image = ROI[i]->image;
- zw->image_org = ROI[i]->image_org;
- result.push_back(zw);
- }
+ for (int _dig = 0; _dig < DIGIT.size(); ++_dig)
+ for (int i = 0; i < DIGIT[_dig]->ROI.size(); ++i)
+ {
+ if (DIGIT[_dig]->name == "default")
+ DIGIT[_dig]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->ROI[i]->name + ".bmp"));
+ else
+ DIGIT[_dig]->ROI[i]->image->SaveToFile(FormatFileName("/sdcard/img_tmp/" + DIGIT[_dig]->name + "_" + DIGIT[_dig]->ROI[i]->name + ".bmp"));
+
+
+ HTMLInfo *zw = new HTMLInfo;
+ if (DIGIT[_dig]->name == "default")
+ {
+ zw->filename = DIGIT[_dig]->ROI[i]->name + ".bmp";
+ zw->filename_org = DIGIT[_dig]->ROI[i]->name + ".jpg";
+ }
+ else
+ {
+ zw->filename = DIGIT[_dig]->name + "_" + DIGIT[_dig]->ROI[i]->name + ".bmp";
+ zw->filename_org = DIGIT[_dig]->name + "_" + DIGIT[_dig]->ROI[i]->name + ".jpg";
+ }
+
+ zw->val = DIGIT[_dig]->ROI[i]->resultklasse;
+ zw->image = DIGIT[_dig]->ROI[i]->image;
+ zw->image_org = DIGIT[_dig]->ROI[i]->image_org;
+ result.push_back(zw);
+ }
return result;
}
+int ClassFlowDigit::getAnzahlDIGIT()
+{
+ return DIGIT.size();
+}
+
+string ClassFlowDigit::getNameDIGIT(int _digit)
+{
+ if (_digit < DIGIT.size())
+ return DIGIT[_digit]->name;
+
+ return "DIGIT DOES NOT EXIST";
+}
+
+digit* ClassFlowDigit::GetDIGIT(int _digit)
+{
+ if (_digit < DIGIT.size())
+ return DIGIT[_digit];
+
+ return NULL;
+}
+
+void ClassFlowDigit::UpdateNameNumbers(std::vector *_name_numbers)
+{
+ for (int _dig = 0; _dig < DIGIT.size(); _dig++)
+ {
+ std::string _name = DIGIT[_dig]->name;
+ bool found = false;
+ for (int i = 0; i < (*_name_numbers).size(); ++i)
+ {
+ if ((*_name_numbers)[i] == _name)
+ found = true;
+ }
+ if (!found)
+ (*_name_numbers).push_back(_name);
+ }
+}
+
+
+
+
diff --git a/code/components/jomjol_flowcontroll/ClassFlowDigit.h b/code/components/jomjol_flowcontroll/ClassFlowDigit.h
index 3af92f85..f6d98616 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowDigit.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowDigit.h
@@ -5,6 +5,8 @@
#include
+
+
struct roi {
int posx, posy, deltax, deltay;
int resultklasse;
@@ -13,11 +15,17 @@ struct roi {
roi* next;
};
+struct digit {
+ string name;
+ std::vector ROI;
+};
+
class ClassFlowDigit :
public ClassFlowImage
{
protected:
- std::vector ROI;
+// std::vector ROI;
+ std::vector DIGIT;
string cnnmodelfile;
int modelxsize, modelysize;
bool SaveAllFiles;
@@ -31,6 +39,7 @@ protected:
bool doNeuralNetwork(string time);
bool doAlignAndCut(string time);
+
void SetInitialParameter(void);
public:
@@ -40,9 +49,18 @@ public:
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
- string getReadout();
+ string getReadout(int _digit);
std::vector GetHTMLInfo();
+ int getAnzahlDIGIT();
+ digit* GetDIGIT(int _digit);
+ digit* GetDIGIT(string _name, bool _create);
+ digit* FindDIGIT(string _name_number);
+
+ string getNameDIGIT(int _digit);
+
+ void UpdateNameNumbers(std::vector *_name_numbers);
+
void DrawROI(CImageBasis *_zw);
string name(){return "ClassFlowDigit";};
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
index 1d0e4c1b..4748b0d7 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
@@ -1,6 +1,8 @@
+#include
#include "ClassFlowMQTT.h"
#include "Helper.h"
+#include "time_sntp.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
@@ -13,6 +15,11 @@ void ClassFlowMQTT::SetInitialParameter(void)
topicError = "";
topicRate = "";
topicTimeStamp = "";
+ maintopic = "";
+ mainerrortopic = "";
+
+ topicUptime = "";
+ topicFreeMem = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
@@ -21,6 +28,9 @@ void ClassFlowMQTT::SetInitialParameter(void)
previousElement = NULL;
ListFlowControll = NULL;
disabled = false;
+ MQTTenable = false;
+
+
}
@@ -88,33 +98,24 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->uri = zerlegt[1];
}
- if ((toUpper(zerlegt[0]) == "TOPIC") && (zerlegt.size() > 1))
- {
- this->topic = zerlegt[1];
- }
- if ((toUpper(zerlegt[0]) == "TOPICERROR") && (zerlegt.size() > 1))
- {
- this->topicError = zerlegt[1];
- }
- if ((toUpper(zerlegt[0]) == "TOPICRATE") && (zerlegt.size() > 1))
- {
- this->topicRate = zerlegt[1];
- }
- if ((toUpper(zerlegt[0]) == "TOPICTIMESTAMP") && (zerlegt.size() > 1))
- {
- this->topicTimeStamp = zerlegt[1];
- }
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
this->clientname = zerlegt[1];
}
+ if (((toUpper(zerlegt[0]) == "TOPIC") || (toUpper(zerlegt[0]) == "MAINTOPIC")) && (zerlegt.size() > 1))
+ {
+ maintopic = zerlegt[1];
+ }
}
- if ((uri.length() > 0) && (topic.length() > 0))
+ if (!MQTTisConnected() && (uri.length() > 0) && (maintopic.length() > 0))
{
- MQTTInit(uri, clientname, user, password, topicError, 60);
+ mainerrortopic = maintopic + "/connection";
+ MQTTInit(uri, clientname, user, password, mainerrortopic, 60);
+ MQTTPublish(mainerrortopic, "connected");
+ MQTTenable = true;
}
return true;
@@ -123,18 +124,66 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
bool ClassFlowMQTT::doFlow(string zwtime)
{
+ if (!MQTTenable)
+ return true;
+
std::string result;
std::string resulterror = "";
std::string resultrate = "";
std::string resulttimestamp = "";
string zw = "";
+ string namenumber = "";
+
+ MQTTPublish(mainerrortopic, "connected");
+ zw = maintopic + "/" + "uptime";
+ char uptimeStr[11];
+ sprintf(uptimeStr, "%ld", (long)getUpTime());
+ MQTTPublish(zw, uptimeStr);
+
+ zw = maintopic + "/" + "freeMem";
+ char freeheapmem[11];
+ sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
+ MQTTPublish(zw, freeheapmem);
+
if (flowpostprocessing)
{
- result = flowpostprocessing->getReadoutParam(false, true);
- resulterror = flowpostprocessing->getReadoutError();
- resultrate = flowpostprocessing->getReadoutRate();
- resulttimestamp = flowpostprocessing->getReadoutTimeStamp();
+ std::vector NUMBERS = flowpostprocessing->GetNumbers();
+
+ for (int i = 0; i < NUMBERS.size(); ++i)
+ {
+ result = NUMBERS[i]->ReturnValueNoError;
+ resulterror = NUMBERS[i]->ErrorMessageText;
+ resultrate = std::to_string(NUMBERS[i]->FlowRateAct);
+ resulttimestamp = NUMBERS[i]->timeStamp;
+
+ namenumber = NUMBERS[i]->name;
+ if (namenumber == "default")
+ namenumber = maintopic + "/";
+ else
+ namenumber = maintopic + "/" + namenumber + "/";
+
+ zw = namenumber + "value";
+ MQTTPublish(zw, result);
+
+ zw = namenumber + "error";
+ MQTTPublish(zw, resulterror, 1);
+
+ zw = namenumber + "rate";
+ MQTTPublish(zw, resultrate);
+
+ zw = namenumber + "timestamp";
+ MQTTPublish(zw, resulttimestamp);
+
+
+ std::string json="{\"value\":"+result;
+ json += ",\"error\":\""+resulterror;
+ json += "\",\"rate\":"+resultrate;
+ json += ",\"timestamp\":\""+resulttimestamp+"\"}";
+
+ zw = namenumber + "json";
+ MQTTPublish(zw, json);
+ }
}
else
{
@@ -149,26 +198,9 @@ bool ClassFlowMQTT::doFlow(string zwtime)
result = result + "\t" + zw;
}
}
+ MQTTPublish(topic, result);
}
- MQTTPublish(topic, result);
-
- if (topicError.length() > 0) {
- if (resulterror.length() == 0)
- {
- resulterror = " ";
- }
- MQTTPublish(topicError, resulterror, 1);
- }
-
- if (topicRate.length() > 0) {
- MQTTPublish(topicRate, resultrate);
- }
-
- if (topicTimeStamp.length() > 0) {
- MQTTPublish(topicTimeStamp, resulttimestamp);
- }
-
OldValue = result;
return true;
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
index 99035659..c79e9b13 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
@@ -9,10 +9,13 @@ class ClassFlowMQTT :
public ClassFlow
{
protected:
- std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp;
+ std::string uri, topic, topicError, clientname, topicRate, topicTimeStamp, topicUptime, topicFreeMem;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
- std::string user, password;
+ std::string user, password;
+ bool MQTTenable;
+
+ std::string maintopic, mainerrortopic;
void SetInitialParameter(void);
public:
diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
index e9d54cb0..4cb80201 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
@@ -1,8 +1,6 @@
#include "ClassFlowPostProcessing.h"
#include "Helper.h"
-#include "ClassFlowAnalog.h"
-#include "ClassFlowDigit.h"
#include "ClassFlowMakeImage.h"
#include "ClassLogFile.h"
@@ -18,130 +16,205 @@
#define PREVALUE_TIME_FORMAT_INPUT "%d-%d-%dT%d:%d:%d"
-string ClassFlowPostProcessing::GetPreValue()
+string ClassFlowPostProcessing::GetPreValue(std::string _number)
{
std::string result;
- bool isAnalog = false;
- bool isDigit = false;
+ int index = -1;
- int AnzahlAnalog = 0;
- result = RundeOutput(PreValue, -DecimalShift);
+ if (_number == "")
+ _number = "default";
- for (int i = 0; i < ListFlowControll->size(); ++i)
- {
- if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
- {
- isAnalog = true;
- AnzahlAnalog = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
- }
- if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
- {
- isDigit = true;
- }
- }
+ for (int i = 0; i < NUMBERS.size(); ++i)
+ if (NUMBERS[i]->name == _number)
+ index = i;
- if (isDigit && isAnalog)
- result = RundeOutput(PreValue, AnzahlAnalog - DecimalShift);
+// result = RundeOutput(NUMBERS[index]->PreValue, -NUMBERS[index]->DecimalShift);
+ result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->Nachkomma);
+
+// if (NUMBERS[index]->digit_roi && NUMBERS[index]->analog_roi)
+// result = RundeOutput(NUMBERS[index]->PreValue, NUMBERS[index]->AnzahlAnalog - NUMBERS[index]->DecimalShift);
return result;
}
+void ClassFlowPostProcessing::SetPreValue(float zw, string _numbers)
+{
+ for (int j = 0; j < NUMBERS.size(); ++j)
+ {
+ if (NUMBERS[j]->name == _numbers)
+ NUMBERS[j]->PreValue = zw;
+ }
+ UpdatePreValueINI = true;
+ SavePreValue();
+}
+
+
bool ClassFlowPostProcessing::LoadPreValue(void)
{
+ std::vector zerlegt;
FILE* pFile;
char zw[1024];
- string zwtime, zwvalue;
+ string zwtime, zwvalue, name;
+ bool _done = false;
+
+ UpdatePreValueINI = false; // Konvertierung ins neue Format
+
pFile = fopen(FilePreValue.c_str(), "r");
if (pFile == NULL)
return false;
fgets(zw, 1024, pFile);
- printf("%s", zw);
+ printf("Read Zeile Prevalue.ini: %s", zw);
zwtime = trim(std::string(zw));
-
- fgets(zw, 1024, pFile);
- fclose(pFile);
- printf("%s", zw);
- zwvalue = trim(std::string(zw));
- PreValue = stof(zwvalue.c_str());
-
- time_t tStart;
- int yy, month, dd, hh, mm, ss;
- struct tm whenStart;
-
- sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
- whenStart.tm_year = yy - 1900;
- whenStart.tm_mon = month - 1;
- whenStart.tm_mday = dd;
- whenStart.tm_hour = hh;
- whenStart.tm_min = mm;
- whenStart.tm_sec = ss;
- whenStart.tm_isdst = -1;
-
- lastvalue = mktime(&whenStart);
-
- time(&tStart);
- localtime(&tStart);
- double difference = difftime(tStart, lastvalue);
- difference /= 60;
- if (difference > PreValueAgeStartup)
+ if (zwtime.length() == 0)
return false;
- Value = PreValue;
- ReturnValue = to_string(Value);
- ReturnValueNoError = ReturnValue;
-
- bool isAnalog = false;
- bool isDigit = false;
- int AnzahlAnalog = 0;
-
- for (int i = 0; i < ListFlowControll->size(); ++i)
+ zerlegt = HelperZerlegeZeile(zwtime, "\t");
+ if (zerlegt.size() > 1) // neues Format
{
- if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
- isAnalog = true;
- if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
- isDigit = true;
- }
+ while ((zerlegt.size() > 1) && !_done)
+ {
+ name = trim(zerlegt[0]);
+ zwtime = trim(zerlegt[1]);
+ zwvalue = trim(zerlegt[2]);
- if (isDigit || isAnalog)
+ for (int j = 0; j < NUMBERS.size(); ++j)
+ {
+ if (NUMBERS[j]->name == name)
+ {
+ NUMBERS[j]->PreValue = stof(zwvalue.c_str());
+ NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
+
+ time_t tStart;
+ int yy, month, dd, hh, mm, ss;
+ struct tm whenStart;
+
+ sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
+ whenStart.tm_year = yy - 1900;
+ whenStart.tm_mon = month - 1;
+ whenStart.tm_mday = dd;
+ whenStart.tm_hour = hh;
+ whenStart.tm_min = mm;
+ whenStart.tm_sec = ss;
+ whenStart.tm_isdst = -1;
+
+ NUMBERS[j]->lastvalue = mktime(&whenStart);
+
+ time(&tStart);
+ localtime(&tStart);
+ double difference = difftime(tStart, NUMBERS[j]->lastvalue);
+ difference /= 60;
+ if (difference > PreValueAgeStartup)
+ {
+ NUMBERS[j]->PreValueOkay = false;
+ }
+ else
+ {
+ NUMBERS[j]->PreValueOkay = true;
+ NUMBERS[j]->Value = NUMBERS[j]->PreValue;
+ NUMBERS[j]->ReturnValue = to_string(NUMBERS[j]->Value);
+ NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
+
+ if (NUMBERS[j]->digit_roi || NUMBERS[j]->analog_roi)
+ {
+ NUMBERS[j]->ReturnValue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
+ NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
+ }
+ }
+
+ }
+ }
+
+ if (!fgets(zw, 1024, pFile))
+ _done = true;
+ else
+ {
+ printf("Read Zeile Prevalue.ini: %s", zw);
+ zerlegt = HelperZerlegeZeile(trim(std::string(zw)), "\t");
+ if (zerlegt.size() > 1)
+ {
+ name = trim(zerlegt[0]);
+ zwtime = trim(zerlegt[1]);
+ zwvalue = trim(zerlegt[2]);
+ }
+ }
+ }
+ fclose(pFile);
+ }
+ else // altes Format
{
- ReturnValue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
- ReturnValueNoError = ReturnValue;
- }
-
+ fgets(zw, 1024, pFile);
+ fclose(pFile);
+ printf("%s", zw);
+ zwvalue = trim(std::string(zw));
+ NUMBERS[0]->PreValue = stof(zwvalue.c_str());
+
+ time_t tStart;
+ int yy, month, dd, hh, mm, ss;
+ struct tm whenStart;
+
+ sscanf(zwtime.c_str(), PREVALUE_TIME_FORMAT_INPUT, &yy, &month, &dd, &hh, &mm, &ss);
+ whenStart.tm_year = yy - 1900;
+ whenStart.tm_mon = month - 1;
+ whenStart.tm_mday = dd;
+ whenStart.tm_hour = hh;
+ whenStart.tm_min = mm;
+ 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);
+
+ NUMBERS[0]->lastvalue = mktime(&whenStart);
+
+ time(&tStart);
+ localtime(&tStart);
+ double difference = difftime(tStart, NUMBERS[0]->lastvalue);
+ difference /= 60;
+ if (difference > PreValueAgeStartup)
+ return false;
+
+ NUMBERS[0]->Value = NUMBERS[0]->PreValue;
+ NUMBERS[0]->ReturnValue = to_string(NUMBERS[0]->Value);
+ NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
+
+ if (NUMBERS[0]->digit_roi || NUMBERS[0]->analog_roi)
+ {
+ NUMBERS[0]->ReturnValue = RundeOutput(NUMBERS[0]->Value, NUMBERS[0]->AnzahlAnalog - NUMBERS[0]->DecimalShift);
+ NUMBERS[0]->ReturnValueNoError = NUMBERS[0]->ReturnValue;
+ }
+
+ UpdatePreValueINI = true; // Konvertierung ins neue Format
+ SavePreValue();
+ }
+
return true;
}
-void ClassFlowPostProcessing::SavePreValue(float value, string zwtime)
+void ClassFlowPostProcessing::SavePreValue()
{
FILE* pFile;
+ string _zw;
+
+ if (!UpdatePreValueINI) // PreValues unverändert --> File muss nicht neu geschrieben werden
+ return;
pFile = fopen(FilePreValue.c_str(), "w");
- if (strlen(zwtime.c_str()) == 0)
+ for (int j = 0; j < NUMBERS.size(); ++j)
{
- time_t rawtime;
- struct tm* timeinfo;
char buffer[80];
-
- time(&rawtime);
- timeinfo = localtime(&rawtime);
-
+ struct tm* timeinfo = localtime(&NUMBERS[j]->lastvalue);
strftime(buffer, 80, PREVALUE_TIME_FORMAT_OUTPUT, timeinfo);
- timeStamp = std::string(buffer);
- }
- else
- {
- timeStamp = zwtime;
+ NUMBERS[j]->timeStamp = std::string(buffer);
+
+ _zw = NUMBERS[j]->name + "\t" + NUMBERS[j]->timeStamp + "\t" + to_string(NUMBERS[j]->PreValue) + "\n";
+ printf("Write PreValue Zeile: %s\n", _zw.c_str());
+
+ fputs(_zw.c_str(), pFile);
}
- PreValue = value;
-
- fputs(timeStamp.c_str(), pFile);
- fputs("\n", pFile);
- fputs(to_string(value).c_str(), pFile);
- fputs("\n", pFile);
+ UpdatePreValueINI = false;
fclose(pFile);
}
@@ -149,22 +222,19 @@ void ClassFlowPostProcessing::SavePreValue(float value, string zwtime)
ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc)
{
- FlowRateAct = 0;
+// FlowRateAct = 0;
PreValueUse = false;
PreValueAgeStartup = 30;
- AllowNegativeRates = false;
- MaxRateValue = 0.1;
ErrorMessage = false;
ListFlowControll = NULL;
- PreValueOkay = false;
- useMaxRateValue = false;
- checkDigitIncreaseConsistency = false;
- DecimalShift = 0;
- ErrorMessageText = "";
- timeStamp = "";
+// PreValueOkay = false;
+// DecimalShift = 0;
+// ErrorMessageText = "";
+// timeStamp = "";
FilePreValue = FormatFileName("/sdcard/config/prevalue.ini");
ListFlowControll = lfc;
flowMakeImage = NULL;
+ UpdatePreValueINI = false;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
@@ -175,10 +245,82 @@ ClassFlowPostProcessing::ClassFlowPostProcessing(std::vector* lfc)
}
}
+void ClassFlowPostProcessing::handleDecimalSeparator(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)
+ {
+ int _zwdc = 0;
+
+ try
+ {
+ _zwdc = stoi(_value);
+ }
+ catch(const std::exception& e)
+ {
+ printf("ERROR - Decimalshift is not a number: %s\n", _value.c_str());
+ }
+
+ if (_digit == "default") // erstmal auf default setzen (falls sonst nichts gesetzt)
+ NUMBERS[j]->DecimalShift = _zwdc;
+
+ if (NUMBERS[j]->name == _digit)
+ NUMBERS[j]->DecimalShift = _zwdc;
+
+ NUMBERS[j]->Nachkomma = NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift;
+ }
+}
+
+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);
+ if (_pospunkt > -1)
+ _digit = _decsep.substr(0, _pospunkt);
+ else
+ _digit = "default";
+
+ for (int j = 0; j < NUMBERS.size(); ++j)
+ {
+ float _zwdc = 1;
+
+ try
+ {
+ _zwdc = stof(_value);
+ }
+ catch(const std::exception& e)
+ {
+ 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;
+ NUMBERS[j]->MaxRateValue = _zwdc;
+ }
+ }
+}
+
bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector zerlegt;
+ int _n;
aktparamgraph = trim(aktparamgraph);
@@ -190,53 +332,148 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
if (aktparamgraph.compare("[PostProcessing]") != 0) // Paragraph passt nich zu MakeImage
return false;
+ InitNUMBERS();
+
+
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = this->ZerlegeZeile(aktparamgraph);
- if ((toUpper(zerlegt[0]) == "DECIMALSHIFT") && (zerlegt.size() > 1))
+ std::string _param = GetParameterName(zerlegt[0]);
+
+ if ((toUpper(_param) == "DECIMALSHIFT") && (zerlegt.size() > 1))
{
- DecimalShift = stoi(zerlegt[1]);
+ handleDecimalSeparator(zerlegt[0], zerlegt[1]);
+ }
+ if ((toUpper(_param) == "MAXRATEVALUE") && (zerlegt.size() > 1))
+ {
+ handleMaxRateValue(zerlegt[0], zerlegt[1]);
}
- if ((toUpper(zerlegt[0]) == "PREVALUEUSE") && (zerlegt.size() > 1))
+ if ((toUpper(_param) == "PREVALUEUSE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
{
PreValueUse = true;
}
}
- if ((toUpper(zerlegt[0]) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
+ if ((toUpper(_param) == "CHECKDIGITINCREASECONSISTENCY") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
- checkDigitIncreaseConsistency = true;
+ for (_n = 0; _n < NUMBERS.size(); ++_n)
+ NUMBERS[_n]->checkDigitIncreaseConsistency = true;
}
- if ((toUpper(zerlegt[0]) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
+ if ((toUpper(_param) == "ALLOWNEGATIVERATES") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
- AllowNegativeRates = true;
+ for (_n = 0; _n < NUMBERS.size(); ++_n)
+ NUMBERS[_n]->AllowNegativeRates = true;
}
- if ((toUpper(zerlegt[0]) == "ERRORMESSAGE") && (zerlegt.size() > 1))
+ if ((toUpper(_param) == "ERRORMESSAGE") && (zerlegt.size() > 1))
{
if (toUpper(zerlegt[1]) == "TRUE")
ErrorMessage = true;
}
- if ((toUpper(zerlegt[0]) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
+ if ((toUpper(_param) == "PREVALUEAGESTARTUP") && (zerlegt.size() > 1))
{
PreValueAgeStartup = std::stoi(zerlegt[1]);
}
- if ((toUpper(zerlegt[0]) == "MAXRATEVALUE") && (zerlegt.size() > 1))
- {
- useMaxRateValue = true;
- MaxRateValue = std::stof(zerlegt[1]);
- }
}
if (PreValueUse) {
- PreValueOkay = LoadPreValue();
+ LoadPreValue();
}
+
return true;
}
+void ClassFlowPostProcessing::InitNUMBERS()
+{
+// ClassFlowDigit* _cdigit = NULL;
+// ClassFlowAnalog* _canalog = NULL;
+ int anzDIGIT = 0;
+ int anzANALOG = 0;
+ std::vector name_numbers;
+
+ flowAnalog = NULL;
+ flowDigit = NULL;
+
+ for (int i = 0; i < ListFlowControll->size(); ++i)
+ {
+ if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
+ {
+ flowDigit = (ClassFlowDigit*) (*ListFlowControll)[i];
+ anzDIGIT = flowDigit->getAnzahlDIGIT();
+ }
+ if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
+ {
+ flowAnalog = (ClassFlowAnalog*)(*ListFlowControll)[i];
+ anzANALOG = flowAnalog->getAnzahlANALOG();
+ }
+ }
+
+ if (flowDigit)
+ flowDigit->UpdateNameNumbers(&name_numbers);
+ if (flowAnalog)
+ flowAnalog->UpdateNameNumbers(&name_numbers);
+
+ printf("Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d\n", name_numbers.size(), anzDIGIT, anzANALOG);
+
+ for (int _num = 0; _num < name_numbers.size(); ++_num)
+ {
+ NumberPost *_number = new NumberPost;
+
+ _number->name = name_numbers[_num];
+
+ _number->digit_roi = NULL;
+ if (flowDigit)
+ _number->digit_roi = flowDigit->FindDIGIT(name_numbers[_num]);
+
+ if (_number->digit_roi)
+ _number->AnzahlDigital = _number->digit_roi->ROI.size();
+ else
+ _number->AnzahlDigital = 0;
+
+ _number->analog_roi = NULL;
+ if (flowAnalog)
+ _number->analog_roi = flowAnalog->FindANALOG(name_numbers[_num]);
+
+
+ if (_number->analog_roi)
+ _number->AnzahlAnalog = _number->analog_roi->ROI.size();
+ else
+ _number->AnzahlAnalog = 0;
+
+ _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
+ _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
+ _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
+ _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
+ _number->ReturnPreValue = "";
+ _number->PreValueOkay = false;
+ _number->AllowNegativeRates = false;
+ _number->MaxRateValue = 0.1;
+ _number->useMaxRateValue = false;
+ _number->checkDigitIncreaseConsistency = false;
+ _number->PreValueOkay = false;
+ _number->useMaxRateValue = false;
+ _number->DecimalShift = 0;
+
+ _number->FlowRateAct = 0; // m3 / min
+ _number->PreValue = 0; // letzter Wert, der gut ausgelesen wurde
+ _number->Value = 0; // letzer ausgelesener Wert, inkl. Korrekturen
+ _number->ReturnRawValue = ""; // Rohwert (mit N & führenden 0)
+ _number->ReturnValue = ""; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
+ _number->ReturnValueNoError = ""; // korrigierter Rückgabewert ohne Fehlermeldung
+ _number->ErrorMessageText = ""; // Fehlermeldung bei Consistency Check
+
+ _number->Nachkomma = _number->AnzahlAnalog;
+
+ NUMBERS.push_back(_number);
+ }
+
+ 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);
+}
+
string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift){
if (_decShift == 0){
@@ -285,173 +522,127 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
string digit = "";
string analog = "";
string zwvalue;
- bool isdigit = false;
- bool isanalog = false;
- int AnzahlAnalog = 0;
string zw;
time_t imagetime = 0;
string rohwert;
- ErrorMessageText = "";
-
-
- for (int i = 0; i < ListFlowControll->size(); ++i)
- {
- if (((*ListFlowControll)[i])->name().compare("ClassFlowMakeImage") == 0)
- {
- imagetime = ((ClassFlowMakeImage*)(*ListFlowControll)[i])->getTimeImageTaken();
- }
- if (((*ListFlowControll)[i])->name().compare("ClassFlowDigit") == 0)
- {
- isdigit = true;
- digit = (*ListFlowControll)[i]->getReadout();
- }
- if (((*ListFlowControll)[i])->name().compare("ClassFlowAnalog") == 0)
- {
- isanalog = true;
- analog = (*ListFlowControll)[i]->getReadout();
- AnzahlAnalog = ((ClassFlowAnalog*)(*ListFlowControll)[i])->AnzahlROIs();
- }
- }
+// ErrorMessageText = "";
+ imagetime = flowMakeImage->getTimeImageTaken();
if (imagetime == 0)
time(&imagetime);
struct tm* timeinfo;
timeinfo = localtime(&imagetime);
-
char strftime_buf[64];
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());
- // // TESTING ONLY////////////////////
- // isdigit = true; digit = "12N";
- // isanalog = true; analog = "456";
-
- ReturnRawValue = "";
-
- if (isdigit)
- ReturnRawValue = digit;
- if (isdigit && isanalog)
- ReturnRawValue = ReturnRawValue + ".";
- if (isanalog)
- ReturnRawValue = ReturnRawValue + analog;
-
-
- if (!isdigit)
+ for (int j = 0; j < NUMBERS.size(); ++j)
{
- AnzahlAnalog = 0;
- }
+ NUMBERS[j]->ReturnRawValue = "";
+ NUMBERS[j]->ErrorMessageText = "";
- ReturnRawValue = ShiftDecimal(ReturnRawValue, DecimalShift);
+ if (NUMBERS[j]->digit_roi)
+ NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j);
+ if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
+ NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + ".";
+ if (NUMBERS[j]->analog_roi)
+ NUMBERS[j]->ReturnRawValue = NUMBERS[j]->ReturnRawValue + flowAnalog->getReadout(j);
- rohwert = ReturnRawValue;
+ NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
- if (!PreValueUse || !PreValueOkay)
- {
- ReturnValue = ReturnRawValue;
- ReturnValueNoError = ReturnRawValue;
+ rohwert = NUMBERS[j]->ReturnRawValue;
- if ((findDelimiterPos(ReturnValue, "N") == std::string::npos) && (ReturnValue.length() > 0))
+ if (!PreValueUse || !NUMBERS[j]->PreValueOkay)
{
- while ((ReturnValue.length() > 1) && (ReturnValue[0] == '0'))
- {
- ReturnValue.erase(0, 1);
- }
- Value = std::stof(ReturnValue);
- ReturnValueNoError = ReturnValue;
+ NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
+ NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnRawValue;
- PreValueOkay = true;
- PreValue = Value;
- if (flowMakeImage)
+ if ((findDelimiterPos(NUMBERS[j]->ReturnValue, "N") == std::string::npos) && (NUMBERS[j]->ReturnValue.length() > 0))
{
- lastvalue = flowMakeImage->getTimeImageTaken();
- zwtime = ConvertTimeToString(lastvalue, PREVALUE_TIME_FORMAT_OUTPUT);
- }
- else
- {
- time(&lastvalue);
- localtime(&lastvalue);
- }
+ while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
+ {
+ NUMBERS[j]->ReturnValue.erase(0, 1);
+ }
+ NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
+ NUMBERS[j]->ReturnValueNoError = NUMBERS[j]->ReturnValue;
- SavePreValue(Value, zwtime);
+ NUMBERS[j]->PreValueOkay = true;
+ NUMBERS[j]->PreValue = NUMBERS[j]->Value;
+ NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
+ NUMBERS[j]->lastvalue = flowMakeImage->getTimeImageTaken();
+ zwtime = ConvertTimeToString(NUMBERS[j]->lastvalue, PREVALUE_TIME_FORMAT_OUTPUT);
+
+ UpdatePreValueINI = true;
+ SavePreValue();
+ }
+ }
+ else
+ {
+ zw = ErsetzteN(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->PreValue);
+
+ NUMBERS[j]->Value = std::stof(zw);
+ if (NUMBERS[j]->checkDigitIncreaseConsistency)
+ {
+ NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
+ }
+
+ zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
+
+ if ((!NUMBERS[j]->AllowNegativeRates) && (NUMBERS[j]->Value < NUMBERS[j]->PreValue))
+ {
+ NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Neg. Rate - Read: " + zwvalue + " - Raw: " + NUMBERS[j]->ReturnRawValue + " - Pre: " + std::to_string(NUMBERS[j]->Value) + " ";
+ NUMBERS[j]->Value = NUMBERS[j]->PreValue;
+ zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->AnzahlAnalog - NUMBERS[j]->DecimalShift);
+ }
+
+ if (NUMBERS[j]->useMaxRateValue && (abs(NUMBERS[j]->Value - NUMBERS[j]->PreValue) > NUMBERS[j]->MaxRateValue))
+ {
+ NUMBERS[j]->ErrorMessageText = NUMBERS[j]->ErrorMessageText + "Rate too high - Read: " + RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma) + " - Pre: " + RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
+ NUMBERS[j]->Value = NUMBERS[j]->PreValue;
+ zwvalue = RundeOutput(NUMBERS[j]->Value, NUMBERS[j]->Nachkomma);
+ }
+
+ NUMBERS[j]->ReturnValueNoError = zwvalue;
+ NUMBERS[j]->ReturnValue = zwvalue;
+ if (NUMBERS[j]->ErrorMessage && (NUMBERS[j]->ErrorMessageText.length() > 0))
+ NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnValue + "\t" + NUMBERS[j]->ErrorMessageText;
+
+
+ double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden
+ difference /= 60; // in Minuten
+ NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
+ NUMBERS[j]->lastvalue = imagetime;
+
+ if (NUMBERS[j]->ErrorMessageText.length() == 0)
+ {
+ NUMBERS[j]->PreValue = NUMBERS[j]->Value;
+ NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
+ NUMBERS[j]->ErrorMessageText = "no error";
+ UpdatePreValueINI = true;
+ }
}
- return true;
}
-
- zw = ErsetzteN(ReturnRawValue);
-
- Value = std::stof(zw);
- if (checkDigitIncreaseConsistency)
- {
- Value = checkDigitConsistency(Value, DecimalShift, isanalog);
- }
-
- zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
-
- if ((!AllowNegativeRates) && (Value < PreValue))
- {
- ErrorMessageText = ErrorMessageText + "Negative Rate - Returned old value - read value: " + zwvalue + " - raw value: " + ReturnRawValue + " - checked value: " + std::to_string(Value) + " ";
- Value = PreValue;
- zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
- }
-
- if (useMaxRateValue && (abs(Value - PreValue) > MaxRateValue))
- {
- ErrorMessageText = ErrorMessageText + "Rate too high - Returned old value - read value: " + zwvalue + " - checked value: " + RundeOutput(Value, AnzahlAnalog - DecimalShift) + " ";
- Value = PreValue;
- zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
- }
-
-
- ReturnValueNoError = zwvalue;
- ReturnValue = zwvalue;
- if (ErrorMessage && (ErrorMessageText.length() > 0))
- ReturnValue = ReturnValue + "\t" + ErrorMessageText;
-
- time_t currenttime;
- if (flowMakeImage)
- {
- currenttime = flowMakeImage->getTimeImageTaken();
- zwtime = ConvertTimeToString(currenttime, PREVALUE_TIME_FORMAT_OUTPUT);
- }
- else
- {
- time(¤ttime);
- localtime(¤ttime);
- }
-
- double difference = difftime(currenttime, lastvalue); // in Sekunden
- difference /= 60; // in Minuten
- FlowRateAct = (Value - PreValue) / difference;
- lastvalue = currenttime;
-// std::string _zw = "CalcRate: " + std::to_string(FlowRateAct) + " TimeDifference[min]: " + std::to_string(difference);
-// _zw = _zw + " Value: " + std::to_string(Value) + " PreValue: " + std::to_string(PreValue);
-// LogFile.WriteToFile(_zw);
-
- if (ErrorMessageText.length() == 0)
- {
- PreValue = Value;
- ErrorMessageText = "no error";
- SavePreValue(Value, zwtime);
- }
+ SavePreValue();
return true;
}
-string ClassFlowPostProcessing::getReadout()
+string ClassFlowPostProcessing::getReadout(int _number)
{
- return ReturnValue;
+ return NUMBERS[_number]->ReturnValue;
}
-string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror)
+string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, int _number)
{
if (_rawValue)
- return ReturnRawValue;
+ return NUMBERS[_number]->ReturnRawValue;
if (_noerror)
- return ReturnValueNoError;
- return ReturnValue;
+ return NUMBERS[_number]->ReturnValueNoError;
+ return NUMBERS[_number]->ReturnValue;
}
string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
@@ -478,7 +669,7 @@ string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
}
-string ClassFlowPostProcessing::ErsetzteN(string input)
+string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
{
int posN, posPunkt;
int pot, ziffer;
@@ -499,7 +690,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input)
pot = posPunkt - posN;
}
- zw = PreValue / pow(10, pot);
+ zw =_prevalue / pow(10, pot);
ziffer = ((int) zw) % 10;
input[posN] = ziffer + 48;
@@ -509,7 +700,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input)
return input;
}
-float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog){
+float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
int aktdigit, olddigit;
int aktdigit_before, olddigit_before;
int pot, pot_max;
@@ -527,12 +718,12 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
{
zw = input / pow(10, pot-1);
aktdigit_before = ((int) zw) % 10;
- zw = PreValue / pow(10, pot-1);
+ zw = _preValue / pow(10, pot-1);
olddigit_before = ((int) zw) % 10;
zw = input / pow(10, pot);
aktdigit = ((int) zw) % 10;
- zw = PreValue / pow(10, pot);
+ zw = _preValue / pow(10, pot);
olddigit = ((int) zw) % 10;
no_nulldurchgang = (olddigit_before <= aktdigit_before);
@@ -558,18 +749,18 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
return input;
}
-string ClassFlowPostProcessing::getReadoutRate()
+string ClassFlowPostProcessing::getReadoutRate(int _number)
{
- return std::to_string(FlowRateAct);
+ return std::to_string(NUMBERS[_number]->FlowRateAct);
}
-string ClassFlowPostProcessing::getReadoutTimeStamp()
+string ClassFlowPostProcessing::getReadoutTimeStamp(int _number)
{
- return timeStamp;
+ return NUMBERS[_number]->timeStamp;
}
-string ClassFlowPostProcessing::getReadoutError()
+string ClassFlowPostProcessing::getReadoutError(int _number)
{
- return ErrorMessageText;
+ return NUMBERS[_number]->ErrorMessageText;
}
diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
index 8a115705..48a5510e 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
@@ -1,58 +1,94 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowMakeImage.h"
+#include "ClassFlowAnalog.h"
+#include "ClassFlowDigit.h"
+
#include
+struct NumberPost {
+// int PreValueAgeStartup;
+ float MaxRateValue;
+ bool useMaxRateValue;
+ bool ErrorMessage;
+ bool PreValueOkay;
+ bool AllowNegativeRates;
+ bool checkDigitIncreaseConsistency;
+ time_t lastvalue;
+ string timeStamp;
+ float FlowRateAct; // m3 / min
+ float PreValue; // letzter Wert, der gut ausgelesen wurde
+ float Value; // letzer ausgelesener Wert, inkl. Korrekturen
+ string ReturnRawValue; // Rohwert (mit N & führenden 0)
+ string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
+ string ReturnPreValue; // korrigierter Rückgabewert ohne Fehlermeldung
+ string ReturnValueNoError;
+ string ErrorMessageText; // Fehlermeldung bei Consistency Check
+ int AnzahlAnalog;
+ int AnzahlDigital;
+ int DecimalShift;
+ int Nachkomma;
+// ClassFlowAnalog* ANALOG;
+// ClassFlowDigit* DIGIT;
+
+ digit *digit_roi;
+ analog *analog_roi;
+
+
+
+ string name;
+};
+
+
class ClassFlowPostProcessing :
public ClassFlow
{
protected:
+ std::vector NUMBERS;
+ bool UpdatePreValueINI;
+
bool PreValueUse;
int PreValueAgeStartup;
- bool AllowNegativeRates;
- float MaxRateValue;
- bool useMaxRateValue;
bool ErrorMessage;
- bool PreValueOkay;
- bool checkDigitIncreaseConsistency;
- int DecimalShift;
- time_t lastvalue;
- float FlowRateAct; // m3 / min
+
+
+ ClassFlowAnalog* flowAnalog;
+ ClassFlowDigit* flowDigit;
string FilePreValue;
- float PreValue; // letzter Wert, der gut ausgelesen wurde
- float Value; // letzer ausgelesener Wert, inkl. Korrekturen
- string ReturnRawValue; // Rohwert (mit N & führenden 0)
- string ReturnValue; // korrigierter Rückgabewert, ggf. mit Fehlermeldung
- string ReturnValueNoError; // korrigierter Rückgabewert ohne Fehlermeldung
- string ErrorMessageText; // Fehlermeldung bei Consistency Check
- string timeStamp;
ClassFlowMakeImage *flowMakeImage;
bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);
- string ErsetzteN(string);
- float checkDigitConsistency(float input, int _decilamshift, bool _isanalog);
+ string ErsetzteN(string, float _prevalue);
+ float checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue);
string RundeOutput(float _in, int _anzNachkomma);
+ void InitNUMBERS();
+ void handleDecimalSeparator(string _decsep, string _value);
+ void handleMaxRateValue(string _decsep, string _value);
+
+
public:
ClassFlowPostProcessing(std::vector* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
- string getReadout();
- string getReadoutParam(bool _rawValue, bool _noerror);
- string getReadoutError();
- string getReadoutRate();
- string getReadoutTimeStamp();
- void SavePreValue(float value, string time = "");
- string GetPreValue();
+ string getReadout(int _number);
+ string getReadoutParam(bool _rawValue, bool _noerror, int _number = 0);
+ string getReadoutError(int _number = 0);
+ string getReadoutRate(int _number = 0);
+ string getReadoutTimeStamp(int _number = 0);
+ void SavePreValue();
+ string GetPreValue(std::string _number = "");
+ void SetPreValue(float zw, string _numbers);
+ std::vector GetNumbers(){return NUMBERS;};
string name(){return "ClassFlowPostProcessing";};
};
diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp
index 0a32b30e..07f7e7e0 100644
--- a/code/components/jomjol_helper/Helper.cpp
+++ b/code/components/jomjol_helper/Helper.cpp
@@ -10,6 +10,7 @@
#include
#include
+
#include "ClassLogFile.h"
//#include "ClassLogFile.h"
@@ -77,8 +78,9 @@ void memCopyGen(uint8_t* _source, uint8_t* _target, int _size)
-FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec)
+FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec)
{
+ printf("open config file %s in mode %s\n", nm, _mode);
FILE *pfile = fopen(nm, _mode);
if (pfile == NULL)
@@ -313,6 +315,14 @@ string toUpper(string in)
return in;
}
+string toLower(string in)
+{
+ for (int i = 0; i < in.length(); ++i)
+ in[i] = tolower(in[i]);
+
+ return in;
+}
+
// CPU Temp
extern "C" uint8_t temprature_sens_read();
float temperatureRead()
@@ -358,3 +368,30 @@ int removeFolder(const char* folderPath, const char* logTag) {
return deleted;
}
+
+
+
+std::vector HelperZerlegeZeile(std::string input, std::string _delimiter = "")
+{
+ std::vector Output;
+ std::string delimiter = " =,";
+ if (_delimiter.length() > 0){
+ delimiter = _delimiter;
+ }
+
+ input = trim(input, delimiter);
+ size_t pos = findDelimiterPos(input, delimiter);
+ std::string token;
+ while (pos != std::string::npos) {
+ token = input.substr(0, pos);
+ token = trim(token, delimiter);
+ Output.push_back(token);
+ input.erase(0, pos + 1);
+ input = trim(input, delimiter);
+ pos = findDelimiterPos(input, delimiter);
+ }
+ Output.push_back(input);
+
+ return Output;
+}
+
diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h
index 5ecf2f5f..46fbf8d6 100644
--- a/code/components/jomjol_helper/Helper.h
+++ b/code/components/jomjol_helper/Helper.h
@@ -1,6 +1,7 @@
#pragma once
#include
#include
+#include
using namespace std;
@@ -10,7 +11,7 @@ void FindReplace(std::string& line, std::string& oldString, std::string& newStri
void CopyFile(string input, string output);
-FILE* OpenFileAndWait(const char* nm, char* _mode, int _waitsec = 1);
+FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1);
size_t findDelimiterPos(string input, string delimiter);
//string trim(string istring);
@@ -22,6 +23,7 @@ string getFileType(string filename);
int mkdir_r(const char *dir, const mode_t mode);
int removeFolder(const char* folderPath, const char* logTag);
+string toLower(string in);
string toUpper(string in);
float temperatureRead();
@@ -30,6 +32,8 @@ time_t addDays(time_t startTime, int days);
void memCopyGen(uint8_t* _source, uint8_t* _target, int _size);
+std::vector HelperZerlegeZeile(std::string input, std::string _delimiter);
+
///////////////////////////
size_t getInternalESPHeapSize();
size_t getESPHeapSize();
diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp
index 71825ca7..a026d985 100644
--- a/code/components/jomjol_logfile/ClassLogFile.cpp
+++ b/code/components/jomjol_logfile/ClassLogFile.cpp
@@ -12,7 +12,7 @@ ClassLogFile LogFile("/sdcard/log/message", "log_%Y-%m-%d.txt");
void ClassLogFile::WriteHeapInfo(std::string _id)
{
-std::string _zw = "\t" + _id;
+ std::string _zw = "\t" + _id;
if (loglevel > 0)
_zw = _zw + "\t" + getESPHeapInfo();
diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp
index 7fde4733..3230cb8f 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.cpp
+++ b/code/components/jomjol_mqtt/interface_mqtt.cpp
@@ -1,12 +1,14 @@
#include "interface_mqtt.h"
-
+//#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#include "esp_log.h"
#include "mqtt_client.h"
#include "ClassLogFile.h"
-static const char *TAG = "interface_mqtt";
+static const char *TAG_INTERFACEMQTT = "interface_mqtt";
+std::map>* connectFunktionMap = NULL;
+std::map>* subscribeFunktionMap = NULL;
bool debugdetail = true;
// #define CONFIG_BROKER_URL "mqtt://192.168.178.43:1883"
@@ -23,44 +25,67 @@ void MQTTPublish(std::string _key, std::string _content, int retained_flag){
msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
zw = "sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
if (debugdetail) LogFile.WriteToFile(zw);
- ESP_LOGI(TAG, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
+ ESP_LOGD(TAG_INTERFACEMQTT, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
}
else {
- ESP_LOGI(TAG, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
+ ESP_LOGW(TAG_INTERFACEMQTT, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
}
}
static esp_err_t mqtt_event_handler_cb(esp_mqtt_event_handle_t event)
{
+ int msg_id;
+ std::string topic = "";
switch (event->event_id) {
+ case MQTT_EVENT_BEFORE_CONNECT:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_BEFORE_CONNECT");
+ break;
case MQTT_EVENT_CONNECTED:
- ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_CONNECTED");
mqtt_connected = true;
+ MQTTconnected();
break;
case MQTT_EVENT_DISCONNECTED:
- ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_DISCONNECTED");
+ break;
+ case MQTT_EVENT_SUBSCRIBED:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
+ msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
+ ESP_LOGI(TAG_INTERFACEMQTT, "sent publish successful, msg_id=%d", msg_id);
+ break;
+ case MQTT_EVENT_UNSUBSCRIBED:
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
- ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
- ESP_LOGI(TAG, "MQTT_EVENT_DATA");
- printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
- printf("DATA=%.*s\r\n", event->data_len, event->data);
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_DATA");
+ ESP_LOGI(TAG_INTERFACEMQTT, "TOPIC=%.*s\r\n", event->topic_len, event->topic);
+ ESP_LOGI(TAG_INTERFACEMQTT, "DATA=%.*s\r\n", event->data_len, event->data);
+ topic.assign(event->topic, event->topic_len);
+ if (subscribeFunktionMap != NULL) {
+ if (subscribeFunktionMap->find(topic) != subscribeFunktionMap->end()) {
+ ESP_LOGD(TAG_INTERFACEMQTT, "call handler function\r\n");
+ (*subscribeFunktionMap)[topic](topic, event->data, event->data_len);
+ }
+ } else {
+ ESP_LOGW(TAG_INTERFACEMQTT, "no handler available\r\n");
+ }
break;
case MQTT_EVENT_ERROR:
- ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
+ ESP_LOGI(TAG_INTERFACEMQTT, "MQTT_EVENT_ERROR");
break;
default:
- ESP_LOGI(TAG, "Other event id:%d", event->event_id);
+ ESP_LOGI(TAG_INTERFACEMQTT, "Other event id:%d", event->event_id);
break;
}
return ESP_OK;
}
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data) {
- ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
+ ESP_LOGD(TAG_INTERFACEMQTT, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
}
@@ -82,7 +107,7 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
if (_user.length() && _password.length()){
mqtt_cfg.username = _user.c_str();
mqtt_cfg.password = _password.c_str();
- printf("Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
+ ESP_LOGI(TAG_INTERFACEMQTT, "Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
};
client = esp_mqtt_client_init(&mqtt_cfg);
@@ -91,3 +116,91 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
MQTTPublish(_LWTContext, "", 1);
}
+
+void MQTTdestroy() {
+ if (client != NULL) {
+ esp_mqtt_client_stop(client);
+ esp_mqtt_client_destroy(client);
+ }
+}
+
+bool MQTTisConnected() {
+ return mqtt_connected;
+}
+
+void MQTTregisterConnectFunction(std::string name, std::function func){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisteronnectFunction %s\r\n", name.c_str());
+ if (connectFunktionMap == NULL) {
+ connectFunktionMap = new std::map>();
+ }
+
+ if ((*connectFunktionMap)[name] != NULL) {
+ ESP_LOGW(TAG_INTERFACEMQTT, "connect function %s already registred", name.c_str());
+ return;
+ }
+
+ (*connectFunktionMap)[name] = func;
+
+ if (mqtt_connected) {
+ func();
+ }
+}
+
+void MQTTunregisterConnectFunction(std::string name){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisteronnectFunction %s\r\n", name.c_str());
+ if ((connectFunktionMap != NULL) && (connectFunktionMap->find(name) != connectFunktionMap->end())) {
+ connectFunktionMap->erase(name);
+ }
+}
+
+void MQTTregisterSubscribeFunction(std::string topic, std::function func){
+ ESP_LOGD(TAG_INTERFACEMQTT, "MQTTregisterSubscribeFunction %s\r\n", topic.c_str());
+ if (subscribeFunktionMap == NULL) {
+ subscribeFunktionMap = new std::map>();
+ }
+
+ if ((*subscribeFunktionMap)[topic] != NULL) {
+ ESP_LOGW(TAG_INTERFACEMQTT, "topic %s already registred for subscription", topic.c_str());
+ return;
+ }
+
+ (*subscribeFunktionMap)[topic] = func;
+
+ if (mqtt_connected) {
+ int msg_id = esp_mqtt_client_subscribe(client, topic.c_str(), 0);
+ ESP_LOGD(TAG_INTERFACEMQTT, "topic %s subscribe successful, msg_id=%d", topic.c_str(), msg_id);
+ }
+}
+
+void MQTTconnected(){
+ if (mqtt_connected) {
+ if (connectFunktionMap != NULL) {
+ for(std::map>::iterator it = connectFunktionMap->begin(); it != connectFunktionMap->end(); ++it) {
+ it->second();
+ ESP_LOGD(TAG_INTERFACEMQTT, "call connect function %s", it->first.c_str());
+ }
+ }
+
+ 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);
+ }
+ }
+ }
+}
+
+void MQTTdestroySubscribeFunction(){
+ if (subscribeFunktionMap != NULL) {
+ if (mqtt_connected) {
+ for(std::map>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
+ int msg_id = esp_mqtt_client_unsubscribe(client, it->first.c_str());
+ ESP_LOGI(TAG_INTERFACEMQTT, "topic %s unsubscribe successful, msg_id=%d", it->first.c_str(), msg_id);
+ }
+ }
+
+ subscribeFunktionMap->clear();
+ delete subscribeFunktionMap;
+ subscribeFunktionMap = NULL;
+ }
+}
\ No newline at end of file
diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h
index f514ea2d..50990e6f 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.h
+++ b/code/components/jomjol_mqtt/interface_mqtt.h
@@ -1,7 +1,23 @@
+#ifndef INTERFACE_MQTT_H
+#define INTERFACE_MQTT_H
+
#include
+#include |
- Storage Path/Name: |
+ Storage Path/Name: |
| x: |
@@ -90,9 +90,8 @@ select {
-
-
+
-
-
-
-
+
+
+
+
diff --git a/sd-card/html/edit_config.html b/sd-card/html/edit_config.html
index 23825d5e..a8c2067e 100644
--- a/sd-card/html/edit_config.html
+++ b/sd-card/html/edit_config.html
@@ -41,7 +41,6 @@ textarea {
-
-
-
-
+
+
+
+