mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-11 22:16:56 +03:00
Version
This commit is contained in:
@@ -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/*.*)
|
||||
|
||||
@@ -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");
|
||||
LogFile.WriteToFile("info_get_handler");
|
||||
char _query[200];
|
||||
char _valuechar[30];
|
||||
std::string _task;
|
||||
|
||||
/* 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);
|
||||
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");
|
||||
|
||||
/* 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");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
code/src/version.cpp
Normal file
4
code/src/version.cpp
Normal file
@@ -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
code/src/version.h
Normal file
38
code/src/version.h
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user