完成了SCANDirection函数和SCANBTWQuery函数

This commit is contained in:
Yerolling 2022-06-04 09:58:10 +08:00
parent 13814579e6
commit 56e97ae4db

View File

@ -265,10 +265,64 @@ bus_query_t *SCANGetQuery(int direction)
int SCANDirection(bus_query_t *query)
{
return BUS_STOP;
if(query == NULL)
{
return BUS_STOP;
} //如果没有请求,公交车停止
else
{
int clockwise = 0;
int counterclockwise = 0; //用于顺,逆时针方向所经站台计数
/**
*
*/
rail_node_t *now_position = the_bus->rail_node_pos;
/**
*
*/
rail_node_t *target_position = query->node;
rail_node_t *pos = now_position;
while (pos != target_position) //顺时针计数
{
clockwise++;
pos = pos->next_node;
}
pos = now_position;
while (pos != target_position) //逆时针计数
{
counterclockwise++;
pos = pos->last_node;
}
if(clockwise <= counterclockwise)
{
return BUS_CLOCK_WISE;
}//若顺时针距离短(或顺逆相等),公交车顺时针运行
else
{
return BUS_COUNTER_CLOCK_WISE;
}//若逆时针距离短,公交车逆时针运行
}
}
bus_query_t *SCANBTWQuery()
{
rail_node_t *now_position = the_bus->rail_node_pos;
//获取公交车当前所在站点
bus_query_t *p = queries;
while(p != NULL)
{
if(p->node == now_position)
{
return p;
}
p = p->next_node;
}//遍历请求链表,判断是否有可以顺便处理的请求
return NULL;
}