From 16f3ed0fe42e607f79ba5f20df1f79d85ddb7738 Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Wed, 25 Dec 2019 17:59:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=88=A0=E9=99=A4=20?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/http_server/app_httpd.c | 32 +++++++++++++++++++++++++++++++- TC1/timed_task/timed_task.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index 45a219e..1c20872 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -214,6 +214,36 @@ exit: return err; } +static int HttpAddTask(httpd_request_t *req) +{ + //TODO 从url获取参数 + char buf[16] = "5 1234567 0"; //假设已经获取到了. + + 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 从url获取参数 + char buf[16] = "1234567"; //假设已经获取到了. + + 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[] = { {"/", HTTPD_HDR_DEFORT, 0, HttpGetIndexPage, NULL, 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/scan", HTTPD_HDR_DEFORT, 0, HttpGetWifiScan, HttpSetWifiScan, 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); diff --git a/TC1/timed_task/timed_task.c b/TC1/timed_task/timed_task.c index 8682849..5807681 100644 --- a/TC1/timed_task/timed_task.c +++ b/TC1/timed_task/timed_task.c @@ -40,7 +40,7 @@ bool AddTask(pTimedTask task) return false; } -bool DelTask() +bool DelFirstTask() { if (task_top) { @@ -53,6 +53,39 @@ bool DelTask() 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* str = (char*)malloc(sizeof(char)*task_count * 40);