added backend implementation of the last scheduled event execute
This commit is contained in:
parent
a5c32d884f
commit
41f7e8ff6e
|
|
@ -1,4 +1,6 @@
|
||||||
objects_dscr = ["object_1", "object_2", "object_3", "object_4", "object_5", "object_6", "object_7", "object_8", "object_9", "object_10", "object_11", "object_12", "object_13", "object_14", "object_15", "object_16"];
|
objects_dscr = ["object_1", "object_2", "object_3", "object_4", "object_5", "object_6",
|
||||||
|
"object_7", "object_8", "object_9", "object_10", "object_11", "object_12", "object_13",
|
||||||
|
"object_14", "object_15", "object_16"];
|
||||||
actions_dscr = ["action_1", "action_2", "action_3", "action_4"];
|
actions_dscr = ["action_1", "action_2", "action_3", "action_4"];
|
||||||
|
|
||||||
function PostData(data,page,conf,alrt,reld) {
|
function PostData(data,page,conf,alrt,reld) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit abd7941e2750c1873173fc9bff53d6264406ac1f
|
Subproject commit 832bd3e6236fc7eb9fe3a02b2625bd4dee0c2444
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
idf:
|
idf:
|
||||||
component_hash: null
|
component_hash: null
|
||||||
source:
|
source:
|
||||||
type: idf
|
type: idf
|
||||||
version: 5.0.1
|
version: 4.4.4
|
||||||
manifest_hash: cc4f7a08a6eeed39d05fbfb84ff3df9215bdf0009945794b887b5e99cbaee95b
|
manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd
|
||||||
target: esp32
|
target: esp32
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,20 @@
|
||||||
#define TIMER_CRONSTRING_LENGTH (32)
|
#define TIMER_CRONSTRING_LENGTH (32)
|
||||||
#define CRON_EXPRESS_MAX_LENGTH (128)
|
#define CRON_EXPRESS_MAX_LENGTH (128)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cron scheduler configuration structure
|
||||||
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int num;
|
int num; /*!< Index of sheduler */
|
||||||
bool enab;
|
bool del; /*!< Flag of non valid record, free for future overwrite */
|
||||||
char name[TIMER_NAME_LENGTH];
|
bool enab; /*!< Enable scheduler */
|
||||||
int obj;
|
bool prev; /*!< Enable to execute nearest in the past sheduled action */
|
||||||
int act;
|
char name[TIMER_NAME_LENGTH]; /*!< Human readable name of scheduler */
|
||||||
char cron[TIMER_CRONSTRING_LENGTH];
|
int obj; /*!< Index of object scheduler affected on */
|
||||||
bool del;
|
int act; /*!< Index of action with the object*/
|
||||||
|
char cron[TIMER_CRONSTRING_LENGTH]; /*!< Cron expression */
|
||||||
|
|
||||||
} cron_timer_t;
|
} cron_timer_t;
|
||||||
|
|
||||||
typedef struct appconf
|
typedef struct appconf
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,11 @@ esp_err_t ReloadCronSheduler();
|
||||||
char* GetCronError();
|
char* GetCronError();
|
||||||
void DebugTimer();
|
void DebugTimer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Handle all actions under all objects
|
||||||
|
* \param obj Index of the object
|
||||||
|
* \param act Index of the action
|
||||||
|
*/
|
||||||
|
void custom_cron_execute(int obj, int act);
|
||||||
|
|
||||||
#endif /* MAIN_INCLUDE_CRONTIMERS_H_ */
|
#endif /* MAIN_INCLUDE_CRONTIMERS_H_ */
|
||||||
|
|
|
||||||
|
|
@ -116,12 +116,14 @@ void ResetAppConfig(APP_CONFIG *Conf)
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
|
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
|
||||||
{
|
{
|
||||||
GetAppConf()->Timers[i].num = i+1;
|
GetAppConf()->Timers[i].num = i+1;
|
||||||
GetAppConf()->Timers[i].enab = true;
|
GetAppConf()->Timers[i].del = true;
|
||||||
|
GetAppConf()->Timers[i].enab = false;
|
||||||
|
GetAppConf()->Timers[i].prev = false;
|
||||||
GetAppConf()->Timers[i].obj = 0;
|
GetAppConf()->Timers[i].obj = 0;
|
||||||
GetAppConf()->Timers[i].act = 0;
|
GetAppConf()->Timers[i].act = 0;
|
||||||
strcpy(GetAppConf()->Timers[i].name, "Timer Name");
|
strcpy(GetAppConf()->Timers[i].name, "Timer Name");
|
||||||
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
|
||||||
GetAppConf()->Timers[i].del = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,27 @@
|
||||||
|
|
||||||
#define TAG "CRON_TIMER"
|
#define TAG "CRON_TIMER"
|
||||||
|
|
||||||
|
const char *cron_objects[] = { "RELAY1", "RELAY2", "RELAY3", "RELAY4", "RELAY5", "SYSTEM" };
|
||||||
|
const char *cron_actions[] = { "ON", "OFF", "REBOOT" };
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
char* GetCronError()
|
char* GetCronError()
|
||||||
{
|
{
|
||||||
return cron_express_error;
|
return cron_express_error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Handle all actions under all objects
|
||||||
|
* \param obj Index of the object
|
||||||
|
* \param act Index of the action
|
||||||
|
*/
|
||||||
|
void custom_cron_execute(int obj, int act)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void custom_cron_job_callback(cron_job *job)
|
void custom_cron_job_callback(cron_job *job)
|
||||||
|
|
@ -41,7 +56,8 @@ void custom_cron_job_callback(cron_job *job)
|
||||||
//here call all timers jobs depends on object and action
|
//here call all timers jobs depends on object and action
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
ESP_LOGI(TAG, "Executed timer '%s' action %d under object %d at time %d", name, act, obj, (unsigned int)now);
|
ESP_LOGI(TAG, "Executed timer '%s' action %d under object %d at time %d", name, act, obj, (unsigned int )now);
|
||||||
|
custom_cron_execute(obj, act);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,26 +76,66 @@ const char* check_expr(const char *expr)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ExecuteLastAction()
|
||||||
|
{
|
||||||
|
int obj;
|
||||||
|
for (obj = 0; obj < sizeof(cron_objects); obj++)
|
||||||
|
{
|
||||||
|
int shdl;
|
||||||
|
time_t now;
|
||||||
|
time(&now);
|
||||||
|
time_t delta = now;
|
||||||
|
int act = -1;
|
||||||
|
|
||||||
|
for (shdl = 0; shdl < CRON_TIMERS_NUMBER; shdl++)
|
||||||
|
{
|
||||||
|
if (GetAppConf()->Timers[shdl].enab &&
|
||||||
|
!GetAppConf()->Timers[shdl].del &&
|
||||||
|
GetAppConf()->Timers[shdl].obj == obj)
|
||||||
|
{
|
||||||
|
cron_expr cron_exp = { 0 };
|
||||||
|
cron_parse_expr(GetAppConf()->Timers[shdl].cron, &cron_exp, NULL);
|
||||||
|
time_t prev = cron_prev(&cron_exp, now);
|
||||||
|
if ((now - prev) < delta)
|
||||||
|
{
|
||||||
|
delta = (now - prev);
|
||||||
|
act = GetAppConf()->Timers[shdl].act;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(act != -1)
|
||||||
|
{
|
||||||
|
ESP_LOGW(TAG, "Needed execute lost action %d with object %d", act, obj);
|
||||||
|
custom_cron_execute(obj, act);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TimeObtainHandler(struct timeval *tm)
|
void TimeObtainHandler(struct timeval *tm)
|
||||||
{
|
{
|
||||||
ESP_LOGW(TAG, "Current time received with value %d", (unsigned int )tm->tv_sec);
|
ESP_LOGW(TAG, "Current time received with value %d", (unsigned int )tm->tv_sec);
|
||||||
ReloadCronSheduler();
|
ReloadCronSheduler();
|
||||||
|
ExecuteLastAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DebugTimer()
|
void DebugTimer()
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
ESP_LOGW(TAG, "Timestamp %d", (unsigned int)now);
|
ESP_LOGW(TAG, "Timestamp %d", (unsigned int )now);
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
||||||
{
|
{
|
||||||
if(GetAppConf()->Timers[i].del) continue;
|
if (GetAppConf()->Timers[i].del)
|
||||||
|
continue;
|
||||||
ESP_LOGW(TAG, "Cron expression:%s", GetAppConf()->Timers[i].cron);
|
ESP_LOGW(TAG, "Cron expression:%s", GetAppConf()->Timers[i].cron);
|
||||||
cron_expr cron_exp = {0};
|
cron_expr cron_exp = { 0 };
|
||||||
cron_parse_expr(GetAppConf()->Timers[i].cron, &cron_exp, NULL);
|
cron_parse_expr(GetAppConf()->Timers[i].cron, &cron_exp, NULL);
|
||||||
ESP_LOGW(TAG, "Timer %d prev: %u", i, (unsigned int)cron_prev(&cron_exp, now));
|
ESP_LOGW(TAG, "Timer %d prev: %u", i, (unsigned int )cron_prev(&cron_exp, now));
|
||||||
ESP_LOGW(TAG, "Timer %d next: %u", i, (unsigned int)cron_next(&cron_exp, now));
|
ESP_LOGW(TAG, "Timer %d next: %u", i, (unsigned int )cron_next(&cron_exp, now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2658
webguiapp.doxyfile
Normal file
2658
webguiapp.doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user