mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 05:28:14 +08:00
添加 删除 定时任务 接口
This commit is contained in:
@@ -214,6 +214,36 @@ exit:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int HttpAddTask(httpd_request_t *req)
|
||||||
|
{
|
||||||
|
//TODO <20><>url<72><6C>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
char buf[16] = "5 1234567 0"; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>.
|
||||||
|
|
||||||
|
TimedTask task;
|
||||||
|
sscanf(buf, "%d %d %d", &task.time, &task.socket_idx, &task.on);
|
||||||
|
|
||||||
|
char mess[] = AddTask(task) ? "OK" : "NO";
|
||||||
|
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
send_http(mess, strlen(mess), exit, &err);
|
||||||
|
exit:
|
||||||
|
}
|
||||||
|
|
||||||
|
static int HttpDelTask(httpd_request_t *req)
|
||||||
|
{
|
||||||
|
//TODO <20><>url<72><6C>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||||
|
char buf[16] = "1234567"; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>.
|
||||||
|
|
||||||
|
int time;
|
||||||
|
sscanf(buf, "%d", &time);
|
||||||
|
|
||||||
|
char mess[] = DelTask(time) ? "OK" : "NO";
|
||||||
|
|
||||||
|
OSStatus err = kNoErr;
|
||||||
|
send_http(mess, strlen(mess), exit, &err);
|
||||||
|
exit:
|
||||||
|
}
|
||||||
|
|
||||||
struct httpd_wsgi_call g_app_handlers[] = {
|
struct httpd_wsgi_call g_app_handlers[] = {
|
||||||
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
{"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, NULL, NULL},
|
||||||
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
{"/socket", HTTPD_HDR_DEFORT, 0, NULL, HttpSetSocketStatus, NULL, NULL},
|
||||||
@@ -222,7 +252,7 @@ struct httpd_wsgi_call g_app_handlers[] = {
|
|||||||
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
|
{"/wifi/config", HTTPD_HDR_DEFORT, 0, HttpGetWifiConfig, HttpSetWifiConfig, NULL, NULL},
|
||||||
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL },
|
{"/wifi/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, NULL, NULL },
|
||||||
{"/log", HTTPD_HDR_DEFORT, 0, HttpGetLog, NULL, NULL, NULL},
|
{"/log", HTTPD_HDR_DEFORT, 0, HttpGetLog, NULL, NULL, NULL},
|
||||||
{"/task", HTTPD_HDR_DEFORT, 0, HttpGetTasks, NULL, NULL, NULL },
|
{"/task", HTTPD_HDR_DEFORT, 0, HttpGetTasks, HttpAddTask, NULL, HttpDelTask },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
|
static int g_app_handlers_no = sizeof(g_app_handlers)/sizeof(struct httpd_wsgi_call);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ bool AddTask(pTimedTask task)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DelTask()
|
bool DelFirstTask()
|
||||||
{
|
{
|
||||||
if (task_top)
|
if (task_top)
|
||||||
{
|
{
|
||||||
@@ -53,6 +53,39 @@ bool DelTask()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DelTask(int time)
|
||||||
|
{
|
||||||
|
if (task_top == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time == task_top->time)
|
||||||
|
{
|
||||||
|
pTimedTask tmp = task_top;
|
||||||
|
task_top = task_top->next;
|
||||||
|
free(task_top);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (task_top->next == NULL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pTimedTask pre_tsk = task_top;
|
||||||
|
pTimedTask tmp_tsk = task_top->next;
|
||||||
|
while (tmp_tsk)
|
||||||
|
{
|
||||||
|
if (time == tmp_tsk->time)
|
||||||
|
{
|
||||||
|
pre_tsk->next = tmp_tsk->next;
|
||||||
|
free(tmp_tsk);
|
||||||
|
}
|
||||||
|
tmp_tsk = tmp_tsk->next;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char* GetTaskStr()
|
char* GetTaskStr()
|
||||||
{
|
{
|
||||||
char* str = (char*)malloc(sizeof(char)*task_count * 40);
|
char* str = (char*)malloc(sizeof(char)*task_count * 40);
|
||||||
|
|||||||
Reference in New Issue
Block a user