Rolling 2020-10-04

Initial MQTT
This commit is contained in:
jomjol
2020-10-04 08:09:59 +02:00
parent f8e8c756ab
commit 70a88088f2
16 changed files with 268 additions and 56 deletions

View File

@@ -12,6 +12,8 @@
#include "ClassLogFile.h"
bool debugdetailanalog = false;
ClassFlowAnalog::ClassFlowAnalog()
{
isLogImage = false;
@@ -147,6 +149,8 @@ bool ClassFlowAnalog::doFlow(string time)
return false;
};
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doFlow nach Alignment");
doNeuralNetwork(time);
return true;
@@ -167,7 +171,7 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
CAlignAndCutImage *caic = new CAlignAndCutImage(input);
if (!caic->ImageOkay()){
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
delete caic;
return false;
}
@@ -175,7 +179,7 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
if (input_roi.length() > 0){
img_roi = new CImageBasis(input_roi);
if (!img_roi->ImageOkay()){
LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
delete caic;
delete img_roi;
return false;
@@ -190,6 +194,13 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
caic->CutAndSave(output, ROI[i]->posx, ROI[i]->posy, ROI[i]->deltax, ROI[i]->deltay);
rs = new CResizeImage(output);
if (!rs->ImageOkay()){
if (debugdetailanalog) LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut CResizeImage(output);!");
delete caic;
delete rs;
return false;
}
rs->Resize(modelxsize, modelysize);
ioresize = "/sdcard/img_tmp/ra" + std::to_string(i) + ".bmp";
ioresize = FormatFileName(ioresize);
@@ -248,8 +259,11 @@ bool ClassFlowAnalog::doNeuralNetwork(string time)
f1 = 0; f2 = 0;
#ifndef OHNETFLITE
// LogFile.WriteToFile("ClassFlowAnalog::doNeuralNetwork vor CNN tflite->LoadInputImage(ioresize)");
tflite->LoadInputImage(ioresize);
tflite->Invoke();
if (debugdetailanalog) LogFile.WriteToFile("Nach Invoke");
f1 = tflite->GetOutputValue(0);
f2 = tflite->GetOutputValue(1);

View File

@@ -20,6 +20,9 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _
if (_stepname.compare("[Analog]") == 0){
_classname = "ClassFlowAnalog";
}
if (_stepname.compare("[MQTT]") == 0){
_classname = "ClassFlowMQTT";
}
// std::string zw = "Classname: " + _classname + "\n";
// printf(zw.c_str());
@@ -80,6 +83,8 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
cfc = new ClassFlowAnalog(&FlowControll);
if (toUpper(_type).compare("[DIGITS]") == 0)
cfc = new ClassFlowDigit(&FlowControll);
if (toUpper(_type).compare("[MQTT]") == 0)
cfc = new ClassFlowMQTT(&FlowControll);
if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
{
cfc = new ClassFlowPostProcessing(&FlowControll);

View File

@@ -8,6 +8,7 @@
#include "ClassFlowDigit.h"
#include "ClassFlowAnalog.h"
#include "ClassFlowPostProcessing.h"
#include "ClassFlowMQTT.h"
class ClassFlowControll :

View File

@@ -0,0 +1,110 @@
#include "ClassFlowMQTT.h"
#include "Helper.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
#include <time.h>
static const char* TAG2 = "example";
ClassFlowMQTT::ClassFlowMQTT()
{
uri = "";
topic = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
}
ClassFlowMQTT::ClassFlowMQTT(std::vector<ClassFlow*>* lfc)
{
uri = "";
topic = "";
clientname = "watermeter";
OldValue = "";
flowpostprocessing = NULL;
ListFlowControll = lfc;
for (int i = 0; i < ListFlowControll->size(); ++i)
{
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
{
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
}
}
}
bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
{
std::vector<string> zerlegt;
aktparamgraph = trim(aktparamgraph);
if (aktparamgraph.size() == 0)
if (!this->GetNextParagraph(pfile, aktparamgraph))
return false;
if (toUpper(aktparamgraph).compare("[MQTT]") != 0) // Paragraph passt nich zu MakeImage
return false;
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
{
zerlegt = this->ZerlegeZeile(aktparamgraph);
if ((toUpper(zerlegt[0]) == "URI") && (zerlegt.size() > 1))
{
this->uri = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "TOPIC") && (zerlegt.size() > 1))
{
this->topic = zerlegt[1];
}
if ((toUpper(zerlegt[0]) == "CLIENTID") && (zerlegt.size() > 1))
{
this->clientname = zerlegt[1];
}
}
if ((uri.length() > 0) && (topic.length() > 0))
{
MQTTInit(uri, clientname);
}
return true;
}
bool ClassFlowMQTT::doFlow(string zwtime)
{
std::string result;
string zw = "";
if (flowpostprocessing)
{
result = flowpostprocessing->getReadoutParam(false, true);
}
else
{
for (int i = 0; i < ListFlowControll->size(); ++i)
{
zw = (*ListFlowControll)[i]->getReadout();
if (zw.length() > 0)
{
if (result.length() == 0)
result = zw;
else
result = result + "\t" + zw;
}
}
}
MQTTPublish(topic, result);
OldValue = result;
return true;
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include "ClassFlow.h"
#include "ClassFlowPostProcessing.h"
#include <string>
class ClassFlowMQTT :
public ClassFlow
{
protected:
std::string uri, topic, clientname;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
public:
ClassFlowMQTT();
ClassFlowMQTT(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string name(){return "ClassFlowMQTT";};
};