From d7f14f8c6e63a6df9f82b3c3e997c29ed5c8a6d1 Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Sun, 8 Mar 2020 18:34:29 +0800 Subject: [PATCH] =?UTF-8?q?TODO=20=E6=B7=BB=E5=8A=A0=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E5=91=A8=E7=9A=84=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/main.c | 5 +---- TC1/main.h | 1 + TC1/timed_task/timed_task.c | 26 +++++++++++++++++++++++++- TC1/timed_task/timed_task.h | 1 + 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/TC1/main.c b/TC1/main.c index dea0914..e8f6931 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -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); } diff --git a/TC1/main.h b/TC1/main.h index d4ceb93..9fcab0d 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -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) diff --git a/TC1/timed_task/timed_task.c b/TC1/timed_task/timed_task.c index 1b4d3fb..8c859c2 100644 --- a/TC1/timed_task/timed_task.c +++ b/TC1/timed_task/timed_task.c @@ -3,7 +3,11 @@ #include #include #include + +#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 ÐÇÆÚÎå + 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)); diff --git a/TC1/timed_task/timed_task.h b/TC1/timed_task/timed_task.h index 5b58c5e..a6393a3 100644 --- a/TC1/timed_task/timed_task.h +++ b/TC1/timed_task/timed_task.h @@ -18,4 +18,5 @@ extern int task_count; bool AddTask(pTimedTask task); bool DelTask(int time); bool DelFirstTask(); +void ProcessTask(); char* GetTaskStr();