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)
{
pTimedTask pt = (pTimedTask)malloc(sizeof(struct TimedTask));
pt->time = time(NULL) + 5;
pt->prs_time = time(NULL) + 5;
pt->socket_idx = 5;
pt->on = 0;
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>.
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";

View File

@@ -170,10 +170,10 @@ int application_start(void)
user_mqtt_hass_power();
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]",
task_top->time, task_top->socket_idx, task_top->on);
os_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();
}

View File

@@ -18,7 +18,7 @@ bool AddTask(pTimedTask task)
return true;
}
if (task->time <= task_top->time)
if (task->prs_time <= task_top->prs_time)
{
task->next = task_top;
task_top = task;
@@ -28,7 +28,7 @@ bool AddTask(pTimedTask task)
pTimedTask tmp = task_top;
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)
{
task->next = tmp->next;
@@ -61,7 +61,7 @@ bool DelTask(int time)
return false;
}
if (time == task_top->time)
if (time == task_top->prs_time)
{
pTimedTask tmp = task_top;
task_top = task_top->next;
@@ -78,7 +78,7 @@ bool DelTask(int time)
pTimedTask tmp_tsk = task_top->next;
while (tmp_tsk)
{
if (time == tmp_tsk->time)
if (time == tmp_tsk->prs_time)
{
pre_tsk->next = tmp_tsk->next;
free(tmp_tsk);
@@ -101,7 +101,7 @@ char* GetTaskStr()
{
char buffer[26];
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);
sprintf(tmp_str, "{time:'%s',socket_index:%d,on:%d},",

View File

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