From 74668607c16a740c1d00659220a7b569a7957019 Mon Sep 17 00:00:00 2001 From: bogd Date: Tue, 10 Oct 2023 15:08:54 +0200 Subject: [PATCH] cleaned from command processor and cron --- components/webguiapp | 2 +- main/include/AppConfiguration.h | 1 + main/main.c | 5 +- main/src/CommandProcApp.c | 88 +++++---------------------------- sdkconfig | 8 +++ 5 files changed, 22 insertions(+), 82 deletions(-) diff --git a/components/webguiapp b/components/webguiapp index 4ec2b11..62ccd1b 160000 --- a/components/webguiapp +++ b/components/webguiapp @@ -1 +1 @@ -Subproject commit 4ec2b111eb583580e3c7bc0b2b54acbffbfc4090 +Subproject commit 62ccd1bb416ce1cbe912f6d1661e6341ead94d25 diff --git a/main/include/AppConfiguration.h b/main/include/AppConfiguration.h index 8faae96..d52d9e8 100644 --- a/main/include/AppConfiguration.h +++ b/main/include/AppConfiguration.h @@ -60,5 +60,6 @@ esp_err_t ResetInitAppConfig(void); void LoadDefaultReset(void); void DelayedRestart(void); void RegAppVariables(void); +void RegObjects(void); #endif /* MAIN_INCLUDE_APPCONFIGURATION_H_ */ diff --git a/main/main.c b/main/main.c index 5085545..910ac83 100644 --- a/main/main.c +++ b/main/main.c @@ -11,7 +11,6 @@ int HTTPPrintCustom(httpd_req_t *req, char *buf, char *var, int arg); HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData); void UserMQTTEventHndlr(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data); void SaveUserConf(); -int ExecAppCommand(char *cmd); const char my_context_data[] = "MyContextDataPassedIntoMQTTHandler"; @@ -20,12 +19,10 @@ void app_main(void) regHTTPPrintCustom(&HTTPPrintCustom); regAfterPostHandlerCustom(&AfterPostHandlerCustom); regUserEventHandler(&UserMQTTEventHndlr, (void*) my_context_data); - regCustomSaveConf(&SaveUserConf); - regCustomExecCommand(&ExecAppCommand); RegAppVariables(); - + RegObjects(); WebGuiAppInit(); if (GetUserAppNeedReset()) diff --git a/main/src/CommandProcApp.c b/main/src/CommandProcApp.c index 9a8d4f8..1e2c65f 100644 --- a/main/src/CommandProcApp.c +++ b/main/src/CommandProcApp.c @@ -23,11 +23,6 @@ #define TAG "COMMAND_PROC_APP" -#define OBJECTS_NUMBER_APP (1) -#define EXEC_ACTIONS_MAX_NUMBER_APP (2) - -static int ExecCommandParseApp(char *cmd); - static void APPLICATION_TEST1_handle(char *obj, char *com, char *arg) { ESP_LOGI(TAG, "Object:%s, Command:%s, Argument %s",obj, com, arg); @@ -38,87 +33,26 @@ static void APPLICATION_TEST2_handle(char *obj, char *com, char *arg) ESP_LOGI(TAG, "Object:%s, Command:%s, Argument %s",obj, com, arg); } -typedef struct -{ - int index; - char object_name[EXEC_OBJECT_NAME_MAX_LENGTH]; - char allowed_actions[EXEC_ACTIONS_MAX_NUMBER_APP][EXEC_ACTION_NAME_MAX_LENGTH]; - void (*command_handlers[EXEC_ACTIONS_MAX_NUMBER_APP])(char *obj, char *com, char *arg); -} app_obj_struct_t; -const app_obj_struct_t app_com_obj_arr[] = { +const obj_struct_t app_com_obj_arr[] = { { .index = 0, .object_name = "APPLICATION", .allowed_actions = { "TEST1", "TEST2" }, .command_handlers = { &APPLICATION_TEST1_handle, &APPLICATION_TEST2_handle } - } + }, + { + .index = 0, + .object_name = "APPLICATION2", + .allowed_actions = { "TEST1", "TEST2", "TEST3" }, + .command_handlers = { &APPLICATION_TEST1_handle, &APPLICATION_TEST2_handle } + }, + { 0 } }; -void GetAppObjectsInfo(char *data) +void RegObjects(void) { - struct jWriteControl jwc; - jwOpen(&jwc, data, VAR_MAX_VALUE_LENGTH, JW_ARRAY, JW_COMPACT); - for (int idx = 0; idx < OBJECTS_NUMBER_APP; idx++) - { - jwArr_object(&jwc); - jwObj_string(&jwc, "object", app_com_obj_arr[idx].object_name); - jwObj_array(&jwc, "actions"); - for (int i = 0; i < EXEC_ACTIONS_MAX_NUMBER_APP; i++) - { - if ((app_com_obj_arr[idx].allowed_actions[i])[0] != NULL) - jwArr_string(&jwc, app_com_obj_arr[idx].allowed_actions[i]); - } - jwEnd(&jwc); - jwEnd(&jwc); - } - jwClose(&jwc); + SetCustomObjects((obj_struct_t*) app_com_obj_arr); } -int ExecAppCommand(char *cmd) -{ - return ExecCommandParseApp(cmd); -} - -static int ExecCommandParseApp(char *cmd) -{ - char *obj = NULL, *com = NULL, *arg = NULL; - int err = 0; - int commlen = strlen(cmd); - if (commlen > EXEC_COMMAND_MAX_LENGTH) - return 1; - char comm[EXEC_COMMAND_MAX_LENGTH + 1]; - const char del1 = ','; - const char del2 = 0x00; - strcpy(comm, cmd); - obj = strtok(comm, &del1); - com = strtok(NULL, &del1); - arg = strtok(NULL, &del2); - if (!obj) - return 2; - if (!com) - return 2; - err = 4; - for (int idx = 0; idx < OBJECTS_NUMBER_APP; idx++) - { - if (!strcmp(obj, app_com_obj_arr[idx].object_name)) - { - err = 5; - for (int i = 0; i < EXEC_ACTIONS_MAX_NUMBER_APP; i++) - { - if (!strcmp(com, app_com_obj_arr[idx].allowed_actions[i])) - { - if (app_com_obj_arr[idx].command_handlers[i] != NULL) - { - app_com_obj_arr[idx].command_handlers[i](obj, com, arg); - err = 0; - } - else - err = 6; - } - } - } - } - return err; -} diff --git a/sdkconfig b/sdkconfig index cb9e0bc..94e4ec3 100644 --- a/sdkconfig +++ b/sdkconfig @@ -1649,6 +1649,14 @@ CONFIG_WEBGUIAPP_SNTP_AUTOUPDATE_PERIOD=3600 CONFIG_WEBGUIAPP_SNTP_TIMEZONE=2 # end of SNTP client settings +# +# Command Processor settings +# +CONFIG_WEBGUIAPP_MAX_OBJECTS_NUM=8 +CONFIG_WEBGUIAPP_MAX_COMMANDS_NUM=8 +CONFIG_WEBGUIAPP_MAX_COMMAND_STRING_LENGTH=64 +# end of Command Processor settings + # # CRON settings #