Update to v0.9.0

This commit is contained in:
jomjol
2020-09-04 18:59:00 +02:00
parent 78e3256493
commit d51eaa1428
48 changed files with 10625 additions and 633 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,7 @@
#include "server_help.h"
#include "Helper.h"
#include "miniz.h"
/* Max length a file path can have on storage */
// #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
@@ -487,6 +488,103 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
}
void delete_all_in_directory(std::string _directory)
{
struct dirent *entry;
DIR *dir = opendir(_directory.c_str());
std::string filename;
if (!dir) {
ESP_LOGE(TAG, "Failed to stat dir : %s", _directory.c_str());
return;
}
/* Iterate over all files / folders and fetch their names and sizes */
while ((entry = readdir(dir)) != NULL) {
if (!(entry->d_type == DT_DIR)){
filename = _directory + std::string(entry->d_name);
ESP_LOGI(TAG, "Deleting file : %s", filename.c_str());
/* Delete file */
unlink(filename.c_str());
};
}
closedir(dir);
}
void unzip(std::string _in_zip_file, std::string _target_directory){
int i, sort_iter;
mz_bool status;
size_t uncomp_size;
mz_zip_archive zip_archive;
void* p;
const int N = 50;
char data[2048];
char archive_filename[64];
std::string zw;
// static const char* s_Test_archive_filename = "testhtml.zip";
printf("miniz.c version: %s\n", MZ_VERSION);
// Now try to open the archive.
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
return;
}
// Get and print information about each file in the archive.
int numberoffiles = (int)mz_zip_reader_get_num_files(&zip_archive);
for (sort_iter = 0; sort_iter < 2; sort_iter++)
{
memset(&zip_archive, 0, sizeof(zip_archive));
status = mz_zip_reader_init_file(&zip_archive, _in_zip_file.c_str(), sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
if (!status)
{
printf("mz_zip_reader_init_file() failed!\n");
return;
}
for (i = 0; i < numberoffiles; i++)
{
mz_zip_archive_file_stat file_stat;
mz_zip_reader_file_stat(&zip_archive, i, &file_stat);
sprintf(archive_filename, file_stat.m_filename);
// Try to extract all the files to the heap.
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
if (!p)
{
printf("mz_zip_reader_extract_file_to_heap() failed!\n");
mz_zip_reader_end(&zip_archive);
return;
}
// Save to File.
zw = std::string(archive_filename);
zw = _target_directory + zw;
printf("Filename to extract: %s", zw.c_str());
FILE* fpTargetFile = fopen(zw.c_str(), "wb");
fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
fclose(fpTargetFile);
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
// printf("File data: \"%s\"\n", (const char*)p);
// We're done.
mz_free(p);
}
// Close the archive, freeing any resources it was using
mz_zip_reader_end(&zip_archive);
}
printf("Success.\n");
}
void register_server_file_uri(httpd_handle_t server, const char *base_path)
{
static struct file_server_data *server_data = NULL;

View File

@@ -1,3 +1,8 @@
#include <esp_http_server.h>
#include <string>
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void unzip(std::string _in_zip_file, std::string _target_directory);
void delete_all_in_directory(std::string _directory);

View File

@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include "server_tflite.h"
#include "server_file.h"
#include "ClassLogFile.h"
@@ -301,14 +302,23 @@ void CheckOTAUpdate(void)
esp_err_t handler_ota_update(httpd_req_t *req)
{
LogFile.WriteToFile("handler_ota_update");
char _query[100];
char _query[200];
char _filename[30];
char _valuechar[30];
std::string fn = "/sdcard/firmware/";
bool _file_del = false;
std::string _task;
if (httpd_req_get_url_query_str(req, _query, 100) == ESP_OK)
if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
{
printf("Query: "); printf(_query); printf("\n");
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
printf("task is found"); printf(_valuechar); printf("\n");
_task = std::string(_valuechar);
}
if (httpd_query_key_value(_query, "file", _filename, 30) == ESP_OK)
{
fn.append(_filename);
@@ -323,6 +333,20 @@ esp_err_t handler_ota_update(httpd_req_t *req)
};
if (_task.compare("unziphtml") == 0)
{
std::string in, out, zw;
in = "/sdcard/firmware/html.zip";
out = "/sdcard/html/";
unzip(in, out);
zw = "Unzip html Done";
httpd_resp_sendstr_chunk(req, zw.c_str());
}
if (_file_del)
{
struct stat file_stat;

View File

@@ -72,6 +72,10 @@ bool ClassFlow::doFlow(string time)
return false;
}
string ClassFlow::getHTMLSingleStep(string host){
return "";
}
string ClassFlow::getReadout()
{
return string();

View File

@@ -33,6 +33,7 @@ public:
ClassFlow(std::vector<ClassFlow*> * lfc);
virtual bool ReadParameter(FILE* pfile, string &aktparamgraph);
virtual bool doFlow(string time);
virtual string getHTMLSingleStep(string host);
virtual string getReadout();
virtual string name(){return "ClassFlow";};

View File

@@ -60,6 +60,17 @@ bool ClassFlowAlignment::ReadParameter(FILE* pfile, string& aktparamgraph)
}
string ClassFlowAlignment::getHTMLSingleStep(string host)
{
string result;
result = "<p>Rotated Image: </p> <p><img src=\"" + host + "/img_tmp/rot.jpg\"></p>\n";
result = result + "<p>Found Alignment: </p> <p><img src=\"" + host + "/img_tmp/rot_roi.jpg\"></p>\n";
result = result + "<p>Aligned Image: </p> <p><img src=\"" + host + "/img_tmp/alg.jpg\"></p>\n";
return result;
}
bool ClassFlowAlignment::doFlow(string time)
{
string input = namerawimage;

View File

@@ -23,6 +23,7 @@ public:
ClassFlowAlignment(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
string name(){return "ClassFlowAlignment";};
};

View File

@@ -113,6 +113,31 @@ bool ClassFlowAnalog::ReadParameter(FILE* pfile, string& aktparamgraph)
}
string ClassFlowAnalog::getHTMLSingleStep(string host)
{
string result, zw;
std::vector<HTMLInfo*> htmlinfo;
result = "<p>Found ROIs: </p> <p><img src=\"" + host + "/img_tmp/alg_roi.jpg\"></p>\n";
result = result + "Analog Pointers: <p> ";
htmlinfo = GetHTMLInfo();
for (int i = 0; i < htmlinfo.size(); ++i)
{
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << htmlinfo[i]->val;
zw = stream.str();
result = result + "<img src=\"" + host + "/img_tmp/" + htmlinfo[i]->filename + "\"> " + zw;
delete htmlinfo[i];
}
htmlinfo.clear();
return result;
}
bool ClassFlowAnalog::doFlow(string time)
{
doAlignAndCut(time);

View File

@@ -25,6 +25,7 @@ public:
ClassFlowAnalog(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
string getReadout();
bool doNeuralNetwork(string time);

View File

@@ -1,8 +1,39 @@
#include "ClassFlowControll.h"
#include "ClassLogFile.h"
#include "time_sntp.h"
#include "Helper.h"
std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
bool found = false;
std::string _classname = "";
std::string result = "";
if (_stepname.compare("[MakeImage]") == 0){
_classname = "ClassFlowMakeImage";
}
if (_stepname.compare("[Alignment]") == 0){
_classname = "ClassFlowAlignment";
}
if (_stepname.compare("[Digits]") == 0){
_classname = "ClassFlowDigit";
}
if (_stepname.compare("[Analog]") == 0){
_classname = "ClassFlowAnalog";
}
// std::string zw = "Classname: " + _classname + "\n";
// printf(zw.c_str());
for (int i = 0; i < FlowControll.size(); ++i)
if (FlowControll[i]->name().compare(_classname) == 0){
// printf(FlowControll[i]->name().c_str()); printf("\n");
FlowControll[i]->doFlow("");
result = FlowControll[i]->getHTMLSingleStep(_host);
found = true;
}
return result;
}
std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
{
for (int i = 0; i < FlowControll.size(); ++i)
@@ -67,8 +98,6 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
void ClassFlowControll::InitFlow(std::string config)
{
int aktFlow;
bool handeled;
string line;
flowpostprocessing = NULL;
@@ -79,8 +108,6 @@ void ClassFlowControll::InitFlow(std::string config)
pFile = fopen(config.c_str(), "r");
line = "";
handeled = true;
char zw[1024];
if (pFile != NULL)
@@ -109,15 +136,24 @@ void ClassFlowControll::InitFlow(std::string config)
}
std::string ClassFlowControll::getActStatus(){
return aktstatus;
}
bool ClassFlowControll::doFlow(string time)
{
bool result = true;
std::string zw_time;
for (int i = 0; i < FlowControll.size(); ++i)
{
zw_time = gettimestring("%Y%m%d-%H%M%S");
aktstatus = zw_time + ": " + FlowControll[i]->name();
string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
LogFile.WriteToFile(zw);
result = result && FlowControll[i]->doFlow(time);
}
zw_time = gettimestring("%Y%m%d-%H%M%S");
aktstatus = zw_time + ": Flow is done";
return result;
}

View File

@@ -21,6 +21,7 @@ protected:
bool AutoStart;
float AutoIntervall;
void SetInitialParameter(void);
std::string aktstatus;
public:
@@ -31,8 +32,12 @@ public:
string GetPrevalue();
bool ReadParameter(FILE* pfile, string& aktparamgraph);
std::string doSingleStep(std::string _stepname, std::string _host);
bool isAutoStart(long &_intervall);
std::string getActStatus();
std::vector<HTMLInfo*> GetAllDigital();
std::vector<HTMLInfo*> GetAllAnalog();

View File

@@ -91,6 +91,32 @@ bool ClassFlowDigit::ReadParameter(FILE* pfile, string& aktparamgraph)
}
string ClassFlowDigit::getHTMLSingleStep(string host)
{
string result, zw;
std::vector<HTMLInfo*> htmlinfo;
result = "<p>Found ROIs: </p> <p><img src=\"" + host + "/img_tmp/alg_roi.jpg\"></p>\n";
result = result + "Digital Counter: <p> ";
htmlinfo = GetHTMLInfo();
for (int i = 0; i < htmlinfo.size(); ++i)
{
if (htmlinfo[i]->val == 10)
zw = "NaN";
else
{
zw = to_string((int) htmlinfo[i]->val);
}
result = result + "<img src=\"" + host + "/img_tmp/" + htmlinfo[i]->filename + "\"> " + zw;
delete htmlinfo[i];
}
htmlinfo.clear();
return result;
}
bool ClassFlowDigit::doFlow(string time)
{
doAlignAndCut(time);

View File

@@ -29,6 +29,7 @@ public:
ClassFlowDigit(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
string getReadout();
std::vector<HTMLInfo*> GetHTMLInfo();

View File

@@ -120,6 +120,12 @@ void ClassFlowMakeImage::CopyFile(string input, string output)
printf("Copy done\n");
}
string ClassFlowMakeImage::getHTMLSingleStep(string host)
{
string result;
result = "Raw Image: <br>\n<img src=\"" + host + "/img_tmp/raw.jpg\">\n";
return result;
}
bool ClassFlowMakeImage::doFlow(string zwtime)
{

View File

@@ -35,6 +35,7 @@ public:
ClassFlowMakeImage(std::vector<ClassFlow*>* lfc);
bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
string getHTMLSingleStep(string host);
time_t getTimeImageTaken();
string name(){return "ClassFlowMakeImage";};
};

View File

@@ -18,10 +18,14 @@ float CTfLiteClass::GetOutputValue(int nr)
int CTfLiteClass::GetClassFromImage(std::string _fn)
{
// printf("Before Load image %s\n", _fn.c_str());
if (!LoadInputImage(_fn))
return -1000;
// printf("After Load image %s\n", _fn.c_str());
Invoke();
printf("After Invoke %s\n", _fn.c_str());
return GetOutClassification();
// return 0;
}
@@ -102,46 +106,6 @@ void CTfLiteClass::Invoke()
// printf("Invoke Done.\n");
}
/* mit CImageBasis --> funktioniert nicht, keine Ahnung warum !!!
bool CTfLiteClass::LoadInputImage(std::string _fn)
{
CImageBasis *cib = new CImageBasis(_fn);
GetInputDimension(true);
printf("TFlite load image size: %d x %d x %d\n", cib->getWidth(), cib->getHeight(), cib->getChannels());
// printf("TFlite expected image size: %d x %d x %d\n", im_width, im_height, im_channel);
if ((cib->getWidth() != im_width) || (cib->getHeight() != im_height) || (cib->getChannels() != im_channel))
{
printf("Input Imagesize Wrong.\n");
return false;
}
input_i = 0;
float* input_data_ptr = (interpreter->input(0))->data.f;
uint8_t ui8;
unsigned char zw;
for (int y = 0; y < cib->getHeight(); ++y)
for (int x = 0; x < cib->getWidth(); ++x)
{
printf("CIB: ");
for (int ch = 0; ch < cib->getChannels(); ++ch)
{
ui8 = cib->GetPixelColor(x, y, ch);
printf("%f ", (float) ui8);
*(input_data_ptr) = (float) ui8;
input_data_ptr++;
}
printf("\n");
}
delete cib;
return true;
}
*/
bool CTfLiteClass::LoadInputImage(std::string _fn)
{