mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 04:58:17 +08:00
TODO 添加下一周的定时任务
This commit is contained in:
@@ -128,10 +128,7 @@ int application_start(void)
|
||||
time_t now = time(NULL);
|
||||
if (task_top && now >= task_top->prs_time)
|
||||
{
|
||||
tc1_log("process task time[%ld] socket_idx[%d] on[%d]",
|
||||
task_top->prs_time, task_top->socket_idx, task_top->on);
|
||||
UserRelaySet(task_top->socket_idx, task_top->on);
|
||||
DelFirstTask();
|
||||
ProcessTask();
|
||||
}
|
||||
mico_thread_msleep(1000);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define ota_log(M, ...) do { custom_log("OTA", M, ##__VA_ARGS__); web_log("OTA", M, ##__VA_ARGS__) } while(0)
|
||||
#define rtc_log(M, ...) do { custom_log("RTC", M, ##__VA_ARGS__); web_log("RTC", M, ##__VA_ARGS__) } while(0)
|
||||
#define tc1_log(M, ...) do { custom_log("TC1", M, ##__VA_ARGS__); web_log("TC1", M, ##__VA_ARGS__) } while(0)
|
||||
#define task_log(M, ...) do { custom_log("TASK", M, ##__VA_ARGS__); web_log("TASK", M, ##__VA_ARGS__) } while(0)
|
||||
#define http_log(M, ...) do { custom_log("HTTP", M, ##__VA_ARGS__); web_log("HTTP", M, ##__VA_ARGS__) } while(0)
|
||||
#define mqtt_log(M, ...) do { custom_log("MQTT", M, ##__VA_ARGS__); web_log("MQTT", M, ##__VA_ARGS__) } while(0)
|
||||
#define wifi_log(M, ...) do { custom_log("WIFI", M, ##__VA_ARGS__); web_log("WIFI", M, ##__VA_ARGS__) } while(0)
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
#include<string.h>
|
||||
#include<stdbool.h>
|
||||
#include<time.h>
|
||||
|
||||
#include"main.h"
|
||||
#include"user_gpio.h"
|
||||
#include"timed_task/timed_task.h"
|
||||
#include"http_server/web_log.h"
|
||||
|
||||
pTimedTask task_top = NULL;
|
||||
int task_count = 0;
|
||||
@@ -46,7 +50,7 @@ bool AddTaskWeek(pTimedTask task)
|
||||
{
|
||||
int day_sec = 86400;
|
||||
time_t now = time(NULL);
|
||||
int today_weekday = (now / day_sec + 3) % 7 + 1; //1970-01-01 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int today_weekday = (now / day_sec + 3) % 7 + 1; //1970-01-01 星期五
|
||||
int next_day = task->weekday - today_weekday;
|
||||
bool next_day_is_today = next_day == 0 && task->prs_time % day_sec > now % day_sec;
|
||||
next_day = next_day > 0 || next_day_is_today ? next_day : next_day + 7;
|
||||
@@ -110,6 +114,26 @@ bool DelTask(int time)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProcessSingle()
|
||||
{
|
||||
UserRelaySet(task_top->socket_idx, task_top->on);
|
||||
DelFirstTask();
|
||||
}
|
||||
|
||||
void ProcessWeek()
|
||||
{
|
||||
//TODO 添加下一周的定时任务
|
||||
ProcessSingle();
|
||||
}
|
||||
|
||||
void ProcessTask()
|
||||
{
|
||||
task_log("process task time[%ld] socket_idx[%d] on[%d]",
|
||||
task_top->prs_time, task_top->socket_idx, task_top->on);
|
||||
if (task_top->weekday == 0) ProcessSingle();
|
||||
else ProcessWeek();
|
||||
}
|
||||
|
||||
char* GetTaskStr()
|
||||
{
|
||||
char* str = (char*)malloc(sizeof(char)*(task_count*80+2));
|
||||
|
||||
@@ -18,4 +18,5 @@ extern int task_count;
|
||||
bool AddTask(pTimedTask task);
|
||||
bool DelTask(int time);
|
||||
bool DelFirstTask();
|
||||
void ProcessTask();
|
||||
char* GetTaskStr();
|
||||
|
||||
Reference in New Issue
Block a user