auto_bus/main.c

103 lines
2.5 KiB
C
Raw Normal View History

2022-05-20 15:00:04 +08:00
#include "bus_io.h"
2022-04-29 10:37:33 +08:00
2022-05-04 16:24:05 +08:00
/**
* @brief
*
* @return int 0
*/
2022-04-29 10:37:33 +08:00
int main()
{
2022-05-20 15:00:04 +08:00
/**
*
*/
char input[30];
/**
*
*/
char output[150];
2022-05-20 15:00:04 +08:00
/**
* the_bus指针的本体
*/
bus_t main_bus;
/**
*
*/
int direction;
/**
*
*/
bus_query_t *finished_query;
// 读取配置文件
rails = ReadConfigFile();
// 制造公交车
the_bus = &main_bus;
the_bus->distance = 0;
the_bus->rail_node_pos = FindNode(rails, 1);
// 开始时公交车应该是停下的
direction = BUS_STOP;
PrintState(output);
2022-05-20 15:00:04 +08:00
printf("%s", output);
for(;;)
{
fgets(input, sizeof input, stdin);
int result = ReadInput(input);
if(result == IO_CLOCK)
{
// 时间流动
AddTime();
switch (chosen_strategy)
{
case BUS_FCFS:
// 如果到站,处理请求和
if(JudgeOnStation() == BUS_TRUE)
{
direction = FCFSDirection();
finished_query = FCFSQuery();
if(finished_query != NULL) // 有请求就处理请求
{
// 循环处理所有可以处理的请求,总共消耗一秒
while (finished_query != NULL)
{
DeleteQuery(finished_query);
finished_query = FCFSQuery();
}
}
else //如果没有请求就继续前进
{
RunBus(direction);
}
}
else
{
RunBus(direction);
}
break;
case BUS_SSTF:
break;
case BUS_SCAN:
break;
default:
break;
}
PrintState(output);
printf("%s", output);
2022-05-20 15:00:04 +08:00
}
else if(result == IO_END)
{
printf("end\n");
break;
}
else
{
//在读取到创建请求的情况下,不做任何事
}
}
2022-04-29 10:37:33 +08:00
}