restored backward scheduler execution, need debug

This commit is contained in:
Bogdan Pilyugin 2023-10-10 16:37:20 +02:00
parent 62ccd1bb41
commit cc46ae2150
3 changed files with 40 additions and 39 deletions

View File

@ -39,5 +39,9 @@ int ExecCommand(char *cmd);
void GetObjectsInfo(char *data); void GetObjectsInfo(char *data);
void SetCustomObjects(obj_struct_t *obj); void SetCustomObjects(obj_struct_t *obj);
obj_struct_t* GetSystemObjects();
obj_struct_t* GetCustomObjects();
#endif /* COMPONENTS_WEBGUIAPP_INCLUDE_COMMANDPROCSYS_H_ */ #endif /* COMPONENTS_WEBGUIAPP_INCLUDE_COMMANDPROCSYS_H_ */

View File

@ -37,13 +37,8 @@ const char *exec_errors[] = {
"handler not set" "handler not set"
}; };
static int ExecCommandParse(char *cmd);
int (*CustomExecCommand)(char *cmd); static int ExecCommandParse(char *cmd);
void regCustomExecCommand(int (*custom_exec)(char *cmd))
{
CustomExecCommand = custom_exec;
}
static void SYSTEM_TEST_handle(char *obj, char *com, char *arg) static void SYSTEM_TEST_handle(char *obj, char *com, char *arg)
{ {
@ -88,6 +83,17 @@ const obj_struct_t com_obj_arr[] = {
{ 0 } { 0 }
}; };
obj_struct_t* GetSystemObjects()
{
return com_obj_arr;
}
obj_struct_t* GetCustomObjects()
{
return custom_com_obj_arr;
}
void GetObjectsInfo(char *data) void GetObjectsInfo(char *data)
{ {
struct jWriteControl jwc; struct jWriteControl jwc;

View File

@ -30,13 +30,14 @@
// "exec": "OUTPUTS,TEST,ARGUMENTS" // "exec": "OUTPUTS,TEST,ARGUMENTS"
// }] // }]
// }}},"signature":"6a11b872e8f766673eb82e127b6918a0dc96a42c5c9d184604f9787f3d27bcef"} // }}},"signature":"6a11b872e8f766673eb82e127b6918a0dc96a42c5c9d184604f9787f3d27bcef"}
#include <CronTimers.h> #include <CronTimers.h>
#include "esp_log.h" #include "esp_log.h"
#include "webguiapp.h" #include "webguiapp.h"
#define TAG "CRON_TIMER" #define TAG "CRON_TIMER"
extern obj_struct_t app_com_obj_arr[];
extern obj_struct_t com_obj_arr[];
const char *cron_actions[] = { "ON", "REBOOT", "TOGGLE", "OFF", "VERYLONG_OPERATION" }; const char *cron_actions[] = { "ON", "REBOOT", "TOGGLE", "OFF", "VERYLONG_OPERATION" };
const char *cron_objects[] = { const char *cron_objects[] = {
@ -88,7 +89,6 @@ char* GetCronActAvail(int idx)
return (char*) cron_act_avail[idx]; return (char*) cron_act_avail[idx];
} }
static cron_job *JobsList[CRON_TIMERS_NUMBER]; static cron_job *JobsList[CRON_TIMERS_NUMBER];
static char cron_express_error[CRON_EXPRESS_MAX_LENGTH]; static char cron_express_error[CRON_EXPRESS_MAX_LENGTH];
@ -105,25 +105,11 @@ char* GetCronError()
void custom_cron_execute(int obj, int act) void custom_cron_execute(int obj, int act)
{ {
} }
void custom_cron_job_callback(cron_job *job) void custom_cron_job_callback(cron_job *job)
{ {
ExecCommand(((cron_timer_t*) job->data)->exec); ExecCommand(((cron_timer_t*) job->data)->exec);
/*
int act = ((cron_timer_t*) job->data)->act;
int obj = ((cron_timer_t*) job->data)->obj;
char *name = ((cron_timer_t*) job->data)->name;
//here call all timers jobs depends on object and action
time_t now;
time(&now);
ESP_LOGI(TAG, "Execute scheduler '%s' action %d under object %d at time %d", name, act, obj, (unsigned int )now);
LogFile("cron.log", "Executed sheduler with action %u under object %u", act, obj);
custom_cron_execute(obj, act);
return;
*/
} }
esp_err_t InitCronSheduler() esp_err_t InitCronSheduler()
@ -141,24 +127,30 @@ const char* check_expr(const char *expr)
return err; return err;
} }
static void ExecuteLastAction() static void ExecuteLastAction()
{ {
int obj; int obj;
for (obj = 0; obj < sizeof(cron_objects); obj++) for (obj = 0; obj < CONFIG_WEBGUIAPP_MAX_OBJECTS_NUM; obj++)
{ {
int shdl; int shdl;
time_t now; time_t now;
time(&now); time(&now);
time_t delta = now; time_t delta = now;
int act = -1; int act = -1;
int minimal = -1;
char *obj = GetSystemObjects()->object_name;
for (shdl = 0; shdl < CRON_TIMERS_NUMBER; shdl++) for (shdl = 0; shdl < CRON_TIMERS_NUMBER; shdl++)
{ {
char *obj_in_cron = strtok(GetSysConf()->Timers[shdl].exec, ',');
if (GetSysConf()->Timers[shdl].enab && if (GetSysConf()->Timers[shdl].enab &&
!GetSysConf()->Timers[shdl].del && !GetSysConf()->Timers[shdl].del &&
GetSysConf()->Timers[shdl].prev && GetSysConf()->Timers[shdl].prev &&
GetSysConf()->Timers[shdl].obj == obj) !strcmp(obj, obj_in_cron))
{ {
cron_expr cron_exp = { 0 }; cron_expr cron_exp = { 0 };
cron_parse_expr(GetSysConf()->Timers[shdl].cron, &cron_exp, NULL); cron_parse_expr(GetSysConf()->Timers[shdl].cron, &cron_exp, NULL);
@ -166,16 +158,15 @@ static void ExecuteLastAction()
if ((now - prev) < delta) if ((now - prev) < delta)
{ {
delta = (now - prev); delta = (now - prev);
act = GetSysConf()->Timers[shdl].act; minimal = shdl;
} }
} }
} }
if(act != -1) if (shdl != -1)
{ {
ESP_LOGW(TAG, "Execute last action %d with object %d", act, obj);
LogFile("cron.log", "Execute last action %d under object %d", act, obj); ExecCommand(GetSysConf()->Timers[shdl].exec);
custom_cron_execute(obj, act);
} }
} }
} }