jomjol 5 лет назад
Родитель
Сommit
5a98b3d0bb

+ 3 - 1
README.md

@@ -27,7 +27,9 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 
 
-##### Rolling - (2020-09-25)
+##### Rolling - (2020-09-26)
+
+* Integration of version info (menu: SYSTEM --> INFO)
 
 * based on v2.1.0 (2020-09-25)
 

+ 7 - 0
code/CMakeLists.txt

@@ -4,5 +4,12 @@ list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/proto
 
 set(PROJECT_VER "0.0.9.3")
 
+ADD_CUSTOM_COMMAND(
+    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
+           ${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
+    COMMAND ${CMAKE_COMMAND} -P
+            ${CMAKE_CURRENT_SOURCE_DIR}/version.cmake)
+
+
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)
 project(esp32cam-server-only)

+ 1 - 4
code/lib/jomjol_fileserver_ota/server_file.cpp

@@ -258,7 +258,7 @@ static esp_err_t download_get_handler(httpd_req_t *req)
         return ESP_FAIL;
     }
 
-    esp_err_t res = httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
+    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);
@@ -437,7 +437,6 @@ static esp_err_t delete_post_handler(httpd_req_t *req)
 
 //////////////////////////////////////////////////////////////
     char _query[200];
-    char _filename[30];
     char _valuechar[30];    
     std::string fn = "/sdcard/firmware/";
     std::string _task;
@@ -576,8 +575,6 @@ void unzip(std::string _in_zip_file, std::string _target_directory){
     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";

+ 8 - 2
code/lib/jomjol_flowcontroll/ClassFlowAnalog.cpp

@@ -171,8 +171,14 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
         return false;
     }
 
-    if (input_roi.length() > 0)
-        img_roi = new CImageBasis(input_roi);    
+    if (input_roi.length() > 0){
+        img_roi = new CImageBasis(input_roi);
+        if (!img_roi->ImageOkay()){
+            LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
+            delete img_roi;
+            return false;
+        }
+    }
 
     for (int i = 0; i < ROI.size(); ++i)
     {

+ 0 - 2
code/lib/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -6,7 +6,6 @@
 #include "server_ota.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){
@@ -29,7 +28,6 @@ std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _
  //           printf(FlowControll[i]->name().c_str()); printf("\n");
             FlowControll[i]->doFlow("");
             result = FlowControll[i]->getHTMLSingleStep(_host);
-            found = true;
         }
 
     return result;

+ 8 - 1
code/lib/jomjol_flowcontroll/ClassFlowDigit.cpp

@@ -149,8 +149,15 @@ bool ClassFlowDigit::doAlignAndCut(string time)
         return false;
     }
 
-    if (input_roi.length() > 0)
+    if (input_roi.length() > 0){
         img_roi = new CImageBasis(input_roi);
+        if (!img_roi->ImageOkay()){
+            LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut ImageRoi not okay!");
+            delete img_roi;
+            return false;
+        }
+    }
+
 
 
     for (int i = 0; i < ROI.size(); ++i)

+ 36 - 29
code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -329,9 +329,15 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
         return true;
     }
 
-    zw = ErsetzteN(ReturnRawValue);
+    zw = ErsetzteN(ReturnRawValue); 
+
 
     Value = std::stof(zw);
+    if (checkDigitIncreaseConsistency)
+    {
+//        Value = checkDigitConsistency(Value, DecimalShift, isanalog);
+    }
+
     zwvalue = RundeOutput(Value, AnzahlAnalog - DecimalShift);
 
     if ((!AllowNegativeRates) && (Value < PreValue))
@@ -413,39 +419,40 @@ string ClassFlowPostProcessing::ErsetzteN(string input)
     return input;
 }
 
-string ClassFlowPostProcessing::checkDigitConsistency(string input, int _decilamshift, int lastvalueanalog){
-/*    
-    if (checkDigitIncreaseConsistency && lastvalueanalog > -1)
+float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog){
+    int aktdigit, olddigit;
+    int aktdigit_before, olddigit_before;
+    int pot, pot_max;
+    float zw;
+
+    pot = _decilamshift;
+    if (!_isanalog)             // falls es keine analogwerte gibt, kann die letzte nicht bewerte werden
     {
-        int zifferIST;
-//        int substrakt = 0;
-        bool lastcorrected = false;
-        for (int i = input.length() - 1; i >= 0; --i)
-        {
-            zifferIST = input[i] - 48;  //std::stoi(std::string(input[i]));
-            if (lastcorrected)
-            {
-                zifferIST--;
-                input[i] = zifferIST + 48;
-                lastcorrected = false;
-            }
+        pot++;
+    }
+    pot_max = ((int) log10(input)) + 1;
+
+    while (pot <= pot_max)
+    {
+        zw = input / pow(10, pot-1);
+        aktdigit_before = ((int) zw) % 10;
+        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);
+        olddigit = ((int) zw) % 10;
 
-            pot = posPunkt - i - 1;
-            zw = PreValue / pow(10, pot);
-            ziffer = ((int) zw) % 10;
-            if (zifferIST < ziffer)
+        if (aktdigit != olddigit) {
+            if (olddigit_before >= aktdigit_before)         // stelle vorher hat noch keinen Nulldurchgang --> nachfolgestelle sollte sich nicht verändern
             {
-                if (lastvalueanalog >= 7)
-                {
-                    input[i] = ziffer + 48;
-                    lastvalueanalog = ziffer;
-                    lastcorrected = true;
-                }
+                input = input + ((float) (olddigit - aktdigit)) * pow(10, pot);     // Neue Digit wird durch alte Digit ersetzt;
             }
-        
-            
         }
+
+        pot++;
     }
-*/
+
     return input;
 }

+ 2 - 2
code/lib/jomjol_flowcontroll/ClassFlowPostProcessing.h

@@ -9,7 +9,7 @@ class ClassFlowPostProcessing :
 {
 protected:
     bool PreValueUse;
-    int PreValueAgeStartup;
+    int PreValueAgeStartup; 
     bool AllowNegativeRates;
     float MaxRateValue;
     bool useMaxRateValue;
@@ -29,7 +29,7 @@ protected:
     string ShiftDecimal(string in, int _decShift);
 
     string ErsetzteN(string);
-    string checkDigitConsistency(string, int _decilamshift, int lastvalueanalog = -1);
+    float checkDigitConsistency(float input, int _decilamshift, bool _isanalog);
     string RundeOutput(float _in, int _anzNachkomma);
 
 public:

+ 0 - 2
code/lib/jomjol_image_proc/CFindTemplate.cpp

@@ -528,8 +528,6 @@ void CAlignAndCutImage::CutAndSave(std::string _template1, int x1, int y1, int d
     int memsize = dx * dy * this->channels;
     uint8_t* odata = (unsigned char*)GET_MEMORY(memsize);
 
-
-    int x_source, y_source;
     stbi_uc* p_target;
     stbi_uc* p_source;
 

+ 50 - 0
code/src/CMakeLists.txt

@@ -1,6 +1,56 @@
 # This file was automatically generated for projects
 # without default 'CMakeLists.txt' file.
 
+##################################################################
+##################################################################
+execute_process(COMMAND git log --pretty=format:'%h' -n 1
+                OUTPUT_VARIABLE GIT_REV
+                ERROR_QUIET)
+
+string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M")
+
+# Check whether we got any revision (which isn't
+# always the case, e.g. when someone downloaded a zip
+# file from Github instead of a checkout)
+if ("${GIT_REV}" STREQUAL "")
+    set(GIT_REV "N/A")
+    set(GIT_DIFF "")
+    set(GIT_TAG "N/A")
+    set(GIT_BRANCH "N/A")
+else()
+    execute_process(
+        COMMAND bash -c "git diff --quiet --exit-code || echo +"
+        OUTPUT_VARIABLE GIT_DIFF)
+    execute_process(
+        COMMAND git describe --exact-match --tags
+        OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
+    execute_process(
+        COMMAND git rev-parse --abbrev-ref HEAD
+        OUTPUT_VARIABLE GIT_BRANCH)
+
+    string(STRIP "${GIT_REV}" GIT_REV)
+    string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
+    string(STRIP "${GIT_DIFF}" GIT_DIFF)
+    string(STRIP "${GIT_TAG}" GIT_TAG)
+    string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
+endif()
+
+set(VERSION "const char* GIT_REV=\"${GIT_REV}${GIT_DIFF}\";
+const char* GIT_TAG=\"${GIT_TAG}\";
+const char* GIT_BRANCH=\"${GIT_BRANCH}\";
+const char* BUILD_TIME=\"${BUILD_TIME}\";")
+
+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
+    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
+else()
+    set(VERSION_ "")
+endif()
+
+if (NOT "${VERSION}" STREQUAL "${VERSION_}")
+    file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
+endif()
+#######################################################################
+#######################################################################
 
 
 FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)

+ 67 - 71
code/src/server_main.cpp

@@ -3,9 +3,12 @@
 #include <string>
 
 #include "server_help.h"
+#include "ClassLogFile.h"
 
 #include "time_sntp.h"
 
+#include "version.h"
+
 
 httpd_handle_t server = NULL;   
 
@@ -14,80 +17,73 @@ std::string starttime = "";
 
 
 /* An HTTP GET handler */
-esp_err_t hello_get_handler(httpd_req_t *req)
+esp_err_t info_get_handler(httpd_req_t *req)
 {
-    char*  buf;
-    size_t buf_len;
-    printf("req uri:\n");
-    printf(req->uri);
-    printf("\n");
-
-    /* Get header value string length and allocate memory for length + 1,
-     * extra byte for null termination */
-    buf_len = httpd_req_get_hdr_value_len(req, "Host") + 1;
-    if (buf_len > 1) {
-        buf = (char*) malloc(buf_len);
-        /* Copy null terminated value string into buffer */
-        if (httpd_req_get_hdr_value_str(req, "Host", buf, buf_len) == ESP_OK) {
-            ESP_LOGI(TAG, "Found header => Host: %s", buf);
+    LogFile.WriteToFile("info_get_handler");    
+    char _query[200];
+    char _valuechar[30];    
+    std::string _task;
+
+    if (httpd_req_get_url_query_str(req, _query, 200) == ESP_OK)
+    {
+        printf("Query: "); printf(_query); printf("\n");
+        
+        if (httpd_query_key_value(_query, "type", _valuechar, 30) == ESP_OK)
+        {
+            printf("type is found"); printf(_valuechar); printf("\n"); 
+            _task = std::string(_valuechar);
         }
-        free(buf);
+    };
+
+    if (_task.compare("GitBranch") == 0)
+    {
+        std::string zw;
+        zw = std::string(libfive_git_branch());
+        httpd_resp_sendstr_chunk(req, zw.c_str());
+        httpd_resp_sendstr_chunk(req, NULL);  
+        return ESP_OK;        
     }
 
-    buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-2") + 1;
-    if (buf_len > 1) {
-        buf = (char*) malloc(buf_len);
-        if (httpd_req_get_hdr_value_str(req, "Test-Header-2", buf, buf_len) == ESP_OK) {
-            ESP_LOGI(TAG, "Found header => Test-Header-2: %s", buf);
-        }
-        free(buf);
+
+    if (_task.compare("GitTag") == 0)
+    {
+        std::string zw;
+        zw = std::string(libfive_git_version());
+        httpd_resp_sendstr_chunk(req, zw.c_str());
+        httpd_resp_sendstr_chunk(req, NULL);  
+        return ESP_OK;        
     }
 
-    buf_len = httpd_req_get_hdr_value_len(req, "Test-Header-1") + 1;
-    if (buf_len > 1) {
-        buf = (char*) malloc(buf_len);
-        if (httpd_req_get_hdr_value_str(req, "Test-Header-1", buf, buf_len) == ESP_OK) {
-            ESP_LOGI(TAG, "Found header => Test-Header-1: %s", buf);
-        }
-        free(buf);
+
+
+    if (_task.compare("GitRevision") == 0)
+    {
+        std::string zw;
+        zw = std::string(libfive_git_revision());
+        httpd_resp_sendstr_chunk(req, zw.c_str());
+        httpd_resp_sendstr_chunk(req, NULL);  
+        return ESP_OK;        
     }
 
-    /* Read URL query string length and allocate memory for length + 1,
-     * extra byte for null termination */
-    buf_len = httpd_req_get_url_query_len(req) + 1;
-    if (buf_len > 1) {
-        buf = (char*) malloc(buf_len);
-        if (httpd_req_get_url_query_str(req, buf, buf_len) == ESP_OK) {
-            ESP_LOGI(TAG, "Found URL query => %s", buf);
-            char param[32];
-            /* Get value of expected key from query string */
-            if (httpd_query_key_value(buf, "query1", param, sizeof(param)) == ESP_OK) {
-                ESP_LOGI(TAG, "Found URL query parameter => query1=%s", param);
-            }
-            if (httpd_query_key_value(buf, "query3", param, sizeof(param)) == ESP_OK) {
-                ESP_LOGI(TAG, "Found URL query parameter => query3=%s", param);
-            }
-            if (httpd_query_key_value(buf, "query2", param, sizeof(param)) == ESP_OK) {
-                ESP_LOGI(TAG, "Found URL query parameter => query2=%s", param);
-            }
-        }
-        free(buf);
+    if (_task.compare("BuildTime") == 0)
+    {
+        std::string zw;
+        zw = std::string(build_time());
+        httpd_resp_sendstr_chunk(req, zw.c_str());
+        httpd_resp_sendstr_chunk(req, NULL);  
+        return ESP_OK;        
     }
 
-    /* Set some custom headers */
-    httpd_resp_set_hdr(req, "Custom-Header-1", "Custom-Value-1");
-    httpd_resp_set_hdr(req, "Custom-Header-2", "Custom-Value-2");
+    if (_task.compare("GitBaseBranch") == 0)
+    {
+        std::string zw;
+        zw = std::string(git_base_branch());
+        httpd_resp_sendstr_chunk(req, zw.c_str());
+        httpd_resp_sendstr_chunk(req, NULL);  
+        return ESP_OK;        
+    }
 
-    /* Send response with custom headers and body set as the
-     * string passed in user context*/
-    const char* resp_str = (const char*) req->user_ctx;
-    httpd_resp_send(req, resp_str, strlen(resp_str));
 
-    /* After sending the HTTP response the old HTTP request
-     * headers are lost. Check if HTTP request headers can be read now. */
-    if (httpd_req_get_hdr_value_len(req, "Host") == 0) {
-        ESP_LOGI(TAG, "Request headers lost");
-    }
     return ESP_OK;
 }
 
@@ -205,6 +201,15 @@ esp_err_t img_tmp_handler(httpd_req_t *req)
 
 void register_server_main_uri(httpd_handle_t server, const char *base_path)
 {
+    httpd_uri_t info_get_handle = {
+        .uri       = "/version",  // Match all URIs of type /path/to/file
+        .method    = HTTP_GET,
+        .handler   = info_get_handler,
+        .user_ctx  = (void*) base_path    // Pass server data as context
+    };
+    httpd_register_uri_handler(server, &info_get_handle);
+
+
     httpd_uri_t starttime_tmp_handle = {
         .uri       = "/starttime",  // Match all URIs of type /path/to/file
         .method    = HTTP_GET,
@@ -260,14 +265,6 @@ httpd_handle_t start_webserver(void)
 //    config.uri_match_fn = NULL;                            
     config.uri_match_fn = httpd_uri_match_wildcard;
 
-
-    httpd_uri_t hll = {};
-    hll.uri       = "/hello";
-    hll.method    = HTTP_GET;
-    hll.handler   = hello_get_handler;
-    hll.user_ctx  = (void*) "Hello World!";
-
-
     starttime = gettimestring("%Y%m%d-%H%M%S");
 
     // Start the httpd server
@@ -275,7 +272,6 @@ httpd_handle_t start_webserver(void)
     if (httpd_start(&server, &config) == ESP_OK) {
         // Set URI handlers
         ESP_LOGI(TAG, "Registering URI handlers");
-        httpd_register_uri_handler(server, &hll);
         return server;
     }
 

+ 0 - 43
code/src/version.cmake

@@ -1,43 +0,0 @@
-execute_process(COMMAND git log --pretty=format:'%h' -n 1
-                OUTPUT_VARIABLE GIT_REV
-                ERROR_QUIET)
-
-# Check whether we got any revision (which isn't
-# always the case, e.g. when someone downloaded a zip
-# file from Github instead of a checkout)
-if ("${GIT_REV}" STREQUAL "")
-    set(GIT_REV "N/A")
-    set(GIT_DIFF "")
-    set(GIT_TAG "N/A")
-    set(GIT_BRANCH "N/A")
-else()
-    execute_process(
-        COMMAND bash -c "git diff --quiet --exit-code || echo +"
-        OUTPUT_VARIABLE GIT_DIFF)
-    execute_process(
-        COMMAND git describe --exact-match --tags
-        OUTPUT_VARIABLE GIT_TAG ERROR_QUIET)
-    execute_process(
-        COMMAND git rev-parse --abbrev-ref HEAD
-        OUTPUT_VARIABLE GIT_BRANCH)
-
-    string(STRIP "${GIT_REV}" GIT_REV)
-    string(SUBSTRING "${GIT_REV}" 1 7 GIT_REV)
-    string(STRIP "${GIT_DIFF}" GIT_DIFF)
-    string(STRIP "${GIT_TAG}" GIT_TAG)
-    string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
-endif()
-
-set(VERSION "const char* GIT_REV=\"${GIT_REV}${GIT_DIFF}\";
-const char* GIT_TAG=\"${GIT_TAG}\";
-const char* GIT_BRANCH=\"${GIT_BRANCH}\";")
-
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
-    file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
-else()
-    set(VERSION_ "")
-endif()
-
-if (NOT "${VERSION}" STREQUAL "${VERSION_}")
-    file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
-endif()

+ 4 - 0
code/src/version.cpp

@@ -0,0 +1,4 @@
+const char* GIT_REV="d428abc";
+const char* GIT_TAG="";
+const char* GIT_BRANCH="rolling";
+const char* BUILD_TIME="2020-09-26 18:56";

+ 38 - 0
code/src/version.h

@@ -0,0 +1,38 @@
+// These variables are autogenerated and compiled
+// into the library by the version.cmake script
+extern "C"
+{
+    extern const char* GIT_TAG;
+    extern const char* GIT_REV;
+    extern const char* GIT_BRANCH;
+    extern const char* BUILD_TIME;
+}
+
+const char* GIT_BASE_BRANCH = "master - v2.1.0 - 2020-09-25";
+
+
+const char* git_base_branch(void)
+{
+    return GIT_BASE_BRANCH;
+}
+
+
+const char* build_time(void)
+{
+    return BUILD_TIME;
+}
+
+const char* libfive_git_version(void)
+{
+    return GIT_TAG;
+}
+
+const char* libfive_git_revision(void)
+{
+    return GIT_REV;
+}
+
+const char* libfive_git_branch(void)
+{
+    return GIT_BRANCH;
+}

+ 4 - 0
code/version.cpp

@@ -0,0 +1,4 @@
+const char* GIT_REV="d428abc";
+const char* GIT_TAG="";
+const char* GIT_BRANCH="rolling";
+const char* BUILD_TIME="2020-09-26 18:56";

BIN
firmware/bootloader.bin


BIN
firmware/firmware.bin


BIN
firmware/html.zip


+ 1 - 0
sd-card/html/index.html

@@ -93,6 +93,7 @@ li.dropdown {
       <a href="#"onclick="document.getElementById('maincontent').src = '/ota_page.html';">OTA Update</a>
       <a href="#"onclick="document.getElementById('maincontent').src = '/fileserver/log.txt';">Log Viewer</a>      
       <a href="#"onclick="document.getElementById('maincontent').src = '/reboot_page.html';">Reboot</a>
+      <a href="#"onclick="document.getElementById('maincontent').src = '/info.html';">Info</a>      
     </div> 
 </ul>
 <p>

+ 79 - 0
sd-card/html/info.html

@@ -0,0 +1,79 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Set PreValue</title>
+<meta charset="utf-8">
+	
+<style>
+h1 {font-size: 2em;}
+h2 {font-size: 1.5em;}
+h3 {font-size: 1.2em;}
+p {font-size: 1em;}
+
+div {
+	width: 250px;
+    padding: 10px 5px;
+    border: 1px solid #ccc;
+	font-family: arial;
+    font-size: 16px;
+	max-height: 35px;	
+}
+
+</style>	
+	
+</head>
+
+
+
+<body style="font-family: arial; padding: 0px 10px;">
+<h3>Version Info</h3>
+
+<table style="font-family: arial">
+  <tr>
+	<td>
+		Git-Branch:
+	</td>
+	<td>
+		<div id="gitbranch">
+			<object data="/version?type=GitBranch"></object>
+		</div>
+	</td>
+  </tr>	
+
+  <tr>
+	<td>
+		Git-Base-Branch:
+	</td>
+	<td>
+		<div>
+			<object data="/version?type=GitBaseBranch"></object>
+		</div>
+	</td>
+  </tr>	
+
+  <tr>
+	<td>
+		Git-Version:
+	</td>
+	<td>
+		<div>
+			<object data="/version?type=GitVersion"></object>
+		</div>
+	</td>
+  </tr>	
+
+  <tr>
+	<td>
+		Build Time:
+	</td>
+	<td>
+		<div>
+			<object data="/version?type=BuildTime"></object>
+		</div>
+	</td>
+  </tr>
+</table>
+
+
+</body>
+</html>