added backend implementation of the last scheduled event execute

This commit is contained in:
Bogdan Pilyugin 2023-05-07 16:47:15 +02:00
parent a5c32d884f
commit 41f7e8ff6e
10 changed files with 6691 additions and 2600 deletions

3138
.project

File diff suppressed because it is too large Load Diff

View File

@ -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"];
function PostData(data,page,conf,alrt,reld) {

@ -1 +1 @@
Subproject commit abd7941e2750c1873173fc9bff53d6264406ac1f
Subproject commit 832bd3e6236fc7eb9fe3a02b2625bd4dee0c2444

View File

@ -1,9 +1,9 @@
dependencies:
idf:
component_hash: null
source:
type: idf
version: 5.0.1
manifest_hash: cc4f7a08a6eeed39d05fbfb84ff3df9215bdf0009945794b887b5e99cbaee95b
target: esp32
version: 1.0.0
dependencies:
idf:
component_hash: null
source:
type: idf
version: 4.4.4
manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd
target: esp32
version: 1.0.0

View File

@ -44,15 +44,20 @@
#define TIMER_CRONSTRING_LENGTH (32)
#define CRON_EXPRESS_MAX_LENGTH (128)
/**
* Cron scheduler configuration structure
*/
typedef struct
{
int num;
bool enab;
char name[TIMER_NAME_LENGTH];
int obj;
int act;
char cron[TIMER_CRONSTRING_LENGTH];
bool del;
int num; /*!< Index of sheduler */
bool del; /*!< Flag of non valid record, free for future overwrite */
bool enab; /*!< Enable scheduler */
bool prev; /*!< Enable to execute nearest in the past sheduled action */
char name[TIMER_NAME_LENGTH]; /*!< Human readable name of scheduler */
int obj; /*!< Index of object scheduler affected on */
int act; /*!< Index of action with the object*/
char cron[TIMER_CRONSTRING_LENGTH]; /*!< Cron expression */
} cron_timer_t;
typedef struct appconf

View File

@ -31,4 +31,11 @@ esp_err_t ReloadCronSheduler();
char* GetCronError();
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_ */

View File

@ -116,12 +116,14 @@ void ResetAppConfig(APP_CONFIG *Conf)
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
{
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].act = 0;
strcpy(GetAppConf()->Timers[i].name, "Timer Name");
strcpy(GetAppConf()->Timers[i].cron, "* * * * * *");
GetAppConf()->Timers[i].del = true;
}
}

View File

@ -25,12 +25,27 @@
#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 char cron_express_error[CRON_EXPRESS_MAX_LENGTH];
char* GetCronError()
{
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)
@ -41,7 +56,8 @@ void custom_cron_job_callback(cron_job *job)
//here call all timers jobs depends on object and action
time_t 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;
}
@ -60,26 +76,66 @@ const char* check_expr(const char *expr)
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)
{
ESP_LOGW(TAG, "Current time received with value %d", (unsigned int )tm->tv_sec);
ReloadCronSheduler();
ExecuteLastAction();
}
void DebugTimer()
{
time_t 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++)
{
if(GetAppConf()->Timers[i].del) continue;
if (GetAppConf()->Timers[i].del)
continue;
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);
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 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));
}
}

3369
sdkconfig

File diff suppressed because it is too large Load Diff

2658
webguiapp.doxyfile Normal file

File diff suppressed because it is too large Load Diff