cleaned from command processor and cron
This commit is contained in:
parent
bf2210b530
commit
74668607c1
|
|
@ -1 +1 @@
|
||||||
Subproject commit 4ec2b111eb583580e3c7bc0b2b54acbffbfc4090
|
Subproject commit 62ccd1bb416ce1cbe912f6d1661e6341ead94d25
|
||||||
|
|
@ -60,5 +60,6 @@ esp_err_t ResetInitAppConfig(void);
|
||||||
void LoadDefaultReset(void);
|
void LoadDefaultReset(void);
|
||||||
void DelayedRestart(void);
|
void DelayedRestart(void);
|
||||||
void RegAppVariables(void);
|
void RegAppVariables(void);
|
||||||
|
void RegObjects(void);
|
||||||
|
|
||||||
#endif /* MAIN_INCLUDE_APPCONFIGURATION_H_ */
|
#endif /* MAIN_INCLUDE_APPCONFIGURATION_H_ */
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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 UserMQTTEventHndlr(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data);
|
||||||
void SaveUserConf();
|
void SaveUserConf();
|
||||||
int ExecAppCommand(char *cmd);
|
|
||||||
|
|
||||||
const char my_context_data[] = "MyContextDataPassedIntoMQTTHandler";
|
const char my_context_data[] = "MyContextDataPassedIntoMQTTHandler";
|
||||||
|
|
||||||
|
|
@ -20,12 +19,10 @@ void app_main(void)
|
||||||
regHTTPPrintCustom(&HTTPPrintCustom);
|
regHTTPPrintCustom(&HTTPPrintCustom);
|
||||||
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
||||||
regUserEventHandler(&UserMQTTEventHndlr, (void*) my_context_data);
|
regUserEventHandler(&UserMQTTEventHndlr, (void*) my_context_data);
|
||||||
|
|
||||||
regCustomSaveConf(&SaveUserConf);
|
regCustomSaveConf(&SaveUserConf);
|
||||||
regCustomExecCommand(&ExecAppCommand);
|
|
||||||
|
|
||||||
RegAppVariables();
|
RegAppVariables();
|
||||||
|
RegObjects();
|
||||||
|
|
||||||
WebGuiAppInit();
|
WebGuiAppInit();
|
||||||
if (GetUserAppNeedReset())
|
if (GetUserAppNeedReset())
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,6 @@
|
||||||
|
|
||||||
#define TAG "COMMAND_PROC_APP"
|
#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)
|
static void APPLICATION_TEST1_handle(char *obj, char *com, char *arg)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Object:%s, Command:%s, Argument %s",obj, com, 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);
|
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,
|
.index = 0,
|
||||||
.object_name = "APPLICATION",
|
.object_name = "APPLICATION",
|
||||||
.allowed_actions = { "TEST1", "TEST2" },
|
.allowed_actions = { "TEST1", "TEST2" },
|
||||||
.command_handlers = { &APPLICATION_TEST1_handle, &APPLICATION_TEST2_handle }
|
.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;
|
SetCustomObjects((obj_struct_t*) app_com_obj_arr);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1649,6 +1649,14 @@ CONFIG_WEBGUIAPP_SNTP_AUTOUPDATE_PERIOD=3600
|
||||||
CONFIG_WEBGUIAPP_SNTP_TIMEZONE=2
|
CONFIG_WEBGUIAPP_SNTP_TIMEZONE=2
|
||||||
# end of SNTP client settings
|
# 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
|
# CRON settings
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user