This commit is contained in:
zogodo
2019-12-26 21:56:05 +08:00
parent 08b4dc8c35
commit 0a6f32c1ac
4 changed files with 12 additions and 11 deletions

View File

@@ -200,7 +200,7 @@ exit:
static int HttpGetTasks(httpd_request_t *req) static int HttpGetTasks(httpd_request_t *req)
{ {
pTimedTask pt = (pTimedTask)malloc(sizeof(struct TimedTask)); pTimedTask pt = (pTimedTask)malloc(sizeof(struct TimedTask));
pt->time = time(NULL) + 5; pt->prs_time = time(NULL) + 5;
pt->socket_idx = 5; pt->socket_idx = 5;
pt->on = 0; pt->on = 0;
AddTask(pt); AddTask(pt);
@@ -220,7 +220,7 @@ static int HttpAddTask(httpd_request_t *req)
char buf[16] = "5 1234567 0"; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>. char buf[16] = "5 1234567 0"; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>.
struct TimedTask task; struct TimedTask task;
sscanf(buf, "%d %d %d", &task.time, &task.socket_idx, &task.on); sscanf(buf, "%ld %d %d", &task.prs_time, &task.socket_idx, &task.on);
char* mess = AddTask(&task) ? "OK" : "NO"; char* mess = AddTask(&task) ? "OK" : "NO";

View File

@@ -170,10 +170,10 @@ int application_start(void)
user_mqtt_hass_power(); user_mqtt_hass_power();
time_t now = time(NULL); time_t now = time(NULL);
if (task_top && now >= task_top->time) if (task_top && now >= task_top->prs_time)
{ {
os_log("process task time[%d] socket_idx[%d] on[%d]", os_log("process task time[%ld] socket_idx[%d] on[%d]",
task_top->time, task_top->socket_idx, task_top->on); task_top->prs_time, task_top->socket_idx, task_top->on);
UserRelaySet(task_top->socket_idx, task_top->on); UserRelaySet(task_top->socket_idx, task_top->on);
DelFirstTask(); DelFirstTask();
} }

View File

@@ -18,7 +18,7 @@ bool AddTask(pTimedTask task)
return true; return true;
} }
if (task->time <= task_top->time) if (task->prs_time <= task_top->prs_time)
{ {
task->next = task_top; task->next = task_top;
task_top = task; task_top = task;
@@ -28,7 +28,7 @@ bool AddTask(pTimedTask task)
pTimedTask tmp = task_top; pTimedTask tmp = task_top;
while (tmp) while (tmp)
{ {
if ((task->time > tmp->time && task->time <= tmp->next->time) if ((task->prs_time > tmp->prs_time && task->prs_time <= tmp->next->prs_time)
|| tmp->next == NULL) || tmp->next == NULL)
{ {
task->next = tmp->next; task->next = tmp->next;
@@ -61,7 +61,7 @@ bool DelTask(int time)
return false; return false;
} }
if (time == task_top->time) if (time == task_top->prs_time)
{ {
pTimedTask tmp = task_top; pTimedTask tmp = task_top;
task_top = task_top->next; task_top = task_top->next;
@@ -78,7 +78,7 @@ bool DelTask(int time)
pTimedTask tmp_tsk = task_top->next; pTimedTask tmp_tsk = task_top->next;
while (tmp_tsk) while (tmp_tsk)
{ {
if (time == tmp_tsk->time) if (time == tmp_tsk->prs_time)
{ {
pre_tsk->next = tmp_tsk->next; pre_tsk->next = tmp_tsk->next;
free(tmp_tsk); free(tmp_tsk);
@@ -101,7 +101,7 @@ char* GetTaskStr()
{ {
char buffer[26]; char buffer[26];
struct tm* tm_info; struct tm* tm_info;
tm_info = localtime(&tmp_tsk->time); tm_info = localtime(&tmp_tsk->prs_time);
strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info); strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
sprintf(tmp_str, "{time:'%s',socket_index:%d,on:%d},", sprintf(tmp_str, "{time:'%s',socket_index:%d,on:%d},",

View File

@@ -1,10 +1,11 @@
#pragma once #pragma once
#include <time.h>
struct TimedTask; struct TimedTask;
typedef struct TimedTask* pTimedTask; typedef struct TimedTask* pTimedTask;
struct TimedTask struct TimedTask
{ {
int time; //被执行的格林尼治时间戳 time_t prs_time; //被执行的格林尼治时间戳
int socket_idx; //要控制的插孔 int socket_idx; //要控制的插孔
int on; //开或者关 int on; //开或者关
pTimedTask next; //下一个任务(按之间排序) pTimedTask next; //下一个任务(按之间排序)