Răsfoiți Sursa

Merge pull request #1033 from caco3/auto-add-version

Auto add version
jomjol 3 ani în urmă
părinte
comite
45c9914efa

+ 0 - 2
code/CMakeLists.txt

@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.13.4)
 
 
 list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
 list(APPEND EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common)
 
 
-set(PROJECT_VER "0.0.9.3")
-
 ADD_CUSTOM_COMMAND(
 ADD_CUSTOM_COMMAND(
     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
            ${CMAKE_CURRENT_BINARY_DIR}/_version.cpp
            ${CMAKE_CURRENT_BINARY_DIR}/_version.cpp

+ 2 - 0
code/main/CMakeLists.txt

@@ -39,6 +39,7 @@ set(VERSION "const char* GIT_REV=\"${GIT_REV}${GIT_DIFF}\";
 const char* GIT_TAG=\"${GIT_TAG}\";
 const char* GIT_TAG=\"${GIT_TAG}\";
 const char* GIT_BRANCH=\"${GIT_BRANCH}\";
 const char* GIT_BRANCH=\"${GIT_BRANCH}\";
 const char* BUILD_TIME=\"${BUILD_TIME}\";")
 const char* BUILD_TIME=\"${BUILD_TIME}\";")
+set(VERSION_HTML "${GIT_BRANCH}, ${GIT_REV}${GIT_DIFF}, ${GIT_TAG}")
 
 
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
     file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
     file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
@@ -48,6 +49,7 @@ endif()
 
 
 if (NOT "${VERSION}" STREQUAL "${VERSION_}")
 if (NOT "${VERSION}" STREQUAL "${VERSION_}")
     file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
     file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
+    file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/../sd-card/html/version.txt "${VERSION_HTML}")
 endif()
 endif()
 #######################################################################
 #######################################################################
 #######################################################################
 #######################################################################

+ 13 - 1
code/main/main.cpp

@@ -29,6 +29,11 @@
 #include "server_camera.h"
 #include "server_camera.h"
 #include "Helper.h"
 #include "Helper.h"
 
 
+extern const char* GIT_TAG;
+extern const char* GIT_REV;
+extern const char* GIT_BRANCH;
+extern const char* BUILD_TIME;
+
 // #include "jomjol_WS2812Slow.h"
 // #include "jomjol_WS2812Slow.h"
 #include "SmartLeds.h"
 #include "SmartLeds.h"
 
 
@@ -133,6 +138,12 @@ void task_NoSDBlink(void *pvParameter)
 extern "C" void app_main(void)
 extern "C" void app_main(void)
 {
 {
     TickType_t xDelay;
     TickType_t xDelay;
+    string versionFormated = "Branch: '" + std::string(GIT_BRANCH) + "', Tag: '" + std::string(GIT_TAG) + \
+            "', Revision: " + std::string(GIT_REV) +", Date/Time: " + std::string(BUILD_TIME);
+
+    printf("=============================================================================================\n");
+    printf("%s\n", versionFormated.c_str());
+    printf("=============================================================================================\n");
 
 
     PowerResetCamera();
     PowerResetCamera();
     esp_err_t cam = Camera.InitCam();
     esp_err_t cam = Camera.InitCam();
@@ -179,7 +190,8 @@ extern "C" void app_main(void)
     setBootTime();
     setBootTime();
     LogFile.WriteToFile("=============================================================================================");
     LogFile.WriteToFile("=============================================================================================");
     LogFile.WriteToFile("=================================== Main Started ============================================");
     LogFile.WriteToFile("=================================== Main Started ============================================");
-    LogFile.WriteToFile("=============================================================================================");
+    LogFile.WriteToFile("=============================================================================================");    
+    LogFile.WriteToFile(versionFormated);
     LogFile.SwitchOnOff(false);
     LogFile.SwitchOnOff(false);
 
 
     std::string zw = gettimestring("%Y%m%d-%H%M%S");
     std::string zw = gettimestring("%Y%m%d-%H%M%S");

+ 7 - 3
code/main/server_main.cpp

@@ -82,7 +82,9 @@ esp_err_t info_get_handler(httpd_req_t *req)
 
 
     if (_task.compare("GitBaseBranch") == 0)
     if (_task.compare("GitBaseBranch") == 0)
     {
     {
-        httpd_resp_sendstr_chunk(req, git_base_branch());
+        string buf = "Branch: '" + std::string(GIT_BRANCH) + "', Tag: '" + std::string(GIT_TAG) + \
+            "', Revision: " + std::string(GIT_REV);
+        httpd_resp_sendstr_chunk(req, buf.c_str());
         httpd_resp_sendstr_chunk(req, NULL);  
         httpd_resp_sendstr_chunk(req, NULL);  
         return ESP_OK;        
         return ESP_OK;        
     }
     }
@@ -285,7 +287,8 @@ esp_err_t sysinfo_handler(httpd_req_t *req)
     std::string gitversion = libfive_git_version();
     std::string gitversion = libfive_git_version();
     std::string buildtime = build_time();
     std::string buildtime = build_time();
     std::string gitbranch = libfive_git_branch();
     std::string gitbranch = libfive_git_branch();
-    std::string gitbasebranch = git_base_branch();
+    std::string gittag = libfive_git_version();
+    std::string gitrevision = libfive_git_revision();
     std::string htmlversion = getHTMLversion();
     std::string htmlversion = getHTMLversion();
     char freeheapmem[11];
     char freeheapmem[11];
     sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
     sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
@@ -300,7 +303,8 @@ esp_err_t sysinfo_handler(httpd_req_t *req)
                 \"firmware\" : \"" + gitversion + "\",\
                 \"firmware\" : \"" + gitversion + "\",\
                 \"buildtime\" : \"" + buildtime + "\",\
                 \"buildtime\" : \"" + buildtime + "\",\
                 \"gitbranch\" : \"" + gitbranch + "\",\
                 \"gitbranch\" : \"" + gitbranch + "\",\
-                \"gitbasebranch\" : \"" + gitbasebranch + "\",\
+                \"gittag\" : \"" + gittag + "\",\
+                \"gitrevision\" : \"" + gitrevision + "\",\
                 \"html\" : \"" + htmlversion + "\",\
                 \"html\" : \"" + htmlversion + "\",\
                 \"cputemp\" : \"" + cputemp + "\",\
                 \"cputemp\" : \"" + cputemp + "\",\
                 \"hostname\" : \"" + hostname + "\",\
                 \"hostname\" : \"" + hostname + "\",\

+ 8 - 11
code/main/version.h

@@ -1,3 +1,6 @@
+#ifndef _VERSION_H
+#define _VERSION_H
+
 // These variables are autogenerated and compiled
 // These variables are autogenerated and compiled
 // into the library by the version.cmake script
 // into the library by the version.cmake script
 extern "C"
 extern "C"
@@ -13,14 +16,6 @@ extern "C"
 #include "Helper.h"
 #include "Helper.h"
 #include <fstream>
 #include <fstream>
 
 
-const char* GIT_BASE_BRANCH = "master - v11.3.0 - 2022-09-16";
-
-
-const char* git_base_branch(void)
-{
-    return GIT_BASE_BRANCH;
-}
-
 
 
 const char* build_time(void)
 const char* build_time(void)
 {
 {
@@ -43,7 +38,7 @@ const char* libfive_git_branch(void)
 }
 }
 
 
 
 
-char _char_getHTMLversion[20]="NaN\0";
+char _char_getHTMLversion[50]="NaN\0";
 
 
 const char* getHTMLversion(void){
 const char* getHTMLversion(void){
     FILE* pFile;
     FILE* pFile;
@@ -53,8 +48,10 @@ const char* getHTMLversion(void){
     if (pFile == NULL)
     if (pFile == NULL)
         return _char_getHTMLversion;
         return _char_getHTMLversion;
 
 
-    fgets(_char_getHTMLversion, 20, pFile);
+    fgets(_char_getHTMLversion, sizeof(_char_getHTMLversion), pFile);
     fclose(pFile);
     fclose(pFile);
 
 
     return _char_getHTMLversion;
     return _char_getHTMLversion;
-}
+}
+
+#endif // _VERSION_H

+ 25 - 0
sd-card/html/common.js

@@ -29,3 +29,28 @@ function LoadHostname() {
 //               alert("Loading Hostname failed");
 //               alert("Loading Hostname failed");
     }
     }
 }
 }
+
+
+function LoadVersion() {
+    _basepath = getbasepath(); 
+
+    var xhttp = new XMLHttpRequest();
+    xhttp.addEventListener('load', function(event) {
+        if (xhttp.status >= 200 && xhttp.status < 300) {
+            version = xhttp.responseText;
+            document.getElementById("Version").innerHTML  = version;
+        } 
+        else {
+                console.warn(request.statusText, request.responseText);
+        }
+    });
+
+    try {
+            url = _basepath + '/version?type=GitBaseBranch';     
+            xhttp.open("GET", url, true);
+            xhttp.send();
+
+    }
+    catch (error)
+    {}
+}

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

@@ -151,8 +151,11 @@ li.dropdown {
 
 
 <iframe name="maincontent" class="iframe" id="maincontent" src="wasserzaehler_roi.html"></iframe>
 <iframe name="maincontent" class="iframe" id="maincontent" src="wasserzaehler_roi.html"></iframe>
 
 
+<span id="Version" style="font-size: 10px; margin-top: -5px">Loading version...</span>
+
 <script type="text/javascript">
 <script type="text/javascript">
   LoadHostname();
   LoadHostname();
+  LoadVersion();
 </script>
 </script>
 
 
 </div>
 </div>

+ 4 - 0
sd-card/html/index_configure.html

@@ -152,11 +152,15 @@ li.dropdown {
 
 
 <iframe name="maincontent" class="iframe" id="maincontent" src="edit_config_param.html"></iframe>
 <iframe name="maincontent" class="iframe" id="maincontent" src="edit_config_param.html"></iframe>
 
 
+<span id="Version" style="font-size: 10px; margin-top: -5px">Loading version...</span>
+
 <script type="text/javascript" src="common.js"></script>
 <script type="text/javascript" src="common.js"></script>
 <script type="text/javascript" src="gethost.js"></script>
 <script type="text/javascript" src="gethost.js"></script>
 
 
+
 <script type="text/javascript">
 <script type="text/javascript">
   LoadHostname();
   LoadHostname();
+  LoadVersion();
 </script>
 </script>
 
 
 </div>
 </div>

+ 5 - 5
sd-card/html/info.html

@@ -12,7 +12,7 @@ h3 {font-size: 1.2em;}
 p {font-size: 1em;}
 p {font-size: 1em;}
 
 
 div {
 div {
-	width: 250px;
+	width: 350px;
     padding: 10px 5px;
     padding: 10px 5px;
     border: 1px solid #ccc;
     border: 1px solid #ccc;
 	font-family: arial;
 	font-family: arial;
@@ -93,22 +93,22 @@ div {
 
 
   <tr>
   <tr>
 	<td>
 	<td>
-		Git-Base-Branch:
+		Git-Tag:
 	</td>
 	</td>
 	<td>
 	<td>
 		<div>
 		<div>
-			<object data="/version?type=GitBaseBranch"></object>
+			<object data="/version?type=GitTag"></object>
 		</div>
 		</div>
 	</td>
 	</td>
   </tr>
   </tr>
 
 
   <tr>
   <tr>
 	<td>
 	<td>
-		Git-Version:
+		Git-Revision:
 	</td>
 	</td>
 	<td>
 	<td>
 		<div>
 		<div>
-			<object data="/version?type=GitVersion"></object>
+			<object data="/version?type=GitRevision"></object>
 		</div>
 		</div>
 	</td>
 	</td>
   </tr>
   </tr>

+ 2 - 1
sd-card/html/version.txt

@@ -1 +1,2 @@
-16.4.1
+# HTML version
+# Do not edit, it will get be updated by cmake!