From 6c36e7fbf8b6c7c14fad0a860dff6249528d77a6 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sat, 28 May 2022 22:26:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E9=94=99=E8=AF=AF=20?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BA=86all=5Fbus=5Ftest=E4=B8=AD=E7=9A=84ma?= =?UTF-8?q?in=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- all_test/main.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++- main.c | 4 +-- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/all_test/main.c b/all_test/main.c index b606558..4c8886c 100644 --- a/all_test/main.c +++ b/all_test/main.c @@ -82,7 +82,6 @@ int main() // 如果到站,处理请求和 if(JudgeOnStation() == BUS_TRUE) { - direction = FCFSDirection(); finished_query = FCFSQuery(); if(finished_query != NULL) // 有请求就处理请求 @@ -93,6 +92,9 @@ int main() DeleteQuery(finished_query); finished_query = FCFSQuery(); } + + // 请求处理完再进行方向的判断 + direction = FCFSDirection(); } else //如果没有请求就继续前进 { @@ -105,10 +107,83 @@ int main() } break; case BUS_SSTF: + // 如果没有指定的请求就获得指定的请求 + if(target_query == NULL) + { + target_query = SSTFGetQuery(); + direction = SSTFDirection(target_query); + } + + if(JudgeOnStation() == BUS_TRUE) + { + // 如果到达目标的站点 + if(the_bus->rail_node_pos == target_query->node) + { + DeleteQuery(target_query); + target_query = NULL; + } + else + { + target_query = SSTFBTWQuery(); + if(target_query != NULL) + { + while (target_query != NULL) + { + DeleteQuery(target_query); + target_query = SSTFBTWQuery(); + } + } + else + { + RunBus(direction); + } + } + } + else + { + RunBus(direction); + } break; case BUS_SCAN: + // 如果没有指定的请求就获得指定的请求 + if(target_query == NULL) + { + target_query = SCANGetQuery(); + direction = SCANDirection(target_query); + } + + if(JudgeOnStation() == BUS_TRUE) + { + // 如果到达目标的站点 + if(the_bus->rail_node_pos == target_query->node) + { + DeleteQuery(target_query); + target_query = NULL; + } + else + { + target_query = SCANBTWQuery(); + if(target_query != NULL) + { + while (target_query != NULL) + { + DeleteQuery(target_query); + target_query = SCANBTWQuery(); + } + } + else + { + RunBus(direction); + } + } + } + else + { + RunBus(direction); + } break; default: + // 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支 break; } diff --git a/main.c b/main.c index ec20da9..0580ce5 100644 --- a/main.c +++ b/main.c @@ -125,7 +125,7 @@ int main() if(target_query == NULL) { target_query = SCANGetQuery(); - direction = SSTFDirection(target_query); + direction = SCANDirection(target_query); } if(JudgeOnStation() == BUS_TRUE) @@ -138,7 +138,7 @@ int main() } else { - target_query = SCANGetQuery(); + target_query = SCANBTWQuery(); if(target_query != NULL) { while (target_query != NULL)