moved cron to system
This commit is contained in:
parent
633494b184
commit
d2aa936ace
|
|
@ -1 +1 @@
|
||||||
Subproject commit fcffb19740889a4df6ceb731bd18e9398c6e1067
|
Subproject commit 4ec2b111eb583580e3c7bc0b2b54acbffbfc4090
|
||||||
|
|
@ -24,6 +24,6 @@ dependencies:
|
||||||
path: .
|
path: .
|
||||||
type: git
|
type: git
|
||||||
version: b42825192c6455569f1a047b21140d6d1fe5e4ef
|
version: b42825192c6455569f1a047b21140d6d1fe5e4ef
|
||||||
manifest_hash: de9e4304539f2d9fdf8343990570637f9871f587269fc808dbe52977ba91b213
|
manifest_hash: f2b73d2131559de982a5eb7d9536f35c19e58c3610c8f1b7a1fe1b318cd0090f
|
||||||
target: esp32
|
target: esp32
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@
|
||||||
typedef struct appconf
|
typedef struct appconf
|
||||||
{
|
{
|
||||||
int test;
|
int test;
|
||||||
cron_timer_t Timers[CRON_TIMERS_NUMBER];
|
|
||||||
cron_obj_t CronObjects[CRON_OBJECTS_NUMBER];
|
|
||||||
} APP_CONFIG;
|
} APP_CONFIG;
|
||||||
|
|
||||||
void UserInitIO(void);
|
void UserInitIO(void);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
int HTTPPrintCustom(httpd_req_t *req, char *buf, char *var, int arg);
|
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 TimeObtainHandler(struct timeval *tm);
|
|
||||||
void SaveUserConf();
|
void SaveUserConf();
|
||||||
int ExecAppCommand(char *cmd);
|
int ExecAppCommand(char *cmd);
|
||||||
|
|
||||||
|
|
@ -21,7 +20,7 @@ void app_main(void)
|
||||||
regHTTPPrintCustom(&HTTPPrintCustom);
|
regHTTPPrintCustom(&HTTPPrintCustom);
|
||||||
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
regAfterPostHandlerCustom(&AfterPostHandlerCustom);
|
||||||
regUserEventHandler(&UserMQTTEventHndlr, (void*) my_context_data);
|
regUserEventHandler(&UserMQTTEventHndlr, (void*) my_context_data);
|
||||||
regTimeSyncCallback(&TimeObtainHandler);
|
|
||||||
regCustomSaveConf(&SaveUserConf);
|
regCustomSaveConf(&SaveUserConf);
|
||||||
regCustomExecCommand(&ExecAppCommand);
|
regCustomExecCommand(&ExecAppCommand);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,23 +118,7 @@ void ResetAppConfig(APP_CONFIG *Conf)
|
||||||
{
|
{
|
||||||
//default init test param
|
//default init test param
|
||||||
GetAppConf()->test = 0;
|
GetAppConf()->test = 0;
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++ )
|
|
||||||
{
|
|
||||||
GetAppConf()->Timers[i].num = i+1;
|
|
||||||
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, "* * * * * *");
|
|
||||||
|
|
||||||
}
|
|
||||||
for (int i = 0; i < CRON_OBJECTS_NUMBER; i++ )
|
|
||||||
{
|
|
||||||
strcpy(GetAppConf()->CronObjects[i].objname, GetCronObjectNameDef(i));
|
|
||||||
GetAppConf()->CronObjects[i].idx = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,12 @@ 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, "INPUTS handler command %s with argument %s", com, arg);
|
ESP_LOGI(TAG, "Object:%s, Command:%s, Argument %s",obj, com, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void APPLICATION_TEST2_handle(char *obj, char *com, char *arg)
|
static void APPLICATION_TEST2_handle(char *obj, char *com, char *arg)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "SYSTEM handler command %s with argument %s", com, arg);
|
ESP_LOGI(TAG, "Object:%s, Command:%s, Argument %s",obj, com, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
||||||
|
|
@ -56,57 +56,8 @@ HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, ch
|
||||||
|
|
||||||
static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData)
|
static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData)
|
||||||
{
|
{
|
||||||
char tmp[512];
|
|
||||||
if (httpd_query_key_value(PostData, "tmrec", tmp, sizeof(tmp)) == ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGI("HTTP_POST", "%s", tmp);
|
|
||||||
struct jReadElement result;
|
|
||||||
cron_timer_t T = {0};
|
|
||||||
jRead(tmp, "", &result);
|
|
||||||
if (result.dataType == JREAD_OBJECT)
|
|
||||||
{
|
|
||||||
T.num = jRead_int(tmp, "{'num'", NULL);
|
|
||||||
T.del = jRead_int(tmp, "{'del'", NULL);
|
|
||||||
T.enab = jRead_int(tmp, "{'enab'", NULL);
|
|
||||||
T.prev = jRead_int(tmp, "{'prev'", NULL);
|
|
||||||
jRead_string(tmp, "{'name'", T.name, sizeof(T.name), NULL);
|
|
||||||
T.obj = jRead_int(tmp, "{'obj'", NULL);
|
|
||||||
T.act = jRead_int(tmp, "{'act'", NULL);
|
|
||||||
jRead_string(tmp, "{'cron'", T.cron, sizeof(T.cron), NULL);
|
|
||||||
|
|
||||||
memcpy(&GetAppConf()->Timers[T.num-1], &T, sizeof(cron_timer_t));
|
|
||||||
WriteNVSAppConfig(GetAppConf());
|
|
||||||
ReloadCronSheduler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (httpd_query_key_value(PostData, "deltimer", tmp, sizeof(tmp)) == ESP_OK)
|
|
||||||
{
|
|
||||||
int num = (atoi(tmp) - 1);
|
|
||||||
if(num >= 0 && num < 16)
|
|
||||||
{
|
|
||||||
GetAppConf()->Timers[num].del = true;
|
|
||||||
WriteNVSAppConfig(GetAppConf());
|
|
||||||
ReloadCronSheduler();
|
|
||||||
}
|
|
||||||
return HTTP_IO_DONE;
|
|
||||||
}
|
|
||||||
if (httpd_query_key_value(PostData, "addtimer", tmp, sizeof(tmp)) == ESP_OK)
|
|
||||||
{
|
|
||||||
for(int i = 0; i< CRON_TIMERS_NUMBER; i++)
|
|
||||||
{
|
|
||||||
if(GetAppConf()->Timers[i].del == true)
|
|
||||||
{
|
|
||||||
GetAppConf()->Timers[i].del = false;
|
|
||||||
WriteNVSAppConfig(GetAppConf());
|
|
||||||
ReloadCronSheduler();
|
|
||||||
return HTTP_IO_DONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (httpd_query_key_value(PostData, "tmrdbg", tmp, sizeof(tmp)) == ESP_OK)
|
|
||||||
{
|
|
||||||
DebugTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
return HTTP_IO_DONE;
|
return HTTP_IO_DONE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@
|
||||||
|
|
||||||
static void HTTPPrint_crontmr(char *VarData, void *arg)
|
static void HTTPPrint_crontmr(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
int idx = *((int*)(arg));
|
/*
|
||||||
|
int idx = *((int*)(arg));
|
||||||
if(idx < CRON_TIMERS_NUMBER)
|
if(idx < CRON_TIMERS_NUMBER)
|
||||||
{
|
{
|
||||||
char data[MAX_DYNVAR_LENGTH];
|
char data[MAX_DYNVAR_LENGTH];
|
||||||
|
|
@ -46,14 +47,16 @@ static void HTTPPrint_crontmr(char *VarData, void *arg)
|
||||||
jwClose(&jwc);
|
jwClose(&jwc);
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void HTTPPrint_cronerr(char *VarData, void *arg)
|
static void HTTPPrint_cronerr(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, GetCronError());
|
//snprintf(VarData, MAX_DYNVAR_LENGTH, GetCronError());
|
||||||
}
|
}
|
||||||
static void HTTPPrint_cronobjs(char *VarData, void *arg)
|
static void HTTPPrint_cronobjs(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
char data[MAX_DYNVAR_LENGTH];
|
char data[MAX_DYNVAR_LENGTH];
|
||||||
int idx = *((int*)(arg));
|
int idx = *((int*)(arg));
|
||||||
if(idx < CRON_OBJECTS_NUMBER)
|
if(idx < CRON_OBJECTS_NUMBER)
|
||||||
|
|
@ -66,11 +69,12 @@ static void HTTPPrint_cronobjs(char *VarData, void *arg)
|
||||||
jwClose(&jwc);
|
jwClose(&jwc);
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", data);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
static void HTTPPrint_cronacts(char *VarData, void *arg)
|
static void HTTPPrint_cronacts(char *VarData, void *arg)
|
||||||
{
|
{
|
||||||
int idx = *((int*) (arg));
|
//int idx = *((int*) (arg));
|
||||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "\"%s\"", GetCronActionName(idx));
|
//snprintf(VarData, MAX_DYNVAR_LENGTH, "\"%s\"", GetCronActionName(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,52 +27,6 @@
|
||||||
|
|
||||||
extern APP_CONFIG AppConfig;
|
extern APP_CONFIG AppConfig;
|
||||||
|
|
||||||
static void funct_cronrecs(char *argres, int rw)
|
|
||||||
{
|
|
||||||
struct jWriteControl jwc;
|
|
||||||
jwOpen(&jwc, argres, VAR_MAX_VALUE_LENGTH, JW_ARRAY, JW_COMPACT);
|
|
||||||
for (int idx = 0; idx < CRON_TIMERS_NUMBER; idx++)
|
|
||||||
{
|
|
||||||
cron_timer_t T;
|
|
||||||
memcpy(&T, &GetAppConf()->Timers[idx], sizeof(cron_timer_t));
|
|
||||||
jwArr_object(&jwc);
|
|
||||||
jwObj_int(&jwc, "num", (unsigned int) T.num);
|
|
||||||
jwObj_int(&jwc, "del", (T.del) ? 1 : 0);
|
|
||||||
jwObj_int(&jwc, "enab", (T.enab) ? 1 : 0);
|
|
||||||
jwObj_int(&jwc, "prev", (T.prev) ? 1 : 0);
|
|
||||||
jwObj_string(&jwc, "name", T.name);
|
|
||||||
jwObj_int(&jwc, "obj", (unsigned int) T.obj);
|
|
||||||
jwObj_int(&jwc, "act", (unsigned int) T.act);
|
|
||||||
jwObj_string(&jwc, "cron", T.cron);
|
|
||||||
jwEnd(&jwc);
|
|
||||||
}
|
|
||||||
jwClose(&jwc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void funct_cronobjs(char *argres, int rw)
|
|
||||||
{
|
|
||||||
struct jWriteControl jwc;
|
|
||||||
jwOpen(&jwc, argres, VAR_MAX_VALUE_LENGTH, JW_ARRAY, JW_COMPACT);
|
|
||||||
for (int idx = 0; idx < CRON_OBJECTS_NUMBER; idx++)
|
|
||||||
{
|
|
||||||
jwArr_object(&jwc);
|
|
||||||
jwObj_string(&jwc, "name", GetAppConf()->CronObjects[idx].objname);
|
|
||||||
jwObj_raw(&jwc, "acts", GetCronActAvail(idx));
|
|
||||||
jwEnd(&jwc);
|
|
||||||
}
|
|
||||||
jwClose(&jwc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void funct_cronacts(char *argres, int rw)
|
|
||||||
{
|
|
||||||
struct jWriteControl jwc;
|
|
||||||
jwOpen(&jwc, argres, VAR_MAX_VALUE_LENGTH, JW_ARRAY, JW_COMPACT);
|
|
||||||
for (int idx = 0; idx < CRON_OBJECTS_NUMBER; idx++)
|
|
||||||
{
|
|
||||||
jwArr_string(&jwc, GetCronActionName(idx));
|
|
||||||
}
|
|
||||||
jwClose(&jwc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void funct_time(char *argres, int rw)
|
static void funct_time(char *argres, int rw)
|
||||||
{
|
{
|
||||||
|
|
@ -84,9 +38,6 @@ static void funct_time(char *argres, int rw)
|
||||||
const rest_var_t ApplicationVariables[] =
|
const rest_var_t ApplicationVariables[] =
|
||||||
{
|
{
|
||||||
/*FUNCTIONS*/
|
/*FUNCTIONS*/
|
||||||
{ 0, "cronrecs", &funct_cronrecs, VAR_FUNCT, R, 0, 0 },
|
|
||||||
{ 0, "cronobjs", &funct_cronobjs, VAR_FUNCT, R, 0, 0 },
|
|
||||||
{ 0, "cronacts", &funct_cronacts, VAR_FUNCT, R, 0, 0 },
|
|
||||||
|
|
||||||
{ 0, "mytime", &funct_time, VAR_FUNCT, R, 0, 0 },
|
{ 0, "mytime", &funct_time, VAR_FUNCT, R, 0, 0 },
|
||||||
{ 0, "myvar", &AppConfig.test, VAR_INT, R, 0, 0 }
|
{ 0, "myvar", &AppConfig.test, VAR_INT, R, 0, 0 }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user