From 9b4f84f3785ea2906a8aa41fcfa9be4c60fec98d Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sun, 5 Jun 2022 20:56:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86=E4=BA=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all_test/main.c | 1 + convert.py | 4 +--- include/controller.h | 16 +--------------- main.c | 1 + src/bus_io.c | 6 +++++- src/controller.c | 15 --------------- src/rail.c | 35 +++++++++++++++++++---------------- 7 files changed, 28 insertions(+), 50 deletions(-) diff --git a/all_test/main.c b/all_test/main.c index c090d95..f7c8917 100644 --- a/all_test/main.c +++ b/all_test/main.c @@ -223,6 +223,7 @@ int main() // 没到站的话那就走吧 RunBus(direction); } + break; default: // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 break; diff --git a/convert.py b/convert.py index f1e1a97..00ae222 100644 --- a/convert.py +++ b/convert.py @@ -1,4 +1,3 @@ -from email.encoders import encode_noop import os path = "SSTF/" @@ -9,7 +8,7 @@ out_path = path + "{}.out" dict_file = open(dict_path, "r", encoding="utf8") dict_str = dict_file.read() -dict_file.close(); +dict_file.close() for i in range(1, 11): dir_path = "{}/".format(i + 7) @@ -36,4 +35,3 @@ for i in range(1, 11): output_file.close() dict_file.close() - diff --git a/include/controller.h b/include/controller.h index a39e79a..4f63cc7 100644 --- a/include/controller.h +++ b/include/controller.h @@ -72,18 +72,4 @@ int SCANDirection(bus_query_t *query, int orientation); */ bus_query_t *SCANBTWQuery(); -/** - * FCFS策略的控制函数 - */ -void FCFSControl(); - -/** - * SSTF策略的控制函数 - */ -void SSTFControl(); - -/** - * SCAN策略的控制函数 - */ -void SCANControl(); -#endif //AUTO_PILOT_BUS_CONTROLLER_H +#endif //AUTO_PILOT_BUS_CONTROLLER_H \ No newline at end of file diff --git a/main.c b/main.c index 0f90dbb..b96ac24 100644 --- a/main.c +++ b/main.c @@ -193,6 +193,7 @@ int main() // 没到站的话那就走吧 RunBus(direction); } + break; default: // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 break; diff --git a/src/bus_io.c b/src/bus_io.c index 4ba1135..47951cf 100644 --- a/src/bus_io.c +++ b/src/bus_io.c @@ -8,7 +8,9 @@ int ReadInput(char *inputString) char src[20]; int num; + sscanf(inputString, "%[a-z] %d", src, &num); + if (0 == strcmp("clock", src)) { return IO_CLOCK; @@ -83,6 +85,7 @@ rail_node_t *ReadConfigFile() case 'S': // STRATEGY p = buffer; + // 将=前的字符全部略去 while (*p != '=') { @@ -134,7 +137,6 @@ rail_node_t *ReadConfigFile() default: continue; } - } // 处理参数去缺省值的情况 @@ -169,6 +171,7 @@ void PrintState() clockwise[count] = '0'; counterclockwise[count] = '0'; } //遍历轨道链表,将所有站点初始化为0,即:无任何请求; + // 在字符串的末尾填0 target[count] = '\0'; clockwise[count] = '\0'; counterclockwise[count] = '\0'; @@ -216,6 +219,7 @@ void PrintStateInner(char *str) clockwise[count] = '0'; counterclockwise[count] = '0'; } //遍历轨道链表,将所有站点初始化为0,即:无任何请求; + // 在字符串的末尾填0 target[count] = '\0'; clockwise[count] = '\0'; counterclockwise[count] = '\0'; diff --git a/src/controller.c b/src/controller.c index 6354cb7..ab7b075 100644 --- a/src/controller.c +++ b/src/controller.c @@ -283,19 +283,4 @@ bus_query_t *SCANBTWQuery() }//遍历请求链表,判断是否有可以顺便处理的请求 return NULL; -} - -void FCFSControl() -{ - -} - -void SSTFControl() -{ - -} - -void SCANControl() -{ - } \ No newline at end of file diff --git a/src/rail.c b/src/rail.c index d6cf67d..f905a58 100644 --- a/src/rail.c +++ b/src/rail.c @@ -40,24 +40,27 @@ rail_node_t *CreateRails(int length, int node_num) rail_node_t *FindNode(rail_node_t *head, int id) { - rail_node_t *p = NULL; - if(head) + // 排除头节点为空的情况 + if(head == NULL) { - if(head->id == id) - { - return head; - } - if(head->next_node != NULL) - { - p = FindNode(head->next_node, id); - if(p) - { - return p; - } - } - + return NULL; } - return NULL; + + rail_node_t *result = NULL; + rail_node_t *p = head; + + do + { + if(p->id == id) + { + result = p; + break; + } + p = p->next_node; + } + while (p != head); + + return result; } void FreeRails(rail_node_t *head)