/********************************************************
*
* 文 件 名： InterlockLogicManage.c
* 版权说明： 北京交控科技有限公司
* 创建时间： 2012-04-10
* 作    者： 联锁组
* 功能描述： 联锁逻辑管理函数
* 修改记录：
*
********************************************************/

#include "InterlockLogicManage.h"
#include "../DataManage/DeviceConfigDataManage.h"
#include "RouteRecoverManage.h"
#include "../ParsePack/ParsePackPSCData.h"
#include "TrainDataManage.h"
#include "HLHTHeadContexManage.h"
#include "TrainOnAcManage.h"
#include "TrainDataManage.h"
#include "SectionStateProcess_define.h"
#include "DynamicRouteDataManage.h"
#include "LogicalRouteDataManage.h"
#include "../LogicProcess/LogicalRouteLogicCheck.h"
#include "../LogicManage/TradInterlockLogicManage.h"




void RouteAutoManage(const UINT16 routeId);
void CiTrainTestLogicManage(void);
void DriveAllSignaleRedClose(void);
/*
* 功能描述： 互联互通进路锁闭Overlap处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
static void LockRouteOverlapManageHlht(const UINT16 routeId);
/*
* 功能描述： 互联互通进路解锁锁Overlap处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
static void UnlockRouteOverlapManageHlht(const UINT16 routeId);

/*
* 功能描述： 互联互通进路保护区段解锁状态判断
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ：
0:不存在某一条保护区段，其包含的所有物理全均保护锁闭
>0:某一条保护区段，其包含的所有物理全均保护锁闭
*/
static UINT16 GetRouteLockedOvlpHlht(const UINT16 routeId);

/*
* 功能描述： 为互联互通CI锁闭本方保护区段时，设置Overlap防护锁闭
* 参数说明：
* const UINT16 overlapId, 保护区段ID
* const UINT8 lockState, 锁闭状态
* const UINT8 lockDir，锁闭方向
* 返回值  ： 无
*/
static void SetOvlpLockStateForHlhtCi(const UINT16 overlapId, const UINT8 lockState, const UINT8 lockDir);

/*
* 功能描述：TIOC与逻辑区段跳跃锁闭所属IVOC不同通信状态下的处理
* 参数说明：const UINT16 logSectionId，逻辑区段ID
const UINT16 trainId,列车ID
* 返回值  ： void
* 创建	  ：
*/
static void TrainTransitmitStatJumpLockProcess(const UINT16 logSectionId, const UINT16 trainId);

/*
* 功能描述： 列车逻辑区段资源回撤管理
* 参数说明： void
* 返回值  ：
*/
static void TrainLogicSecResRetreatManage(void);

/*
* 功能描述： 设置联锁引导总锁标志逻辑
* 参数说明： UINT8 setFlag 引导总锁标志
				CI_ALL_SWITCH_YLOCK_YES
				CI_ALL_SWITCH_YLOCK_NO
* 返回值  ： void
*/
void SetCiYLockManage(UINT8 setFlag)
{
	UINT8 yLockFlag = 0u;

	yLockFlag = GetAllSwitchYLockFlag();
	if ((CI_ALL_SWITCH_YLOCK_NO == setFlag) &&
		(CI_ALL_SWITCH_YLOCK_YES == yLockFlag))
	{
		/*取消引导总锁*/
		SetAllSwitchYLockFlag(setFlag);
	}
	else if ((setFlag == CI_ALL_SWITCH_YLOCK_YES) &&
		(CI_ALL_SWITCH_YLOCK_NO == GetAllSwitchYLockFlag()))
	{
		/*设置引导总锁*/
		SetAllSwitchYLockFlag(setFlag);
	}
	else
	{
		/*不处理*/
	}
}
/*
* 功能描述： 设置联锁引导总锁标志逻辑
* 参数说明： UINT8 setFlag 引导总锁标志
			 const UINT8 virCIid  虚拟联锁ID
* 返回值  ： void
*/
void SetCiYLockManage_UseVirCI(UINT8 setFlag, const UINT8 virCIid)
{
	UINT8 yLockFlag = 0u;

	yLockFlag = GetVirCIAllSwitchYLockState(virCIid);
	if ((CI_ALL_SWITCH_YLOCK_NO == setFlag) &&
		(CI_ALL_SWITCH_YLOCK_YES == yLockFlag))
	{
		/*取消引导总锁*/
		AllSwitchYLock_UseVirCI(virCIid, setFlag);
	}
	else if ((CI_ALL_SWITCH_YLOCK_YES == setFlag) &&
		(CI_ALL_SWITCH_YLOCK_NO == yLockFlag))
	{
		/*设置引导总锁*/
		AllSwitchYLock_UseVirCI(virCIid, setFlag);
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述： 联锁逻辑主处理
* 参数说明： void
* 返回值  ：
*/
void InterlockLogicMainProc(void)
{
	UINT8 localCiType = GetLocalCiType();
	UINT8 cRcWorkMode = GetLocalRcWorkMode();

	signed long long cost[20] = {0U};
	 cost[0] = MSCP_GetTick();
	if ((CI_TYPE_ZX == localCiType) || (CI_TYPE_SCX == localCiType))
	{
		/*全自动折返进路逻辑处理*/
		AllAutoReturnLogicManage();
#if 0
		/*进路逻辑处理*/
		RouteLogicManage();
#endif
		/*进路不在本联锁，进路需关闭信号机在本联锁处理*/
		NearCIRouteNeedCloseProce();
		/*cgh-合并CID-2341-8：清除保护区段的选排起始周期号, 进路空闲状态，清除进路保护区段选排起始周期*/
		ClearOverlapXuanPaiStartCycNum();
		if (CI_TYPE_SCX == localCiType)
		{
			CiTrainTestLogicManage();
		}
#if 0
		/*指示灯逻辑管理*/
		IndicatorLogicManage();
#endif

		/*防淹门逻辑处理*/
		FloodLogicManage();

		/*逻辑进路状态处理*/
		LogicalRouteProcess();
	}
	else
	{
		/*应急盘功能处理*/
		JKJRelayLogicProcess();

		/*长调进路逻辑处理*/
		LongRouteLogicProcess();
#if 0
		/*进路逻辑处理*/
		RouteLogicProcess();
#endif
		/*非进路逻辑处理*/
		NonRouteLogicProcess();

		/* 车库门逻辑处理 */
		GargeDoorLogicProcess();
	}

	/*动态组合进路逻辑处理（车辆段与正线均支持）*/
	DynamicRouteLogicProcess();

	cost[1] = MSCP_GetTick();
	/*进路逻辑处理*/
	RouteLogicManage();

	/*保护区段照查继电器更新管理*/
	OverlapZhaoChaRelayUpDateManage();

	/*进路列车释放解锁逻辑管理*/
	RouteTrainResUnlockManage();

	cost[2] = MSCP_GetTick();

	/*进路其它联锁道岔管理*/
	RouteOtherCiSwitchManage();

	/*保护区段其它联锁防护道岔管理*/
	OverlapOtherCiProSwitchManage();

	/*解锁道岔逻辑处理*/
	UnlockSwitchLogicManage();

	/*逻辑区段资源管理*/
	LogicSecResManage();
	cost[3] = MSCP_GetTick();

	/*跳跃锁闭逻辑处理*/
	JumpLockManage();
	cost[4] = MSCP_GetTick();
	debug_infor_printf((const)"\n JKJRelayLogicProcess :%dms  RouteLogicManage:%dms LogicSecResManage:%dms JumpLockManage:%dms \n",(cost[1]-cost[0])/1000,(cost[2]-cost[1])/1000,(cost[3]-cost[2])/1000,(cost[4]-cost[3])/1000);

}


/*
* 功能描述： 进路逻辑管理
* 参数说明： void
* 返回值  ：
*/
void RouteLogicManage(void)
{
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/

	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 routeBelongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT8 routeLevel = 0u;        /*进路监督级别*/
	UINT8 zongQuXiaoFlag = 0u;    /*进路总取消标志*/
	UINT8 zongRenJieFlag = 0u;    /*进路总人解标志*/
	UINT8 routeStateFlag = ROUTE_STATE_FLAG_NO;   /*进路状态转移标志*/
	UINT16 ii = 0u;               /*循环索引*/
	UINT8 sameLineCi = SAME_LINE_ERR;
	UINT16 endSigId = 0u;/*进路终端信号机*/
	UINT8 endSigCi = 0u;/*进路终端信号所属联锁*/
	UINT16 tempLockedOvlp = 0u;/*临时变量，互联互通下，进路的某一条保护区段，其包含的所有物理区段都处于锁闭状态*/
	UINT16 rtLockedOvlp = 0u;/*进路当前锁闭的保护区段ID*/
	UINT32 curCycleNum = 0u;
	UINT8 startLockState = 0u;
	UINT8 startFlockFlag = 0u;
	UINT8 rtVal = CI_ERROR;
	UINT8 localCiType = GetLocalCiType();
	UINT8 flagExec = CI_ERROR;/*继续执行标志*/
	UINT8 virCIid = 0u;
	UINT16 recordErrorNum = 0u;

	UINT8 cRcWorkMode = 0u;

	/* RC工作模式 */
	cRcWorkMode = GetLocalRcWorkMode();

	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	curCycleNum = Get2oo2CurCycleNum();			/*获取当前周期号*/

	startLockState = GetStartLockFlag();        /*获取上电解锁标志*/
	startFlockFlag = GetStartFLockFlag();       /*获取上电解封标志*/


	if (0u == localCiId)
	{
		rtVal = CI_ERROR;
	}
	else
	{
		rtVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == rtVal)
	{
		if ((CI_TYPE_ZX == localCiType) || (CI_TYPE_SCX == localCiType))
		{/*正线和试车线既检查上电解锁，又检查全站解封*/
			if ((CI_START_LOCK_NO != startLockState) || (CI_START_FLOCK_NO != startFlockFlag))
			{/*未全站解封且未上电解锁*/
				rtVal = CI_ERROR;
			}
		}
		else
		{/*车辆段仅检查上电解锁*/
			if (GetStartLockFlag() != CI_START_LOCK_NO)
			{ /*未上电解锁*/

				rtVal = CI_ERROR;
			}
		}
	}



	if (CI_SUCCESS == rtVal)
	{
		/*引导总锁信号开放管理*/
		YLockSignalOpenManage();

		if (CI_TYPE_CLD == localCiType)
		{
			/*处理车辆段调车中途折返*/
			DTrainReturnUnlockP();
		}
	}


	if (CI_SUCCESS == rtVal)
	{
		/*处理进路*/
		for (ii = 0u; ii < routeCurSum; ii++)
		{
			routeId = 0u;	         /*进路ID*/
			routeBelongCiId = 0u;          /*进路所属联锁ID*/
			routeState = 0u;          /*进路状态*/
			routeLevel = 0u;          /*进路监督级别*/
			zongQuXiaoFlag = 0u;      /*进路总取消标志*/
			zongRenJieFlag = 0u;      /*进路总人解标志*/

			routeId = GetRouteId(ii);                           /*获取进路ID*/
			routeBelongCiId = GetRouteBelongCiId(routeId);           /*获取进路所属联锁ID*/

			/*cgh-合并CID-2349-5：*/
			virCIid = GetRouteBelongVirCiId(routeId);
			recordErrorNum = GetErrorDataCurSum();
			if ((0u == routeId) || (routeId > ROUTE_SUM_MAX))
			{
				flagExec = CI_ERROR;
			}
			else
			{
				flagExec = CI_SUCCESS;
			}

			if (CI_SUCCESS == flagExec)
			{
				if (routeBelongCiId != localCiId)
				{
					/*判断是否同一条线路的两个联锁*/
					sameLineCi = IsSameLineCI(routeBelongCiId, localCiId);
					if (SAME_LINE_YES == sameLineCi)
					{/*同一条线路的CI，才执行交控相邻CI的处理逻辑*/
						/*************非本联锁Overlap逻辑管理***************/
						/*处理站间保护区段锁闭逻辑处理*/
						LockOverlapLogicManage(routeId);

						/*解锁保护区段*/
						UnlockOverlapLogicManage(routeId);
					}

					/*****************进路逻辑管理**********************/
					flagExec = CI_ERROR;
				}
			}

			if (CI_SUCCESS == flagExec)
			{
				/*互联互通下，保护区段解锁状态判断*/
				endSigId = GetRouteEndSignalId(routeId);
				endSigCi = GetSignalBelongCiId(endSigId);
				sameLineCi = IsSameLineCI(localCiId, endSigCi);

				if (SAME_LINE_NO == sameLineCi)
				{
					tempLockedOvlp = GetRouteLockedOvlpHlht(routeId);
					if (0u == tempLockedOvlp)
					{
						/*说明进路的保护区段已经处于未锁闭状态*/
						rtLockedOvlp = GetRouteOverlapLockedId(routeId);
						if (rtLockedOvlp > 0u)
						{
							SetOverlapLockState(rtLockedOvlp, PHYSICAL_SECTION_LOCK_NO, routeId);  /*设置Overlap未锁闭*/
						}
					}
				}

				/*获取进路动态字段*/
				zongQuXiaoFlag = GetRouteZongQuXiaoFlag(routeId);          /*获取进路总取消标志*/
				zongRenJieFlag = GetRouteZongRenJieFlag(routeId);          /*获取进路总人解标志*/
				routeStateFlag = GetRouteStateFlag(routeId);			   /* 获取进路状态转移标志*/

				/*进路监督级别确认*/
				routeLevel = RouteLevelConfirmLogicProcess(routeId);

				/*设置进路监督级别*/
				SetRouteLevel(routeId, routeLevel);

				/* 自动触发办理自动进路/自动折返 */
				RouteAutoManage(routeId);

				/*清理进路信号容忍开放开始周期*/
				SetClearKeepSignalTolerateCyc(routeId);

				routeState = GetRouteState(routeId);

				/*#####进路状态处理#####*/
				if (ROUTE_STATE_IDLE == routeState)
				{ /*进路空闲*/

					RouteIdleManage(routeId);
				}
				else if (ROUTE_STATE_FIRST_XUANPAI == routeState)
				{/*进路预选*/

					RouteFirstXuanPaiManage(routeId);
				}
				else if (ROUTE_STATE_LEAD_FIRST_XUANPAI == routeState)
				{/*引导预选*/

					LeadRouteFirstXuanPaiManage(routeId);
				}
				else if (ROUTE_STATE_XUANPAI == routeState)
				{ /*进路选排*/

					RouteXuanPaiManage(routeId);
				}
				else if (ROUTE_STATE_LEAD_XUANPAI == routeState)
				{ /*引导选排*/

					LeadRouteXuanPaiManage(routeId);
				}
				else if (ROUTE_STATE_FIRST_LOCK == routeState)
				{ /*进路初锁*/

					RouteFirstLockManage(routeId);
				}
				else if (ROUTE_STATE_FIRST_LOCKERR == routeState)
				{ /*进路初锁异常*/

					RouteFirstLockErrManage(routeId);
				}
				else if (ROUTE_STATE_YUXIAN_LOCK == routeState)
				{ /*预先锁闭*/

					RouteYuXianLockManage(routeId);
				}
				else if (ROUTE_STATE_YUXIAN_OPEN == routeState)
				{ /*预先开放*/

					RouteYuXianOpenManage(routeId);
				}
				else if (ROUTE_STATE_NEAR_LOCK == routeState)
				{ /*接近锁闭正常*/

					RouteNearLockManage(routeId);
				}
				else if (ROUTE_STATE_NEAR_LOCKERR == routeState)
				{ /*接近锁闭异常*/

					RouteNearLockErrManage(routeId);
				}
				else if (ROUTE_STATE_NEAR_OPEN == routeState)
				{ /*接近开放*/

					RouteNearOpenManage(routeId);
				}
				else if (ROUTE_STATE_DELAY_UNLOCK == routeState)
				{ /*延时解锁*/

					RouteDelayUnlockManage(routeId);
				}
				else if (ROUTE_STATE_AUTO_UNLOCK == routeState)
				{ /*自动解锁正常*/

					RoutePhyOrLogSecAutoUnlocManage(routeId);
				}
				else if (ROUTE_STATE_AUTO_UNLOCKERR == routeState)
				{ /*自动解锁异常*/

					RoutePhySecAutoUnlockErrManage(routeId);
				}
				else if (ROUTE_STATE_LEAD_LOCK == routeState)
				{ /*引导锁闭*/

					RouteLeadLockManage(routeId);
				}
				else if (ROUTE_STATE_LEAD_OPEN == routeState)
				{ /*引导开放*/

					RouteLeadOpenManage(routeId);
				}
				else if (ROUTE_STATE_LEAD_LOCKERR == routeState)
				{
					/*引导锁闭异常*/
					RouteLeadLockErrManage(routeId);
				}
#if 0
				else if (ROUTE_STATE_HALF_FIRST_XUAN == routeState)
				{/*部分锁闭预选*/

					RouteHalfFirstXuanManage(routeId);
				}
				else if (ROUTE_STATE_HALF_XUANPAI == routeState)
				{ /*部分锁闭选排*/

					RouteHalfXuanPaiManage(routeId);
				}
#endif
				else if (ROUTE_STATE_HALF_LOCK == routeState)
				{
					/*进路部分锁闭处理*/
					RouteHalfLockManage(routeId);
				}
				else if (ROUTE_STATE_HALF_UNLOCK == routeState)
				{
					/*进路部分锁闭解锁处理*/
					RouteHalfUnlockManage(routeId);
				}
				else if (ROUTE_STATE_HALF_UNLOCKDELAY == routeState)
				{ /*进路第一个锁闭的逻辑区段延时设置区段故障状态*/
					RouteHalfUnlockDelayManage(routeId);
				}
				else
				{
					/*状态异常*/
					/*xxxxx 宕机*/

					/*记录系统故障*/
					SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
						EFUNC_LOGIC_MANAGE_SYETEM,
						CI_ERROR,
						ETYPE_SYSTEM_EXCEPT,
						CI_ERROR, ESEND_LEVEL_ZERO);
				}

				/*获取进路状态*/
				routeState = GetRouteState(routeId);

				if ((ROUTE_STATE_IDLE != routeState) &&
					(ROUTE_STATE_FIRST_XUANPAI != routeState) &&
					(ROUTE_STATE_XUANPAI != routeState) &&
					(ROUTE_STATE_LEAD_FIRST_XUANPAI != routeState) &&
					(ROUTE_STATE_LEAD_XUANPAI != routeState) &&
					(ROUTE_STATE_AUTO_UNLOCK != routeState) &&
					(ROUTE_STATE_AUTO_UNLOCKERR != routeState))
				{
					/*进路锁闭后到列车驶入为止，需关闭信号处理*/
					(void)RouteOpenNeedCloseSignal(routeId);
				}

				/*照查驱动状态更新*/
				UpdateZhaoChaStateManage(routeId, routeState);

				TryClearRouteTrainEnterFlag(routeId);

				/*进路最近列车解锁逻辑*/
				if (RC_WORK_MODE_TIOC == cRcWorkMode)
				{
					RouteNearestTrainRenJieManage(routeId);
				}
				/*#####进路取消处理#####*/
				if (ROUTE_ZONGQUXIAO_SET_YES == zongQuXiaoFlag)
				{ /*已办理总取消*/

					RouteZongQuXiaoProc(routeId);
				}
				else if (ROUTE_ZONGRENJIE_SET_YES == zongRenJieFlag)
				{ /*已办理总人解*/

					RouteZongRenJieProc(routeId);
				}
				else
				{/*不处理*/
				}

				/*************本联锁Overlap逻辑管理***************/
				/*处理站间保护区段锁闭逻辑处理*/
				if (SAME_LINE_YES == sameLineCi)
				{
					LockOverlapLogicManage(routeId);

					/*解锁保护区段*/
					UnlockOverlapLogicManage(routeId);
				}
				else if (SAME_LINE_NO == sameLineCi)
				{
					LockRouteOverlapManageHlht(routeId);
					UnlockRouteOverlapManageHlht(routeId);
				}
				else
				{
					/*无法判断是否同线路，不做处理，无安全问题*/
				}

				/*****************进路逻辑管理********************/
				/*CBTC模式追踪办进路，
				修改前：当后面的进路选排不成功时会将进路状态设置为空闲，
				从而前车所在区段及之前锁闭的区段变为未锁闭，存在安全隐患；
				修改后：只有当后面遍历的进路锁闭成功才将之前的进路状态转移，否则保持原来进路状态*/
				if (ROUTE_STATE_FLAG_YES == routeStateFlag)
				{
					RouteStateFlagManage(routeId);
				}

				if (RC_WORK_MODE_TIOC == cRcWorkMode)
				{
					/*列车申请取消资源延时处理 wei 缺陷：资源取消问题*/
					RouteCancelResApplyManage(routeId);
				}

				RouteRecoverOpenProc(routeId);

				/*处理取消自动信号命令函数*/
				CancleAutoSigCmdProcc(routeId);

				/*进路调车同意逻辑处理*/
				RouteDCTYLogic(routeId);

				/*cgh-合并CID-2341-5：根据进路状态清除相关标志*/
				ClearSomeFlagDependRouteState(routeId);


				/*cgh-合并CID-2349-5：*/
				SetErrorDataBelongVirCiId(recordErrorNum, virCIid);/*设置ErrorCode虚拟联锁ID*/

			}

		}
	}
}

/*
* 功能描述： 进路不在本联锁，进路需关闭信号机在本联锁处理
* 参数说明： void
* 返回值  ：
*/
void NearCIRouteNeedCloseProce(void)
{
	UINT16 i = 0u;
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 routeState = 0u;
	UINT8 commState = 0u;/*通信状态*/
	UINT8 funcSwitchSupportRelayInterface = 0u;
	UINT8 confirmRelayInterfaceFlag = 0u;

	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	for (i = 0u; i < routeCurSum; i++)
	{
		routeId = GetRouteId(i);                           /*获取进路ID*/
		belongCiId = GetRouteBelongCiId(routeId);           /*获取进路所属联锁ID*/

		if (localCiId != belongCiId)
		{
			/*获取通信状态、继电接口*/
			commState = GetLocalCiAndOtherCiTransSta(belongCiId);
			funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
			confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

			/*继电接口已确认*/
			if ((TRANSMIT_STATE_BAD == commState) && (CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)
				&& (FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*不检查*/
			}
			else
			{
				/*获取进路状态*/
				routeState = GetRouteState(routeId);
				/*进路锁闭状态*/
				if ((ROUTE_STATE_IDLE != routeState) &&
					(ROUTE_STATE_FIRST_XUANPAI != routeState) &&
					(ROUTE_STATE_XUANPAI != routeState) &&
					(ROUTE_STATE_LEAD_FIRST_XUANPAI != routeState) &&
					(ROUTE_STATE_LEAD_XUANPAI != routeState) &&
					(ROUTE_STATE_AUTO_UNLOCK != routeState) &&
					(ROUTE_STATE_AUTO_UNLOCKERR != routeState))
				{
					/*进路锁闭后到列车驶入为止，需关闭信号处理*/
					(void)RouteOpenNeedCloseSignal(routeId);
				}
			}
		}
	}
}


/*
* 功能描述： 自动进路触发处理
*			该函数在进路管理中，无条件执行。
*			根据当前进路的状态以及进路办理条件，自动触发进路办理。
*
*
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteAutoManage(const UINT16 routeId)
{

	UINT8 autoRouteType = 0u;	/*获取自动进路类型:普通自动进路、自动折返进路*/
	UINT8 autoSigRouteType = 0u; /*获取进路当前是否为自动信号进路*/
	UINT8 autoReturnRouteType = 0u;
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 redDsFlag = 0u;
	UINT8 greenDsFlag = 0u;
	UINT8 yellowDsFlag = 0u;
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 checkRouteFlag = 0u;		/* 检查进路办理条件 */
	UINT8 autoRouteFlg = 0u;			/* 进路触发办理条件 */
	UINT8 autoTriggerType = 0u;      /*自动触发进路属性*/
	UINT8 triggerFlag = AUTO_TRIGGER_SET_NO;  /*自动触发标志*/
	UINT8 autoSigProperty = 0u;
	UINT8 checkDSBreakLoseEfficacyFlag = 0u;     /*是否断丝后自动信号失效*/
	UINT8 setRouteAutoFlag = 0u;
	UINT8 autoReturnValid = 0u;
	UINT8 routeTriggerOccu = 0u;
	UINT8 phySectionUseState = 0u;
	UINT16 routeAutoReturnId = 0u;
	UINT8 virCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	checkDSBreakLoseEfficacyFlag = GetCiFunctionSwitchConfig(FUNC_DS_BREAK_AUTOSIG_LOSE_EFFICACY_FLAG);

	autoSigProperty = GetRouteAutoSigProperty(routeId);/*获取进路自动信号属性*/

	if ((ROUTE_AUTOSIG_PROPERTY_YES == autoSigProperty) && (ROUTE_AUTOSIG_DSBREAK_LOSE_EFFICACY == checkDSBreakLoseEfficacyFlag))
	{
		/*获取进路始端信号机ID*/
		startSignalId = GetRouteStartSignalId(routeId);
		redDsFlag = GetSignalDsBreakFlag(startSignalId);
		greenDsFlag = GetSignalGreenDsBreakFlag(startSignalId);
		yellowDsFlag = GetSignalYellowDsBreakFlag(startSignalId);



		/*始端信号机断丝*/
		if ((SIGNAL_DS_BREAK_YES == redDsFlag) || (SIGNAL_DS_BREAK_YES == greenDsFlag)
			|| (SIGNAL_DS_BREAK_YES == yellowDsFlag))
		{
			/*设置自动信号属性失效*/
			setRouteAutoFlag = SetRouteAutoSigLoseEfficacyFlag(routeId, ROUTE_AUTOSIG_LOSE_DSSET_YES);
			if (CI_ERROR == setRouteAutoFlag)
			{
				/*不做处理*/
			}
		}

		startSignalCurColor = GetSignalCurColor(startSignalId);
		openCloseState = GetSignalOpenCloseState(startSignalCurColor);

		if (SIGNAL_OPEN == openCloseState)
		{
			/*设置自动信号属性有效*/
			setRouteAutoFlag = SetRouteAutoSigLoseEfficacyFlag(routeId, ROUTE_AUTOSIG_LOSE_DSSET_NO);
			if (CI_ERROR == setRouteAutoFlag)
			{
				/*不做处理*/
			}
		}
	}
	/*自动进路 || 自动信号 :自动办理*/
	autoRouteType = GetRouteAutoRouteSetState(routeId);/*获取自动进路类型:普通自动进路、自动折返进路*/
	autoSigRouteType = GetRouteAutoSigSetState(routeId);/*获取进路当前是否为自动信号进路*/
	autoTriggerType = GetAutoTriggerType(routeId);

	triggerFlag = GetRouteAutoTriggerFlag(routeId);/*获取进路自动触发进路属性*/
	/*
	 * 自动通过进路办理条件: 只需要满足该进路办理条件，就自动触发办理该条进路。
	 *  自动折返进路时: 折入进路只要满足条件，就可以办理
	 *                  折出进路的时候，除了满足办理条件以外，还需要满足列车在折返轨上
	 *
	 */
	if ((ROUTE_AUTOROUTE_NORMAL == autoRouteType) || (ROUTE_AUTOSIGROUTE_YES == autoSigRouteType))
	{
		/*自动进路 || 自动信号*/
		checkRouteFlag = SetRouteProc(routeId);
		if (CI_SUCCESS == checkRouteFlag)
		{
			autoRouteFlg = 1u;
		}
	}
	else if (ROUTE_AUTOROUTE_RETURN == autoRouteType)
	{
		routeAutoReturnId = GetRouteAutoReturnId(routeId);
		autoReturnRouteType = GetAutoReturnRouteType(routeAutoReturnId, routeId);
		if (AUTO_RETURN_ROUTE_TYPE_IN == autoReturnRouteType)
		{
			/* 折入进路 检查 */
			checkRouteFlag = SetRouteProc(routeId);
			if (CI_SUCCESS == checkRouteFlag)
			{
				autoRouteFlg = 1u;
			}
		}
		else if (autoReturnRouteType == AUTO_RETURN_ROUTE_TYPE_OUT)
		{
			autoReturnValid = GetAutoReturnRebackRouteValid(routeId);
			if (CI_SUCCESS == autoReturnValid)
			{
				/*自动折返折出进路办理条件满足*/
				/* 折入进路 检查 */
				checkRouteFlag = SetRouteProc(routeId);
				if (CI_SUCCESS == checkRouteFlag)
				{
					autoRouteFlg = 1u;
				}
			}
		}
		else
		{
			/*不处理*/
			autoRouteFlg = 0u;
		}
	}
	else if (AUTO_TRIGGER_SET_YES == triggerFlag)
	{   /*自动触发进路且已设置触发标志*/
		/*触发区段有车占压，则进路自动触发*/
		routeTriggerOccu = RouteTriggerOccu(routeId);
		if (CI_SUCCESS == routeTriggerOccu)
		{
			checkRouteFlag = SetRouteProc(routeId);
			if (CI_SUCCESS == checkRouteFlag)
			{
				autoRouteFlg = 1u;
			}
		}
	}
	else
	{
		/*普通进路不处理*/
		autoRouteFlg = 0u;
	}
	/* 触发办理进路，需要检查征用状态 */
	if (1U == autoRouteFlg)
	{
		phySectionUseState = RoutePhySectionUseLogicProcess(routeId);
		/*进路物理区段未征用检查*/
		if (CI_SUCCESS == phySectionUseState)
		{
#if 0
			/*全部区段未征用*/

			SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/

			/*进路初选处理*/
			RouteFirstXuanPaiManage(routeId);
#else
			SetCommonRouteLogicManage(routeId, ESEND_LEVEL_ATS);
#endif
		}
	}

	/*自动通过,自动折返,全自动折返,自动触发 处理*/
	if ((ROUTE_AUTOROUTE_NORMAL == autoRouteType)
		|| (ROUTE_AUTOROUTE_RETURN == autoRouteType)
		|| (ROUTE_ALLAUTOROUTE_RETURN == autoRouteType)
		|| (ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType))
	{
		CrossCiAutoRouteFLockDevProc(routeId);
	}
}
/*
* 功能描述： 进路空闲管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteIdleManage(const UINT16 routeId)
{
	/*
	 * 该函数部分，移到自动进路触发管理函数RouteAutoManage内。
	 * 空闲状态处理目前不做任何处理
	 */
#if 0
	UINT8 autoRouteType = 0u;
	UINT8 autoReturnRouteType = 0u;

	/*自动进路自动办理*/
	autoRouteType = GetRouteAutoRouteSetState(routeId);

	if (autoRouteType == ROUTE_AUTOROUTE_NORMAL)
	{
		/*自动进路*/

		/*进路物理区段未征用检查*/
		if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
		{
			/*全部区段未征用*/

			SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/

			/*进路初选处理*/
			RouteFirstXuanPaiManage(routeId);
		}
		else
		{
			/*区段有征用*/

			/*保持原进路状态*/
		}
	}
	else if (autoRouteType == ROUTE_AUTOROUTE_RETURN)
	{
		autoReturnRouteType = GetAutoReturnRouteType(GetRouteAutoReturnId(routeId), routeId);
		if (autoReturnRouteType == AUTO_RETURN_ROUTE_TYPE_IN)
		{
			/*自动折返进路*/

			/*进路物理区段未征用检查*/
			if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
			{
				/*全部区段未征用*/

				SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/

				/*进路初选处理*/
				RouteFirstXuanPaiManage(routeId);
			}
			else
			{
				/*区段有征用*/

				/*保持原进路状态*/
			}
		}
		else if (autoReturnRouteType == AUTO_RETURN_ROUTE_TYPE_OUT)
		{
			if (GetAutoReturnRebackRouteValid(routeId) == CI_SUCCESS)
			{
				/*自动折返折出进路办理条件满足*/

				/*进路物理区段未征用检查*/
				if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
				{
					/*全部区段未征用*/

					SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/

					/*进路初选处理*/
					RouteFirstXuanPaiManage(routeId);
				}
				else
				{
					/*区段有征用*/

					/*保持原进路状态*/
				}
			}
			else
			{
				/*不处理 等待折出条件满足*/
			}
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*普通进路不处理*/
	}
#endif
}


/*
* 功能描述： 进路初选管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteFirstXuanPaiManage(const UINT16 routeId)
{
	UINT8 returnValueFunc1 = 0U;    /*返回值定义*/
	UINT8 returnValueFunc2 = 0U;	   /*返回值定义*/
	UINT8 firstXuanPaiOvertime = 0U;/*初选超时*/
	UINT8 routeCheck = 0U;
	UINT8 routeProperty = 0U;
	UINT8 chFunctionId = 0U;/*故障码函数ID*/
	UINT8 chLocalCiType = 0U;/*本地联锁类型*/

	routeCheck = SetRouteProc(routeId);
	chLocalCiType = GetLocalCiType();     /*获取本地联锁类型*/
	if (CI_TYPE_CLD == chLocalCiType)
	{
		chFunctionId = EFUNC_CommonRouteXuanPaiDeal;
	}
	else
	{
		chFunctionId = EFUNC_RouteFirstXuanPaiManage;
	}
	/*办理进路处理*/
	if (CI_SUCCESS == routeCheck)
	{ /*办理成功*/
		firstXuanPaiOvertime = RouteFirstXuanOverTime(routeId);
		if (OVERTIME_YES == firstXuanPaiOvertime)
		{/*初选超时*/
			/*cgh - 合并CID - 2341 - 7： 修改选排超时不清征用问题*/
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			routeProperty = GetRouteReverseProperty(routeId);
			if (ROUTE_REVERSE_PROPERTY_YES == routeProperty)
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);

			/*增加进路初选超时错误码打印*/
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_ROUTE, routeId,
				ETYPE_ROUTE_FIRST_XUANPAI_OVERTIME, ROUTE_STATE_FIRST_XUANPAI, ESEND_LEVEL_ZERO);
		}
		/*未超时*/

		/*进路初选处理*/
		returnValueFunc1 = RouteFirstXuanProc(routeId);
#if 0
		returnValueFunc2 = RouteFirstXuanAutoSigProc(routeId);
#else
		returnValueFunc2 = RouteFirstXuanAutoSigCancelPro(routeId);
#endif
		if ((CI_ERROR == returnValueFunc1) || (CI_ERROR == returnValueFunc2))
		{
			/*征用失败 || 反向进路自动信号进路取消失败*/

			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
		}
		else if ((CI_SUCCESS == returnValueFunc1) && (CI_SUCCESS == returnValueFunc2))
		{
			/*征用成功*/

			SetRouteStateManage(routeId, ROUTE_STATE_XUANPAI);  /*-->设置进路选排*/

			/*进路选排处理*/
			RouteXuanPaiManage(routeId);
		}
		else if ((RETURN_FIRSTXUANPAI_ERR_WAIT == returnValueFunc1) || (RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT == returnValueFunc2))
		{
			/*等待*/
		}
		else
		{
		}
	}
	else
	{
		/*进路办理失败*/

		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

			SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
		}

		/*设置进路空闲*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);


	}
}


/*
* 功能描述： 进路选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteXuanPaiManage(const UINT16 routeId)
{
	UINT8 returnValue = CI_ERROR;    /*返回值定义*/
	UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE; /*带动道岔是否需要被驱动*/
	UINT8 routSwitDrvOvtmFlag = 0U;/*进路内道岔是否驱动超时标志*/
	UINT8 chkSwitchPos = CI_ERROR;

	returnValue = LockRouteProc(routeId);

	if ((CI_SUCCESS == returnValue) || (RETURN_LOCK_ERR_SWITPOS == returnValue))
	{
		RouteXuanPaiCommonProcess(routeId, returnValue);
	}
	else if (RETURN_LOCK_ERR_WAIT_SWCHECK == returnValue)
	{
		/*等待相邻联锁反馈道岔检查状态*/
		;
	}
	else
	{
		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

			SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
		}
		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
	}
}

/*
* 功能描述： 引导进路选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void LeadRouteXuanPaiManage(const UINT16 routeId)
{
	UINT8 returnValue = 0u;    /*返回值定义*/

	UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE;/*带动道岔是否需要被驱动*/

	UINT8 routSwitDrvOvtmFlag = 0u;/*进路内道岔是否驱动超时标志*/

	/*进路锁闭管理*/
	returnValue = LockLeadRouteLogicProcess(routeId);

	/*进路带动道岔位置检查*/
	NeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(routeId);

	routSwitDrvOvtmFlag = ChekRoutSwitDrivOvtmStat(routeId);/*检查进路内道岔是否驱动超时*/

	if ((CI_SUCCESS == returnValue) && (SWITCH_NEED_DRIV_FALSE == NeedForDrvRoutAssoSwit))
	{
		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

		/*锁闭成功*/
		SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCK);  /*-->设置进路引导锁闭*/

		/*引导锁闭处理*/
		RouteLeadLockManage(routeId);
	}
	else if (((RETURN_LOCK_ERR_SWITPOS == returnValue) && (CI_SUCCESS == routSwitDrvOvtmFlag)) ||
		((SWITCH_NEED_DRIV_TRUE == NeedForDrvRoutAssoSwit) && (CI_SUCCESS == returnValue)))
	{ /*道岔位置不正确*//*选排引导进路*/

		/*进路锁闭驱动道岔*/
		if (CI_ERROR == RouteLockDriveSwitch(routeId, NeedForDrvRoutAssoSwit))
		{/* 单操取消办理 */
			SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
		}
	}
	else if (RETURN_LOCK_ERR_WAIT_SWCHECK == returnValue)
	{
		/*等待相邻联锁反馈道岔检查状态*/
		;
	}
	else
	{
		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

		/* 进路锁闭失败 */
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
	}

}

/*
* 功能描述： 进路初锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteFirstLockManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*信号机开放关闭状态*/
	UINT8 routeLevel = 0u;           /*进路监督级别*/
	UINT8 returnValue = 0u;          /*是否继续执行*/
	UINT8 routeType = 0u;/*进路类型*/
	UINT8 routeReverse = 0u;
	UINT8 routeAirShaft = 0u;

	/* 开放信号时间状态*/
	UINT8 const routeTimeState = SystemOverTimeCheck(GetRouteOpenSigStatrtCycNum(routeId),
		GetSystemParaRouteOpenSigCyc());


	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/
	openCloseState = GetSignalOpenCloseState(GetSignalCurColor(startSignalId));   /*获取进路始端信号机开放关闭状态*/
	routeLevel = GetRouteLevel(routeId);  /*获取进路监督级别*/

	routeType = GetRouteType(routeId);
	routeReverse = GetRouteReverseProperty(routeId);
	routeAirShaft = GetAirShaftRouteType(routeId);
	if ((ROUTE_LEVEL_BLOC == routeLevel) ||
		(ROUTE_TYPE_RETURN == routeType) || (ROUTE_TYPE_DIAOCHE == routeType) ||
		(ROUTE_REVERSE_PROPERTY_YES == routeReverse) ||
		(ROUTE_TYPE_AIRSHAFT == routeAirShaft))
	{
		/*点式进路或折返进路或反向进路或风井进路*/
		if (ROUTE_OVERLAP_SET_NO == GetRouteOverlapLockFlag(routeId))
		{
			/*进路保护区段未锁闭*/
			if (CI_TIME_OUT == routeTimeState)
			{
				/*信号开放超时*/
				SetErrorData(EFUNC_LOCK_BLOC_T_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_OVERLAP_UNLOCK, ROUTE_OVERLAP_SET_NO, ESEND_LEVEL_ATS);
				SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);  /*-->设置初锁异常*/

				/*保护区段锁闭失败，信号无法开放，设置对应始端信号机扣车旁路按钮无效*/
				SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);

				returnValue = CI_ERROR;
			}
			else
			{
				/*未超时等待保护区段锁闭,此时不做信号开放检查*/
				returnValue = CI_ERROR;
			}
		}
		else
		{
			/*保护区段已锁或没有保护区段*/

			/*保护区段占用检查*/
			returnValue = BlocOverlapOccClearProc(routeId);
			if (CI_ERROR == returnValue)
			{
				/*有占用*/
				if (routeTimeState != CI_TIME_IN)
				{/*占用超时*/
					SetErrorData(EFUNC_LOCK_BLOC_T_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_OVERLAP_UNLOCK, ROUTE_OVERLAP_SET_NO, ESEND_LEVEL_ATS);
					debug_infor_printf((const)"\nRoute %d ovlerlap OccTimeOut.\n", routeId);
					SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);  /*-->设置初锁异常*/

					/*保护区段锁闭失败，信号无法开放，设置对应始端信号机扣车旁路按钮无效*/
					SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
				}

			}
			else
			{
				;
			}

		}
	}
	else
	{
		returnValue = CI_SUCCESS;
	}

	if (CI_SUCCESS == returnValue)
	{
		if (SIGNAL_OPEN == openCloseState)
		{ /*信号开放*/

			if (CI_SUCCESS == RouteHaveTrainNear(routeId))
			{
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);    /*设置接近开放*/

				RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
			}
			else
			{
				SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*设置预先开放*/

				RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
			}
		}
		else
		{ /*信号关闭*/

			/*开放进路信号处理*/
			returnValue = OpenRouteSignalProc(routeId);

			if (CI_SUCCESS == returnValue)
			{
				/*开放成功*/

				/*等待开灯*/
			}
			else
			{
				/*开放失败*/
				SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);  /*-->设置初锁异常*/

				/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
				SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
			}
		}
	}


}


/*
* 功能描述： 进路初锁异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteFirstLockErrManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*信号机开放关闭状态*/
	UINT8 dctyReOpenFlag = ROUTE_DCTY_REOPEN_NO;/*调车同意重开标志*/
	UINT8 needOpenNotTrueRepeatFlag = ROUTE_NEEDOPEN_REOPEN_NO;/*需开放不满足时重开标志*/
	UINT8 cFuncRetVal = CI_ERROR;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/
	openCloseState = GetSignalOpenCloseState(GetSignalCurColor(startSignalId));   /*获取进路始端信号机开放关闭状态*/

	if (SIGNAL_OPEN == openCloseState)
	{
		/*信号开放*/

		if ((CI_SUCCESS == AutoSignalOrRouteValid(routeId)) ||
			(ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId)))
		{
			/*信号重开*/

			SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN); /*设置进路状态【预先开放】*/

			RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
		}
		else
		{
			needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
			/*获取调车同意重开标志*/
			dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);

			if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag)
				|| (ROUTE_DCTY_REOPEN == dctyReOpenFlag))
			{
#if 0
				SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0);
#endif
				SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN); /*设置进路状态【预先开放】*/

				RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
			}
			else
			{
				/*信号机异常开放*/
				/*xxxxx宕机*/

				/*记录系统故障*/
				SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
					CI_DEVICE_TYPE_SIGNAL,
					startSignalId,
					ETYPE_SYSTEM_SIGNAL_OPEN,
					openCloseState, ESEND_LEVEL_ZERO);
			}
		}

	}
	else
	{
		/*信号关闭*/

		if (((CI_SUCCESS == AutoSignalOrRouteValid(routeId)) && (SIGNAL_DS_BREAK_NO == GetSignalDsBreakFlag(startSignalId))) ||
			(ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId)))
		{
			/*重开信号处理*/
			cFuncRetVal = OpenRouteSignalProc(routeId);
			if (CI_SUCCESS == cFuncRetVal)
			{
				/*开放成功，等待开灯*/
			}
			else
			{
				/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
				SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
			}
		}
		else
		{
			/* 保持进路异常锁闭状态*/
			needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
			/*获取调车同意重开标志*/
			dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);

			if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag)
				|| (ROUTE_DCTY_REOPEN == dctyReOpenFlag))
			{/*处理需开放不满足，需开放重开标志有效/调车同意重开标志有效时*/
				cFuncRetVal = OpenRouteSignalProc(routeId);
				if (CI_SUCCESS == cFuncRetVal)
				{
					/*开放成功，等待开灯*/
				}
				else
				{
					/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
					SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
				}
			}
		}
	}
}


/*
* 功能描述： 进路预先锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteYuXianLockManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 startSignalPreDrvColor = 0u;   /*始端信号机上周期驱动颜色*/
	UINT8 cFuncRetVal = CI_ERROR;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

	startSignalCurColor = GetSignalCurColor(startSignalId);
	startSignalPreDrvColor = GetSignalPreDriveColor(startSignalId);

	openCloseState = GetSignalOpenCloseState(startSignalCurColor);

	if (SIGNAL_OPEN == openCloseState)
	{/*始端信号机开放*/
		if (SIGNAL_OPEN != GetSignalOpenCloseState(startSignalPreDrvColor))
		{/*之前驱动关闭*/
			/*驱动关闭的信号机未关闭*/
		}
		else
		{/*之前驱动开放*/
			if ((CI_SUCCESS == AutoSignalOrRouteValid(routeId)) ||
				(ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId)))
			{
				/*自动进路或信号有效||信号重开有效*/
				if (CI_SUCCESS == RouteHaveTrainNear(routeId))
				{ /*进路有车接近*/

					SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/

					RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
				}
				else
				{
					SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*-->设置预先开放*/

					RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
				}
			}
			else
			{
				/*信号机异常开放*/
				/*xxxxx宕机*/

				/*记录系统故障*/
				SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
					CI_DEVICE_TYPE_SIGNAL,
					startSignalId,
					ETYPE_SYSTEM_SIGNAL_OPEN,
					openCloseState, ESEND_LEVEL_ZERO);
			}
		}
	}
	else
	{
		/*信号关闭*/

		if (CI_SUCCESS == RouteHaveTrainNear(routeId))
		{
			/*有车接近*/

			SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
		}
		else
		{
			/*无车接近*/

			if (((CI_SUCCESS == AutoSignalOrRouteValid(routeId)) && (SIGNAL_DS_BREAK_NO == GetSignalDsBreakFlag(startSignalId))) ||
				(ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId)))
			{
				/*自动进路或信号有效||信号重开有效*/

				/*开放进路信号处理*/
				cFuncRetVal = OpenRouteSignalProc(routeId);
				if (CI_SUCCESS == cFuncRetVal)
				{
					/*开放成功，等待开灯*/
				}
				else
				{
					/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
					SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
				}
			}
			else
			{
				/*无重开或自动信号*/
			}
		}
	}
}


/*
* 功能描述： 进路预先开放管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteYuXianOpenManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 needOpenNotTrueRepeatFlag = ROUTE_NEEDOPEN_REOPEN_NO;
	UINT8 curColor = 0u;
	UINT8 sigState = 0u;
	UINT8 funcId = EFUNC_RouteYuXianOpenManage;/*函数ID*/
	UINT8 checkResult = 0u;
	UINT8 dctyReOpenFlag = ROUTE_DCTY_REOPEN_NO;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

	curColor = GetSignalCurColor(startSignalId);

	sigState = GetSignalOpenCloseState(curColor);

	if (SIGNAL_OPEN == sigState)
	{ /*信号开放*/
		needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
		if (ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag)
		{
			SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
			SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0);
		}

		dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);
		if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
		{
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
			SetRouteDCTYNotSatisfyStartCnt(routeId, 0U);
		}
		else
		{
			;
		}

		/*保持开放进路信号处理*/
		checkResult = KeepOpenRouteSignalProc(routeId);
		if (CI_SUCCESS == checkResult)
		{
			/*保持成功*/
			checkResult = RouteHaveTrainNear(routeId);
			if (CI_SUCCESS == checkResult)
			{
				/*进路有车接近*/
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->接近开放*/

				RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
			}
			else
			{
				/*保持预先开放*/
				return;
			}
		}
		else
		{
			/*保持失败*/
			checkResult = RouteHaveTrainNear(routeId);
			if (CI_SUCCESS == checkResult)
			{
				/*有车接近*/
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);    /*-->设置接近锁闭异常*/
			}
			else
			{
				/*无车接近*/
				SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_LOCK);     /*-->设置预先锁闭*/
			}

			/*保持开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
	}
	else
	{
		/*信号关闭*/
		checkResult = RouteHaveTrainNear(routeId);
		if (CI_SUCCESS == checkResult)
		{
			/*有车接近*/
			SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);    /*-->设置接近锁闭异常*/
		}
		else
		{
			/*无车接近*/
			SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_LOCK);     /*-->设置预先锁闭*/
		}

		/*增加信号机故障关闭报警*/
		SetErrorData(funcId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, sigState, ESEND_LEVEL_ATS);

		/*保持开放期间信号异常关闭，设置对应始端信号机扣车旁路按钮无效*/
		SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
	}
}


/*
* 功能描述： 进路接近锁闭异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* mod： 更新编码规范，if判断之前承接，更新重开信号后重新判断是否接近
*/
void RouteNearLockErrManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 startSignalPreDrvColor = 0u;   /*始端信号机上周期驱动颜色*/
	UINT8 routeAutoState = 0u;
	UINT16 sigInfirPhySecId = 0u;/*信号机内方第一区段*/
	UINT8 preOpenCloseState = 0U; /*上周期开放状态*/
	UINT8 autoSignalValid = 0U; /*进路自动信号是否有效*/
	UINT8 startSignalDsStat = 0U;
	UINT8 routeRepeatStat = 0U;
	UINT8 routeTrainNear = 0U;
	UINT8 cFuncRetVal = CI_ERROR;
	UINT8 cFuncSwitch = 0U;

	/*获取进路始端信号机ID*/
	startSignalId = GetRouteStartSignalId(routeId);
	sigInfirPhySecId = GetSignalInFirstPhySecId(startSignalId, routeId);

	startSignalCurColor = GetSignalCurColor(startSignalId);
	startSignalPreDrvColor = GetSignalPreDriveColor(startSignalId);

	openCloseState = GetSignalOpenCloseState(startSignalCurColor);
	routeAutoState = GetRouteAutoRouteSetState(routeId);

	preOpenCloseState = GetSignalOpenCloseState(startSignalPreDrvColor);

	autoSignalValid = AutoSignalOrRouteValid(routeId);								/*自动信号有效标志*/
	startSignalDsStat = GetSignalDsBreakFlag(startSignalId);						/*信号机灯丝标志*/
	routeRepeatStat = GetRouteRepeatOpenFlag(routeId);								/*进路重开标志*/
	routeTrainNear = RouteHaveTrainNear(routeId);                                   /*进路列车接近*/
	if (SIGNAL_OPEN == openCloseState)
	{/*始端信号机开放*/
		if (SIGNAL_OPEN != preOpenCloseState)
		{/*之前驱动关闭*/
			/*驱动关闭的信号机未关闭*/
		}
		else
		{/*之前驱动开放*/
			if ((CI_SUCCESS == autoSignalValid) || (ROUTE_REPEATOPEN_SET_YES == routeRepeatStat))
			{ /*自动信号或者重开*/
				cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_REOPRN_SET_NEAR);
				if(FUNC_SWITCH_ON == cFuncSwitch)
				{
					/*“重开信号是否记忆进路接近锁闭状态开关”配置为0xAA时，默认设置进路接近*/
					SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/
					RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
				}
				else
				{
					/*“重开信号是否记忆进路接近锁闭状态开关”配置为0x55时，根据接近区段占用状态设置进路接近/未接近*/
					if (CI_SUCCESS == routeTrainNear)
					{/*进路有车接近*/
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/

						RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
					}
					else
					{/*进路无车接近*/
						SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*-->设置预先开放*/

						RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
					}
				}
			}
			else
			{
				/*信号异常开放*/
				/*xxxxx宕机*/

				/*记录系统故障*/
				SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
					CI_DEVICE_TYPE_SIGNAL,
					startSignalId,
					ETYPE_SYSTEM_SIGNAL_OPEN,
					openCloseState, ESEND_LEVEL_ZERO);
			}
		}
	}
	else
	{
		/*信号关闭*/
#if 0
		/*需求变化：燕房线正线内方第一区段不再变绿光带20171016*/
		/*如果信号机跨压且内方第一区段空闲，则设置第一区段故障锁闭，并给现地反馈：信号异常关闭，信号机内方第一区段空闲*/
		if ((SIGNAL_CROSS_STATE_YES == GetSignalCrossState(startSignalId)) && (SECTION_OCCUPY_NO == GetPhySecCurMergeState(sigInfirPhySecId)))
		{
			/*添加给现地反馈：信号异常关闭，信号机内方第一区段空闲*/
			SetCiSendCmdBackInfoData(CI_BACK_SIG_CLOSE_EXCEPT, CI_DEVICE_TYPE_SIGNAL, startSignalId, 0, 0);
			/*设置内方第一区段故障锁闭*/
			SetPhySecLockState(sigInfirPhySecId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));
			/*-->设置自动解锁异常*/
			SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
		}
		else
		{
		}
#endif
		if (((CI_SUCCESS == autoSignalValid) && (SIGNAL_DS_BREAK_NO == startSignalDsStat)) ||
			(ROUTE_REPEATOPEN_SET_YES == routeRepeatStat))
		{
			/*自动进路或信号有效||信号重开有效*/

			/*开放进路信号处理*/
			cFuncRetVal = OpenRouteSignalProc(routeId);

			if (CI_SUCCESS == cFuncRetVal)
			{
				/*开放成功，等待开灯*/
			}
			else
			{
				/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
				SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
			}
		}
		else
		{
			/*无重开信号*/
		}
	}
}


/*
* 功能描述： 进路接近开放管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteNearOpenManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 routeState = 0u;
	UINT8 autoSigRouteType = 0u;
	UINT16 errorCodeCurSum = 0u;  /*错误码总数目*/
	ErrorDataStruct* errorCodeStu = NULL; /*错误码数据*/
	UINT16 ii = 0u;  /*循环索引*/
	UINT8 curColor = 0u;
	UINT8 sigState = 0u;
	UINT8 funcId = EFUNC_RouteNearOpenManage;/*函数ID*/
	UINT8 checkResult = 0u;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

	curColor = GetSignalCurColor(startSignalId);

	sigState = GetSignalOpenCloseState(curColor);

	/*如果始端信号内外方同时占压，认为列车驶入；注意：该驶入标志，只用于总人解判断，与正常的列车驶入判断存在差异*/
	checkResult = RouteInOutSecOccupy(routeId);
	if (CI_SUCCESS == checkResult)
	{
		SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_YES);
	}

	if (SIGNAL_OPEN == sigState)
	{ /*信号开放*/

		/*保持开放进路信号处理*/
		checkResult = KeepOpenRouteSignalProc(routeId);
		if (CI_SUCCESS == checkResult)
		{
			/*保持成功*/
			return;
		}
		else
		{
			/*保持失败*/
			checkResult = RouteLTrainEnter(routeId);
			if (CI_SUCCESS == checkResult)
			{ /*列车驶入*/
				errorCodeCurSum = GetErrorDataCurSum();  /*获取错误码总数*/
				/*处理错误码*/
				for (ii = 0u; ii < errorCodeCurSum; ii++)
				{
					errorCodeStu = GetErrorData(ii);  /*获取错误码数据*/

					if (NULL != errorCodeStu)
					{

						if ((EFUNC_KEEP_BLOC_T_SIGNAL == errorCodeStu->FunctionId) || (EFUNC_KEEP_BLOC_R_SIGNAL == errorCodeStu->FunctionId))
						{/*点式列车进路信号保持和点式折返进路信号保持*/
							/*点式级别进路*/
							if ((CI_DEVICE_TYPE_PHYSEC == errorCodeStu->DeviceType) && (ETYPE_PS_MERGY_OCU_STATE == errorCodeStu->DeviceStateType))
							{   /*正常驶入，将错误反馈删除*/
								DeleteErrorData(ii);
							}

						}
						else if ((EFUNC_KEEP_CBTC_T_SIGNAL == errorCodeStu->FunctionId) || (EFUNC_KEEP_CBTC_R_SIGNAL == errorCodeStu->FunctionId))
						{ /*CBTC级别进路*/
							if ((CI_DEVICE_TYPE_LOGICSEC == errorCodeStu->DeviceType) && (ETYPE_LOGSEC_OCC_STATE == errorCodeStu->DeviceStateType))
							{/*此时认为是正常压入*/
								DeleteErrorData(ii);
							}

						}
						else if ((EFUNC_CLD_KEEP_L_TRAIN_ROUTE == errorCodeStu->FunctionId) || (EFUNC_CLD_KEEP_D_TRAIN_ROUTE == errorCodeStu->FunctionId))
						{/*列车进路和调车进路信号保持*/
							if (((CI_DEVICE_TYPE_PHYSEC == errorCodeStu->DeviceType) || (CI_DEVICE_TYPE_LOGICSEC == errorCodeStu->DeviceType)) &&
								(ETYPE_PS_MERGY_OCU_STATE == errorCodeStu->DeviceStateType))
							{   /*正常驶入，将错误反馈删除*/
								DeleteErrorData(ii);
							}

						}
						else
						{
							/*其他不作处理*/
						}
					}
				}
				checkResult = AutoSignalOrRouteValid(routeId);
				if (CI_SUCCESS == checkResult)
				{ /*自动进路或信号有效*/
					routeState = GetRouteAutoRouteSetState(routeId);
					autoSigRouteType = GetRouteAutoSigSetState(routeId);/*获取进路当前是否为自动信号进路*/

					if ((routeState == ROUTE_AUTOROUTE_RETURN) || (routeState == ROUTE_ALLAUTOROUTE_RETURN)
						|| (autoSigRouteType == ROUTE_AUTOSIGROUTE_YES))
					{
						/*自动折返进路可解锁*//*自动信号按正常转移状态走，在接近锁闭正常逻辑中处理解锁问题*/

						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCK);  /*-->设置接近锁闭正常*/
					}
					else
					{

						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
					}
				}
				else
				{
					SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCK);  /*-->设置接近锁闭正常*/
				}
			}
			else
			{
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
			}

			/*保持开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
	}
	else
	{
		/*信号故障关闭*/
		SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/

		/*增加信号机故障关闭报馈警*/
		SetErrorData(funcId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, sigState, ESEND_LEVEL_ATS);

		/*保持开放期间信号异常关闭，设置对应始端信号机扣车旁路按钮无效*/
		SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
	}
}


/*
* 功能描述： 进路接近锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
#if 0
void RouteNearLockManage(const UINT16 routeId)
{
	UINT16 phySectionId = 0u;        /*物理区段ID*/
	UINT8 returnValue = 0u;          /*函数返回值*/
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 	autoSigRouteState = 0u;        /*自动信号进路状态*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 startSignalPreDrvColor = 0u;   /*始端信号机上周期驱动颜色*/

	/*获取进路始端信号机ID*/
	startSignalId = GetRouteStartSignalId(routeId);
	autoSigRouteState = GetRouteAutoSigSetState(routeId);        /*获取自动信号进路状态*/
	startSignalCurColor = GetSignalCurColor(startSignalId);
	startSignalPreDrvColor = GetSignalPreDriveColor(startSignalId);
	openCloseState = GetSignalOpenCloseState(startSignalCurColor);

	if ((SIGNAL_OPEN == openCloseState) && (startSignalCurColor != startSignalPreDrvColor))
	{
		/*驱动关闭的信号机未关闭*/
		return;
	}
	else if ((SIGNAL_OPEN == openCloseState) && (startSignalCurColor == startSignalPreDrvColor))
	{
		if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
		{

			if (CI_SUCCESS == RouteHaveTrainNear(routeId))
			{/*进路有车接近*/
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/

				RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
			}
			else
			{/*进路无车接近*/
				SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*-->设置预先开放*/

				RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
			}
		}
	}
	else
	{  /*始端信号机关闭*/
		if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
		{
			if (SIGNAL_DS_BREAK_NO == GetSignalDsBreakFlag(startSignalId))
			{
				/*自动信号重开有效*/

				/*开放进路信号处理*/
				OpenRouteSignalProc(routeId);

			}
		}
		else
		{

			/*进路区段自动解锁处理*/
			returnValue = RouteFirstSecAutoUnlockLogicProcess(routeId, &phySectionId);

			if (phySectionId > 0u)
			{
				if (CI_SUCCESS == returnValue)
				{ /*解锁成功*/

					SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_DELAY, routeId, GetRouteDirection(routeId));  /*设置物理区段延时解锁*/

					SetPhySecAutoUnlockStartCycNum(phySectionId, Get2oo2CurCycleNum());  /*设置物理区段延时解锁起始周期*/

					SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCK);   /*-->设置自动解锁正常*/
				}
				else if (RETURN_AUTOLOCK_ERR_EXCEPT == returnValue)
				{ /*解锁异常*/

					SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);   /*-->设置接近锁闭异常*/
				}
				else
				{ /*解锁失败*/
				}
			}
		}
	}
}
#endif

/*	@func 进路接近锁闭管理
*	@param UINT16 routeId 进路ID
*	@return void
*	@brief 更新逻辑区段关联物理区段为直接关联
*/
void RouteNearLockManage(const UINT16 routeId)
{
	UINT16 phySectionId = 0u;        /*物理区段ID*/
	UINT8 returnValue = 0u;          /*函数返回值*/
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 	autoSigRouteState = 0u;        /*自动信号进路状态*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 startSignalPreDrvColor = 0u;   /*始端信号机上周期驱动颜色*/
	UINT16 fLockLogId = 0u;
	UINT8 logCurOccupyState = 0u;
	UINT8 logPreOccupyState = 0u;
	UINT16 logSectionId = 0u;
	UINT16 logBelongPhyId = 0u;
	UINT8 routeDir = 0u;
	UINT32 cycNum = 0u;
	UINT8 chPhyIncSwitchSum = 0U;
	UINT16* pPhySecSwitchId = NULL;
	UINT8 chRoutePhysectionSum = 0U; /*区段总数*/
	RoutePhysicalSectionStruct* pRouteSecStru = NULL; /*区段数据*/
	UINT8 chRoutePhySecState = 0U;/*进路包含物理区段当前融合状态*/
	UINT8 chRoutePhySecType = 0U;/*进路包含物理区段当前类型*/
	UINT8 chRouteType = 0u;/*进路类型*/
	UINT16 validReturnSigId = 0U;  /*有效折返信号机*/
	UINT16 returnSecId = 0U;  /*折返区段*/
	UINT8 localCiType = 0U;/*联锁类型*/
	UINT8 cFuncRetVal = CI_ERROR;

	localCiType = GetLocalCiType();
	/*获取进路始端信号机ID*/
	startSignalId = GetRouteStartSignalId(routeId);
	autoSigRouteState = GetRouteAutoSigSetState(routeId);        /*获取自动信号进路状态*/
	startSignalCurColor = GetSignalCurColor(startSignalId);
	startSignalPreDrvColor = GetSignalPreDriveColor(startSignalId);
	openCloseState = GetSignalOpenCloseState(startSignalCurColor);
	cycNum = Get2oo2CurCycleNum();
	/*获取进路方向*/
	routeDir = GetRouteDirection(routeId);
	chRoutePhysectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	chRouteType = GetRouteType(routeId);/*获取进路类型*/
	chRoutePhySecState = GetPhySecCurMergeState(pRouteSecStru[0].PhysicalSectionId);/*进路包含物理区段当前融合状态*/
	chRoutePhySecType = GetPhySecType(pRouteSecStru[0].PhysicalSectionId);/*进路包含物理区段当前类型*/

	if ((ROUTE_TYPE_DIAOCHE == chRouteType) &&
		(PHYSICAL_SEC_TYPE_NOSWITCH == chRoutePhySecType) &&
		(1u == chRoutePhysectionSum) &&
		(SECTION_OCCUPY_YES == chRoutePhySecState))
	{ /*cgh合并调车进路处理：调车进路&&只有一个区段&&无岔区段&&此区段融合占用*/

		SetPhySecLockState(pRouteSecStru[0].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, routeId, routeDir);  /*设置物理区段未锁闭*/
		/*同时设置物理区段其他属于本进路锁闭的逻辑区段未锁闭*/
		SetPhyIncludeLogLockState(pRouteSecStru[0].PhysicalSectionId, LOG_SECTION_LOCK_NO, routeId);
		SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
	}
	else
	{

		if (SIGNAL_OPEN == openCloseState)
		{/*始端信号机开放*/
			if (SIGNAL_OPEN != GetSignalOpenCloseState(startSignalPreDrvColor))
			{/*之前驱动关闭*/
				/*驱动关闭的信号机未关闭*/
			}
			else
			{/*之前驱动开放*/
				if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
				{
					if (CI_SUCCESS == RouteHaveTrainNear(routeId))
					{/*进路有车接近*/
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/

						RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
					}
					else
					{/*进路无车接近*/
						SetRouteStateManage(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*-->设置预先开放*/

						RouteYuXianOpenManage(routeId);  /*进路预先开放管理*/
					}
				}
				else
				{
					/*增加本else分之。修改日期：2017年02月10日。修改原因：支持接近锁闭异常时，响应信号重开命令*/
					if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
					{
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/

						RouteNearOpenManage(routeId); /*-->进路接近开放管理*/
					}
					else
					{
						/*记录系统故障*/
						SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
							CI_DEVICE_TYPE_SIGNAL,
							startSignalId,
							ETYPE_SYSTEM_SIGNAL_OPEN,
							openCloseState, ESEND_LEVEL_ZERO);
					}
				}
			}
		}
		else
		{	/*始端信号机关闭*/
			if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
			{
				if (SIGNAL_DS_BREAK_NO == GetSignalDsBreakFlag(startSignalId))
				{
					cFuncRetVal = OpenRouteSignalProc(routeId);

					if (CI_SUCCESS == cFuncRetVal)
					{
						/*开放成功，等待开灯*/
					}
					else
					{
						/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
						SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
					}
				}
				else
				{
					/*断丝时等待，不做处理*/
				}
			}
			else if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
			{
				/*(ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))。修改日期：2017年02月09日。修改原因：支持接近锁闭异常时，响应信号重开命令*/
				cFuncRetVal = OpenRouteSignalProc(routeId);

				if (CI_SUCCESS == cFuncRetVal)
				{
					/*开放成功，等待开灯*/
				}
				else
				{
					/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
					SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
				}
			}
			else
			{
				/*获取进路锁闭的第一逻辑区段占用状态*/
				fLockLogId = GetRouteFirstNormalLockLogId(routeId);
				logCurOccupyState = GetLogSecCurCtOrUtOccupyState(fLockLogId);
				logPreOccupyState = GetLogSecPreCtOrUtOccupyState(fLockLogId);

				logBelongPhyId = GetLgcSecRelativePhySecId(fLockLogId);
				chPhyIncSwitchSum = GetPhyIncludeSwitchSum(logBelongPhyId);

				pPhySecSwitchId = GetPhySecIncludeSwitch(logBelongPhyId);

				validReturnSigId = GetValidReturnSinalId(routeId, logBelongPhyId);
				returnSecId = GetSignalOutFirstPhySecId(validReturnSigId);
				/*逻辑区段当前CT占用，或者之前CT占用，当前空闲 且逻辑区段不是道岔区段，且非折返进路或为折返进路但非折返轨*/
				if (((LOGICSECTION_OCCUPY_CT == logCurOccupyState) ||
					((LOGICSECTION_OCCUPY_NO == logCurOccupyState) && (LOGICSECTION_OCCUPY_CT == logPreOccupyState)))
					&& ((0U == chPhyIncSwitchSum) && (NULL != pPhySecSwitchId))
					&& (((returnSecId != logBelongPhyId) && (0U != logBelongPhyId)) || ((ROUTE_TYPE_RETURN != chRouteType) && (0U == validReturnSigId)))
					&& (CI_TYPE_CLD != localCiType))
				{
					/*按逻辑区段解锁*/
					returnValue = RouteLogSecAutoUnlockProcess(routeId, &logSectionId);
				}
				else
				{
					/*按物理区段解锁：进路区段自动解锁处理*/
					returnValue = RouteFirstSecAutoUnlockProcess(routeId, &phySectionId);
				}

				/*待解锁的物理区段ID大于0，且逻辑区段等于0*/
				if ((0u < phySectionId) && (0u == logSectionId))
				{
					if (CI_SUCCESS == returnValue)
					{ /*解锁成功*/

						SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_DELAY, routeId, routeDir);  /*设置物理区段延时解锁*/

						/*同时设置物理区段其他属于本进路锁闭的逻辑区段延时锁闭*/
						SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_DELAY, routeId);

						SetPhySecAutoUnlockStartCycNum(phySectionId, cycNum);  /*设置物理区段延时解锁起始周期*/

						SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCK);   /*-->设置自动解锁正常*/
					}
					else if (RETURN_AUTOLOCK_ERR_EXCEPT == returnValue)
					{ /*解锁异常*/

#if 0
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);   /*-->设置接近锁闭异常*/
#endif
						if (ROUTE_TYPE_DIAOCHE == chRouteType)
						{
							/*cgh 20230630 YF0083-991*/
							SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);
						}
						else
						{
							/*设置物理区段异常锁闭*/
							SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, routeDir);
							/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
							SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_EXCEPT, routeId);
							/*-->设置自动解锁异常*/
							SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
						}
					}
					else if (CI_CANCLE_ZHAOCHA_FAIL == returnValue)
					{/*取消照查继电器未吸起*/
						/*设置进路接近锁闭异常*/
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);
					}
					else
					{ /*解锁失败*/
					}
				}
				/*待解锁的逻辑区段ID大于0，且物理区段等于0*/
				else if ((0u == phySectionId) && (0u < logSectionId))
				{
					/*解锁成功*/
					if (CI_SUCCESS == returnValue)
					{
						/*设置逻辑区段延时解锁*/
						SetLogSecLockState(logSectionId, LOG_SECTION_LOCK_DELAY, routeId, routeDir);
						/*设置逻辑区段延时解锁起始周期号*/
						SetLogUnlockStartCycNum(logSectionId, cycNum);
						SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCK);   /*-->设置自动解锁正常*/
					}
					/*解锁异常*/
					else if (RETURN_AUTOLOCK_ERR_EXCEPT == returnValue)
					{
						/*找到对应的物理区段*/
						logBelongPhyId = GetLgcSecRelativePhySecId(logSectionId);
						routeDir = GetRouteDirection(routeId);
						/*设置物理区段异常锁闭*/
						SetPhySecLockState(logBelongPhyId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, routeDir);
						/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
						SetPhyIncludeLogLockState(logBelongPhyId, LOG_SECTION_LOCK_EXCEPT, routeId);
						/*-->设置自动解锁异常*/
						SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
					}
					/*取消照查继电器未吸起*/
					else if (CI_CANCLE_ZHAOCHA_FAIL == returnValue)
					{
						/*设置进路接近锁闭异常*/
						SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);
					}
					else
					{ /*解锁失败*/
					}
				}
				/*其他情况*/
				else
				{
					/*不做处理*/
				}
			}
		}
	}
}

/*
* 功能描述： 进路延时解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteDelayUnlockManage(const UINT16 routeId)
{
	UINT8 routeLevel = 0u;         /*进路监督级别*/
	UINT16 startSignalId = 0u;     /*进路始端信号机ID*/
	UINT32 delayStartCycNum = 0u;  /*延时解锁起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时解锁总周期数*/
	UINT8 checkTimeState = CI_TIME_NO;
	UINT8 zrjDelayType;/*进路总人解延时类型*/
	UINT8 routePreState = 0u;/*进路之前状态*/
	UINT8 zqxDelayflag = 0u;/*总取消延时标志*/
	UINT8 checkRouteCancle = 0u;
	UINT8 checkZongRenJieRulst = 0u;
	UINT16 wTrainId = 0u;
	UINT16 wLastTrainId = 0u;
	UINT32 curCycle = 0u;
	UINT8 chRouteState = 0u;

	/*获取进路动态字段*/
	routeLevel = GetRouteLevel(routeId);                       /*获取进路监督级别*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/
	curCycle = Get2oo2CurCycleNum();
	chRouteState = GetRouteType(routeId);

	(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/

	if (SIGNAL_OPEN == GetSignalOpenCloseState(GetSignalCurColor(startSignalId)))
	{ /*信号开放*/

		return;
	}

	delayStartCycNum = GetRouteDelayUnlockStartCycNum(routeId);  /*获取进路延时解锁起始周期*/
	delayTotalCycSum = GetRouteDelayCycleCount(routeId);

	zrjDelayType = GetRouteZongRenJieDelayType(routeId);/*获得进路总人解延时类型*/
	/*获取总取消延时标志*/
	zqxDelayflag = GetRouteZongQuXiaoDelayFlag(routeId);

	/*进路总取消标志设置*/
	if (ROUTE_ZQX_DELAY_YES == zqxDelayflag)
	{
		/*进路取消条件检查*/
		checkRouteCancle = RouteCancelLogicProcess(routeId);
		/*取消进路条件满足*/
		if (CI_SUCCESS == checkRouteCancle)
		{
			/*延时计时*/
			checkTimeState = SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum);
			/*解锁计时超时*/
			if (CI_TIME_OUT == checkTimeState)
			{
				/*-->设置进路空闲*/
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
				/*取消延时不设置*/
				SetRouteZongQuXiaoDelayFlag(routeId, ROUTE_ZQX_DELAY_NO);
			}
			else
			{
				/*等待计时*/
			}

		}
		else
		{
			/*设置初锁异常*/
			SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);
			/*取消延时不设置*/
			SetRouteZongQuXiaoDelayFlag(routeId, ROUTE_ZQX_DELAY_NO);
		}
	}
	else
	{
		if (ROUTE_ZRJ_DELAY_TYPE_IDLE == zrjDelayType)
		{
			/*进路取消条件检查*/
			checkRouteCancle = RouteCancelLogicProcess(routeId);
			if (CI_SUCCESS == checkRouteCancle)
			{
				/*取消成功*/
				checkTimeState = SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum);

				if ((CI_TIME_OUT == checkTimeState) || (ROUTE_STOPENSURE_YES == GetRouteStopensureFlag(routeId)))
				{
					/*解锁超时或收到停车保证*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
					/* 清除询问列车ID */
					SetRouteStopEnsureTrainId(routeId, 0u);
					SetRouteStopEnsureCyc(routeId, 0u);
				}
				else
				{
					/*时间未到或未设置*/
					wTrainId = GetRouteNearestTrainId(routeId);
					wLastTrainId = GetRouteStopEnassureTrainId(routeId);

					if ((wTrainId != wLastTrainId) && (0u != wTrainId))
					{
						/* 询问或者前车变了，重新问 */
						SetRouteStopEnsureTrainId(routeId, wTrainId);
						SetRouteStopEnsureCyc(routeId, curCycle);
					}
				}
			}
			else
			{ /*取消失败*/
				routePreState = GetRoutePreState(routeId);
				/* 清除询问列车ID */
				SetRouteStopEnsureTrainId(routeId, 0u);
				SetRouteStopEnsureCyc(routeId, 0u);
				if ((ROUTE_STATE_LEAD_LOCKERR == routePreState) || (ROUTE_STATE_LEAD_LOCK == routePreState))
				{
					SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
				}
				else if ((ROUTE_STATE_FIRST_LOCK == routePreState) || (ROUTE_STATE_YUXIAN_LOCK == routePreState) || (ROUTE_STATE_FIRST_LOCKERR == routePreState))
				{
					SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);  /*-->设置初锁异常*/
				}
				else
				{
					SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
				}
				SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
			}
		}
		else if ((ROUTE_ZRJ_DELAY_TYPE_ALL_EXP == zrjDelayType) || (ROUTE_ZRJ_DELAY_TYPE_EXP_TO_OCCUPY == zrjDelayType))
		{
			checkZongRenJieRulst = CheckRouteZongRenJieFeasibility(routeId);
			if (CI_SUCCESS == checkZongRenJieRulst)
			{
				/*取消成功*/
				checkTimeState = SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum);

				if ((CI_TIME_OUT == checkTimeState) || (ROUTE_STOPENSURE_YES == GetRouteStopensureFlag(routeId)))
				{
					/*解锁超时或收到停车保证*/

					/*将进路内所有物理区段变成绿光带*/

					if (ROUTE_ZRJ_DELAY_TYPE_ALL_EXP == zrjDelayType)
					{
						SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_EXCEPT);

						/*进路逻辑区段都故障锁闭*/
						SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_EXCEPT);
					}
					else
					{
						/*只将列车走过的白光带变成绿光带*/
						SetRoutePhySecExpLockToOccupy(routeId);
					}

					SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);

					/* 清除询问列车ID */
					SetRouteStopEnsureTrainId(routeId, 0u);
					SetRouteStopEnsureCyc(routeId, 0u);
				}
				else
				{
					/*时间未到或未设置,获取进路内的列车ID*/
					wTrainId = GetRouteNearestTrainId(routeId);


					wLastTrainId = GetRouteStopEnassureTrainId(routeId);

					if ((wTrainId != wLastTrainId) && (0u != wTrainId))
					{
						/* 询问或者前车变了，重新问 */
						SetRouteStopEnsureTrainId(routeId, wTrainId);
						SetRouteStopEnsureCyc(routeId, curCycle);
					}
				}

			}
			else
			{ /*取消失败*/
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
				SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
				/* 清除询问列车ID */
				SetRouteStopEnsureTrainId(routeId, 0u);
				SetRouteStopEnsureCyc(routeId, 0u);
			}
		}
		else
		{
			SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
		}
	}
}


/*
* 功能描述： 进路物理区段自动解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RoutePhySecAutoUnlockManage(const UINT16 routeId)
{
	UINT16 phySectionId = 0u;        /*物理区段ID*/
	UINT8 returnValue = 0u;          /*函数返回值*/
	UINT8  localCiType = 0u;
	UINT16  sectionSum = 0u;    /*区段总数*/
	UINT16 sectionId = 0u;     /*区段ID*/
	UINT8  sectionState = 0u;  /*设备状态*/
	UINT16 applyRelayId = 0u; /*申请试车继电器ID*/
	UINT16 allowRelayId = 0u; /*允许试车继电器ID*/
	UINT8 ii = 0u;
	UINT8 expLockCancel = 0u; /*标志位*//*默认不取消异常锁闭*/
	UINT8 kk = 0;
	NonRouteDataStruct* pNonData = NULL;
	UINT8 interfaceType = GetCiFunctionSwitchConfig(SCX_CLD_INTERFACE_TYPE);/*获取试车线与车辆段接口方式类型*/

	/*进路区段自动解锁处理*/
	returnValue = RouteOtherSecAutoUnlockProcess(routeId, &phySectionId);

	if (0u == phySectionId)
	{
		/*未找到正常锁闭区段*/
	}
	else
	{
		if (CI_SUCCESS == returnValue)
		{ /*区段解锁成功*/
			SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_DELAY, routeId, GetRouteDirection(routeId));  /*设置物理区段延时解锁*/

			/*同时设置物理区段其他属于本进路锁闭的逻辑区段延时锁闭*/
			SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_DELAY, routeId);

			SetPhySecAutoUnlockStartCycNum(phySectionId, Get2oo2CurCycleNum());  /*设置物理区段延时解锁起始周期*/
		}
		else if (RETURN_AUTOLOCK_ERR_EXCEPT == returnValue)
		{
			/*解锁异常*/
			localCiType = GetLocalCiType();
			if (CI_TYPE_SCX == localCiType)
			{
				/*获取非进路id*/

				for (; kk < NONROUTE_ID_NUM_MAX; kk++)
				{
					pNonData = GetNonRouteDataPtr() + kk;
					if (SCX_CLD_INTERFACE_RELAY == interfaceType)
					{/*试车线与车辆段采用继电器接口*/
						applyRelayId = GetSCXDrvApplyTryRelayIdById(pNonData->NonRouteId);
						allowRelayId = GetSCXColAgreeTryRelayIdById(pNonData->NonRouteId);

						if ((RELAY_STATE_DOWN == GetRelayCollState(applyRelayId)) && (RELAY_STATE_DOWN == GetRelayCollState(allowRelayId)))
						{
							sectionSum = GetPhySecCurSum();
							for (ii = 0u; ii < sectionSum; ii++)
							{
								sectionId = GetPhySecId(ii);                      /*获取物理区段ID*/
								sectionState = GetPhySecCurMergeState(sectionId);

								if (SECTION_OCCUPY_NO != sectionState)
								{
									break;
								}
							}

							if (ii == sectionSum)
							{
								expLockCancel = 1u;
							}
						}
					}
					else if ((SCX_CLD_INTERFACE_COMM == interfaceType) || (SCX_CLD_SERIAL_PORT_COMM == interfaceType))
					{/*试车线与车辆段通信接口*/
						if ((COMM_TRAIN_TEST_DEV_STATE_INVALID == GetCommTrainTestSCXSQAJStatus()) && (COMM_TRAIN_TEST_DEV_STATE_INVALID == GetCommTrainTestSCXYSKJStatus()))
						{/*两个设备状态无效，认为试车结束，列车已驶入车辆段*/
							sectionSum = GetPhySecCurSum();
							for (ii = 0u; ii < sectionSum; ii++)
							{
								sectionId = GetPhySecId(ii);                      /*获取物理区段ID*/
								sectionState = GetPhySecCurMergeState(sectionId);

								if (SECTION_OCCUPY_NO != sectionState)
								{
									break;
								}
							}

							if (ii == sectionSum)
							{/*最后一个区段占用*/
								expLockCancel = 1u;
							}
						}
					}
					else
					{
						/*无操作*/
					}
				}
			}

			if (1u == expLockCancel)
			{
				/*所有物理区段空闲,试车线特殊处理，避免产生绿光带*/
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);    /*设置进路空闲*/
			}
			else
			{
				/*设置物理区段异常锁闭*/
				SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));
				/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
				SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_EXCEPT, routeId);
				/*-->设置自动解锁异常*/
				SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
			}
			return;
		}
		else
		{
			/*解锁失败*/
		}
	}
#if 0
	/*进路区段延时解锁处理*/
	PhySecDelayUnlockProc(routeId);
#endif
}


/*
* 功能描述： 进路物理区段自动解锁异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RoutePhySecAutoUnlockErrManage(const UINT16 routeId)
{
	UINT16 dlockLogId = 0u;
	UINT32 logUnlockStartCycNum = 0u;
	UINT32 phyUnlockStartCycNum = 0u;
	UINT16 logBelongPhyId = 0u;

	/*获取第一个延时锁闭逻辑区段*/
	dlockLogId = GetRouteFirstDelayLockLogId(routeId);
	logUnlockStartCycNum = GetLogUnlockStartCycNum(dlockLogId);

	/*获取第一延时锁闭逻辑区段所属物理区段*/
	logBelongPhyId = GetLgcSecRelativePhySecId(dlockLogId);

	/*获取物理区段延时解锁周期号*/
	phyUnlockStartCycNum = GetPhySecAutoUnlockStartCycNum(logBelongPhyId);

	/*逻辑区段延时解锁起始周期号大于0*/
	if ((dlockLogId > 0u) && (logUnlockStartCycNum > 0u))
	{
		/*延时解锁该逻辑区段*/
		LogSecDelayUnlockProc(routeId);
	}
	/*说明是物理区段在延时解锁*/
	else if ((dlockLogId > 0u) && (0u == logUnlockStartCycNum) && (phyUnlockStartCycNum > 0u))
	{
		/*按物理区段延时解锁*/
		PhySecDelayUnlockProc(routeId);
	}
	else
	{
		/*不做处理*/
	}
	/*异常锁闭区段传递*/
	RouteExpLockContinue(routeId);
}


/*
* 功能描述： 进路引导锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLeadLockManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 returnValue = 0u;        /*返回值定义*/
	UINT32 dwDelayOpenStartCyc = 0U;  /*声光报警延时开放起始周期*/
	UINT32 dwDelayOpenCycNum = 0U;  /*声光报警延时开放周期数*/
	UINT8 cRouteCanOpenFlag = CI_ERROR;  /*进路可开放标志*/
	UINT8 cTimeCheckFlag = CI_TIME_NO;
	UINT32 dwRouteSigOpenStartCyc = 0U;  /*进路信号开放起始周期*/
	UINT32 dwCurCyc = 0U;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

#if 0
	if (RouteSecFlockVainCheck(routeId) == CI_ERROR)
	{
		/*有区段封锁*/
		SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*设置引导锁闭异常*/

		return;
	}
#endif

	if (SIGNAL_OPEN == GetSignalOpenCloseState(GetSignalCurColor(startSignalId)))
	{ /*信号开放*/
		if (GetPhySecCurMergeState(GetSignalInFirstPhySecId(startSignalId, routeId)) == SECTION_OCCUPY_YES)
		{/*内方区段故障*/
			SetRouteLeadFaultOpenStartCyc(routeId, Get2oo2CurCycleNum());  /*设置引导故障延时时间*/
		}
		else
		{
			SetRouteLeadFaultOpenStartCyc(routeId, 0u);  /*清除引导故障延时时间*/
		}

		SetRouteStateManage(routeId, ROUTE_STATE_LEAD_OPEN);  /*设置引导开放*/

		RouteLeadOpenManage(routeId);/*进路引导开放管理*/
	}
	else
	{ /*信号关闭*/
		dwDelayOpenStartCyc = GetRouteDelayOpenStartCyc(routeId);  /*获取进路声光报警延时开放起始周期号*/
		dwDelayOpenCycNum = GetSGBJRouteDelayOpenCount();
		cTimeCheckFlag = SystemOverTimeCheck(dwDelayOpenStartCyc, dwDelayOpenCycNum);

		if ((CI_TIME_OUT == cTimeCheckFlag) || (CI_TIME_NO == cTimeCheckFlag))
		{
			dwRouteSigOpenStartCyc = GetRouteOpenSigStatrtCycNum(routeId);
			if (0U == dwRouteSigOpenStartCyc)
			{
				dwCurCyc = Get2oo2CurCycleNum();
				SetRouteOpenSigStartCycNum(routeId, dwCurCyc);  /*因声光报警延时导致进路信号开放时间未设置，此处设置进路信号开放时间为当前周期*/
			}
			else
			{
				/*进路信号开放起始周期已设置，不处理*/
			}
			SetRouteDelayOpenStartCyc(routeId, 0U);  /*清除声光报警延时开放起始周期号*/
			cRouteCanOpenFlag = CI_SUCCESS;
		}
		else
		{
			/*延时中，不处理*/
		}

		returnValue = OpenLeadRouteLogicProcess(routeId);

		/*开放引导进路信号处理*/
		if (CI_SUCCESS == returnValue)
		{ /*检查成功*/
			if (CI_SUCCESS == cRouteCanOpenFlag)
			{
				DriveSignalOpen(startSignalId, routeId);  /*驱动进路信号开放*/
			}
			else
			{
				/*延时中，不处理*/
			}
#if 0
			CleanRoutePhySecPreOccupyState(routeId);  /*清除进路相关物理区段之前占用状态*/
#endif
		}
		else if (RETURN_OPEN_ERR_SIGOPEN == returnValue)
		{ /*需关闭信号未关闭*/
			(void)DriveSignalClose(startSignalId);    /*驱动信号关闭*/
		}
		else if (RELAY_STATE_WAITE == returnValue)
		{
			/*等待驱落*/
		}
		else
		{ /*检查失败*/

			SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
			/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
	}
}


/*
* 功能描述： 进路引导锁闭异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLeadLockErrManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT8 startSignalPreDrvColor = 0u;   /*始端信号机上周期驱动颜色*/


	/*获取进路始端信号机ID*/
	startSignalId = GetRouteStartSignalId(routeId);

	startSignalCurColor = GetSignalCurColor(startSignalId);
	startSignalPreDrvColor = GetSignalPreDriveColor(startSignalId);

	openCloseState = GetSignalOpenCloseState(startSignalCurColor);

	if ((SIGNAL_OPEN == openCloseState) && (startSignalCurColor != startSignalPreDrvColor))
	{
		/*驱动关闭的信号机未关闭*/
		return;
	}
	else if ((SIGNAL_OPEN == openCloseState) && (startSignalCurColor == startSignalPreDrvColor))
	{
		/*信号开放*/

		if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
		{
			/*信号重开有效*/
			SetRouteStateManage(routeId, ROUTE_STATE_LEAD_OPEN);   /*-->设置引导开放*/

			RouteLeadOpenManage(routeId);/*进路引导开放管理*/
		}
		else
		{
			/*信号异常开放*/
			/*xxxxx宕机*/

			/*记录系统故障*/
			SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
				CI_DEVICE_TYPE_SIGNAL,
				startSignalId,
				ETYPE_SYSTEM_SIGNAL_OPEN,
				openCloseState, ESEND_LEVEL_ZERO);

		}
	}
	else
	{
		/*信号关闭*/

	}
}


/*
* 功能描述： 进路引导开放管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* 修复bug YF0083-100
*/
void RouteLeadOpenManage(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 returnValue = 0u;          /*返回值定义*/
	UINT8 judgeOccupy = 0u;          /*判断始端信号机内外方物理区段是否同时占压*/
	UINT8 sigOpenCloseState = 0u;    /*信号机开放关闭状态*/
	UINT8 phyCurMergState = 0u;      /*物理区段当前融合状态*/
	UINT16 phySecId = 0u;            /*物理区段ID*/
	UINT8 driveRetVal = 0U;

	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

#if 0
	if (RouteSecFlockVainCheck(routeId) == CI_ERROR)
	{
		/*有区段封锁*/
		DriveSignalClose(startSignalId);    /*驱动信号关闭*/

		SetRouteLeadFaultOpenStartCyc(routeId, 0u);  /*设置引导故障延时时间*/

		SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*设置引导锁闭异常*/

		return;
	}
#endif
	
	/*如果始端信号内外方同时占压，认为列车驶入；注意：该驶入标志，只用于总人解判断，与正常的列车驶入判断存在差异*/
	judgeOccupy = RouteInOutSecOccupy(routeId);
	if (CI_SUCCESS == judgeOccupy)
	{
		SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_YES);
	}

	sigOpenCloseState = GetSignalOpenCloseState(GetSignalCurColor(startSignalId));
	if (SIGNAL_OPEN == sigOpenCloseState)
	{ /*信号开放*/

		/*保持开放引导进路信号处理*/
		returnValue = KeepLeadRouteLogicProcess(routeId);

		if (CI_SUCCESS == returnValue)
		{ /*保持成功*/

			phySecId = GetSignalInFirstPhySecId(startSignalId, routeId);
			phyCurMergState = GetPhySecCurMergeState(phySecId);
			if (SECTION_OCCUPY_NO == phyCurMergState)
			{/*内方第一区段未占用*/

				SetRouteLeadFaultOpenStartCyc(routeId, 0u);  /*清除引导故障延时时间*/
			}

			DriveSignalOpen(startSignalId, routeId);  /*驱动进路信号开放*/
		}
		else
		{ /*保持失败*/
			/*cgh-合并CID-2539-4：*/
			driveRetVal = DriveSignalClose(startSignalId);  /*驱动进路信号关闭*/
			if (CI_ERROR == driveRetVal)
			{
				/*驱动信号关闭失败*/
			}

			SetRouteLeadFaultOpenStartCyc(routeId, 0u);  /*设置引导故障延时时间*/
			SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/

			/*保持开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
	}
	else
	{
		/*信号关闭*/

		SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
		 /*增加信号机故障关闭报警，add by yt 2022年4月22日*/
		SetErrorData(EFUNC_CLD_OPEN_LEAD_ROUTE, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, SIGNAL_CLOSE, ESEND_LEVEL_ATS);

		/*保持开放期间信号异常关闭，设置对应始端信号机扣车旁路按钮无效*/
		SetDetCutBtnState(startSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
	}
}


/*
* 功能描述： 办理进路处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 SetRouteProc(const UINT16 routeId)
{
	UINT8 routeType = 0U;      /*进路类型*/
	UINT8 routeLevel = 0U;     /*进路监督级别*/
	UINT8 returnValue = CI_ERROR;    /*返回值定义*/
	UINT8 chLocalCiType = 0U;  /*本地联锁类型*/
	UINT8 chStopCheckState = 0U;/*停止检查标志*/
	UINT8 chRouteState = 0U;/*进路状态*/

	routeType = GetRouteType(routeId);      /*获取进路类型*/
	routeLevel = GetRouteLevel(routeId);    /*获取进路监督级别*/
	chLocalCiType = GetLocalCiType();     /*获取本地联锁类型*/
	chRouteState = GetRouteState(routeId);

	/*by cgh 20230720 合并车辆段与正线进路办理处理*/
	if (ROUTE_TYPE_LIECHE == routeType)
	{
		/*列车进路*/
		if ((CI_TYPE_ZX == chLocalCiType) || (CI_TYPE_SCX == chLocalCiType))
		{
			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{
				/*办理反向列车进路逻辑处理*/
				returnValue = SetRevrLTrainRouteLogicProcess(routeId);
			}
			else
			{
				if (ROUTE_LEVEL_CBTC == routeLevel)
				{ /*CBTC*/

					/*办理CBTC列车进路逻辑处理*/
					returnValue = SetCbtcLTrainRouteLogicProcess(routeId);
				}
				else
				{
					/*办理点式列车进路逻辑处理*/
					returnValue = SetBlocLTrainRouteLogicProcess(routeId);
				}
			}
		}
		else if (CI_TYPE_CLD == chLocalCiType)
		{
			returnValue = SetLTrainRouteP(routeId);
		}
		else
		{
			; /*无效联锁类型不处理*/
		}
	}
	else if (ROUTE_TYPE_RETURN == routeType)
	{
		/*折返进路*/
		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{
			/*办理反向折返进路逻辑处理*/
			returnValue = SetReverseRtnRouteLogicProcess(routeId);
		}
		else
		{
			if (ROUTE_LEVEL_CBTC == routeLevel)
			{ /*CBTC*/

				/*办理CBTC折返进路逻辑处理*/
				returnValue = SetCbtcReturnRouteLogicProcess(routeId);
			}
			else
			{
				/*办理点式折返进路逻辑处理*/
				returnValue = SetBlocReturnRouteLogicProcess(routeId);
			}
		}

	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{
		if (ROUTE_STATE_IDLE == chRouteState)
		{
			/*调车进路---进路空闲第一次办理的时候设置进路停止检查标志*/
			chStopCheckState = GetStopCheckFlag();
			SetRouteStopFlagManage(routeId, chStopCheckState);
		}

		returnValue = SetDTrainRouteP(routeId);
		if (CI_ERROR == returnValue)
		{
			SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO);/*清除进路停止检查标志*/
		}

	}
	else
	{
		; /*未知不处理*/
	}
	return returnValue;
}




/*
* 功能描述： 进路初选-取消自动信号进路处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
			 CI_SUCCESS:取消成功
			 CI_ERROR:取消失败
			 RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT:等待取消
*/
UINT8 RouteFirstXuanAutoSigProc(const UINT16 routeId)
{
	UINT8 i = 0u;
	UINT8 waitFlag = 0u;/*等待取消标志*/
	UINT8 succFlag = 1u;/*成功取消标志*/
	UINT8 failFlag = 0u;/*取消失败标志*/
	UINT8 retVal = CI_ERROR;/*返回值变量*/
	UINT8 funcRetVal = CI_SUCCESS;/*返回值变量*/
	UINT8 autoSigRouteIncludeSum = 0u;
	UINT16* autoSigRouteIncludeIdBuf = NULL;
	UINT8 localCiId = 0u;
	UINT8 routeBelongCi = 0u;
	UINT8 commState = 0u;
	UINT8 routeCancleState = 0u;
	UINT8 routeReverseProperty = 0u;

	localCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	routeReverseProperty = GetRouteReverseProperty(routeId);
	if (ROUTE_REVERSE_PROPERTY_NO == routeReverseProperty)
	{/*不具备反向属性*/
		succFlag = 1u;
	}
	else
	{
		autoSigRouteIncludeSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含的自动信号进路条数*/
		autoSigRouteIncludeIdBuf = GetReverseRouteIncludeRouteBuf(routeId);/*获取反向进路包含的自动信号进路Id数组*/
		for (i = 0u; i < autoSigRouteIncludeSum; i++)
		{
			/*获取自动信号所属联锁*/
			routeBelongCi = GetRouteBelongCiId(autoSigRouteIncludeIdBuf[i]);

			if (localCiId == routeBelongCi)
			{
				/*设置自动信号属性失效*/
				(void)SetRouteAutoSigLoseEfficacyFlag(autoSigRouteIncludeIdBuf[i], ROUTE_AUTOSIG_LOSE_REVSET_YES);
				funcRetVal = AutoSigRouteQuXiaoProc(autoSigRouteIncludeIdBuf[i]);/*取消自动信号进路*/
			}
			else
			{
				/*获取通信状态*/
				commState = GetLocalCiAndOtherCiTransSta(routeBelongCi);
				/*通信状态良好*/
				if (TRANSMIT_STATE_GOOD == commState)
				{
					/*自动信号没有取消命令，添加取消命令*/
					routeCancleState = GetAutoSigCancleState(autoSigRouteIncludeIdBuf[i]);
					/*命令无效*/
					if (AUTO_ROUTE_CANCLE_NO == routeCancleState)
					{
						/*添加相邻联锁处理命令*/
						AddCiSendToCiCmdInfo(CI_CMD_AUTO_SIG_ROUTE_CANCLE, autoSigRouteIncludeIdBuf[i], 0, routeBelongCi);
						funcRetVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT;
					}
					/*取消等待*/
					else if (AUTO_ROUTE_CANCLE_WAIT == routeCancleState)
					{
						funcRetVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT;
					}
					/*取消成功*/
					else if (AUTO_ROUTE_CANCLE_SUCCESS == routeCancleState)
					{
						funcRetVal = CI_SUCCESS;
					}
					else
					{
						/*设置失败*/
						funcRetVal = CI_ERROR;
					}
				}
				else
				{
					/*设置失败*/
					funcRetVal = CI_ERROR;
				}
			}
			if (CI_SUCCESS == funcRetVal)
			{/*本自动信号进路取消成功*/
				succFlag = 1u;
			}
			else if (CI_ERROR == funcRetVal)
			{/*本自动信号进路取消失败*/
				failFlag = 1u;
			}
			else if (RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT == funcRetVal)
			{/*等待取消本自动信号进路*/
				waitFlag = 1u;
			}
			else
			{
				/*不做处理*/
			}
		}
	}

	if (1u == failFlag)
	{/*有一条自动信号进路取消失败，则返回失败*/
		retVal = CI_ERROR;
	}
	else if (1u == waitFlag)
	{/*有一条自动信号进路等待取消，则返回等待*/
		retVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT;
	}
	else if ((0u == failFlag) && (0u == waitFlag) && (1u == succFlag))
	{/*自动信号全部取消成功*/
		retVal = CI_SUCCESS;
	}
	else
	{
		/*无操作*/
	}

	return retVal;
}



/*
* 功能描述： 锁闭进路处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 LockRouteProc(const UINT16 routeId)
{
	UINT8 routeType = 0U;      /*进路类型*/
	UINT8 routeLevel = 0U;     /*进路监督级别*/
	UINT8 returnValue = CI_ERROR;    /*返回值定义*/
	UINT8 chLocalCIType = 0U;/*联锁类型*/

	routeType = GetRouteType(routeId);      /*获取进路类型*/
	routeLevel = GetRouteLevel(routeId);    /*获取进路监督级别*/
	chLocalCIType = GetLocalCiType();

	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/
		if ((CI_TYPE_ZX == chLocalCIType) || (CI_TYPE_SCX == chLocalCIType))
		{
			if (ROUTE_LEVEL_CBTC == routeLevel)
			{ /*CBTC*/

				/*锁闭CBTC列车进路逻辑处理*/
				returnValue = LockCbtcLTrainRouteLogicProcess(routeId);
			}
			else
			{
				/*锁闭点式列车进路逻辑处理*/
				returnValue = LockBlocLTrainRouteLogicProcess(routeId);
			}
		}
		else if (CI_TYPE_CLD == chLocalCIType)
		{
			returnValue = LockLTrainRouteP(routeId);
		}
		else
		{
			; /*无效联锁类型不处理*/
		}
	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{ /*调车进路*/
		returnValue = LockDTrainRouteP(routeId);
	}
	else if (ROUTE_TYPE_RETURN == routeType)
	{
		if (ROUTE_LEVEL_CBTC == routeLevel)
		{ /*CBTC*/

			/*锁闭CBTC折返进路逻辑处理*/
			returnValue = LockCbtcReturnRouteLogicProcess(routeId);
		}
		else
		{
			/*锁闭点式折返进路逻辑处理*/
			returnValue = LockBlocReturnRouteLogicProcess(routeId);
		}
	}
	else
	{
		; /*未知不处理*/
	}
	return returnValue;
}

/*
* 功能描述：根据ATS命令锁闭进路Overlap处理
* 参数说明：const UINT16 routeId, 进路ID
*           const UINT16 expLkOverlapId, 期望锁闭保护区段ID
* 返 回 值：0 失败
*           1 成功
*           0x22 道岔位置错误
*           0x30 防护道岔等待征用
*           0x31 防护道岔等待检查
*/
UINT8 LockRouteOverlapAccdToAtsCmd(const UINT16 routeId, const UINT16 expLkOverlapId)
{/*线路类型为FAOHLHT且进路期望锁闭保护区段ID有效*/
	UINT8 localCiId = 0u;	/*本联锁集中区ID*/
	UINT8 retValue = CI_ERROR;	/*返回值定义*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 devPreState = 0u;				 /*设备前一状态*/
	UINT8 overlapCurOccuState = 0u;			 /*保护区段当前占用状态*/
	UINT8 routeState = 0u;			/*进路状态*/
	UINT32 cycNum = Get2oo2CurCycleNum();
	UINT16 wOverlapLockRouteId = 0U;/*保护区段锁闭所属进路*/
	UINT32 dwXuanpaiStartCycNum = 0U;  /*保护区段道岔选排起始周期*/
	UINT8 cTimeCheckFlag = CI_TIME_OUT;

	localCiId = GetSystemParaLocalCiId();	/*获取本机联锁ID*/

	if (ROUTE_OVERLAP_SET_YES == GetRouteOverlapLockFlag(routeId))
	{ /*进路保护区段已锁闭过，返回成功*/
		retValue = CI_SUCCESS;
	}
	else
	{/*进路保护区段未锁闭过，继续执行*/
		if (GetOverlapBelongCiId(expLkOverlapId) == localCiId)
		{
			/*属于本联锁保护区段*/
			devId = GetRouteLastPhySectionId(routeId);
			devState = GetPhySecCurOccupyState(devId);
			devPreState = GetPhySecPreOccupyState(devId);
			overlapCurOccuState = GetPhySecCurOccupyState(GetRouteLeavePhySecId(routeId));
			routeState = GetRouteState(routeId);
			if ((SECTION_OCCUPY_NO == devState) &&
				(SECTION_OCCUPY_YES == devPreState) &&
				(SECTION_OCCUPY_NO == overlapCurOccuState) &&
				(PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(devId)) &&
				(ROUTE_STATE_AUTO_UNLOCK == routeState) &&
				(GetSystemParaLocalCiId() != GetRouteBelongCiId(routeId))
				)
			{
				SetProtectSecLockDelayTimeFlag(devId, PROTECTSECLOCKDELAY_YES);
				SetPhySecLockDelayStartCycNum(devId, cycNum);  /*设置物理区段延时锁闭周期号*/
			}

			if (PROTECTSECLOCKDELAY_NO == GetProtectSecLockDelayTimeFlag(devId))
			{
				/*锁闭进路Overlap管理*/
				retValue = LockRouteOverlapLogicProcess(routeId, expLkOverlapId, ATS_LOCK_OVERLAP);
			}
			else if (((Get2oo2CurCycleNum() - GetPhySecLockDelayStartCycNum(devId)) > GetCiAndCiTransBadEnsureCnt())
				&& (PROTECTSECLOCKDELAY_YES == GetProtectSecLockDelayTimeFlag(devId)))
			{  /*标志设置超时则清除标志*/
				SetProtectSecLockDelayTimeFlag(devId, PROTECTSECLOCKDELAY_NO);
				SetPhySecLockDelayStartCycNum(devId, 0);  /*清物理区段延时锁闭周期号*/
				/*锁闭进路Overlap管理*/
				retValue = LockRouteOverlapLogicProcess(routeId, expLkOverlapId, ATS_LOCK_OVERLAP);
			}
			else
			{
				/*未超时则不做任何操作*/
				retValue = CI_ERROR;
			}

			if (CI_SUCCESS == retValue)
			{ /*锁闭成功*/

				/*为了解决保护区段不解锁，重复被两条进路锁闭时，第二条进路锁闭保护区段前，清除第一条进路锁闭过的保护区段ID；
				否则第二次锁闭第一条进路时，保护区段无法重新锁闭*/
				wOverlapLockRouteId = GetOverlapBelongRouteId(expLkOverlapId);
				if (0U < wOverlapLockRouteId)
				{
					SetRouteOverlapLockedId(wOverlapLockRouteId,0U);
				}
				else
				{
					; /*为0不清除*/
				}

				SetOverlapLockState(expLkOverlapId, PHYSICAL_SECTION_LOCK_PROTECT, routeId);  /*设置Overlap防护锁闭*/

				/*设置保护区段中所有包含的道岔征用结束*/
				SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_NO);
				SetOverlapXuanPaiStartCycNum(expLkOverlapId, 0);
				SetOverlapProSwtCheckStartFlag(expLkOverlapId, PROSWITCH_CHECK_START_INVALID);  /*锁闭成功，设置防护道岔检查开始标志为停止检查*/
				SetOverlapProSwtCheckResultFlag(expLkOverlapId, PROSWITCH_CHECK_RESULT_DEFAULT);  /*锁闭成功，设置防护道岔检查结果标志为默认值*/
				SetOverlaplockSucessStartCycNum(expLkOverlapId, cycNum);/*设置锁闭起始周期*/
			}
			else if (RETURN_WAIT_SWITCH_USING == retValue)
			{
				/*防护道岔未征用，设置道岔征用*/
				SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_YES);
				SetOverlapXuanPaiStartCycNum(expLkOverlapId, cycNum);
				dwXuanpaiStartCycNum = GetOverlapXuanPaiStartCycNum(expLkOverlapId);
				cTimeCheckFlag = SystemOverTimeCheck(dwXuanpaiStartCycNum, OVERLAP_USING_OVERTIME_CYC_NUM);  /*检查征用是否超时*/
				if (CI_TIME_OUT == cTimeCheckFlag)
				{
					/*征用超时，清除征用*/
					SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_NO);
					SetOverlapXuanPaiStartCycNum(expLkOverlapId, 0U);
					retValue = CI_ERROR;
				}
				else
				{
					retValue = RETURN_WAIT_SWITCH_USING;
				}
			}
			else if (RETURN_WAIT_SWITCH_CHECK == retValue)
			{
				/*道岔征用检查通过，设置防护道岔检查开始标志为开始检查*/
				SetOverlapProSwtCheckStartFlag(expLkOverlapId, PROSWITCH_CHECK_START_VALID);
				retValue = RETURN_WAIT_SWITCH_CHECK;
			}
			else if (RETURN_LOCK_ERR_SWITPOS == retValue)
			{
				SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_YES);
				SetOverlapXuanPaiStartCycNum(expLkOverlapId, cycNum);
				retValue = ChekSwitDrivOvtm(expLkOverlapId);  /*需要驱动道岔时，检查道岔是否驱动超时*/
				if (CI_SUCCESS == retValue)
				{
					/*overlap锁闭驱动道岔*/
					if (CI_ERROR == OverlapLockDriveSwitch(expLkOverlapId))
					{
						/*保护区段不满足锁闭条件 取消道岔征用*/
						SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_NO);
						SetOverlapXuanPaiStartCycNum(expLkOverlapId, 0U);
						SetOverlapProSwtCheckStartFlag(expLkOverlapId, PROSWITCH_CHECK_START_INVALID);  /*驱动失败，设置防护道岔检查开始标志为停止检查*/
						SetOverlapProSwtCheckResultFlag(expLkOverlapId, PROSWITCH_CHECK_RESULT_DEFAULT);  /*驱动失败，设置防护道岔检查结果标志为默认值*/
						retValue = CI_ERROR;
					}
					else
					{
						retValue = RETURN_LOCK_ERR_SWITPOS;
					}
				}
				else
				{
					/*保护区段驱动道岔超时 取消征用*/
					SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_NO);
					SetOverlapXuanPaiStartCycNum(expLkOverlapId, 0u);
					SetOverlapProSwtCheckStartFlag(expLkOverlapId, PROSWITCH_CHECK_START_INVALID);  /*驱动超时，设置防护道岔检查开始标志为停止检查*/
					SetOverlapProSwtCheckResultFlag(expLkOverlapId, PROSWITCH_CHECK_RESULT_DEFAULT);  /*驱动超时，设置防护道岔检查结果标志为默认值*/
					SetErrorData(EFUNC_SWITCH_DRIVE_OUTTIME, CI_DEVICE_TYPE_SWITCH, expLkOverlapId, CI_DEVICE_TYPE_OVERLAP, SWITCH_POSITION_INVALID, ESEND_LEVEL_ZERO);
					retValue = CI_ERROR;
					SetRouteAtsExpLkOverlapId(routeId, 0u);	/*清除ATS或现地期望锁闭保护区段ID*/
					SetOverlapFromSetRouteCmdFlag(expLkOverlapId, OVERLAP_ROUTE_FLAG_NO);/*清除保护区段建立命令由进路命令连带下发标志*/
				}
			}
			else
			{
				/*锁闭检查不满足，清道岔征用（避免因保护区段道岔征用，且保护区段又无法锁闭，导致进路无法办理）*/
				SetOverlapRelSwitchUsing(expLkOverlapId, SWITCH_USING_NO);
				SetOverlapXuanPaiStartCycNum(expLkOverlapId, 0U);
				SetOverlapProSwtCheckStartFlag(expLkOverlapId, PROSWITCH_CHECK_START_INVALID);  /*锁闭检查不满足，设置防护道岔检查开始标志为停止检查*/
				SetOverlapProSwtCheckResultFlag(expLkOverlapId, PROSWITCH_CHECK_RESULT_DEFAULT);  /*锁闭检查不满足，设置防护道岔检查结果标志为默认值*/
				retValue = CI_ERROR;
			}
		}
	}

	return retValue;
}

/*
* 功能描述：进路锁闭Overlap处理
* 参数说明：const UINT16 routeId, 进路ID
* 返 回 值：0 失败
*           1 成功
*           0x22 道岔位置错误
*           0x30 防护道岔等待征用
*           0x31 防护道岔等待检查
*/
UINT8 LockRouteOverlapProc(const UINT16 routeId)
{
	UINT8 const localCiId = GetSystemParaLocalCiId(); /*获取本机联锁ID*/

	UINT8 returnValue = CI_ERROR;    /*返回值定义*/
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT8 ii = 0u;
	UINT32 thisOverlapCycNum = 0u;
	UINT8 cRouteOverlapLockFlag = ROUTE_OVERLAP_SET_NO;  /*进路保护区段锁闭标志*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 devPreState = 0u;				 /*设备前一状态*/
	UINT8 overlapState = 0u;			 /*保护区段状态*/
	UINT8 routeState = 0u;
	UINT16 wOverlapLockRouteId = 0U;/*保护区段锁闭所属进路*/
	UINT32 dwCurCycNum = 0u;
	UINT32 dwXuanPaiStartCycNum = 0U;  /*保护区段道岔选排起始周期*/
	UINT8 cTimeCheckFlag = CI_TIME_OUT;
	UINT8 cKeepWorkFlag = CI_ERROR;

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/
	dwCurCycNum = Get2oo2CurCycleNum();
	cRouteOverlapLockFlag = GetRouteOverlapLockFlag(routeId);
	if ((NULL == overlapIdBuf) || (ROUTE_OVERLAP_SET_YES == cRouteOverlapLockFlag))
	{
		returnValue = CI_SUCCESS;  /*没有保护区段或进路保护区段已锁闭过，返回成功*/
	}
	else
	{
		/*处理能直接锁闭的保护区段*/
		cKeepWorkFlag = CI_SUCCESS;
		for (ii = 0u; ii < overlapSum; ii++)
		{
			if (GetOverlapBelongCiId(overlapIdBuf[ii]) == localCiId)
			{
				/*属于本联锁保护区段*/

				/*
				*解决问题：
				*  某联锁办理了一条进路，此进路的保护区段是本联锁的。在列车占压最后一个物理区段后，本联锁的保护区段自动延时解锁完毕。
				*	如果出现飞车现象，进路最后一个物理区段突然变为空闲（且显示为绿光带），此时还未收到对方联锁发来的进路最后一个物理区段
				*	锁闭异常信息，本联锁维护的状态依然为正常锁闭。这时候本联锁又会自动锁闭保护区段，这不合适，因此为解决该问题追加判断
				*	锁闭保护区段的限制条件。
				*	问题根源: 保护区段解锁，最后一个区段失去列车分路，而进路状态管理在相邻联锁处理。因此判断出异常，晚于本联锁。
				*			  针对该情况，本联锁的进路状态自动解锁状态，属于防护区段锁闭处理的条件依然满足，因此将锁闭。
				*  解决该问题打补丁思想: 由于异常解锁故障晚于本联锁防护区段锁闭处理，因此在锁闭处理中，先进行异常状态预判处理。
				*						预判出来后，设置标志位，将不再锁闭防护区段。其他场景下，按照正常逻辑处理。
			 *
			 *  预判断条件为：
			 *	（进路最后一个物理区段当前未占用） &&（进路最后一个物理区段前一状态为占用） &&（保护区段当前未占用） &&（进路最后一个物理区段当前锁闭状态为正常锁闭）& (进路状态自动解锁状态)
			 *	时设置一个标志，锁闭保护区段要检查此标志
			 *	恢复标志时机为：
			 *	当本联锁收到对方联锁发来的进路最后一个物理区段锁闭异常信息后，恢复标志
			 * 防护以下出现的情景:
			 例如:CI1 和 CI5
			 CI1办理进路Z3-CD1进路，列车占压最后一个物理区段ZHG后，保护区段JK1G解锁。此时出现飞车现象，物理区段ZHG突然空闲，保护区段JK1G又重新锁闭
			 */
				devId = GetRouteLastPhySectionId(routeId);
				devState = GetPhySecCurOccupyState(devId);
				devPreState = GetPhySecPreOccupyState(devId);
				overlapState = GetPhySecCurOccupyState(GetRouteLeavePhySecId(routeId));
				routeState = GetRouteState(routeId);
				if ((SECTION_OCCUPY_NO == devState) &&
					(SECTION_OCCUPY_YES == devPreState) &&
					(SECTION_OCCUPY_NO == overlapState) &&
					(PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(devId)) &&
					(ROUTE_STATE_AUTO_UNLOCK == routeState) &&
					(GetSystemParaLocalCiId() != GetRouteBelongCiId(routeId))
					)
				{
					SetProtectSecLockDelayTimeFlag(devId, PROTECTSECLOCKDELAY_YES);
					SetPhySecLockDelayStartCycNum(devId, Get2oo2CurCycleNum());  /*设置物理区段延时锁闭周期号*/
				}
				else
				{
					;
				}

				if (PROTECTSECLOCKDELAY_NO == GetProtectSecLockDelayTimeFlag(devId))
				{
					/*锁闭进路Overlap管理*/
					returnValue = LockRouteOverlapLogicProcess(routeId, overlapIdBuf[ii], CI_LOCK_OVERLAP);
				}
				else if (((Get2oo2CurCycleNum() - GetPhySecLockDelayStartCycNum(devId)) > GetCiAndCiTransBadEnsureCnt())
					&& (PROTECTSECLOCKDELAY_YES == GetProtectSecLockDelayTimeFlag(devId)))
				{  /*标志设置超时则清除标志*/
					SetProtectSecLockDelayTimeFlag(devId, PROTECTSECLOCKDELAY_NO);
					SetPhySecLockDelayStartCycNum(devId, 0);  /*清物理区段延时锁闭周期号*/
					/*锁闭进路Overlap管理*/
					returnValue = LockRouteOverlapLogicProcess(routeId, overlapIdBuf[ii], CI_LOCK_OVERLAP);
				}
				else
				{
					/*未超时则不做任何操作*/
					returnValue = CI_ERROR;
				}

				if (CI_SUCCESS == returnValue)
				{ /*锁闭成功*/

					/*为了解决保护区段不解锁，重复被两条进路锁闭时，第二条进路锁闭保护区段前，清除第一条进路锁闭过的保护区段ID；
					否则第二次锁闭第一条进路时，保护区段无法重新锁闭*/
					wOverlapLockRouteId = GetOverlapBelongRouteId(overlapIdBuf[ii]);
					if (0U < wOverlapLockRouteId)
					{
						SetRouteOverlapLockedId(wOverlapLockRouteId, 0U);
					}
					else
					{
						; /*为0不清除*/
					}

					SetOverlapLockState(overlapIdBuf[ii], PHYSICAL_SECTION_LOCK_PROTECT, routeId);  /*设置Overlap防护锁闭*/

					/*设置保护区段中所有包含的道岔征用结束*/
					SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_NO);  /*锁闭成功，清除征用*/
					SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0u);  /*锁闭成功，清除选排起始周期*/
					SetOverlapProSwtCheckStartFlag(overlapIdBuf[ii], PROSWITCH_CHECK_START_INVALID);  /*锁闭成功，设置防护道岔检查开始标志为停止检查*/
					SetOverlapProSwtCheckResultFlag(overlapIdBuf[ii], PROSWITCH_CHECK_RESULT_DEFAULT);  /*锁闭成功，防护道岔检查结果标志设置为默认值*/
					SetOverlaplockSucessStartCycNum(overlapIdBuf[ii], dwCurCycNum);/*设置锁闭起始周期*/
					cKeepWorkFlag = CI_ERROR;  /*停止遍历*/
					returnValue = CI_SUCCESS;
				}
				else if (RETURN_WAIT_SWITCH_USING == returnValue)
				{
					/*防护道岔未征用，设置道岔征用*/
					SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_YES);
					SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], dwCurCycNum);
					dwXuanPaiStartCycNum = GetOverlapXuanPaiStartCycNum(overlapIdBuf[ii]);
					cTimeCheckFlag = SystemOverTimeCheck(dwXuanPaiStartCycNum, OVERLAP_USING_OVERTIME_CYC_NUM);  /*检查征用是否超时*/
					if (CI_TIME_OUT == cTimeCheckFlag)
					{
						/*征用超时，清除征用*/
						SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_NO);
						SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0U);
						returnValue = CI_ERROR;
					}
					else
					{
						returnValue = RETURN_WAIT_SWITCH_USING;
					}
					cKeepWorkFlag = CI_ERROR;  /*停止遍历*/
				}
				else if (RETURN_WAIT_SWITCH_CHECK == returnValue)
				{
					/*道岔征用检查通过，设置防护道岔检查开始标志为开始检查*/
					SetOverlapProSwtCheckStartFlag(overlapIdBuf[ii], PROSWITCH_CHECK_START_VALID);  /*设置保护区段防护道岔检查开始标志为检查开始，保护区段处于锁闭中*/
					cKeepWorkFlag = CI_ERROR;  /*停止遍历*/
					returnValue = RETURN_WAIT_SWITCH_CHECK;
				}
				else if (RETURN_LOCK_ERR_SWITPOS == returnValue)
				{
					SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_YES);
					SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], dwCurCycNum);
					returnValue = ChekSwitDrivOvtm(overlapIdBuf[ii]);  /*需要驱动道岔时，检查道岔是否驱动超时*/
					if (CI_SUCCESS == returnValue)
					{
						/*overlap锁闭驱动道岔*/
						if (CI_ERROR == OverlapLockDriveSwitch(overlapIdBuf[ii]))
						{
							/*保护区段不满足锁闭条件 取消道岔征用*/
							SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_NO);
							SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0U);
							SetOverlapProSwtCheckStartFlag(overlapIdBuf[ii], PROSWITCH_CHECK_START_INVALID);  /*驱动失败，设置防护道岔检查开始标志为停止检查*/
							SetOverlapProSwtCheckResultFlag(overlapIdBuf[ii], PROSWITCH_CHECK_RESULT_DEFAULT);  /*驱动失败，设置防护道岔检查结果标志为默认值*/
							returnValue = CI_ERROR;
						}
						else
						{
							returnValue = RETURN_LOCK_ERR_SWITPOS;
						}
					}
					else
					{
						/*保护区段驱动道岔超时 取消征用*/
						SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_NO);
						SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0U);
						SetOverlapProSwtCheckStartFlag(overlapIdBuf[ii], PROSWITCH_CHECK_START_INVALID);  /*驱动超时，设置防护道岔检查开始标志为停止检查*/
						SetOverlapProSwtCheckResultFlag(overlapIdBuf[ii], PROSWITCH_CHECK_RESULT_DEFAULT);  /*驱动超时，设置防护道岔检查结果标志为默认值*/
						SetErrorData(EFUNC_SWITCH_DRIVE_OUTTIME, CI_DEVICE_TYPE_SWITCH, overlapIdBuf[ii], CI_DEVICE_TYPE_OVERLAP, SWITCH_POSITION_INVALID, ESEND_LEVEL_ZERO);
						returnValue = CI_ERROR;
					}
					cKeepWorkFlag = CI_ERROR;  /*停止遍历*/
				}
				else
				{
					/*优先位置锁闭失败，尝试次要位置*/
					thisOverlapCycNum = GetOverlapXuanPaiStartCycNum(overlapIdBuf[ii]);
					if (thisOverlapCycNum != 0U)
					{
						SetOverlapRelSwitchUsing(overlapIdBuf[ii], SWITCH_USING_NO);
						SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0U);
						SetOverlapProSwtCheckStartFlag(overlapIdBuf[ii], PROSWITCH_CHECK_START_INVALID);  /*锁闭检查失败，设置防护道岔检查开始标志为停止检查*/
						SetOverlapProSwtCheckResultFlag(overlapIdBuf[ii], PROSWITCH_CHECK_RESULT_DEFAULT);  /*锁闭检查失败，设置防护道岔检查结果标志为默认值*/
						cKeepWorkFlag = CI_ERROR;  /*驱动道岔至优先位置过程中锁闭条件变为不满足时，不再尝试锁闭次要位置*/
						returnValue = CI_ERROR;
					}
				}
			}
			else
			{
				;
			}

			if (CI_ERROR == cKeepWorkFlag)
			{
				break;
			}
			else
			{
				/*继续遍历保护区段，进行锁闭检查*/
			}
		}
	}

	return returnValue;
}

/*
锁闭本联锁保护区段管理
UINT8 overlapIdSum 保护区段总数
UINT16 * pOverlapIdBuf 保护区段ID缓存指针
UINT8 PLockDirect 锁闭方向

CI_SUCCESS 成功
CI_ERROR 失败

*/
UINT8 LockLocalOvlpManageHlht(UINT8 overlapSum, UINT16* pOverlapIdBuf, UINT8 PLockDirect)
{
	UINT8 const localCiId = GetSystemParaLocalCiId(); /*获取本机联锁ID*/

	UINT8 returnValue = 0u;    /*返回值定义*/
	UINT8 ii = 0u;

	if ((0u == overlapSum) || (NULL == pOverlapIdBuf))
	{
		/*没有保护区段*/
		return CI_SUCCESS;
	}

	/*锁闭保护区段处理*/
		/*处理能直接锁闭的保护区段*/
	for (ii = 0u; ii < overlapSum; ii++)
	{
		if (GetOverlapBelongCiId(pOverlapIdBuf[ii]) == localCiId)
		{
			/*锁闭进路Overlap管理*/
			returnValue = LockLocalOvlpCheckHlht(pOverlapIdBuf[ii], PLockDirect);

			if (CI_SUCCESS == returnValue)
			{ /*锁闭成功*/

				SetOvlpLockStateForHlhtCi(pOverlapIdBuf[ii], PHYSICAL_SECTION_LOCK_PROTECT, PLockDirect);  /*设置Overlap防护锁闭*/

				return CI_SUCCESS;
			}
			else if (RETURN_LOCK_ERR_SWITPOS == returnValue)
			{
				/*overlap锁闭驱动道岔*/
				if (CI_ERROR == OverlapLockDriveSwitch(pOverlapIdBuf[ii]))
				{
					return CI_ERROR;
				}
				else
				{
					return RETURN_LOCK_ERR_SWITPOS;
				}
			}
			else
			{ 
				/*锁闭失败*/
			}
		}
	}
	return CI_ERROR;
}


/*
* 功能描述： 开放进路信号处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 OpenRouteSignalProc(const UINT16 routeId)
{
	UINT8 routeType = 0u;          /*进路类型*/
	UINT8 routeLevel = 0u;         /*进路监督级别*/
	UINT16 startSignalId = 0u;     /*进路始端信号机ID*/
	UINT8 returnValue = 0u;        /*返回值定义*/
	UINT8 errType = CI_ERROR;/*定义检查失败时的错误类型*/
	UINT8 recoverState = ROUTE_RECOVER_STA_STAY;/*当前恢复重开状态*/
	UINT8 routeState = 0u;/*进路状态*/
	UINT32 curCycle = 0u;/*当前周期*/
	UINT8 needOpenNotTrueRepeatFlag = ROUTE_NEEDOPEN_REOPEN_NO;/*需开放未满足，重开标志*/
	UINT32 needOpenRepeatStartCount = 0u;/*需开放未满足，重开起始周期*/
	UINT32 sysparaRepeatCount = 0u;/*系统参数重开维持周期*/
	UINT8 routeTimeState = CI_TIME_NO;
	UINT32 dwDelayOpenStartCyc = 0U;  /*声光报警延时开放起始周期*/
	UINT32 dwDelayOpenCycNum = 0U;  /*声光报警延时开放周期数*/
	UINT8 cRouteCanOpenFlag = CI_ERROR;  /*进路可开放标志*/
	UINT32 dwRouteSigOpenStartCyc = 0U;  /*进路信号开放起始周期*/
	UINT8 dctyReOpenFlag = ROUTE_DCTY_REOPEN_NO;/*调车同意重开标志*/
	UINT32 dctyStartCount = 0u;/*调车同意起始周期*/

	routeType = GetRouteType(routeId);                /*获取进路类型*/
	routeLevel = GetRouteLevel(routeId);              /*获取进路监督级别*/
	startSignalId = GetRouteStartSignalId(routeId);   /*获取进路始端信号机ID*/
	routeState = GetRouteState(routeId);
	curCycle = Get2oo2CurCycleNum();


	if (CI_SUCCESS == AutoSignalOrRouteValid(routeId))
	{
		/*自动信号或自动进路自动重置开放时间*/
		SetRouteOpenSigStartCycNum(routeId, Get2oo2CurCycleNum());
#if 0
		SetOverlapLockStartCycNum(routeId,Get2oo2CurCycleNum());  /*自动信号目前删除保护区段及触发区段*/
#endif
	}


	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/

		if (ROUTE_LEVEL_CBTC == routeLevel)
		{ /*CBTC*/

			returnValue = OpenCbtcLTrainRouteLogicProcess(routeId);   /*开放CBTC列车进路*/
			errType = OpenCbtcLTrainRouteErrProcess(routeId, OPEN_CHECK_STEP_OPEN);/*检查失败原因*/
		}
		else
		{ /*点式*/

			returnValue = OpenBlocLTrainRouteLogicProcess(routeId);   /*开放点式列车进路*/
			errType = OpenBlocLTrainRouteErrProcess(routeId);/*检查失败原因*/
		}

	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{/*调车进路*/
		returnValue = OpenDTrainRouteP(routeId); /*开放调车进路*/
		errType = OpenDTrainRouteErrP(routeId, OPEN_CHECK_STEP_OPEN); /*检查失败原因*/
	}
	else if (ROUTE_TYPE_RETURN == routeType)
	{ /*折返进路*/

		if (ROUTE_LEVEL_CBTC == routeLevel)
		{ /*CBTC*/

			returnValue = OpenCbtcReturnRouteLogicProcess(routeId);   /*开放CBTC折返进路*/
			errType = OpenCbtcReturnRouteErrProcess(routeId, OPEN_CHECK_STEP_OPEN);/*检查失败原因*/
		}
		else
		{ /*点式*/

			returnValue = OpenBlocReturnRouteLogicProcess(routeId);   /*开放点式折返进路*/
			errType = OpenBlocReturnRouteErrProcess(routeId);/*检查失败原因*/
		}
	}
	else
	{/*不处理*/
	}

	dwDelayOpenStartCyc = GetRouteDelayOpenStartCyc(routeId);  /*获取进路声光报警延时开放起始周期号*/
	dwDelayOpenCycNum = GetSGBJRouteDelayOpenCount();
	routeTimeState = SystemOverTimeCheck(dwDelayOpenStartCyc, dwDelayOpenCycNum);

	if ((CI_TIME_OUT == routeTimeState) || (CI_TIME_NO == routeTimeState))
	{
		dwRouteSigOpenStartCyc = GetRouteOpenSigStatrtCycNum(routeId);
		if (0U == dwRouteSigOpenStartCyc)
		{
			SetRouteOpenSigStartCycNum(routeId, curCycle);  /*因声光报警延时导致进路信号开放时间未设置，此处设置进路信号开放时间为当前周期*/
		}
		else
		{
			/*进路信号开放起始周期已设置，不处理*/
		}

		SetRouteDelayOpenStartCyc(routeId, 0U);  /*清除声光报警延时开放起始周期号*/
		cRouteCanOpenFlag = CI_SUCCESS;
	}
	else
	{
		/*延时中，不处理*/
	}

	dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);/*获取调车同意重开标志*/

	/*根据开放信号返回值处理*/
	if (CI_SUCCESS == returnValue)
	{ /*检查成功*/
		if (CI_SUCCESS == cRouteCanOpenFlag)
		{
			DriveSignalOpen(startSignalId, routeId);  /*驱动信号开放*/

			/*满足开放条件后也清除进路恢复状态，用于下一次进路状态流转*/
			SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);
		}
		else
		{
			/*不处理，等待延时结束开放信号*/
		}

		returnValue = CI_SUCCESS;
	}
	else if (RETURN_OPEN_ERR_SIGOPEN == returnValue)
	{ /*需关闭信号未关闭*/
		(void)DriveSignalClose(startSignalId);    /*驱动信号关闭*/

		/*清开放未开放重开标志，清未开放不满足重开开始时间*/
		SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
		SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);


		if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
		{
			SetErrorData(EFUNC_CLD_OpenCommRouteSigProc,CI_DEVICE_TYPE_ROUTE, routeId,ETYPE_DCTY_REOPEN_TIMING_BREAK, dctyReOpenFlag, ESEND_LEVEL_ATS);
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
			SetRouteDCTYNotSatisfyStartCnt(routeId, 0U);
		}
		else
		{
			;
		}

		returnValue = CI_SUCCESS;
	}
	else if (RETURN_OPEN_ERR_NEEDOPEN == returnValue)
	{/*开放需开放不满足*/
		(void) DriveSignalClose(startSignalId);

		if (ROUTE_STATE_FIRST_LOCK == routeState/*初锁*/)
		{
			/*设置重开标志，设置未开放不满足重开开始时间*/
			/*判断条件：列车进路、需开放信号机为虚拟信号机，且关闭*/
			if (ROUTE_TYPE_LIECHE == routeType)
			{
				SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_YES);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, curCycle);
			}
			else
			{
				SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
			}
		}
		else if (ROUTE_STATE_FIRST_LOCKERR == routeState/*初锁异常*/)
		{
			/*获取重开标志*/
			/*检查超时*/
			needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
			needOpenRepeatStartCount = GetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId);
			sysparaRepeatCount = GetSystemParaRouteOpenSigCyc();/*开放需开放等待时间采用进路信号开放周期时间*/
			if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag) && (0U < needOpenRepeatStartCount))
			{
				/*检查超时，超时，清标志*/
				/* 开放信号时间状态*/
				routeTimeState = SystemOverTimeCheck(needOpenRepeatStartCount, sysparaRepeatCount);
				if (CI_TIME_OUT == routeTimeState)/*超时*/
				{
					SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
					SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
				}
				else if (CI_TIME_NO == routeTimeState)/*未计时*/
				{
					SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
					SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
				}
				else if (CI_TIME_IN == routeTimeState)/*计时中*/
				{
					/*继续重开*/
				}
				else
				{
					/*非法*/
					SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
					SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
				}
				/*因为处于开放需开放不满足时自动重开中，所以，清除信号自动重开标志，避免重复*/
				SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*清除进路信号重开标志*/
				SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
				SetRouteOpenSigStartCycNum(routeId, 0U); /*重置信号开放时间*/
			}
			else
			{
				/*需开放不满足的重开标志为不重开，——判断信号重开失败，此后不在进入信号重开条件判断*/

				SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);  /*清除进路信号重开标志*/

				SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);

				SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

				/*清开放未开放重开标志，清未开放不满足重开开始时间*/
				SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
			}
		}
		else
		{
			/*需开放不满足的重开标志为不重开，——判断信号重开失败，此后不在进入信号重开条件判断*/

			SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);  /*清除进路信号重开标志*/

			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);

			SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

			/*清开放未开放重开标志，清未开放不满足重开开始时间*/
			SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
			SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);
		}	

		if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
		{
			SetErrorData(EFUNC_CLD_OpenCommRouteSigProc, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_DCTY_REOPEN_TIMING_BREAK, dctyReOpenFlag, ESEND_LEVEL_ATS);
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
			SetRouteDCTYNotSatisfyStartCnt(routeId, 0U);
		}
		else
		{
			;
		}

		returnValue = CI_ERROR;
	}
	else if ((ROUTE_TYPE_DIAOCHE == routeType) && (RETURN_DCTY_NOT_SATISIFY == returnValue)/*调车同意不满足*/)
		{
		(void)DriveSignalClose(startSignalId);/*先驱信号关闭*/

		if (ROUTE_STATE_FIRST_LOCK == routeState/*初锁*/)
		{
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN);
			SetRouteDCTYNotSatisfyStartCnt(routeId, curCycle);
		}
		else if (ROUTE_STATE_FIRST_LOCKERR == routeState/*初锁异常*/)
		{
			sysparaRepeatCount = 0u;
			/*检查超时*/
			dctyStartCount = GetRouteDCTYNotSatisfyStartCnt(routeId);/*获取调车同意不满足起始周期*/
			sysparaRepeatCount = GetSysParaDCTYWaitSigOpenCnt();/*获取系统参数调车同意等待信号重开时间时间*/

			if ((ROUTE_DCTY_REOPEN == dctyReOpenFlag) && (dctyStartCount > 0u))
			{
				/*检查超时，超时，清标志*/
				/* 开放信号时间状态*/
				routeTimeState = SystemOverTimeCheck(dctyStartCount, sysparaRepeatCount);
				if (CI_TIME_OUT == routeTimeState)/*超时*/
				{
					SetErrorData(EFUNC_CLD_OpenCommRouteSigProc,
						CI_DEVICE_TYPE_ROUTE, routeId,
						ETYPE_DCTY_REOPEN_TIMEOUT, dctyReOpenFlag, ESEND_LEVEL_ATS);

					SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
					SetRouteDCTYNotSatisfyStartCnt(routeId, 0u);
				}
				else if (CI_TIME_NO == routeTimeState)/*未计时*/
				{
					SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
					SetRouteDCTYNotSatisfyStartCnt(routeId, 0u);
				}
				else if (CI_TIME_IN == routeTimeState)/*计时中*/
				{
					/*继续重开*/
				}
				else
				{
					/*非法*/
					SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
					SetRouteDCTYNotSatisfyStartCnt(routeId, 0u);
				}
			}
		}
		else
		{
			/*不做处理*/
		}
		/*因为处于开放需开放不满足时自动重开中，所以，清除信号自动重开标志，避免重复*/
		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*清除进路信号重开标志*/
		SetRouteOpenSigStartCycNum(routeId, 0u); /*重置信号开放时间*/

		returnValue = CI_ERROR;
		}
	else if (RELAY_STATE_WAITE == returnValue)
	{
		/*清开放未开放重开标志，清未开放不满足重开开始时间*/
		SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
		SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0);
		returnValue = CI_SUCCESS;   /*等待驱落*/
	}
	else
	{ /*开放失败*/

		(void)DriveSignalClose(startSignalId);    /*驱动信号关闭*/

		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);  /*清除进路信号重开标志*/

		SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);

		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

		/*清开放未开放重开标志，清未开放不满足重开开始时间*/
		SetRouteNeedOpenReopenFlag(routeId, ROUTE_NEEDOPEN_REOPEN_NO);
		SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId, 0U);

		if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
		{
			SetErrorData(EFUNC_CLD_OpenCommRouteSigProc, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_DCTY_REOPEN_TIMING_BREAK, dctyReOpenFlag, ESEND_LEVEL_ATS);
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId, ROUTE_DCTY_REOPEN_NO);
			SetRouteDCTYNotSatisfyStartCnt(routeId, 0U);
		}
		else
		{
			;
		}

		if (CI_ROUTE_RECOVER_ERR == errType)
		{
			recoverState = GetRouteRecoverOpenFlag(routeId);

			if ((ROUTE_RECOVER_STA_INIT == recoverState) || (ROUTE_RECOVER_STA_WAIT == recoverState))
			{
				/*进路之前处于可恢复状态，继续保持可恢复状态（等待恢复）*/
				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_WAIT);
			}
			else
			{
				/*如果进路之前已经处于不可恢复状态，继续保持不可恢复状态，防止重开操作使进路具备了恢复重开特性*/
				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);
			}
		}
		else
		{
			SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);/*一旦有其它条件不满足，进路变不具备自动重开特性*/
		}

		returnValue = CI_ERROR;
	}

	return returnValue;
}


/*
* 功能描述： 保持开放进路信号处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 KeepOpenRouteSignalProc(const UINT16 routeId)
{
	UINT8 routeType = 0u;          /*进路类型*/
	UINT8 routeLevel = 0u;         /*进路监督级别*/
	UINT16 startSignalId = 0u;     /*进路始端信号机ID*/
	UINT8 returnValue = 0u;        /*返回值定义*/
	UINT8 errType = CI_ERROR;/*定义检查失败时的错误类型*/
	UINT8 ciType = 0u;
	UINT16 outPhySecId = 0u; /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u; /*信号机内方第一区段ID*/
	UINT8 inPhySecCurMergeState = 0U;
	UINT8 inPhySecPreMergeState = 0U;
	UINT8 outPhySecCurMergeState = 0U;

	routeType = GetRouteType(routeId);                /*获取进路类型*/
	routeLevel = GetRouteLevel(routeId);              /*获取进路监督级别*/
	startSignalId = GetRouteStartSignalId(routeId);   /*获取进路始端信号机ID*/
	inPhySecId = GetSignalInFirstPhySecId(startSignalId, routeId);    /*信号机内方第一物理区段ID*/
	outPhySecId = GetSignalOutFirstPhySecId(startSignalId);  /*信号机外方第一物理区段ID*/

#if 0
	if (RouteSecFlockVainCheck(routeId) == CI_ERROR ||
		RouteOverlapSecFlockVainCheck == CI_ERROR)
	{
		/*有区段封锁*/
		DriveSignalClose(startSignalId);  /*驱动信号关闭*/

		return CI_ERROR;
	}
#endif

	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/

		if (ROUTE_LEVEL_CBTC == routeLevel)
		{ /*CBTC*/

			returnValue = KeepCbtcLTrainRouteLogicProcess(routeId);   /*保持CBTC列车进路*/
			errType = KeepCbtcLTrainRouteErrProcess(routeId);/*检查失败原因*/
		}
		else
		{ /*点式*/

			returnValue = KeepBlocLTrainRouteLogicProcess(routeId);   /*保持点式列车进路*/
			errType = KeepBlocLTrainRouteErrProcess(routeId);/*检查失败原因*/
		}

	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{
		returnValue = KeepDTrainRouteP(routeId); /*保持调车进路信号*/
		errType = KeepDTrainRouteErrP(routeId);/*检查失败原因*/
		inPhySecCurMergeState = GetPhySecCurMergeState(inPhySecId);
		inPhySecPreMergeState = GetPhySecPreMergeState(inPhySecId);
		outPhySecCurMergeState = GetPhySecCurMergeState(outPhySecId);
		/*判断列车驶入:（内方第一区段当前占用 && 之前空闲） ）&& （始端信号机外方第一区段当前占用*/
		if ((SECTION_OCCUPY_YES == inPhySecCurMergeState) && (SECTION_OCCUPY_NO == inPhySecPreMergeState))
		{
			if ((0U == outPhySecId) || (SECTION_OCCUPY_YES == outPhySecCurMergeState))
			{
				SetTrainEnterRouteFlag(routeId, TRAIN_ENTER_ROUTE_FLAG_YES);
			}
		}
	}
	else if (ROUTE_TYPE_RETURN == routeType)
	{ /*折返进路*/

		if (ROUTE_LEVEL_CBTC == routeLevel)
		{ /*CBTC*/

			returnValue = KeepCbtcReturnRouteLogicProcess(routeId);   /*保持CBTC折返进路*/
			errType = KeepCbtcReturnRouteErrProcess(routeId);/*检查失败原因*/
		}
		else
		{ /*点式*/

			returnValue = KeepBlocReturnRouteLogicProcess(routeId);   /*保持点式折返进路*/
			errType = KeepBlocReturnRouteErrProcess(routeId);/*检查失败原因*/
		}
	}
	else
	{/*不处理*/
	}

	/*根据开放信号返回值处理*/
	if (CI_SUCCESS == returnValue)
	{ /*成功*/

		(void)DriveSignalOpen(startSignalId, routeId);  /*驱动信号开放*/

		return CI_SUCCESS;
	}
	else
	{ /*失败*/

		(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/

		if (CI_ROUTE_RECOVER_ERR == errType)
		{
			/*进路因为恢复后可重开的因素导致无法保持开放，需置进路具备等待恢复特性*/
			SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_WAIT);
		}
		else
		{
			SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);
		}

		return CI_ERROR;
	}
}


/*
* 功能描述： 进路总取消处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteZongQuXiaoProc(const UINT16 routeId)
{
	UINT8 routeState = 0u;         /*进路状态*/
	UINT16 startSignalId = 0u;
	UINT8 sigCurColor = SIGNAL_SHOWCOLOUR_INVALID;
	UINT8 routeDelayUnlockflag = 0u; /* 进路延时解锁属性*/
	UINT8 checkRouteCancel = 0u;
	UINT8 cSignalInHumidRailFlag = PHYSEC_IN_HUMID_RAIL_NO;  /*信号机湿轨标志*/

	/*获取进路动态字段*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/
	startSignalId = GetRouteStartSignalId(routeId);
	sigCurColor = GetSignalCurColor(startSignalId);

	if (GetSignalOpenCloseState(sigCurColor) == SIGNAL_OPEN)
	{
		/*信号未关闭*/

		(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/

		return;
	}
	else
	{
		/*信号已关闭*/

		SetRouteZongQuXiaoFlag(routeId, ROUTE_ZONGQUXIAO_SET_NO);  /*取消进路总取消标志*/
	}

	cSignalInHumidRailFlag = GetSignalInHumidRailFlag(startSignalId);
	if (PHYSEC_IN_HUMID_RAIL_NO == cSignalInHumidRailFlag)
	{
		/*总取消进路处理*/
		if ((ROUTE_STATE_XUANPAI == routeState) || (ROUTE_STATE_FIRST_XUANPAI == routeState))
		{
			/*进路选排或初选*/

			/*取消进路选排*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

		}
		/*进路初锁||进路初锁异常||进路预先锁闭*/
		else if ((ROUTE_STATE_FIRST_LOCK == routeState) ||
			(ROUTE_STATE_FIRST_LOCKERR == routeState) ||
			(ROUTE_STATE_YUXIAN_LOCK == routeState))
		{
			/* 检查取消检查条件*/
			checkRouteCancel = RouteCancelLogicProcess(routeId);
			/* 获取进路延时解锁属性*/
			routeDelayUnlockflag = GetRouteNeedDelayUnlock(routeId);
			if (CI_SUCCESS == checkRouteCancel)
			{
				/*需要延时解锁*/
				if (ROUTE_NEED_DELAY_UNLOCK == routeDelayUnlockflag)
				{
					/*设置进路延时解锁状态*/
					SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);
					/*设置延时解锁*/
					SetRouteZongQuXiaoDelayFlag(routeId, ROUTE_ZQX_DELAY_YES);
				}
				else
				{
					/*-->设置进路空闲*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
				}
			}
			else
			{
				/*进路不能取消*/
			}
		}
		else if ((ROUTE_STATE_NEAR_LOCK == routeState) ||
			(ROUTE_STATE_NEAR_LOCKERR == routeState))
		{
			/*反馈接近锁闭*/
			SetCiSendCmdBackInfoData(CI_BACK_ROUTE_NEAR_LOCK_YES, CI_DEVICE_TYPE_ROUTE, routeId, 0u, 0u);
		}
		else if ((ROUTE_STATE_LEAD_LOCK == routeState) ||
			(ROUTE_STATE_LEAD_LOCKERR == routeState) ||
			(ROUTE_STATE_LEAD_FIRST_XUANPAI == routeState) ||
			(ROUTE_STATE_LEAD_OPEN == routeState) ||
			(ROUTE_STATE_LEAD_XUANPAI == routeState))
		{
			/*引导进路总取消新增报警信息*/
			SetCiSendCmdBackInfoData(CI_BACK_LEAD_ROUTE_CANCEL, CI_DEVICE_TYPE_ROUTE, routeId, 0u, 0u);
		}
		else if (ROUTE_STATE_IDLE == routeState)
		{
			CancelLongRouteXuanPai(routeId);  /*修复缺陷YF0083-2370：总取消时若进路空闲，则取消长调进路选排*/
		}
		else
		{
			/*反馈未完整锁闭*/
			SetCiSendCmdBackInfoData(CI_BACK_ROUTE_LOCK_NOTALL, CI_DEVICE_TYPE_ROUTE, routeId, 0u, 0u);
		}
	}
	else
	{
		/*进路始端信号机处于湿轨范围，不解锁进路*/
		debug_infor_printf((const)"\n SignalInHumidRailFlag Valid,Not RouteZongQuXiaoProc \n");
	}
}

/*
* 功能描述： 自动信号进路取消处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS:成功
			 CI_ERROR:失败
*/
UINT8 AutoSigRouteQuXiaoProc(const UINT16 routeId)
{
	UINT8 routeState = 0u;         /*进路状态*/
	UINT16 startSignalId = 0u;
	UINT8 retVal = CI_SUCCESS;

	/*获取进路动态字段*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/
	startSignalId = GetRouteStartSignalId(routeId);

	if (GetSignalOpenCloseState(GetSignalCurColor(startSignalId)) == SIGNAL_OPEN)
	{/*信号未关闭*/
#if 0
		if ((ROUTE_STATE_YUXIAN_OPEN == routeState) || (ROUTE_STATE_YUXIAN_LOCK == routeState))
		{/*(信号开放) && (未有车接近)时才可以驱动关闭自动信号机*/

			DriveSignalClose(startSignalId);  /*驱动信号关闭*/
			retVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT;
		}
		else
		{/*(信号开放) && (有车接近)时不可以驱动关闭自动信号机*/
			retVal = CI_ERROR;
		}
#endif


		/*持续检查接近区段有无占用*/
		if (CI_ERROR == RouteHaveTrainNear(routeId))
		{    /*进路未接近*/
			if (CI_SUCCESS == RouteCancelLogicProcess(routeId))
			{
				(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/
				retVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT;
			}
			else
			{
				retVal = CI_ERROR;
			}
		}
		else
		{  /*进路接近*/
			/*反馈接近锁闭*/
			SetCiSendCmdBackInfoData(CI_BACK_ROUTE_NEAR_LOCK_YES, CI_DEVICE_TYPE_ROUTE, routeId, 0u, 0u);
			retVal = CI_ERROR;
		}



	}
	else
	{/*信号已经关闭*/

		/*总取消进路处理*/
		if ((ROUTE_STATE_XUANPAI == routeState) || (ROUTE_STATE_FIRST_XUANPAI == routeState))
		{
			/*进路选排或初选*/

			/*取消进路选排*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
			retVal = CI_SUCCESS;
		}
		else if ((ROUTE_STATE_FIRST_LOCK == routeState) ||
			(ROUTE_STATE_FIRST_LOCKERR == routeState) ||
			(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
			(ROUTE_STATE_YUXIAN_OPEN == routeState))
		{
			/*进路初锁||进路初锁异常||进路预先锁闭 ||预先开放*/

			/*增加预先开放状态的原因:如果反向进路在自动信号进路之前遍历，那么自动信号没来的及
			   ROUTE_STATE_YUXIAN_OPEN--->ROUTE_STATE_YUXIAN_LOCK,这样会导致自动信号进路取消
			   失败。但其实这时已经满足取消的条件了。

			   总取消之所以没有添加此状态是因为:总取消处理函数是放在进路状态处理之后的
			*/
			if (CI_SUCCESS == RouteCancelLogicProcess(routeId))
			{
				/*取消成功*/

				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
				retVal = CI_SUCCESS;
			}
			else
			{
				/*取消失败*/
				retVal = CI_ERROR;
			}
		}
		else if ((ROUTE_STATE_NEAR_LOCK == routeState) ||
			(ROUTE_STATE_NEAR_LOCKERR == routeState) ||
			(ROUTE_STATE_NEAR_OPEN == routeState))
		{

			if (CI_ERROR == RouteHaveTrainNear(routeId))
			{/*接近区段无车占用，则可以取消该自动信号进路*/
				if (CI_SUCCESS == RouteCancelLogicProcess(routeId))
				{
					/*取消成功*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
					retVal = CI_SUCCESS;
				}
				else
				{
					/*取消失败*/
					retVal = CI_ERROR;
				}
			}
			else
			{
				retVal = CI_ERROR;
			}
		}
		else if (ROUTE_STATE_IDLE == routeState)
		{
			retVal = CI_SUCCESS;
		}
		else
		{
			/*取消失败*/
			retVal = CI_ERROR;
		}
	}

	return retVal;
}

/*
* 功能描述： 进路总人解处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteZongRenJieProc(const UINT16 routeId)
{
	UINT8 routeState = 0u;         /*进路状态*/
	UINT16 startSignalId = 0u;
	UINT8 checkResult = CI_ERROR;/*区段是否有车占用*/
	UINT16 firstOccuSecId = 0u;/*进路内方第一个占用的物理区段ID*/
	UINT8 devState = 0u;
	UINT8 trainEnterSta = 0u;/*进路列车驶入标志*/
	UINT8 checkZongRenJieResult = 0u;
	UINT8 routeDelayUnlockflag = 0u;
	UINT8 checkResultSecAndQXZC = 0u;    /*RouteExceptLastSecOccuClrCheck此函数的检查结果*/
	UINT8 cSignalColor = 0u;
	UINT8 cSignalOpenState = 0u;

	/*获取进路动态字段*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/
	startSignalId = GetRouteStartSignalId(routeId);

	cSignalColor = GetSignalCurColor(startSignalId);
	cSignalOpenState = GetSignalOpenCloseState(cSignalColor);

	if (SIGNAL_OPEN == cSignalOpenState)
	{
		/*信号未关闭*/

		(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/
#if 0
		SetRouteZongRenJieCloseFlag(routeId, ROUTE_ZRJ_CLOSE_FLAG_YES);  /*进路信号关闭是总人解导致*/
#endif
		return;
	}
	else
	{
		/*信号已关闭*/
		(void)SetRouteZongRenJieFlag(routeId, ROUTE_ZONGRENJIE_SET_NO);  /*取消进路总人解标志*/
#if 0
		zrjCloseSigFlag = GetRouteZongRenJieCloseFlag(routeId);  /*或取进路的总人解关信号标志*/
		SetRouteZongRenJieCloseFlag(routeId, ROUTE_ZRJ_CLOSE_FLAG_NO);  /*用完清除*/
#endif
	}

	checkResult = RouteAllSecOccuClearCheck(routeId, &firstOccuSecId, &devState);
	trainEnterSta = GetRouteTrainEnterFlag(routeId);

	/*总人解进路处理*/
	if ((ROUTE_STATE_XUANPAI == routeState) || (ROUTE_STATE_FIRST_XUANPAI == routeState))
	{
		/*进路选排或初选*/

		/*取消进路选排*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

	}
	else  if ((ROUTE_STATE_FIRST_LOCK == routeState) ||
		(ROUTE_STATE_FIRST_LOCKERR == routeState) ||
		(ROUTE_STATE_YUXIAN_LOCK == routeState))
	{
		/*进路初锁||进路初锁异常||进路预先锁闭*/
		/*总人解逻辑处理*/
		checkZongRenJieResult = CheckRouteZongRenJieFeasibility(routeId);
		/* 获取进路延时解锁属性*/
		routeDelayUnlockflag = GetRouteNeedDelayUnlock(routeId);
		if (CI_SUCCESS == checkZongRenJieResult)
		{
			/*进路需要延时解锁*/
			if (ROUTE_NEED_DELAY_UNLOCK == routeDelayUnlockflag)
			{
				/*进路内无占用*/
				if (CI_SUCCESS == checkResult)
				{
					/*-->设置进路延时解锁*/
					SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);
					/*进路内无占压，延时后全部解锁*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);
				}
				else
				{
					/* 进路内有车占用，判断内方第一逻辑区段是否占用 */
					if (ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta)
					{/*无车驶入，全部变绿光带*/
						/*将进路内所有物理区段变成绿光带*/
						SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_EXCEPT);

						/*进路逻辑区段都故障锁闭*/
						SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_EXCEPT);
					}
					else
					{
						/*车身后变绿光带*/
						SetRoutePhySecExpLockToOccupy(routeId);
					}

					SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
				}
			}
			else
			{

				if (CI_SUCCESS == checkResult)
				{/*已无占用*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
				}
				else
				{
					if (ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta)
					{/*无车驶入，全部变绿光带*/
						/*将进路内所有物理区段变成绿光带*/
						SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_EXCEPT);

						/*进路逻辑区段都故障锁闭*/
						SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_EXCEPT);
					}
					else
					{
						/*车身后变绿光带*/
						SetRoutePhySecExpLockToOccupy(routeId);
					}

					SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
				}
			}
		}
		else
		{
			/*进路不能取消*/
		}
	}
	else if (ROUTE_STATE_NEAR_LOCKERR == routeState)
	{
		/*总人解逻辑处理*/
		checkZongRenJieResult = CheckRouteZongRenJieFeasibility(routeId);
		if (CI_SUCCESS == checkZongRenJieResult)
		{
			SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);  /*-->设置进路延时解锁*/

			if (CI_SUCCESS == checkResult)
			{
				/*进路内无占压，延时后全部解锁*/
				SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);
			}
			else
			{
				/* 进路内有车占用 */
				if (ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta)
				{
					/*无列车驶入过，延时后全部边绿光带*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_ALL_EXP);
				}
				else
				{
					/*延时后部分绿光带，即一个占压的物理区段之前的物理区段变绿光带*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_EXP_TO_OCCUPY);
				}
			}
		}
		else
		{
			/*进路不能取消*/
		}
	}
	else if ((ROUTE_STATE_LEAD_LOCK == routeState) || (ROUTE_STATE_LEAD_LOCKERR == routeState))
	{   /*引导锁闭||引导锁闭异常*/
		/*人解引导进路解锁原则：修改20180809
		当进路内方空闲或最后一个区段占用时，立即解锁；
		当非最后一个区段占用且无驶入，则延时解锁，其他场景不解锁*/

		checkResultSecAndQXZC = RouteExceptLastSecOccuClrCheck(routeId);
		if (CI_SUCCESS == checkResultSecAndQXZC)
		{   /*所有区段空闲或最后一个区段占用，也需要延时解锁*/

			/*总人解办理*/
			SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);  /*-->设置进路延时解锁*/
			/*延时后全部解锁*/
			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);/*延时结束后所有区段解锁*/
		}
		else if ((ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta) && (CI_ERROR_QXZC != checkResultSecAndQXZC))
		{/*当总人解引导进路时，有取消照查继电器且未吸起则不能解锁引导进路*/
			/*总人解办理*/
			SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);  /*-->设置进路延时解锁*/
			/*延时后全部解锁*/
			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);/*延时结束后所有区段解锁*/
		}
		else
		{
			/*不解锁*/
		}

	}
	else
	{
		/*进路状态不满足*/
		/* 记录故障码 */
		SetErrorData(EFUNC_ROUTE_ZRJ_DEAL, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, ESEND_LEVEL_ATS);
	}
}


/*
解锁本联锁保护区段管理
UINT8 overlapIdSum 保护区段总数
UINT16 * pOverlapIdBuf 保护区段ID缓存指针

CI_SUCCESS 成功
CI_ERROR 失败

*/
UINT8 UnLockLocalOvlpManageHlht(UINT8 overlapIdSum, UINT16* pOverlapIdBuf)
{
	UINT8 const localCiId = GetSystemParaLocalCiId(); /*获取本机联锁ID*/

	UINT8 retVal = CI_ERROR;
	UINT16 overlapId = 0u;
	UINT8 ii = 0u;

	if ((0u == overlapIdSum) || (NULL == pOverlapIdBuf))
	{
		/*没有保护区段*/
		retVal = CI_SUCCESS;
	}
	else
	{
		for (ii = 0u; ii < overlapIdSum; ii++)
		{
			overlapId = *(pOverlapIdBuf + ii);

			if (GetOverlapBelongCiId(overlapId) == localCiId)
			{
				/*解锁进路Overlap管理*/
				if (CI_SUCCESS == UnlockLocalOvlpCheckHlht(overlapId))
				{ /*解锁成功*/
					SetOvlpLockStateForHlhtCi(overlapId, PHYSICAL_SECTION_LOCK_NO, 0);  /*设置Overlap未锁闭*/

					retVal = CI_SUCCESS;

					break;
				}
				else
				{ /*解锁失败*/
					/*跳过*/
				}
			}
		}
	}

	return retVal;
}


/*
* 功能描述： 解锁进路OVERLAP处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 UnlockRouteOverlapProc(const UINT16 routeId)
{
	UINT8 const localCiId = GetSystemParaLocalCiId(); /*获取本机联锁ID*/

	UINT16 unlockOverlapId = 0u;  /*保护区段ID*/

	UINT16 overlapId = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 devCurMergeState = 0u;         /*设备融合占用状态*/
	UINT8 utOrCtOccFlag = 0u;            /*物理区段CT或UT占用状态*/
	UINT8 routeState = 0u;                /*进路状态*/
	UINT8 routeBelongCi = 0u;             /*进路所属联锁*/
	UINT16 wTrainId = 0u;				  /* 列车编号 */
	UINT8 ret = CI_SUCCESS;
	UINT8 cRcWorkMode = 0u;
	UINT32 dwCurSysCycNum = 0U;  /*当前系统周期*/
	UINT32 dwReqUnlockStartCycNum = 0U;  /*向车申请解锁起始周期号*/

	/* RC工作模式 */
	cRcWorkMode = GetLocalRcWorkMode();
	dwCurSysCycNum = Get2oo2CurCycleNum();

	if (ROUTE_OVERLAP_SET_YES != GetRouteOverlapLockFlag(routeId))
	{ /*进路保护区段未锁闭*/

		return CI_SUCCESS;
	}

	overlapId = GetRouteOverlapLockedId(routeId);

	if (GetOverlapBelongCiId(overlapId) != localCiId)
	{
		/*不属于本联锁保护区段*/
		return CI_ERROR;
	}

	devId = GetRouteLastPhySectionId(routeId);
	devState = GetPhySecLockState(devId);
	routeState = GetRouteState(routeId);
	routeBelongCi = GetRouteBelongCiId(routeId);
	devCurMergeState = GetPhySecCurMergeState(devId);
	utOrCtOccFlag = GetPhySecPreOccState(devId);	/*获取物理区段CT或UT占用状态*/
	if ((PHYSICAL_SECTION_LOCK_NO != devState) && (GetRouteDirection(routeId) == GetPhySecLockDirection(devId)) &&
		(ROUTE_STATE_IDLE == routeState) &&
		(routeBelongCi != localCiId))/*2017年02月22日，增加&&(GetRouteDirection(routeId)==GetPhySecLockDirection(devId))，原因：列车占压保护区段时，进路已经解锁。此时办理了相反方向的进路，物理区段又锁闭了，但是此时与之前的保护区段无关*/
	{	/*
		 *解决: 相邻联锁重启后，向本联锁发送进路空闲，而进路最后一个区段属于本联锁时处于绿光带，这个时候如果解防护
			   防护区段，不太合适，因此为解决该问题追加判断。
			判断条件为：
		   （ 进路状态空闲）&&（该进路不属于本联锁）&&（最后一个区段锁闭状态不为未锁闭）时不解锁保护区段
			防护以下出现的情景:
			例如:CI1 和 CI5
			CI1办理进路Z3-CD1进路，CI1宕机，ZHG1绿光带且保护区段JK1G存在；CI1重启，JK1G解锁
		*/
	}
	else
	{
		ret = UnlockRouteOverlapLogicProcess(routeId, &unlockOverlapId, &wTrainId);
		/*解锁进路Overlap管理*/
		if ((CI_SUCCESS == ret) || (CI_OVERLAP_OCC_UNLOCK == ret))
		{ /*可以解锁*/
			SetOverlapLockState(unlockOverlapId, PHYSICAL_SECTION_LOCK_NO, routeId);  /*设置Overlap未锁闭*/
			return CI_SUCCESS;
		}
		else if (CI_UNLOCK_OVERLAP_REQURE == ret)
		{
			/*可以发送解锁申请*/
			if (RC_WORK_MODE_TIOC == cRcWorkMode)
			{
				/* 需要询问列车进行保护区段解锁，当没有列车资源占用时才解锁 */
				wTrainId = wTrainId & 0x00FFU;
				SetOverlapUnlockApplyTrainId(unlockOverlapId, wTrainId);

				dwReqUnlockStartCycNum = GetReqIvocUnlockStartCycNum(unlockOverlapId);
				if (0U == dwReqUnlockStartCycNum)
				{
					SetReqIvocUnlockStartCycNum(unlockOverlapId, dwCurSysCycNum);  /*仅将第一次申请时的周期号最为申请解锁起始周期号*/
				}
				else
				{
					/*不处理*/
				}
			}
			else if (RC_WORK_MODE_CI == cRcWorkMode)
			{
				/* TODO */
				SetOverlapUnlockApplyFlag(unlockOverlapId, UNLOCK_OVERLAP_APPLY_YES);
			}
			else
			{
				; /* 无处理 */
			}
		}
		else if (CI_ERROR == ret)
		{
			/*错误，什么也不做*/
		}
		else
		{
			/*什么也不做*/
		}

		wTrainId = GetOverlapUnlockApplyTrainId(unlockOverlapId);

		if (SECTION_OCCUPY_NO == devCurMergeState)/*当前空闲*/
		{
			if (RC_WORK_MODE_TIOC == cRcWorkMode)
			{
				if (0u != wTrainId)
				{
					/*停止发解锁申请*/
					SetOverlapUnlockApplyTrainId(unlockOverlapId, 0U);
					SetReqIvocUnlockStartCycNum(unlockOverlapId, 0U);
					/*停止倒计时*/
					SetSecUtOrCtOccuStartCycNum(devId, 0u);
				}
			}
			else if (RC_WORK_MODE_CI == cRcWorkMode)
			{
				/* TODO */
				if (UNLOCK_OVERLAP_APPLY_YES == GetOverlapUnlockApplyFlag(unlockOverlapId))/*当前正给ZC发送解锁申请*/
				{
					/*停止发解锁申请*/
					SetOverlapUnlockApplyFlag(unlockOverlapId, UNLOCK_OVERLAP_APPLY_NO);
					/*停止倒计时*/
					SetSecUtOrCtOccuStartCycNum(devId, 0u);
				}
			}
			else
			{
				; /* 无处理 */
			}

		}
		else if ((SECTION_OCCUPY_YES == devCurMergeState) && (LOGICSECTION_OCCUPY_UT == utOrCtOccFlag))/*当前UT占用*/
		{
			if (RC_WORK_MODE_TIOC == cRcWorkMode)
			{
				if (0u != wTrainId)
				{
					/*停止发解锁申请*/
					SetOverlapUnlockApplyTrainId(unlockOverlapId, 0u);
					SetReqIvocUnlockStartCycNum(unlockOverlapId, 0U);
				}
			}
			else if (RC_WORK_MODE_CI == cRcWorkMode)
			{
				/* TODO */
				if (UNLOCK_OVERLAP_APPLY_YES == GetOverlapUnlockApplyFlag(unlockOverlapId))/*当前正给ZC发送解锁申请*/
				{
					/*停止发解锁申请*/
					SetOverlapUnlockApplyFlag(unlockOverlapId, UNLOCK_OVERLAP_APPLY_NO);
				}
			}
			else
			{
				; /* 无处理 */
			}
		}
		else
		{
			/*什么也不做*/
		}
	}
	return CI_ERROR;
}


/*
* 功能描述： 物理区段延时解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void PhySecDelayUnlockProc(const UINT16 routeId)
{
	UINT16 phySectionId = 0u;        /*物理区段ID*/
	UINT16 nextPhySectionId = 0u;    /*下一物理区段ID*/
	UINT8 secLockState = 0u;         /*区段锁闭状态*/
	UINT8 returnValue = 0u;          /*函数返回值*/
	UINT16 routeLastSwiPhySecId = 0u;    /*进路最远端道岔区段ID*/

	UINT8 sectionSum = 0u; /*该进路区段总数*/
	RoutePhysicalSectionStruct* pRouteSecStru = NULL; /*区段数据*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/

/*进路区段延时解锁处理*/
	returnValue = PhySectionDelayUnlockProcess(routeId, &phySectionId);

	if (0u == phySectionId)
	{
		/*不做处理*/
#if 0/*按逻辑区段解锁，注释掉*/
		/*没有延时解锁区段*/
		if (CI_SUCCESS == CheckRoutePhySecHaveUnLock(routeId))
		{
			/*进路区段全部解锁*/
			if (ROUTE_STATE_FLAG_YES == GetRouteStateFlag(routeId))
			{/*CBTC追踪办理进路标志有效，则不改变进路状态，继续保持自动解锁正常（此时进路区段已全部解锁）*/
			}
			else
			{/*CBTC追踪办理进路标志无效，则设置进路空闲*/
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
			}
		}
#endif

	}
	else
	{
		/*有延时解锁区段*/
		if (CI_SUCCESS == returnValue)
		{ /*成功*/
			SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId));  /*设置物理区段未锁闭*/

			/*同时设置物理区段其他属于本进路锁闭的逻辑区段未锁闭*/
			SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_NO, routeId);

			routeLastSwiPhySecId = GetRouteLastSwichPhySecId(routeId);
			if (phySectionId == routeLastSwiPhySecId)
			{/*解锁进路关联防护道岔*/
				SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL);/*取消进路关联防护道岔的防护锁闭*/
			}

			/*调车最后一个无岔区段连带解锁*/
			if ((ROUTE_TYPE_DIAOCHE == GetRouteType(routeId)) &&
				(sectionSum >= 2u) &&
				(phySectionId == pRouteSecStru[sectionSum - 2U].PhysicalSectionId) &&
				(PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(pRouteSecStru[sectionSum - 1U].PhysicalSectionId)))
			{ /*调车进路 && 区段数大于2 && 进路倒数第二个区段 && 最后一个区段无岔*/

				SetPhySecLockState(pRouteSecStru[sectionSum - 1U].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId));  /*设置物理区段未锁闭*/
			}
			else
			{
				;
			}

			if (CI_SUCCESS == CheckRoutePhySecHaveUnLock(routeId))
			{
				/*进路区段全部解锁*/
				if (ROUTE_STATE_FLAG_YES == GetRouteStateFlag(routeId))
				{/*CBTC追踪办理进路标志有效，则不改变进路状态，继续保持自动解锁正常（此时进路区段已全部解锁）*/
				}
				else
				{/*CBTC追踪办理进路标志无效，则设置进路空闲*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
				}
			}
			else
			{
				nextPhySectionId = GetRouteNextPhySecId(routeId, phySectionId);  /*获取下一物理区段ID*/
				secLockState = GetPhySecLockState(nextPhySectionId);  /*获取物理区段锁闭状态*/

				if ((nextPhySectionId > 0u) && (PHYSICAL_SECTION_LOCK_DELAY == secLockState))
				{
					/*更新下一区段计时*/
					SetPhySecAutoUnlockStartCycNum(nextPhySectionId, Get2oo2CurCycleNum());  /*设置物理区段延时解锁起始周期*/
				}
				else
				{
					/*下一区段未延时锁闭*/
				}
			}
		}
		else if (RETURN_DELAYUNLOCK_ERR_TIMECOUNT == returnValue)
		{
			/*计时未到*/
		}
		else
		{
			/*失败*/
			SetPhySecAutoUnlockStartCycNum(phySectionId, Get2oo2CurCycleNum());  /*设置物理区段延时解锁起始周期*/
		}
	}
}


/*
* 功能描述： 进路列车驶入检查
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS：成功
*            ERROR：  失败
* mod by qw.liu 修改编码规范，修改CBTC级别列车进路驶入判断
*/
UINT8 RouteLTrainEnter(const UINT16 routeId)
{
	UINT16 startSigId = 0u;     /*进路始端信号机ID*/
	UINT16 outPhySecId = 0u;    /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u;     /*信号机内方第一区段ID*/
	UINT8 routeLevel = 0u;
	UINT8 routeType = 0u;
	UINT8 routeCrossState = 0u;
	UINT16 nextPhySecId = 0u;
	UINT8 signalType = 0u;
	UINT8 signalCrossCloseType = 0u;
	UINT16 wszTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT8  chTrainInfoSum = 0U;
	UINT8  chDsnFuncSwitch = 0U;

	UINT8 chRetVal = CI_ERROR;
	UINT8 chFuncRet = CI_ERROR;
	UINT16 wDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chRCMode = 0u;
	UINT8 cRoutePreLevel = 0U;  /*进路之前级别*/
	UINT8 chLocalCiType = 0U;/*联锁类型*/

	/* 联锁逻辑检查 */

	chDsnFuncSwitch = GetCiFunctionSwitchConfig(FUNC_TOA_SWITCH);
	startSigId = GetRouteStartSignalId(routeId);  /*获取进路起始信号机ID*/
	signalType = GetSignalType(startSigId);	/*获取信号机点灯逻辑类型*/
	signalCrossCloseType = GetSignalCrossCloseAttr(startSigId);	/*获取信号机调车跨压关灯类型*/

	if (0u == startSigId)
	{
		chRetVal = CI_ERROR;
	}
	else
	{
		chRetVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == chRetVal)
	{
		inPhySecId = GetSignalInFirstPhySecId(startSigId, routeId);    /*信号机内方第一物理区段ID*/
		outPhySecId = GetSignalOutFirstPhySecId(startSigId);  /*信号机外方第一物理区段ID*/
		if (0u == inPhySecId)
		{
			chRetVal = CI_ERROR;
		}
		else
		{
			; /*继续执行*/
		}
	}
	else
	{
		;
	}
	if (CI_SUCCESS == chRetVal)
	{
		routeType = GetRouteType(routeId);

		if (ROUTE_TYPE_DIAOCHE == routeType)
		{ /*调车进路*/
		  /*调车信号，当车列全部越过信号机时；或在信号机外方区段留有车辆或信号机外方区段未设轨道电路（无论是否留有车辆）的情况下车列出清内方第一区段时*/
			if ((SECTION_OCCUPY_NO == GetPhySecCurMergeState(inPhySecId)) &&
				(SECTION_OCCUPY_YES == GetPhySecPreMergeState(inPhySecId)))
			{ /*内方第一区段空闲*/
				if ((outPhySecId == 0u) || ((SECTION_OCCUPY_YES == GetPhySecCurMergeState(outPhySecId)) &&
					(PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(outPhySecId))))
				{ /*外方区段为0||外方区段当前占用&&无岔区段*/

					nextPhySecId = GetRouteNextPhySecId(routeId, inPhySecId); /*获取内方第一区段的下一区段ID*/
					if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(nextPhySecId))
					{
						chRetVal = CI_SUCCESS; /*列车驶入*/
					}
					else
					{
						chRetVal = CI_ERROR;
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(inPhySecId))
			{ /*内方第一区段占用*/
				if (0u == outPhySecId)
				{
					chRetVal = CI_SUCCESS; /*列车驶入*/
				}
				else if (((SIGNAL_TYPE_JINKUCHUKU == signalType) || ((SIGNAL_TYPE_TWO_JINKU_RGY == signalType) || (SIGNAL_TYPE_THREE_JINKU_YINDAO == signalType)))
					&& ((SIGNAL_CROSS_ClOSE_YES == signalCrossCloseType) && (SECTION_OCCUPY_YES == GetPhySecCurMergeState(outPhySecId))))
				{/*车辆段调车进路进库信号机，当内方第一区段占用且有调车跨压关灯属性时即认为列车驶入*/
					chRetVal = CI_SUCCESS; /*列车驶入*/
				}
				else
				{
					if ((SECTION_OCCUPY_NO == GetPhySecCurMergeState(outPhySecId)) &&
						(SECTION_OCCUPY_YES == GetPhySecPreMergeState(outPhySecId)))
					{ /*外方区段当前空闲&&之前占用*/

						chRetVal = CI_SUCCESS; /*列车驶入*/
					}
					else
					{
						chRetVal = CI_ERROR;
					}
				}

			}
			else
			{ /*内方之前及当前均空闲*/

				chRetVal = CI_ERROR;
			}
		}
		else if ((ROUTE_TYPE_LIECHE == routeType) || (ROUTE_TYPE_RETURN == routeType))
		{
			routeLevel = GetRouteLevel(routeId);
			chRCMode = GetLocalRcWorkMode();/*获取当前RC工作模式*/
			if (RC_WORK_MODE_TIOC == chRCMode)
			{
				if (ROUTE_LEVEL_CBTC == routeLevel)
				{
					chRetVal = RouteCbtcTiranEnterCheck(routeId);/*函数内调用过 GetRouteReadyEnterTrainInfo*/
				}
				else
				{
					chFuncRet = GetRouteReadyEnterTrainInfo(routeId, &chTrainInfoSum, wszTrainId);
					cRoutePreLevel = GetRoutePreLevel(routeId);  /*获取进路之前级别*/
					if ((CI_ERROR == chFuncRet) || (1U < chTrainInfoSum) || (ROUTE_LEVEL_BLOC != cRoutePreLevel))
					{
						chRetVal = CI_ERROR;  /*准备驶入列车数量大于1或者之前进路级别非点式级别，返回0失败*/
					}
					else
					{
						; /*资源数量为1或0 通过检查*/
					}
				}
			}
			else if (RC_WORK_MODE_CI == chRCMode)
			{/*CI*/

				routeCrossState = GetSignalCrossState(startSigId);
				if ((routeLevel == ROUTE_LEVEL_CBTC) && (routeCrossState == SIGNAL_CROSS_STATE_NO))
				{
					/*CBTC进路非跨压信号机关闭*/
					chRetVal = CI_ERROR;
				}
				else
				{
					;/*检查通过*/
				}
			}
			else
			{
				chRetVal = CI_ERROR;/*模式错误返回失败*/
			}

			/*内外方占压检查*/
			if (CI_SUCCESS == chRetVal)
			{
				chDevState = GetPhySecCurMergeState(inPhySecId);
				if (SECTION_OCCUPY_YES == chDevState)
				{ /*内方区段占用，进路为CBTC非车辆段时，考虑为列车高速跨压,只需要考虑内方第一区段的占压，不用管外方*/
					chLocalCiType = GetLocalCiType();
					if ((ROUTE_LEVEL_CBTC == routeLevel) && (CI_TYPE_CLD != chLocalCiType))
					{
						chRetVal = CI_SUCCESS;
					}
					else
					{
						if (outPhySecId == 0u)
						{
							chRetVal = CI_SUCCESS;
						}
						else
						{
							chDevState = GetPhySecCurMergeState(outPhySecId);
							if (SECTION_OCCUPY_YES == chDevState)
							{ /*外方区段占用*/

								chRetVal = CI_SUCCESS;
							}
							else
							{
								chRetVal = CI_ERROR;
							}
						}
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				;
			}

			if (FUNC_SWITCH_ON == chDsnFuncSwitch)
			{
				chFuncRet = RouteFaultOccuCheck(routeId, &wDevId, &chDevState);
				if (CI_SUCCESS == chFuncRet)
				{
					chDevState = GetPhySecCurOccupyState(inPhySecId);
					if (SECTION_OCCUPY_YES == chDevState)
					{

					}
					else
					{
						chRetVal = CI_ERROR;
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}


/*
* 功能描述： 进路开放需关闭信号处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS：成功
*            ERROR：  失败
*/
UINT8 RouteOpenNeedCloseSignal(const UINT16 routeId)/* liu 06-26*/
{
	UINT8 needCloseSignalNum = 0u;
	UINT16* needCloseSignalIdBuf = NULL;
	UINT16 curSignalId = 0u;
	UINT8 ii = 0u;
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 closeFlag = 0u;		/* 需要关闭的标志 */
	UINT8 belongCiId = 0u;        /*信号机所属联锁ID*/
	UINT8 driveRetVal = 0u;

	localCiId = GetSystemParaLocalCiId();/*本联锁ID*/

	if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
	{
		return CI_ERROR;
	}

	needCloseSignalNum = GetRouteOpenNeedCloseSigSum(routeId);
	if (0u == needCloseSignalNum)
	{
		return CI_SUCCESS;
	}
	/*
	 * 如果需要驱动关闭的信号机是自动信号，则需要关闭，
	 * 如果不是自动信号机，则如果已经信号已经开放，则不去驱动关闭
	 *
	 */
	if (ROUTE_OPENNEEDCLOSESIG_SUM_MAX >= needCloseSignalNum)
	{
		needCloseSignalIdBuf = GetRouteOpenNeedCloseSigIdBuf(routeId);
		for (ii = 0u; ii < needCloseSignalNum; ii++)
		{
			closeFlag = 0u;		/* 不驱动 */
			curSignalId = needCloseSignalIdBuf[ii];
			belongCiId = GetSignalBelongCiId(curSignalId);
			if (localCiId != belongCiId)
			{
				closeFlag = 0u;	/* 不去驱动关闭 ,非本联锁也不驱动*/
			}
			else
			{
				closeFlag = 1u;/* 关闭 */
			}

			if (closeFlag == 1u)
			{
				driveRetVal = DriveSignalClose(curSignalId);
				if (CI_ERROR == driveRetVal)
				{
					return CI_ERROR;
				}
			}
		}

		return CI_SUCCESS;
	}
	else
	{
		return CI_ERROR;
	}
}


/*
* 功能描述： overlap锁闭驱动道岔处理
* 参数说明： const UINT16 overlapId, overlap ID
* 返回值  ： 0:失败
*			 1:成功
*/
UINT8 OverlapLockDriveSwitch(const UINT16 overlapId)/* liu 06-26*/
{
	UINT8 ii;
	UINT8 switchSum = 0u;
	UINT16 switchId = 0u;
	UINT8 switchExpPosition = 0u;
	UINT8 switchCurPosition = 0u;
	UINT8 switchDancaoPosition = 0u; /*单操有效位置*/
	UINT8 retVal = CI_SUCCESS;
	OverlapConditionSwitchStruct* conditionSwitchStru = NULL;
	UINT8 overlapProtectSwitchSum = 0u; 							/*防护道岔数目*/
	OverlapProtectSwitchStruct* overlapProtectSwitchStru = NULL;    /*防护道岔数据*/
	UINT8 cLocalCiId = 0U;
	UINT8 cSwitchBelongCiId = 0U;

	cLocalCiId = GetSystemParaLocalCiId();

	if ((0u == overlapId) || (overlapId >= OVERLAP_SUM_MAX))
	{
		retVal = CI_ERROR;
	}

	switchSum = GetOverlapSwitchSum(overlapId);
	conditionSwitchStru = GetOverlapCondSwitchStruct(overlapId);
	overlapProtectSwitchSum = GetOverlapRelatedProtSwitSum(overlapId);
	overlapProtectSwitchStru = GetOverlapRelatedProtSwitStru(overlapId);

	if (NULL == conditionSwitchStru)
	{
		retVal = CI_ERROR;
	}

	if (NULL == overlapProtectSwitchStru)
	{
		retVal = CI_ERROR;
	}

	/*保护区段条件道岔处理*/
	for (ii = 0u; ii < switchSum; ii++)
	{
		switchId = conditionSwitchStru[ii].SwitchId;
		cSwitchBelongCiId = GetSwitchBelongCiId(switchId);
		if ((0U != cSwitchBelongCiId) && (cLocalCiId == cSwitchBelongCiId))
		{
			switchExpPosition = conditionSwitchStru[ii].SwitchPosition;
			switchDancaoPosition = GetSwitchDanCaoPostition(switchId);
			switchCurPosition = GetSwitchCurPosition(switchId);
			if ((switchDancaoPosition == SWITCH_POSITION_INVALID)
				|| (switchDancaoPosition == switchExpPosition))
			{
				/*单操无效 或者 单操位置与动作位置一样*/
			}
			else
			{
				/*单操到相反位置取消进路*/
				retVal = CI_ERROR;
				break;
			}
			if ((switchExpPosition != SWITCH_POSITION_INVALID) && (switchCurPosition == switchExpPosition))
			{
				/*期望位置有效 且期望位置与当前位置一样*/
			}
			else
			{
				if (CI_ERROR == SwitchDriveProcess(switchId, switchExpPosition))
				{
					retVal = CI_ERROR;
					break;
				}
			}
		}
		else
		{
			/*非本控区道岔，不处理*/
		}
	}

	if (CI_SUCCESS == retVal)
	{
		/*保护区段关联防护道岔处理*/
		for (ii = 0u; ii < overlapProtectSwitchSum; ii++)
		{
			switchId = overlapProtectSwitchStru[ii].ProtectSwitchId;
			cSwitchBelongCiId = GetSwitchBelongCiId(switchId);
			if ((0U != cSwitchBelongCiId) && (cLocalCiId == cSwitchBelongCiId))
			{
				switchExpPosition = overlapProtectSwitchStru[ii].ProtectPosition;
				switchDancaoPosition = GetSwitchDanCaoPostition(switchId);
				switchCurPosition = GetSwitchCurPosition(switchId);
				if ((switchDancaoPosition == SWITCH_POSITION_INVALID)
					|| (switchDancaoPosition == switchExpPosition))
				{
					/*单操无效 或者 单操位置与动作位置一样*/
				}
				else
				{
					/*单操到相反位置取消进路*/
					retVal = CI_ERROR;
					break;
				}
				if ((switchExpPosition != SWITCH_POSITION_INVALID) && (switchCurPosition == switchExpPosition))
				{
					/*期望位置有效 且期望位置与当前位置一样*/
				}
				else
				{
					if (CI_ERROR == SwitchDriveProcess(switchId, switchExpPosition))
					{
						retVal = CI_ERROR;
						break;
					}
				}
			}
			else
			{
				/*非本控区道岔，不处理*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
* 功能描述： 设置Overlap锁闭状态
* 参数说明： const UINT16 overlapId, overlap ID
*            const UINT8 lockState, 锁闭状态
*            const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void SetOverlapLockState(const UINT16 overlapId, const UINT8 lockState, const UINT16 routeId)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT16* pPhySecIdBuf = NULL;  /*物理区段结构指针*/
	UINT8 cLogicSectionSum = 0u;  /*逻辑区段总数*/
	UINT16* pLogicSectionIdBuf = NULL;  /*逻辑区段ID数组*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 jj = 0U;
	UINT8 rtVal = CI_ERROR;
	UINT8 routeDir = 0u;/*进路方向*/
	UINT8 haveDirChangeInRoute = 0u;/*进路内有方向变化点*/
	UINT8 haveDirChangeAfterRoute = 0u;/*进路和保护区段之间有方向变化点*/
	UINT8 cLogicSectionLockState = 0u;
	UINT16 wRouteLastLogicSectionId = 0u;
	UINT8 cTrainSum = 0u;
	LogicTrainResStruct* pLogicTrainResData = NULL;
	UINT16 wLockBelongRouteId = 0u;/*逻辑区段锁闭所属进路ID*/

	phySecSum = GetOverlapPhySecSum(overlapId);  /*获取overlap物理区段总数*/
	pPhySecIdBuf = GetOverlapPhySecIdBuf(overlapId);  /*获取overlap物理区段ID数组*/

	cLogicSectionSum = GetOverlapLogicSectionSum(overlapId);
	pLogicSectionIdBuf = GetOverlapLogicSectionBuf(overlapId);

	wRouteLastLogicSectionId = GetRouteInLastLogSecId(routeId);


	if ((0u == phySecSum) || (NULL == pPhySecIdBuf)
		|| (0u == cLogicSectionSum) || (NULL == pLogicSectionIdBuf)
		|| (0u == wRouteLastLogicSectionId))
	{
		rtVal = CI_ERROR;
	}
	else
	{
		rtVal = CI_SUCCESS;
		if ((PHYSICAL_SECTION_LOCK_PROTECT != lockState) &&
			(PHYSICAL_SECTION_LOCK_NO != lockState))
		{ /*区段状态无效*/

			rtVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == rtVal)
	{
		routeDir = GetRouteDirection(routeId);
		haveDirChangeInRoute = GetRouteHaveDirChangePointIn(routeId);
		haveDirChangeAfterRoute = GetRouteHaveDirChangePointAfter(routeId);
		if ((ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeInRoute) || (ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeAfterRoute))
		{
			if (CI_SYSTEM_DIRECTION_UP == routeDir)
			{
				routeDir = CI_SYSTEM_DIRECTION_DOWN;/*之前按上行锁闭的，取反*/
			}
			else if (CI_SYSTEM_DIRECTION_DOWN == routeDir)
			{
				routeDir = CI_SYSTEM_DIRECTION_UP;/*锁闭方向取反*/
			}
			else
			{
				/*不会执行到这*/
			}
		}

		/*设置Overlap区段状态*/
		for (ii = 0u; ii < phySecSum; ii++)
		{
			SetPhySecLockState(pPhySecIdBuf[ii], lockState, routeId, routeDir);
		}

		if (PHYSICAL_SECTION_LOCK_PROTECT == lockState)
		{ /*防护锁闭*/

			/*设置保护区段所属进路ID*/
			SetOverlapBelongRouteId(overlapId, routeId);

			/*设置进路锁闭保护区段Id*/
			SetRouteOverlapLockedId(routeId, overlapId);

			/*设置保护区段关联防护道岔为防护锁闭*/
			SetOverlapRelateProtSwLockSta(overlapId, SWITCH_LOCK_PROTECT_SET);
#if 0
			/*清除Overlap锁闭时间*/
			SetOverlapLockStartCycNum(routeId, 0);
#endif

			/*清除保护区段相关道岔期望驱动位置*/
			ClearOverlapSwitchDrivePos(overlapId);

			/*清除保护区段关联道岔单操位置*/
			ClearOverlapSwitchDanCaoPos(overlapId);

			/*保护区段锁闭成功，清除人工锁闭保护区段命令*/
			SetOverlaplaborLockCmdFlag(overlapId, LOCK_OVERLAP_CMD_NO);

			SetOverlapFromSetRouteCmdFlag(overlapId, OVERLAP_ROUTE_FLAG_NO);/*清除保护区段建立命令由进路命令连带下发标志*/

			/* 设置逻辑区段防护锁闭 */
			cLogicSectionLockState = LOG_SECTION_LOCK_PROTECT;
		}
		else if (PHYSICAL_SECTION_LOCK_NO == lockState)
		{ /*未锁闭*/
			/*设置防护区段锁闭进路ID为0*/
			SetOverlapBelongRouteId(overlapId, 0u);

			/*清除进路锁闭保护区段Id*/
			SetRouteOverlapLockedId(routeId, 0u);
			/*清除申请解锁保护区段标志*/
			SetOverlapUnlockApplyFlag(overlapId, UNLOCK_OVERLAP_APPLY_NO);
			/*取消保护区段关联防护道岔的防护锁闭*/
			SetOverlapRelateProtSwLockSta(overlapId, SWITCH_LOCK_PROTECT_CANCEL);
#if 0
			/*设置防护区段解锁起始周期为0*/
			SetOverlapUnlockStartCycNum(overlapId, 0);
#endif
			SetRouteAtsExpLkOverlapId(routeId, 0u);

			/*设置为不可以人工解锁保护区段*/
			SetOverlapCanLaborUnlockFlag(overlapId, CANNOT_LABOR_UNLOCK_OVERLAP);
			/*清人工解锁起始周期号*/
			SetlaborUnlockStartCycNum(overlapId, 0u);
			/*人工解锁保护区段命令清除*/
			SetOverlapLaborUnlockSetState(overlapId, LABOR_UNLOCK_OVERLAP_NO);
			/*清除保护区段锁闭命令*/
			CleanOverlapAtsOrlaborLockFlag(routeId, overlapId);
			/*设置锁闭起始周期0*/
			SetOverlaplockSucessStartCycNum(overlapId, 0u);

			/*设置保护区段申请解锁的列车ID为0*/
			SetOverlapUnlockApplyTrainId(overlapId, 0U);

			/*设置保护区段向车申请解锁起始周期为0*/
			SetReqIvocUnlockStartCycNum(overlapId, 0U);

			SetOverlapFromSetRouteCmdFlag(overlapId, OVERLAP_ROUTE_FLAG_NO);/*清除保护区段建立命令由进路命令连带下发标志*/

			/*设置保护区段列车不同意解锁*/
			SetOverlapIvocAllowUnlockFlag(overlapId, IVOC_ALLOW_UNLOCK_OVERLAP_NO);

			/* 设置逻辑区段未锁闭 */
			cLogicSectionLockState = LOG_SECTION_LOCK_NO;
		}
		else
		{
			/*不处理*/
		}


		if ((LOG_SECTION_LOCK_NO == cLogicSectionLockState) || (LOG_SECTION_LOCK_PROTECT == cLogicSectionLockState))
		{
			/* 设置逻辑区段防护锁闭状态 */
			for (ii = 0u; ii < cLogicSectionSum; ii++)
			{
				SetLogSecLockState(pLogicSectionIdBuf[ii], cLogicSectionLockState, routeId, routeDir);
#if 0
				wLockBelongRouteId = GetLogSecLockBelongRoute(pLogicSectionIdBuf[ii]);/*逻辑区段锁闭所属进路*/
				if ((LOGIC_SECTION_RES_SHARE_NO == chResShrFlag) && (0u != wLockBelongRouteId))
				{
					/*解锁保护区段，有锁闭时不置非公共*/
				}
				else
				{
					SetLogSecResShareFlag(pLogicSectionIdBuf[ii], chResShrFlag);
				}
#endif
			}
		}

#if 0
		if (LOG_SECTION_LOCK_PROTECT == cLogicSectionLockState)
		{
			/* 若为防护防护锁闭，需同步进路包含逻辑区段的列车资源申请信息 */
			cTrainSum = GetLogSecTrainInfoSum(wRouteLastLogicSectionId);
			pLogicTrainResData = GetLogSecTrainInfo(wRouteLastLogicSectionId);

			if ((0u != cTrainSum) && (NULL != pLogicTrainResData))
			{
				for (ii = 0u; ii < cLogicSectionSum; ii++)
				{
					for (jj = 0u; jj < cTrainSum; jj++)
					{
						/* 将所有列车申请添加到保护区段的逻辑区段中 */
						AddLogSecTrainRes(pLogicSectionIdBuf[ii], pLogicTrainResData[jj].wTrainId);
					}
				}
			}
		}
		else if (LOG_SECTION_LOCK_NO == cLogicSectionLockState)
		{
			ReleaseOverlapRes(overlapId);
		}
		else
		{
			/*无操作*/
		}
#endif
	}
}



/*
* 功能描述： 办理普通进路逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
*	         const UINT8 chSendLevel 命令发送等级
* 返回值  ： void
* BY cgh 20250828
*/
void SetCommonRouteLogicManage(const UINT16 routeId,const UINT8 chSendLevel)
{
	UINT8 localCiId = 0u;       /*本地联锁ID*/
	UINT8 belongCiId = 0u;      /*进路所属联锁ID*/
	UINT8 routeType = 0u;      /*进路类型*/
	UINT8 routeLevel = 0u;       /*进路级别*/
	UINT8 routeState = 0u;       /*进路状态*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 AirShaftType = 0u;       /*风井进路类型*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 triggerFlag = 0u;
	UINT8 checkRetVal = CI_FALSE;
	UINT16 startSignalId = 0u;
	UINT8 sendLevel = 0u; /*故障发送级别*/
	UINT8 virCIid = 0u;
	UINT8 funcSwitch = 0u;               /*功能开关*/
	UINT8 cRcWorkMode = 0u;
	UINT8 cKeepWorkFlag = CI_ERROR;
	UINT8 firstLogicOccuState = 0u;
	UINT8 chLocalCiType = 0U;/*本地联锁类型*/
	UINT8 chSignalReOpenFunc = 0U;
	UINT8  chReadyEnterRouteTrainSum = 0U;
	UINT16 wszReadyEtRouteTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT8 chFunRet = CI_ERROR;
	UINT8 chHitSoftWallSwitch = 0U;/*撞软墙开关*/
	
	chHitSoftWallSwitch = GetHitSoftWallSwitch();
	/*进路信号异常关闭，收到进路办理命令后执行信号重开开关  0xaa执行  0x55不执行*/
	chSignalReOpenFunc = GetCiFunctionSwitchConfig(FUNC_ROUTELOCK_OPEN_SIGNAL);		

	/* RC工作模式 */
	cRcWorkMode = GetLocalRcWorkMode();
	chLocalCiType = GetLocalCiType();     /*获取本地联锁类型*/

	if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
	{
		;	/* 无处理 */
	}
	else
	{
		cKeepWorkFlag = CI_SUCCESS;/*Go on*/
	}
	if (CI_SUCCESS == cKeepWorkFlag)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/
		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			cKeepWorkFlag = CI_ERROR;
		}
		else
		{
			/*Go on*/
		}
	}
	if (CI_SUCCESS == cKeepWorkFlag)
	{
		funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
		routeType = GetRouteType(routeId);      /*获取进路类型*/
		routeLevel = GetRouteLevel(routeId);
		routeState = GetRouteState(routeId);
		triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/

		
	}
	if (CI_SUCCESS == cKeepWorkFlag)
	{
		/* 获取内放第一逻辑区段占用状态 */
		firstLogicOccuState = GetLogSecCurOccupyState(GetRouteInFirstLogSecId(routeId));
		checkResult = SetRouteProc(routeId);/*检查办理条件是否满足*/
		if (CI_ERROR == checkResult)
		{
			if ((CI_TYPE_ZX == chLocalCiType) || (CI_TYPE_SCX == chLocalCiType))
			{
				if ((ROUTE_TYPE_LIECHE == routeType) && (ROUTE_REVERSE_PROPERTY_NO == GetRouteReverseProperty(routeId))
					&& (ROUTE_LEVEL_CBTC == routeLevel) && (ROUTE_STATE_NEAR_LOCK == routeState))
				{
					if (RC_WORK_MODE_CI == cRcWorkMode)
					{
						if (SECTION_OCCUPY_NO != firstLogicOccuState)
						{
							cKeepWorkFlag = CI_ERROR;
						}
					}
					else
					{
						; /* TIOC无需判断内放第一逻辑区段占用状态 */
					}
				}
				else
				{
					if ((ROUTE_TYPE_LIECHE == routeType) && ((ROUTE_STATE_FIRST_LOCKERR == routeState)
						|| (ROUTE_STATE_YUXIAN_LOCK == routeState) || (ROUTE_STATE_NEAR_LOCKERR == routeState)))
					{
						; /*by cgh 20230704 YF0083-562 进路完整锁闭（初锁异常、预先锁闭、接近锁闭异常），可在下面逻辑直接到进路初锁*/
					}
					else
					{
						cKeepWorkFlag = CI_ERROR;/*不办理*/
					}
				}
			}
			else
			{
				SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
				cKeepWorkFlag = CI_ERROR;/*车辆段办理条件不满足，则不再继续往下逻辑*/
			}
		}
		else
		{
			/*Go on*/
		}
	}

	if (CI_SUCCESS == cKeepWorkFlag)
	{
		AirShaftType = GetAirShaftRouteType(routeId);
		routeState = GetRouteState(routeId);
		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{/*若为反向进路*/
			if (ROUTE_STATE_IDLE == routeState)
			{
				/*进路空闲*/

				/*进路物理区段未征用检查*/
				if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
				{
					/*全部区段未征用*/

					/*检查所含道岔是否被征用*/
					if (CI_SUCCESS == CheckRouteContainSwitchUseSta(routeId))
					{
						SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/
					}
					else
					{
						/*设置错误码：道岔已征用*/
						SetErrorData(EFUNC_CHECK_SWITCH_USING, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_SWT_USE_STATE, SWITCH_USING_YES, ESEND_LEVEL_ATS);
					}
				}
			}
			else if (ROUTE_STATE_HALF_UNLOCK == routeState)
			{
				/*部分进路等待解锁*/
				/*进路物理区段未征用检查*/
				if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
				{
					/*全部区段未征用，设置进路物理区段征用*/
					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES);

					SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_YES);  /*-->设置进路状态转移标志有效*/
					(void)SetRouteXuanPaiStartCycNum(routeId, 0U);/*每次新的有效办理，都需要重新计算选排时间*/
				}
			}
			else
			{
				/*不处理*/
			}
		}
		else
		{
			if ((AutoSignalOrRouteValid(routeId) == CI_SUCCESS) ||
				(AUTO_TRIGGER_SET_YES == triggerFlag))
			{
				/*自动进路或自动触发进路不发送ATS*/
				sendLevel = ESEND_LEVEL_ZERO;
			}
			else
			{
				sendLevel = ESEND_LEVEL_ATS;
			}

			if ((routeLevel == ROUTE_LEVEL_CBTC) && (ROUTE_TYPE_AIRSHAFT != AirShaftType))
			{/* CBTC模式但不为风井进路*//*风井进路不允许追踪办进路*/
				if (ROUTE_STATE_IDLE == routeState)
				{
					/*进路物理区段未征用检查*/
					if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
					{
						/*全部区段未征用*/
						/*检查所含道岔是否被征用*/
						if (CI_SUCCESS == CheckRouteContainSwitchUseSta(routeId))
						{
							SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/
						}
						else
						{
							/*设置错误码：道岔已征用*/
							SetErrorData(EFUNC_CHECK_SWITCH_USING, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_SWT_USE_STATE, SWITCH_USING_YES, ESEND_LEVEL_ATS);
						}
					}
				}
				else if ((ROUTE_STATE_AUTO_UNLOCK == routeState) || (ROUTE_STATE_AUTO_UNLOCKERR == routeState) || (ROUTE_STATE_HALF_UNLOCK == routeState))
				{
					/*进路自动解锁正常、自动解锁异常（ARB且故障锁闭）、部分进路等待解锁*/

					/*进路物理区段未征用检查*/
					if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
					{
						/*全部区段未征用*/
						/*设置进路物理区段征用*/
						SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES);

						SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_YES);  /*-->设置进路状态转移标志有效*/
						(void)SetRouteXuanPaiStartCycNum(routeId, 0u);/*每次新的有效办理，都需要重新计算选排时间*/
					}
				}
				else if (ROUTE_STATE_NEAR_LOCK == routeState)
				{
					if (FUNC_HITSOFTWALL_OFF == chHitSoftWallSwitch)
					{
						chFunRet = GetRouteInOutFstLgcTrainInfo(routeId, &chReadyEnterRouteTrainSum, wszReadyEtRouteTrainId);
						if (CI_SUCCESS == chFunRet)
						{
							if (0U == chReadyEnterRouteTrainSum)
							{
								/*列车完全驶入进路*/
								/*接近锁闭正常，再次办理进路将进路状态设置为进路初锁，ATS申请路径时直接添加资源，同周期条件满足开放信号*/
								/*删除对应场景下进路办理错误反馈*/
								DeleteSetRouteErrorData();

								SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/
							}
							else
							{
								/*列车未完全驶入进路，不改变进路状态,根据命令类型决定是否报警*/
								if (ESEND_LEVEL_ATS == chSendLevel)
								{
									/*要报警*/
								}
								else
								{
									/*删除对应场景下进路办理错误反馈*/
									DeleteSetRouteErrorData();
								}
							}
						}
						else
						{
							; /*不处理*/
						}
					}
					else
					{
						/*接近锁闭正常，再次办理进路将进路状态设置为进路初锁，ATS申请路径时直接添加资源，同周期条件满足开放信号*/
						/*删除对应场景下进路办理错误反馈*/
						DeleteSetRouteErrorData();

						SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/
					}
				}			
				else
				{
					if (FUNC_SWITCH_ON == chSignalReOpenFunc)
					{
						if ((ROUTE_STATE_NEAR_LOCKERR == routeState) ||
							(ROUTE_STATE_YUXIAN_LOCK == routeState) || (ROUTE_STATE_FIRST_LOCKERR == routeState))
						{
							/*进路状态为锁闭：预先锁闭、初锁异常、接近锁闭正常、接近锁闭异常则尝试信号重开*/
							startSignalId = GetRouteStartSignalId(routeId);
							checkRetVal = CheckTheDevIsNotOfDiffLine(CI_DEVICE_TYPE_SIGNAL, startSignalId);

							if (CI_TRUE == checkRetVal)
							{
								/*删除对应场景下进路办理错误反馈*/
								DeleteSetRouteErrorData();
								/*信号重开*/
								RepeatOpenSignalLogicManage(startSignalId);
							}
						}
						else
						{
							/*不做处理*/
						}
					}
					else
					{
						/*开关关闭，无处理*/
					}
				}

			}
			else
			{
				if (ROUTE_STATE_IDLE == routeState)
				{
					/*进路空闲*/
					if (ROUTE_TYPE_AIRSHAFT == AirShaftType)
					{/*风井进路内区段全部空闲且未锁闭*/
						if (FUNC_SWITCH_ON == funcSwitch)
						{
							/*modify 20221008 适配进路驱动道岔提前扳动功能*/
							/*按照逻辑区段检查区段空闲和锁闭状态*/
							checkResult = RouteAllLogSecOccuClearCheck(routeId, &devId, &devState);
							if (CI_SUCCESS == checkResult)
							{
								checkResult = BlockRouteLogSecLockValidCheck(routeId, &devId, &devState);
								if (CI_SUCCESS == checkResult)
								{
									checkResult = RouteSwOtherLogLockValidCheck(routeId, &devId, &devState);
									if (CI_ERROR == checkResult)
									{/*风井进路办理不成功添加错误反馈*/
										SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
									}
									else
									{

									}
								}
								else
								{
									/*风井进路办理不成功添加错误反馈*/
									SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
								}

							}
							else
							{/*风井进路办理不成功添加错误反馈*/  /*自动信号机或自动触发进路不反馈*/

								SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
							}
						}
						else
						{
							/*按照物理区段检查区段空闲和锁闭状态*/
							checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);
							if (CI_SUCCESS == checkResult)
							{
								checkResult = BlockRouteSecLockValidCheck(routeId, &devId, &devState);
								if (CI_ERROR == checkResult)
								{/*风井进路办理不成功添加错误反馈*/

									SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
								}

							}
							else
							{/*风井进路办理不成功添加错误反馈*/  /*自动信号机或自动触发进路不反馈*/

								SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
							}
						}
					}


					if (CI_SUCCESS == checkResult)
					{
						/*进路物理区段未征用检查*/
						if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
						{
							/*全部区段未征用*/
							/*检查所含道岔是否被征用*/
							if (CI_SUCCESS == CheckRouteContainSwitchUseSta(routeId))
							{
								SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/
							}
							else
							{
								/*设置错误码：道岔已征用*/
								SetErrorData(EFUNC_CHECK_SWITCH_USING, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_SWT_USE_STATE, SWITCH_USING_YES, ESEND_LEVEL_ATS);
							}

						}
					}

				}
				else if (ROUTE_STATE_FIRST_XUANPAI != routeState)
				{ /*进路预选此时不作任何操作，等待区段征用*//*自动信号和自动触发进路不反馈错误信息*/
					SetErrorData(EFUNC_SET_AIRSHAFT_ERROR, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, sendLevel);
				}
				else
				{
					/*不做处理*/
				}

			}
		}
	}
	else
	{
		; /* 无处理 */
	}
}


/*
* 功能描述： 办理引导进路逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
* edit cgh 20250224
*/
void SetLeadRouteLogicManage(const UINT16 signalId)
{
	UINT8 routeState = 0u;
	UINT8 routeLevel = 0u;
	UINT16 routeId = 0u;
	UINT8 setleadRouteCheak = 0U;
	UINT8 signalBrightFlag = 0u;
	UINT8 cRcWorkMode = 0U;
	UINT8 chUseStateCheck = 0U;/*征用状态检查*/


	/* 获取子系统工作模式 */
	cRcWorkMode = GetLocalRcWorkMode();

	signalBrightFlag = GetSignalMaintainState(signalId);		/*单维修点灯*/
	routeId = GetStartSignalRouteId(signalId);
	routeLevel = GetRouteLevel(routeId);		/*获取进路级别*/

	if ((0u != routeId) && (routeId < ROUTE_SUM_MAX))
	{
		if ((ROUTE_LEVEL_BLOC == routeLevel)
			|| ((RC_WORK_MODE_CI == cRcWorkMode) && (MAINTAIN_STATE_YES == signalBrightFlag)))
		{
			routeState = GetRouteState(routeId);           /*获取进路状态*/

#if 0
			if (RouteSecFlockVainCheck(routeId) == CI_ERROR)
			{
				/*有区段封锁*/
				return;
			}
#endif

			/*  进路状态为【进路空闲】*/
			if (ROUTE_STATE_IDLE == routeState)
			{
				/*进路空闲*/
				setleadRouteCheak = SetLeadRouteP(routeId);
				if (CI_SUCCESS == setleadRouteCheak)
				{/*检查通过*/
						/*检查所含道岔是否被征用*/
					chUseStateCheck = CheckRouteContainSwitchUseSta(routeId);
					if (CI_SUCCESS == chUseStateCheck)
					{
						SetRouteStateManage(routeId, ROUTE_STATE_LEAD_FIRST_XUANPAI);  /*-->设置引导初选*/
					}
					else
					{
						/*设置错误码：道岔已征用*/
						SetErrorData(EFUNC_CHECK_SWITCH_USING, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_SWT_USE_STATE, SWITCH_USING_YES, ESEND_LEVEL_ATS);
					}
				}
				else
				{
					; /*区段有征用,进路办理失败，错误码在函数里已记录*/
				}

			}
			else
			{
				SetErrorData(EFUNC_LEAD_ROUTE_MANAGE_ERROR, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, ESEND_LEVEL_ATS);
			}
		}
		else if (ROUTE_LEVEL_CBTC == routeLevel)
		{
			SetErrorData(EFUNC_LEAD_ROUTE_MANAGE_ERROR, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_LEVEL, routeLevel, ESEND_LEVEL_ATS);
		}
		else
		{
			/*预留错误进路监督级别*/
		}

	}
}


/*
* 功能描述： 进路总取消逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteZongQuXiaoLogicManage(const UINT16 routeId)
{
	UINT8 localCiId = 0u;        /*本地联锁ID*/
	UINT8 belongCiId = 0u;       /*进路所属联锁ID*/
	UINT8 autoSigRouteState = 0u;  /*自动信号进路状态*/
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT8 ii = 0u;
	UINT8 virCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	autoSigRouteState = GetRouteAutoSigSetState(routeId);/*获取进路自动信号状态*/

	if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
	{ /*自动信号*/
		return;
	}

	/*设置进路总取消标志*/
	SetRouteZongQuXiaoFlag(routeId, ROUTE_ZONGQUXIAO_SET_YES);

	/*设置进路自动进路无效*/
	SetAutoRouteSetFlag(GetRouteAutoRouteId(routeId), AUTO_ROUTE_SET_NO);
	SetAutoReturnSetFlag(GetRouteAutoReturnId(routeId), AUTO_RETURN_SET_NO);
	SetAllAutoReturnSetFlag(GetRouteAllAutoReturnId(routeId), ALL_AUTO_RETURN_SET_NO);
	if (ROUTE_TYPE_AUTO_TRIGGER == GetAutoTriggerType(routeId))
	{/*虚拟联锁兼容*/
		SetRouteAutoTriggerFlag(routeId, AUTO_TRIGGER_SET_NO);
	}
	/* 优化代码：判断如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到总取消命令时进行清除重开标志 */
	if (GetRouteRecoverOpenFlag(routeId) == ROUTE_RECOVER_STA_WAIT)
	{
		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);  /*清除进路信号重开标志*/

		SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);

		SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);/*防止后面逻辑重开*/
	}

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/
	for (ii = 0u; ii < overlapSum; ii++)
	{
		SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0u);
	}
}


/*
* 功能描述： 进路总人解逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteZongRenJieLogicManage(const UINT16 routeId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 autoSigRouteState = 0u;  /*自动信号进路状态*/
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT8 ii = 0u;
	UINT8 virCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	autoSigRouteState = GetRouteAutoSigSetState(routeId); /*获取进路自动信号状态*/

	if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)
	{ /*自动信号*/

		return;
	}

	/*设置进路总人解标志*/
	(void)SetRouteZongRenJieFlag(routeId, ROUTE_ZONGRENJIE_SET_YES);

	/*设置进路自动进路无效*/
	SetAutoRouteSetFlag(GetRouteAutoRouteId(routeId), AUTO_ROUTE_SET_NO);
	SetAutoReturnSetFlag(GetRouteAutoReturnId(routeId), AUTO_RETURN_SET_NO);
	SetAllAutoReturnSetFlag(GetRouteAllAutoReturnId(routeId), ALL_AUTO_RETURN_SET_NO);
	if (ROUTE_TYPE_AUTO_TRIGGER == GetAutoTriggerType(routeId))
	{/*虚拟联锁兼容*/
		SetRouteAutoTriggerFlag(routeId, AUTO_TRIGGER_SET_NO);
	}
	/* 优化代码：判断如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到总人解时进行清除重开标志 */
	if (GetRouteRecoverOpenFlag(routeId) == ROUTE_RECOVER_STA_WAIT)
	{
		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);  /*清除进路信号重开标志*/

		SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);

		SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);/*防止后面逻辑重开*/
	}

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/
	for (ii = 0u; ii < overlapSum; ii++)
	{
		SetOverlapXuanPaiStartCycNum(overlapIdBuf[ii], 0u);
	}
}


/*
* 功能描述： 设置道岔单操逻辑管理
* 参数说明： UINT16 switchId, 道岔ID
*            const UINT8 switchSetPos, 道岔设置位置
* 返回值  ： void
*/
void SetSwitchPositionLogicManage(const UINT16 switchId, const UINT8 switchSetPos)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 check_Result = CI_SUCCESS;
	UINT8 lineType = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取轨道交通线路类型*/
	UINT8 chTemp = CI_ERROR;

	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	if (CI_TRADITION_RAILWAY == lineType)
	{/*城轨线路*/
		if ((switchSetPos != SWITCH_POSITION_DINGWEI) && (switchSetPos != SWITCH_POSITION_FANWEI))
		{/*单操位置无效*/
			check_Result = CI_ERROR;
		}
		else
		{/*单操位置有效*/
			check_Result = CI_SUCCESS;
		}
	} /* zt 删除单轨相关代码 2022-02-15 */
	else
	{/*不存在的线路类型*/
		check_Result = CI_ERROR;
	}

	if (CI_SUCCESS == check_Result)
	{/*单操位置有效*/
		/*道岔单操逻辑处理*/
		if (CI_SUCCESS == SetSwitchPositionLogicProcess(switchId, switchSetPos, 0U, &chTemp))
		{ /*成功*/
			(void)SetSwitchDanCaoPosition(switchId, switchSetPos); /*设置单操位置标志*/
		}
		else
		{ /*失败*/
			/*添加记录错误码代码*/
		}
	}
}


/*
* 功能描述： 设置道岔单锁逻辑管理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： void
*/
void SetSwitchDLockLogicManage(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/


	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	/*设置道岔单锁逻辑处理*/
	if (CI_SUCCESS == SetSwitchDLockLogicProcess(switchId))
	{ /*成功*/

		if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
		{/*双动道岔*/

			SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO, 0u, GetDSwitchOtherId(switchId), SWITCH_LOCK_DANSUO_SET);  /*设置另一道岔单锁*/
		}

		SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO, 0u, switchId, SWITCH_LOCK_DANSUO_SET);  /*设置本道岔单锁*/
	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}


/*
* 功能描述： 取消道岔单锁逻辑管理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ：
*/
void CancelSwitchDLockLogicManage(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/


	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{

		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}


	/*取消道岔单锁逻辑处理*/
	if (CI_SUCCESS == CancelSwitchDLockLogicProcess(switchId))
	{ /*成功*/

		if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
		{/*双动道岔*/

			SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO, 0u, GetDSwitchOtherId(switchId), SWITCH_LOCK_DANSUO_CANCEL);  /*取消另一道岔单锁*/
		}

		SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO, 0u, switchId, SWITCH_LOCK_DANSUO_CANCEL);  /*取消道岔单锁*/
	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}


/*
* 功能描述： 设置道岔封锁逻辑管理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： void
*/
void SetSwitchFLockLogicManage(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 checkSum = 0u;
	RouteSwitchStruct* routeSwitchStr = NULL;
	UINT16 jj = 0u;
	UINT16 ii = 0u;
	UINT16 kk = 0u;
	UINT16 routeSum = 0u;              /*进路数目 (配置字段)*/
	UINT16 routeId = 0u;
	UINT16* overlapIdBuf = NULL;  /*进路包含的保护区段ID*/
	UINT8 overlapSum = 0u; /*进路包含的保护区段数目*/
	OverlapConditionSwitchStruct* overlapCondSwitchStr = NULL;
	UINT8 overlapSwitchSum = 0u;	/*保护区段条件防护道岔数量*/
	RouteProtectSwitchStruct* pRouteProSwitchDataBuf = NULL;/*进路关联防护道岔数据结构体指针*/
	UINT8 routeProSwitchSum = 0u;	/*进路关联防护道岔数量*/
	OverlapProtectSwitchStruct* pOverlapProSwitchDataBuf = NULL;/*保护区段关联防护道岔数据结构体指针*/
	UINT8 overlapProSwitchSum = 0u;	/*保护区段关联防护道岔数量*/

	UINT16 doubleSwitchOtherId = 0u;/*双动道岔另一道岔Id*/
	UINT8 flagCancel = 0u;/*取消标志*/
	UINT8 flagBreak = 0u;/*中断标志*/
	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}



	/*设置道岔封锁逻辑处理*/
	if (CI_SUCCESS == SetSwitchFLockLogicProcess(switchId))
	{ /*成功*/

		if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
		{/*双动道岔*/

			SetSwitchFLockState(GetDSwitchOtherId(switchId), SWITCH_LOCK_FENGSUO_YES);  /*设置另一道岔封锁*/
		}

		SetSwitchFLockState(switchId, SWITCH_LOCK_FENGSUO_YES);  /*设置本道岔封锁*/

		routeSum = GetRouteCurSum();/*获取进路条数*/
		for (ii = 0u; ii < routeSum; ii++)
		{  /*道岔有可能被两条进路锁闭防护锁闭，所以不能有break*/
			routeId = GetRouteId(ii);                           /*获取进路ID*/
			routeSwitchStr = GetRouteSwitchData(routeId);
			checkSum = GetRouteSwitchSum(routeId);
			overlapSum = GetRouteOverlapSum(routeId);
			overlapIdBuf = GetRouteOverlapIdBuf(routeId);
			doubleSwitchOtherId = GetDSwitchOtherId(switchId);
			for (jj = 0u; jj < checkSum; jj++)
			{
				if ((switchId == routeSwitchStr[jj].SwitchId) || (GetDSwitchOtherId(switchId) == routeSwitchStr[jj].SwitchId))
				{  /*当进路包含封锁的道岔时，则取消该进路的自动属性*/
					if (CI_ERROR == CancleAutoFlag(routeId))
					{
						SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, SWITCH_LOCK_FENGSUO_YES, ESEND_LEVEL_ATS);
					}
					break;
				}

			}

			pRouteProSwitchDataBuf = GetRouteRelatedProtSwitchData(routeId);	/*进路防护道岔结构体指针*/
			routeProSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);	/*进路防护道岔数量*/
			flagCancel = 0u;
			if (NULL != pRouteProSwitchDataBuf)
			{/*当进路防护道岔封锁时，取消该进路的自动属性*/
				for (jj = 0u; jj < routeProSwitchSum; jj++)
				{
					if ((switchId == pRouteProSwitchDataBuf[jj].ProtectSwitchId) ||
						(doubleSwitchOtherId == pRouteProSwitchDataBuf[jj].ProtectSwitchId))
					{
						flagCancel = CancleAutoFlag(routeId);
						if (CI_ERROR == flagCancel)
						{
							SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, SWITCH_LOCK_FENGSUO_YES, ESEND_LEVEL_ATS);
							break;
						}
					}
				}
			}

			flagBreak = 0u;
			for (jj = 0u; jj < overlapSum; jj++)
			{  /*当进路保护区段的条件道岔封锁时，取消自动属性*/
				overlapCondSwitchStr = GetOverlapCondSwitchStruct(overlapIdBuf[jj]);
				overlapSwitchSum = GetOverlapSwitchSum(overlapIdBuf[jj]);

				if (NULL != overlapCondSwitchStr)
				{
					for (kk = 0u; kk < overlapSwitchSum; kk++)
					{
						if ((switchId == overlapCondSwitchStr[kk].SwitchId) ||
							(doubleSwitchOtherId == overlapCondSwitchStr[kk].SwitchId))
						{/*当进路保护区段内道岔包含封锁的道岔时，则取消该进路的自动属性*/
							flagCancel = CancleAutoFlag(routeId);
							if (CI_ERROR == flagCancel)
							{
								SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, SWITCH_LOCK_FENGSUO_YES, ESEND_LEVEL_ATS);
								flagBreak = 1u;
								break;
							}

						}
					}
				}


				pOverlapProSwitchDataBuf = GetOverlapRelatedProtSwitStru(overlapIdBuf[jj]);
				overlapProSwitchSum = GetOverlapRelatedProtSwitSum(overlapIdBuf[jj]);
				if (NULL != pOverlapProSwitchDataBuf)
				{
					for (kk = 0u; kk < overlapProSwitchSum; kk++)
					{
						if ((switchId == pOverlapProSwitchDataBuf[kk].ProtectSwitchId) ||
							(doubleSwitchOtherId == pOverlapProSwitchDataBuf[kk].ProtectSwitchId))
						{/*当进路保护区段防护道岔被封锁时，则取消该进路的自动属性*/
							flagCancel = CancleAutoFlag(routeId);
							if (CI_ERROR == flagCancel)
							{
								SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, SWITCH_LOCK_FENGSUO_YES, ESEND_LEVEL_ATS);
								flagBreak = 1u;
								break;
							}

						}

					}

				}

				if (1u == flagBreak)
				{
					break;
				}
			}
		}

	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}


/*
* 功能描述： 取消道岔封锁逻辑管理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： void
*/
void CancelSwitchFLockLogicManage(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/


	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}


	/*取消道岔封锁逻辑处理*/
	if (CI_SUCCESS == CancelSwitchFLockLogicProcess(switchId))
	{ /*成功*/

		if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
		{/*双动道岔*/

			SetSwitchFLockState(GetDSwitchOtherId(switchId), SWITCH_LOCK_FENGSUO_NO);  /*取消另一道岔封锁*/
		}

		SetSwitchFLockState(switchId, SWITCH_LOCK_FENGSUO_NO);  /*取消道岔封锁*/
	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}


/*
* 功能描述： 重开信号逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
*/
void RepeatOpenSignalLogicManage(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT16 ii = 0u;               /*循环索引*/
	UINT8 cSGBJDelayOpenFlag = 0U;  /*声光报警延时开放标志*/
	UINT8 cRelZuHeSGBJDelayOpenFlag = 0U;  /*关联组合进路声光报警延时开放标志*/
	UINT32 dwCurDelayOpenStartCycNum = 0U;  /*进路声光报警延时开放起始周期*/
	UINT32 dwCurCycNum = 0U;

	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	routeCurSum = GetRouteCurSum();	  /*获取进路总数*/

	/*处理进路*/
	for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = 0u;	      /*进路ID*/
		belongCiId = 0u;       /*进路所属联锁ID*/
		routeState = 0u;       /*进路状态*/


		routeId = GetRouteId(ii);   /*获取进路ID*/

		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
			continue;
		}

		belongCiId = GetRouteBelongCiId(routeId);   /*获取进路所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			continue;
		}

		if (signalId != GetRouteStartSignalId(routeId))
		{ /*不为进路始端信号机ID*/

			continue;
		}


		routeState = GetRouteState(routeId);  /*获取进路状态*/

		if ((routeState != ROUTE_STATE_FIRST_LOCKERR) &&
			(routeState != ROUTE_STATE_YUXIAN_LOCK) &&
			(routeState != ROUTE_STATE_NEAR_LOCKERR) &&
			(routeState != ROUTE_STATE_NEAR_LOCK))
		{ /*进路状态不为: 初锁异常&&预先锁闭&&接近锁闭异常&&接近锁闭正常。修改日期：20170209。原因：支持在接近锁闭正常时响应信号重开命令。*/
			if (ROUTE_STATE_DELAY_UNLOCK == routeState)
			{/*总人解延时解锁期间，信号重开无效，记录故障并给现地和ATS发送反馈*/
				SetErrorData(EFUNC_CANCLE_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR, ESEND_LEVEL_ATS);
			}
			continue;

		}

		if ((ROUTE_ZONGQUXIAO_SET_YES == GetRouteZongQuXiaoFlag(routeId)) ||
			(ROUTE_ZONGRENJIE_SET_YES == GetRouteZongRenJieFlag(routeId)))
		{ /*总取消或总人解*/
			SetErrorData(EFUNC_CANCLE_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR, ESEND_LEVEL_ATS);/*总取消或总人解时，信号重开无效，记录故障并给现地和ATS发送反馈*/
			return;
		}

		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_YES);  /*设置进路信号重开标志*/

		/*清除ATS取消资源向Ivoc申请的标志*/
		SetRouteZhefanJiesuoTrainId(routeId, 0U);
		SetRouteZhefanJiesuoCyc(routeId, 0U);


		dwCurCycNum = Get2oo2CurCycleNum();
		cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(routeId);
		cRelZuHeSGBJDelayOpenFlag = GetRelZuHeRouteSGBJDelayFlag(routeId);
		dwCurDelayOpenStartCycNum = GetRouteDelayOpenStartCyc(routeId);

		if ((0U == dwCurDelayOpenStartCycNum) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cSGBJDelayOpenFlag) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cRelZuHeSGBJDelayOpenFlag))
		{
			SetRouteDelayOpenStartCyc(routeId, dwCurCycNum);
			SetRouteOpenSigStartCycNum(routeId, 0U);  /*若存在声光报警延时，先清除进路信号开放时间，避免因声光报警延时导致进路信号开放时间超限*/
		}
		else if((ROUTE_SGBJ_DELAY_OPEN_VALID != cSGBJDelayOpenFlag) || (ROUTE_SGBJ_DELAY_OPEN_VALID != cRelZuHeSGBJDelayOpenFlag))
		{
			SetRouteOpenSigStartCycNum(routeId, dwCurCycNum);  /*进路无需声光报警延时开放，设置信号开放起始时间*/
		}
		else
		{
			/*已设置延时起始周期，不处理*/
		}
#if 0
		/* 设置保护区段锁闭时间 */
		SetOverlapLockStartCycNum(routeId,Get2oo2CurCycleNum());
#endif

		return;
	}
}

/*
* 功能描述： 开放引导信号逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
* TIOC V2.0首版首轮优化，信号机亮灭=>判断进路监督级别为点式
*/
void OpenLeadSignalLogicManage(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT8 chKeepWork = CI_ERROR;
	UINT8 chRouteLevel = 0U;
	UINT16 wRouteStartSignalId = 0U;
	UINT8 chSignalOpenCloseState = 0U;
	UINT8 chTimeState = CI_TIME_OUT;
	UINT8 chFunRet = CI_ERROR;
	UINT8 signalBrightFlag = 0u;	/*单维修点灯*/
	UINT8 cRcWorkMode = 0U;       /*子系统工作模式 */
	UINT8 chSignalCurColor = 0U;/*信号机开放颜色*/
	UINT32 dwFaultOpenStartCyc = 0U;/*故障开放起始周期*/
	UINT32 dwLeadFaultOpenCyc = 0U; /*引导进路故障开放持续周期数*/
	UINT16 wInFirstPhySecId = 0U; /*内方第一物理区段ID*/
	UINT32 dwCurCycleNum = 0U;/*当前周期号*/

	/* 获取子系统工作模式 */
	cRcWorkMode = GetLocalRcWorkMode();
	dwCurCycleNum = Get2oo2CurCycleNum();

	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
		chKeepWork = CI_ERROR;
	}
	else
	{
		chKeepWork = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		wInFirstPhySecId = GetSignalInFirstLockedPhySecId(signalId);
		routeId = GetPhySecRLockBelongRouteId(wInFirstPhySecId);
		signalBrightFlag = GetSignalMaintainState(signalId);
		chRouteLevel = GetRouteLevel(routeId);
		/* 点式或者CBTC但CI模式下全站亮灯标志有效*/
		if ((ROUTE_LEVEL_BLOC == chRouteLevel) || ((ROUTE_LEVEL_CBTC == chRouteLevel) && (RC_WORK_MODE_CI == cRcWorkMode) && (MAINTAIN_STATE_YES == signalBrightFlag)))
		{
			chKeepWork = CI_SUCCESS;
		}
		else
		{
			SetErrorData(EFUNC_CLD_OPEN_LEAD_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_LEVEL, chRouteLevel, ESEND_LEVEL_ATS);
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		wRouteStartSignalId = GetRouteStartSignalId(routeId);
		if (wRouteStartSignalId != signalId)
		{
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		belongCiId = GetRouteBelongCiId(routeId);
		if (belongCiId != localCiId)
		{
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		routeState = GetRouteState(routeId);
		chSignalCurColor = GetSignalCurColor(signalId);
		chSignalOpenCloseState = GetSignalOpenCloseState(chSignalCurColor);
		dwFaultOpenStartCyc = GetRouteLeadFaultOpenStartCyc(routeId);
		dwLeadFaultOpenCyc = GetSystemParaLeadFaultOpenCyc();
		chTimeState = SystemOverTimeCheck(dwFaultOpenStartCyc,dwLeadFaultOpenCyc);

		if ((ROUTE_STATE_LEAD_LOCKERR == routeState) &&
			(SIGNAL_CLOSE == chSignalOpenCloseState))
		{
			/*引导信号重开*/

			SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCK);  /*设置进路引导锁闭*/

		}
		else if ((ROUTE_STATE_LEAD_OPEN == routeState) &&
			(SIGNAL_OPEN == chSignalOpenCloseState) &&
			(CI_TIME_IN == chTimeState))
		{
			/*引导信号按钮保持*/

			/*重置开灯时间*/
			SetRouteLeadFaultOpenStartCyc(routeId, dwCurCycleNum);
		}
		else if ((ROUTE_STATE_FIRST_LOCKERR == routeState) ||
			(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
			(ROUTE_STATE_NEAR_LOCK == routeState) ||
			(ROUTE_STATE_NEAR_LOCKERR == routeState))
		{
			/*锁闭转引导进路-需要重新设置信号开放起始周期，避免检查超时*/
			SetRouteOpenSigStartCycNum(routeId, dwCurCycleNum); 
			   /*【进路初锁异常】或
			   【预先锁闭】或
			   【接近锁闭正常】或
			   【接近锁闭异常】*/
			SetRouteToLeadFlag(routeId, ROUTE_TO_LEAD_FLAG_YES);  /*设置引导进路转换标志有效，进行其它联锁条件检查时，将按照引导进路进行*/
			chFunRet = OpenLeadRouteLogicProcess(routeId);
			if (CI_SUCCESS == chFunRet)
			{
				/*锁闭成功*/
				SetRouteStateManage(routeId, ROUTE_STATE_LEAD_LOCK);  /*设置进路引导锁闭*/

			}
			else
			{
				/*锁闭失败*/

				/*保持原进路状态*/
				
				/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
				SetDetCutBtnState(signalId, SIGNAL_DETAIN_CUT_VALID_NO);
			}

			SetRouteToLeadFlag(routeId, ROUTE_TO_LEAD_FLAG_NO);  /*引导进路开放条件检查完成后，立即清除引导进路转换标志为无效*/
		}
		else
		{
			if (ROUTE_STATE_DELAY_UNLOCK == routeState)
			{/*引导进路总人解延时解锁期间，引导信号重开无效，记录故障并给现地和ATS发送反馈*/
				SetErrorData(EFUNC_CANCLE_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR, ESEND_LEVEL_ATS);
			}
			else
			{
				SetErrorData(EFUNC_OPEN_LEAD_SIGNAL, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, ESEND_LEVEL_ATS);
			}

		}
	}
}


/*
* 功能描述： 设置信号机封锁逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
*/
void SetSignalFLockLogicManage(const UINT16 signalId)
{
	UINT16 ii = 0u;
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT16 routeSum = 0u;              /*进路数目 (配置字段)*/
	UINT16 routeId = 0u;
	UINT8 checkSum = 0u;
	UINT16* dataIdBuf = NULL;
	UINT16 jj = 0u;

	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
		return;
	}
	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

	if ((belongCiId != localCiId) || (localCiId == 0u))
	{

		return;
	}
	/*设置信号机封锁逻辑处理*/
	if (CI_SUCCESS == SetSignalFLockLogicProcess(signalId))
	{ /*成功*/

		SetSignalFLockState(signalId, SIGNAL_FENGSUO_YES);  /*设置信号机封锁*/
		routeSum = GetRouteCurSum();/*获取进路条数*/
		for (ii = 0u; ii < routeSum; ii++)
		{
			routeId = GetRouteId(ii);                           /*获取进路ID*/
			dataIdBuf = GetRouteFengSuoSignalIdBuf(routeId);
			checkSum = GetRouteFengSuoSignalSum(routeId);
			for (jj = 0u; jj < checkSum; jj++)
			{
				if (signalId == dataIdBuf[jj])
				{  /*当进路包含封锁的信号机，则取消该进路的自动属性*/
					if (CI_ERROR == CancleAutoFlag(routeId))
					{
						SetErrorData(EFUNC_SET_SIGNAL_FLOCK, CI_DEVICE_TYPE_SIGNAL, signalId, ETYPE_SIG_FLOCK_STATE, SIGNAL_FENGSUO_YES, ESEND_LEVEL_ATS);

					}
					break;
				}

			}
		}

	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}


/*
* 功能描述： 取消信号机封锁逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
*/
void CancelSignalFLockLogicManage(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/


	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
		return;
	}

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}


	/*取消信号机封锁逻辑处理*/
	if (CI_SUCCESS == CancelSignalFLockLogicProcess(signalId))
	{ /*成功*/

		SetSignalFLockState(signalId, SIGNAL_FENGSUO_NO);  /*取消信号机封锁*/
	}
	else
	{ /*失败*/

		/*???添加记录错误码代码*/
	}
}

/*
* 功能描述： 上电解锁逻辑管理
* 参数说明： void
* 返回值  ： void
*/
void SetStartupUnLockLogicManage(void)
{
	UINT16 phySecId = 0u;		/*物理区段ID*/
	UINT16 phySecSum = 0u;		/*物理区段总数*/
	UINT16 logSecSum = 0u;      /*逻辑区段数*/
	UINT16 logSecId = 0u;
	UINT8 logState = 0u;
	UINT16 ii = 0u;				/*游标*/
	UINT8 retFlag = CI_ERROR;
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 logBelongCiId = 0u;
	UINT8 startLockFlag = 0u;
	UINT8 startFengsuoFlag = 0u;
	UINT8 ciType = 0u;

	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	ciType = GetCiType(localCiId);
	startLockFlag = GetStartLockFlag();
	startFengsuoFlag = GetStartFLockFlag();

	if (CI_TYPE_CLD == ciType)
	{
		if (CI_START_LOCK_YES == startLockFlag)
		{
			retFlag = CI_SUCCESS;
		}
	}
	else
	{
		if ((CI_START_LOCK_YES == startLockFlag) && (CI_START_FLOCK_NO == startFengsuoFlag))
		{
			retFlag = CI_SUCCESS;
		}
	}

	if (CI_SUCCESS == retFlag)
	{
		phySecSum = GetPhySecCurSum();              /*获取物理区段总数*/
		logSecSum = GetLogicSecCurSum();           /*获取逻辑区段总数*/

		if ((0u != phySecSum) && (0u != logSecSum))
		{

			for (ii = 0u; ii < phySecSum; ii++)
			{/*遍历物理区段*/
				belongCiId = 0u;          /*进路所属联锁ID*/

				phySecId = GetPhySecId(ii);/*获取物理区段ID*/
				belongCiId = GetPhySecBelongCiId(phySecId);

				if ((phySecId > 0u) && (phySecId < PHYSICAL_SECTION_SUM_MAX))
				{
					if (belongCiId == localCiId)
					{


						if (PHYSICAL_SECTION_LOCK_START == GetPhySecLockState(phySecId))
						{/*物理区段上电锁闭*/

							SetPhySecLockState(phySecId, PHYSICAL_SECTION_LOCK_NO, 0, 0);/*设置物理区段锁闭状态为未锁闭*/
						}
						else
						{
							/* 上电解锁失败 */
							SetStartLockFlag(CI_START_LOCK_ERROR);

							/*记录和发送故障码*/
							SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
								CI_DEVICE_TYPE_PHYSEC,
								phySecId,
								ETYPE_SYSTEM_STARTLOCKE_ERROR,
								GetPhySecLockState(phySecId), ESEND_LEVEL_ATS);

							retFlag = CI_ERROR;
						}
					}
				}
				if (CI_ERROR == retFlag)
				{
					break;
				}
			}

			if (CI_SUCCESS == retFlag)
			{
				/*设置逻辑区段未锁闭*/
				for (ii = 0u; ii < logSecSum; ii++)
				{
					logBelongCiId = 0u;          /*进路所属联锁ID*/
					logSecId = GetLogicSecId(ii);/*获取物理区段ID*/
					logBelongCiId = GetLogSecBelongCiId(logSecId);

					/*逻辑区段ID正常*/
					if ((0u < logSecId) && (LOGIC_SECTION_SUM_MAX > logSecId))
					{
						/*是本联锁*/
						if (logBelongCiId == localCiId)
						{
							logState = GetLogSecLockState(logSecId);
							if (LOG_SECTION_LOCK_START == logState)
							{
								/*设置未锁闭*/
								SetLogSecLockState(logSecId, LOG_SECTION_LOCK_NO, 0u, 0u);
							}
							else
							{
								/* 上电解锁失败 */
								SetStartLockFlag(CI_START_LOCK_ERROR);
								/*记录和发送故障码*/
								SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
									CI_DEVICE_TYPE_LOGICSEC,
									logSecId,
									ETYPE_SYSTEM_STARTLOCKE_ERROR,
									logState, ESEND_LEVEL_ATS);

								retFlag = CI_ERROR;
							}
						}
					}
				}
			}

		}
		else
		{
			/*不做处理*/
			retFlag = CI_ERROR;
		}


	}
	else
	{
		/*不做处理*/
		retFlag = CI_ERROR;
	}

	if (CI_SUCCESS == retFlag)
	{
		/* 上电解锁成功 */
		SetStartLockFlag(CI_START_LOCK_NO);
	}
}


/*
* 功能描述： 进路状态设置管理，进路状态设置必须通过本函数
* 参数说明：
			const UINT16 routeId, UINT8 routeState
* 返回值  ：void
* edit cgh 20250224
*/
void SetRouteStateManage(const UINT16 routeId, UINT8 routeState)
{
	UINT8 setStateResult = 0u;
	UINT8 virCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 trainIdSum = 0u; /*列车ID总数量*/
	UINT8 i = 0u; /*索引*/
	UINT16* ptrainIdBuff = NULL; /*列车ID BUFF*/
	UINT8 keepWork = CI_ERROR;
	UINT8 retVal = CI_ERROR;
	UINT8 localCiType = 0U;
	UINT32 curCycNum = 0U;
	UINT16 wHalfResReqTrainId = 0U;
	UINT8 cSGBJDelayOpenFlag = 0U;  /*声光报警延时开放标志*/
	UINT8 cRelZuHeSGBJDelayOpenFlag = 0U;  /*关联组合进路声光报警延时开放标志*/
	UINT32 dwCurDelayOpenStartCycNum = 0U;  /*进路声光报警延时开放起始周期*/

	localCiType = GetLocalCiType();
	curCycNum = Get2oo2CurCycleNum();

	switch (routeState)
	{
	case ROUTE_STATE_IDLE:
		/*进路空闲*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*设置进路物理区段未锁闭*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO);
			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			/*清空指定进路ITS申请路径命令记录的列车ID信息 增加 WQM 20220310*/
			ClearITSRouteApplyTrainIDInfo(routeId);
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
			/*取消进路关联防护道岔的防护锁闭*/
			SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL);
			/*清除ATS期望锁闭的保护区段ID*/
			SetRouteAtsExpLkOverlapId(routeId, 0u);
			/*设置进路逻辑区段公共资源标志*/
			SetRouteLgcSecShareFlag(routeId, LOGIC_SECTION_RES_SHARE_NO);
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			/*设置进路部分锁闭区段0*/
			SetHalfRouteLockLgcSec(routeId, 0U, NULL);
			/*设置列车脚下资源0*/
			SetHalfRouteTrainLocLgcSec(routeId, 0U, NULL);
			/*设置道岔不可动标志*/
			SetHalfRouteSwitchMoveValid(routeId, ROUTE_HALF_SWITCH_MOVE_INVALID);
			/*设置资源请求列车ID为0*/
			SetHalfRouteResReqTrainId(routeId, 0U);

			/*设置关联组合进路声光报警延时标志有效*/
			SetRelZuHeRouteSGBJDelayFlag(routeId, ROUTE_SGBJ_DELAY_OPEN_VALID);

			/*设置进路驱动声光报警标志无效*/
			SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_INVALID);

			/*设置进路未驱动过声光报警*/
			SetRouteHasDrivedSGBJFlag(routeId, ROUTE_HAS_DRIVED_SGBJ_INVALID);

			/*设置进路办理道岔检查标志为默认*/
			SetRouteApplySwitchCheckFlag(routeId, ROUTE_APPLY_SWITCH_CHECK_DEF);

			if (localCiType == CI_TYPE_CLD)
			{
				SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
				if (GetRouteBelongLongRouteId(routeId) > 0u)
				{
					SetLongRouteStateDeal(GetRouteBelongLongRouteId(routeId), ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
				}
				SetRouteBelongLongRouteId(routeId, 0u); /*清除进路所属长调*/
				SetRouteOpenSigStartCycNum(routeId, 0u); /*重置信号开放时间*/
				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);/*空闲也清除进路恢复状态，用于下一次进路状态流转*/
				SetTrainEnterRouteFlag(routeId, TRAIN_ENTER_ROUTE_FLAG_NO);/*进路空闲后清除列车驶入进路标志*/
			}
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_FIRST_XUANPAI:
		/*进路初选*/
		setStateResult = SetRouteState(routeId, routeState);
		if (setStateResult == CI_SUCCESS)
		{
			/*设置进路物理区段征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_LEAD_FIRST_XUANPAI:
		/*引导初选*/
		setStateResult = SetRouteState(routeId, routeState);
		if (setStateResult == CI_SUCCESS)
		{
			/*设置进路物理区段征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;


	case ROUTE_STATE_LEAD_XUANPAI:
		/*进路引导选排*/
		setStateResult = SetRouteState(routeId, routeState);
		if (setStateResult == CI_SUCCESS)
		{
			/*车辆段引导进路不跨控区没有引导预选过程，所以也需要设征用*/
			/*设置进路物理区段征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;
	case ROUTE_STATE_HALF_FIRST_XUAN:
		/*进路部分初选*/
		setStateResult = SetRouteState(routeId, routeState);
		if (setStateResult == CI_SUCCESS)
		{
			/*设置进路物理区段征用*/
			SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_YES);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;
	case ROUTE_STATE_XUANPAI:
		/*进路选排*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}

		break;
	case ROUTE_STATE_HALF_XUANPAI:
		/*进路选排*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}

		break;
	case ROUTE_STATE_FIRST_LOCK:
		/*进路初锁*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路物理区段: 正常锁闭*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NORMAL);

			/*设置进路逻辑区段: 正常锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NORMAL);

			/*设置进路逻辑区段公共资源标志*/
			SetRouteLgcSecShareFlag(routeId, LOGIC_SECTION_RES_SHARE_YES);
			/*获取记录的指定进路的ITS路径申请列车ID,将其添加到锁闭的逻辑区段，并清空指定进路的ITS路径申请列车ID信息 增加 WQM 20220310*/
			trainIdSum = GetITSRouteApplyTrainIdSum(routeId);
			ptrainIdBuff = GetITSRouteApplyTrainIdBuf(routeId);
			/*存在列车ID且未越界*/
			if ((0u < trainIdSum) && (ROUTE_APPLY_RECD_TRAIN_SUM_MAX >= trainIdSum) && (NULL != ptrainIdBuff))
			{
				for (i = 0u; i < trainIdSum; i++)
				{
					SetRouteLogicSecResTrainId(routeId, ptrainIdBuff[i]);
				}
				ClearITSRouteApplyTrainIDInfo(routeId);
			}
			else
			{
				;/* 无处理 */
			}

			/*设置进路关联防护道岔: 防护锁闭*/
			SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_SET);

			/*设置信号开放时间*/
			SetRouteOpenSigStartCycNum(routeId, curCycNum);

			/*清除进路相关道岔期望驱动位置*/
			ClearRouteSwitchDrivePos(routeId);

			/*清除进路相关道岔单操位置*/
			ClearRouteSwitchDanCaoPos(routeId);

			/*设置声光报警延时开放起始周期时间*/
			cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(routeId);
			cRelZuHeSGBJDelayOpenFlag = GetRelZuHeRouteSGBJDelayFlag(routeId);
			dwCurDelayOpenStartCycNum = GetRouteDelayOpenStartCyc(routeId);
			if ((0U == dwCurDelayOpenStartCycNum) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cSGBJDelayOpenFlag) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cRelZuHeSGBJDelayOpenFlag))
			{
				SetRouteDelayOpenStartCyc(routeId, curCycNum);
				SetRouteOpenSigStartCycNum(routeId, 0U);  /*若存在声光报警延时，先清除进路信号开放时间，避免因声光报警延时导致进路信号开放时间超限*/
			}
			else
			{
				/*不延时或已设置延时起始周期，不处理*/
			}

			if (localCiType == CI_TYPE_CLD)
			{
				SetRouteBelongLongRouteId(routeId, 0u); /*清除进路所属长调*/
				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);/*初锁意味着重新完整锁闭，准备开信号*/
			}

			/*设置进路办理道岔检查标志为默认*/
			SetRouteApplySwitchCheckFlag(routeId, ROUTE_APPLY_SWITCH_CHECK_DEF);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_HALF_LOCK:
		/*进路部分初锁*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			wHalfResReqTrainId = GetHalfRouteResReqTrainId(routeId);
			/*设置进路物理区段未征用*/
			SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路逻辑区段: 正常锁闭*/
			SetRouteHalfLogSecLockState(routeId, LOG_SECTION_LOCK_NORMAL);

			/*设置进路物理区段: 正常锁闭*/
			SetRouteHalfPhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NORMAL);


			/*设置道岔不可动标志*/
			SetHalfRouteSwitchMoveValid(routeId, ROUTE_HALF_SWITCH_MOVE_INVALID);
			/*设置进路逻辑区段公共资源标志*/
			SetRouteHalfLgcSecShareFlag(routeId, LOGIC_SECTION_RES_SHARE_YES);

			/*添加部分锁闭列车资源*/
			SetRouteHalfLogSecResTrainId(routeId, wHalfResReqTrainId);


			/*设置进路部分防护道岔: 防护锁闭*/
			SetRouteHalfProSwLockState(routeId, SWITCH_LOCK_PROTECT_SET);


			/*清除进路相关道岔期望驱动位置*/
			ClearRouteHalfSwitchDrivePos(routeId);

			/*清除进路相关道岔单操位置*/
			ClearRouteHalfSwitchDanCaoPos(routeId);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;
	case ROUTE_STATE_FIRST_LOCKERR:
		/*进路初锁异常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_YUXIAN_LOCK:
		/*预先锁闭*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_YUXIAN_OPEN:
		/*预先开放*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*重置信号开放时间*/
			SetRouteOpenSigStartCycNum(routeId, 0);

			/*取消进路信号重开标志*/
			SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);

			/*清除进路相关物理区段之前占用状态*/
			(void)CleanRoutePhySecPreOccupyState(routeId);

			if ((CI_TYPE_CLD == localCiType) || (CI_TYPE_TCC == localCiType))
			{
				(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
				(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
			}
			else
			{
				;
			}
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_NEAR_LOCK:
		/*接近锁闭正常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_NEAR_LOCKERR:
		/*接近锁闭异常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_NEAR_OPEN:
		/*接近开放*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*重置信号开放时间*/
			SetRouteOpenSigStartCycNum(routeId, 0);

			/*取消进路信号重开标志*/
			SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);

			/*清除进路相关物理区段之前占用状态*/
			(void)CleanRoutePhySecPreOccupyState(routeId);

			if ((ROUTE_STOPCHECK_SET_YES == GetRouteStopCheckFlag(routeId)) &&
				((CI_TYPE_CLD == localCiType) || (CI_TYPE_TCC == localCiType)))
			{
				(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
				(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
			}
			else
			{
				;
			}
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_DELAY_UNLOCK:
		/*延时解锁*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_AUTO_UNLOCK:
		/*自动解锁正常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_HALF_UNLOCK:
		/*进路部分锁闭解锁*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*设置进路部分锁闭区段0*/
			SetHalfRouteLockLgcSec(routeId, 0U, NULL);

			/*设置列车脚下资源0*/
			SetHalfRouteTrainLocLgcSec(routeId, 0U, NULL);
			/*设置道岔不可动标志*/
			SetHalfRouteSwitchMoveValid(routeId, ROUTE_HALF_SWITCH_MOVE_INVALID);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;
	case ROUTE_STATE_AUTO_UNLOCKERR:
		/*自动解锁异常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			SetRouteXianSuConfirmStt(routeId, ROUTE_XIANSU_CONFIRM_NO);
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_LEAD_LOCK:
		/*引导锁闭*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			/*设置信号开放时间*/
			SetRouteOpenSigStartCycNum(routeId, Get2oo2CurCycleNum());
#if 0
			/* 清除保护区段锁闭时间 */
			SetOverlapLockStartCycNum(routeId,0);
#endif

			/*设置进路物理区段: 正常锁闭*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NORMAL);

			/*设置进路逻辑区段: 正常锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NORMAL);

			/*设置进路关联防护道岔: 防护锁闭*/
			SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_SET);

			/*设置进路自动进路无效*/
			SetAutoRouteSetFlag(GetRouteAutoRouteId(routeId), AUTO_ROUTE_SET_NO);
			SetAutoReturnSetFlag(GetRouteAutoReturnId(routeId), AUTO_RETURN_SET_NO);
			SetAllAutoReturnSetFlag(GetRouteAllAutoReturnId(routeId), ALL_AUTO_RETURN_SET_NO);
			if (ROUTE_TYPE_AUTO_TRIGGER == GetAutoTriggerType(routeId))
			{/*虚拟联锁兼容*/
				SetRouteAutoTriggerFlag(routeId, AUTO_TRIGGER_SET_NO);
			}
			else
			{
				;
			}
			/*清除进路相关道岔期望驱动位置*/
			ClearRouteSwitchDrivePos(routeId);

			/*清除进路相关道岔单操位置*/
			ClearRouteSwitchDanCaoPos(routeId);

			/*设置声光报警延时开放起始周期时间*/
			cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(routeId);
			dwCurDelayOpenStartCycNum = GetRouteDelayOpenStartCyc(routeId);
			if ((0U == dwCurDelayOpenStartCycNum) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cSGBJDelayOpenFlag))
			{
				SetRouteDelayOpenStartCyc(routeId, curCycNum);
				SetRouteOpenSigStartCycNum(routeId, 0U);  /*若存在声光报警延时，先清除进路信号开放时间，避免因声光报警延时导致进路信号开放时间超限*/
			}
			else
			{
				/*不延时或已设置延时起始周期，不处理*/
			}

			/*设置进路办理道岔检查标志为默认*/
			SetRouteApplySwitchCheckFlag(routeId, ROUTE_APPLY_SWITCH_CHECK_DEF);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_LEAD_LOCKERR:
		/*引导锁闭异常*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*设置引导故障延时时间*/
			SetRouteLeadFaultOpenStartCyc(routeId, 0u);

			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;

	case ROUTE_STATE_LEAD_OPEN:
		/*引导开放*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			/*重置信号开放时间*/
			SetRouteOpenSigStartCycNum(routeId, 0u);

			/*取消进路信号重开标志*/
			SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO);
			
			/*清除进路相关物理区段之前占用状态*/
			(void)CleanRoutePhySecPreOccupyState(routeId);
			if ((localCiType == CI_TYPE_CLD) || (localCiType == CI_TYPE_TCC))
			{
				(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
				(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
			}
			else
			{
				;
			}
			keepWork = CI_SUCCESS;
		}
		else
		{
			/*进路状态异常*/
			/*xxxxx宕机*/
		}
		break;
	case ROUTE_STATE_HALF_UNLOCKDELAY:
		/*列车脚下区段全部锁闭后，或列车丢失通信后倒计时开始进入此状态*/
		setStateResult = SetRouteState(routeId, routeState);
		if (CI_SUCCESS == setStateResult)
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			; 
		}
		break;
	default:

		/*进路状态异常*/
		/*xxxxx宕机*/
		break;
	}

	if (CI_SUCCESS == keepWork)
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		/*记录系统故障*/
		SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
			EFUNC_LOGIC_MANAGE_SYETEM,
			CI_ERROR,
			ETYPE_SYSTEM_EXCEPT,
			CI_ERROR, ESEND_LEVEL_ZERO);
		retVal = CI_ERROR;
	}
}

/*
* 功能描述： 更新照查继电器管理
* 参数说明：
			const UINT16 routeId, UINT8 routeState
* 返回值  ：
			CI_ERROR
			CI_SUCCESS
*/
void UpdateZhaoChaStateManage(const UINT16 routeId, UINT8 routeState)
{
	UINT16 wSelfRealyId = 0U;/*本端照查继电器ID*/
	UINT8 relauDrvState = 0U;
	UINT16 realyIdInterface = 0u;
	UINT8 relauDrvStateInterface = 0u;
	UINT8 endSignalBelongCi = 0u;
	UINT8 localCi = 0u;
	UINT8 commState = 0u;/*通信状态*/
	UINT8 realyIdState = 0u;
	UINT32 routeLockCycNum = 0u;
	UINT32 timeOutCycCount = 0u;
	UINT8 overTimeCheck = 0u;
	UINT16 endSignalId = 0u;
	UINT8 funcSwitchSupportRelayInterface = 0u;
	UINT8 confirmRelayInterfaceFlag = 0u;

	wSelfRealyId = GetRouteThisZhaoChaRelayId(routeId); /*本端照查继电器ID*/

/*获取继电接口本端照查ID*/
	realyIdInterface = GetRouteRelayBenDuanZcIdOnRelay(routeId);
	relauDrvStateInterface = GetRelayDriveState(realyIdInterface);
	localCi = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	endSignalId = GetRouteEndSignalId(routeId);/*进路终端信号机*/
	endSignalBelongCi = GetSignalBelongCiId(endSignalId);

	/*获取超时判断信息*/
	routeLockCycNum = GetRouteLockStartCycNum(routeId);
	timeOutCycCount = GetSystemParaSignalCloseCyc();

	if (0U < wSelfRealyId)
	{
		/*网络接口本端继电器存在*/
		if ((ROUTE_STATE_IDLE == routeState) ||
			(ROUTE_STATE_FIRST_XUANPAI == routeState) ||
			(ROUTE_STATE_XUANPAI == routeState) ||
			(ROUTE_STATE_LEAD_FIRST_XUANPAI == routeState) ||
			(ROUTE_STATE_LEAD_XUANPAI == routeState))
		{
			relauDrvState = GetRelayDriveState(wSelfRealyId);
			if (RELAY_DRIVE_STATE_NULL == relauDrvState)
			{
				(void)SetRelayDriveState(wSelfRealyId, RELAY_STATE_UP);
			}
		}
		else
		{
			(void)SetRelayDriveState(wSelfRealyId, RELAY_STATE_DOWN);
			realyIdState = GetRelayCollState(wSelfRealyId);

			if (RELAY_STATE_DOWN != realyIdState)
			{
				overTimeCheck = SystemOverTimeCheck(routeLockCycNum, timeOutCycCount);
				if (CI_TIME_OUT == overTimeCheck)
				{
					SetPlatOverFlag(); /*设置平台宕机*/
					SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_RELAY, wSelfRealyId, ETYPE_ZHAOCHA_ROUTE_OVERTIME, RELAY_STATE_UP, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
				}
			}
		}
	}

	/*继电接口继电器存在*/
	if (0u < realyIdInterface)
	{
		/*不属于本联锁*/
		if (endSignalBelongCi != localCi)
		{
			/*获取通信状态*/
			commState = GetLocalCiAndOtherCiTransSta(endSignalBelongCi);
		}
		/*继电接口信息*/
		funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
		confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

		if ((localCi != endSignalBelongCi) && (TRANSMIT_STATE_BAD == commState)
			&& (CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)
			&& (FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
		{
			if ((ROUTE_STATE_IDLE == routeState) ||
				(ROUTE_STATE_FIRST_XUANPAI == routeState) ||
				(ROUTE_STATE_XUANPAI == routeState) ||
				(ROUTE_STATE_LEAD_FIRST_XUANPAI == routeState) ||
				(ROUTE_STATE_LEAD_XUANPAI == routeState))
			{
				/*进路空闲 照查吸起*/
				if (RELAY_DRIVE_STATE_NULL == relauDrvStateInterface)
				{
					(void)SetRelayDriveState(realyIdInterface, RELAY_STATE_UP);

				}
				else
				{
					/*不做处理*/
				}
			}
			else
			{
				(void)SetRelayDriveState(realyIdInterface, RELAY_STATE_DOWN);
				realyIdState = GetRelayCollState(realyIdInterface);
				if (RELAY_STATE_DOWN != realyIdState)
				{
					overTimeCheck = SystemOverTimeCheck(routeLockCycNum, timeOutCycCount);
					if (CI_TIME_OUT == overTimeCheck)
					{
						SetPlatOverFlag(); /*设置平台宕机*/
						SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_RELAY, realyIdInterface, ETYPE_ZHAOCHA_ROUTE_OVERTIME, RELAY_STATE_UP, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
					}
				}
			}
		}

	}
}

/*
* 功能描述： 设置自动进路逻辑管理
* 参数说明： const UINT16 autoRouteId, 进路ID
* 返回值  ： void
*/
void SetAutoRouteLogicManage(const UINT16 autoRouteId, const UINT8 virCIid)
{
	UINT8 chkStatus = 0u;/*临时变量，检查结果*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 chFunctionId = EFUNC_SET_AUTOROUTE;/*函数ID*/
	UINT8 chSendLevel = ESEND_LEVEL_ATS;/*报警等级初始化为向ATS发送*/
	UINT8 routeSum = 0u;              /*自动进路包含进路数目 (配置字段)*/
	UINT16* routeIdBuf = NULL;    /*自动进路进路ID数组 (配置字段)*/
	UINT8 ii = 0U;

	routeSum = GetAutoRouteIncludeRouteSum(autoRouteId);/*该进路所包含进路数目*/
	routeIdBuf = GetAutoRouteIncludeRouteBuf(autoRouteId);/*获取该自动进路对应的基本进路*/

	if ((0u == autoRouteId) || (autoRouteId >= AUTO_ROUTE_SUM_MAX))
	{
		chkStatus = CI_ERROR;
	}
	else
	{
		chkStatus = CI_SUCCESS;
	}

	if (CI_SUCCESS == chkStatus)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			/*检查自动进路包含进路是否都属于输入虚拟联锁，不属于则返回失败*/
			chkStatus = CheckAutoRouteBelongVirCI(autoRouteId, virCIid);
		}
	}

	if (CI_SUCCESS == chkStatus)
	{
		chkStatus = AutoRouteIsOpposedCheck(autoRouteId,chFunctionId);
		
	}

	if (CI_SUCCESS == chkStatus)
	{
		chkStatus = ChekAutoRouteFlockState(autoRouteId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTOROUTE, autoRouteId, ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_HAVE_BLOCK, chSendLevel);
		}

	}

	if (CI_SUCCESS == chkStatus)
	{
		chkStatus = AutoRouteFloodStateCheck(autoRouteId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTOROUTE, autoRouteId, ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_FLOOD_STATE_ERR, chSendLevel);
		}
	}

	if (CI_SUCCESS == chkStatus)
	{
		SetAutoRouteSetFlag(autoRouteId, AUTO_ROUTE_SET_YES);

		/*遍历自动进路包含的进路*/
		if ((0U != routeSum) && (NULL != routeIdBuf))
		{
			for ( ii = 0U; ii < routeSum; ii++)
			{
				/*清除ATS取消资源向Ivoc申请的标志（列车在等待掉头解锁过程中，重新办理进路，默认解锁失败）*/
				SetRouteZhefanJiesuoTrainId(routeIdBuf[ii], 0U);
				SetRouteZhefanJiesuoCyc(routeIdBuf[ii], 0U);
			}
		}
	}
}
/*
* 功能描述： 取消自动进路逻辑管理
* 参数说明： const UINT16 autoRouteId, 进路ID
* 返回值  ： void
*/
void CancelAutoRouteLogicManage(const UINT16 autoRouteId, const UINT8 virCIid)
{
	UINT8 reVal = CI_ERROR;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	if ((0u == autoRouteId) || (autoRouteId >= AUTO_ROUTE_SUM_MAX))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			reVal = CheckAutoRouteBelongVirCI(autoRouteId, virCIid);
		}

	}

	if (CI_SUCCESS == reVal)
	{
		SetAutoRouteSetFlag(autoRouteId, AUTO_ROUTE_SET_NO);
	}
}


/*
* 功能描述： 设置自动折返逻辑管理
* 参数说明： const UINT16 autoReturnId, 进路ID
* 返回值  ： void
*/
void SetAutoReturnLogicManage(const UINT16 autoReturnId, const UINT8 virCIid)
{
	UINT8 chkStatus = 0u;/*临时变量，检查结果*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 chFunctionId = EFUNC_SET_AUTORETURN;/*函数ID*/
	UINT8 chSendLevel = ESEND_LEVEL_ATS;/*报警等级初始化为向ATS发送*/

	if ((0u == autoReturnId) || (autoReturnId >= AUTO_RETURN_SUM_MAX))
	{
		chkStatus = CI_ERROR;
	}
	else
	{
		chkStatus = CI_SUCCESS;
	}
	if (CI_SUCCESS == chkStatus)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			chkStatus = CheckAutoReturnBelongVirCI(autoReturnId, virCIid);
		}
	}
	if (CI_SUCCESS == chkStatus)
	{/*自动折返进路是否有抵触自动进路已办理检查*/
		chkStatus = AutoReturnIsOpposedCheck(autoReturnId, chFunctionId);
		
	}

	if (CI_SUCCESS == chkStatus)
	{/*检查自动折返进路内方信号机道岔区段防护道岔的封锁情况*/
		chkStatus = ChekAutoReturnFlockState(autoReturnId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTORETURN, autoReturnId, ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_HAVE_BLOCK, chSendLevel);
		}

	}

	if (CI_SUCCESS == chkStatus)
	{/*检查自动折返进路内防淹门状态*/
		chkStatus = AutoReturnFloodStateCheck(autoReturnId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTORETURN, autoReturnId, ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_FLOOD_STATE_ERR, chSendLevel);
		}
	}

	if (CI_SUCCESS == chkStatus)
	{/*所有检查项完毕，设置自动属性*/
		SetAutoReturnSetFlag(autoReturnId, AUTO_RETURN_SET_YES);
	}




}
/*
* 功能描述： 取消自动折返逻辑管理
* 参数说明： const UINT16 autoReturnId, 进路ID
* 返回值  ： void
*/
void CancelAutoReturnLogicManage(const UINT16 autoReturnId, const UINT8 virCIid)
{
	UINT8 reVal = CI_ERROR;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	if ((1U > autoReturnId) || (autoReturnId >= AUTO_RETURN_SUM_MAX))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == reVal)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			reVal = CheckAutoReturnBelongVirCI(autoReturnId, virCIid);
		}
	}
	if (CI_SUCCESS == reVal)
	{
		SetAutoReturnSetFlag(autoReturnId, AUTO_RETURN_SET_NO);
	}
}


/*
* 功能描述： 进路保护区段锁闭逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： 无
*/
void LockOverlapLogicManage(const UINT16 routeId)
{
	UINT8 routeState = 0u;
	UINT8 overlapLockState = CI_ERROR;
	UINT8 rtOverlapSum = 0u;	/*进路包含的保护区段数目*/
	UINT8 lockOverlapType = 0u;	/*锁闭保护区段方式标识*/
	UINT16 atsCmdLkOverlapId = 0u;	/*ATS或现地期望锁闭保护区段ID*/
	UINT8 ciCtrModeFlag = 0u;	/*联锁控制模式标志*/
	UINT8 autoTriggerType = 0u;      /*进路自动触发进路属性*/
	UINT8 triggerFlag = 0u;	/*进路自动触发设置标志*/
	UINT8 autoSignalOrRouteValid = 0u;
	UINT8 virCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 routeOverlapNum = 0u;
	UINT16* pRouteOverlapIdbuf = NULL;
	UINT8 routeOverlapNeedCIlockFlag = 0u;
	UINT8 overlapLockProcFlag = 0u;
	UINT8 overlapFromRouteFlag = 0U;
	routeState = GetRouteState(routeId); /*获取进路状态*/

	/*cgh-合并CID-3037-4：*/
	triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/
	/*cgh-合并CID-2539-10：*/
	SetRouteOverlapNeedCIlockM(routeId);/*管理是否要设置可以联锁锁闭保护区段标志*/
	/*
	  进路为以下状态时锁闭保护区段：
	  进路初锁、初锁异常、预先开放、预先锁闭、接近开放、接近锁闭、接近锁闭异常、自动解锁、部分进路等待解锁
	*/
	if ((ROUTE_STATE_FIRST_LOCK == routeState) ||
		(ROUTE_STATE_FIRST_LOCKERR == routeState) ||
		(ROUTE_STATE_YUXIAN_OPEN == routeState) ||
		(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
		(ROUTE_STATE_NEAR_OPEN == routeState) ||
		(ROUTE_STATE_NEAR_LOCK == routeState) ||
		(ROUTE_STATE_NEAR_LOCKERR == routeState) ||
		(ROUTE_STATE_AUTO_UNLOCK == routeState) ||
		(ROUTE_STATE_HALF_UNLOCK == routeState)
		)
	{
		rtOverlapSum = GetRouteOverlapSum(routeId);	/*获取进路保护区段数目*/
		atsCmdLkOverlapId = GetRouteAtsExpLkOverlapId(routeId);	/*获取进路的ATS期望锁闭保护区段Id*/
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			/*cgh-合并CID-2539-10：*/
			routeOverlapNum = GetRouteOverlapSum(routeId);
			pRouteOverlapIdbuf = GetRouteOverlapIdBuf(routeId);
			if ((0u < routeOverlapNum) && (NULL != pRouteOverlapIdbuf))
			{
				virCIid = GetOverlapBelongVirCiId(pRouteOverlapIdbuf[0]);
				ciCtrModeFlag = GetVirCImode(virCIid);/*获取联锁控制模式*/
			}
		}
		else
		{
			ciCtrModeFlag = GetCiModeFlag();	/*获取联锁控制模式*/
		}
		
		lockOverlapType = GetOverlapLockTypeSwitch();   /*获取锁闭保护区段方式 0x02：联锁自行锁闭保护区段 0x01：根据ATS命令锁闭保护区段*/
		autoSignalOrRouteValid = AutoSignalOrRouteValid(routeId);
		/*获取标志*/
		routeOverlapNeedCIlockFlag = GetRouteOverlapNeedCIlockFlag(routeId);
		overlapLockProcFlag = GetRouteOverlapLockProcFlag(routeId);
		if ((FUNC_OVERLAP_LOCK_BY_CI == lockOverlapType) || (CI_MODE_CI_LOCAL == ciCtrModeFlag)
			|| (OVERLAPCILOCK_YES == routeOverlapNeedCIlockFlag) || (OVERLAP_LOCK_SELF_PROC_YES == overlapLockProcFlag)
			|| (CI_SUCCESS == autoSignalOrRouteValid) || (AUTO_TRIGGER_SET_YES == triggerFlag))
		{
			/*当获取锁闭保护区段方式为0x55 或 线路联锁控模式 或（进路只有一条保护区段）或（进路为自动进路：通过、折返或全自动折返）|| （联锁自动触发进路已设置）时，锁闭默认保护区段*/
			overlapLockState = LockRouteOverlapProc(routeId);/*Overlap锁闭*/
			if (CI_ERROR == overlapLockState)
			{/*在联锁触发未成功的情况下，若有ATS或人工触发，则继续检查能否执行*/
				/*cgh-合并CID-2539-1：不在锁闭过程*/
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_PROC_NO);
				if ((CI_MODE_CI_LOCAL != ciCtrModeFlag) && (0u < ciCtrModeFlag)
					&& (FUNC_OVERLAP_LOCK_BY_ATS == lockOverlapType) && (1U <= rtOverlapSum) && (0U < atsCmdLkOverlapId))  /*根据ATS命令锁闭保护区段*/
				{
					overlapLockState = LockRouteOverlapAccdToAtsCmd(routeId, atsCmdLkOverlapId);
				}
			}
			else if ((RETURN_WAIT_SWITCH_USING == overlapLockState) || (RETURN_WAIT_SWITCH_CHECK == overlapLockState) || (RETURN_LOCK_ERR_SWITPOS == overlapLockState))
			{
				/*防护道岔等待征用/防护道岔等待检查/道岔位置错误，设置联锁在自行锁闭保护区段过程中-（保护区段联锁设置标志）*/
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_SELF_PROC_YES);
			}
			else
			{
				/*不在锁闭过程*/
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_PROC_NO);
			}
		}
		else if ((FUNC_OVERLAP_LOCK_BY_ATS == lockOverlapType) && (rtOverlapSum >= 1u) && (atsCmdLkOverlapId > 0u))      /*根据ATS命令锁闭保护区段*/
		{/*获取锁闭保护区段方式为0xaa 线路根据ATS命令锁闭进路Overlap处理*/
			overlapFromRouteFlag = GetOverlapFromSetRouteCmdFlag(atsCmdLkOverlapId);
			if (OVERLAP_ROUTE_FLAG_YES == overlapFromRouteFlag)
			{
				if (ROUTE_STATE_AUTO_UNLOCK != routeState)
				{
					overlapLockState = LockRouteOverlapAccdToAtsCmd(routeId, atsCmdLkOverlapId);
				}
				else
				{/*什么也不做*/
				}
			}
			else
			{/*进路无连带标志*/
				overlapLockState = LockRouteOverlapAccdToAtsCmd(routeId, atsCmdLkOverlapId);
			}

			if (CI_ERROR == overlapLockState)
			{
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_PROC_NO);  /*设置进路不在锁闭过程*/
			}
			else if ((RETURN_WAIT_SWITCH_USING == overlapLockState) || (RETURN_WAIT_SWITCH_CHECK == overlapLockState) || (RETURN_LOCK_ERR_SWITPOS == overlapLockState))
			{
				/*防护道岔等待征用/防护道岔等待检查/道岔位置错误，设进路在ATS锁闭保护区段过程中*/
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_ATS_PROC_YES);
			}
			else
			{
				SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_PROC_NO);  /*设置进路不在锁闭过程*/
			}
		}
		else
		{
			/*不锁闭保护区段*/
		}

#if 0
		lineIdentity = GetCiFunctionSwitchConfig(VOBC_INTERFACE_IDENTITY);	/*获取线路标识*/
		rtOverlapSum = GetRouteOverlapSum(routeId);	/*获取进路保护区段数目*/
		atsCmdLkOverlapId = GetRouteAtsExpLkOverlapId(routeId);	/*获取进路的ATS期望锁闭保护区段Id*/
		ciCtrModeFlag = GetCiModeFlag();	/*获取联锁控制模式*/

		if ((LINE_FAOHLHT == lineIdentity) && (rtOverlapSum > 1) && (atsCmdLkOverlapId > 0))
		{/*互联互通FAO 线路根据ATS命令锁闭进路Overlap处理*/
			overlapLockState = LockRouteOverlapAccdToAtsCmd(routeId, atsCmdLkOverlapId);
		}
		else
		{
			if ((LINE_FAOHLHT != lineIdentity) || ((LINE_FAOHLHT == lineIdentity) && (CI_MODE_CI_LOCAL == ciCtrModeFlag)) || (1 == rtOverlapSum)
				|| (CI_SUCCESS == AutoSignalOrRouteValid(routeId)) || ((ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType) && (AUTO_TRIGGER_SET_YES == triggerFlag)))
			{/*当（线路类型为非FAOHLHT）或（FAOHLHT线路紧急站控模式）或（进路只有一条保护区段）或（进路为自动进路：通过、折返或全自动折返）|| （联锁自动触发进路已设置）时，锁闭默认保护区段；FAOHLHT非紧急站控模式进路保护区段多余1条时一直等待ATS锁闭保护区段命令*/
				overlapLockState = LockRouteOverlapProc(routeId);/*Overlap锁闭*/
			}

		}
		retVal = overlapLockState;
#endif
	}
	else
	{
		overlapLockProcFlag = GetRouteOverlapLockProcFlag(routeId);
		if ((OVERLAP_LOCK_SELF_PROC_YES == overlapLockProcFlag) || (OVERLAP_LOCK_ATS_PROC_YES == overlapLockProcFlag))
		{
			/*若保护区段中存储的周期号与本周期号不一致，表示本次因为其他分支未进入到锁闭保护区段流程，则清除该保护区段对道岔的征用*/
			ClearOverlopUsing(routeId);
			/*不在锁闭过程*/
			SetRouteOverlapLockProcFlag(routeId, OVERLAP_LOCK_PROC_NO);
			/*其他状态不锁闭Overlap*/
		}
		else
		{
			/*进路保护区段不在锁闭中，不处理*/
		}
	}
}

/*
* 功能描述： 进路保护区段解锁逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： 无
*/
void UnlockOverlapLogicManage(const UINT16 routeId)
{
	UINT8 const routeState = GetRouteState(routeId);
	UINT8 overlapLockState = CI_ERROR;

	/*
	  进路为以下状态时锁闭保护区段：
	  进路空闲、接近开放、接近锁闭、接近锁闭异常、自动解锁异常、自动解锁、初锁异常、预先锁闭、预先开放、部分进路等待解锁
	*/
	if ((routeState == ROUTE_STATE_IDLE) ||
		(routeState == ROUTE_STATE_NEAR_OPEN) ||
		(routeState == ROUTE_STATE_NEAR_LOCK) ||
		(routeState == ROUTE_STATE_NEAR_LOCKERR) ||
		(routeState == ROUTE_STATE_AUTO_UNLOCK) ||
		(routeState == ROUTE_STATE_AUTO_UNLOCKERR) ||
		(routeState == ROUTE_STATE_FIRST_LOCKERR) ||
		(routeState == ROUTE_STATE_YUXIAN_LOCK) ||
		(routeState == ROUTE_STATE_YUXIAN_OPEN) ||
		(routeState == ROUTE_STATE_HALF_UNLOCK))
	{
		/*自动信号或自动进路解锁保护区段*/
		overlapLockState = UnlockRouteOverlapProc(routeId);
	}
	else
	{
		/*不做处理*/
	}

}

/*
* 功能描述： 全站解封逻辑管理
* 参数说明： void
* 返回值  ： void
*/
void SetStartFLockUnLockLogicManage(void)
{
	UINT16 phySecId = 0u;		/*物理区段ID*/
	UINT16 phySecSum = 0u;		/*物理区段总数*/
	UINT16 ii = 0u;				/*游标*/

	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/

	UINT8 tmpRet = CI_ERROR;
	UINT8 tmpFState = PHYSICAL_SECTION_FLOCK_YES;

	UINT8 chStartFlockFlag = GetStartFLockFlag();
	if (CI_START_FLOCK_YES == chStartFlockFlag )
	{
		/*未全站解封过*/
	}
	else
	{
		return;
	}

	phySecSum = GetPhySecCurSum();/*获取物理区段总数*/
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	if (0u == phySecSum)
	{
		return;
	}

	for (ii = 0u; ii < phySecSum; ii++)
	{/*遍历物理区段*/
		belongCiId = 0u;          /*进路所属联锁ID*/

		phySecId = GetPhySecId(ii);/*获取物理区段ID*/
		belongCiId = GetPhySecBelongCiId(phySecId);

		if ((0u == phySecId) || (phySecId >= PHYSICAL_SECTION_SUM_MAX))
		{
			continue;
		}

		if ((belongCiId != localCiId) || (localCiId == 0u))
		{
			continue;
		}

		tmpFState = GetPhySecFLockState(phySecId);

		if (PHYSICAL_SECTION_FLOCK_YES == tmpFState)
		{/*物理区段封锁*/

			tmpRet = SetPhySecFLockState(phySecId, PHYSICAL_SECTION_FLOCK_NO);/*设置物理区段封锁状态为未封锁*/

			if (CI_ERROR == tmpRet)
			{
				/*设置物理区段封锁错误处理*/
			}
		}
		else
		{
			/* 上电解封失败 */
			SetStartFLockFlag(CI_START_FLOCK_ERROR);

			/*记录和发送故障码*/
			SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
				CI_DEVICE_TYPE_PHYSEC,
				phySecId,
				ETYPE_SYSTEM_STARTLOCKE_ERROR,
				GetPhySecLockState(phySecId), ESEND_LEVEL_ATS);

			return;
		}
	}

	/*全站解封成功*/
	SetStartFLockFlag(CI_START_FLOCK_NO);
}

/*
* 功能描述： 计轴复位命令逻辑管理
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ： void
*/
void SetSectionResetLogicManage(const UINT16 phySecId, const UINT8 resetType)
{
	UINT8 const functionId = EFUNC_SET_SEC_RESET_LOGIC_MANAGE; /*函数故障码*/
	UINT16 retValid = CI_ERROR;	/*计轴总复位继电器状态有效性值，默认为无效*/
	UINT8 occupyState = 0u; /*占用状态*/

	if ((0u < phySecId) && (PHYSICAL_SECTION_SUM_MAX > phySecId))
	{
		occupyState = GetPhySecCurOccupyState(phySecId);
		if (SECTION_OCCUPY_YES == occupyState) /*采集占用*/
		{
			occupyState = GetPhySecCurTxOccupyState(phySecId);
			if (LOGICSECTION_OCCUPY_TX == occupyState) /*CT占用*/
			{
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySecId, ETYPE_PS_NO_UT_CT_OCU_STATE, occupyState, ESEND_LEVEL_ATS);
			}
			else
			{
				retValid = GetZFWValidByPhySecId(phySecId); /*获取物理区段计轴总复位继电器状态有效性*/
				if (CI_SUCCESS == retValid) /*有效，执行计轴复位功能*/
				{
					SetPhySecSectionResetType(phySecId, resetType);
					SetPhySecResetStartCycNum(phySecId, Get2oo2CurCycleNum());/*设置当前周期号位计轴复位命令起始周期号*/
				}
				else /*无效，反馈计轴复位失败：总复位继电器落下*/
				{
					SetCiSendCmdBackInfoData(CI_BACK_PSEC_RESET_ZFW_ERROR, CI_DEVICE_TYPE_PHYSEC, phySecId, 0u, 0u);
				}
			}
		}
		else	/*无占压，反馈计轴复位失败，缺陷YF0083-761,反馈计轴空闲，缺陷YF0083-1068*/
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySecId, ETYPE_PS_MERGY_OCU_STATE, occupyState, ESEND_LEVEL_ATS);
		}
	}
}

/*
* 功能描述： 批量计轴复位命令逻辑管理
* 参数说明： const UINT8 cPhySecSum  物理区段数量
*		     const UINT16 pPhySecIdBuff[]  物理区段ID数组
* 返回值  ： void
*/
void BatchAixsResetLogicManage(const UINT8 cPhySecSum, const UINT16 pPhySecIdBuff[], const UINT8 resetType)
{
	UINT8 const functionId = EFUNC_SET_SEC_RESET_LOGIC_MANAGE; /*函数故障码*/
	UINT8 retValid = CI_ERROR;	/*计轴总复位继电器状态有效性值，默认为无效*/
	UINT8 occupyState = 0U; /*占用状态*/
	UINT8 ii = 0U;
	UINT16 phySecId = 0U;	/*物理区段ID*/
	UINT8 cCheckRetVal = CI_ERROR;	/*检查结果*/
	UINT8 cBreakFlag = CI_SUCCESS;   /*跳出标志*/
	UINT32 dwCurCyc = 0U;  /*周期号*/
	dwCurCyc = Get2oo2CurCycleNum();
	if ((pPhySecIdBuff != NULL) && (cPhySecSum != 0U))
	{
		for (ii = 0U; ii < cPhySecSum; ii++)
		{
			phySecId = pPhySecIdBuff[ii];
			if ((0U < phySecId) && (PHYSICAL_SECTION_SUM_MAX > phySecId))
			{
				occupyState = GetPhySecCurOccupyState(phySecId);
				if (SECTION_OCCUPY_YES == occupyState) /*采集占用*/
				{
					occupyState = GetPhySecCurTxOccupyState(phySecId);
					if (LOGICSECTION_OCCUPY_TX == occupyState) /*CT占用*/
					{
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySecId, ETYPE_PS_NO_UT_CT_OCU_STATE, occupyState, ESEND_LEVEL_ATS);
						cCheckRetVal = CI_ERROR;
						cBreakFlag = CI_ERROR;
					}
					else
					{
						retValid = GetZFWValidByPhySecId(phySecId); /*获取物理区段计轴总复位继电器状态有效性*/
						if (CI_SUCCESS == retValid)
						{
							cCheckRetVal = CI_SUCCESS;
						}
						else
						{							
							SetCiSendCmdBackInfoData(CI_BACK_PSEC_RESET_ZFW_ERROR, CI_DEVICE_TYPE_PHYSEC, phySecId, 0U, 0U);
							cCheckRetVal = CI_ERROR;
							cBreakFlag = CI_ERROR;
						}
					}
				}
				else	/*无占压，反馈计轴复位失败,反馈计轴空闲*/
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySecId, ETYPE_PS_MERGY_OCU_STATE, occupyState, ESEND_LEVEL_ATS);
					cCheckRetVal = CI_ERROR;
					cBreakFlag = CI_ERROR;
				}
				if (cBreakFlag == CI_ERROR)
				{
					break;	/*条件满足，退出循环*/
				}
			}
		}
		if (CI_SUCCESS == cCheckRetVal)
		{/*有效，执行计轴复位功能*/
			for (ii = 0U; ii < cPhySecSum; ii++)
			{
				SetPhySecSectionResetType(pPhySecIdBuff[ii], resetType);
				SetPhySecResetStartCycNum(pPhySecIdBuff[ii], dwCurCyc);/*设置当前周期号位计轴复位命令起始周期号*/
			}
		}
		else
		{
			/*无效，不执行计轴复位功能*/
		}
	}
	else
	{
		/*数据有误，无计轴需复位*/
	}
}


/*
* 功能描述： 设置折返进路为通过进路管理
* 参数说明： const UINT16 signalId, 通过信号机ID
* 返回值  ： void
*/
void SetThroughRouteManage(const UINT16 signalId)
{
	UINT8 localCiId = 0u;        /*本地联锁ID*/
	UINT8 belongCiId = 0u;       /*进路所属联锁ID*/

	UINT16 signalOutSecId = 0u;  /*信号机外方区段*/
	UINT16 signalInSecId = 0u;   /*信号机内方区段*/
	UINT16 returnRouteId = 0u;   /*折返进路*/
	UINT16 throughRouteId = 0u;  /*通过进路*/
	UINT16 nextRouteId = 0u;     /*下一个进路*/
	UINT8 returnRouteState = 0u; /*折返进路状态*/
	UINT8 returnRouteIdBelongCiId = 0u;/*折返进路所属联锁ID*/
	UINT8 throughRouteIdBelongCiId = 0u;/*通过进路所属联锁ID*/
	UINT16 reRouteNormalLockPhy = 0u;
	UINT8 phyMergeState = 0u;
	UINT16 nextRouteLockPhy = 0u;
	UINT16 lockPhyBelongRoute = 0u;
	UINT8 saveReRouteDir = 0u;
	UINT8 throughRouteDir = 0u;
	UINT16 wLastLgcSecId = 0U;
	UINT16 wTrainId = 0u;
	UINT8 chTrainSum = 0u;
	UINT16 wLogicSecId = 0u;
	UINT16 wEndSignalId = 0U;/*折返进路的终端信号机*/
	UINT16 wStartSignalId = 0U;/*待信号特开进路的始端信号机*/
	LogicTrainResStruct* pstLgcResInfo = NULL;
	LogicTrainResStruct  stTmpResInfo[LOGIC_SECTION_RES_SUM_MAX] = { 0U };

	/*信号机ID不合法*/
	if ((0u == signalId) || (SIGNAL_SUM_MAX <= signalId))
	{
		/*不做处理*/
	}
	else
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

		if ((belongCiId == localCiId) && (localCiId != 0u))
		{

			signalOutSecId = GetSignalOutFirstPhySecId(signalId);
			signalInSecId = GetSignalInFirstLockedPhySecId(signalId);

			returnRouteId = GetPhySecRLockBelongRouteId(signalOutSecId);
			nextRouteId = GetPhySecRLockBelongRouteId(signalInSecId);
			throughRouteId = GetRouteThroughRouteId(returnRouteId);
			wEndSignalId = GetRouteEndSignalId(returnRouteId);/*获取终端信号机*/
			wStartSignalId = GetRouteStartSignalId(nextRouteId);/*待办理信号特开的进路始端信号机*/
			returnRouteIdBelongCiId = GetRouteBelongCiId(returnRouteId);/*获取折返进路所属联锁ID*/
			throughRouteIdBelongCiId = GetRouteBelongCiId(throughRouteId);/*获取通过进路所属联锁ID*/

			if ((returnRouteId == 0u) || (nextRouteId == 0u) || (throughRouteId == 0u))
			{
				/*进路号无效,不做处理*/
			}
			else
			{

				/*获取进路相关信息*/
				reRouteNormalLockPhy = GetRouteFirstNormalLockSection(returnRouteId);
				phyMergeState = GetPhySecCurMergeState(signalOutSecId);
				nextRouteLockPhy = GetPhySecLockState(signalInSecId);

				/*折返进路最后一个【正常锁闭】且【区段占用】*/
				if ((reRouteNormalLockPhy == signalOutSecId) &&
					(SECTION_OCCUPY_YES == phyMergeState))
				{
					/*下一进路第一区段锁闭*/
					if (PHYSICAL_SECTION_LOCK_NORMAL == nextRouteLockPhy)
					{
						/*获取锁闭进路*/
						lockPhyBelongRoute = GetPhySecRLockBelongRouteId(signalInSecId);
						saveReRouteDir = GetRouteDirection(returnRouteId);/*保存进路实际方向*/
						throughRouteDir = GetRouteDirection(throughRouteId); /*折返进路对应的通过进路方向*/

						/*方向相同*/
						if (wEndSignalId == wStartSignalId)
						{
							if ((localCiId == returnRouteIdBelongCiId) && (localCiId == throughRouteIdBelongCiId))
							{/*折返进路和通过进路都属于本联锁才设置折返进路空闲和通过进路自动解锁正常*/

								/*清除折返进路*/
								returnRouteState = GetRouteState(returnRouteId);	/*设置区段锁闭所属之前进路未锁闭*/
								wLastLgcSecId = GetRouteInLastLogSecId(returnRouteId);

								chTrainSum = GetLogSecTrainInfoSum(wLastLgcSecId);
								pstLgcResInfo = GetLogSecTrainInfo(wLastLgcSecId);
								if (NULL != pstLgcResInfo)
								{
									(void)ComMemCopy(pstLgcResInfo, stTmpResInfo, (UINT16)(sizeof(LogicTrainResStruct) * LOGIC_SECTION_RES_SUM_MAX));
								}


								SetLogSecLockState(wLastLgcSecId, LOG_SECTION_LOCK_NO, returnRouteId, saveReRouteDir);

								SetPhySecLockState(signalOutSecId, PHYSICAL_SECTION_LOCK_NO, returnRouteId, saveReRouteDir);
								SetRouteStateManage(returnRouteId, ROUTE_STATE_IDLE);

								/*设置区段属于当前进路锁闭*/
								SetLogSecLockState(wLastLgcSecId, LOG_SECTION_LOCK_NORMAL, throughRouteId, throughRouteDir);

								if (NULL != pstLgcResInfo)
								{
									CpyLgcSecResTrain(wLastLgcSecId, chTrainSum, stTmpResInfo);
								}/* 将逻辑区段所有资源设置为非折返 */
								SetLogSecAllTrainReturnState(wLastLgcSecId, LOGIC_SECTION_TRAIN_RETURN_NO);


								/*设置通过进路*/
								SetPhySecLockState(signalOutSecId, PHYSICAL_SECTION_LOCK_NORMAL, throughRouteId, throughRouteDir);
								SetRouteStateManage(throughRouteId, returnRouteState);

								/*重开下一进路信号*/
								RepeatOpenSignalLogicManage(signalId);


							}
						}
					}
					else
					{
						/*不做处理*/
					}
				}
				else
				{
					/*不做处理*/
				}
			}
		}
		else
		{
			/*不做处理*/
		}
	}
}


/*
* 功能描述： 设置引导总锁开放引导信号机状态管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
*/
void SetYLockSignalOpenStateManage(UINT8 virCIid, UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 belongVirCIid = 0u;
	UINT8 allSwitchYLockState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	if ((0u == signalId) || (SIGNAL_SUM_MAX <= signalId))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == reVal)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			reVal = CI_ERROR;
		}
	}
	if (CI_SUCCESS == reVal)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			belongVirCIid = GetSignalBelongVirCiId(signalId);
			if ((belongVirCIid == virCIid) && (0u != virCIid))
			{
				allSwitchYLockState = GetVirCIAllSwitchYLockState(virCIid);
				if (CI_ALL_SWITCH_YLOCK_YES == allSwitchYLockState)
				{
					SetSignalYLockOpenState(signalId, SIGNAL_OPEN);
				}
			}
		}
		else
		{
			allSwitchYLockState = GetAllSwitchYLockFlag();
			if (CI_ALL_SWITCH_YLOCK_YES == allSwitchYLockState)
			{
				SetSignalYLockOpenState(signalId, SIGNAL_OPEN);
			}
		}
	}
}
/*
* 功能描述： 设置道岔强扳逻辑管理
* 参数说明： UINT16 switchId, 道岔ID
*            const UINT8 switchSetPos, 道岔设置位置
* 返回值  ： void
*/
UINT8 ForceSetSwitchPositionManage(const UINT16 switchId, const UINT8 switchSetPos)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 retVal = 0U;

	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSwitchBelongCiId(switchId);    /*获取信号机所属联锁ID*/

		if ((belongCiId != localCiId) || (localCiId == 0u))
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		; /*不继续处理*/
	}
	if (CI_SUCCESS == retVal)
	{
		if (ForceSetSwitchPosLogicProcess(switchId, switchSetPos) == CI_SUCCESS)
		{
			retVal = SetSwitchDanCaoPosition(switchId, switchSetPos); /*设置单操位置标志*/
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		; /*不继续处理*/
	}
	return retVal;
}

#if 0
/*
* 功能描述： 因扣车导致需要重开的出站信号机标志计算
* 参数说明： UINT16 signalId, 信号机ID
* 返回值  ： void
*/
static void DetainCloseSignalProc(UINT16 signalId)
{
	UINT8 psdCloseSig = 0u;
	UINT8 psdIdSum = 0u;
	UINT16* psdIdBuf = NULL;
	UINT16 curOutRoute = 0u;/*当前离站进路*/
	UINT16 psdReOpenRoute = 0u;/*PSD关闭后重开出站进路*/
	UINT16 i = 0u;
	UINT8 j = 0u;
	UINT16* routeBuf = NULL;
	UINT16 routeNum = 0u;
	UINT8 routeSta = 0u;/*进路状态*/
	UINT8 wanZhengSuoBiFlag = 0u;/*标记进路是否已经完整锁闭*/

	routeBuf = GetStartSignalRouteBuf(signalId);/*获取始端信号机相同的进路ID数组*/
	routeNum = GetStartSignalRouteSum(signalId);/*获取始端信号机相同的进路数目*/
	psdIdSum = GetSignalRelatedPsdSum(signalId);/*获取以给定信号机为出站信号机的PSD的ID数量*/
	psdIdBuf = GetSignalRelatedPsdBuf(signalId);/*获取以给定信号机为出站信号机的PSD的ID数组*/
	if ((routeNum > 0u) && (routeBuf != NULL))
	{
		for (i = 0u; i < routeNum; i++)
		{
			routeSta = GetRouteState(routeBuf[i]);/*获取进路状态*/

			if ((ROUTE_STATE_YUXIAN_OPEN == routeSta) || (ROUTE_STATE_NEAR_OPEN == routeSta))
			{
				SetRouteDetainCloseFlag(routeBuf[i], ROUTE_DETAIN_CLOSE_SIG_YES);

				wanZhengSuoBiFlag = 1u;
			}
			else if ((ROUTE_STATE_NEAR_LOCKERR == routeSta) || (ROUTE_STATE_YUXIAN_LOCK == routeSta))
			{/*如果信号机是因为VOBC打开PSD关闭的，此时也把扣车需要重开标志置上*/
				psdCloseSig = 0u;

				if ((psdIdSum > 0u) && (psdIdBuf != NULL))
				{
					for (j = 0u; j < psdIdSum; j++)
					{
						curOutRoute = GetPsdClosedRouteId(psdIdBuf[j]);
						psdReOpenRoute = GetPsdToBeOpenedRoute(psdIdBuf[j]);
						if (((curOutRoute > 0u) && (curOutRoute == routeBuf[i])) || ((psdReOpenRoute > 0u) && (psdReOpenRoute == routeBuf[i])))
						{
							/*说明之前该信号机时因为VOBC打开车门而关闭的*/
							psdCloseSig = 1u;

							break;
						}
					}
				}
				if (1u == psdCloseSig)
				{
					SetRouteDetainCloseFlag(routeBuf[i], ROUTE_DETAIN_CLOSE_SIG_YES);
				}
				else
				{/*如果信号机是因为SPKS按下导致信号机关闭的，此时也把扣车需要重开标志置上*/
					if ((ROUTE_CLOSE_SPKS_YES == GetSPKSToRouteCloseFlag(routeBuf[i])) || (ROUTE_SPKS_RE_OPEN_SIG_YES == GetRouteSpksReOpenSigFlag(routeBuf[i])))
					{
						SetRouteDetainCloseFlag(routeBuf[i], ROUTE_DETAIN_CLOSE_SIG_YES);
					}
				}

				wanZhengSuoBiFlag = 1u;
			}
			else
			{
				/*什么都不做*/
			}

			if (1u == wanZhengSuoBiFlag)
			{
				break;
			}
		}
	}

}
#endif

/*
* 功能描述： 扣车逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
*            const UINT8 SetState, 设置状态
* 返回值  ： void
*/
void DetainLogicManage(const UINT16 signalId, const UINT8 setState)
{
	UINT8 detainState = 0u;
	UINT8 retResult = CI_SUCCESS;

	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
		retResult = CI_ERROR;
	}

	if (CI_SUCCESS == retResult)
	{
		detainState = GetSignalDetainFlag(signalId);
		if (SIGNAL_DETAIN_ATS == setState)
		{/*ATS办理人工扣车命令*/

			if ((SIGNAL_DETAIN_NO == detainState) || (SIGNAL_DETAIN_XIANDI_ATSAUTO == detainState) || (SIGNAL_DETAIN_ATS_AUTO == detainState) || (SIGNAL_DETAIN_XIANDI == detainState) || (SIGNAL_RELAY_DETAIN_YES == detainState))
			{/*当前状态为【未扣车】或【ATS自动扣车】或【仅现地扣车】或【硬线扣车】*/

				retResult = SetSignalDetainFlag(signalId, setState);
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_ATS_AUTO == setState)
		{/*办理ATS自动扣车命令*/
			if ((SIGNAL_DETAIN_NO == detainState) || (SIGNAL_DETAIN_XIANDI == detainState) || (SIGNAL_RELAY_DETAIN_YES == detainState))
			{/*当前状态为【未扣车】或【仅现地扣车】或【硬线扣车】*/

				retResult = SetSignalDetainFlag(signalId, setState);
			}
			else
			{
				/*已办理ATS人工扣车后，不能再办理自动扣车*/
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_XIANDI == setState)
		{/*现地办理扣车命令*/
#if 0
		 /*扣车重开出站信号标志计算*/
			DetainCloseSignalProc(signalId);
#endif

			if ((SIGNAL_DETAIN_NO == detainState) || (SIGNAL_DETAIN_ATS == detainState) || (SIGNAL_DETAIN_ATS_AUTO == detainState) || (SIGNAL_RELAY_DETAIN_YES == detainState))
			{/*当前状态为【未扣车】或【仅ATS人工扣车】或【仅ATS自动扣车】或【硬线扣车】*/

				retResult = SetSignalDetainFlag(signalId, setState);
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_ATS_NO == setState)
		{/*ATS办理取消扣车命令*/
			if ((SIGNAL_DETAIN_YES == detainState) || (SIGNAL_DETAIN_XIANDI_ATSAUTO == detainState) || (SIGNAL_DETAIN_ATS == detainState) || (SIGNAL_DETAIN_ATS_AUTO == detainState) || (SIGNAL_RELAY_DETAIN_YES == detainState))
			{/*当前状态为【均扣车】或【仅ATS人工扣车】或【仅ATS自动扣车】或【硬线扣车】*/
				retResult = SetSignalDetainFlag(signalId, setState);/*取消扣车*/
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_XIANDI_NO == setState)
		{/*现地办理取消扣车命令*/
			if ((SIGNAL_DETAIN_YES == detainState) || (SIGNAL_DETAIN_XIANDI_ATSAUTO == detainState) || (SIGNAL_DETAIN_XIANDI == detainState) || (SIGNAL_RELAY_DETAIN_YES == detainState))
			{/*当前状态为【均扣车】或【仅现地扣车】或【硬线扣车】*/
				retResult = SetSignalDetainFlag(signalId, setState);/*取消扣车*/
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_CI_RELAY_YES == setState)
		{/*相邻联锁硬线扣车*/
			if ((SIGNAL_DETAIN_NO == detainState) || (SIGNAL_DETAIN_XIANDI == detainState) ||
				(SIGNAL_DETAIN_ATS == detainState) || (SIGNAL_DETAIN_ATS_AUTO == detainState) ||
				(SIGNAL_DETAIN_YES == detainState) || (SIGNAL_DETAIN_XIANDI_ATSAUTO == detainState))
			{/*当前状态为【未扣车】或【仅现地扣车】或【仅ATS人工扣车】或【仅ATS自动扣车】或【现地+ATS自动扣车】或【现地+ATS人工扣车】*/

				retResult = SetSignalDetainFlag(signalId, setState);
				SetSignalDetainBtnActFlag(signalId, SIGNAL_ZFS_BTN_ACT_FLAG_YES); /*信号机属于本联锁，扣车按钮非本联锁，收到相邻联锁扣车命令，置扣车按钮激活有效*/
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else if (SIGNAL_DETAIN_CI_RELAY_NO == setState)
		{/*相邻联锁硬线不扣车*/
			if (SIGNAL_RELAY_DETAIN_YES == detainState)
			{/*当前状态为【硬线扣车】*/
				retResult = SetSignalDetainFlag(signalId, setState);/*取消扣车*/
				SetSignalDetainBtnActFlag(signalId, SIGNAL_ZFS_BTN_ACT_FLAG_NO); /*信号机属于本联锁，扣车按钮非本联锁，收到相邻联锁不扣车命令，置扣车按钮激活无效*/
			}
			else
			{
				retResult = CI_ERROR;
			}
		}
		else
		{
			retResult = CI_ERROR;
		}
	}

#if 0
	if (CI_SUCCESS == retResult && SIGNAL_DETAIN_NO == GetSignalDetainFlag(signalId))
	{/*ATS和现地均未扣车*/
		routeBuf = GetStartSignalRouteBuf(signalId);
		routeNum = GetStartSignalRouteSum(signalId);
		for (i = 0u; i < routeNum; i++)
		{
			routeSta = GetRouteState(routeBuf[i]);

			if ((ROUTE_DETAIN_CLOSE_SIG_YES == GetRouteDetainToRouteCloseFlag(routeBuf[i])) && ((ROUTE_STATE_YUXIAN_LOCK == routeSta) || (ROUTE_STATE_NEAR_LOCKERR == routeSta)))
			{
				SetRouteDetainReOpenSigFlag(routeBuf[i], ROUTE_DETAIN_RE_OPEN_SIG_YES);/*设置进路因取消扣车需要重开信号标志*/
				SetRouteDetainCloseFlag(routeBuf[i], ROUTE_DETAIN_CLOSE_SIG_NO);/*一次有效，一旦取消扣车重开信号标志有效，即清除扣车导致进路信号关闭标志*/

				break;
		}
			}
		}
#endif
	if (CI_ERROR == retResult)
	{
		debug_infor_printf((const)"DetainLogicManage ERROR signalId: %d   State:%d \n",signalId,setState);
	}
}
/*
* 功能描述： 设置全自动折返逻辑管理
* 参数说明： const UINT16 allAutoReturnId, 进路ID
* 返回值  ： void
*/
void SetAllAutoReturnLogicManage(const UINT16 allAutoReturnId, const UINT8 virCIid)
{
	UINT8 chkStatus = 0u;/*临时变量，检查结果*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 chFunctionId = EFUNC_SET_ALLAUTORETURN;/*函数ID*/
	UINT8 chSendLevel = ESEND_LEVEL_ATS;/*报警等级初始化为向ATS发送*/

	if ((0u == allAutoReturnId) || (allAutoReturnId >= AUTO_ROUTE_SUM_MAX))
	{
		chkStatus = CI_ERROR;
	}
	else
	{
		chkStatus = CI_SUCCESS;
	}
	if (CI_SUCCESS == chkStatus)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			chkStatus = CheckALLAutoReturnBelongVirCI(allAutoReturnId, virCIid);
		}
	}

	if (CI_SUCCESS == chkStatus)
	{/*全自动折返进路是否有抵触自动进路已办理检查*/
		chkStatus = AllAutoReturnIsOpposedCheck(allAutoReturnId, chFunctionId);
	}

	if (CI_SUCCESS == chkStatus)
	{/*检查全自动折返进路内方信号机道岔区段保护区段道岔及防护道岔的封锁情况*/
		chkStatus = ChekAllAutoReturnFlockState(allAutoReturnId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_ALLAUTORETURN, allAutoReturnId, ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_HAVE_BLOCK, chSendLevel);
		}

	}

	if (CI_SUCCESS == chkStatus)
	{/*检查全自动折返进路内防淹门状态*/
		chkStatus = AllAutoReturnFloodStateCheck(allAutoReturnId);
		if (CI_SUCCESS != chkStatus)
		{
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_ALLAUTORETURN, allAutoReturnId, ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_FLOOD_STATE_ERR, chSendLevel);
		}
	}

	if (CI_SUCCESS == chkStatus)
	{
		SetAllAutoReturnSetFlag(allAutoReturnId, ALL_AUTO_RETURN_SET_YES);
	}

}

/*
* 功能描述： 取消全自动折返逻辑管理
* 参数说明： const UINT16 allAutoReturnId, 进路ID
* 返回值  ： void
*/
void CancelAllAutoReturnLogicManage(const UINT16 allAutoReturnId, const UINT8 virCIid)
{
	UINT8 reVal = CI_ERROR;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	if ((allAutoReturnId < 1u) || (allAutoReturnId >= ALL_AUTO_RETURN_SUM_MAX))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == reVal)
	{
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			reVal = CheckALLAutoReturnBelongVirCI(allAutoReturnId, virCIid);
		}
	}
	if (CI_SUCCESS == reVal)
	{
		SetAllAutoReturnSetFlag(allAutoReturnId, ALL_AUTO_RETURN_SET_NO);
	}
}
/*
* 功能描述： 全自动折返进路逻辑管理
* 参数说明： void
* 返回值  ：
*/
void AllAutoReturnLogicManage(void)
{
	UINT16 routeCurSum = 0u;	     /*全自动折返进路总数目*/
	UINT16 allAutoReturnRouteId = 0u;	         /*全自动折返进路ID*/

	UINT8 routeLevel = 0u;        /*进路监督级别*/

	UINT16 ii = 0u;               /*循环索引*/
	UINT16 jj = 0u;
	UINT8 autoRouteType = 0u;
	UINT8 allAutoReturnIncludeSum = 0u;
	UINT16* pAllAutoReturnIncludeBuf = NULL;
	UINT8 startLockState = 0u;
	UINT8 startFlockFlag = 0u;

	routeCurSum = GetAllAutoReturnRouteCurSum();		        /*获取全自动折返进路总数*/

	startLockState = GetStartLockFlag();        /*获取上电解锁标志*/
	startFlockFlag = GetStartFLockFlag();       /*获取上电解封标志*/


	if ((CI_START_LOCK_NO != startLockState) || (CI_START_FLOCK_NO != startFlockFlag))
	{/*未全站解封且未上电解锁*/

	}
	else
	{

		/*引导总锁信号开放管理*/
		YLockSignalOpenManage();


		/*处理全自动折返进路*/
		for (ii = 0u; ii < routeCurSum; ii++)
		{
			allAutoReturnRouteId = 0u;
			routeLevel = 0u;          /*进路监督级别*/
			allAutoReturnIncludeSum = 0u;
			pAllAutoReturnIncludeBuf = NULL;
			allAutoReturnRouteId = GetAllAutoReturnRouteId(ii);
			allAutoReturnIncludeSum = GetAllAutoReturnIncludeRouteSum(allAutoReturnRouteId);     /*获取所包含的进路数目*/
			pAllAutoReturnIncludeBuf = GetAllAutoReturnIncludeRouteBuf(allAutoReturnRouteId);     /*获取进路ID数组*/

			for (jj = 0u; jj < allAutoReturnIncludeSum; jj++)
			{
				autoRouteType = GetRouteAutoRouteSetState(pAllAutoReturnIncludeBuf[jj]);       /*获取进路属性，并判断是否为全自动折返进路*/
				if (ROUTE_ALLAUTOROUTE_RETURN == autoRouteType)			/*为全自动折返进路则执行，否则遍历下一条进路*/
				{
					if ((0u != pAllAutoReturnIncludeBuf[jj]) && (pAllAutoReturnIncludeBuf[jj] < ROUTE_SUM_MAX))
					{


						/*进路监督级别确认*/
						routeLevel = RouteLevelConfirmLogicProcess(pAllAutoReturnIncludeBuf[jj]);

						/*设置进路监督级别*/
						SetRouteLevel(pAllAutoReturnIncludeBuf[jj], routeLevel);

						/* 自动触发办理全自动折返进路 */
						AllAutoReturnManage(pAllAutoReturnIncludeBuf[jj]);

#if 0

						/*#####进路状态处理#####*/
						if (ROUTE_STATE_IDLE == routeState)
						{ /*进路空闲*/

							RouteIdleManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_FIRST_XUANPAI == routeState)
						{/*进路预选*/

							RouteFirstXuanPaiManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_XUANPAI == routeState)
						{ /*进路选排*/

							RouteXuanPaiManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_FIRST_LOCK == routeState)
						{ /*进路初锁*/

							RouteFirstLockManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_FIRST_LOCKERR == routeState)
						{ /*进路初锁异常*/

							RouteFirstLockErrManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_YUXIAN_LOCK == routeState)
						{ /*预先锁闭*/

							RouteYuXianLockManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_YUXIAN_OPEN == routeState)
						{ /*预先开放*/

							RouteYuXianOpenManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_NEAR_LOCK == routeState)
						{ /*接近锁闭正常*/

							RouteNearLockManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_NEAR_LOCKERR == routeState)
						{ /*接近锁闭异常*/

							RouteNearLockErrManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_NEAR_OPEN == routeState)
						{ /*接近开放*/

							RouteNearOpenManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_DELAY_UNLOCK == routeState)
						{ /*延时解锁*/

							RouteDelayUnlockManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_AUTO_UNLOCK == routeState)
						{ /*自动解锁正常*/

							RoutePhySecAutoUnlockManage(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_STATE_AUTO_UNLOCKERR == routeState)
						{ /*自动解锁异常*/

							RoutePhySecAutoUnlockErrManage(pAllAutoReturnIncludeBuf[jj]);
						}

						else
						{
							/*状态异常*/
							/*xxxxx 宕机*/

							/*记录系统故障*/
							SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
								EFUNC_LOGIC_MANAGE_SYETEM,
								CI_ERROR,
								ETYPE_SYSTEM_EXCEPT,
								CI_ERROR, ESEND_LEVEL_ZERO);
						}

						/*获取进路状态*/
						routeState = GetRouteState(pAllAutoReturnIncludeBuf[jj]);

						if ((routeState != ROUTE_STATE_IDLE) &&
							(routeState != ROUTE_STATE_FIRST_XUANPAI) &&
							(routeState != ROUTE_STATE_XUANPAI) &&
							(routeState != ROUTE_STATE_LEAD_XUANPAI))
						{
							/*进路锁闭后需关闭信号处理*/
							RouteOpenNeedCloseSignal(pAllAutoReturnIncludeBuf[jj]);
						}

						/*#####进路取消处理#####*/
						if (ROUTE_ZONGQUXIAO_SET_YES == zongQuXiaoFlag)
						{ /*已办理总取消*/

							RouteZongQuXiaoProc(pAllAutoReturnIncludeBuf[jj]);
						}
						else if (ROUTE_ZONGRENJIE_SET_YES == zongRenJieFlag)
						{ /*已办理总人解*/

							RouteZongRenJieProc(pAllAutoReturnIncludeBuf[jj]);
						}
						else
						{/*不处理*/

						}
#endif
					}
				}
			}
		}
	}

}
/*
* 功能描述： 全自动折返进路触发处理
*			该函数在进路管理中，无条件执行。
*			根据当前进路的状态以及进路办理条件，自动触发进路办理。
*
*
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void AllAutoReturnManage(const UINT16 routeId)
{

	UINT8 autoRouteType = 0u;
	UINT8 allAutoReturnRouteType = 0u;

	UINT8 autoRouteFlg = 0u;			/* 进路触发办理条件 */
	UINT16 allAutoReturnId = 0u;
	UINT16* pAutoIncludeRouteIdbuf = NULL;
	UINT8 autoIncludeRouteSum = 0u;
	UINT8 ii = 0u;
	UINT8 checkResult = 0u;
	UINT8 routeValid = 0u;

	UINT16 startSigId = 0u;/*进路始端信号机ID*/
	UINT16 outFirstSectionId = 0u;/*外方第一物理区段ID*/

	UINT8 nearBlocSecConditionSum = 0u;	/*点式接近区段条件数量*/
	RouteNearPhySectionStruct* nearPhySecStru = NULL;	/*接近物理区段结构数组*/

	UINT32 orderOccupyStartCycle = 0u;/*顺序占用开始周期*/
	UINT8 hasNearSecFalg = 0u; /*是否有接近区段*/
	UINT8 virCIid = GetRouteBelongVirCiId(routeId);
	UINT16 recordErrorNum = GetErrorDataCurSum();
	UINT8 chPhySecSameFlag = 0U;/*区段重叠检查标志*/

	/*全自动进路自动办理*/
	autoRouteType = GetRouteAutoRouteSetState(routeId);
	allAutoReturnId = GetRouteAllAutoReturnId(routeId);

	/*
	 *  全自动折返进路: 折入进路满足条件并且有车接近，就可以办理；
						  折入进路满足条件并且无车接近，再判断与他相抵触的折出进路是否满足办理条件，不满足则仍可以办理折入进路；
	 *                    折出进路，除了满足办理条件以外，还需要满足列车在折返轨上并且触发时间比另一条折出进路的时间长
	 */
	if (autoRouteType == ROUTE_ALLAUTOROUTE_RETURN)
	{
		allAutoReturnRouteType = GetAllAutoReturnRouteType(allAutoReturnId, routeId);
		if (allAutoReturnRouteType == ALL_AUTO_RETURN_ROUTE_TYPE_IN)
		{
			checkResult = SetRouteProc(routeId);
			if (CI_SUCCESS == checkResult)
			{
				nearBlocSecConditionSum = GetRouteBlocNearSecConditionSum(routeId);	/*获取Bloc进路接近物理区段条件数目*/
				nearPhySecStru = GetRouteBlocNearPhySectionStru(routeId);	/*获取Bloc进路接近物理区段结构体*/

				if ((nearBlocSecConditionSum > 0u) && (NULL != nearPhySecStru))
				{/*有接近区段，计算信号机外方第一物理区段，取第一个接近区段*/
					if ((nearPhySecStru[0].NearPhySecIdBuf != NULL) && (nearPhySecStru[0].NearPhySecSum > 0u))
					{
						hasNearSecFalg = 1u;
					}
				}

				/*有接近区段，取第一组接近区段的第一个物理区段；没有就取信号机外方第一物理区段*/
				if (1u == hasNearSecFalg)
				{
					outFirstSectionId = nearPhySecStru[0].NearPhySecIdBuf[0];
				}
				else
				{
					startSigId = GetRouteStartSignalId(routeId);/*获取进路始端信号机ID*/
					outFirstSectionId = GetSignalOutFirstPhySecId(startSigId);/*获取信号机外方第一物理区段ID*/
				}

				orderOccupyStartCycle = GetSecCurOccupyStartCycNum(outFirstSectionId);/*获取信号机外方第一区段连续占用开始时间*/

				if (orderOccupyStartCycle > 0u)
				{/*顺序占用开始周期大于0，则表明该区段为顺序占用，可办折入*/
					autoRouteFlg = 1u;
				}
				else
				{   /*判断与本折入折返进路相抵触的折出进路是否满足办理条件，不满足，则仍可办理本折入进路*/
					autoIncludeRouteSum = GetAllAutoReturnIncludeRouteSum(allAutoReturnId);
					pAutoIncludeRouteIdbuf = GetAllAutoReturnIncludeRouteBuf(allAutoReturnId);
					for (ii = 0u; ii < autoIncludeRouteSum; ii++)
					{
						allAutoReturnRouteType = GetAllAutoReturnRouteType(allAutoReturnId, pAutoIncludeRouteIdbuf[ii]);
						if (ALL_AUTO_RETURN_ROUTE_TYPE_OUT == allAutoReturnRouteType)
						{
							routeValid = GetAllAutoReturnOutRouteValid(pAutoIncludeRouteIdbuf[ii]);
							/*修改原因：当折出的进路不满足办理条件但车在转换轨，此时折入的进路不允许办理，
							等待转换轨的车折出后才可办理*/
							if (CI_SUCCESS == routeValid)
							{
#if 0
								/*by cgh 20240320 折出进路满足办理条件，但当前折入进路与折出进路无区段重叠，此时折入进路可以办理*/
								chPhySecSameFlag = CheckRoutePhySecSame(routeId, pAutoIncludeRouteIdbuf[ii]);
								if (CI_SUCCESS == chPhySecSameFlag)
								{
									autoRouteFlg = 1u;
								}
								else
								{
									autoRouteFlg = 0u;     /*相抵触的折出进路满足办理条件*/
									break;
								}
#endif

								autoRouteFlg = 0u;     /*相抵触的折出进路满足办理条件*/
								break;
							}
							else
							{
								autoRouteFlg = 1u;
							}
						}
					}
				}
			}
		}
		else if (ALL_AUTO_RETURN_ROUTE_TYPE_OUT == allAutoReturnRouteType)
		{
			/*在满足本进路办理条件的基础上，判断另一条折出进路的触发时间是否比本进路的触发时间长，是则按照先入先出的原则，本进路不能办理*/
			checkResult = SetRouteProc(routeId);

			routeValid = GetAllAutoReturnOutRouteValid(routeId);
			if ((CI_SUCCESS == routeValid) && (CI_SUCCESS == checkResult))
			{
				autoRouteFlg = 1u;   /*办理折出进路*/
			}
			else
			{
				autoRouteFlg = 0u;
			}
		}
		else
		{
			/*不处理*/
			autoRouteFlg = 0u;
		}
	}
	else
	{
		/*普通进路不处理*/
		autoRouteFlg = 0u;
	}
	/* 触发办理进路，需要检查征用状态 */
	if (1u == autoRouteFlg)
	{

		/*进路物理区段未征用检查*/
		if (CI_SUCCESS == RoutePhySectionUseLogicProcess(routeId))
		{
#if 0
			/*全部区段未征用*/

			SetRouteStateManage(routeId, ROUTE_STATE_FIRST_XUANPAI);  /*-->设置进路初选*/

			/*进路初选处理*/
			RouteFirstXuanPaiManage(routeId);
#else
			SetCommonRouteLogicManage(routeId, ESEND_LEVEL_ATS);
#endif
	}
}
	/*cgh-合并CID-2349-5：*/
	SetErrorDataBelongVirCiId(recordErrorNum, virCIid);
}


/*
* 功能描述： 设置试车请求处理
*
*
* 参数说明： void
* 返回值  ： void
*/
void StartTrianTestManage(void)
{
	UINT8 localCiType = GetLocalCiType();
	UINT8 trainTestStatus = GetCiTrainTestStatus();
	/* 当本联锁是试车线同时本联锁未开始试车作业下，才处理试车请求命令 */
	if ((CI_TYPE_SCX == localCiType) && (CI_TRAIN_TEST_OFF == trainTestStatus))
	{
		SetCiTrainTestStatus(CI_TRAIN_TEST_START);

	}
}

/*
* 功能描述： 取消试车
*
*
* 参数说明： void
* 返回值  ： void
*/
void StopTrianTestManage(void)
{
	UINT8 localCiType = GetLocalCiType();
	UINT8 trainTestStatus = GetCiTrainTestStatus();
	/* 当本联锁是试车线同时本联锁未开始试车作业下，才处理试车请求命令 */
	if ((CI_TYPE_SCX == localCiType))
	{
		if (CI_TRAIN_TEST_ON == trainTestStatus)
		{
			SetCiTrainTestStatus(CI_TRAIN_TEST_STOP);
		}
		else if (CI_TRAIN_TEST_START == trainTestStatus)
		{
			SetCiTrainTestStatus(CI_TRAIN_TEST_OFF);
		}
		else
		{
			/* 不处理 */
		}
	}
}

/*
* 功能描述： 取消临时限速设置
* 参数说明： 无
* 返回值  ：
		   CI_ERROR 		 失败
		   CI_SUCCESS 		 成功
*/
UINT8 CancleLinShiXianSuManage(void)
{
	UINT16 ii;
	UINT16 logSecId = 0u;
	UINT8 state = 0u;
	UINT8 retVal = 0u;
	/*通信状态*/
	UINT8 comunicationState = 0u;
	UINT8 zcCommState = 0u;
	UINT8 localCi = 0u;
	UINT8* pSourceIdBuf = NULL;
	UINT8 dianshiLinshixiansuFlag = 0U;/*是否支持点式临时限速*/


	dianshiLinshixiansuFlag = GetCiFunctionSwitchConfig(FUNC_DIANSHI_LINSHIXIANSU_FLAG);
	localCi = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	pSourceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID*/

	if (pSourceIdBuf != NULL)
	{
		/*更新与ZC通信状态*/
		(void)UpdateCiTransmitState(localCi, CI_SYSTEM_TYPE_ZC, pSourceIdBuf[0]);
		zcCommState = GetHLHTHeadCtxValid(CI_SYSTEM_TYPE_ZC, pSourceIdBuf[0]);
		/*通信异常*/
		if (CI_ERROR == zcCommState)
		{
			comunicationState = TRANSMIT_STATE_BAD;
		}
		else
		{
			comunicationState = TRANSMIT_STATE_GOOD;
		}
	}
	if ((TRANSMIT_STATE_GOOD != comunicationState) && (HAVE_DIANSHILINSHIXIANSU == dianshiLinshixiansuFlag))
	{/*和ZC通信故障时，才允许人工取消临时限速*/
		for (ii = 0u; ii < GetLogicSecCurSum(); ii++)
		{
			logSecId = GetLogicSecId(ii);                                                          /*获取逻辑区段ID*/
			state = GetLogSecLinShiXianSuSetState(logSecId);                                       /*获取逻辑区段临时限速设置状态*/
			if (LOGSEC_LSXS_SET_STATE_INVALID != state)
			{/*具有临时限速属性*/
				SetLogSecLinShiXianSuState(logSecId, LOGSEC_LSXS_SET_STATE_NO);        /*取消临时限速*/
			}
		}
		retVal = CI_SUCCESS;
	}
	else
	{
		/*记录和发送故障码*/
		SetErrorData(EFUNC_CHECK_LABOUR_CANCEL_VALID,
			CI_DEVICE_TYPE_LOGICSEC,
			0,
			ETYPE_LOGSEC_LINSHIXIANSU_CANCLE_STATE,
			GetLabourCancelLinShiXianState(), ESEND_LEVEL_ATS);

		retVal = CI_ERROR;
	}

	LabourCancelLSXianStaMoveProc(LINSHIXIANSU_LABOURCANCLE_YES_STATE);  /*人工取消临时限速状态迁移*/
	return retVal;
}
/*
* 功能描述： 取消临时限速设置
* 参数说明： 无
* 返回值  ：void
*/
void CancleLinShiXianSuManage_Vir(const UINT8 virCIid)
{
	UINT16 ii = 0u;
	UINT16 logSecId = 0u;
	UINT8 state = 0u;
	/*通信状态*/
	UINT8 comunicationState = 0u;
	UINT8 zcCommState = 0u;
	UINT8 localCi = 0u;
	UINT8* pSourceIdBuf = NULL;
	UINT8 belongVirCIid = 0u;
	UINT8 labourCancelLinShiXianState = 0u;
	UINT8 dianshiLinshixiansuFlag = 0U;/*是否支持点式临时限速*/

	dianshiLinshixiansuFlag = GetCiFunctionSwitchConfig(FUNC_DIANSHI_LINSHIXIANSU_FLAG);
	localCi = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	pSourceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID*/
	labourCancelLinShiXianState = GetVirCILabourCancelLSXianSta(virCIid);
	if (pSourceIdBuf != NULL)
	{
		/*更新与ZC通信状态*/
		(void)UpdateCiTransmitState(localCi, CI_SYSTEM_TYPE_ZC, pSourceIdBuf[0]);
		zcCommState = GetHLHTHeadCtxValid(CI_SYSTEM_TYPE_ZC, pSourceIdBuf[0]);
		/*通信异常*/
		if (CI_ERROR == zcCommState)
		{
			comunicationState = TRANSMIT_STATE_BAD;
		}
		else
		{
			comunicationState = TRANSMIT_STATE_GOOD;
		}
	}
	if ((TRANSMIT_STATE_GOOD != comunicationState) && (HAVE_DIANSHILINSHIXIANSU == dianshiLinshixiansuFlag))
	{/*和ZC通信故障时，且联锁支持点式临时限速 才允许人工取消临时限速*/
		for (ii = 0u; ii < GetLogicSecCurSum(); ii++)
		{
			logSecId = GetLogicSecId(ii);                                                          /*获取逻辑区段ID*/
			state = GetLogSecLinShiXianSuSetState(logSecId);                                       /*获取逻辑区段临时限速设置状态*/
			belongVirCIid = GetLogSecBelongVirCiId(logSecId);
			if ((LOGSEC_LSXS_SET_STATE_INVALID != state) && (belongVirCIid == virCIid))
			{/*具有临时限速属性*/
				SetLogSecLinShiXianSuState(logSecId, LOGSEC_LSXS_SET_STATE_NO);        /*取消临时限速*/
			}
		}
	}
	else
	{


		/*记录和发送故障码,*/
		SetErrorData(EFUNC_CHECK_LABOUR_CANCEL_VALID,
			CI_DEVICE_TYPE_LOGICSEC,
			0u,
			ETYPE_LOGSEC_LINSHIXIANSU_CANCLE_STATE,
			labourCancelLinShiXianState, ESEND_LEVEL_ATS);

	}

	LaborCancelLSXSXStaMoveProc_Vir(LINSHIXIANSU_LABOURCANCLE_YES_STATE, virCIid);  /*人工取消临时限速状态迁移*/
}


/*
* 功能描述： 试车状态管理逻辑处理
*	在试车线状态调用该函数，该函数主要功能实现试车线状态转移
*     初始状态 -----|试车请求} ---- >试车开始 ---- |同意试车| -->试车中 --|试车结束| --> 试车结束
*         ↑---|试车结束|-- -------------↓                         |                        |
*          -----------------------|同意试车结束| -------------------↓------------------------↓
*
*
* 参数说明：
* 返回值  ：
*/
void CiTrainTestLogicManage(void)
{
	UINT8 trainTestStatus = GetCiTrainTestStatus();
	UINT8 interfaceType = GetCiFunctionSwitchConfig(SCX_CLD_INTERFACE_TYPE);/*获取试车线与车辆段接口方式*/

	NonRouteDataStruct* pNonRoute = NULL;
	UINT16 wCollAgreeTryTrainRelayId = 0U;/*试车线采集同意试车继电器ID*/
	UINT8 chRelayCollState = 0U;/*采集继电器状态*/
	UINT8 ii = 0;
	for (; ii < NONROUTE_ID_NUM_MAX; ii++)
	{
		pNonRoute = GetNonRouteDataPtr() + ii;
		wCollAgreeTryTrainRelayId = GetSCXColAgreeTryRelayIdById(pNonRoute->NonRouteId);
		chRelayCollState = GetRelayCollState(wCollAgreeTryTrainRelayId);
		switch (trainTestStatus)
		{
		case CI_TRAIN_TEST_START:	/* 试车请求按下 */
		{
			if (SCX_CLD_INTERFACE_RELAY == interfaceType)
			{/*试车线与车辆段使用继电器接口*/
				/* 试车请求按钮按下后，采集到同意试车，则进入到试车状态 */
				if (RELAY_STATE_UP == chRelayCollState)
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_ON);
				}
			}
			else if ((SCX_CLD_INTERFACE_COMM == interfaceType) || (SCX_CLD_SERIAL_PORT_COMM == interfaceType))
			{/*试车线与车辆段使用通信接口*/
				if (COMM_TRAIN_TEST_DEV_STATE_VALID == GetCommTrainTestSCXYSKJStatus())
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_ON);
				}
			}
			else if (SCX_NONELOCAL_MODE == interfaceType)
			{
				SetCommTrainTestSCXYSKJStatus(COMM_TRAIN_TEST_DEV_STATE_VALID);
				SetCommTrainTestSCXSQAJStatus(COMM_TRAIN_TEST_DEV_STATE_VALID);
				SetCiTrainTestStatus(CI_TRAIN_TEST_ON);
			}
			else
			{
				/*不存在的接口方式*/
			}
		}
		break;
		case CI_TRAIN_TEST_STOP:	/* 试车请求按钮取消  */
			if (SCX_CLD_INTERFACE_RELAY == interfaceType)
			{/*试车线与车辆段使用继电器接口*/
				if (RELAY_STATE_DOWN == chRelayCollState)
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_OFF);
				}
			}
			else if ((SCX_CLD_INTERFACE_COMM == interfaceType) || (SCX_CLD_SERIAL_PORT_COMM == interfaceType))
			{/*试车线与车辆段使用通信接口*/
				if (COMM_TRAIN_TEST_DEV_STATE_INVALID == GetCommTrainTestSCXYSKJStatus())
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_OFF);
				}
			}
			else if (SCX_NONELOCAL_MODE == interfaceType)
			{
				SetCommTrainTestSCXYSKJStatus(COMM_TRAIN_TEST_DEV_STATE_INVALID);
				SetCommTrainTestSCXSQAJStatus(COMM_TRAIN_TEST_DEV_STATE_INVALID);
				SetCiTrainTestStatus(CI_TRAIN_TEST_OFF);
			}
			else
			{
				/*不存在的接口方式*/
			}
			break;
		case CI_TRAIN_TEST_ON:
			if (SCX_CLD_INTERFACE_RELAY == interfaceType)
			{/*试车线与车辆段使用继电器接口*/
				/* 试车中,未采集到同意试车，则为退回试车请求 */
				if (RELAY_STATE_DOWN == chRelayCollState)
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_START);
				}
			}
			else if ((SCX_CLD_INTERFACE_COMM == interfaceType) || (SCX_CLD_SERIAL_PORT_COMM == interfaceType))
			{/*试车线与车辆段使用通信接口*/
				if (COMM_TRAIN_TEST_DEV_STATE_INVALID == GetCommTrainTestSCXYSKJStatus())
				{
					SetCiTrainTestStatus(CI_TRAIN_TEST_START);
				}
			}
			else
			{
				/*不存在的接口方式*/
			}
			break;
		default:
			/*不可达分支*/
			break;
		}

		if (CI_TRAIN_TEST_ON != GetCiTrainTestStatus())
		{
			DriveAllSignaleRedClose();
		}
	}
}

/*
* 功能描述： 驱动关信号
* 参数说明： 无
* 返回值  ： 无
*/
void DriveAllSignaleRedClose(void)
{
	UINT16 signalSum = GetSignalCurSum();
	UINT16 ii = 0u;
	for (ii = 0u; ii < signalSum; ii++)
	{
		UINT16 signalId = GetSignalId(ii);
		/* 本机 */
		if (GetSignalBelongCiId(signalId) == GetSystemParaLocalCiId())
		{
			SetSignalCurDriveColor(signalId, SIGNAL_DRIVECOLOUR_REDCLOSE);
		}
	}
}

/*
* 功能描述： 进路初选-取消自动信号进路等待区段锁闭检查通过
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
			 CI_SUCCESS:取消自动信号进路后区段锁闭检查成功
			 CI_ERROR:取消自动信号进路后区段锁闭检查失败
			 RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT:等待取消
*/
UINT8 RouteFirstXuanAutoSigCancelPro(const UINT16 routeId)
{
	UINT8 i = 0u;/*游标*/
	UINT8 retVal = CI_ERROR;/*返回值变量*/
	UINT8 funcRetVal = CI_SUCCESS;/*返回值变量*/
	UINT8 autoSigRouteIncludeSum = 0u;/*反向进路包含的自动信号进路数目*/
	UINT16* autoSigRouteIncludeIdBuf = NULL;/*反向进路包含的自动信号进路数组*/
	UINT16 devId = 0u;/*设备Id*/
	UINT8 devState = 0u;/*设备状态*/
	UINT16 belongRouteId = 0u;/*区段所属进路Id*/
	UINT8 checkSecLockResult = 0u;/*进路包含区段锁闭检查结果*/
	UINT8 funcSwitch = 0U;
	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
	if (ROUTE_REVERSE_PROPERTY_NO == GetRouteReverseProperty(routeId))
	{/*不具备反向属性*/
		retVal = CI_SUCCESS;
	}
	else
	{
		funcRetVal = RouteFirstXuanAutoSigProc(routeId);

		autoSigRouteIncludeSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含的自动信号进路条数*/
		autoSigRouteIncludeIdBuf = GetReverseRouteIncludeRouteBuf(routeId);/*获取反向进路包含的自动信号进路Id数组*/

		if (CI_SUCCESS == funcRetVal)
		{/*如果取消自动信号进路成功，检查反向进路内物理区段锁闭状态*/
			if (FUNC_SWITCH_ON == funcSwitch)
			{
				/*modify 20221008 适配进路驱动道岔提前扳动功能*/
				checkSecLockResult = ReverseRouteLogSecLockValCheck(routeId, &devId, &devState);
			}
			else
			{
				checkSecLockResult = BlockRouteSecLockValidCheck(routeId, &devId, &devState);
			}

			if (CI_SUCCESS == checkSecLockResult)
			{
				/* 检查通过 */
				retVal = CI_SUCCESS;
			}
			else
			{
				/*遍历反向进路包含的自动信号进路，判断锁闭检查未通过区段是否属于自动信号进路，若是则返回等待，否则返回错误*/
				belongRouteId = GetPhySecRLockBelongRouteId(devId);
				if (belongRouteId == 0u)
				{
					/* 查看是否是属于防护锁闭 */
					belongRouteId = GetPhySecPLockBelongRouteId(devId);
				}
				if (belongRouteId != 0u)
				{
					for (i = 0u; i < autoSigRouteIncludeSum; i++)
					{
						if (belongRouteId == autoSigRouteIncludeIdBuf[i])
						{
							/*锁闭检查未通过区段属于自动信号进路*/
							retVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT; /*等待标志*/
							break;					/*只要属于自动信号，则返回等待*/
						}
						else
						{
							/*锁闭检查未通过区段不属于自动信号进路*/
							retVal = CI_ERROR;/*错误标志*/

						}
					}
				}
				else
				{
					retVal = CI_ERROR;
				}
			}
		}
		else if (RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT == funcRetVal)
		{
			/*如果等待取消自动信号进路，则返回等待*/
			retVal = RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT; /*等待标志*/
		}
		else
		{
			/*取消自动信号进路失败，则返回错误*/
			retVal = CI_ERROR;/*错误标志*/
		}

	}

	return retVal;
}

/*
* 功能描述： 进路状态转移管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteStateFlagManage(const UINT16 routeId)
{
	UINT8 returnValueFunc1 = 0u;    /*返回值定义*/
	UINT16 atsExpLkOverlapId = 0U;
	UINT8 routeStateFlag = 0U;
	UINT8 OverlapFromSetRouteCmdFlag = 0U;
	UINT8 routeState = 0u;        /*进路状态*/

	/*办理进路处理*/
	if (CI_SUCCESS == SetRouteProc(routeId))
	{ /*办理成功*/

		/*进路初选处理*/
		returnValueFunc1 = RouteFirstXuanProc(routeId);

		if (CI_ERROR == returnValueFunc1)
		{
			/*征用失败 */

			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_NO);  /*-->设置进路状态转移标志无效*/
		}
		else if (CI_SUCCESS == returnValueFunc1)
		{
			/*征用成功*/
			if (GetRouteXuanPaiStartCycNum(routeId) == 0u)
			{
				(void)SetRouteXuanPaiStartCycNum(routeId, Get2oo2CurCycleNum());
			}

			/*进路选排处理*/
			RouteXuanPaiStateManage(routeId);
		}
		else if (RETURN_FIRSTXUANPAI_ERR_WAIT == returnValueFunc1)
		{
			/*等待*/
		}
		else
		{
			/*无操作*/
		}
	}
	else
	{
		/*进路办理失败*/

		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

		SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_NO);  /*-->设置进路状态转移标志无效*/

	}

	routeStateFlag = GetRouteStateFlag(routeId);
	if (ROUTE_STATE_FLAG_NO == routeStateFlag)
	{
		atsExpLkOverlapId = GetRouteAtsExpLkOverlapId(routeId);
		if (0U < atsExpLkOverlapId)
		{
			routeState = GetRouteState(routeId);
			OverlapFromSetRouteCmdFlag = GetOverlapFromSetRouteCmdFlag(atsExpLkOverlapId);
			if ((OVERLAP_ROUTE_FLAG_YES == OverlapFromSetRouteCmdFlag)&&((ROUTE_STATE_AUTO_UNLOCK== routeState)||(ROUTE_STATE_IDLE == routeState)))		/*从ATS来的办进路命令，但是不满足追踪，清除期望办理的保护区段*/
			{
				/*办理失败把连带标志清除，办理成功设置防护锁闭状态会清除该标志*/
				SetOverlapFromSetRouteCmdFlag(atsExpLkOverlapId, OVERLAP_ROUTE_FLAG_NO);
				SetRouteAtsExpLkOverlapId(routeId, 0u);	/*清除ATS或现地期望锁闭保护区段ID*/
			}
		}
	}
}


/*
* 功能描述： 进路选排状态转移管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* modify 20221011 适配进路提前驱动道岔新功能
*/
void RouteXuanPaiStateManage(const UINT16 routeId)
{
	UINT8 returnValue = 0u;    /*返回值定义*/
	UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE; /*带动道岔是否需要被驱动*/
	UINT8 routSwitDrvOvtmFlag = 0u;/*进路内道岔是否驱动超时标志*/

	/*进路锁闭管理*/
	returnValue = LockRouteProc(routeId);

	NeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(routeId);/*检查进路带动道岔组是否需要被驱动*/

	routSwitDrvOvtmFlag = ChekRoutSwitDrivOvtmStat(routeId);/*检查进路内道岔是否驱动超时*/

	if ((CI_SUCCESS == returnValue) && (SWITCH_NEED_DRIV_FALSE == NeedForDrvRoutAssoSwit))
	{
		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

		/*锁闭成功*/
		SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/

		/*进路初锁处理*/
		RouteFirstLockManage(routeId);
		SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_NO);  /*-->设置进路状态转移标志无效*/
	}
	else if (((RETURN_LOCK_ERR_SWITPOS == returnValue) && (CI_SUCCESS == routSwitDrvOvtmFlag)) ||
		((SWITCH_NEED_DRIV_TRUE == NeedForDrvRoutAssoSwit) && (CI_SUCCESS == returnValue)))
	{
		/*道岔位置不正确*/

		/*进路锁闭驱动道岔*/
		if (CI_ERROR == RouteLockDriveSwitch(routeId, NeedForDrvRoutAssoSwit))
		{
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

			/* 单操取消办理 */
			SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_NO);  /*-->设置进路状态转移标志无效*/
		}
	}
	else if (RETURN_LOCK_ERR_WAIT_SWCHECK == returnValue)
	{
		/*等待相邻联锁反馈道岔检查状态*/
		;
	}
	else
	{
		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

		/* 进路锁闭失败 */
		SetRouteStateFlag(routeId, ROUTE_STATE_FLAG_NO);  /*-->设置进路状态转移标志无效*/
	}

}

/*
* 功能描述： 互联互通进路锁闭Overlap处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： 无
*/
static void LockRouteOverlapManageHlht(const UINT16 routeId)
{
	UINT8 routeState = 0u;
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT16 i = 0u;
	UINT16 tempOvlpId = 0u;

	UINT8 swRet = CI_ERROR;
	UINT8 ovlpSwSum = 0u;
	OverlapConditionSwitchStruct* tempSwCondBuf = NULL;

	UINT16 swId = 0u;
	UINT8  swCurPos = 0u;
	UINT8  switchPos = 0u;
	UINT16 j = 0u;

	UINT8 phyRet = CI_ERROR;
	UINT8 phySecSum = 0u;/*保护区段包含的物理区段数目*/
	UINT16* phySecBuf = NULL;/*保护区段包含的物理区段数组*/
	UINT16 tempPhySec = 0u;

	UINT8 ovlpLocked = 0u;

	routeState = GetRouteState(routeId);

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/

	if ((0u < overlapSum) && (NULL != overlapIdBuf))
	{
		if ((routeState == ROUTE_STATE_FIRST_LOCK) ||
			(routeState == ROUTE_STATE_FIRST_LOCKERR) ||
			(routeState == ROUTE_STATE_YUXIAN_OPEN) ||
			(routeState == ROUTE_STATE_YUXIAN_LOCK) ||
			(routeState == ROUTE_STATE_NEAR_OPEN) ||
			(routeState == ROUTE_STATE_NEAR_LOCK) ||
			(routeState == ROUTE_STATE_NEAR_LOCKERR) ||
			(routeState == ROUTE_STATE_AUTO_UNLOCK)
			)
		{
			/*说明仍然需要锁闭保护区段*/
			if (ROUTE_OVERLAP_SET_YES != GetRouteOverlapLockFlag(routeId))
			{
				/*说明保护区段还未锁闭*/
				for (i = 0u; i < overlapSum; i++)
				{
					tempOvlpId = overlapIdBuf[i];

					phyRet = CI_SUCCESS;
					/*检查包含的物理区段锁闭条件*/
					phySecSum = GetOverlapPhySecSum(tempOvlpId);
					phySecBuf = GetOverlapPhySecIdBuf(tempOvlpId);
					if ((phySecSum > 0u) && (phySecBuf != NULL))
					{
						for (j = 0u; j < phySecSum; j++)
						{
							tempPhySec = phySecBuf[j];

							if ((0U < GetPhySecPLockBelongRouteId(tempPhySec)) && (GetPhySecLockDirection(tempPhySec) == GetRouteDirection(routeId)))
							{
								/*do nothing*/
							}
							else
							{
								break;
							}
						}

						if (j < phySecSum)
						{
							phyRet = CI_ERROR;
						}
					}
					else
					{
						phyRet = CI_ERROR;
					}

					if (CI_SUCCESS == phyRet)
					{
						swRet = CI_SUCCESS;
						ovlpSwSum = GetOverlapSwitchSum(tempOvlpId);
						tempSwCondBuf = GetOverlapCondSwitchStruct(tempOvlpId);
						if ((ovlpSwSum > 0u) && (tempSwCondBuf != NULL))
						{
							/*开始检查*/
							for (j = 0u; j < ovlpSwSum; j++)
							{
								swId = tempSwCondBuf[j].SwitchId;
								swCurPos = GetSwitchCurPosition(swId);
								switchPos = tempSwCondBuf[j].SwitchPosition;
								if (switchPos != swCurPos)
								{
									/*道岔位置不正确*/
									swRet = CI_ERROR;
									break;
								}
							}
						}
					}

					if ((CI_SUCCESS == swRet) && (CI_SUCCESS == phyRet))
					{
						ovlpLocked = 1u;
						break;
					}
				}

				if (1u == ovlpLocked)
				{
					/*设置进路保护锁闭状态*/
					SetOverlapLockState(tempOvlpId, PHYSICAL_SECTION_LOCK_PROTECT, routeId);  /*设置Overlap防护锁闭*/
				}
				else
				{
					/*说明保护区段还未锁闭*/
					for (i = 0u; i < overlapSum; i++)
					{
						tempOvlpId = overlapIdBuf[i];

						/*检查保护区段是否满足互联互通锁闭条件*/
						if (CI_SUCCESS == LockOthCiOvlpCheckHlht(routeId, tempOvlpId))
						{
							/*只要有一个保护区段可尝试锁闭，就会通过进路的终端信号机发送锁闭命令*/
							SetSignalPLockCommand(GetRouteEndSignalId(routeId), SIGNAL_PLOCK_CMD_CREATE);
							break;
						}
					}
				}
			}
		}
	}
}


/*
* 功能描述： 互联互通进路解锁锁Overlap处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
static void UnlockRouteOverlapManageHlht(const UINT16 routeId)
{
	UINT8 routeState = 0u;
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT16 i = 0u;

	UINT8 phySecSum = 0u;/*保护区段包含的物理区段数目*/
	UINT16* phySecBuf = NULL;/*保护区段包含的物理区段数组*/

	UINT16 lockedOvlpId = 0u;/*保护区段ID，其包含的所有物理区段，均处于保护锁闭状态*/

	UINT16 const routeLastSecId = GetRouteLastPhySectionId(routeId);
	UINT16 const secStopFlag = GetPhySecStopSteadyFlag(routeLastSecId);
	UINT8 const secStopTimeState = SystemOverTimeCheck(GetSecCurOccupyStartCycNum(routeLastSecId),
		GetSystemParaProtSecUnlockCyc());
	UINT8 const secLockState = GetPhySecLockState(routeLastSecId);
	UINT8 toUnLock = 0u;/*标记是否可以解保护区段*/

	routeState = GetRouteState(routeId);

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/

	if ((0u < overlapSum) && (NULL != overlapIdBuf))
	{
#if 0
		for (i = 0u; i < overlapSum; i++)
		{
			tempOvlpId = overlapIdBuf[i];

			/*检查包含的物理区段锁闭条件*/
			phySecSum = GetOverlapPhySecSum(tempOvlpId);
			phySecBuf = GetOverlapPhySecIdBuf(tempOvlpId);

			for (j = 0u; j < phySecSum; j++)
			{
				if ((GetPhySecPLockBelongRouteId(phySecBuf[j]) > 0u) && (GetPhySecLockDirection(phySecBuf[j]) == GetRouteDirection(routeId)))
				{
					/*说明保护区段内的物理区段还处于进路方向锁闭状态*/
				}
				else
				{
					break;
				}
			}

			if (j == phySecSum)
			{
				/*说明存在一条保护区段，其内部的所有物理区段，都沿着当前进路同向保护锁闭*/
				break;
}
		}
#endif
		lockedOvlpId = GetRouteLockedOvlpHlht(routeId);

		if (lockedOvlpId > 0u)
		{/*说明进路的某一条保护区段仍然处于锁闭状态*/
			phySecSum = GetOverlapPhySecSum(lockedOvlpId);
			phySecBuf = GetOverlapPhySecIdBuf(lockedOvlpId);

			for (i = 0u; i < phySecSum; i++)
			{
				if (GetPhySecCurMergeState(phySecBuf[i]) != SECTION_OCCUPY_NO)
				{
					break;
				}
			}

			if (i == phySecSum)
			{
#if 0
				/*说明保护区段内的物理区段已全部出清*/
				if ((PHYSICAL_SECTION_LOCK_NO == secLockState) || (GetRouteDirection(routeId) != GetPhySecLockDirection(routeLastSecId)) || ((secStopTimeState == CI_TIME_IN) && (secStopFlag == PHYSICAL_SECTION_STOPSTEADY_YES)) || (secStopTimeState == CI_TIME_OUT))
				{
					SetSignalPLockCommand(GetRouteEndSignalId(routeId), SIGNAL_PLOCK_CMD_CANCEL);
				}
#endif

				toUnLock = 0u;/*设置成不可以解保护区段*/

				if (PHYSICAL_SECTION_LOCK_NO == secLockState)
				{
					/*最后一个物理区段未锁闭则可以解锁*/
					/* 直接解锁保护区段 */
					toUnLock = 1u;
				}
				else
				{
					if (GetRouteDirection(routeId) == GetPhySecLockDirection(routeLastSecId))
					{/*说明进路最后的物理区段锁闭方向与进路的方向相同*/
						if (GetPhySecCurMergeState(routeLastSecId) == SECTION_OCCUPY_YES)
						{
							if (((PHYSICAL_SECTION_STOPSTEADY_YES == secStopFlag) && (CI_TIME_IN == secStopTimeState)) || (CI_TIME_OUT == secStopTimeState))
							{
								toUnLock = 1u;
							}
							else
							{
								/*未挺稳且挺稳倒计时未到，不能解锁保护区段*/
							}
						}
						else
						{
							/*最后一个物理区段锁闭但未占用，不可以解锁*/
						}
					}
					else
					{
						/*最后一个物理区段已经反方向锁闭，保护区段可以解锁*/
						toUnLock = 1u;
					}
				}

				if (1u == toUnLock)
				{
					SetSignalPLockCommand(GetRouteEndSignalId(routeId), SIGNAL_PLOCK_CMD_CANCEL);
				}
			}
		}
	}
}

/*
* 功能描述： 为互联互通CI锁闭本方保护区段时，设置Overlap防护锁闭
* 参数说明：
* const UINT16 overlapId, 保护区段ID
* const UINT8 lockState, 锁闭状态
* const UINT8 lockDir，锁闭方向
* 返回值  ： 无
*/
static void SetOvlpLockStateForHlhtCi(const UINT16 overlapId, const UINT8 lockState, const UINT8 lockDir)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT16* pPhySecIdBuf = NULL;  /*物理区段结构指针*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 cLogicSectionSum = 0u;  /*逻辑区段总数*/
	UINT16* pLogicSectionIdBuf = NULL;  /*逻辑区段ID数组*/
	UINT8 cLogicSectionLockState = 0u;


	phySecSum = GetOverlapPhySecSum(overlapId);  /*获取overlap物理区段总数*/
	pPhySecIdBuf = GetOverlapPhySecIdBuf(overlapId);  /*获取overlap物理区段ID数组*/
	cLogicSectionSum = GetOverlapLogicSectionSum(overlapId);
	pLogicSectionIdBuf = GetOverlapLogicSectionBuf(overlapId);


	if (0u < phySecSum)
	{
		if ((PHYSICAL_SECTION_LOCK_PROTECT == lockState) ||
			(PHYSICAL_SECTION_LOCK_NO == lockState))
		{ /*区段状态无效*/

			/*设置Overlap区段状态*/
			for (ii = 0u; ii < phySecSum; ii++)
			{
				SetPhySecLockState(pPhySecIdBuf[ii], lockState, UINT16_MAX, lockDir);
			}

			if (PHYSICAL_SECTION_LOCK_PROTECT == lockState)
			{ /*防护锁闭*/

				/*设置保护区段所属进路ID*/
				SetOverlapBelongRouteId(overlapId, UINT16_MAX);

				/*设置保护区段关联防护道岔为防护锁闭*/
				SetOverlapRelateProtSwLockSta(overlapId, SWITCH_LOCK_PROTECT_SET);

				/*清除保护区段相关道岔期望驱动位置*/
				ClearOverlapSwitchDrivePos(overlapId);

				/*清除保护区段关联道岔单操位置*/
				ClearOverlapSwitchDanCaoPos(overlapId);
				/* 设置逻辑区段防护锁闭 */
				cLogicSectionLockState = LOG_SECTION_LOCK_PROTECT;

			}
			else
			{ /*未锁闭*/
				/*设置防护区段锁闭进路ID为0*/
				SetOverlapBelongRouteId(overlapId, 0u);
				/*取消保护区段关联防护道岔的防护锁闭*/
				SetOverlapRelateProtSwLockSta(overlapId, SWITCH_LOCK_PROTECT_CANCEL);
				/*清除申请解锁保护区段标志*/
				SetOverlapUnlockApplyFlag(overlapId, UNLOCK_OVERLAP_APPLY_NO);
				/* 设置逻辑区段未锁闭 */
				cLogicSectionLockState = LOG_SECTION_LOCK_NO;

			}


			if ((LOG_SECTION_LOCK_NO == cLogicSectionLockState) || (LOG_SECTION_LOCK_PROTECT == cLogicSectionLockState))
			{
				/* 设置逻辑区段防护锁闭状态 */
				for (ii = 0u; ii < cLogicSectionSum; ii++)
				{
					SetLogSecLockState(pLogicSectionIdBuf[ii], cLogicSectionLockState, UINT16_MAX, lockDir);
				}
			}
			else
			{

			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 互联互通进路保护区段解锁状态判断
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ：
	0:不存在某一条保护区段，其包含的所有物理全均保护锁闭
	>0:某一条保护区段，其包含的所有物理全均保护锁闭
*/
static UINT16 GetRouteLockedOvlpHlht(const UINT16 routeId)
{
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT16 i = 0u, j = 0u;
	UINT16 tempOvlpId = 0u;

	UINT8 phySecSum = 0u;/*保护区段包含的物理区段数目*/
	UINT16* phySecBuf = NULL;/*保护区段包含的物理区段数组*/

	UINT16 lockOvlpId = 0u;/*包含的所有物理区段都处于保护锁闭的保护区段ID*/

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	overlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/

	if (0u < overlapSum)
	{
		for (i = 0u; i < overlapSum; i++)
		{
			tempOvlpId = overlapIdBuf[i];

			/*检查包含的物理区段锁闭条件*/
			phySecSum = GetOverlapPhySecSum(tempOvlpId);
			phySecBuf = GetOverlapPhySecIdBuf(tempOvlpId);

			for (j = 0u; j < phySecSum; j++)
			{
				if ((GetPhySecPLockBelongRouteId(phySecBuf[j]) > 0u) && (GetPhySecLockDirection(phySecBuf[j]) == GetRouteDirection(routeId)))
				{
					/*说明保护区段内的物理区段还处于锁闭状态（与进路方向相同）*/
				}
				else
				{
					break;
				}
			}

			if (j == phySecSum)
			{
				/*说明存在一条保护区段，其内部的所有物理区段，都沿着当前进路同向保护锁闭*/
				break;
			}
		}

		if (i == overlapSum)
		{
			/*说明进路的所有保护区段都处于未锁闭状态*/
			lockOvlpId = 0u;
		}
		else
		{
			lockOvlpId = tempOvlpId;
		}
	}
	else
	{
		lockOvlpId = 0u;/*无保护区段，认为进路的保护区段处于未锁闭状态*/
	}

	return lockOvlpId;
}

/*
* 功能描述：设置指定OverlapId所包含的所有道岔征用（或未征用）
* 参数说明： UINT16 overlapId, 保护区段ID
*            UINT8 usingState 是否征用 SWITCH_USING_YES：已征用   SWITCH_USING_NO：未征用
*/
void SetOverlapRelSwitchUsing(UINT16 overlapId, UINT8 usingState)
{
	UINT8 ii = 0U;
	UINT8 overlapContainSwitchSum = 0u;
	OverlapConditionSwitchStruct* pOverlapContainSwitchSumIdBuf = NULL;
	UINT16 containSwitchId = 0u;
	UINT16 proSwitchId = 0u;

	OverlapProtectSwitchStruct* pOverlapProSwitchBuf = NULL;
	UINT16 overlapProSwitchSum = 0u;
	UINT8 cLocalCiId = 0U;
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属控区*/
	UINT8 cCommState = 0U;  /*与防护道岔控区通信状态*/
	UINT8 cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);  /*相邻联锁间是否有继电接口*/
	UINT8 cConfirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();  /*继电接口确认状态*/
	UINT8 cSwitchCurUsingState = 0U;  /*道岔当前征用状态*/

	overlapContainSwitchSum = GetOverlapSwitchSum(overlapId);/*获取保护区段内的道岔数量*/
	pOverlapContainSwitchSumIdBuf = GetOverlapCondSwitchStruct(overlapId);/*获取保护区段内的道岔数据*/

	overlapProSwitchSum = GetOverlapRelatedProtSwitSum(overlapId);/*获取保护区段防护道岔数量*/
	pOverlapProSwitchBuf = GetOverlapRelatedProtSwitStru(overlapId);/*获取保护区段防护道岔数据*/

	cLocalCiId = GetSystemParaLocalCiId();

	/* 设置道岔征用状态结束 */
	if ((NULL != pOverlapContainSwitchSumIdBuf) && (NULL != pOverlapProSwitchBuf) && (0U != cLocalCiId))
	{
		/*遍历保护区段内的条件道岔*/
		for (ii = 0U; ii < overlapContainSwitchSum; ii++)
		{
			/*获取道岔ID*/
			containSwitchId = pOverlapContainSwitchSumIdBuf[ii].SwitchId;

			if (SWITCH_USING_YES == usingState)
			{
				/*设置道岔征用*/
				SetSwitchUsingState(containSwitchId, SWITCH_USING_YES, overlapId);
			}
			else if (SWITCH_USING_NO == usingState)
			{
				/*设置道岔未征用*/
				SetSwitchUsingState(containSwitchId, SWITCH_USING_NO, overlapId);
			}
			else
			{
				/*不做处理*/
			}
		}
		
		cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);  /*相邻联锁间是否有继电接口开关*/
		cConfirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();  /*继电接口确认状态*/

		/*遍历保护区段的防护道岔（防护道岔存在跨控区场景需区别处理）*/
		for (ii = 0U; ii < overlapProSwitchSum; ii++)
		{
			proSwitchId = pOverlapProSwitchBuf[ii].ProtectSwitchId;
			cSwitchCurUsingState = GetSwitchUsingState(proSwitchId);
			cSwitchBelongCiId = GetSwitchBelongCiId(proSwitchId);
			if (SWITCH_USING_YES == usingState)
			{
				if (cLocalCiId == cSwitchBelongCiId)
				{
					/*设置道岔征用*/
					SetSwitchUsingState(proSwitchId, SWITCH_USING_YES, overlapId);
				}
				else
				{
					cCommState = GetLocalCiAndOtherCiTransSta(cSwitchBelongCiId);  /*本联锁与防护道岔联锁通信状态*/
					if ((TRANSMIT_STATE_BAD == cCommState) && (CICI_RELAY_INTERFACE_CONFIRM_YES == cConfirmRelayInterfaceFlag) && (FUNC_SWITCH_ON == cFuncSwitch))
					{
						/*设置道岔征用*/
						SetSwitchUsingState(proSwitchId, SWITCH_USING_YES, overlapId);
					}
					else
					{
						if (SWITCH_USING_NO == cSwitchCurUsingState)
						{
							/*设置道岔申请征用*/
							SetSwitchUsingState(proSwitchId, SWITCH_USING_APPLY, overlapId);
						}
						else
						{
							/*已征用/申请征用，不处理*/
						}
					}
				}
			}
			else if (SWITCH_USING_NO == usingState)
			{
				if (cLocalCiId == cSwitchBelongCiId)
				{
					/*设置道岔未征用*/
					SetSwitchUsingState(proSwitchId, SWITCH_USING_NO, overlapId);
				}
				else
				{
					cCommState = GetLocalCiAndOtherCiTransSta(cSwitchBelongCiId);  /*本联锁与防护道岔联锁通信状态*/
					if ((TRANSMIT_STATE_BAD == cCommState) && (CICI_RELAY_INTERFACE_CONFIRM_YES == cConfirmRelayInterfaceFlag) && (FUNC_SWITCH_ON == cFuncSwitch))
					{
						/*设置道岔未征用*/
						SetSwitchUsingState(proSwitchId, SWITCH_USING_NO, overlapId);
					}
					else
					{
						if ((SWITCH_USING_YES == cSwitchCurUsingState) || (SWITCH_USING_APPLY == cSwitchCurUsingState))
						{
							/*设置道岔申请取消征用*/
							SetSwitchUsingState(proSwitchId, SWITCH_USING_CANCEL, overlapId);
						}
						else
						{
							/*未征用且未申请征用，不处理*/
						}
					}
				}
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*入参检查失败，不处理*/
	}
}

/*
* 功能描述：获取指定RouteId所包含的所有道岔是否征用
* 参数说明： UINT16 routeId, 进路ID
* 返回值：   UINT8 是否征用 CI_ERROR：已征用   CI_SUCCESS：未征用
*/
UINT8 CheckRouteContainSwitchUseSta(UINT16 routeId)
{
	UINT8 ii = 0;
	UINT8 jj = 0;
	UINT8 const routeContainSwitchSum = GetRouteSwitchSum(routeId);
	RouteSwitchStruct* const pRouteContainSwitchSumIdBuf = GetRouteSwitchData(routeId);
	UINT8 overlapContainSwitchSum = 0u;
	OverlapConditionSwitchStruct* overlapContainSwitchSumIdBuf = NULL;
	UINT16 switchBelongOverlapId = 0u;
	UINT16 AssocswitchBelongOverlapId = 0u;

	RouteProtectSwitchStruct* pRouteProSwitchData = NULL;/*进路防护道岔数据*/
	UINT16 routeProSwitchSum = 0u;/*进路防护道岔数量*/

	OverlapProtectSwitchStruct* pOverlapProSwitchData = NULL;/*保护区段防护道岔数据*/
	UINT16 overlapProSwitchSum = 0u;

	UINT8 AssocswitchSum = 0u; 									/*道岔数目*/
	UINT8 kk = 0;											/*循环变量*/
	UINT8 returnValue = CI_SUCCESS;
	RouteAssocSwitchStruct routeAssocSwitchStru = { 0u };		/*带动道岔数据*/
	AssocswitchSum = GetRouteAssocSwitchSum(routeId); /*获取进路带动道岔数目*/

	pRouteProSwitchData = GetRouteRelatedProtSwitchData(routeId);/*获取进路防护道岔数据*/
	routeProSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);/*获取进路防护道岔数量*/

	/* 设置道岔征用状态结束 */
	if ((NULL == pRouteContainSwitchSumIdBuf) || (NULL == pRouteProSwitchData))
	{
		/*道岔指针为空*/
	}
	else
	{
		/*遍历道岔  有一个已被征用 则返回已被征用*/
		for (ii = 0U; ii < routeContainSwitchSum; ii++)
		{
			switchBelongOverlapId = GetSwitchBelongOverlapId(pRouteContainSwitchSumIdBuf[ii].SwitchId);
			if (switchBelongOverlapId > 0u)
			{
				/*道岔所属保护区段ID大于0 表示有被保护区段征用 返回值先置为CI_ERROR*/
				returnValue = CI_ERROR;

				/*此时虽然被征用 但如果保护区段对道岔期望位置与进路对道岔期望位置一致 则返回成功 进路可以初锁*/
				/*根据征用道岔的保护区段ID获取该保护区段所包含道岔数据*/
				overlapContainSwitchSum = GetOverlapSwitchSum(switchBelongOverlapId);
				overlapContainSwitchSumIdBuf = GetOverlapCondSwitchStruct(switchBelongOverlapId);

				/*遍历保护区段包含的所有道岔 找到与上一级循环中循环到的道岔ID一致的保护区段包含道岔数据*/
				for (jj = 0U; jj < overlapContainSwitchSum; jj++)
				{
					if ((overlapContainSwitchSumIdBuf[jj].SwitchId == pRouteContainSwitchSumIdBuf[ii].SwitchId) &&
						(overlapContainSwitchSumIdBuf[jj].SwitchPosition == pRouteContainSwitchSumIdBuf[ii].SwitchPosition))
					{
						/*若保护区段 进路对该道岔的期望位置一致 则将刚才返回的CI_ERROR变为CI_SUCCESS*/
						returnValue = CI_SUCCESS;
						break;
					}
				}
				if (CI_ERROR == returnValue)
				{/*没找到，继续找*/
					overlapProSwitchSum = GetOverlapRelatedProtSwitSum(switchBelongOverlapId);
					pOverlapProSwitchData = GetOverlapRelatedProtSwitStru(switchBelongOverlapId);

					if (NULL != pOverlapProSwitchData)
					{
						for (jj = 0U; jj < overlapProSwitchSum; jj++)
						{
							if ((pOverlapProSwitchData[jj].ProtectSwitchId == pRouteContainSwitchSumIdBuf[ii].SwitchId) &&
								(pOverlapProSwitchData[jj].ProtectPosition == pRouteContainSwitchSumIdBuf[ii].SwitchPosition))
							{
								/*若保护区段 进路对该道岔的期望位置一致 则将刚才返回的CI_ERROR变为CI_SUCCESS*/
								returnValue = CI_SUCCESS;
								break;
							}
						}
					}
				}

				if (CI_ERROR == returnValue)
				{
					break;
				}
			}

		}

		/*继续检查进路防护道岔征用*/
		if (CI_SUCCESS == returnValue)
		{
			for (ii = 0U; ii < routeProSwitchSum; ii++)
			{
				switchBelongOverlapId = GetSwitchBelongOverlapId(pRouteProSwitchData[ii].ProtectSwitchId);
				if (switchBelongOverlapId > 0u)
				{
					/*道岔所属保护区段ID大于0 表示有被保护区段征用 返回值先置为CI_ERROR*/
					returnValue = CI_ERROR;

					/*此时虽然被征用 但如果保护区段对道岔期望位置与进路对道岔期望位置一致 则返回成功 进路可以初锁*/
					/*根据征用道岔的保护区段ID获取该保护区段所包含道岔数据*/
					overlapContainSwitchSum = GetOverlapSwitchSum(switchBelongOverlapId);
					overlapContainSwitchSumIdBuf = GetOverlapCondSwitchStruct(switchBelongOverlapId);

					/*遍历保护区段包含的所有道岔 找到与上一级循环中循环到的道岔ID一致的保护区段包含道岔数据*/
					for (jj = 0U; jj < overlapContainSwitchSum; jj++)
					{
						if ((overlapContainSwitchSumIdBuf[jj].SwitchId == pRouteProSwitchData[ii].ProtectSwitchId) &&
							(overlapContainSwitchSumIdBuf[jj].SwitchPosition == pRouteProSwitchData[ii].ProtectPosition))
						{
							/*若保护区段 进路对该道岔的期望位置一致 则将刚才返回的CI_ERROR变为CI_SUCCESS*/
							returnValue = CI_SUCCESS;
							break;
						}
					}

					if (CI_ERROR == returnValue)
					{/*没找到，继续找*/
						overlapProSwitchSum = GetOverlapRelatedProtSwitSum(switchBelongOverlapId);
						pOverlapProSwitchData = GetOverlapRelatedProtSwitStru(switchBelongOverlapId);

						if (NULL != pOverlapProSwitchData)
						{
							for (jj = 0U; jj < overlapProSwitchSum; jj++)
							{
								if ((pOverlapProSwitchData[jj].ProtectSwitchId == pRouteProSwitchData[ii].ProtectSwitchId) &&
									(pOverlapProSwitchData[jj].ProtectPosition == pRouteProSwitchData[ii].ProtectPosition))
								{
									/*若保护区段 进路对该道岔的期望位置一致 则将刚才返回的CI_ERROR变为CI_SUCCESS*/
									returnValue = CI_SUCCESS;
									break;
								}
							}
						}
					}

					if (CI_ERROR == returnValue)
					{
						break;
					}
				}

			}
		}

		/*继续检查带动道岔征用*/
		if (CI_SUCCESS == returnValue)
		{
			for (kk = 0U; kk < AssocswitchSum; kk++)
			{
				GetRouteAssocSwitchData(routeId, kk, &routeAssocSwitchStru);/*获取带动道岔数据*/

				AssocswitchBelongOverlapId = GetSwitchBelongOverlapId(routeAssocSwitchStru.SwitchId);
				if (AssocswitchBelongOverlapId > 0u)
				{
					returnValue = CI_ERROR;
					/*此时虽然被征用 但如果保护区段对道岔期望位置与进路带动道岔对道岔期望位置一致 则返回成功*/
					/*根据征用道岔的保护区段ID获取该保护区段所包含道岔数据*/
					overlapContainSwitchSum = GetOverlapSwitchSum(AssocswitchBelongOverlapId);
					overlapContainSwitchSumIdBuf = GetOverlapCondSwitchStruct(AssocswitchBelongOverlapId);

					/*遍历保护区段包含的所有道岔 找到与上一级循环中循环到的道岔ID一致的保护区段包含道岔数据*/
					for (jj = 0U; jj < overlapContainSwitchSum; jj++)
					{
						if ((overlapContainSwitchSumIdBuf[jj].SwitchId == routeAssocSwitchStru.SwitchId) && (overlapContainSwitchSumIdBuf[jj].SwitchPosition == routeAssocSwitchStru.SwitchPosition))
						{
							/*若保护区段 进路对该道岔的期望位置一致 则将刚才返回的CI_ERROR变为CI_SUCCESS*/
							returnValue = CI_SUCCESS;
							break;
						}
					}
					if (CI_ERROR == returnValue)
					{
						break;
					}
				}
			}
		}

	}

	return returnValue;
}

/*
* 功能描述： 设置区段封锁逻辑管理
* 参数说明： const UINT16 phySecId, 区段ID
* 返回值  ： void
*/
UINT8 SetSectionFLockLogicManage(const UINT16 phySecId)
{
	UINT16 phySecSum = 0u;		/*物理区段总数*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 retVal = CI_ERROR;
	UINT8 flockState = 0u;        /*物理区段封锁状态*/
	UINT8 flockType = 0u;         /*物理区段封锁类型*/
	UINT8 tmpRet = CI_ERROR;
	UINT8 nonRouteFlag = 0U;

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetPhySecBelongCiId(phySecId);   /*获取区段所属联锁ID*/
	nonRouteFlag = CheckPhySecBelongNonRoute(phySecId);/*区段是否属于已办理非进路*/


	if ((0u == phySecId) || (phySecId >= PHYSICAL_SECTION_SUM_MAX))
	{
		retVal = CI_ERROR;
	}
	else
	{
		/*检查通过*/
		retVal = CI_SUCCESS;
	}

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		retVal = CI_ERROR;
	}
	else
	{
		/*检查通过*/
	}

	if (CI_SUCCESS == nonRouteFlag)
	{
		/*区段所属非进路已办理*/
		retVal = CI_ERROR;
		SetErrorData(EFUNC_SET_SECTION_FLOCK, CI_DEVICE_TYPE_PHYSEC, phySecId, ETYPE_PS_NONROUTE_SET, nonRouteFlag, ESEND_LEVEL_ZERO);
	}
	else
	{
		/*检查通过*/
	}
	

	if (CI_SUCCESS == retVal)
	{
		flockState = GetPhySecFLockState(phySecId);   /*物理区段封锁状态*/
		flockType = GetPhySecFLockType(phySecId);     /*物理区段封锁类型*/

		if (PHYSICAL_SECTION_FLOCK_NO == flockState)
		{/*物理区段未封锁*/
			tmpRet = SetPhySecFLockState(phySecId, PHYSICAL_SECTION_FLOCK_YES);/*设置物理区段封锁状态为封锁*/
			if (CI_ERROR == tmpRet)
			{/*错误处理*/
				retVal = CI_ERROR;
			}
			else
			{
				SetPhySecFLockType(phySecId, PHY_SEC_FLOCK_TYPE_CMD);/*记录物理区段封锁是由于命令按下导致*/
			}
		}
		else if ((PHYSICAL_SECTION_FLOCK_YES == flockState) && (PHY_SEC_FLOCK_TYPE_SPKS == flockType))
		{/*物理区段封锁*/
			SetPhySecFLockType(phySecId, PHY_SEC_FLOCK_TYPE_SPKSCMD);/*记录物理区段封锁是由于命令和SPKS按下导致*/
		}
		else
		{	/*已经设置封锁状态，或已经SPKS封锁不再设置区段封锁*/
			/*记录和发送故障码*/
			SetErrorData(EFUNC_SET_SECTION_FLOCK,
				CI_DEVICE_TYPE_PHYSEC,
				phySecId,
				ETYPE_PS_FLOCK_STATE,
				flockState, ESEND_LEVEL_ATS);

			retVal = CI_ERROR;
		}
	}
	else
	{
		/*返回失败*/
	}
	return retVal;
}

/*
* 功能描述： 取消区段封锁逻辑管理
* 参数说明： const UINT16 phySecId, 区段ID
* 返回值  ： void
*/
UINT8 CancelSectionFLockLogicManage(const UINT16 phySecId)
{
	UINT16 phySecSum = 0u;		/*物理区段总数*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 retVal = CI_ERROR;
	UINT8 flockState = 0u;        /*物理区段封锁状态*/
	UINT8 flockType = 0u;         /*物理区段封锁类型*/

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetPhySecBelongCiId(phySecId);   /*获取区段所属联锁ID*/

	if ((0u == phySecId) || (phySecId >= PHYSICAL_SECTION_SUM_MAX))
	{
		retVal = CI_ERROR;
	}
	else
	{
		/*检查通过*/
		retVal = CI_SUCCESS;
	}

	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		retVal = CI_ERROR;
	}
	else
	{
		/*检查通过*/
	}

	

	if (CI_SUCCESS == retVal)
	{
		flockState = GetPhySecFLockState(phySecId);   /*物理区段封锁状态*/
		flockType = GetPhySecFLockType(phySecId);     /*物理区段封锁类型*/
		if (PHYSICAL_SECTION_FLOCK_YES == flockState)
		{
			if (PHY_SEC_FLOCK_TYPE_SPKSCMD == flockType)
			{/*物理区段封锁*/
				SetPhySecFLockType(phySecId, PHY_SEC_FLOCK_TYPE_SPKS);/*封锁类型设置成SPKS按下封锁*/
			}
			else if (PHY_SEC_FLOCK_TYPE_CMD == flockType)
			{
				(void)SetPhySecFLockState(phySecId, PHYSICAL_SECTION_FLOCK_NO);/*设置物理区段封锁状态为未封锁*/
				SetPhySecFLockType(phySecId, PHY_SEC_FLOCK_TYPE_NONE);/*封锁类型设置成无封锁*/
			}
			else
			{
				/*SPKS封锁不能取消封锁*/
			}
		}
		else
		{/*记录和发送故障码*/
			SetErrorData(EFUNC_SET_SECTION_FLOCK,
				CI_DEVICE_TYPE_PHYSEC,
				phySecId,
				ETYPE_PS_UNFLOCK_STATE,
				flockState, ESEND_LEVEL_ATS);
			retVal = CI_ERROR;
		}
	}
	else
	{
		/*返回失败*/
	}
	return retVal;
}


/*
* 功能描述： 防淹门逻辑管理
* 参数说明： void
* 返回值  ：
*/
void FloodLogicManage(void)
{
	UINT16 floodCurSum = 0u;
	UINT16 ii = 0u;/*游标*/
	UINT16 jj = 0u;/*游标*/
	UINT16 kk = 0u;/*游标*/
	UINT16 pp = 0u;/*游标*/
	UINT8* pSourceIdBuf = NULL;		/*源IDBuf*/
	UINT8 dataValidFlag = 0u;	/*数据有效性标识：0无效，1有效*/
	UINT16 floodId = 0u;
	UINT16 devId = 0u;
	UINT8 devState = 0u;
	UINT8 floodState = 0u;
	UINT8 zcAgreeState = 0u;

	UINT16 routeSum = 0u;              /*进路数目 (配置字段)*/
	UINT16 routeId = 0u;/*进路id*/
	UINT16* pRouteFloodIdBuf = NULL;/*进路关联防淹门id数组指针*/
	UINT16 routeFloodSum = 0u;/*进路关联防淹门总数*/
	UINT16* pOverlapFloodIdBuf = NULL;/*保护区段关联防淹门id数组指针*/
	UINT16 overlapFloodSum = 0u;/*保护区段关联防淹门总数*/
	UINT16* pRouteOverlapIdBuf = NULL;/*进路保护区段id数组指针*/
	UINT16 routeOverlapSum = 0u;/*进路保护区段数量*/

	UINT8 flagCancel = 0u;/*取消标志*/
	UINT8 flagBreak = 0u;/*中断标志*/

	UINT8 headValid = 0u;

	UINT8 floodGateBelongCI = 0u;/*防淹门所属联锁*/
	UINT8 routeBelongCI = 0u;/*进路所属联锁*/
	UINT8 localSysCI = 0u;/*本机联锁*/

	UINT8 chkRes = CI_ERROR;
	UINT32 FloodGateDelayCloseCycSum = 0U;			/*防淹门接近区段占压延迟关门配置时间*/
	UINT32 wFloodGateDelayCloseStartCyc = 0U;		/*防淹门接近区段占压延迟关门起始时间*/
	UINT8 checkTimeState = CI_TIME_NO;
	UINT32 curCycle = 0U;
	UINT8 wFloodGateCloseCheckFlag = 0U;
	UINT8 cRcWorkMode = GetLocalRcWorkMode();
	UINT8 rtVal = CI_ERROR;
	UINT8 ivocAgreeState = 0U;
	UINT8 FloodGateAccessUTFlag = 0U;
	UINT16 TempTrainIdBuf[FLOOD_GATE_APPLY_TRAIN_SUM_MAX] = { 0U };

	localSysCI = GetSystemParaLocalCiId();
	floodCurSum = GetTotalFloodGateCurSum();
	FloodGateDelayCloseCycSum = GetFloodGateDelayCloseCount();
	curCycle = Get2oo2CurCycleNum();			/*获取当前周期*/

	if (RC_WORK_MODE_CI == cRcWorkMode)
	{
		/*CI模式下，先检查和ZC的通信*/
		pSourceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/
		if (NULL != pSourceIdBuf)
		{
			headValid = GetHLHTHeadCtxValid(CI_SYSTEM_TYPE_ZC, (UINT8)(pSourceIdBuf[0u]));

			if (CI_ERROR == headValid)	/*不使用GetZcMaskZcId()来获取ZC ID，因为组包完给ZC数据就清空了*/
			{
				dataValidFlag = 0u;
			}
			else
			{/*消息有效*/
				dataValidFlag = 1u;
			}
		}
	}
	else
	{

	}

	for (ii = 0u; ii < floodCurSum; ii++)
	{
		floodId = GetFloodGateId(ii);
		wFloodGateCloseCheckFlag = 0U;		/*每个防淹门出清标志*/
		if (0u < floodId)
		{
			floodGateBelongCI = GetFloodGateBelongCiId(floodId);/*获取防淹门所属联锁*/

			if (0u != floodGateBelongCI)
			{
				if (floodGateBelongCI == localSysCI)
				{/*只控制本联锁区的防淹门*/
					floodState = GetFloodGateCurCloseRequestSta(floodId);
					if (FLOOD_GATE_CLOSEREQ == floodState)
					{
						chkRes = FloodGateProtPhysecOccuCheck(floodId, &devId, &devState);			/*检查防护区域区段是否有占用*/
						if (CI_SUCCESS == chkRes)
						{
							chkRes = FloodGateAccessPhysecAcCheck(floodId, &devId, &devState);
							wFloodGateDelayCloseStartCyc = GetFloodGateDelayCloseStartCnt(floodId);
							checkTimeState = SystemOverTimeCheck(wFloodGateDelayCloseStartCyc, FloodGateDelayCloseCycSum);
							if (CI_SUCCESS == chkRes)
							{/*接近区段空闲，列车未接近，检查是否在延时关门期间，若未在，则允许关门*/
								if (CI_TIME_NO == checkTimeState)	/*未计时*/
								{
									(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_AGREE_CLOSE);		/*未计时，同意关门*/
								}
								else
								{
									wFloodGateCloseCheckFlag = 1U;			/*在计时中，需要执行关门检查逻辑*/
								}
							}
							else
							{/*接近区段占压，且，列车接近，或者UT占压，延时关门检查*/

							 /*接近情况需要延时，同时向ZC，或接近区段内的所有IVOC发送关门请求*/
								if (CI_TIME_NO == checkTimeState)
								{
									/*开始计时*/
									SetFloodGateDelayCloseStartCnt(floodId, curCycle);
									(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);		/*刚开始延时第一周期，还未向ZC或IVOC发请求，此时不同意关门*/
									if (RC_WORK_MODE_TIOC == cRcWorkMode)
									{	/*TIOC模式下，需要对接近区段上所有列车申请关闭防淹门*/
										rtVal = SetFloodGateAcCloseApplyProc(floodId);		/*防淹门接近区段列车占压，向所有列车申请处理,同时检查所有列车是否都为通信车，混跑返回失败，按延时允许走*/
										if (CI_SUCCESS == rtVal)
										{
											SetFloodGateAccessUTFlag(floodId, FLOOD_GATE_ACCESS_UT_NO);
										}
										else
										{
											SetFloodGateAccessUTFlag(floodId, FLOOD_GATE_ACCESS_UT_YES);
										}
									}
								}
								wFloodGateCloseCheckFlag = 1U;			/*开始计时，在计时中，需要执行关门检查逻辑*/
							}
						}
						else
						{
							/*延时清0*/
							SetFloodGateDelayCloseStartCnt(floodId, 0U);
							(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);
							ClearFloodGateAllowClosFlagIVOC(floodId);		/*出清可能保存的列车回复允许数量及状态*/
						}
					}
					else
					{
						/*延时清0*/
						SetFloodGateDelayCloseStartCnt(floodId, 0U);
						(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);
						ClearFloodGateAllowClosFlagIVOC(floodId);		/*出清可能保存的列车回复允许数量及状态*/
					}

					if (1U == wFloodGateCloseCheckFlag)
					{
						if (CI_TIME_OUT == checkTimeState)
						{
							(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_AGREE_CLOSE);		/*超时，同意关门，并出清计时*/
							/*出清关门申请列车信息*/
							SetFloodGateCloseApplyIvocSum(floodId, 0U);
							SetFloodGateCloseApplyIvocId(floodId, TempTrainIdBuf); 
						}
						else
						{
							if (RC_WORK_MODE_CI == cRcWorkMode)
							{
								zcAgreeState = GetFloodGateCurZCAgrCloseAck(floodId);
								if ((1u == dataValidFlag) && (FLOOD_GATE_ALLOWCLOSE_ZC == zcAgreeState))
								{	/*与ZC通信正常，接近区段占压，且接近，在延时时间内，收到关门允许，同意关门，不满足则不同意关闭，延时结束同意*/
									(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_AGREE_CLOSE);
								}
								else
								{
									(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);
								}
							}
							else
							{/*TIOC模式下需要查询接近区段上所有列车都允许防淹门关门*/
								FloodGateAccessUTFlag = GetFloodGateAccessUTFlag(floodId);
								if (FLOOD_GATE_ACCESS_UT_YES == FloodGateAccessUTFlag)
								{
									(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);/*申请关防淹门时，接近区段上有混跑的多列车，未向列车申请关防淹门请求，按延时关闭走，超时才同意*/
								}
								else
								{
									ivocAgreeState = GetFloodGateAccessCloseAskIVOC(floodId);
									if (CI_SUCCESS == ivocAgreeState)
									{
										/*延时期间内收到所有列车的允许关门，则同意关门*/
										(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_AGREE_CLOSE);
									}
									else
									{
										(void)SetFloodGateCurAgreeCloseOutSta(floodId, FLOOD_GATE_NOT_AGREE_CLOSE);
									}
								}
							}
						}
					}
				}

				/*增加以下逻辑，当防淹门关闭时，把关联防淹门的进路，关联防淹门的保护区段的进路的自动属性去掉*/
				/*注：这个不需区分防淹门是否属于本联锁*/
				routeSum = GetRouteCurSum();/*获取进路条数*/
				for (jj = 0u; jj < routeSum; jj++)
				{
					routeId = GetRouteId(jj);                           /*获取进路ID*/
					routeBelongCI = GetRouteBelongCiId(routeId);/*获取进路所属联锁*/
					pRouteFloodIdBuf = GetRouteFloodGateBuf(routeId);
					routeFloodSum = GetRouteFloodGateSum(routeId);
					pRouteOverlapIdBuf = GetRouteOverlapIdBuf(routeId);
					routeOverlapSum = GetRouteOverlapSum(routeId);
					chkRes = 0u;

					if ((0u != routeBelongCI) && (routeBelongCI == localSysCI))
					{/*进路属于本联锁才能取消进路自动属性*/

						/*获取防淹门关闭状态*/
						floodState = GetFloodGateCurLogicCloseState(floodId);

						if (FLOOD_GATE_OPEN != floodState)
						{
							/*如进路关联防淹门有一个防淹门ID为本防淹门，且防淹门关闭，则取消进路自动属性*/
							if (0u < routeFloodSum)
							{
								if (NULL != pRouteFloodIdBuf)
								{
									for (kk = 0u; kk < routeFloodSum; kk++)
									{
										if (floodId == pRouteFloodIdBuf[kk])
										{
											flagCancel = CancleAutoFlag(routeId);
											if (CI_ERROR == flagCancel)
											{
												SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_FLOODGATE, floodId, ETYPE_FLOODGATE_CLOSESTATE, floodState, ESEND_LEVEL_ZERO);
												break;
											}
										}
									}
								}
								else
								{
									/*pRouteFloodIdBuf为空时，软件出了问题，此时导向安全侧，取消进路自动属性*/
									flagCancel = CancleAutoFlag(routeId);
									if (CI_ERROR == flagCancel)
									{
										SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_FLOODGATE, floodId, ETYPE_FLOODGATE_CLOSESTATE, floodState, ESEND_LEVEL_ZERO);
									}
								}
							}

							/*遍历进路保护区段，如此进路的保护区段关联防淹门关闭，则取消进路自动属性*/
							flagBreak = 0u;
							for (kk = 0u; kk < routeOverlapSum; kk++)
							{
								if (NULL != pRouteOverlapIdBuf)
								{
									pOverlapFloodIdBuf = GetOverlapFloodGateBuf(pRouteOverlapIdBuf[kk]);
									overlapFloodSum = GetOverlapFloodGateSum(pRouteOverlapIdBuf[kk]);
									if (overlapFloodSum > 0u)
									{
										if (NULL != pOverlapFloodIdBuf)
										{
											for (pp = 0u; pp < overlapFloodSum; pp++)
											{
												if (pOverlapFloodIdBuf[pp] == floodId)
												{
													flagCancel = CancleAutoFlag(routeId);
													if (CI_ERROR == flagCancel)
													{
														flagBreak = 1u;
														SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_FLOODGATE, floodId, ETYPE_FLOODGATE_CLOSESTATE, floodState, ESEND_LEVEL_ZERO);
														break;
													}
												}
											}
											if (1u == flagBreak)
											{
												break;
											}
										}
										else
										{
											flagCancel = CancleAutoFlag(routeId);
											if (CI_ERROR == flagCancel)
											{
												SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_FLOODGATE, floodId, ETYPE_FLOODGATE_CLOSESTATE, floodState, ESEND_LEVEL_ZERO);
												break;
											}
										}

									}

								}
								else
								{
									/*pRouteOverlapIdBuf为空时，软件出了问题，此时导向安全侧，取消进路自动属性*/
									flagCancel = CancleAutoFlag(routeId);
									if (CI_ERROR == flagCancel)
									{
										SetErrorData(EFUNC_SET_SWITCH_FLOCK, CI_DEVICE_TYPE_FLOODGATE, floodId, ETYPE_FLOODGATE_CLOSESTATE, floodState, ESEND_LEVEL_ZERO);
									}
								}
							}
						}
					}


				}
			}
		}
	}
}


/*
* 功能描述： 解锁道岔逻辑管理
* 参数说明： void
* 返回值  ：
*/
void UnlockSwitchLogicManage(void)
{
	UINT16 j = 0U;
	UINT16 ii = 0U;
	UINT16 dwSwitchTotalSum = 0U;
	UINT8 localCiId = 0U;         /*本地联锁ID*/
	UINT16 switchId = 0U;
	UINT16 wDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chFuncRet = 0U;
	UINT8 chFuncRet1 = 0U;
	UINT16 hostSwitchNum = 0U;/*主体道岔数量*/
	UINT16* pHostSwitchBuf = NULL;/*主体道岔Id缓存指针*/
	UINT16 hostSwitchId = 0U;/*主体道岔ID*/
	UINT16 hostPhyId = 0U;/*主体道岔物理区段ID*/
	UINT8 phyLockStatus = 0U;/*物理区段锁闭状态*/
	UINT8 unlockFlag = 0U;/*解锁标志*/
	UINT8 funcSwitch = 0U;
	UINT8 chPhySecLogLockState = 0U;/*物理区段逻辑锁闭状态*/
	UINT8 chPhySecJumpLockState = 0U;

	localCiId = GetSystemParaLocalCiId();				/*获取本机联锁ID*/
	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
	dwSwitchTotalSum = GetTotalSwitchCurNum();  /*修复YF0083-2507：跨控区防护道岔可在主体道岔区段解锁后解锁*/
	for (ii = 0u; ii < dwSwitchTotalSum; ii++)
	{
		switchId = GetSwitchId(ii); 					 /*获取道岔ID*/

		if ((0u < switchId) && (switchId < SWITCH_SUM_MAX))
		{
			/*Note：修复YF0083-2507，跨控区防护道岔可在主体道岔区段解锁后解锁，SetSwitchLockStatus函数在清除防护锁闭状态时已对道岔控区进行限制，此处无需判断道岔所属控区*/
			hostSwitchNum = GetSwitchHostSwitchNum(switchId);
			pHostSwitchBuf = GetSwitchHostSwitchIdBuf(switchId);
			unlockFlag = 0u;
			if ((hostSwitchNum > 0u) && (pHostSwitchBuf != NULL))
			{
				for (j = 0u; j < hostSwitchNum; j++)
				{
					hostSwitchId = pHostSwitchBuf[j];

					hostPhyId = GetSwitchPhySectionId(hostSwitchId);/*获取主体道岔的道岔区段ID*/

					if (0u == hostPhyId)
					{
						debug_infor_printf((const)"Error:hostSwitchId %d phySec is 0.\r\n", hostSwitchId);
					}

					phyLockStatus = GetPhySecLockState(hostPhyId);/*获取物理区段锁闭状态*/
					chFuncRet1 = GetSwitchLogSecLockState(hostSwitchId, &wDevId, &chDevState);
					chPhySecLogLockState = PhySecLogLockStateCheck(hostPhyId);
					chPhySecJumpLockState = GetPhySecJumpLockState(hostPhyId);

					if ((PHYSICAL_SECTION_LOCK_NO == phyLockStatus) && (CI_SUCCESS == chFuncRet1)
						&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState) && (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhySecJumpLockState))
					{/*区段锁闭状态为未锁闭(物理区段未被进路锁，逻辑区段未被进路锁，物理区段未被逻辑进路锁,未被跳跃锁闭)*/
						unlockFlag = 1u;
					}
					else
					{
						if (FUNC_SWITCH_ON == funcSwitch)
						{
							chFuncRet = GetSwitchLogSecLockState(hostSwitchId, &wDevId, &chDevState);
						}
						else
						{
							chFuncRet = CI_ERROR;
						}
						if (CI_SUCCESS == chFuncRet)
						{
							unlockFlag = 1u;
						}
						else
						{
							unlockFlag = 0u;
							break;
						}


					}
				}
			}

			if (1u == unlockFlag)
			{/*解锁道岔防护锁闭*/
				debug_infor_printf((const)"UnLock switch:%d	\r\n", switchId);
				SetSwitchLockStatus(SWITCH_PLOCKTYPE_NOROUTE_NOOVERLAP_NONONROUTE, 0u, switchId, 0u);
			}
		}
	}
}

#if 0
/*
* 功能描述： 有岔计轴区段跳跃锁闭逻辑管理
* 参数说明： void
* 返回值  ：
*/
void SwitchAxisSecJumpLockLogicManage(void)
{
	UINT8 funcSwitchJumpLockDriveSwitch = 0u;/*功能开关：跳跃锁闭是否驱道岔*/

	UINT16 axisSectionDataSum = 0u;					/*计轴区段总数*/
	UINT16 axisSectionId = 0u;						/*计轴区段ID*/

	UINT16 ii = 0u;/*索引标志*/
	UINT16 jj = 0u;/*索引标志*/

	UINT8 applyFlag = 0u;/*申请标志*/
	UINT8 cancelApplyFlag = 0u;/*取消申请标志*/

	UINT16 phyId = 0u;/*物理区段ID*/
	UINT8 phyUseState = 0u;/*物理区段征用状态*/

	UINT8 jumpLockState = 0u;/*跳跃锁闭状态*/

	UINT8 secBelongCi = 0u;/*区段所属联锁*/
	UINT8 localCi = 0u;/*本联锁*/

	UINT8 rtVal = 0u;    /*函数执行返回值*/

	UINT8 logSecNum = 0u;
	UINT16* pLogSecIdBuf = NULL;
	UINT16 tmplogSecId = 0u;
	UINT32 applyCycle = 0u;/*跳跃锁闭申请周期*/
	UINT32 curCycle = 0u;/*当前周期号*/
	UINT8 switchSum = 0u;
	UINT8 kk = 0u;
	UINT8 mm = 0u;
	UINT16 logicSecSum = 0u;
	UINT16 logicSecId = 0u;



	localCi = GetSystemParaLocalCiId();
	funcSwitchJumpLockDriveSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_JUMPLOCK_DRIVE_SWITCH);


	if (FUNC_SWITCH_ON == funcSwitchJumpLockDriveSwitch)
	{
		axisSectionDataSum = GetTotalAxisCurNum();

		for (ii = 0u; ii < axisSectionDataSum; ii++)
		{
			curCycle = Get2oo2CurCycleNum();
			axisSectionId = GetAxisSecId(ii);/*获取配置数据中该索引下的计轴区段ID*/
			switchSum = GetAxisSwitchSum(axisSectionId);
			applyFlag = GetAxisSecJumpLockApplyFlag(axisSectionId);
			applyCycle = GetAxisSecJumpLockApplyCylce(axisSectionId);
			cancelApplyFlag = GetAxisSecJumpLockCancelApplyFlag(axisSectionId);

			jumpLockState = GetAxisJumpLockState(axisSectionId);/*获取跳跃锁闭状态*/

			phyId = GetAxisSecRelativePhySecId(axisSectionId);/*获取相关物理区段ID*/
			phyUseState = GetPhySecUseState(phyId);/*获取物理区段征用状态*/

			secBelongCi = GetPhySecBelongCiId(phyId);

			logSecNum = GetAxisSecLogSectionSum(axisSectionId); /** 计轴包含的逻辑区段数量*/
			pLogSecIdBuf = GetAxisSecLogSectionIdBuf(axisSectionId); /** 计轴包含的逻辑区段ID*/

			if ((0u < switchSum) && (secBelongCi == localCi) && (NULL != pLogSecIdBuf))
			{/*物理区段所属联锁为本联锁，才处理*/

			 /*计轴跳跃状态处理：空闲处理、选排处理、锁闭处理*/
				switch (jumpLockState)
				{
				case AXIS_SECTION_JUMPLOCK_STATE_IDLE:
				{/*计轴区段空闲处理*/

					/** 计轴区段跳跃空闲，则设置计轴区段关联的逻辑区段跳跃锁闭未锁闭 */
					for (jj = 0u; jj < logSecNum; jj++)
					{
						tmplogSecId = pLogSecIdBuf[jj];
						SetLogSecJumpLockState(tmplogSecId, LOGIC_SECTION_JUMP_LOCK_NO);
					}

					/*有跳跃锁闭申请，且没有取消跳跃申请*/
					/*如果计轴跳跃状态空闲，如果物理区段未征用，则计轴跳跃状态转跳跃锁闭、且设征用*/
					if ((AXIS_SECTION_JUMPLOCK_APPLY_YES == applyFlag) &&
						(AXSEC_CANCEL_JUMPLOCK_APPLY_NO == cancelApplyFlag))
					{/*有跳跃锁闭申请*/

						if (PHYSICAL_SECTION_USING_NO == phyUseState)
						{/*未征用*/
						 /*设置征用*/
							SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_YES, 0);
							/*转为选排*/
							SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_XUANPAI);
						}
					}
				}
				break;

				case AXIS_SECTION_JUMPLOCK_STATE_XUANPAI:
				{/*计轴区段跳跃选排处理*/

					AxisJumpLockXuanPaiManage(axisSectionId);
				}
				break;

				case AXIS_SECTION_JUMPLOCK_STATE_LOCK:
				{/*计轴区段跳跃锁闭处理*/

				 /*持续进行锁闭检查，检查通过，设置物理区段跳跃锁闭；检查不通过，设置未跳跃锁闭*/
					rtVal = LockAxisSecProc(axisSectionId);/*跳跃锁闭联锁条件检查*/
					if (CI_SUCCESS == rtVal)
					{
						if ((AXIS_SECTION_JUMPLOCK_APPLY_YES == applyFlag) &&
							(AXSEC_CANCEL_JUMPLOCK_APPLY_NO == cancelApplyFlag) &&
							(curCycle == applyCycle))
						{/*本周期有跳跃锁闭申请，才设置逻辑区段跳跃锁闭*/
							for (jj = 0u; jj < logSecNum; jj++)
							{
								tmplogSecId = pLogSecIdBuf[jj];
								SetLogSecJumpLockState(tmplogSecId, LOGIC_SECTION_JUMP_LOCK_YES);
							}
						}
					}
					else
					{/*之前处于锁闭，当持续检查锁闭条件不满足时，内部维持跳跃锁闭，给ZC发不锁闭*/
						SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
					}

					if ((AXIS_SECTION_JUMPLOCK_APPLY_NO == applyFlag) &&
						(AXSEC_CANCEL_JUMPLOCK_APPLY_YES == cancelApplyFlag))
					{/*有取消跳跃申请*/

						SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);
					}
				}
				break;


				default:
					break;
				}
			}
			else
			{
				/**无岔计轴区段或者非本控区计轴区段不处理*/
			}

		}

		/** 根据逻辑区段跳跃锁闭状态设置物理区段跳跃锁闭状态*/
		logicSecSum = GetLogicSecCurSum();
		if (LOGIC_SECTION_SUM_MAX > logicSecSum)
		{
			for (ii = 0u; ii < logicSecSum; ii++)
			{
				logicSecId = GetLogicSecId(ii);
				SetLogRelaPhySecJumpLockSta(logicSecId);
			}
		}
		else
		{
			/** 不做处理*/
	}
}

}
#endif

/*
* 功能描述： 跳跃锁闭逻辑处理
* 参数说明： void
* 返回值  ：
*/
void JumpLockManage(void)
{
	UINT8 chRCMode = GetLocalRcWorkMode();
	UINT8 chFunctionJumpDriveSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_JUMPLOCK_DRIVE_SWITCH);
	UINT8 chLocalCiType = GetLocalCiType();

	if (RC_WORK_MODE_TIOC == chRCMode)
	{
		/*逻辑区段跳跃锁闭条件的周期检查和通信中断处理*/
		CheckLogSecJumpLockManage();

		/*向后跳跃申请处理*/
		TrainJumpBackApplyProc();
	}
	else if (RC_WORK_MODE_CI == chRCMode)
	{
		if ((FUNC_SWITCH_ON == chFunctionJumpDriveSwitch) && (CI_TYPE_ZX == chLocalCiType))
		{
			/*计轴区段跳跃锁闭逻辑处理*/
			AxisSecJumpLockLogicManage();
		}
		else
		{
			/*物理区段跳跃锁闭逻辑处理*/
			PhySecJumpLockLogicManage();
		}
	}
	else
	{
		/*模式错误无处理*/
	}

}

/*
* 功能描述： 周期检查逻辑区段跳跃锁闭条件
* 参数说明： 无
* 返回值  ： 无
*/
void CheckLogSecJumpLockManage(void)
{
	UINT16 logicSecSum = 0u;
	UINT16 logicSecId = 0u;
	UINT8 logSecBelongCiId = 0u;
	UINT8 checkResult = CI_ERROR;
	UINT16 ii = 0u;
	UINT8 logJumpLockState = LOGIC_SECTION_JUMP_LOCK_NO;
	UINT8 localCi = 0u;/*本联锁*/
	UINT16 logJumpLockTrainId = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 retVal = CI_ERROR;


	localCi = GetSystemParaLocalCiId();
	logicSecSum = GetLogicSecCurSum();
	for (ii = 0U; ii < logicSecSum; ii++)
	{
		logicSecId = GetLogicSecId(ii);
		logSecBelongCiId = GetLogSecBelongCiId(logicSecId);
		logJumpLockState = GetLogSecJumpLockState(logicSecId);
		if ((0U < logicSecId) && (UINT16_MAX > logicSecId))
		{
			if (localCi == logSecBelongCiId)
			{
				if (LOGIC_SECTION_JUMP_LOCK_YES == logJumpLockState)
				{
					/** 检查本TIOC控区逻辑区段跳跃锁闭条件*/
					checkResult = CheckLogJumpLockApply(logicSecId);
					if (CI_SUCCESS == checkResult)
					{
						devId = 0u;
						devState = 0u;
						retVal = LogicSecRltvPrtctSwLockCheck(logicSecId, &devId, &devState);
						if (CI_SUCCESS == retVal)
						{
							/** 检查条件满足，设置跳跃锁闭允许标志为允许 */
							SetLogSecJumpLockPermFlag(logicSecId, LOGIC_JUMPUNLOCK_PERMISSIVE_YES);
						}
						else
						{
							/** 检查条件不满足，设置跳跃锁闭允许标志为禁止 */
							SetLogSecJumpLockPermFlag(logicSecId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
						}
					}
					else
					{
						/** 检查条件不满足，设置跳跃锁闭允许标志为禁止 */
						SetLogSecJumpLockPermFlag(logicSecId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
					}
				}
				else
				{
					/** 逻辑区段未跳跃锁闭，无需周期检查跳跃锁闭条件*/
				}

				/** 处理TIOC与指定IVOC通信状态下的跳跃锁闭*/
				logJumpLockTrainId = GetLogSecJumpLockTrainId(logicSecId);
				if (0u != logJumpLockTrainId)
				{
					TrainTransitmitStatJumpLockProcess(logicSecId, logJumpLockTrainId);
				}
				else
				{
					/** 不处理*/
				}

				SetLogRelaPhySecJumpLockSta(logicSecId);

			}
			else
			{
				/** 非本TIOC控区逻辑区段，不检查跳跃锁闭条件*/
			}
		}
		else
		{
			/** 不处理*/
		}

	}

}

/*
* 功能描述： 计轴区段跳跃锁闭逻辑管理
* 参数说明： void
* 返回值  ：
*/
void AxisSecJumpLockLogicManage(void)
{
	UINT16 axisSectionDataSum = 0u;					/*计轴区段总数*/
	UINT16 axisSectionId = 0u;						/*计轴区段ID*/
	UINT16 ii = 0u;/*索引标志*/
	UINT16 jj = 0u;/*索引标志*/
	UINT8 applyFlag = 0u;/*申请标志*/
	UINT8 cancelApplyFlag = 0u;/*取消申请标志*/
	UINT16 phyId = 0u;/*物理区段ID*/
	UINT8 jumpLockState = 0u;/*跳跃锁闭状态*/
	UINT8 secBelongCi = 0u;/*区段所属联锁*/
	UINT8 localCi = 0u;/*本联锁*/
	UINT8 rtVal = 0u;    /*函数执行返回值*/
	UINT8 axisSecNum = 0u;
	UINT16* pAxisSecIdBuf = NULL;
	UINT16 cntAxisIdle = 0u;
	UINT16 tmpAxisId = 0u;
	UINT8  tmpAxisSecJumpLockState = 0u;
	UINT32 applyCycle = 0u;/*跳跃锁闭申请周期*/
	UINT32 curCycle = 0u;/*当前周期号*/
	UINT8 chPhySecJmpState = 0U;
	UINT8 chJumpPhySectionUseCheck = 0U;

	localCi = GetSystemParaLocalCiId();
	axisSectionDataSum = GetTotalAxisCurNum();

	for (ii = 0u; ii < axisSectionDataSum; ii++)
	{
		curCycle = Get2oo2CurCycleNum();
		axisSectionId = GetAxisSecId(ii);/*获取配置数据中该索引下的计轴区段ID*/
		applyFlag = GetAxisSecJumpLockApplyFlag(axisSectionId);
		applyCycle = GetAxisSecJumpLockApplyCylce(axisSectionId);
		cancelApplyFlag = GetAxisSecJLockCancelApplyFlag(axisSectionId);

		jumpLockState = GetAxisJumpLockState(axisSectionId);/*获取跳跃锁闭状态*/

		phyId = GetAxisSecRelativePhySecId(axisSectionId);/*获取相关物理区段ID*/

		secBelongCi = GetPhySecBelongCiId(phyId);

		if (secBelongCi == localCi)
		{/*物理区段所属联锁为本联锁，才处理*/
			/*计轴跳跃状态处理：空闲处理、选排处理、锁闭处理*/
			switch (jumpLockState)
			{
			case AXIS_SECTION_JUMPLOCK_STATE_IDLE:
			{/*计轴区段空闲处理*/
				/*计轴区段跳跃空闲，要继续判此计轴区段关联的物理区段的所有计轴区段是否都空闲，才设置物理区段未跳跃锁闭*/
				pAxisSecIdBuf = GetPAxisSectionIdBuf(phyId);
				axisSecNum = GetPAxisSectionSum(phyId);
				if (NULL != pAxisSecIdBuf)
				{
					cntAxisIdle = 0u;
					for (jj = 0u; jj < axisSecNum; jj++)
					{
						tmpAxisId = pAxisSecIdBuf[jj];
						tmpAxisSecJumpLockState = GetAxisJumpLockState(tmpAxisId);
						if (AXIS_SECTION_JUMPLOCK_STATE_IDLE == tmpAxisSecJumpLockState)
						{
							cntAxisIdle++;
						}
					}
					if (cntAxisIdle == axisSecNum)
					{
						SetPhySecJumpLockState(phyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
						SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
					}
				}
				/*有跳跃锁闭申请，且没有取消跳跃申请*/
				/*如果计轴跳跃状态空闲，如果物理区段未征用，则计轴跳跃状态转跳跃锁闭、且设征用*/
				if ((AXIS_SECTION_JUMPLOCK_APPLY_YES == applyFlag) &&
					(AXSEC_CANCEL_JUMPLOCK_APPLY_NO == cancelApplyFlag))
				{/*有跳跃锁闭申请*/

					chJumpPhySectionUseCheck = JumpPhySectionUseCheck(axisSectionId);
					if (CI_SUCCESS == chJumpPhySectionUseCheck)
					{/*未征用*/
						/*设置征用*/
						SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_YES, 0);
						SetJumpPhySectionPortectSecUse(axisSectionId, PHYSICAL_SECTION_USING_YES);/*设置物理区段关联防护道岔的区段征用*/
						/*转为选排*/
						SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_XUANPAI);
					}
				}
			}
			break;

			case AXIS_SECTION_JUMPLOCK_STATE_XUANPAI:
			{/*计轴区段跳跃选排处理*/

				AxisJumpLockXuanPaiManage(axisSectionId);
			}
			break;

			case AXIS_SECTION_JUMPLOCK_STATE_LOCK:
			{/*计轴区段跳跃锁闭处理*/
				AxisJumpLockStateManage(axisSectionId);
			}
			break;
			default:
				/*不可达分支*/
				break;
			}
		}
	}
}


/*
* 功能描述： 计轴区段跳跃选排管理
* 参数说明： const UINT16 axisSecId, 计轴区段ID
* 返回值  ： void
*/
void AxisJumpLockXuanPaiManage(const UINT16 axisSecId)
{
	UINT8 rtVal = 0u;    /*函数执行返回值*/
	UINT16 phyId = 0u;/*物理区段ID*/
	UINT8 axisSecSwitDrvOvtmFlag = 0u;/*计轴区段内道岔是否驱动超时标志*/
	UINT8 const functionId = EFUNC_LockAxisSecProc;/*函数故障码*/
	UINT8 chPhySecFLockType = 0U;/*物理区段封锁类型*/

	phyId = GetAxisSecRelativePhySecId(axisSecId);/*获取相关物理区段ID*/
	chPhySecFLockType = GetPhySecFLockType(phyId);/*获取物理区段封锁类型*/

	if (PHY_SEC_FLOCK_TYPE_NONE != chPhySecFLockType)
	{
		/*物理区段处于封锁状态*/
		AccToPhySecFlockTypeSetErrcode(phyId, functionId, ESEND_LEVEL_ZERO, chPhySecFLockType);
		rtVal = CI_ERROR;
	}
	else
	{
		rtVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == rtVal)
	{
		rtVal = JumpPhySecAllUseCheck(axisSecId);/*所有区段已设置上征用（不考虑相邻联锁，若防护道岔在相邻联锁则不跳跃锁闭）*/
	}

	if (CI_SUCCESS == rtVal)
	{
		rtVal = LockAxisSecProc(axisSecId);/*跳跃锁闭联锁条件检查*/
	}
	axisSecSwitDrvOvtmFlag = ChekJumpLockSwitDrivOvtmStat(axisSecId);/*检查计轴区段关联道岔是否驱动超时*/
	if (CI_SUCCESS == rtVal)
	{/*检查成功*/

		SetAxisJumpLockState(axisSecId, AXIS_SECTION_JUMPLOCK_STATE_LOCK);/*状态机流程转*/

	}
	else if ((RETURN_LOCK_ERR_SWITPOS == rtVal) && (CI_SUCCESS == axisSecSwitDrvOvtmFlag))
	{/*位置错误可驱动且驱动道岔没有超时*/
		/*跳跃锁闭驱动道岔*/
		rtVal = JumpLockDriveSwitch(axisSecId);

		if (CI_ERROR == rtVal)
		{
			/*设置未征用*/
			SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_NO, 0);
			SetJumpPhySectionPortectSecUse(axisSecId, PHYSICAL_SECTION_USING_NO);/*设置物理区段的防护道岔所在区段取消防护征用*/

			/*设置计轴区段跳跃状态空闲*/
			SetAxisJumpLockState(axisSecId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);
		}
	}
	else
	{/*其它*/
		/*设置未征用*/
		SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_NO, 0);
		SetJumpPhySectionPortectSecUse(axisSecId, PHYSICAL_SECTION_USING_NO);/*设置物理区段的防护道岔所在区段取消防护征用*/

		/*设置计轴区段跳跃状态空闲*/
		SetAxisJumpLockState(axisSecId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);
	}
}


/*
* 功能描述： 锁闭计轴区段检查
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 LockAxisSecProc(const UINT16 axisSecId)
{
	UINT8 rtVal = CI_ERROR;    /*返回值定义*/

	UINT8 const functionId = EFUNC_LockAxisSecProc;/*函数故障码*/

	/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;		/*不发送ATS*/

	UINT8 axisSecJumpLockState = 0u;/*计轴区段锁闭状态*/


	/*计轴区段状态为选排或锁闭*/
	axisSecJumpLockState = GetAxisJumpLockState(axisSecId);
	if ((AXIS_SECTION_JUMPLOCK_STATE_XUANPAI == axisSecJumpLockState) ||
		(AXIS_SECTION_JUMPLOCK_STATE_LOCK == axisSecJumpLockState))
	{
		/* 通过检查 */
		rtVal = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_AXISSEC, axisSecId, CI_DEVICE_TYPE_AXISSEC, axisSecJumpLockState, sendLevel);
		/* 失败返回 */
		rtVal = CI_ERROR;

	}

	/*跳跃锁闭区段检查为通过*/
	if (CI_SUCCESS == rtVal)
	{
		rtVal = JumpLockSecStateCheck(axisSecId, functionId, sendLevel);
	}

	/*跳跃锁闭道岔检查为通过*/
	if (CI_SUCCESS == rtVal)
	{
		rtVal = JumpLockSwitchCheck(axisSecId, functionId, sendLevel);/*返回值为：成功、错误、道岔位置错误可驱动*/
	}

	return rtVal;
}

/*
* 功能描述： 跨集中区自动进路封锁设备处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void CrossCiAutoRouteFLockDevProc(const UINT16 routeId)
{
	UINT8 const functionId = EFUNC_CROSS_CI_AUTOROUTE_FLOCK_DEV; /*日志函数ID*/
	UINT8 const sendLevel = ESEND_LEVEL_ZERO; /*日志发送级别*/
	UINT8 isCancleAuto = 0u; /*是否取消进路自动属性*/
	UINT8 fLockState = 0u; /*封锁状态*/
	UINT8 flagCancel = 0u; /*取消进路自动属性标识返回值*/
	UINT16 ii = 0u; /*用于循环*/
	UINT16 jj = 0u; /*用于循环*/
	UINT8 secSum = 0u; /*进路包含区段数量(配置字段)*/
	RoutePhysicalSectionStruct* pSecStru = NULL; /*进路包含区段数据(配置字段)*/
	UINT16* pSecIds = NULL; /*保护区段包含区段ID列表*/
	UINT8 overlapSum = 0u; /*进路相关防护区段组数目(配置字段)*/
	UINT16* pOverlapIds = NULL; /*进路相关防护区段组ID数组(配置字段)*/
	UINT16 overlapId = 0u; /*防护区段ID*/
	UINT8 fsSignalSum = 0u; /*进路相关封锁信号机数目(配置字段)*/
	UINT16* pFsSignalIds = NULL; /*进路相关封锁信号机ID数组(配置字段)*/

	secSum = GetRoutePhysicalSectionSum(routeId);
	pSecStru = GetRouteSectionData(routeId);
	if (0u < secSum)  /*有数量,指针非空检查*/
	{
		for (ii = 0u; ii < secSum; ii++)
		{
			fLockState = GetPhySecFLockState(pSecStru[ii].PhysicalSectionId);
			if (PHYSICAL_SECTION_FLOCK_YES == fLockState) /*区段封锁*/
			{
				flagCancel = CancleAutoFlag(routeId);
				if (CI_ERROR == flagCancel)
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, pSecStru[ii].PhysicalSectionId, ETYPE_PS_FLOCK_STATE, fLockState, sendLevel);
				}
				isCancleAuto = 1u; /*设置取消进路自动属性*/
				break; /*退出遍历*/
			}
			else
			{
				;
			}
		}
	}
	else
	{
		;
	}

	if (0u == isCancleAuto) /*未取消进路自动属性*/
	{
		overlapSum = GetRouteOverlapSum(routeId);
		pOverlapIds = GetRouteOverlapIdBuf(routeId);
		if ((0u < overlapSum) && (NULL != pOverlapIds)) /*有数量,指针非空检查*/
		{
			for (ii = 0u; ii < overlapSum; ii++)
			{
				overlapId = pOverlapIds[ii];
				secSum = GetOverlapPhySecSum(overlapId);
				pSecIds = GetOverlapPhySecIdBuf(overlapId);
				if ((0u < secSum) && (NULL != pSecIds)) /*有数量,指针非空检查*/
				{
					for (jj = 0u; jj < secSum; jj++)
					{
						fLockState = GetPhySecFLockState(pSecIds[jj]);
						if (PHYSICAL_SECTION_FLOCK_YES == fLockState) /*区段封锁*/
						{
							flagCancel = CancleAutoFlag(routeId);
							if (CI_ERROR == flagCancel)
							{
								SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, pSecIds[jj], ETYPE_PS_FLOCK_STATE, fLockState, sendLevel);
							}
							isCancleAuto = 1u; /*设置取消进路自动属性*/
							break; /*退出遍历*/
						}
					}
				}
				else
				{
					;
				}
				if (1u == isCancleAuto) /*已设置取消进路自动属性,退出遍历*/
				{
					break;
				}
				else
				{
					;
				}
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (0U == isCancleAuto) /*未取消进路自动属性*/
	{
		fsSignalSum = GetRouteFengSuoSignalSum(routeId);
		pFsSignalIds = GetRouteFengSuoSignalIdBuf(routeId);
		if ((0u < fsSignalSum) && (NULL != pFsSignalIds)) /*有数量,指针非空检查*/
		{
			for (ii = 0u; ii < fsSignalSum; ii++)
			{
				fLockState = GetSignalFLockState(pFsSignalIds[ii]);
				if (SIGNAL_FENGSUO_YES == fLockState) /*信号机封锁*/
				{
					flagCancel = CancleAutoFlag(routeId);
					if (CI_ERROR == flagCancel)
					{
						SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, pFsSignalIds[ii], ETYPE_SIG_FLOCK_STATE, fLockState, sendLevel);
					}
					else
					{
						;
					}
					isCancleAuto = 1u; /*设置取消进路自动属性*/
					break; /*退出遍历*/
				}
				else
				{
					;
				}
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}


/******************************相邻联锁继电接口确认状态************************************************************/

/*
* 功能描述： 获取继电接口确认标志
* 参数说明： void
* 返回值  ：CICI_RELAY_INTERFACE_CONFIRM_NO   相邻联锁继电接口未确认
*			CICI_RELAY_INTERFACE_CONFIRM_YES  相邻联锁继电接已未确认
*/
UINT8 GetCiCiRelayInterfConfirmFlag(void)
{
	return CiCiRelayInterfaceConfirmFlag;
}

/*
* 功能描述： 设置继电接口确认标志
* 参数说明： UINT8 setFlag,设置标志
* 返回值  ：void
*/
void SetCiCiRelayInterfConfirmFlag(UINT8 setFlag)
{
	UINT8 localCi = 0u;/*本联锁ID*/
	UINT8 jj = 0u;
	UINT8 tranCiState = 0u;
	UINT8 sameLineFlag = SAME_LINE_ERR;/*标记两个CI是否属于同一条线路*/
	UINT8* pCiIdBuf = NULL;
	UINT8 ciSum = 0u;
	UINT8 dstCIType = 0u;/*目标联锁类型*/

	UINT8 allCommState = CI_ERROR;
	UINT8 funcId = EFUNC_SetCiCiRelayInterfaceConfirmFlag;
	UINT8 sendLevel = ESEND_LEVEL_ATS;

	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);

	if (FUNC_SWITCH_ON == funcSwitchSupportRelayInterface)
	{
		if (CICI_RELAY_INTERFACE_CONFIRM_YES == setFlag)
		{
			localCi = GetSystemParaLocalCiId();/*本联锁ID*/

			/*如果与相邻联锁通信都正常，则确认失败*/
			ciSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_CI);     /*获取通信联锁设备总数*/
			pCiIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_CI);/*获取和本联锁通信的联锁ID组*/

			for (jj = 0u; jj < ciSum; jj++)
			{
				sameLineFlag = IsSameLineCI(localCi, pCiIdBuf[jj]);

				if (SAME_LINE_YES == sameLineFlag)
				{
					dstCIType = GetCiType(pCiIdBuf[jj]);
					if (CI_TYPE_SCX != dstCIType)
					{
						tranCiState = GetCiTransmitState(CI_SYSTEM_TYPE_CI, pCiIdBuf[jj]);

						if (TRANSMIT_STATE_GOOD == tranCiState)
						{
							allCommState = CI_SUCCESS;
						}
						else
						{
							/*有一个通信中断就打断循环*/
							allCommState = CI_ERROR;

							break;
						}
					}
				}
			}
			if (CI_ERROR == allCommState)
			{/*有一个通信中断，才可以设置上*/
				CiCiRelayInterfaceConfirmFlag = setFlag;
			}
			else
			{/*报警，与相邻联锁通信都正常*/
				SetErrorData(funcId, CI_SYSTEM_TYPE_CI, localCi, ETYPE_COMM_WITH_NEIGHBOUR_CI, allCommState, sendLevel);
			}

		}
		else if (CICI_RELAY_INTERFACE_CONFIRM_NO == setFlag)
		{
			CiCiRelayInterfaceConfirmFlag = setFlag;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		debug_infor_printf((const)"funcSwitchSupportRelayInterface not 0xaa\n");
	}
}

/******************************相邻联锁继电接口确认状态**************END*****************************************************/
/*
* 功能描述： 根据进路状态清理信号保持容忍开放开始周期值
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void SetClearKeepSignalTolerateCyc(const UINT16 routeId)
{
	UINT8 bCiSwitchShowGreenYellow = FUNC_SWITCH_OFF;/*绿黄开关*/
	UINT8 routeLevel = 0u;/*进路等级*/
	UINT8 routeState = 0u;/*进路状态*/

	bCiSwitchShowGreenYellow = GetCiFunctionSwitchConfig(CI_FUNCTION_SWITCH_SHOW_SIGNAL_GreenYellow);
	if (FUNC_SWITCH_ON == bCiSwitchShowGreenYellow)/*如果显示绿黄灯开关【打开】*/
	{
		routeLevel = GetRouteLevel(routeId);
		if (ROUTE_LEVEL_CBTC == routeLevel)
		{
			(void)SetRouteKeepSigTolerateCyc(routeId, 0u);
		}
		else if (ROUTE_LEVEL_BLOC == routeLevel)
		{
			routeState = GetRouteState(routeId);
			if ((ROUTE_STATE_YUXIAN_OPEN != routeState) && (ROUTE_STATE_NEAR_OPEN != routeState))
			{
				(void)SetRouteKeepSigTolerateCyc(routeId, 0u);
			}
			else
			{
				/*什么也不做*/
			}
		}
		else
		{
			/*什么也不做*/
		}
	}
	else
	{
		/*什么也不做*/
	}

}

/*
* 功能描述： 设置PSC旁路状态确认标志
* 参数说明： UINT8 setFlag,设置标志
*            UINT16 pscId  PSC设备ID
* 返回值  ：无
*/
void SetCiPscPlConfirmFlag(UINT8 setFlag, const UINT16 pscId)
{
	/*变量初始化*/
	UINT8 i = 0u;
	UINT8 j = 0u;
	UINT8 lowBytePscId = 0u;
	UINT16 savePscId = 0u;
	UINT8 localCiId = 0u;
	UINT8 deviceSum = 0u;/*通信设备总数*/
	UINT8* pDeviceIdBuf = NULL;/*通信设备ID数组*/
	UINT8 transmitState = 0u;
	UINT8 pscSystemId = 0u;
	UINT8 funcId = EFUNC_SETCIPSCPLCONFIRMFLAG;
	UINT8 sendLevel = ESEND_LEVEL_ATS;
	UINT8 psdCiId = 0u;
	UINT8 psdAtsConfirmFlag = 0u;
	UINT8 pscNoPlStateNum = 0u;
	UINT8 localCiPsdNum = 0u;
	UINT8 errorFlag = 0u;
	UINT8 transmitReval = CI_ERROR;
	PSCToCiDataStruct* pscToCiDataStru = GetPscToCiDataStru();

	/*对变量赋值*/
	savePscId = pscId;
	lowBytePscId = (UINT8)(savePscId & 0x00FFU);

	deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_PSC);     /*获取通信PSC设备总数*/
	pDeviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_PSC); /*获取通信PSC设备ID数组*/
	localCiId = GetSystemParaLocalCiId();/*获取CI ID*/

	/*参数防护*/
	if (NULL != pscToCiDataStru)
	{
		for (i = 0u; i < deviceSum; i++)
		{
			/*匹配PSC ID*/
			if (lowBytePscId == pDeviceIdBuf[i])
			{
				pscSystemId = pDeviceIdBuf[i];
				/*PSC系统ID合法*/
				if (PSC_TO_CI_SUM_MAX > pscSystemId)
				{
					/*更新与CI通信状态*/
					transmitReval = UpdateCiTransmitState(localCiId, CI_SYSTEM_TYPE_PSC, pscSystemId);
					if (CI_SUCCESS == transmitReval)
					{
						transmitState = GetCiTransmitState(CI_SYSTEM_TYPE_PSC, pscSystemId);
					}
					/*设置旁路*/
					if (CI_PSC_PL_CONFIRM_YES == setFlag)
					{
						for (j = 0u; j < pscToCiDataStru[pscSystemId].psdSum; j++)
						{
							psdCiId = GetPsdBelongCiId(pscToCiDataStru[pscSystemId].psdDataStr[j].psdId);
							if (psdCiId == localCiId)
							{
								/*通信异常*/
								if (TRANSMIT_STATE_GOOD != transmitState)
								{
									/*设置对应PSC系统对应PSD旁路状态*/
									SetPsdConfirmFlag(pscToCiDataStru[pscSystemId].psdDataStr[j].psdId, setFlag);
								}
								else
								{
									errorFlag = 1u;
								}
							}
							/*不是本联锁*/
							else
							{
								/*添加相邻联锁命令*/
								AddCiSendToCiCmdInfo((UINT8)CI_CMD_SET_PSC_PL, pscToCiDataStru[pscSystemId].psdDataStr[j].psdId, pscId, psdCiId);
							}
						}
						if (1u == errorFlag)
						{
							/*报警，CI与对应PSC系统通信状态良好*/
							SetErrorData(funcId, CI_SYSTEM_TYPE_PSC, pscId, ETYPE_COMM_WITH_PSC, transmitState, sendLevel);
						}
					}
					else
					{
						/*数据置0*/
						pscNoPlStateNum = 0u;
						localCiPsdNum = 0u;
						for (j = 0u; j < pscToCiDataStru[pscSystemId].psdSum; j++)
						{
							psdCiId = GetPsdBelongCiId(pscToCiDataStru[pscSystemId].psdDataStr[j].psdId);
							if (psdCiId == localCiId)
							{
								localCiPsdNum++;
								/*获取屏蔽门ATS确认旁路标志*/
								psdAtsConfirmFlag = GetPsdPlFlag(pscToCiDataStru[pscSystemId].psdDataStr[j].psdId);
								if (CI_PSC_PL_CONFIRM_YES == psdAtsConfirmFlag)
								{
									/*设置取消确认标志*/
									SetPsdConfirmFlag(pscToCiDataStru[pscSystemId].psdDataStr[j].psdId, CI_PSC_PL_CONFIRM_NO);
								}
								else
								{
									/*不是旁路状态*/
									pscNoPlStateNum++;

								}
							}
							/*不是本联锁*/
							else
							{
								/*添加相邻联锁命令*/
								AddCiSendToCiCmdInfo((UINT8)CI_CMD_QX_PSC_PL, pscToCiDataStru[pscSystemId].psdDataStr[j].psdId, pscId, psdCiId);
							}
						}
						/*PSC下的PSD都不是PSC旁路状态，反馈报警*/
						if (pscNoPlStateNum == localCiPsdNum)
						{   /*报警*/
							SetErrorData(funcId, CI_SYSTEM_TYPE_PSC, pscId, ETYPE_PSC_CONFIRM_PL_STATE, CI_PSC_PL_CONFIRM_NO, sendLevel);
						}

					}
				}
				/*找到对应PSC ID，则跳出循环*/
				break;
			}
		}
	}
}

/*
* 功能描述： 根据保护区段开始选排周期值清除征用
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void ClearOverlopUsing(const UINT16 routeId)
{
	UINT8 overlapSum = 0u;/*保护区段数目*/
	UINT16* pOverlapIdBuf = NULL;/*保护区段*/
	UINT16 jj = 0u;

	overlapSum = GetRouteOverlapSum(routeId);  /*获取Overlap总数*/
	pOverlapIdBuf = GetRouteOverlapIdBuf(routeId);  /*获取Overlap ID BUF*/
	if ((NULL != pOverlapIdBuf) && (ROUTE_PROTECTSECGROUP_SUM_MAX >= overlapSum))
	{
		for (jj = 0u; jj < overlapSum; jj++)
		{
			SetOverlapRelSwitchUsing(pOverlapIdBuf[jj], SWITCH_USING_NO);
			SetOverlapXuanPaiStartCycNum(pOverlapIdBuf[jj], 0U);  /*进路状态空闲，清除保护区段的选排起始周期*/
			SetOverlapProSwtCheckStartFlag(pOverlapIdBuf[jj], PROSWITCH_CHECK_START_INVALID);  /*进路状态空闲，设置防护道岔检查开始标志为停止检查*/
			SetOverlapProSwtCheckResultFlag(pOverlapIdBuf[jj], PROSWITCH_CHECK_RESULT_DEFAULT);  /*防护道岔检查结果标志设置为默认值*/
		}
	}
}


/*
*函数功能：设置组合自动通过进路自动属性
*参数说明：const UINT16 groupAutoRouteId 组合自动进路ID
*返回值：无
*/
void SetGroupAutoRouteLogicManage(const UINT16 groupAutoRouteId)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT8 retCheck = CI_ERROR;
	UINT16 groupAutoRouteSum = 0u;              /*组合自动进路包含自动进路数目 (配置字段)*/
	UINT16* pgroupAutoRouteIdBuf = NULL;              /*组合自动进路包含自动进路进路ID数组 (配置字段)*/

	if ((0u != groupAutoRouteId) && (GROUP_AUTO_ROUTE_SUM_MAX > groupAutoRouteId))
	{
		/*获取组合自动进路信息*/
		groupAutoRouteSum = GetGroupAutoRouteHasRouteSum(groupAutoRouteId);
		pgroupAutoRouteIdBuf = GetGroupAutoRouteHasRouteIdBuff(groupAutoRouteId);

		/*组合自动进路有数据*/
		if (0u != groupAutoRouteSum)
		{
			for (i = 0u; i < groupAutoRouteSum; i++)
			{
				/*处理组合自动进路包含的自动进路逻辑*/
				retCheck = GroupInAutoRouteConditionCheck(pgroupAutoRouteIdBuf[i]);
				if (CI_ERROR == retCheck)
				{
					/*跳出循环*/
					break;
				}
			}
			/*判断最后返回值是成功*/
			if (CI_SUCCESS == retCheck)
			{
				for (i = 0u; i < groupAutoRouteSum; i++)
				{
					/*设置自动属性*/
					SetAutoRouteSetFlag(pgroupAutoRouteIdBuf[i], AUTO_ROUTE_SET_YES);
				}
			}
			else
			{
				/*发送报警*/
				SetErrorData(EFUNC_CHECK_GROUP_AUTO_ROUTE, CI_DEVICE_TYPE_GROUP_AUTO_ROUTE, groupAutoRouteId, ETYPE_GROUP_AUTO_ROUTE_STATE, CI_BACK_GROUP_AUTO_ROUTE_SET_ERR, ESEND_LEVEL_ATS);
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
*函数功能：取消组合自动通过进路自动属性
*参数说明：const UINT16 groupAutoRouteId 组合自动进路ID
*返回值：无
*/
void CancleGroupAutoRouteLogicManage(const UINT16 groupAutoRouteId)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 groupAutoRouteSum = 0u;              /*组合自动进路包含自动进路数目 (配置字段)*/
	UINT16* pgroupAutoRouteIdBuf = NULL;              /*组合自动进路包含自动进路进路ID数组 (配置字段)*/

	if ((0u != groupAutoRouteId) && (GROUP_AUTO_ROUTE_SUM_MAX > groupAutoRouteId))
	{
		/*获取组合自动进路信息*/
		groupAutoRouteSum = GetGroupAutoRouteHasRouteSum(groupAutoRouteId);
		pgroupAutoRouteIdBuf = GetGroupAutoRouteHasRouteIdBuff(groupAutoRouteId);

		/*组合自动进路有数据*/
		if (0u != groupAutoRouteSum)
		{
			for (i = 0u; i < groupAutoRouteSum; i++)
			{
				SetAutoRouteSetFlag(pgroupAutoRouteIdBuf[i], AUTO_ROUTE_SET_NO);
			}
		}
	}
}
/*
* 功能描述： 检查自动进路包含的进路是否属于本虚拟联锁
* 参数说明： 自动进路ID 虚拟联锁ID
* 返回值  ： void
*/
UINT8 CheckAutoRouteBelongVirCI(const UINT16 autoRouteId, const UINT8 virCIid)
{
	UINT8 autoIncludeRouteSum = 0u;
	UINT16* pAutoIncludeRouteIdbuf = NULL;
	UINT8 ii = 0u;
	UINT8 belongVirCIid = 0u;

	UINT8 returnValue = CI_ERROR;

	autoIncludeRouteSum = GetAutoRouteIncludeRouteSum(autoRouteId);
	pAutoIncludeRouteIdbuf = GetAutoRouteIncludeRouteBuf(autoRouteId);
	if ((NULL == pAutoIncludeRouteIdbuf) || (AUTO_ROUTE_INCLROUTE_SUM_MAX < autoIncludeRouteSum))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;
	}

	if (CI_SUCCESS == returnValue)
	{
		for (ii = 0u; ii < autoIncludeRouteSum; ii++)
		{
			belongVirCIid = GetRouteBelongVirCiId(pAutoIncludeRouteIdbuf[ii]);
			if (virCIid != belongVirCIid)
			{
				returnValue = CI_ERROR;
				break;
			}
		}
	}
	return returnValue;
}

/*
* 功能描述： 检查自动折返进路包含的进路是否属于输入虚拟联锁
* 参数说明： 自动进路ID 虚拟联锁ID
* 返回值  ： void
*/
UINT8 CheckAutoReturnBelongVirCI(const UINT16 autoRouteId, const UINT8 virCIid)
{
	UINT8 autoIncludeRouteSum = 0u;
	UINT16* pAutoIncludeRouteIdbuf = NULL;
	UINT8 ii = 0u;
	UINT8 belongVirCIid = 0u;

	UINT8 returnValue = CI_ERROR;

	autoIncludeRouteSum = GetAutoReturnIncludeRouteSum(autoRouteId);
	pAutoIncludeRouteIdbuf = GetAutoReturnIncludeRouteBuf(autoRouteId);
	if ((NULL == pAutoIncludeRouteIdbuf) || (AUTO_RETURN_INCLROUTE_SUM_MAX < autoIncludeRouteSum))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;
	}

	if (CI_SUCCESS == returnValue)
	{
		for (ii = 0u; ii < autoIncludeRouteSum; ii++)
		{
			belongVirCIid = GetRouteBelongVirCiId(pAutoIncludeRouteIdbuf[ii]);
			if (virCIid != belongVirCIid)
			{
				returnValue = CI_ERROR;
				break;
			}
		}
	}
	return returnValue;
}
/*
* 功能描述： 检查全自动折返进路包含的进路是否属于输入虚拟联锁
* 参数说明： 自动进路ID 虚拟联锁ID
* 返回值  ： void
*/
UINT8 CheckALLAutoReturnBelongVirCI(const UINT16 allAutoRouteId, const UINT8 virCIid)
{
	UINT8 autoIncludeRouteSum = 0u;
	UINT16* pAutoIncludeRouteIdbuf = NULL;
	UINT8 ii = 0u;
	UINT8 belongVirCIid = 0u;

	UINT8 returnValue = CI_ERROR;

	autoIncludeRouteSum = GetAllAutoReturnIncludeRouteSum(allAutoRouteId);
	pAutoIncludeRouteIdbuf = GetAllAutoReturnIncludeRouteBuf(allAutoRouteId);
	if ((NULL == pAutoIncludeRouteIdbuf) || (ALL_AUTO_RETURN_INCLROUTE_SUM_MAX < autoIncludeRouteSum))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;
	}

	if (CI_SUCCESS == returnValue)
	{
		for (ii = 0u; ii < autoIncludeRouteSum; ii++)
		{
			belongVirCIid = GetRouteBelongVirCiId(pAutoIncludeRouteIdbuf[ii]);
			if (virCIid != belongVirCIid)
			{
				returnValue = CI_ERROR;
				break;
			}
		}
	}
	return returnValue;
}

/*
* 功能描述： 进路物理区段或逻辑区段自动解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RoutePhyOrLogSecAutoUnlocManage(const UINT16 routeId)
{
	/*变量初始化*/
	UINT16 fLockLogId = 0u;   /*进路锁闭的第一个逻辑区段*/
	UINT8 logCurOccupyState = 0u;
	UINT8 logPreOccupyState = 0u;
	UINT8 routeType = 0u;
	UINT16 logBelongPhyId = 0u;
	UINT16 validReturnSigId = 0u; /*有效折返信号机*/
	UINT16 returnSecId = 0u; /*折返区段*/
	UINT16 dlockLogId = 0u;
	UINT32 logUnlockStartCycNum = 0u;
	UINT32 phyUnlockStartCycNum = 0u;
	UINT16 fLogBelongPhyId = 0u;
	UINT8 chPhyIncSwitchSum = 0U;
	UINT16* pPhySecSwitchId = NULL;
	UINT8 localCiType = 0U;/*联锁类型*/

	localCiType = GetLocalCiType();
	

	/*获取进路锁闭的第一逻辑区段占用状态*/
	fLockLogId = GetRouteFirstNormalLockLogId(routeId);
	logCurOccupyState = GetLogSecCurCtOrUtOccupyState(fLockLogId);
	logPreOccupyState = GetLogSecPreCtOrUtOccupyState(fLockLogId);

	/*第一个正常锁闭的逻辑区段所属的物理区段*/
	fLogBelongPhyId = GetLgcSecRelativePhySecId(fLockLogId);

	chPhyIncSwitchSum = GetPhyIncludeSwitchSum(fLogBelongPhyId);
	pPhySecSwitchId = GetPhySecIncludeSwitch(fLogBelongPhyId);
	/*获取进路信息*/
	routeType = GetRouteType(routeId);
	validReturnSigId = GetValidReturnSinalId(routeId, fLogBelongPhyId);
	returnSecId = GetSignalOutFirstPhySecId(validReturnSigId);

	/*进路第一个延时锁闭逻辑区段*/
	dlockLogId = GetRouteFirstDelayLockLogId(routeId);

	/*存在第一个锁闭的逻辑区段（逻辑区段是0，说明进路最后一个逻辑区段在延时中）*/
	if (fLockLogId > 0u)
	{
		/*折返进路且待解锁是折返区段、或者通过进路有对应的折返进路，且待解锁区段是折返区段*/
		if (((ROUTE_TYPE_RETURN == routeType) && (fLogBelongPhyId == returnSecId)) ||
			((ROUTE_TYPE_RETURN != routeType) && (0U <validReturnSigId) && (fLogBelongPhyId == returnSecId)))
		{
			/*按物理区段解锁*/
			RoutePhySecAutoUnlockManage(routeId);
		}
		else
		{
			/*逻辑区段当前CT占用，或者之前CT占用，当前空闲*/
			/*车辆段进路按照物理区段解锁*/
			if (((LOGICSECTION_OCCUPY_CT == logCurOccupyState) ||
				((LOGICSECTION_OCCUPY_NO == logCurOccupyState) && (LOGICSECTION_OCCUPY_CT == logPreOccupyState)))
				&& ((0U == chPhyIncSwitchSum) && (NULL != pPhySecSwitchId))
				&&(CI_TYPE_CLD != localCiType))
			{
				/*按逻辑区段解锁*/
				RouteLogSecAutoUnlockManage(routeId);
			}
			else
			{
				/*按物理区段解锁*/
				RoutePhySecAutoUnlockManage(routeId);
			}
		}
	}

	/*获取第一个延时锁闭逻辑区段*/
	dlockLogId = GetRouteFirstDelayLockLogId(routeId);
	logUnlockStartCycNum = GetLogUnlockStartCycNum(dlockLogId);

	/*获取第一延时锁闭逻辑区段所属物理区段*/
	logBelongPhyId = GetLgcSecRelativePhySecId(dlockLogId);

	/*获取物理区段延时解锁周期号*/
	phyUnlockStartCycNum = GetPhySecAutoUnlockStartCycNum(logBelongPhyId);

	/*逻辑区段延时解锁起始周期号大于0*/
	if ((dlockLogId > 0u) && (logUnlockStartCycNum > 0u))
	{
		/*延时解锁该逻辑区段*/
		LogSecDelayUnlockProc(routeId);
	}
	/*说明是物理区段在延时解锁*/
	else if ((dlockLogId > 0u) && (0u == logUnlockStartCycNum) && (phyUnlockStartCycNum > 0u))
	{
		/*按物理区段延时解锁*/
		PhySecDelayUnlockProc(routeId);
	}
	else
	{
		/*不做处理*/
	}

}

/*
* 功能描述： 进路逻辑区段自动解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLogSecAutoUnlockManage(const UINT16 routeId)
{
	/*变量初始化*/
	UINT16 lockLogId = 0u;
	UINT16 logBelongPhyId = 0u;
	UINT8 routeDir = 0u;
	UINT32 cycNum = 0u;
	UINT8 returnValue = 0u;          /*函数返回值*/


	/*区段解锁逻辑检查*/
	returnValue = RouteLogSecAutoUnlockProcess(routeId, &lockLogId);
	cycNum = Get2oo2CurCycleNum();
	routeDir = GetRouteDirection(routeId);
	/*未找到正常锁闭区段*/
	if (0u == lockLogId)
	{
		/*不做处理*/
	}
	else
	{
		/*解锁成功*/
		if (CI_SUCCESS == returnValue)
		{
			/*设置逻辑区段延时解锁*/
			SetLogSecLockState(lockLogId, LOG_SECTION_LOCK_DELAY, routeId, routeDir);
			/*设置逻辑区段延时解锁起始周期号*/
			SetLogUnlockStartCycNum(lockLogId, cycNum);
		}
		else if (RETURN_AUTOLOCK_ERR_EXCEPT == returnValue)
		{
			/*找到对应的物理区段*/
			logBelongPhyId = GetLgcSecRelativePhySecId(lockLogId);
#if 0
			logBelongPhyId = GetAxisSecRelativePhySecId(logBelongAxisId);
#endif
			/*设置物理区段异常锁闭*/
			SetPhySecLockState(logBelongPhyId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, routeDir);
			/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
			SetPhyIncludeLogLockState(logBelongPhyId, LOG_SECTION_LOCK_EXCEPT, routeId);

			/*-->设置自动解锁异常*/
			SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
	}
		else
		{
			/*不做处理*/
		}
}
}


/*
* 功能描述： 逻辑区段资源管理
* 参数说明： void
* 返回值  ：
*/
void LogicSecResManage(void)
{
	UINT16 wLogicCurSum = 0U;
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT16 wLogicPLockRouteId = 0u;	         /*逻辑区段防护锁闭进路ID*/
	UINT16 wLogicSecId = 0U;		/*逻辑区段ID*/
	UINT16 wLogicSecBelongCiId = 0u;        /*逻辑区段所属联锁ID*/
	UINT8 routeLevel = 0u;        /*进路监督级别*/
	UINT16 wTrainId = 0U;
	UINT16 ii = 0u;               /*循环索引*/

	UINT8 chLogicLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 startLockState = 0u;
	UINT8 startFlockFlag = 0u;
	UINT8 rtVal = CI_ERROR;
	UINT8 chFlagExec = CI_ERROR;/*继续执行标志*/
	UINT16 wOverlapId = 0u;
	UINT8 cOtherCiId = 0u;
	UINT8 chLogicSecProResCheckSta = CI_ERROR;/*逻辑区段防护锁闭资源可用性检查结果*/

	wLogicCurSum = GetLogicSecCurSum();
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	startLockState = GetStartLockFlag();        /*获取上电解锁标志*/
	startFlockFlag = GetStartFLockFlag();       /*获取上电解封标志*/


	if (0u == localCiId)
	{
		rtVal = CI_ERROR;
	}
	else
	{
		rtVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == rtVal)
	{

		if ((CI_START_LOCK_NO != startLockState) || (CI_START_FLOCK_NO != startFlockFlag))
		{/*未全站解封且未上电解锁*/
			rtVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == rtVal)
	{
		/*处理所有逻辑区段*/
		for (ii = 0u; ii < wLogicCurSum; ii++)
		{
			wLogicSecBelongCiId = 0u;          /*逻辑区段所属联锁ID*/
			routeLevel = 0u;          /*进路监督级别*/
			chFlagExec = CI_ERROR;
			chLogicSecProResCheckSta = CI_ERROR;/*逻辑区段防护锁闭资源可用性检查结果*/

			wLogicSecId = GetLogicSecId(ii);

			wLogicPLockRouteId = GetLogSecPLockRouteId(wLogicSecId);
			wLogicSecBelongCiId = GetLogSecBelongCiId(wLogicSecId);           /*获取逻辑区段所属联锁ID*/
			if ((0u == wLogicSecId) || (LOGIC_SECTION_SUM_MAX < wLogicSecId))
			{
				chFlagExec = CI_ERROR;
			}
			else
			{
				chFlagExec = CI_SUCCESS;
			}

			if (CI_SUCCESS == chFlagExec)
			{
				if (wLogicSecBelongCiId != localCiId)
				{
					chFlagExec = CI_ERROR;
				}
				else
				{
					; /*继续执行*/
				}
			}

			if (CI_SUCCESS == chFlagExec)
			{
				/*获取进路动态字段*/
				chLogicLockState = GetLogSecLockState(wLogicSecId);

				if ((0U < wLogicPLockRouteId) && ((LOG_SECTION_LOCK_PROTECT == chLogicLockState)
					|| (LOG_SECTION_LOCK_NORMAL == chLogicLockState) || (LOG_SECTION_LOCK_DELAY == chLogicLockState)))
				{
					/*此逻辑区段被防护锁闭，查保护区段可用性*/
					wOverlapId = GetRouteOverlapLockedId(wLogicPLockRouteId);
					/*获取保护区段检查状态*/
					chLogicSecProResCheckSta = OverlapUsableCheck(wOverlapId);
					/*逻辑区段有防护锁闭，若检查条件通过则可用*/
					if (CI_SUCCESS == chLogicSecProResCheckSta)
					{
						SetLogSecProResUseState(wLogicSecId, LOGIC_SECTION_PRO_RES_USABLE);
					}
					else
					{
						SetLogSecProResUseState(wLogicSecId, LOGIC_SECTION_PRO_RES_UNUSABLE);
					}
				}
				else
				{
					SetLogSecProResUseState(wLogicSecId, LOGIC_SECTION_PRO_RES_UNUSABLE);
				}

				/*设置所有列车在逻辑区段上的资源*/
				SetAllTrainLogicResUseable(wLogicSecId);
			}

			if (CI_SUCCESS == chFlagExec)
			{
				/* 添加相邻联锁进路资源锁命令 */
				cOtherCiId = GetLogSecResReqOtherCIId(wLogicSecId);
				wTrainId = GetLogSecResReqTrainId(wLogicSecId);
				if ((0u != cOtherCiId) && (cOtherCiId != localCiId) && (0u != wTrainId))
				{
					SetLogSecResReqOtherCIId(wLogicSecId, 0);
					SetLogSecResReqTrainId(wLogicSecId, 0);
					AddCiSendToCiCmdInfo(CI_CMD_LOGSEC_LOCK, wLogicSecId, wTrainId, cOtherCiId);
				}
			}
		}
		/*处理完成后，处理列车回撤资源*/
		TrainLogicSecResRetreatManage();
	}
}


/*
* 功能描述： 列车逻辑区段资源回撤管理
* 参数说明： void
* 返回值  ：
*/
static void TrainLogicSecResRetreatManage(void)
{
	/**变量初始化*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT16 wTrainId = 0U;
	UINT16 wTrainSum = 0U;
	UINT16 wTrainIncLogicSecIdBuf[TRAIN_INCLUDE_RES_MAX_SUM] = { 0U };
	UINT16  wTrainIncLogcSecSum = 0U;
	UINT16 wszTrainUsableLgcIdBuf[TRAIN_INCLUDE_RES_MAX_SUM] = { 0U };
	UINT16  wTrainUsableLgcSum = 0U;
	UINT16 wszSetUnUsableLgcIdBuf[TRAIN_INCLUDE_RES_MAX_SUM * 2U] = { 0U };
	UINT16  wTrainUnUsableLgcSum = 0U;
	UINT8  chTrainCommState = 0U;

	UINT8 chFuncRet = 0U;
	UINT16 ii = 0u;               /*循环索引*/
	UINT16 jj = 0u;               /*循环索引*/
	UINT16 kk = 0U;				  /*循环索引*/
	UINT8 rtVal = CI_ERROR;
	UINT8 chStartAdd = CI_ERROR;
	UINT8 chTrainTailLogFlag = CI_ERROR;
	UINT8 chFlagExec = CI_ERROR;/*继续执行标志*/
	UINT8 chLgcSecTrainApply = 0U;
	UINT8 chTrainSleepState = 0U;

	struct_PathPoint stTrainTailPoint = { 0U };
	UINT16 wTrainMinTailLink = 0U;
	UINT32 dwTrainMinTailOff = 0U;
	UINT16 wTmpLogicId = 0U;
	UINT8 chTmpLogicBelongCiId = 0U;
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	wTrainSum = GetTrainSum();
	rtVal = CI_SUCCESS;
	if (CI_SUCCESS == rtVal)
	{
		/*处理进路*/
		for (ii = 0u; ii < wTrainSum; ii++)
		{
			(void)CommonMemSet(wTrainIncLogicSecIdBuf, (UINT32)sizeof(wTrainIncLogicSecIdBuf), 0, (UINT32)sizeof(wTrainIncLogicSecIdBuf));
			(void)CommonMemSet(wszTrainUsableLgcIdBuf, (UINT32)sizeof(wszTrainUsableLgcIdBuf), 0, (UINT32)sizeof(wszTrainUsableLgcIdBuf));
			(void)CommonMemSet(wszSetUnUsableLgcIdBuf, (UINT32)sizeof(wszSetUnUsableLgcIdBuf), 0, (UINT32)sizeof(wszSetUnUsableLgcIdBuf));
			wTrainIncLogcSecSum = 0U;
			wTrainUsableLgcSum = 0U;
			wTrainUnUsableLgcSum = 0U;

			wTrainId = GetTrainId(ii);
			chTrainCommState = GetTrainTransitmitStat(wTrainId);
			chTrainSleepState = GetTrainSleepState(wTrainId);
			chFlagExec = CI_SUCCESS;
			chStartAdd = CI_ERROR;
			wTrainMinTailLink = GetTrainMinTailLink(wTrainId);
			dwTrainMinTailOff = GetTrainMinTailOffset(wTrainId);
			stTrainTailPoint.wLinkId = wTrainMinTailLink;
			stTrainTailPoint.dwOffset = dwTrainMinTailOff;
			wTmpLogicId = GetPointBelongLogSec(stTrainTailPoint);
			chTmpLogicBelongCiId = GetLogSecBelongCiId(wTmpLogicId);
			if ((TRAIN_COMM_STATE_GOOD == chTrainCommState)
				|| ((TRAIN_SLEEP_YES == chTrainSleepState) && (TRAIN_COMM_STATE_BAD == chTrainCommState)))
			{
				chFuncRet = CalTrainFrontLogicSecSeq(wTrainId, &wTrainIncLogcSecSum, wTrainIncLogicSecIdBuf);
				if (CI_SUCCESS != chFuncRet)
				{
					chFlagExec = CI_ERROR;
				}
				else
				{
					; /*继续执行*/
				}
			}
			if (CI_SUCCESS == chFlagExec)
			{
				chFuncRet = GetTrainUsableLogicSec(wTrainId, &wTrainUsableLgcSum, wszTrainUsableLgcIdBuf);
				if (CI_SUCCESS != chFuncRet)
				{
					chFlagExec = CI_ERROR;
				}
				else
				{

					; /*继续执行*/
				}
			}

			if (CI_SUCCESS == chFlagExec)
			{
				chTrainTailLogFlag = CI_ERROR;
				for (jj = 0U; jj < wTrainIncLogcSecSum; jj++)
				{
					/*找到第一个列车申请过的区段，防止查找不在范围里，导致不可用*/
					chLgcSecTrainApply = GetLogSecTrainApply(wTrainIncLogicSecIdBuf[jj], wTrainId);
					if ((wTrainIncLogicSecIdBuf[jj] == wTmpLogicId)
						|| (localCiId != chTmpLogicBelongCiId))
					{
						/*从车尾所在区段开始计算看是否有车申请过的*/
						chTrainTailLogFlag = CI_SUCCESS;
					}
					else
					{
						; /*不处理*/
					}
					if (((CI_SUCCESS == chTrainTailLogFlag)
						&& (LOGIC_SECTION_TRAIN_APPLY_YES == chLgcSecTrainApply)) /*能够找到逻辑区段并且*/
						|| (CI_SUCCESS == chStartAdd))				/*已经添加过*/
					{
						chStartAdd = CI_SUCCESS;

						for (kk = 0U; kk < wTrainUsableLgcSum; kk++)
						{
							if (wTrainIncLogicSecIdBuf[jj] == wszTrainUsableLgcIdBuf[kk])
							{
								break;
							}
							else
							{
								; /*继续执行*/
							}
						}

					}
					else
					{
						/*继续执行*/
					}
					if ((kk == wTrainUsableLgcSum) && (CI_SUCCESS == chStartAdd))
					{
						break;
					}
					else
					{
						; /*不处理*/
					}
				}

				/*找到可用后，查找第一个不可用的区段，并记录，后续置不可用*/
				(void)CommonMemCpy((void*)wszSetUnUsableLgcIdBuf, (UINT32)sizeof(wszSetUnUsableLgcIdBuf), (void*)(&wTrainIncLogicSecIdBuf[jj]), (UINT32)((wTrainIncLogcSecSum - jj) * sizeof(UINT16)));
				wTrainUnUsableLgcSum = wTrainIncLogcSecSum - jj;

				for (jj = 0U; jj < wTrainUsableLgcSum; jj++)
				{
					for (kk = 0U; kk < wTrainIncLogcSecSum; kk++)
					{
						if (wTrainIncLogicSecIdBuf[kk] == wszTrainUsableLgcIdBuf[jj])
						{
							break;
						}
						else
						{
							; /*继续执行*/
						}
					}

					if (kk == wTrainIncLogcSecSum)
					{
						wszSetUnUsableLgcIdBuf[wTrainUnUsableLgcSum++] = wszTrainUsableLgcIdBuf[jj];
					}
				}

				for (jj = 0U; jj < wTrainUnUsableLgcSum; jj++)
				{
					SetLogSecTrainUseState(wszSetUnUsableLgcIdBuf[jj], wTrainId, LOGIC_SECTION_RES_UNUSABLE);
				}
			}
		}
	}
}

/*
* 功能描述： 进路逻辑区段资源列车解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLgcSecResUnlockManage(const UINT16 wRouteId)
{
	/*变量初始化*/
	UINT8 chRouteState = 0u;
	UINT8 chAutoSigRouteState = 0U;
	UINT8 chStartSignalCurColor = 0U;
	UINT8 chOpenCloseState = 0U;
	UINT8 chRouteRepeatOpenFlag = 0U;
	UINT16 wStartSignalId = 0U;

	/*获取进路信息*/
	chRouteState = GetRouteState(wRouteId);
	wStartSignalId = GetRouteStartSignalId(wRouteId);
	chAutoSigRouteState = GetRouteAutoSigSetState(wRouteId);        /*获取自动信号进路状态*/
	chStartSignalCurColor = GetSignalCurColor(wStartSignalId);
	chOpenCloseState = GetSignalOpenCloseState(chStartSignalCurColor);
	chRouteRepeatOpenFlag = GetRouteRepeatOpenFlag(wRouteId);

	if ((SIGNAL_OPEN == chOpenCloseState) && (ROUTE_STATE_HALF_UNLOCK != chRouteState) && (ROUTE_STATE_AUTO_UNLOCK != chRouteState))
	{/*始端信号机开放*/

	}
	else
	{	/*始端信号机关闭*/
		if ((ROUTE_AUTOSIGROUTE_YES != chAutoSigRouteState)
			&& (ROUTE_REPEATOPEN_SET_YES != chRouteRepeatOpenFlag)
			&& ((ROUTE_STATE_AUTO_UNLOCK == chRouteState)
				|| (ROUTE_STATE_NEAR_LOCK == chRouteState)
				|| (ROUTE_STATE_HALF_UNLOCK == chRouteState))) /*部分锁闭相应列车释放解锁*/
		{
			RouteLgcSecResUnlockProcess(wRouteId);
		}
		else /*只处理释放资源*/
		{

		}
	}

	/*TODO:释放资源*/

	RouteLgcSecResReleaseProcess(wRouteId);
}


/*
* @brief 办理申请路径逻辑管理
* @param const UINT16 routeId 进路ID
*        const UINT16 trainId 列车编号
* @note 创建 WQM 20220307
*/
void RouteApplyLogicManage(const UINT16 routeId, const UINT16 trainId)
{
	UINT8 keepWork = CI_ERROR;
	UINT8 routeCurState = ROUTE_STATE_IDLE;
	UINT8 chRouteType = 0U;

	/** 入参检查*/
	if ((0u == routeId) || (ROUTE_SUM_MAX <= routeId) || (TRAIN_ID_MIN >= trainId) || (TRAIN_ID_MAX <= trainId))
	{
		keepWork = CI_ERROR;
	}
	else
	{
		keepWork = CI_SUCCESS;
	}
	if (CI_SUCCESS == keepWork)
	{
		chRouteType = GetRouteType(routeId);
		if ((ROUTE_TYPE_LIECHE == chRouteType)
			|| (ROUTE_TYPE_RETURN == chRouteType))
		{
			keepWork = CI_SUCCESS;
		}
		else
		{
			keepWork = CI_ERROR;
		}
	}
	/** 入参检查合法，可继续执行*/
	if (CI_SUCCESS == keepWork)
	{
		routeCurState = GetRouteState(routeId);

		if ((ROUTE_STATE_YUXIAN_OPEN != routeCurState) && (ROUTE_STATE_NEAR_OPEN != routeCurState))
		{
			/** 进入办理普通进路逻辑*/
			SetCommonRouteLogicManage(routeId, ESEND_LEVEL_ZERO);
		}
		else
		{
			/*进路已开放，不再办理进路*/
		}

		routeCurState = GetRouteState(routeId);

		/** 如果进路状态为【进路初锁】或【进路初锁异常】或【预先锁闭】或【预先开放】或【接近锁闭异常】或【接近开放】*/
		if ((ROUTE_STATE_FIRST_LOCK == routeCurState)
			|| (ROUTE_STATE_FIRST_LOCKERR == routeCurState)
			|| (ROUTE_STATE_YUXIAN_LOCK == routeCurState)
			|| (ROUTE_STATE_YUXIAN_OPEN == routeCurState)
			|| (ROUTE_STATE_NEAR_LOCKERR == routeCurState)
			|| (ROUTE_STATE_NEAR_OPEN == routeCurState))
		{
			/** 此时逻辑区段处于锁闭状态且还无需解锁，直接设置进路逻辑区段资源的列车ID*/
			SetRouteLogicSecResTrainId(routeId, trainId);
		}
		/*进路接近锁闭正常且已设置信号重开*/
		else if (ROUTE_STATE_NEAR_LOCK == routeCurState)
		{
			/*不设置进路逻辑区段资源的列车ID*/
		}
		/** 进路不是【进路空闲】状态*/
		else if (ROUTE_STATE_IDLE != routeCurState)
		{
			/** 进路办理成功但逻辑区段还未锁闭，暂不对逻辑区段增加列车ID，而是记录ITS申请路径包含的列车ID供逻辑区段锁闭时使用*/
			SetITSRouteApplyTrainIDInfo(routeId, trainId);
		}
		/** 进路空闲，即进路未办理成功*/
		else
		{
			/*无需处理*/
		}
	}
	else
	{

	}
}

/*
* @brief 办理申请部分路径逻辑管理
* @param const UINT8 cLogSecSeqDir 逻辑区段序列方向
*        const UINT16 wTrainId 列车编号
*        const UINT8 cLogSecSum 逻辑区段数量
*        const UINT16 pLogSecIdBuff[] 逻辑区段序列
*/
void RoutePartApplyLogicManage(const UINT8 cLogSecSeqDir, const UINT16 wTrainId, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[])
{
	/*局部变量初始化*/
	UINT8 keepWork = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 k = 0U;
	UINT16 wVBTCOccLogSecSum = 0U;   /*VBTC列车占压的逻辑区段数量*/
	UINT16 wVBTCOccLogSecID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };   /*VBTC列车占压的逻辑区段ID*/
	UINT8 cRelatedSigSum = 0U;      /*逻辑区段关联信号机数量*/
	UINT16* pRelatedSigId = NULL;   /*逻辑区段关联信号机ID数组*/
	UINT8 cSignalProDir = 0U;       /*信号机防护方向*/
	UINT8 tempIndex = 0U;
	UINT8 cEndSignalSum = 0U;       /*逻辑区段包含的同向的终端信号机数量，即拆分后的序列个数*/
	UINT16 wEndSignalIdBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };     /*逻辑区段包含的同向的终端信号机ID数组*/
	UINT8 cSplitLogSecSumBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };   /*拆分后的各逻辑区段序列包含的逻辑区段数量*/
	UINT16 wSplitLogSecIdBuff[ROUTE_SUBROUTE_SUM_MAX][MAX_ROUTE_IN_LT_NUM] = { 0U };  /*拆分后的各逻辑区段序列包含的逻辑区段ID数组*/
	UINT8 szQueryDir[UINT8_MAX] = { 0U };  /*逻辑区段对应的查询方向（逻辑方向）*/
	UINT8 cMatchedRouteSum = 0U;  /*逻辑区段序列匹配成功的进路数量，包含跨RC进路*/
	UINT16 wMatchedRouteIdBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };   /*逻辑区段序列匹配成功的进路ID数组，包含跨RC进路*/
	UINT8 cDrSubSum = 0U;  /*动态进路包含的子进路数量*/
	UINT16 wDrSubIdBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };   /*动态进路包含的子进路ID数组*/

	struct_PathPoint start = { 0u };  /*列车逻辑起点*/
	struct_PathPoint end = { 0u };    /*列车逻辑终点*/
	UINT16 wCTOccLogSum = 0U;         /*通信列车脚下逻辑区段数量*/
	UINT16 wCTOccLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };   /*通信列车占压的逻辑区段ID*/
	UINT8 cHalfRouteSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;  /*半截进路道岔可动标志*/
	UINT8 cHalfRouteFlag = CI_ERROR;  /*半截进路标志*/
	UINT16 wUsableDrId = 0U;        /*最小可用的动态进路ID*/
	UINT8 routeCurState = ROUTE_STATE_IDLE;  /*进路状态*/
	UINT8 cCheckStep = 0U;      /*记录代码运行到的位置，便于错误分析*/
	UINT8 cLocalCiId = 0U;
	UINT8 cRouteBelongCiId = 0U;
	UINT8 cLogSecBelongCiId = 0U;
	UINT16 wSigProLinkId = 0U;  /*信号机防护link*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;  /*方向变化点数量*/
	UINT8 cFirstLogSecDir = 0U;  /*序列内首个逻辑区段的查询方向（运营方向）*/
	UINT8 cLogicRouteNum = 0U;  /*拆分出的逻辑进路数量*/
	UINT8 szLrBelongCi[ROUTE_SUBROUTE_SUM_MAX] = { 0U };  /*拆分出的逻辑进路的所属控区*/
	UINT8 szLrDir[ROUTE_SUBROUTE_SUM_MAX] = { 0U };  /*拆分出的逻辑进路的方向*/
	UINT16 szLrStartSignalId[ROUTE_SUBROUTE_SUM_MAX] = { 0U };  /*拆分出的逻辑进路的始端信号机ID*/
	UINT8 szLrIncLogSecNum[ROUTE_SUBROUTE_SUM_MAX] = { 0U };  /*拆分出的逻辑进路包含的逻辑区段数量*/
	UINT16 szLrIncLogSecId[ROUTE_SUBROUTE_SUM_MAX][MAX_ROUTE_IN_LT_NUM] = { 0U };  /*拆分出的逻辑进路包含的逻辑区段ID*/
	UINT8 cEndSignalFlag = FLAG_UNSET;  /*逻辑区段是否存在终端信号机标志，初始化为不存在*/
	UINT16 wLastEndSignalId = 0U;  /*上一序列中的终端信号机ID*/
	UINT8 cLogicRouteFlag = FLAG_UNSET;  /*第一个逻辑区段序列是否为逻辑进路，默认不是*/
	UINT16 wUsableLogicRouteId = 0U;  /*可用的最小逻辑进路ID*/
	UINT8 cCiType = 0U;  /*联锁类型*/
	UINT8 cCommStateWithTrain = CI_ERROR;  /*与车通信状态*/
	UINT8 cFunRet = CI_ERROR;
	UINT8 cFunctionId = EFUNC_PART_ROUTE_CMD_PROC;
	UINT8 cSendLevel = ESEND_LEVEL_ATS;

	cLocalCiId = GetSystemParaLocalCiId();

	/*入参检查（列车ID暂不查）*/
	if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) || (CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir))
		&& (0U != cLogSecSum) && (NULL != pLogSecIdBuff))
	{
		keepWork = CI_SUCCESS;
	}
	else
	{
		keepWork = CI_ERROR;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第一步：检查逻辑区段序列是否连续*/
		keepWork = LogSecSeqIsContinuousCheck(cLogSecSeqDir, cLogSecSum, pLogSecIdBuff, szQueryDir);
		cCheckStep++;
		if (CI_ERROR == keepWork)
		{
			SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_CONTINUOUS, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
		}
		else
		{
			/*继续检查*/
		}
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第二步：检查列车脚下资源是否齐全、运行方向是否与ATS下发的运行方向匹配*/
		keepWork = TrainResAndDirCheck(wTrainId, szQueryDir[0U], cLogSecSum, pLogSecIdBuff, &cHalfRouteSwitchMoveFlag, &wVBTCOccLogSecSum, wVBTCOccLogSecID, cFunctionId, cSendLevel);
		cCheckStep++;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第三步：拆分逻辑区段序列*/
		for (i = 0U; i < cLogSecSum; i++)
		{
			/*获取逻辑区段关联信号机的数量/ID数组*/
			cRelatedSigSum = GetLogRelateEndSigSum(pLogSecIdBuff[i]);
			pRelatedSigId = GetLogRelateEndSigData(pLogSecIdBuff[i]);
			pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[i]);
			cEndSignalFlag = FLAG_UNSET;  /*每个逻辑区段先清一次无终端信号机标志*/

			/*选出逻辑区段关联信号机中防护方向与ATS下发的运行方向相同的信号机，并拆分逻辑区段序列*/
			if ((NULL != pRelatedSigId) && (NULL != pLogSecIncLinkId))
			{
				for (j = 0U; j < cRelatedSigSum; j++)
				{
					cSignalProDir = GetSignalDirection(pRelatedSigId[j]);
					wSigProLinkId = GetSignalProtectLink(pRelatedSigId[j]);
					strCurPoint.Lnk = pLogSecIncLinkId[0U];
					strCurPoint.Off = 0U;
					strNxtPoint.Lnk = wSigProLinkId;
					strNxtPoint.Off = 0U;
					cDirChangeNum = GetDirChangeNumBtwPoints(&strCurPoint, &strNxtPoint);  /*查询当前link到信号机防护link间的方向变化点*/
					cSignalProDir = TransDirByChangeNum(cSignalProDir, cDirChangeNum);

					if (cSignalProDir == szQueryDir[i])
					{
						/*以当前信号机为分界点，拆分出逻辑区段序列*/
						for (k = tempIndex; k < (i + 1U); k++)
						{
							wSplitLogSecIdBuff[cEndSignalSum][cSplitLogSecSumBuff[cEndSignalSum]] = pLogSecIdBuff[k];   /*存储被拆分的逻辑区段序列ID*/
							cSplitLogSecSumBuff[cEndSignalSum]++;      /*存储当前被拆分的逻辑区段序列包含的逻辑区段数量*/
						}

						wLastEndSignalId = pRelatedSigId[j];  /*存储本序列的终端信号机ID，作为后一逻辑进路的始端信号机*/
						wEndSignalIdBuff[cEndSignalSum] = pRelatedSigId[j];  /*存储同向的终端信号机ID*/
						cEndSignalSum++;
						tempIndex = i + 1U;  /*存储当前索引位置，用于下次拆分逻辑区段序列的起点*/

						cEndSignalFlag = FLAG_SET;  /*逻辑区段存在终端信号机，置上存在标志*/
						break;
					}
					else
					{
						/*非同向终端信号机，不处理*/
					}
				}

				if ((i == (cLogSecSum - 1U)) && (FLAG_UNSET == cEndSignalFlag))
				{
					/*最后一个逻辑区段不存在终端信号机，根据逻辑区段所属控区将剩下的逻辑区段填入逻辑进路包含的逻辑区段数组中*/
					for (k = tempIndex; k < cLogSecSum; k++)
					{
						cLogSecBelongCiId = GetLogSecBelongCiId(pLogSecIdBuff[k]);

						if ((0U == szLrBelongCi[cLogicRouteNum]) && (0U != cLogSecBelongCiId))
						{
							szLrBelongCi[cLogicRouteNum] = cLogSecBelongCiId;  /*为第一条逻辑进路添加进路所属控区*/
							szLrDir[cLogicRouteNum] = szQueryDir[k];  /*存储逻辑进路的方向*/
							szLrStartSignalId[cLogicRouteNum] = wLastEndSignalId;  /*存储逻辑进路的始端信号机ID*/
							wLastEndSignalId = 0U;  /*仅第一条逻辑进路的始端信号机为上一序列的终端信号机，其余逻辑进路始端信号机ID默认为0*/
						}

						if ((cLogSecBelongCiId != szLrBelongCi[cLogicRouteNum]) && (0U != cLogSecBelongCiId))
						{
							cLogicRouteNum++;
							szLrBelongCi[cLogicRouteNum] = cLogSecBelongCiId;  /*为逻辑进路添加进路所属控区*/
							szLrDir[cLogicRouteNum] = szQueryDir[k];  /*存储逻辑进路的方向*/
							szLrStartSignalId[cLogicRouteNum] = wLastEndSignalId;  /*存储逻辑进路的始端信号机ID*/
						}

						szLrIncLogSecId[cLogicRouteNum][szLrIncLogSecNum[cLogicRouteNum]] = pLogSecIdBuff[k];   /*存储被拆分的逻辑区段序列ID*/
						szLrIncLogSecNum[cLogicRouteNum]++;      /*存储当前被拆分的逻辑区段序列包含的逻辑区段数量*/
					}

					cLogicRouteNum++;

					keepWork = LogSecIsSwitchAndStopAreaCheck(pLogSecIdBuff[cLogSecSum - 1U]);  /*检查最后一个逻辑区段的停车区域属性*/
				}
			}
			else
			{
				keepWork = CI_ERROR;
			}

			/*检查序列数量及包含的逻辑区段数量是否越界*/
			keepWork &= SeqNumAndIncLogSecNumCheck(cEndSignalSum, cSplitLogSecSumBuff);
			keepWork &= SeqNumAndIncLogSecNumCheck(cLogicRouteNum, szLrIncLogSecNum);
			
			if (CI_ERROR == keepWork)
			{
				SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_MATCH_ROUTE, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
				break;  /*拆分失败，停止遍历*/
			}
			else
			{
				/*继续检查*/
			}
		}

		cCheckStep++;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第四步：拆分逻辑区段序列，与进路进行匹配*/
		if (0U != cEndSignalSum)
		{
			keepWork = LogSecSeqAndRouteMatchCheck(cEndSignalSum, wEndSignalIdBuff, cSplitLogSecSumBuff, wSplitLogSecIdBuff, wMatchedRouteIdBuff, &cLogicRouteFlag);

			if (FLAG_UNSET == cLogicRouteFlag)
			{
				cMatchedRouteSum = cEndSignalSum;
			}
			else
			{
				/*将未匹配的首个序列存入逻辑进路包含的逻辑区段数组中*/
				for (k = 0U; k < cSplitLogSecSumBuff[0U]; k++)
				{
					szLrIncLogSecId[cLogicRouteNum][szLrIncLogSecNum[cLogicRouteNum]] = wSplitLogSecIdBuff[0U][k];  /*存储逻辑进路的逻辑区段序列ID*/
					szLrIncLogSecNum[cLogicRouteNum]++;  /*存储逻辑进路的逻辑区段数量*/
				}

				cLogSecBelongCiId = GetLogSecBelongCiId(wSplitLogSecIdBuff[0U][0U]);
				szLrBelongCi[cLogicRouteNum] = cLogSecBelongCiId;  /*为逻辑进路添加进路所属控区*/
				szLrDir[cLogicRouteNum] = szQueryDir[0U];  /*存储逻辑进路的方向*/
				szLrStartSignalId[cLogicRouteNum] = 0U;  /*首个序列的逻辑进路其始端信号机默认为0*/
				cLogicRouteNum++;

				keepWork &= LogSecIsSwitchAndStopAreaCheck(szLrIncLogSecId[cLogicRouteNum - 1U][szLrIncLogSecNum[cLogicRouteNum - 1U] - 1U]);  /*检查最后一个逻辑区段的停车区域属性*/
				keepWork &= SeqNumAndIncLogSecNumCheck(cLogicRouteNum, szLrIncLogSecNum);  /*校验逻辑进路数量及其包含的逻辑区段数量是否超限*/

				/*清除匹配进路中存在的逻辑进路信息*/
				cMatchedRouteSum = cEndSignalSum - 1U;  /*存在逻辑进路，匹配的进路数量需减1*/
				for (k = 0U; k < cMatchedRouteSum; k++)
				{
					/*存在逻辑进路，匹配的第一条进路ID为0，需删除*/
					wMatchedRouteIdBuff[k] = wMatchedRouteIdBuff[k + 1U];
					wMatchedRouteIdBuff[k + 1U] = 0U;

					for (j = 0U; j < cSplitLogSecSumBuff[k + 1U]; j++)
					{
						/*存在逻辑进路，需将拆分出的第一个逻辑区段序列删除，避免影响后续半截子进路包含的逻辑区段*/
						wSplitLogSecIdBuff[k][j] = wSplitLogSecIdBuff[k + 1U][j];
						wSplitLogSecIdBuff[k + 1U][j] = 0U;
					}

					cSplitLogSecSumBuff[k] = cSplitLogSecSumBuff[k + 1U];  /*删除第一个逻辑区段序列包含的逻辑区段数量*/
					cSplitLogSecSumBuff[k + 1U] = 0U;
				}
			}

			if (CI_ERROR == keepWork)
			{
				SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_MATCH_ROUTE, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
			}
			else
			{
				/*继续检查*/
			}
		}

		cCheckStep++;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第五步：检查通信车有没有前端可疑*/
		keepWork = CtTrainHeadSuspCheck(wTrainId, cLogSecSeqDir, pLogSecIdBuff[0U]);

		if (CI_ERROR == keepWork)
		{
			SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SCREEN, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
		}
		else
		{
			/*继续检查*/
		}		
		cCheckStep++;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第六步：筛选半截进路，进路办理条件检查*/
		cCommStateWithTrain = GetTrainTransitmitStat(wTrainId);

		if (TRAIN_COMM_STATE_GOOD == cCommStateWithTrain)
		{
			end.wLinkId = GetTrainMaxHeadLink(wTrainId);
			end.dwOffset = GetTrainMaxHeadOffset(wTrainId);
			start.wLinkId = GetTrainMinTailLink(wTrainId);
			start.dwOffset = GetTrainMinTailOffset(wTrainId);
			keepWork = GetLogSecBtwTwoPoints(start, end, &wCTOccLogSum, wCTOccLogID);  /*获取通信车脚下逻辑区段信息，此处不用考虑方向*/
		}
		else
		{
			wCTOccLogSum = 0U;  /*非通信车，不处理*/
		}

		if (CI_SUCCESS == keepWork)
		{
			debug_infor_printf((const)"HalfRouteSwitchMoveFlag:0x%x\n", cHalfRouteSwitchMoveFlag);
			debug_infor_printf((const)"Half Route Id:[ ");
			/*动态进路传递*/
			for (i = 0U; i < cMatchedRouteSum; i++)
			{
				cHalfRouteFlag = HalfRouteTypeCheck(i, wMatchedRouteIdBuff, wCTOccLogSum, wCTOccLogID, cLogicRouteFlag);

				/*确定需要传给相邻联锁的逻辑区段序列查询方向*/
				cRouteBelongCiId = GetRouteBelongCiId(wMatchedRouteIdBuff[i]);
				cCiType = GetCiType(cRouteBelongCiId);
				if (0U == i)
				{
					tempIndex = 0U;
				}
				else
				{
					tempIndex += cSplitLogSecSumBuff[i - 1U];
				}

				if (CI_SUCCESS == cHalfRouteFlag)  /*半截进路处理*/
				{
					if ((cLocalCiId == cRouteBelongCiId) && (0U != cLocalCiId))
					{
						/*填充半截进路结构体*/
						SetHalfRouteSwitchMoveValid(wMatchedRouteIdBuff[i], cHalfRouteSwitchMoveFlag);  /*设置半截进路道岔可动标志*/
						SetHalfRouteLockLgcSec(wMatchedRouteIdBuff[i], cSplitLogSecSumBuff[i], wSplitLogSecIdBuff[i]);  /*设置半截进路锁闭的逻辑区段数据*/
						SetHalfRouteResReqTrainId(wMatchedRouteIdBuff[i], wTrainId);  /*设置发送资源请求的列车ID*/
						SetHalfRouteTrainLocLgcSec(wMatchedRouteIdBuff[i], (UINT8)wVBTCOccLogSecSum, wVBTCOccLogSecID);  /*设置半截进路列车脚下逻辑区段数据*/

						keepWork = HalfRoutePhySecUseLogicProcess(wMatchedRouteIdBuff[i]);  /*半截子进路区段征用检查*/
						if (CI_SUCCESS == keepWork)
						{
							debug_infor_printf((const)"%d,", wMatchedRouteIdBuff[i]);
							wDrSubIdBuff[cDrSubSum] = wMatchedRouteIdBuff[i];
							cDrSubSum++;
						}
						else
						{
							debug_infor_printf((const)"HalfRoutePhySecUseLogicProcess Err!\n");
						}
					}
					else if ((cLocalCiId != cRouteBelongCiId) && (0U != cLocalCiId))
					{
						cFunRet = RouteCldAttrCheck(wMatchedRouteIdBuff[i]);  /*进路场段属性检查*/
						if (CI_SUCCESS == cFunRet)
						{
							/*非车辆段或为车辆段出库/段进路，添加到发送给相邻联锁动态进路命令结构体*/
							cFirstLogSecDir = ConvertLogicDirToRun(szQueryDir[tempIndex]);
							AddCiSendToCiDrCmdHalfInfo(wTrainId, (UINT8)wVBTCOccLogSecSum, wVBTCOccLogSecID, cHalfRouteSwitchMoveFlag, 0U);
							AddCiSendToCiDrCmdLogSecInfo(CICI_DR_CMD_HALF, cFirstLogSecDir, cSplitLogSecSumBuff[i], wSplitLogSecIdBuff[i], cRouteBelongCiId);
						}
						else
						{
							/*不处理*/
						}
					}
					else
					{
						/*不处理*/
					}
				}
				else  /*完整进路处理*/
				{
					keepWork = RoutePhySectionUseLogicProcess(wMatchedRouteIdBuff[i]);  /*完整子进路区段征用检查*/
					if (CI_SUCCESS == keepWork)
					{
						if ((cLocalCiId == cRouteBelongCiId) && (0U != cLocalCiId))
						{
							routeCurState = GetRouteState(wMatchedRouteIdBuff[i]);
							/*进路是【进路空闲】状态*/
							if ((ROUTE_STATE_IDLE == routeCurState) || (ROUTE_STATE_HALF_UNLOCK == routeCurState))
							{
								/*进路办理条件检查通过，记录ITS申请路径包含的列车ID供逻辑区段锁闭时使用*/
								SetITSRouteApplyTrainIDInfo(wMatchedRouteIdBuff[i], wTrainId);
							}
							else
							{
								/*无需处理*/
							}
							wDrSubIdBuff[cDrSubSum] = wMatchedRouteIdBuff[i];
							cDrSubSum++;
						}
						else if ((cLocalCiId != cRouteBelongCiId) && (0U != cLocalCiId) && (CI_TYPE_CLD != cCiType))
						{
							/*对方控区非场段，添加到发送给相邻联锁动态进路命令结构体*/
							cFirstLogSecDir = ConvertLogicDirToRun(szQueryDir[tempIndex]);
							AddCiSendToCiDrCmdHalfInfo(wTrainId, (UINT8)wVBTCOccLogSecSum, wVBTCOccLogSecID, cHalfRouteSwitchMoveFlag, 0U);
							AddCiSendToCiDrCmdLogSecInfo(CICI_DR_CMD_FULL, cFirstLogSecDir, cSplitLogSecSumBuff[i], wSplitLogSecIdBuff[i], cRouteBelongCiId);
						}
						else
						{
							/*不处理*/
						}
					}
				}

				if (CI_SUCCESS != keepWork)
				{
					break;  /*任意子进路失败，则动态进路办理失败*/
				}
			}
			debug_infor_printf((const)"]\n");

			if ((CI_SUCCESS == keepWork) && (0U != cDrSubSum))
			{
				/*将匹配的进路传递至动态进路处理*/
				wUsableDrId = GetUsableDrId();
				SetDrSubRoute(wUsableDrId, cDrSubSum, wDrSubIdBuff);

				debug_infor_printf((const)"Dynamic Sub Route Sum:%d, Dynamic Sub Route ID:[", cDrSubSum);
				for (i = 0U; i < cDrSubSum; i++)
				{
					debug_infor_printf((const)"%d,", wDrSubIdBuff[i]);
				}
				debug_infor_printf((const)"]\n");
			}

			/*逻辑进路传递*/
			for (i = 0U; i < cLogicRouteNum; i++)
			{
				if (0U == szLrStartSignalId[i])
				{
					/*逻辑进路始端信号机为0，需考虑是否为ATS将部分进路和逻辑进路拆分办理的结果*/
					szLrStartSignalId[i] = LogicRouteAddStartSignalCheck(szLrIncLogSecId[i][0U], szLrDir[i], wTrainId);
				}

				keepWork = CheckLogicRouteCbtcProperty(szLrIncLogSecNum[i], szLrIncLogSecId[i]);  /*检查逻辑进路内逻辑区段的CBTC属性*/
				if (CI_SUCCESS == keepWork)
				{
					cCiType = GetCiType(szLrBelongCi[i]);
					if ((cLocalCiId == szLrBelongCi[i]) && (0U != cLocalCiId))
					{
						/*逻辑进路处理：填充逻辑进路结构体*/
						wUsableLogicRouteId = GetUsableLogicalRouteId();
						if (0U != wUsableLogicRouteId)
						{
							keepWork = RepeatSetLogicRouteCheck(szLrIncLogSecNum[i], szLrIncLogSecId[i], wTrainId);  /*检查逻辑进路是否重复办理*/

							if (CI_SUCCESS == keepWork)
							{
								cLocalCiId = GetSystemParaLocalCiId();  /*获取本联锁ID*/
								cFirstLogSecDir = ConvertLogicDirToRun(szLrDir[i]);  /*将逻辑方向转为运营方向*/

								SetLogicalRouteBelongCiId(wUsableLogicRouteId, cLocalCiId);
								SetLogicalRouteDir(wUsableLogicRouteId, cFirstLogSecDir);  /*设置逻辑进路方向*/
								SetLogicalRouteSwitchMoveFlag(wUsableLogicRouteId, cHalfRouteSwitchMoveFlag);  /*设置逻辑进路道岔可动标志*/
								SetLogicalRouteRelateBeginSigId(wUsableLogicRouteId, szLrStartSignalId[i]);  /*设置逻辑进路始端信号机*/
								LogicRouteLevelConfirmProcess(wUsableLogicRouteId);  /*确定逻辑进路监督级别*/
								SetLogRouteApplyResTrainData(wUsableLogicRouteId, wTrainId);  /*设置ATS申请的资源列车ID*/
								SetLogicalRouteInLogSecData(wUsableLogicRouteId, szLrIncLogSecNum[i], szLrIncLogSecId[i]);  /*设置逻辑进路包含的逻辑区段*/
								SetLogicalRouteTrainLogSecData(wUsableLogicRouteId, wVBTCOccLogSecSum, wVBTCOccLogSecID);  /*设置列车脚下包含的逻辑区段*/
								LogicRouteOpenColorProc(wUsableLogicRouteId);  /*设置逻辑进路始端信号机开放颜色*/
								LogRouteOutLgcSecConfigDataInit(wUsableLogicRouteId);

								/*区段征用通过，设置逻辑进路状态为初选，否则设置逻辑进路状态空闲*/
								keepWork = LogRoutePhySecUseLogicProcess(wUsableLogicRouteId);
								if (CI_SUCCESS == keepWork)
								{
									SetLogRouteStateManage(wUsableLogicRouteId, ROUTE_LOGICAL_STATE_FIRST_XUANPAI);

									debug_infor_printf((const)"Dynamic Logic Route Set Is Success! Dynamic Logic Route ID:%d\n", wUsableLogicRouteId);
								}
								else
								{
									SetLogRouteStateManage(wUsableLogicRouteId, ROUTE_LOGICAL_STATE_IDLE);
								}
							}
							else
							{
								SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_REPEAT, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
								debug_infor_printf((const)"Dynamic Logic Route Set Is Error: LogicRoute Repeat Set!\n");  /*逻辑进路重复办理或非停车区域*/
							}
						}
						else
						{
							/*无空闲逻辑进路，不处理*/
							debug_infor_printf((const)"Dynamic Logic Route Set Is Error: LogicRoute Is Not Idle!\n");
						}
					}
					else if ((cLocalCiId != szLrBelongCi[i]) && (0U != cLocalCiId) && (CI_TYPE_CLD != cCiType))
					{
						/*添加到发送给相邻联锁逻辑进路命令结构体*/
						cFirstLogSecDir = ConvertLogicDirToRun(szLrDir[i]);
						AddCiSendToCiDrCmdHalfInfo(wTrainId, (UINT8)wVBTCOccLogSecSum, wVBTCOccLogSecID, cHalfRouteSwitchMoveFlag, szLrStartSignalId[i]);
						AddCiSendToCiDrCmdLogSecInfo((UINT8)CICI_DR_CMD_LOGIC, cFirstLogSecDir, szLrIncLogSecNum[i], szLrIncLogSecId[i], szLrBelongCi[i]);
					}
					else
					{
						/*不处理*/
					}
				}
				else
				{
					SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SEC_CBTC, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
					debug_infor_printf((const)"Dynamic Logic Route Set Is Error: LogSec Is Not CBTC Property!\n");  /*逻辑进路办理办理失败，逻辑区段非CBTC属性*/
				}
			}
		}

		cCheckStep++;
	}

	/*记录错误日志*/
	if (CI_SUCCESS != keepWork)
	{
		/*办理失败，记录错误日志，
		cCheckStep：为0表示入参校验失败，为1表示逻辑区段序列连续性检查失败，为2表示列车脚下资源和方向检查失败，为3表示拆分序列失败，
					为4表示序列匹配进路失败，为5表示序列内隐藏车检查失败，为6表示进路办理条件检查失败*/
		debug_infor_printf((const)"Route Part Apply Error! Error Position Is [%d]\n", cCheckStep);
	}
}

/*
* 功能描述： 开放限速信号逻辑管理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： void
* note：修复bug YF0083-200
*/
void OpenXianSuSignalLogicManage(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT8 chKeepWork = CI_ERROR;		 /*标志位*/
	UINT16 wSignalInFirstPhyId = 0U;
	UINT16 wLockRouteId = 0U;
	UINT16 wRouteStartSignalId = 0U;
	UINT8 chRouteLevel = 0U;
	UINT8 cRouteZongQuXiaoState = 0u;
	UINT8 cRouteZongRenJieState = 0u;

	if ((0u == signalId) || (SIGNAL_SUM_MAX <= signalId))
	{
		chKeepWork = CI_ERROR;
	}
	else
	{
		chKeepWork = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chKeepWork)
	{

		wSignalInFirstPhyId = GetSignalInFirstLockedPhySecId(signalId);
		wLockRouteId = GetPhySecRLockBelongRouteId(wSignalInFirstPhyId);/*物理区段锁闭所属进路ID*/
		if ((0u == wLockRouteId) || (ROUTE_SUM_MAX <= wLockRouteId))
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		chRouteLevel = GetRouteLevel(wLockRouteId);

		/*进路等级为点式进路*/
		if (ROUTE_LEVEL_BLOC != chRouteLevel)
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		/**检查进路内和进路保护区段内是否至少有一个逻辑区段设置了临时限速*/
		chKeepWork = CheckRouteLgsLinShiXianSuExist(wLockRouteId);
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		cRouteZongQuXiaoState = GetRouteZongQuXiaoFlag(wLockRouteId);
		cRouteZongRenJieState = GetRouteZongRenJieFlag(wLockRouteId);
		if ((ROUTE_ZONGQUXIAO_SET_YES == cRouteZongQuXiaoState) ||
			(ROUTE_ZONGRENJIE_SET_YES == cRouteZongRenJieState))
		{ /*无总取消或总人解*/
			SetErrorData(EFUNC_CANCLE_ROUTE, CI_DEVICE_TYPE_ROUTE, wLockRouteId, ETYPE_ROUTE_CANCEL, CI_ERROR, ESEND_LEVEL_ATS);/*总取消或总人解时，信号重开无效，记录故障并给现地和ATS发送反馈*/
			chKeepWork = CI_ERROR;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		wRouteStartSignalId = GetRouteStartSignalId(wLockRouteId);
		if (signalId == wRouteStartSignalId)
		{ /*是进路始端信号机ID*/
			routeState = GetRouteState(wLockRouteId);  /*获取进路状态*/

			if ((ROUTE_STATE_FIRST_LOCKERR == routeState) ||
				(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
				(ROUTE_STATE_NEAR_LOCKERR == routeState) ||
				(ROUTE_STATE_NEAR_LOCK == routeState))
			{ /*进路状态为: 初锁异常||预先锁闭||接近锁闭异常||接近锁闭正常。修改日期：20170209。原因：支持在接近锁闭正常时响应信号重开命令。*/

				SetRouteXianSuConfirmStt(wLockRouteId, ROUTE_XIANSU_CONFIRM_YES);
				SetRouteRepeatOpenFlag(wLockRouteId, ROUTE_REPEATOPEN_SET_YES);  /*设置进路信号重开标志*/

				SetRouteOpenSigStartCycNum(wLockRouteId, Get2oo2CurCycleNum());  /*设置信号开放时间*/
#if 0
				SetOverlapLockStartCycNum(routeId,Get2oo2CurCycleNum());  /* 设置保护区段锁闭时间 */
#endif
			}
			else if (ROUTE_STATE_DELAY_UNLOCK == routeState)
			{/*总人解延时解锁期间，信号重开无效，记录故障并给现地和ATS发送反馈*/
				SetErrorData(EFUNC_CANCLE_ROUTE, CI_DEVICE_TYPE_ROUTE, wLockRouteId, ETYPE_ROUTE_CANCEL, CI_ERROR, ESEND_LEVEL_ATS);
			}
			else
			{
				; /*DO NOTHING*/
			}

		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述：TIOC与逻辑区段跳跃锁闭所属IVOC不同通信状态下的处理
* 参数说明：const UINT16 logSectionId，逻辑区段ID
			const UINT16 trainId,列车ID
* 返回值  ： void
* 创建	  ：
*/
static void TrainTransitmitStatJumpLockProcess(const UINT16 logSectionId, const UINT16 trainId)
{
	UINT8 logSecJumpDelayUnlockFlag = LOGIC_JUMPUNLOCK_DELAY_SET_NO;
	UINT32 startTimeCycle = 0u;
	UINT32 secJumpLockDelayUnlockCount = 0u;
	UINT8 overTimeCheck = CI_TIME_OUT;
	UINT32 curCycle = 0u;
	UINT8 trainTransmitState = TRAIN_COMM_STATE_UNKNOWN;
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 localCi = 0u;/*本联锁*/
	UINT8 logSecBelongCiId = 0u;


	localCi = GetSystemParaLocalCiId();

	curCycle = Get2oo2CurCycleNum();

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 入参检查*/
	if ((LOGIC_SECTION_SUM_MAX > bufIndex)
		&& (TRAIN_ID_MIN < trainId) && (TRAIN_ID_MAX > trainId))
	{
		logSecBelongCiId = GetLogSecBelongCiId(logSectionId);
		if (localCi == logSecBelongCiId)
		{
			/** 获取IVOC与TIOC通信状态*/
			trainTransmitState = GetTrainTransitmitStat(trainId);
			/** 通信状态良好*/
			if (TRAIN_COMM_STATE_GOOD == trainTransmitState)
			{
				/** 恢复通信，倒计时立即结束 */
				/** 清除区段跳跃锁闭延时解锁起始周期号和延时解锁设置标志*/
				SetLogSecJumpDelayUnlocStartCyc(logSectionId, 0u);
				SetLogSecJumpDelayUnlockFlag(logSectionId, LOGIC_JUMPUNLOCK_DELAY_SET_NO);
			}
			else
			{
				/** 通信中断 */
				logSecJumpDelayUnlockFlag = GetLogSecJumpDelayUnlockFlag(logSectionId);
				/** 未设置延时解锁标志 */
				if (LOGIC_JUMPUNLOCK_DELAY_SET_NO == logSecJumpDelayUnlockFlag)
				{
					/** 设置区段跳跃锁闭延时解锁起始周期号和延时解锁设置标志*/
					SetLogSecJumpDelayUnlocStartCyc(logSectionId, curCycle);
					SetLogSecJumpDelayUnlockFlag(logSectionId, LOGIC_JUMPUNLOCK_DELAY_SET_YES);
				}
				else
				{
					/** 已设置延时解锁标志，判断延时解锁是否超时 */
					startTimeCycle = GetLogSecJumpDelayUnlocStartCyc(logSectionId);
					secJumpLockDelayUnlockCount = GetSysParaSecJLokDelayUnlockCyc();
					overTimeCheck = SystemOverTimeCheck(startTimeCycle, secJumpLockDelayUnlockCount);
					/** 已超时 */
					if (CI_TIME_OUT == overTimeCheck)
					{
						/** 清除跳跃锁闭命令列车ID */
						ClearLogSecJumpLockTrainId(logSectionId);
						/** 设置跳跃锁闭允许标志为禁止 */
						SetLogSecJumpLockPermFlag(logSectionId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
						/** 设置逻辑区段跳跃锁闭未锁闭*/
						SetLogSecJumpLockState(logSectionId, LOGIC_SECTION_JUMP_LOCK_NO);
						/** 设置逻辑区段关联物理区段跳跃锁闭状态 */
						SetLogRelaPhySecJumpLockSta(logSectionId);
						/** 清除区段跳跃锁闭延时解锁起始周期号和延时解锁设置标志*/
						SetLogSecJumpDelayUnlocStartCyc(logSectionId, 0u);
						SetLogSecJumpDelayUnlockFlag(logSectionId, LOGIC_JUMPUNLOCK_DELAY_SET_NO);
						/*取消防护锁闭*/
						SetLogSecRelProSwitchLockSta(logSectionId, SWITCH_LOCK_PROTECT_CANCEL);
					}
					else
					{
						/** 不做处理 */
					}
				}
			}
		}
		else
		{
			/** 逻辑区段不属于本控区，不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述：检查进路和保护区段内至少存在一个设置了临时限速的逻辑区段
* 参数说明：const UINT16 routeId，进路ID
* 返回值  ： CI_ERROR 均未设置临时限速
			 CI_SUCCESS 至少一个逻辑区段设置了临时限速
* 创建	  ：wqm 20220809
*/
UINT8 CheckRouteLgsLinShiXianSuExist(const UINT16 routeId)
{
	UINT8 retValue = CI_ERROR;
	UINT16 routeSectionSum = 0u;
	UINT16* pRouteSectionDataBuf = NULL;
	UINT16 overlapId = 0u;
	UINT8 routeOvlapSectionSum = 0u;
	UINT16* pRouteOvlapSectionDataBuf = NULL;
	UINT16 i = 0u;
	UINT8 j = 0u;
	UINT16 logSecId = 0u;
	UINT8  logSecState = 0u;
	UINT8 wRouteRelSwitchNum = 0U;  /*进路关联的道岔数量*/
	RouteSwitchStruct* pRouteRelSwitchStr = NULL;  /*进路关联的道岔结构体*/
	UINT16 wRouteRelSwitchId = 0U;  /*进路关联的道岔ID*/
	UINT8 wOvlpRelSwitchNum = 0U;  /*保护区段关联的道岔数量*/
	OverlapConditionSwitchStruct* pOvlpRelSwitchStr = NULL;  /*保护区段关联的道岔结构体*/
	UINT16 wOvlpRelSwitchId = 0U;  /*保护区段关联的道岔ID*/
	UINT8 cCheckFlag = CI_SUCCESS;
	UINT16 devId = 0U;
	UINT8 devState = 0U;

	/** 获取进路内逻辑区段和进路保护区段包含的逻辑区段*/
	routeSectionSum = GetRouteLogSectionSum(routeId);
	pRouteSectionDataBuf = GetRouteLogSectionIdBuf(routeId);
	overlapId = GetRouteOverlapLockedId(routeId);
	routeOvlapSectionSum = GetOverlapLogicSectionSum(overlapId);
	pRouteOvlapSectionDataBuf = GetOverlapLogicSectionBuf(overlapId);

	/** 检查进路内逻辑区段临时限速状态*/
	for (i = 0u; i < routeSectionSum; i++)
	{
		logSecId = pRouteSectionDataBuf[i];
		logSecState = GetLogSecLinShiXianSuSetState(logSecId);
		if (logSecState == LOGSEC_LSXS_SET_STATE_YES)
		{
			/** 进路内至少有一个逻辑区段设置了临时限速*/
			break;
		}
		else
		{

		}
	}
	/** 进路内所有逻辑区段均未设置临时限速,继续检查进路保护区段内的临时限速状态*/
	if (i == routeSectionSum)
	{
		retValue = CI_ERROR;
		/** 检查进路保护区段包含的逻辑区段临时限速状态*/
		for (j = 0u; j < routeOvlapSectionSum; j++)
		{
			logSecId = pRouteOvlapSectionDataBuf[j];
			logSecState = GetLogSecLinShiXianSuSetState(logSecId);
			if (logSecState == LOGSEC_LSXS_SET_STATE_YES)
			{
				/** 进路保护区段内至少有一个逻辑区段设置了临时限速*/
				break;
			}
			else
			{

			}
		}
		/** 进路保护区段内所有逻辑区段均未设置临时限速*/
		if (j == routeOvlapSectionSum)
		{
			/*进路内道岔关联的逻辑区段临时限速状态检查*/
			wRouteRelSwitchNum = GetRouteSwitchSum(routeId);
			pRouteRelSwitchStr = GetRouteSwitchData(routeId);
			if ((0U != wRouteRelSwitchNum) && (NULL != pRouteRelSwitchStr))
			{
				for (j = 0U; j < wRouteRelSwitchNum; j++)
				{
					devId = 0U;
					devState = 0U;
					wRouteRelSwitchId = pRouteRelSwitchStr[j].SwitchId;
					cCheckFlag = SwitchRelLogSecLSXSStateCheck(wRouteRelSwitchId, &devId, &devState);

					if (CI_ERROR == cCheckFlag)
					{
						/*存在逻辑区段设置有临时限速，返回成功*/
						retValue = CI_SUCCESS;
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				/*不处理*/
			}

			/*保护区段内道岔关联的逻辑区段临时限速状态检查*/
			wOvlpRelSwitchNum = GetOverlapSwitchSum(overlapId);
			pOvlpRelSwitchStr = GetOverlapCondSwitchStruct(overlapId);
			if ((CI_SUCCESS != retValue) && (0U != wOvlpRelSwitchNum) && (NULL != pOvlpRelSwitchStr))
			{
				cCheckFlag = CI_SUCCESS;
				for (j = 0U; j < wOvlpRelSwitchNum; j++)
				{
					devId = 0U;
					devState = 0U;
					wOvlpRelSwitchId = pOvlpRelSwitchStr[j].SwitchId;
					cCheckFlag = SwitchRelLogSecLSXSStateCheck(wOvlpRelSwitchId, &devId, &devState);

					if (CI_ERROR == cCheckFlag)
					{
						/*存在逻辑区段设置有临时限速，返回成功*/
						retValue = CI_SUCCESS;
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				/*不处理*/
			}
		}
		else
		{
			/** 进路保护区段内至少有一个逻辑区段设置了临时限速*/
			retValue = CI_SUCCESS;
		}
	}
	else
	{
		/** 进路内至少有一个逻辑区段设置了临时限速*/
		retValue = CI_SUCCESS;
	}

	return retValue;
}

/*
* 功能描述： 进路取消资源逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteCancelResLogicManage(const UINT16 wRouteId, const UINT16 wTrainId)
{
	UINT8 localCiId = 0u;        /*本地联锁ID*/
	UINT8 belongCiId = 0u;       /*进路所属联锁ID*/
	UINT8 ii = 0u;
	UINT8 chKeepWork = CI_ERROR;
	UINT8 chTrainCommStt = 0U;
	UINT16 wLgcLockBelongRouteId = 0U;
	UINT8 chLgcTrainResSum = 0U;
	LogicTrainResStruct* pLgcTrainResInfo = NULL;
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT32 curCycle = 0u;					/*平台周期号*/
	UINT8 routeState = 0u;         /*进路状态*/
	UINT8 autoSigRouteState = 0u;  /*自动信号进路状态*/

	const UINT16 wRouteInLgcSecSum = GetRouteLogSectionSum(wRouteId);
	const UINT16* pRouteInLgcSecBuf = GetRouteLogSectionIdBuf(wRouteId);
	UINT16 wRouteNearestTrainId = GetRouteNODirNearestTrainId(wRouteId);				/*获取进路接近区段上最近的列车,不区分列车方向*/

	UINT8 flagCancel = 0u;/*取消标志*/
	
	curCycle = Get2oo2CurCycleNum();		/*获取平台周期号*/
	routeState = GetRouteState(wRouteId);  /*获取进路状态*/


	if ((0u == wRouteId) || (ROUTE_SUM_MAX <= wRouteId))
	{
		chKeepWork = CI_ERROR;
	}
	else
	{
		chKeepWork = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepWork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetRouteBelongCiId(wRouteId);      /*获取进路所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
#if 0
	if (CI_SUCCESS == chKeepWork)
	{
		chRouteType = GetRouteType(wRouteId);      /*获取进路类型*/

		if (ROUTE_TYPE_RETURN != chRouteType)
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}

	if (CI_SUCCESS == chKeepWork)
	{
		chTrainZeroSpeStt = GetTrainZeroState(wTrainId);      /*获取列车零速标志*/

		if (TRAIN_SPEED_ZERO_YES != chTrainZeroSpeStt)
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
#endif
	if (CI_SUCCESS == chKeepWork)
	{
		chTrainCommStt = GetTrainTransitmitStat(wTrainId);      /*获取列车通信状态*/

		if (TRAIN_COMM_STATE_GOOD != chTrainCommStt)
		{
			chKeepWork = CI_ERROR;
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}

	/*检查列车资源*/
	if (CI_SUCCESS == chKeepWork)
	{

		if ((0U != wRouteInLgcSecSum)
			&& (MAX_ROUTE_IN_LT_NUM > wRouteInLgcSecSum))
		{
			for (ii = 0U; ii < wRouteInLgcSecSum; ii++)
			{
				chLgcTrainResSum = GetLogSecTrainInfoSum(pRouteInLgcSecBuf[ii]);
				if (0U < chLgcTrainResSum)				/*进路逻辑区段有列车资源*/
				{
					pLgcTrainResInfo = GetLogSecTrainInfoById(pRouteInLgcSecBuf[ii], wTrainId);
					wLgcLockBelongRouteId = GetLogSecLockBelongRoute(pRouteInLgcSecBuf[ii]);
					if ((NULL == pLgcTrainResInfo) || (wRouteId != wLgcLockBelongRouteId))
					{
						chKeepWork = CI_ERROR;
					}
					else
					{
						; /*继续执行*/
					}
				}
				else
				{
					chKeepWork = CI_ERROR;
				}

				if (CI_ERROR == chKeepWork)
				{
					break;
				}
				else
				{
					; /*继续执行*/
				}
			}
		}
		else
		{
			chKeepWork = CI_ERROR;/*失败*/
		}
	}
	else
	{
		; /*不处理*/
	}

	/*列车是否为最接近进路的列车*/
	if (CI_SUCCESS == chKeepWork)
	{
		checkResult = RouteAllSecOccuClearCheck(wRouteId, &devId, &devState);		/*进路空闲检查*/
		wRouteNearestTrainId |= 0x1400U;									/*加上车类型*/
		autoSigRouteState = GetRouteAutoSigSetState(wRouteId); /*获取进路自动信号状态*/

		if (ROUTE_AUTOSIGROUTE_YES == autoSigRouteState)					/*进路自动信号不处理*/
		{
			;/*不处理*/
		}
		else if (wRouteNearestTrainId == wTrainId)				/*ATS下发列车为最近一列车(接近区段上),20S等换端总人解逻辑,先设上对应列车和周期号，在主逻辑判方向*/
		{
			/*取消自动通过属性*/
			flagCancel = CancleAutoFlag(wRouteId);

			SetRouteZhefanJiesuoTrainId(wRouteId, wTrainId);			/*设置需要进行折返解锁的列车ID*/
			SetRouteZhefanJiesuoCyc(wRouteId, curCycle);				/*设置需要进行折返解锁的周期号*/
		}
		else 							/*ATS下发不是最近的车,且进路不是自动信号*/
		{
			if (CI_SUCCESS != checkResult)	/*进路内有占压按询问资源取消处理*/
			{
				/*向车申请取消资源收到回复后删除资源,开始计时，若一定时间未接到车的取消资源回复则不再询问*/
				SetRouteResourceCancelTrainId(wRouteId, wTrainId);
				SetRouteResourceCancelCyc(wRouteId, curCycle);
				SetRouteResCancelDelayFlag(wRouteId, RUUTE_RESCANCEL_DELAY_YES);
			}
			else
			{
				if ((ROUTE_STATE_XUANPAI == routeState)
					|| (ROUTE_STATE_FIRST_XUANPAI == routeState)
					|| (ROUTE_STATE_FIRST_LOCK == routeState)
					|| (ROUTE_STATE_FIRST_LOCKERR == routeState)
					|| (ROUTE_STATE_YUXIAN_LOCK == routeState)
					|| (ROUTE_STATE_YUXIAN_OPEN == routeState))
				{
					/*进路未接近锁闭，走总取消逻辑*/
					RouteZongQuXiaoLogicManage(wRouteId);
				}
				else				/*接近锁闭*/
				{
					/*向车申请取消资源后删除资源，不设置列车周期号*/
					SetRouteResourceCancelTrainId(wRouteId, wTrainId);
					SetRouteResourceCancelCyc(wRouteId, curCycle);
					SetRouteResCancelDelayFlag(wRouteId, RUUTE_RESCANCEL_DELAY_YES);
				}
			}
		}
	}
	else
	{
		;	/*不处理*/
	}
}

/*
* 功能描述： 进路初选是否超时
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*			OVERTIME_YES，选排超时
*			OVERTIME_NO，选排未超时
* cgh-合并CID-2341-7： 修改选排超时不清征用问题
*/
UINT8 RouteFirstXuanOverTime(const UINT16 routeId)
{
	UINT8 rtVal = OVERTIME_NO;
	UINT32 routeXuanPaiStartCycle = 0u;/*选排起始周期*/
	UINT8 stat = 0u;
	routeXuanPaiStartCycle = GetRouteXuanPaiStartCycNum(routeId);
	if (0u < routeXuanPaiStartCycle)
	{/*选排起始周期大于0*/
		stat = SystemOverTimeCheck(routeXuanPaiStartCycle, ROUTE_CHUXUAN_OVERTIME_CYCLE_NUM);
		if (CI_TIME_OUT == stat)
		{/*选排超时*/
			rtVal = OVERTIME_YES;
		}
		else
		{
			rtVal = OVERTIME_NO;
		}
	}
	else
	{
		rtVal = OVERTIME_NO;
	}

	return rtVal;
}

/*
* 功能描述： 清除保护区段的选排起始周期号
* 参数说明： 无
*
*修改：cgh-合并CID-2341-8：
*/
void ClearOverlapXuanPaiStartCycNum(void)
{
	/*变量初始化*/
	UINT16 i = 0;
	UINT16 j = 0;
	UINT8 overlapBelongCi = 0u;
	UINT8 localCiId = 0u;
	UINT16 overlapCurSum = 0u;
	UINT16 overlapId = 0u;
	UINT8 routeState = 0u;
	UINT16 overlapRouteSum = 0u;
	UINT16* overlapRouteBuf = NULL;
	UINT8 Flag = 0u;

	localCiId = GetSystemParaLocalCiId();


	/*获取保护区段数据*/
	overlapCurSum = GetOverlapCurSum();
	for (i = 0u; i < overlapCurSum; i++)
	{
		Flag = 0u;
		overlapId = GetOverlapId(i);
		/*获取保护区段所属进路信息*/
		overlapRouteSum = GetOverlapRouteIdSum(overlapId);
		overlapRouteBuf = GetOverlapRouteIdBuf(overlapId);
		overlapBelongCi = GetOverlapBelongCiId(overlapId);

		/*本联锁*/
		if (overlapBelongCi == localCiId)
		{
			if ((0u < overlapRouteSum) && (overlapRouteSum < OVERLAP_ROUTE_SUM_MAX) && (NULL != overlapRouteBuf))
			{
				for (j = 0u; j < overlapRouteSum; j++)
				{
					routeState = GetRouteState(overlapRouteBuf[j]);
					/*进路不等于空闲*/
					if ((ROUTE_STATE_IDLE != routeState) && (ROUTE_STATE_FIRST_XUANPAI != routeState)
						&& (ROUTE_STATE_XUANPAI != routeState))
					{
						debug_infor_printf((const)"\nROUTE IS LOCK routeId:%d overlapId:%d\n", overlapRouteBuf[j], overlapId);
						Flag = 1u;
						break;
					}
					else
					{
						/*不做处理*/
					}
				}
				if (0u == Flag)
				{
					/*选排清零*/
					SetOverlapXuanPaiStartCycNum(overlapId, 0u);
				}
			}
		}
	}
}
/*
* 功能描述： 检查指定ID物理区段封锁是由那个spks落下导致的
* 参数说明： const UINT16 phySectionId, 物理区段ID
UINT8 *state spks状态
UINT16 *spksId spksId
* 返回值  ： CI_SUCCESS: 物理区段的spks由落下的
*			 CI_ERROR: 物理区段对应的spks全未落下或传入的spksId不合法
add by pfq 2022.04.21
*/
UINT8 CheckPhysecFlockReasonSpksId(const UINT16 phySectionId, UINT16* spksId, UINT8* state)
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT8 retVal = CI_ERROR;
	UINT8 phySecSpksSum = 0u;
	UINT16 i = 0u;  /*循环索引*/
	UINT16 tempSpksId = 0u;  /*获取的物理区段对应的spksId*/
	UINT8 tempSpksState = 0u; /*物理区段对应的spks状态*/
	UINT8 tempSpksCutState = 0u; /*物理区段对应的spks的旁路状态*/
	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		phySecSpksSum = GetPhySecSpksSum(phySectionId);  /*获取物理区段spks开关数*/

		for (i = 0u; i < phySecSpksSum; i++)
		{
			tempSpksId = GetPhySecSpksIdBySpksIdx(phySectionId, i);  /*依次获取物理区段对应的所有的spksId*/
			tempSpksState = GetSpksState(tempSpksId);            /*获取spks状态*/
			tempSpksCutState = GetSpksCutState(tempSpksId);      /*获取spks旁路状态*/
			if ((SPKS_STATUS_YES == tempSpksState) && (SPKS_CUT_YES != tempSpksCutState))
			{/*spks落下且未旁路*/
				*spksId = tempSpksId;
				*state = tempSpksState;
				retVal = CI_SUCCESS;      /*找到导致物区段封锁的第一个spks则返回成功跳出循环*/
				break;
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述：人工解锁保护区段处理
* 参数说明： const UINT8 overlapId 保护区段ID
* 返回值：CI_ERROR 失败
*         CI_SUCCESS 成功
*
*修改：mpt 2022年3月9日 增加保护区段人工解锁逻辑
*/
UINT8 LaborUnlockOverlapProc(const UINT16 overlapId)
{
	/*变量初始化*/
	UINT8 overlapBelongCi = 0u;
	UINT8 localCiId = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 OverlapCanLaborUnlockFlag = 0u;
	UINT32 cycNum = Get2oo2CurCycleNum();


	localCiId = GetSystemParaLocalCiId();

	if ((0u < overlapId) && (0u < localCiId))
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}

	if (CI_SUCCESS == reVal)
	{

		overlapBelongCi = GetOverlapBelongCiId(overlapId);
		if (localCiId == overlapBelongCi)
		{/*保护区段属于本联锁*/
			OverlapCanLaborUnlockFlag = GetOverlapCanLaborUnlockFlag(overlapId);
			if (CAN_LABOR_UNLOCK_OVERLAP == OverlapCanLaborUnlockFlag)/*若保护区段此时可以人工解锁*/
			{
				SetOverlapLaborUnlockSetState(overlapId, LABOR_UNLOCK_OVERLAP_YES);
				SetlaborUnlockStartCycNum(overlapId, cycNum);/*设置人工解锁起始周期号*/
			}
			else
			{
				reVal = CI_ERROR;
			}
		}
		else
		{
			if (0u < overlapBelongCi)
			{
				AddCiSendToCiCmdInfo(CI_CMD_UNLOCK_OVERLAP_CMD, overlapId, 0u, overlapBelongCi);
			}
			else
			{
				reVal = CI_ERROR;
			}
		}
	}

	if (CI_SUCCESS != reVal)
	{
		/*发送现地*/
		SetCiSendCmdBackInfoData(UNLOCK_OVELAP_CANNOT, CI_DEVICE_TYPE_OVERLAP, overlapId, 0u, 0u);
	}
	return reVal;
}
/*
* 功能描述： 设置联锁锁闭保护区段标志管理
* 参数说明： const UINT16 routeId, 进路ID
* cgh-合并CID-2539-10： 进路所在联锁紧急站控，则无论保护区段所处联锁什么状态，都由联锁锁闭保护区段
*/
void SetRouteOverlapNeedCIlockM(const UINT16 routeId)
{
	UINT8 routeBelongCIid = GetRouteBelongCiId(routeId);
	UINT8 localCIid = GetSystemParaLocalCiId();
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 virCIid = 0u;
	UINT8 ciCtrModeFlag = 0u;
	UINT8 setflag = 0u;
	UINT8 triggerFlag = 0u;
	UINT8 autoSignalOrRouteValid = 0u;/*自动进路具备标志*/
	UINT8 groupRouteCmd = 0u;
	UINT8 chTempCheckFlag = 0U;/*临时检查标志*/

	if (localCIid == routeBelongCIid)
	{
		/*获取相关标志*/
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			virCIid = GetRouteBelongVirCiId(routeId);
			ciCtrModeFlag = GetVirCImode(virCIid);/*获取联锁控制模式*/
		}
		else
		{
			ciCtrModeFlag = GetCiModeFlag();
		}
		triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/
		 /*进路所属联锁紧急站控下，需要保护区段由联锁锁闭，设置该标志*/
		if (CI_MODE_CI_LOCAL == ciCtrModeFlag)/*是联锁控制*/
		{
			setflag = 1u;
		}
		else
		{
			/*什么也不做*/
		}
		/*进路所属联锁设置自动触发，需要保护区段由联锁锁闭，设置该标志*/
		if (AUTO_TRIGGER_SET_YES == triggerFlag)
		{
			setflag = 1u;
		}
		else
		{
			/*什么也不做*/
		}

		/*进路所属联锁设置自动进路，需要保护区段由联锁锁闭，设置该标志*/
		autoSignalOrRouteValid = AutoSignalOrRouteValid(routeId);
		if (CI_SUCCESS == autoSignalOrRouteValid)
		{
			setflag = 1u;
		}
		else
		{
			/*什么也不做*/
		}

		/*获取进路所属组合列车进路*/
		groupRouteCmd = GetRouteGroupRouteCmdFlag(routeId);
		if (ROUTE_GROUPROUTE_CMD_YES == groupRouteCmd)
		{
			setflag = 1u;
		}
		else
		{
			/*什么也不做*/
		}

		/*保护区段锁闭所属进路和进路最后一个区段锁闭进路不一致，联锁再次锁闭保护区段*/
		chTempCheckFlag = CheakRouteHaveLockOverlap(routeId);
		if (CI_SUCCESS == chTempCheckFlag)
		{
			setflag = 1u;
		}
		else
		{
			;
		}

		if (1u == setflag)
		{
			SetRouteOverlapNeedCIlockFlag(routeId, OVERLAPCILOCK_YES);/*设置保护区段需要联锁锁闭标志*/
		}
		else
		{
			SetRouteOverlapNeedCIlockFlag(routeId, OVERLAPCILOCK_NO);
		}
	}
	else
	{
		/*什么也不做*/
	}
}

/*
* 功能描述： 物理区段跳跃锁闭逻辑管理
* 参数说明： void
* 返回值  ：
* by-cgh-20230628
*/
void PhySecJumpLockLogicManage(void)
{
	UINT8 chTempcheck = 0U;
	UINT16 ii = 0U;
	UINT16 wAxisSectionDataSum = 0U;/*当前集中区及相邻联锁计轴区段总数目*/
	UINT16 wAxisSectionId = 0U;/*计轴区段ID*/
	UINT8 chApplyFlag = 0U;  /*跳跃锁闭申请标志*/
	UINT8 chCancelApplyFlag = 0U;   /*跳跃锁闭取消标志*/
	UINT16 wPhyId = 0U;/*物理区段ID*/
	UINT32 dwApplyCycle = 0U;/*跳跃锁闭申请周期号*/
	UINT8 chPhySecFLockType = 0U;/*物理区段封锁类型*/
	UINT8 chPhySecJempState = 0U;/*物理区段跳跃锁闭状态*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	wAxisSectionDataSum = GetTotalAxisCurNum();

	for (ii = 0U; ii < wAxisSectionDataSum; ii++)
	{
		wAxisSectionId = GetAxisSecId(ii);/*获取配置数据中该索引下的计轴区段ID*/
		chApplyFlag = GetAxisSecJumpLockApplyFlag(wAxisSectionId);/*计轴区段跳跃锁闭申请标志*/
		chCancelApplyFlag = GetAxisSecJLockCancelApplyFlag(wAxisSectionId);/*计轴区段跳跃锁闭取消申请标志*/
		wPhyId = GetAxisSecRelativePhySecId(wAxisSectionId);/*获取相关物理区段ID*/
		chPhySecJempState = GetPhySecJumpLockState(wPhyId); /*获取物理区段跳跃锁闭状态*/

		if (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhySecJempState)
		{
			if ((AXIS_SECTION_JUMPLOCK_APPLY_YES == chApplyFlag) && (AXSEC_CANCEL_JUMPLOCK_APPLY_NO == chCancelApplyFlag))
			{
				/*物理区段未跳跃锁闭，但当前周期有一个计轴区段有跳跃锁闭申请且无取消申请，则设置物理区段跳跃锁闭状态*/
				chTempcheck = CheckJumpLockApply(wAxisSectionId);
				if (CI_SUCCESS == chTempcheck)
				{
					chPhySecFLockType = GetPhySecFLockType(wPhyId); /*获取物理区段封锁类型*/
					if ((PHY_SEC_FLOCK_TYPE_NONE == chPhySecFLockType))
					{
						ClearAxisSeceSwitchDanCaoPos(wAxisSectionId);/*清除单操*/
						SetPhySecJumpLockState(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
						SetAxisRelProSwitchLockSta(wAxisSectionId, SWITCH_LOCK_PROTECT_SET);

						chTempcheck = AxisRelatedProSwitchLockCheck(wAxisSectionId, &devId, &devState);
						if (CI_SUCCESS == chTempcheck)
						{/*检查计轴区段锁闭状态*/
							SetPhySecJumpLockStateToZC(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
							SetAxisInCludeLogJumpLockState(wAxisSectionId, LOGIC_SECTION_JUMP_LOCK_YES);
						}
						else
						{
							/*无执行*/
						}



					}
					else
					{
						AccToPhySecFlockTypeSetErrcode(wPhyId, EFUNC_LockAxisSecProc, ESEND_LEVEL_ZERO, chPhySecFLockType);
					}
				}
			}
		}
		else
		{
			dwApplyCycle = GetAxisSecJumpLockApplyCylce(wAxisSectionId);
			if (0U < dwApplyCycle)
			{/*设置周期大于0，说明ZC没有取消*/
				chTempcheck = CheckJumpLockApply(wAxisSectionId);
				if (CI_ERROR == chTempcheck)
				{
					/*之前处于锁闭，当持续检查锁闭条件不满足时，内部维持跳跃锁闭，给ZC发不锁闭*/
					SetPhySecJumpLockStateToZC(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
				}
				else
				{  /*联锁内部锁闭，当持续检查锁闭条件满足时，再次给ZC发锁闭*/
					devId = 0u;
					devState = 0u;
					chTempcheck = AxisRelatedProSwitchLockCheck(wAxisSectionId, &devId, &devState);
					if (CI_SUCCESS == chTempcheck)
					{
						SetPhySecJumpLockStateToZC(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
					}
					else
					{
						SetPhySecJumpLockStateToZC(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
					}
				}
			}
		}
		if ((AXIS_SECTION_JUMPLOCK_APPLY_NO == chApplyFlag) &&
			(AXSEC_CANCEL_JUMPLOCK_APPLY_YES == chCancelApplyFlag))
		{/*有取消跳跃申请*/
			SetPhySecJumpLockState(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
			SetPhySecJumpLockStateToZC(wPhyId, PHYSICAL_SECTION_JUMP_LOCK_NO);
			SetAxisRelProSwitchLockSta(wAxisSectionId, SWITCH_LOCK_PROTECT_CANCEL);/*取消防护锁闭*/
		}
	}
}

/*
* 功能描述： 进路区段异常延时处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* cgh:2023.05.06
*/
void RouteHalfUnlockDelayManage(const UINT16 routeId)
{
	UINT32 dwDelayStartCycNum = 0U;        /*进路区段故障解锁延时开始周期*/
	UINT32 dwDelayTotalCycSum = 0U;        /*进路区段故障解锁延时周期数*/
	UINT8 chCheckTimeState = 0U;           /*时间参数检查结果*/
	UINT8 chLogLockRouteIdDir = 0U;      /*逻辑区段所属进路进路方向*/
	UINT16 wFirstNormalLockLogId = 0U; /*进路内第一个正常锁闭逻辑区段id*/
	UINT16 wRelativePhySecId = 0U;   /*进路内第一个正常锁闭逻辑区段关联物理区段*/
	UINT16 wRelativePhyLockRoute = 0U;   /*进路内第一个正常锁闭逻辑区段关联物理区段锁闭所属进路*/

	wFirstNormalLockLogId = GetRouteFirstNormalLockLogId(routeId);
	chLogLockRouteIdDir = GetRouteDirection(routeId);
	dwDelayStartCycNum = GetRouFirstElockStaCycNum(routeId);  /*获取逻辑区段故障解锁起始周期*/
	/*超时时间复用总人解时间*/
	dwDelayTotalCycSum = GetSystemParaBlocRouteDelayCyc();   /*获取点式进路延时周期数*/

	/*延时计时*/
	chCheckTimeState = SystemOverTimeCheck(dwDelayStartCycNum, dwDelayTotalCycSum);
	/*解锁计时超时*/
	if (CI_TIME_OUT == chCheckTimeState)
	{/*被设置过延时解锁周期的逻辑区段处理----对应逻辑区段异常锁闭，进路自动解锁异常*/
		wRelativePhySecId = GetLgcSecRelativePhySecId(wFirstNormalLockLogId);
		wRelativePhyLockRoute = GetPhySecRLockBelongRouteId(wRelativePhySecId);

		if (routeId == wRelativePhyLockRoute)
		{/*逻辑区段所属物理区段锁闭所属进路为本进路，则同时设置物理区段异常锁闭*/
			SetPhySecLockState(wRelativePhySecId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, chLogLockRouteIdDir);
		}
		else
		{
			/*不同时进行物理区段故障锁闭处理*/
		}

		/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
		SetPhyIncludeLogLockState(wRelativePhySecId, LOG_SECTION_LOCK_EXCEPT, routeId);
		SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);  /*-->设置进路自动解锁异常*/
		(void)SetRouFirstElockStaCycNum(routeId, 0U);

	}
	else
	{
		/*等待计时*/
	}

}

/*
* 功能描述： 进路部分路径初选管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteHalfFirstXuanManage(const UINT16 routeId)
{
	UINT8 returnValueFunc1 = 0u;    /*返回值定义*/
	UINT8 returnValueFunc2 = 0u;	   /*返回值定义*/
	UINT8 firstXuanPaiOvertime = 0u;/*初选超时*/
	UINT8 routeCheck = 0u;
	UINT8 routeProperty = 0u;

	routeCheck = SetRouteHalfProc(routeId);

	/*办理进路处理*/
	if (CI_SUCCESS == routeCheck)
	{ /*办理成功*/
		firstXuanPaiOvertime = RouteFirstXuanOverTime(routeId);
		if (OVERTIME_YES == firstXuanPaiOvertime)
		{/*初选超时*/
		 /*cgh - 合并CID - 2341 - 7： 修改选排超时不清征用问题*/
		 /*设置进路物理区段未征用*/
			SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

			routeProperty = GetRouteReverseProperty(routeId);
			if (ROUTE_REVERSE_PROPERTY_YES == routeProperty)
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);

			/*增加进路初选超时错误码打印*/
			SetErrorData(EFUNC_PartialRouteFirstXuanPaiManage, CI_DEVICE_TYPE_ROUTE, routeId,
				ETYPE_ROUTE_FIRST_XUANPAI_OVERTIME, ROUTE_DYNAMIC_STATE_FIRST_XUANPAI, ESEND_LEVEL_ZERO);
		}
		/*未超时*/
		/* TODO 做进路部分的区段征用及反向自动信号取消处理*/
		/*进路初选处理*/
		returnValueFunc1 = RouteHalfFirstXuanProc(routeId);
#if 0
		returnValueFunc2 = RouteFirstXuanAutoSigProc(routeId);
#else
		returnValueFunc2 = RouteFirstXuanAutoSigCancelPro(routeId);
#endif
		if ((CI_ERROR == returnValueFunc1) || (CI_ERROR == returnValueFunc2))
		{
			/*征用失败 || 反向进路自动信号进路取消失败*/

			/*设置进路物理区段未征用*/
			SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			/*设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
		}
		else if ((CI_SUCCESS == returnValueFunc1) && (CI_SUCCESS == returnValueFunc2))
		{
			/*征用成功*/

			SetRouteStateManage(routeId, ROUTE_STATE_HALF_XUANPAI);  /*-->设置进路选排*/

																/*进路选排处理*/
			RouteHalfXuanPaiManage(routeId);
		}
		else if ((RETURN_FIRSTXUANPAI_ERR_WAIT == returnValueFunc1) || (RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT == returnValueFunc2))
		{
			/*等待*/
		}
		else
		{
		}
	}
	else
	{
		/*进路办理失败*/

		/*设置进路物理区段未征用*/
		SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

			SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
		}

		/*设置进路空闲*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
	}
}

/*
* 功能描述： 办理部分进路处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 SetRouteHalfProc(const UINT16 routeId)
{
	UINT8 returnValue = 0u;    /*返回值定义*/

	returnValue = SetHalfTrainRouteLogicProcess(routeId);

	/*根据办理返回值处理*/
	if (CI_SUCCESS == returnValue)
	{ /*办理成功*/

		returnValue = CI_SUCCESS;
	}
	else
	{ /*办理失败*/

		returnValue = CI_ERROR;
	}

	return returnValue;
}

/*
* 功能描述： 进路部分路径选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteHalfXuanPaiManage(const UINT16 routeId)
{
	UINT8 returnValue = 0u;    /*返回值定义*/
	UINT8 routSwitDrvOvtmFlag = 0u;/*进路内道岔是否驱动超时标志*/
	UINT8 chkSwitchPos = CI_ERROR;
	UINT8 cLocalCiId = 0u;
	UINT8 ciType = 0u;/*目标联锁类型*/

	cLocalCiId = GetSystemParaLocalCiId();
	ciType = GetCiType(cLocalCiId);

	returnValue = LockRouteHalfProc(routeId);

	routSwitDrvOvtmFlag = ChekRouteHalfSwDrvOvTime(routeId);/*检查进路内道岔是否驱动超时*/

	if (CI_SUCCESS == returnValue)
	{
		chkSwitchPos = ChekRouteHalfSwPosRight(routeId);/*检查道岔位置是否正确*/

		if (CI_SUCCESS == chkSwitchPos)
		{/*道岔位置正确*/

			SetRouteStateManage(routeId, ROUTE_STATE_HALF_LOCK);  /*-->设置进路初锁*/

			/*进路部分锁闭处理*/
			RouteHalfLockManage(routeId);
		}
		else
		{

			/*道岔未动作到位或者带动道岔仍需被驱动*/
			if (CI_SUCCESS == routSwitDrvOvtmFlag)
			{/*检查进路内方道岔驱动是否超时*/

			}
			else
			{
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

				SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
			}
		}

	}
	else if ((RETURN_LOCK_ERR_SWITPOS == returnValue) && (CI_SUCCESS == routSwitDrvOvtmFlag))
	{
		/*道岔位置不正确*/

		/*进路锁闭驱动道岔*/
		if (CI_ERROR == RouteLockHalfDriveSwitch(routeId))
		{
			/*设置进路物理区段未征用*/
			SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

			if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}

			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
		}
	}
	else
	{
		/*设置进路物理区段未征用*/
		SetRouteHalfPhySecUsingState(routeId, PHYSICAL_SECTION_USING_NO);

		if (ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId))
		{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

			SetRevrRouteAutoSigInvalidFlag(routeId, ROUTE_AUTOSIG_LOSE_SET_NO);
		}
		/* 进路锁闭失败 */
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
	}
}

/*
*
* 功能描述： 进路部分锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteHalfLockManage(const UINT16 routeId)
{
	UINT16 resReqTrainId = 0U;
	UINT8 trainLocLogicSecSum = 0U;			/*列车脚下资源数量*/
	UINT8 halfRouteLogicSecSum = 0U;			/*列车脚下资源数量*/
	const UINT16* const pHalfLogicSecId = GetHalfRouteLockLgcSecIdBuf(routeId);	/*列车脚下资源*/
	const UINT16* const pTrainLocLogicSecId = GetHalfRouteTrainLocLgcSecIdBuf(routeId);	/*列车脚下资源*/
	trainLocLogicSecSum = GetHalfRouteTrainLocLgcSecNum(routeId);
	resReqTrainId = GetHalfRouteResReqTrainId(routeId);
	halfRouteLogicSecSum = GetHalfRouteLockLgcSecSum(routeId);

	if ((NULL == pTrainLocLogicSecId) || (NULL == pHalfLogicSecId))
	{
		/*不可能场景 ，进入该场景前已查询routeId有效,设置宕机标志*/
		SetPlatOverFlag();
	}
	else if (0U == trainLocLogicSecSum)
	{
		/*无列车脚下资源，进入部分锁闭状态解锁*/
		SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);
	}
	else
	{

		/*处理列车脚下资源换向*/
		SetRouteTrainLocLogSecState(routeId, LOG_SECTION_LOCK_NORMAL);
		SetRouteTrainLocPhySecState(routeId, PHYSICAL_SECTION_LOCK_NORMAL);
		/*更新进路状态*/
		SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);
#if 0
		routeDir = GetRouteDirection(routeId);
		trainDir = GetTrainDir(resReqTrainId);
		trainCommStt = GetTrainTransitmitStat(resReqTrainId);
		if (trainCommStt == TRAIN_COMM_STATE_GOOD)
		{
			if (routeDir == trainDir)
			{
				/*处理列车脚下资源换向*/
				SetRouteTrainLocLogSecState(routeId, LOG_SECTION_LOCK_NORMAL);
				SetRouteTrainLocPhySecState(routeId, PHYSICAL_SECTION_LOCK_NORMAL);
				/*更新进路状态*/
				SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);
			}
			else
			{
				/* 列车沿逻辑正向运行 */
				if (EMAP_SAME_DIR == trainDir)
				{
					end.wLinkId = GetTrainMaxHeadLink(resReqTrainId);
					end.dwOffset = GetTrainMaxHeadOffset(resReqTrainId);
					start.wLinkId = GetTrainMinTailLink(resReqTrainId);
					start.dwOffset = GetTrainMinTailOffset(resReqTrainId);
				}

				/* 列车沿逻辑反向运行 */
				else if (EMAP_CONVER_DIR == trainDir)
				{
					start.wLinkId = GetTrainMaxHeadLink(resReqTrainId);
					start.dwOffset = GetTrainMaxHeadOffset(resReqTrainId);
					end.wLinkId = GetTrainMinTailLink(resReqTrainId);
					end.dwOffset = GetTrainMinTailOffset(resReqTrainId);
				}
				else
				{
					/*无操作*/
				}

				/*获取列车脚下逻辑区段数量/ID*/
				funcRet = GetLogSecBtwTwoPoints(start, end, &trainNowLgcSecSum, trainNowLgcSecId);
				if (CI_SUCCESS == funcRet)
				{
					for (ii = 0U; ii < trainLocLogicSecSum; ii++)
					{
						for (jj = 0U; jj < trainNowLgcSecSum; jj++)
						{
							if (pTrainLocLogicSecId[ii] == trainNowLgcSecId[jj])
							{
								break;
							}
							else
							{

							}
						}

						if (jj == trainNowLgcSecSum)
						{
							break;
						}
					}
					if (trainLocLogicSecSum == ii)
					{
						/*列车仍在当前位置，不更新*/
					}
					else
					{

						/*设置其他进路也为half unlock*/
						SetTrainLocRouteHalfUnlock(routeId);
						/*更新进路状态*/
						SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);

					}
				}
				else
				{

					/*设置其他进路也为half unlock*/
					SetTrainLocRouteHalfUnlock(routeId);
					/*更新进路状态*/
					SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);

				}
			}
		}
		else
		{

			/*设置其他进路也为half unlock*/
			SetTrainLocRouteHalfUnlock(routeId);
			for (jj = 0U; jj < halfRouteLogicSecSum; jj++)
			{
				lgcSecRLockId = GetLogSecLockBelongRoute(pHalfLogicSecId[jj]);
				if (lgcSecRLockId == routeId)
				{
					break;
					/*锁闭属于本进路或未锁闭，继续执行*/
				}
				else
				{

				}
			}

			if (jj == halfRouteLogicSecSum)
			{
				/*列车换向失败，无锁闭区段，转为空闲*/
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
			}
			else
			{
				/*列车丢失通信，直接更新进路状态*/
				SetRouteStateManage(routeId, ROUTE_STATE_HALF_UNLOCK);
	}

}
#endif
	}


}


/*
*
* 功能描述： 进路部分锁闭解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteHalfUnlockManage(const UINT16 routeId)
{
	/*TODO 无需求，当前无需处理该状态，由列车释放部分处理*/
}
/*
* 功能描述： 锁闭进路部分路径处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 LockRouteHalfProc(const UINT16 routeId)
{
	UINT8 routeType = 0u;      /*进路类型*/
	UINT8 returnValue = 0u;    /*返回值定义*/
	UINT8 retval = 0u;

	routeType = GetRouteType(routeId);      /*获取进路类型*/

	if ((ROUTE_TYPE_LIECHE == routeType)
		|| (ROUTE_TYPE_RETURN == routeType))
	{
		/*锁闭进路部分路径逻辑处理*/
		returnValue = LockRouteHalfLogicProcess(routeId);

	}
	else
	{
		/* 暂不做处理*/
	}



	/*根据锁闭返回值处理*/
	if (CI_SUCCESS == returnValue)
	{
		/*锁闭成功*/

		retval = CI_SUCCESS;
	}
	else if (RETURN_LOCK_ERR_SWITPOS == returnValue)
	{ /*道岔位置不正确*/

		retval = RETURN_LOCK_ERR_SWITPOS;
	}
	else
	{ /*锁闭失败*/

		retval = CI_ERROR;
	}
	return retval;
}

/*
* @brief 办理来自其它CI的部分路径申请
* 输入参数：ToCiDrCmdDataStruct pCiRecvCiDrCmdStru 接收其它联锁动态进路命令的结构体
* 输出参数：无
* 返回值：无
*/
void SetRoutePartApplyFromCi(ToCiDrCmdDataStruct* pCiRecvCiDrCmdStru)
{
	/*局部变量初始化*/
	UINT8 keepWork = CI_ERROR;
	UINT16 wMatchedRouteId = 0U;  /*逻辑区段序列匹配成功的进路ID*/
	UINT8 routeCurState = ROUTE_STATE_IDLE;  /*进路状态*/
	UINT16 wUsableDrId = 0U;  /*可用的最小动态进路ID*/
	UINT16 wUsableLogicRouteId = 0U;  /*可用的最小逻辑进路ID*/
	UINT8 cCheckStep = 0U;  /*记录代码运行到的位置，便于错误分析*/
	UINT8 szQueryDir[UINT8_MAX] = { 0U };  /*逻辑区段对应的查询方向（逻辑方向）*/
	UINT8 cLocalCiId = 0U;  /*本联锁ID*/	

	/*入参检查*/
	if (NULL == pCiRecvCiDrCmdStru)
	{
		/*入参校验失败，不处理*/
	}
	else
	{
		/*第一步：检查逻辑区段序列是否连续*/
		keepWork = LogSecSeqIsContinuousCheck(pCiRecvCiDrCmdStru->cLogSecSeqDir, pCiRecvCiDrCmdStru->cLogSecSum, pCiRecvCiDrCmdStru->wLogSecIdBuff, szQueryDir);
		cCheckStep++;

		if ((CI_SUCCESS == keepWork) && (CICI_DR_CMD_LOGIC != pCiRecvCiDrCmdStru->cCmdType))
		{
			/*第二步：为非逻辑进路命令的序列匹配非主进路的列车进路*/
			keepWork = MatchedRouteCheck(pCiRecvCiDrCmdStru->cLogSecSeqDir, pCiRecvCiDrCmdStru->cLogSecSum, pCiRecvCiDrCmdStru->wLogSecIdBuff, &wMatchedRouteId);
			cCheckStep++;
		}
		else
		{
			/*不处理*/
		}

		if (CI_SUCCESS == keepWork)
		{
			/*第三步：筛选半截进路，进路办理条件检查*/
			if (CICI_DR_CMD_HALF == pCiRecvCiDrCmdStru->cCmdType)
			{
				/*半截进路处理：填充半截进路结构体*/
				SetHalfRouteSwitchMoveValid(wMatchedRouteId, pCiRecvCiDrCmdStru->cSwitchMoveFlag);  /*设置半截进路道岔可动标志*/
				SetHalfRouteLockLgcSec(wMatchedRouteId, pCiRecvCiDrCmdStru->cLogSecSum, pCiRecvCiDrCmdStru->wLogSecIdBuff);  /*设置半截进路锁闭的逻辑区段数据*/
				SetHalfRouteResReqTrainId(wMatchedRouteId, pCiRecvCiDrCmdStru->wTrainId);  /*设置发送资源请求的列车ID*/
				SetHalfRouteTrainLocLgcSec(wMatchedRouteId, pCiRecvCiDrCmdStru->cTrainLocLogSecSum, pCiRecvCiDrCmdStru->wTrainLocLogSecIdBuff);  /*设置半截进路列车脚下逻辑区段数据*/
				debug_infor_printf((const)"HalfRouteSwitchMoveFlag From CI: 0x%x\n", pCiRecvCiDrCmdStru->cSwitchMoveFlag);

				keepWork = HalfRoutePhySecUseLogicProcess(wMatchedRouteId);  /*半截子进路区段征用检查*/
				if (CI_SUCCESS == keepWork)
				{
					/*将匹配的进路传递至动态进路处理*/
					wUsableDrId = GetUsableDrId();
					SetDrSubRoute(wUsableDrId, (UINT8)1U, &wMatchedRouteId);

					debug_infor_printf((const)"Dynamic Route Set From CI Is Success! Dynamic Sub Route ID From CI: %d\n", wMatchedRouteId);  /*办理成功，记录日志*/
				}
				else
				{
					SetRouteStateManage(wMatchedRouteId, ROUTE_STATE_IDLE);  /*征用失败，设置进路空闲*/
				}
			}
			else if (CICI_DR_CMD_FULL == pCiRecvCiDrCmdStru->cCmdType)
			{
				keepWork = RoutePhySectionUseLogicProcess(wMatchedRouteId);  /*完整子进路区段征用检查*/
				if (CI_SUCCESS == keepWork)
				{
					/*完整进路处理*/
					routeCurState = GetRouteState(wMatchedRouteId);
					if ((ROUTE_STATE_IDLE == routeCurState) || (ROUTE_STATE_HALF_UNLOCK == routeCurState))
					{
						/*进路办理条件检查通过，记录ITS申请路径包含的列车ID供逻辑区段锁闭时使用*/
						SetITSRouteApplyTrainIDInfo(wMatchedRouteId, pCiRecvCiDrCmdStru->wTrainId);
					}
					else
					{
						/*无需处理*/
					}

					/*将匹配的进路传递至动态进路处理*/
					wUsableDrId = GetUsableDrId();
					SetDrSubRoute(wUsableDrId, (UINT8)1U, &wMatchedRouteId);

					debug_infor_printf((const)"Dynamic Route Set From CI Is Success! Dynamic Sub Route ID From CI: %d\n", wMatchedRouteId);  /*办理成功，记录日志*/
				}
			}
			else if (CICI_DR_CMD_LOGIC == pCiRecvCiDrCmdStru->cCmdType)
			{
				/*逻辑进路处理：填充逻辑进路结构体*/
				wUsableLogicRouteId = GetUsableLogicalRouteId();
				if (0U != wUsableLogicRouteId)
				{
					keepWork = RepeatSetLogicRouteCheck(pCiRecvCiDrCmdStru->cLogSecSum, pCiRecvCiDrCmdStru->wLogSecIdBuff, pCiRecvCiDrCmdStru->wTrainId);  /*检查逻辑进路是否重复办理*/

					if (CI_SUCCESS == keepWork)
					{
						cLocalCiId = GetSystemParaLocalCiId();  /*获取本联锁ID*/

						SetLogicalRouteBelongCiId(wUsableLogicRouteId, cLocalCiId);
						SetLogicalRouteDir(wUsableLogicRouteId, pCiRecvCiDrCmdStru->cLogSecSeqDir);  /*设置逻辑进路方向*/
						SetLogicalRouteSwitchMoveFlag(wUsableLogicRouteId, pCiRecvCiDrCmdStru->cSwitchMoveFlag);  /*设置逻辑进路道岔可动标志*/
						SetLogicalRouteRelateBeginSigId(wUsableLogicRouteId, pCiRecvCiDrCmdStru->wRelStartSignalId);  /*设置逻辑进路始端信号机*/
						LogicRouteLevelConfirmProcess(wUsableLogicRouteId);  /*确定逻辑进路监督级别*/
						SetLogRouteApplyResTrainData(wUsableLogicRouteId, pCiRecvCiDrCmdStru->wTrainId);  /*设置ATS申请的资源列车ID*/
						SetLogicalRouteInLogSecData(wUsableLogicRouteId, pCiRecvCiDrCmdStru->cLogSecSum, pCiRecvCiDrCmdStru->wLogSecIdBuff);  /*设置逻辑进路包含的逻辑区段*/
						SetLogicalRouteTrainLogSecData(wUsableLogicRouteId, pCiRecvCiDrCmdStru->cTrainLocLogSecSum, pCiRecvCiDrCmdStru->wTrainLocLogSecIdBuff);  /*设置列车脚下包含的逻辑区段*/
						LogicRouteOpenColorProc(wUsableLogicRouteId);  /*设置逻辑进路始端信号机开放颜色*/
						LogRouteOutLgcSecConfigDataInit(wUsableLogicRouteId);

						/*区段征用通过，设置逻辑进路状态为初选，否则设置逻辑进路状态空闲*/
						keepWork = LogRoutePhySecUseLogicProcess(wUsableLogicRouteId);
						if (CI_SUCCESS == keepWork)
						{
							SetLogRouteStateManage(wUsableLogicRouteId, ROUTE_LOGICAL_STATE_FIRST_XUANPAI);

							debug_infor_printf((const)"Dynamic Logic Route Set From CI Is Success! Dynamic Logic Route ID: %d\n", wUsableLogicRouteId);  /*办理成功，记录日志*/
						}
						else
						{
							SetLogRouteStateManage(wUsableLogicRouteId, ROUTE_LOGICAL_STATE_IDLE);
						}
					}
					else
					{
						debug_infor_printf((const)"Dynamic Logic Route Set From CI Is Error: LogicRoute Repeat Set!\n");  /*逻辑进路重复办理或非停车区域*/
					}
				}
				else
				{
					/*无空闲逻辑进路，不处理*/
					debug_infor_printf((const)"Dynamic Logic Route Set From CI Is Error: LogicRoute Is Not Idle!\n");
				}
			}
			else
			{
				/*不处理*/
			}
		}
		else
		{
			debug_infor_printf((const)"Route Part Apply From CI Is Error! Error Position Is [%d]\n", cCheckStep);  /*办理失败，记录日志*/
		}
	}
}

/*
* 功能描述： 进路申请取消资源命令延时处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteCancelResApplyManage(const UINT16 routeId)
{
	UINT8 ResCancelflag = 0u;
	UINT32 delayStartCycNum = 0u;  /*延时取消资源申请起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时取消资源申请总周期数*/
	UINT8 checkTimeState = CI_TIME_NO;	/*是否超时状态*/
	UINT16 wTrainId = 0u;		/*资源取消申请的列车ID*/
	UINT8 chTrainCommStt = 0U;
	UINT8 routeState = 0u;         /*进路状态*/


	delayStartCycNum = GetRouteResourceCancelCyc(routeId);		/*获取资源取消申请时的周期号*/
	delayTotalCycSum = GetRouteResCancelApplyCyc();		/*获取资源取消申请的总周期数*/
	wTrainId = GetRouteResourceCancelTrainId(routeId);			/*获取指定进路的资源取消允许列车ID*/
	chTrainCommStt = GetTrainTransitmitStat(wTrainId);      /*获取列车通信状态*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/


	ResCancelflag = GetRouteResCancelDelayFlag(routeId);

	if (RUUTE_RESCANCEL_DELAY_YES == ResCancelflag)
	{
		/*延时计时*/
		checkTimeState = SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum);

		if ((CI_TIME_OUT == checkTimeState) || (TRAIN_COMM_STATE_GOOD != chTrainCommStt) || (ROUTE_STATE_IDLE == routeState))
		{
			SetRouteResourceCancelTrainId(routeId, 0U);			/*清除申请*/
			SetRouteResourceCancelCyc(routeId, 0U);
			SetRouteResCancelDelayFlag(routeId, RUUTE_RESCANCEL_DELAY_NO);	/*清除延时标志*/
		}
		else
		{
			;	/*未超时，进路未取消，车通信良好继续运行*/
		}
	}
	else
	{
		;	/*未有延时取消资源申请的处理，继续运行*/
	}
}

/*
* 功能描述： 进路选排通用处理
* 参数说明： const UINT16 wRouteId, 进路ID
*			const UINT8 chLockRouteProcCheck 锁闭进路检查结果
* 返回值  ： UINT8
* by cgh 20230720 降低圈复杂度，进路选排阶段道岔相关条件检查挪到此函数处理
*/
void RouteXuanPaiCommonProcess(const UINT16 wRouteId, const UINT8 chLockRouteProcCheck)
{
	UINT8 chNeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE; /*带动道岔是否需要被驱动*/
	UINT8 chRoutSwitDrvOvtmFlag = 0u;/*进路内道岔是否驱动超时标志*/
	UINT8 chSwitchPos = CI_ERROR;
	UINT8 chSwitchDrive = CI_ERROR;		/*道岔驱动结果*/
	UINT8 chLocalCIType = 0U;
	UINT8 chReverseRouteProperty = 0U;/*反向进路属性*/

	chLocalCIType = GetLocalCiType();
	chReverseRouteProperty = GetRouteReverseProperty(wRouteId);
	chNeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(wRouteId);/*检查进路带动道岔组是否需要被驱动*/
	chRoutSwitDrvOvtmFlag = ChekRoutSwitDrivOvtmStat(wRouteId);/*检查进路内道岔是否驱动超时*/
	chSwitchPos = CheckRouteSwitchPosRight(wRouteId);/*检查道岔位置是否正确*/

	if ((CI_SUCCESS == chLockRouteProcCheck) && (SWITCH_NEED_DRIV_FALSE == chNeedForDrvRoutAssoSwit) && (CI_SUCCESS == chSwitchPos))
	{
		/*进路道岔位置正确及带动道岔无需被驱动*/
		/*清除进路带动道岔组被单操过的历史*/
		SetRoutAssoSwitSingOperStat(wRouteId, SWITCH_SINGLE_OPERATED_FALSE);
		/*锁闭成功*/
		SetRouteStateManage(wRouteId, ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/
		/*进路初锁处理*/
		RouteFirstLockManage(wRouteId);

	}
	else if (((CI_SUCCESS == chLockRouteProcCheck) && (SWITCH_NEED_DRIV_TRUE == chNeedForDrvRoutAssoSwit)) || (RETURN_LOCK_ERR_SWITPOS == chLockRouteProcCheck))
	{
		if (CI_SUCCESS == chRoutSwitDrvOvtmFlag)
		{
			chSwitchDrive = RouteLockDriveSwitch(wRouteId, chNeedForDrvRoutAssoSwit);
		}
		if ((CI_ERROR == chRoutSwitDrvOvtmFlag) || ((CI_SUCCESS == chRoutSwitDrvOvtmFlag) && (CI_ERROR == chSwitchDrive)))
		{
			/*进路内方道岔驱动超时或未超时但驱动道岔失败*/
			SetRoutAssoSwitSingOperStat(wRouteId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

			SetRouteStateManage(wRouteId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

			SetRoutePhySectionOccupyState(wRouteId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/

			if (ROUTE_REVERSE_PROPERTY_YES == chReverseRouteProperty)
			{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/

				SetRevrRouteAutoSigInvalidFlag(wRouteId, ROUTE_AUTOSIG_LOSE_SET_NO);
			}
		}
		else
		{
			; /*继续*/
		}
	}
	else
	{
		SetRoutAssoSwitSingOperStat(wRouteId, SWITCH_SINGLE_OPERATED_FALSE);/*清除带动道岔被单操过的历史*/
		SetRoutePhySectionOccupyState(wRouteId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
		if (ROUTE_REVERSE_PROPERTY_YES == chReverseRouteProperty)
		{/*进路若为反向进路，则恢复反向进路包含的自动信号进路的自动属性*/
			SetRevrRouteAutoSigInvalidFlag(wRouteId, ROUTE_AUTOSIG_LOSE_SET_NO);
		}
		SetRouteStateManage(wRouteId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
	}
}


/*
* 功能描述： 进路最近的车需要总人解进路时，延时处理逻辑
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteNearestTrainRenJieManage(const UINT16 routeId)
{
	UINT16 wTrainId = 0U;		/*进路需要总人解的列车ID*/
	UINT8 chTrainCommStt = 0U;		/*列车通信状态*/
	UINT8 routeState = 0u;         /*进路状态*/
	UINT8 checkTimeState = CI_TIME_NO;	/*是否超时状态*/
	UINT32 delayStartCycNum = 0u;  /*延时取消资源申请起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时取消资源申请总周期数*/
	UINT8 zongRenJieFlag = 0u;    /*进路总人解标志*/

	UINT8 cRouteDir = CI_SYSTEM_DIRECTION_NONE;		/*信号机防护方向*/

	UINT8 cTrainRunDir = CI_SYSTEM_DIRECTION_NONE;		/*列车运行方向*/
	UINT16 cSignalId = 0u;
	LOD_STRU pSignalProtePoint = { 0u }; /*信号机位置*/
	LOD_STRU pTrainMinTailPoint = { 0u }; /*列车安全车尾位置*/
	UINT8 cDirChangedNum = 0U;			/*方向变化点数量*/

	UINT16 startSignalId = 0U;   /*进路始端信号机ID*/
	UINT8 cSignalColor = 0U;     /*进路始端信号机当前颜色*/
	UINT8 cSignalOpenState = 0U; /*进路始端信号机开放状态*/
	UINT16 wRouteNearestTrainId = GetRouteNODirNearestTrainId(routeId);				/*获取进路接近区段上最近的列车*/



	wTrainId = GetRouteZhefanJiesuoTrainId(routeId);			/*需要进行进路折返解锁的相关的列车ID*/
	chTrainCommStt = GetTrainTransitmitStat(wTrainId);      /*获取列车通信状态*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/

	delayStartCycNum = GetRouteZhefanJiesuoCyc(routeId);		/*获取需要折返解锁开始的时间*/
	delayTotalCycSum = GetRouteTrainRanJieDelayCyc();		/*获取进路需要折返解锁的总周期数*/
	zongRenJieFlag = GetRouteZongRenJieFlag(routeId);          /*获取进路总人解标志*/
	wRouteNearestTrainId |= 0x1400U;									/*加上车类型*/


	startSignalId = GetRouteStartSignalId(routeId);
	cSignalColor = GetSignalCurColor(startSignalId);
	cSignalOpenState = GetSignalOpenCloseState(cSignalColor);

	if (0U != wTrainId)
	{
		/*进路当前为接近开放，驱动信号关闭*/
		if (SIGNAL_OPEN == cSignalOpenState)
		{
			(void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/
			
			if (ROUTE_STATE_NEAR_OPEN == routeState)
			{
				SetRouteStateManage(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
			}
		}

		/*延时计时*/
		checkTimeState = SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum);

		if ((CI_TIME_OUT == checkTimeState) || (TRAIN_COMM_STATE_GOOD != chTrainCommStt)
			||  (ROUTE_ZONGRENJIE_SET_YES == zongRenJieFlag)
			|| (wTrainId != wRouteNearestTrainId))
		{
			/*当出现，20s计时超时，需要折返解锁的列车通信不好，进路存在总人解，需要折返解锁的列车已经不是最近的列车了，此类情况都不再进行解锁，同时出清对应的列车ID和周期号*/
			SetRouteZhefanJiesuoTrainId(routeId, 0U);
			SetRouteZhefanJiesuoCyc(routeId, 0U);
		}
		else
		{
			/*未超时且未出现异常情况，则查询列车是否换方向，与进路方向背离*/
			cSignalId = GetRouteStartSignalId(routeId);		/*获取进路始端信号机*/
			cRouteDir = GetSignalDirection(cSignalId);/*信号机防护方向*/

			cTrainRunDir = GetTrainDir(wTrainId);		/*获取列车运行逻辑方向*/

			/*始端信号机位置*/
			pSignalProtePoint.Lnk = GetSignalProtectLink(cSignalId);
			pSignalProtePoint.Off = GetSignalProtectLinkOff(cSignalId);
			/*安全车尾位置*/
			pTrainMinTailPoint.Lnk = GetTrainMinTailLink(wTrainId);
			pTrainMinTailPoint.Off = GetTrainMinTailOffset(wTrainId);

			cDirChangedNum = GetDirChangeNumBtwPoints(&pSignalProtePoint, &pTrainMinTailPoint);			/*查安全车尾到始端信号机位置有多少方向变化点*/
			/*根据方向变换点数量转换方向*/
			cTrainRunDir = TransDirByChangeNum(cTrainRunDir, cDirChangedNum);

			if (((DIR_CONVERT != cTrainRunDir) && (DIR_SAME != cTrainRunDir))
				|| ((DIR_CONVERT != cRouteDir) && (DIR_SAME != cRouteDir)))
			{
				/*方向出现异常不再等待20s*/
				SetRouteZhefanJiesuoTrainId(routeId, 0U);			/*出清需要进行折返解锁的列车ID*/
				SetRouteZhefanJiesuoCyc(routeId, 0U);				/*出清需要进行折返解锁的周期号*/
			}
			else
			{
				if (cRouteDir != cTrainRunDir)		/*列车运行方向和进路方向背离，远离进路，直接走折返解锁*/
				{
					/*列车中途折返解锁进路处理*/
					RouteZhongtuZhefanQuxiaoProc(routeId);

					/*清空进路解锁数据*/
					SetRouteZhefanJiesuoTrainId(routeId, 0U);			/*出清需要进行折返解锁的列车ID*/
					SetRouteZhefanJiesuoCyc(routeId, 0U);				/*出清需要进行折返解锁的周期号*/
				}
				else
				{
					;/*列车未改方向，等列车改方向*/
				}
			}
		}
	
	}
	else
	{
		;/*未有需要进行延时总人解的进路，不处理*/
	}
}

/*
* 功能描述： 删除进路锁闭后再次办理进路时的错误反馈数据
* 参数说明： void
* 返回值  ： void
* by cgh 20230930
*/
void DeleteSetRouteErrorData(void)
{
	UINT16 wErrorCodeCurSum = 0U;/*错误码当前总数*/
	ErrorDataStruct* errorCodeStu = NULL; /*错误码数据*/

	wErrorCodeCurSum = GetErrorDataCurSum();  /*获取错误码总数*/
	if (0U < wErrorCodeCurSum)
	{
		errorCodeStu = GetErrorData(wErrorCodeCurSum - 1U);  /*获取错误码数据*/
		if (NULL != errorCodeStu)
		{
			/*1、当前车驶入CBTC列车进路（非反向非风井进路）
			  2、且进路状态为接近锁闭正常、接近锁闭异常、预先锁闭、初锁异常时，
			  以上两个条件再次办理进路，此时检查进路办理失败,但后车可以追踪办理进路，此时不能反馈错误*/
			if (EFUNC_SET_CBTC_T_ROUTE == errorCodeStu->FunctionId)
			{ /*CBTC级别进路*/
				if ((CI_DEVICE_TYPE_ROUTE == errorCodeStu->DeviceType) && (ETYPE_ROUTE_STATE == errorCodeStu->DeviceStateType))
				{
					DeleteErrorData(wErrorCodeCurSum - 1U);
				}
				else
				{
					; /*其他不处理*/
				}
			}
			else
			{
				;/*其他不作处理*/
			}
		}
	}
	else
	{
		; /*没有错误码数据不处理*/
	}
}
/*
* 功能描述： 设置所有列车逻辑区段资源处理
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* 返回值  ： VOID
*/
void SetAllTrainLogicResUseable(const UINT16 wLogSectionId)
{
	UINT8 chLogicResTrainSum = 0U;/*指定逻辑区资源列车数量*/
	UINT8 jj = 0u;               /*循环索引*/
	UINT16 wTrainId = 0U;
	UINT16 routeResourceCancelTrainId = 0U;/*指定进路的资源取消允许列车ID*/
	UINT16 wLogicRLockRouteId = 0u;	         /*逻辑区段锁闭进路ID*/
	UINT8 chLogicApplyState = 0U;/*列车逻辑区段申请状态*/
	UINT8 chLogicLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 chLogicSecCheckState = CI_ERROR;/*逻辑区段资源可用性检查*/
	UINT8 chLogRouteLogicLockState = 0U;		/*逻辑进路逻辑区段锁闭状态*/
	UINT8 chLogicSecLogRouteCheckState = CI_ERROR;	/*逻辑进路逻辑区段资源可用性检查*/
	UINT16 wLogicRLockLogRouteId = 0U;			/*逻辑区段锁闭逻辑进路ID*/
	UINT8 chLogSecAblReverseProperty = 0U;  /*逻辑区段ABL反向进路属性*/

	chLogicResTrainSum = GetLogSecTrainInfoSum(wLogSectionId);
	wLogicRLockRouteId = GetLogSecLockBelongRoute(wLogSectionId);         /*获取进路ID*/

	chLogicLockState = GetLogSecLockState(wLogSectionId);			/*正常进路锁闭状态*/
	chLogRouteLogicLockState = GetLogSecLogLockState(wLogSectionId);		/*逻辑进路锁闭状态*/
	if (LOGIC_SECTION_RES_SUM_MAX > chLogicResTrainSum)
	{
		if ((0U < wLogicRLockRouteId) && ((LOG_SECTION_LOCK_NORMAL == chLogicLockState)
			|| (LOG_SECTION_LOCK_DELAY == chLogicLockState)))
		{
			/*此逻辑区段被进路锁闭，查逻辑区段资源可用性*/
			chLogicSecCheckState = LogicSecResApplicabilityCheck(wLogSectionId);
			if (CI_SUCCESS == chLogicSecCheckState)
			{
				SetLogSecAblUseFlag(wLogSectionId, LOGIC_ABLNEAR_USE_FLAG_YES);
			}
			else
			{
				SetLogSecAblUseFlag(wLogSectionId, LOGIC_ABLNEAR_USE_FLAG_NO);
			}
		}
		else
		{
			/*无锁闭，ABL后备发送逻辑区段不可用*/
			SetLogSecAblUseFlag(wLogSectionId, LOGIC_ABLNEAR_USE_FLAG_NO);
		}

		for (jj = 0U; jj < chLogicResTrainSum; jj++)
		{
			wTrainId = GetLogSecTrainIdByIndex(wLogSectionId, jj);
			/*收到资源取消标志*/
			wLogicRLockLogRouteId = GetLogSecBelongLogRouteId(wLogSectionId, wTrainId);		/*列车关联逻辑进路ID*/
			routeResourceCancelTrainId = GetRouteResourceCancelTrainId(wLogicRLockRouteId);	/*获取指定进路的资源取消允许列车ID*/

			chLogicApplyState = GetLogSecTrainApply(wLogSectionId, wTrainId);

			if ((LOGIC_SECTION_TRAIN_APPLY_YES == chLogicApplyState)
				&& (routeResourceCancelTrainId != wTrainId))				/*资源取消指令已经移除资源*/
			{
				chLogSecAblReverseProperty = CheckLogSecAblReverseProperty(wLogSectionId, (wTrainId & 0x00FFU));

				if ((LOG_SECTION_LOGLOCK_NORMAL == chLogRouteLogicLockState) && (0U < wLogicRLockLogRouteId))
				{
					/*动态进路锁闭，查询逻辑区段资源可用性*/
					chLogicSecLogRouteCheckState = LogRouteLogSecResAppCheck(wLogSectionId, wLogicRLockLogRouteId);

					SetLogRouteLogicResUsable(wLogSectionId, wTrainId, chLogicSecLogRouteCheckState);
				}
				else if ((0U < wLogicRLockRouteId) && ((LOG_SECTION_LOCK_NORMAL == chLogicLockState)
					|| (LOG_SECTION_LOCK_DELAY == chLogicLockState)) && (CI_SUCCESS == chLogSecAblReverseProperty))
				{
					/*当不存在逻辑进路，查正常进路的逻辑区段资源时要求列车级别不为ABL且逻辑区段锁闭所属进路不为反向*/
					SetNormalRouteLogicResUsable(wLogSectionId, wTrainId, chLogicSecCheckState);
				}
				else
				{
					SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);		/*不存在进路*/
				}
			}
			else
			{
				/*列车未申请 置为不可使用*/
				SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
			}
		}
	}
}
/*
* 功能描述： 设置指定列车逻辑进路中逻辑区段锁闭资源
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		申请列车ID
*			 UINT8 wLogicSecLogRouteCheckState		逻辑区段可用性检查返回值
* 返回值  ： void
*/
void SetLogRouteLogicResUsable(const UINT16 wLogSectionId, const UINT16 wTrnId, UINT8 wLogicSecLogRouteCheckState)
{
	UINT16 wLogicRLockLogRouteId = 0U;			/*逻辑区段锁闭逻辑进路ID*/
	UINT8 wLogRouteState = 0U;		/*逻辑进路状态*/
	UINT8 chLogRouteLogicLockState = 0U;		/*逻辑进路逻辑区段锁闭状态*/
	UINT8 chRouteTrainEnterFlag = 0U;/*列车处于进路位置*/
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/
	UINT16 wBelongPhySec = 0U;
	UINT8 chQcxFlag = 0U;/*牵出线属性*/
	UINT8 chKeepFlag = CI_ERROR;
	UINT8 chTrainLevel = TRAIN_LEVEL_UR;
	wLogicRLockLogRouteId = GetLogSecBelongLogRouteId(wLogSectionId, wTrnId);
	wLogRouteState = GetLogicalRouteState(wLogicRLockLogRouteId);
	chLogRouteLogicLockState = GetLogSecLogLockState(wLogSectionId);
	if ((0U != wLogSectionId) && (0U != wTrnId))
	{
		if (LOG_SECTION_LOGLOCK_NORMAL == chLogRouteLogicLockState)
		{
			wBelongPhySec = GetLgcSecRelativePhySecId(wLogSectionId);
			chQcxFlag = GetPhySecQcxFlag(wBelongPhySec);
			if (PHYSICAL_SECTION_QCX_YES == chQcxFlag)
			{
				/*牵出线区段RM列车检查区段外方进路*/
				chTrainLevel = GetTrainLevel(wTrnId);
				if (TRAIN_LEVEL_VBTC == chTrainLevel)
				{
					chKeepFlag = CI_SUCCESS;
				}
				else
				{
					/*检查牵出线外方信号机办理列车进路/折返进路*/
					chKeepFlag = CheckQcxLiecheRoute(wBelongPhySec);
				}
			}
			else if (PHYSICAL_SECTION_QCX_NO == chQcxFlag)
			{
				chKeepFlag = CI_SUCCESS;
			}
			else
			{
				/*异常防护*/
				chKeepFlag = CI_ERROR;
			}
			if (CI_SUCCESS == chKeepFlag)
			{
				wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogicRLockLogRouteId);
				if (0U != wLogSignalId)
				{
					chRouteTrainEnterFlag = dsuLogRouteMinHeadTrainCrosSig(wTrnId, wLogicRLockLogRouteId);
				}
				else
				{
					chRouteTrainEnterFlag = TRAIN_ENTER_ROUTE_FULL;		/*无始端信号机，列车已经完全驶入进路*/
				}
				if ((TRAIN_ENTER_ROUTE_NO == chRouteTrainEnterFlag)
					|| (TRAIN_ENTER_ROUTE_HEAD == chRouteTrainEnterFlag))
				{
					if ((ROUTE_LOGICAL_STATE_OPEN == wLogRouteState))
					{
						if (CI_SUCCESS == wLogicSecLogRouteCheckState)
						{
							SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_USABLE);
						}
						else
						{
							SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
						}
					}
					else if ((ROUTE_LOGICAL_STATE_UNLOCKWAIT == wLogRouteState) && (TRAIN_ENTER_ROUTE_NO == chRouteTrainEnterFlag))
					{
						/*若列车已出清逻辑进路最后一个逻辑区段但未解锁（进路保持等待解锁状态）*/
						if (CI_SUCCESS == wLogicSecLogRouteCheckState)
						{
							SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_USABLE);
						}
						else
						{
							SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
						}
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else if ((TRAIN_ENTER_ROUTE_FULL == chRouteTrainEnterFlag)
					|| (TRAIN_ENTER_ROUTE_TAIL == chRouteTrainEnterFlag)
					|| (TRAIN_ENTER_ROUTE_CROSS == chRouteTrainEnterFlag))
				{
					if (CI_SUCCESS == wLogicSecLogRouteCheckState)
					{
						SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_USABLE);
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else
				{
					SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
				}
			}
			else
			{
				SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
			}
		}
		else
		{
		/*无锁闭状态 或锁闭状态异常*/
		SetLogSecTrainUseState(wLogSectionId, wTrnId, LOGIC_SECTION_RES_UNUSABLE);
		}
	}
}

/*
* 功能描述：  设置指定列车正常进路中逻辑区段锁闭资源
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrainId		申请列车ID
*			 UINT8 wLogicSecCheckState	  逻辑区段可用性检查返回值
* 返回值  ： void
*/
void SetNormalRouteLogicResUsable(const UINT16 wLogSectionId, const UINT16 wTrainId, UINT8 wLogicSecCheckState)
{
	UINT8 chRouteTrainEnterFlag = 0U;/*列车处于进路位置*/
	UINT8 chLogicLockState = 0U;/*逻辑区段锁闭状态*/
	UINT16 wLogicRLockRouteId = 0u;	         /*逻辑区段锁闭进路ID*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT8 routeLevel = 0U;   /*进路监督级别*/
	UINT8 chTrainMaxHeadCross = 0U;/*列车大前是否驶入进路标志*/
	UINT16 autoRouteID = 0U;
	UINT16 autoRouteSetFlag = AUTO_ROUTE_SET_NO;
	UINT16 wLockBelongRouteId = 0U;  /*进路锁闭所属进路*/
	UINT16 wRouteLastLogSecId = 0U;  /*进路内方最后一个逻辑区段*/
	UINT16 wBelongPhySec = 0U;
	UINT8 chQcxFlag = 0U;/*牵出线属性*/
	UINT8 chKeepFlag = CI_ERROR;
	UINT8 chTrainLevel = TRAIN_LEVEL_UR;
	chLogicLockState = GetLogSecLockState(wLogSectionId);			/*正常进路锁闭状态*/
	wLogicRLockRouteId = GetLogSecLockBelongRoute(wLogSectionId);         /*获取进路ID*/
	routeState = GetRouteState(wLogicRLockRouteId);                       /*获取进路状态*/
	routeLevel = GetRouteLevel(wLogicRLockRouteId);    /*获取进路监督级别*/
	autoRouteID = GetRouteAutoRouteId(wLogicRLockRouteId);
	autoRouteSetFlag = GetAutoRouteSetFlag(autoRouteID);


	if ((LOG_SECTION_LOCK_NORMAL == chLogicLockState)
		|| (LOG_SECTION_LOCK_DELAY == chLogicLockState))
	{
		wBelongPhySec = GetLgcSecRelativePhySecId(wLogSectionId);
		chQcxFlag = GetPhySecQcxFlag(wBelongPhySec);
		if (PHYSICAL_SECTION_QCX_YES == chQcxFlag)
		{
			/*牵出线区段RM列车检查区段外方进路*/
			chTrainLevel = GetTrainLevel(wTrainId);
			if (TRAIN_LEVEL_VBTC == chTrainLevel)
			{
				chKeepFlag = CI_SUCCESS;
			}
			else
			{
				/*检查牵出线外方信号机办理列车进路/折返进路*/
				chKeepFlag = CheckQcxLiecheRoute(wBelongPhySec);
			}
		}
		else if (PHYSICAL_SECTION_QCX_NO == chQcxFlag)
		{
			chKeepFlag = CI_SUCCESS;
		}
		else
		{
			/*异常防护*/
			chKeepFlag = CI_ERROR;
		}
		if (CI_SUCCESS == chKeepFlag)
		{
			chRouteTrainEnterFlag = dsuTrainMinHeadCrossSignal(wTrainId, wLogicRLockRouteId);

			chTrainMaxHeadCross = dsuTrainCrossSignal(wTrainId, wLogicRLockRouteId);/*判断列车大前是否驶入进路*/

			/*列车未在进路中 或者列车小前进入进路但未越过跨压距离*/
			if ((TRAIN_ENTER_ROUTE_NO == chRouteTrainEnterFlag) || (TRAIN_ENTER_ROUTE_HEAD == chRouteTrainEnterFlag))
			{
				if ((ROUTE_STATE_YUXIAN_OPEN == routeState)
					|| (ROUTE_STATE_NEAR_OPEN == routeState)
					|| (ROUTE_STATE_HALF_UNLOCK == routeState))
				{
					if (CI_SUCCESS == wLogicSecCheckState)
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_USABLE);
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else if ((ROUTE_STATE_AUTO_UNLOCK == routeState) && (TRAIN_ENTER_ROUTE_NO == chRouteTrainEnterFlag))
				{
					/*若列车已出清进路最后一个逻辑区段但未解锁，保持资源可用（只有一个区段的进路出清后为接近锁闭正常时，资源不可用，采用三点检查解锁）*/
					if (CI_SUCCESS == wLogicSecCheckState)
					{
						wLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);  /*获取逻辑区段锁闭所属进路*/
						wRouteLastLogSecId = GetRouteInLastLogSecId(wLockBelongRouteId);  /*获取进路内方最后一个逻辑区段ID*/
						if (wRouteLastLogSecId == wLogSectionId)
						{
							SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_USABLE);  /*进路自动解锁正常且列车不在进路内，仅进路内方最后一个逻辑区段资源状态可用*/
						}
						else
						{
							SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
						}
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else if ((ROUTE_STATE_NEAR_LOCK == routeState) &&
					((TRAIN_ENTER_ROUTE_HEAD == chTrainMaxHeadCross) || (TRAIN_ENTER_ROUTE_CROSS == chTrainMaxHeadCross)))
				{
					/*点式进路在列车驶入进路但未跨压时已关闭信号（接近锁闭正常），若此时大前已驶入进路，需要保持资源可用*/
					/*CBTC进路在列车驶入进路但未跨压时已关闭信号（接近锁闭正常），若此时大前已驶入进路，需要保持资源可用   ——列车驶入点式进路后升级，使进路转变为CBTC进路后，需要保持资源仍然可用 LC 20240626*/
					if (CI_SUCCESS == wLogicSecCheckState)
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_USABLE);
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else if ((ROUTE_STATE_NEAR_LOCKERR == routeState) && (AUTO_ROUTE_SET_YES == autoRouteSetFlag) && (TRAIN_ENTER_ROUTE_HEAD == chRouteTrainEnterFlag))
				{
					/*自动通过进路在列车驶入后转为接近锁闭异常，修复列车驶入进路但未跨压时，资源不可用的问题 LC20240625*/
					if (CI_SUCCESS == wLogicSecCheckState)
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_USABLE);
					}
					else
					{
						SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
					}
				}
				else
				{
					SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
				}

			}
			/*列车跨压信号机  或者列车完全在进路中  或者列车车尾在进路*/
			else if ((TRAIN_ENTER_ROUTE_FULL == chRouteTrainEnterFlag)
				|| (TRAIN_ENTER_ROUTE_TAIL == chRouteTrainEnterFlag)
				|| (TRAIN_ENTER_ROUTE_CROSS == chRouteTrainEnterFlag))
			{
				if (CI_SUCCESS == wLogicSecCheckState)
				{
					SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_USABLE);
				}
				else
				{
					SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
				}
			}
			else
			{
				SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
			}
		}
		else
		{
			SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
		}
	}
	else
	{
		/*无锁闭状态 或锁闭状态异常*/
		SetLogSecTrainUseState(wLogSectionId, wTrainId, LOGIC_SECTION_RES_UNUSABLE);
	}
}

/*
* 功能描述： 列车中途折返进路解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* BY LC
*/
void RouteZhongtuZhefanQuxiaoProc(const UINT16 routeId)
{
	UINT8 checkJiesuoResult = 0u;
	
	/*进路解锁条件判断*/
	checkJiesuoResult = CheckRouteZhefanJiesuo(routeId);
	if (CI_SUCCESS == checkJiesuoResult)
	{
		/*设置进路空闲*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
	}
	else
	{
		/*进路不能解锁*/
	}

}

/*
* @brief 办理申请部分路径逻辑管理（车辆段）
* @param const UINT8 cLogSecSeqDir 逻辑区段序列方向
*        const UINT16 wTrainId 列车编号
*        const UINT8 cLogSecSum 逻辑区段数量
*        const UINT16* pLogSecIdBuff 逻辑区段序列
* Created By LQ 2024.09.05
*/
void RoutePartApplyLogicManageCLD(const UINT8 cLogSecSeqDir, const UINT16 wTrainId, const UINT8 cLogSecSum, const UINT16* pLogSecIdBuff)
{
	/*局部变量初始化*/
	UINT16 wTrainIndex = 0U;
	UINT8 keepWork = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 cDrSubSum = 0U;  /*动态进路包含的子进路数量*/
	UINT16 wDrSubIdBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };   /*动态进路包含的子进路ID数组*/
	UINT8 cCTOccLogSum = 0U;         /*通信列车脚下逻辑区段数量*/
	UINT16 szCTOccLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };   /*通信列车占压的逻辑区段ID*/
	UINT16 wUsableDrId = 0U;        /*最小可用的动态进路ID*/
	UINT8 cLocalCiId = 0U;
	UINT8 cRouteBelongCiId = 0U;
	UINT16 wMatchedRouteId = 0U;  /*最终匹配的进路*/
	UINT8 cCheckStep = 0U;  /*记录代码运行到的位置，便于错误分析*/
	UINT8 cFunctionId = EFUNC_PART_ROUTE_CMD_PROC_CLD;
	UINT8 cSendLevel = ESEND_LEVEL_ATS;

	/*入参检查*/
	wTrainIndex = GetTrainBufIndex(wTrainId);
	if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) || (CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir))
		&& (TRAIN_SUM_MAX > wTrainIndex) && (0U != cLogSecSum) && (NULL != pLogSecIdBuff))
	{
		keepWork = CI_SUCCESS;
	}
	else
	{
		keepWork = CI_ERROR;
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第一步：检查逻辑区段序列及列车位置：逻辑区段为休眠唤醒轨且唯一且未锁闭、且列车完全位于休眠唤醒轨*/
		keepWork = LogSecSeqAndTrainPosCheckCLD(cLogSecSum, pLogSecIdBuff, wTrainId, cFunctionId, cSendLevel);
		cCheckStep++;
	}
	else
	{
		/*不处理*/
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第二步：拆分逻辑区段序列，匹配列车进路*/
		keepWork = LogSecSeqAndRouteMatchCheckCLD(cLogSecSeqDir, pLogSecIdBuff[0], &wMatchedRouteId);

		if (CI_SUCCESS != keepWork)
		{
			SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_MATCH_ROUTE, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
		}
		else
		{
			/*继续检查*/
		}
		cCheckStep++;
	}
	else
	{
		/*不处理*/
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第三步：检查通信车没有前端及后端可疑*/
		keepWork = CtTrainSuspCheck(wTrainId);

		if (CI_SUCCESS != keepWork)
		{
			SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SCREEN, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
		}
		else
		{
			/*继续检查*/
		}
		cCheckStep++;
	}
	else
	{
		/*不处理*/
	}

	if (CI_SUCCESS == keepWork)
	{
		/*第四步：进路办理条件检查*/
		debug_infor_printf((const)"CLD Half Route Id[%d]\n", wMatchedRouteId);

		cLocalCiId = GetSystemParaLocalCiId();
		cRouteBelongCiId = GetRouteBelongCiId(wMatchedRouteId);

		if ((cLocalCiId == cRouteBelongCiId) && (0U != cLocalCiId))
		{
			/*填充部分进路结构体*/
			SetHalfRouteSwitchMoveValid(wMatchedRouteId, ROUTE_HALF_SWITCH_MOVE_INVALID);  /*设置部分进路道岔可动标志*/
			SetHalfRouteLockLgcSec(wMatchedRouteId, cLogSecSum, pLogSecIdBuff);  /*设置部分进路锁闭的逻辑区段数据*/
			SetHalfRouteResReqTrainId(wMatchedRouteId, wTrainId);  /*设置发送资源请求的列车ID*/
			SetHalfRouteTrainLocLgcSec(wMatchedRouteId, cCTOccLogSum, szCTOccLogID);  /*设置部分进路列车脚下逻辑区段数据*/

			keepWork = HalfRoutePhySecUseLogicProcess(wMatchedRouteId);  /*部分进路区段征用检查*/
			if (CI_SUCCESS == keepWork)
			{
				wDrSubIdBuff[cDrSubSum] = wMatchedRouteId;
				cDrSubSum++;
			}
			else
			{
				SetRouteStateManage(wMatchedRouteId, ROUTE_STATE_IDLE);  /*征用失败，设置进路空闲*/
			}
		}
		else
		{
			keepWork = CI_ERROR;  /*不处理*/
		}

		if ((CI_SUCCESS == keepWork) && (0U != cDrSubSum))
		{
			/*将匹配的进路传递至动态进路处理*/
			wUsableDrId = GetUsableDrId();
			SetDrSubRoute(wUsableDrId, cDrSubSum, wDrSubIdBuff);

			debug_infor_printf((const)"CLD Dynamic Sub Route Sum:%d, CLD Dynamic Sub Route ID:[", cDrSubSum);
			for (ii = 0U; ii < cDrSubSum; ii++)
			{
				debug_infor_printf((const)"%d,", wDrSubIdBuff[ii]);
			}
			debug_infor_printf((const)"]\n");
		}
		else
		{
			keepWork = CI_ERROR;  /*不处理*/
		}
		cCheckStep++;
	}
	else
	{
		/*不处理*/
	}

	/*记录错误日志*/
	if (CI_SUCCESS != keepWork)
	{
		/*办理失败，记录错误日志，
		cCheckStep：为0表示入参校验失败，为1表示逻辑区段序列和列车位置检查失败，为2表示匹配进路失败，为3表示列车前/后筛选检查失败，
					为4表示进路办理条件检查失败*/
		debug_infor_printf((const)"CLD Route Part Apply Error! Error Position Is [%d]\n", cCheckStep);
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述： 进路其它联锁道岔管理
* 参数说明： void
* 返回值  ：无
* by cgh 20241203
*/
void RouteOtherCiSwitchManage(void)
{
	UINT16 wRouteCurSum = 0U;	     /*进路总数目*/
	UINT16 ii = 0U;
	UINT8 chLocalCiId = 0U;         /*本地联锁ID*/
	UINT16 wRouteId = 0U;	         /*进路ID*/
	UINT8 chRouteBelongCiId = 0U;        /*进路所属联锁ID*/
	UINT8 chRouteState = 0U;/*进路状态*/
	UINT8 chRouteStateFlag = 0U;/*进路状态转移标志*/
	UINT8 chRouteSwPosValidCheck = 0U;/*进路其它联锁道岔检查*/
	UINT8 chResult = 0U;/*检查结果*/
	UINT8 chTransmitStat = 0U;/*通信状态*/
	UINT8 chRouteApplySwitchCheckFlag = 0U;/*进路办理道岔检查标志*/
	UINT8 chOthCiRouteExistLocalCiSw = 0U;/*其他控区进路是否存在本控区道岔*/
	UINT16 errorCodeCurSum = 0U;
	ErrorDataStruct* errorCodeStu = NULL; /*错误码数据*/
	UINT16 devId = 0U;
	UINT8 devState = 0U;

	wRouteCurSum = GetRouteCurSum();		        /*获取进路总数*/
	chLocalCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
		/*处理进路*/
	for (ii = 0u; ii < wRouteCurSum; ii++)
	{
		wRouteId = 0U;

		wRouteId = GetRouteId(ii);
		chRouteBelongCiId = GetRouteBelongCiId(wRouteId);
		chOthCiRouteExistLocalCiSw = GetOthCiRouteExistLocalCiSw(wRouteId);

		if ((chLocalCiId != chRouteBelongCiId) && (0U != chLocalCiId) && (0U != chRouteBelongCiId) && (0U != chOthCiRouteExistLocalCiSw))
		{
			chRouteState = GetRouteState(wRouteId);
			chRouteStateFlag = GetRouteStateFlag(wRouteId);

			if ((ROUTE_STATE_XUANPAI == chRouteState)
				|| (((ROUTE_STATE_AUTO_UNLOCK == chRouteState) || (ROUTE_STATE_AUTO_UNLOCKERR == chRouteState)) && (ROUTE_STATE_FLAG_YES == chRouteStateFlag))
				|| (ROUTE_STATE_LEAD_XUANPAI == chRouteState))
			{

				/*通信中断时，相邻联锁进路状态和追踪办理标志是维持的，此时持续会判断当前是否是失败*/
				chRouteApplySwitchCheckFlag = GetRouteApplySwitchCheckFlag(wRouteId);

				if ((ROUTE_APPLY_SWITCH_CHECK_YES == chRouteApplySwitchCheckFlag) || (ROUTE_APPLY_SWITCH_CHECK_DEF == chRouteApplySwitchCheckFlag))
				{
					chRouteSwPosValidCheck = RouteOtherCiSwPosValidCheck(wRouteId);
					if (CI_SUCCESS == chRouteSwPosValidCheck)
					{
						chResult = ChekRoutSwitDrivOvtmStat(wRouteId);
						if (CI_SUCCESS == chResult)
						{
							chResult = RouteLockSwitchDanCaoCheck(wRouteId);

							if (CI_SUCCESS == chResult)
							{
								SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_YES);
								chResult = RouteRelAllSwitchPosCheck(wRouteId, &devId, &devState);
								if (CI_SUCCESS == chResult)
								{
									; /*道岔位置正确返回成功*/
								}
								else
								{
									if (ROUTE_STATE_LEAD_XUANPAI != chRouteState)
									{
										/*驱动进路道岔*/
										RouteDrvInnerSwitch(wRouteId, SWITCH_NEED_DRIV_TRUE);
									}
									else
									{
										/*引导进路要求相邻联锁道岔在规定位置，不驱动道岔*/
										SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_NO);
										SetRouteApplySwitchCheckErrorData(wRouteId, devId, CI_DEVICE_TYPE_SWITCH, devState, ETYPE_SWT_POSTION_STATE);
									}
								}

							}
							else
							{
								SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_NO);
								SetRouteApplySwitchCheckErrorData(wRouteId, wRouteId, CI_DEVICE_TYPE_ROUTE, 0U, ETYPE_ROUTE_APPLY_SWITCH_MOVE);/*进路道岔单操方向不一致*/
							}
						}
						else
						{
							SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_NO);
						}
					}
					else
					{
						/*处理相邻联锁传递处理错误码*/
						errorCodeCurSum = GetErrorDataCurSum();  /*获取错误码总数*/
						errorCodeStu = GetErrorData(errorCodeCurSum - 1U);  /*最新故障记录*/
						SetRouteApplySwitchCheckErrorData(wRouteId, errorCodeStu->DeviceId, errorCodeStu->DeviceType, errorCodeStu->DeviceState, errorCodeStu->DeviceStateType);
						SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_NO);
					}
				}
				else
				{
					SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_NO);
				}
			}
			else
			{
				/*设置进路办理道岔检查标志为默认*/
				SetRouteApplySwitchCheckFlag(wRouteId, ROUTE_APPLY_SWITCH_CHECK_DEF);
			}
		}
		else
		{
			; /*进路是自己联锁或联锁ID存在异常不处理*/
		}
	}
}

/*
* 功能描述：保护区段其它联锁防护道岔管理
* 参数说明：void
* 返 回 值：无
* Created By LQ 2024.12.09
*/
void OverlapOtherCiProSwitchManage(void)
{
	UINT16 wOverlapCurSum = 0U;  /*保护区段总数目*/
	UINT16 ii = 0U;
	UINT8 cLocalCiId = 0U;  /*本地联锁ID*/
	UINT16 wOverlapId = 0U;  /*保护区段ID*/
	UINT8 cOverlapBelongCiId = 0U;  /*保护区段所属联锁ID*/
	UINT8 cCheckResultFlag = PROSWITCH_CHECK_RESULT_INVALID;  /*保护区段防护道岔检查结果标志*/
	UINT8 cCheckStartFlag = PROSWITCH_CHECK_START_INVALID;  /*保护区段防护道岔检查开始标志*/
	UINT8 cCheckResult = CI_ERROR;  /*检查结果*/	

	wOverlapCurSum = GetOverlapCurSum();  /*获取保护区段总数*/
	cLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	
	for (ii = 0u; ii < wOverlapCurSum; ii++)
	{
		wOverlapId = GetOverlapId(ii);
		cOverlapBelongCiId = GetOverlapBelongCiId(wOverlapId);

		if ((cLocalCiId != cOverlapBelongCiId) && (0U != cLocalCiId) && (0U != cOverlapBelongCiId))
		{
			cCheckResultFlag = GetOverlapProSwtCheckResultFlag(wOverlapId);  /*获取保护区段防护道岔检查结果标志*/
			cCheckStartFlag = GetOverlapProSwtCheckStartFlag(wOverlapId);  /*获取保护区段防护道岔检查开始标志*/
			
			if ((PROSWITCH_CHECK_RESULT_INVALID != cCheckResultFlag) && (PROSWITCH_CHECK_START_VALID == cCheckStartFlag))
			{
				cCheckResult = OtherCiOvlpRelProSwMovValCheck(wOverlapId);  /*保护区段防护道岔可动性检查*/
				if (CI_SUCCESS == cCheckResult)
				{
					cCheckResult = ChekSwitDrivOvtm(wOverlapId);  /*检查道岔是否驱动超时*/
					if (CI_SUCCESS == cCheckResult)
					{
						cCheckResult = OverlapLockDriveSwitch(wOverlapId);  /*保护区段锁闭驱动道岔处理*/
						if (CI_SUCCESS == cCheckResult)
						{
							SetOverlapProSwtCheckResultFlag(wOverlapId, PROSWITCH_CHECK_RESULT_VALID);  /*成功，设置保护区段防护道岔检查结果标志成功*/
						}
						else
						{
							SetOverlapProSwtCheckResultFlag(wOverlapId, PROSWITCH_CHECK_RESULT_INVALID);  /*道岔驱动失败，设置保护区段防护道岔检查结果标志失败*/
						}
					}
					else
					{
						SetOverlapProSwtCheckResultFlag(wOverlapId, PROSWITCH_CHECK_RESULT_INVALID);  /*道岔驱动超时，设置保护区段防护道岔检查结果标志失败*/
						SetErrorData(EFUNC_SWITCH_DRIVE_OUTTIME, CI_DEVICE_TYPE_SWITCH, wOverlapId, CI_DEVICE_TYPE_OVERLAP, SWITCH_POSITION_INVALID, ESEND_LEVEL_ZERO);
					}
				}
				else
				{
					SetOverlapProSwtCheckResultFlag(wOverlapId, PROSWITCH_CHECK_RESULT_INVALID);  /*可动性检查失败，设置保护区段防护道岔检查结果标志失败*/
				}
			}
			else
			{
				/*保护区段不在锁闭中或当前检查失败，不处理*/
			}
		}
		else
		{
			/*保护区段属于本控区或ID存在异常，不处理*/
		}
	}
}

/*
* 功能描述： 进路列车释放解锁逻辑管理
* 参数说明： void
* 返回值  ：无
* by cgh 20250107
*/
void RouteTrainResUnlockManage(void)
{
	UINT16 wRouteCurSum = 0U;	     /*进路总数目*/
	UINT8 chLocalCiId = 0U;          /*本地联锁ID*/
	UINT16 wRouteId = 0U;	         /*进路ID*/
	UINT8 chRouteBelongCiId = 0U;    /*进路所属联锁ID*/
	UINT16 ii = 0U;                  /*循环索引*/
	UINT8 chStartLockState = 0U;     /*上电解锁标志*/
	UINT8 chStartFlockFlag = 0U;     /*上电解封标志*/
	UINT8 chLocalCiType = 0U;        /*本地联锁类型*/
	UINT8 chFlagExec = CI_ERROR;     /*继续执行标志*/
	UINT8 chRcWorkMode = 0U;         /*RC工作模式*/

	chLocalCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	chRcWorkMode = GetLocalRcWorkMode();

	if ((0U != chLocalCiId) && (RC_WORK_MODE_TIOC == chRcWorkMode))
	{
		chFlagExec = CI_SUCCESS;
		chLocalCiType = GetLocalCiType();
		chStartLockState = GetStartLockFlag();        /*获取上电解锁标志*/
		chStartFlockFlag = GetStartFLockFlag();       /*获取上电解封标志*/

		if ((CI_TYPE_ZX == chLocalCiType) || (CI_TYPE_SCX == chLocalCiType))
		{
			/*正线和试车线既检查上电解锁，又检查全站解封*/
			if ((CI_START_LOCK_NO != chStartLockState) || (CI_START_FLOCK_NO != chStartFlockFlag))
			{
				/*未全站解封且未上电解锁*/
				chFlagExec = CI_ERROR;
			}
			else
			{
				; 
			}
		}
		else
		{/*车辆段仅检查上电解锁*/
			if (CI_START_LOCK_NO != chStartLockState)
			{ /*未上电解锁*/

				chFlagExec = CI_ERROR;
			}
			else
			{
				;
			}
		}
	}
	else
	{
		; /*本联锁ID非法或非RC模式，不继续执行*/
	}



	if (CI_SUCCESS == chFlagExec)
	{
		wRouteCurSum = GetRouteCurSum();		        /*获取进路总数*/

		/*处理进路*/
		for (ii = 0u; ii < wRouteCurSum; ii++)
		{
			wRouteId = 0U;	         /*进路ID*/
			chRouteBelongCiId = 0U;          /*进路所属联锁ID*/

			wRouteId = GetRouteId(ii);                           /*获取进路ID*/

			if ((0U < wRouteId) && (ROUTE_SUM_MAX > wRouteId))
			{
				chRouteBelongCiId = GetRouteBelongCiId(wRouteId);           /*获取进路所属联锁ID*/
				
				if (chLocalCiId == chRouteBelongCiId)
				{
					RouteLgcSecResUnlockManage(wRouteId);
				}
				else
				{
					; /*非本联锁不处理*/
				}
			}
			else
			{
				; /*进路ID非法*/
			}
		}
	}
	else
	{
		; /*不继续执行*/
	}
}

/*
* 功能描述： 引导进路初选管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* by cgh 20250224
*/
void LeadRouteFirstXuanPaiManage(const UINT16 routeId)
{
	UINT8 returnValueFunc = 0U;    /*返回值定义*/
	UINT8 firstXuanPaiOvertime = 0U;/*初选超时*/
	UINT8 routeCheck = 0U;
	UINT8 chFunctionId = EFUNC_LEAD_ROUTE_FIRST_XUANPAI;/*故障码函数ID*/

	routeCheck = SetLeadRouteCheck(routeId);
	
	/*办理进路处理*/
	if (CI_SUCCESS == routeCheck)
	{
		firstXuanPaiOvertime = RouteFirstXuanOverTime(routeId);
		if (OVERTIME_YES == firstXuanPaiOvertime)
		{
			/*初选超时*/
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			/*设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);

			/*增加进路初选超时错误码打印*/
			SetErrorData(chFunctionId, CI_DEVICE_TYPE_ROUTE, routeId,
				ETYPE_ROUTE_FIRST_XUANPAI_OVERTIME, ROUTE_STATE_LEAD_FIRST_XUANPAI, ESEND_LEVEL_ZERO);
		}
		else
		{
			/*进路初选处理*/
			returnValueFunc = RouteFirstXuanProc(routeId);

			if (CI_ERROR == returnValueFunc)
			{
				/*征用失败*/

				/*设置进路物理区段未征用*/
				SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

				/*设置进路空闲*/
				SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
			}
			else if (CI_SUCCESS == returnValueFunc)
			{
				/*征用成功*/

				SetRouteStateManage(routeId, ROUTE_STATE_LEAD_XUANPAI);  /*-->设置引导选排*/

				/*进路选排处理*/
				LeadRouteXuanPaiManage(routeId);
			}
			else
			{
				; /*等待*/
			}
		}
	}
	else
	{
		/*进路办理失败*/

		/*设置进路物理区段未征用*/
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

		/*设置进路空闲*/
		SetRouteStateManage(routeId, ROUTE_STATE_IDLE);
	}
}

/*
* 功能描述： 设置OC-P旁路状态确认标志
* 参数说明： UINT8 setFlag,设置标志
*            UINT16 pscId  PSC设备ID
* 返回值  ：无
*/
void SetOcPscPlConfirmFlag(UINT8 setFlag, const UINT16 ocPId)
{
	/*变量初始化*/
	UINT8 i = 0u;
	UINT8 j = 0u;
	UINT8 kk = 0u;
	UINT8 localCiId = 0u;
	UINT8 deviceSum = 0u;/*通信设备总数*/
	UINT8* pDeviceIdBuf = NULL;/*通信设备ID数组*/
	UINT16 saveOcPId = 0u;
	UINT8 lowByteOcPId = 0u;
	UINT8 ocPSystemId = 0u;
	UINT8 transmitReval = CI_ERROR;
	UINT8 transmitState = 0u;
	UINT8 ocPscConfirmFlag = 0u;
	UINT8 findOcFlag = 0u;

	/*对变量赋值*/
	saveOcPId = ocPId;
	lowByteOcPId = (UINT8)(saveOcPId & 0x00FFU);

	deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_OC);     /*获取通信OC设备总数*/
	pDeviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_OC); /*获取通信OC设备ID数组*/
	localCiId = GetSystemParaLocalCiId();/*获取CI ID*/

	for (i = 0u; i < deviceSum; i++)
	{
		findOcFlag = 0u;
		/*匹配OC-P ID*/
		if (lowByteOcPId == pDeviceIdBuf[i])
		{
			ocPSystemId = pDeviceIdBuf[i];
			/*OC-P系统ID合法*/
			if (OC_SUM_MAX > ocPSystemId)
			{
				/*更新与CI通信状态*/
				transmitReval = UpdateCiTransmitState(localCiId, CI_SYSTEM_TYPE_OC, ocPSystemId);
				if (CI_SUCCESS == transmitReval)
				{
					transmitState = GetCiTransmitState(CI_SYSTEM_TYPE_OC, ocPSystemId);
				}

				/*找到ID对应的索引*/
				for (kk = 0u; kk < m_OcToCiOrginDataNum; kk++)
				{
					/*找到OC id对应的数组下标kk*/
					if (m_OcToCiOrginDataArr[kk].OcId == ocPSystemId)
					{
						findOcFlag = 1u;
						break;
					}
				}

				if (1u == findOcFlag)
				{
					/*找到了，设置旁路*/
					if (OC_PSC_PL_CONFIRM_YES == setFlag)
					{
						for (j = 0u; j < m_OcToCiOrginDataArr[kk].OCPsdNum; j++)
						{
							/*通信异常*/
							if (TRANSMIT_STATE_GOOD != transmitState)
							{
								/*设置OC-P系统对应PSD旁路状态*/
								SetPsdConfirmFlag(m_OcToCiOrginDataArr[kk].PsdInfo[j].wPsdId, setFlag);
							}
							else
							{
								/*不处理*/
							}
						}
					}
					else
					{
						for (j = 0u; j < m_OcToCiOrginDataArr[kk].OCPsdNum; j++)
						{
							/*获取OC-P确认旁路标志*/
							ocPscConfirmFlag = GetPsdPlFlag(m_OcToCiOrginDataArr[kk].PsdInfo[j].wPsdId);
							if (OC_PSC_PL_CONFIRM_YES == ocPscConfirmFlag)
							{
								/*设置取消确认标志*/
								SetPsdConfirmFlag(m_OcToCiOrginDataArr[kk].PsdInfo[j].wPsdId, OC_PSC_PL_CONFIRM_NO);
							}
							else
							{
								/*不是旁路状态*/
							}
						}
					}
				}
				
			}
			else
			{
				/*OC-P ID不合法*/
			}

			/*找到跳出循环*/
			break;
		}

	}
}

/*
* 功能描述： 保护区段照查条件更新
* 参数说明： const UINT16 wRouteId 进路ID
* 返回值  ：无
* by cgh 20250617
*/
void OverlapZhaoChaRelayUpDateManage(void)
{
	UINT16 wOverlapCurSum = 0U;/*保护区段当前总数*/
	UINT16 ii = 0U;
	UINT16 wOverlapId = 0U;/*保护区段ID*/
	UINT8 chOverlapBelCiId = 0U;/*保护区段所属联锁ID*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT16 wThisZhaoChaRelayId = 0U; /*本端照查继电器ID*/
	UINT32 dwOverlapLockStartCycNum = 0U;/*保护区段锁闭起始周期号*/
	UINT8 chRelayDriveState = 0U; /*继电器驱动状态*/
	UINT8 chRelayCollState = 0U; /*继电器采集状态*/
	UINT8 chTimeCheckFlag = 0U;/*时间检查结果*/
	UINT32 dwSigalCloseCyc = 0U; /*信号机关闭超限周期数*/

	wOverlapCurSum = GetOverlapCurSum();
	chLocalCiId = GetSystemParaLocalCiId();

	for (ii = 0U; ii < wOverlapCurSum; ii++)
	{
		wOverlapId = GetOverlapId(ii);
		chOverlapBelCiId = GetOverlapBelongCiId(wOverlapId);

		if ((chLocalCiId == chOverlapBelCiId) && (0U != chLocalCiId))
		{
			wThisZhaoChaRelayId = GetOverlapThisZhaoChaRelayId(wOverlapId); /*本端照查继电器ID*/

			if (0U < wThisZhaoChaRelayId)
			{
				dwOverlapLockStartCycNum = GetOverlaplockSucessStartCycNum(wOverlapId);
				/*网络接口本端继电器存在*/
				if (0U == dwOverlapLockStartCycNum)
				{
					chRelayDriveState = GetRelayDriveState(wThisZhaoChaRelayId);

					if (RELAY_DRIVE_STATE_NULL == chRelayDriveState)
					{
						(void)SetRelayDriveState(wThisZhaoChaRelayId, RELAY_DRIVE_STATE_UP);
					}
				}
				else
				{
					(void)SetRelayDriveState(wThisZhaoChaRelayId, RELAY_DRIVE_STATE_DOWN);
					chRelayCollState = GetRelayCollState(wThisZhaoChaRelayId);

					if (RELAY_STATE_DOWN != chRelayCollState)
					{
						dwSigalCloseCyc = GetSystemParaSignalCloseCyc();
						chTimeCheckFlag = SystemOverTimeCheck(dwOverlapLockStartCycNum, dwSigalCloseCyc);

						if (CI_TIME_OUT == chTimeCheckFlag)
						{
							SetPlatOverFlag(); /*设置平台宕机*/
							SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_RELAY, wThisZhaoChaRelayId, ETYPE_ZHAOCHA_OVERLAP_OVERTIME, RELAY_STATE_UP, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
						}
					}
				}
			}
			else
			{
				; /*无本端照查继电器不处理*/
			}
		}
		else
		{
			; /*不属于本联锁不处理*/
		}
	}	
}

/*
* 功能描述： 更新列车向后跳跃允许状态处理
* 参数说明： 无
* 返回值  ： 无
* Create: fan 20250725
*/
void TrainJumpBackApplyProc(void)
{
	UINT8 chTrainIndex = 0U;
	UINT16 wTrainId = 0U; /*列车ID*/
	UINT16 wMaxTailLink = 0u; /*大后link*/
	UINT16 wAxisSecId = 0U; /*计轴区段ID*/
	UINT8 chJumpBackApplyState = 0U;/*列车后跳申请状态*/
	UINT8 chAcBelongCiId = 0U; /*计轴区段所属联锁*/
	UINT8 chLocalCiId = 0U;/*本联锁ID*/
	UINT8 chDir = 0U;  /*大后运行方向*/
	UINT8 linkNum = 0U;/*计轴关联link数量*/
	TRAIN_SEQUANCE_s linkInctrainList[SIZE_MAX_TRAINOFAC] = { 0u };  /*link上的列车序列*/
	UINT8 k = 0U;
	UINT8 cLinkIncTrainSum = 0U; /*link关联列车数量*/
	UINT8 chFindBaseTrain = CI_ERROR;
	UINT8 chBackTrain = CI_ERROR;
	UINT16 chElmTrainID = 0U;
	EnvelopeStruct* strTrainEnvelope = NULL;  /*列车包络信息*/

	chLocalCiId = GetSystemParaLocalCiId();
	/* 遍历所有列车 */
	for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
	{
		wTrainId = GetTrainId(chTrainIndex);
		chElmTrainID = (wTrainId & 0x00ff);
		chJumpBackApplyState = GetTrainJumpBackApplyState(wTrainId);
		wMaxTailLink = GetTrainMaxTailLink(wTrainId);
		wAxisSecId = GetLinkBelongAcId(wMaxTailLink);
		chAcBelongCiId = (UINT8)GetAxisBelongTiocAllLine(wAxisSecId);
		if (TRAIN_JUMP_BACK_STATE_VALID != chJumpBackApplyState)
		{
			/*未申请,默认状态 0*/
			SetTrainJumpBackReplyState(wTrainId, TRAIN_JUMP_BACK_STATE_NONE);
		}
		else
		{
			/*先设置不允许*/
			SetTrainJumpBackReplyState(wTrainId, TRAIN_JUMP_BACK_STATE_INVALID);
			linkNum = GetAxisLinkSum(wAxisSecId);
			if (chLocalCiId == chAcBelongCiId)
			{
				strTrainEnvelope = elm_GetEnvelopeInfoByTrainID(chElmTrainID);
				if ((1U == linkNum) && (NULL != strTrainEnvelope))
				{
					if (0U == strTrainEnvelope->tailTrainID)
					{
						chDir = GetTrainDir_MaxTail(wTrainId);
						cLinkIncTrainSum = as_GetLinkTrainList(wMaxTailLink, linkInctrainList, SIZE_MAX_TRAINOFAC);
						chFindBaseTrain = CI_ERROR;
						chBackTrain = CI_SUCCESS;
						if (DIR_CONVERT == chDir)
						{
							for (k = 0U; k < cLinkIncTrainSum; k++)
							{
								if (chElmTrainID == linkInctrainList[k].u16TrainID)
								{
									chFindBaseTrain = CI_SUCCESS;
								}
								else
								{
									if (CI_SUCCESS == chFindBaseTrain)
									{
										/*本车后方列车*/
										chBackTrain = CI_ERROR;
										break;
									}
									else
									{
										; /*本车前方列车 继续遍历*/
									}
								}
							}
						}
						else if (DIR_SAME == chDir)
						{
							for (k = cLinkIncTrainSum; 0U < k; k--)
							{
								if (chElmTrainID == linkInctrainList[k - 1].u16TrainID)
								{
									chFindBaseTrain = CI_SUCCESS;
								}
								else
								{
									if (CI_SUCCESS == chFindBaseTrain)
									{
										/*本车后方列车*/
										chBackTrain = CI_ERROR;
										break;
									}
									else
									{
										; /*本车前方列车 继续遍历*/
									}
								}
							}
						}
						else
						{
							/*方向错误*/
							chBackTrain = CI_ERROR;
						}
						if (CI_SUCCESS == chBackTrain)
						{
							SetTrainJumpBackReplyState(wTrainId, TRAIN_JUMP_BACK_STATE_VALID);
						}
					}
					else
					{
						; /*已设置不允许*/
					}
				}
				else
				{
					; /*已设置不允许*/
				}
			}
			else
			{
				; /*已设置不允许*/
			}
		}
	}
}
/*
* 功能描述：牵出线区段外方进路检查
* 参数说明： const UINT16 wPhySecId 牵出线区段
* 返回值  ：CI_SUCCESS列车进路已办理 CI_ERROR未办理列车进路
* by fan 20260415
*/
UINT8 CheckQcxLiecheRoute(UINT16 wPhySecId)
{
	UINT16 wStatrSigRtSum = 0U;/*获取以该信号机为始端信号机的进路数目*/
	UINT16* szStartSigRouteBuf = NULL;/*获取以该信号机为始端信号机的进路数组*/
	UINT16 wSigId = 0U;/*信号机ID*/
	UINT16 jj = 0U;
	UINT16 ii = 0U;
	UINT8 chRouteState = 0U;/*进路状态*/
	UINT8 chRouteType = 0U;/*进路类型*/
	UINT8 chRtnval = CI_ERROR;
	UINT16 wSigSum = 0U;/*信号机总数*/
	UINT16 wSigOutSec = 0U;
	/*遍历以该信号机为始端信号机的进路，存在列车进路非空闲*/
	wSigSum = GetSignalCurSum();
	
	for (ii = 0u; ii < wSigSum; ii++)
	{
		wSigId = GetSignalId(ii);
		wStatrSigRtSum = GetStartSignalRouteSum(wSigId);/*获取以该信号机为始端信号机的进路数目*/
		szStartSigRouteBuf = GetStartSignalRouteBuf(wSigId);/*获取以该信号机为始端信号机的进路数组*/
		wSigOutSec = GetSignalOutFirstPhySecId(wSigId);
		/*信号机外方区段存在且与牵出线区段一致、信号机存在关联进路*/
		if ((0U != wSigOutSec) && (wSigOutSec == wPhySecId) && (0U != wStatrSigRtSum))
		{
			for (jj = 0U; jj < wStatrSigRtSum; jj++)
			{/*查找以信号机为始端信号机的开放的进路ID*/
				chRouteState = GetRouteState(szStartSigRouteBuf[jj]);/*获取进路状态*/
				chRouteType = GetRouteType(szStartSigRouteBuf[jj]);/*进路类型*/
				/*列车进路（车辆段折返进路初始化为列车进路） 接近开放或接近锁闭正常*/
				if ((ROUTE_TYPE_LIECHE == chRouteType)
					&&((ROUTE_STATE_NEAR_OPEN == chRouteState)||(ROUTE_STATE_NEAR_LOCK == chRouteState)))
				{
					chRtnval = CI_SUCCESS;
					break;
				}
			}
		}
		if (CI_SUCCESS == chRtnval)
		{
			break;
		}
	}
	return chRtnval;
}
/*
* 功能描述： 计轴区段跳跃锁闭状态机管理
* 参数说明： const UINT16 axisSecId, 计轴区段ID
* 返回值  ： void
* add by mpt 20260407
*/
void AxisJumpLockStateManage(const UINT16 axisSectionId)
{
	UINT8 rtVal = 0U;
	UINT8 applyFlag = 0U;
	UINT32 applyCycle = 0U;
	UINT8 cancelApplyFlag = 0U;
	UINT16 phyId = 0U;
	UINT32 curCycle = 0U;
	UINT8 chPhySecJmpState = 0U;


	applyFlag = GetAxisSecJumpLockApplyFlag(axisSectionId);
	applyCycle = GetAxisSecJumpLockApplyCylce(axisSectionId);
	cancelApplyFlag = GetAxisSecJLockCancelApplyFlag(axisSectionId);

	phyId = GetAxisSecRelativePhySecId(axisSectionId);/*获取相关物理区段ID*/
	curCycle = Get2oo2CurCycleNum();


	/*持续进行锁闭检查，检查通过，设置物理区段跳跃锁闭；检查不通过，设置未跳跃锁闭*/
	rtVal = LockAxisSecProc(axisSectionId);/*跳跃锁闭联锁条件检查*/
	if (CI_SUCCESS == rtVal)
	{
		if ((AXIS_SECTION_JUMPLOCK_APPLY_YES == applyFlag) &&
			(AXSEC_CANCEL_JUMPLOCK_APPLY_NO == cancelApplyFlag) &&
			(curCycle == applyCycle))
		{/*本周期有跳跃锁闭申请，才设置物理区段跳跃锁闭*/
			chPhySecJmpState = GetPhySecJumpLockState(phyId);
			if (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhySecJmpState)
			{/*无跳跃锁闭且当前无征用*/
				ClearAxisSeceSwitchDanCaoPos(axisSectionId);/*清除单操*/

				SetPhySecJumpLockState(phyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
				SetAxisRelProSwitchLockSta(axisSectionId, SWITCH_LOCK_PROTECT_SET);
				SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
				SetAxisInCludeLogJumpLockState(axisSectionId, LOGIC_SECTION_JUMP_LOCK_YES);

				/*设置未征用*/
				SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_NO, 0);
				SetJumpPhySectionPortectSecUse(axisSectionId, PHYSICAL_SECTION_USING_NO);/*设置物理区段的防护道岔所在区段取消防护征用*/
			}
			else
			{
				/*不执行*/
			}
		}
		else
		{
			chPhySecJmpState = GetPhySecJumpLockState(phyId);
			if ((PHYSICAL_SECTION_JUMP_LOCK_YES == chPhySecJmpState) && (0U < applyCycle))
			{
				SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_YES);
			}
			else if (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhySecJmpState)
			{/*当前未跳跃锁闭*/
				SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_NO);/*给ZC不锁闭*/

				if (AXIS_SECTION_JUMPLOCK_APPLY_NO == applyFlag)
				{/*当前未申请*/
					/*设置未征用*/
					SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_NO, 0);
					SetJumpPhySectionPortectSecUse(axisSectionId, PHYSICAL_SECTION_USING_NO);/*设置物理区段的防护道岔所在区段取消防护征用*/

					SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);/*设置计轴区段跳跃锁闭状态为空闲*/
				}
				else
				{
					/*有申请则继续锁闭*/
				}
			}
			else
			{/*维持之前*/
			}
		}
	}
	else
	{/*之前处于锁闭，当持续检查锁闭条件不满足时，内部维持跳跃锁闭，给ZC发不锁闭*/
		SetPhySecJumpLockStateToZC(phyId, PHYSICAL_SECTION_JUMP_LOCK_NO);

		chPhySecJmpState = GetPhySecJumpLockState(phyId);
		if (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhySecJmpState)
		{/*未锁闭就一定有征用*/
			/*设置未征用*/
			SetPhySecUseState(phyId, PHYSICAL_SECTION_USING_NO, 0);
			SetJumpPhySectionPortectSecUse(axisSectionId, PHYSICAL_SECTION_USING_NO);/*设置物理区段的防护道岔所在区段取消防护征用*/
			SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);/*设置计轴区段跳跃锁闭状态为空闲*/
		}

	}
	if ((AXIS_SECTION_JUMPLOCK_APPLY_NO == applyFlag) &&
		(AXSEC_CANCEL_JUMPLOCK_APPLY_YES == cancelApplyFlag))
	{/*有取消跳跃申请*/
		SetAxisJumpLockState(axisSectionId, AXIS_SECTION_JUMPLOCK_STATE_IDLE);
		SetAxisRelProSwitchLockSta(axisSectionId, SWITCH_LOCK_PROTECT_CANCEL);
	}

}

