as requested; allow users to change boot success mark time - part 1

This commit is contained in:
openshwprojects
2022-06-07 00:11:38 +02:00
parent 6e6d9ecbee
commit 35470c431c
7 changed files with 72 additions and 5 deletions

View File

@@ -1159,6 +1159,7 @@ int http_fn_cfg(http_request_t *request) {
poststr(request,htmlHeader);
poststr(request,g_header);
poststr(request,"<form action=\"cfg_pins\"><input type=\"submit\" value=\"Configure Module\"/></form>");
poststr(request,"<form action=\"cfg_generic\"><input type=\"submit\" value=\"Configure General\"/></form>");
poststr(request,"<form action=\"cfg_quick\"><input type=\"submit\" value=\"Quick Config\"/></form>");
poststr(request,"<form action=\"cfg_wifi\"><input type=\"submit\" value=\"Configure WiFi\"/></form>");
poststr(request,"<form action=\"cfg_mqtt\"><input type=\"submit\" value=\"Configure MQTT\"/></form>");
@@ -1321,6 +1322,42 @@ int http_fn_cfg_pins(http_request_t *request) {
return 0;
}
int http_fn_cfg_generic(http_request_t *request) {
int iChanged = 0;
int iChangedRequested = 0;
int i;
char tmpA[128];
char tmpB[64];
http_setup(request, httpMimeTypeHTML);
poststr(request,htmlHeader);
poststr(request,g_header);
if( http_getArg(request->url,"boot_ok_delay",tmpA,sizeof(tmpA))) {
i = atoi(tmpA);
if(i <= 0) {
poststr(request,"<h5>Boot ok delay must be at least 1 second<h5>");
i = 1;
}
hprintf128(request,"<h5>Setting boot OK delay to %i<h5>",i);
CFG_SetBootOkSeconds(i);
}
poststr(request,"<form action=\"/cfg_generic\">\
<label for=\"boot_ok_delay\">Uptime seconds required to mark boot as ok:</label><br>\
<input type=\"text\" id=\"boot_ok_delay\" name=\"boot_ok_delay\" value=\"");
hprintf128(request, "%i",CFG_GetBootOkSeconds());
poststr(request,"\"><br>\"");
poststr(request,"<input type=\"submit\" value=\"Save\"/></form>");
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
poststr(request, NULL);
return 0;
}
void XR809_RequestOTAHTTP(const char *s);
int http_fn_ota_exec(http_request_t *request) {

View File

@@ -29,3 +29,4 @@ int http_fn_empty_url(http_request_t *request);
int http_fn_other(http_request_t *request);
int http_fn_cm(http_request_t *request);
int http_fn_startup_command(http_request_t *request);
int http_fn_cfg_generic(http_request_t *request);

View File

@@ -530,6 +530,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
if(http_checkUrlBase(urlStr,"cmd_tool")) return http_fn_cmd_tool(request);
if(http_checkUrlBase(urlStr,"config_dump_table")) return http_fn_config_dump_table(request);
if(http_checkUrlBase(urlStr,"startup_command")) return http_fn_startup_command(request);
if(http_checkUrlBase(urlStr,"cfg_generic")) return http_fn_cfg_generic(request);
if(http_checkUrlBase(urlStr,"cfg_quick")) return http_fn_cfg_quick(request);
if(http_checkUrlBase(urlStr,"cfg_ha")) return http_fn_cfg_ha(request);

View File

@@ -8,6 +8,7 @@
#include "hal/hal_flashConfig.h"
#include "cmnds/cmd_public.h"
#define DEFAULT_BOOT_SUCCESS_TIME 30
mainConfig_t g_cfg;
int g_configInitialized = 0;
@@ -120,6 +121,7 @@ static void CFG_SetDefaultConfig() {
g_cfg.ident0 = CFG_IDENT_0;
g_cfg.ident1 = CFG_IDENT_1;
g_cfg.ident2 = CFG_IDENT_2;
g_cfg.timeRequiredToMarkBootSuccessfull = DEFAULT_BOOT_SUCCESS_TIME;
strcpy(g_cfg.ping_host,"192.168.0.1");
strcpy(g_cfg.mqtt_host, "192.168.0.113");
strcpy(g_cfg.mqtt_brokerName, "test");
@@ -144,6 +146,24 @@ const char *CFG_GetShortStartupCommand() {
return g_cfg.initCommandLine;
}
void CFG_SetBootOkSeconds(int v) {
// at least 1 second, always
if(v < 1)
v = 1;
if(g_cfg.timeRequiredToMarkBootSuccessfull != v) {
g_cfg.timeRequiredToMarkBootSuccessfull = v;
g_cfg_pendingChanges++;
}
}
int CFG_GetBootOkSeconds() {
if(g_configInitialized==0){
return DEFAULT_BOOT_SUCCESS_TIME;
}
if(g_cfg.timeRequiredToMarkBootSuccessfull <= 0) {
return DEFAULT_BOOT_SUCCESS_TIME;
}
return g_cfg.timeRequiredToMarkBootSuccessfull;
}
const char *CFG_GetPingHost() {
return g_cfg.ping_host;
}

View File

@@ -42,7 +42,8 @@ int CFG_GetPingIntervalSeconds();
void CFG_SetPingHost(const char *s);
void CFG_SetPingDisconnectedSecondsToRestart(int i);
void CFG_SetPingIntervalSeconds(int i);
void CFG_SetBootOkSeconds(int v);
int CFG_GetBootOkSeconds();

View File

@@ -118,7 +118,8 @@ typedef struct mainConfig_s {
pinsState_t pins;
byte unusedSectorA[256];
byte unusedSectorB[128];
byte unusedSectorC[56];
byte unusedSectorC[55];
byte timeRequiredToMarkBootSuccessfull;
int ping_interval;
int ping_seconds;
char ping_host[64];

View File

@@ -158,6 +158,7 @@ void CFG_Save_SetupTimer() {
void Main_OnPingCheckerReply(int ms) {
g_timeSinceLastPingReply = 0;
}
int g_bBootMarkedOK = 0;
void Main_OnEverySecond()
{
int bMQTTconnected;
@@ -207,9 +208,14 @@ void Main_OnEverySecond()
}
// when we hit 30s, mark as boot complete.
if (g_secondsElapsed == BOOT_COMPLETE_SECONDS){
HAL_FlashVars_SaveBootComplete();
g_bootFailures = HAL_FlashVars_GetBootFailures();
if(g_bBootMarkedOK==false) {
int bootCompleteSeconds = CFG_GetBootOkSeconds();
if (g_secondsElapsed > bootCompleteSeconds){
ADDLOGF_INFO("Boot complete time reached (%i seconds)\n",bootCompleteSeconds);
HAL_FlashVars_SaveBootComplete();
g_bootFailures = HAL_FlashVars_GetBootFailures();
g_bBootMarkedOK = true;
}
}
if (g_openAP){