2KB main config structure (NET_PARAM is 4096 so 2048 bytes left free)

This commit is contained in:
openshwprojects
2022-04-17 00:30:45 +02:00
parent 1d8914c3e2
commit eeba31415f
19 changed files with 541 additions and 1498 deletions

View File

@ -9,7 +9,8 @@
#include "../driver/drv_public.h"
#include "../logging/logging.h"
#include "../hal/hal_wifi.h"
#include "../hal/hal_pins.h"
#include "../hal/hal_pins.h"
#include "../hal/hal_flashConfig.h"
#ifdef WINDOWS
// nothing
@ -216,6 +217,7 @@ int http_fn_index(http_request_t *request) {
poststr(request,"<form action=\"about\"><input type=\"submit\" value=\"About\"/></form>");
hprintf128(request,"<h3>Cfg size: %i, change counter: %i, ota counter: %i!</h3>",sizeof(g_cfg),g_cfg.changeCounter,g_cfg.otaCounter);
poststr(request,htmlReturnToMenu);
HTTP_AddBuildFooter(request);
@ -300,14 +302,8 @@ int http_fn_cfg_mqtt_set(http_request_t *request) {
if(http_getArg(request->url,"client",tmpA,sizeof(tmpA))) {
CFG_SetMQTTBrokerName(tmpA);
}
if(CFG_SaveMQTT()) {
poststr(request,"MQTT mode set!");
} else {
poststr(request,"Error saving MQTT settings to flash!");
}
poststr(request,"Please wait for module to connect... if there is problem, restart it...");
poststr(request,"Please wait for module to connect... if there is problem, restart it from Index html page...");
poststr(request,"<br>");
poststr(request,"<a href=\"cfg_mqtt\">Return to MQTT settings</a>");
@ -483,9 +479,9 @@ int http_fn_cfg_wifi_set(http_request_t *request) {
}
poststr(request,"WiFi mode set: connect to WLAN.");
}
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: calling CFG_SaveWiFi \r\n");
CFG_SaveWiFi();
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: done CFG_SaveWiFi \r\n");
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: calling CFG_Save_IfThereArePendingChanges \r\n");
CFG_Save_IfThereArePendingChanges();
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP,"HTTP_ProcessPacket: done CFG_Save_IfThereArePendingChanges \r\n");
poststr(request,"Please wait for module to reset...");
RESET_ScheduleModuleReset(3);
@ -777,16 +773,9 @@ int http_fn_config_dump_table(http_request_t *request) {
http_setup(request, httpMimeTypeHTML);
poststr(request,htmlHeader);
poststr(request,g_header);
#if WINDOWS
poststr(request,"Not implemented <br>");
#elif PLATFORM_XR809
poststr(request,"Not implemented <br>");
#elif PLATFORM_BL602
poststr(request,"Not implemented <br>");
#else
poststr(request,"Dumped to log <br>");
config_dump_table();
#endif
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
@ -1032,7 +1021,7 @@ int http_fn_cfg_pins(http_request_t *request) {
}
}
if(iChangedRequested>0) {
PIN_SaveToFlash();
CFG_Save_IfThereArePendingChanges();
hprintf128(request, "Pins update - %i reqs, %i changed!<br><br>",iChangedRequested,iChanged);
}
// strcat(outbuf,"<button type=\"button\">Click Me!</button>");

View File

@ -535,13 +535,6 @@ static int http_rest_get_seriallog(http_request_t *request){
static int http_rest_get_pins(http_request_t *request){
int i;
/*typedef struct pinsState_s {
byte roles[32];
byte channels[32];
} pinsState_t;
extern pinsState_t g_pins;
*/
http_setup(request, httpMimeTypeJson);
poststr(request, "{\"rolenames\":[");
for (i = 0; i < IOR_Total_Options; i++){
@ -555,17 +548,17 @@ static int http_rest_get_pins(http_request_t *request){
for (i = 0; i < 32; i++){
if (i){
hprintf128(request, ",%d", g_pins.roles[i]);
hprintf128(request, ",%d", g_cfg.pins.roles[i]);
} else {
hprintf128(request, "%d", g_pins.roles[i]);
hprintf128(request, "%d", g_cfg.pins.roles[i]);
}
}
poststr(request, "],\"channels\":[");
for (i = 0; i < 32; i++){
if (i){
hprintf128(request, ",%d", g_pins.channels[i]);
hprintf128(request, ",%d", g_cfg.pins.channels[i]);
} else {
hprintf128(request, "%d", g_pins.channels[i]);
hprintf128(request, "%d", g_cfg.pins.channels[i]);
}
}
poststr(request, "]}");
@ -770,7 +763,7 @@ static int http_rest_post_pins(http_request_t *request){
}
}
if (iChanged){
PIN_SaveToFlash();
CFG_Save_IfThereArePendingChanges();
ADDLOG_DEBUG(LOG_FEATURE_API, "Changed %d - saved to flash", iChanged);
}
@ -911,12 +904,7 @@ static int http_rest_get_flash(http_request_t *request, int startaddr, int len){
static int http_rest_get_dumpconfig(http_request_t *request){
#if PLATFORM_XR809
#elif PLATFORM_BL602
#else
config_dump_table();
#endif
http_setup(request, httpMimeTypeText);
poststr(request, NULL);
@ -937,70 +925,7 @@ ITEM_NEW_TEST_CONFIG testconfig;
#endif
static int http_rest_get_testconfig(http_request_t *request){
#ifdef TESTCONFIG_ENABLE
INFO_ITEM_ST *ret;
int intres;
testconfig.head.type = (UINT32) *((UINT32*)"TEST");
testconfig.head.len = sizeof(testconfig) - sizeof(testconfig.head);
strcpy(testconfig.somename, "test it here");
config_dump_table();
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "search found %x", ret);
config_dump_table();
intres = config_delete_item(testconfig.head.type);
ADDLOG_DEBUG(LOG_FEATURE_API, "delete_item returned %d", intres);
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "search2 found %x len %d", ret, (ret?ret->len:0));
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "search3 found %x len %d", ret, (ret?ret->len:0));
if (ret){
if (os_memcmp(ret, &testconfig, sizeof(testconfig))){
ADDLOG_DEBUG(LOG_FEATURE_API, "content mismatch");
} else {
ADDLOG_DEBUG(LOG_FEATURE_API, "content match");
}
}
testconfig.head.len = sizeof(testconfig) - sizeof(testconfig.head) - 1;
intres = config_save_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "save_item returned %d", intres);
ret = config_search_item((INFO_ITEM_ST *)&testconfig);
ADDLOG_DEBUG(LOG_FEATURE_API, "search4 found %x len %d", ret, (ret?ret->len:0));
config_dump_table();
intres = config_delete_item(testconfig.head.type);
ADDLOG_DEBUG(LOG_FEATURE_API, "delete_item returned %d", intres);
config_dump_table();
config_release_tbl();
config_dump_table();
http_setup(request, httpMimeTypeText);
poststr(request, NULL);
#else
return http_rest_error(request, 400, "unsupported");
#endif
return 0;
}