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


#include "InterlockLogicCheck.h"
#include "../System/CiSystemDefine.h"
#include "../ERROR/ErrorDefine.h"
#include "RouteConfigDataManage.h"
#include "InterlockLogicManage.h"
#include "AxisSort.h"
#include "AxisSort_api.h"
#include "EnvelopeManageAPI.h"
#include "LogicalRouteLogicCheck.h"
#include "../Garagedoor/GaragedoorDataManage.h"
#include "../EnvelopeManage/ELMDataPrepare.h"

/*
* 功能描述： 信号机关联检查: 进路开放的信号状态不能高于指定的信号机状态。
*			 关联信号机显示为引导信号，则进路开放信号不能高于引导。
*			 关联信号机为调车信号机，则进路开放信号机只能为调车信号。
*			 列车信号机-引导或列车(0xbb),列车信号机-列车信号(非引导)(0x55)
* 参数说明： UINT16 const routeId 进路ID
*            UINT16 const relationSignalId 信号机ID
*			 UINT8 const devStatus		设备检查状态
* 返回值  ： 0   失败
*			 >0  设备状态
*/
static UINT8 CheckRelationSignalOnSameOpen(UINT16 const routeId, UINT16 const relationSignalId, UINT8 const devStatus);

/*
* 功能描述： 其他联锁条件检查
* 参数说明： UINT16 routeId 进路ID
* 返回值  ：
CI_ERROR:失败
CI_SUCCESS:成功
CI_ROUTE_RECOVER_ERR:失败，但是当条件满足时可以重开信号
*/
static UINT8 OtherCiValidErrCheck(UINT16 const routeId);
/*
* 功能描述： 进路信号机封锁状态检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteSignalFLockCheck(UINT16 const routeId, UINT16 *pDevId,UINT8 *pDevState)
{
	UINT8 routeInitFsState = 0u;
	/* 封锁信号机 */
    UINT8 const checkSum = GetRouteFengSuoSignalSum(routeId);
    UINT16* const dataIdBuf = GetRouteFengSuoSignalIdBuf(routeId);

	/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 sigBelongCi = 0u;/*信号机所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportState = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	routeInitFsState = GetRouteInitFSStatus(routeId);

	if (ROUTE_INIT_NOT_FS == routeInitFsState)
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
		*pDevState = SIGNAL_FENGSUO_YES;
	}

	if (CI_SUCCESS == reVal)
	{
		/* 检查封锁状态 */
		if(NULL != dataIdBuf)
		{
			if(0u != checkSum)
			{
				/*开始检查*/
				for (i = 0u; i < checkSum; i++)
				{
					devId = dataIdBuf[i];
					devState = GetSignalFLockState(devId);

					sigBelongCi = GetSignalBelongCiId(devId);/*获取信号机所属联锁*/
					commState = GetLocalCiAndOtherCiTransSta(sigBelongCi);/*本联锁与其它联锁通信通信状态*/

					if ((localCi !=sigBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
						(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag) &&
						(FUNC_SWITCH_ON == funcSwitchSupportState))
					{

						/*如果信号机所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则可以不检查该信号机封锁状态*/
						reVal = CI_SUCCESS;
					}
					else
					{
						if (SIGNAL_FENGSUO_NO == devState)
						{
							/* 通过检查*/
							reVal = CI_SUCCESS;
						}
						else
						{
							/*状态不一致返回故障状态*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
							break;
						}
					}
				}
			}
			else
			{
				/*无可封锁信号机*/
				/*无可封锁信号机则不检查,并判定信号机封锁状态检查通过*/
				reVal = CI_SUCCESS;
			}
		}
		else
		{
			/*数据错误*/
			reVal = CI_ERROR;
		}
	}

	

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 进路敌对条件无效检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   满足敌对
*            CI_SUCCESS 不满足敌对
*/
UINT8 RouteSignalEnemyVainCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 敌对进路 */
    UINT8 const checkSum = GetRouteEnemySignalSum(routeId);
    RouteEnemySignalStruct* const dataIdBuf = GetRouteEnemySignalData(routeId);

/* 局部变量定义初始化 */
    UINT16 i = 0u,j = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 enemySwitchSum = 0u;
    RouteConditionSwitchStruct* enemySwitchConStru = NULL;
    UINT16 enemySwitchId = 0u;
    UINT8 enemySwitchPos = 0u;

    UINT8 enemySwitchPosValid = CI_ERROR;
	UINT8 reVal = CI_ERROR;
	UINT8 localCiID = GetSystemParaLocalCiId();
	UINT8 sigBelongCiId = 0u;
	UINT8 commNeiborCiState = 0u;
	UINT8 signalCurColor = 0u;
	UINT8 routeInitEnemyState = 0u;/*进路初始敌对*/

	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	routeInitEnemyState = GetRouteInitEnemyStatus(routeId);/*获取进路初始化敌对*/

	/*指针防空*/
    if (NULL == dataIdBuf)
    {
        reVal = CI_ERROR;
    }
	else
	{
		reVal = CI_SUCCESS;
	}
    
	if (CI_SUCCESS == reVal)
	{
		if(ROUTE_INIT_NOT_ENEMY == routeInitEnemyState)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reVal)
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SignalId;
			signalCurColor = GetSignalCurColor(devId);
			devState = GetSignalOpenCloseState(signalCurColor);

			/* 检查敌对信号是否开放*/
			if (SIGNAL_OPEN == devState)
			{
				/*敌对信号开放*/
				enemySwitchSum = dataIdBuf[i].SwitchSum;
				if (0u < enemySwitchSum)
				{
					/*敌对道岔位置检查*/
					enemySwitchPosValid = CI_ERROR;
					for (j = 0u; j<enemySwitchSum; j++)
					{
						enemySwitchConStru = &dataIdBuf[i].ConditionSwitchStru[j];
						enemySwitchId = enemySwitchConStru->SwitchId;
						enemySwitchPos = GetSwitchCurPosition(enemySwitchId);

                        if (enemySwitchPos == enemySwitchConStru->SwitchPosition)
                        {
                            enemySwitchPosValid = CI_ERROR;
                        }
                        else
                        {
                            /*道岔未敌对*/
                            enemySwitchPosValid = CI_SUCCESS;
                            break;
                        }
					}

					if (CI_ERROR == enemySwitchPosValid)
					{
						/*有岔敌对条件成立*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}
					else
					{/*有岔敌对条件不成立*/
						reVal = CI_SUCCESS;
					}
				}
				else
				{
					/*无岔敌对条件成立*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{/*敌对信号未开放*/
				sigBelongCiId = GetSignalBelongCiId(devId);/*获取敌对信号所属联锁ID*/

				if (localCiID != sigBelongCiId)
				{/*不属于本联锁的信号机*/
					/*更新与CI通信状态*/
					(void)UpdateCiTransmitState(localCiID, CI_SYSTEM_TYPE_CI, sigBelongCiId);
					commNeiborCiState = GetCiTransmitState(CI_SYSTEM_TYPE_CI,sigBelongCiId);

					if (TRANSMIT_STATE_GOOD != commNeiborCiState)
					{/*与相邻联锁通信中断，认为敌对条件成立*/
						if ((CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
							(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
						{
							/*如果当前线路支持继电接口，且继电接口已确认，则不需要检查相邻联锁信号机的敌对*/
						}
						else
						{
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
						
					}
					else
					{/*与相邻联锁通信良好且未敌对信号未开放，则敌对条件不成立*/
						reVal = CI_SUCCESS;
					}
				}
				else
				{/*敌对信号属于本联锁，未开放则敌对不成立*/
					reVal = CI_SUCCESS;
				}
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
		}
    }
    /* 未检测到敌对条件 */
    return reVal;
}


/*
* 功能描述： 反向进路敌对条件无效检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   满足敌对
*            CI_SUCCESS 不满足敌对
*/
UINT8 ReverseRouteSigEnemyVainCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 敌对进路 */
    UINT8 const checkSum = GetRouteEnemySignalSum(routeId);                        /*获取敌对信号机数量*/
    RouteEnemySignalStruct* const dataIdBuf = GetRouteEnemySignalData(routeId);    /*获取敌对信号机结构体数组*/

/* 局部变量定义初始化 */
    UINT16 i = 0u,j = 0u,k = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	
    UINT8 enemySwitchSum = 0u;                               /*敌对道岔数目*/
    RouteConditionSwitchStruct* enemySwitchConStru = NULL;  /*条件道岔结构体数组*/
    UINT16 enemySwitchId = 0u;                               /*敌对道岔ID*/
    UINT8 enemySwitchPos = 0u;                               /*对对道岔位置*/
    UINT8 chRevrsRouteHasAutoSigRouteSum = 0u;           /*反向进路包含自动信号进路数目*/
    UINT16 * reverseRouteAutoSigRouteBuf = NULL;     /*反向进路包含自动信号进路Id数组*/
	UINT16 startSignalId = 0u;                               /*进路始端信号机*/
    UINT8 enemySwitchPosValid = CI_ERROR;                   /*敌对道岔位置*/
	
	UINT8 retVal = CI_ERROR;                              /*函数返回值*/
	UINT8 localCiID = GetSystemParaLocalCiId();
	UINT8 sigBelongCiId = 0u;
	UINT8 commNeiborCiState = 0u;

	UINT8 routeInitEnemyState = 0u;/*进路初始敌对*/
	
    chRevrsRouteHasAutoSigRouteSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含自动信号进路数目*/
	reverseRouteAutoSigRouteBuf = GetReverseRouteIncludeRouteBuf(routeId);/*获取反向进路包含自动信号进路ID数组*/

	routeInitEnemyState = GetRouteInitEnemyStatus(routeId);/*获取进路初始化敌对*/

/* 检查敌对状态 */
    if (NULL == dataIdBuf)
    {
        /*无检查项:返回成功*/
        retVal = CI_ERROR;
    }
	else
	{
		retVal =CI_SUCCESS;
	}
	
	if (CI_SUCCESS == retVal)
	{
		if(ROUTE_INIT_ENEMY == routeInitEnemyState)
		{
			retVal = CI_ERROR;
		}
	}
	
	if (CI_SUCCESS == retVal)
	{
		for (i = 0u; i<checkSum; i++)
		{/*遍历所有敌对信号机*/
		
			devId = dataIdBuf[i].SignalId;  
			for(k = 0u ;k < chRevrsRouteHasAutoSigRouteSum ;k++)
			{/*遍历反向进路包含的所有自动信号进路*/
				startSignalId = GetRouteStartSignalId(reverseRouteAutoSigRouteBuf[k]);/*自动信号进路的始端自动信号机ID*/
				if(devId  == startSignalId)
				{/*此敌对信号机是反向进路包含的自动信号机，“办理检查阶段”不检查*/
					retVal = CI_SUCCESS;
					break;
				}
				
			}

			if(chRevrsRouteHasAutoSigRouteSum == k)
			{/*若此敌对信号不是反向进路包含的自动信号机，则"办理检查阶段"才需检查*/
				devState = GetSignalOpenCloseState(GetSignalCurColor(devId));
				/* 检查敌对信号是否开放*/
				if (devState == SIGNAL_OPEN)
				{
					/*敌对信号开放*/
					enemySwitchSum = dataIdBuf[i].SwitchSum;
					if (enemySwitchSum > 0u)
					{
						/*敌对道岔位置检查*/
						enemySwitchPosValid = CI_ERROR;
						for (j = 0u; j<enemySwitchSum; j++)
						{
							enemySwitchConStru = &dataIdBuf[i].ConditionSwitchStru[j];
							enemySwitchId = enemySwitchConStru->SwitchId;
							enemySwitchPos = GetSwitchCurPosition(enemySwitchId);

                            if (enemySwitchPos == enemySwitchConStru->SwitchPosition)
                            {
                                enemySwitchPosValid = CI_ERROR;
                            }
                            else
                            {
                                /*道岔未敌对*/
                                enemySwitchPosValid = CI_SUCCESS;
                                break;

                            }
						}

						if (enemySwitchPosValid == CI_ERROR)
						{
							/*该组敌对道岔全部满足敌对，敌对条件才成立*/
							*pDevId = devId;
							*pDevState = devState;
							retVal = CI_ERROR;
						}
						else
						{
							/*该组敌对道岔不是全部满足敌对，敌对条件不成立*/
							retVal = CI_SUCCESS;
						}
					}
					else
					{
						/*该组无岔敌对全部满足敌对，敌对条件才成立*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
					}
				}
				else
				{
					/*敌对信号未开放*/
					sigBelongCiId = GetSignalBelongCiId(devId);/*获取敌对信号所属联锁ID*/

					if (localCiID != sigBelongCiId)
					{/*不属于本联锁的信号机*/
						/*更新与CI通信状态*/
						(void)UpdateCiTransmitState(localCiID, CI_SYSTEM_TYPE_CI, sigBelongCiId);
						commNeiborCiState = GetCiTransmitState(CI_SYSTEM_TYPE_CI,sigBelongCiId);

						if (TRANSMIT_STATE_GOOD != commNeiborCiState)
						{/*与相邻联锁通信中断，认为敌对条件成立*/
							*pDevId = devId;
							*pDevState = devState;
							retVal = CI_ERROR;
						}
						else
						{/*与相邻联锁通信良好且未敌对信号未开放，则敌对条件不成立*/
							retVal = CI_SUCCESS;
						}
					}
					else
					{/*敌对信号属于本联锁，未开放则敌对不成立*/
						retVal = CI_SUCCESS;
					}

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

    return retVal;
}


/*
* 功能描述： 进路照查物理区段条件满足检查
* 参数说明： UINT16 const checkRouteId   检查进路段号
*            UINT16 const zcPhySecId  照查物理区段号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RoutePhySecZhaoChaCheck(UINT16 const checkRouteId ,UINT16 const zcPhySecId,UINT16 *pDevId,UINT8 *pDevState )
{
	UINT8 secFlockState = 0u;                         /*区段封锁状态*/
	UINT8 secLockState = 0u;                          /*区段锁闭状态*/
	UINT8 secLockedDirection = 0u;                    /*区段锁闭方向*/
	UINT8 routeDirection = 0u;                        /*进路方向*/
	UINT8 retVal = CI_ERROR;                       /*函数返回值*/

	UINT8 phyBelongCi = 0u;/*物理区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	UINT16 zcPhyLockBelongRouteId = 0u;
	UINT8 haveDirChangeInLockRoute = 0u;/*进路存在方向变化点*/
	UINT8 lockRouteZcPhyOppose = 0u;
	UINT8 haveDirChangeInCheckRoute = 0u;
	UINT8 checkRouteZcPhyOppose = 0u;
	UINT8 haveDirChangeAfterLockRoute = 0u;
	UINT16 phyPLockBelongRouteId = 0u;

	phyBelongCi = GetPhySecBelongCiId(zcPhySecId);/*获取物理区段所属联锁*/

    routeDirection = GetRouteDirection(checkRouteId);     /*获取进路方向*/

	if ((NULL == pDevId ) || (NULL == pDevState))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;

		commState = GetLocalCiAndOtherCiTransSta(phyBelongCi);/*本联锁与其它联锁通信通信状态*/

		if ((localCi !=phyBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
			(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
			(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
		{
			/*如果信号机所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
				且已配置支持继电接口，则可以不检查该信号机封锁状态*/
			retVal = CI_SUCCESS;
		}
		else
		{ 
			secFlockState = GetPhySecFLockState(zcPhySecId);    /*获取物理区段封锁状态*/
			if(PHYSICAL_SECTION_FLOCK_NO == secFlockState)
			{/*区段封锁状态:未封锁*/ 

				secLockState = GetPhySecLockState(zcPhySecId);  /*获取物理区段锁闭状态*/

				if(PHYSICAL_SECTION_LOCK_NO == secLockState)
				{
					/*区段锁闭状态:未锁闭  本照查区段检查通过*/
				}
				else if((PHYSICAL_SECTION_LOCK_PROTECT  == secLockState)   || (PHYSICAL_SECTION_LOCK_NORMAL == secLockState) 
					|| (PHYSICAL_SECTION_LOCK_EXCEPT == secLockState)     || (PHYSICAL_SECTION_LOCK_DELAY == secLockState) 
					|| (PHYSICAL_SECTION_LOCK_FAULTDELAY == secLockState))
				{/*区段锁闭状态:防护锁闭 或 正常锁闭 或 异常锁闭 或 延时解锁 或 故障延时解锁，解决进路在延时解锁时照查指示灯突然亮灯的情况*/
					
					zcPhyLockBelongRouteId =  GetPhySecRLockBelongRouteId(zcPhySecId);/*获取照查区段锁闭所属进路ID*/
					haveDirChangeInLockRoute = GetRouteHaveDirChangePointIn(zcPhyLockBelongRouteId); /*锁闭进路存在方向变化点*/
					lockRouteZcPhyOppose = GetRoutePhySecShouldLockOppose(zcPhyLockBelongRouteId,zcPhySecId);/*是否应该取反*/
					

					/*传入检查进路方向变化点获取*/
					haveDirChangeInCheckRoute = GetRouteHaveDirChangePointIn(checkRouteId);
					checkRouteZcPhyOppose = GetRoutePhySecShouldLockOppose(checkRouteId,zcPhySecId);/*是否应该取反*/

					/*防护锁闭*/
					if(PHYSICAL_SECTION_LOCK_PROTECT  == secLockState)
					{
						/*防护锁闭所属进路*/
						phyPLockBelongRouteId = GetPhySecPLockBelongRouteId(zcPhySecId);
						/*进路后存在方向变化点*/
					    haveDirChangeAfterLockRoute = GetRouteHaveDirChangePointAfter(phyPLockBelongRouteId);
					}

					secLockedDirection = GetPhySecLockDirection(zcPhySecId); /*获取锁闭方向*/
					debug_infor_printf((const)"\n RoutePhySecZhaoChaCheck Route%d -ZCPhyRouteDirChange:%d--haveDirChangeInCheckRoute:%d .-ZcPhyOppose%d_checkRouteZcPhyOppose:%d  \n", checkRouteId, haveDirChangeInLockRoute, haveDirChangeInCheckRoute, lockRouteZcPhyOppose, checkRouteZcPhyOppose);
					/*本进路不检查:其他锁闭、防护锁闭本进路都不查*/
					if(((PHYSICAL_SECTION_LOCK_PROTECT != secLockState) && (zcPhyLockBelongRouteId != checkRouteId)) 
						|| ((PHYSICAL_SECTION_LOCK_PROTECT == secLockState) && (phyPLockBelongRouteId != checkRouteId)))
					{
						/*1.区段锁闭所属进路存在方向变化点且区段应该取反，且检查进路无方向变化点；2、锁闭进路无方向变化点，且区段属于非锁闭进路的照查区段且属于应该取反区段，将锁闭取反；
						3、防护锁闭，防护锁闭所属进路后存在方向变化点，锁闭取反*/
						if (((ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeInLockRoute) && (ROUTE_PHYSEC_SHOULD_OPPOSE_LOCK == lockRouteZcPhyOppose) && (ROUTE_HAVE_DIR_CHANGE_POINT != haveDirChangeInCheckRoute))
							|| ((ROUTE_HAVE_DIR_CHANGE_POINT != haveDirChangeInLockRoute) && (ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeInCheckRoute) && (ROUTE_PHYSEC_SHOULD_OPPOSE_LOCK == checkRouteZcPhyOppose))
							|| ((PHYSICAL_SECTION_LOCK_PROTECT  == secLockState) && (ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeAfterLockRoute)))
						{

							if(CI_SYSTEM_DIRECTION_UP == secLockedDirection)
							{
								secLockedDirection = CI_SYSTEM_DIRECTION_DOWN;
							}
							else if(CI_SYSTEM_DIRECTION_DOWN == secLockedDirection)
							{
								secLockedDirection = CI_SYSTEM_DIRECTION_UP;
							}
							else
							{
								/*不做处理*/
							}
						}
						else
						{
						}
						if(routeDirection == secLockedDirection)
						{
							/*锁闭方向和进路方向一致，通过检查*/
						}
						else
						{
							/*锁闭方向和进路方向不一致，检查失败*/
							retVal = CI_ERROR;
							*pDevId = zcPhySecId;
							*pDevState = secLockState;
						}
					}
					else 
					{
						/*不做处理*/
					}
				}
				else
				{   /*区段锁闭状态:非法锁闭状态 检查失败*/
					retVal = CI_ERROR;
					*pDevId = zcPhySecId;
					*pDevState = secLockState;
				}
			}
			else
			{/*区段封锁状态:封锁  检查失败*/
				retVal = CI_ERROR;
				*pDevId = zcPhySecId;
				*pDevState = secFlockState;
			}
		}
		
	}
	

	return retVal;
}

/*
* 功能描述： 进路照查条件满足检查
* 参数说明： UINT16 const routeId,  进路号
*            UINT8 functionId,      调用函数编号
*            UINT8 sendLevel,       故障码发送级别
* 返回值  ： CI_ERROR               失败
*            CI_SUCCESS             成功
*			 RELAY_STATE_WAITE      进路初锁本端照查继电器条件不满足--等待
*			 RES_CHECK_STATE_WAITE  资源检查本端照查继电器条件不满足--等待
*/
UINT8 RouteRelayZhaoChaCheck(UINT16 const routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT16 relayId = 0u;
	UINT8 relayState = 0u;
	UINT8 zcPhySecSum = 0u;                          /*照查物理区段数目*/
	UINT16* pZcPhySecIdBuf = NULL;                   /*照查物理区段ID数组*/
	UINT8 ii = 0u;
	UINT16 thisRealyId = 0u;
	UINT8 thisRelayState = 0u;
	UINT8 routeState = 0u;
	UINT8 retVal = CI_ERROR;                      /*函数返回值*/
	UINT16 pDevId = 0u;
	UINT8 pDevState = 0u;
	UINT8 funcSwitchSupportRelayInterface = 0u;
	UINT8 confirmRelayInterfaceFlag = 0u;
	UINT16 endSignalId = 0u;
	UINT8 commState = 0u;/*通信状态*/
	UINT8 endSignalBelongCi = 0u;
	UINT8 localCi = 0u;

	localCi = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	/* 对端照查检查 */
	zcPhySecSum = GetRouteThatZhaoChaPhySecSum(routeId);              /*获取照查物理区段数目*/
	pZcPhySecIdBuf = GetRouteThatZhaoChaPhySecIdBuf(routeId);       /*获取照查物理区段ID数组*/

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

	funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	if (endSignalBelongCi != localCi)
	{
		/*获取通信状态*/
		commState = GetLocalCiAndOtherCiTransSta(endSignalBelongCi);
	}

	/*继电接口确认*/
	if ((localCi != endSignalBelongCi) && (TRANSMIT_STATE_BAD == commState)
		&& (CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)
		&& (FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
	{
		/*获取继电接口本端照查ID*/
		thisRealyId = GetRouteRelayBenDuanZcIdOnRelay(routeId);
		/*获取继电接口对端照查ID*/
		relayId = GetRouteRelayDuiDuanZcIdOnRelay(routeId);
	}
	else
	{
		thisRealyId = GetRouteThisZhaoChaRelayId(routeId); /*本端照查继电器ID*/
		relayId = GetRouteThatZhaoChaRelayId(routeId); /*对端照查继电器ID*/
	}

	if (NULL == pZcPhySecIdBuf)
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;

		for (ii = 0u; ii < zcPhySecSum; ii++)
		{
			retVal = RoutePhySecZhaoChaCheck(routeId, pZcPhySecIdBuf[ii], &pDevId, &pDevState);
			if (CI_ERROR == retVal)
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, pDevId, ETYPE_PS_ZHAOCHA_CHECK, pDevState, sendLevel);
				break;
			}

		}
	}

	if (CI_SUCCESS == retVal)
	{/*照查物理区段检查通过,检查本端照查继电器*/

		routeState = GetRouteState(routeId);               /*获取进路状态*/
		if (thisRealyId > 0u)
		{/*存在本端照查继电器*/
			thisRelayState = GetRelayCollState(thisRealyId);   /*获取指定ID继电器的状态*/
			if ((ROUTE_STATE_FIRST_LOCKERR == routeState) ||
				(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
				(ROUTE_STATE_YUXIAN_OPEN == routeState) ||			
				(ROUTE_STATE_NEAR_OPEN == routeState) ||
				(ROUTE_STATE_NEAR_LOCK == routeState) ||
				(ROUTE_STATE_NEAR_LOCKERR == routeState) ||
				(ROUTE_STATE_DELAY_UNLOCK == routeState) || 
				(ROUTE_STATE_AUTO_UNLOCK == routeState) || 
				(ROUTE_STATE_AUTO_UNLOCKERR == routeState) || 
				(ROUTE_STATE_HALF_UNLOCKDELAY == routeState) ||
				(ROUTE_STATE_LEAD_LOCKERR == routeState) ||
				(ROUTE_STATE_LEAD_OPEN == routeState))
			{
				/*需判断本端照查的状态*/
				if (RELAY_STATE_UP == thisRelayState)
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, thisRealyId, ETYPE_THIS_ZHAOCHA, RELAY_STATE_UP, sendLevel);
					retVal = CI_ERROR;
				}
			}
			else if (ROUTE_STATE_HALF_UNLOCK == routeState)
			{
				/*考虑优化容忍时间
				部分进路办理后列车申请资源时本端照查继电器未完成驱动*/
				retVal = KeepSignalRelayZhaoChaCheck(routeId);
				if (CI_ERROR == retVal)
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, thisRealyId, ETYPE_THIS_ZHAOCHA, RELAY_STATE_UP, sendLevel);

				}
			}
			else if ((ROUTE_STATE_FIRST_LOCK == routeState) || 
				(ROUTE_STATE_LEAD_LOCK == routeState))
			{
				if (RELAY_STATE_UP == thisRelayState)
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, thisRealyId, ETYPE_THIS_ZHAOCHA, RELAY_STATE_UP, ESEND_LEVEL_ZERO);
					/*等待，返回等待标志*/
					retVal = RELAY_STATE_WAITE;
				}

			}
			else
			{
				/*进路状态为其它值，此时不处理*/
			}
		}

	}


	if ((CI_SUCCESS == retVal) || (RELAY_STATE_WAITE == retVal) || (RES_CHECK_STATE_WAITE == retVal))
	{/*本端照查继电器检查通过/等待，检查对端照查继电器*/
		if (0u != relayId)
		{/*存在对端照查继电器*/

			relayState = GetRelayCollState(relayId);

			/* 照查吸起检查*/
			if (RELAY_STATE_UP == relayState)
			{
				/*检查通过*/
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, relayId, ETYPE_THAT_ZHAOCHA, relayState, sendLevel);

				retVal = CI_ERROR;
			}
		}
	}

	return retVal;
}


/*
* 功能描述： 进路区段全部空闲检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteAllSecOccuClearCheck(UINT16 const routeId, UINT16 *pDevId,UINT8 *pDevState )
{
/* 进路区段*/
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

/* 区段占用检查 */
    if (0u == checkSum) 
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecCurMergeState(devId);

			if (SECTION_OCCUPY_NO==devState)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }
    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： 进路内逻辑区段和进路道岔关联逻辑区段全部空闲检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221007 适配进路提前驱动道岔功能
*/
UINT8 RouteAllLogSecOccuClearCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路内逻辑区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf = GetRouteLogSectionIdBuf(routeId);

	/* 进路道岔关联的非进路内的逻辑区段*/
	UINT16 const checkOtherSum = GetRouteSwitOtherLogSecSum(routeId);
	UINT16* const dataOtherIdBuf = GetRouteSwitOtherPosLogSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 j = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 进路内逻辑区段占用检查 */
	if ((0u == checkSum) || (NULL == dataIdBuf))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetLogSecCurOccupyState(devId);

			if (SECTION_OCCUPY_NO == devState)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*检查进路内道岔关联的非进路内逻辑区段占用状态*/
	if (CI_SUCCESS == reVal)
	{
		if(NULL == dataOtherIdBuf)
		{
			/*区段数据错误*/
			reVal = CI_ERROR;
		}
		else if (checkOtherSum == 0u)
		{
			/*进路不包含道岔，返回成功*/
			reVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查*/
			for (j = 0u; j<checkOtherSum; j++)
			{
				devId = dataOtherIdBuf[j];
				devState = GetLogSecCurOccupyState(devId);

				if (SECTION_OCCUPY_NO == devState)
				{
					/* 通过检查*/
				}
				else
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
					break;
				}
			}
		}
	}
	else
	{
		reVal = CI_ERROR;
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 点式进路逻辑区段锁闭有效性检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221007 适配进路提前驱动道岔功能
*/
UINT8 BlockRouteLogSecLockValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路内逻辑区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf = GetRouteLogSectionIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 secLockDirection = 0u;
	UINT8 ciType = 0u;
	UINT8 cLocalCiId = 0U;
	UINT8 const routeDirDirection = GetRouteDirection(routeId);
	UINT8 reVal = CI_ERROR;
	UINT8 phyArbState = 0u;
	UINT16 phySecId = 0u;          /* 物理区段ID */

	cLocalCiId = GetSystemParaLocalCiId();
	ciType = GetCiType(cLocalCiId); 

	/*检查进路内逻辑区段锁闭状态*/
	if ((0u == checkSum) || (NULL == dataIdBuf))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetLogSecLockState(devId);
			secLockDirection = GetLogSecLockDir(devId);
			phySecId = GetLgcSecRelativePhySecId(devId);

			if (LOG_SECTION_LOCK_NO == devState)
			{
				/* 未锁闭 */
			}
			else if (LOG_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/

				if (secLockDirection != routeDirDirection)
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else if (LOG_SECTION_LOCK_NORMAL == devState)
			{
				if ((ROUTE_STOPCHECK_SET_YES == GetRouteStopCheckFlag(routeId)) &&
					(PHYSICAL_SECTION_LJK_YES == GetPhySecLjkFlag(phySecId)) &&
					(PHYSICAL_STOPCHECK_SET_YES == GetPhySectionStopCheckFlag(phySecId)) &&
					(secLockDirection == routeDirDirection))
				{
					/*区段锁闭状态为正常锁闭，停止检查有效且为列检库区段，且物理区段停止检查有效
					该情景为：上个进路为列车进路最后一个区段无法解锁且列车故障，此时需办理调车进路将故障列车调出去
					物理区段锁闭方向与进路方向一致*/

				}
				else
				{
					/*状态无效故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else if (LOG_SECTION_LOCK_EXCEPT == devState)
			{
				if (CI_TYPE_CLD == ciType)
				{
					/*获取ARB状态*/
					phyArbState = GetPhySecArbState(phySecId);
					/*区段ARB状态，且锁闭方向一致*/
					if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirDirection))
					{
						/*不做处理*/
					}
					else
					{
						/*返回失败*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}
				}
				else
				{
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{
				/*状态无效故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}

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

	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 点式进路区段锁闭有效性检查
* 参数说明： 
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 BlockRouteSecLockValidCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路区段*/
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
    UINT8 i = 0U;           /* 循环变量 */
	UINT8 j = 0U;
    UINT16 devId = 0U;
    UINT8  devState = 0U;
    UINT8 secLockDirection = 0U;  /*区段锁闭状态*/
	UINT8 ciType = 0U;
	UINT8 cLocalCiId = 0U;
    UINT8 const routeDirDirection = GetRouteDirection(routeId);
	UINT8 reVal = CI_ERROR;
	UINT8 phyArbState = 0U;
	UINT16 phySecId = 0U;
	UINT8 cPhySecIncLogSecNum = 0U;  /*物理区段包含的逻辑区段数量*/
	UINT16* pPhySecIncLogSecId = NULL;  /*物理区段包含的逻辑区段ID*/

	cLocalCiId = GetSystemParaLocalCiId();
	ciType = GetCiType(cLocalCiId);

    if ((0U != checkSum) && (NULL != dataIdBuf) && (NULL != pDevId) && (NULL != pDevState))
    {
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0U; i < checkSum; i++)
		{
			cPhySecIncLogSecNum = GetPhySecIncLogSecSum(dataIdBuf[i].PhysicalSectionId); 
			pPhySecIncLogSecId = GetPhySecIncLogSecIdBuf(dataIdBuf[i].PhysicalSectionId);

			if ((0U != cPhySecIncLogSecNum) && (NULL != pPhySecIncLogSecId))
			{
				/*检查物理区段包含的所有逻辑区段锁闭状态是否合法*/
				for (j = 0u; j < cPhySecIncLogSecNum; j++)
				{
					devId = pPhySecIncLogSecId[j];
					devState = GetLogSecLockState(devId);
					secLockDirection = GetLogSecLockDir(devId);
					phySecId = GetLgcSecRelativePhySecId(devId);

					if (LOG_SECTION_LOCK_NO == devState)
					{
						/* 未锁闭，检查通过 */
					}
					else if (LOG_SECTION_LOCK_PROTECT == devState)
					{
						/*防护锁闭*/
						if (secLockDirection != routeDirDirection)
						{
							/*方向不一致，返回0失败*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
					}
					else if (LOG_SECTION_LOCK_NORMAL == devState)
					{
						if ((ROUTE_STOPCHECK_SET_YES == GetRouteStopCheckFlag(routeId)) &&
							(PHYSICAL_SECTION_LJK_YES == GetPhySecLjkFlag(phySecId)) &&
							(PHYSICAL_STOPCHECK_SET_YES == GetPhySectionStopCheckFlag(phySecId)) &&
							(secLockDirection == routeDirDirection))
						{
							/*区段锁闭状态为正常锁闭，停止检查有效且为列检库区段，且物理区段停止检查有效
							该情景为：上个进路为列车进路最后一个区段无法解锁且列车故障，此时需办理调车进路将故障列车调出去
							物理区段锁闭方向与进路方向一致*/
						}
						else
						{
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;  /*返回0失败*/
						}
					}
					else if (LOG_SECTION_LOCK_EXCEPT == devState)
					{
						if (CI_TYPE_CLD == ciType)
						{
							/*获取ARB状态*/
							phyArbState = GetPhySecArbState(phySecId);
							/*区段ARB状态，且锁闭方向一致*/
							if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirDirection))
							{
								/*不做处理*/
							}
							else
							{
								/*返回失败*/
								*pDevId = devId;
								*pDevState = devState;
								reVal = CI_ERROR;
							}
						}
						else
						{
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
					}
					else
					{
						/*状态无效故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}

					if (CI_ERROR == reVal)
					{
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				reVal = CI_ERROR;  /*获取物理区段包含的逻辑区段失败，返回0失败*/
			}

			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
				/*继续检查*/
			}
		}		
    }
	else
	{
		reVal = CI_ERROR;
	}

    return reVal;
}


/*
* 功能描述： 调车进路区段锁闭有效性检查
* 参数说明： 
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 DTrainRouteSecLockValidCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路区段*/
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
    
/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
	UINT16 jj = 0u;		/* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 secProtectDirection = 0u;
    UINT8 const routeDirDirection = GetRouteDirection(routeId);
	UINT8 physwitchtype = 0u;
	UINT16 preLockedRouteID = 0u;/*之前被锁闭的进路ID*/
	UINT8 prePhySecSum = 0u;/*物理区段数量*/
	RoutePhysicalSectionStruct* pPrePhysecData = NULL;/*物理区段数据*/
	UINT16 tmpRLockedRouteID = 0u;
	UINT8 flagCheck = CI_ERROR;
	UINT8 devCurMergeState = 0u;/*物理区段融合占用状态*/
	UINT8 reVal = CI_ERROR;

/* 区段锁闭检查 */
    if ((0u == checkSum) || (NULL == dataIdBuf))
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {   
		/*数据合法*/
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecLockState(devId);
			secProtectDirection = GetPhySecLockDirection(devId);

			if (PHYSICAL_SECTION_LOCK_NO == devState)
			{
				/* 未锁闭 */
			}
			else if (PHYSICAL_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/
				
				if (secProtectDirection != routeDirDirection)
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

			}
			else if (PHYSICAL_SECTION_LOCK_NORMAL == devState)
			{/*冲区段进路锁闭状态比较少见，此时，可以多加些打印*/
				/*获取区段是否无道岔*/
				physwitchtype = GetPhySecType(devId);
				/*最后一个物理区段锁闭且没有道岔*/
				if((i == (checkSum-1u)) && (PHYSICAL_SEC_TYPE_NOSWITCH == physwitchtype))
				{
					/*根据郑州3 需求修改调车进路逻辑*/
					devCurMergeState = GetPhySecCurMergeState(devId);
					preLockedRouteID = GetPhySecRLockBelongRouteId(devId);/*获取进路锁闭所属的进路ID*/
					if ((preLockedRouteID > 0u) && (SECTION_OCCUPY_YES == devCurMergeState))
					{/*物理区段是进路锁闭，且融合状态是占用的*/
						prePhySecSum = GetRoutePhysicalSectionSum(preLockedRouteID);/*获取进路物理区段数量*/
						pPrePhysecData = GetRouteSectionData(preLockedRouteID);/*获取进路物理区段数据*/
						if ((prePhySecSum > 0u) && (NULL != pPrePhysecData))
						{/*区段数据正常*/
							flagCheck = CI_SUCCESS;
							if (prePhySecSum > 1u)
							{/*多于1个区段，对除最后一个区段之外其他区段，进行未锁闭检查*/
								for (jj=0u;jj<(prePhySecSum - 1u);jj++)
								{
									tmpRLockedRouteID = GetPhySecRLockBelongRouteId(pPrePhysecData[jj].PhysicalSectionId);
									if ((0u == tmpRLockedRouteID) || (preLockedRouteID != tmpRLockedRouteID))
									{/*未进路锁闭:进路锁闭所属进路ID为0*/
										flagCheck = CI_SUCCESS;
									}
									else
									{
										flagCheck = CI_ERROR;
										break;
									}
								}
							}
							else
							{
								/*对于1个区段，只要占用且锁闭检查通过，就过了*/
							}

							if (CI_SUCCESS == flagCheck)
							{
								if (pPrePhysecData[prePhySecSum - 1u].PhysicalSectionId == devId)
								{/*是之前锁闭的进路的最后一个区段*/

								}
								else
								{
									flagCheck = CI_ERROR;
								}
							}


							if (CI_ERROR == flagCheck)
							{	
								*pDevId = devId;
								*pDevState = devState;
								reVal = CI_ERROR;
							}

						}
						else
						{
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
							debug_infor_printf((const)"Route %d ConfigData error.\n",preLockedRouteID);
						}
					}
					else
					{
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
						debug_infor_printf((const)"Section %d's routeID %d Data error,Occupy %d.\n",devId,preLockedRouteID,devCurMergeState);
					}
				}
				else
				{
					/*状态无效故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
            else
            {
                /*状态无效故障状态*/
                *pDevId = devId;
                *pDevState = devState;
                reVal = CI_ERROR;
				debug_infor_printf((const)"Section %d state %d: FaultLock or ? \n",devId,devState);
            }

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

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： 反向进路区段锁闭有效性检查
* 参数说明： 
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 ReverseRouteSecLockValidCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路区段*/
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);/*获取进路包含的物理区段数目*/
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);/*获取进路包含物理区段结构数组*/
    
/* 局部变量定义初始化 */
	UINT8 i = 0;
	UINT8 j = 0U;
    UINT16 devId = 0U;			   /*设备ID*/
    UINT8  devState = 0U;		   /*设备状态*/
    UINT8 secLockDirection = 0U; /*区段锁闭方向*/
	UINT8 chRevrsRouteHasAutoSigRouteSum = 0U;       /*反向进路包含自动信号进路数目*/
    UINT16 * reverseRouteAutoSigRouteBuf = NULL; /*反向进路包含自动信号进路Id数组*/
	UINT16 secLockBlongRouteId = 0U;                     /*区段锁闭所属进路Id*/
	UINT16 secPLockBlongRouteId = 0U;					/*区段防护锁闭所属进路Id*/
	UINT8 retVal = CI_ERROR;                          /*函数返回值*/
    UINT8 const routeDirDirection = GetRouteDirection(routeId); /*进路方向*/
	UINT8 cIndex = 0U;
	UINT8 cPhySecIncLogSecNum = 0U;  /*物理区段包含的逻辑区段数目*/
	UINT16* pPhySecIncLogSecId = NULL;  /*物理区段包含的逻辑区段ID数组*/
	UINT8 cRouteState = ROUTE_STATE_IDLE;
	UINT8 cRouteType = 0U;  /*进路类型*/

	chRevrsRouteHasAutoSigRouteSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含自动信号进路数目*/
	reverseRouteAutoSigRouteBuf = GetReverseRouteIncludeRouteBuf(routeId);/*获取反向进路包含自动信号进路ID数组*/

    if ((0U != checkSum) && (NULL != dataIdBuf) && (NULL != pDevId) && (NULL != pDevState))
    {
		retVal = CI_SUCCESS;
		for (i = 0U; i < checkSum; i++)
		{
			cPhySecIncLogSecNum = GetPhySecIncLogSecSum(dataIdBuf[i].PhysicalSectionId);
			pPhySecIncLogSecId = GetPhySecIncLogSecIdBuf(dataIdBuf[i].PhysicalSectionId);

			if ((0U != cPhySecIncLogSecNum) && (NULL != pPhySecIncLogSecId))
			{
				/*检查物理区段包含的逻辑区段锁闭状态是否合法*/
				for (cIndex = 0U; cIndex < cPhySecIncLogSecNum; cIndex++)
				{
					devId = pPhySecIncLogSecId[cIndex];/*获取逻辑区段ID*/
					devState = GetLogSecLockState(devId);/*获取逻辑区段锁闭状态*/
					secLockDirection = GetLogSecLockDir(devId);/*逻辑区段锁闭方向*/

					if (LOG_SECTION_LOCK_NO == devState)
					{
						/*未锁闭，检查通过*/
					}
					else if (LOG_SECTION_LOCK_PROTECT == devState)
					{
						if (secLockDirection == routeDirDirection)
						{
							/*防护锁闭方向一致：检查通过*/
						}
						else
						{
							/*防护锁闭方向不一致*/							
							if (0U == chRevrsRouteHasAutoSigRouteSum)
							{
								/*反向进路中不包含自动信号进路(即可得此区段不是被自动信号进路防护锁闭)，检查不通过*/
								*pDevId = devId;
								*pDevState = devState;
								retVal = CI_ERROR;
							}
							else
							{
								secPLockBlongRouteId = GetLogSecPLockRouteId(devId);  /*逻辑区段防护锁闭所属进路*/
								for (j = 0U; j < chRevrsRouteHasAutoSigRouteSum; j++)
								{
									/*遍历每条自动信号进路，检查反向进路中是否包含自动信号进路*/
									if (secPLockBlongRouteId == reverseRouteAutoSigRouteBuf[j])
									{
										break;  /*区段为自动信号进路防护锁闭，停止遍历*/
									}
								}

								if (j == chRevrsRouteHasAutoSigRouteSum)
								{
									/*区段不为任何自动信号进路防护锁闭，检查不通过*/
									*pDevId = devId;
									*pDevState = devState;
									retVal = CI_ERROR;
								}
							}
						}
					}
					else if (LOG_SECTION_LOCK_NORMAL == devState)
					{
						secLockBlongRouteId = GetLogSecLockBelongRoute(devId);  /*逻辑区段锁闭所属进路ID*/
						cRouteState = GetRouteState(secLockBlongRouteId);
						cRouteType = GetRouteType(routeId);  /*获取进路类型*/

						if ((ROUTE_STATE_HALF_UNLOCK == cRouteState) && (ROUTE_TYPE_LIECHE == cRouteType) && (secLockDirection == routeDirDirection))
						{
							/*逻辑区段锁闭所属进路当前为部分进路等待解锁状态且为列车进路，且区段锁闭方向与本进路方向相同，则检查通过*/
						}
						else
						{
							if (0U == chRevrsRouteHasAutoSigRouteSum)
							{
								/*反向进路中不包含自动信号进路(即可得此物理区段不是为自动信号进路锁闭)，检查不通过*/
								*pDevId = devId;
								*pDevState = devState;
								retVal = CI_ERROR;
							}
							else
							{
								/*反向进路中包含自动信号进路*/
								for (j = 0U; j < chRevrsRouteHasAutoSigRouteSum; j++)
								{
									/*遍历每条自动信号进路*/
									if (secLockBlongRouteId == reverseRouteAutoSigRouteBuf[j])
									{
										break;  /*区段为自动信号进路锁闭，停止遍历*/
									}
								}
								if (j == chRevrsRouteHasAutoSigRouteSum)
								{
									/*区段不为任何自动信号进路锁闭，检查不通过*/
									*pDevId = devId;
									*pDevState = devState;
									retVal = CI_ERROR;
								}
							}
						}
					}
					else
					{
						/*状态无效，返回失败*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
					}

					if (CI_ERROR == retVal)
					{
						break;
					}
				}
			}
			else
			{
				retVal = CI_ERROR;  /*获取物理区段包含的逻辑区段失败，返回0失败*/
			}

			if (CI_ERROR == retVal)
			{
				break;
			}
		}
    }
	else
	{		
		retVal = CI_ERROR;  /*获取进路包含的物理区段数据错误/入参非法，返回0失败*/
	}
    
    return retVal;
}

/*
* 功能描述： 反向进路逻辑区段锁闭有效性检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路提前驱动道岔功能
*/
UINT8 ReverseRouteLogSecLockValCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路内逻辑区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf = GetRouteLogSectionIdBuf(routeId);/* 局部变量定义初始化 */
	UINT16 i = 0u;            /* 循环变量 */
	UINT16 j = 0u;            /* 循环变量 */
	UINT16 devId = 0u;			   /*设备ID*/
	UINT8  devState = 0u;		   /*设备状态*/
	UINT8 secLockDirection = 0u; /*区段防护锁闭方向*/
	UINT8 chRevrsRouteHasAutoSigRouteSum = 0u;       /*反向进路包含自动信号进路数目*/
	UINT16 * reverseRouteAutoSigRouteBuf = NULL; /*反向进路包含自动信号进路Id数组*/
	UINT16 secLockBlongRouteId = 0u;                     /*区段锁闭所属进路Id*/
	UINT16 secPLockBlongRouteId = 0u;					/*区段防护锁闭所属进路Id*/
	UINT8 retVal = CI_SUCCESS;                          /*函数返回值*/
	UINT8 cRouteState = ROUTE_STATE_IDLE;  /*进路状态*/
	UINT8 routeDirDirection = 0U;  /*进路方向*/
	UINT8 cRouteType = 0U;  /*进路类型*/

	routeDirDirection = GetRouteDirection(routeId);
	chRevrsRouteHasAutoSigRouteSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含自动信号进路数目*/
	reverseRouteAutoSigRouteBuf = GetReverseRouteIncludeRouteBuf(routeId);/*获取反向进路包含自动信号进路ID数组*/

	if ((0u == checkSum) || (NULL == dataIdBuf))
	{
		/*区段数据错误*/
		retVal = CI_ERROR;
	}
	else 
	{
		/*进行后续检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];/*获取逻辑区段ID*/
			devState = GetLogSecLockState(devId);/*获取逻辑区段锁闭状态*/
			secLockDirection = GetLogSecLockDir(devId);/*防护锁闭方向*/

			if (LOG_SECTION_LOCK_NO == devState)
			{
				/*未锁闭，检查通过*/
			}
			else if (LOG_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/
				if (secLockDirection == routeDirDirection)
				{
					/*方向一致：检查通过*/
				}
				else
				{
					/*方向不一致*/
					secPLockBlongRouteId = GetLogSecPLockRouteId(devId);/*逻辑区段防护锁闭所属进路*/
					if (0u == chRevrsRouteHasAutoSigRouteSum)
					{/*反向进路中不包含自动信号进路(即可得此物理区段不是为自动信号进路防护锁闭)，检查不通过*/

					 /*状态无效故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
					}
					else
					{/*反向进路中包含自动信号进路*/

						for (j = 0u; j < chRevrsRouteHasAutoSigRouteSum; j++)
						{/*遍历每条自动信号进路*/
							if (secPLockBlongRouteId == reverseRouteAutoSigRouteBuf[j])
							{/*区段为自动信号进路防护锁闭*/
								break;
							}
						}
						if (j == chRevrsRouteHasAutoSigRouteSum)
						{/*区段不为任何自动信号进路防护锁闭*/

						 /*状态无效故障状态*/
							*pDevId = devId;
							*pDevState = devState;
							retVal = CI_ERROR;
						}
					}
				}
			}
			else if (LOG_SECTION_LOCK_NORMAL == devState)
			{
				secLockBlongRouteId = GetLogSecLockBelongRoute(devId);  /*逻辑区段锁闭所属进路ID*/
				cRouteState = GetRouteState(secLockBlongRouteId);
				cRouteType = GetRouteType(routeId);  /*获取进路类型*/

				if ((ROUTE_STATE_HALF_UNLOCK == cRouteState) && (ROUTE_TYPE_LIECHE == cRouteType) && (secLockDirection == routeDirDirection))
				{
					/*逻辑区段锁闭所属进路当前为部分进路等待解锁状态且为列车进路，且区段锁闭方向与本进路方向相同，则检查通过*/
				}
				else
				{					
					if (0u == chRevrsRouteHasAutoSigRouteSum)
					{/*反向进路中不包含自动信号进路(即可得此物理区段不是为自动信号进路锁闭)，检查不通过*/

							/*状态无效故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
					}
					else
					{
						/*反向进路中包含自动信号进路*/
						for (j = 0u; j < chRevrsRouteHasAutoSigRouteSum; j++)
						{/*遍历每条自动信号进路*/
							if (secLockBlongRouteId == reverseRouteAutoSigRouteBuf[j])
							{/*区段为自动信号进路锁闭*/
								break;
							}
						}
						if (j == chRevrsRouteHasAutoSigRouteSum)
						{/*区段不为任何自动信号进路锁闭*/

						 /*状态无效故障状态*/
							*pDevId = devId;
							*pDevState = devState;
							retVal = CI_ERROR;

						}
					}
				}
			}
			else
			{
				/*状态无效故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				retVal = CI_ERROR;
			}

			if (CI_ERROR == retVal)
			{
				break;
			}
			else
			{
				/*继续检查其它区段*/
			}
		}
	}

	return retVal;
}



/*
* 功能描述： 进路侵限无效检查
* 参数说明： 
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   侵限
*            CI_SUCCESS 侵限不满足
*/
UINT8 RouteIntruSecVainCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 侵限区段 */
	UINT8 const checkSum = GetRouteIntrudePhySectionSum(routeId);
	RouteIntrudePhySectionStruct* const dataIdBuf = GetRouteIntrudePhySectionData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0U;
	UINT16 j = 0U;           /* 循环变量 */
	UINT16 devId = 0U;
	UINT8 devState = 0U;
	UINT8 devFLockState = 0U;
	UINT8 intruSwitchSum = 0U;
	RouteConditionSwitchStruct* intruSwitchConStru = NULL;
	UINT16 intruSwitchId = 0u;
	UINT8 intruSwitchPos = 0u;
	UINT8 intruSwitchPosValid = CI_ERROR;
	UINT8 reVal = CI_ERROR;/*返回值，初始化为错误*/
	UINT8 routeInitInstru = 0u;
	UINT8 chPhySecLockDir = 0U;
	UINT8 chPhySecCtOrUt = 0U;
	UINT8 devLockState = 0U;
	UINT8 devJumpLockState = 0U;
	UINT8 checkFlockFlag = GetCiFunctionSwitchConfig(FUNC_INTRUSEC_CHECKFLOCK_FLAG);
	UINT8 chPhySecLogLockState = 0U;/*物理区段逻辑锁闭状态*/

	routeInitInstru = GetRouteInitInstruStatus(routeId);/*获取进路初始侵限*/


	/* 检查指针是否为空 */
	if (NULL == dataIdBuf)
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		if (ROUTE_INIT_NOT_INSTRU == routeInitInstru)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SectionId;
			devState = GetPhySecCurMergeState(devId);
			devFLockState = GetPhySecFLockState(devId);
			chPhySecLockDir = GetPhySecLockDirection(devId);
			chPhySecCtOrUt = GetPhySecUtOrCtOccuState(devId);
			devLockState = GetPhySecLockState(devId);
			devJumpLockState = GetPhySecJumpLockState(devId);
			chPhySecLogLockState = PhySecLogLockStateCheck(devId);


			/* 检查侵限区段是否占用||封锁||不等于未锁闭||跳跃锁闭*/
			/* 检查侵限区段是否占用||(封锁且检查封锁)||不等于未锁闭||跳跃锁闭*/
			if ((SECTION_OCCUPY_NO != devState)
				|| ((PHYSICAL_SECTION_FLOCK_NO != devFLockState) && (FUNC_SWITCH_ON != checkFlockFlag))
				|| (PHYSICAL_SECTION_LOCK_NO != devLockState)
				|| (PHYSICAL_SECTION_JUMP_LOCK_NO != devJumpLockState)
				|| (LOG_SECTION_LOGLOCK_NO != chPhySecLogLockState))
			{
				/*侵限区段占用或封锁*/
				intruSwitchSum = dataIdBuf[i].SwitchSum;
				if (intruSwitchSum > 0u)
				{
					/*侵限道岔位置检查*/
					intruSwitchPosValid = CI_ERROR;
					for (j = 0u; j < intruSwitchSum; j++)
					{
						intruSwitchConStru = &dataIdBuf[i].ConditionSwitchStru[j];
						intruSwitchId = intruSwitchConStru->SwitchId;
						intruSwitchPos = GetSwitchCurPosition(intruSwitchId);

						if ((intruSwitchPos == intruSwitchConStru->SwitchPosition)
							|| (SWITCH_POSITION_SIKAI == intruSwitchPos)
							|| (SWITCH_POSITION_MOVE == intruSwitchPos)
							|| (SWITCH_POSITION_JICHA == intruSwitchPos)
							|| (SWITCH_POSITION_INVALID == intruSwitchPos))
						{
							/* 占用锁闭时进去判断 */
							if ((PHYSICAL_SECTION_FLOCK_NO == devFLockState)
								&& (PHYSICAL_SECTION_JUMP_LOCK_NO == devJumpLockState)
								&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState))
							{
								if ((chPhySecLockDir == dataIdBuf[i].chCondSwitLockDir)
									&& ((CI_SYSTEM_DIRECTION_UP == dataIdBuf[i].chCondSwitLockDir)
										|| (CI_SYSTEM_DIRECTION_DOWN == dataIdBuf[i].chCondSwitLockDir)))
								{
									if (LOGICSECTION_OCCUPY_CT == chPhySecCtOrUt)
									{
										intruSwitchPosValid = CI_SUCCESS; /*检查成功*/
									}
									else
									{
										intruSwitchPosValid = IntruSecVainCheck(devId);
									}
								}
								else
								{
									intruSwitchPosValid = CI_ERROR;
								}
							}
							else
							{
								intruSwitchPosValid = CI_ERROR;
							}
						}
						else
						{
							/*道岔未侵限*/
							intruSwitchPosValid = CI_SUCCESS;
							break;
						}
					}

					if (CI_ERROR == intruSwitchPosValid)
					{
						/*有岔侵限条件成立*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}
				}
				else
				{
					/*无岔侵限条件条件成立*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
				if (CI_ERROR == reVal)
				{
					break;
				}
			}
			else if ((SECTION_OCCUPY_NO == devState)
				&& ((PHYSICAL_SECTION_FLOCK_NO == devFLockState) || (FUNC_SWITCH_ON == checkFlockFlag))
				&& (PHYSICAL_SECTION_LOCK_NO == devLockState)
				&& (PHYSICAL_SECTION_JUMP_LOCK_NO == devJumpLockState)
				&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState))
			{/*侵限区段未占用且(未封锁或不检查封锁)且未锁闭未跳跃锁闭*/
				/*侵限区段检查通过*/
			}
			else
			{/*该侵限区段状态异常*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}

		}
	}

	/* 未检测到侵限条件 */
	return reVal;
}


/*
* 功能描述： 进路道岔引导总锁状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteSwitchYLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState )
{
/* 进路道岔 */
    UINT8 const checkSum = GetRouteSwitchSum(routeId);
    RouteSwitchStruct* const dataIdBuf = GetRouteSwitchData(routeId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

/* 检查封锁状态 */
	if (NULL == dataIdBuf)
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchYLockState(devId);
			if (devState == SWITCH_LOCK_YINZONG_NO)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 进路道岔封锁状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteSwitchFLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路道岔 */
    UINT8 const checkSum = GetRouteSwitchSum(routeId);
    RouteSwitchStruct* const dataIdBuf = GetRouteSwitchData(routeId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

/* 检查封锁状态 */
    if (NULL == dataIdBuf)
    {
        /*无检查项*/
        reVal = CI_ERROR;
    }
    else
    {
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchFLockState(devId);
			if (devState == SWITCH_LOCK_FENGSUO_NO)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 进路道岔位置和动作有效性检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 sendLevel  报警等级
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* edit cgh 20241204
*/
UINT8 RouteSwitchPosAndMoveValidCheck(UINT16 const routeId,UINT8 sendLevel)
{
    UINT8 const checkSum = GetRouteSwitchSum(routeId);
    RouteSwitchStruct* const dataIdBuf = GetRouteSwitchData(routeId);
	UINT8 i = 0U;           /* 循环变量 */
	UINT8 reVal = CI_ERROR;
	UINT8 chRouteSwitchBelCiCheck = 0U;/*进路道岔是否全部属于进路所在联锁检查*/
	UINT8 chRouteApplySwitchCheckFlag = 0U;/*进路办理道岔检查标志*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chSwitchBelCiId = 0U;/*道岔所属联锁ID*/
	UINT8 chSearchCiId = 0U;/*查询到的联锁ID*/
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chDevType = 0U;
	UINT8 chDevErrorType = 0U;
    if (0U == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
	else if(NULL == dataIdBuf)
	{
	    reVal = CI_ERROR;
	}
    else
    {
		reVal = CI_SUCCESS;
		chLocalCiId = GetSystemParaLocalCiId();
        /*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			chSwitchBelCiId = GetSwitchBelongCiId(dataIdBuf[i].SwitchId);
			if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
			{
				reVal = CheckSwitchPosAndMoveValid(dataIdBuf[i].SwitchId, dataIdBuf[i].SwitchPosition, sendLevel);
				if (CI_ERROR == reVal)
				{
					break;
				}
				else
				{
					;
				}
			}
			else
			{
				/*这里找到其他控区道岔不跳出，完全检查本控区的道岔*/
				; 
			}
		}

		if (CI_SUCCESS == reVal)
		{
			chRouteSwitchBelCiCheck = CheckRouteSwitchBelCi(routeId,&chSearchCiId);
			if (CI_SUCCESS == chRouteSwitchBelCiCheck)
			{
				/*道岔完全本控区，直接成功*/
				reVal = CI_SUCCESS;
			}
			else
			{
				/*有道岔在其它控区*/
				chRouteApplySwitchCheckFlag = GetRouteApplySwitchCheckFlag(routeId);
				if (ROUTE_APPLY_SWITCH_CHECK_YES == chRouteApplySwitchCheckFlag)
				{
					/*相邻联锁驱动道岔标志通过，返回成功*/
					reVal = CI_SUCCESS;
				}
				else if(ROUTE_APPLY_SWITCH_CHECK_DEF == chRouteApplySwitchCheckFlag)
				{
					/*等相邻联锁回复同意*/
					reVal = RETURN_LOCK_ERR_WAIT_SWCHECK;
				}
				else
				{
					reVal = CI_ERROR;
					chDevId = GetRouteApplySwitchCheckErrorData(routeId, &chDevType, &chDevState, &chDevErrorType);
					if (0U != chDevId)
					{
						SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, chDevType, chDevId, chDevErrorType, chDevState, sendLevel);
					}
				}
			}
		}
		else
		{
			; /*返回失败*/
		}
    }

    /*全部通过检查*/
    return reVal;
}

/* zt 删除单轨相关代码 2022-02-15 */

/*
* 功能描述： CBTC进路办理区段锁闭有效性检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteCbtcSecLockValidCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{   
    /* 进路区段*/
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
    UINT8 i = 0U;           /* 循环变量 */
	UINT8 j = 0U;
    UINT16 devId = 0U;
    UINT8  devState = 0U;
    UINT8  secLockDirection = 0U;
    UINT16 routeLockedId = 0U;
    UINT8 routeLockedType = 0U;
    UINT8 const routeDirection = GetRouteDirection(routeId);
	UINT8 phyArbState = 0U;
	UINT8 reVal = CI_ERROR;
	UINT16 phySecId = 0U;
	UINT8 cPhySecIncLogSecNum = 0U;  /*物理区段包含的逻辑区数量*/
	UINT16* pPhySecIncLogSecId = NULL;  /*物理区段包含的逻辑区ID数组*/

    if ((0U != checkSum) && (NULL != dataIdBuf) && (NULL != pDevId) && (NULL != pDevState))
    {
		reVal = CI_SUCCESS;

		for (i = 0U; i < checkSum; i++)
		{
			cPhySecIncLogSecNum = GetPhySecIncLogSecSum(dataIdBuf[i].PhysicalSectionId);  /*获取物理区段包含的逻辑区段数量*/
			pPhySecIncLogSecId = GetPhySecIncLogSecIdBuf(dataIdBuf[i].PhysicalSectionId);  /*获取物理区段包含的逻辑区段ID*/

			if ((0U != cPhySecIncLogSecNum) && (NULL != pPhySecIncLogSecId))
			{
				/*检查物理区段包含的所以逻辑区段锁闭状态是否合法*/
				for (j = 0U; j < cPhySecIncLogSecNum; j++)
				{
					devId = pPhySecIncLogSecId[j];
					devState = GetLogSecLockState(devId);

					if (LOG_SECTION_LOCK_NO == devState)
					{
						/* 区段未锁闭，检查通过 */
					}
					else if (LOG_SECTION_LOCK_PROTECT == devState)
					{
						/*防护锁闭*/
						secLockDirection = GetLogSecLockDir(devId);
						if (secLockDirection == routeDirection)
						{
							/*方向一致，检查通过*/
						}
						else
						{
							/*方向不一致，返回0失败*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}

					}
					else if ((LOG_SECTION_LOCK_NORMAL == devState) || (LOG_SECTION_LOCK_DELAY == devState))
					{
						/* 区段【正常锁闭】或 【延时锁闭】 */
						secLockDirection = GetLogSecLockDir(devId);
						routeLockedId = GetLogSecLockBelongRoute(devId);
						routeLockedType = GetRouteType(routeLockedId);
						if ((secLockDirection == routeDirection)
							&& (ROUTE_TYPE_LIECHE == routeLockedType))
						{
							/*方向一致且进路为列车进路或（进路为折返进路且处于部分进路等待解锁状态），检查通过*/
						}
						else
						{
							/*方向不一致或进路条件不满足，返回0失败*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
					}
					else if (LOG_SECTION_LOCK_EXCEPT == devState)
					{
						/*区段【异常锁闭】:获取逻辑区段所属物理区段ARB状态、逻辑区段异常锁闭方向*/
						phySecId = GetLgcSecRelativePhySecId(devId);
						phyArbState = GetPhySecArbState(phySecId);
						secLockDirection = GetLogSecLockDir(devId);
						
						if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirection))
						{
							/*区段ARB，且异常锁闭方向一致,不做处理*/
						}
						else
						{
							/*返回错误*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
					}
					else
					{
						/*锁闭状态不满足*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}

					if (CI_ERROR == reVal)
					{
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				reVal = CI_ERROR;  /*获取物理区段包含的逻辑区段失败，返回0失败*/
			}

			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
				/*继续检查*/
			}
		}
    }
	else
	{
		reVal = CI_ERROR;  /*返回0失败*/
	}

    return reVal;
}


/*
* 功能描述： CBTC进路办理逻辑区段锁闭有效性检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221005 适配进路驱动道岔提前扳动功能
*/
UINT8 RouteCbtcLogSecLockValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf = GetRouteLogSectionIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8  secLockDirection = 0u;
	UINT16 routeLockedId = 0u;
	UINT8 routeLockedType = 0u;
	UINT16 phySecId = 0u;
	UINT8 const routeDirection = GetRouteDirection(routeId);
	UINT8 phyArbState = 0u;
	UINT8 reVal = CI_ERROR;


	/*联锁检查*/
	/*检查进路内逻辑区段状态*/
	if ((checkSum == 0u) || (NULL == dataIdBuf))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		/* 进路内所有区段进路内所有逻辑区段锁闭状态【未锁闭】
		或方向相同的【防护锁闭】或
		(方向相同的【正常锁闭】或 方向相同的【延时锁闭】且锁闭进路为【列车进路】)
		故障锁闭且ARB且锁闭方向一致)
		*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetLogSecLockState(devId);

			if (LOG_SECTION_LOCK_NO == devState)
			{
				/* 区段未锁闭 */

			}
			else if (LOG_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/
				secLockDirection = GetLogSecLockDir(devId);
				if (secLockDirection == routeDirection)
				{
					/*方向一致*/

				}
				else
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

			}
			else if ((LOG_SECTION_LOCK_NORMAL == devState)
				|| (LOG_SECTION_LOCK_DELAY == devState))
			{
				/* 区段【正常锁闭】或 【延时锁闭】 */
				secLockDirection = GetLogSecLockDir(devId);
				routeLockedId = GetLogSecLockBelongRoute(devId);
				routeLockedType = GetRouteType(routeLockedId);
				if ((secLockDirection == routeDirection) 
					&& (ROUTE_TYPE_LIECHE == routeLockedType))
				{
					/*方向一致*/
				}
				else
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			/*区段异常锁闭*/
			else if (LOG_SECTION_LOCK_EXCEPT == devState)
			{
				/*获取逻辑区段所属物理区段ARB状态、逻辑区段异常锁闭方向*/
				phySecId = GetLgcSecRelativePhySecId(devId);
				phyArbState = GetPhySecArbState(phySecId);
				secLockDirection = GetLogSecLockDir(devId);
				/*区段ARB，且异常锁闭方向一致*/
				if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirection))
				{
					/*不做处理*/
				}
				else
				{
					/*返回错误*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{
				/*锁闭状态不满足*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{

			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： CBTC进路内道岔关联另一逻辑区段未锁闭
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221005 优化进路条件检查，进路办理时，检查道岔另一位置关联逻辑区段未锁闭
*/
UINT8 RouteSwOtherLogLockValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT16 const checkOtherSum = GetRouteSwitOtherLogSecSum(routeId);
	UINT16* const dataOtherIdBuf = GetRouteSwitOtherPosLogSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 j = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 cLogicLockState = 0U;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogicLockBelongRouteNum = 0U;  /*逻辑区段逻辑锁闭所属进路数量*/

	/*检查进路内道岔关联的非进路内逻辑区段状态*/
	if (NULL == dataOtherIdBuf)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else if (checkOtherSum == 0u)
	{
		/*进路不包含道岔，返回成功*/
		reVal = CI_SUCCESS;
	}
	else
	{
		/*开始检查*/
		reVal = CI_SUCCESS;
		/* 检查进路内道岔关联的非进路内逻辑区段状态【未锁闭】 */
		for (j = 0u; j < checkOtherSum; j++)
		{
			devId = dataOtherIdBuf[j];
			devState = GetLogSecLockState(devId);
			cLogicLockState = GetLogSecLogLockState(devId);  /*获取逻辑区段逻辑锁闭状态*/
			cLogicLockBelongRouteNum = GetLogSecLockBelLogRouteSum(devId);  /*获取逻辑区段逻辑锁闭所属进路数量*/

			if ((LOG_SECTION_LOCK_NO == devState) && (LOG_SECTION_LOGLOCK_NO == cLogicLockState) && (0U == cLogicLockBelongRouteNum))
			{
				/* 区段未锁闭且未逻辑锁闭且逻辑锁闭所属进路数量为0，返回成功 */
			}
			else
			{
				/*锁闭状态不满足*/
				*pDevId = devId;
				if (LOG_SECTION_LOCK_NO == devState)
				{
					*pDevState = cLogicLockState;
				}
				else
				{
					*pDevState = devState;
				}
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
				; /*不处理*/
			}
		}
	}

	return reVal;
}
/*
* 功能描述： 进路锁闭，进路包含的物理区段的非进路内且非道岔关联的逻辑区段有效性检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路驱动道岔提前扳动功能
*/
UINT8 RouteOutLogSecLockValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路包含的物理区段内非进路内且非道岔关联的逻辑区段*/
	UINT16 const checkSum = GetRouteOutLogSecSum(routeId);
	UINT16* const dataIdBuf = GetRouteOutLogSecSumIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8  cLogicLockState = 0U;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogicLockBelongRouteNum = 0U;  /*逻辑区段逻辑锁闭所属进路数量*/

	/*逻辑区段【未锁闭】*/
	if  (NULL == dataIdBuf)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else if (0u == checkSum)
	{
		/*未划分新逻辑区段，返回成功。*/
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_SUCCESS;
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetLogSecLockState(devId);
			cLogicLockState = GetLogSecLogLockState(devId);  /*获取逻辑区段逻辑锁闭状态*/
			cLogicLockBelongRouteNum = GetLogSecLockBelLogRouteSum(devId);  /*获取逻辑区段逻辑锁闭所属进路数量*/

			if ((LOG_SECTION_LOCK_NO == devState) && (LOG_SECTION_LOGLOCK_NO == cLogicLockState) && (0U == cLogicLockBelongRouteNum))
			{
				/* 区段未锁闭且未逻辑锁闭且逻辑锁闭所属进路数量为0，返回成功 */
			}
			else
			{
				/*锁闭状态不满足*/
				*pDevId = devId;
				if (LOG_SECTION_LOCK_NO == devState)
				{
					*pDevState = cLogicLockState;
				}
				else
				{
					*pDevState = devState;
				}
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 进路锁闭，进路包含的物理区段的非进路内且非道岔关联的逻辑区段未占压
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路驱动道岔提前扳动功能
*/
UINT8 RouteOutLogSecOccClearCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路包含的物理区段的非进路内且非道岔关联的逻辑区段*/
	UINT16 const checkSum = GetRouteOutLogSecSum(routeId);
	UINT16* const dataIdBuf = GetRouteOutLogSecSumIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;


	/*联锁检查*/
	/*逻辑区段【未锁闭】*/
	if (NULL == dataIdBuf)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else if (checkSum == 0u)
	{
		/*未划分新逻辑区段，返回成功。*/
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_SUCCESS;
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState =GetLogSecCurOccupyState(devId);

			if (SECTION_OCCUPY_NO == devState)
			{
				/* 区段未占压 */

			}
			else
			{
				/*锁闭状态不满足*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 进路内所有道岔位置正确检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteAllSwitchPosCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路道岔 */
    UINT8 const checkSum = GetRouteSwitchSum(routeId);
    RouteSwitchStruct* const dataIdBuf = GetRouteSwitchData(routeId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;    
    UINT8 reVal = CI_SUCCESS;

/* 检查封锁状态 */
    if (0u == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
	else if ((NULL == dataIdBuf))
	{
	    reVal = CI_ERROR;
	}
    else
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			if (devState == dataIdBuf[i].SwitchPosition)
			{
				/*道岔位置正确*/

			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}

/* zt 删除单轨相关代码 2022-02-15 */

/*
* 功能描述： 进路关联防护道岔位置正确检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteRelatedProSwitchPosCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 进路关联防护道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const dataIdBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;    
	UINT8 reVal = CI_ERROR;

	if ((NULL == dataIdBuf) || (NULL == pDevId)|| (NULL == pDevState))
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchCurPosition(devId);
			if (dataIdBuf[i].ProtectPosition == devState)
			{
				/*道岔位置正确*/
			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路关联防护道岔防护锁闭检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteRelatedProSwitchLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 进路关联防护道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const dataIdBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;    
	UINT8 reVal = CI_ERROR;

	if (NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchLockStatus(devId);
			if ((SWITCH_LOCK_STATUS_PROTECT == devState) || (SWITCH_LOCK_STATUS_DAP == devState))
			{
				/*道岔已【防护锁闭】或【单锁且防护锁闭】*/
			}
			else
			{
				/*道岔未【防护锁闭】且未【单锁且防护锁闭】*/
				*pDevId = devId;
				*pDevState = SWITCH_LOCK_STATUS_PROTECT_NO;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路关联防护道岔引导总锁检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteRelatedProSwitchYLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState )
{
	/* 进路关联防护道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const dataIdBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	if ((NULL == dataIdBuf) || (NULL == pDevId)|| (NULL == pDevState))
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if(CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchYLockState(devId);
			if (SWITCH_LOCK_YINZONG_NO == devState)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路关联防护道岔位置和动作有效性检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 sendLevel  发送等级
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* edit cgh  20241203
*/
UINT8 RouteRelProSwiPosAndMovValCheck(UINT16 const routeId,UINT8 sendLevel)
{
	/* 进路关联防护道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const dataIdBuf = GetRouteRelatedProtSwitchData(routeId);
	UINT8 i = 0U;           /* 循环变量 */
	UINT8 reVal = CI_ERROR;
	UINT8 chRouteSwitchBelCiCheck = 0U;/*进路道岔是否全部属于进路所在联锁检查*/
	UINT8 chRouteApplySwitchCheckFlag = 0U;/*进路办理道岔检查标志*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chSwitchBelCiId = 0U;/*道岔所属联锁ID*/
	UINT8 chSearchCiId = 0U;/*查询到的联锁ID*/
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chDevType = 0U;
	UINT8 chDevErrorType = 0U;

	if (0U == checkSum)
	{
		/*无检查项*/
		reVal = CI_SUCCESS;
	}
	else if (NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		chLocalCiId = GetSystemParaLocalCiId();
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			chSwitchBelCiId = GetSwitchBelongCiId(dataIdBuf[i].ProtectSwitchId);
			if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
			{
				reVal = CheckSwitchPosAndMoveValid(dataIdBuf[i].ProtectSwitchId, dataIdBuf[i].ProtectPosition, sendLevel);
				if (CI_ERROR == reVal)
				{
					break;
				}
				else
				{
					;
				}
			}
			else
			{
				/*这里找到其他控区道岔不跳出，完全检查本控区的道岔*/
				;
			}
		}

		if (CI_SUCCESS == reVal)
		{
			chRouteSwitchBelCiCheck = CheckRouteProSwitchBelCi(routeId, &chSearchCiId);
			if (CI_SUCCESS == chRouteSwitchBelCiCheck)
			{
				/*道岔完全本控区，直接成功*/
				reVal = CI_SUCCESS;
			}
			else
			{
				/*有道岔在其它控区*/
				chRouteApplySwitchCheckFlag = GetRouteApplySwitchCheckFlag(routeId);
				if (ROUTE_APPLY_SWITCH_CHECK_YES == chRouteApplySwitchCheckFlag)
				{
					/*相邻联锁驱动道岔标志默认或通过，返回成功*/
					reVal = CI_SUCCESS;
				}
				else if (ROUTE_APPLY_SWITCH_CHECK_DEF == chRouteApplySwitchCheckFlag)
				{
					/*等相邻联锁回复同意*/
					reVal = RETURN_LOCK_ERR_WAIT_SWCHECK;
				}
				else
				{
					reVal = CI_ERROR;
					chDevId = GetRouteApplySwitchCheckErrorData(routeId, &chDevType, &chDevState, &chDevErrorType);
					if (0U != chDevId)
					{
						SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, chDevType, chDevId, chDevErrorType, chDevState, sendLevel);
					}
				}
			}
		}
		else
		{
			; /*返回失败*/
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： Overlap区段空闲检查
* 参数说明： UINT16 const overlapId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OverlapAllSecOccuClearCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap区段 */
    UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
    UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_SUCCESS;

/* 区段占用检查 */
    /*联锁检查*/
    if (0u == checkSum) 
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
        /*开始检查*/
	   for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecCurMergeState(devId);
			if (SECTION_OCCUPY_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }
 
    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： Overlap区段征用检查
* 参数说明： UINT16 const overlapId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pAlarmType 报警类型（返回）
* 返回值  ： CI_ERROR  0 非全部未征用
*            CI_SUCCESS 1 全部未征用
*            RETURN_WAIT_SWITCH_USING 0x30 等待防护道岔征用
*/
UINT8 OverlapAllSecUsingClearCheck(UINT16 const overlapId, UINT16 *pDevId,UINT8 *pDevState, UINT8* pAlarmType)
{
	/* overlap区段 */
	UINT8 overlapSecSum = 0U;
	UINT16* pOverlapSecIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT16 i = 0U;           /* 循环变量 */
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT16 phySecProtectUseRouteId = 0U;
	UINT16 phySecUseRouteId = 0U;
	UINT8 reVal = CI_ERROR;
	UINT8 cAlarmType = FLAG_UNSET;  /*报警类型：0xAA-按物理区段报警；0x55-按道岔报警*/

	overlapSecSum = GetOverlapPhySecSum(overlapId);/*获取保护区段内区段数量*/
	pOverlapSecIdBuf = GetOverlapPhySecIdBuf(overlapId);/*获取保护区段内区段数据*/

	if ((NULL == pOverlapSecIdBuf) || (NULL == pDevId) || (NULL == pDevState) || (NULL == pAlarmType))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0U; i<overlapSecSum; i++)
		{
			devId = pOverlapSecIdBuf[i];
			devState = GetPhySecUseState(devId);
			if (PHYSICAL_SECTION_USING_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				phySecProtectUseRouteId = GetPhySecProtectUseRouteId(devId);
				phySecUseRouteId = GetPhySecUseRouteId(devId);
				if (CI_SUCCESS == reVal)
				{
					/*执行到此处两个都为0说明是非进路征用，直接返回检查失败*/
					if ((0U == phySecProtectUseRouteId) && (0U == phySecUseRouteId))
					{
						reVal = CI_ERROR;
					}
					else
					{
						/*继续检查*/
					}
				}
				else
				{
					/*返回失败*/
				}

				/*当前区段的道岔位置或者道岔期望动作位置是否与本保护区段要求的位置相同*/
				if (CI_SUCCESS == reVal)
				{
					reVal = CheckOverlapPhysecUseState(devId, overlapId);
				}
				else
				{
					/*返回失败*/
				}

				if (CI_SUCCESS != reVal)
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					*pAlarmType = cAlarmType;
					break;
				}
				else
				{
					/*继续遍历检查*/
				}
			}
		}
	}

	/*检查保护区段的防护道岔所在区段的征用*/
	if (CI_SUCCESS == reVal)
	{
		reVal = OverlapProSwUsingCheck(overlapId, pDevId, pDevState, pAlarmType);
	}
	else
	{
		/*返回失败*/
	}

	return reVal;
}


/*
* 功能描述： 保护区段所属物理区段锁闭方向检查
* 参数说明： const UINT16 overlapId 保护区段ID
			UINT8 plockDirect 锁闭方向
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OverlapAllSecLockDirectCheck(const UINT16 overlapId, UINT8 plockDirect, UINT16 *pDevId, UINT8 *pDevState)
{
/* overlap区段 */
    UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
    UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT16 secLockDirection = 0u;
	UINT8 reVal = CI_SUCCESS;

/* 联锁条件检查 */
    if (0u == checkSum) 
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
        /*开始检查*/
		 /* 保护区段内所有区【未锁闭】
			或者 方向相同【正常锁闭】
			或者 方向相同【防护锁闭】*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecLockState(devId);

			if (PHYSICAL_SECTION_LOCK_NO==devState)
			{
				/* 未锁闭 */
			}
			else if((PHYSICAL_SECTION_LOCK_NORMAL==devState) || (PHYSICAL_SECTION_LOCK_DELAY == devState))
			{
				/*正常锁闭或延时解锁*/
				secLockDirection = GetPhySecLockDirection(devId);
				if(plockDirect == secLockDirection)
				{
					/* 方向相同 */

				}
				else
				{
					reVal = CI_ERROR;
				}
			}
			else if(devState == PHYSICAL_SECTION_LOCK_PROTECT)
			{
				/*防护锁闭*/
				secLockDirection = GetPhySecLockDirection(devId);
				if(plockDirect == secLockDirection)
				{
					/* 方向相同 */
				}
				else
				{
					reVal = CI_ERROR;
				}
			}
			else
			{
				reVal = CI_ERROR;
			}

			if (CI_ERROR == reVal)
			{
				*pDevId = devId;
				*pDevState = devState;
				break;
			}
			else
			{
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}
/*
* 功能描述： 保护区段锁闭状态有效性检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 const routeId,    进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OverlapAllSecLockValidCheck(UINT16 const overlapId,UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap区段 */
    UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
    UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT16 secLockDirection = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 haveChangeInRoute = 0u;
	UINT8 haveChangeAfterRoute = 0u;
    UINT8 routeDirection = 0u;/* 进路方向 */

	routeDirection = GetRouteDirection(routeId);

/* 联锁条件检查 */
    if (0u == checkSum) 
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
		/*获取进路是否有方向变化点*/
		haveChangeInRoute = GetRouteHaveDirChangePointIn(routeId);
		haveChangeAfterRoute = GetRouteHaveDirChangePointAfter(routeId);

        /*开始检查*/
		 /* 保护区段内所有区【未锁闭】
			或者 方向相同【正常锁闭】
			或者 方向相同【防护锁闭】*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecLockState(devId);
			if (PHYSICAL_SECTION_LOCK_NO == devState)
			{
				/* 未锁闭 */

			}
			else if((PHYSICAL_SECTION_LOCK_NORMAL == devState) || (PHYSICAL_SECTION_LOCK_DELAY == devState))
			{
				/*正常锁闭或延时解锁*/
				secLockDirection = GetPhySecLockDirection(devId);
				/*存在方向变化点,且进路与保护区段锁闭方向相反*/
				if(((ROUTE_HAVE_DIR_CHANGE_POINT == haveChangeInRoute) || (ROUTE_HAVE_DIR_CHANGE_POINT == haveChangeAfterRoute))
					&& (routeDirection != secLockDirection))
				{
					if(CI_SYSTEM_DIRECTION_UP == routeDirection)
					{
						routeDirection = CI_SYSTEM_DIRECTION_DOWN;
					}
					else if(CI_SYSTEM_DIRECTION_DOWN == routeDirection)
					{
						routeDirection = CI_SYSTEM_DIRECTION_UP;
					}
					else
					{
						/*不做处理*/
					}
				}
				else
				{
				}

				if(routeDirection == secLockDirection)
				{
					/* 方向相同 */

				}
				else
				{
					/*状态非法返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else if(PHYSICAL_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/
				secLockDirection = GetPhySecLockDirection(devId);
				if((ROUTE_HAVE_DIR_CHANGE_POINT == haveChangeInRoute) || (ROUTE_HAVE_DIR_CHANGE_POINT == haveChangeAfterRoute))
				{
					/*方向取反*/
					if(CI_SYSTEM_DIRECTION_UP == routeDirection)
					{
						routeDirection = CI_SYSTEM_DIRECTION_DOWN;
					}
					else if(CI_SYSTEM_DIRECTION_DOWN == routeDirection)
					{
						routeDirection = CI_SYSTEM_DIRECTION_UP;
					}
					else
					{
						/*不做处理*/
					}
				}
				else
				{
				}

				if(routeDirection == secLockDirection)
				{
					/* 方向相同 */

				}
				else
				{
					/*状态非法返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{
				/*状态非法返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
			}
		}
    }
    
    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： overlap道岔引导总锁状态检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OverlapSwitchYLockCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap道岔 */
    UINT8 const checkSum = GetOverlapSwitchSum(overlapId);
    OverlapConditionSwitchStruct* const dataIdBuf = GetOverlapCondSwitchStruct(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_SUCCESS;

/* 检查封锁状态 */
    if (0u == checkSum)
    {
        /*没有道岔*/
        reVal = CI_SUCCESS;
    }
    else
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchYLockState(devId);
			if (devState == SWITCH_LOCK_YINZONG_NO)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： overlap关联防护道岔引导总锁状态检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OvlpRelatedProSwitchYLockCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap防护道岔 */
    UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
    OverlapProtectSwitchStruct* const dataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

/* 检查封锁状态 */
    if (NULL == dataIdBuf)
    {
        /*指针为空，返回失败*/
        reVal = CI_ERROR;
    }
	else
	{
		reVal = CI_SUCCESS;
	}

    if (CI_SUCCESS == reVal)
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchYLockState(devId);
			if (devState == SWITCH_LOCK_YINZONG_NO)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 保护区段道岔封锁状态检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OverlapSwitchFLockStateCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap道岔 */
    UINT8 const checkSum = GetOverlapSwitchSum(overlapId);
    OverlapConditionSwitchStruct* const dataIdBuf = GetOverlapCondSwitchStruct(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

/* 检查封锁状态 */
    if (NULL == dataIdBuf)
    {
        /*无检查项*/
        reVal = CI_ERROR;
    }
    else
    {
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchFLockState(devId);
			if (devState == SWITCH_LOCK_FENGSUO_NO)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 保护区段道岔动作有效性检查检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OverlapSwitchMoveValidCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap道岔 */
    UINT8 const checkSum = GetOverlapSwitchSum(overlapId);
    OverlapConditionSwitchStruct* const dataIdBuf = GetOverlapCondSwitchStruct(overlapId);

/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;/*不发送*/

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8  switchPos = 0u;
    UINT8 switchMoveState = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 checkResult = 0u;

/* 检查封锁状态 */
    if (0u == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
	else if(NULL == dataIdBuf)
	{
	    reVal = CI_ERROR;
	}
    else
    {
			/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].SwitchPosition;
			if (devState == switchPos)
			{
				/*道岔位置正确*/
				/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
				checkResult = checkSwtLastValDrvPosStayorNot(devId,switchPos);
				if (CI_SUCCESS == checkResult)
				{
				}
				else
				{
					reVal = CI_ERROR;
				}
			}
			else if (SWITCH_POSITION_SIKAI == devState)
			{
				/*四开*/
				reVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA == devState)
			{
					/*挤岔*/
				reVal = CI_ERROR;
			}
			else 
			{
				/* 道岔位置不正确 */
				switchMoveState = GetSwitchMoveValidState(devId,SWITCH_OPER_NO_DANCAO,sendLevel);
				if (CI_SUCCESS==switchMoveState )
				{
					/*道岔可动*/

				} 
				else
				{
					/*道岔位置不正确 且 道岔不可动作*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述：保护区段关联防护道岔动作有效性检查检查
* 参数说明：UINT16 const overlapId,  OverlapID
*           UINT16 *pDevId,    设备Id（返回）
*           UINT8 *pDevState,  设备状态（返回）
*           UINT8 *pAlarmType,  报警类型（返回）
* 返 回 值：CI_ERROR 0 失败
*           CI_SUCCESS 1 成功
*           RETURN_WAIT_SWITCH_CHECK 0x31 等待防护道岔检查
*/
UINT8 OvlpRelatedProtSwiMovValCheck(UINT16 const overlapId, UINT16 *pDevId, UINT8 *pDevState, UINT8* pAlarmType)
{
/* overlap关联防护道岔 */
	UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
    OverlapProtectSwitchStruct* const dataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;/*不发送*/

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8  switchPos = 0u;
    UINT8 switchMoveState = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 checkResult = 0u;
	UINT8 cLocalCiId = 0U;
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属控区*/
	UINT8 cAlarmType = FLAG_UNSET;  /*报警类型：0xAA-报警道岔位置错误，0x55-报警道岔可动性检查错误*/
	UINT8 cProSwCheckResultFlag = 0U;  /*防护道岔检查结果标志*/

/* 检查封锁状态 */
    if (0u == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }else if ((NULL == dataIdBuf) || (NULL == pDevId) || (NULL == pDevState) || (NULL == pAlarmType))
	{
		reVal = CI_ERROR;
	}
    else
    {
		cLocalCiId = GetSystemParaLocalCiId();

		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			cSwitchBelongCiId = GetSwitchBelongCiId(devId);
			if (cLocalCiId == cSwitchBelongCiId)
			{
				devState = GetSwitchCurPosition(devId);
				switchPos = dataIdBuf[i].ProtectPosition;
				if (devState == switchPos)
				{
					/*道岔位置正确*/
					/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
					checkResult = checkSwtLastValDrvPosStayorNot(devId, switchPos);
					if (CI_SUCCESS == checkResult)
					{
					}
					else
					{
						reVal = CI_ERROR;
					}
				}
				else if (SWITCH_POSITION_SIKAI == devState)
				{
					/*四开*/
					reVal = CI_ERROR;
				}
				else if (SWITCH_POSITION_JICHA == devState)
				{
					/*挤岔*/
					reVal = CI_ERROR;
				}
				else
				{
					/* 道岔位置不正确 */
					switchMoveState = GetSwitchMoveValidState(devId, SWITCH_OPER_NO_DANCAO, sendLevel);
					if (CI_SUCCESS == switchMoveState)
					{
						/*道岔可动*/
					}
					else
					{
						/*道岔位置不正确 且 道岔不可动作*/
						reVal = CI_ERROR;
					}
				}
			}
			else
			{
				cProSwCheckResultFlag = GetOverlapProSwtCheckResultFlag(overlapId);
				if (PROSWITCH_CHECK_RESULT_VALID == cProSwCheckResultFlag)
				{
					/*防护道岔检查结果标志为成功，检查通过*/
				}
				else if (PROSWITCH_CHECK_RESULT_DEFAULT == cProSwCheckResultFlag)
				{
					reVal = RETURN_WAIT_SWITCH_CHECK;  /*防护道岔检查结果标志为默认值，返回等待防护道岔检查*/
				}
				else
				{
					devState = cProSwCheckResultFlag;  /*记录故障状态*/
					cAlarmType = FLAG_SET;
					reVal = CI_ERROR;
				}
			}

			if (CI_ERROR == reVal)
			{
				*pDevId = devId;
				*pDevState = devState;
				*pAlarmType = cAlarmType;
				break;
			}
			else
			{
				;
			}
		}
    }

    return reVal;
}

/* zt 删除单轨相关代码 2022-02-15 */


/*
* 功能描述： 保护区段道岔位置正确检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OverlapSwitchPosCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
/* overlap道岔 */
    UINT8 const checkSum = GetOverlapSwitchSum(overlapId);
    OverlapConditionSwitchStruct* const dataIdBuf = GetOverlapCondSwitchStruct(overlapId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8  switchPos = 0u;
	UINT8 reVal = CI_SUCCESS;

/* 检查封锁状态 */
    if (0u == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }else if(NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
    else
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].SwitchPosition;
			if (switchPos == devState)
			{
				/*道岔位置正确*/

			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： 保护区段关联防护道岔位置检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OvlpRelatedProtSwitchPosCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* overlap道岔 */
	UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
	OverlapProtectSwitchStruct* const dataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8  switchPos = 0u;
	UINT8 reVal = CI_SUCCESS;

	/* 检查封锁状态 */
	 if (0u == checkSum) 
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }else if(NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].ProtectPosition;
			if (switchPos == devState)
			{
				/*道岔位置正确*/

			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 保护区段关联防护道岔防护锁闭检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OvlpRelatedProtSwitchLockCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 进路关联防护道岔 */
	UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
	OverlapProtectSwitchStruct* const dataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;    
	UINT8 reVal = CI_ERROR;

	if (NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if(CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchLockStatus(devId);
			if ((SWITCH_LOCK_STATUS_PROTECT == devState) || (SWITCH_LOCK_STATUS_DAP == devState))
			{
				/*道岔已【防护锁闭】或【单锁且防护锁闭】*/
			}
			else
			{
				/*道岔未【防护锁闭】或未【单锁且防护锁闭】*/
				*pDevId = devId;
				*pDevState = SWITCH_LOCK_STATUS_PROTECT_NO;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/* zt 删除单轨相关代码 2022-02-15 */


/*
* 功能描述： 保护区段内的折返进路检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR 保护区段不可以锁闭
*            CI_SUCCESS 保护区段可以锁闭
*/
UINT8 OverlapAllReturnRouteCheckup(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 获取保护区段锁闭条件包含折返进路及折返轨物理区段数目*/
    UINT8 const RetRoutAndTrkPhySecSum = GetOvlpRetRoutAndTrkPhySecSum(overlapId);

	/* 局部变量定义初始化 */
    UINT16	i = 0u;				/* 循环变量 */
    UINT16	routeId = 0u;		/*进路ID*/
    UINT8	routeState = 0u;		/*进路状态*/
    UINT16	phySecId = 0u;		/*物理区段ID*/
    UINT8	phySecState = 0u;	/*物理区段状态*/
    UINT8	reVal = CI_SUCCESS;	/* 保护区段折返进路检查结果*/

	/* 区段占用检查 */
    /*联锁检查*/
    if (OVLP_RETROUTSEC_N_RETTRKPHYSEC_SUM_MAX < RetRoutAndTrkPhySecSum)
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
        /*开始检查*/
		for (i = 0u; i < RetRoutAndTrkPhySecSum; i++)
		{
			/*获取折返进路ID*/
			routeId = GetOverlapReturnRouteId(overlapId, i);
			/*获取折返进路状态*/
			routeState = GetRouteState(routeId);

			if (ROUTE_STATE_IDLE == routeState)
			{
				/* 折返进路通过空闲检查*/
				;
			}
			else
			{
				/*获取折返轨物理区段ID*/
				phySecId = GetOverlapRetTrkPhySecId(overlapId, i);
				/*获取折返轨物理区段状态*/
				phySecState = GetPhySecCurMergeState(phySecId);
				

				if(SECTION_OCCUPY_NO == phySecState)
				{
					/* 物理区段通过空闲检查*/
					;
				}
				else
				{
					/*折返进路被占用并且对应物理区段也被占用*/
					*pDevId = phySecId;
					*pDevState = phySecState;
					reVal = CI_ERROR;
					break;
				}
			}
		}
    }
 
    /*全部通过检查*/
    return reVal;
}

/*
功能描述:	保护区段关联的侵限区段及条件道岔检查
输入参数:	UINT16 const overlapId	保护区段ID
输出参数:	UINT16 *pDevId		设备Id
				UINT8 *pDevState		设备状态
返回值: 		CI_SUCCESS			不满足侵限条件
				CI_ERROR			满足侵限条件
*/
UINT8 OverlapInvSecAndConSwiCheckup(UINT16 const overlapId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 invSecAndConSwiSum = 0U;	/* 侵限区段总数*/
	UINT16 i = 0U; 			/* 循环变量 */
	UINT16 j = 0U; 			/* 循环变量 */
	UINT16 invSecAndConSwiId = 0U;	/*侵限区段及条件道岔组ID*/
	UINT16 invaSectId = 0U;			/*侵限区段ID*/
	UINT8  invaSectState = 0U;		/*侵限区段状态*/
	UINT8  devFLockState = 0U;       /*侵限区段封锁状态*/
	UINT16 condSwitSum = 0U;			/*条件道岔总数*/
	UINT16 condSwitId = 0U;			/*条件道岔ID*/
	UINT16 condSwitStat = 0U;		/*条件道岔侵限状态(位置)*/
	UINT8 currSwitPos = 0U;			/*条件道岔实际位置*/
	UINT16 tmpDevId = 0U;			/*临时变量*/
	UINT8 tmpDevState = 0U;			/*临时变量*/
	UINT8 fLockType = PHY_SEC_FLOCK_TYPE_NONE;/*物理区段封锁类型变量*/
	UINT8 condSwitchPosValid = CI_ERROR;
	UINT8 devLockState = 0U;
	UINT8 devJumpLockState = 0U;
	UINT8 reVal = CI_SUCCESS;
	UINT8 checkFlockFlag = GetCiFunctionSwitchConfig(FUNC_INTRUSEC_CHECKFLOCK_FLAG);
	UINT8 cFuncSwitchSpks = 0U;  /*SPKS信号自动重开开关，0x55检查进路级别，0xaa不检查*/
	UINT16 wLockBelongRouteId = 0U;  /*保护区段锁闭所属进路*/
	UINT8 cRouteLevel = 0U;
	UINT8 chPhySecLogLockState = 0U;/*物理区段逻辑锁闭状态*/

	/*检查pDevId是否为NULL*/
	if (NULL != pDevId)
	{
		/*通过检查*/
		;
	}
	else
	{
		pDevId = &tmpDevId;
	}

	/*检查pDevState是否为NULL*/
	if (NULL != pDevState)
	{
		/*通过检查*/
		;
	}
	else
	{
		pDevState = &tmpDevState;
	}
	reVal = CI_SUCCESS;

	invSecAndConSwiSum = GetOverlapInvSecAndConSwiSum(overlapId);

	/* 检查侵限状态 */
	if (0U < invSecAndConSwiSum)
	{
		cFuncSwitchSpks = GetCiFunctionSwitchConfig(FUNC_REPEATE_OPEN_CHECK_SPKS);
		wLockBelongRouteId = GetOverlapBelongRouteId(overlapId);
		cRouteLevel = GetRouteLevel(wLockBelongRouteId);

		/*开始检查*/
		for (i = 0U; i < invSecAndConSwiSum; i++)
		{
			invSecAndConSwiId = GetOverlapInvSecAndConSwiId(overlapId, i);
			invaSectId = GetInvaSectId(invSecAndConSwiId);
			invaSectState = GetPhySecCurMergeState(invaSectId);
			devFLockState = GetPhySecFLockState(invaSectId);
			fLockType = GetPhySecFLockType(invaSectId);
			devLockState = GetPhySecLockState(invaSectId);
			devJumpLockState = GetPhySecJumpLockState(invaSectId);
			chPhySecLogLockState = PhySecLogLockStateCheck(invaSectId);

			/* 检查侵限区段是否占用或封锁*/
			if ((SECTION_OCCUPY_YES == invaSectState)
				|| ((PHYSICAL_SECTION_FLOCK_YES == devFLockState) && (FUNC_SWITCH_ON != checkFlockFlag))
				|| (PHYSICAL_SECTION_LOCK_NO != devLockState)
				|| (PHYSICAL_SECTION_JUMP_LOCK_YES == devJumpLockState)
				|| (LOG_SECTION_LOGLOCK_NO != chPhySecLogLockState))
			{/*侵限区段占用或(检查封锁且封锁)、或者锁闭、跳跃锁闭*/

				condSwitSum = GetInvaSectsCondSwitSum(invSecAndConSwiId);

				if (0u < condSwitSum)
				{
					/*条件道岔位置检查*/
					for (j = 0u; j < condSwitSum; j++)
					{
						condSwitId = GetInvaSectsCondSwitId(invSecAndConSwiId, (INT16)j);
						condSwitStat = GetInvaSectsCondSwitStat(invSecAndConSwiId, (INT16)j);
						currSwitPos = GetSwitchCurPosition(condSwitId);

						if ((condSwitStat == currSwitPos)
							||
							(SWITCH_POSITION_SIKAI == currSwitPos)
							||
							(SWITCH_POSITION_MOVE == currSwitPos)
							||
							(SWITCH_POSITION_JICHA == currSwitPos))
						{/*条件道岔侵限*/
							condSwitchPosValid = CI_ERROR;
						}
						else
						{/*条件道岔未侵限*/
							condSwitchPosValid = CI_SUCCESS;
							break;
						}
					}

					if (condSwitchPosValid == CI_ERROR)
					{/*条件道岔满足侵限条件*/
						*pDevId = invaSectId;
						*pDevState = invaSectState;
						if ((SECTION_OCCUPY_YES != invaSectState) && (PHYSICAL_SECTION_FLOCK_YES == devFLockState) && (PHY_SEC_FLOCK_TYPE_SPKS == fLockType) && (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState)
							&& ((FUNC_SWITCH_ON == cFuncSwitchSpks) || ((FUNC_SWITCH_OFF == cFuncSwitchSpks) && (ROUTE_LEVEL_CBTC == cRouteLevel))))
						{/*侵限区段未占用且封锁且是由于SPKS按下导致的封锁，且SPKS重开开关打开或关闭但进路为CBTC，在SPKS恢复后可自动重开*/
							reVal = CI_ROUTE_RECOVER_ERR;
						}
						else
						{/*除区段SPKS按下侵限成立外的其他条件导致的侵限成立的场景，不可重开*/
							reVal = CI_ERROR;
						}
					}
					else
					{/*条件道岔不满足侵限条件*/
						;
					}
				}
				else
				{/*无道岔检查项,无岔侵限条件条件成立*/
					*pDevId = invaSectId;
					*pDevState = invaSectState;
					if ((SECTION_OCCUPY_YES != invaSectState) && (PHYSICAL_SECTION_FLOCK_YES == devFLockState) && (PHY_SEC_FLOCK_TYPE_SPKS == fLockType) && (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState)
						&& ((FUNC_SWITCH_ON == cFuncSwitchSpks) || ((FUNC_SWITCH_OFF == cFuncSwitchSpks) && (ROUTE_LEVEL_CBTC == cRouteLevel))))
					{/*侵限区段未占用且封锁且是由于SPKS按下导致的封锁，且SPKS重开开关打开或关闭但进路为CBTC，在SPKS恢复后可自动重开*/
						reVal = CI_ROUTE_RECOVER_ERR;
					}
					else
					{/*除区段SPKS按下侵限成立外的其他条件导致的侵限成立的场景，不可重开*/
						reVal = CI_ERROR;
					}
				}

				if (CI_ERROR == reVal)
				{/*除区段SPKS按下侵限成立外的其他条件导致的侵限成立的场景，不可重开，该侵限区段及条件道岔满足侵限条件*/
					/*不再继续检查其他侵限区段及条件道岔*/
					break;
				}
				else
				{/*该侵限区段及条件道岔满足侵限条件*/
					;
				}
			}
			else if ((SECTION_OCCUPY_NO == invaSectState)
				&& ((PHYSICAL_SECTION_FLOCK_NO == devFLockState) || (FUNC_SWITCH_ON == checkFlockFlag))
				&& (PHYSICAL_SECTION_LOCK_NO == devLockState)
				&& (PHYSICAL_SECTION_JUMP_LOCK_NO == devJumpLockState)
				&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState))
			{/*侵限区段未占用且(未封锁或不检查封锁)且未锁闭且未跳跃锁闭*/
				/*侵限区段检查通过*/
			}
			else
			{/*该侵限区段状态异常*/
				*pDevId = invaSectId;
				*pDevState = invaSectState;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	else
	{/*无侵限区段检查项*/
		reVal = CI_SUCCESS;
	}

	/*全部通过检查*/
	return reVal;
}


/*
功能描述:	保护区段关联的侵限敌对保护区段检查
输入参数:	UINT16 const overlapId	保护区段ID
输出参数:	UINT16 *pDevId		设备Id
				UINT8 *pDevState		设备状态
返回值: 		CI_SUCCESS			不满足侵限条件
				CI_ERROR			满足侵限条件
*/
UINT8 OverlapInvOppOverlapCheckup(UINT16 const overlapId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 invOppOverlapSum = 0u;	/*侵限敌对保护区段总数*/
	UINT16 invOppOverlapId = 0u;		/*侵限敌对保护区段ID*/
	UINT16 i = 0u; 					/* 循环变量 */
	UINT16 tmpDevId = 0u;			/*临时变量*/
	UINT8 tmpDevState = 0u;			/*临时变量*/

	UINT8 OvlpLockState = CI_SUCCESS;

	UINT8 reVal = CI_SUCCESS;

	/*检查pDevId是否为NULL*/
	if(NULL != pDevId)
	{		
		/*通过检查*/
		;
	}
	else
	{
		pDevId = &tmpDevId;
	}

	/*检查pDevState是否为NULL*/
	if(NULL != pDevState)
	{	
		/*通过检查*/
		;
	}
	else
	{
		pDevState = &tmpDevState;
	}

	invOppOverlapSum = GetOverlapInvOppOverlapSum(overlapId);

	/* 检查侵限状态 */
	if(0u < invOppOverlapSum)
	{
		/*开始检查*/
		for(i = 0u; i < invOppOverlapSum; i++)
		{
			invOppOverlapId = GetOverlapInvOppOverlapId(overlapId, i);

			OvlpLockState = GetOverlapLockState(invOppOverlapId);

			/* 检查侵限敌对保护区段是否锁闭*/
			if(CI_SUCCESS == OvlpLockState)
			{/*侵限敌对保护区段锁闭*/

				*pDevId = invOppOverlapId;
				*pDevState = OvlpLockState;
				reVal = CI_ERROR;

				break;
			}
			else
			{/*侵限敌对保护区段未锁闭*/
				;
			}
		}
	}
	else
	{/*无侵限敌对保护区段检查项*/
		reVal = CI_SUCCESS;
	}

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： 进路内区段锁闭状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteAllSecLockStateCheck(UINT16 const routeId,UINT8 checkState,UINT16 *pDevId,UINT8 *pDevState)
{
/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 secDirction = 0u;

/*进路数据*/
    /* 进路区段*/
    UINT8 const routeSectionSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const pRouteSectionDataBuf = GetRouteSectionData(routeId);
    UINT8 const routeDirction = GetRouteDirection(routeId);
    UINT8 reVal = CI_SUCCESS;

/* 区段占用检查 */
    if (0u == routeSectionSum) 
    {
        /*区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
			/*开始检查*/ 
		for (i = 0u; i<routeSectionSum; i++)
		{
			devId = pRouteSectionDataBuf[i].PhysicalSectionId;
			devState = GetPhySecLockState(devId);
			secDirction = GetPhySecLockDirection(devId);

			/* 需检查本区段 */ 
			if (devState == checkState)
			{
				if ((PHYSICAL_SECTION_LOCK_NO==checkState) || (PHYSICAL_SECTION_LOCK_START==checkState))
				{
					/*【未锁闭】与【上电锁闭】不检查方向*/
					/* 通过检查*/

				}
				else
				{
					/*其他锁闭需检查区段锁闭方向与进路一致*/
					if (secDirction == routeDirction)
					{
						/* 通过检查*/
						
					}
					else
					{
						/*状态不一致返回故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}
				}

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
			else
			{
			}
		}
    }
   
    /*全部通过检查*/
    return reVal;
}



/*
* 功能描述： 站台紧急关闭按钮无效检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteEsbVainCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
    /*进路等级*/
    UINT8 const routeLevel = GetRouteLevel(routeId);
    
    /*ESB数据*/
    UINT8 checkSum = 0u;
    UINT16 *dataIdBuf = NULL;
    
    /* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8  devCutState = 0u;
    UINT8 reVal = CI_SUCCESS;

    /*获取ESB数据*/
    if (routeLevel == ROUTE_LEVEL_BLOC)
    {
        checkSum = GetRouteBlocEsbSum(routeId);
        dataIdBuf = GetRouteBlocEsbIdBuf(routeId);
    }
    else if (routeLevel == ROUTE_LEVEL_CBTC)
    {
        checkSum = GetRouteCbtcEsbSum(routeId);
        dataIdBuf = GetRouteCbtcEsbIdBuf(routeId);
    }
    else
    {    
        checkSum = 0u;
        dataIdBuf = NULL;
    
    }
    
    /* 紧急按钮状态 */
    if ((0u == checkSum) || (NULL == dataIdBuf))
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
    else
    {
			/*开始检查*/    
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetEsbState(devId);
			devCutState = GetEsbCutState(devId);
			if ((devState == ESB_STATE_VALID_NO) || (ESB_CUT_YES == devCutState))
			{
				/* 无效*/

			}
			else
			{
				/*有效*/
				*pDevId = (UINT16) devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }
 
    /*全部通过检查*/
    return reVal;
}



/*
* 功能描述： s20_站台屏蔽门关闭检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RoutePsdCloseCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/*进路等级*/
    UINT8 const routeLevel = GetRouteLevel(routeId);
    
/*PSD数据*/
    UINT8 checkSum = 0u;
    UINT16 *dataIdBuf = NULL;
    
/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 reVal = CI_SUCCESS;
	UINT8 psdMutualLockState = 0u;

/*获取PSD数据*/
    if (routeLevel == ROUTE_LEVEL_BLOC)
    {
        checkSum = GetRouteBlocPsdSum(routeId);
        dataIdBuf = GetRouteBlocPsdIdBuf(routeId);
    }
    else if (routeLevel == ROUTE_LEVEL_CBTC)
    {
        checkSum = GetRouteCbtcPsdSum(routeId);
        dataIdBuf = GetRouteCbtcPsdIdBuf(routeId);
    }
    else
    {    
        checkSum = 0u;
        dataIdBuf = NULL;
    }


/* 站台屏蔽门状态 */
    if ((0u == checkSum) || (NULL == dataIdBuf))
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
    else
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPsdState(devId);
			psdMutualLockState = GetPsdMutualLockRemoveState(devId);
			if (( PSD_STATE_CLOSE == devState) || ( PSD_MUTUALLOCK_REMOVE_YES == psdMutualLockState)
				|| (PSD_ATS_MUTUALLOCK_REMOVE_YES == psdMutualLockState) || (PSD_ATS_AND_JD_MUTUALLOCK_REMOVE_YES == psdMutualLockState))
			{
				/* 站台安全屏蔽门关闭或互锁解除 */
	
			}
			else
			{
				/* 开启 */
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }
 
    /*全部通过检查*/
    return reVal;
}



/*
* 功能描述： 信号机ID数组开放状态检查
* 参数说明： UINT8 *dataIdBuf,    检查数据数组
*            UINT8 checkSum,    检查长度
*            UINT8 checkState,    检查长度
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 SignalBufOpenCloseStateCheck(UINT16 *dataIdBuf,UINT8 checkSum,UINT8 checkState,UINT16 *pDevId,UINT8 *pDevState)
{
/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 reVal = CI_SUCCESS;

/* 信号机开放状态检查 */
    if ((checkSum == 0u) || (dataIdBuf == NULL))
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
    else
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetSignalOpenCloseState(GetSignalCurColor(devId));
			if (devState == checkState)
			{
				/* 一致 */
				
			}
			else
			{
				/* 不一致 */
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
    }
  
    /*全部通过检查*/
    return reVal;
}




/*
* 功能描述： 进路内区段未征用状态检查
* 参数说明： UINT16 const routeId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteAllSecUseVainCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{    
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;

	UINT16 proSwitchId = 0u;/*防护道岔ID*/
	UINT16 proSwitchSecId = 0u;/*防护道岔所在区段ID*/
	UINT8 proSwitchRoutePos = 0u;/*进路要求的防护道岔位置*/

	UINT8 reVal = CI_ERROR;

	/* 进路区段*/
    UINT8 routeSecSum = 0u;/*进路内区段数量*/
    RoutePhysicalSectionStruct* pRouteSecDataBuf = NULL;/*进路内区段数据*/

	/*进路防护道岔*/
	UINT8 routeProSwitchSum = 0u;/*进路防护道岔数量*/
	RouteProtectSwitchStruct *pRouteProSwitchDataBuf = NULL;/*进路防护道岔数据*/

	UINT8 phyBelongCi = 0u;/*区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	UINT16 phySecProtectUseRouteId = 0u;
	UINT16 phySecUseRouteId =0u;
	UINT8 phySecType = 0U;

	routeSecSum =  GetRoutePhysicalSectionSum(routeId);/*获取进路内区段数量*/
	pRouteSecDataBuf = GetRouteSectionData(routeId);/*获取进路内区段数据*/

	routeProSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);/*获取进路防护道岔数量*/
	pRouteProSwitchDataBuf = GetRouteRelatedProtSwitchData(routeId);/*获取进路防护道岔数据*/

	/* 指针防空检查 */
    if ((0u==routeSecSum)||(NULL == pRouteSecDataBuf) || (NULL == pRouteProSwitchDataBuf))
    {
        /*区段数据错误或指针为空*/
        reVal = CI_ERROR;
    }
    else
    {
		reVal = CI_SUCCESS;
        /*开始检查进路内区段征用*/
		for (i = 0u; i<routeSecSum; i++)
		{
			devId = pRouteSecDataBuf[i].PhysicalSectionId;
			devState = GetPhySecUseState(devId);        

			phyBelongCi = GetPhySecBelongCiId(devId);/*获取区段所属联锁*/
			commState = GetLocalCiAndOtherCiTransSta(phyBelongCi);/*本联锁与其它联锁通信通信状态*/

			if ((localCi !=phyBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*如果区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查该信号机封锁状态*/
			}
			else
			{
				/* 需检查本区段 */ 
				if (PHYSICAL_SECTION_USING_NO == devState)
				{
					/* 通过检查*/
				
				}
				else
				{
					phySecProtectUseRouteId = GetPhySecProtectUseRouteId(devId);
					phySecUseRouteId = GetPhySecUseRouteId(devId);
					phySecType = GetPhySecType(devId);
					if ((0U == phySecUseRouteId) && (0U < phySecProtectUseRouteId) && (PHYSICAL_SEC_TYPE_SWITCH == phySecType))
					{/*有岔区段被其他进路防护征用*/
						reVal = CheckPhysecUseState(devId, routeId);/*检查该物理区段包含道岔的征用位置*/
					}
					else
					{
						reVal = CI_ERROR;
					}

					if(CI_SUCCESS != reVal)
					{
						/*状态不一致返回故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						break;
					}
				}
			}
		}
    }

	/*检查进路防护道岔所在区段的征用*/
	if (CI_SUCCESS == reVal)
	{
		for (i = 0u; i<routeProSwitchSum; i++)
		{
			proSwitchId = pRouteProSwitchDataBuf[i].ProtectSwitchId;/*防护道岔id*/
			proSwitchRoutePos =  pRouteProSwitchDataBuf[i].ProtectPosition;/*进路要求的防护道岔位置*/
			proSwitchSecId = GetSwitchPhySectionId(proSwitchId);/*获取防护道岔所在区段id*/
			devState = GetPhySecUseState(proSwitchSecId); /*获取防护道岔所在区段征用状态*/

			phyBelongCi = GetPhySecBelongCiId(proSwitchSecId);/*获取区段所属联锁*/
			commState = GetLocalCiAndOtherCiTransSta(phyBelongCi);/*本联锁与其它联锁通信通信状态*/

			if ((localCi !=phyBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*如果区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查该信号机封锁状态*/
			}
			else
			{
				/* 需检查本区段 */ 
				if (PHYSICAL_SECTION_USING_NO == devState)
				{
					/* 通过检查*/
				}
				else
				{
					phySecUseRouteId = GetPhySecUseRouteId(proSwitchSecId);
					phySecProtectUseRouteId = GetPhySecProtectUseRouteId(proSwitchSecId);
					if ((0U <phySecUseRouteId) || (0U<phySecProtectUseRouteId))
					{
						reVal = CheckPhyUseSecCanOtherUse(proSwitchId, proSwitchRoutePos);
					}
					else
					{
						reVal = CI_ERROR;
					}
				
					/*若返回失败，则退出*/
					if(CI_SUCCESS != reVal)
					{
						/*状态不一致返回故障状态*/
						*pDevId = proSwitchSecId;
						*pDevState = devState;
						break;
					}
				}
			}
		}
	}
 
    return reVal;
}



/*
* 功能描述： 部分进路内区段未征用状态检查
* 参数说明： UINT16 const routeId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 HalfRouteAllSecUseVainCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;

	UINT8 reVal = CI_ERROR;

	/* 进路区段*/
	UINT8 phySecSum = 0u;/*进路内物理区段数量*/
	UINT16 szPhySecData[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };/*进路内物理区段数据*/

	UINT16 phySecProtectUseRouteId = 0u;
	UINT16 phySecUseRouteId = 0u;
	UINT16 phySecUseByLogRouteId = 0u;


	phySecSum = GetRouteHalfPhysicalSecData(routeId, szPhySecData);  /*获取进路部分锁闭物理区段总数*/

	/* 指针防空检查 */
	if ((0u == phySecSum) || (NULL == szPhySecData) )
	{
		/*区段数据错误或指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查进路内区段征用*/
		for (i = 0u; i < phySecSum; i++)
		{
			devId = szPhySecData[i];
			devState = GetPhySecUseState(devId);
			/* 需检查本区段 */
			if (PHYSICAL_SECTION_USING_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				phySecProtectUseRouteId = GetPhySecProtectUseRouteId(devId);
				phySecUseRouteId = GetPhySecUseRouteId(devId);
				phySecUseByLogRouteId = GetPhySecUseLogRouteId(devId);
				if (CI_SUCCESS == reVal)
				{
					if (0u == phySecProtectUseRouteId)
					{
						reVal = CI_ERROR;/*执行到此处phySecProtectUseRouteId为0说明运算错误，导向安全*/
					}
				}
				/*①当前区段被其他进路“进路征用”，则不能办理本进路*/
				if (CI_SUCCESS == reVal)
				{
					if ((0u < phySecUseRouteId) || (0u < phySecUseByLogRouteId))
					{
						reVal = CI_ERROR;
					}
				}
				/*②检查该区段当前道岔位置或期望动作位置是否与本进路要求的位置相同*/
				if (CI_SUCCESS == reVal)
				{
					reVal = CheckPhysecUseState(devId, routeId);
				}

				if (CI_SUCCESS != reVal)
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					break;
				}
			}

		}
	}

	/*检查进路防护道岔所在区段的征用*/
	if (CI_SUCCESS == reVal)
	{
		reVal = CheckProSwUseStateInHalfRoute(routeId, &devId, &devState);
		/*若返回失败，则退出*/
		if (CI_SUCCESS != reVal)
		{
			/*状态不一致返回故障状态*/
			*pDevId = devId;
			*pDevState = devState;

		}
	}

	return reVal;
}

/*
*函数功能：检查部分进路防护道岔所在区段的征用
*参数说明：const UINT16 routeId  进路ID
*返回值：0：失败
*        1：成功
*/
UINT8 CheckProSwUseStateInHalfRoute(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT16 proSwitchId = 0u;/*防护道岔ID*/
	UINT16 proSwitchSecId = 0u;/*防护道岔所在区段ID*/
	UINT8 proSwitchRoutePos = 0u;/*进路要求的防护道岔位置*/
	UINT8 switchCurPosition = 0u;
	UINT8 SwitchDrvPos = 0u;

	UINT8 phyBelongCi = 0u;/*区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/

	UINT16 phySecProtectUseRouteId = 0u;
	UINT16 phySecUseRouteId = 0u;
	UINT16 phySecUseByLogRouteId = 0u;


	/*进路防护道岔*/
	UINT8 routeProSwitchSum = 0u;/*进路防护道岔数量*/
	RouteProtectSwitchStruct szRouteProSwitchData[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };/*进路防护道岔数据*/
	

	if ((0U < routeId) && (ROUTE_SUM_MAX > routeId) && (NULL != pDevId) && (NULL != pDevState))
	{
		reVal = CI_SUCCESS;
		/*获取进路包含防护道岔信息*/
		routeProSwitchSum = GetRouteHalfProSwData(routeId, szRouteProSwitchData);/*获取进路防护道岔数量*/
		if (0U != routeProSwitchSum)
		{
			for (i = 0u; i < routeProSwitchSum; i++)
			{
				proSwitchId = szRouteProSwitchData[i].ProtectSwitchId;/*防护道岔id*/
				proSwitchRoutePos = szRouteProSwitchData[i].ProtectPosition;/*进路要求的防护道岔位置*/
				switchCurPosition = GetSwitchCurPosition(proSwitchId);
				proSwitchSecId = GetSwitchPhySectionId(proSwitchId);/*获取防护道岔所在区段id*/
				devState = GetPhySecUseState(proSwitchSecId); /*获取防护道岔所在区段征用状态*/

				/* 需检查本区段 */
				if (PHYSICAL_SECTION_USING_NO == devState)
				{
					/* 通过检查*/
					reVal = CI_SUCCESS;
				}
				else
				{
					phySecUseRouteId = GetPhySecUseRouteId(proSwitchSecId);
					phySecProtectUseRouteId = GetPhySecProtectUseRouteId(proSwitchSecId);
					if ((0u < phySecUseRouteId) || (0u < phySecProtectUseRouteId))
					{
						reVal = CI_SUCCESS;/*执行到了此处，必须保证这两个值至少一个大于0*/
					}
					else
					{
						reVal = CI_ERROR;
					}

					if (CI_SUCCESS == reVal)
					{
						/*检查当前道岔位置或道岔期望动作位置是否与本进路要求的防护道岔位置相同*/
						if (proSwitchRoutePos == switchCurPosition)
						{
							reVal = CI_SUCCESS;
						}
						else
						{
							/*检查该道岔驱动位置是否与这个进路要求的位置相同*/
							SwitchDrvPos = GetSwitchPreExpDrvPosition(proSwitchId);
							if ((SWITCH_POSITION_DINGWEI == proSwitchRoutePos) && (SWITCH_DRIVE_POS_DINGWEI == SwitchDrvPos))
							{
								reVal = CI_SUCCESS;
							}
							else if ((SWITCH_POSITION_FANWEI == proSwitchRoutePos) && (SWITCH_DRIVE_POS_FANWEI == SwitchDrvPos))
							{
								reVal = CI_SUCCESS;
							}
							else
							{
								reVal = CI_ERROR;
							}
						}

					}

					/*若返回失败，则退出*/
					if (CI_SUCCESS != reVal)
					{
						/*状态不一致返回故障状态*/
						*pDevId = proSwitchSecId;
						*pDevState = devState;
						break;
					}
				}

			}
		}
		else
		{
			reVal = CI_SUCCESS;  /*无防护道岔，返回成功*/
		}

	}
	else
	{
		/*返回失败*/
		reVal = CI_ERROR;
	}
	return reVal;
}



/*****************************************车辆段************************************************/

/*
* 功能描述： 检查进路中需要检查的区段是否除列检库的区段都空闲
* 参数说明： UINT16 routeId 进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
*	返回值： CI_ERROR
*            CI_SUCCESS
*/	
UINT8 CheckDTrainRoutePhySecOccupy(const UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
	UINT8 ii= 0u;
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	
	
	if (sectionSum == 0u) 
	{
	    reVal = CI_ERROR;
	}
	else
	{
		for(ii = 0u; ii < sectionSum; ii++)
		{
			if (((ROUTE_STOPCHECK_SET_YES == GetRouteStopCheckFlag(routeId)) &&
				(PHYSICAL_SECTION_LJK_YES == GetPhySecLjkFlag(pRouteSecStru[ii].PhysicalSectionId)) &&
				(PHYSICAL_STOPCHECK_SET_YES == GetPhySectionStopCheckFlag(pRouteSecStru[ii].PhysicalSectionId)))
				||(ROUTE_PHYSICALSECTION_CHECK_NO == pRouteSecStru[ii].CheckProperty))
			{ /*停止检查有效且为列检库区段且区段停止检查有效,或非联锁检查区段*/
			
			}
			else
			{
				devId = pRouteSecStru[ii].PhysicalSectionId;
				devState = GetPhySecCurMergeState(devId);
				if (SECTION_OCCUPY_YES == devState)
				{ /*区段占用*/

					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);

					reVal = CI_ERROR;
					break;
				}
				else
				{
				}
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查调车进路信号保持物理区段占用情况
* 参数说明： UINT16 routeId 进路号
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckDTrainKeepSigPhySecOccupy(const UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
	UINT16 outPhySecId = 0u; /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u; /*信号机内方第一区段ID*/
	UINT8 ii = 0u;
	UINT8 tempIndex = 0u;
	UINT16 devId = 0u; /*设备ID*/
	UINT8 devState = 0u; /*设备状态*/
	UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT8 signalType = 0u;	/*信号机点灯电路类型*/
	UINT8 signalCrossCloseType = 0u;  /*信号机调车跨压关灯类型*/
	UINT8 stopCheckflag = 0u;
	UINT8 RouteStopKeepCheckFlag = 0u;/*停止股道检查标志*/
	UINT8 PhySecLjkFlag = 0u;/*列检库区段标志*/
	UINT8 PhySectionStopCheckFlag =0u;/*区段停止检查标志*/

	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	startSignalId = GetRouteStartSignalId(routeId);   /*获取进路始端信号机ID*/
	signalCrossCloseType = GetSignalCrossCloseAttr(startSignalId);    /*获取信号机调车跨压关灯类型*/
	if ((sectionSum == 0u) || (pRouteSecStru == NULL))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if(CI_SUCCESS == reVal)
	{
		inPhySecId = pRouteSecStru[0].PhysicalSectionId; /*信号机内方第一物理区段ID*/
		outPhySecId = GetSignalOutFirstPhySecId(startSignalId); /*信号机外方第一物理区段ID*/
		devState = GetPhySecCurMergeState(inPhySecId);
		if (SECTION_OCCUPY_NO == devState)
		{ /*内方第一区段空闲*/

			devId = inPhySecId;
			devState = GetPhySecPreMergeState(inPhySecId);
			if (SECTION_OCCUPY_YES == devState)
			{ /*内方区段之前占用*/

				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);

				reVal = CI_ERROR;
			}
			if(CI_SUCCESS == reVal)
			{
				stopCheckflag = 0u;
				for(ii = 1u; ii < sectionSum; ii++)
				{
					RouteStopKeepCheckFlag = GetRouteStopKeepCheckFlag(routeId);
					PhySecLjkFlag = GetPhySecLjkFlag(pRouteSecStru[ii].PhysicalSectionId);
					PhySectionStopCheckFlag = GetPhySectionStopCheckFlag(pRouteSecStru[ii].PhysicalSectionId);
					if ((ROUTE_STOPCHECK_SET_YES == RouteStopKeepCheckFlag) &&
						(PHYSICAL_SECTION_LJK_YES == PhySecLjkFlag) &&
						(PHYSICAL_STOPCHECK_SET_YES == PhySectionStopCheckFlag))
					{ /*停止检查有效且为列检库区段且区段停止检查有效*/

						stopCheckflag = 1u;
					}

					if (ROUTE_PHYSICALSECTION_CHECK_NO == pRouteSecStru[ii].CheckProperty)
					{ /*非联锁检查区段*/
						stopCheckflag = 1u;
					}
					if(1u != stopCheckflag)
					{
						devId = pRouteSecStru[ii].PhysicalSectionId;
						devState = GetPhySecCurMergeState(devId);
						if (SECTION_OCCUPY_YES == devState)
						{ /*区段占用*/

							/* 记录故障码 */
							SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
							reVal = CI_ERROR;
							break;
						}
					}
					stopCheckflag = 0u;
				}
			}
		}
		else
		{ /*内方第一区段占用*/
			if (0u == outPhySecId)
			{/*外方区段不存在*/
				devState = SECTION_OCCUPY_YES;/*默认为占用*/
			}
			else
			{
				devId = outPhySecId;
				devState = GetPhySecCurMergeState(outPhySecId);
			}
			if (SECTION_OCCUPY_YES == devState)
			{ /*外方区段占用*/

				signalType = GetSignalType(startSignalId);	/*获取信号机点灯逻辑类型*/
				if (((SIGNAL_TYPE_JINKUCHUKU == signalType) || (SIGNAL_TYPE_TWO_JINKU_RGY == signalType) || (SIGNAL_TYPE_THREE_JINKU_YINDAO == signalType)) 
					&& (SIGNAL_CROSS_ClOSE_YES == signalCrossCloseType))
				{
					/*进库信号机，列车驶入即关灯*/

					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
					reVal = CI_ERROR;
				}
				else
				{
					/*记录第一个占用区段偏移*/
					tempIndex = 0u; 
					stopCheckflag = 0u;
					for(ii = 1u; ii < sectionSum; ii++)
					{
						RouteStopKeepCheckFlag = GetRouteStopKeepCheckFlag(routeId);
						PhySecLjkFlag = GetPhySecLjkFlag(pRouteSecStru[ii].PhysicalSectionId);
						PhySectionStopCheckFlag =  GetPhySectionStopCheckFlag(pRouteSecStru[ii].PhysicalSectionId);
						if ((ROUTE_STOPCHECK_SET_YES == RouteStopKeepCheckFlag) &&
							(PHYSICAL_SECTION_LJK_YES == PhySecLjkFlag) &&
							(PHYSICAL_STOPCHECK_SET_YES == PhySectionStopCheckFlag))
						{ /*停止检查有效且为列检库区段且区段停止检查有效*/

							stopCheckflag = 1u;
						}

						if (ROUTE_PHYSICALSECTION_CHECK_NO == pRouteSecStru[ii].CheckProperty)
						{ /*非联锁检查区段*/

							stopCheckflag = 1u;
						}
						if(1u != stopCheckflag)
						{						
							devId = pRouteSecStru[ii].PhysicalSectionId;
							devState = GetPhySecCurMergeState(devId);
							if (SECTION_OCCUPY_YES == devState)
							{ /*区段占用*/
								if ((ii - tempIndex) == 1u)
								{
									/*连续占用*/
									tempIndex = ii;
								}
								else
								{
									/*不连续占用*/

									/* 记录故障码 */
									SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
									reVal = CI_ERROR;
									break;
								}
							}
							else
							{
								/*区段空闲*/
							}
						}
						stopCheckflag = 0u;
					}
					if(CI_SUCCESS == reVal)
					{
						reVal = RouteOutfirstPhySecSwiPosCheck(routeId);/*进路外方第一区段道岔位置检查，若道岔位置与条件道岔位置不同，则返回错误*/
						if(CI_SUCCESS == reVal)
						{
							/*什么也不做*/
						}
						else
						{
							if (0u == outPhySecId)
							{/*外方区段不存在*/
								devState = SECTION_OCCUPY_YES;/*默认为占用*/
							}
							else
							{
								devState = GetPhySecCurMergeState(outPhySecId);
							}
							SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,outPhySecId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
						}
					}
				}
			}
			else
			{ /*外方区段空闲*/
				if ( SECTION_OCCUPY_YES == GetPhySecPreMergeState(outPhySecId))
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,inPhySecId,ETYPE_PS_MERGY_OCU_STATE,SECTION_OCCUPY_YES,sendLevel);
					reVal = CI_ERROR;
				}
				if(CI_SUCCESS == reVal)
				{
					stopCheckflag = 0u;
					for(ii = 0u; ii < sectionSum; ii++)
					{
						RouteStopKeepCheckFlag = GetRouteStopKeepCheckFlag(routeId);
						PhySecLjkFlag = GetPhySecLjkFlag(pRouteSecStru[ii].PhysicalSectionId);
						PhySectionStopCheckFlag =  GetPhySectionStopCheckFlag(pRouteSecStru[ii].PhysicalSectionId);
						if ((ROUTE_STOPCHECK_SET_YES == RouteStopKeepCheckFlag) &&
							(PHYSICAL_SECTION_LJK_YES == PhySecLjkFlag) &&
							(PHYSICAL_STOPCHECK_SET_YES == PhySectionStopCheckFlag))
						{ /*停止检查有效且为列检库区段且区段停止检查有效*/
							stopCheckflag = 1u;
						}

						if (ROUTE_PHYSICALSECTION_CHECK_NO == pRouteSecStru[ii].CheckProperty)
						{ /*非联锁检查区段*/
							stopCheckflag = 1u;
						}
						if(1u != stopCheckflag)
						{						
							devId = pRouteSecStru[ii].PhysicalSectionId;
							devState = GetPhySecCurMergeState(devId);
							if (SECTION_OCCUPY_YES == devState)
							{ /*区段占用*/

								/* 记录故障码 */
								SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
								reVal = CI_ERROR;
								break;
							}
						}
						stopCheckflag=0u;
					}
				}
			}
		}
	}
	else
	{
		/*什么也不做*/
	}
	return reVal;
}


/*
* 功能描述： 非进路道岔位置和动作有效性检查
* 参数说明： 
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 NonRouteSwitchPosMovValCheck(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	/* 进路道岔 */
	UINT8 const checkSum = GetNonRouteSwitchSumById(nonRouteId);
	NonRouteSwitchStruct* const dataIdBuf = GetNonRouteSwitchStructBufById(nonRouteId);

/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8  switchPos = 0u;

    UINT8   switchMoveState = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 checkResult = 0u;

/*联锁检查*/
    if ((0u == checkSum) || (NULL == dataIdBuf))
    {
        /*无检查项*/
        reVal = CI_SUCCESS;
    }
    else
    {
        /*开始检查*/
		/* 进路内所有道岔位置正确 且不为【挤岔】 或位置不正确道岔可动作*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].SwitchPos;
			if (devState == switchPos)
			{
				/* 道岔位置正确 */
				/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
				checkResult = checkSwtLastValDrvPosStayorNot(devId,switchPos);
				if (CI_SUCCESS == checkResult)
				{
				}
				else
				{
					reVal = CI_ERROR;
				}
		
			}
			else if (SWITCH_POSITION_SIKAI == devState)
			{
				/*四开*/

				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_NON_SWITCH_MOVE,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA == devState)
			{
				/*挤岔*/

				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_NON_SWITCH_MOVE,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
			}
			else 
			{
				/* 道岔位置不正确 */
				switchMoveState = GetSwitchMoveValidState(devId,SWITCH_OPER_NO_DANCAO,sendLevel);
				if (switchMoveState == CI_SUCCESS)
				{
					/*道岔可动*/
			
				} 
				else
				{
					/*道岔位置不正确 且 道岔不可动作*/

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

    /*全部通过检查*/
    return reVal;
}

/*
* 功能描述： 非进路关联防护道岔位置和动作有效性检查
* 参数说明： 
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 NonRouteRelProSwiPosMovValCheck(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	/* 进路道岔 */
	UINT8 const protectSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId);
	NonRouteProtectSwitchStruct* const protectSwitchData = GetNonRouteRelatedProtSwitStru(nonRouteId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8  switchPos = 0u;

	UINT8   switchMoveState = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 checkResult = 0u;

	/*联锁检查*/
	if ((0u == protectSwitchSum) || (NULL == protectSwitchData))
	{
		/*无检查项*/
		reVal = CI_SUCCESS;
	}
	else
	{
		/*开始检查*/
		/* 非进路关联防护道岔位置正确 且不为【挤岔】 或位置不正确道岔可动作*/
		for (i = 0u; i<protectSwitchSum; i++)
		{
			devId = protectSwitchData[i].ProtectSwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = protectSwitchData[i].ProtectPosition;
			if (devState == switchPos)
			{
				/* 道岔位置正确 */
				/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
				checkResult = checkSwtLastValDrvPosStayorNot(devId,switchPos);
				if (CI_SUCCESS == checkResult)
				{
				}
				else
				{
					reVal = CI_ERROR;
				}

			}
			else if (SWITCH_POSITION_SIKAI == devState)
			{
				/*四开*/

				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_NON_SWITCH_MOVE,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA == devState)
			{
				/*挤岔*/

				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_NON_SWITCH_MOVE,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
			}
			else 
			{
				/* 道岔位置不正确 */
				switchMoveState = GetSwitchMoveValidState(devId,SWITCH_OPER_NO_DANCAO,sendLevel);
				if (switchMoveState == CI_SUCCESS)
				{
					/*道岔可动*/

				} 
				else
				{
					/*道岔位置不正确 且 道岔不可动作*/

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

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 检查进路道岔正确
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
UINT8 CheckRouteSwitchPosRight(const UINT16 routeId)
{
	UINT8 ii = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 switchSum = 0u;                                      /*道岔总数*/
	RouteSwitchStruct* pRouteSwitchStru = NULL;               /*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 			              /*防护道岔数目*/
	RouteProtectSwitchStruct* routeProtectSwitchStru = NULL;  /*防护道岔数据*/

	switchSum = GetRouteSwitchSum(routeId);                             /*获得进路道岔总数*/
	pRouteSwitchStru = GetRouteSwitchData(routeId);                     /*获得进路道岔数据*/
	routeProtectSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);   /*获得进路关联防护道岔总数*/
	routeProtectSwitchStru = GetRouteRelatedProtSwitchData(routeId); /*获得进路关联防护道岔数据*/


	if (NULL == pRouteSwitchStru )
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		for (ii = 0u; ii < switchSum; ii++)
		{
			if (pRouteSwitchStru[ii].SwitchPosition != GetSwitchCurPosition(pRouteSwitchStru[ii].SwitchId))
			{ /*道岔位置不在规定位置*/
				reVal = CI_ERROR;
				break;
			}
		}

		if (CI_SUCCESS == reVal)
		{
			if (NULL == routeProtectSwitchStru)
			{
				reVal = CI_ERROR;
			} 
			else
			{
				reVal = CI_SUCCESS;
				for (ii = 0u; ii < routeProtectSwitchSum; ii++)
				{
					if (routeProtectSwitchStru[ii].ProtectPosition != GetSwitchCurPosition(routeProtectSwitchStru[ii].ProtectSwitchId))
					{ /*防护道岔不在规定防护位置*/
						reVal = CI_ERROR;
						break;
					}
				}
			}
		} 
		else
		{
			reVal = CI_ERROR;
		}
	}
	return reVal;
}

/*
功能描述:     检查进路带动道岔是否需要被驱动
输入参数:	const UINT16 routeId 进路ID
输出参数: 	无
返回值:       	SWITCH_NEED_DRIV_TRUE:需要被驱动
				SWITCH_NEED_DRIV_FALSE:无需被驱动   
*/
UINT8 CheckRoutAssoSwitNeedDriv(const UINT16 routeId)
{
    UINT8 reVal = SWITCH_NEED_DRIV_FALSE;/*带动道岔是否需要被驱动的标志*/
	UINT8 timeState = CI_TIME_OUT;/*超时标志*/

	UINT16 switchId = 0u; /*道岔ID*/
	UINT8 expectSwitchPos = 0u; /*道岔位置*/
	UINT8 currentSwitchPos = 0u; /*道岔位置*/
	UINT8 assocSwitchSum = 0u; /*道岔数目*/
	RouteAssocSwitchStruct routeAssocSwitchStru; /*道岔数据*/
    UINT8 ii = 0u;/*循环变量*/
    UINT8 switchMoveValidState = CI_ERROR;/*道岔可移动状态*/
	UINT8 RouteAssoSwitSingOperStat = SWITCH_SINGLE_OPERATED_FALSE; /*进路带动道岔组单操标志*/
	UINT8 RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_TRUE;/*带动道岔是否可被驱动的标志*/
	UINT8 switchFengsuoState = 0u;/*道岔封锁状态*/
	UINT16 phySecId = 0u;/*道岔物理区段id*/
	UINT8 phyFengsuoState = 0u;/*道岔物理区段封锁状态*/
	UINT32 RouteXuanPaiStartCycNum = 0U;
	UINT32 SystemParaRouteXuanPaiCyc = 0U;
	/*检查进路选排是否即将超时,
	因为驱动带动道岔可能在进路选排超时时间内不能完成,
	所以在超时前1周期不再驱动带动道岔,
	以避免进路选排超时*/
	RouteXuanPaiStartCycNum = GetRouteXuanPaiStartCycNum(routeId);
	SystemParaRouteXuanPaiCyc = GetSystemParaRouteXuanPaiCyc();
	timeState = SystemOverTimeCheck(RouteXuanPaiStartCycNum, (SystemParaRouteXuanPaiCyc - 1U));

	/*获取进路带动道岔数目*/
	assocSwitchSum = GetRouteAssocSwitchSum(routeId); 

	/*获取带动道岔状态*/
	GetRoutAssoSwitSingOperStat(routeId, &RouteAssoSwitSingOperStat);

	if(SWITCH_SINGLE_OPERATED_FALSE == RouteAssoSwitSingOperStat)
	{/*在本次选排进路过程中,道岔还未被单操过*/
		for(ii = 0u; ii < assocSwitchSum; ii++)
		{
			GetRouteAssocSwitchData(routeId, ii, &routeAssocSwitchStru);
			switchId = routeAssocSwitchStru.SwitchId;
			expectSwitchPos = routeAssocSwitchStru.SwitchPosition;
			currentSwitchPos = GetSwitchCurPosition(switchId);
			switchFengsuoState = GetSwitchFLockState(switchId);
			phySecId = GetSwitchPhySectionId(switchId);/*获取道岔物理区段id*/
			phyFengsuoState = GetPhySecFLockState(phySecId);/*获取道岔物理区段封锁状态*/
	        if(currentSwitchPos != expectSwitchPos)
			{/*道岔不在指定位置*/

				if(SWITCH_POSITION_JICHA == currentSwitchPos)
				{/*道岔处于挤岔位置*/
					/*带动道岔不可被驱动*/
					RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_FALSE;
					/*道岔无需被驱动*/
					reVal = SWITCH_NEED_DRIV_FALSE;

					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, 
						CI_DEVICE_TYPE_SWITCH, 
						switchId, 
						ETYPE_SWT_POSTION_STATE, 
						currentSwitchPos, 
						ESEND_LEVEL_ZERO); 
				}
				else if (SWITCH_POSITION_SIKAI == currentSwitchPos)
				{
					/*道岔处于四开位置*/
					/*带动道岔不可被驱动*/
					RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_FALSE;
					/*道岔无需被驱动*/
					reVal = SWITCH_NEED_DRIV_FALSE;
					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, 
						CI_DEVICE_TYPE_SWITCH, 
						switchId, 
						ETYPE_SWT_POSTION_STATE, 
						currentSwitchPos, 
						ESEND_LEVEL_ZERO); 
				}
				else
				{
					switchMoveValidState = GetSwitchMoveValidState(switchId,SWITCH_OPER_NO_DANCAO, ESEND_LEVEL_ZERO);

					if(CI_SUCCESS == switchMoveValidState)
					{/*道岔可以转动*/
						/*道岔需要被驱动*/
						reVal = SWITCH_NEED_DRIV_TRUE;
		            }
		            else
		            {
						/*带动道岔不可被驱动*/
						RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_FALSE;
						/*道岔无需被驱动*/
						reVal = SWITCH_NEED_DRIV_FALSE;
		            }
	            }
			}
			else
			{/*道岔在指定位置*/
				/*无行为*/
				;
			}

			/*检查带动道岔封锁状态*/
			if (SWITCH_NEED_DRIV_TRUE == reVal)
			{
				if (SWITCH_LOCK_FENGSUO_NO == switchFengsuoState)
				{
					/*未封锁，不作处理*/
				}
				else
				{
					reVal = SWITCH_NEED_DRIV_FALSE;
					RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_FALSE;
					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, 
						CI_DEVICE_TYPE_SWITCH, 
						switchId, 
						ETYPE_SWT_FLOCK_STATE, 
						switchFengsuoState, 
						ESEND_LEVEL_ZERO); 
				}
			}

			/*检查带动道岔所在物理区段封锁状态*/
			if (SWITCH_NEED_DRIV_TRUE == reVal)
			{
				if (PHYSICAL_SECTION_FLOCK_NO == phyFengsuoState)
				{

				}
				else
				{
					reVal = SWITCH_NEED_DRIV_FALSE;
					RouteAssocSwitchCanBeDrived = SWITCH_CAN_BE_DRIVED_FALSE;
					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, 
						CI_DEVICE_TYPE_PHYSEC, 
						phySecId, 
						ETYPE_PS_FLOCK_STATE, 
						phyFengsuoState, 
						ESEND_LEVEL_ZERO); 
				}
			}

			if(SWITCH_CAN_BE_DRIVED_TRUE == RouteAssocSwitchCanBeDrived)
			{/*带动道岔可被驱动*/
				/*无行为*/
				;
			}
			else
			{/*带动道岔组不可被驱动*/
				/*退出带动道岔组的遍历*/
				break;
			}
		}

		if(CI_TIME_OUT == timeState)
		{/*选排进路即将超时*/
			/*道岔无需被驱动*/		
			reVal = SWITCH_NEED_DRIV_FALSE;
		}
		else
		{/*选排进路未超时*/
			/*无行为*/
			;
		}
	}
	else
	{/*带动道岔已被单操过*/
		/*无行为*/
		;
	}

    return reVal;
}

/*
* 功能描述： 检查非进路中信号机未断丝
* 参数说明： 
* 返回值  ： 0：	有信号机断丝
*            1:   	非进路中信号机均未断丝
*/
UINT8 CheckNonRouteSignalNoBreak(UINT8 nonRouteId,UINT8 functionId, UINT8 sendLevel)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((sigSum == 0u) || (pSigIdBuf == NULL))
	{
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL,devId, ETYPE_SIG_START_OPEN_STATE, devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for (ii = 0u; ii < sigSum; ii++)
		{
			devId = pSigIdBuf[ii];
			devState = GetSignalCurColor(devId); /*获取信号机当前颜色*/
			if (SIGNAL_SHOWCOLOUR_REDBREAK == devState)
			{ /*信号机断丝*/
			
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL,devId, ETYPE_SIG_START_OPEN_STATE, devState,sendLevel);

				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路中是否有信号机被封锁
* 参数说明： 
* 返回值  ： 0：	有信号机被封锁
*            1:   	进路中信号机均未被封锁
*/
UINT8 CheckNonRouteSignalFengSuo(UINT8 nonRouteId,UINT8 functionId, UINT8 sendLevel)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((sigSum == 0u) || (pSigIdBuf == NULL))
	{
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL,devId, ETYPE_SIG_FLOCK_STATE, devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for (ii = 0u; ii < sigSum; ii++)
		{
			devId = pSigIdBuf[ii];
			devState = GetSignalFLockState(devId);
			if (SIGNAL_FENGSUO_YES == devState)
			{ /*信号机封锁*/
			
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL,devId, ETYPE_SIG_FLOCK_STATE, devState,sendLevel);

				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路中信号机之前驱动状态
* 参数说明： 
* 返回值  ： 0：	有信号机被封锁
*            1:   	进路中信号机均未被封锁
*/
UINT8 CheckNonRouteSignalPreDrvOpen(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((sigSum == 0u) || (pSigIdBuf == NULL))
	{
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for (ii = 0u; ii < sigSum; ii++)
		{
			devId = pSigIdBuf[ii];
			devState = GetSignalOpenCloseState(GetSignalPreDriveColor(devId));
			if (SIGNAL_CLOSE == devState)
			{ /*之前周期驱动关闭*/
				
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);

				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路中的敌对信号是否成立
* 参数说明： 
*	返回值：CI_ERROR：敌对成立
*           CI_SUCCESS: 敌对不成立
*/				
UINT8 CheckNonRouteEnemySignal(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 enemySigSum = 0u; /*敌对信号总数*/
	UINT16 enemySwitId = 0u; /*敌对道岔ID*/
	UINT8 enemyFlag = 0u; /*敌对标志*/
	NonRouteEnemySignalStruct *pEnemySigStru = NULL;/*敌对信号结构体*/
	UINT8 ii = 0u;
	UINT8 jj = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/	
	UINT8 reVal = CI_ERROR;

	enemySigSum = GetNonRouteEnemySignalSumById(nonRouteId); /*获取非进路敌对信号总数*/
	pEnemySigStru = GetNonRouteEnemySigStruBufById(nonRouteId); /*获取非进路敌对信号结构体数据*/
		
	if (NULL == pEnemySigStru)
	{
	    reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < enemySigSum; ii++)
		{
			devId = pEnemySigStru[ii].EnemySigId;
			devState = GetSignalOpenCloseState(GetSignalCurColor(devId));
			if (SIGNAL_OPEN == devState)
			{ /*敌对信号开放*/
			
				if (0u == pEnemySigStru[ii].SwitchSum)
				{ /*无敌对道岔*/
				
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);

					reVal = CI_ERROR;
				}
				else
				{ /*有条件敌对*/
				
					if (NULL == pEnemySigStru[ii].EnemySwitchStru)
					{
						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);

						reVal = CI_ERROR;
					}
					else
					{
						enemyFlag = 0u;
						for (jj = 0u; jj < pEnemySigStru[ii].SwitchSum; jj++)/*遍历条件道岔*/
						{
							enemySwitId = pEnemySigStru[ii].EnemySwitchStru[jj].SwitchId;
							
							if ((GetSwitchCurPosition(enemySwitId) != pEnemySigStru[ii].EnemySwitchStru[jj].SwitchPos) &&
								(GetSwitchCurPosition(enemySwitId) != SWITCH_POSITION_MOVE))
							{ /*道岔未在敌对位置*/
							
								enemyFlag = 1u;
							}
						}
						
						if(0u == enemyFlag)
						{
							/* 记录故障码 */
							SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);

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

	return reVal;
}
 

/*
* 功能描述： 检查非进路物理区段征用
* 参数说明： 
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckNonRoutePhySecUsing(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	UINT8 nonRouteProSwitchSum = 0u;	/*非进路防护道岔数量*/
	NonRouteProtectSwitchStruct* pNonRouteProSwitchData = NULL;	/*非进路防护道岔数据*/
	UINT16 switchId = 0u;/*道岔ID*/

	sectionSum = GetNonRoutePhySectionSumById(nonRouteId); /*获得非进路包含的区段数目*/
	pPhySecStruBuf = GetNonRoutePhySecStruBufById(nonRouteId); /*获取非进路区段数据*/

	nonRouteProSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId);/*获取非进路防护道岔数量*/
	pNonRouteProSwitchData = GetNonRouteRelatedProtSwitStru(nonRouteId);/*获取非进路防护道岔数据*/
	

	if ((0u == sectionSum) || (NULL == pPhySecStruBuf))
	{
		SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_USE_STATE,devState,sendLevel); 
	    reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		for(ii = 0u; ii < sectionSum; ii++)
		{
			devId = pPhySecStruBuf[ii].PhySectionId;
			devState = GetPhySecUseState(devId);
			if (PHYSICAL_SECTION_USING_NO != devState)
			{ /*区段征用*/
			
				/*记录故障码*/
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_USE_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}
	
	/*检查非进路防护道岔所在区段征用*/
	if (CI_SUCCESS == reVal)
	{
		for (ii=0u;ii<nonRouteProSwitchSum;ii++)
		{
			switchId = pNonRouteProSwitchData[ii].ProtectSwitchId;
			devId = GetSwitchPhySectionId(switchId);
			devState = GetPhySecUseState(devId);
			if (PHYSICAL_SECTION_USING_NO != devState)
			{ /*区段征用*/

				/*记录故障码*/
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_USE_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}
	

	return reVal;
}


/*
* 功能描述： 检查非进路中的是否所有区段都未锁闭
* 参数说明： UINT16 routeId 进路号
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckNonRoutePhySectionUnLock(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sectionSum = GetNonRoutePhySectionSumById(nonRouteId); /*获得非进路包含的区段数目*/
	pPhySecStruBuf = GetNonRoutePhySecStruBufById(nonRouteId); /*获取非进路区段数据*/
	
	
	if ((sectionSum == 0u) || (pPhySecStruBuf == NULL))
	{
		SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_LOCK_STATE,devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for(ii = 0u; ii < sectionSum; ii++)
		{
			devId = pPhySecStruBuf[ii].PhySectionId;
			devState = GetPhySecLockState(devId);
			if (devState != PHYSICAL_SECTION_LOCK_NO)
			{ /*进路区段不是未锁闭*/
			
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_LOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路中是否有道岔被封锁
* 参数说明： 
* 返回值  ： 0：	有道岔被封锁
*            1:   	进路中道岔均未被封锁
*/
UINT8 CheckNonRouteSwitchFengSuo(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteSwitchStruct* pNonRouteSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	switchSum = GetNonRouteSwitchSumById(nonRouteId); /*非进路道岔总数*/
	pNonRouteSwitchStru = GetNonRouteSwitchStructBufById(nonRouteId); /*非进路道岔数据*/
	
	if ((switchSum == 0u) || (pNonRouteSwitchStru == NULL))
	{
	    reVal = CI_SUCCESS;
	}
	else
	{
		for (ii = 0u; ii < switchSum; ii++)
		{
			devId = pNonRouteSwitchStru[ii].SwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_YES == devState)
			{ /*有道岔封锁*/

				/* 记录故障码 */        
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;	
				break;
			}
		}
	}
	
	return reVal;	
}

/*
* 功能描述： 检查非进路关联防护道岔是否防护锁闭
* 参数说明： 
* 返回值  ： 0：	有防护道岔未防护锁闭
*            1:   	所有防护道岔已防护锁闭
*/
UINT8 CheckNonRouteRelProSwiLockSta(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 protectSwitchSum = 0u; /*防护道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*防护道岔数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	protectSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路防护道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路防护道岔数据*/

	if (NULL == pNonRouteProtectSwitchStru)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < protectSwitchSum; ii++)
		{
			devId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
			devState = GetSwitchLockStatus(devId);
			if ((SWITCH_LOCK_STATUS_PROTECT == devState) || (SWITCH_LOCK_STATUS_DAP == devState))
			{
				/*道岔已【防护锁闭】或【单锁且防护锁闭】*/
			}
			else
			{   /*道岔未【防护锁闭】或【单锁且防护锁闭】*/

				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_LOCK_STATUS,SWITCH_LOCK_STATUS_PROTECT_NO,sendLevel); 
				/* 失败返回 */
				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;	
}

/*
* 功能描述： 检查非进路中是否有道岔引导总锁
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： 0：	有道岔被封锁
*            1:   	进路中道岔均未引导总锁
*/
UINT8 CheckNonRouteSwitchYinSuo(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteSwitchStruct* pNonRouteSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	switchSum = GetNonRouteSwitchSumById(nonRouteId); /*非进路道岔总数*/
	pNonRouteSwitchStru = GetNonRouteSwitchStructBufById(nonRouteId); /*非进路道岔数据*/
	
	if ((switchSum == 0u) || (pNonRouteSwitchStru == NULL))
	{
	    reVal = CI_SUCCESS;
	}
	else
	{
		for (ii = 0u; ii < switchSum; ii++)
		{        
			devId = pNonRouteSwitchStru[ii].SwitchId;
			devState = GetSwitchYLockState(devId);
			if (SWITCH_LOCK_YINZONG_YES == devState)
			{ /*有道岔引导总锁*/

				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}
	
	return reVal;	
}

/*
* 功能描述： 检查非进路关联防护道岔是否引导总锁
* 参数说明： const UINT16 routeId, 进路ID
*			 UINT8 functionId,函数Id
*			 UINT8 sendLevel,发送级别
* 返回值  ： 0：	有道岔被封锁
*            1:   	进路中道岔均未引导总锁
*/
UINT8 CheckNonRouteRelProSwiYinSuo(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 protectSwitchSum = 0u; /*道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	protectSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路道岔数据*/
	
	if (NULL == pNonRouteProtectSwitchStru)
	{
	    reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if(CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < protectSwitchSum; ii++)
		{        
			devId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
			devState = GetSwitchYLockState(devId);
			if (SWITCH_LOCK_YINZONG_YES == devState)
			{ /*有道岔引导总锁*/

				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}
	return reVal;	
}


/*
* 功能描述： 检查非进路中区段占用状态
* 参数说明： 
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckNonRoutePhySectionOccupy(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sectionSum = GetNonRoutePhySectionSumById(nonRouteId); /*获得非进路包含的区段数目*/
	pPhySecStruBuf = GetNonRoutePhySecStruBufById(nonRouteId); /*获取非进路区段数据*/
	
	if ((sectionSum == 0u) || (pPhySecStruBuf == NULL))
	{
		SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for(ii = 0u; ii < sectionSum; ii++)
		{
			devId = pPhySecStruBuf[ii].PhySectionId;
			devState = GetPhySecCurMergeState(devId);

			if (NONROUTE_SECTION_OCCUPY_CHECK_YES == pPhySecStruBuf[ii].CheckState)
			{
				if (devState != SECTION_OCCUPY_YES)
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
					reVal = CI_ERROR;
				}
			}
			else if (NONROUTE_SECTION_OCCUPY_CHECK_NO == pPhySecStruBuf[ii].CheckState)
			{
				if (devState != SECTION_OCCUPY_NO)
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
					reVal = CI_ERROR;
				}
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路中的是否所有区段都锁闭
* 参数说明： UINT16 routeId 进路号
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckNonRoutePhySectionLock(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_SUCCESS;

	sectionSum = GetNonRoutePhySectionSumById(nonRouteId); /*获得非进路包含的区段数目*/
	pPhySecStruBuf = GetNonRoutePhySecStruBufById(nonRouteId); /*获取非进路区段数据*/
	
	if ((sectionSum == 0u) || (pPhySecStruBuf == NULL))
	{
		SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_LOCK_STATE,devState,sendLevel);
	    reVal = CI_ERROR;
	}
	else
	{
		for(ii = 0u; ii < sectionSum; ii++)
		{
			devId = pPhySecStruBuf[ii].PhySectionId;
			devState = GetPhySecLockState(devId);
			if ((PHYSICAL_SECTION_LOCK_NORMAL == devState) &&
				(0u == GetPhySecRLockBelongRouteId(pPhySecStruBuf[ii].PhySectionId)))
			{ /*进路区段为正常锁闭且所属进路为0*/
			}
			else
			{ /*非进路区段锁闭错误*/
			
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_LOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}


/*
* 功能描述： 检查非进路道岔正确
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
UINT8 CheckNonRouteSwitchPosRight(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteSwitchStruct* pNonRouteSwitchStru = NULL; /*道岔数据*/
	UINT8 protectSwitchSum = 0u; /*防护道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*防护道岔数据*/

	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	switchSum = GetNonRouteSwitchSumById(nonRouteId); /*非进路道岔总数*/
	pNonRouteSwitchStru = GetNonRouteSwitchStructBufById(nonRouteId); /*非进路道岔数据*/
	protectSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路防护道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路防护道岔数据*/
	
	if (NULL == pNonRouteSwitchStru)
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if(CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < switchSum; ii++)
		{
			devId = pNonRouteSwitchStru[ii].SwitchId;
			devState = GetSwitchCurPosition(devId);
			if (pNonRouteSwitchStru[ii].SwitchPos != devState)
			{ /*道岔位置不在规定位置*/

				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

				reVal = CI_ERROR;
				break;
			}
		}

		if (CI_SUCCESS == reVal)
		{
			if (NULL == pNonRouteProtectSwitchStru)
			{
				/*指针为空*/
				reVal = CI_ERROR;
			}
			else
			{
				reVal = CI_SUCCESS;
			}

			if(CI_SUCCESS == reVal)
			{
				for (ii = 0u; ii < protectSwitchSum; ii++)
				{
					devId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
					devState = GetSwitchCurPosition(devId);
					if (pNonRouteProtectSwitchStru[ii].ProtectPosition != devState)
					{ /*道岔位置不在规定位置*/

						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 

						reVal = CI_ERROR;
						break;
					}
				}
			}
		} 
		else
		{
			reVal = CI_ERROR;
		}
	}
	return reVal;
}

/*
* 功能描述： 检查区故解进路列车已驶出
* 参数说明： UINT16 routeId 进路号
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckPhySecFaultTrainCrossRoute(const UINT16 routeId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 phySecOccupyIndex = 0xFFu; /*物理区段占用下标*/
	UINT8 ii= 0u;
	UINT8 reVal = CI_SUCCESS;
	
	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	RouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	
	if (sectionSum == 0u) 
	{
	    reVal = CI_ERROR;
	}
	else
	{
	}
	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < sectionSum; ii++)
		{
			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(RouteSecStru[sectionSum-1u-ii].PhysicalSectionId))
			{ /*区段占用*/
			    
				phySecOccupyIndex = sectionSum-1u-ii;
				break;
			}
			else
			{
			}
		}
		
		if (0xFFu == phySecOccupyIndex)
		{
			reVal = CI_ERROR;
		}
	}
	else
	{
	}
	if (CI_SUCCESS == reVal)
	{
		/*最后一个占用区段的之前区段全部解锁*/
		for (ii = 0u; ii < phySecOccupyIndex; ii++)
		{
			if ((PHYSICAL_SECTION_LOCK_NO == GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId)) ||
			   ((PHYSICAL_SECTION_LOCK_NO!=GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId)) && (routeId != GetPhySecRLockBelongRouteId(RouteSecStru[ii].PhysicalSectionId))))
			{ /*未锁闭或非本进路锁闭*/
			}
			else
			{
				reVal = CI_ERROR;
				break;
			}
		}
	}
	else
	{
	}
	if (CI_SUCCESS == reVal)
	{
		/*最后一个占用区段的之后区段全部正常锁闭且占用过*/
		for (ii = phySecOccupyIndex+1u; ii < sectionSum; ii++)
		{
			if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId)) &&
				(SECTION_OCCUPY_YES == GetPhySecPreMergeState(RouteSecStru[ii].PhysicalSectionId)))
			{ /*区段正常锁闭且占用过*/
			}
			else
			{
				reVal = CI_ERROR;
				break;
			}
		}
	}
	else
	{
	}
	/*满足解锁条件*/
	return reVal;
}
/*
* 功能描述： 非进路侵限无效检查
* 参数说明： 
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   侵限
*            CI_SUCCESS 侵限不满足
*/
UINT8 NonRouteIntruSecVainCheck(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	/* 侵限区段 */
	UINT8 checkSum = 0U;
	NonRouteIntrudePhySectionStruct* dataIdBuf = NULL;

/* 局部变量定义初始化 */
    UINT16 i = 0u;
	UINT16 j = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 devFLockState = 0u;
    UINT8 intruSwitchSum = 0u;
    NonRouteSwitchStruct* intruSwitchConStru = NULL;
    UINT16 intruSwitchId = 0u;
    UINT8 intruSwitchPos = 0u;

    UINT8 intruSwitchPosValid = CI_ERROR;
	UINT8 reVal = CI_ERROR;
	UINT8 devLockState = 0u;
	UINT8 devJumpLockState = 0u;
	UINT8 checkFlockFlag = GetCiFunctionSwitchConfig(FUNC_INTRUSEC_CHECKFLOCK_FLAG);
	checkSum = GetNonRouteIntrudePhySecSumById(nonRouteId);
	dataIdBuf = GetNonRouteIntrudePhySecBufById(nonRouteId);
	
/* 检查侵限状态 */
    if (NULL==dataIdBuf)
    {
        /*无检查项*/
        reVal = CI_ERROR;
    }
    else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
    {
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SectionId;
			devState = GetPhySecCurMergeState(devId);
			devFLockState = GetPhySecFLockState(devId);
			devLockState = GetPhySecLockState(devId);
			devJumpLockState = GetPhySecJumpLockState(devId);
			/* 检查侵限区段是否占用或(检查封锁且封锁)或锁闭或跳跃锁闭*/
			if ((SECTION_OCCUPY_YES == devState)
				|| ((PHYSICAL_SECTION_FLOCK_YES == devFLockState) && (FUNC_SWITCH_ON != checkFlockFlag))
				|| (PHYSICAL_SECTION_LOCK_NO != devLockState)
				|| (PHYSICAL_SECTION_JUMP_LOCK_YES == devJumpLockState))
			{
				/*侵限区段占用*/
				intruSwitchSum = dataIdBuf[i].SwitchSum;
				if (intruSwitchSum > 0u)
				{
					/*侵限道岔位置检查*/
					intruSwitchPosValid = CI_ERROR;
					for (j = 0u; j<intruSwitchSum; j++)
					{
						intruSwitchConStru = &dataIdBuf[i].ConditionSwitchStru[j];
						intruSwitchId = intruSwitchConStru->SwitchId;
						intruSwitchPos = GetSwitchCurPosition(intruSwitchId);

                        if ((intruSwitchPos == intruSwitchConStru->SwitchPos)
							|| (SWITCH_POSITION_SIKAI == intruSwitchPos) 
							|| (SWITCH_POSITION_MOVE == intruSwitchPos)
                            || (SWITCH_POSITION_JICHA == intruSwitchPos)
							|| (SWITCH_POSITION_INVALID == intruSwitchPos))
                        {
                            intruSwitchPosValid = CI_ERROR;
                        }
                        else
                        {
                            /*道岔未侵限*/
                            intruSwitchPosValid = CI_SUCCESS;
                            break;
                        }

					}
	                
					if (intruSwitchPosValid == CI_ERROR)
					{
						/*有岔侵限条件成立*/
						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_INTRU_OCU_STATE,devState,sendLevel); 
						reVal = CI_ERROR;
					}
					else
					{
						/*道岔未侵限*/
	                    
					}                
				}
				else
				{
					/*无岔侵限条件条件成立*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_INTRU_OCU_STATE,devState,sendLevel); 
					reVal = CI_ERROR;
				}
			}
			else if ((SECTION_OCCUPY_NO == devState)
				&& ((PHYSICAL_SECTION_FLOCK_NO == devFLockState) || (FUNC_SWITCH_ON == checkFlockFlag))
				&& (PHYSICAL_SECTION_LOCK_NO == devLockState)
				&& (PHYSICAL_SECTION_JUMP_LOCK_NO == devJumpLockState))
			{/*侵限区段未占用且(未封锁或不检查封锁)且未锁闭且未跳跃锁闭*/
				/*侵限区段检查通过*/
			}
			else
			{/*该侵限区段状态异常*/
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_INTRU_OCU_STATE,devState,sendLevel); 
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
		}
    }

    /* 未检测到侵限条件 */
    return reVal;
}

/*
* 功能描述： 自动折返进路是否有抵触自动进路已办理检查
* 参数说明： 
*				UINT16 autoReturnId自动进路ID
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   抵触
*            CI_SUCCESS 抵触不满足
*/
UINT8 AutoReturnIsOpposedCheck(UINT16 autoReturnId, UINT8 functionID)
{
	UINT8 autoReturnOpposedRouteSum = 0u;   /*与自动通过进路相抵触的进路数目*/
	UINT16 *autoReturnOpposedRouteBuf = NULL;
	
	UINT8 autoReturnOpposedReturnSum = 0u;             /*与自动折返进路相抵触的进路数目*/
	UINT16 *autoReturnOpposedReturnBuf = NULL;
	
	UINT8 autoReturnOpposedAllReturnSum = 0u;             /*与全自动折返进路相抵触的进路数目*/
	UINT16 *autoReturnOpposedAllReturnBuf = NULL;
	UINT8  opposedRouteIdSum  = 0u;	   			/*进路包含抵触进路数目*/
	UINT16 *opposedRouteIdbuf = NULL;    			/*进路包含抵触进路ID*/
	
	UINT8 includeRouteSum = 0u;						/*自动折返进路所包含的进路数目*/
	UINT16 *includeRouteBuf = NULL;				
	UINT8 setAutoTriggerValidFlag = 0u;       /*自动触发属性设置是否有效检查标志*/
	UINT8 i = 0u;
	UINT8 j = 0u;  
	UINT8 k = 0u;
	UINT8 p = 0u;
	UINT8 q = 0u;
	UINT8 h = 0u;
	UINT8 chOpposeSecCheckRtn = CI_ERROR;
	UINT8 routeState = 0u; /*进路状态*/	
	UINT8 returnValue = CI_ERROR;
	
	if ((autoReturnId < 1u) || (autoReturnId >= AUTO_RETURN_SUM_MAX))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;

	}

	if(CI_SUCCESS == returnValue)
	{
		autoReturnOpposedReturnSum = GetAutoReturnOpposedReturnIdSum(autoReturnId);
		autoReturnOpposedReturnBuf = GetAutoReturnOpposedReturnIdBuf(autoReturnId);
		autoReturnOpposedRouteSum = GetAutoReturnOpposedRouteIdSum(autoReturnId);
		autoReturnOpposedRouteBuf = GetAutoReturnOpposedRouteIdBuf(autoReturnId);
		autoReturnOpposedAllReturnSum = GetAutoRtnOppAllReturnIdSum(autoReturnId);
		autoReturnOpposedAllReturnBuf = GetAutoRtnOppAllReturnIdBuf(autoReturnId);
		/*检查与折返进路相抵触的自动通过进路是否已办理*/ 
		for (i = 0u; i<autoReturnOpposedRouteSum; i++)
		{
			if (AUTO_ROUTE_SET_YES == GetAutoRouteSetFlag(autoReturnOpposedRouteBuf[i]))
			{
				returnValue = CI_ERROR;
				debug_infor_printf((const)"autoReturnOpposedRoute %d is set.\r\n",autoReturnOpposedRouteBuf[i]);
				/*向ATS报警反馈*/
				SetErrorData(functionID, CI_DEVICE_TYPE_AUTOROUTE, autoReturnOpposedRouteBuf[i], ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_DICHU_AUTOROUTE, ESEND_LEVEL_ATS);
				break;
			}
		}
		if(CI_SUCCESS == returnValue)
		{
            /*检查与折返进路相抵触的全自动折返进路是否已办理*/ 
			for (h = 0u; h< autoReturnOpposedAllReturnSum; h++)
			{
				if (ALL_AUTO_RETURN_SET_YES == GetAllAutoReturnSetFlag(autoReturnOpposedAllReturnBuf[h]))
			{
				returnValue = CI_ERROR;
				debug_infor_printf((const)"autoReturnOpposedAllReturn %d is set.\r\n",autoReturnOpposedAllReturnBuf[h]);
				/*向ATS报警反馈*/
				SetErrorData(functionID, CI_DEVICE_TYPE_ALLAUTORETURN, autoReturnOpposedAllReturnBuf[h], ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_DICHU_ALLAUTOROUTE, ESEND_LEVEL_ATS);

				break;
			}
		}
		if(CI_SUCCESS == returnValue)
		{
			/*检查与折返进路相抵触的其他折返进路是否已办理*/
			for (j = 0u; j<autoReturnOpposedReturnSum; j++)
			{
				if (AUTO_RETURN_SET_YES == GetAutoReturnSetFlag(autoReturnOpposedReturnBuf[j]))
				{
					returnValue = CI_ERROR;
					debug_infor_printf((const)"autoReturnOpposedReturn %d is set.\r\n",autoReturnOpposedReturnBuf[j]);
					/*向ATS报警反馈*/
					SetErrorData(functionID, CI_DEVICE_TYPE_AUTORETURN, autoReturnOpposedReturnBuf[j], ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_DICHU_AUTOREROUTE, ESEND_LEVEL_ATS);

					break;
				}
			}

			if(CI_SUCCESS == returnValue)
			{	
				/*检查折返进路所包含的区段是否办理过引导*/
				includeRouteBuf = GetAutoReturnIncludeRouteBuf(autoReturnId);
				includeRouteSum = GetAutoReturnIncludeRouteSum(autoReturnId);
			
				for (k = 0u; k<includeRouteSum; k++)
				{
	
					routeState = GetRouteState(includeRouteBuf[k]); /*获取进路状态*/
					
					opposedRouteIdSum = GetRouteOpposedRouteIdSum(includeRouteBuf[k]);
					opposedRouteIdbuf = GetRouteOpposedRouteIdBuf(includeRouteBuf[k]);
					
					/* 进路的引导属性为【可引导】*/
					if ((routeState == ROUTE_STATE_LEAD_XUANPAI)||(routeState == ROUTE_STATE_LEAD_LOCK)
						||(routeState == ROUTE_STATE_LEAD_LOCKERR)||(routeState == ROUTE_STATE_LEAD_OPEN))
					{
						returnValue = CI_ERROR;
						debug_infor_printf((const)"OpposedRouteId %d is Leadble.\r\n",includeRouteBuf[k]);
						/*向ATS报警反馈*/
						SetErrorData(functionID, CI_DEVICE_TYPE_ROUTE, includeRouteBuf[k], ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_DICHU_COMMROUTE, ESEND_LEVEL_ATS);

						break;
					}
					if(CI_SUCCESS == returnValue)
					{
						for(p = 0u;p < opposedRouteIdSum;p++)
						{

							for(q = 0u ;q < includeRouteSum; q++)
							{
								if(includeRouteBuf[q] == opposedRouteIdbuf[p] )
								{/*此条抵触进路包含在本折返进路中的*/
									debug_infor_printf((const)"opposedRouteId %d is subroute.\r\n",includeRouteBuf[q]);
									break;
								}
							}

							if(q == includeRouteSum )
							{/*此条抵触进路未包含在本折返进路中的*/
								chOpposeSecCheckRtn = AutoRouteOpposeSectionCheck(includeRouteBuf[k], opposedRouteIdbuf[p]);
								setAutoTriggerValidFlag = JudgeSetAutoTriggerFlagIsValid(opposedRouteIdbuf[p]);
								/*2022.8.3 M by pfq:自动折返进路车停在折返轨时，能够设置自动触发属性*/
								if ((CI_SUCCESS == setAutoTriggerValidFlag) || (CI_SUCCESS == chOpposeSecCheckRtn))
								{
									/*有效，或进路内区段未被抵触进路锁闭 则可以设置,继续检查其他设置条件是否满足*/
								}
								else
								{
									debug_infor_printf((const)"opposedRouteId %d is not IDLE.\r\n", opposedRouteIdbuf[p]);
									/*向ATS报警反馈*/
									SetErrorData(functionID, CI_DEVICE_TYPE_ROUTE, opposedRouteIdbuf[p], ETYPE_AUTO_RETURN_FLAG, AUTO_RETURN_DICHU_COMMROUTE, ESEND_LEVEL_ATS);
									returnValue = CI_ERROR;
									break;
								}
							}

						}
					}

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

	return returnValue;
}
/*
* 功能描述： 自动通过进路是否有抵触自动进路已办理检查
* 参数说明： 
*				UINT16 autoReturnId自动进路ID
* 返回值  ： CI_ERROR   抵触
*            CI_SUCCESS 抵触不满足
*/
UINT8 AutoRouteIsOpposedCheck(UINT16 autoRouteId, UINT8 functionID)
{
	UINT8 autoRouteOpposedRouteSum = 0u;   /*与自动通过进路相抵触的自动通过进路数目*/
	UINT16 *autoRouteOpposedRouteBuf = NULL;
	UINT8 autoRouteOpposedReturnSum = 0u;             /*与自动折返进路相抵触的自动折返进路数目*/
	UINT16 *autoRouteOpposedReturnBuf = NULL;
	UINT8 autoRouteOpposedAllReturnSum = 0u;             /*与全自动折返进路相抵触的全自动折返进路数目*/
	UINT16 *autoRouteOpposedAllReturnBuf = NULL;
	UINT16 *includeRouteBuf = NULL;
	UINT8 includeRouteSum = 0u;
	UINT8 i = 0u;
	UINT8 j = 0u;  
	UINT8 k = 0u;
	UINT8 h = 0u;
	UINT8 returnValue = CI_ERROR;
	UINT8 flag = 1u;  /*初始化为检查失败*/

 	UINT8 ii = 0u;
 	UINT8 routeOpposedSum = 0u;             /*与普通进路相抵触的进路数目*/
 	UINT16 *routeOpposedBuf = NULL;
	UINT8 opposeSecCheckRtn = CI_ERROR; /*抵触进路区段检查返回*/


	if ((autoRouteId < 1u) || (autoRouteId >= AUTO_ROUTE_SUM_MAX) )
	{
		flag = 1u;
	}
	else
	{
		flag = 0u;
		autoRouteOpposedReturnSum = GetAutoRouteOpposedReturnIdSum(autoRouteId);
		autoRouteOpposedReturnBuf = GetAutoRouteOpposedReturnIdBuf(autoRouteId);
		autoRouteOpposedRouteSum = GetAutoRouteOpposedRouteIdSum(autoRouteId);
		autoRouteOpposedRouteBuf = GetAutoRouteOpposedRouteIdBuf(autoRouteId);
		autoRouteOpposedAllReturnSum = GetAutoRouteOpposedAllRtnIdSum(autoRouteId);
		autoRouteOpposedAllReturnBuf = GetAutoRouteOpposedAllRtnIdBuf(autoRouteId);

		/*检查与自动进路相抵触的自动折返进路是否已办理*/ 
		for (i = 0u; i<autoRouteOpposedReturnSum; i++)
	    {
	        if (AUTO_RETURN_SET_YES == GetAutoReturnSetFlag(autoRouteOpposedReturnBuf[i]))
	        {
				flag = 1u;
				debug_infor_printf((const)"AutoRouteIsOpposedCheck:AutoReturn %d has set.",autoRouteOpposedReturnBuf[i]);
				/*向ATS反馈报警*/
				SetErrorData(functionID, CI_DEVICE_TYPE_AUTORETURN, autoRouteOpposedReturnBuf[i], ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_DICHU_AUTOREROUTE, ESEND_LEVEL_ATS);

				break;
	        }
		}
		if (1u == flag)
		{
			/*找到抵触进路，检查失败*/
		} 
        else
        {
	        /*检查与自动进路相抵触的全自动折返进路是否已办理*/ 
			for (h = 0u; h < autoRouteOpposedAllReturnSum; h++)
			{
				if (ALL_AUTO_RETURN_SET_YES == GetAllAutoReturnSetFlag(autoRouteOpposedAllReturnBuf[h]))
				{
				
					flag = 1u;
					debug_infor_printf((const)"AutoRouteIsOpposedCheck:AllAutoReturn %d has set.",autoRouteOpposedAllReturnBuf[h]);
					/*向ATS反馈报警*/
					SetErrorData(functionID, CI_DEVICE_TYPE_ALLAUTORETURN, autoRouteOpposedAllReturnBuf[h], ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_DICHU_ALLAUTOREROUTE, ESEND_LEVEL_ATS);

					break;
				}
			}
			if (1u == flag)
			{
				/*相抵触的自动折返进路已办理，不再检查*/
			} 
			else
			{
					/*检查与自动进路相抵触的其他自动进路是否已办理*/
				for (j = 0u; j<autoRouteOpposedRouteSum; j++)
				{
					if (AUTO_ROUTE_SET_YES == GetAutoRouteSetFlag(autoRouteOpposedRouteBuf[j]))
					{
						flag = 1u;
						debug_infor_printf((const)"AutoRouteIsOpposedCheck:AutoRoute %d has set.",autoRouteOpposedRouteBuf[j]);

						/*向ATS反馈报警*/
						SetErrorData(functionID, CI_DEVICE_TYPE_AUTOROUTE, autoRouteOpposedRouteBuf[j], ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_DICHU_AUTOROUTE, ESEND_LEVEL_ATS);

						break;
					}
				}
				if (1u == flag)
				{
				} 
				else
				{

					/*检查自动进路所包含的区段是否办理过引导*/
					includeRouteBuf = GetAutoRouteIncludeRouteBuf(autoRouteId);
					includeRouteSum = GetAutoRouteIncludeRouteSum(autoRouteId);
					for (k = 0u; k<includeRouteSum; k++)
					{
						UINT8 routeState = 0u; /*进路状态*/	
						routeState = GetRouteState(includeRouteBuf[k]); /*获取进路状态*/
			
						/* 进路的引导属性为【可引导】*/
						if ((routeState == ROUTE_STATE_LEAD_XUANPAI)||(routeState == ROUTE_STATE_LEAD_LOCK)
							||(routeState == ROUTE_STATE_LEAD_LOCKERR)||(routeState == ROUTE_STATE_LEAD_OPEN))
						{
							flag = 1u;
							debug_infor_printf((const)"AutoRouteIsOpposedCheck:Route %d LeadState is %d, is Leading Error.",includeRouteBuf[k],routeState);
							
							/*向ATS反馈报警*/
							SetErrorData(functionID, CI_DEVICE_TYPE_ROUTE, includeRouteBuf[k], ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_DICHU_COMMROUTE, ESEND_LEVEL_ATS);

							break;
						}
						if (1u == flag)
						{
 						} 
 						else
 						{
	 
							routeOpposedBuf = GetRouteOpposedRouteIdBuf(includeRouteBuf[k]);
 							routeOpposedSum = GetRouteOpposedRouteIdSum(includeRouteBuf[k]);
	 
 							for (ii = 0u; ii<routeOpposedSum; ii++)
 							{
								/*检查抵触进路空闲或进路内区段未必抵触进路锁闭*/
								opposeSecCheckRtn = AutoRouteOpposeSectionCheck(includeRouteBuf[k], routeOpposedBuf[ii]);
								if (CI_ERROR == opposeSecCheckRtn)
								{
									flag = 1u;
									debug_infor_printf((const)"AutoRouteIsOpposedCheck:Route %d OpposedRoute %d RouteState NOT IDLE 0x1.", includeRouteBuf[k], routeOpposedBuf[ii]);

									/*向ATS反馈报警*/
									SetErrorData(functionID, CI_DEVICE_TYPE_ROUTE, routeOpposedBuf[ii], ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_DICHU_COMMROUTE, ESEND_LEVEL_ATS);

									break;
								}
								else
								{
									; /*继续检查*/
								}
 							} 
 						} 
					}
				}
			}
		}
	}
	if (1u == flag)
	{
		returnValue = CI_ERROR;
	} 
	else
	{
		returnValue = CI_SUCCESS;
	}
	return returnValue;
}

/*
* 功能描述： 以指定进路的始端信号机作为终端信号机的折返进路是已办理检查
* 参数说明： 
*			 UINT16 *dataIdBuf,    检查数据数组
*            UINT8 checkSum,      检查长度
*            UINT16 *pDevId,      设备Id（返回）
*            UINT8 *pDevState,    设备状态（返回）
* 返回值  ： CI_ERROR   未通过检查
*            CI_SUCCESS 通过检查
*/
UINT8 RtnEndSigAsStartSigRouteCheck(UINT16 *pDataIdBuf,UINT8 checkSum,UINT16 *pDevId,UINT8 *pDevState)
{
	UINT8 i = 0u;
	UINT8 routeCurState = 0u; /*进路当前状态*/
	UINT16 devId = 0u;      
    UINT8  devState = 0u;
	UINT8 returnValue = CI_ERROR;

	UINT8 routeBelongCi = 0u;/*进路所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	
	if ((NULL == pDataIdBuf)||(NULL == pDevId)||(NULL == pDevState)||(ROUTE_SIGNAL_OPPOSED_ROUTE_SUM_MAX < checkSum))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;
	
		for(i = 0u;i < checkSum; i++)
		{
			routeCurState = GetRouteState(pDataIdBuf[i]);
			devId = pDataIdBuf[i];
			devState = routeCurState;	

			routeBelongCi = GetRouteBelongCiId(devId);/*获取进路所属联锁*/
			commState = GetLocalCiAndOtherCiTransSta(routeBelongCi);/*本联锁与其它联锁通信通信状态*/
		
			if ((localCi !=routeBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*如果进路所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查*/
				returnValue = CI_SUCCESS;
			}
			else
			{
				if ((ROUTE_STATE_IDLE == routeCurState)
					|| (ROUTE_STATE_XUANPAI == routeCurState)
					|| (ROUTE_STATE_FIRST_XUANPAI == routeCurState)
					|| (ROUTE_STATE_LEAD_FIRST_XUANPAI == routeCurState)
					|| (ROUTE_STATE_LEAD_XUANPAI == routeCurState))
				{
					returnValue = CI_SUCCESS;
				}
				else
				{
					/*以本进路始端信号机作为终端信号机的折返进路已经锁闭，则本进路信号不开放*/
					*pDevId = devId;
					*pDevState = devState;
					returnValue = CI_ERROR;
					break;
				}
			}
		}
	}

	return returnValue;
}

/*
* 功能描述： 进路除最后一个区段外全部空闲检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR       物理区段状态检查不通过
*			 CI_ERROR_QXZC  取消照查条件不满足
*            CI_SUCCESS 
*/
UINT8 RouteExceptLastSecOccuClrCheck(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_CHECK_LEAD_ROUTE_ZRJ;
	/* 进路区段*/
	UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 result = CI_SUCCESS;
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/
	UINT8 sendLevel = ESEND_LEVEL_ATS;    /*发送ATS*/

	/* 区段占用检查 */
	if (0u == checkSum)
	{
		/*区段数据错误*/
		result = CI_ERROR;
	}
	else
	{
	}

	if (CI_SUCCESS == result)
	{
		/*开始检查*/

		for (i = 0u; i < (UINT16)(checkSum - 1u); i++)
		{
			devId = dataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecCurMergeState(devId);

			if (SECTION_OCCUPY_YES == devState)
			{
				/*状态不一致返回故障状态*/
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
				result = CI_ERROR;
				break;
			}
			else
			{
			}
		}
	}

	if (CI_SUCCESS == result)
	{
		cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/

		if ((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
		{
			/*取消继电器有效：取消继电器采集状态为：吸起*/
			relayState = GetRelayCollState(cancleZhaoChaRelayId);/*获取取消继电器采集状态*/
			devId = cancleZhaoChaRelayId;
			devState = relayState;
			if (RELAY_STATE_UP == relayState)
			{
				/* 通过检查 */
				result = CI_SUCCESS;

			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, devId, ETYPE_CANCLE_ZHAOCHA, devState, sendLevel);
				/* 失败返回 */
				result = CI_ERROR_QXZC;
			}

		}
		else
		{
		}

	}
	else
	{

	}

	return result;
}
/*
* 功能描述： 全自动折返进路是否有抵触自动进路已办理检查
* 参数说明： 
*				UINT16 allAutoReturnId

  * 返回值  ： CI_ERROR   抵触
  *            CI_SUCCESS 抵触不满足
*/
UINT8 AllAutoReturnIsOpposedCheck(UINT16 allAutoReturnId, UINT8 chFunctionId)
{
	UINT8 allAutoRtnOpposedRouteSum = 0u;   /*与自动通过进路相抵触的进路数目*/
	UINT16 *allAutoRtnOpposedRouteBuf = NULL;
	
	UINT8 allAutoReturnOpposedReturnSum = 0u;             /*与自动折返进路相抵触的进路数目*/
	UINT16 *allAutoReturnOpposedReturnBuf = NULL;

	UINT8 allAutoReturnOpposedAllReturnSum = 0u;             /*与全自动折返进路相抵触的进路数目*/
	UINT16 *allAutoReturnOpposedAllReturnBuf = NULL;

	UINT8  opposedRouteIdSum  = 0u;	   			/*进路包含抵触进路数目*/
	UINT16 *opposedRouteIdbuf = NULL;    			/*进路包含抵触进路ID*/
	
	UINT8 includeRouteSum = 0u;						/*自动折返进路所包含的进路数目*/
	UINT16 *includeRouteBuf = NULL;				
	
	UINT8 i = 0u;
	UINT8 j = 0u;  
	UINT8 k = 0u;
	UINT8 p = 0u;
	UINT8 q = 0u;
	UINT8 h = 0u;

	UINT8 routeState = 0u; /*进路状态*/	
	UINT8 returnValue = CI_SUCCESS;
	UINT8 chOpposeSecCheckRtn = 0U;
	
	if ((allAutoReturnId < 1u) || (allAutoReturnId >= ALL_AUTO_RETURN_SUM_MAX))
	{
		returnValue = CI_ERROR;
	}
	if(CI_SUCCESS == returnValue)
	{
		allAutoReturnOpposedReturnSum = GetAllAutoRtnOppReturnIdSum(allAutoReturnId);
		allAutoReturnOpposedReturnBuf = GetAllAutoRtnOppReturnIdBuf(allAutoReturnId);
		allAutoRtnOpposedRouteSum = GetAllAutoRtnOppRouteIdSum(allAutoReturnId);
		allAutoRtnOpposedRouteBuf = GetAllAutoRtnOppRouteIdBuf(allAutoReturnId);
		allAutoReturnOpposedAllReturnSum = GetAllAutoRtnOppAllReturnIdSum(allAutoReturnId);
		allAutoReturnOpposedAllReturnBuf = GetAllAutoRtnOppAllRtnIdBuf(allAutoReturnId);
		/*检查与全自动折返进路相抵触的自动通过进路是否已办理*/ 
		for (i = 0u; i< allAutoRtnOpposedRouteSum; i++)
		{
			if (AUTO_ROUTE_SET_YES == GetAutoRouteSetFlag(allAutoRtnOpposedRouteBuf[i]))
			{
				returnValue = CI_ERROR;
				/*向ATS反馈报警*/
				SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTOROUTE, allAutoRtnOpposedRouteBuf[i], ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_DICHU_AUTOR, ESEND_LEVEL_ATS);

				break;
			}
		}
		if(CI_SUCCESS == returnValue)
		{
			/*检查与全自动折返进路相抵触的自动折返进路是否已办理*/ 
			for (h = 0u; h<allAutoReturnOpposedReturnSum; h++)
			{
				if (AUTO_RETURN_SET_YES == GetAutoReturnSetFlag(allAutoReturnOpposedReturnBuf[h]))
				{
					returnValue = CI_ERROR;
					/*向ATS反馈报警*/
					SetErrorData(chFunctionId, CI_DEVICE_TYPE_AUTORETURN, allAutoReturnOpposedReturnBuf[h], ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_DICHU_AUTORETR, ESEND_LEVEL_ATS);

					break;
				}
			}

			if(CI_SUCCESS == returnValue)
			{
				/*检查与全自动折返进路相抵触的其他全自动折返进路是否已办理*/
				for (j = 0u; j<allAutoReturnOpposedAllReturnSum; j++)
				{
					if (ALL_AUTO_RETURN_SET_YES == GetAllAutoReturnSetFlag(allAutoReturnOpposedAllReturnBuf[j]))
					{
						returnValue = CI_ERROR;
						/*向ATS反馈报警*/
						SetErrorData(chFunctionId, CI_DEVICE_TYPE_ALLAUTORETURN, allAutoReturnOpposedAllReturnBuf[j], ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_DICHU_ALLAUTOR, ESEND_LEVEL_ATS);

						break;
					}
				}

				if(CI_SUCCESS == returnValue)
				{	
					/*检查全自动折返进路所包含的区段是否办理过引导*/
					includeRouteBuf = GetAllAutoReturnIncludeRouteBuf(allAutoReturnId);
					includeRouteSum = GetAllAutoReturnIncludeRouteSum(allAutoReturnId);
				
					for (k = 0u; k<includeRouteSum; k++)
					{
		
						routeState = GetRouteState(includeRouteBuf[k]); /*获取进路状态*/
						
						opposedRouteIdSum = GetRouteOpposedRouteIdSum(includeRouteBuf[k]);
						opposedRouteIdbuf = GetRouteOpposedRouteIdBuf(includeRouteBuf[k]);
						
						/* 进路的引导属性为【可引导】*/
						if ((routeState == ROUTE_STATE_LEAD_XUANPAI)||(routeState == ROUTE_STATE_LEAD_LOCK)
							||(routeState == ROUTE_STATE_LEAD_LOCKERR)||(routeState == ROUTE_STATE_LEAD_OPEN))
						{
							returnValue = CI_ERROR;			
							/*向ATS反馈报警*/
							SetErrorData(chFunctionId, CI_DEVICE_TYPE_ROUTE, includeRouteBuf[k], ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_DICHU_COMMR, ESEND_LEVEL_ATS);

						}
						if(CI_SUCCESS == returnValue)
						{
							for(p = 0u;p < opposedRouteIdSum;p++)
							{

								for(q = 0u ;q < includeRouteSum; q++)
								{
									if(includeRouteBuf[q] == opposedRouteIdbuf[p] )
									{/*此条抵触进路包含在本折返进路中的*/
										break;
									}
								}

								if(q == includeRouteSum )
								{/*此条抵触进路未包含在本折返进路中的*/
									/*检查抵触进路空闲或进路内区段未被抵触进路锁闭*/
									chOpposeSecCheckRtn = AutoRouteOpposeSectionCheck(includeRouteBuf[k], opposedRouteIdbuf[p]);
									if (CI_ERROR == chOpposeSecCheckRtn)
									{
										returnValue = CI_ERROR;

										/*向ATS反馈报警*/
										SetErrorData(chFunctionId, CI_DEVICE_TYPE_ROUTE, opposedRouteIdbuf[p], ETYPE_ALL_AUTO_RETURN_FLAG, ALL_AUTO_RETURN_DICHU_COMMR, ESEND_LEVEL_ATS);

										break;
									}
									else
									{
										; /*继续检查*/
									}
								}
								else
								{
								}

							}
						}

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

	return returnValue;
}


/*
* 功能描述： 进路区段封锁检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteSecFLockCheck(UINT16 const routeId, UINT16 *pDevId,UINT8 *pDevState )
{
	/* 进路区段*/
	UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const pDataIdBuf = GetRouteSectionData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;

	UINT8 phyBelongCi = 0u;/*区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	/* 区段占用检查 */
	if (NULL == pDataIdBuf)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecFLockState(devId);
	
			phyBelongCi = GetPhySecBelongCiId(devId);/*获取区段所属联锁*/
			commState = GetLocalCiAndOtherCiTransSta(phyBelongCi);/*本联锁与其它联锁通信通信状态*/

			if ((localCi !=phyBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*如果区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查该信号机封锁状态*/
			}
			else
			{
				/* 状态如果不是未封锁状态，则认为检查失败 */
				if (devState != PHYSICAL_SECTION_FLOCK_NO)			
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					ret = CI_ERROR;
					break;
				}
			}
			
		}
	}

	/*全部通过检查*/
	return ret;
}



/*
* 功能描述： 保护区段封锁状态有效性检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OverlapAllSecFLockValidCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* overlap区段 */
	UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
	UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;

	/* 联锁条件检查 */
	if (0u != checkSum) 
	{
		/*开始检查*/

		/* 保护区段内所有区【未封锁】*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecFLockState(devId);
			if (PHYSICAL_SECTION_FLOCK_NO!= devState )		
			{/* 区段不是未封锁状态，检查不通过 */
				/*状态非法返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				ret = CI_ERROR;
				break;
			}
			else
			{
				ret = CI_SUCCESS;
			}
		}
	}
	else
	{
		ret = CI_ERROR;
	}

	/*全部通过检查*/
	return ret;
}



/*
* 功能描述： 其他联锁条件检查
* 参数说明： UINT16 routeId 进路ID
*			 UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS routeId, functionId, sendLevel
*/
UINT8 OtherCiValidCheck(UINT16 const routeId,UINT8 const functionId,UINT8 const sendLevel)
{
	/*进路等级*/
	UINT8 const routeLevel = GetRouteLevel(routeId);

	/*ESB数据*/
	UINT8 checkSum = 0u;
	RouteOtherCheckStruct *dataOtherCiDevBuf = NULL;
	RouteOtherCheckStruct *tmpOtherCiDevInfo = NULL;

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 devType = 0u;
	UINT8 otherCheckState = 0u;
	UINT8 devStateType = 0u;
	UINT8 ret = CI_SUCCESS;

	/*获取其他联锁检查条件数据*/
	if (ROUTE_LEVEL_BLOC == routeLevel)
	{
		checkSum = GetRouteBlocOtherCiSum(routeId);
		dataOtherCiDevBuf = GetRouteBlocOtherCiBuf(routeId);
	}
	else if (ROUTE_LEVEL_CBTC == routeLevel)
	{
		checkSum = GetRouteCbtcOtherCiSum(routeId);
		dataOtherCiDevBuf = GetRouteCbtcOtherCiBuf(routeId);
	}
	else
	{    
		checkSum = 0u;
		dataOtherCiDevBuf = NULL;

	}

	/* 开始检查 */
	if ((0u != checkSum) && (NULL != dataOtherCiDevBuf))
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			tmpOtherCiDevInfo = &dataOtherCiDevBuf[i];
			otherCheckState = OtherCiDevStatusCheck(routeId,tmpOtherCiDevInfo,&devId,&devState);
			if(CI_ERROR == otherCheckState)
			{
				devType = tmpOtherCiDevInfo->DevType;
#if 0
				if (CI_DEVICE_TYPE_AXISSEC == tmpOtherCiDevInfo->DevType)
				{
					devId = GetAxisSecRelativePhySecId(devId);
				}
#endif
				/*联络线道岔，转为正常道岔*/
				if(CI_DEVICE_TYPE_CONNECT_SWITCH == tmpOtherCiDevInfo->DevType)
				{
					devType = CI_DEVICE_TYPE_SWITCH;
				}
				devStateType = GetOtherCiCheckDevStateType(devType);
				SetErrorData(functionId,devType,devId,devStateType,devState,sendLevel);
				ret = CI_ERROR;
				
			}
			else if(CI_ROUTE_RECOVER_ERR == otherCheckState)
			{
				/* 正常收到VOBC打开屏蔽门命令打开屏蔽门*/
				ret = CI_ERROR;
				
			}
			else
			{
				/*其它联锁条件检查结果为成功，此时不处理*/
			}
			if (CI_ERROR == ret)
			{
				break;
			}
		}			
	}

	return ret;
}

/*
* 功能描述： 其他联锁条件设备状态检查
* 参数说明： UINT16 routeId 进路ID
*			 RouteOhterCheckStruct *pOtherDevInfo
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OtherCiDevStatusCheck(UINT16 const routeId,const RouteOtherCheckStruct *pOtherDevInfo,
	UINT16 *pDevId,UINT8 *pDevState)
{
	UINT16 devId = pOtherDevInfo->DevId;
	UINT16 chkDevStatus = pOtherDevInfo->DevStatus;
	UINT16 devType = pOtherDevInfo->DevType;
	UINT8 devState = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 routeLeadProperty = 0u;	/*进路引导属性*/
	UINT8 routeState = 0u;			/*进路状态*/
	UINT8 retVal = CI_ERROR;
	UINT8 AxisSecLinXianFlag = 0U;
	UINT16 leaveLogicSecId = 0U;  /*进路第一离去逻辑区段*/
	UINT8 routeOverlapSum = 0U;  /*进路保护区段数量*/
	UINT8 logSwichSum = 0U; /*逻辑区段包含的道岔数量*/
	UINT8 logBelogAxisNum = 0u;
	UINT16* logBelogAxisBuff = NULL;
	UINT8 cFuncSwitchFloodGate = FUNC_SWITCH_ON;  /*引导进路是否检查防淹门开关*/
	UINT8 cFuncSwitchEsb = FUNC_SWITCH_ON;  /*引导进路是否检查ESB开关*/
	UINT8 cRouteToLeadFlag = 0U;  /*进路转引导进路标志*/

	devState = GetOtherCiDevStatus(devType,devId,chkDevStatus);

	if (CI_DEVICE_TYPE_SIGNAL != devType)
	{	/* 信号机外的状态 */
		/* 状态不满足，则返回失败 */
		if (chkDevStatus != devState)
		{
			routeLeadProperty = GetRouteLeadProperty(routeId);/*获取进路引导属性*/
			routeState = GetRouteState(routeId);/*获取进路状态*/
			cRouteToLeadFlag = GetRouteToLeadFlag(routeId);  /*获取引导进路转换标志*/

			if (((ROUTE_LEAD_PROPERTY_YES == routeLeadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == routeLeadProperty))
				&& (((ROUTE_STATE_LEAD_LOCK == routeState) || (ROUTE_STATE_LEAD_LOCKERR == routeState) || (ROUTE_STATE_LEAD_OPEN == routeState)) || (ROUTE_TO_LEAD_FLAG_YES == cRouteToLeadFlag)))
			{
				/*引导进路其他联锁条件只检查进路外方计轴区段的占用状态、联络线道岔、道岔、防淹门(根据“引导进路是否检查防淹门状态”开关确定是否检查)
				  和ESB(根据“引导进路是否检查ESB状态”开关确定是否检查)*/
				cFuncSwitchFloodGate = GetCiFunctionSwitchConfig(FUNC_LEADROUTE_FLOODGATE_CHECK);
				cFuncSwitchEsb = GetCiFunctionSwitchConfig(FUNC_LEADROUTE_ESB_CHECK);

				if ((CI_DEVICE_TYPE_AXISSEC == devType) || (CI_DEVICE_TYPE_CONNECT_SWITCH == devType) || (CI_DEVICE_TYPE_SWITCH == devType)
					|| ((CI_DEVICE_TYPE_FLOODGATE == devType) && (FUNC_SWITCH_OFF != cFuncSwitchFloodGate))
					|| ((CI_DEVICE_TYPE_ESB == devType) && (FUNC_SWITCH_OFF != cFuncSwitchEsb)))
				{					
					ret = CI_ERROR;
				}
				else
				{
					ret = CI_SUCCESS;
				}
			}
			else
			{
				if (CI_DEVICE_TYPE_AXISSEC == devType)				/*针对站外直轨，需要将计轴单独判断*/
				{
					AxisSecLinXianFlag = GetAxisSecLinXianFlag(devId);

					if (AXIS_SEC_LINXIAN_NO == AxisSecLinXianFlag)
					{
						/*获取进路外方第一离去逻辑区段*/
						leaveLogicSecId = GetRouteLeaveLogicSecId(routeId);
						/*进路存在外方离去区段*/
						if (0U != leaveLogicSecId)
						{
							/*逻辑区段包含的道岔*/
							logSwichSum = GetLogicSecSwitchSum(leaveLogicSecId);
							routeOverlapSum = GetRouteOverlapSum(routeId);
							/*逻辑区段关联的计轴区段*/
							logBelogAxisNum = GetLgcSecRelativeAxleSecSum(leaveLogicSecId);
							logBelogAxisBuff = GetLgcSecRltvAxleSecIdBuf(leaveLogicSecId);

							/*当前进路无保护区段，且离去逻辑区段不包含道岔*/
							if ((0U == logSwichSum) && (0U == routeOverlapSum) && (1U == logBelogAxisNum))
							{
								/*所配置的计轴为本进路离去计轴区段，可检查进路离去ABL列车条件*/
								if (logBelogAxisBuff[0] == devId)
								{
									ret = TrainLeaveLogSecABLTrainCheck(leaveLogicSecId);
								}
								else
								{
									ret = CI_ERROR;
								}

							}
							else
							{
								ret = CI_ERROR;
							}
						}
						else
						{
							ret = CI_ERROR;		/*进路无离去区段，无需再检查是否有VBL接近，直接返回失败*/
						}
					}
					else
					{
						ret = CI_ERROR;		/*计轴非本线路，无需再检查是否有VBL接近，直接返回失败*/
					}
				}
				else
				{
					if (OTHER_CI_PSD_STATUS_OCCUPY_OPEN == devState)
					{
						/* 正常收到VOBC打开屏蔽门命令打开屏蔽门 只记录不发送*/
						ret = CI_ROUTE_RECOVER_ERR;
					}
					else
					{
						/* 屏蔽门异常打开 */
						ret = CI_ERROR;
					}
				}
			}
		}
		else
		{
			ret = CI_SUCCESS;
		}
	}
	else
	{
		/* 信号机状态 */
		if ((OTHER_CI_SIGNAL_STATUS_SAME == chkDevStatus)||(OTHER_CI_SIGNAL_STATUS_OPEN == chkDevStatus))
		{
			retVal = CheckRelationSignalOnSameOpen(routeId, devId, (UINT8)chkDevStatus);
			if (CI_SUCCESS == retVal)
			{
				ret = CI_SUCCESS;
			}
			else
			{
				ret = CI_ERROR;
			}
		}
		else
		{
			/*异常值防护，信号机只可配置开放条件0x55或者0xbb*/
			ret = CI_ERROR;
		}
	}
	if (CI_ERROR == ret)
	{
		*pDevId = devId;
		*pDevState = devState;
	}

	return ret;

}

/*
* 功能描述： 信号机关联检查: 进路开放的信号状态不能高于指定的信号机状态。
*			 关联信号机显示为引导信号，则进路开放信号不能高于引导。
*			 关联信号机为调车信号机，则进路开放信号机只能为调车信号。
*			 列车信号机-引导或列车(0xbb),列车信号机-列车信号(非引导)(0x55)
* 参数说明： UINT16 const routeId 进路ID
*            UINT16 const relationSignalId 信号机ID
*			 UINT8 const devStatus		设备检查状态
* 返回值  ： 0   失败
*			 >0  设备状态 
*/
static UINT8 CheckRelationSignalOnSameOpen(UINT16 const routeId,UINT16 const relationSignalId,UINT8 const devStatus)
{
	UINT8 routeState = 0u,routeLeadProperty = 0u;
	UINT8 ret = CI_SUCCESS;
	UINT8 routeType = 0u;          /*进路类型*/
	UINT8 relationSignalOpenColor = GetSignalCurColor(relationSignalId);
	UINT8 cRouteStartSigOpenColor = 0U;  /*进路始端信号机开放颜色*/

	routeState = GetRouteState(routeId);
	routeLeadProperty = GetRouteLeadProperty(routeId);/*获取进路引导属性*/
	routeType = GetRouteType(routeId);                /*获取进路类型*/
	
	if ((routeState != 0u) && (relationSignalOpenColor != 0u))
	{		
		/* 如果信号开放，则检查本进路将要开放的信号是否比当前的开放的级别要高 */
		if (SIGNAL_OPEN == GetSignalOpenCloseState(relationSignalOpenColor))
		{
			switch (relationSignalOpenColor)
			{
			case SIGNAL_SHOWCOLOUR_REDYELLOW:
				/* 红黄灯,即信号开放必须是引导信号 */

				if (((ROUTE_LEAD_PROPERTY_YES == routeLeadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == routeLeadProperty))
					&& ((ROUTE_STATE_LEAD_LOCK == routeState)
						|| (ROUTE_STATE_LEAD_LOCKERR == routeState)
						|| (ROUTE_STATE_LEAD_OPEN == routeState)))
				{/* 进路为可引导，且进路状态为<引导锁闭>或<引导锁闭异常>或<引导开放> ,即进路将引导开放,关联 */
					ret = CI_SUCCESS;
				}
				else
				{
					ret = CI_ERROR;
				}
				break;
			case SIGNAL_SHOWCOLOUR_WHITE:
				if (ROUTE_TYPE_DIAOCHE == routeType)
				{
					ret = CI_SUCCESS;
				}
				else
				{
					ret = CI_ERROR;
				}
				break;
			case SIGNAL_SHOWCOLOUR_YELLOW:
			case SIGNAL_SHOWCOLOUR_GREEN:
				if (OTHER_CI_SIGNAL_STATUS_OPEN == devStatus)
				{
					/* 对方开放列车信号，本方可办理引导进路和列车进路，不能办理调车进路(0x55检查项)*/
					if (ROUTE_TYPE_DIAOCHE == routeType)
					{
						ret = CI_ERROR;
					}
					else
					{
						ret = CI_SUCCESS;
					}
				}
				else
				{
					if (ROUTE_TYPE_LIECHE == routeType)
					{
						cRouteStartSigOpenColor = GetRouteSignalOpenColor(routeId);  /*获取进路始端信号机开放颜色*/
						if ((((ROUTE_LEAD_PROPERTY_YES == routeLeadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == routeLeadProperty))
							&& ((ROUTE_STATE_LEAD_LOCK == routeState) || (ROUTE_STATE_LEAD_LOCKERR == routeState) || (ROUTE_STATE_LEAD_OPEN == routeState)))
							|| (cRouteStartSigOpenColor != relationSignalOpenColor))
						{
							/* 引导进路或（列车进路但开放颜色不一致），返回失败 */
							ret = CI_ERROR;
						}
						else
						{/*对方开列车信号，本方只能办理列车信号，且非引导(0xbb)*/
							ret = CI_SUCCESS;
						}
					}
					else
					{
						ret = CI_ERROR;		/*对方开放列车信号，调车不允许办理*/
					}
				}
				break;
			default:
				ret = CI_ERROR;		/*其余颜色不可能设置，反馈失败*/
				break;
			}
		}
		else
		{
			ret = CI_ERROR;
		}
	}
	else
	{
		/* 进路状态获取失败 或者信号机状态获取失败，直接返回检查失败 */
		ret = CI_ERROR;
	}

	return ret;
}

/*
* 功能描述： 驱动车库门开门条件检查
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： CI_ERROR，检查失败   
*            CI_SUCCESS，检查通过
*/
UINT8 DriveGarageDoorOpenCheck(const UINT16 garageDoorId)
{
    UINT8 retVal = CI_ERROR;
	UINT8 jkjRelayValidFlag = GetCiJkjFlag();                     
	/*JKJ应急盘继电器有效标志*/
    UINT8 modeFlag = GetGaragedoorModeState(garageDoorId);    
	UINT8 faultFlag = GetGaragedoorFaultState(garageDoorId);
	UINT8 doorState = GetGaragedoorState(garageDoorId);
	UINT8 pangluState = GetGaragedoorPangLuState(garageDoorId);
    /*函数故障码*/
    UINT8 const functionId = EFUNC_CLD_CLOSE_GARAGEDOOR;  

    /*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ATS;/*发送ATS*/  
	

	if ((GARAGE_DOOR_SUM_MAX > garageDoorId) && (0U < garageDoorId))
	{
		retVal = CI_SUCCESS;
		/* 记录故障码 */
		if (JKJ_REYLAY_VALID == jkjRelayValidFlag)
		{/*应急盘继电器有效状态*/		
			SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, 0u, ETYPE_JKJ_WORK, RELAY_STATE_DOWN, sendLevel);/*增加OC应急控功能，继电器ID填0*/
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_STATE_MODE_LOCAL == modeFlag)
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_STATE_MODE_LOCAL, modeFlag, sendLevel);
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_FAULT_TRUE == faultFlag)
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_FAULT, faultFlag, sendLevel);
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_PANGLU_TRUE == pangluState)
		{
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_PANGLU, pangluState, ESEND_LEVEL_ZERO);
		}
		else if (GARAGE_DOOR_STATE_OPEN == doorState)
		{
			/*车库门为开门状态，且收到开门命令，此时不操作，将此条件移动到车库门故障和控制模式之后，
			是防止同时存在两种不满足条件反馈以上错误码*/
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_DRIVE_INVALID, doorState, ESEND_LEVEL_ZERO);
		}
		else
		{
			retVal = CI_SUCCESS;
		}
	}
	else
	{
		/*返回失败*/
	}
    
    return retVal;
}


/* 功能描述： 驱动车库门关门条件检查
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： CI_ERROR，检查失败   
*			 RETURN_GRGDOOR_CLSCHK_WAITALLOW， 等待
*            CI_SUCCESS，检查通过
*/
UINT8 DriveGarageDoorCloseCheck(const UINT16 garageDoorId)
{
    UINT8 retVal = CI_ERROR;
	UINT8 jkjRelayValidFlag = GetCiJkjFlag();                     
	/*JKJ应急盘继电器有效标志*/
    UINT8 modeFlag = GetGaragedoorModeState(garageDoorId);
	UINT8 faultFlag = GetGaragedoorFaultState(garageDoorId);
	UINT8 pangluState = GetGaragedoorPangLuState(garageDoorId);
    UINT16 wSpksSum = GetGarageSpksSum(garageDoorId);      /*车库门所关联的SPKS数量*/
    UINT16 spksId = 0u;   /*车库门所关联的SPKS ID*/
    UINT16 ii = 0u;
    UINT8 spksState = 0u;    /*spks封锁状态*/
    UINT16 phySum = GetGardoorphySecSum(garageDoorId);
    UINT16 phyId = 0u;
    UINT8 phyState = SECTION_OCCUPY_YES;
	UINT8 phyFLockState = PHYSICAL_SECTION_FLOCK_YES;
	UINT8 phyLockState = PHYSICAL_SECTION_LOCK_NORMAL;/*物理区段锁闭状态*/
    UINT16 jj = 0u;
	UINT32 responseZCStartCyc = 0U;/*等待ZC反馈起始周期*/
	UINT32 responseIVOCStartCyc = 0U;/*等待IVOC反馈起始周期*/

    /*函数故障码*/
    UINT8 const functionId = EFUNC_CLD_CLOSE_GARAGEDOOR;  

    /*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ATS;/*发送ATS*/     
	UINT8 rcWorkMode = 0U;             /*工作模式*/
	

	UINT8 doorState = GetGaragedoorState(garageDoorId);

	rcWorkMode = GetLocalRcWorkMode();		/*RC工作模式获取*/

	if ((GARAGE_DOOR_SUM_MAX > garageDoorId) && (0U < garageDoorId))
	{
		retVal = CI_SUCCESS;
		/* 记录故障码 */
		if (JKJ_REYLAY_VALID == jkjRelayValidFlag)
		{/*应急盘继电器有效状态*/
			SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, 0u, ETYPE_JKJ_WORK, RELAY_STATE_DOWN, sendLevel);/*增加OC应急控功能，继电器ID填0*/
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_STATE_MODE_LOCAL == modeFlag)
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_STATE_MODE_LOCAL, modeFlag, sendLevel);
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_FAULT_TRUE == faultFlag)
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_FAULT, faultFlag, sendLevel);
			retVal = CI_ERROR;
		}
		else if (GARAGE_DOOR_PANGLU_TRUE == pangluState)
		{
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_PANGLU, pangluState, ESEND_LEVEL_ZERO);
		}
		else if (GARAGE_DOOR_STATE_CLOSE == doorState)
		{
			/*车库门为关门状态，且收到关门命令，此时不操作，将此条件移动到车库门故障和控制模式之后，
			是防止同时存在两种不满足条件反馈以上错误码*/
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_GARAGEDOOR, garageDoorId, ETYPE_GARAGEDOOR_DRIVE_INVALID, doorState, ESEND_LEVEL_ZERO);
		}
		else
		{
			/*所有SPKS无效，且相关的物理区段全部为空闲，则通过检查*/
			for (ii = 0u; ii < wSpksSum; ii++)
			{
				spksId = GetGarageSpksIdBuff(garageDoorId, ii);
				spksState = GetSpksState(spksId);
				if ((SPKS_STATUS_NO == spksState) || (GetSpksCutState(spksId) == SPKS_CUT_YES))   /*未封锁 或 旁路*/
				{
					retVal = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_SPKS, spksId, ETYPE_SPKS_STATE_UP, spksState, sendLevel);
					retVal = CI_ERROR;
					break;           /*有一个SPKS有效则返回*/
				}
			}
			if (CI_SUCCESS == retVal)
			{
				if (phySum == 0u)
				{
					retVal = CI_ERROR;
				}
				else if (phySum > 0u)
				{
					for (jj = 0u; jj < phySum; jj++)
					{
						phyId = GetGardoorphySecBuf(garageDoorId, jj);
						phyState = GetPhySecCurAndMergeState(phyId);
						phyFLockState = GetPhySecFLockState(phyId);
						phyLockState=GetPhySecLockState(phyId);
						if ((SECTION_OCCUPY_NO == phyState) && (PHYSICAL_SECTION_FLOCK_NO == phyFLockState) && (PHYSICAL_SECTION_LOCK_NO == phyLockState))
						{
							retVal = CI_SUCCESS;
						}
						else if (PHYSICAL_SECTION_FLOCK_YES == phyFLockState)
						{/* 记录故障码 */
							SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phyId, ETYPE_PS_FLOCK_STATE, phyFLockState, sendLevel);
							retVal = CI_ERROR;
							break;           /*有一个区段封锁则返回*/
						}
						else
						{
							retVal = RETURN_GRGDOOR_CLSCHK_WAITALLOW;     /*有一个区段占用或锁闭则向zc发送申请*/
							break;

						}
					}
				}
				else
				{
					/*<0情况不存在，不予处理*/
				}
			}
			responseZCStartCyc = GetWaiteZCResponseStartCycNum(garageDoorId);
			responseIVOCStartCyc = GetWaiteIVOCResponseStartCycNum(garageDoorId);

			if ((RETURN_GRGDOOR_CLSCHK_WAITALLOW == retVal) && (0u == responseZCStartCyc) && (RC_WORK_MODE_CI == rcWorkMode))
			{
				SetWaiteZCResponseStartCycNum(garageDoorId, Get2oo2CurCycleNum());   /*设置等待ZC反馈起始周期号*/
			}
			if ((RETURN_GRGDOOR_CLSCHK_WAITALLOW == retVal) && (0u == responseIVOCStartCyc) && (RC_WORK_MODE_TIOC == rcWorkMode))
			{
				SetWaiteIVOCResponseStartCycNum(garageDoorId, Get2oo2CurCycleNum());   /*设置等待IVOC反馈起始周期号*/
			}

		}
	}
    return retVal;
}

/* 功能描述： RC模式下存在占用时，车库门关门条件检查
*  参数说明： const UINT16 garageDoorId, 车库门ID
*           const UINT8 sendLevel   是否向ATS发送对应报警
*  返回值：  CI_ERROR，检查失败
*           CI_SUCCESS，检查通过
* BY LC
*/
UINT8 GarageDoorCloseCheckinRCMode(const UINT16 garageDoorId, const UINT8 sendLevel)
{
	UINT8 retVal = CI_ERROR;

	/*函数故障码*/
	UINT8 const functionId = EFUNC_CLD_CHECK_GARAGEDOOR_CLOSE;

	if ((GARAGE_DOOR_SUM_MAX > garageDoorId) && (0U < garageDoorId))
	{
		/*车库门相邻计轴条件检查*/
		retVal = CheckAdjacentACOfGarageDoor(garageDoorId, functionId, sendLevel);

		/*车库门A库轨条件检查*/
		if (CI_SUCCESS == retVal)
		{
			retVal = CheckAkuPhysecOfGarageDoor(garageDoorId, functionId, sendLevel);
		}

		/*车库门A库物理区段最接近列车检查*/
		if (CI_SUCCESS == retVal)
		{
			retVal = CheckNearestTrainOfGarageDoor(garageDoorId, functionId, sendLevel);
		}
	}
	else
	{
		/*返回失败*/
	}
	return retVal;
}


/* 功能描述： 车库门关门相邻计轴条件检查
*  参数说明： const UINT16 garageDoorId, 车库门ID
*           const  UINT8 functionId  调用函数编号
*           const UINT8 sendLevel   故障码发送级别
*  返回值：  CI_ERROR，检查失败
*           CI_SUCCESS，检查通过
* BY LC
*/
UINT8 CheckAdjacentACOfGarageDoor(const UINT16 garageDoorId, const  UINT8 functionId, const UINT8 sendLevel)
{
	UINT8 retVal = CI_ERROR;
	UINT16 adjacentACID[GARAGE_DOOR_ADJACENT_AXIS] = { 0U }; /*相邻计轴ID数组*/
	UINT8 adjacentACNum = 0U;    /*相邻计轴数量*/
	UINT16 occuAdjacentACID[GARAGE_DOOR_ADJACENT_AXIS] = { 0U }; /*被占用的相邻计轴ID数组*/
	UINT8 occuAdjacentACNum = 0U;    /*被占用的相邻计轴数量*/
	UINT8 tempAcStatus = 0U;    
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 attribute = 0U;

	UINT16 devId = 0U;
	UINT8 devState = 0U;

	/*查询车库门的相邻计轴——车库门对应A库线物理区段包含计轴及其出库方向第一个关联计轴*/
	adjacentACNum = GetGarageDoorAdjacentAC(garageDoorId, adjacentACID);
	if ((0U != adjacentACNum) && (GARAGE_DOOR_ADJACENT_AXIS > adjacentACNum))
	{/*相邻计轴查询成功*/

		retVal = CI_SUCCESS;
		/*遍历车库门相邻计轴，筛选存在占用的相邻计轴*/
		for (i = 0U; i < adjacentACNum; i++)
		{
			tempAcStatus = elm_PrepareACStatus(adjacentACID[i]);
			if (ELM_AC_OCC == tempAcStatus)
			{
				occuAdjacentACID[occuAdjacentACNum] = adjacentACID[i];
				occuAdjacentACNum += 1U;
			}
			else
			{
				/*此计轴未占用，继续检查*/
			}
		}
		attribute = GetGarageDoorAttribute(garageDoorId);


		if (GARAGE_DOOR_ATTRIBUTE_LJK == attribute)
		{
			if (0U == occuAdjacentACNum)
			{
				/*相邻计轴不存在占用，直接返回检查通过*/
			}
			else
			{
				for ( j = 0U; j < occuAdjacentACNum; j++)
				{
					/*检查被占压区段是否仅为A库线休眠轨  并且 A库线休眠轨为VBTC占用*/
					retVal &= CheckGarageDoorSleepAC(garageDoorId, occuAdjacentACID[j]);
					retVal &= CheckGarageDoorAKuIsCTOccu(garageDoorId);

					if (CI_ERROR == retVal)
					{
						devId = elm_PrepareACRelPhyId(occuAdjacentACID[j]);
						devState = GetPhySecCurMergeState(devId);
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
						break;
					}
				}
				
			}
		}
		else if (GARAGE_DOOR_ATTRIBUTE_XCK == attribute)
		{
			if (0U == occuAdjacentACNum)
			{
				/*相邻计轴不存在占用，返回检查通过*/
			}
			else
			{
				/*洗车库相邻计轴存在占用，返回失败*/
				retVal = CI_ERROR; 

				devId = elm_PrepareACRelPhyId(occuAdjacentACID[0]);
				devState = GetPhySecCurMergeState(devId);
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			}
		}
		else
		{
			/*无效属性*/
			retVal = CI_ERROR;
		}
	}
	else
	{
		/*查找相邻计轴失败*/
	}
	return retVal;
}

/* 功能描述： 车库门最接近列车条件检查
*  参数说明： const UINT16 garageDoorId, 车库门ID
*           const  UINT8 functionId  调用函数编号
*           const UINT8 sendLevel   故障码发送级别
*  返回值：  CI_ERROR，检查失败
*           CI_SUCCESS，检查通过
* BY LC
*/
UINT8 CheckNearestTrainOfGarageDoor(const UINT16 garageDoorId, const  UINT8 functionId, const UINT8 sendLevel)
{
	UINT8 aKuPhyOccuStatus = 0U;
	UINT8 retVal = CI_ERROR;
	UINT16 trainId = 0U;  /*最接近列车ID*/
	UINT8 chSleepState = TRAIN_SLEEP_NO; /*列车休眠状态*/
	str_Zone strTrainZone = { 0u };
	struct_PathPoint gdPoint = { 0U };
	UINT8 containFlag = CI_ERROR;
	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/

	aKuPhyOccuStatus = GetGarageDoorAKuIsOccu(garageDoorId);

	if (CI_SUCCESS == aKuPhyOccuStatus)
	{/*无占用，检查通过*/

		SetGaragedoorNearestTrainId(garageDoorId, 0U);
		retVal = CI_SUCCESS;

	}
	else
	{
		/*查询A库线离车库门最近的通信车*/
		trainId = FindNearestTrainInAKuPhy(garageDoorId);
		retVal = CI_SUCCESS;

		if ((UINT16_MAX != trainId) && (0U != trainId) && (NAME_FAILUREAREA != trainId))
		{
			SetGaragedoorNearestTrainId(garageDoorId, trainId);

			/*检查列车为休眠车*/
			chSleepState = GetTrainSleepState(trainId);
			if (TRAIN_SLEEP_YES == chSleepState)
			{
				/*休眠车，检查通过，不发送开门申请*/
				SetGaragedoorNearestTrainId(garageDoorId, 0U);
			}
			else
			{/*列车未休眠*/

				/*检查列车接近车库门一端无可疑*/
				retVal = CheckNearestTrainScreen(garageDoorId, trainId, functionId, sendLevel);

				
				if (CI_SUCCESS == retVal)
				{
					/*检查列车未跨压车库门*/
					retVal = CheckNearestTrainKuaya(garageDoorId, trainId, functionId, sendLevel);
				}

				/*最接近列车无可疑且包络未跨压车库门，检查通过*/
				
			}
			
		}
		else
		{
			/*存在隐藏车，返回失败*/
			retVal = CI_ERROR;
			devId = GetGarageDoorAKuPhySec(garageDoorId);
			devState = GetPhySecCurMergeState(devId);
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
		}
	}
	return retVal;

}

/* 功能描述： 车库门区段锁闭条件检查
*  参数说明： const UINT16 garageDoorId, 车库门ID
*           const  UINT8 functionId  调用函数编号
*           const UINT8 sendLevel   故障码发送级别
*  返回值：  CI_ERROR，检查失败
*           CI_SUCCESS，检查通过
* BY LC
*/
UINT8 CheckAkuPhysecOfGarageDoor(const UINT16 garageDoorId, const  UINT8 functionId, const UINT8 sendLevel)
{
	UINT8 retVal = CI_ERROR;
	
	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/

	UINT16 phySecAId = 0U; /*车库门对应A库物理区段ID*/
	UINT8 attribute = 0U;/*车库门属性*/
	UINT8 occuState = 0U;/*A库轨占用状态*/
	UINT8 lockState = 0U;/*A库轨锁闭状态*/
	/*获取车库门对应A库物理区段*/
	phySecAId = GetGarageDoorAKuPhySec(garageDoorId);

	/*获取车库门属性*/
	attribute = GetGarageDoorAttribute(garageDoorId);

	/*检查A库轨占用状态*/
	occuState = GetPhySecCurMergeState(phySecAId);
	/*检查A库轨锁闭状态*/
	lockState = GetPhySecLockState(phySecAId);
	/*列检库*/
	if (GARAGE_DOOR_ATTRIBUTE_LJK == attribute)
	{
		if (PHYSICAL_SECTION_LOCK_NO == lockState) 
		{
			/*A库轨未锁闭 且 不存在占用*/
			if (SECTION_OCCUPY_NO == occuState)
			{
				/*检查通过*/
				retVal = CI_SUCCESS;
			}
			else
			{
				/*检查不通过，报警A库轨占用*/
				devId = phySecAId;
				devState = occuState;
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			}
		}
		else if (PHYSICAL_SECTION_LOCK_NORMAL == lockState)
		{
			/*A库轨锁闭 且 存在占用*/
			if (SECTION_OCCUPY_YES == occuState)
			{
				/*检查通过*/
				retVal = CI_SUCCESS;
			}
			else
			{
				/*检查不通过，报警A库轨锁闭*/
				devId = phySecAId;
				devState = lockState;
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
			}
		}
		else
		{
			/*检查不通过，报警A库轨锁闭状态*/
			devId = phySecAId;
			devState = lockState;
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
		}
		
	}
	else if (GARAGE_DOOR_ATTRIBUTE_XCK == attribute)
	{
		retVal = CheckGDAdjacentACLockState(garageDoorId, &devId, &devState);
		/*相邻计轴未锁闭*/
		if (CI_SUCCESS == retVal)
		{
			/*检查通过*/
		}
		else
		{
			/*检查不通过，报警物理区段锁闭*/
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
		}
	}
	else
	{
		/*属性错误，返回失败*/
	}

	return retVal;
}




/* L14_点式进路信号保持其他信号联锁条件检查 */
/*
* 功能描述： 点式进路信号保持其他信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 KeepBlocRouteOtherSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/

    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

    /* 进路内设备数据 */            
    /*进路相关需开放信号机*/
    UINT8 const needOpenSigSum = GetRouteOpenNeedOpenSigSum(routeId);
    UINT16* const pNeedOpenBuf = GetRouteOpenNeedOpenSigIdBuf(routeId);
    /*进路相关不能同时开放信号机*/
    UINT8 const oneOpenSigSum = GetRouteOnlyOneOpenSigSum(routeId);
    UINT16* const pOneOpenBuf = GetRouteOnlyOneOpenSigIdBuf(routeId);    
    /*进路相关需关闭信号机*/
    UINT8 const needCloseSigSum = GetRouteOpenNeedCloseSigSum(routeId);
    UINT16* const pNeedCloseBuf = GetRouteOpenNeedCloseSigIdBuf(routeId); 

    /*进路开放信号机需检查相关折返进路*/
    UINT8 const zheFanRouteSum = GetRtnEndSigAsStartSigRouteSum(routeId);
    UINT16 * const zheFanRouteIdBuf = GetReturnEndSigAsStartSigRoute(routeId); 
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);

    /* 联锁逻辑检查 */  

    /*进路相关需开放信号机已开放*/
    devId = 0u;
    devState = 0u;
    checkResult = SignalBufOpenCloseStateCheck(pNeedOpenBuf,needOpenSigSum,SIGNAL_OPEN,&devId,&devState);
    if (checkResult == CI_SUCCESS)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_NEED_OPEN_STATE,devState,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;

    }

    if (CI_SUCCESS == reResult)
    {
        /*进路相关不能同时开放信号机未开放*/
        devId = 0u;
        devState = 0u;
        checkResult = SignalBufOpenCloseStateCheck(pOneOpenBuf,oneOpenSigSum,SIGNAL_CLOSE,&devId,&devState);
        if (checkResult == CI_SUCCESS)
        {
            /* 通过检查 */
            reResult = CI_SUCCESS;
        }
        else
        {
            /* 记录故障码 */
            SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ONE_OPEN_STATE,devState,sendLevel); 
            /* 失败返回 */
            reResult = CI_ERROR;

        }
    }

    if (CI_SUCCESS == reResult)
    {
        /*进路相关需关闭信号机已关闭 */
        devId = 0u;
        devState = 0u;
        checkResult = SignalBufOpenCloseStateCheck(pNeedCloseBuf,needCloseSigSum,SIGNAL_CLOSE,&devId,&devState);
        if (checkResult == CI_SUCCESS)
        {
            /* 通过检查 */
            reResult = CI_SUCCESS;
        }
        else
        {
            /* 记录故障码 */
            SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_NEED_CLOSE_STATE,devState,sendLevel); 
            /* 失败返回 */
            reResult = CI_ERROR;

        }
    }

    if (CI_SUCCESS == reResult)
    {
        /*以始端信号机作为终端信号机的折返进路是否已经办理成功检查*/
        devId = 0u;
        devState = 0u;
        checkResult = RtnEndSigAsStartSigRouteCheck(zheFanRouteIdBuf,zheFanRouteSum,&devId,&devState);
        if(CI_SUCCESS == checkResult)
        {
            /* 通过检查 */
            reResult = CI_SUCCESS;		
        }
        else
        {
            /* 记录故障码 */
			/*原报警ETYPE_SIG_RETURN_OPENED_STATE，出现因进路id顺序出现报警不一致*/
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, SIGNAL_CLOSE, sendLevel);
            reResult = CI_ERROR;
        }
    }

    /* 返回结果 */
    return reResult;
}
#if 0
/*
* 功能描述： 点式进路信号保持其他信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 KeepCbtcRouteOtherSignalCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

										 /* 进路内设备数据 */
										 /*进路相关需开放信号机*/
	UINT8 const needOpenSigSum = GetRouteCbtcNeedOpenSigSum(routeId);
	UINT16* const pNeedOpenBuf = GetRouteCbtcNeedOpenSigIdBuf(routeId);
	/*进路相关不能同时开放信号机*/
	UINT8 const oneOpenSigSum = GetRouteOnlyOneOpenSigSum(routeId);
	UINT16* const pOneOpenBuf = GetRouteOnlyOneOpenSigIdBuf(routeId);
	/*进路相关需关闭信号机*/
	UINT8 const needCloseSigSum = GetRouteOpenNeedCloseSigSum(routeId);
	UINT16* const pNeedCloseBuf = GetRouteOpenNeedCloseSigIdBuf(routeId);

	/*进路开放信号机需检查相关折返进路*/
	UINT8 const zheFanRouteSum = GetRtnEndSigAsStartSigRouteSum(routeId);
	UINT16 * const zheFanRouteIdBuf = GetReturnEndSigAsStartSigRoute(routeId);


	/* 联锁逻辑检查 */

	/*进路相关需开放信号机已开放*/
	devId = 0u;
	devState = 0u;
	checkResult = SignalBufOpenCloseStateCheck(pNeedOpenBuf, needOpenSigSum, SIGNAL_OPEN, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_OPEN_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关不能同时开放信号机未开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pOneOpenBuf, oneOpenSigSum, SIGNAL_CLOSE, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_ONE_OPEN_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需关闭信号机已关闭 */
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedCloseBuf, needCloseSigSum, SIGNAL_CLOSE, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_CLOSE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*以始端信号机作为终端信号机的折返进路是否已经办理成功检查*/
		devId = 0u;
		devState = 0u;
		checkResult = ReturnEndSigAsRouteStartSigRouteStateCheck(zheFanRouteIdBuf, zheFanRouteSum, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, devId, ETYPE_SIG_RETURN_OPENED_STATE, devState, sendLevel);
			reResult = CI_ERROR;
		}
	}

	/* 返回结果 */
	return reResult;
}
#endif
/* L12_点式进路信号开放其他信号联锁条件检查 */
/*
* 功能描述： 点式进路信号开放其他信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*			 RETURN_OPEN_ERR_SIGOPEN
*/
UINT8 OpenBlocRouteOtherSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
    UINT8 routeState = 0u;		/*进路状态*/
	UINT8 cRouteLeadProperty = 0U;  /*引导属性*/
	UINT32 dwStartCycNum = 0U;  /*信号开放起始周期*/
	UINT32 dwOpenMaxCount = 0U;  /*信号开放超限周期数*/
    
/* 进路内设备数据 */            
    /* 开放信号时间状态*/
    UINT8 routeTimeState = CI_TIME_OUT;
    /*进路相关需开放信号机*/
    UINT8 const needOpenSigSum = GetRouteOpenNeedOpenSigSum(routeId);
    UINT16* const pNeedOpenBuf = GetRouteOpenNeedOpenSigIdBuf(routeId);
    /*进路相关不能同时开放信号机*/
    UINT8 const oneOpenSigSum = GetRouteOnlyOneOpenSigSum(routeId);
    UINT16* const pOneOpenBuf = GetRouteOnlyOneOpenSigIdBuf(routeId);    
    /*进路相关需关闭信号机*/
    UINT8 const needCloseSigSum = GetRouteOpenNeedCloseSigSum(routeId);
    UINT16* const pNeedCloseBuf = GetRouteOpenNeedCloseSigIdBuf(routeId);
    
	/*进路开放信号机需检查相关折返进路*/
	UINT8 const zheFanRouteSum = GetRtnEndSigAsStartSigRouteSum(routeId);
	UINT16* const zheFanRouteIdBuf = GetReturnEndSigAsStartSigRoute(routeId);

	UINT8 signalVirtualAttr = SIGNAL_VIRTUAL_NO;/*虚拟信号机属性*/
	UINT8 repeatOpenFlag = ROUTE_REPEATOPEN_SET_NO;/*重开标志*/
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);/*始端信号机id*/
	
    /* 联锁逻辑检查 */	
	cRouteLeadProperty = GetRouteLeadProperty(routeId);
	routeState = GetRouteState(routeId);/*获取进路状态*/
	if (((ROUTE_LEAD_PROPERTY_YES == cRouteLeadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == cRouteLeadProperty)) && (ROUTE_STATE_LEAD_LOCK  == routeState))
	{
		dwOpenMaxCount = GetSystemParaSignalOpenCyc(); /*引导进路采用信号开放超限时间*/
	}
	else
	{
		dwOpenMaxCount = GetSystemParaRouteOpenSigCyc();/*非引导进路采用信号开放超限时间*/
	}

	dwStartCycNum = GetRouteOpenSigStatrtCycNum(routeId);
	routeTimeState = SystemOverTimeCheck(dwStartCycNum, dwOpenMaxCount);

    /*进路开放信号超时检查*/
    if (CI_TIME_OUT != routeTimeState)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
		devId = GetRouteStartSignalId(routeId);/*获取进路始端信号机ID*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_OPEN_OVERTIME,routeTimeState,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需开放信号机已开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedOpenBuf,needOpenSigSum,SIGNAL_OPEN,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			
			repeatOpenFlag = GetRouteRepeatOpenFlag(routeId);

			if ((ROUTE_STATE_FIRST_LOCKERR == routeState) && (ROUTE_REPEATOPEN_SET_YES == repeatOpenFlag))
			{
				/*初锁异常，且重开信号时发送报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_OPEN_STATE, devState, sendLevel);
			}
			else if (ROUTE_STATE_FIRST_LOCKERR != routeState)
			{/*cgh-合并CID-2539-3：*/
				/*进路初锁、预先锁闭、引导锁闭、接近锁闭异常、接近锁闭正常时报警，m by yt 2022年8月3日*/
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_OPEN_STATE, devState, sendLevel);
			}
			else
			{
				; /*不进行报警*/
			}

			if (devId>0u)
			{
				signalVirtualAttr = GetSignalVirtualAttr(devId);
				if (SIGNAL_VIRTUAL_YES == signalVirtualAttr)
				{
					reResult = RETURN_OPEN_ERR_NEEDOPEN;
				}
				else
				{
					reResult = CI_ERROR;
				}
			} 
			else
			{
				reResult = CI_ERROR;
			}		
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关不能同时开放信号机未开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pOneOpenBuf,oneOpenSigSum,SIGNAL_CLOSE,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ONE_OPEN_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需关闭信号机已关闭 
		  失败返回 RETURN_OPEN_ERR_SIGOPEN*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedCloseBuf,needCloseSigSum,SIGNAL_CLOSE,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{

        	reResult = RETURN_OPEN_ERR_SIGOPEN;
		} 
	}

	if (CI_SUCCESS == reResult)
	{
		/*以始端信号机作为终端信号机的折返进路是否已经办理成功检查*/
		devId = 0u;
		devState = 0u;
		checkResult = RtnEndSigAsStartSigRouteCheck(zheFanRouteIdBuf,zheFanRouteSum,&devId,&devState);
		if(CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;		
		}
		else
		{
			/* 记录故障码 */
			/*原报警ETYPE_SIG_RETURN_OPENED_STATE 出现因进路id顺序出现报警不一致 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, SIGNAL_CLOSE, sendLevel);
			reResult = CI_ERROR;
		}
	}

    /* 返回结果 */
    return reResult;
}

/*
* 功能描述：CBTC进路信号开放其他信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*			 RETURN_OPEN_ERR_SIGOPEN
*/
UINT8 OpenCbtcRouteOtherSignalCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 routeState = 0u;		/*进路状态*/

	/* 进路内设备数据 */
	/* 开放信号时间状态*/
	UINT8 const routeTimeState = SystemOverTimeCheck(GetRouteOpenSigStatrtCycNum(routeId),
		GetSystemParaRouteOpenSigCyc());
	/*进路相关需开放信号机*/
	UINT8 const needOpenSigSum = GetRouteCbtcNeedOpenSigSum(routeId);
	UINT16* const pNeedOpenBuf = GetRouteCbtcNeedOpenSigIdBuf(routeId);
	/*进路相关不能同时开放信号机*/
	UINT8 const oneOpenSigSum = GetRouteOnlyOneOpenSigSum(routeId);
	UINT16* const pOneOpenBuf = GetRouteOnlyOneOpenSigIdBuf(routeId);
	/*进路相关需关闭信号机*/
	UINT8 const needCloseSigSum = GetRouteOpenNeedCloseSigSum(routeId);
	UINT16* const pNeedCloseBuf = GetRouteOpenNeedCloseSigIdBuf(routeId);

	/*进路开放信号机需检查相关折返进路*/
	UINT8 const zheFanRouteSum = GetRtnEndSigAsStartSigRouteSum(routeId);
	UINT16* const zheFanRouteIdBuf = GetReturnEndSigAsStartSigRoute(routeId);

	UINT8 signalVirtualAttr = SIGNAL_VIRTUAL_NO;/*虚拟信号机属性*/
	UINT8 repeatOpenFlag = ROUTE_REPEATOPEN_SET_NO;/*重开标志*/
	UINT8 needOpenNotTrueRepeatFlag = ROUTE_NEEDOPEN_REOPEN_NO;/*需开放不满足重开标志*/
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);/*始端信号机id*/

	routeState = GetRouteState(routeId);/*获取进路状态*/
										/* 联锁逻辑检查 */

										/*进路开放信号超时检查*/
	if (CI_TIME_OUT != routeTimeState)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		devId = GetRouteStartSignalId(routeId);/*获取进路始端信号机ID*/
											   /* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_OPEN_OVERTIME, routeTimeState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需开放信号机已开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedOpenBuf, needOpenSigSum, SIGNAL_OPEN, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			
			repeatOpenFlag = GetRouteRepeatOpenFlag(routeId);
			if ((ROUTE_STATE_FIRST_LOCKERR == routeState) && (ROUTE_REPEATOPEN_SET_YES == repeatOpenFlag))
			{
				/*初锁异常，且重开信号时发送报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_OPEN_STATE, devState, sendLevel);
			}
			else if (ROUTE_STATE_FIRST_LOCKERR != routeState)
			{/*cgh-合并CID-2539-3：*/
			 /*进路初锁、预先锁闭、引导锁闭、接近锁闭异常、接近锁闭正常时报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_NEED_OPEN_STATE, devState, sendLevel);
			}
			else
			{
				; /*不进行报警*/
			}

			if (devId>0u)
			{
				signalVirtualAttr = GetSignalVirtualAttr(devId);
				if (SIGNAL_VIRTUAL_YES == signalVirtualAttr)
				{
					reResult = RETURN_OPEN_ERR_NEEDOPEN;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}
			else
			{
				reResult = CI_ERROR;
			}
			/* 失败返回 */


		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关不能同时开放信号机未开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pOneOpenBuf, oneOpenSigSum, SIGNAL_CLOSE, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_ONE_OPEN_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需关闭信号机已关闭
		失败返回 RETURN_OPEN_ERR_SIGOPEN*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedCloseBuf, needCloseSigSum, SIGNAL_CLOSE, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{

			reResult = RETURN_OPEN_ERR_SIGOPEN;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*以始端信号机作为终端信号机的折返进路是否已经办理成功检查*/
		devId = 0u;
		devState = 0u;
		checkResult = RtnEndSigAsStartSigRouteCheck(zheFanRouteIdBuf, zheFanRouteSum, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			/*原报警ETYPE_SIG_RETURN_OPENED_STATE 出现因进路id顺序出现报警不一致 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, SIGNAL_CLOSE, sendLevel);
			reResult = CI_ERROR;
		}
	}

	/* 返回结果 */
	return reResult;
}
/*
* 功能描述： 进路内区段跳跃锁闭状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： 失败返回CI_ERROR   
*            成功返回CI_SUCCESS 
*/
UINT8 RouteAllSecJumpLockStateCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;

	/*进路数据*/
	/* 进路区段*/
	UINT8 const routeSectionSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const pRouteSectionDataBuf = GetRouteSectionData(routeId);
	UINT8 reVal = CI_ERROR;

	/* 区段跳跃锁闭状态检查 */
	if (0u == routeSectionSum) 
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/ 
		for (i = 0u; i<routeSectionSum; i++)
		{
			devId = pRouteSectionDataBuf[i].PhysicalSectionId;
			devState = GetPhySecJumpLockState(devId);/*获取跳跃锁闭状态*/

			/* 需检查本区段 */ 
			if (PHYSICAL_SECTION_JUMP_LOCK_NO != devState)
			{
				/*状态不等于未跳跃锁闭返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
			else
			{
				reVal = CI_SUCCESS;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 保护区段内区段跳跃锁闭状态检查
* 参数说明： UINT16 const overlapId,    保护区段ID
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： 失败返回CI_ERROR   
*            成功返回CI_SUCCESS 
*/
UINT8 OverlapAllSecJumpLockStateCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;

	/* overlap区段 */
	UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
	UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);
	UINT8 reVal = CI_SUCCESS;

	/* 区段跳跃锁闭状态检查 */
	if (0u == checkSum) 
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/ 
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecJumpLockState(devId);/*获取跳跃锁闭状态*/

			/* 需检查本区段 */ 
			if (PHYSICAL_SECTION_JUMP_LOCK_NO != devState)
			{
				/*状态不等于未跳跃锁闭返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
			else
			{
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 进路信号保持道岔联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 KeepRouteSwitchCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 FSwitchFlag = 0u;

	UINT8 lineIdentity = CI_TRADITION_RAILWAY;

	/* 进路内设备数据 */

	lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取线路标识*/    

	/* 联锁逻辑检查 */ 

	FSwitchFlag = GetCiFunctionSwitchConfig(CLOSE_OPENED_SIG_LOCK_SWITCH);
	if (FUNC_SWITCH_OFF == FSwitchFlag)    /*开关未打开则不检查道岔封锁状态*/
	{
		reResult = CI_SUCCESS;
	} 
	else if(FUNC_SWITCH_ON == FSwitchFlag) 
	{
		/*进路内所有道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSwitchFLockCheck(routeId,&devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}

		if (CI_SUCCESS == reResult)
		{
			/*进路防护道岔【未封锁】*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteReltProtSwitchFLockCheck(routeId,&devId, &devState);

			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		
	}
	else
	{
		reResult = CI_ERROR;
	}


	if (CI_SUCCESS == reResult)
	{
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*进路所有道岔位置正确*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		reResult = CI_ERROR;
	}

	/* zt 删除单轨相关代码 2022-02-15 */

	if (CI_SUCCESS == reResult)
	{/*进路保持开放防护道岔检查*/
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*进路关联防护道岔位置正确*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteRelatedProSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}

			if (CI_SUCCESS == reResult)
			{
				/*进路关联防护道岔【防护锁闭】或【单锁且防护锁闭】*/
				devId = 0u;
				devState = 0u;
				checkResult = RouteRelatedProSwitchLockCheck(routeId,&devId, &devState);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_LOCK_STATUS,devState,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			} 
			else
			{
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = RouteAllLtrlDfncSwitchCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	/* 返回结果 */
	return reResult;
}

/*
* 功能描述： 保持列车进路信号机联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 KeepLTrainRouteSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 FSwitchFlag = 0u;

	/* 进路内设备数据 */
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);

	/* 联锁逻辑检查 */  

	/* 进路始端信号机上周期驱动颜色为【开放】*/
	devState = GetSignalOpenCloseState(GetSignalPreDriveColor(startSignalId));
	if (devState == SIGNAL_OPEN)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,startSignalId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		FSwitchFlag = GetCiFunctionSwitchConfig(CLOSE_OPENED_SIG_LOCK_SIGNAL);
		if (FUNC_SWITCH_OFF == FSwitchFlag)
		{
			reResult = CI_SUCCESS;  /*开关未打开则不检查信号机封锁状态*/
		}
		else if(FUNC_SWITCH_ON == FSwitchFlag)
		{

			/*进路内所有信号机【未封锁】*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);

			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;

			}
		}
		else
		{
			/*不做处理*/
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路的敌对条件不成立*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalEnemyVainCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{/*检查终端信号机断丝*/
		reResult = CheckRouteEndSignalDS(routeId,functionId,sendLevel);
	}

	/* 返回结果 */
	return reResult;
}

/* L07_点式进路锁闭道岔联锁条件检查 */
/*
* 功能描述： 点式进路锁闭道岔联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*			RETURN_LOCK_ERR_SWITPOS 道岔位置不正确
*/
UINT8 LockBlocRouteSwitchCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
	UINT8 reResultP = CI_ERROR;          /*保护区段局部检查返回值*/

    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
    
	UINT8 lineIdentity = CI_TRADITION_RAILWAY;
	UINT32 startCycNum = GetRouteXuanPaiStartCycNum(routeId); /*选排起始周期号*/
	UINT32 startCycMax = GetSystemParaRouteXuanPaiCyc(); /*选排超限周期数*/

/* 进路内设备数据 */
    /* 选排锁闭超时状态 */
	UINT8 const routeTimeState = SystemOverTimeCheck(startCycNum, startCycMax);
	UINT8 chConnetCheckFunc = 0U;

	chConnetCheckFunc = GetCiFunctionSwitchConfig(FUNC_SETROUTE_CONNECT_CHECK);		/*获取是否要检查联络线条件的开关*/

	lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取线路标识*/    
/* 联锁逻辑检查 */  
    

    /*进路内所有道岔【未引导总锁】*/
    devId = 0u;
    devState = 0u;
    checkResult = RouteSwitchYLockCheck(routeId,&devId, &devState);
    if (CI_SUCCESS == checkResult)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

	if (CI_SUCCESS == reResult)
	{
		/*进路内所有道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSwitchFLockCheck(routeId,&devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路防护道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteReltProtSwitchFLockCheck(routeId,&devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路锁闭时间超时检查*/
		/*判断为CI_TIME_IN时会存在普通进路转引导时此处超时(因为选排时间为0)*/
		if (CI_TIME_OUT == routeTimeState )
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE,routeId, ETYPE_ROUTE_XUANPAI_OVERTIME,routeTimeState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
		else
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
	}
	
	if (CI_SUCCESS == reResult)
	{
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = RouteAllLtrlDfncSwitchCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{
		if (FUNC_SWITCH_ON == chConnetCheckFunc)
		{
			;	/*开关打开，不检查联络线条件*/
		}
		else
		{
			/*进路联络线设备条件检查*/
			checkResult = RouteContactLineDevSwitchCheck(routeId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	if (CI_SUCCESS == reResult)
	{
		if (CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*进路内所有道岔位置正确或位置不正确但可动作*/
			devId = 0u;
			devState = 0u;

			checkResult = RouteSwitchPosAndMoveValidCheck(routeId, sendLevel);

			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = checkResult;
			}
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/* 
			进路内所有道岔位置正确
				不正确：RETURN_LOCK_ERR_SWITPOS
				正确：CI_SUCCESS
			*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = RETURN_LOCK_ERR_SWITPOS;
				
			}
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/*如果是进路内道岔等待相邻联锁反馈道岔检查状态,先不检查道岔是否全在位置，继续等待*/
	}

	if((CI_SUCCESS == reResult)||(RETURN_LOCK_ERR_SWITPOS == reResult))
	{/*进路锁闭防护道岔检查*/
		/*进路关联防护道岔【未引导总锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteRelatedProSwitchYLockCheck(routeId,&devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResultP = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResultP = CI_ERROR;
		}

		if (CI_SUCCESS == reResultP)
		{
			/*进路关联防护道岔位置正确或位置不正确但可动作*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteRelProSwiPosAndMovValCheck(routeId,sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResultP = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResultP = checkResult;
			}
		} 
		else
		{
			reResultP = CI_ERROR;
		}

		if (CI_SUCCESS == reResultP)
		{
			/*进路关联防护道岔位置正确*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteRelatedProSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResultP = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResultP = RETURN_LOCK_ERR_SWITPOS;
			}
		} 
		else
		{
			/*如果是进路内防护道岔等待相邻联锁反馈道岔检查状态,先不检查道岔是否全在位置，继续等待*/
		}

		if (CI_ERROR == reResultP)
		{/*如果防护道岔的检查结果为错误，则总的检查结果为错误*/
			reResult = CI_ERROR;
		}
		else if (CI_SUCCESS == reResultP)
		{
			/*如果防护道岔的检查结果为成功，则总的检查结果保持不变*/
		}
		else if (RETURN_LOCK_ERR_WAIT_SWCHECK == reResultP)
		{
			/*如果防护道岔的检查结果等待检查，则总的检查结果等待检查*/
			reResult = RETURN_LOCK_ERR_WAIT_SWCHECK;
		}
		else if (RETURN_LOCK_ERR_SWITPOS == reResultP)
		{/*如果防护道岔的检查结果为锁闭位置错误，则总的检查结果为锁闭位置错误*/
			reResult = RETURN_LOCK_ERR_SWITPOS;
		}
		else
		{/*其它不存在的情况，置总的结果为错误*/
			reResult = CI_ERROR;
		}
		
	}
	else if (RETURN_LOCK_ERR_WAIT_SWCHECK == reResult)
	{
		/*进路内道岔等待相邻联锁反馈道岔检查状态,先不检查防护道岔状态，继续等待*/
		;
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}


    /* 返回结果 */
    return reResult;
}

/*
* 功能描述： 锁闭点式进路区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路驱动道岔提前扳动功能
*/
UINT8 LockBlocRouteSectionCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	/* 进路内所有区段【空闲】 */
	checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段【未锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteOutLogSecLockValidCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{

	}

	return reResult;
}

/*
* 功能描述： 锁闭CBTC列车进路区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路驱动道岔提前扳动功能
*/
UINT8 LockCBTCRouteSectionCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段【未锁闭】*/
	checkResult = RouteOutLogSecLockValidCheck(routeId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段【未占压】*/
		checkResult = RouteOutLogSecOccClearCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	return reResult;
}


/*
* 功能描述： 锁闭引导列车进路区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221008 适配进路驱动道岔提前扳动功能
*/
UINT8 LockLeadRouteSectionCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 chFuncDriveSwitchEarly = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);

	/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段【未锁闭】*/
	checkResult = RouteOutLogSecLockValidCheck(routeId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{
		if (FUNC_SWITCH_ON == chFuncDriveSwitchEarly)
		{
			/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段【未占压】*/
			checkResult = RouteOutLogSecOccClearCheck(routeId, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			; /*提前驱动道岔开关关闭，此项不检查*/
		}
	}
	return reResult;
}
/*
* 功能描述： 检查进路是否有道岔驱动超时
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:进路无道岔驱动超时
			 CI_ERROR:进路有道岔驱动超时
*/
UINT8 ChekRoutSwitDrivOvtmStat(const UINT16 routeId)
{
	UINT8 retVal = CI_SUCCESS;
	/* 进路道岔 */
	UINT8 const routeSwitchSum = GetRouteSwitchSum(routeId);
	RouteSwitchStruct* const switchDataBuf = GetRouteSwitchData(routeId);
	/* 进路关联防护道岔 */
	UINT8 const protectSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const protectSwitchDataBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;    
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chSwitchBelCiId = 0U;/*道岔所属联锁ID*/

	chLocalCiId = GetSystemParaLocalCiId();
	if (0U == routeSwitchSum)
	{
		/*无检查项*/
		retVal = CI_SUCCESS;
	}
	else
	{	
		/*开始检查进路内道岔*/
		for (i = 0u; i<routeSwitchSum; i++)
		{
			SwitchId = switchDataBuf[i].SwitchId;
			chSwitchBelCiId = GetSwitchBelongCiId(SwitchId);
			if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
			{
				SwitchPos = switchDataBuf[i].SwitchPosition;
				SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

				if (SWITCH_POSITION_DINGWEI == SwitchPos)
				{
					/*道岔位置正确*/
					if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
						break;
					}

				}
				else if (SWITCH_POSITION_FANWEI == SwitchPos)
				{
					/*道岔位置正确*/
					if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
						break;
					}

				}
				else
				{
					; /*什么也不做*/
				}
			}
			else
			{
				; /*其它控区道岔不检查*/
			}
		}
	}
	
	if (CI_SUCCESS == retVal)
	{
		if (0U == protectSwitchSum)
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查进路关联防护道岔*/
			for (i = 0u; i<protectSwitchSum; i++)
			{
				SwitchId = protectSwitchDataBuf[i].ProtectSwitchId;
				chSwitchBelCiId = GetSwitchBelongCiId(SwitchId);
				if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
				{
					SwitchPos = protectSwitchDataBuf[i].ProtectPosition;
					SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

					if (SWITCH_POSITION_DINGWEI == SwitchPos)
					{
						if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
							break;
						}

					}
					else if (SWITCH_POSITION_FANWEI == SwitchPos)
					{
						if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
							break;
						}

					}
					else
					{
						; /*什么也不做*/
					}
				}
				else
				{
					;
				}
			}
		}
	} 
	else
	{
		retVal = CI_ERROR;
	}
	
	return retVal;
}

/* C28_区段故障解锁 */
/*
* 功能描述： 区段故障解锁
* 参数说明： UINT16 const phySectionId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_UNLOCK_FAULT_SECTION
*/
UINT8 PhySecFaultUnlockLogicProcess(UINT16 const phySectionId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_UNLOCK_FAULT_SECTION;
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;        /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 phySecLockBelongRouteId = 0u; /*锁闭所属进路ID*/
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT16 cancleRelayZhaoChaRelayId = 0u;    /*继电接口取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/
	/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ATS;		/*发送ATS*/
	UINT8 phyBelongCi = 0u;/*物理区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	UINT8 routeBelongCi = 0u;
	UINT8 otherCiId = 0u;/*其它联锁ID*/
	UINT8 execRes = 0u;/*执行结果*/

	/*获取区段相关信息*/
	phySecLockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId);
	phyBelongCi = GetPhySecBelongCiId(phySectionId);/*获取物理区段所属联锁*/
	routeBelongCi = GetRouteBelongCiId(phySecLockBelongRouteId);/*获取进路所属联锁*/

	/*联锁检查*/

	/*区段状态为【异常锁闭】*/
	checkResult = GetPhySecLockState(phySectionId);
	if (checkResult == PHYSICAL_SECTION_LOCK_EXCEPT)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySectionId, ETYPE_PS_LOCK_STATE, checkResult, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*区段【空闲】*/
	if (CI_SUCCESS == reResult)
	{
		/*本联锁与其它联锁通信通信状态*/
		commState = GetLocalCiAndOtherCiTransSta(phyBelongCi);
		/*进路为本联锁，区段为相邻联锁，且继电接口下，不检查区段占用*/
		if ((localCi == routeBelongCi) && (localCi != phyBelongCi) &&
			(TRANSMIT_STATE_BAD == commState) && (CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)
			&& (FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			checkResult = GetPhySecCurMergeState(phySectionId);
			if (checkResult == SECTION_OCCUPY_NO)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySectionId, ETYPE_PS_MERGY_OCU_STATE, checkResult, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	/*取消照查继电器为吸起*/
	if (CI_SUCCESS == reResult)
	{
		cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(phySecLockBelongRouteId); /*取消照查继电器ID*/
		commState = GetLocalCiAndOtherCiTransSta(routeBelongCi);/*本联锁与其它联锁通信通信状态*/
		if ((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
		{
			if ((localCi == phyBelongCi) && (localCi != routeBelongCi) &&
				(TRANSMIT_STATE_BAD == commState) &&
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag) &&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				/*如果物理区段所属联锁为本联锁，进路所属联锁与本联锁不同，且本联锁与进路所属联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查该物理区段故障锁闭状态*/
				reResult = CI_SUCCESS;
			}
			else
			{

				/*取消继电器有效：取消继电器采集状态为：吸起*/
				relayState = GetRelayCollState(cancleZhaoChaRelayId);/*获取取消继电器采集状态*/
				if (RELAY_STATE_UP == relayState)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;

				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, cancleZhaoChaRelayId, ETYPE_CANCLE_ZHAOCHA, relayState, sendLevel);
					/* 失败返回 */
					reResult = CI_ERROR;
				}

			}
		}

	}

	/*继电接口取消照查继电器为吸起*/
	if (CI_SUCCESS == reResult)
	{
		/*继电取消照查*/
		cancleRelayZhaoChaRelayId = GetRouteCancleZCRelayId(phySecLockBelongRouteId);
		execRes = RouteHavePhySecBelongOtherCi(phySecLockBelongRouteId, &otherCiId);

		if ((0u != cancleRelayZhaoChaRelayId) && (0xFFFFu != cancleRelayZhaoChaRelayId))
		{
			if (routeBelongCi == localCi)
			{/*进路属于本联锁*/
				if ((CI_SUCCESS == execRes) && (otherCiId > 0u) && (otherCiId != routeBelongCi))
				{
					commState = GetLocalCiAndOtherCiTransSta(otherCiId);/*本联锁与其它联锁通信通信状态*/
					if ((TRANSMIT_STATE_BAD == commState) &&
						(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
					{/*进路属于本联锁的才需要检查*/
						if (CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)
						{
							/*如果本联锁与其它联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则需要检查继电接口下取消照查继电器状态*/
							reResult = CI_SUCCESS;

							/*取消继电器有效：取消继电器采集状态为：吸起*/
							relayState = GetRelayCollState(cancleRelayZhaoChaRelayId);/*获取取消继电器采集状态*/
							if (RELAY_STATE_UP == relayState)
							{
								/* 通过检查 */
								reResult = CI_SUCCESS;

							}
							else
							{
								/* 记录故障码 */
								SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, cancleRelayZhaoChaRelayId, ETYPE_CANCLE_ZHAOCHA, relayState, sendLevel);
								/* 失败返回 */
								reResult = CI_ERROR;
							}
						}
						else
						{/*没有确认，不准区故解，检查失败*/
							reResult = CI_ERROR;
							debug_infor_printf((const)"PhySectionFaultUnlockLogicProcess error,not Confirm.\n");
						}

					}

				}
			}
			else
			{/*进路不属于本联锁，不需要检查*/

			}

		}


	}
	return reResult;
}

/*
* 功能描述： 检查进路总人解的可行性。只要进路有一个区段可以直接解锁或变绿光带都认为总人解可行。注：调车进路总人解不可调用该函数
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
CI_SUCCESS:总人解可执行
CI_ERROR:总人解不可执行
*/
UINT8 CheckRouteZongRenJieFeasibility(const UINT16 routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_CHECK_ROUTE_ZRJ;
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;        /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/
	UINT8 trainEnterFlag = 0u;           /*进路的列车驶入标志*/
	UINT16 inPhySecId = 0u; /*信号机内方第一区段ID*/
	UINT16 wInLogSecId = 0u;  /* 进路内方最后一个逻辑区段 */
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
	UINT8 sectionSum = 0u;/*进路包含的物理区段数量*/									/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ATS;		/*发送ATS*/
	UINT16 secIdx = 0u;/*进路内包含的物理区段遍历索引变量*/

	/*联锁条件检查*/
	/* 进路内所有区段锁闭状态【正常锁闭】*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteAllSecLockStateCheck(routeId, PHYSICAL_SECTION_LOCK_NORMAL, &devId, &devState);
	if (CI_SUCCESS==checkResult)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	
	if (CI_SUCCESS == reResult)
	{
		trainEnterFlag = GetRouteTrainEnterFlag(routeId);/*获取进路的列车驶入标志*/

		sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
		pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/

		if (ROUTE_TRAIN_ENTER_FLAG_NO==trainEnterFlag)
		{/*列车没有驶入*/
			/*进路内存在空闲的物理区段 功能优化，修改时间：2017年03月01日。修改原因：避免进路内所有物理区段占压时，看不到绿光带。*/
			if ((NULL==pRouteSecStru ) || (0u == sectionSum))
			{
				reResult = CI_ERROR;
			}
			else
			{
				for (secIdx = 0u;secIdx < sectionSum;secIdx++)
				{/*遍历进路内物理区段，检查是否存在空闲物理区段*/
					inPhySecId = pRouteSecStru[secIdx].PhysicalSectionId;
					devState = GetPhySecCurMergeState(inPhySecId);

					if (SECTION_OCCUPY_NO == devState)
					{
						break;
					}
					else
					{
					}
				}

				if (secIdx < sectionSum)
				{/*进路内存在空闲的物理区段*/
					reResult = CI_SUCCESS;
				}
				else
				{/*进路内物理区段全部占用*/
					reResult = CI_ERROR;
				}
			}
		}
		else
		{
			if ((NULL==pRouteSecStru ) || (0u == sectionSum))
			{
				reResult = CI_ERROR;
			}
			else
			{
#if 0
				inPhySecId = pRouteSecStru[0].PhysicalSectionId;/*进路内方第一区段*/
				devState = GetPhySecCurMergeState(inPhySecId);

				if (SECTION_OCCUPY_NO == devState)
				{/*空闲*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
					reResult = CI_ERROR;
				}
#endif
				/* 进路内方第一逻辑区段空闲 */
				wInLogSecId = GetRouteInFirstLogSecId(routeId);
				devState = GetLogSecCurCtOrUtOccupyState(wInLogSecId);

				if (SECTION_OCCUPY_NO == devState)
				{
					/* 空闲 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, wInLogSecId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
					reResult = CI_ERROR;
				}
			}
		}
		
	}
	else
	{
	}

	if (CI_SUCCESS == reResult)
	{
		cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/
		
		if ((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
		{
			/*取消继电器有效：取消继电器采集状态为：吸起*/
			relayState = GetRelayCollState(cancleZhaoChaRelayId);/*获取取消继电器采集状态*/
			devId = cancleZhaoChaRelayId;
			devState = relayState;
			if (RELAY_STATE_UP == relayState)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;

			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, devId, ETYPE_CANCLE_ZHAOCHA, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}

		}
		else
		{
		}
	}
	else
	{
	}

	return reResult;
}


/*
锁闭本联锁保护区段条件检查
UINT16 const overlapId 保护区段ID
UINT8 PLockDirect 锁闭方向

CI_SUCCESS 成功
CI_ERROR 失败

*/
UINT8 LockLocalOvlpCheckHlht(const UINT16 overlapId, UINT8 PLockDirect)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOCK_HLHT_LOC_OVLP;

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;		/*不发送ATS*/

	/*保护区段 内所有区段【未封锁】*/
	devId = 0u;
	devState = 0u;
	checkResult = OverlapAllSecFLockValidCheck(overlapId, &devId, &devState);
	if (CI_SUCCESS == checkResult)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}



	/*保护区段 内所有区段【空闲】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecOccuClearCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}

	/* 保护区段内所有折返进路空闲*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllReturnRouteCheckup(overlapId, &devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_USE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}

	/* 保护区段内侵限区段及条件道岔检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapInvSecAndConSwiCheckup(overlapId, &devId, &devState);

		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}

	/* 保护区段侧防条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapLateralDfnCheck(overlapId, &devId, &devState);

		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段的敌对侵限保护区段检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapInvOppOverlapCheckup(overlapId, &devId, &devState);

		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_OVERLAP, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/*保护区段 内所有道岔【未引导总锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchYLockCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/*保护区段 内所有道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchFLockStateCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/*保护区段 关联防护道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OvlpRelProtSwiFLockStaCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/* 保护区段内所有区【未锁闭】
	或者 方向相同【正常锁闭】
	或者 方向相同【防护锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecLockDirectCheck(overlapId, PLockDirect, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/*进路内所有道岔位置正确或位置不正确但可动作*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchMoveValidCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}
	/*保护区段道岔位置检查
	   RETURN_LOCK_ERR_SWITPOS： 保护区段道岔位置不正确
	   CI_SUCCESS： 保护区段内所有道岔位置正确
	*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchPosCheck(overlapId, &devId, &devState);
		if (CI_ERROR == checkResult)
		{
			/* 道岔位置不正确 */
			reResult = RETURN_LOCK_ERR_SWITPOS;
		}
		else
		{
			/* 道岔位置正确 通过检查 */
			reResult = CI_SUCCESS;
		}
	}
	else
	{
	}
	/* 保护区段内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecJumpLockStateCheck(overlapId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_JUMP_LOCK, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
	}


	return reResult;
}

/* C11_锁闭进路overlap逻辑处理 */
/*
* 功能描述： 锁闭进路overlap逻辑处理,进路属于自家CI，但是保护区段属于互联互通的邻线
* 参数说明： const UINT16 routeId, const UINT16 overlapId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_OVER_LAP
*/
UINT8 LockOthCiOvlpCheckHlht(const UINT16 routeId, const UINT16 overlapId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOCK_HLHT_REM_OVLP;/*需要重新定义函数编码*/

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

										/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;		/*不发送ATS*/
	UINT8 cAlarmType = FLAG_UNSET;

	/* 联锁条件检查 */

	/*进路最后一个区段【空闲】*/
	devId = GetRouteLastPhySectionId(routeId);
	devState = GetPhySecCurMergeState(devId);
	if (devState == SECTION_OCCUPY_NO)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路最后一个区段【正常锁闭】且属于当前进路*/
		devId = GetRouteLastPhySectionId(routeId);
		devState = GetPhySecLockState(devId);
		if ((GetPhySecLockState(devId) == PHYSICAL_SECTION_LOCK_NORMAL) &&
			(GetPhySecRLockBelongRouteId(devId) == routeId))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*保护区段 内所有区段【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecFLockValidCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


	/*保护区段 内所有区段【空闲】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecOccuClearCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段 内所有区段【未征用】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecUsingClearCheck(overlapId, &devId, &devState, &cAlarmType);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if (RETURN_WAIT_SWITCH_USING == checkResult)
		{
			reResult = RETURN_WAIT_SWITCH_USING;  /*互联互通线路暂不支持防护道岔跨控区场景*/
		}
		else
		{
			/* 记录故障码 */
			if (FLAG_SET == cAlarmType)
			{
				/*按道岔报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_USE_STATE, devState, sendLevel);
			}
			else
			{
				/*按物理区段报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_USE_STATE, devState, sendLevel);
			}
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段内所有区【未锁闭】
	或者 方向相同【正常锁闭】
	或者 方向相同【防护锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecLockValidCheck(overlapId, routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段内所有逻辑区段【未逻辑锁闭】或者方向相同【逻辑正常锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapLogSecLogicLockCheck(overlapId, routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段内侵限区段及条件道岔检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapInvSecAndConSwiCheckup(overlapId, &devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段侧防条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapLateralDfnCheck(overlapId, &devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段的敌对侵限保护区段检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapInvOppOverlapCheckup(overlapId, &devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_OVERLAP, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段 内所有道岔【未引导总锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchYLockCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段 内所有道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapSwitchFLockStateCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段 内所有道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OvlpRelProtSwiFLockStaCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 保护区段内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecJumpLockStateCheck(overlapId,&devId,&devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_JUMP_LOCK,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	
	return reResult;
}

/*
解锁本联锁保护区段条件检查
UINT16 overlapId 保护区段ID

CI_SUCCESS 成功
CI_ERROR 失败

*/
UINT8 UnlockLocalOvlpCheckHlht(UINT16 overlapId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_UNLOCK_OVER_LAP;  

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	/*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO; 	/*不发送ATS*/

	/*防护进路检查*/
	/*上层函数已检查overlapId不为0，故此处的else分支走不到，此处错误反馈不必修改*/

	/*进路有防护锁闭区段*/
	if (overlapId > 0u )
	{
		/*有防护进路*/
		reResult = CI_SUCCESS;      
	}
	else
	{
		/*无防护进路不检查*/
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE, overlapId, ETYPE_ROUTE_OVERLAP_UNLOCK, CI_ERROR, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;        
	}

	if (CI_SUCCESS == reResult)
	{
		/*保护区段 内所有区段【空闲】*/
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecOccuClearCheck(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;			
		}
	}

	return reResult;
}

/*
功能描述:	进路终端信号机保护区段有效性检查
输入参数:	UINT16 const routeId	进路ID
输出参数:	UINT16 *pDevId		设备Id
UINT8 *pDevState		设备状态
返回值: 		CI_SUCCESS			不满足侵限条件
CI_ERROR			满足侵限条件
*/
UINT8 SignalOverlapValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT8 reResult = CI_ERROR;

	/*检查进路侵限条件状态*/
	UINT16 tempDevId = 0u;/*进路终端信号机*/
	UINT8 tempDevState = SIGNAL_PRO_SEC_INVALID;/*信号机保护区段有效性*/
	
	if (routeId>0u)
	{
		/*检查保护区段有效性*/
		tempDevId = GetRouteEndSignalId(routeId);

		if (tempDevId > 0u)
		{
			tempDevState = GetSignalProSecValid(tempDevId);

			if (SIGNAL_PRO_SEC_VALID == tempDevState)
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				reResult = CI_ERROR;
			}
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	else
	{
		reResult = CI_ERROR;
	}

	*pDevId = tempDevId;
	*pDevState = tempDevState;

	return reResult;
}

/*
* 功能描述： 检查进路终端信号机为非CBTC级别
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 CheckRouteEndSignalNotCbtc(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 bCiSwitchShowGreenYellow = FUNC_SWITCH_OFF;/*绿黄开关*/
	UINT16 routeEndSignalId = 0u;	/*进路终端信号机ID*/
	UINT8 endSignalLightExtinctState = 0u;/*信号机亮灭信息*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT32 curCycle = 0u;		/*当前周期号*/
	UINT32 keepSignalTolerateCyc = 0u;		/*信号保持开放状态容忍周期*/

	UINT8 sigBelongCi = 0u;/*信号机所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 localCi = GetSystemParaLocalCiId();/*本机联锁*/
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	UINT8 sigalMaintainState = 0U;/*信号机维修点灯状态*/
	UINT8 belongVirCI = 0u;
	UINT8 allSignalBrightFlag = 0u; /*全站亮灯*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	bCiSwitchShowGreenYellow = GetCiFunctionSwitchConfig(CI_FUNCTION_SWITCH_SHOW_SIGNAL_GreenYellow);
	if (FUNC_SWITCH_ON == bCiSwitchShowGreenYellow)/*如果显示绿黄灯开关【打开】*/
	{
		routeEndSignalId = GetRouteEndSignalId(routeId);

		sigBelongCi = GetSignalBelongCiId(routeEndSignalId);/*获取信号机所属联锁*/
		commState = GetLocalCiAndOtherCiTransSta(sigBelongCi);/*本联锁与其它联锁通信通信状态*/

		if ((localCi !=sigBelongCi) && (TRANSMIT_STATE_BAD == commState) && 
			(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
			(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
		{
			/*如果信号机所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
				且已配置支持继电接口，则可以不检查该信号机封锁状态*/
			reResult = CI_SUCCESS;
		}
		else
		{
			endSignalLightExtinctState = GetSignalLightExtinctState(routeEndSignalId);/*获取终端信号机强制点灯状态*/
			  /*如果是灭灯 且非维修点灯*/
			sigalMaintainState = GetSignalMaintainState(routeEndSignalId);/*信号机维修点灯状态*/

			if (FUNC_SWITCH_ON == includeVirFlag)
			{
				belongVirCI = GetSignalBelongVirCiId(routeEndSignalId);
				allSignalBrightFlag = GetVirCIAllSignalBrightState(belongVirCI);/*本虚拟联锁全站亮灯标志*/
			}
			else
			{
				allSignalBrightFlag = GetAllSignalBrightFlag();  /*全站亮灯标志*/
			}
			if ((SIGNAL_LIGHT_EXTICT_STATE_NO == endSignalLightExtinctState )&&(MAINTAIN_STATE_NO == sigalMaintainState))
			{
				routeState = GetRouteState(routeId);
				if((ROUTE_STATE_YUXIAN_OPEN == routeState)||(ROUTE_STATE_NEAR_OPEN == routeState))
				{
					curCycle = Get2oo2CurCycleNum();/*当前周期号*/
					reResult = (UINT8)GetRouteKeepSigTolerateCyc(routeId,&keepSignalTolerateCyc);/*获取信号保持开放状态容忍周期*/
					if(CI_SUCCESS == reResult)
					{
						if(0u == keepSignalTolerateCyc)
						{
						   reResult = SetRouteKeepSigTolerateCyc(routeId,curCycle);/*设置开放信号容忍周期*/
						   if(CI_SUCCESS == reResult)
						   {
							  /* 什么也不做*/
						   }
						   else
						   {
							   /* 记录故障码 */
							   SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_LIGHT_EXTINCT,SIGNAL_LIGHT_EXTICT_STATE_NO,sendLevel);
							   reResult = CI_ERROR;
						   }
						}
						else
						{
							if(ROUTE_SIGNAL_TOLERATE_OPEN_COUNT >= (curCycle - keepSignalTolerateCyc))
							{
								reResult = CI_SUCCESS;
							}
							else
							{
								/* 记录故障码 */
								SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_LIGHT_EXTINCT,SIGNAL_LIGHT_EXTICT_STATE_NO,sendLevel);
								reResult = CI_ERROR;
							}
						}
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_LIGHT_EXTINCT,SIGNAL_LIGHT_EXTICT_STATE_NO,sendLevel);
						reResult = CI_ERROR;  
					}
       
				}
				else
				{
					/* 记录故障码 */
		     		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_LIGHT_EXTINCT,SIGNAL_LIGHT_EXTICT_STATE_NO,sendLevel);
		    		reResult = CI_ERROR;
				}
			
			}
			else if ((SIGNAL_LIGHT_EXTICT_STATE_YES == endSignalLightExtinctState )||(MAINTAIN_STATE_YES == sigalMaintainState))/*如果是亮灯*/
			{
				reResult = SetRouteKeepSigTolerateCyc(routeId,0);/*设置信号容忍开放开始周期为0*/
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_LIGHT_EXTINCT,SIGNAL_LIGHT_EXTICT_STATE_NO,sendLevel);
				reResult = CI_ERROR;
			}
		}
	}
	else
	{
		reResult = CI_SUCCESS;
	}
	return reResult;
}

/*
* 功能描述： 检查进路终端信号机断丝
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 CheckRouteEndSignalDS(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 bCiSwitchCheckEndSignalDs = FUNC_SWITCH_OFF;/*检查开关*/
	UINT16 routeEndSignalId = 0u;	/*进路终端信号机ID*/
	UINT8 endSignalCurColor = 0u;/*终端信号机当前颜色*/
	UINT8 routeLevel = 0u;	/*进路级别*/
	UINT8 routeType = 0u;	/*列车类型*/
	UINT8 routeState = 0u;	/*进路状态*/

	bCiSwitchCheckEndSignalDs = GetCiFunctionSwitchConfig(FUNC_SWITCH_CHECK_END_SIGNAL_DS);
	routeLevel = GetRouteLevel(routeId);/*进路级别*/
	routeType = GetRouteType(routeId);/*进路类型*/
	routeState = GetRouteState(routeId);/*获取进路状态*/

	if (FUNC_SWITCH_ON == bCiSwitchCheckEndSignalDs)
	{/*开关打开进行检查*/
		routeEndSignalId = GetRouteEndSignalId(routeId);

		endSignalCurColor = GetSignalCurColor(routeEndSignalId);/*获取终端信号机当前颜色状态*/

		if ((ROUTE_LEVEL_BLOC == routeLevel) && (ROUTE_TYPE_DIAOCHE != routeType)
			&& (ROUTE_STATE_LEAD_LOCK != routeState) && (ROUTE_STATE_LEAD_OPEN != routeState)
			&& (ROUTE_STATE_LEAD_LOCKERR != routeState))
		{/*只做后备、非调车（包括列车、折返、0）、非引导锁闭、非引导开放、且非引导锁闭异常类型下的检查*/
			if (SIGNAL_SHOWCOLOUR_REDBREAK == endSignalCurColor )/*如果是红断*/
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeEndSignalId,ETYPE_SIG_ENDSIGNAL_DS,SIGNAL_SHOWCOLOUR_REDBREAK,sendLevel);
				reResult = CI_ERROR;
			}
			else
			{
				reResult = CI_SUCCESS;
			}
		}
		else
		{/*开关打开，非后备模式或者调车进路，返回成功*/
			reResult = CI_SUCCESS;
		}
		
	}
	else
	{/*开关关闭，返回成功*/
		reResult = CI_SUCCESS;
	}
	return reResult;
}

/*
* 功能描述： 点式进路开放信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenBlocRouteSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/


	/* 进路内设备数据 */
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);

	/* 联锁逻辑检查 */  

	devState = GetSignalCurColor(startSignalId); /*获取信号机当前颜色*/
	if (SIGNAL_SHOWCOLOUR_REDBREAK != devState)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,startSignalId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{

		/*进路内所有信号机【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路的敌对条件不成立*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalEnemyVainCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		reResult = CheckRouteEndSignalNotCbtc(routeId,functionId,sendLevel);
	}

	if (CI_SUCCESS == reResult)
	{/*检查终端信号机断丝*/
		reResult = CheckRouteEndSignalDS(routeId,functionId,sendLevel);
	}

	/* 返回结果 */
	return reResult;
}

/*
* 功能描述： 开放进路道岔联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenLTrainRouteSwitchCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/



	/* 联锁逻辑检查 */  

	/*进路内所有道岔【未封锁】*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteSwitchFLockCheck(routeId,&devId, &devState);
	if (CI_SUCCESS == checkResult)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路防护道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteReltProtSwitchFLockCheck(routeId,&devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}
	

	if(CI_SUCCESS == reResult)
	{
		/*进路所有道岔位置正确*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSwitchPosCheck(routeId,&devId, &devState);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{/*进路开放防护道岔检查*/
		/*进路关联防护道岔位置正确*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteRelatedProSwitchPosCheck(routeId,&devId, &devState);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
		}

		if (CI_SUCCESS == reResult)
		{
			/*进路关联防护道岔【防护锁闭】或【单锁且防护锁闭】*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteRelatedProSwitchLockCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_LOCK_STATUS,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		} 
		else
		{
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	
	/* 返回结果 */
	return reResult;
}

/* 点式折返进路信号保持信号联锁条件检查 */
/*
* 功能描述： 点式折返进路信号保持信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 KeepBlocReturnSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT16 endSigId = 0u;				/*获取中途折返信号机ID*/
	UINT8 endSigState = SIGNAL_OPEN;              /*终端信号机开放状态 */


	/* 进路内设备数据 */            
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);
	UINT8 flag = 0u;
	UINT8 FSignalFlag = 0u;

	/* 联锁逻辑检查 */  

	/* 进路始端信号机上周期驱动颜色为【开放】*/
	devState = GetSignalOpenCloseState(GetSignalPreDriveColor(startSignalId));
	if (devState == SIGNAL_OPEN)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,startSignalId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
		flag = 1u;
	}
	if (1u == flag)
	{
	} 
	else
	{
		FSignalFlag = GetCiFunctionSwitchConfig(CLOSE_OPENED_SIG_LOCK_SIGNAL);
		if (FUNC_SWITCH_OFF == FSignalFlag)   /*开关未打开则不检查信号机封锁状态*/
		{
			reResult = CI_SUCCESS;
		} 
		else if(FUNC_SWITCH_ON == FSignalFlag)
		{	    
			devId = 0u;
			devState = 0u;
			checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
				flag = 1u;
			}
		}
		else
		{
			/*不做处理*/
		}
		/*进路内所有信号机【未封锁】*/

		if (1u == flag)
		{
		} 
		else
		{
			/* 进路终端信号机未开放*/
			endSigId = GetRouteEndSignalId(routeId); /*获取中途折返信号机ID*/
			endSigState = GetSignalOpenCloseState(GetSignalCurColor(endSigId));
			if (endSigState == SIGNAL_CLOSE)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,endSigId,ETYPE_SIG_RETURN_DS_STATE,endSigState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
				flag = 1u;
			}
			if (1u == flag)
			{
			} 
			else
			{
				/*进路的敌对条件不成立*/
				devId = 0u;
				devState = 0u;
				checkResult = RouteSignalEnemyVainCheck(routeId, &devId, &devState);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}
		}
	}  

	if (CI_SUCCESS == reResult)
	{/*检查终端信号机断丝*/
		reResult = CheckRouteEndSignalDS(routeId,functionId,sendLevel);
	}

	/* 返回结果 */
	return reResult;
}

/* L01_点式办理进路信号机联锁条件检查 */
/*
* 功能描述： 点式进路信号机联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetBlocRouteSignalCheck( UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 signalCurColor = 0u;

	/* 进路内设备数据 */
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);

	/* 联锁逻辑检查 */  

	/* 进路始端信号机未开放*/
	signalCurColor = GetSignalCurColor(startSignalId);
	devState = GetSignalOpenCloseState(signalCurColor);
	if (devState == SIGNAL_CLOSE)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,startSignalId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路内所有信号机【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路的敌对条件不成立*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalEnemyVainCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	/* 返回结果 */
	return reResult;
}

/* L11_点式进路开放信号站台联锁条件检查 */
/*
* 功能描述： 点式进路开放信号站台联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenRoutePlatformCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/


	UINT8 devState = 0u;                 /*设备状态*/ 

	UINT16 routeStartSignalId = GetRouteStartSignalId(routeId);

	/* 联锁逻辑检查 */  
#if 0 /* 站台PSD，ESB等，在其他联锁条件中检查 */
	/*接发车进路*/
	/*站台紧急关闭按钮未被按下*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteEsbVainCheck(routeId, &devId,&devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_PLATFORM,devId,ETYPE_ESB_VALID,devState,sendLevel); 
		/* 失败返回 */
		reResult = CI_ERROR;
		return reResult;
	}

	/*站台安全屏蔽门关闭或互锁解除*/
	devId = 0u;
	devState = 0u;
	checkResult = RoutePsdCloseCheck(routeId,&devId,&devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_PLATFORM,devId,ETYPE_PSD_CLOSE_NO,devState,sendLevel); 
		/* 失败返回 */
		reResult = CI_ERROR;
		return reResult;
	}

#endif
	/*站台未实施扣车作业*/
	devState = GetSignalDetainFlag(routeStartSignalId);
	if (SIGNAL_DETAIN_NO==devState  )
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,routeStartSignalId,ETYPE_PLAT_DETAIN,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}


	/* 返回结果 */
	return reResult;
}

/*
* 功能描述： 引导进路全站引导总锁检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LeadzLockCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 includeVirFlag = 0U;
	UINT8 belongVirCI = 0u;
	UINT8 yLockState = 0u;			/*引导总锁状态*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT16 routeStartSignalId = GetRouteStartSignalId(routeId);		/*获取进路始端信号机*/
	/*虚拟联锁ID*/
	includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	/*获取进路引导属性*/
	devState = GetRouteLeadProperty(routeId);

	/*获取全站引导总锁的标志*/
	if (FUNC_SWITCH_ON == includeVirFlag)
	{
		belongVirCI = GetRouteBelongVirCiId(routeId); /*获取进路所属虚拟联锁ID*/
		yLockState = GetVirCIAllSwitchYLockState(belongVirCI);
	}
	else
	{
		yLockState = GetAllSwitchYLockFlag();
	}

	if (ROUTE_LEAD_PROPERTY_YES == devState)		
	{
		reResult = CI_SUCCESS;		/*非CBTC场段区域的进路无需检查引导总锁，非成都区域的地方配置*/
	}
	else						/*引导进路的引导属性只只有0xaa和0xbb两种*/
	{
		/*CBTC场段区域和正线的进路需要检查引导总锁，成都四线配置*/
		if (CI_ALL_SWITCH_YLOCK_NO != yLockState)
		{
			/*具有引导总锁，向ATS报警，YF0083-1318*/
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, routeStartSignalId, ETYPE_SIG_LEAD_ALL_LOCK, CI_ERROR, sendLevel);
			reResult = CI_ERROR;
		}
		else
		{
			reResult = CI_SUCCESS;
		}
	}
	return reResult;
}

/*
* 功能描述： 开放列车进路信号机联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenLTrainRouteSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/


	/* 进路内设备数据 */
	/* 始端信号机Id */
	UINT16 const startSignalId = GetRouteStartSignalId(routeId);

	/* 联锁逻辑检查 */  

	/* 进路始端信号机颜色为【红灯】*/
	devState = GetSignalCurColor(startSignalId);
	if ((SIGNAL_SHOWCOLOUR_RED == devState)||(SIGNAL_DRIVECOLOUR_REDCLOSE == devState))
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,startSignalId,ETYPE_SIG_START_OPEN_STATE,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}
	if(CI_SUCCESS == reResult)
	{
		/*进路内所有信号机【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if(CI_SUCCESS == reResult)
	{
		/*进路的敌对条件不成立*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalEnemyVainCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{/*检查终端信号机断丝*/
		reResult = CheckRouteEndSignalDS(routeId,functionId,sendLevel);
	}

	/* 返回结果 */
	return reResult;
}

/* L09_点式进路开放信号道岔联锁条件检查 */
/*
* 功能描述： 点式进路开放信号道岔联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenBlocRouteSwitchCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	UINT8 lineIdentity = CI_TRADITION_RAILWAY;

	lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取线路标识*/

	/* 进路内设备数据 */


	/* 联锁逻辑检查 */  

	/*进路内所有道岔【未封锁】*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteSwitchFLockCheck(routeId,&devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路防护道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteReltProtSwitchFLockCheck(routeId,&devId, &devState);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*进路所有道岔位置正确*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}

	if(CI_SUCCESS == reResult)
	{
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{/*进路开放防护道岔检查*/
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*进路关联防护道岔位置正确*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteRelatedProSwitchPosCheck(routeId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}

			if (CI_SUCCESS == reResult)
			{
				/*进路关联防护道岔【防护锁闭】或【单锁且防护锁闭】*/
				devId = 0u;
				devState = 0u;
				checkResult = RouteRelatedProSwitchLockCheck(routeId,&devId, &devState);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_LOCK_STATUS,devState,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			} 
			else
			{
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 失败返回 *//* zt 删除单轨相关代码 2022-02-15 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = RouteAllLtrlDfncSwitchCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	
	/* 返回结果 */
	return reResult;
}


/* L10_点式进路开放信号保护区段联锁条件检查 */
/*
* 功能描述： 点式进路开放信号保护区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR    失败
*            CI_SUCCESS 成功
*	         RELAY_STATE_WAITE 等待本端照查继电器落下
*/
UINT8 OpenBlocRouteOverlapCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8	devStateType = 0u;		/*设备状态类型*/
	UINT8 devState = 0u;                 /*设备状态*/

	/* 进路内设备数据 */    
	/*防护进路*/
	UINT8 const overlapSum = GetRouteOverlapSum(routeId);
	UINT16 const overlapId = GetRouteOverlapLockedId(routeId);

	UINT8 lineIdentity = CI_TRADITION_RAILWAY;
    
	lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取线路标识*/

	/* 联锁逻辑检查 */  

	/*防护进路检查*/
	if (overlapSum>0u)
	{
		/*有防护进路*/
		/*进路【保护区段锁闭Id】>0 且 保护区段【防护锁闭所属进路ID】等于当前进路*/
		devId = GetOverlapFirstPhySecId(overlapId);
		devState = GetPhySecLockState(devId);
		if ((overlapId > 0u) && (routeId == GetPhySecPLockBelongRouteId(devId)))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_OVERLAP_UNLOCK,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}

		/*所有防护区段【未封锁】*/
		if(CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapAllSecFLockValidCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* cgh-合并CID-2539-1：cgh-合并CID-2539-1： */
				AccToPhySecFlockTypeSetErrcode(devId, functionId, sendLevel, devState);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*所有防护区段【空闲】*/
		if(CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OpenBlockOvlpAllSecOccuClrCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_ROUTE_OVERLAP_OCCUPY,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}


		if(CI_TRADITION_RAILWAY == lineIdentity)
		{
			/*保护区段道岔【位置正确】*/
			if(CI_SUCCESS == reResult)
			{
				devId = 0u;
				devState = 0u;
				checkResult = OverlapSwitchPosCheck(overlapId,&devId,&devState);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}	
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}

		}
		else
		{
			/* zt 删除单轨相关代码 2022-02-15 */
			/*其他线路情况不处理*/
		}

#if 0     /*进路办理完成并开灯，此时办理引导总锁，进路应保持原来状态不变*/

		/*保护区段 内所有道岔【未引导总锁】*/
		if(CI_SUCCESS == checkResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapSwitchYLockCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
#endif

		/*保护区段 内所有道岔【未封锁】*/
		if(CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapSwitchFLockStateCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*保护区段 关联防护道岔【未封锁】*/
		if(CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OvlpRelProtSwiFLockStaCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*保护区段关联防护道岔【位置正确】*/
		if(CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OvlpRelatedProtSwitchPosCheck(overlapId,&devId,&devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}	
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*保护区段关联防护道岔【防护锁闭】或【单锁且防护锁闭】*/
		if (CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OvlpRelatedProtSwitchLockCheck(overlapId,&devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_LOCK_STATUS,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		if (CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = SignalOverlapValidCheck(routeId, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_PRO_SEC_VALID, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		if (CI_SUCCESS == reResult)
		{
			/*检查保护区段侵限条件状态*/
			devId = 0u;
			devState = 0u;
			checkResult = OverlapInvSecAndConSwiCheckup(overlapId, &devId, &devState);

			if(CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;		
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
				reResult = CI_ERROR;
			}
		}

		/*进路保护区段侧防条件检查*/
		if (CI_SUCCESS == reResult)
		{			
			devId = 0u;
			devState = 0u;
			checkResult = OverlapLateralDfnCheck(overlapId, &devId, &devState);

			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
				reResult = CI_ERROR;
			}
		}

		/* 保护区段内所有区段【未设置跳跃锁闭】*/
		if (CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapAllSecJumpLockStateCheck(overlapId,&devId,&devState);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_JUMP_LOCK,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		

		/*保护区段内所有防淹门状态检查*/
		if (CI_SUCCESS == reResult)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapFloodGateStateCheck(overlapId,&devId,&devStateType,&devState);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,devId,devStateType,devState,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*检查照查继电器状态*/
		if (CI_SUCCESS == reResult)
		{
			checkResult = OverlapZhaoChaRelayCheck(overlapId, ESEND_LEVEL_ATS);

			if (CI_SUCCESS == checkResult)
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/*等待本端照查继电器落下或对端检查不过，返回检查结果*/
				reResult = checkResult;
			}
		}
	}
	else
	{
		/*无防护进路不检查*/
		reResult = CI_SUCCESS;
	}

	/* 返回结果 */
	return reResult;
}


/* zt 删除单轨相关代码 2022-02-15 */

/*检查道岔上一次的有效驱动是否在持续
* 参数说明：
*            const UINT16 switchId,  道岔ID
*            const UINT8 swtCurPos,  道岔位置
*返回值： CI_ERROR 仍在持续，道岔不可动
*          CI_SUCCESS 没有持续，道岔可动作
*/
UINT8 checkSwtLastValDrvPosStayorNot(const UINT16 switchId,const UINT8 swtCurPos)
{
	UINT8 retVal = CI_ERROR;/*返回值*/
	UINT8 lastValidDrvSta = 0u;/*道岔最近一次的有效驱动状态*/
	UINT32 lastValidDrvCycNum = 0u;/*道岔最近一次的有效驱动状态起始周期*/

	lastValidDrvSta = GetSwitchLastValidDrvPos(switchId);
	lastValidDrvCycNum = GetSwitchLastValDrvPosStartCyc(switchId);

	if (SWITCH_POSITION_DINGWEI == swtCurPos)
	{/*道岔定位*/
		if (SWITCH_DRIVE_POS_FANWEI == lastValidDrvSta)
		{/*最近一次有效驱动为反位*/
			if ((Get2oo2CurCycleNum() - lastValidDrvCycNum) <= SWITCH_LAST_DRV_STAY_MAX_NUM )
			{/*驱动持续*/
				retVal = CI_ERROR;
			}
			else
			{
				retVal = CI_SUCCESS;
			}
		}
		else if((SWITCH_DRIVE_POS_DINGWEI == lastValidDrvSta)
			||(SWITCH_DRIVE_POS_INVALID ==lastValidDrvSta))
		{
			/*驱动为定位或者没有驱动*/
			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else if (SWITCH_POSITION_FANWEI == swtCurPos)
	{/*道岔反位*/
		if (SWITCH_DRIVE_POS_DINGWEI == lastValidDrvSta)
		{/*最近一次有效驱动为定位*/
			if ((Get2oo2CurCycleNum() - lastValidDrvCycNum) <= SWITCH_LAST_DRV_STAY_MAX_NUM )
			{/*驱动持续*/
				retVal = CI_ERROR;
			}
			else
			{
				retVal = CI_SUCCESS;
			}
		}
		else if ((SWITCH_DRIVE_POS_FANWEI == lastValidDrvSta)
			|| (SWITCH_DRIVE_POS_INVALID == lastValidDrvSta))
		{
			/*驱动为反位或者没有驱动*/
			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;/*返回值*/
}


/*
* 功能描述： 锁闭保护区段检查道岔驱动超时
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:无道岔驱动超时
			 CI_ERROR:有道岔驱动超时
*/
UINT8 ChekSwitDrivOvtm(const UINT16 overlapId)
{
	UINT8 retVal = CI_SUCCESS;

	/* overlap道岔 */
	UINT8 const routeSwitchSum = GetOverlapSwitchSum(overlapId);
	OverlapConditionSwitchStruct* const switchDataBuf = GetOverlapCondSwitchStruct(overlapId);
	UINT8 const protectSwitchSum = GetOverlapRelatedProtSwitSum(overlapId);
	OverlapProtectSwitchStruct* const protectSwitchDataBuf = GetOverlapRelatedProtSwitStru(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;    
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;
	UINT8 cLocalCiId = 0U;
	UINT8 cSwitchBelongCiId = 0U;

	cLocalCiId = GetSystemParaLocalCiId();

	if ((0u == routeSwitchSum) || (NULL == switchDataBuf))
	{
		/*无检查项*/
		retVal = CI_SUCCESS;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i<routeSwitchSum; i++)
		{
			SwitchId = switchDataBuf[i].SwitchId;
			cSwitchBelongCiId = GetSwitchBelongCiId(SwitchId);
			if ((0U != cSwitchBelongCiId) && (cLocalCiId == cSwitchBelongCiId))
			{
				SwitchPos = switchDataBuf[i].SwitchPosition;
				SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

				if (SWITCH_POSITION_DINGWEI == SwitchPos)
				{
					/*道岔位置正确*/
					if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
						break;
					}

				}
				else if (SWITCH_POSITION_FANWEI == SwitchPos)
				{
					/*道岔位置正确*/
					if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
						break;
					}

				}
				else
				{
					/*什么也不做*/
				}
			}
			else
			{
				/*非本控区道岔，不处理*/
			}
		}
	}
	
	if (CI_SUCCESS == retVal)
	{
		if ((0u == protectSwitchSum) || (NULL == protectSwitchDataBuf))
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查防护道岔*/
			for (i = 0u; i<protectSwitchSum; i++)
			{
				SwitchId = protectSwitchDataBuf[i].ProtectSwitchId;
				cSwitchBelongCiId = GetSwitchBelongCiId(SwitchId);
				if ((0U != cSwitchBelongCiId) && (cLocalCiId == cSwitchBelongCiId))
				{
					SwitchPos = protectSwitchDataBuf[i].ProtectPosition;
					SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

					if (SWITCH_POSITION_DINGWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
							break;
						}

					}
					else if (SWITCH_POSITION_FANWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
							break;
						}

					}
					else
					{
						/*什么也不做*/
					}
				}
				else
				{
					/*非本控区道岔，不处理*/
				}
			}
		}

	}
	else
	{
		retVal = CI_ERROR;
	}
	

	return retVal;
}


/*
* 功能描述： 检查自动通过进路内方信号机道岔区段的封锁情况
* 参数说明： const UINT16 autoRouteId, 自动通过进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*/
UINT8 ChekAutoRouteFlockState(const UINT16 autoRouteId)
{
	UINT8 functionId = ETYPE_AUTO_ROUTE_FLAG;
	UINT8 routeSum = 0u;              /*自动进路包含进路数目 (配置字段)*/
	UINT16 *routeIdBuf = NULL;    /*自动进路进路ID数组 (配置字段)*/
	UINT8 reVal = CI_SUCCESS;
	UINT8 ii = 0u;

	routeSum = GetAutoRouteIncludeRouteSum(autoRouteId);/*该进路所包含进路数目*/
	routeIdBuf = GetAutoRouteIncludeRouteBuf(autoRouteId);/*获取该自动进路对应的基本进路*/
	for (ii = 0u;ii< routeSum; ii++)
	{
		reVal = ChekRouteFlockState(routeIdBuf[ii],functionId);
		if (CI_ERROR == reVal)
		{
			break;    /*包含的进路其中有一有封锁，则不允许设置自动属性*/
		}

	}
	return reVal;

}

/*
* 功能描述： 检查自动折返进路内方信号机道岔区段的封锁情况
* 参数说明： const UINT16 autoReturnId, 自动通过进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*/
UINT8 ChekAutoReturnFlockState(const UINT16 autoReturnId)
{
	UINT8 functionId = EFUNC_SET_AUTORETURN;
	UINT8 routeSum = 0u;              /*自动折返进路包含进路数目 (配置字段)*/
	UINT16 *routeIdBuf = NULL;    /*自动折返进路进路ID数组 (配置字段)*/
	UINT8 reVal = CI_SUCCESS;
	UINT8 ii = 0u;

	routeSum = GetAutoReturnIncludeRouteSum(autoReturnId);/*该进路所包含进路数目*/
	routeIdBuf = GetAutoReturnIncludeRouteBuf(autoReturnId);/*获取该自动进路对应的基本进路*/
	for (ii = 0u;ii< routeSum; ii++)
	{
		reVal = ChekRouteFlockState(routeIdBuf[ii],functionId);
		if (CI_ERROR == reVal)
		{
			break;    /*包含的进路其中有一有封锁，则不允许设置自动属性*/
		}

	}
	return reVal;

}

/*
* 功能描述： 检查全自动折返进路内方信号机道岔区段的封锁情况
* 参数说明： const UINT16 allAutoReturnId,全自动折返进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*/
UINT8 ChekAllAutoReturnFlockState(const UINT16 allAutoReturnId)
{
	UINT8 functionId = EFUNC_SET_ALLAUTORETURN;
	UINT8 routeSum = 0u;              /*自动折返进路包含进路数目 (配置字段)*/
	UINT16 *routeIdBuf = NULL;    /*自动折返进路进路ID数组 (配置字段)*/
	UINT8 reVal = CI_SUCCESS;
	UINT8 ii = 0u;

	routeSum = GetAllAutoReturnIncludeRouteSum(allAutoReturnId);/*该进路所包含进路数目*/
	routeIdBuf = GetAllAutoReturnIncludeRouteBuf(allAutoReturnId);/*获取该自动进路对应的基本进路*/
	for (ii = 0u;ii< routeSum; ii++)
	{
		reVal = ChekRouteFlockState(routeIdBuf[ii],functionId);
		if (CI_ERROR == reVal)
		{
			break;    /*包含的进路其中有一有封锁，则不允许设置自动属性*/
		}

	}
	return reVal;

}

/*
* 功能描述： 检查自动触发进路内方信号机道岔区段的封锁情况
* 参数说明：
* 返回值  ： UINT8
			 CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*cgh-合并CID-3037-4：
*/
UINT8 ChekAutoTriggerRouteFlockState(UINT16 routeId)
{
	UINT8 functionId = ETYPE_AUTO_TRAGGER_FLAG;
	UINT8 reVal = CI_ERROR;

	UINT8 autoTriggerType = 0U;      /*自动触发进路属性*/


	autoTriggerType = GetAutoTriggerType(routeId);      /*获取进路自动触发进路属性*/
	if (ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType)
	{
		reVal = ChekRouteFlockState(routeId, functionId);
		if (CI_ERROR == reVal)
		{
			debug_infor_printf((const)"ChekAutoTriggerRouteFlockState fail. Route %d FLock.\n", routeId);
		}

	}
	return reVal;

}
/*
* 功能描述： 检查进路内方信号机道岔区段的封锁情况
* 参数说明： const UINT16 autoRouteId, 进路ID
*            const UINT8 functionId, 功能ID
* 返回值  ： UINT8   
             CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*/
UINT8 ChekRouteFlockState(const UINT16 routeId, const UINT8 functionId)
{
	
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 sendLevel = ESEND_LEVEL_ATS;
	/*防护进路*/
	UINT8 overlapSum = GetRouteOverlapSum(routeId);            
	UINT16* overlapIdBuf = GetRouteOverlapIdBuf(routeId);
	UINT8 ii = 0u;
	/* 联锁逻辑检查 */  
	/* 进路内所有区段未被封锁 */

	checkResult = RouteSecFLockCheck(routeId,&devId,&devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/*cgh-合并CID-2539-1： 根据物理区段封锁类型设置errorcode*/
		AccToPhySecFlockTypeSetErrcode(devId, functionId, sendLevel, devState);
		/* 失败返回 */
		reResult = CI_ERROR;		
	}

	/*进路内所有道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteSwitchFLockCheck(routeId,&devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	/*进路防护道岔【未封锁】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteReltProtSwitchFLockCheck(routeId,&devId, &devState);

		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路内所有信号机【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteSignalFLockCheck(routeId,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	/*有一组防护区段【未封锁】*/
	if(CI_SUCCESS == reResult)
	{
		for (ii = 0u; ii < overlapSum; ii++)
		{
			devId = 0u;
			devState = 0u;
			checkResult = OverlapAllSecFLockValidCheck(overlapIdBuf[ii],&devId,&devState);
			if (CI_SUCCESS == checkResult)
			{/*保护区段内道岔封锁检查*/
				reResult = OverlapSwitchFLockStateCheck(overlapIdBuf[ii],&devId,&devState);
				
				if (CI_SUCCESS == reResult)
				{/*保护区段关联防护道岔封锁检查*/
					reResult = OvlpRelProtSwiFLockStaCheck(overlapIdBuf[ii],&devId,&devState);
					/* 通过检查 */
					if (CI_SUCCESS == reResult)
					{				
						reResult = CI_SUCCESS;  /*有一组保护区段未封锁则允许设置自动标志*/
						break;
					}
				}
			}
		
		}
		if ((ii == overlapSum) && (CI_ERROR == checkResult))
		{  /*所有保护区段均封锁*/
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
		else if ((ii == overlapSum) && (CI_ERROR == reResult))
		{
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		} 
		else
		{
			/* 注释 */
		}
	}

	
	return reResult;
}

/*
* 功能描述： 检查防淹门接近区域物理区段是否接近检查
* 参数说明：
*            UINT16 *pDevId,    设备id指针，取物理区段id
*            UINT8 *pDevState,  设备id状态指针，取物理区段状态
*            UINT16 floodGateId,    防淹门Id
* 返回值  ： CI_ERROR   接近
*            CI_SUCCESS		非接近
*/
UINT8 FloodGateAccessPhysecAcCheck(UINT16 floodGateId,UINT16 *pDevId,UINT8 *pDevState)
{
	UINT8 reResult =CI_ERROR;

	UINT16 phySecSum = 0u;
	FloodGateAccessPhySecStruct *pAccessPhySecData = NULL;/*临时变量：防淹门管理物理区段数量和id数组指针*/
	UINT16 phyId = 0u;
	UINT8 phyDir = 0U;		/*防淹门接近区域接近方向*/
	UINT8 phyOccupyState = 0u;/*临时变量：物理区段占用状态*/
	UINT16 phyRlockBelongRouteId = 0U;			/*进路锁闭所属进路*/
	UINT8 lockDir = 0u;/*锁闭方向*/
	UINT8 haveDirChangeInRoute = 0u;
	UINT8 shouldOppose = 0u;/*是否应该取反*/
	UINT16 ii=0u;

	phySecSum = GetFloodGateAccessPhySecNum(floodGateId);
	pAccessPhySecData = GetFloodGateAccessPhyDataStru(floodGateId);

	if ((NULL == pAccessPhySecData) ||(NULL == pDevId) || (NULL == pDevState))
	{
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		for (ii=0u;ii<phySecSum;ii++)
		{
			phyId = pAccessPhySecData[ii].AccessPhySecId;
			phyDir = pAccessPhySecData[ii].AccessPhySecDir;
			if (phyId > 0u)
			{
				phyOccupyState = GetPhySecCurMergeState(phyId);
				
				if (SECTION_OCCUPY_YES == phyOccupyState)
				{/*如果是占用，检查方向*/
					if ((FLOOD_GATE_ACCESS_DIR == phyDir) || (FLOOD_GATE_AWAY_DIR == phyDir))
					{
						phyRlockBelongRouteId = GetPhySecRLockBelongRouteId(phyId);
						if (0U < phyRlockBelongRouteId)
						{
							lockDir = GetPhySecLockDirection(phyId);
							haveDirChangeInRoute = GetRouteHaveDirChangePointIn(phyRlockBelongRouteId);
							shouldOppose = GetRoutePhySecShouldLockOppose(phyRlockBelongRouteId, phyId);/*是否应该取反*/
							if (ROUTE_HAVE_DIR_CHANGE_POINT == haveDirChangeInRoute)
							{/*进路内有方向变化点*/
								if (ROUTE_PHYSEC_SHOULD_OPPOSE_LOCK == shouldOppose)
								{/*应该取反*/
									if (CI_SYSTEM_DIRECTION_UP == lockDir)
									{
										lockDir = CI_SYSTEM_DIRECTION_DOWN;/*之前按上行锁闭的，取反*/
									}
									else if (CI_SYSTEM_DIRECTION_DOWN == lockDir)
									{
										lockDir = CI_SYSTEM_DIRECTION_UP;/*锁闭方向取反*/
									}
									else
									{
										/*不会执行到这*/
									}
								}
								else
								{/*不应取反*/
									/*之前锁闭是啥，就是啥*/
								}
							}
							lockDir = ConvertDirectionToLogic(lockDir);			/*运营方向转换为逻辑方向*/

							if (phyDir != lockDir)
							{
								/*非接近方向，返回非接近*/
								reResult = CI_SUCCESS;
							}
							else
							{
								reResult = CI_ERROR;	/*列车接近，返回接近*/
							}
						}
						else
						{
							reResult = CI_ERROR;	/*物理区段未进路锁闭，未防护锁闭，UT占压，返回接近*/
						}
					}
					else
					{
						/*配置方向为默认时，判为接近*/
						reResult = CI_ERROR;
					}
					
					if (CI_ERROR == reResult)
					{
						*pDevId = phyId;
						*pDevState = phyOccupyState;
						break;
					}
				}
				else
				{
					/*区段空闲，非接近*/
					reResult = CI_SUCCESS;
				}
			}
		
		}
	}
	return reResult;
}


/*
* 功能描述： 检查防淹门防护区域物理区段占用检查
* 参数说明：
*            UINT16 floodGateId,    防淹门Id
*            UINT16 *pDevId,    设备id指针，取物理区段id
*            UINT8 *pDevState,  设备id状态指针，取物理区段状态
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 FloodGateProtPhysecOccuCheck(UINT16 floodGateId,UINT16 *pDevId,UINT8 *pDevState)
{
	UINT8 reResult =CI_ERROR;

	UINT16 phySecSum = 0u;
	UINT16 *pPhySecIdBuf = NULL;/*临时变量：防淹门管理物理区段数量和id数组指针*/
	UINT16 phyId = 0u;
	UINT8 phyOccupyState = 0u;/*临时变量：物理区段占用状态*/

	UINT16 ii=0u;

	phySecSum = GetFloodGateProtectPhySecNum(floodGateId);
	pPhySecIdBuf = GetFloodGateProtectPhyIDBuf(floodGateId);

	if ((NULL == pPhySecIdBuf) ||(NULL == pDevId) || (NULL == pDevState))
	{
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		for (ii=0u;ii<phySecSum;ii++)
		{
		
			phyId = pPhySecIdBuf[ii];

			if (phyId > 0u)
			{
				phyOccupyState = GetPhySecCurMergeState(phyId);

				if (SECTION_OCCUPY_YES == phyOccupyState)
				{/*如果是占用，检查失败，打断循环*/
					reResult = CI_ERROR;
					*pDevId = phyId;
					*pDevState = phyOccupyState;
					break;
				}

			}
		
		}
	}
	return reResult;
}



/*
* 功能描述： 保护区段关联防淹门状态检查
* 参数说明： UINT16 const overlapId,    保护区段ID
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*			 UINT8 *pDevStateType,设备状态类型（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： 失败返回CI_ERROR   
*            成功返回CI_SUCCESS 
*/
UINT8 OverlapFloodGateStateCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevStateType,UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	UINT8  floodState = 0u;/*临时变量：防淹门状态*/
	UINT8 reVal = CI_ERROR;
	/* overlap区段 */
	UINT8 const floodSum = (UINT8)GetOverlapFloodGateSum(overlapId);
	UINT16* const pFloodIdBuf = GetOverlapFloodGateBuf(overlapId);
	

	/* 空指针检查 */
	if ((NULL == pFloodIdBuf) || (NULL == pDevId) || (NULL == pDevStateType) || (NULL == pDevState) )
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/ 
		for (i = 0u; i<floodSum; i++)
		{
			devId = pFloodIdBuf[i];

			floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

			/*检查1：检查防淹门开启锁闭状态为开启锁闭*/
			if (CI_SUCCESS == reVal)
			{
				floodState = GetFloodGateCurOpenLockState(floodGateId);
				if (FLOOD_GATE_OPENLOCK == floodState)
				{
					reVal = CI_SUCCESS;
				}
				else
				{
					reVal = CI_ERROR;
					*pDevId = floodGateId;
					*pDevStateType = ETYPE_FLOODGATE_OPENLOCKSTATE;
					*pDevState = floodState;
					break;
				}
			}



			/*检查2：检查防淹门关门请求状态为未关门请求*/
			if (CI_SUCCESS == reVal)
			{
				floodState = GetFloodGateCurCloseRequestSta(floodGateId);
				if (FLOOD_GATE_NOT_CLOSEREQ == floodState)
				{
					reVal = CI_SUCCESS;
				}
				else
				{
					reVal = CI_ERROR;
					*pDevId = floodGateId;
					*pDevStateType = ETYPE_FLOODGATE_CLOSEREQSTATE;
					*pDevState = floodState;
					break;
				}
			}

			/*检查3：检查防淹门当前同意关门输入状态为不同意关门*/
			if (CI_SUCCESS == reVal)
			{
				floodState = GetFloodGateCurAgreeCloseSta(floodGateId);
				if (FLOOD_GATE_NOT_AGREE_CLOSE == floodState)
				{
					reVal = CI_SUCCESS;
				}
				else
				{
					reVal = CI_ERROR;
					*pDevId = floodGateId;
					*pDevStateType = ETYPE_FLOODGATE_AGREECLOSESTATE;
					*pDevState = floodState;
					break;
				}
			}
			
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 检查自动通过进路内防淹门状态
* 参数说明： const UINT16 autoRouteId, 自动通过进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:检查成功
			 CI_ERROR:检查失败
*/
UINT8 AutoRouteFloodStateCheck(const UINT16 autoRouteId)
{
	UINT8 reVal = CI_ERROR;
	UINT8 functionId = ETYPE_AUTO_ROUTE_FLAG;
	UINT8 sendLevel = ESEND_LEVEL_ATS;
	UINT8 routeSum = 0u;              /*自动进路包含进路数目 (配置字段)*/
	UINT16 *pRouteIdBuf = NULL;    /*自动进路进路ID数组 (配置字段)*/
	UINT16 ii = 0u;
	UINT16 kk = 0u;
	UINT16 pp = 0u;
	UINT16 routeId = 0u;

	UINT16 floodSum = 0u;
	UINT16 *pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/

	UINT16 jj=0u;/*临时索引*/
	UINT8 flagBreak = 0u;/*中断循环标志*/

	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	
	UINT16 devId = 0u;

	UINT16 *pRouteOverlapIdBuf = NULL;/*进路保护区段id数组指针*/
	UINT16 routeOverlapSum =0u;/*进路保护区段数量*/
	UINT16 *pOverlapFloodIdBuf = NULL;/*保护区段关联防淹门id数组指针*/
	UINT16 overlapFloodSum = 0u;/*保护区段关联防淹门总数*/

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

	if (NULL != pRouteIdBuf)
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}

	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u;ii< routeSum; ii++)
		{
			routeId = pRouteIdBuf[ii];

			floodSum = GetRouteFloodGateSum(routeId);
			pFloodIdBuf = GetRouteFloodGateBuf(routeId);

			if (NULL == pFloodIdBuf)
			{
				reVal = CI_ERROR;
			}
			else
			{
				reVal = CI_SUCCESS;
			}

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;
				for (jj =0u;jj<floodSum;jj++)
				{
					devId = pFloodIdBuf[jj];

					floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

					reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);/*防淹门状态检查*/

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

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;
				pRouteOverlapIdBuf = GetRouteOverlapIdBuf(routeId);/*获取进路保护区段buf*/
				routeOverlapSum = GetRouteOverlapSum(routeId);/*获取进路保护区段数量*/
				for(kk =0u;kk<routeOverlapSum;kk++)
				{
					if (pRouteOverlapIdBuf != NULL)
					{
						pOverlapFloodIdBuf = GetOverlapFloodGateBuf(pRouteOverlapIdBuf[kk]);/*获取保护区段关联防淹门buf*/
						overlapFloodSum = GetOverlapFloodGateSum(pRouteOverlapIdBuf[kk]);/*获取保护区段关联防淹门数量*/
						if (overlapFloodSum > 0u)
						{
							if (pOverlapFloodIdBuf != NULL)
							{
								for (pp=0u;pp<overlapFloodSum;pp++)
								{
									floodGateId = pOverlapFloodIdBuf[pp];
									reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);/*防淹门状态检查*/
									if (CI_ERROR == reVal)
									{
										
										flagBreak = 1u;/*中断循环标志置1*/
										break;
									}
								}
								if (1u == flagBreak)
								{
									break;
								}
							}

						}

					}
					
				}
			}

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

	return reVal;
}



/*
* 功能描述： 检查自动折返进路内防淹门状态
* 参数说明： const UINT16 autoReturnId, 自动折返进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:检查成功
			 CI_ERROR:检查失败
*/
UINT8 AutoReturnFloodStateCheck(const UINT16 autoReturnId)
{
	UINT8 reVal = CI_ERROR;
	UINT8 functionId = EFUNC_SET_AUTORETURN;
	UINT8 routeSum = 0u;              /*自动折返进路包含进路数目 (配置字段)*/
	UINT16 *pRouteIdBuf = NULL;    /*自动折返进路进路ID数组 (配置字段)*/
	UINT8 ii = 0u;
	UINT16 routeId = 0u;

	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 floodSum = 0u;
	UINT16 *pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/

	UINT16 phySecSum = 0u;
	UINT16 *pPhySecIdBuf = NULL;/*临时变量：防淹门管理物理区段数量和id数组指针*/

	UINT16 jj=0u;/*临时索引*/
	UINT16 kk=0u;/*临时索引*/
	UINT16 pp = 0u;
	UINT8 flagBreak = 0u;/*中断循环标志*/

	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	UINT8 floodState = 0u;/*防淹门状态*/
	
	UINT16 devId = 0u;
	UINT8 sendLevel = ESEND_LEVEL_ATS;

	UINT16 *pRouteOverlapIdBuf = NULL;/*进路保护区段id数组指针*/
	UINT16 routeOverlapSum =0u;/*进路保护区段数量*/
	UINT16 *pOverlapFloodIdBuf = NULL;/*保护区段关联防淹门id数组指针*/
	UINT16 overlapFloodSum = 0u;/*保护区段关联防淹门总数*/
	
	routeSum = GetAutoReturnIncludeRouteSum(autoReturnId);/*该进路所包含进路数目*/
	pRouteIdBuf = GetAutoReturnIncludeRouteBuf(autoReturnId);/*获取该自动折返进路对应的基本进路*/

	if (NULL != pRouteIdBuf)
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}

	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u;ii< routeSum; ii++)
		{
			routeId = pRouteIdBuf[ii];
			/*0.获取进路关联防淹门*/
			floodSum = GetRouteFloodGateSum(routeId);
			pFloodIdBuf = GetRouteFloodGateBuf(routeId);

			if (NULL == pFloodIdBuf)
			{
				reVal = CI_ERROR;
			}
			else
			{
				reVal = CI_SUCCESS;
			}

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;
				for (jj =0u;jj<floodSum;jj++)
				{
					devId = pFloodIdBuf[jj];

					floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

					if (floodGateId > 0u)
					{
						reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);
						if (CI_ERROR == reVal)
						{
							flagBreak = 1u;
							break;
						}						
					}
				}
				if (1u == flagBreak)
				{
					break;
				}
			}

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;
				pRouteOverlapIdBuf = GetRouteOverlapIdBuf(routeId);
				routeOverlapSum = GetRouteOverlapSum(routeId);
				for(kk =0u;kk<routeOverlapSum;kk++)
				{
					if (pRouteOverlapIdBuf != NULL)
					{
						pOverlapFloodIdBuf = GetOverlapFloodGateBuf(pRouteOverlapIdBuf[kk]);
						overlapFloodSum = GetOverlapFloodGateSum(pRouteOverlapIdBuf[kk]);
						if (overlapFloodSum > 0u)
						{
							if (pOverlapFloodIdBuf != NULL)
							{
								for (pp=0u;pp<overlapFloodSum;pp++)
								{
									floodGateId = pOverlapFloodIdBuf[pp];
									reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);
									if (CI_ERROR == reVal)
									{
										flagBreak = 1u;
										break;
									}
								}
								if (1u == flagBreak)
								{
									break;
								}
							}

						}

					}

				}
			}

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

	return reVal;
}


/*
* 功能描述： 检查全自动折返进路内防淹门状态
* 参数说明： const UINT16 allAutoReturnId, 全自动折返进路ID
* 返回值  ： UINT8   
             CI_SUCCESS:检查成功
			 CI_ERROR:检查失败
*/
UINT8 AllAutoReturnFloodStateCheck(const UINT16 allAutoReturnId)
{
	UINT8 reVal = CI_ERROR;
	UINT8 functionId = EFUNC_SET_ALLAUTORETURN;
	UINT8 routeSum = 0u;              /*自动折返进路包含进路数目 (配置字段)*/
	UINT16 *pRouteIdBuf = NULL;    /*自动折返进路进路ID数组 (配置字段)*/
	UINT8 ii = 0u;
	UINT16 routeId = 0u;

	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 floodSum = 0u;
	UINT16 *pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/

	UINT16 phySecSum = 0u;
	UINT16 *pPhySecIdBuf = NULL;/*临时变量：防淹门管理物理区段数量和id数组指针*/

	UINT16 jj=0u;/*临时索引*/
	UINT16 kk=0u;/*临时索引*/
	UINT16 pp=0u;/*临时索引*/

	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	UINT8 floodState = 0u;/*防淹门状态*/
	
	UINT16 devId = 0u;
	UINT8 flagBreak = 0u;/*中断循环标志*/

	UINT16 *pRouteOverlapIdBuf = NULL;/*进路保护区段id数组指针*/
	UINT16 routeOverlapSum =0u;/*进路保护区段数量*/
	UINT16 *pOverlapFloodIdBuf = NULL;/*保护区段关联防淹门id数组指针*/
	UINT16 overlapFloodSum = 0u;/*保护区段关联防淹门总数*/

	UINT8 sendLevel = ESEND_LEVEL_ATS;
	
	routeSum = GetAllAutoReturnIncludeRouteSum(allAutoReturnId);/*该进路所包含进路数目*/
	pRouteIdBuf = GetAllAutoReturnIncludeRouteBuf(allAutoReturnId);/*获取该自动折返进路对应的基本进路*/

	if (NULL != pRouteIdBuf)
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}

	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u;ii< routeSum; ii++)
		{
			routeId = pRouteIdBuf[ii];
			/*0.获取进路关联防淹门*/
			floodSum = GetRouteFloodGateSum(routeId);
			pFloodIdBuf = GetRouteFloodGateBuf(routeId);

			if (NULL == pFloodIdBuf)
			{
				reVal = CI_ERROR;
			}
			else
			{
				reVal = CI_SUCCESS;
			}

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;/*每个进路对应的防淹门检查前都把中断标志初始化为不中断*/

				for (jj =0u;jj<floodSum;jj++)
				{
					devId = pFloodIdBuf[jj];

					floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

					if (floodGateId > 0u)
					{
						/*检查防淹门状态为开启状态*/
						reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);
						if (CI_ERROR == reVal)
						{
							flagBreak = 1u;
							break;
						}

					}

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

			if (CI_SUCCESS == reVal)
			{
				flagBreak = 0u;
				pRouteOverlapIdBuf = GetRouteOverlapIdBuf(routeId);
				routeOverlapSum = GetRouteOverlapSum(routeId);
				for(kk =0u;kk<routeOverlapSum;kk++)
				{
					if (pRouteOverlapIdBuf != NULL)
					{
						pOverlapFloodIdBuf = GetOverlapFloodGateBuf(pRouteOverlapIdBuf[kk]);
						overlapFloodSum = GetOverlapFloodGateSum(pRouteOverlapIdBuf[kk]);
						if (overlapFloodSum > 0u)
						{
							if (pOverlapFloodIdBuf != NULL)
							{
								for (pp=0u;pp<overlapFloodSum;pp++)
								{
									floodGateId = pOverlapFloodIdBuf[pp];
									reVal = FloodGateStateCheck(floodGateId,functionId,sendLevel);
									if (CI_ERROR == reVal)
									{

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

						}

					}

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

			

		}
	}

	return reVal;
}


/*
* 功能描述： 检查自动触发进路内方防淹门的状态
* 参数说明：
* 返回值  ： UINT8
			 CI_SUCCESS:无封锁
			 CI_ERROR:有封锁
*/
UINT8 ChekAutoTrigRouteFloodGateState(UINT16 routeId)
{
#if 0
	UINT8 functionId = ETYPE_AUTO_TRAGGER_FLAG;
	UINT8 reVal = CI_ERROR;
	UINT8 ii = 0u;
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 autoTriggerType = 0u;      /*自动触发进路属性*/

	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	/*处理进路*/
	for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = GetRouteId(ii);                           /*获取进路ID*/
		belongCiId = GetRouteBelongCiId(routeId);           /*获取进路所属联锁ID*/

		if ((0u == routeId) || (routeId > ROUTE_SUM_MAX) || (belongCiId != localCiId))
		{
			/*ID无效或非本联锁*/
		}
		else
		{
			autoTriggerType = GetAutoTriggerType(routeId);      /*获取进路自动触发进路属性*/
			if (ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType)
			{
				BlocRouteFloodGateCheck
					reVal = ChekRouteFlockState(routeId, functionId);
				if (CI_ERROR == reVal)
				{
					break;    /*包含的进路其中有一有封锁，则不允许设置自动属性*/
				}
			}
		}

	}
	return reVal;
#endif

	UINT8 functionId = ETYPE_AUTO_TRAGGER_FLAG;
	UINT8 reVal = CI_ERROR;
	UINT8 sendLevel = ESEND_LEVEL_ATS;
	UINT16 ii = 0U;
	UINT16 kk = 0U;
	UINT16 pp = 0U;
	UINT16 devId = 0U;
	UINT8 autoTriggerType = 0U;      /*自动触发进路属性*/

	UINT16 floodSum = 0u;
	UINT16* pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/

	UINT16* pRouteOverlapIdBuf = NULL;/*进路保护区段id数组指针*/
	UINT16 routeOverlapSum = 0u;/*进路保护区段数量*/
	UINT16* pOverlapFloodIdBuf = NULL;/*保护区段关联防淹门id数组指针*/
	UINT16 overlapFloodSum = 0u;/*保护区段关联防淹门总数*/

	UINT16 jj = 0u;/*临时索引*/
	UINT8 flagBreak = 0u;/*中断循环标志*/

	UINT16 floodGateId = 0U;/*临时变量：防淹门id*/



	autoTriggerType = GetAutoTriggerType(routeId);      /*获取进路自动触发进路属性*/
	if (ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType)
	{
		floodSum = GetRouteFloodGateSum(routeId);
		pFloodIdBuf = GetRouteFloodGateBuf(routeId);

		if (NULL == pFloodIdBuf)
		{
			reVal = CI_ERROR;
		}
		else
		{
			reVal = CI_SUCCESS;
		}

		if (CI_SUCCESS == reVal)
		{
			flagBreak = 0u;
			for (jj = 0u; jj < floodSum; jj++)
			{
				devId = pFloodIdBuf[jj];

				floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

				reVal = FloodGateStateCheck(floodGateId, functionId, sendLevel);/*防淹门状态检查*/

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

	if (CI_SUCCESS == reVal)
	{
		flagBreak = 0u;
		pRouteOverlapIdBuf = GetRouteOverlapIdBuf(routeId);/*获取进路保护区段buf*/
		routeOverlapSum = GetRouteOverlapSum(routeId);/*获取进路保护区段数量*/
		for (kk = 0u; kk < routeOverlapSum; kk++)
		{
			if (pRouteOverlapIdBuf != NULL)
			{
				pOverlapFloodIdBuf = GetOverlapFloodGateBuf(pRouteOverlapIdBuf[kk]);/*获取保护区段关联防淹门buf*/
				overlapFloodSum = GetOverlapFloodGateSum(pRouteOverlapIdBuf[kk]);/*获取保护区段关联防淹门数量*/
				if (overlapFloodSum > 0u)
				{
					if (pOverlapFloodIdBuf != NULL)
					{
						for (pp = 0u; pp < overlapFloodSum; pp++)
						{
							floodGateId = pOverlapFloodIdBuf[pp];
							reVal = FloodGateStateCheck(floodGateId, functionId, sendLevel);/*防淹门状态检查*/
							if (CI_ERROR == reVal)
							{

								flagBreak = 1u;/*中断循环标志置1*/
								break;
							}
						}
						if (1u == flagBreak)
						{
							break;
						}
					}

				}

			}

		}
	}
	return reVal;

}


/*
* 功能描述： 进路关联防护道岔封锁状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteReltProtSwitchFLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 进路道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const pDataIdBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 检查封锁状态 */
	if (NULL == pDataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 保护区段关联防护道岔封锁状态检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OvlpRelProtSwiFLockStaCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* overlap道岔 */
	UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
	OverlapProtectSwitchStruct* const pDataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 检查封锁状态 */
	if (NULL == pDataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].ProtectSwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 检查非进路防护道岔是否有道岔封锁
* 参数说明： 
* 返回值  ： 0：	有道岔被封锁
*            1:   	进路中道岔均未被封锁
*/
UINT8 CheckNonRouteRelProSwiFengSuo(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	switchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路防护道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路防护道岔数据*/

	if (NULL == pNonRouteProtectSwitchStru)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < switchSum; ii++)
		{
			devId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_YES == devState)
			{ /*有道岔封锁*/

				/* 记录故障码 */        
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_FLOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;	
				break;
			}
		}
	}

	return reVal;	
}


/*
* 功能描述： 进路关联防护道岔道岔区段封锁状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteRelProtSwitchSecFLockCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
	

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT16	switchSecId = 0u;/*临时变量：道岔区段*/
	UINT8 reVal = CI_ERROR;

	/* 进路道岔 */
	UINT8 const checkSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* const pDataIdBuf = GetRouteRelatedProtSwitchData(routeId);

	/* 检查封锁状态 */
	if (NULL == pDataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].ProtectSwitchId;
			switchSecId = GetSwitchPhySectionId(devId);
			devState = GetPhySecFLockState(switchSecId);
			if (PHYSICAL_SECTION_FLOCK_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = switchSecId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*返回结果*/
	return reVal;
}


/*
* 功能描述： 保护区段关联防护道岔区段封锁状态检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OvlpRelProSwiSecFLockStaCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT16	switchSecId = 0u;/*临时变量：道岔区段*/
	UINT8 reVal = CI_ERROR;

	/* overlap道岔 */
	UINT8 const checkSum = GetOverlapRelatedProtSwitSum(overlapId);
	OverlapProtectSwitchStruct* const pDataIdBuf = GetOverlapRelatedProtSwitStru(overlapId);

	/* 检查封锁状态 */
	if (NULL == pDataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].ProtectSwitchId;
			switchSecId = GetSwitchPhySectionId(devId);
			devState = GetPhySecFLockState(switchSecId);
			if (PHYSICAL_SECTION_FLOCK_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = switchSecId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 检查非进路防护道岔所在区段是否有区段封锁
* 参数说明： 
* 返回值  ： 0：	有区段被封锁
*            1:   	检查成功，没有被封锁
*/
UINT8 CheckNonRouteRelProSwitSecFLock(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT16	switchSecId = 0u;/*临时变量：道岔区段*/
	UINT8 reVal = CI_ERROR;

	switchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路防护道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路防护道岔数据*/

	if (NULL == pNonRouteProtectSwitchStru)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == reVal)
	{
		for (ii = 0u; ii < switchSum; ii++)
		{
			devId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
			switchSecId = GetSwitchPhySectionId(devId);
			devState = GetPhySecFLockState(switchSecId);
			if (PHYSICAL_SECTION_FLOCK_NO==devState)
			{
				/* 通过检查*/

			}
			else
			{
				/* 记录故障码 */        
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_FLOCK_STATE,devState,sendLevel); 
				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;	
}


/*
* 功能描述： 检查非进路中是否有区段被封锁
* 参数说明： 
* 返回值  ： 0：	有物理区段被封锁
*            1:   	进路中物理区段均未被封锁
*/
UINT8 CheckNonRoutePhysecFengSuo(UINT8 nonRouteId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 physecSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct* pNonRoutePhySecStru = NULL; /*区段数据*/
	UINT8 ii = 0u;

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;

	physecSum = GetNonRoutePhySectionSumById(nonRouteId); /*非进路道岔总数*/
	pNonRoutePhySecStru = GetNonRoutePhySecStruBufById(nonRouteId); /*非进路道岔数据*/

	if ( NULL == pNonRoutePhySecStru )
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;

		for (ii = 0u; ii < physecSum; ii++)
		{
			devId = pNonRoutePhySecStru[ii].PhySectionId;
			devState = GetPhySecFLockState(devId);
			if (PHYSICAL_SECTION_FLOCK_YES == devState)
			{ /*有区段封锁*/

				/* 记录故障码 */        
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_FLOCK_STATE,devState,sendLevel); 

				reVal = CI_ERROR;	
				break;
			}
		}
	}

	return reVal;	
}



/*
* 功能描述： 调车进路调车同意联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*			 RETURN_OPEN_ERR_SIGOPEN
*/
UINT8 DRouteDCTYCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT8 dctyState = 0u;/*调车同意按钮状态*/
	UINT16 dctRelayId = 0u;/*调车同意继电器*/
	UINT8 routeState = 0u;/*进路状态*/

	dctRelayId = GetRouteDCTAJId(routeId);

	routeState = GetRouteState(routeId);/*获取进路状态*/
	
	if (0u == dctRelayId)
	{/*调车同意按钮继电器不存在，检查成功。不是所有调车进路都有调车同意功能*/
		reVal = CI_SUCCESS;
	}
	else
	{
		dctyState = GetRouteDCTYState(routeId);
		if (ROUTE_DCT_AGREE == dctyState)
		{/*调车同意状态为 调车同意，检查成功*/
			reVal = CI_SUCCESS;
		}
		else
		{/*返回调车同意不满足*/
			reVal = RETURN_DCTY_NOT_SATISIFY;

			/*进路状态不为初锁异常时，报警；否则一直报*/
			if ((ROUTE_STATE_FIRST_LOCKERR != routeState) ||
				((ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId)) && (ROUTE_STATE_FIRST_LOCKERR == routeState))
				)
			{
				SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_DCTY_NOT_SATIFY,dctyState,sendLevel);
			}
			
		}
	}

	return reVal;
}

/*
* 功能描述： 防淹门状态检查
* 参数说明：
*            UINT16 floodGateId,    防淹门编号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*			 RETURN_OPEN_ERR_SIGOPEN
*/
UINT8 FloodGateStateCheck(UINT16 floodGateId,UINT8 functionId,UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT8 ii = 0u;
	UINT8 floodState = 0u;/*防淹门状态*/
	UINT16 bufIndex = 0u;
	
	bufIndex = GetFloodGateBufIndex(floodGateId);
	if (0u != bufIndex)
	{
		reVal = CI_SUCCESS;
	}
	
	/*检查1：检查防淹门开启锁闭状态为开启锁闭*/
	if (CI_SUCCESS == reVal)
	{
		floodState = GetFloodGateCurOpenLockState(bufIndex);
		if (FLOOD_GATE_OPENLOCK == floodState)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
			SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,bufIndex,ETYPE_FLOODGATE_OPENLOCKSTATE,floodState,sendLevel);
		}
	}

	/*检查2：检查防淹门关门请求状态为未关门请求*/
	if (CI_SUCCESS == reVal)
	{
		floodState = GetFloodGateCurCloseRequestSta(bufIndex);
		if (FLOOD_GATE_NOT_CLOSEREQ == floodState)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
			SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,bufIndex,ETYPE_FLOODGATE_CLOSEREQSTATE,floodState,sendLevel);
		}
	}

	/*检查3：检查防淹门当前同意关门输入状态为不同意关门*/
	if (CI_SUCCESS == reVal)
	{
		floodState = GetFloodGateCurAgreeCloseSta(bufIndex);
		if (FLOOD_GATE_NOT_AGREE_CLOSE == floodState)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
			SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,bufIndex,ETYPE_FLOODGATE_AGREECLOSESTATE,floodState,sendLevel);
		}
	}
	return reVal;
}

/*
* 功能描述： 检查计轴区段跳跃锁闭是否有道岔驱动超时
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
			 CI_SUCCESS:计轴区段内无道岔驱动超时
			 CI_ERROR:计轴区段内有道岔驱动超时
*/
UINT8 ChekJumpLockSwitDrivOvtmStat(const UINT16 axisSecId)
{
	UINT8 retVal = CI_ERROR;

	/* 进路道岔 */
	UINT8 const checkSum = GetAxisSwitchSum(axisSecId);
	AxisSwitchStruct* const dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;


	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		/*开始检查计轴区段内道岔*/
		for (i = 0u; i < checkSum; i++)
		{
			SwitchId = dataIdBuf[i].SwitchId;
			SwitchPos = dataIdBuf[i].SwitchPosition;
			SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

			if (SWITCH_POSITION_DINGWEI == SwitchPos)
			{
				/*道岔位置正确*/
				if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
				{
					retVal = CI_ERROR;
					break;
				}

			}
			else if (SWITCH_POSITION_FANWEI == SwitchPos)
			{
				/*道岔位置正确*/
				if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
				{
					retVal = CI_ERROR;
					break;
				}

			}
			else
			{
				/*什么也不做*/
			}
		}
	}

	if (CI_SUCCESS == retVal)
	{/*检查防护道岔是否驱动超时*/
		retVal = ChekJumpLockProtectSwitDrivOvtmStat(axisSecId);
	}

	return retVal;
}

/*
* 功能描述： 跳跃锁闭区段检查
* 参数说明： const UINT16 axisSecId, 计轴区段ID
* 返回值  ： UINT8   
             CI_SUCCESS:检查通过
			 CI_ERROR:检查失败
*/
UINT8 JumpLockSecStateCheck(const UINT16 axisSectionId,UINT8 funcId,UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;

	UINT16 physicalSecId = 0u;

	UINT8 routeState = 0u;  /*设置跳跃锁闭的区段所属的进路状态*/

	UINT16 routeRlockId = 0u;   /*物理区段正常锁闭所属进路ID*/
	UINT16 routePlockId = 0u;   /*物理区段防护锁闭所属进路ID*/

	UINT8 routeType = 0u;/*进路类型*/

	UINT8 routeHaveNear = 0u;/*是否有接近*/

	UINT16 jj = 0U;
	UINT16 floodGateSum = 0U;		/*防淹门数量*/
	UINT16* floodGateIdBuf = NULL;/*临时变量*/
	UINT8 floodState = 0u;/*防淹门状态*/

	UINT8 phySecFLockState = 0u;	/*物理区段封锁状态*/

	UINT8 routeLevel = 0u; /*进路监督级别*/
	UINT8 pLockRouteState = 0u;
	physicalSecId = GetAxisSecRelativePhySecId(axisSectionId);
	routeRlockId = GetPhySecRLockBelongRouteId(physicalSecId);/*物理区段进路锁闭所属进路ID*/
	routePlockId = GetPhySecPLockBelongRouteId(physicalSecId);/*物理区段防护锁闭所属进路ID*/

	routeType = GetRouteType(routeRlockId);/*进路类型*/

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

	phySecFLockState = GetPhySecFLockState(physicalSecId);/*获取物理区段封锁状态*/

	/*不能被调车进路锁闭*/
	if ((routeRlockId > 0u) && ( ROUTE_TYPE_DIAOCHE == routeType)) 
	{
		/*调车进路锁闭*/ 
		reVal = CI_ERROR;
		SetErrorData(funcId,CI_DEVICE_TYPE_ROUTE,routeRlockId,ETYPE_JUMP_LOCK_DIAOCE_ROUTE_LOCK,ROUTE_TYPE_DIAOCHE,sendLevel);
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	/*不能防护锁闭*/
	if ((routePlockId > 0u) && (CI_SUCCESS == reVal))
	{  
		routeLevel = GetRouteLevel(routePlockId);  /*获取防护锁闭所属进路监督级别*/
		pLockRouteState = GetRouteState(routePlockId);  /*获取进路状态*/
		/*CBTC*/
		if(ROUTE_LEVEL_CBTC == routeLevel)
		{
			reVal = CI_SUCCESS; /*返回成功*/
		}
		else
		{		
			routeHaveNear = RouteHaveTrainNear(routePlockId);
			/*进路有车接近且进路状态为接近开放或预先开放*/
			if ((CI_SUCCESS == routeHaveNear) && 
				((ROUTE_STATE_YUXIAN_OPEN == pLockRouteState)||(ROUTE_STATE_NEAR_OPEN == pLockRouteState)))
			{     
				reVal = CI_ERROR;
				SetErrorData(funcId,CI_DEVICE_TYPE_ROUTE,routePlockId,ETYPE_ROUTE_STATE,pLockRouteState,sendLevel);
			}
		}
	} 

	/*不能被车接近且进路接近开放或预先开放*/
	if ((CI_SUCCESS == reVal)&&(routeRlockId > 0u))
	{   
		routeLevel = GetRouteLevel(routeRlockId);  /*获取锁闭所属进路监督级别*/
		/*点式进路*/
		if(ROUTE_LEVEL_BLOC == routeLevel)
		{
			routeHaveNear = RouteHaveTrainNear(routeRlockId);
			/*进路有车接近且进路状态为接近开放或预先开放*/
			if ((CI_SUCCESS == routeHaveNear) && 
				((ROUTE_STATE_YUXIAN_OPEN == routeState)||(ROUTE_STATE_NEAR_OPEN == routeState)))
			{     
				reVal = CI_ERROR;
				SetErrorData(funcId,CI_DEVICE_TYPE_ROUTE,routeRlockId,ETYPE_ROUTE_STATE,routeState,sendLevel);
			}
		}
		else
		{
			/*返回成功*/
			reVal = CI_SUCCESS;
		}
	}

	if ((CI_SUCCESS == reVal) &&(PHYSICAL_SECTION_FLOCK_YES == phySecFLockState))
	{
		/*物理区段处于封锁状态*/
		SetErrorData(funcId,CI_DEVICE_TYPE_PHYSEC,physicalSecId,ETYPE_PS_FLOCK_STATE,phySecFLockState,sendLevel);
		reVal = CI_ERROR;
	}

	if ((CI_SUCCESS == reVal)&&( CI_ERROR == PhysicalIntruSecVainCheck(physicalSecId)))
	{
		/*侵限区段被侵限*/
		SetErrorData(funcId,CI_DEVICE_TYPE_PHYSEC,physicalSecId,ETYPE_PS_INSTRU,0,sendLevel);
		reVal = CI_ERROR;
	}

	if (CI_SUCCESS == reVal)
	{
		if (physicalSecId > 0u)
		{
			floodGateSum = GetPhySecLocatedFloodSum(physicalSecId);		/*数量为0说明没有防淹门，无需检查，依旧返回成功*/
			if (0U < floodGateSum)
			{
				floodGateIdBuf = GetPhySecLocatedFloodId(physicalSecId);
				if (NULL != floodGateIdBuf)
				{
					for (jj = 0U; jj < floodGateSum; jj++)
					{
						/*如果物理区段所在有防淹门，则检查防淹门状态*/
						floodState = GetFloodGateCurLogicCloseState(floodGateIdBuf[jj]);
						if (FLOOD_GATE_OPEN != floodState)
						{
							reVal = CI_ERROR;
							break;
						}
						else
						{
							reVal = CI_SUCCESS;
						}
					}
				}
				else
				{
					reVal = CI_ERROR;		/*获取数据失败，反馈失败*/
				}
			}
		}
	}
	return reVal;
}



/*
* 功能描述： 跳跃锁闭道岔检查
* 参数说明： const UINT16 axisSecId, 计轴区段ID
* 返回值  ： UINT8
			 CI_SUCCESS:检查通过
			 CI_ERROR:检查失败
*/
UINT8 JumpLockSwitchCheck(const UINT16 axisSecId, UINT8 funcId, UINT8 sendLevel)
{
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 reVal = CI_ERROR;
	UINT16 phyId = 0u;
	UINT8 chPhySecJmpState = 0U;

	phyId = GetAxisSecRelativePhySecId(axisSecId);/*获取相关物理区段ID*/

	/*计轴区段内所有道岔未引导总锁*/
	devId = 0u;
	devState = 0u;
	reVal = AxisSecSwitchYZLockCheck(axisSecId, &devId, &devState);
	if (CI_ERROR == reVal)
	{
		/* 记录故障码 */
		SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
	}

	/*计轴区段的防护道岔未引导总锁*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecProtSwtYLockCheck(axisSecId, &devId, &devState);
		if (CI_ERROR == reVal)
		{
			/* 记录故障码 */
			SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
		}
		else
		{
			/*继续检查*/
		}
	}

	/*计轴区段内所有道岔未封锁*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecSwitchFLockCheck(axisSecId, &devId, &devState);
		if (CI_ERROR == reVal)
		{
			/* 记录故障码 */
			SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
		}
	}

	/*计轴区段的防护道岔未封锁*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecProtSwitchFLockCheck(axisSecId, &devId, &devState);
		if (CI_ERROR == reVal)
		{
			/* 记录故障码 */
			SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
		}
	}




	/*计轴区段内所有道岔位置正确且如有最后一次驱动一致或位置不正确但可动作*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecSwitchPosMoveValCheck(axisSecId, &devId, &devState, funcId, sendLevel);
		if (CI_ERROR == reVal)
		{
			/* 记录故障码 */
			SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
		}
	}

	/*计轴区段防护道岔位置正确且如有最后一次驱动一致或位置不正确但可动作*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecPorteSwitchPosMoveCheck(axisSecId, &devId, &devState, funcId, sendLevel);
		if (CI_ERROR == reVal)
		{
			/* 记录故障码 */
			SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
		}
	}

	if (CI_SUCCESS == reVal)
	{
		chPhySecJmpState = GetPhySecJumpLockState(phyId);
		if (PHYSICAL_SECTION_JUMP_LOCK_YES == chPhySecJmpState)
		{/*检查防护道岔锁闭状态*/
			devId = 0u;
			devState = 0u;
			reVal = AxisRelatedProSwitchLockCheck(axisSecId, &devId, &devState);
		}
		else
		{
			/*此时尚未锁闭区段，尚未锁闭防护道岔,故不检查*/
		}
	}



	/*计轴区段内所有道岔位置正确	不正确：RETURN_LOCK_ERR_SWITPOS 	正确：CI_SUCCESS*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecAllSwitchPosCheck(axisSecId, &devId, &devState);
		if (CI_ERROR == reVal)
		{
			reVal = RETURN_LOCK_ERR_SWITPOS;
		}
	}

	/*计轴区段防护道岔所有道岔位置正确	不正确：RETURN_LOCK_ERR_SWITPOS 	正确：CI_SUCCESS*/
	if (CI_SUCCESS == reVal)
	{
		devId = 0u;
		devState = 0u;
		reVal = AxisSecAllProtSwitchPosCheck(axisSecId, &devId, &devState);
		if (CI_ERROR == reVal)
		{
			reVal = RETURN_LOCK_ERR_SWITPOS;
		}
	}

	return reVal;
}

/*
* 功能描述： 计轴区段道岔引导总锁状态检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 AxisSecSwitchYZLockCheck(UINT16 const axisSecId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 计轴区段道岔 */
	UINT8 const checkSum = GetAxisSwitchSum(axisSecId);
	AxisSwitchStruct* const dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 检查封锁状态 */
	if (NULL == dataIdBuf)
	{
		/*指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchYLockState(devId);
			if (SWITCH_LOCK_YINZONG_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 计轴区段道岔封锁状态检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 AxisSecSwitchFLockCheck(UINT16 const axisSecId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 进路道岔 */
	UINT8 const checkSum = GetAxisSwitchSum(axisSecId);
	AxisSwitchStruct* const dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 检查封锁状态 */
	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 计轴区段道岔位置和动作有效性检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 AxisSecSwitchPosMoveValCheck(UINT16 const axisSecId,UINT16 *pDevId,UINT8 *pDevState,UINT8 funcId,UINT8 sendLevel)
{
	/* 计轴区段道岔 */
	
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8  switchPos = 0u;

	UINT8 switchMoveState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 checkResult = 0u;

	UINT8 const checkSum = GetAxisSwitchSum(axisSecId);
	AxisSwitchStruct* const dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	/*联锁检查*/
	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		/* 进路内所有道岔位置正确 且不为【挤岔】 或位置不正确道岔可动作*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].SwitchPosition;
			if (devState == switchPos)
			{
				/* 道岔位置正确 */
				/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
				checkResult = checkSwtLastValDrvPosStayorNot(devId,switchPos);
				if (CI_SUCCESS == checkResult)
				{
				}
				else
				{
					reVal = CI_ERROR;
				}
			}
			else if (SWITCH_POSITION_SIKAI==devState)
			{
				/*四开*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(funcId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				reVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA==devState)
			{
				/*挤岔*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(funcId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel); 
				reVal = CI_ERROR;
			}
			else 
			{
				/* 道岔位置不正确 */
				switchMoveState = GetSwitchMoveValidState(devId,SWITCH_OPER_NO_DANCAO,sendLevel);
				if (CI_SUCCESS == switchMoveState)
				{
					/*道岔可动*/
				} 
				else
				{
					/*道岔位置不正确 且 道岔不可动作*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			if(CI_ERROR == reVal)
			{
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}


/*
* 功能描述： 计轴区段内所有道岔位置正确检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 AxisSecAllSwitchPosCheck(UINT16 const axisSecId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* 计轴区段道岔 */
	UINT8 const checkSum = GetAxisSwitchSum(axisSecId);
	AxisSwitchStruct* const dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;    
	UINT8 reVal = CI_ERROR;

	/* 检查封锁状态 */
	if ( NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			if (devState == dataIdBuf[i].SwitchPosition)
			{
				/*道岔位置正确*/

			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 指定进路信号机外方第一物理区段道岔位置检查
* 参数说明： UINT16 const routeId,    进路编号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* qw.liu	修改 进路外方第一区段道岔位置检查不使用接近区段，改为直接查逻辑区段
*/
UINT8 RouteOutfirstPhySecSwiPosCheck(UINT16 const routeId)
{
	UINT8 reVal = CI_ERROR;
	UINT16 outPhySecId = 0u; /*信号机外方第一区段ID*/
	UINT16 signalId = 0u;
	UINT16 signalOutFirstLogSecId = 0U;

	signalId = GetRouteStartSignalId(routeId);/*进路始端信号机*/
	outPhySecId = GetSignalOutFirstPhySecId(signalId); /*信号机外方第一物理区段ID*/
	signalOutFirstLogSecId = GetSignalOutFirstLogSec(signalId);

	if (0u != outPhySecId)
	{
		signalOutFirstLogSecId = GetSignalOutFirstLogSec(signalId);

		if (0U != signalOutFirstLogSecId)
		{
			/*逻辑区段有效 道岔位置已经在函数中查询通过*/
			reVal = CI_SUCCESS;
		}
		else
		{
			/*逻辑区段无效*/
			reVal = CI_ERROR;
		}
	}
	else
	{
		reVal = CI_SUCCESS;/*无外方第一物理区段，则不做此检查*/
	}
	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 指条件接近道岔与道岔当前位置检查
* 参数说明： RouteNearPhySectionStruct* pRouteNearPSSecStru,    进路接近区段结构体
*           UINT16 outPhySecId 信号机外方第一区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 BlocNearConditionSwitchPosCheck(RouteNearPhySectionStruct* pRouteNearPSSecStru,UINT16 outPhySecId)
{
	UINT8 reVal = CI_ERROR;
	UINT8 axisSecSum = 0u;
	UINT16* pAxisSecIdBuf=NULL;
	UINT8 switchSum=0u;
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 axisSwitchSum=0u; 
	AxisSwitchStruct*  pAxisSwitchStruct = NULL;
	UINT16 i = 0u; /* 循环变量 */
	UINT16 j = 0u; /* 循环变量 */
	UINT16 k = 0u; /* 循环变量 */

	axisSecSum = GetPAxisSectionSum(outPhySecId);/*信号机外方第一物理区段ID包含计轴区段数目*/
	pAxisSecIdBuf = GetPAxisSectionIdBuf(outPhySecId);/*信号机外方第一物理区段ID包含计轴区段数组*/
	if((NULL != pRouteNearPSSecStru)&&(NULL != pAxisSecIdBuf))
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}
	if((PHYSICAL_INCLUDE_AXIS_SUM_MAX >= axisSecSum)&&(CI_SUCCESS==reVal))
	{		
		for(i=0u;i<axisSecSum;i++)
		{
			axisSwitchSum = GetAxisSwitchSum(pAxisSecIdBuf[i]);/*计轴区段包含道岔数*/
			pAxisSwitchStruct= GetAxisSwitchIdStru(pAxisSecIdBuf[i]);/*计轴区段包含道岔数组*/
			if(NULL == pAxisSwitchStruct)
			{
				reVal = CI_ERROR;
			}
			else
			{
	            /*什么也不做*/
			}
			if(CI_SUCCESS == reVal)
			{
				if(AXIS_INCLUDE_SWITCH_SUM_MAX >= axisSwitchSum)
				{						
					for(j=0u;j<axisSwitchSum;j++)
					{
						devId = pAxisSwitchStruct[j].SwitchId;/*道岔编号*/
						switchSum = pRouteNearPSSecStru->SwitchSum;/*接近物理区段包含道岔数量*/
						if(CI_SUCCESS == reVal)
						{	
							if(ROUTE_CONDITION_SWITCH_SUM_MAX >= switchSum)
							{									
								for(k=0u;k<switchSum;k++)
								{
									if(devId == pRouteNearPSSecStru->ConditionSwitchStru[k].SwitchId)
									{
										devState = GetSwitchCurPosition(devId);/*获取道岔位置*/
										if(devState != pRouteNearPSSecStru->ConditionSwitchStru[k].SwitchPosition)
										{
											reVal = CI_ERROR;
											break;
										}
										else
										{
											/*什么也不做*/
										}
									}
									else
									{
										/*什么也不做*/
									}
								}	
							}
							else
							{
								reVal = CI_ERROR;/*数组越界，返回错误值*/
							}
						}
						else
						{
							/*什么也不做*/
						}
					}
				}
				else
				{
					reVal = CI_ERROR;/*数组越界，返回错误值*/
				}
			}
			else
			{
				/*什么也不做*/
			}
		}
	}
	else
	{
		reVal = CI_ERROR;/*数组越界，返回错误值*/
	}
	return reVal;
}

/*
* 功能描述： 车辆段列车进路区段锁闭有效性检查
* 参数说明： 
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 TradLTrainRouteSecLockValCheck(UINT16 const routeId,UINT16 *pDevId,UINT8 *pDevState)
{
/* 进路区段*/
    UINT8 checkSum = 0u;
    RoutePhysicalSectionStruct* pDataIdBuf = NULL;
    
/* 局部变量定义初始化 */
    UINT16 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
    UINT8 secProtectDirection = 0u;
	UINT8 phyArbState = 0u;
    UINT8 routeDirDirection = 0u;
	UINT8 routeStopState = 0u;
	UINT8 phyLJKValue = 0u;
	UINT8 phyStoCheckFlag = 0u;
	UINT8 reVal = CI_ERROR;

	/*赋值*/
	pDataIdBuf = GetRouteSectionData(routeId);
	checkSum = GetRoutePhysicalSectionSum(routeId);
	routeDirDirection = GetRouteDirection(routeId);

/* 区段锁闭检查 */
    if ((0u == checkSum) || (NULL == pDataIdBuf))
    {
        /*区段数据错误*/
    }
    else
    {
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecLockState(devId);
			secProtectDirection = GetPhySecLockDirection(devId);

			if (PHYSICAL_SECTION_LOCK_NO == devState)
			{
				/* 未锁闭 */
			}
			else if (PHYSICAL_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/
				
				if (secProtectDirection != routeDirDirection)
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

			}
			else if (PHYSICAL_SECTION_LOCK_NORMAL == devState)
			{
				/*获取区段相关信息*/
				routeStopState = GetRouteStopCheckFlag(routeId);
				phyLJKValue = GetPhySecLjkFlag(devId);
				phyStoCheckFlag = GetPhySectionStopCheckFlag(devId);

                if ((ROUTE_STOPCHECK_SET_YES == routeStopState) &&
                    (PHYSICAL_SECTION_LJK_YES == phyLJKValue) && 
					(PHYSICAL_STOPCHECK_SET_YES == phyStoCheckFlag) &&
					(secProtectDirection == routeDirDirection))
                {
                    /*区段锁闭状态为正常锁闭，停止检查有效且为列检库区段，且物理区段停止检查有效
                    该情景为：上个进路为列车进路最后一个区段无法解锁且列车故障，此时需办理调车进路将故障列车调出去
					物理区段锁闭方向与进路方向一致*/

                } 
                else
                {
                    /*状态无效故障状态*/
                    *pDevId = devId;
                    *pDevState = devState;
                    reVal = CI_ERROR;
                }

			}
			/*异常锁闭*/
			else if(PHYSICAL_SECTION_LOCK_EXCEPT == devState)
			{
				/*获取ARB状态*/
				phyArbState = GetPhySecArbState(devId);
				/*区段ARB状态，且锁闭方向一致*/
				if( (AXIS_SECTION_ARB_YES == phyArbState) && (secProtectDirection == routeDirDirection))
				{
					/*不做处理*/
				}
				else
				{
					/*返回失败*/
					*pDevId = devId;
                    *pDevState = devState;
                    reVal = CI_ERROR;
				}
			}
            else
            {
                /*状态无效故障状态*/
                *pDevId = devId;
                *pDevState = devState;
                reVal = CI_ERROR;
            }

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

    /*全部通过检查*/
    return reVal;
}

/*
*函数功能：检查自动组合进路包含的自动进路是否满足条件
*参数说明：const UINT16 autoRouteId 自动进路ID
*返回值：无
*/
UINT8 GroupInAutoRouteConditionCheck(UINT16 autoRouteId)
{
	/*变量初始化*/
	UINT8 returnValue = CI_ERROR;
	UINT8 chkStatus = 0U;/*临时变量，检查结果*/
	UINT8 chFunctionId = EFUNC_CHECK_GROUP_AUTO_ROUTE;/*函数ID*/
	UINT16 opposeRouteID = 0U;

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

	if (CI_SUCCESS == chkStatus)
	{
		/*抵触进路办理*/
		chkStatus = AutoRouteIsOpposedCheck(autoRouteId, chFunctionId);
		
	}

	if (CI_SUCCESS == chkStatus)
	{
		/*封锁状态检查*/
		chkStatus = ChekAutoRouteFlockState(autoRouteId);
		if (CI_SUCCESS != chkStatus)
		{ 
			SetErrorData(EFUNC_CHECK_GROUP_AUTO_ROUTE, CI_DEVICE_TYPE_AUTOROUTE,autoRouteId, ETYPE_AUTO_ROUTE_FLAG,AUTO_ROUTE_HAVE_BLOCK, ESEND_LEVEL_ATS);
		}

	}

	if (CI_SUCCESS == chkStatus)
	{
		/*防淹门检查*/
		chkStatus = AutoRouteFloodStateCheck(autoRouteId);
		if (CI_SUCCESS != chkStatus)
		{ 
			SetErrorData(EFUNC_CHECK_GROUP_AUTO_ROUTE, CI_DEVICE_TYPE_AUTOROUTE,autoRouteId, ETYPE_AUTO_ROUTE_FLAG, AUTO_ROUTE_FLOOD_STATE_ERR, ESEND_LEVEL_ATS);
		}
	}
	/*对检查条件的判断*/
	if(CI_SUCCESS == chkStatus)
	{
		returnValue = CI_SUCCESS;
	}
	else
	{
		/*返回错误*/
		returnValue = CI_ERROR;
	}
	return(returnValue);
}

/*
*函数功能：保护区段内道岔、防护道岔是否征用检查
*参数说明：const UINT16 overlapId保护区段ID 
*返回值：CI_ERROR:保护区段相关道岔未征用
*        CI_SUCCESS：保护区段相关道岔征用
*/
UINT8 OvlpIncludeAndProtSwitchCheck(const UINT16 overlapId)
{
	/*变量初始化*/
	UINT8 returnValue = CI_ERROR;
	UINT16 switchUsingOverlapId = 0u; /*道岔被征用的保护区段*/
	UINT16 i = 0u;
	UINT8 includeSwitchSum = 0u;  /*保护区段内道岔*/
	OverlapConditionSwitchStruct* pincludeSwitchBuff = NULL;
	UINT8 protectSwitchSum = 0u;  /*保护区段防护道岔*/
	OverlapProtectSwitchStruct* protectSwitchBuff = NULL;

	/*获取道岔信息*/
	includeSwitchSum = GetOverlapSwitchSum(overlapId);
	pincludeSwitchBuff = GetOverlapCondSwitchStruct(overlapId);
	protectSwitchSum = GetOverlapRelatedProtSwitSum(overlapId);
	protectSwitchBuff = GetOverlapRelatedProtSwitStru(overlapId);

	/*保护区段包含道岔*/
	if((0u != includeSwitchSum) && (NULL != pincludeSwitchBuff))
	{
		for(i = 0u; i < includeSwitchSum; i++)
		{
			/*获取道岔征用状态*/
			switchUsingOverlapId = GetSwitchBelongOverlapId(pincludeSwitchBuff[i].SwitchId);
			/*道岔征用属于本保护区段*/
			if(switchUsingOverlapId == overlapId)
			{
				returnValue = CI_SUCCESS;
				break;
			}
		}
	}
	else
	{
		/*返回失败*/
		returnValue = CI_ERROR;
	}
	/*保护区段内道岔非征用*/
	if(CI_ERROR == returnValue)
	{
		/*保护区段存在防护道岔*/
		if((0u != protectSwitchSum) && (NULL != protectSwitchBuff))
		{
			for(i = 0u; i < protectSwitchSum; i++)
			{
				/*获取道岔征用状态*/
				switchUsingOverlapId = GetSwitchBelongOverlapId(protectSwitchBuff[i].ProtectSwitchId);
				/*道岔征用属于本保护区段*/
				if(switchUsingOverlapId == overlapId)
				{
					returnValue = CI_SUCCESS;
					break;
				}
			}
		}
		else
		{
			returnValue = CI_ERROR;
		}
	}
	return(returnValue);
}
/*
*函数功能：区段处于进路征用时，检查区段道岔状态与进路内要求的是否一致
*参数说明：const UINT16 devId 物理区段ID 
*          const UINT16 routeId 已经征用或要征用该区段的进路
*返回值：0：失败
*        1：成功
*/
UINT8 CheckPhysecUseState(const UINT16 devId,const UINT16 routeId)
{
	RouteSwitchStruct *pRouteSwitchStruct = NULL;
	UINT8 routeSwitchSum = 0U;
	UINT8 reVal = CI_ERROR;
	UINT16 *pPhySecIncludeSwitch = NULL;
	UINT8 phyIncludeSwitchSum = 0U;
	UINT8 i = 0U;
	UINT16 routeSwitchID = 0U;
	UINT8 routeSwitchPos = 0U;
	UINT8 j = 0U;
	UINT16 phySecIncludeSwitchID = 0U;
	UINT8 SwitchExpDrvPos = 0U;/*道岔期望动作位置*/

	pRouteSwitchStruct = GetRouteSwitchData(routeId);/*正在办理的这条进路内的道岔数据*/
	routeSwitchSum = GetRouteSwitchSum(routeId);

	pPhySecIncludeSwitch = GetPhySecIncludeSwitch(devId);/*获取物理区段包含道岔*/
	phyIncludeSwitchSum = GetPhyIncludeSwitchSum(devId);

	if ((NULL == pRouteSwitchStruct) || (NULL == pPhySecIncludeSwitch))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	/*检查区段当前道岔位置与本进路内道岔位置是否相同*/
	if (CI_SUCCESS == reVal)
	{
		for (j = 0U; j<phyIncludeSwitchSum; j++)
		{
			phySecIncludeSwitchID = pPhySecIncludeSwitch[j];
			/*遍历进路的每一个道岔*/
			for (i = 0U; i<routeSwitchSum; i++)/*防护征用进路的道岔数*/
			{
				routeSwitchID = pRouteSwitchStruct[i].SwitchId;
				routeSwitchPos = pRouteSwitchStruct[i].SwitchPosition;
				if (phySecIncludeSwitchID == routeSwitchID)
				{
					reVal = CheckPhyUseSecCanOtherUse(phySecIncludeSwitchID, routeSwitchPos);/*检查已征用的道岔是否和本进路要求征用位置一致*/
				}
				/*失败后跳出*/
				if (CI_ERROR == reVal)
				{
					break;
				}
			}
			/*失败后跳出*/
			if (CI_ERROR == reVal)
			{
				break;
			}
		}

	}
	return reVal;
}
/*
*函数功能：保护区段区段处于征用时，是否可以办理检查
*参数说明：const UINT16 devId 物理区段ID 
*          const UINT16 overlapId 保护区段ID
*返回值：0：失败
*        1：成功
*/
UINT8 CheckOverlapPhysecUseState(const UINT16 devId,const UINT16 overlapId)
{
	UINT8 reVal = CI_ERROR;
	UINT16 *pPhySecIncludeSwitch = NULL;
	UINT8 phyIncludeSwitchSum = 0U;
	UINT8 i = 0U;
	UINT16 overlapSwitchID = 0U;
	UINT8 overlapSwitchPos = 0U;
	UINT8 j = 0U;
	UINT16 phySecIncludeSwitchID = 0U;
	UINT8 OverlapSwitchSum = 0U;
	OverlapConditionSwitchStruct* pConditionSwitchStr = NULL;
	UINT8 SwitchDrvPos = 0U;

	OverlapSwitchSum = GetOverlapSwitchSum(overlapId);
	pConditionSwitchStr = GetOverlapCondSwitchStruct(overlapId);


	pPhySecIncludeSwitch = GetPhySecIncludeSwitch(devId);/*获取物理区段包含道岔*/
	phyIncludeSwitchSum = GetPhyIncludeSwitchSum(devId);


	if ((NULL == pConditionSwitchStr) || (NULL == pPhySecIncludeSwitch))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	/*检查区段当前道岔位置与本保护区段内道岔位置是否相同*/
	if (CI_SUCCESS == reVal)
	{
		for (j = 0U; j<phyIncludeSwitchSum; j++)
		{
			phySecIncludeSwitchID = pPhySecIncludeSwitch[j];
			/*遍历保护区段的每一个道岔*/
			for (i = 0U; i<OverlapSwitchSum; i++)/*防护征用保护区段道岔数*/
			{
				overlapSwitchID = pConditionSwitchStr[i].SwitchId;
				overlapSwitchPos = pConditionSwitchStr[i].SwitchPosition;
				if (phySecIncludeSwitchID == overlapSwitchID)
				{
					reVal = CheckPhyUseSecCanOtherUse(overlapSwitchID, overlapSwitchPos);
				}

				/*失败后跳出*/
				if (CI_ERROR == reVal)
				{
					break;
				}

			}
			/*失败后跳出*/
			if (CI_ERROR == reVal)
			{
				break;
			}
		}

	}
	return reVal;
}

/*
*函数功能：道岔征用检查
* 输入参数：const UINT16 overlapId 保护区段ID
*           UINT16 *pDevId  设备ID
*返回值：CI_ERROR 0 检查失败
*        CI_SUCCESS 1 检查通过
*        RETURN_WAIT_SWITCH_USING 0x30 等待防护道岔征用
*/
UINT8 CheckOverlapSwitchUseState(const UINT16 overlapId,UINT16 *pDevId)
{
	/*变量初始化*/
	UINT8 returnValue = CI_ERROR;
	UINT16 switchUsingOverlapId = 0u; /*道岔被征用的保护区段*/
	UINT16 i = 0u;
	UINT8 includeSwitchSum = 0u;  /*保护区段内道岔*/
	OverlapConditionSwitchStruct* pincludeSwitchBuff = NULL;
	UINT8 protectSwitchSum = 0u;  /*保护区段防护道岔*/
	OverlapProtectSwitchStruct* protectSwitchBuff = NULL;
	UINT8 cSwitchUsingState = 0U;  /*道岔征用状态*/
	UINT8 cLocalCiId = 0U;
	UINT8 cSwitchBelongCiId = 0U;
	UINT32 dwXuanPaiStartCycNum = 0U;  /*保护区段选排起始周期*/

	/*获取道岔信息*/
	includeSwitchSum = GetOverlapSwitchSum(overlapId);
	pincludeSwitchBuff = GetOverlapCondSwitchStruct(overlapId);
	protectSwitchSum = GetOverlapRelatedProtSwitSum(overlapId);
	protectSwitchBuff = GetOverlapRelatedProtSwitStru(overlapId);

	if((NULL == pincludeSwitchBuff)||(NULL == protectSwitchBuff)|| (NULL == pDevId))
	{
		returnValue = CI_ERROR;
	}
	else
	{
		returnValue = CI_SUCCESS;

		/*保护区段内方道岔征用检查*/
		for (i = 0u; (i < includeSwitchSum) && (OVERLAP_CONDISWIT_SUM_MAX > i); i++)
		{
			cSwitchUsingState = GetSwitchUsingState(pincludeSwitchBuff[i].SwitchId);  /*获取道岔征用状态*/
			switchUsingOverlapId = GetSwitchBelongOverlapId(pincludeSwitchBuff[i].SwitchId);
			
			/*道岔征用检查*/
			if (((SWITCH_USING_YES == cSwitchUsingState) && (switchUsingOverlapId == overlapId))
				|| ((SWITCH_USING_NO == cSwitchUsingState) && (0U == switchUsingOverlapId)))
			{
				/*道岔未征用或被该保护区段征用，检查通过*/
			}
			else
			{
				/*道岔征用不属于本保护区段，返回失败*/
				*pDevId = pincludeSwitchBuff[i].SwitchId;
				returnValue = CI_ERROR;
				break;
			}
		}
	}

	/*保护区段防护道岔征用检查*/
	if(CI_SUCCESS == returnValue)
	{
		cLocalCiId = GetSystemParaLocalCiId();
		for(i = 0u; (i < protectSwitchSum)&&(OVERLAP_PROTECTSWI_SUM_MAX >i); i++)
		{
			cSwitchUsingState = GetSwitchUsingState(protectSwitchBuff[i].ProtectSwitchId);  /*获取道岔征用状态*/
			switchUsingOverlapId = GetSwitchBelongOverlapId(protectSwitchBuff[i].ProtectSwitchId);

			cSwitchBelongCiId = GetSwitchBelongCiId(protectSwitchBuff[i].ProtectSwitchId);  /*获取防护道岔所属控区*/
			if (cLocalCiId == cSwitchBelongCiId)
			{
				/*检查本控区防护道岔征用状态*/
				if (((SWITCH_USING_YES == cSwitchUsingState) && (switchUsingOverlapId == overlapId))
					|| ((SWITCH_USING_NO == cSwitchUsingState) && (0U == switchUsingOverlapId)))
				{
					/*道岔未征用或被该保护区段征用，检查通过*/
				}
				else
				{
					/*道岔征用不属于本保护区段，返回失败*/
					returnValue = CI_ERROR;
				}
			}
			else
			{
				/*检查非本控区防护道岔征用状态*/
				dwXuanPaiStartCycNum = GetOverlapXuanPaiStartCycNum(overlapId);  /*获取保护区段选排起始周期号*/

				if ((SWITCH_USING_YES == cSwitchUsingState) && (overlapId == switchUsingOverlapId))
				{
					/*防护道岔已被该保护区段征用，检查通过*/
				}
				else if (((SWITCH_USING_APPLY == cSwitchUsingState) && (overlapId == switchUsingOverlapId))
					|| ((SWITCH_USING_NO == cSwitchUsingState) && (0U == dwXuanPaiStartCycNum)))
				{
					returnValue = RETURN_WAIT_SWITCH_USING;  /*防护道岔处于申请征用或还未开始征用，返回等待征用*/
				}
				else
				{
					/*道岔征用不属于本保护区段，返回失败*/
					returnValue = CI_ERROR;
				}
			}

			if (CI_ERROR == returnValue)
			{
				*pDevId = protectSwitchBuff[i].ProtectSwitchId;
				break;
			}
		}
	}

	return returnValue;
}


/*
* 功能描述： Overlap区段列车数量检查
* 参数说明： UINT16 const overlapId
*            UINT16 *pTrainId,    列车编号（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OverlapLogicSectionTrainCheck(UINT16 const overlapId, UINT16 *pTrainId)
{
	UINT16 wTrainId = 0u;
	UINT8 cOverlapLogicSectionSum = 0u;
	UINT16* pOverlapLogicSectionIdBuf = NULL;
	UINT8 cLogicSectionTrainSum = 0u;
	LogicTrainResStruct* pLogicSectionTrainRes = NULL;

	UINT8 i = 0u;
	UINT8 reVal = CI_ERROR;
	
	cOverlapLogicSectionSum = GetOverlapLogicSectionSum(overlapId);
	pOverlapLogicSectionIdBuf = GetOverlapLogicSectionBuf(overlapId);

	if ((NULL != pTrainId) && (0u != cOverlapLogicSectionSum))
	{
		reVal = CI_SUCCESS;
	}
	else
	{
	}

	if (CI_SUCCESS == reVal)
	{
		for (i = 0u; i < cOverlapLogicSectionSum; i++)
		{
			cLogicSectionTrainSum = GetLogSecTrainInfoSum(pOverlapLogicSectionIdBuf[i]);
			pLogicSectionTrainRes = GetLogSecTrainInfo(pOverlapLogicSectionIdBuf[i]);

			if(NULL == pLogicSectionTrainRes)
			{
				reVal = CI_ERROR;
			}
			else if (0u == cLogicSectionTrainSum)
			{
				/* 无车，继续 */
			}
			else if(1u == cLogicSectionTrainSum)
			{
				/* 仅一辆车占压 */
				if ((0u == wTrainId) || (wTrainId == pLogicSectionTrainRes[0u].wTrainId))
				{
					/* 第一个次比较或列车ID相同 */
					wTrainId = pLogicSectionTrainRes[0u].wTrainId;
				}
				else
				{
					/* 列车ID不同 */
					reVal = CI_ERROR;
				}
			}
			else
			{
				/* 多辆车占压 */
				reVal = CI_ERROR;
			}

			if (CI_ERROR == reVal)
			{
				wTrainId = 0u;
				break;
			}
			else
			{
			}
		}
		*pTrainId = wTrainId;
	}
	else
	{
	}

	return reVal;
}

/*
* 功能描述： 逻辑区段封锁状态检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
*/
UINT8 LogicSecFLockCheck(UINT16 const wLgcId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 wLgcRelativePhyId = 0U;
	UINT8 chRetVal = CI_ERROR;
	UINT8 chPhyFLockState = PHYSICAL_SECTION_FLOCK_YES;
	UINT8 chPhyFLockReason = 0U;
	if ((NULL != pDevId)&&(NULL!= pDevState))
	{
		wLgcRelativePhyId = GetLgcSecRelativePhySecId(wLgcId);
		chPhyFLockState = GetPhySecFLockState(wLgcRelativePhyId);
		if (PHYSICAL_SECTION_FLOCK_NO == chPhyFLockState)
		{
			/* 通过检查*/
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chPhyFLockReason = GetPhySecFLockType(wLgcRelativePhyId);
			if (PHY_SEC_FLOCK_TYPE_SPKS == chPhyFLockReason)
			{
				/* SPKS按下时不影响资源征用*/
				chRetVal = CI_SUCCESS;
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = wLgcRelativePhyId;
				*pDevState = chPhyFLockState;
				chRetVal = CI_ERROR;
			}
		}
				
		
	}
	else
	{
		chRetVal = CI_ERROR;
	}



	return chRetVal;
}

/*
* 功能描述： 逻辑区段所处道岔位置检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
* 更新    ： 使用逻辑区段关联道岔进行计算
*/
UINT8 LogicSecRelativeSwitchPosCheck(UINT16 const wLgcId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT16 wLgcRelativeAxleSecId = 0U;
	UINT8 chCheckSum = 0U;
	LogsecSwitchStruct *pstlogicSecSwitchBuf = NULL;

	chCheckSum = GetLogicSecSwitchSum(wLgcId);
	pstlogicSecSwitchBuf = GetLogicSecSwitchIdStru(wLgcId);
	if ((NULL != pDevId) 
		&& (NULL != pDevState)
		&&(NULL !=pstlogicSecSwitchBuf)
		&&(LOGSEC_INCLUDE_SWITCH_SUM_MAX>chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			chDevId = pstlogicSecSwitchBuf[ii].SwitchId;
			chDevState = GetSwitchCurPosition(chDevId);
			if (pstlogicSecSwitchBuf[ii].SwitchPosition == chDevState)
			{
				/* 位置一致，继续检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = chDevId;
				*pDevState = chDevState;
				chRetVal = CI_ERROR;
			}
		}
		


	}
	else
	{
		chRetVal = CI_ERROR;
	}



	return chRetVal;
}

/*
* 功能描述： 逻辑区段所处道岔未封锁检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
*/
UINT8 LogicSecRelSwitchFLockCheck(UINT16 const wLgcId, UINT16 *pDevId, UINT8 *pDevState, UINT8* pYLockAlarmFlag)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chCheckSum = 0U;
	LogsecSwitchStruct *pstLogicSecSwitchBuf = NULL;

	chCheckSum = GetLogicSecSwitchSum(wLgcId);
	pstLogicSecSwitchBuf = GetLogicSecSwitchIdStru(wLgcId);
	if ((NULL != pDevId) && (NULL != pDevState) && (NULL != pYLockAlarmFlag) && (NULL != pstLogicSecSwitchBuf)
		&& (LOGSEC_INCLUDE_SWITCH_SUM_MAX>chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			chDevId = pstLogicSecSwitchBuf[ii].SwitchId;
			chDevState =GetSwitchFLockState(chDevId);
			if (SWITCH_LOCK_FENGSUO_NO == chDevState)
			{
				/*未封锁，继续检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = chDevId;
				*pDevState = chDevState;
				*pYLockAlarmFlag = FLAG_UNSET;
				chRetVal = CI_ERROR;
			}

			if (CI_SUCCESS == chRetVal)
			{
				chDevState = GetSwitchYLockState(chDevId);
				if (SWITCH_LOCK_YINZONG_NO == chDevState)
				{

				}
				else
				{
					/*状态不一致返回故障状态*/
					*pDevId = chDevId;
					*pDevState = chDevState;
					*pYLockAlarmFlag = FLAG_SET;
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				/*不处理，返回失败*/
			}

			if (CI_SUCCESS != chRetVal)
			{
				break;
			}
			else
			{
				; /*继续执行*/
			}
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段所处道岔防护道岔未封锁检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
*/
UINT8 LogicSecRltvPrtctSwFLockCheck(UINT16 const wLgcId, UINT16* pDevId, UINT8* pDevState, UINT8* pYLockAlarmFlag)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 jj = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chCheckSum = 0U;
	UINT16 wProtectSwSum = 0U;
	UINT16* pProtectSwIdBuf = NULL;
	LogsecSwitchStruct* pstLogicSecSwitchBuf = NULL;
	chCheckSum = GetLogicSecSwitchSum(wLgcId);
	pstLogicSecSwitchBuf = GetLogicSecSwitchIdStru(wLgcId);
	if ((NULL != pDevId) && (NULL != pDevState) && (NULL != pYLockAlarmFlag) && (NULL != pstLogicSecSwitchBuf)
		&& (LOGSEC_INCLUDE_SWITCH_SUM_MAX > chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			wProtectSwSum = GetSwitchProtectSwitchNum(pstLogicSecSwitchBuf[ii].SwitchId);
			pProtectSwIdBuf = GetSwitchProtectSwitchIdBuf(pstLogicSecSwitchBuf[ii].SwitchId);

			if ((NULL != pProtectSwIdBuf)
				&& (SWITCH_PROTECT_SWITCH_MAX_NUM > wProtectSwSum))
			{
				for (jj = 0U; jj < wProtectSwSum; jj++)
				{
					chDevId = pProtectSwIdBuf[jj];
					chDevState = GetSwitchFLockState(chDevId);
					if (SWITCH_LOCK_FENGSUO_NO == chDevState)
					{
						/*未封锁，继续检查*/
					}
					else
					{
						/*状态不一致返回故障状态*/
						*pDevId = chDevId;
						*pDevState = chDevState;
						*pYLockAlarmFlag = FLAG_UNSET;
						chRetVal = CI_ERROR;
					}

					if (CI_SUCCESS == chRetVal)
					{
						chDevState = GetSwitchYLockState(chDevId);
						if (SWITCH_LOCK_YINZONG_NO == chDevState)
						{

						}
						else
						{
							/*状态不一致返回故障状态*/
							*pDevId = chDevId;
							*pDevState = chDevState;
							*pYLockAlarmFlag = FLAG_SET;
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*不处理，返回失败*/
					}

						if (CI_SUCCESS != chRetVal)
						{
							break;
						}
						else
						{
							; /*继续执行*/
						}
				}
			}

			if (CI_ERROR == chRetVal)
			{
				break;
			}
			else
			{
				/*继续执行*/
			}
		}



	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段所处道岔防护道岔位置检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
* 修改：使用逻辑区段防护道岔位置做计算 qw.liu
*/
UINT8 LogicSecRltvPrtctSwPosCheck(UINT16 const wLgcId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 jj = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chCheckSum = 0U;
	UINT8 chProSwState = 0U;
	LogsecSwitchStruct* pstLogicSecSwitchBuf = NULL;

	chCheckSum = GetLgcRelateProSwSum(wLgcId);/*获取指定ID逻辑区段关联防护道岔数目*/
	pstLogicSecSwitchBuf = GetLgcRelateProSwStru(wLgcId);
	if ((NULL != pDevId)
		&& (NULL != pDevState)
		&& (NULL != pstLogicSecSwitchBuf)
		&& (LOGSEC_RELATE_PRO_SW_SUM_MAX > chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		/*遍历逻辑区段关联防护道岔*/
		for (ii = 0U; ii < chCheckSum; ii++)
		{

			chDevId = pstLogicSecSwitchBuf[ii].SwitchId;
			chDevState = GetSwitchCurPosition(chDevId);/*获取道岔当前位置*/
			chProSwState = pstLogicSecSwitchBuf[ii].SwitchPosition;

			chRetVal = checkSwtLastValDrvPosStayorNot(chDevId, chDevState);	/*检查道岔上一次驱动是否还在有效期*/
			/*道岔位置一致*/
			if ((chProSwState == chDevState)
				&& (CI_SUCCESS == chRetVal)
				&& ((SWITCH_POSITION_DINGWEI == chProSwState)
					|| (SWITCH_POSITION_FANWEI == chProSwState)))
			{
				/*位置检查通过，继续检查*/


			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = chDevId;
				*pDevState = chDevState;
				chRetVal = CI_ERROR;
				break;
			}
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段所处道岔防护道岔锁闭状态检查(防护锁闭或防护单锁叠加)
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
*/
UINT8 LogicSecRltvPrtctSwLockCheck(UINT16 const wLgcId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chProtectSwitchSum = 0U;
	LogsecSwitchStruct* chProtectSwitchIdBuf = NULL;
	chProtectSwitchSum = GetLgcRelateProSwSum(wLgcId);/*获取指定ID逻辑区段关联防护道岔数目*/
	chProtectSwitchIdBuf = GetLgcRelateProSwStru(wLgcId);

	if ((NULL != pDevId)
		&& (NULL != pDevState)
		&& (NULL != chProtectSwitchIdBuf)
		&& (LOGSEC_INCLUDE_SWITCH_SUM_MAX > chProtectSwitchSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chProtectSwitchSum; ii++)
		{
			chDevId = chProtectSwitchIdBuf[ii].SwitchId;
			chDevState = GetSwitchLockStatus(chDevId);
			if ((SWITCH_LOCK_STATUS_PROTECT == chDevState) || (SWITCH_LOCK_STATUS_DAP == chDevState))
			{
				/*道岔已【防护锁闭】或【单锁且防护锁闭】*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = chDevId;
				*pDevState = chDevState;
				chRetVal = CI_ERROR;
			}

			if (CI_SUCCESS != chRetVal)
			{
				break;
			}
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段侵限无效检查
* 参数说明：
*            UINT16 const physicalId,    物理区段ID
* 返回值  ： CI_ERROR   侵限
*            CI_SUCCESS 侵限不满足
* 创  建  
*/
UINT8 LogicIntruSecVainCheck(UINT16 const wLogicSecId, UINT16* pDevId, UINT8* pDevState)
{

	/* 局部变量定义初始化 */
	UINT16 i = 0u, j = 0u;           /* 循环变量 */
	UINT16 intruSwitchSum = 0u;
	UINT16 intruSwitchId = 0u;
	UINT16 intruSwitchPos = 0u;
	UINT8 intruSwitchLockDir = 0U;
	UINT16 wDevId = 0u;
	UINT8 chDevState = 0u;
	UINT8 chDevFengSuoState = 0u;
	UINT8 intruSwitchPosValid = CI_ERROR;
	UINT8 reVal = CI_ERROR;
	UINT8 chSwitchCurPos = 0U;
	UINT8 chPhysecLockDir = 0U;
	UINT8 chPhySecCtOrUt = 0U;
	UINT8 cPhyLockState = 0U;
	UINT8 cPhyJumpLockState = 0U;
	/*侵限时是否检查封锁  */
	UINT8 checkFlockFlag = GetCiFunctionSwitchConfig(FUNC_INTRUSEC_CHECKFLOCK_FLAG);
	/* 侵限区段 */
	UINT8 const chLgcIntruSum = GetSecIntrudeLgcSectionSum(wLogicSecId);
	UINT16* const pLgcSecIntruIdBuf = GetSecIntrudeLgcSectionData(wLogicSecId);
	UINT8* const pLgcSecIntruDirBuf = GetSecIntrudeLgcSecDirData(wLogicSecId);
	UINT8 chPhySecLogLockState = 0U;/*物理区段逻辑锁闭状态*/

	/* 检查侵限状态 */
	if ((NULL == pLgcSecIntruIdBuf)
		|| (NULL == pLgcSecIntruDirBuf)
		|| (NULL == pDevId)
		|| (NULL == pDevState))
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < chLgcIntruSum; i++)
		{
			wDevId = GetInvaSectId(pLgcSecIntruIdBuf[i]);
			chDevState = GetPhySecCurMergeState(wDevId);
			chDevFengSuoState = GetPhySecFLockState(wDevId);
			chPhySecCtOrUt = GetPhySecUtOrCtOccuState(wDevId);
			chPhysecLockDir = GetPhySecLockDirection(wDevId);
			intruSwitchLockDir = pLgcSecIntruDirBuf[i];
			cPhyLockState = GetPhySecLockState(wDevId);
			cPhyJumpLockState = GetPhySecJumpLockState(wDevId);
			chPhySecLogLockState = PhySecLogLockStateCheck(wDevId);

			/* 检查侵限区段是否占用或封锁*/
			if ((SECTION_OCCUPY_NO != chDevState)
				|| ((PHYSICAL_SECTION_FLOCK_NO != chDevFengSuoState) && (FUNC_SWITCH_ON != checkFlockFlag))
				|| (PHYSICAL_SECTION_LOCK_NO != cPhyLockState)
				|| (PHYSICAL_SECTION_JUMP_LOCK_NO != cPhyJumpLockState) 
				|| (LOG_SECTION_LOGLOCK_NO != chPhySecLogLockState))
			{
				/*侵限区段占用或封锁*/
				intruSwitchSum = GetInvaSectsCondSwitSum(pLgcSecIntruIdBuf[i]);
				if (intruSwitchSum > 0u)
				{
					/*侵限道岔位置检查*/
					intruSwitchPosValid = CI_ERROR;
					for (j = 0u; j < intruSwitchSum; j++)
					{
						intruSwitchId = GetInvaSectsCondSwitId(pLgcSecIntruIdBuf[i], (INT16)j);
						intruSwitchPos = GetInvaSectsCondSwitStat(pLgcSecIntruIdBuf[i], (INT16)j);

						chSwitchCurPos = GetSwitchCurPosition(intruSwitchId);
						if ((intruSwitchPos == chSwitchCurPos)
							|| (SWITCH_POSITION_SIKAI == chSwitchCurPos)
							|| (SWITCH_POSITION_MOVE == chSwitchCurPos)
							|| (SWITCH_POSITION_JICHA == chSwitchCurPos)
							|| (SWITCH_POSITION_INVALID == chSwitchCurPos))
						{
							/* 仅占压判断占压方向 */
							if ((PHYSICAL_SECTION_FLOCK_NO == chDevFengSuoState)
								&& (PHYSICAL_SECTION_JUMP_LOCK_NO == cPhyJumpLockState)
								&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState))
							{
								if ((chPhysecLockDir == intruSwitchLockDir)
									&& ((CI_SYSTEM_DIRECTION_UP == intruSwitchLockDir)
										|| (CI_SYSTEM_DIRECTION_DOWN == intruSwitchLockDir)))
								{
									if (LOGICSECTION_OCCUPY_CT == chPhySecCtOrUt)
									{
										intruSwitchPosValid = CI_SUCCESS; /*检查成功*/
									}
									else
									{
										intruSwitchPosValid = IntruSecVainCheck(wDevId);
									}

								}
								else
								{
									intruSwitchPosValid = CI_ERROR;
								}
							}
							else
							{
								intruSwitchPosValid = CI_ERROR;
							}
						}
						else
						{
							/*道岔未侵限*/
							intruSwitchPosValid = CI_SUCCESS;
							break;
						}
					}

					if (intruSwitchPosValid == CI_ERROR)
					{
						/*有岔侵限条件成立*/
						reVal = CI_ERROR;
						*pDevId = wDevId;
						*pDevState = chDevState;
					}
				}
				else
				{
					/*无岔侵限条件条件成立*/
					reVal = CI_ERROR;
					*pDevId = wDevId;
					*pDevState = chDevState;
				}
				if (CI_ERROR == reVal)
				{
					*pDevId = wDevId;
					*pDevState = chDevState;
					break;
				}
			}
			/* 检查侵限区段未占用且未封锁*/
			else if ((SECTION_OCCUPY_NO == chDevState)
				&& ((PHYSICAL_SECTION_FLOCK_NO == chDevFengSuoState) || (FUNC_SWITCH_ON == checkFlockFlag))
				&& (PHYSICAL_SECTION_LOCK_NO == cPhyLockState)
				&& (PHYSICAL_SECTION_JUMP_LOCK_NO == cPhyJumpLockState)
				&& (LOG_SECTION_LOGLOCK_NO == chPhySecLogLockState))
			{/*侵限区段未占用且(未封锁或不检查封锁)且未锁闭未跳跃锁闭且未逻辑锁闭*/
				/*侵限区段检查通过*/
			}
			else
			{
				/*侵限区段占用状态异常导向安全*/
				reVal = CI_ERROR;
				*pDevId = wDevId;
				*pDevState = chDevState;
				break;
			}
		}
	}

	/* 未检测到侵限条件 */
	return reVal;
}

/*
* 功能描述： 进路最后一个逻辑区段的下一相邻逻辑区段锁闭检查
* 参数说明：UINT16 const wLogicSecId,  逻辑区段ID
*           UINT16 *pDevId,     设备Id（返回）
*           UINT8  *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
* 创  建
*/
UINT8 LogicNextLogSecLockCheck(UINT16 const wLogicSecId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 i = 0U;
	UINT8 reVal = CI_ERROR;
	UINT16 wRouteLastLogSecId = 0U;   /*逻辑区段所属进路的最后一个逻辑区段ID*/
	UINT16 wNextLogSecId = 0U;        /*下一相邻逻辑区段ID*/
	UINT16 wThisLogSecLockBelongRouteId = 0U;    /*逻辑区段锁闭所属进路ID*/
	UINT8 cRouteMainorSub = 0U;       /*主子进路属性*/
	UINT16 wRouteEndSignalId = 0U;    /*进路终端信号机*/
	UINT8 cSignalIsVir = 0U;          /*信号机虚拟属性*/
	UINT8 cThisRouteLockDir = 0U;     /*逻辑区段锁闭所属进路的锁闭方向*/
	UINT8 cThisLogSecLockDir = 0U;    /*逻辑区段锁闭方向*/
	UINT8 cNextLogSecLockstate = 0U;  /*下一相邻逻辑区段锁闭状态*/
	UINT8 cNextLogSecLockDir = 0U;    /*下一相邻逻辑区段锁闭方向*/
	UINT8 cSysLogDir = 0U;            /*系统定义的逻辑方向*/
	UINT8 cRelatedLogSecSum = 0U;     /*下一相邻逻辑区段数量*/
	UINT16* pRelatedLogSecId = NULL;  /*下一相邻逻辑区段ID数组*/

	wThisLogSecLockBelongRouteId = GetLogSecLockBelongRoute(wLogicSecId);
	wRouteLastLogSecId = GetRouteInLastLogSecId(wThisLogSecLockBelongRouteId);
	
	if (0U == wRouteLastLogSecId)/*进路最后一个逻辑区段ID无效*/
	{
		reVal = CI_ERROR;
		*pDevId = wNextLogSecId;
		*pDevState = cNextLogSecLockDir;
	}
	else if (wRouteLastLogSecId == wLogicSecId)  /*当前逻辑区段为进路最后一个逻辑区段才处理*/
	{
		cRouteMainorSub = GetRouteMainorSubPropert(wThisLogSecLockBelongRouteId);

		if (ROUTE_SUB_PROPERTY == cRouteMainorSub)  /*分段进路，继续判断*/
		{
			wRouteEndSignalId = GetRouteEndSignalId(wThisLogSecLockBelongRouteId);
			cSignalIsVir = GetSignalVirtualAttr(wRouteEndSignalId);

			if (SIGNAL_VIRTUAL_NO != cSignalIsVir)  /*虚拟信号机，继续判断*/
			{
				cThisRouteLockDir = GetRouteDirection(wThisLogSecLockBelongRouteId);
				cSysLogDir = GetLinkLogicDirUpAndDown();

				/*根据逻辑方向确定逻辑区段下一相邻逻辑区段数量/ID*/
				if (cThisRouteLockDir == cSysLogDir)
				{
					cRelatedLogSecSum = GetLogBeginLogSecSum(wLogicSecId);
					pRelatedLogSecId = GetLogBeginLogSecData(wLogicSecId);
				}
				else
				{
					cRelatedLogSecSum = GetLogEndLogSecSum(wLogicSecId);
					pRelatedLogSecId = GetLogEndLogSecData(wLogicSecId);
				}

				for (i = 0U; i < cRelatedLogSecSum; i++)
				{
					wNextLogSecId = pRelatedLogSecId[i];
					cNextLogSecLockstate = GetLogSecLockState(wNextLogSecId);

					if ((LOG_SECTION_LOCK_NORMAL == cNextLogSecLockstate) || (LOG_SECTION_LOCK_PROTECT == cNextLogSecLockstate)) /*修缺陷YF0083-916，2023-07-03*/
					{
						cThisLogSecLockDir = GetLogSecLockDir(wLogicSecId);
						cNextLogSecLockDir = GetLogSecLockDir(wNextLogSecId);

						if (((CI_SYSTEM_DIRECTION_DOWN == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_DOWN == cNextLogSecLockDir))
							|| ((CI_SYSTEM_DIRECTION_UP == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_UP == cNextLogSecLockDir)))
						{
							reVal = CI_SUCCESS;  /*逻辑区段与下一相邻逻辑区段锁闭方向相同，返回成功*/
						}
						else
						{
							
							*pDevId = wNextLogSecId;
							*pDevState = cNextLogSecLockDir;
							reVal = CI_ERROR;
							break;
						}
					}
					else
					{
						*pDevId = wNextLogSecId;
						*pDevState = cNextLogSecLockDir;
						reVal = CI_ERROR;
					}
				}
			}
			else
			{
				reVal = CI_SUCCESS;  /*实体信号机，返回成功*/
			}
		}
		else
		{
			reVal = CI_SUCCESS;  /*主进路或普通进路，返回成功*/
		}
	}
	else
	{
		reVal = CI_SUCCESS;  /*非进路最后一个逻辑区段，返回成功*/
	}

	return reVal;
}

/*
* 功能描述： 逻辑进路最后一个逻辑区段的下一相邻逻辑区段锁闭检查
* 参数说明：UINT16 const wLogicSecId,  逻辑区段ID
*			UINT16 const wLogRouteId,  
*           UINT16 *pDevId,     设备Id（返回）
*           UINT8  *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
* 创  建
*/
UINT8 LogRouteNextLogSecLockCheck(UINT16 const wLogicSecId, UINT16 const wLogRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT8 reVal = CI_ERROR;
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 wRouteLastLogSecId = 0U;
	UINT16 wNextLogSecId = 0U;        /*下一相邻逻辑区段ID*/
	UINT8 cNextLogSecLockDir = 0U;    /*下一相邻逻辑区段锁闭方向*/
	UINT8 cThisRouteLockDir = 0U;     /*逻辑区段锁闭所属逻辑进路的锁闭方向*/
	UINT8 cSysLogDir = 0U;            /*系统定义的逻辑方向*/
	UINT8 cRelatedLogSecSum = 0U;     /*下一相邻逻辑区段数量*/
	UINT16* pRelatedLogSecId = NULL;  /*下一相邻逻辑区段ID数组*/
	UINT8 i = 0U;
	UINT8 cNextLogSecLockstate = 0U;  /*下一相邻逻辑区段锁闭状态*/
	UINT8 cThisLogSecLockDir = 0U;    /*逻辑区段锁闭方向*/
	UINT8 cLogRouteNextLogSecLockstate = 0U;	/*下一相邻逻辑区段逻辑锁闭状态*/

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	wRouteLastLogSecId = LogSecIdBuff[logSecSum - 1U];			/*取逻辑进路最后一个逻辑区段*/

	if (0U == wRouteLastLogSecId)/*进路最后一个逻辑区段ID无效*/
	{
		reVal = CI_ERROR;
		*pDevId = wNextLogSecId;
		*pDevState = cNextLogSecLockDir;
	}
	else if (wRouteLastLogSecId == wLogicSecId)
	{
		cThisRouteLockDir = GetLogicalRouteDir(wLogRouteId);
		cSysLogDir = GetLinkLogicDirUpAndDown();

		/*根据逻辑方向确定逻辑区段下一相邻逻辑区段数量/ID*/
		if (cThisRouteLockDir == cSysLogDir)
		{
			cRelatedLogSecSum = GetLogBeginLogSecSum(wLogicSecId);
			pRelatedLogSecId = GetLogBeginLogSecData(wLogicSecId);
		}
		else
		{
			cRelatedLogSecSum = GetLogEndLogSecSum(wLogicSecId);
			pRelatedLogSecId = GetLogEndLogSecData(wLogicSecId);
		}

		for (i = 0U; i < cRelatedLogSecSum; i++)
		{
			wNextLogSecId = pRelatedLogSecId[i];
			cNextLogSecLockstate = GetLogSecLockState(wNextLogSecId);
			cLogRouteNextLogSecLockstate = GetLogSecLogLockState(wNextLogSecId);	/*获取逻辑区段逻辑进路锁闭状态*/
			cThisLogSecLockDir = GetLogSecLogLockDir(wLogicSecId);			/*逻辑进路逻辑锁闭方向*/

			if ((LOG_SECTION_LOCK_NORMAL == cNextLogSecLockstate) || (LOG_SECTION_LOCK_PROTECT == cNextLogSecLockstate)) /*修缺陷YF0083-916，2023-07-03*/
			{
				cNextLogSecLockDir = GetLogSecLockDir(wNextLogSecId);

				if (((CI_SYSTEM_DIRECTION_DOWN == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_DOWN == cNextLogSecLockDir))
					|| ((CI_SYSTEM_DIRECTION_UP == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_UP == cNextLogSecLockDir)))
				{
					reVal = CI_SUCCESS;  /*逻辑区段与下一相邻逻辑区段锁闭方向相同，返回成功*/
				}
				else
				{

					*pDevId = wNextLogSecId;
					*pDevState = cNextLogSecLockDir;
					reVal = CI_ERROR;
					break;
				}
			}
			else if(LOG_SECTION_LOCK_NO== cNextLogSecLockstate)
			{
				reVal = CI_SUCCESS;			/*下一逻辑区段空闲，可以给资源，返回成功*/
			}
			else
			{
				*pDevId = wNextLogSecId;
				*pDevState = cNextLogSecLockDir;
				reVal = CI_ERROR;
				break;
			}

			if (CI_SUCCESS == reVal)
			{
				if (LOG_SECTION_LOGLOCK_NORMAL == cLogRouteNextLogSecLockstate)
				{
					cNextLogSecLockDir = GetLogSecLogLockDir(wNextLogSecId);		/*下一区段逻辑锁闭方向*/

					if (((CI_SYSTEM_DIRECTION_DOWN == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_DOWN == cNextLogSecLockDir))
						|| ((CI_SYSTEM_DIRECTION_UP == cThisLogSecLockDir) && (CI_SYSTEM_DIRECTION_UP == cNextLogSecLockDir)))
					{
						reVal = CI_SUCCESS;  /*逻辑区段与下一相邻逻辑区段锁闭方向相同，返回成功*/
					}
					else
					{

						*pDevId = wNextLogSecId;
						*pDevState = cNextLogSecLockDir;
						reVal = CI_ERROR;
						break;
					}
				}
				else if (LOG_SECTION_LOGLOCK_NO == cLogRouteNextLogSecLockstate)
				{
					reVal = CI_SUCCESS;			/*下一逻辑区段空闲，可以给资源，返回成功*/
				}
				else
				{
					*pDevId = wNextLogSecId;
					*pDevState = cNextLogSecLockDir;
					reVal = CI_ERROR;
					break;
				}
			}
		}
	}
	else
	{
		reVal = CI_SUCCESS;  /*非进路最后一个逻辑区段，返回成功*/
	}

	return reVal;
}

/*
* 功能描述： 逻辑区段跳跃锁闭状态检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-02
*/
UINT8 LogicSecJumpLockCheck(UINT16 const wLgcId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 wLgcRelativePhyId = 0U;
	UINT8 chRetVal = CI_ERROR;
	UINT8 chPhyJumpLockState = PHYSICAL_SECTION_JUMP_LOCK_YES;

	if ((NULL != pDevId) && (NULL != pDevState))
	{
		wLgcRelativePhyId = GetLgcSecRelativePhySecId(wLgcId);
		chPhyJumpLockState = GetPhySecJumpLockState(wLgcRelativePhyId);
		if (PHYSICAL_SECTION_JUMP_LOCK_NO == chPhyJumpLockState)
		{
			/* 通过检查*/
			chRetVal = CI_SUCCESS;
		}
		else
		{
			/*状态不一致返回故障状态*/
			*pDevId = wLgcRelativePhyId;
			*pDevState = chPhyJumpLockState;
			chRetVal = CI_ERROR;
		}


	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段资源可用性检查
* 参数说明：
*            UINT16 wLogicSecId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogicSecResSwitchCheck(UINT16 wLogicSecId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 FSwitchFlag = 0u;
	UINT8 cYLockAlarmFlag = FLAG_UNSET;  /*引导总锁报警标志*/

	/* 联锁逻辑检查 */

	FSwitchFlag = GetCiFunctionSwitchConfig(CLOSE_OPENED_SIG_LOCK_SWITCH);
	if (FUNC_SWITCH_OFF == FSwitchFlag)    /*开关未打开则不检查道岔封锁状态*/
	{
		reResult = CI_SUCCESS;
	}
	else if (FUNC_SWITCH_ON == FSwitchFlag)
	{
		/*进路内所有道岔【未封锁】*/
		devId = 0u;
		devState = 0u;
		checkResult =LogicSecRelSwitchFLockCheck(wLogicSecId, &devId, &devState, &cYLockAlarmFlag);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			if (FLAG_SET == cYLockAlarmFlag)
			{
				SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
			}
			else
			{
				SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
			}
			/* 失败返回 */
			reResult = CI_ERROR;

		}

		if (CI_SUCCESS == reResult)
		{
			/*进路防护道岔【未封锁】*/
			devId = 0u;
			devState = 0u;
			cYLockAlarmFlag = FLAG_UNSET;
			checkResult =LogicSecRltvPrtctSwFLockCheck (wLogicSecId, &devId, &devState, &cYLockAlarmFlag);

			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				if (FLAG_SET == cYLockAlarmFlag)
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_YLOCK_STATE, devState, sendLevel);
				}
				else
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_FLOCK_STATE, devState, sendLevel);
				}
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

	}
	else
	{
		reResult = CI_ERROR;
	}


	if (CI_SUCCESS == reResult)
	{
		
		/*进路所有道岔位置正确*/
		devId = 0u;
		devState = 0u;
		checkResult =LogicSecRelativeSwitchPosCheck (wLogicSecId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
		
	}
	else
	{
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路关联防护道岔位置正确*/
		devId = 0u;
		devState = 0u;
		checkResult = LogicSecRltvPrtctSwPosCheck(wLogicSecId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}

		if (CI_SUCCESS == reResult)
		{
			/*进路关联防护道岔【防护锁闭】或【单锁且防护锁闭】*/
			devId = 0u;
			devState = 0u;
			checkResult =LogicSecRltvPrtctSwLockCheck(wLogicSecId, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_LOCK_STATUS, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			reResult = CI_ERROR;
		}
		
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	
	if (CI_SUCCESS == reResult)
	{
		/*逻辑区段侧防道岔条件满足*/
		devId = 0u;
		devState = 0u;
		checkResult = LogicSecSwitchLtrlDfncCheck(wLogicSecId, &devId, &devState);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_NO_UT_CT_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	if (CI_SUCCESS == reResult)
	{
		/*逻辑区段联络线道岔条件满足*/
		devId = 0u;
		devState = 0u;
		checkResult = LogicContactLineDevCheck(wLogicSecId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/* 返回结果 */
	return reResult;
}


/*
* 功能描述： 逻辑区段资源可用区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogicSecResSectionCheck(UINT16 wLogicSecId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 cLocalWorkMode = RC_WORK_MODE_CI;  /*工作模式*/
	UINT16 wLogSecRelPhySecId = 0U;  /*逻辑区段关联的物理区段*/

	devId = 0u;
	devState = 0u;

	/* 逻辑区段检查 */
#if 0
	/* 逻辑区段所属物理区段未被封锁 */
	checkResult = LogicSecFLockCheck(wLogicSecId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}
#endif

	/*逻辑区段 侵限区段侵限条件不满足检查*/
	devId = 0u;
	devState = 0u;
	cLocalWorkMode = GetLocalRcWorkMode();
	if (RC_WORK_MODE_TIOC == cLocalWorkMode)
	{
		checkResult = LogicIntruSecVainCheck(wLogicSecId, &devId, &devState);  /*RC模式检查逻辑区段侵限条件是否满足*/
	}
	else
	{
		wLogSecRelPhySecId = GetLgcSecRelativePhySecId(wLogicSecId);
		checkResult = PhysicalIntruSecVainCheck(wLogSecRelPhySecId);  /*CI模式检查逻辑区段关联的物理区段侵限条件是否满足*/
	}

	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}


	/*进路最后一个逻辑区段的下一相邻逻辑区段锁闭检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogicNextLogSecLockCheck(wLogicSecId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*逻辑区段CBTC区域属性检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = wLogicSecId;
		devState = 0U;
		checkResult = CheckLogSecCbtcProperty(wLogicSecId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_CBTC_PROPERTY, devState, sendLevel);
			reResult = CI_ERROR;
		}
	}

#if 0
	/* 逻辑区段所属物理区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogicSecJumpLockCheck(wLogicSecId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_JUMP_LOCK, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
#endif
	/* 返回结果 */
	return reResult;
}

/*
* 功能描述： 逻辑进路逻辑区段资源可用区段联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*			 UINT16 wLogicSecId,	逻辑区段ID
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteLogicSecResSectionCheck(UINT16 wLogicSecId, UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/


	devId = 0u;
	devState = 0u;


	/* 逻辑区段检查 */
#if 0
	/* 逻辑区段所属物理区段未被封锁 */
	checkResult = LogicSecFLockCheck(wLogicSecId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}
#endif


	/*逻辑区段 侵限区段侵限条件不满足检查*/

	devId = 0u;
	devState = 0u;
	checkResult = LogicIntruSecVainCheck(wLogicSecId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路最后一个逻辑区段的下一相邻逻辑区段锁闭检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteNextLogSecLockCheck(wLogicSecId, wLogRouteId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 返回结果 */
	return reResult;
}
/*
* 功能描述： 逻辑区段资源可用性检查
* 参数说明： UINT16 const wLogicSecId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOGIC_RES_APP_CHECK
*/
UINT8 LogicSecResApplicabilityCheck(UINT16 const wLogicSecId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOGIC_RES_APP_CHECK;

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;         /*返回值*/
	UINT8 checkResult = CI_ERROR;        /*检查结果*/
	UINT16 routeId = 0U;
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;				 /*故障发送级别*/
	UINT8 chLocalCiType = 0U;  /*本地联锁类型*/
	UINT8 chTrainTestState = 0U; /*试车状态*/

	chLocalCiType = GetLocalCiType();
	chTrainTestState = GetCiTrainTestStatus();

	if ((CI_TYPE_SCX == chLocalCiType) && (CI_TRAIN_TEST_ON != chTrainTestState))
	{
		SetErrorData(functionId, CI_SYSTEM_TYPE_CI, chLocalCiType, ETYPE_SYSTEM_EXCEPT, chTrainTestState, sendLevel);
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	/* 检查进路锁闭且未处于引导锁闭状态 */
	if (CI_SUCCESS == reResult)
	{
		/* 逻辑区段锁闭所属进路 */
		routeId = GetLogSecLockBelongRoute(wLogicSecId);
		reResult = CheckRouteStateNotYinDaoLock(routeId);
		if (CI_SUCCESS == reResult)
		{
			;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	
	/* 进路类型是列车进路*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if ((ROUTE_TYPE_LIECHE == devState)
			||(ROUTE_TYPE_RETURN == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_TYPE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if (RES_CHECK_STATE_WAITE == checkResult)
		{
			checkResult = TrainRelateLogSecCheck(wLogicSecId, routeId);
			if (CI_SUCCESS == checkResult)
			{
				/* 列车脚下逻辑区段本端照查继电器吸起容忍期间通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


	/* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult =LogicSecResSectionCheck (wLogicSecId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	/* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogicSecResSwitchCheck(wLogicSecId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 防淹门联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = FloodGateCheck(wLogicSecId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	

	return reResult;
}

/*
* 功能描述： 逻辑进路逻辑区段资源可用性检查
* 参数说明： UINT16 const wLogicSecId	逻辑区段ID
*			 UINT16 const wLogRouteId	逻辑进路ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOGROUTE_LOGIC_RES_APP_CHECK
*/
UINT8 LogRouteLogSecResAppCheck(UINT16 const wLogicSecId,UINT16 const wLogRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOGROUTE_LOGIC_RES_APP_CHECK;
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;         /*返回值*/
	UINT8 checkResult = CI_ERROR;        /*检查结果*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;				 /*故障发送级别*/
	UINT8 chLocalCiType = 0U;  /*本地联锁类型*/
	UINT8 chTrainTestState = 0U; /*试车状态*/

	chLocalCiType = GetLocalCiType();
	chTrainTestState = GetCiTrainTestStatus();

	if ((CI_TYPE_SCX == chLocalCiType) && (CI_TRAIN_TEST_ON != chTrainTestState))
	{
		SetErrorData(functionId, CI_SYSTEM_TYPE_CI, chLocalCiType, ETYPE_SYSTEM_EXCEPT, chTrainTestState, sendLevel);
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = LogRouteLogicSecResSectionCheck(wLogicSecId, wLogRouteId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogicSecResSwitchCheck(wLogicSecId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 防淹门联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = FloodGateCheck(wLogicSecId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	return reResult;
}

/*
* 功能描述： 逻辑区段侧防条件检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： 
*/
UINT8 LogicSecSwitchLtrlDfncCheck(UINT16 const wLgcId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 jj = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT16 wSwitchRltvPhySecId = 0U;
	UINT8 chCheckSum = 0U;
	UINT16 wLtrlDfncSwSum = 0U;
	LogsecSwitchStruct* pProtectSwIdBuf = NULL;
	UINT8 chPhySecUtOrCtOccState = 0U;
	UINT8 chPhySecLockDir = 0U;
	UINT8 chSwitchCurPos = 0U;
	UINT8 *pSwitchLtrlDfncLockDir = NULL;
	UINT16 wLgcLockBelongRutId = 0U;
	UINT16 wRutIncProSwFlag = CI_ERROR;
	UINT8 chPhySecMerOccState = 0U;
	LogsecSwitchStruct *pstLtrlDfncSwitch = NULL;
	UINT8 cLogSecLockFlag = CI_ERROR; /*逻辑区段锁闭标志*/
	
	wLtrlDfncSwSum = GetLgcSecLtrlDfncSwSum(wLgcId);
	pstLtrlDfncSwitch =GetLgcSecLtrlDfncSwStru (wLgcId);
	pSwitchLtrlDfncLockDir = GetLgcSecLtrlDfncLockDir(wLgcId);
	if ((NULL != pDevId)
		&& (NULL != pDevState)
		&& (NULL != pstLtrlDfncSwitch)
		&&(NULL!= pSwitchLtrlDfncLockDir)
		&& (LOGSEC_LTRL_DFNC_SUM_MAX>wLtrlDfncSwSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < wLtrlDfncSwSum; ii++)
		{
			/*获取道岔关联物理区段*/
			wSwitchRltvPhySecId =GetSwitchPhySectionId(pstLtrlDfncSwitch[ii].SwitchId);
			/*获取道岔当前位置*/
			chSwitchCurPos = GetSwitchCurPosition(pstLtrlDfncSwitch[ii].SwitchId);
			/*获取物理区段锁闭方向*/
			chPhySecLockDir = GetPhySecLockDirection(wSwitchRltvPhySecId);
			cLogSecLockFlag = CheckPSecIncLSecLogicLockState(wSwitchRltvPhySecId, pDevId, pDevState);
			if (CI_ERROR != wSwitchRltvPhySecId)
			{
				/*参数合法*/
				chPhySecMerOccState = GetPhySecCurMergeState(wSwitchRltvPhySecId);
				chPhySecUtOrCtOccState = GetPhySecUtOrCtOccuState(wSwitchRltvPhySecId);
				if (SECTION_OCCUPY_NO != chPhySecMerOccState)
				{
					/*物理区段融合状态为占用*/
					if ((pstLtrlDfncSwitch[ii].SwitchPosition == chSwitchCurPos)
						&&((SWITCH_POSITION_DINGWEI==pstLtrlDfncSwitch[ii].SwitchPosition)
							||(SWITCH_POSITION_FANWEI == pstLtrlDfncSwitch[ii].SwitchPosition)))
					{
						; /*满足侧防位置，不处理*/
					}
					else
					{
						if (LOGICSECTION_OCCUPY_CT == chPhySecUtOrCtOccState)
						{
							/*CT占压，检查锁闭方向是否满足*/
							if ((pSwitchLtrlDfncLockDir[ii] != chPhySecLockDir)
								&& ((CI_SYSTEM_DIRECTION_UP == chPhySecLockDir) || (CI_SYSTEM_DIRECTION_DOWN == chPhySecLockDir))
								&& ((CI_SYSTEM_DIRECTION_UP == pSwitchLtrlDfncLockDir[ii]) || (CI_SYSTEM_DIRECTION_DOWN == pSwitchLtrlDfncLockDir[ii]))
								&& (CI_SUCCESS == cLogSecLockFlag))
							{
								; /*锁闭方向为接近道岔方向且逻辑区段无逻辑锁闭*/
							}
							else
							{
								chRetVal = CI_ERROR;  /*锁闭方向非接近方向或被逻辑进路锁闭，返回失败*/
							}
						}
						else
						{
							chRetVal = CI_ERROR;  /*非CT占压，返回失败*/
						}
					}
				}
			}
			else
			{
				/* 防护 配置数据有误*/
				chRetVal = CI_ERROR;
			}
			if (CI_ERROR == chRetVal)
			{
				*pDevId = wSwitchRltvPhySecId;
				*pDevState = chPhySecUtOrCtOccState;
				break;
			}
			else
			{
				/*继续执行*/
			}
		}

	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}
/*
* 功能描述： 保护区段可用性逻辑检查
* 参数说明： UINT16 const overlapId 保护区段ID
* 返回值  ： CI_ERROR 检查不通过
*            CI_SUCCESS 检查通过
*/
UINT8 OverlapUsableCheck(UINT16 const wOverlapId)
{
	UINT8 const functionId = EFUNC_OVERLAP_RES_APP_CHECK;
	UINT8 sendLevel = ESEND_LEVEL_ZERO;
	UINT8 cErrStep = 0U;
	UINT8 cRetVal = CI_ERROR; /*返回值*/
	UINT8 overlapPhySecSum = 0u;/*保护区段包含物理区段数目*/
	UINT16 *overlapContainPhySecIdBuf = NULL;/*保护区段包含物理区段数组*/
	UINT8 ii = 0u;
	UINT16 overlapbelongRtId = 0u;/*保护区段保护锁闭所属进路*/
	UINT16 rtOverlapLockedId = 0u;/*进路实际锁闭的保护区段*/
	UINT8 checkResult = CI_ERROR;/*检查结果变量*/
	UINT16 tempDevId = 0u;/*设备ID临时变量，调用Check函数需要的出口参数，本函数不关心*/
	UINT8 tempDevSta = 0u;/*设备状态临时变量，调用Check函数需要的出口参数，本函数不关心*/
	UINT8 overlapSum = 0u;
	UINT16* overlapIdBuf = NULL;
	UINT8 jj = 0u;

	overlapPhySecSum = GetOverlapPhySecSum(wOverlapId);
	overlapContainPhySecIdBuf = GetOverlapPhySecIdBuf(wOverlapId);
	for (ii = 0u; ii < overlapPhySecSum; ii++)
	{/*遍历保护区段包含的物理区段，查找防护锁闭所属进路ID*/
		overlapbelongRtId = GetPhySecPLockBelongRouteId(overlapContainPhySecIdBuf[ii]);
		if (0u != overlapbelongRtId)
		{/*查找成功*/
			cRetVal = CI_SUCCESS;
			break;
		}
	}
	if (CI_SUCCESS == cRetVal)
	{
		overlapSum = GetRouteOverlapSum(overlapbelongRtId);  /*获取Overlap总数*/
		overlapIdBuf = GetRouteOverlapIdBuf(overlapbelongRtId);  /*获取Overlap ID BUF*/
	}

	if ((NULL != overlapIdBuf)
		&&(0U<overlapSum)
		&& (ROUTE_PROTECTSECGROUP_SUM_MAX >overlapSum))
	{
		for (jj = 0u; jj < overlapSum; jj++)
		{  /*当进路包含的保护区段与锁闭的保护区段一致，则发送保护区段锁闭码位，否则不发，
		   防止多条进路包含同一个物理区段保护信息，导致实际没有锁闭的进路的保护区段也发送保护区段锁闭码位，20190109*/
			rtOverlapLockedId = GetRouteOverlapLockedId(overlapbelongRtId);/*获取进路实际锁闭的保护区段ID*/

			if ((overlapIdBuf[jj] == rtOverlapLockedId) && (wOverlapId == overlapIdBuf[jj]))
			{
				/*保护区段建立码位有效性检查*/
				checkResult = OverlapValidMaskCheck(rtOverlapLockedId);

				if (CI_SUCCESS == checkResult)
				{
					cRetVal = CI_SUCCESS;
				}
				else
				{
					cErrStep = 1U;
					cRetVal = CI_ERROR;
				}

				/*检查信号机保护区段有效性*/
				if (CI_SUCCESS == cRetVal)
				{
					checkResult = SignalOverlapValidCheck(overlapbelongRtId, &tempDevId, &tempDevSta);

					if (CI_SUCCESS == checkResult)
					{
						cRetVal = CI_SUCCESS;
					}
					else
					{
						cErrStep = 2U;
						cRetVal = CI_ERROR;
					}
				}
				else
				{
					cRetVal = CI_ERROR;
				}

				/*检查保护区段的CBTC区域属性*/
				if (CI_SUCCESS == cRetVal)
				{
					checkResult = CheckOverlapCbtcProperty(wOverlapId);
					if (CI_SUCCESS == checkResult)
					{
						cRetVal = CI_SUCCESS;  /*继续遍历检查*/
					}
					else
					{
						cErrStep = 3U;
						cRetVal = CI_ERROR;  /*逻辑区段不具有CBTC区域属性，停止遍历，返回失败*/
					}
				}
				else
				{
					cRetVal = CI_ERROR;
				}

				/*检查保护区段侧防条件是否满足*/
				if (CI_SUCCESS == cRetVal)
				{
					checkResult = OverlapLateralDfnCheck(wOverlapId, &tempDevId, &tempDevSta);

					if (CI_SUCCESS == checkResult)
					{
						cRetVal = CI_SUCCESS;
					}
					else
					{
						cErrStep = 4U;
						cRetVal = CI_ERROR;
					}
				}
				else
				{
					cRetVal = CI_ERROR;
				}

				if (CI_SUCCESS != cRetVal)
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_OVERLAP, wOverlapId, ETYPE_OVERLAP_RES_CHECK_FAIL, cErrStep, sendLevel);  /*记录失败原因*/
				}

				break;
			}
			else
			{
				cRetVal = CI_ERROR;
			}
		}
	}
	else
	{
		cRetVal = CI_ERROR;
	}

	return cRetVal;
}

/*
* 功能描述： 进路VBTC条件下第一逻辑区段检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
*/
UINT8 RouteCbtcFirstLgcSecCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 chRetVal = CI_ERROR;
	UINT8 chFunRet = CI_ERROR;
										 /* 进路内设备数据 */
										 /*信号机*/
	UINT16 startSignalId = 0u;
	UINT16 wOutFirstSecId = 0U;
	UINT8 chOutFirstOccState = 0U;
	UINT16 wInFirstSecId = 0U;
	UINT16 wTrainId = 0U;
	UINT8  chTrainEnterState = 0U;
	UINT8  chTrainInfoSum = 0U;
	UINT8  chReadyEnterRouteTrainSum = 0U;
	UINT16 wszReadyEtRouteTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT8 chLogSecOccupyState = 0U;/*逻辑区段占用状态*/
	LOD_STRU strTrainLod = { 0U }; /*列车位置*/
	LOD_STRU strRouteStartSigLod = { 0U }; /*进路始端信号机位置*/

	if ((NULL != pDevId) && (NULL != pDevState))
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	/* 联锁逻辑检查 */


	/* 进路始端信号机【未跨压】且 非（进路外方区段【空闲】且内方第一逻辑区段【占用】）*/
	if (CI_SUCCESS == chRetVal)
	{
		
		/* 通过检查 CBTC进路在第一逻辑区段有多个列车资源时，不关信号*/
		chFunRet = GetRouteInOutFstLgcTrainInfo(routeId, &chReadyEnterRouteTrainSum, wszReadyEtRouteTrainId);
		startSignalId = GetRouteStartSignalId(routeId);
		wOutFirstSecId = GetSignalOutFirstPhySecId(startSignalId);
		chOutFirstOccState = GetPhySecCurMergeState(wOutFirstSecId);
		wInFirstSecId = GetRouteInFirstLogSecId(routeId);
		devState = GetLogSecCurOccupyState(wInFirstSecId); /*融合占压状态*/
		chLogSecOccupyState = GetLogSecCurCtOrUtOccupyState(wInFirstSecId); /*占压状态融合后的判断CT、UT占压*/
		
		if (CI_SUCCESS == chFunRet)
		{
			if (1U < chReadyEnterRouteTrainSum)
			{
				chRetVal = CI_SUCCESS;
			}
			else if (1U == chReadyEnterRouteTrainSum)
			{
				chTrainEnterState = dsuTrainMinHeadCrossSignal(wszReadyEtRouteTrainId[0], routeId);

				if (TRAIN_ENTER_ROUTE_FULL == chTrainEnterState)
				{
					/*列车完全驶入进路 by cgh 20250102*/
					chRetVal = CI_ERROR;
				}
				else if (TRAIN_ENTER_ROUTE_TAIL == chTrainEnterState)
				{
					strTrainLod.Lnk = GetTrainMinTailLink(wszReadyEtRouteTrainId[0]);
					strTrainLod.Off = GetTrainMinTailOffset(wszReadyEtRouteTrainId[0]);
					strTrainLod.Dir = GetTrainDir(wszReadyEtRouteTrainId[0]);

					strRouteStartSigLod.Lnk = GetSignalProtectLink(startSignalId);
					strRouteStartSigLod.Off = GetSignalProtectLinkOff(startSignalId);
					strRouteStartSigLod.Dir = GetSignalDirection(startSignalId);

					chFunRet = IsPointABSameDir(strTrainLod, strRouteStartSigLod);

					if (FLAG_UNSET == chFunRet)
					{
						/*列车方向和进路始端信号机相反*/
						if (SECTION_OCCUPY_NO == devState)
						{
							/*第一逻辑区段融合状态未占压，不关灯 */
							chRetVal = CI_SUCCESS;
						}
						else
						{
							/*第一逻辑区段融合状态占压 关灯*/
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*列车方向和进路始端信号机相同*/
						chRetVal = CI_ERROR;
					}
				}
				else if (TRAIN_ENTER_ROUTE_HEAD == chTrainEnterState)
				{
					/*列车驶入进路未跨压信号机，不关灯 */
					chRetVal = CI_SUCCESS;
				}
				else if (TRAIN_ENTER_ROUTE_CROSS == chTrainEnterState)
				{
					/*列车跨压信号机，需判断第一逻辑区段占压状态*/

					if (SECTION_OCCUPY_NO == devState)
					{/*第一逻辑区段融合状态未占压，不关灯 */
						chRetVal = CI_SUCCESS;
					}
					else
					{/*第一逻辑区段融合状态占压 关灯*/
						chRetVal = CI_ERROR;
					}

				}
				else if((TRAIN_ENTER_ROUTE_NO == chTrainEnterState)
					|| (CI_ERROR == chTrainEnterState))
				{
					/*列车未上线，或列车未跨压，不关灯*/
					chRetVal = CI_SUCCESS;
				}
				else
				{
					
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				if ((!((SECTION_OCCUPY_YES != chOutFirstOccState) && (SECTION_OCCUPY_NO!=devState))))
				{
					/*不是列车完全驶入进路*/
					if (LOGICSECTION_OCCUPY_UT == chLogSecOccupyState)
					{
						/*CBTC进路判断内方第一逻辑区段有非通信车占压时，关灯 by cgh 20231101*/
						chRetVal = CI_ERROR;
					}
					else
					{
						/* 通过检查 */
						;
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
	
		}
		else
		{
			chRetVal = CI_ERROR;
		}

		if (CI_SUCCESS == chRetVal)
		{
		}
		else
		{
			*pDevId = wInFirstSecId;
			*pDevState = devState;
		}
	}
		
	/* 未检测到侵限条件 */
	return chRetVal;
}



/*
* 功能描述： 折返进路VBTC条件下第一逻辑区段检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
*/
UINT8 RouteCbtcReturnFirstLgcSecCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 侵限区段 */
	UINT16 wLgcSecId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 chRetVal = CI_ERROR;
	UINT8 chFunRet = CI_ERROR;
	/* 进路内设备数据 */
	/*信号机*/
	UINT16 startSignalId = 0u;
	UINT16 wOutFirstSecId = 0U;
	UINT8 chOutFirstOccState = 0U;
	UINT16 wInFirstSecId = 0U;
	UINT16 wTrainId = 0U;
	UINT8  chTrainEnterState = 0U;
	UINT8  chTrainInfoSum = 0U;
	UINT8  chReadyEnterRouteTrainSum = 0U;
	UINT16 wszReadyEtRouteTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT16 wCrossTrainId = 0u;
	UINT8 chGroupRelate = 0u;
	LOD_STRU strTrainLod = { 0U }; /*列车位置*/
	LOD_STRU strRouteStartSigLod = { 0U }; /*进路始端信号机位置*/

	if ((NULL != pDevId) && (NULL != pDevState))
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	/* 联锁逻辑检查 */


	/* 进路始端信号机【未跨压】且 非（进路外方区段【空闲】且内方第一逻辑区段【占用】）*/
	if (CI_SUCCESS == chRetVal)
	{
		startSignalId = GetRouteStartSignalId(routeId);
		wOutFirstSecId = GetSignalOutFirstPhySecId(startSignalId);
		chOutFirstOccState = GetPhySecCurMergeState(wOutFirstSecId);
		wInFirstSecId = GetRouteInFirstLogSecId(routeId);
		devState = GetLogSecCurOccupyState(wInFirstSecId);
		/* 通过检查 CBTC进路在第一逻辑区段有多个列车资源时，不是编组折返的两辆车，关信号*/
		chFunRet = GetRouteInOutFstLgcTrainInfo(routeId, &chReadyEnterRouteTrainSum, wszReadyEtRouteTrainId);
		if (CI_SUCCESS == chFunRet)
		{
			if (2U < chReadyEnterRouteTrainSum)
			{
				/*折返资源数量大于2 ,返回失败*/
				chRetVal = CI_ERROR;
				
			}
			else if (1U == chReadyEnterRouteTrainSum)
			{
				wCrossTrainId = wszReadyEtRouteTrainId[0];
				chRetVal = CI_SUCCESS;
			}
			else if (2U == chReadyEnterRouteTrainSum)
			{
				/*编组折返后车才关信号*/
				chRetVal = isTwoGroupRunTrain(wszReadyEtRouteTrainId[0], wszReadyEtRouteTrainId[1]);
				if (CI_SUCCESS == chRetVal)
				{
					chGroupRelate = GetGroupTrainRelation(wszReadyEtRouteTrainId[0]);
					if (VOBC_CI_GROUP_TAIL == chGroupRelate)
					{
						wCrossTrainId = wszReadyEtRouteTrainId[0];
					}
					else
					{
						wCrossTrainId = wszReadyEtRouteTrainId[1];
					}
				}
				else
				{
					/*不是编组折返车，关信号*/
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				if ((!((SECTION_OCCUPY_YES != chOutFirstOccState) && (SECTION_OCCUPY_NO != devState))))
				{
					/* 通过检查 */
					chRetVal = CI_SUCCESS;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}

			/*跨压之后关信号*/
			if ((CI_SUCCESS == chRetVal)&&(0u != wCrossTrainId))
			{
				chTrainEnterState = dsuTrainMinHeadCrossSignal(wCrossTrainId, routeId);
				if (TRAIN_ENTER_ROUTE_FULL == chTrainEnterState)
				{
					/*折返进路列车完全驶入进路关灯 by cgh 20231215*/
					chRetVal = CI_ERROR;
				}
				else if (TRAIN_ENTER_ROUTE_TAIL == chTrainEnterState)
				{
					strTrainLod.Lnk = GetTrainMinTailLink(wCrossTrainId);
					strTrainLod.Off = GetTrainMinTailOffset(wCrossTrainId);
					strTrainLod.Dir = GetTrainDir(wCrossTrainId);

					strRouteStartSigLod.Lnk = GetSignalProtectLink(startSignalId);
					strRouteStartSigLod.Off = GetSignalProtectLinkOff(startSignalId);
					strRouteStartSigLod.Dir = GetSignalDirection(startSignalId);

					chFunRet = IsPointABSameDir(strTrainLod, strRouteStartSigLod);

					if (FLAG_UNSET == chFunRet)
					{
						/*列车方向和进路始端信号机相反*/
						if (SECTION_OCCUPY_NO == devState)
						{
							/*第一逻辑区段融合状态未占压，不关灯 */
							chRetVal = CI_SUCCESS;
						}
						else
						{
							/*第一逻辑区段融合状态占压 关灯*/
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*列车方向和进路始端信号机相同*/
						chRetVal = CI_ERROR;
					}
				}
				else if (TRAIN_ENTER_ROUTE_HEAD == chTrainEnterState)
				{
					/*列车驶入进路未跨压信号机，不关灯 */
					chRetVal = CI_SUCCESS;
				}
				else if (TRAIN_ENTER_ROUTE_CROSS == chTrainEnterState)
				{
					/*列车跨压信号机，需判断第一逻辑区段占压状态*/

					if (SECTION_OCCUPY_NO == devState)
					{/*第一逻辑区段融合状态未占压，不关灯，等待占压 */
						chRetVal = CI_SUCCESS;
					}
					else
					{/*第一逻辑区段融合状态占压 关灯*/
						chRetVal = CI_ERROR;
					}
				}
				else if ((TRAIN_ENTER_ROUTE_NO == chTrainEnterState) || (CI_ERROR == chTrainEnterState))
				{
					/*列车未上线，或列车未跨压*/
					chRetVal = CI_SUCCESS;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				chRetVal = CI_ERROR;
			}
			
		}
		else 
		{
			chRetVal = CI_ERROR;
		}

		if (CI_SUCCESS == chRetVal)
		{
		}
		else
		{
			*pDevId = wInFirstSecId;
			*pDevState = devState;
		}

	}
	else
	{
		; /*执行失败*/
	}

	
	/* 未检测到侵限条件 */
	return chRetVal;
}

/*
* 功能描述： 进路区段全部采集空闲检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteAllSecColOccuClearCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	if ((NULL == pDevId) || (NULL == pDevState))
	{
		/*入参错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{/* 区段占用检查 */
		if (0u == checkSum) 
		{
			/*区段数据错误*/
			reVal = CI_ERROR;
		}
		else
		{
			/*开始检查*/
			for (i = 0u; i < checkSum; i++)
			{
				devId = dataIdBuf[i].PhysicalSectionId;
				devState =GetPhySecCurOccupyState(devId);

				if (SECTION_OCCUPY_NO == devState)
				{
					/* 通过检查*/
				}
				else
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
					break;
				}
			}
		}
		
	}
	else
	{
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路区段全部采集空闲检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteFaultOccuCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
	UINT16 wOutFirstPhySecId = 0U;
	UINT8 chTrainNum = 0U;
	UINT16 szTrianId[TRAIN_SUM_MAX] = { 0U };
	UINT16 wTrainId = 0U;
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 chFuncRet = CI_ERROR;
	UINT8 chAllClearFlag = CI_ERROR;

	if ((NULL == pDevId) || (NULL == pDevState))
	{
		/*入参错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{/* 区段占用检查 */
		if (0u == checkSum) 
		{
			/*区段数据错误*/
			reVal = CI_ERROR;
		}
		else
		{
			/*开始检查*/
			for (i = 0u; i < checkSum; i++)
			{
				devId = dataIdBuf[i].PhysicalSectionId;
				devState = IsPhyFree(devId);
				chTrainNum = ToaGetPhyUtNum(devId);
				chFuncRet = ToaGetPhyUtId(devId,szTrianId);
				if (CI_SUCCESS == devState)
				{
					chAllClearFlag = CI_SUCCESS;/* 通过检查*/
				}
				else
				{
					if (CI_SUCCESS == chFuncRet)
					{
						/*区段只存在一个故障车*/
						if (1U == chTrainNum)
						{
							
							if (0U == wTrainId)
							{
								/*当前记录故障车ID为0*/
								wTrainId = szTrianId[0];
							}
							else if((szTrianId[0]== wTrainId)&&(255U!=wTrainId))
							{
								/*进路内方仅一个故障车*/
							}
							else
							{
								
								reVal = CI_ERROR;
							}
						}
						else
						{
							
							reVal = CI_ERROR;
						}
					}
					else
					{/*状态不一致返回故障状态*/
						
						reVal = CI_ERROR;
					}

				}

				if ((CI_SUCCESS == chAllClearFlag)&&(0U!=chTrainNum))
				{
					reVal = CI_ERROR;
				}

				if (CI_ERROR == reVal)
				{
					*pDevId = devId;
					*pDevState = devState;
					break;
				}
			}
		}
	}

	if (CI_SUCCESS == reVal)
	{
		if (1U == chTrainNum)
		{
			devId = GetSignalOutFirstPhySecId(GetRouteStartSignalId(routeId));
			devState = IsPhyFree(devId);
			chTrainNum = ToaGetPhyUtNum(devId);
			chFuncRet = ToaGetPhyUtId(devId, szTrianId);
			if ((TRAIN_SUM_MAX > chTrainNum)
				&& (CI_SUCCESS == chFuncRet)
				&& (CI_ERROR == devState))
			{
				for (i = 0u; i < chTrainNum; i++)
				{
					if ((szTrianId[i] == wTrainId))
					{
						break;
					}
				}

				if (i == chTrainNum)
				{
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}
		}
		else
		{
			/*无故障车 且全空闲*/
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路内限速状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteAllLgcSecXianSuCheck(UINT16 const routeId,UINT16 *pDevId, UINT8 *pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT8 j = 0U;
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 secDirction = 0u;
	UINT8 chRouteXianSuCfmState = 0U;
	/*进路数据*/
	/* 进路区段*/
	UINT16 const routeSectionSum = GetRouteLogSectionSum(routeId);
	UINT16* const pRouteSectionDataBuf = GetRouteLogSectionIdBuf(routeId);
	UINT16 const overlapId = GetRouteOverlapLockedId(routeId);
	UINT8 const routeOvlapSectionSum =GetOverlapLogicSectionSum (overlapId);
	UINT16* const pRouteOvlapSectionDataBuf =GetOverlapLogicSectionBuf (overlapId);
	UINT8 wRouteRelSwitchNum = 0U;  /*进路关联的道岔数量*/
	RouteSwitchStruct* pRouteRelSwitchStr = NULL;  /*进路关联的道岔结构体*/
	UINT16 wRouteRelSwitchId = 0U;  /*进路关联的道岔ID*/
	UINT8 wOvlpRelSwitchNum = 0U;  /*保护区段关联的道岔数量*/
	OverlapConditionSwitchStruct* pOvlpRelSwitchStr = NULL;  /*保护区段关联的道岔结构体*/
	UINT16 wOvlpRelSwitchId = 0U;  /*保护区段关联的道岔ID*/
	UINT8 reVal = CI_ERROR;

	/* 数据检查 */
	if ((MAX_ROUTE_IN_LT_NUM <= routeSectionSum) 
		|| (NULL == pRouteSectionDataBuf)
		||(OVLP_LOGICSECTION_SUM_MAX <= routeOvlapSectionSum)
		|| ((0U!=routeOvlapSectionSum)
			&&(NULL==pRouteOvlapSectionDataBuf)))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		chRouteXianSuCfmState =GetRouteXiansuConfirmStt (routeId);
		if (ROUTE_XIANSU_CONFIRM_YES == chRouteXianSuCfmState)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			for (i = 0u; i < routeSectionSum; i++)
			{
				devId = pRouteSectionDataBuf[i];
				devState = GetLogSecLinShiXianSuSetState(devId);
				/*开始检查*/
				/* 需检查本区段 */
				if ((LOGSEC_LSXS_SET_STATE_NO == devState)
					|| (LOGSEC_LSXS_SET_STATE_INVALID == devState))
				{
					reVal = CI_SUCCESS;

				}
				else
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

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

			/*进路内道岔关联的逻辑区段临时限速状态检查*/
			wRouteRelSwitchNum = GetRouteSwitchSum(routeId);
			pRouteRelSwitchStr = GetRouteSwitchData(routeId);
			if ((CI_SUCCESS == reVal) && (0U != wRouteRelSwitchNum) && (ROUTE_SWITCH_SUM_MAX > wRouteRelSwitchNum) && (NULL != pRouteRelSwitchStr))
			{
				for (j = 0U; j < wRouteRelSwitchNum; j++)
				{
					devId = 0U;
					devState = 0U;
					wRouteRelSwitchId = pRouteRelSwitchStr[j].SwitchId;
					reVal = SwitchRelLogSecLSXSStateCheck(wRouteRelSwitchId, &devId, &devState);

					if (CI_ERROR == reVal)
					{
						/*存在逻辑区段设置有临时限速，返回失败*/
						*pDevId = devId;
						*pDevState = devState;
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				/*继续检查*/
			}

			if (CI_SUCCESS == reVal)
			{
				for (i = 0u; i < routeOvlapSectionSum; i++)
				{
					devId = pRouteOvlapSectionDataBuf[i];
					devState = GetLogSecLinShiXianSuSetState(devId);
					/*开始检查*/
					/* 需检查本区段 */
					if ((LOGSEC_LSXS_SET_STATE_NO == devState)
						|| (LOGSEC_LSXS_SET_STATE_INVALID == devState))
					{
						reVal = CI_SUCCESS;

					}
					else
					{
						/*状态不一致返回故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}

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

			/*保护区段内道岔关联的逻辑区段临时限速状态检查*/
			wOvlpRelSwitchNum = GetOverlapSwitchSum(overlapId);
			pOvlpRelSwitchStr = GetOverlapCondSwitchStruct(overlapId);
			if ((CI_SUCCESS == reVal) && (0U != wOvlpRelSwitchNum) && (OVERLAP_CONDISWIT_SUM_MAX > wOvlpRelSwitchNum) && (NULL != pOvlpRelSwitchStr))
			{
				for (j = 0U; j < wOvlpRelSwitchNum; j++)
				{
					devId = 0U;
					devState = 0U;
					wOvlpRelSwitchId = pOvlpRelSwitchStr[j].SwitchId;
					reVal = SwitchRelLogSecLSXSStateCheck(wOvlpRelSwitchId, &devId, &devState);

					if (CI_ERROR == reVal)
					{
						/*存在逻辑区段设置有临时限速，返回失败*/
						*pDevId = devId;
						*pDevState = devState;
						break;
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				/*继续检查*/
			}
		}
	}

	return reVal;

}

/*
* 功能描述： Overlap区段空闲检查
* 参数说明： UINT16 const overlapId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OpenBlockOvlpAllSecOccuClrCheck(UINT16 const overlapId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* overlap区段 */
	UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
	UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_SUCCESS;
	UINT8 chSwitch = 0u;
	UINT16 wRouteId = 0u;
	UINT16 wFirstPhyId = 0u;
	UINT8 chPTrainNum = 0u;
	UINT16 szPTrainId[MAX_AC_IN_TRAIN];
	UINT8 chFTrainNum = 0u;
	UINT16 szFTrainId[MAX_AC_IN_TRAIN];
	UINT8 chOccState = SECTION_OCCUPY_YES;

	chSwitch = GetCiFunctionSwitchConfig(FUNC_TOA_SWITCH);

	/* 区段占用检查 */
	/*联锁检查*/
	if (0u == checkSum) 
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecCurMergeState(devId);
			if (SECTION_OCCUPY_NO==devState)
			{
				/* 通过检查*/
				
			}
			else
			{
				if (FUNC_SWITCH_ON == chSwitch)
				{
					chOccState = GetPhySecCurOccupyState(devId);
					wRouteId = GetPhySecPLockBelongRouteId(devId);
					wFirstPhyId = GetRouteFirstPhySectionId(wRouteId);
					chFTrainNum = ToaGetPhyTrain(wFirstPhyId, szFTrainId);
					chPTrainNum = ToaGetPhyTrain(devId, szPTrainId);
					if ((1u == chFTrainNum) && (1u == chPTrainNum) && (szPTrainId[0] == szFTrainId[0]) && (SECTION_OCCUPY_NO == chOccState))
					{
						;
					}
					else
					{
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
						break;
					}
				}
				else
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
					break;
				}
			}
		}
	}

	/*全部通过检查*/
	return reVal;

}

/*
* 功能描述： 保持信号开放时进路区段空闲检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
*/
UINT8 KeepCbtcReturnRouteSecOccCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT16 devId = 0u;
	UINT8 devState = 0u;
	UINT8 checkResult = CI_ERROR;
	UINT8 reResult = CI_ERROR;
	UINT16 wRouteFirstPhySecId = 0u;	/*进路第一物理区段*/
	UINT8 chTrainEnterState = CI_ERROR; /*列车驶入进路状态*/
	UINT8 axisSecSum = 0u;
	UINT16* pAxisSecIdBuf = NULL;
	UINT8 logSectionSum = 0u;
	UINT16* logIdBuf = NULL;
	UINT8 cLogSecLinkSum = 0u;	/*逻辑区段包含Link数量*/
	UINT16* cLogSecLinkBuf = NULL;
	UINT8 logCurOccupyState = 0u;		/*逻辑区段占用状态*/
	UINT8 cRouteDir = 0U;				/*进路方向*/
	UINT8 cLinkLogicDir = 0U;			/*逻辑方向*/
	UINT16 wLogId = 0u;
	UINT8 i = 0u;
	UINT8 j = 0u;
	UINT8 index = 0u;
	TRAIN_SEQUANCE_s tmpTrainInfo = { 0u };
	UINT8 chTrainNum = 0U;
	UINT16 wRouteTrainId = 0U;
	UINT8 SetLogicErrorFlag = 0U;
	UINT8 ChangeDirFlag = 0U;			/*改方向标志*/
	checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);

	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		wRouteFirstPhySecId = GetRouteFirstPhySectionId(routeId);
		chTrainEnterState = GetTrainEnteringRouteState(routeId);
		if ((devId == wRouteFirstPhySecId) && (CI_SUCCESS == chTrainEnterState))
		{
			checkResult = RouteCbtcReturnFirstLgcSecCheck(routeId, &devId, &devState);
			/*CBTC折返进路列车正驶入时跨压信息未到,此时不关信号*/
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				SetLogicErrorFlag = 1U;
				
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);

#if 0
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, wRouteFirstPhySecId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
#endif
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			/*如果是编组前车占压则不关信号*/
			axisSecSum = GetPAxisSectionSum(devId);
			pAxisSecIdBuf = GetPAxisSectionIdBuf(devId);

			if ((NULL != pAxisSecIdBuf)
				&&(PHYSICAL_INCLUDE_AXIS_SUM_MAX>axisSecSum))
			{
				for (i = 0u; i < axisSecSum; i++)
				{
					logSectionSum = GetAxisSecLogSectionSum(pAxisSecIdBuf[i]);
					logIdBuf = GetAxisSecLogSectionIdBuf(pAxisSecIdBuf[i]);
					if ((NULL != logIdBuf)
						&&(AXIS_INCLUDE_LOG_SUM_MAX>logSectionSum))
					{
						for (j = 0u; j < logSectionSum; j++)
						{
							wLogId = logIdBuf[j];
							logCurOccupyState = GetLogSecCurCtOrUtOccupyState(wLogId);
							if (LOGICSECTION_OCCUPY_CT == logCurOccupyState)
							{
								checkResult = IsLogicHaveNoSupicTrain(wLogId);
								if (CI_SUCCESS == checkResult)
								{
									/*CT占压且不存在隐藏车*/
									break;
								}
								else
								{
									/* 不处理*/
								}
							}
							else 
							{
								/* 继续遍历*/
							}

						}

						if (j != logSectionSum)
						{
							break;
						}
						else
						{
							/* 继续遍历*/
						}
					}
					else
					{
						/* 数据出错*/
					}
				}

				if (i != axisSecSum)
				{
					cRouteDir = GetRouteDirection(routeId);
					cLinkLogicDir = ConvertDirectionToLogic(cRouteDir);		/*转运营方向为逻辑方向*/
					ChangeDirFlag = GetLogSecLockDirOpposedFlag(wLogId);
					if (CI_SUCCESS == ChangeDirFlag)	/*方向需要取反*/
					{
						cLinkLogicDir = ConvertTrainDir(cLinkLogicDir);
					}
					else
					{
						;	/*方向无需取反*/
					}
					cLogSecLinkSum = GetSecIntrudeLinkSum(wLogId);
					cLogSecLinkBuf = GetSecIntrudeLinkIdBuf(wLogId);
					if ((NULL != cLogSecLinkBuf)&&
						(LOGSEC_INCLUDE_LINK_SUM_MAX > cLogSecLinkSum))
					{/*逻辑区段占压的第一辆车*/
						for (index = 0u; index < cLogSecLinkSum; index++)
						{
							if (DIR_SAME == cLinkLogicDir)
							{
								chTrainNum = as_GetLinkTrainNum(cLogSecLinkBuf[index]);
								tmpTrainInfo = as_GetLinkFirstTrain(cLogSecLinkBuf[index]);
							}
							else
							{
								chTrainNum = as_GetLinkTrainNum(cLogSecLinkBuf[index]);
								tmpTrainInfo = as_GetLinkLastTrain(cLogSecLinkBuf[index]);
							}

							if (0u != chTrainNum)
							{
								wRouteTrainId = tmpTrainInfo.u16TrainID;
								break;
							}
						}

						/*逻辑区段CT占压是否为编组前车*/
						checkResult = isGroupHeadTrain(wRouteTrainId);

						if (CI_SUCCESS == checkResult)
						{
							reResult = CI_SUCCESS;/*编组前车占压，不关信号*/
						}
						else
						{
							reResult = CI_ERROR;/*不是编组前车占压*/
						}
					}
					else
					{
						reResult = CI_ERROR;
					}
				}
				else
				{
					reResult = CI_ERROR;/*不是CT占压或存在前后筛可疑的CT占压*/
				}
			}
			else
			{	
				reResult = CI_ERROR;/*数据出错*/
			}
			
			
			
		}

	}

	if (CI_SUCCESS == reResult)
	{
		/* 不关信号*/
	}
	else
	{
		if (0U == SetLogicErrorFlag)
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
		}
		else
		{
			/*当记录逻辑区段故障码后，不再记录物理区段故障码*/
		}
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	return reResult;
}

/*
* 功能描述： CBTC进路，检查列车驶入条件(仅在CBTC下使用)
* 参数说明：
*            UINT16 const routeId,    进路号
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过 最后一个列车准备驶入进路导致进路关信号
*/
UINT8 RouteCbtcTiranEnterCheck(UINT16 const routeId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 chFunRet = CI_ERROR;
	UINT8  chTrainEnterState = 0U;
	UINT8  chReadyEnterRouteTrainSum = 0U;
	UINT16 wszReadyEtRouteTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT16 wCrossTrainId = 0u;
	UINT16 wInFirstSecId = 0U;/*进路内方第一区段*/
	UINT8 chLogSecCurOccupySta = 0U;/*逻辑区段融合占用状态*/
	UINT16 wStartSignalId = 0U;/*始端信号机ID*/
	UINT16 wOutFirstPhySecId = 0U;/*外方第一物理区段ID*/
	UINT8 chOutFirstPhyOccState = 0U;/*外方第一物理区段融合占用状态*/

	/* 通过检查 CBTC进路在第一逻辑区段有多个列车资源时，不是编组折返的两辆车，关信号*/
	chFunRet = GetRouteInOutFstLgcTrainInfo(routeId, &chReadyEnterRouteTrainSum, wszReadyEtRouteTrainId);
	if (CI_SUCCESS == chFunRet)
	{
		if (1U < chReadyEnterRouteTrainSum)
		{
			/*资源数量大于1,返回失败*/
			chRetVal = CI_ERROR;
		}
		else if (1U == chReadyEnterRouteTrainSum)
		{
			wCrossTrainId = wszReadyEtRouteTrainId[0];
			chRetVal = CI_SUCCESS;
		}
#if 0
		/*删除编组折返内容，不具备编组车*/
		else if (2U == chReadyEnterRouteTrainSum)
		{
			if (CI_TYPE_CLD == chLocalCiType)
			{
				/*车辆段资源数量大于1 ,返回失败*/
				chRetVal = CI_ERROR;
			}
			else
			{
				chRouteType = GetRouteType(routeId);
				/*编组折返后车才关信号*/
				chRetVal = isTwoGroupRunTrain(wszReadyEtRouteTrainId[0], wszReadyEtRouteTrainId[1]);
				if ((CI_SUCCESS == chRetVal)
					&& (ROUTE_TYPE_RETURN == chRouteType))
				{
					chGroupRelate = GetGroupTrainRelation(wszReadyEtRouteTrainId[0]);
					if (VOBC_CI_GROUP_TAIL == chGroupRelate)
					{
						wCrossTrainId = wszReadyEtRouteTrainId[0];
					}
					else
					{
						wCrossTrainId = wszReadyEtRouteTrainId[1];
					}
				}
				else
				{
					/*不是编组折返车，关信号*/
					chRetVal = CI_ERROR;
				}
			}
		}
#endif
		else
		{
			chRetVal = CI_ERROR;
		}

		/*跨压之后关信号*/
		if ((CI_SUCCESS == chRetVal) && (0u != wCrossTrainId))
		{
			wInFirstSecId = GetRouteInFirstLogSecId(routeId);
			chLogSecCurOccupySta = GetLogSecCurOccupyState(wInFirstSecId);
			chTrainEnterState = dsuTrainMinHeadCrossSignal(wCrossTrainId, routeId);

			wStartSignalId = GetRouteStartSignalId(routeId);
			wOutFirstPhySecId = GetSignalOutFirstPhySecId(wStartSignalId);
			chOutFirstPhyOccState = GetPhySecCurMergeState(wOutFirstPhySecId);

			/*列车跨压信号机*/
			if (TRAIN_ENTER_ROUTE_CROSS == chTrainEnterState)
			{
				if (SECTION_OCCUPY_NO == chOutFirstPhyOccState)
				{
					/*短车高速跨压但是外方第一区段已经空闲，此时异常关灯*/
					chRetVal = CI_ERROR;
				}
				else
				{
					if (SECTION_OCCUPY_NO != chLogSecCurOccupySta)
					{
						; /*列车跨压信号机且第一逻辑区段占压，接近锁闭正常 by cgh 20231129*/
					}
					else
					{
						/*列车跨压信号机且第一逻辑区段空闲，接近锁闭异常 by cgh 20231129*/
						chRetVal = CI_ERROR;
					}
				}
			}
			else if ((TRAIN_ENTER_ROUTE_FULL == chTrainEnterState) || (TRAIN_ENTER_ROUTE_TAIL == chTrainEnterState))
			{
				if (SECTION_OCCUPY_NO != chLogSecCurOccupySta)
				{
					; /*短车高速列车完全在进路或者车头驶出第一逻辑区段占压，接近锁闭正常*/
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				chRetVal = CI_ERROR;
			}			
		}
		else
		{
			chRetVal = CI_ERROR;
		}

	}
	else
	{
		chRetVal = CI_ERROR;
	}

	if (CI_SUCCESS == chRetVal)
	{
		; /* DO NOTHING*/
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	/* 未检测到侵限条件 */
	return chRetVal;
}

/*
* 功能描述： 进路区段全部侧防条件满足检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteAllLtrlDfncSwitchCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf =GetRouteLogSectionIdBuf (routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 区段占用检查 */
	if (0u == checkSum)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			reVal = LogicSecSwitchLtrlDfncCheck(devId,pDevId, pDevState);
			if (CI_SUCCESS == reVal)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态,使用LogicSecSwitchLtrlDfncCheck里的故障记录*/
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 进路区段全部联络线设备条件满足检查
* 参数说明： UINT16 routeId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteContactLineDevSwitchCheck(UINT16 const routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT16 LogSectionSum = 0U;
	UINT16 ii = 0U;
	UINT16 *pLogicSecId = NULL;

	/*逻辑区段联络线道岔条件满足*/
	LogSectionSum = GetRouteLogSectionSum(routeId);
	pLogicSecId = GetRouteLogSectionIdBuf(routeId);
	if (0u == LogSectionSum)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (ii = 0U; ii < LogSectionSum; ii++)
		{
			reVal = LogicContactLineDevCheck(pLogicSecId[ii], functionId, sendLevel);
			if (reVal == CI_SUCCESS)
			{
				;		/*通过检查*/
			}
			else
			{
				reVal = CI_ERROR;
				break;
			}
		}
	}
	return reVal;
}
/*
* 功能描述： ats锁闭保护区段占用检查
* 参数说明： UINT16 const overlapId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 AtsLockOverlapSecOccupyCheck(UINT16 const overlapId,UINT16 *pDevId,UINT8 *pDevState)
{
	/* overlap区段 */
	UINT8 const checkSum = GetOverlapPhySecSum(overlapId);
	UINT16* const dataIdBuf = GetOverlapPhySecIdBuf(overlapId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	UINT8 includeSwitchSum = 0u;
	OverlapConditionSwitchStruct* pincludeSwitchBuff = NULL;
	UINT8 phySecType = 0u;
	UINT8 j = 0u;
	UINT8 SwitchPos = 0u;
	UINT16 phyID = 0u;

	/*获取道岔信息*/
	includeSwitchSum = GetOverlapSwitchSum(overlapId);
	pincludeSwitchBuff = GetOverlapCondSwitchStruct(overlapId);

	if((0U == checkSum) || (NULL == dataIdBuf)||(NULL == pincludeSwitchBuff)||(0u == overlapId)||(NULL==pDevId))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	if(CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
		    reVal = CI_ERROR;
			devId = dataIdBuf[i];
			devState = GetPhySecCurMergeState(devId);
			if (devState == SECTION_OCCUPY_NO)
			{
				/* 通过检查*/
				reVal = CI_SUCCESS;
			}
			else
			{
				phySecType = GetPhySecType(devId);
				if (PHYSICAL_SEC_TYPE_NOSWITCH == phySecType)
				{
					/* 通过检查*/
					reVal = CI_SUCCESS;
				}
				else
				{
					for(j=0u;j<includeSwitchSum;j++)
					{
					    phyID = GetSwitchPhySectionId(pincludeSwitchBuff[j].SwitchId);
					    if(phyID == devId)
						{
						    SwitchPos = GetSwitchCurPosition(pincludeSwitchBuff[j].SwitchId);
						    if(SwitchPos == pincludeSwitchBuff[j].SwitchPosition)
							{
								 /* 通过检查*/
								  reVal = CI_SUCCESS;
							}
							else
							{
								  reVal = CI_ERROR;
								  break;
							}
						}
					}


					if(CI_SUCCESS !=  reVal)
					{
						/*状态不一致返回故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						break;
					}
				}	
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 检查指定进路外方逻辑区段状态
* 参数说明： const UINT16 signalId, 信号机ID    
*           UINT16 *logicSecId 输出逻辑区段ID
* 返回值  ：0：获取失败
           >0:占用状态：CT占用orUT占用or空闲   
*/
UINT8 CheckRouteIdOutFirstLogSecState(const UINT16 routeId,UINT16 *logicSecId)
{
	UINT16 bufIndex = 0;  /*数组下标*/

	UINT8 retVal = CI_ERROR;
	UINT8 signalDirection = 0u;
	UINT16 signalOutFirstPhySecId = 0u;
	UINT16 * pAxisSectionIdBuf =NULL;
	UINT8 axisSectionSum = 0u;
	UINT8 i=0u;
	UINT8 PhySecType = 0u;
	UINT16* pLogSectionIdBuf =NULL;
	UINT8 logSectionSum = 0u;
	UINT8 startSigisEndSigRouteSum = 0u;
	UINT16 *pStartSigisEndSigRouteIdBuf = NULL;
	UINT16 routeStartSignalId = 0u;
	UINT16 routeInLastLogSecId = 0u;

	if((0u < routeId)&&(NULL != logicSecId))
	{
	     *logicSecId = 0u;
		retVal = CI_SUCCESS;
	}
	else
	{
		retVal = CI_ERROR;
	}

	if(CI_SUCCESS == retVal)
	{
	     startSigisEndSigRouteSum = GetRouteStartSigisEndRouteSum(routeId);
		 pStartSigisEndSigRouteIdBuf = GetRouteStartSigisEndRouteBuf(routeId);
		 if(NULL == pStartSigisEndSigRouteIdBuf)
		 {
			retVal = CI_ERROR;
		 }
	}

	if(CI_SUCCESS == retVal)
	{
		if(0U == startSigisEndSigRouteSum)
		{/*以信号机防护方向查找逻辑区段*/
			routeStartSignalId = GetRouteStartSignalId(routeId);
			signalDirection = GetSignalDirection(routeStartSignalId);
			signalOutFirstPhySecId =  GetSignalOutFirstPhySecId(routeStartSignalId);

			if(0u < signalOutFirstPhySecId)
			{
				pAxisSectionIdBuf= GetPAxisSectionIdBuf(signalOutFirstPhySecId);
				axisSectionSum = GetPAxisSectionSum(signalOutFirstPhySecId);
			}
			else
			{
				retVal = CI_ERROR;
			}

			if(CI_SUCCESS == retVal)
			{
				if((NULL ==pAxisSectionIdBuf)||(0u == axisSectionSum))
				{
					retVal = CI_ERROR;
				}
			}

			if(CI_SUCCESS == retVal)
			{
				retVal = CI_ERROR;
				PhySecType = GetPhySecType(signalOutFirstPhySecId);
				if(PHYSICAL_SEC_TYPE_NOSWITCH ==PhySecType)
				{
					pLogSectionIdBuf = GetAxisSecLogSectionIdBuf(pAxisSectionIdBuf[0]);
					logSectionSum = GetAxisSecLogSectionSum(pAxisSectionIdBuf[0]);
					if((NULL != pLogSectionIdBuf)&&(0u < logSectionSum))
					{
						if(LINK_DIRECTION == signalDirection)
						{
							retVal = GetLogSecCurCtOrUtOccupyState(pLogSectionIdBuf[0]);
							*logicSecId = pLogSectionIdBuf[0];/*输出逻辑区段ID*/
						}
						else if(NOT_LINK_DIRECTION == signalDirection)
						{
							retVal = GetLogSecCurCtOrUtOccupyState(pLogSectionIdBuf[logSectionSum-1U]);
							*logicSecId =pLogSectionIdBuf[logSectionSum-1U];/*输出逻辑区段ID*/
						}
						else
						{
							retVal = CI_ERROR;/*返回错误*/
						}
					}
				}
				else
				{  
					retVal = CI_ERROR;/*返回错误*/
				}
			}
		}
		else
		{/*以进路方向查找逻辑区段*/
			for(i=0u;i<startSigisEndSigRouteSum;i++)
			{
			    routeInLastLogSecId =  GetRouteInLastLogSecId(pStartSigisEndSigRouteIdBuf[i]);
				retVal = GetLogSecCurCtOrUtOccupyState(routeInLastLogSecId);
				if((LOGICSECTION_OCCUPY_CT == retVal)||(LOGICSECTION_OCCUPY_UT == retVal))
				{   
				     break;
				}
			}
			*logicSecId = routeInLastLogSecId;	/*记录当前区段ID*/
		}
	}


	return retVal;
}


#if 0
/*
* @func： 逻辑区段处于保护锁闭时主进路检查
* @param： UINT16 wLgcSecId, 逻辑区段ID

* @return CI_ERROR   不可用
*		  CI_SUCCESS 可用
*/
UINT8 OverlapLgcResMainRtCheck(UINT16 wLgcSecId)
{
	/*变量初始化*/
	UINT8 ii = 0u;           /* 循环变量 */
	UINT16 wRouteLastLogSecId = 0u;
	UINT16 belongRouteId = 0u;
	UINT8  chLogResTrainSum = 0u;
	UINT16 wLgcSecResTrainId = 0U;
	LogicTrainResStruct * pstLogicResTrainInfo = NULL;
	UINT8 chRouteState = 0U;
	UINT8 chRetVal = CI_ERROR;

	belongRouteId =GetLogSecPLockRouteId(wLgcSecId);
	wRouteLastLogSecId = GetRouteInLastLogSecId(belongRouteId);
	chRouteState = GetRouteState(belongRouteId);
	if (CI_ERROR != wRouteLastLogSecId)
	{
		if (ROUTE_STATE_IDLE != belongRouteId)
		{
			chRetVal = LgcHaveUseableRes(wRouteLastLogSecId);
		}
		else
		{
			chRetVal = CI_SUCCESS;
		}
	}
	else
	{
		chRetVal = CI_ERROR; /*不可能分支 ，进这个检查必须有防护锁闭所属进路*/
	}
	
#if 0 
	if (CI_SUCCESS == chRetVal)
	{
		belongRouteId = GetLogSecLockBelongRoute(wLgcSecId);
		wRouteLastLogSecId = GetRouteInLastLogSecId(belongRouteId);
		if (CI_ERROR != wRouteLastLogSecId)
		{
			chRetVal = LgcHaveUseableRes(wRouteLastLogSecId);
		}
		else
		{
			; /*不处理，如果无锁闭所属进路 不做处理*/
		}
	}
#endif

	return (chRetVal);
}

#endif
/*
* 功能描述： 检查是否是列车真正跨压
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS:未跨压
			 CI_ERROR:跨压
*cgh-合并CID-2341-5：
*/
UINT8 CheckEngineerVehicleNear(const UINT16 routeId)
{
	UINT8 rtVal = CI_ERROR;
	UINT16 startSignalId = 0u;
	UINT8 EngineerVehicleNearSta = 0u;
	UINT16 routeFirstPhySectionId = 0u;
	UINT8 inSecCurOccupyState = 0u;
	UINT8 signalCrossState = 0u;

	startSignalId = GetRouteStartSignalId(routeId);
	signalCrossState = GetSignalCrossState(startSignalId);
	EngineerVehicleNearSta = GetSigEngineerVehicleNearSte(startSignalId);

	routeFirstPhySectionId = GetRouteFirstPhySectionId(routeId);
	inSecCurOccupyState = GetPhySecCurMergeState(routeFirstPhySectionId);
	/*CI收到了ZC发送的车接近时，收到了ZC发送的跨压后，在采集到内方区段空闲时，才进行信号保持,等占压到来*/
	if (SIGNAL_CROSS_STATE_YES == signalCrossState)
	{
		if (SECTION_OCCUPY_NO == inSecCurOccupyState)/*进路第一区段空闲*/
		{
			rtVal = CI_SUCCESS;
			SetSigVobcCrossInPhyOccSta(startSignalId, SECTION_OCCUPY_NO);
		}
		else
		{
			if (SIG_ENGINEERVEHICNEAR_STE_YES == EngineerVehicleNearSta)
			{
				SetEnginVehicCroCloBelongRoute(startSignalId, routeId);
				SetSigEnginVehicCrossCloseSte(startSignalId, ENGIN_VEHIC_CROSSCLOSE_STE_YES);
			}
			else
			{
				;	/*不处理*/
			}
			SetSigVobcCrossInPhyOccSta(startSignalId, SECTION_OCCUPY_YES);
			rtVal = CI_ERROR;
		}
	}
	else
	{
		rtVal = CI_ERROR;
	}
	return rtVal;
}
/*
* 功能描述： 根据物理区段封锁类型设置errorcode
* 参数说明： const UINT16 phySectionId, 物理区段ID
*            const UINT8 functionId  函数ID
*            const UINT8 sendLevel 发送级别
*            const UINT8 cDevState 设备状态
* 返回值：无
* add by pfq 2022.04.21
*/
void AccToPhySecFlockTypeSetErrcode(const UINT16 phySectionId, const UINT8 functionId, const UINT8 sendLevel, const UINT8 devState)
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 spksId = 0u;            /*当保护区段内的物理区段是spks封锁时，报警显示spks落下*/
	UINT8 spksState = 0u;          /*spks状态*/
	UINT8 PhySecFlockType = 0u;   /*物理区段的封锁类型*/

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		PhySecFlockType = GetPhySecFLockType(phySectionId);
		if (PHY_SEC_FLOCK_TYPE_CMD == PhySecFlockType)
		{
			/*物理区段是ATS的命令封锁类型则报警对应物理区段*/
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySectionId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		}
		else if (PHY_SEC_FLOCK_TYPE_SPKS == PhySecFlockType)
		{/*物理区段是spks落下造成的封锁，则报警spks按下*/
			checkResult = CheckPhysecFlockReasonSpksId(phySectionId, &spksId, &spksState);/*获取物理区段封锁是由于那个spks落下导致的*/
			if (CI_SUCCESS == checkResult)
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SPKS, spksId, ETYPE_SPKS_STATE_UP, spksState, sendLevel);
			}
		}
		else  if (PHY_SEC_FLOCK_TYPE_SPKSCMD == PhySecFlockType)
		{
			/*物理区段是spks落下且设置封锁，则报警两次一次报spks，一次报物理区段封锁
			将设备状态类型特殊设置，在设置错误码的时候设置两次*/
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, phySectionId, ETYPE_PS_FLOCK_SPKSCMD_STATE, devState, sendLevel);
		}
		else
		{
			/*不做处理*/
		}
	}
}
/*
* 功能描述： CBTC进路信号保持其他信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 KeepCBTCRouteOtherSignalCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/
	UINT8 needOpenSigSum = 0U;
	UINT16* pNeedOpenBuf = NULL;
	UINT8 oneOpenSigSum = 0U;
	UINT16* pOneOpenBuf = NULL;
	UINT8 needCloseSigSum = 0U;
	UINT16* pNeedCloseBuf = NULL;
	UINT8 zheFanRouteSum = 0U;
	UINT16 * zheFanRouteIdBuf = NULL;
	UINT16  startSignalId = GetRouteStartSignalId(routeId);/*始端信号机id*/
	/* 进路内设备数据 */            
	/*进路相关需开放信号机*/
	needOpenSigSum = GetRouteCbtcNeedOpenSigSum(routeId);
	pNeedOpenBuf = GetRouteCbtcNeedOpenSigIdBuf(routeId);
	/*进路相关不能同时开放信号机*/
	oneOpenSigSum = GetRouteOnlyOneOpenSigSum(routeId);
	pOneOpenBuf = GetRouteOnlyOneOpenSigIdBuf(routeId);    
	/*进路相关需关闭信号机*/
	needCloseSigSum = GetRouteOpenNeedCloseSigSum(routeId);
	pNeedCloseBuf = GetRouteOpenNeedCloseSigIdBuf(routeId); 

	/*进路开放信号机需检查相关折返进路*/
	zheFanRouteSum = GetRtnEndSigAsStartSigRouteSum(routeId);
	zheFanRouteIdBuf = GetReturnEndSigAsStartSigRoute(routeId); 


	/* 联锁逻辑检查 */  

	/*进路相关需开放信号机已开放*/
	devId = 0u;
	devState = 0u;
	checkResult = SignalBufOpenCloseStateCheck(pNeedOpenBuf,needOpenSigSum,SIGNAL_OPEN,&devId,&devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_NEED_OPEN_STATE,devState,sendLevel); 
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关不能同时开放信号机未开放*/
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pOneOpenBuf,oneOpenSigSum,SIGNAL_CLOSE,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ONE_OPEN_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路相关需关闭信号机已关闭 */
		devId = 0u;
		devState = 0u;
		checkResult = SignalBufOpenCloseStateCheck(pNeedCloseBuf,needCloseSigSum,SIGNAL_CLOSE,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_NEED_CLOSE_STATE,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*以始端信号机作为终端信号机的折返进路是否已经办理成功检查*/
		devId = 0u;
		devState = 0u;
		checkResult = RtnEndSigAsStartSigRouteCheck(zheFanRouteIdBuf,zheFanRouteSum,&devId,&devState);
		if(CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;		
		}
		else
		{
			/* 记录故障码 */
			/*原报警ETYPE_SIG_RETURN_OPENED_STATE 出现因进路id顺序出现报警不一致 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_START_OPEN_STATE, SIGNAL_CLOSE, sendLevel);
			reResult = CI_ERROR;
		}
	}

	/* 返回结果 */
	return reResult;
}

/*
* 功能描述： 引导进路内区段锁闭状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LeadRouteSecLockStateCheck(UINT16 const routeId, UINT8 checkState, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0U;           /* 循环变量 */
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT8 secDirction = 0U;

	/*进路数据*/
	/* 进路区段*/
	UINT8  routeSectionSum = 0U;
	RoutePhysicalSectionStruct* pRouteSectionDataBuf = NULL;
	UINT8 routeDirction = 0U;
	UINT8 reVal = CI_ERROR;


	routeDirction = GetRouteDirection(routeId);
	routeSectionSum = GetRoutePhysicalSectionSum(routeId);
	pRouteSectionDataBuf = GetRouteSectionData(routeId);
	/* 区段占用检查 */
	if ((0u == routeSectionSum) || (NULL == pRouteSectionDataBuf))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0U; i < routeSectionSum; i++)
		{
			devId = pRouteSectionDataBuf[i].PhysicalSectionId;
			devState = GetPhySecLockState(devId);
			secDirction = GetPhySecLockDirection(devId);

			/* 需检查本区段 */
			if ((devState == checkState) || (PHYSICAL_SECTION_LOCK_NO == devState))
			{
				if ((PHYSICAL_SECTION_LOCK_NO == checkState) || (PHYSICAL_SECTION_LOCK_START == checkState))
				{
					/*【未锁闭】与【上电锁闭】不检查方向*/
					/* 通过检查*/

				}
				else
				{
					if (PHYSICAL_SECTION_LOCK_NO == devState)
					{
						/* 通过检查*/
					}
					else
					{
						/*其他锁闭需检查区段锁闭方向与进路一致*/
						if (secDirction == routeDirction)
						{
							/* 通过检查*/
						}
						else
						{
							/*状态不一致返回故障状态*/
							*pDevId = devId;
							*pDevState = devState;
							reVal = CI_ERROR;
						}
					}

				}

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 检查设置自动折返属性条件是否通过
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ：CI_SUCCESS：自动折返属性条件检通过
			CI_ERROR:自动折返属性条件检失败
			2022.08.03 add by pfq 折返轨有车占用时判断抵触进路为折返进路且进路最后一个物理区段正常锁闭且占用则能设置自动折返属性
*/
UINT8 JudgeSetAutoTriggerFlagIsValid(const UINT16 routeId)
{
	UINT8 retVal = CI_ERROR;
	UINT16 routeInPhySecId = 0u;   /*进路内方物理区段ID */
	UINT8 PhySecOccupyState = 0u;          /*物理区段占用状态*/
	UINT8 PhySecLockState = 0u;           /*物理区段锁闭状态*/
	UINT8 phySectionSum = 0u;        /*进路包含的物理区段数量*/
	UINT8 routeState = 0u;           /*进路状态*/
	RoutePhysicalSectionStruct* pRoutePhysicalSectionBuf = NULL;
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT16 ii = 0u;       /*循环下标*/

	bufIndex = GetRouteConfigBufIndex(routeId);  /*获取进路数组下标*/

	if (bufIndex >= ROUTE_SUM_MAX)
	{
		retVal = CI_ERROR;
	}
	else
	{
		routeState = GetRouteState(routeId);
		if (ROUTE_STATE_AUTO_UNLOCK == routeState)   /*抵触进路是自动解锁正常时，对进路内方区段进行检查*/
		{
			phySectionSum = GetRoutePhysicalSectionSum(bufIndex);   /*获取进路内方区段数量*/
			/*获取进路内方物理区段ID*/
			pRoutePhysicalSectionBuf = GetRouteSectionData(bufIndex);
			if ((0u < phySectionSum) && (NULL != pRoutePhysicalSectionBuf))
			{
				retVal = CI_SUCCESS;
			}
			else
			{
				retVal = CI_ERROR;
			}
		}
		else
		{
			retVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == retVal)
	{
		for (ii = 0u; ii < phySectionSum; ii++)
		{
			routeInPhySecId = pRoutePhysicalSectionBuf[ii].PhysicalSectionId;
			PhySecOccupyState = GetPhySecCurOccupyState(routeInPhySecId);    /*获取物理区段当前占用状态*/
			PhySecLockState = GetPhySecLockState(routeInPhySecId);           /*获取物理区段当前锁闭状态*/
			if (ii < (phySectionSum - 1U))
			{
				if ((PHYSICAL_SECTION_LOCK_NO == PhySecLockState) && (SECTION_OCCUPY_NO == PhySecOccupyState))
				{
					/*自动解锁正常的进路内方出最后一个物理区段外其他物理区段都未锁闭且空闲*/
					retVal = CI_SUCCESS;
				}
				else
				{
					retVal = CI_ERROR;  /*有一个不满足则退出*/
					break;
				}
			}
			else
			{
				if ((PHYSICAL_SECTION_LOCK_NORMAL == PhySecLockState) && (SECTION_OCCUPY_YES == PhySecOccupyState))
				{
					/*当折入进路的列车停在站台时，可以设置折返进路的自动触发属性*/
					retVal = CI_SUCCESS;
				}
				else
				{
					retVal = CI_ERROR;
				}
			}
		}
	}

	return retVal;
}


/*
* 功能描述： 引导进路逻辑区段锁闭有效性检查
* 参数说明：
*            UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add 20221007 适配进路提前驱动道岔功能
*/
UINT8 LeadRouteLogSecLockValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路内逻辑区段*/
	UINT16 const checkSum = GetRouteLogSectionSum(routeId);
	UINT16* const dataIdBuf = GetRouteLogSectionIdBuf(routeId);


	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 secLockDirection = 0u;
	UINT8 ciType = 0u;
	UINT8 cLocalCiId = 0U;
	UINT8 const routeDirDirection = GetRouteDirection(routeId);
	UINT8 reVal = CI_ERROR;
	UINT8 phyArbState = 0u;
	UINT16 phySecId = 0u;          /* 物理区段ID */

	cLocalCiId = GetSystemParaLocalCiId();
	ciType = GetCiType(cLocalCiId);

	/*检查进路内逻辑区段锁闭状态*/
	if ((0u == checkSum) || (NULL == dataIdBuf || (NULL == pDevId) || (NULL == pDevState)))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetLogSecLockState(devId);
			secLockDirection = GetLogSecLockDir(devId);
			phySecId = GetLgcSecRelativePhySecId(devId);

			if (LOG_SECTION_LOCK_NO == devState)
			{
				/* 未锁闭 */
			}
			else if (LOG_SECTION_LOCK_PROTECT == devState)
			{
				/*防护锁闭*/

				if (secLockDirection != routeDirDirection)
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

			}
			else if (LOG_SECTION_LOCK_NORMAL == devState)
			{
				if (secLockDirection == routeDirDirection)
				{
					/*区段锁闭状态为正常锁闭，
					物理区段锁闭方向与进路方向一致*/

				}
				else
				{
					/*锁闭方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}

			}
			else if (LOG_SECTION_LOCK_EXCEPT == devState)
			{
				if (CI_TYPE_CLD == ciType)
				{
					/*获取ARB状态*/
					phyArbState = GetPhySecArbState(phySecId);
					/*区段ARB状态，且锁闭方向一致*/
					if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirDirection))
					{
						/*不做处理*/
					}
					else
					{
						/*返回失败*/
						*pDevId = devId;
						*pDevState = devState;
						reVal = CI_ERROR;
					}
				}
				else
				{
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else
			{
				/*状态无效故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
			}

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

	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 侵限区段对应侵限条件判断
* 参数说明：
*            UINT16 const wInvaSectId,    侵限区段ID
* 返回值  ： CI_ERROR   侵限
*            CI_SUCCESS 侵限不满足
* cgh-20230422创  建
*/
UINT8 IntruSecVainCheck(UINT16 const wInvaSectId)
{
	UINT16 i = 0U;           /* 循环变量 */
	UINT8 chDevState = 0U;  /*侵限区段当前融合状态*/
	UINT8 intruSwitchPosValid = CI_ERROR;/*侵限区段条件检查返回值*/
	UINT8 chDevLockState = 0U;/*侵限区段锁闭状态*/
	UINT16 wPhyLockBelongRouteId = 0U;/*侵限区段进路锁闭所属进路ID*/
	UINT8 chPhyLockRouteLevel = 0U;    /*侵限区段进路锁闭所属进路监督级别*/
	UINT16 wRouteLogNum = 0U;/*侵限区段进路锁闭所属进路包含逻辑区段数目*/
	UINT16* wRouteLogIdBuf = NULL;/*侵限区段进路锁闭所属进路包含逻辑区段ID*/
	UINT8 chLogSecOccupyState = 0U;/*逻辑区段占用状态*/
	UINT16 wLogOccupyNoNum = 0U;/*逻辑区段空闲数目*/

	chDevState = GetPhySecCurMergeState(wInvaSectId);
	chDevLockState = GetPhySecLockState(wInvaSectId);
	wPhyLockBelongRouteId = GetPhySecRLockBelongRouteId(wInvaSectId);
	chPhyLockRouteLevel = GetRouteLevel(wPhyLockBelongRouteId);
	/*获取进路逻辑区段数据*/
	wRouteLogNum = GetRouteLogSectionSum(wPhyLockBelongRouteId);
	wRouteLogIdBuf = GetRouteLogSectionIdBuf(wPhyLockBelongRouteId);

	if (NULL != wRouteLogIdBuf)
	{
		/*侵限区段空闲*/
		if (SECTION_OCCUPY_NO == chDevState)
		{
			/*侵限区段被进路正常锁闭*/
			if (PHYSICAL_SECTION_LOCK_NORMAL == chDevLockState)
			{
				for (i = 0; i < wRouteLogNum; i++)
				{/*侵限区段所属进路内方逻辑区段占用状态判断；若存在UT占用，返回侵限，否则返回不侵限*/
					chLogSecOccupyState = GetLogSecOccupyState(wRouteLogIdBuf[i]);
					if (LOGICSECTION_OCCUPY_CT == chLogSecOccupyState)
					{
						intruSwitchPosValid = CI_SUCCESS;
					}
					else if (LOGICSECTION_OCCUPY_NO == chLogSecOccupyState)
					{
						wLogOccupyNoNum++;
						intruSwitchPosValid = CI_SUCCESS;
					}
					else
					{
						intruSwitchPosValid = CI_ERROR;
						break;
					}
				}
			}
			else
			{
				intruSwitchPosValid = CI_ERROR;
			}
			/*内方所有区段空闲且进路级别为CBTC*/
			if ((CI_SUCCESS == intruSwitchPosValid) && (wRouteLogNum == wLogOccupyNoNum)
				&& (ROUTE_LEVEL_CBTC == chPhyLockRouteLevel))
			{
				intruSwitchPosValid = CI_SUCCESS; /*检查成功*/
			}
			else if ((CI_SUCCESS == intruSwitchPosValid) && (ROUTE_LEVEL_CBTC == chPhyLockRouteLevel))
			{/*进路内方区段只存在CT占压*/
				intruSwitchPosValid = CI_SUCCESS; /*检查成功*/
			}
			else
			{
				intruSwitchPosValid = CI_ERROR;
			}
		}
		else
		{
			intruSwitchPosValid = CI_ERROR;
		}
	}
	else
	{
		intruSwitchPosValid = CI_ERROR;
	}
	/* 未检测到侵限条件 */
	return intruSwitchPosValid;
}

/*
* 功能描述： 进路锁闭部分区段封锁检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfSecFLockCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
														 
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = GetLgcSecRelativePhySecId(pDataIdBuf[i]);
			devState = GetPhySecFLockState(devId);

			/* 状态如果不是未封锁状态，则认为检查失败 */
			if (devState != PHYSICAL_SECTION_FLOCK_NO)
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				ret = CI_ERROR;
				break;
			}
			

		}
	}

	/*全部通过检查*/
	return ret;
}



/*
* 功能描述： 进路锁闭部分区段锁闭条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfSecLockCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);
		
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 retVal = CI_ERROR;
	UINT8 funcRet = CI_ERROR;
	UINT8 routeDirection = 0U;
	UINT8 secLockDirection = 0U;
	UINT16 routeLockedId = 0U;
	UINT8 routeLockedType = 0U;
	UINT16 protectLockedId = 0U;
	UINT16 phySecId = 0U;
	UINT8 phyArbState = 0U;
	UINT8 cLogicLockState = 0U;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogicLockBelongRouteNum = 0U;  /*逻辑区段逻辑锁闭所属进路数量*/

	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		routeDirection = GetRouteDirection(routeId);
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];
			devState = GetLogSecLockState(devId);

			switch (devState)
			{
			case LOG_SECTION_LOCK_NO:
				/* 区段【未锁闭】*/
				break;
			case LOG_SECTION_LOCK_PROTECT:
				/* 区段【防护锁闭】*/
				secLockDirection = GetLogSecLockDir(devId);
				if (secLockDirection == routeDirection)
				{
					/*方向一致*/
				}
				else
				{
					/*方向不一致*/
					*pDevId = devId;
					*pDevState = devState;
					retVal = CI_ERROR;
				}
				break;
			case LOG_SECTION_LOCK_NORMAL:
			case LOG_SECTION_LOCK_DELAY:
				/* 区段【正常锁闭】或 【延时解锁】 */
				secLockDirection = GetLogSecLockDir(devId);
				routeLockedId = GetLogSecLockBelongRoute(devId);
				routeLockedType = GetRouteType(routeLockedId);
				protectLockedId = GetLogSecPLockRouteId(devId);
				/*获取指定ID进路列车脚下资源包含该逻辑区段*/
				funcRet = CheckLgcSecHaveTrainLoc(routeId, devId);

				if ((secLockDirection == routeDirection) && (ROUTE_TYPE_LIECHE == routeLockedType))
				{
					/*列车进路且方向一致*/
				}
				else
				{
					/*方向不一致*/
					if ((CI_SUCCESS == funcRet) && (0U == protectLockedId))
					{
						/*列车脚下区段从头开始遍历, 记录时，从列车大前到小后的逻辑区段*/
					}
					else
					{/*检查不通过*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
					}
				}
				break;
			case LOG_SECTION_LOCK_EXCEPT:
				/*获取逻辑区段所属物理区段ARB状态、逻辑区段异常锁闭方向*/
				phySecId = GetLgcSecRelativePhySecId(devId);
				phyArbState = GetPhySecArbState(phySecId);
				secLockDirection = GetLogSecLockDir(devId);
				/*区段ARB，且异常锁闭方向一致*/
				if ((AXIS_SECTION_ARB_YES == phyArbState) && (secLockDirection == routeDirection))
				{
					/*不做处理*/
				}
				else
				{
					/*返回错误*/
					*pDevId = devId;
					*pDevState = devState;
					retVal = CI_ERROR;
				}
				break;
			default:
				/*锁闭状态不满足*/
				*pDevId = devId;
				*pDevState = devState;
				retVal = CI_ERROR;
				break;
			}

			cLogicLockState = GetLogSecLogLockState(devId);  /*获取逻辑区段逻辑锁闭状态*/
			cLogicLockBelongRouteNum = GetLogSecLockBelLogRouteSum(devId);  /*获取逻辑区段逻辑锁闭所属进路数量*/

			/*逻辑区段未逻辑锁闭且锁闭所属逻辑进路数量为0，返回成功，否则返回失败*/
			if ((LOG_SECTION_LOGLOCK_NO == cLogicLockState) && (0U == cLogicLockBelongRouteNum))
			{
				/*不处理*/
			}
			else if ((LOG_SECTION_LOGLOCK_NORMAL == cLogicLockState) && (1U == cLogicLockBelongRouteNum))
			{
				/*【逻辑正常锁闭】且【仅被一条逻辑进路锁闭】*/
				secLockDirection = GetLogSecLogLockDir(devId);
				funcRet = CheckLgcSecHaveTrainLoc(routeId, devId);
				protectLockedId = GetLogSecPLockRouteId(devId);
				if ((((CI_SYSTEM_DIRECTION_UP == routeDirection) && (CI_SYSTEM_DIRECTION_DOWN == secLockDirection))
					|| ((CI_SYSTEM_DIRECTION_DOWN == routeDirection) && (CI_SYSTEM_DIRECTION_UP == secLockDirection)))
					&& (CI_SUCCESS == funcRet) && (0U == protectLockedId))
				{
					/*区段逻辑锁闭方向与进路方向相反，且为列车脚下逻辑区段，且不存在防护锁闭*/
				}
				else
				{
					*pDevId = devId;
					*pDevState = cLogicLockState;
					retVal = CI_ERROR;  /*逻辑区段存在逻辑锁闭，停止遍历，返回失败*/
				}
			}
			else
			{
				*pDevId = devId;
				*pDevState = cLogicLockState;
				retVal = CI_ERROR;  /*逻辑区段存在逻辑锁闭，停止遍历，返回失败*/
			}

			if (CI_ERROR == retVal)
			{
				break;
			}
			else
			{
				/*继续遍历*/
			}
		}
	}

	/*全部通过检查*/
	return retVal;
}


/*
* 功能描述： 进路锁闭部分侵限条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfIntruSecCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
														 /* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];
			
			ret = LogicIntruSecVainCheck(devId, pDevId, pDevState);

			/* 检查失败 */
			if ( CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}

/*
* 功能描述： 逻辑区段所处道岔位置检查
* 参数说明： UINT16 const routeId, 进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
* 更新    ： 使用逻辑区段关联道岔进行计算
*/
UINT8 LogicSwitchMoveValidCheck(UINT16 const wLgcId, UINT8 routeHalfSwitchMoveStt, UINT16 *pDevId, UINT8 *pDevState, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 devId = 0U;
	UINT8 devState = 0U;
	UINT8 chCheckSum = 0U;
	UINT8 switchMoveState = 0U;
	
	LogsecSwitchStruct *pstlogicSecSwitchBuf = NULL;

	chCheckSum = GetLogicSecSwitchSum(wLgcId);
	pstlogicSecSwitchBuf = GetLogicSecSwitchIdStru(wLgcId);
	if ((NULL != pDevId)
		&& (NULL != pDevState)
		&& (NULL != pstlogicSecSwitchBuf)
		&& (LOGSEC_INCLUDE_SWITCH_SUM_MAX>chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			devId = pstlogicSecSwitchBuf[ii].SwitchId;
			devState = GetSwitchCurPosition(devId);
			if (SWITCH_POSITION_INVALID == devState)
			{
				/*道岔位置无效*/
				*pDevId = devId;
				*pDevState = devState;
				chRetVal = CI_ERROR;
			}
			else if ((SWITCH_POSITION_DINGWEI == devState) || (SWITCH_POSITION_FANWEI == devState)|| (SWITCH_POSITION_MOVE == devState))
			{
				if (pstlogicSecSwitchBuf[ii].SwitchPosition == devState)
				{
					/* 位置一致，继续检查*/
				}
				else
				{/*位置不一致*/
					if (ROUTE_HALF_SWITCH_MOVE_VALID == routeHalfSwitchMoveStt)
					{
						/* 道岔位置不正确 且半截锁闭允许动道岔*/
						switchMoveState = GetSwitchMoveValidState(devId, SWITCH_OPER_NO_DANCAO, sendLevel);
						if (switchMoveState == CI_SUCCESS)
						{
							/*道岔可动*/
						}
						else
						{
							/*道岔位置不正确 且 道岔不可动作*/
							*pDevId = devId;
							*pDevState = devState;
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*道岔位置不正确 且 道岔不可动作*/
						*pDevId = devId;
						*pDevState = devState;
						chRetVal = CI_ERROR;
					}
				}
			}
			else if (SWITCH_POSITION_SIKAI == devState)
			{
				/*四开*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				chRetVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA == devState)
			{
				/*挤岔*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				chRetVal = CI_ERROR;
			}
			else
			{
				/*道岔位置状态无效 */
				*pDevId = devId;
				*pDevState = devState;
				chRetVal = CI_ERROR;
			}
			if (CI_ERROR == chRetVal)
			{
				break;
			}
			else
			{
			}
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	return chRetVal;
}

/*
* 功能描述： 进路锁闭部分道岔位置与是否可动条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfSwitchMoveValidCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 routeHalfSwitchMoveStt = 0U;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		routeHalfSwitchMoveStt = GetHalfRouteSwitchMoveValid(routeId);
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSwitchMoveValidCheck(devId, routeHalfSwitchMoveStt,pDevId, pDevState,(UINT8)1U);
			
			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*故障状态采信LogicSwitchMoveValidCheck*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}


/*
* 功能描述： 逻辑区段防护道岔位置及可动性检查
* 参数说明： UINT16 const wLgcId, 逻辑区段ID
*			 UINT8 const routeHalfSwitchMoveStt 半截进路是否可动标志
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ： qw.liu 2022-03-01
* 更新    ： 使用逻辑区段关联道岔进行计算
*/
UINT8 LogicProSwitchMoveValidCheck(UINT16 const wLgcId, UINT8 const routeHalfSwitchMoveStt, UINT16 *pDevId, UINT8 *pDevState, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 devId = 0U;
	UINT8 devState = 0U;
	UINT8 chCheckSum = 0U;
	UINT8 switchMoveState = 0U;
	LogsecSwitchStruct *pstlogicSecSwitchBuf = NULL;

	
	chCheckSum = GetLgcRelateProSwSum(wLgcId);
	pstlogicSecSwitchBuf = GetLgcRelateProSwStru(wLgcId);
	if ((NULL != pDevId)
		&& (NULL != pDevState)
		&& (NULL != pstlogicSecSwitchBuf)
		&& (LOGSEC_INCLUDE_SWITCH_SUM_MAX>chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			devId = pstlogicSecSwitchBuf[ii].SwitchId;
			devState = GetSwitchCurPosition(devId);
			if (SWITCH_POSITION_INVALID == devState)
			{
				/*道岔位置无效*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				chRetVal = CI_ERROR;
			}
			else
			{
				if (pstlogicSecSwitchBuf[ii].SwitchPosition == devState)
				{
					/* 位置一致，继续检查*/
				}
				else if (SWITCH_POSITION_SIKAI == devState)
				{
					/*四开*/
					*pDevId = devId;
					*pDevState = devState;
					/* 记录故障码 */
					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
					chRetVal = CI_ERROR;
				}
				else if (SWITCH_POSITION_JICHA == devState)
				{
					/*挤岔*/
					*pDevId = devId;
					*pDevState = devState;
					/* 记录故障码 */
					SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
					chRetVal = CI_ERROR;
				}
				else
				{
					if (ROUTE_HALF_SWITCH_MOVE_VALID == routeHalfSwitchMoveStt)
					{

						switchMoveState = GetSwitchMoveValidState(devId, SWITCH_OPER_NO_DANCAO, sendLevel);

						if (switchMoveState == CI_SUCCESS)
						{
							/*道岔可动*/
						}
						else
						{
							/*道岔位置不正确 且 道岔不可动作*/
							*pDevId = devId;
							*pDevState = devState;
							/* 记录故障码 */
							SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*道岔位置不正确 且 道岔不可动作*/
						*pDevId = devId;
						*pDevState = devState;
						/* 记录故障码 */
						SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
						chRetVal = CI_ERROR;
					}
				}
			}
			if (CI_ERROR == chRetVal)
			{
				break;
			}
			else
			{
			}
		}



	}
	else
	{
		chRetVal = CI_ERROR;
	}



	return chRetVal;
}

/*
* 功能描述： 进路锁闭部分防护道岔条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfProSwitchMoveValCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 routeHalfSwitchMoveStt = 0U;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		routeHalfSwitchMoveStt = GetHalfRouteSwitchMoveValid(routeId);
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicProSwitchMoveValidCheck(devId, routeHalfSwitchMoveStt, pDevId, pDevState, (UINT8)1U);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}


/*
* 功能描述： 进路锁闭部分防护道岔位置条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfProSwitchPosCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 routeHalfSwitchMoveStt = 0U;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;
		
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRltvPrtctSwPosCheck(devId, pDevId, pDevState);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}
/*
* 功能描述： 进路锁闭部分防护道岔封锁条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfProSwitchFLockCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState, UINT8* pYLockAlarmFlag)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRltvPrtctSwFLockCheck(devId, pDevId, pDevState, pYLockAlarmFlag);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}
/*
* 功能描述： 进路锁闭部分道岔封锁条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfSwitchFLockCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState, UINT8* pYLockAlarmFlag)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];
			
			ret = LogicSecRelSwitchFLockCheck(devId, pDevId, pDevState, pYLockAlarmFlag);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;
}

/*
* 功能描述： 进路锁闭部分道岔位置条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfSwitchPosCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRelativeSwitchPosCheck(devId, pDevId, pDevState);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

	/*全部通过检查*/
	return ret;

}

/*
* 功能描述： 进路内部分区段跳跃锁闭状态检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 checkState,  比对值
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： 失败返回CI_ERROR
*            成功返回CI_SUCCESS
*/
UINT8 RouteHalfSecJumpLockStateCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const pDataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 ret = CI_ERROR;

	
	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = GetLgcSecRelativePhySecId(pDataIdBuf[i]);
			devState = GetPhySecJumpLockState(devId);

			 /* 需检查本区段 */
			if (PHYSICAL_SECTION_JUMP_LOCK_NO != devState)
			{
				/*状态不等于未跳跃锁闭返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				ret = CI_ERROR;
				break;
			}
			else
			{
				; /*继续执行*/
			}
		}
	}

	/*全部通过检查*/
	return ret;
}

/*
* 功能描述： 进路区段全部侧防条件满足检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfLtrlDfncSwitchCheck(UINT16 const routeId, UINT16 *pDevId, UINT8 *pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetHalfRouteLockLgcSecSum(routeId);
	UINT16* const dataIdBuf = GetHalfRouteLockLgcSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 区段占用检查 */
	if ((0u == checkSum)||(NULL==pDevId)||(NULL==pDevState))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i];
			reVal = LogicSecSwitchLtrlDfncCheck(devId, pDevId, pDevState);
			if (CI_SUCCESS == reVal)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 部分进路区段全部联络线设备条件满足检查
* 参数说明： UINT16 routeId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteHalfContactLineDevCheck(UINT16 const routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT16 LogSectionSum = 0U;
	UINT16 ii = 0U;
	UINT16 *pLogicSecId = NULL;

	/*逻辑区段联络线道岔条件满足*/
	LogSectionSum = GetHalfRouteLockLgcSecSum(routeId);		/*获取部分进路包含的逻辑区段*/
	pLogicSecId = GetHalfRouteLockLgcSecIdBuf(routeId);
	if (0u == LogSectionSum)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (ii = 0U; ii < LogSectionSum; ii++)
		{
			reVal = LogicContactLineDevCheck(pLogicSecId[ii], functionId, sendLevel);
			if (reVal == CI_SUCCESS)
			{
				;		/*通过检查*/
			}
			else
			{
				reVal = CI_ERROR;
				break;
			}
		}
	}
	return reVal;
}

/*
* 功能描述： 分段进路条件检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT8 functionId,      调用函数编号
*            UINT8 sendLevel,       故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 RouteFenDuanConditionCheck(UINT16 const routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 routeProperty = 0U;    /*进路属性 ——主/子/普通进路*/
	UINT8 retVal = CI_ERROR;
	UINT16* subRouteIDBuff = NULL;   /*主进路包含的子进路ID*/
	UINT8 subRouteSum = 0U;           /*主进路包含的子进路数量*/

	UINT16* mainRouteIDBuff = NULL;   /*子进路所属的主进路ID*/
	UINT8 mainRouteSum = 0U;           /*子进路所属的主进路数量*/
	
	routeProperty = GetRouteMainorSubPropert(routeId);
	/*进路为主进路*/
	if (ROUTE_MAIN_PROPERTY == routeProperty)
	{
		subRouteIDBuff = GetSubRouteBuff(routeId);
		subRouteSum = GetSubRouteSum(routeId);
		if ((NULL == subRouteIDBuff) || (0U == subRouteSum))
		{
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeProperty, sendLevel);
		}
		else
		{
			/*主进路联锁条件检查*/
			retVal = MainRouteCheck(routeId);
			if (CI_ERROR == retVal)
			{
				/*主进路联锁条件检查失败*/
				SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeProperty, sendLevel);
			}
		}
	}
	/*进路为子进路*/
	else if (ROUTE_SUB_PROPERTY == routeProperty)
	{
		mainRouteIDBuff = GetMainRouteBuff(routeId);
		mainRouteSum = GetMainRouteSum(routeId);
		if ((NULL == mainRouteIDBuff) || (0U == mainRouteSum))
		{
			retVal = CI_ERROR;
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeProperty, sendLevel);
		}
		else
		{
			/*子进路联锁条件检查*/
			retVal = SubRouteCheck(routeId);
			if (CI_ERROR == retVal)
			{
				/*子进路联锁条件检查失败*/
				SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeProperty, sendLevel);
			}
		}
	}
	/*普通进路  直接通过*/
	else if (ROUTE_INIT_PROPERTY == routeProperty)
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		/*进路属性无效*/
		retVal = CI_ERROR;
	}
	return retVal;

}

/*
* 功能描述： 主进路建立联锁条件检查
* 参数说明： UINT16 const routeId,    进路号
* 返回值  ：  CI_ERROR               不通过
*            CI_SUCCESS             通过
*/
UINT8 MainRouteCheck(UINT16 const routeId)
{
	UINT16 curRouteID = 0U;
	UINT8 curRoutestate = 0U;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 retVal = CI_ERROR;

	UINT16* subRouteIDBuff = GetSubRouteBuff(routeId);   /*主进路包含的子进路ID*/
	UINT8  subRouteSum = GetSubRouteSum(routeId);  /*主进路包含的子进路数量*/

	if ((NULL == subRouteIDBuff) || (0U == subRouteSum))
	{
		/*子进路数据无效,返回CI_ERROR*/
	}
	else
	{
		retVal = CI_SUCCESS;
		for (i = 0U; i < subRouteSum; i++)
		{
			curRouteID = subRouteIDBuff[i];
			if (ROUTE_SUM_MAX > curRouteID)
			{
				curRoutestate = GetRouteState(curRouteID);
				/*主进路包含的子进路已办理*/
				if (ROUTE_STATE_IDLE != curRoutestate)
				{
					retVal = CI_ERROR;
				}
				else
				{
					/*继续循环*/
				}
			}
			else
			{
				/*子进路ID无效*/
				retVal = CI_ERROR;
			}

			if (CI_ERROR == retVal)
			{/*跳出循环*/
				break;
			}
			else
			{
				/*继续循环*/
			}

		}
	}
	return retVal;
}


/*
* 功能描述： 子进路建立联锁条件检查
* 参数说明： UINT16 const routeId,    进路号
* 返回值  ：  CI_ERROR         不通过
*            CI_SUCCESS       通过
*/
UINT8 SubRouteCheck(UINT16 const routeId)
{

	UINT16 curRouteID = 0U;
	UINT8 curRoutestate = 0U;
	UINT16 curPhysicId = 0U;
	UINT8 curPhysicState = 0U;

	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT16 devId = 0U;
	UINT8 devState = 0U;
	UINT8 retVal = CI_ERROR;
	UINT16 routeLockedId = 0;    /*区段锁闭所属的进路ID*/
	UINT16* mainRouteIDBuff = NULL; /*子进路所属的主进路ID*/
	UINT8 mainRouteSum = 0U; /*子进路所属的主进路数量*/
	UINT16  logicSum = 0U;
	UINT16* logicIdBuf = NULL;

	mainRouteIDBuff = GetMainRouteBuff(routeId);
	mainRouteSum = GetMainRouteSum(routeId);
	logicSum = GetRouteLogSectionSum(routeId);                           /*进路包含的逻辑区段数量*/
	logicIdBuf = GetRouteLogSectionIdBuf(routeId);                      /*进路包含的逻辑区段*/

	if ((NULL == mainRouteIDBuff) || (0U == mainRouteSum)
		|| (NULL == logicIdBuf) || (0U == logicSum))
	{
		/*进路数据无效,返回CI_ERROR*/
	}
	else
	{
		retVal = CI_SUCCESS;
		/*逻辑区段锁闭检查*/
		for (i = 0U; i < logicSum; i++)
		{
			devId = logicIdBuf[i];
			devState = GetLogSecLockState(devId);

			if (LOG_SECTION_LOCK_NO != devState)
			{/*逻辑区段锁闭*/
				routeLockedId = GetLogSecLockBelongRoute(devId);/*获取指定逻辑区段锁闭所属进路*/
				/*遍历该进路包含的子进路*/
				for (j = 0U; j < mainRouteSum; j++)
				{
					if (routeLockedId == mainRouteIDBuff[j])
					{/*子进路锁闭区段所属进路为主进路  检查不通过*/
						retVal = CI_ERROR;
						break;
					}
					else
					{
						/*继续循环*/
					}
				}
			}
			else
			{
				/*区段未锁闭 不检查 继续循环*/
			}

			if (CI_ERROR == retVal)
			{
				/*检查条件不满足，跳出循环，返回CI_ERROR*/
				break;
			}
			else
			{
				/*继续循环*/
			}
		}
	}
	return retVal;
}

/*
* 功能描述： 检查进路部分路径锁闭是否有道岔驱动超时
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
CI_SUCCESS:进路无道岔驱动超时
CI_ERROR:进路有道岔驱动超时
*/
UINT8 ChekRouteHalfSwDrvOvTime(const UINT16 routeId)
{
	UINT8 retVal = CI_ERROR;

	UINT8   lgcSecSwitchSum = 0U;							/*逻辑区段关联道岔数量*/
	LogsecSwitchStruct *pLgcSecSwitchData = NULL;
	UINT8 	ii = 0u;											/*循环变量*/
	UINT8  jj = 0U;
	RouteSwitchStruct* pRouteSwitchStru = NULL; 				/*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };  /*防护道岔数据*/

	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;

	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;

	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetHalfRouteLockLgcSecSum(routeId);
	pLogIdBuff = GetHalfRouteLockLgcSecIdBuf(routeId);
	routeProtectSwitchSum = GetRouteHalfProSwData(routeId, routeProtectSwitchStru);      /*获取防护道岔数据*/
	/* 局部变量定义初始化 */

	if ((0u == logSectionSum) || (NULL == pLogIdBuff))
	{
		/*无逻辑区段，错误场景*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		for (ii = 0u; ii < logSectionSum; ii++)
		{
			lgcSecSwitchSum = GetLogicSecSwitchSum(pLogIdBuff[ii]);
			pLgcSecSwitchData = GetLogicSecSwitchIdStru(pLogIdBuff[ii]);
			if ((NULL != pLgcSecSwitchData)
				&& (lgcSecSwitchSum < LOGSEC_INCLUDE_SWITCH_SUM_MAX))
			{
				/*开始检查进路内道岔*/
				for (i = 0u; i < lgcSecSwitchSum; i++)
				{
					SwitchId = pLgcSecSwitchData[i].SwitchId;
					SwitchPos = pLgcSecSwitchData[i].SwitchPosition;
					SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

					if (SWITCH_POSITION_DINGWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
						}

					}
					else if (SWITCH_POSITION_FANWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
						}

					}
					else
					{
						/*数据配置错误*/
						retVal = CI_ERROR;
					}

					if (CI_SUCCESS != retVal)
					{
						/*存在超时*/
						break;
					}
				}
			}
		}
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0u == routeProtectSwitchSum))
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查进路关联防护道岔*/
			for (i = 0u; i<routeProtectSwitchSum; i++)
			{
				SwitchId = routeProtectSwitchStru[i].ProtectSwitchId;
				SwitchPos = routeProtectSwitchStru[i].ProtectPosition;
				SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

				if (SWITCH_POSITION_DINGWEI == SwitchPos)
				{
					if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
					}

				}
				else if (SWITCH_POSITION_FANWEI == SwitchPos)
				{
					if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
					}

				}
				else
				{
					/*数据配置错误*/
					retVal = CI_ERROR;
				}

				if (CI_SUCCESS != retVal)
				{
					/*存在超时*/
					break;
				}
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}


/*
* 功能描述： 检查进路部分路径锁闭道岔位置正确
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*	CI_SUCCESS:进路无道岔驱动超时
*	CI_ERROR:进路有道岔驱动超时
*/
UINT8 ChekRouteHalfSwPosRight(const UINT16 routeId)
{
	UINT8 retVal = CI_ERROR;

	UINT8   lgcSecSwitchSum = 0U;							/*逻辑区段关联道岔数量*/
	LogsecSwitchStruct *pLgcSecSwitchData = NULL;
	UINT8 	ii = 0u;											/*循环变量*/
	UINT8  jj = 0U;
	RouteSwitchStruct* pRouteSwitchStru = NULL; 				/*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };  /*防护道岔数据*/

	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 switchCurPos = SWITCH_POSITION_INVALID;
	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetHalfRouteLockLgcSecSum(routeId);
	pLogIdBuff = GetHalfRouteLockLgcSecIdBuf(routeId);
	routeProtectSwitchSum = GetRouteHalfProSwData(routeId, routeProtectSwitchStru);      /*获取防护道岔数据*/


	if ((0u == logSectionSum) || (NULL == pLogIdBuff))
	{
		/*无逻辑区段，错误场景*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		for (ii = 0u; ii < logSectionSum; ii++)
		{
			lgcSecSwitchSum = GetLogicSecSwitchSum(pLogIdBuff[ii]);
			pLgcSecSwitchData = GetLogicSecSwitchIdStru(pLogIdBuff[ii]);
			if ((NULL != pLgcSecSwitchData)
				&& (lgcSecSwitchSum < LOGSEC_INCLUDE_SWITCH_SUM_MAX))
			{
				/*开始检查进路内道岔*/
				for (i = 0u; i < lgcSecSwitchSum; i++)
				{
					SwitchId = pLgcSecSwitchData[i].SwitchId;
					SwitchPos = pLgcSecSwitchData[i].SwitchPosition;
					switchCurPos =GetSwitchCurPosition (SwitchId);

					if ((switchCurPos == SwitchPos)
						&&((SWITCH_POSITION_DINGWEI ==SwitchPos)
							||(SWITCH_POSITION_FANWEI == SwitchPos)))
					{
						

					}
					
					else
					{
						retVal = CI_ERROR;
					}

					if (CI_SUCCESS != retVal)
					{
						/*存在超时*/
						break;
					}
				}
			}
		}
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0u == routeProtectSwitchSum))
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查进路关联防护道岔*/
			for (i = 0u; i<routeProtectSwitchSum; i++)
			{
				SwitchId = routeProtectSwitchStru[i].ProtectSwitchId;
				SwitchPos = routeProtectSwitchStru[i].ProtectPosition;
				switchCurPos = GetSwitchCurPosition(SwitchId);

				if ((switchCurPos == SwitchPos)
					&& ((SWITCH_POSITION_DINGWEI == SwitchPos)
						|| (SWITCH_POSITION_FANWEI == SwitchPos)))
				{
					/*道岔位置一致*/
				}

				else
				{
					retVal = CI_ERROR;
				}

				if (CI_SUCCESS != retVal)
				{
					/*存在超时*/
					break;
				}
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
* 功能描述：检查逻辑区段序列是否连续
* 输入参数：const UINT8 cLogSecSeqDir 逻辑区段序列方向
*           const UINT8 cLogSecSum 逻辑区段数量
*           const UINT16 pLogSecIdBuff[] 逻辑区段序列
* 输出参数：UINT8 pQueryDir[] 每个逻辑区段对应的查询方向
* 返回值  ：CI_ERROR   逻辑区段序列不连续
*           CI_SUCCESS 逻辑区段序列连续
*/
UINT8 LogSecSeqIsContinuousCheck(const UINT8 cLogSecSeqDir, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[], UINT8 pQueryDir[])
{
	/*局部变量初始化*/
	UINT8 retVal = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 cRelatedLogSecSum = 0U;      /*下一相邻逻辑区段数量*/
	UINT16* pRelatedLogSecId = NULL;   /*下一相邻逻辑区段ID数组*/
	UINT8 cQueryLogicDir = 0U;  /*查询的逻辑方向*/
	UINT8 cQueryRunDir = 0U;  /*查询的运营方向*/
	UINT8 cDirChangeFlag = DIRECTIONPOINT_FLAG_INVALID;  /*方向变化点标志*/
	UINT8 cDirChangeNum = 0U;
	UINT16* pCurLinkIdBuff = NULL;  /*当前逻辑区段包含的link*/
	UINT16* pNxtLinkIdBuff = NULL;  /*下一相邻逻辑区段包含的link*/
	LOD_STRU curStrPoint = { 0U };  /*当前逻辑区段包含的link端点*/
	LOD_STRU nxtStrPoint = { 0U };  /*下一相邻逻辑区段包含的link端点*/

	/*入参检查*/
	if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) || (CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir))
		&& (0U != cLogSecSum) && (NULL != pLogSecIdBuff))
	{
		retVal = CI_SUCCESS;
	
		cQueryLogicDir = ConvertDirectionToLogic(cLogSecSeqDir);  /*初始化时，根据ATS输入的运行方向设置查询的逻辑方向*/
		pQueryDir[0U] = cQueryLogicDir;

		/*根据逻辑方向查询逻辑区段序列是否连续*/
		for (i = 0U; i < (cLogSecSum - 1U); i++)
		{
			/*根据逻辑方向获取逻辑区段下一相邻逻辑区段数量/ID数组*/
			if (DIR_CONVERT == cQueryLogicDir)
			{
				cRelatedLogSecSum = GetLogBeginLogSecSum(pLogSecIdBuff[i]);
				pRelatedLogSecId = GetLogBeginLogSecData(pLogSecIdBuff[i]);
			}
			else if (DIR_SAME == cQueryLogicDir)
			{
				cRelatedLogSecSum = GetLogEndLogSecSum(pLogSecIdBuff[i]);
				pRelatedLogSecId = GetLogEndLogSecData(pLogSecIdBuff[i]);
			}
			else
			{
				retVal = CI_ERROR;  /*查询方向错误，返回失败*/
			}

			if ((0U != cRelatedLogSecSum) && (NULL != pRelatedLogSecId) && (CI_SUCCESS == retVal))
			{
				/*判断序列中的下一逻辑区段是否为相邻逻辑区段*/
				for (j = 0U; j < cRelatedLogSecSum; j++)
				{
					if (pRelatedLogSecId[j] == pLogSecIdBuff[i + 1U])
					{
						retVal = CI_SUCCESS;
						break;
					}
					else
					{
						retVal = CI_ERROR;
					}
				}
			}
			else
			{
				retVal = CI_ERROR;  /*不存在下一相邻逻辑区段，直接返回失败*/
			}

			/*确定下一逻辑区段的查询方向并存储*/
			pCurLinkIdBuff = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[i]);  /*获取当前逻辑区段包含的link*/
			pNxtLinkIdBuff = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[i + 1U]);  /*获取下一相邻逻辑区段包含的link*/

			if ((NULL != pCurLinkIdBuff) && (NULL != pNxtLinkIdBuff) && (CI_SUCCESS == retVal))
			{
				curStrPoint.Lnk = pCurLinkIdBuff[0];
				curStrPoint.Off = 0U;
				nxtStrPoint.Lnk = pNxtLinkIdBuff[0];
				nxtStrPoint.Off = 0U;

				cDirChangeNum = GetDirChangeNumBtwPoints(&curStrPoint, &nxtStrPoint);
				cQueryLogicDir = TransDirByChangeNum(cQueryLogicDir, cDirChangeNum);  /*查询相邻逻辑区段时，根据方向变化点设置查询的逻辑方向*/
				pQueryDir[i + 1U] = cQueryLogicDir;  /*存储逻辑区段对应的查询方向，用于跨RC办动态进路时传给相邻联锁*/
				ASSERT_SETRET(0U == cQueryLogicDir, retVal, CI_ERROR, CI_SUCCESS);
			}
			else
			{
				retVal = CI_ERROR;  /*获取link失败，返回失败*/
			}

			/*序列中存在不连续的逻辑区段，停止检查*/
			if (CI_SUCCESS != retVal)
			{
				break;
			}
			else
			{
				/*继续检查*/
			}
		}		
	}
	else
	{
		retVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return retVal;
}

/*
* 功能描述：逻辑区段序列与进路匹配检查
* 输入参数：const UINT8 cEndSignalSum 逻辑区段序列关联的终端信号机数量
*           const UINT16 wEndSignalIdBuff[] 逻辑区段序列关联的终端信号机ID
*           const UINT8 cSplitLogSecSumBuff[] 拆分后的逻辑区段序列包含的逻辑区段数量
*           const UINT16 pSplitLogSecIdBuff[][MAX_ROUTE_IN_LT_NUM] 拆分后的逻辑区段序列包含的逻辑区段ID
* 输出参数：UINT16 pMatchedRouteIdBuff[] 与逻辑区段序列匹配的进路ID数组
*           UINT8* pLogicRouteFlag 逻辑进路存在标志
* 返回值  ：CI_ERROR   匹配失败
*           CI_SUCCESS 匹配成功
*/
UINT8 LogSecSeqAndRouteMatchCheck(const UINT8 cEndSignalSum, const UINT16 pEndSignalIdBuff[], const UINT8 pSplitLogSecSumBuff[], const UINT16 pSplitLogSecIdBuff[][MAX_ROUTE_IN_LT_NUM], UINT16 pMatchedRouteIdBuff[], UINT8* pLogicRouteFlag)
{
	/*局部变量初始化*/
	UINT8 retVal = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 k = 0U;
	UINT16 m = 0U;
	UINT8 tempIndex = 0U;
	UINT8 cRelatedRouteSum = 0U;      /*逻辑区段关联进路数量*/
	UINT16* pRelatedRouteId = NULL;   /*逻辑区段关联进路ID数组*/
	UINT16 wRouteEndSignalId = 0U;    /*进路终端信号机*/
	UINT16 cRouteIncLogSecSum = 0U;          /*进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecIdBuff = NULL;   /*进路包含的逻辑区段ID数组*/
	UINT8 cMatchedLogSum = 0U;        /*序列中被进路包含的逻辑区段数量，用于判断序列是否被进路完全包含*/
	UINT8 cPossibleRouteSumBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };   /*初筛成功的进路数量*/
	UINT16 wPossibleRouteIdBuff[ROUTE_SUBROUTE_SUM_MAX][MAX_ROUTE_IN_LT_NUM] = { 0U };  /*初筛成功的进路ID数组（终端信号机相同且能完全包含逻辑区段序列）*/
	UINT8 cLogicRouteFlag = FLAG_SET;  /*首条进路是否为逻辑进路标志，初始化为存在*/

	/*入参检查*/
	if ((0U == cEndSignalSum) || (ROUTE_SUBROUTE_SUM_MAX <= cEndSignalSum) || (NULL == pEndSignalIdBuff) || (NULL == pSplitLogSecSumBuff) || (NULL == pSplitLogSecIdBuff))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		/*遍历所有拆分后的逻辑区段序列，进行进路匹配*/
		for (i = 0U; i < cEndSignalSum; i++)
		{
			tempIndex = pSplitLogSecSumBuff[i] - 1U;    /*获取当前逻辑区段序列中的最后一个逻辑区段索引*/

			/*获取序列中最后一个逻辑区段关联进路信息*/
			cRelatedRouteSum = GetLogRelateRouteSum(pSplitLogSecIdBuff[i][tempIndex]);
			pRelatedRouteId = GetLogRelateRouteData(pSplitLogSecIdBuff[i][tempIndex]);

			for (j = 0U; j < cRelatedRouteSum; j++)
			{
				wRouteEndSignalId = GetRouteEndSignalId(pRelatedRouteId[j]);

				/*进路终端信号机与逻辑区段序列终端信号机相同*/
				if (wRouteEndSignalId == pEndSignalIdBuff[i])
				{
					/*获取进路包含的逻辑区段信息*/
					cRouteIncLogSecSum = GetRouteLogSectionSum(pRelatedRouteId[j]);
					pRouteIncLogSecIdBuff = GetRouteLogSectionIdBuf(pRelatedRouteId[j]);
					cMatchedLogSum = 0U;

					/*判断进路是否能完全包含逻辑区段序列*/
					for (k = 0U; k < pSplitLogSecSumBuff[i]; k++)
					{
						for (m = 0U; m < cRouteIncLogSecSum; m++)
						{
							if (pSplitLogSecIdBuff[i][k] == pRouteIncLogSecIdBuff[m])
							{
								cMatchedLogSum++;
								break;
							}
							else
							{
								/*继续与进路的下一个逻辑区段匹配*/
							}
						}
					}

					/*存储能完全包含逻辑区段序列的进路信息*/
					if (cMatchedLogSum == pSplitLogSecSumBuff[i])
					{
						wPossibleRouteIdBuff[i][cPossibleRouteSumBuff[i]] = pRelatedRouteId[j];
						cPossibleRouteSumBuff[i]++;

						if (0U == i)
						{
							cLogicRouteFlag = FLAG_UNSET;  /*首条进路非逻辑进路，置上标志*/
						}
						else
						{
							/*不处理*/
						}
					}
					else
					{
						;
					}
				}
				else
				{
					/*终端信号机不相同，不处理*/
				}
			}

			if ((0U == cPossibleRouteSumBuff[i]) && (0U != i))
			{
				retVal = CI_ERROR;   /*存在逻辑区段序列未匹配到进路，停止执行*/
				break;
			}
			else
			{
				retVal = CI_SUCCESS; /*继续匹配下一逻辑区段序列*/
			}
		}
	}
	else
	{
		/*入参检查失败，不处理*/
	}

	/*所有序列均匹配出了可能的进路，再根据进路性质确定最终的进路ID*/
	if (CI_SUCCESS == retVal)
	{
		*pLogicRouteFlag = cLogicRouteFlag;  /*传出逻辑进路标志*/
		retVal = MatchNonMainAndLieCheRoute(cEndSignalSum, cPossibleRouteSumBuff, wPossibleRouteIdBuff, pMatchedRouteIdBuff);  /*匹配非主进路的列车进路*/
	}
	else
	{
		/*不处理*/
	}

	return retVal;
}

/*
* 功能描述：匹配非主进路的列车进路
* 输入参数：const UINT8 cEndSignalSum 逻辑区段序列关联的终端信号机数量
*           const UINT8 szRouteSum[ROUTE_SUBROUTE_SUM_MAX] 每个逻辑区段序列匹配到的可能的进路数量数组
*           const UINT16 szRouteId[ROUTE_SUBROUTE_SUM_MAX][MAX_ROUTE_IN_LT_NUM] 每个逻辑区段序列匹配到的可能的进路ID数组
* 输出参数：UINT16 szMatchedRouteId[ROUTE_SUBROUTE_SUM_MAX] 与逻辑区段序列匹配的进路ID数组
* 返回值  ：CI_ERROR   匹配失败
*           CI_SUCCESS 匹配成功
* Created By LQ 2024.05.07
*/
UINT8 MatchNonMainAndLieCheRoute(const UINT8 cEndSignalSum, const UINT8 szRouteSum[ROUTE_SUBROUTE_SUM_MAX], const UINT16 szRouteId[ROUTE_SUBROUTE_SUM_MAX][MAX_ROUTE_IN_LT_NUM], UINT16 szMatchedRouteId[ROUTE_SUBROUTE_SUM_MAX])
{
	UINT8 retVal = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 cLieCheIndex = 0U;  /*目标列车进路索引*/
	UINT8 cReturnIndex = 0U;  /*目标折返进路索引*/
	UINT8 cRouteType = 0U;  /*进路类型*/
	UINT8 cMainRouteProperty = 0U;  /*主/子进路属性*/
	UINT8 cTargRouteFlag = FLAG_UNSET;

	/*入参检查*/
	if ((0U != cEndSignalSum) && (ROUTE_SUBROUTE_SUM_MAX >= cEndSignalSum) && (NULL != szRouteSum) && (NULL != szRouteId) && (NULL != szMatchedRouteId))
	{
		retVal = CI_SUCCESS;

		for (i = 0U; i < cEndSignalSum; i++)
		{
			cLieCheIndex = 0U;
			cReturnIndex = 0U;
			cTargRouteFlag = FLAG_UNSET;  /*每循环一次，清一次标志*/

			for (j = 0U; j < szRouteSum[i]; j++)
			{
				cRouteType = GetRouteType(szRouteId[i][j]);
				if (0U == i)
				{
					/*第一个逻辑区段序列为半截进路，通过进路属性找出进路中的非主进路列车进路*/
					cMainRouteProperty = GetRouteMainorSubPropert(szRouteId[i][j]);
					if (ROUTE_TYPE_LIECHE == cRouteType)
					{
						if (ROUTE_MAIN_PROPERTY != cMainRouteProperty)
						{
							cLieCheIndex = j;
							cTargRouteFlag = FLAG_SET;  /*找到列车进路且非主进路，确定为最终匹配的进路，置标志有效，停止遍历*/
						}
						else
						{
							cLieCheIndex = j;
						}
					}
					else
					{
						if (ROUTE_MAIN_PROPERTY != cMainRouteProperty)
						{
							cReturnIndex = j;
						}
						else
						{
							/*不处理*/
						}
					}
				}
				else
				{
					/*其余逻辑区段序列通过列车进路属性找出目标进路*/
					if (ROUTE_TYPE_LIECHE == cRouteType)
					{
						cLieCheIndex = j;
						cTargRouteFlag = FLAG_SET;  /*找到列车进路，确定为最终匹配的进路，置标志有效，停止遍历*/
					}
					else
					{
						/*不处理*/
					}
				}

				if (FLAG_SET == cTargRouteFlag)
				{
					break;  /*找到目标进路，停止遍历*/
				}
				else
				{
					/*继续查找*/
				}
			}

			if (0U != cLieCheIndex)
			{
				szMatchedRouteId[i] = szRouteId[i][cLieCheIndex];  /*存在列车进路，以列车进路优先*/
			}
			else
			{
				szMatchedRouteId[i] = szRouteId[i][cReturnIndex];  /*不存在列车进路，使用折返进路*/
			}
		}
	}
	else
	{
		/*入参检查失败，返回0失败*/
	}

	return retVal;
}

/*
* 功能描述：逻辑区段序列内隐藏车检查
* 输入参数：const UINT16 wTrainId 列车ID
*           const UINT8 cLogSecSum 序列中的逻辑区段数量
*           const UINT16 pLogSecIdBuff[] 逻辑区段序列
* 输出参数：无
* 返回值  ：CI_ERROR   检查失败
*           CI_SUCCESS 检查成功
*/
UINT8 LogSecSeqIncUTCheck(const UINT16 wTrainId, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[])
{
	/*局部变量初始化*/
	UINT8 retVal = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 k = 0U;
	UINT8 cTrainCommState = 0U;  /*列车通信状态*/
	EnvelopeStruct* pTrainEnvelopeData = NULL;  /*列车包络*/
	UINT8 cLogSecOccState = 0U;      /*逻辑区段占用状态*/
	UINT8 cLogSecIncLinkNum = 0U;    /*逻辑区段包含的link数量*/
	UINT16* pLogSecIncLinkIdBuff = NULL;   /*逻辑区段包含的linkID*/
	UINT8 cLinkIncTrainSum = 0U;     /*link上的列车数量*/
	TRAIN_SEQUANCE_s linkInctrainList[SIZE_MAX_TRAINOFAC] = { 0u };  /*link上的列车序列*/

	/*入参检查（暂不查列车ID）*/
	if ((0U == cLogSecSum) || (NULL == pLogSecIdBuff))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0U != wTrainId) && (UINT16_MAX != wTrainId))  /*列车ID合法，继续判断*/
		{
			cTrainCommState = GetTrainTransitmitStat(wTrainId);
			if (TRAIN_COMM_STATE_GOOD == cTrainCommState)  /*通信车检查前筛*/
			{
				if (CI_SUCCESS == retVal)
				{
					/*检查逻辑区段序列内是否存在隐藏车*/
					for (i = 0U; i < cLogSecSum; i++)
					{
						cLogSecOccState = GetLogSecCurCtOrUtOccupyState(pLogSecIdBuff[i]);
						if (LOGICSECTION_OCCUPY_NO != cLogSecOccState)
						{
							/*有车占用时，继续判断逻辑区段是否有隐藏车*/
							cLogSecIncLinkNum = GetSecIntrudeLinkSum(pLogSecIdBuff[i]);
							pLogSecIncLinkIdBuff = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[i]);
							for (j = 0U; j < cLogSecIncLinkNum; j++)
							{
								cLinkIncTrainSum = as_GetLinkTrainList(pLogSecIncLinkIdBuff[j], linkInctrainList, SIZE_MAX_LINETRAIN);
								for (k = 0U; k < cLinkIncTrainSum; k++)
								{
									if ((NAME_FAILUREAREA != linkInctrainList[k].u16TrainID) && (TYPE_CT == linkInctrainList[k].u8TrainType))
									{
										retVal = CI_SUCCESS;   /*通信车，继续检查*/
									}
									else
									{
										retVal = CI_ERROR;    /*存在非通信车，停止检查。返回失败*/
										break;
									}
								}

								if (CI_SUCCESS != retVal)
								{
									break;  /*逻辑区段有一个link存在隐藏车，停止检查，反回失败*/
								}
								else
								{
									/*继续遍历*/
								}
							}
						}
						else
						{
							retVal = CI_SUCCESS;  /*无车占用，检查通过*/
						}

						if (CI_SUCCESS != retVal)
						{
							break;  /*有一个逻辑区段存在隐藏车，停止检查，反回失败*/
						}
						else
						{
							/*继续遍历*/
						}
					}
				}
				{
					/*通信车前端可疑，直接返回失败*/
				}
			}
			else
			{
				/*非通信车，直接返回成功*/
			}
		}
		else
		{
			/*车组号无效，直接返回成功*/
		}
	}
	else
	{
		/*入参校验失败*/
	}

	return retVal;
}

/*
* 功能描述：进路属于本联锁，内方所有物理区段属于其他联锁检查
* 输入参数：const UINT16 routeId, 进路ID
* 输出参数：无
* 返回值  ：CI_ERROR   进路属于本联锁，内方有物理区段属于本联锁
*           CI_SUCCESS 进路属于本联锁，内方没有物理区段属于本联锁
* cgh:成都27出段进路特殊需求，进路属于本联锁，区段全部属于其他联锁
*/
UINT8 RouteAllPhyBelongCiCheck(const UINT16 routeId)
{
	UINT8 reval = CI_ERROR;
	UINT8 chLocalCiId = 0U;/*本机联锁*/
	UINT8 chPhySecSum = 0u;  /*物理区段总数*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT8 chPhyBelongCiId = 0U;/*物理区段所属联锁*/
	UINT8 ii = 0U;
	UINT8 chRouteProSwitchSum = 0U; 							/*防护道岔数目*/
	RouteProtectSwitchStruct* pRouteProtectSwitchStru = NULL;    /*防护道岔数据*/
	UINT16 wProSwRelPhySecId = 0U;/*防护道岔关联物理区段ID*/

	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	chPhySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/

	if ((0u == chLocalCiId) || (NULL == pPhySecDataStru))
	{
		reval = CI_ERROR;
	}
	else
	{
		reval = CI_SUCCESS; /*条件通过，继续执行*/
	}

	if (CI_SUCCESS == reval)
	{
		for (ii = 0U; ii < chPhySecSum; ii++)
		{
			chPhyBelongCiId = GetPhySecBelongCiId(pPhySecDataStru[ii].PhysicalSectionId);
			if (chLocalCiId == chPhyBelongCiId)
			{
				/*进路包含的物理区段有一个属于本联锁，返回CI_ERROR*/
				reval = CI_ERROR;
				break;
			}
			else
			{
				; /*继续检查*/
			}
		}
	}
	else
	{
		;
	}
	
	if (CI_SUCCESS == reval)
	{
		chRouteProSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);
		pRouteProtectSwitchStru = GetRouteRelatedProtSwitchData(routeId);

		for (ii= 0u; ii < chRouteProSwitchSum; ii++)
		{
			wProSwRelPhySecId = GetSwitchPhySectionId(pRouteProtectSwitchStru[ii].ProtectSwitchId);
			chPhyBelongCiId = GetPhySecBelongCiId(wProSwRelPhySecId);
			if (chLocalCiId == chPhyBelongCiId)
			{
				/*进路包含的物理区段有一个属于本联锁，返回CI_ERROR*/
				reval = CI_ERROR;
				break;
			}
			else
			{
				; /*继续检查*/
			}
		}
	}
	else
	{

	}

	return reval;
}
/*
* 功能描述：判断进路是否完整锁闭
* 输入参数：const UINT16 routeId, 进路ID
* 输出参数：无
* 返回值  ：CI_ERROR   进路不是完整锁闭
*          CI_SUCCESS 进路是完整锁闭
*/
UINT8 RouteAllLockCheck(const UINT16 routeId)
{
	UINT8 reval = CI_ERROR;
	UINT8 routeState = 0U;/*进路状态*/
	routeState = GetRouteState(routeId);               /*获取进路状态*/


	if((ROUTE_STATE_FIRST_LOCK== routeState)||
		(ROUTE_STATE_FIRST_LOCKERR== routeState)||
		(ROUTE_STATE_YUXIAN_LOCK == routeState)||
		(ROUTE_STATE_YUXIAN_OPEN == routeState)||
		(ROUTE_STATE_NEAR_OPEN == routeState) ||
		(ROUTE_STATE_NEAR_LOCKERR == routeState)||
		(ROUTE_STATE_NEAR_LOCK == routeState)
		)
	{
		/*进路是完整锁闭:进路初锁、进路初锁异常、预先锁闭、预先开放、接近开放、接近锁闭异常、接近锁闭正常*/
		reval = CI_SUCCESS;
	}
	else
	{
		/*进路是完整锁闭*/
	}
	return reval;
}

/*
* 功能描述：检查逻辑区段序列是否有匹配的进路
* 输入参数：const UINT8 cLogSecSeqDir 逻辑区段序列方向
*           const UINT8 cLogSecSum 逻辑区段数量
*           const UINT16 pLogSecIdBuff[] 逻辑区段序列
* 输出参数：UINT16* pMatchedRouteId 匹配的进路ID
* 返回值  ：0: 匹配成功
*           1: 匹配失败
*/
UINT8 MatchedRouteCheck(const UINT8 cLogSecSeqDir, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[], UINT16* pMatchedRouteId)
{
	UINT8 cLastIndex = 0U;
	UINT8 i = 0U;
	UINT8 cRelatedSigSum = 0U;      /*逻辑区段关联信号机数量*/
	UINT16* pRelatedSigId = NULL;   /*逻辑区段关联信号机ID数组*/
	UINT8 cSignalProDir = 0U;
	UINT16 wSigProLinkId = 0U;  /*信号机防护link*/
	UINT8 cQueryLogDir = 0U;  /*查询方向（逻辑方向）*/
	UINT16 wEndSignalId = 0U;  /*终端信号机ID*/
	UINT16 wMatchedRouteId = 0U;
	UINT8 retVal = CI_ERROR;
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;  /*方向变化点数量*/

	if (((CI_SYSTEM_DIRECTION_DOWN != cLogSecSeqDir) && (CI_SYSTEM_DIRECTION_UP != cLogSecSeqDir))
		|| (0U == cLogSecSum) || (NULL == pLogSecIdBuff))
	{
		retVal = CI_ERROR;  /*入参失败*/
	}
	else
	{		
		cLastIndex = cLogSecSum - 1U;
		cRelatedSigSum = GetLogRelateEndSigSum(pLogSecIdBuff[cLastIndex]); /*获取序列最后一个逻辑区段关联终端信号机的数量/ID数组*/
		pRelatedSigId = GetLogRelateEndSigData(pLogSecIdBuff[cLastIndex]);
		pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[0]);  /*获取序列首个逻辑区段包含的link*/

		/*选出逻辑区段关联终端信号机中防护方向与相邻RC发送的运行方向相同的信号机，并拆分逻辑区段序列*/
		if ((0U != cRelatedSigSum) && (NULL != pRelatedSigId) && (NULL != pLogSecIncLinkId))
		{
			cQueryLogDir = ConvertDirectionToLogic(cLogSecSeqDir);  /*将运营方向转为逻辑方向*/

			for (i = 0U; i < cRelatedSigSum; i++)
			{
				cSignalProDir = GetSignalDirection(pRelatedSigId[i]);
				wSigProLinkId = GetSignalProtectLink(pRelatedSigId[i]);
				strCurPoint.Lnk = pLogSecIncLinkId[0];
				strCurPoint.Off = 0U;
				strNxtPoint.Lnk = wSigProLinkId;
				strNxtPoint.Off = 0U;
				cDirChangeNum = GetDirChangeNumBtwPoints(&strCurPoint, &strNxtPoint);  /*查询当前link到信号机防护link间的方向变化点*/
				cSignalProDir = TransDirByChangeNum(cSignalProDir, cDirChangeNum);

				if (cSignalProDir == cQueryLogDir)
				{
					wEndSignalId = pRelatedSigId[i];  /*最后一逻辑区段存在同向终端信号机，返回其信号机ID*/
					break;
				}
				else
				{
					/*非同向终端信号机或非最后一逻辑区段，不处理*/
				}
			}

			/*逻辑区段序列匹配进路*/
			if (0U != wEndSignalId)
			{
				wMatchedRouteId = SearchMatchedRoute(wEndSignalId, cLogSecSum, pLogSecIdBuff);

				if (0U != wMatchedRouteId)
				{
					*pMatchedRouteId = wMatchedRouteId;
					retVal = CI_SUCCESS;
				}
				else
				{
					retVal = CI_ERROR;
				}
			}
			else
			{
				retVal = CI_ERROR;  /*未找到终端信号机*/
			}
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	
	return retVal;
}

/*
* 功能描述：寻找与逻辑区段序列匹配的进路
* 输入参数：UINT16 wEndSignalId 终端信号机ID
*           const UINT8 cLogSecSum 逻辑区段数量
*           const UINT16 pLogSecIdBuff[] 逻辑区段序列
* 输出参数：无
* 返回值  ：0: 未找到匹配的进路
*          >0: 匹配的进路ID
*/
UINT16 SearchMatchedRoute(UINT16 wEndSignalId, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[])
{
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT16 k = 0U;
	UINT8 tempIndex = 0U;
	UINT8 cRelatedRouteSum = 0U;      /*逻辑区段关联进路数量*/
	UINT16* pRelatedRouteId = NULL;   /*逻辑区段关联进路ID数组*/
	UINT16 wRouteEndSignalId = 0U;    /*进路终端信号机*/
	UINT16 cRouteIncLogSecSum = 0U;          /*进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecIdBuff = NULL;   /*进路包含的逻辑区段ID数组*/
	UINT8 cMatchedLogSum = 0U;        /*序列中被进路包含的逻辑区段数量，用于判断序列是否被进路完全包含*/
	UINT8 wPossibleRouteSum = 0U ;   /*初筛成功的进路数量*/
	UINT16 wPossibleRouteIdBuff[ROUTE_SUBROUTE_SUM_MAX] = { 0U };  /*初筛成功的进路ID数组（终端信号机相同且能完全包含逻辑区段序列）*/
	UINT16 wMatchedRouteId = 0U;  /*匹配的进路ID*/
	UINT8 cLocalCiId = 0U;
	UINT8 cRouteBelongCiId = 0U;

	cLocalCiId = GetSystemParaLocalCiId();

	
	if ((0U == wEndSignalId) || (0U == cLogSecSum) || (NULL == pLogSecIdBuff))
	{
		/*入参检查失败*/
	}
	else
	{
		tempIndex = cLogSecSum - 1U;    /*获取当前逻辑区段序列中的最后一个逻辑区段索引*/

		/*获取序列中最后一个逻辑区段关联进路信息*/
		cRelatedRouteSum = GetLogRelateRouteSum(pLogSecIdBuff[tempIndex]);
		pRelatedRouteId = GetLogRelateRouteData(pLogSecIdBuff[tempIndex]);

		for (i = 0U; i < cRelatedRouteSum; i++)
		{
			wRouteEndSignalId = GetRouteEndSignalId(pRelatedRouteId[i]);
			cRouteBelongCiId = GetRouteBelongCiId(pRelatedRouteId[i]);

			if ((cRouteBelongCiId == cLocalCiId) && (wRouteEndSignalId == wEndSignalId)) /*进路属于本联锁且进路终端信号机与逻辑区段序列终端信号机相同*/
			{
				/*获取进路包含的逻辑区段信息*/
				cRouteIncLogSecSum = GetRouteLogSectionSum(pRelatedRouteId[i]);
				pRouteIncLogSecIdBuff = GetRouteLogSectionIdBuf(pRelatedRouteId[i]);
				cMatchedLogSum = 0U;

				/*判断进路是否能完全包含逻辑区段序列*/
				for (j = 0U; j < cLogSecSum; j++)
				{
					for (k = 0U; k < cRouteIncLogSecSum; k++)
					{
						if (pLogSecIdBuff[j] == pRouteIncLogSecIdBuff[k])
						{
							cMatchedLogSum++;
							break;
						}
						else
						{
							/*继续与进路的下一个逻辑区段匹配*/
						}
					}
				}

				/*存储能完全包含逻辑区段序列的进路信息*/
				if (cMatchedLogSum == cLogSecSum)
				{
					wPossibleRouteIdBuff[wPossibleRouteSum] = pRelatedRouteId[i];
					wPossibleRouteSum++;
				}
				else
				{
					;
				}
			}
			else
			{
				/*终端信号机不相同，不处理*/
			}
		}

		if (0U == wPossibleRouteSum)
		{
			/*未匹配到进路*/
		}
		else
		{
			/*继续找出非主进路属性的列车进路*/
			wMatchedRouteId = SearchNonMainRoute(wPossibleRouteSum, wPossibleRouteIdBuff);
		}
	}
	return wMatchedRouteId;
}

/*
* 功能描述：寻找进路数组中的非主进路
* 输入参数：UINT8 cRouteSum 进路数量
*           UINT16 wRouteIdBuff[] 进路ID数组
* 输出参数：无
* 返回值  ：UINT16 wNonMainRouteId 进路ID
*/
UINT16 SearchNonMainRoute(UINT8 cRouteSum, UINT16 wRouteIdBuff[])
{
	UINT16 wNonMainRouteId = 0U;
	UINT8 i = 0U;
	UINT8 tempLiecheIndex = 0U;  /*列车进路索引*/
	UINT8 tempReturnIndex = 0U;  /*折返进路索引*/
	UINT8 cMainRouteProperty = 0U;    /*主/子进路属性*/
	UINT8 cRouteType = 0u;  /*进路类型*/

	if ((0U == cRouteSum) || (NULL == wRouteIdBuff))
	{
		/*入参检查失败*/
	}
	else
	{
		for (i = 0U; i < cRouteSum; i++)
		{
			cRouteType = GetRouteType(wRouteIdBuff[i]);

			if (ROUTE_TYPE_LIECHE == cRouteType)
			{
				cMainRouteProperty = GetRouteMainorSubPropert(wRouteIdBuff[i]);
				if (ROUTE_MAIN_PROPERTY != cMainRouteProperty)
				{
					tempLiecheIndex = i;  /*找到列车进路且非主进路，确定为最终匹配的进路，停止遍历*/
					break;
				}
				else
				{
					tempLiecheIndex = i;  /*存下当前列车主进路索引*/
				}
			}
			else
			{
				cMainRouteProperty = GetRouteMainorSubPropert(wRouteIdBuff[i]);
				if (ROUTE_MAIN_PROPERTY != cMainRouteProperty)
				{
					tempReturnIndex = i;  /*找到折返进路且非主进路，确定为最终匹配的进路，停止遍历*/
				}
				else
				{
					/*不处理*/
				}
			}
		}

		if (0U != tempLiecheIndex)
		{
			/*存在列车进路，以列车进路为主*/
			wNonMainRouteId = wRouteIdBuff[tempLiecheIndex];
		}
		else
		{
			/*不存在列车进路，返回折返非主进路，若折返非主进路也不存在，则返回进路数组中的第一条进路*/
			wNonMainRouteId = wRouteIdBuff[tempReturnIndex];
		}
	}

	return wNonMainRouteId;
}

/*
* 功能描述：检查道岔关联的逻辑区段的临时限速状态
* 输入参数：UINT16 switchId 道岔Id
* 输出参数：UINT16* pLogSecId 存在临时限速的逻辑区段ID
*           UINT8 *pLogState,  逻辑区段临时限速状态
* 返回值  ：CI_SUCCESS: 关联逻辑区段不存在临时限速
*			CI_ERROR: 关联逻辑区段存在临时限速
* modify 20230927 增加进路内道岔关联的逻辑区段临时限速状态检查
*/
UINT8 SwitchRelLogSecLSXSStateCheck(UINT16 switchId, UINT16* pLogSecId, UINT8* pLogState)
{
	UINT16 i = 0U;
	UINT16 wLogSecSum = 0U;
	UINT8 cLogSecLockState = 0U;
	UINT16* pLogSecIDBuf = NULL;
	UINT8 retValue = CI_ERROR;

	if ((0U != switchId) && (SWITCH_SUM_MAX > switchId) && (NULL != pLogSecId) && (NULL != pLogState))
	{
		/*获取道岔关联逻辑区段信息*/
		wLogSecSum = GetSwitchLogSecSum(switchId);
		pLogSecIDBuf = GetSwitchLogSecBuf(switchId);

		if ((0U != wLogSecSum) && (NULL != pLogSecIDBuf))
		{
			/*检查逻辑区段临时限速状态*/
			for (i = 0U; i < wLogSecSum; i++)
			{
				cLogSecLockState = GetLogSecLinShiXianSuSetState(pLogSecIDBuf[i]);
				if ((LOGSEC_LSXS_SET_STATE_NO == cLogSecLockState)
					|| (LOGSEC_LSXS_SET_STATE_INVALID == cLogSecLockState))
				{
					retValue = CI_SUCCESS;
				}
				else
				{
					*pLogSecId = pLogSecIDBuf[i];
					*pLogState = cLogSecLockState;
					retValue = CI_ERROR;
					break;
				}
			}
		}
		else
		{
			/*返回失败*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return retValue;
}

/*
* 功能描述： 进路照查容忍条件满足检查
* 参数说明： UINT16 const routeId,  进路号
* 返回值  ： CI_ERROR 失败
*            CI_SUCCESS 成功
*			 RES_CHECK_STATE_WAITE 等待
* by cgh 20230930
*/
UINT8 KeepSignalRelayZhaoChaCheck(UINT16 const routeId)
{
	UINT8 chRetVal = CI_ERROR; /*函数返回值*/
	UINT16 wSelfRealyId = 0U;/*当前级别本端照查继电器ID*/
	UINT8 chRelayCollState = 0U;/*继电器采集状态*/
	UINT8 checkRelayRes = 0U;/*继电器驱动超时检查结果*/
	UINT8 chRouteState = 0U;/*进路状态*/
	UINT32 dwRouteLockStartCyc = 0U;/*进路锁闭起始周期*/

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

	if (0U < wSelfRealyId)
	{
		chRelayCollState = GetRelayCollState(wSelfRealyId);   /*获取指定ID继电器的状态*/
			/*两者均有效，此时不容忍直接判断*/
		if (RELAY_STATE_UP == chRelayCollState)
		{
			chRouteState = GetRouteState(routeId);

			if (ROUTE_STATE_HALF_UNLOCK == chRouteState)
			{
				dwRouteLockStartCyc = GetRouteLockStartCycNum(routeId);
				checkRelayRes = SystemOverTimeCheck(dwRouteLockStartCyc, RELAY_DRIVE_MAX_NUM);
				if (CI_TIME_IN == checkRelayRes)
				{
					/*照查继电器状态驱动落下容忍10周期，计时内返回成功*/
					chRetVal = RES_CHECK_STATE_WAITE;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				chRetVal = CI_ERROR;
			}
		}
		else if (RELAY_STATE_DOWN == chRelayCollState)
		{
			chRetVal = CI_SUCCESS;
		}
		else
		{
			/*采集状态非法*/
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		/*本级别本端照查继电器无效，检查通过*/
		chRetVal = CI_SUCCESS;
	}
	return chRetVal;
}

/*
* 功能描述： 检查物理区段对应逻辑区段是否存在锁闭所属进路
* 参数说明： const UINT16 phySectionId  物理区段ID
* 返回值  ： 逻辑区段锁闭所属进路
* cgh-20231002创建
*/
UINT16 CheckLogSecLockBelongRoute(const UINT16 phySectionId)
{
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT8 ii = 0U;               /*物理区段包含逻辑区段循环索引*/
	UINT16 wLogLockBelongRouteId = 0U;  /*逻辑区段锁闭所属进路ID*/
	UINT16 chReval = 0U;

	chPhyIncLogSum = GetPhySecIncLogSecSum(phySectionId);
	pPhyIncLogId = GetPhySecIncLogSecIdBuf(phySectionId);

	if (NULL != pPhyIncLogId)
	{
		for (ii = 0U; ii < chPhyIncLogSum; ii++)
		{
			wLogLockBelongRouteId = GetLogSecLockBelongRoute(pPhyIncLogId[ii]);
			if ((0U < wLogLockBelongRouteId) && (ROUTE_SUM_MAX > wLogLockBelongRouteId))
			{
				chReval = wLogLockBelongRouteId;
				break;
			}
			else
			{
				/*继续查找*/
			}
		}
	}
	return chReval;
}

/*
* 功能描述： 逻辑区段故障解锁
* 参数说明： UINT16 const wLogSecId 逻辑区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_UNLOCK_FAULT_LOGSEC
* by cgh 20231004
*/
UINT8 LogSecFaultUnlockLogicProcess(UINT16 const wLogSecId)
{
	UINT8 chResult = CI_ERROR;
	UINT8 const chFunctionId = EFUNC_UNLOCK_FAULT_LOGSEC;/*函数故障码*/
	UINT8 chLogSecLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 chCheckResult = 0U;/*逻辑检查结果*/
	UINT8 chSendLevel = ESEND_LEVEL_ATS;/*报警发送等级-ATS*/
	UINT8 chTransmitState = 0U;/*与其他联锁通信状态*/
	UINT8 chLogSecBelongCiId = 0U;/*逻辑区段所属联锁*/
	UINT8 chFuncSwitch = 0U; 	/*相邻联锁是否支持继电接口*/
	UINT8 chLocalCi = 0U;/*本机联锁ID*/
	UINT8 chConfirmRelayInterfaceFlag = 0U;/*继电接口确认状态*/
	UINT16 wLogSecLockBelongRouteId = 0U;/*逻辑区段锁闭所属进路ID*/
	UINT8 chRouteBelongCi = 0U;/*进路所属联锁*/
	UINT16 wLogSecBelongPhySecId = 0U;/*逻辑区段所属物理区段ID*/
	UINT16 wCancleZhaoChaRelayId = 0U;/*取消照查继电器ID*/
	UINT8 chRelayCollState = 0U;/*继电器采集状态*/
	UINT8 chOtherCiId = 0U;/*其它联锁ID*/
	UINT8 chExecRes = 0U;/*执行逻辑检查结果*/
	UINT8 chCommState = 0U;/*本联锁与其它联锁通信通信状态*/

	chFuncSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	chLocalCi = GetSystemParaLocalCiId();
	chConfirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();
	chLogSecBelongCiId = GetLogSecBelongCiId(wLogSecId);
	wLogSecLockBelongRouteId = GetLogSecLockBelongRoute(wLogSecId);
	chRouteBelongCi = GetRouteBelongCiId(wLogSecLockBelongRouteId);/*获取进路所属联锁*/
	chTransmitState = GetLocalCiAndOtherCiTransSta(chLogSecBelongCiId);

	/*联锁检查*/
	/*区段锁闭状态*/
	chCheckResult = GetLogSecLockState(wLogSecId);
	if (LOG_SECTION_LOCK_EXCEPT == chCheckResult)
	{
		chResult = CI_SUCCESS;
	}
	else
	{
		SetErrorData(chFunctionId, CI_DEVICE_TYPE_LOGICSEC, wLogSecId, ETYPE_LOGSEC_LOCK_STATE, chCheckResult, chSendLevel);
		chResult = CI_ERROR;
	}

	/*区段空闲*/
	if (CI_SUCCESS == chResult)
	{
		wLogSecBelongPhySecId = GetLgcSecRelativePhySecId(wLogSecId);
		/*进路为本联锁，区段为相邻联锁，且继电接口下，不检查区段占用*/
		if ((chLocalCi == chRouteBelongCi) && (chLocalCi != chLogSecBelongCiId) &&
			(TRANSMIT_STATE_BAD == chTransmitState) && (CICI_RELAY_INTERFACE_CONFIRM_YES == chConfirmRelayInterfaceFlag)
			&& (FUNC_SWITCH_ON == chFuncSwitch))
		{
			chResult = CI_SUCCESS;
		}
		else
		{
			chCheckResult = GetPhySecCurMergeState(wLogSecBelongPhySecId);
			if (SECTION_OCCUPY_NO == chCheckResult)
			{
				/* 通过检查 */
				chResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(chFunctionId, CI_DEVICE_TYPE_PHYSEC, wLogSecBelongPhySecId, ETYPE_PS_MERGY_OCU_STATE, chCheckResult, chSendLevel);
				/* 失败返回 */
				chResult = CI_ERROR;
			}
		}

	}

	/*取消照查继电器为吸起*/
	if (CI_SUCCESS == chResult)
	{
		wCancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(wLogSecLockBelongRouteId); /*取消照查继电器ID*/
		
		if ((0U != wCancleZhaoChaRelayId) && (0xFFFFU != wCancleZhaoChaRelayId))
		{
			if ((chLocalCi == chLogSecBelongCiId) && (chLocalCi != chRouteBelongCi) &&
				(TRANSMIT_STATE_BAD == chTransmitState) &&
				(CICI_RELAY_INTERFACE_CONFIRM_YES == chConfirmRelayInterfaceFlag) &&
				(FUNC_SWITCH_ON == chFuncSwitch))
			{
				/*如果区段所属联锁为本联锁，进路所属联锁与本联锁不同，且本联锁与进路所属联锁通信中断，且运营人员已下发确认继电接口命令，
					且已配置支持继电接口，则可以不检查该区段取消照查继电器状态*/
				chResult = CI_SUCCESS;
			}
			else
			{
				/*取消继电器有效：取消继电器采集状态为：吸起*/
				chRelayCollState = GetRelayCollState(wCancleZhaoChaRelayId);/*获取取消继电器采集状态*/
				if (RELAY_STATE_UP == chRelayCollState)
				{
					/* 通过检查 */
					chResult = CI_SUCCESS;

				}
				else
				{
					/* 记录故障码 */
					SetErrorData(chFunctionId, CI_DEVICE_TYPE_RELAY, wCancleZhaoChaRelayId, ETYPE_CANCLE_ZHAOCHA, chRelayCollState, chSendLevel);
					/* 失败返回 */
					chResult = CI_ERROR;
				}
			}
		}
	}

	/*继电接口取消照查继电器为吸起*/
	if (CI_SUCCESS == chResult)
	{
		/*继电取消照查*/
		wCancleZhaoChaRelayId = GetRouteCancleZCRelayId(wLogSecLockBelongRouteId);
		chExecRes = RouteHavePhySecBelongOtherCi(wLogSecLockBelongRouteId, &chOtherCiId);

		if ((0U != wCancleZhaoChaRelayId) && (0xFFFFU != wCancleZhaoChaRelayId))
		{
			if (chRouteBelongCi == chLocalCi)
			{/*进路属于本联锁*/
				if ((CI_SUCCESS == chExecRes) && (0U < chOtherCiId) && (chOtherCiId != chRouteBelongCi))
				{
					chCommState = GetLocalCiAndOtherCiTransSta(chOtherCiId);/*本联锁与其它联锁通信通信状态*/
					if ((TRANSMIT_STATE_BAD == chCommState) &&
						(FUNC_SWITCH_ON == chFuncSwitch))
					{/*进路属于本联锁的才需要检查*/
						if (CICI_RELAY_INTERFACE_CONFIRM_YES == chConfirmRelayInterfaceFlag)
						{
							/*如果本联锁与其它联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则需要检查继电接口下取消照查继电器状态*/
							chResult = CI_SUCCESS;

							/*取消继电器有效：取消继电器采集状态为：吸起*/
							chRelayCollState = GetRelayCollState(wCancleZhaoChaRelayId);/*获取取消继电器采集状态*/
							if (RELAY_STATE_UP == chRelayCollState)
							{
								/* 通过检查 */
								chResult = CI_SUCCESS;

							}
							else
							{
								/* 记录故障码 */
								SetErrorData(chFunctionId, CI_DEVICE_TYPE_RELAY, wCancleZhaoChaRelayId, ETYPE_CANCLE_ZHAOCHA, chRelayCollState, chSendLevel);
								/* 失败返回 */
								chResult = CI_ERROR;
							}
						}
						else
						{/*没有确认，不准区故解，检查失败*/
							chResult = CI_ERROR;
							debug_infor_printf((const)"LogSectionFaultUnlockLogicProcess error,not Confirm.\n");
						}
					}
				}
			}
			else
			{/*进路不属于本联锁，不需要检查*/

			}
		}
	}
	return chResult;
}

/*
* 功能描述： 物理区段区故解锁闭进路检查
* 参数说明： const UINT16 wPhySectionId  物理区段ID
*			 const UINT8 chVirCIid 虚拟联锁ID
* 返回值  ： CI_ERROR  检查不通过
*			 CI_SUCCESS 检查通过
* cgh-20231011创建
*/
UINT8 PhySecFaultUnlockRouteCheck(const UINT16 wPhySectionId, const UINT8 chVirCIid)
{
	UINT8 chReval = CI_ERROR;
	UINT16 wPhySecLockBelRouteId = 0U;  /*物理区段锁闭所属进路ID*/
	UINT16 wLogLockBelongRouteId = 0U;  /*逻辑区段锁闭所属进路ID*/
	UINT8 chLogLockBelLogRouteCheck = 0U; /*逻辑区段锁闭所属逻辑进路检查*/

	if ((0U == wPhySectionId) || (PHYSICAL_SECTION_SUM_MAX < wPhySectionId))
	{
		/*物理区段ID无效*/
		chReval = CI_ERROR;
	}
	else
	{
		wPhySecLockBelRouteId = GetPhySecRLockBelongRouteId(wPhySectionId);  /*获取物理区段进路锁闭所属进路ID*/
		chLogLockBelLogRouteCheck = CheckLogSecLockExistLogRoute(wPhySectionId);

		if (ROUTE_SUM_MAX < wPhySecLockBelRouteId)
		{
			/*锁闭所属进路ID无效*/
			chReval = CI_ERROR;
			SetCiSendCmdBackInfoData(CI_BACK_PSEC_LOCK_NO, CI_DEVICE_TYPE_PHYSEC, wPhySectionId, 0U, 0U);
		}
		else if (0U == wPhySecLockBelRouteId)
		{
			/*物理区段锁闭所属进路为0，（1）可能是任意位置折返列车完全开出进路释放，此时可能有逻辑区段锁闭所属进路（2）可能是只办理了逻辑进路*/
			/*以上情况不继续执行物理区段的区段故障解锁逻辑，执行逻辑区段故障解锁*/
			chReval = CI_ERROR;
			wLogLockBelongRouteId = CheckLogSecLockBelongRoute(wPhySectionId);
			if (((0U == wLogLockBelongRouteId) || (ROUTE_SUM_MAX < wLogLockBelongRouteId)) && (CI_ERROR == chLogLockBelLogRouteCheck))
			{
				SetCiSendCmdBackInfoData(CI_BACK_PSEC_LOCK_NO, CI_DEVICE_TYPE_PHYSEC, wPhySectionId, 0U, 0U);
			}
			else
			{
				LogicSecFaultUnlockLogicManage(wPhySectionId, chVirCIid);
			}

		}
		else
		{
			/*物理区段存在锁闭所属进路，如果可能存在逻辑进路与普通进路叠加办理*/
			if (CI_SUCCESS == chLogLockBelLogRouteCheck)
			{
				chReval = CheckPhyAllLogSecExceptLockSta(wPhySectionId);
			}
			else
			{
				/*只有物理区段存在锁闭所属进路，继续往下执行（执行正常区故解和部分路径区故解逻辑）*/
				chReval = CI_SUCCESS;
			}
			if (CI_ERROR == chReval)
			{
				SetErrorData(EFUNC_PHYSEC_FAULT_BELONG_ROUTE, CI_DEVICE_TYPE_PHYSEC, wPhySectionId,
					ETYPE_PS_LJJL_PHYJL_ALL_NAMAL, chReval, ESEND_LEVEL_ZERO);

				/*如果检查不通过，关闭普通进路信号及逻辑进路有效的信号*/
				SecFaultUnlockDrvRelSigClose(wPhySectionId);
			}
		}
	}
	return chReval;
}

/*
* 功能描述： 检查物理区段对应逻辑区段是否存在锁闭所属逻辑进路
* 参数说明： const UINT16 wPhySectionId  物理区段ID
* 返回值  ： CI_ERROR  不存在
*            CI_SUCCESS  存在
* cgh-20231011创建
*/
UINT8 CheckLogSecLockExistLogRoute(const UINT16 wPhySectionId)
{
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT8 ii = 0U;               /*物理区段包含逻辑区段循环索引*/
	UINT8 wLogLockBelLogRouteSum = 0U;  /*逻辑区段锁闭所属逻辑进路数目*/
	UINT8 chReval = CI_ERROR;

	chPhyIncLogSum = GetPhySecIncLogSecSum(wPhySectionId);
	pPhyIncLogId = GetPhySecIncLogSecIdBuf(wPhySectionId);

	if (NULL != pPhyIncLogId)
	{
		for (ii = 0U; ii < chPhyIncLogSum; ii++)
		{
			wLogLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(pPhyIncLogId[ii]);
			if (0U < wLogLockBelLogRouteSum)
			{
				chReval = CI_SUCCESS;
				break;
			}
			else
			{
				/*继续查找*/
			}
		}
	}
	return chReval;
}

/*
* 功能描述： 检查物理区段对应逻辑区段异常逻辑锁闭状态
* 参数说明： const UINT16 wPhySectionId  物理区段ID
* 返回值  ： CI_ERROR    全部为正常锁闭
*            CI_SUCCESS  有一个为故障锁闭或者无锁闭所属逻辑进路
* cgh-20231011创建
*/
UINT8 CheckPhyAllLogSecExceptLockSta(const UINT16 wPhySectionId)
{
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT8 ii = 0U;               /*物理区段包含逻辑区段循环索引*/
	UINT8 wLogLockBelLogRouteSum = 0U;  /*逻辑区段锁闭所属逻辑进路数目*/
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT8 chLogSecLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 chReval = CI_ERROR;

	if ((0u == wPhySectionId) || (PHYSICAL_SECTION_SUM_MAX < wPhySectionId))
	{
		/*物理区段ID无效*/
		chReval = CI_ERROR;
	}
	else
	{
		chPhyIncLogSum = GetPhySecIncLogSecSum(wPhySectionId);
		pPhyIncLogId = GetPhySecIncLogSecIdBuf(wPhySectionId);

		if ((NULL != pPhyIncLogId) && ((0U < chPhyIncLogSum) && (PHYSICAL_INCLUDE_LOG_SUM_MAX > chPhyIncLogSum)))
		{
			for (ii = 0U; ii < chPhyIncLogSum; ii++)
			{
				wLogLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(pPhyIncLogId[ii]);
				chLogSecLockState = GetLogSecLockState(pPhyIncLogId[ii]);

				if (0U != wLogLockBelLogRouteSum)
				{
					chReval = CI_ERROR;
					chLogSecLogLockState = GetLogSecLogLockState(pPhyIncLogId[ii]);

					if ((LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState) && (LOG_SECTION_LOCK_NORMAL == chLogSecLockState))
					{
						break;
					}
					else if ((LOG_SECTION_LOGLOCK_EXCEPT == chLogSecLogLockState) && (LOG_SECTION_LOCK_NORMAL == chLogSecLockState))
					{
						/*动态进路异常锁闭，普通进路未异常锁闭，该场景不存在，若异常发生，则不可区故解，宕机*/
						SetPlatOverFlag(); /*设置平台宕机*/
						SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_LOGICSEC, pPhyIncLogId[ii], ETYPE_PS_LJJL_NAMAL_BUT_LOGEXCEPT, LOG_SECTION_LOCK_NORMAL, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
						break;
					}
					else
					{
						;/*其他情况允许区故解*/
					}
				}
				else
				{
					;/*当前逻辑区段无逻辑锁闭进路，继续检查*/
				}
			}

			if (chPhyIncLogSum == ii)
			{
				chReval = CI_SUCCESS;
			}
			else
			{
				chReval = CI_ERROR;
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	return chReval;
}

/*
* 功能描述： 检查拆分的序列数量及其包含逻辑区段数量是否超限
* 参数说明： const UINT8 cSeqNum 序列数量
*            const UINT8 pSeqIncLogSecNum[] 各序列包含的逻辑区段数量
* 返回值  ： CI_ERROR    失败
*            CI_SUCCESS  成功
* Created By LQ 2023/10/12
*/
UINT8 SeqNumAndIncLogSecNumCheck(const UINT8 cSeqNum, const UINT8 pSeqIncLogSecNum[])
{
	UINT8 retVal = CI_ERROR;
	UINT8 ii = 0U;

	if ((ROUTE_SUBROUTE_SUM_MAX > cSeqNum) && (NULL != pSeqIncLogSecNum))
	{
		if (0U != cSeqNum)
		{
			for (ii == 0U; ii < cSeqNum; ii++)
			{
				if ((MAX_ROUTE_IN_LT_NUM > pSeqIncLogSecNum[ii]))
				{
					retVal = CI_SUCCESS;
				}
				else
				{
					retVal = CI_ERROR;  /*越界，返回失败*/
					break;
				}
			}
		}
		else
		{
			retVal = CI_SUCCESS;  /*序列数量为0，返回成功*/
		}
	}
	else
	{
		/*返回失败*/
	}

	return retVal;
}

/*
* 功能描述： 校验指定动态进路子进路是否为半截进路
* 参数说明： const UINT8 cIndex 子进路索引
*            const UINT16 pRouteId[] 子进路ID数组
*            const UINT16 pCTOccLogSecNum CT脚下逻辑区段数量
*            const UINT16 pCTOccLogSecId[] CT脚下逻辑区段ID数组
*            const UINT8 cLogicRouteFlag 第一个序列是否为逻辑进路的标志
* 返回值  ： CI_ERROR    非半截进路
*            CI_SUCCESS  半截进路
* Created By LQ 2023/10/12
*/
UINT8 HalfRouteTypeCheck(const UINT8 cIndex, const UINT16 pRouteId[], const UINT16 pCTOccLogSecNum, const UINT16 pCTOccLogSecId[], const UINT8 cLogicRouteFlag)
{
	UINT8 retVal = CI_ERROR;
	UINT16 i = 0U;
	UINT16 j = 0U;
	UINT16 cRouteIncLogSecSum = 0U;  /*进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecIdBuff = NULL;   /*进路包含的逻辑区段ID数组*/
	UINT8 cCTOccFlag = FLAG_UNSET;  /*列车占压标志，初始化为无车占压*/

	if ((ROUTE_SUBROUTE_SUM_MAX > cIndex) && (NULL != pRouteId) && (SIZE_MAX_SECTION_BT_TRAIN > pCTOccLogSecNum) && (NULL != pCTOccLogSecId)
		&& ((FLAG_SET == cLogicRouteFlag) || (FLAG_UNSET == cLogicRouteFlag)))
	{
		/*判断进路内是否有列车占压*/
		if (0U != pCTOccLogSecNum)
		{
			cRouteIncLogSecSum = GetRouteLogSectionSum(pRouteId[cIndex]);
			pRouteIncLogSecIdBuff = GetRouteLogSectionIdBuf(pRouteId[cIndex]);
			for (i = 0U; i < cRouteIncLogSecSum; i++)
			{
				for (j = 0U; j < pCTOccLogSecNum; j++)
				{
					if (pRouteIncLogSecIdBuff[i] == pCTOccLogSecId[j])
					{
						cCTOccFlag = FLAG_SET;  /*有车占压，置上标志*/
						break;
					}
					else
					{
						cCTOccFlag = FLAG_UNSET; 
					}
				}

				if (FLAG_SET == cCTOccFlag)
				{
					break;  /*有车占压，停止遍历*/
				}
				else
				{
					/*继续遍历*/
				}
			}
		}
		else
		{
			cCTOccFlag = FLAG_UNSET;
		}

		if (0U != cIndex)
		{
			if (FLAG_UNSET == cCTOccFlag)
			{
				retVal = CI_ERROR;  /*无车占压，匹配的进路应为完整子进路*/
			}
			else
			{
				retVal = CI_SUCCESS;  /*有车占压，匹配的进路应为半截子进路*/
			}
			
		}
		else
		{
			if ((FLAG_SET == cLogicRouteFlag) && (FLAG_UNSET == cCTOccFlag))
			{
				retVal = CI_ERROR;  /*第一个序列为逻辑进路且无车占压时，匹配的首条进路应为完整子进路*/
			}
			else
			{
				retVal = CI_SUCCESS;  /*第一个序列非逻辑进路或有车占压时，匹配的首条进路应为半截子进路*/
			}
		}
	}
	else
	{
		/*入参非法，不处理*/
	}

	return retVal;
}

/*
* 功能描述： 保护区段包含的逻辑区段逻辑锁闭状态有效性检查
* 参数说明： const UINT16 overlapId 保护区段ID
*            const UINT16 routeId 保护区段防护锁闭所属进路ID
*            UINT16 *pDevId 设备Id（返回）
*            UINT8 *pDevState 设备状态（返回）
* 返回值  ： CI_ERROR 失败
*            CI_SUCCESS 成功
* Created By LQ 2023/10/14
*/
UINT8 OverlapLogSecLogicLockCheck(const UINT16 overlapId, const UINT16 routeId, UINT16* pDevId, UINT8* pDevState)
{
	UINT8 reVal = CI_ERROR;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT16 wLogSecId = 0U;
	UINT8  wLogSecLogicLockState = 0U;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogSecLogicLockDir = 0U;  /*逻辑区段逻辑锁闭方向*/
	UINT8 cLogicLockBelongRouteNum = 0U;  /*逻辑区段逻辑锁闭所属进路数量*/
	UINT8 cChangeInRoute = 0U;  /*进路中的方向变化点标志*/
	UINT8 cChangeAfterRoute = 0U;  /*进路与保护区段间的方向变化点标志*/
	UINT8 cRouteDir = 0U;  /*进路方向*/
	UINT8 cOverlapIncPhySecNum = 0U;  /*保护区段包含的物理区段数量*/
	UINT16* pOverlapIncPhySecId = NULL;  /*保护区段包含的物理区段ID数组*/
	UINT8 wPhySecIncLogSecNum = 0U;  /*物理区段包含的逻辑区段数量*/
	UINT16* pPhySecIncLogSecID = NULL;  /*物理区段包含的逻辑区段ID数组*/

	if ((0U < overlapId) && (OVERLAP_SUM_MAX > overlapId) && (0U < routeId) && (ROUTE_SUM_MAX > routeId) && (NULL != pDevId) && (NULL != pDevState))
	{
		cOverlapIncPhySecNum = GetOverlapPhySecSum(overlapId);
		pOverlapIncPhySecId = GetOverlapPhySecIdBuf(overlapId);

		if ((0U != cOverlapIncPhySecNum) && (NULL != pOverlapIncPhySecId))
		{
			/*获取进路方向及是否有方向变化点*/
			cRouteDir = GetRouteDirection(routeId);
			cChangeInRoute = GetRouteHaveDirChangePointIn(routeId);
			cChangeAfterRoute = GetRouteHaveDirChangePointAfter(routeId);			

			 /*校验保护区段内所有逻辑区段【未逻辑锁闭】或与进路同方向的【逻辑正常锁闭】*/
			for (i = 0U; i < cOverlapIncPhySecNum; i++)
			{
				wPhySecIncLogSecNum = GetPhySecIncLogSecSum(pOverlapIncPhySecId[i]);
				pPhySecIncLogSecID = GetPhySecIncLogSecIdBuf(pOverlapIncPhySecId[i]);

				if ((0U != wPhySecIncLogSecNum) && (NULL != pPhySecIncLogSecID))
				{
					for (j = 0U; j < wPhySecIncLogSecNum; j++)
					{
						wLogSecId = pPhySecIncLogSecID[j];
						wLogSecLogicLockState = GetLogSecLogLockState(wLogSecId);
						cLogicLockBelongRouteNum = GetLogSecLockBelLogRouteSum(wLogSecId);

						if ((LOG_SECTION_LOGLOCK_NO == wLogSecLogicLockState) && (0U == cLogicLockBelongRouteNum))
						{
							reVal = CI_SUCCESS;  /*未逻辑锁闭且逻辑锁闭所属进路数量为0，返回成功*/
						}
						else if (LOG_SECTION_LOGLOCK_NORMAL == wLogSecLogicLockState)
						{
							/*逻辑正常锁闭时（（进路无方向变化点且锁闭方向与进路方向相同）或（进路有方向变化点且锁闭方向与进路方向不相同）），返回成功*/
							cLogSecLogicLockDir = GetLogSecLogLockDir(wLogSecId);
							if (((((ROUTE_HAVE_DIR_CHANGE_POINT != cChangeInRoute) && (ROUTE_HAVE_DIR_CHANGE_POINT != cChangeAfterRoute)) && (cRouteDir == cLogSecLogicLockDir))
								|| (((ROUTE_HAVE_DIR_CHANGE_POINT == cChangeInRoute) || (ROUTE_HAVE_DIR_CHANGE_POINT == cChangeAfterRoute)) && (cRouteDir != cLogSecLogicLockDir)))
								&& (CI_ERROR != cRouteDir) && (CI_ERROR != cLogSecLogicLockDir))

							{
								reVal = CI_SUCCESS;
							}
							else
							{
								*pDevId = wLogSecId;
								*pDevState = wLogSecLogicLockState;
								reVal = CI_ERROR;  /*状态非法,返回失败*/
							}
						}
						else
						{							
							*pDevId = wLogSecId;
							*pDevState = wLogSecLogicLockState;
							reVal = CI_ERROR;  /*状态非法,返回失败*/
						}

						if (CI_ERROR == reVal)
						{
							break;  /*存在逻辑区段检查未通过，停止检查，返回失败*/
						}
						else
						{
							/*继续检查*/
						}
					}
				}
				else
				{
					/*获取物理区段包含的逻辑区段失败，返回失败*/
				}

				if (CI_ERROR == reVal)
				{
					break;  /*存在逻辑区段检查未通过，停止检查，返回失败*/
				}
			}
		}
		else
		{
		    /*获取保护区段包含的物理区段失败，返回失败*/
        }
	}

	return reVal;
}

/*
* 功能描述： 进路包含的逻辑区段逻辑锁闭状态检查
* 参数说明： const UINT16 routeId 进路ID
*            UINT16 *pDevId 设备Id（返回）
*            UINT8 *pDevState 设备状态（返回）
* 返回值  ： CI_ERROR 失败
*            CI_SUCCESS 成功
* Created By LQ 2023/10/14
*/
UINT8 RouteIncLogSecLogicLockCheck(const UINT16 routeId, UINT16* pDevId, UINT8* pDevState)
{
	UINT8 reVal = CI_ERROR;
	UINT16 i = 0U;
	UINT16 wLogSecId = 0U;
	UINT16 cRouteIncLogSecNum = 0U;  /*进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecId = NULL;  /*进路包含的逻辑区段ID数组*/	
	UINT8  cLogicLockState = 0U;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogicLockBelongRouteNum = 0U;  /*逻辑区段逻辑锁闭所属进路数量*/

	if ((0U < routeId) && (ROUTE_SUM_MAX > routeId) && (NULL != pDevId) && (NULL != pDevState))
	{
		cRouteIncLogSecNum = GetRouteLogSectionSum(routeId);
		pRouteIncLogSecId = GetRouteLogSectionIdBuf(routeId);

		if ((0U != cRouteIncLogSecNum) && (NULL != pRouteIncLogSecId))
		{
			for (i = 0U; i < cRouteIncLogSecNum; i++)
			{
				wLogSecId = pRouteIncLogSecId[i];
				cLogicLockState = GetLogSecLogLockState(wLogSecId);  /*获取逻辑区段逻辑锁闭状态*/
				cLogicLockBelongRouteNum = GetLogSecLockBelLogRouteSum(wLogSecId);  /*获取逻辑区段逻辑锁闭所属进路数量*/

				/*逻辑区段未逻辑锁闭且锁闭所属逻辑进路数量为0，返回成功，否则返回失败*/
				if ((LOG_SECTION_LOGLOCK_NO == cLogicLockState) && (0U == cLogicLockBelongRouteNum))
				{
					reVal = CI_SUCCESS;
				}
				else
				{
					*pDevId = wLogSecId;
					*pDevState = cLogicLockState;
					reVal = CI_ERROR;  /*逻辑区段存在逻辑锁闭，停止遍历，返回失败*/
				}

				if (CI_ERROR == reVal)
				{
					break;  /*存在逻辑区段检查未通过，停止检查，返回失败*/
				}
				else
				{
					/*继续检查*/
				}
			}
		}
		else
		{
			/*获取进路包含的物理区段失败，返回失败*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return reVal;
}


/*
* 功能描述： 获取逻辑区段内所有列车信息
* 参数说明： UINT16 wLogSectionId
* 返回值  ： 列车数量
* By LC 20231116
*/
UINT8 GetLogSecTrainId(const UINT16 wLogSectionId, UINT16 * trainIdbuff)
{
	UINT8 cLogSecLinkSum = 0u;	/*逻辑区段包含Link数量*/
	UINT16* cLogSecLinkBuf = NULL;
	UINT8 i = 0U;
	UINT8 j = 0U;
	UINT8 k = 0U;
	TRAIN_SEQUANCE_s strTmp[SIZE_MAX_TRAINOFAC] = { 0u }; /*link上的列车序列*/
	UINT8 tmpTrainNum = 0U;
	UINT8 trainCount = 0U;


	cLogSecLinkSum = GetSecIntrudeLinkSum(wLogSectionId);
	cLogSecLinkBuf = GetSecIntrudeLinkIdBuf(wLogSectionId);
	if ((NULL != cLogSecLinkBuf) && (LOGSEC_INCLUDE_LINK_SUM_MAX > cLogSecLinkSum))
	{/*获取逻辑区段内列车数据*/
		for (i = 0u; i < cLogSecLinkSum; i++)
		{
			tmpTrainNum = as_GetLinkTrainNum(cLogSecLinkBuf[i]);

			/*获取Link上列车排序信息*/
			tmpTrainNum = as_GetLinkTrainList(cLogSecLinkBuf[i], strTmp, SIZE_MAX_TRAINOFAC);
			if (0u != tmpTrainNum)
			{
				for (j = 0U; j < tmpTrainNum; j++)
				{
					trainIdbuff[trainCount] = strTmp[j].u16TrainID;
					trainCount++;
				}
			}
		}
	}
	return trainCount;
}
/*
* 功能描述： 逻辑区段关联联络线设备条件检查
* 参数说明： UINT16 const wLgcId, 逻辑区段ID
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ：
*/
UINT8 LogicContactLineDevCheck(UINT16 const wLgcId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 wLgcSecContactLineCheckSum = 0U;
	LogsecContacSwitchStruct *pLgcSecContactSwitchCheck = NULL;
	UINT16 *pLogContactAxisCheckData = NULL;
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/

	wLgcSecContactLineCheckSum = GetLgcSecContactLineCheckSum(wLgcId);
	pLgcSecContactSwitchCheck = GetLgcSecContactSwitchCheckStru(wLgcId);
	pLogContactAxisCheckData = GetLogContactAxisCheckData(wLgcId);

	if ((NULL != pLgcSecContactSwitchCheck) && (NULL != pLogContactAxisCheckData))
	{
		if (0U == wLgcSecContactLineCheckSum)
		{
			chRetVal = CI_SUCCESS;		/*无联络线设备，返回成功，无需检查*/
		}
		else
		{
			chRetVal = CI_SUCCESS;
			for (ii = 0U; ii < wLgcSecContactLineCheckSum; ii++)
			{
				/*检查联络线道岔是否满足条件*/
				if (0U != pLgcSecContactSwitchCheck[ii].ContactSwitchId)
				{
					chRetVal = CheckLogContactSwitchState(pLgcSecContactSwitchCheck[ii].ContactSwitchId, pLgcSecContactSwitchCheck[ii].ContactSwitchCheckState, &devId, &devState);
				}

				/*检查联络线道岔区段占压是否满足条件*/
				if (CI_SUCCESS == chRetVal)
				{
					if (0U != pLogContactAxisCheckData[ii])
					{
						chRetVal = CheckLogContactOccState(pLogContactAxisCheckData[ii], &devId, &devState);
					}

					if (CI_ERROR == chRetVal)
					{
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
					}
				}
				else
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				}

				if (CI_ERROR == chRetVal)
				{
					break;	/*出现不满足即跳出*/
				}
			}
		}
	}
	else
	{
		;	/*逻辑区段不合法，返回失败*/
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段关联联络线道岔条件检查(同其他条件检查联络线道岔)
* 参数说明： UINT16 const wSwitchId, 道岔ID
*			 UINT8 const wState		道岔检查状态
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ：
*/
UINT8 CheckLogContactSwitchState(UINT16 const wSwitchId,UINT8 const wState, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT8 switchDsState = 0u;
	UINT8 switchBypassState = 0u;
	UINT8 switchPosState = 0u;
	UINT8 chRetVal = CI_ERROR;

	if ((OTHER_CI_CONNECT_SWITCH_YES == wState) || (OTHER_CI_CONNECT_SWITCH_NODSUO_YES == wState) || (OTHER_CI_CONNECT_SWITCH_NO == wState))
	{
		switchDsState = GetConnetSwitchDsState(wSwitchId);
		switchBypassState = GetConnetSwitchByPassState(wSwitchId);
		switchPosState = GetSwitchCurPosition(wSwitchId);
		if (OTHER_CI_CONNECT_SWITCH_YES == wState)
		{
			/*旁路，不检查*/
			if (SWITCH_BYPASS_YES == switchBypassState)
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				/*单锁且定位状态*/
				if ((CONNECT_SWITCH_DANSUO_YES == switchDsState) && (SWITCH_POSITION_DINGWEI == switchPosState))
				{
					chRetVal = CI_SUCCESS;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
		}
		else if (OTHER_CI_CONNECT_SWITCH_NODSUO_YES == wState)
		{
			/*旁路，不检查*/
			if (SWITCH_BYPASS_YES == switchBypassState)
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				/*定位状态*/
				if (SWITCH_POSITION_DINGWEI == switchPosState)
				{
					chRetVal = CI_SUCCESS;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
		}
		else
		{
			/*不处理*/
		}
	}

	if (CI_ERROR == chRetVal)
	{
		/* 记录故障码 */
		*pDevId = wSwitchId;
		*pDevState = switchPosState;
	}

	return chRetVal;
}

/*
* 功能描述： 逻辑区段关联联络线区段占压条件检查(同其他联锁条件检查计轴占压)
* 参数说明： UINT16 const wAxisId,  计轴区段ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 创建    ：
*/
UINT8 CheckLogContactOccState(UINT16 const wAxisId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT16 wPhySecId = 0U;
	UINT8 wPhySecOccState = 0u;
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0u;
	UINT8 axisSwitchSum = 0u;
	AxisSwitchStruct* axisSwitchStru = NULL;
	UINT8 switchBypassState = 0u;
	UINT8 switchCurPosition = 0u;
	UINT8 switchContactFlag = CI_SUCCESS;
	UINT8 devIsThisLine = 0u; /*设备是否本进路*/ 

	wPhySecId = GetAxisSecRelativePhySecId(wAxisId);
	wPhySecOccState = GetPhySecCurMergeState(wPhySecId);

	/*计轴区段相关的物理区段占用状态*/
	if (SECTION_OCCUPY_YES == wPhySecOccState)
	{
		axisSwitchSum = GetAxisSwitchSum(wAxisId);
		axisSwitchStru = GetAxisSwitchIdStru(wAxisId);
		if ((0u != axisSwitchSum) && (NULL != axisSwitchStru))
		{
			for (ii = 0u; ii < axisSwitchSum; ii++)
			{
				devIsThisLine = GetSwitchIsThisLineState(axisSwitchStru[ii].SwitchId);
				if (DEV_IS_THIS_LINE_NO == devIsThisLine)
				{
					switchBypassState = GetConnetSwitchByPassState(axisSwitchStru[ii].SwitchId);
					if (SWITCH_BYPASS_YES == switchBypassState)
					{
						switchContactFlag = CI_ERROR;			/*对方道岔区段占压，已旁路，无需检查*/
					}
					else
					{
						switchContactFlag = CI_SUCCESS;			/*对方道岔区段占压，未旁路，需要检查*/
					}
				}
				else
				{
					switchContactFlag = CI_SUCCESS;			/*设备为本线设备,需要检查道岔区段占压*/
				}

				if (CI_SUCCESS == switchContactFlag)
				{
					break;		/*当出现是本线路或者道岔未全旁路的，需要检查所有道岔是否满足条件*/
				}
			}

			for (ii = 0u; ii < axisSwitchSum; ii++)
			{
				if (CI_SUCCESS == switchContactFlag)
				{
					switchCurPosition = GetSwitchCurPosition(axisSwitchStru[ii].SwitchId);
					if ((axisSwitchStru[ii].SwitchPosition == switchCurPosition) ||
						(SWITCH_POSITION_SIKAI == switchCurPosition) || (SWITCH_POSITION_MOVE == switchCurPosition)
						|| (SWITCH_POSITION_JICHA == switchCurPosition))
					{/*判断当前计轴包含的道岔位置与道岔当前的位置是否都相同,或包含的道岔为四开，移动，挤岔*/
						chRetVal = CI_ERROR;
					}
					else
					{
						chRetVal = CI_SUCCESS;
						break;
					}
				}
				else
				{
					chRetVal = CI_SUCCESS;
					break;
				}
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else if (SECTION_OCCUPY_NO == wPhySecOccState)
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	if (CI_ERROR == chRetVal)
	{
		/* 记录故障码 */
		*pDevId = wPhySecId;
		*pDevState = wPhySecOccState;
	}
	return chRetVal;
}

/*
* 功能描述： 设置防淹门关门请求列车处理
* 参数说明：	UINT16 floodGateId		防淹门ID
* 返回值  ： CI_ERROR   混跑
*            CI_SUCCESS		纯CT车
*/
UINT8 SetFloodGateAcCloseApplyProc(UINT16 floodGateId)
{
	UINT16 axisSum = 0u;
	UINT16 *pAxisIdBuf = NULL;
	UINT8 reResult = CI_ERROR;
	UINT16 axisId = 0u;	/*计轴区段ID*/
	UINT16 phyId = 0U;	/*物理区段ID*/
	UINT8 phyOccupyState = 0u;/*临时变量：物理区段占用状态*/
	UINT16 ii = 0u;
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT8 mm = 0U;
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 cAxisLinkSum = 0U;
	UINT16 *pAxisLinkIdBuf = NULL;
	UINT16 wAxisLinkId = 0U;
	UINT8 linkIndex = 0U;
	UINT8 chTrainSum = 0U;
	TRAIN_SEQUANCE_s TrainList[FLOOD_GATE_APPLY_TRAIN_SUM_MAX] = { 0u };
	UINT8 chTrainIndex = 0U;

	UINT8 chTempTrainSum = 0U;		/*临时存储变量*/
	UINT16 TempTrainIdBuf[FLOOD_GATE_APPLY_TRAIN_SUM_MAX] = { 0U };

	bufIndex = GetFloodGateBufIndex(floodGateId);  /*获取防淹门数组下标*/
	axisSum = GetFloodGateAccessAxisNum(floodGateId);
	pAxisIdBuf = GetFloodGateAccessAxisIDBuf(floodGateId);

	if (NULL == pAxisIdBuf)
	{
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		SetFloodGateCloseApplyIvocSum(floodGateId, 0U);		/*先出清，防止已存在过的申请，脏数据*/
		SetFloodGateCloseApplyIvocId(floodGateId, TempTrainIdBuf);
		ClearFloodGateAllowClosFlagIVOC(floodGateId);		/*再一次申请前，出清之前已经回复过的列车数据*/
		for (ii = 0u; ii < axisSum; ii++)
		{
			axisId = pAxisIdBuf[ii];
			phyId = GetAxisSecRelativePhySecId(axisId);	/*获取计轴关联物理区段，取融合占压*/
			if ((0U < axisId) && (0U < phyId))
			{
				phyOccupyState = GetPhySecCurMergeState(phyId);
				if (SECTION_OCCUPY_YES == phyOccupyState)
				{
					/*获取计轴区段包含的包络，如果存在非CT包络，说明有非通信车混跑，跳出循环*/
					cAxisLinkSum = GetAxisLinkSum(axisId);
					pAxisLinkIdBuf = GetAxisLinkIdBuf(axisId);
					if (NULL == pAxisLinkIdBuf)
					{
						reResult = CI_ERROR;
					}
					else
					{
						for (linkIndex = 0U; linkIndex < cAxisLinkSum; linkIndex++)
						{
							wAxisLinkId = pAxisLinkIdBuf[linkIndex];
							chTrainSum = as_GetLinkTrainList(wAxisLinkId, TrainList, FLOOD_GATE_APPLY_TRAIN_SUM_MAX);
							if (0u != chTrainSum)
							{
								for (chTrainIndex = 0u; chTrainIndex < chTrainSum; chTrainIndex++)
								{
									if (TYPE_CT == TrainList[chTrainIndex].u8TrainType)
									{
										for (kk = 0U; kk < chTempTrainSum; kk++)
										{
											if (TempTrainIdBuf[kk] == TrainList[chTrainIndex].u16TrainID)
											{
												break;		/*已经添加过的列车，无需再添加，去重*/
											}
											else
											{

											}
										}
										if (kk == chTempTrainSum)
										{
											TempTrainIdBuf[chTempTrainSum] = TrainList[chTrainIndex].u16TrainID;		/*添加申请的列车ID，到临时存储空间*/
											chTempTrainSum++;
										}
										reResult = CI_SUCCESS;
									}
									else
									{
										reResult = CI_ERROR;
										break;			/*有隐藏车，跳出循环*/
									}
								}
							}

							if (CI_ERROR == reResult)
							{
								break;		/*出现link包含隐藏车，跳出循环，不再查下一link*/
							}
						}
					}
					if (CI_ERROR == reResult)
					{
						break;		/*出现计轴混跑，跳出循环，返回混跑，不再查下一计轴*/
					}
				}
				else
				{
					reResult = CI_SUCCESS;
				}
			}
		}

		if (CI_SUCCESS == reResult)
		{
			SetFloodGateCloseApplyIvocSum(floodGateId, chTempTrainSum);		/*待所有接近区域的计轴都查询完无隐藏车时，存入要向列车发送的ID*/
			SetFloodGateCloseApplyIvocId(floodGateId, TempTrainIdBuf);
		}
	}

	return reResult;
}


/*
* 功能描述： 获取防淹门关门请求列车回复
* 参数说明：	UINT16 floodGateId		防淹门ID
* 返回值  ： CI_ERROR   不同意关门
*            CI_SUCCESS		同意关门
*/
UINT8 GetFloodGateAccessCloseAskIVOC(UINT16 floodGateId)
{
	UINT8 reResult = CI_ERROR;
	UINT8 wTrainSum = 0U;
	UINT16 *pTrainIdBuf = NULL;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT16 chTrainID = 0U;
	UINT8 FloodGateCloseFromIvocSum = 0U;
	FloodGateTrainAnsStruct *pFloodGatteAnsFromIvoc = NULL;
	UINT8 wTrainAnsFlag = 0U;
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetFloodGateBufIndex(floodGateId);  /*获取防淹门数组下标*/
	wTrainSum = GetFloodGateCloseApplyIvocSum(floodGateId);
	pTrainIdBuf = GetFloodGateCloseApplyIvocId(floodGateId);
	pFloodGatteAnsFromIvoc = GetFloodGateCloseFromIvocStru(floodGateId);
	FloodGateCloseFromIvocSum = GetFloodGateCloseAnsIvocSum(floodGateId);

	if ((0U < FloodGateCloseFromIvocSum) && (0U < wTrainSum) && (NULL != pTrainIdBuf) && (NULL != pFloodGatteAnsFromIvoc))
	{
		for (ii = 0U; ii < wTrainSum; ii++)
		{
			chTrainID = pTrainIdBuf[ii];

			for (jj = 0U; jj < FloodGateCloseFromIvocSum; jj++)
			{
				if (chTrainID == pFloodGatteAnsFromIvoc[jj].wTrainId)
				{
					wTrainAnsFlag = pFloodGatteAnsFromIvoc[jj].wFloodGateCloseIvocFlag;
					if (FLOOD_GATE_ALLOWCLOSE_IVOC == wTrainAnsFlag)
					{
						reResult = CI_SUCCESS;
						break;
					}
					else
					{
						reResult = CI_ERROR;	/*有一个列车未回复允许，则不可同意关门请求*/
					}
				}
				else
				{
					reResult = CI_ERROR;		/*当未查到所有回复的列车和之前申请的一致，返回失败*/
				}
			}	

			if (CI_ERROR == reResult)
			{
				break;	/*出错不再查下一个列车*/
			}
		}
	}

	return reResult;
}

/*
* 功能描述： 逻辑区段所在防淹门条件检查
* 参数说明：
*            UINT16 wLogicSecId,   逻辑区段编号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 FloodGateCheck(UINT16 wLogicSecId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;
	UINT16 wPhySecId = 0U;		/*物理区段ID*/
	UINT16 jj = 0U;
	UINT16 floodGateSum = 0U;		/*防淹门数量*/
	UINT16* floodGateIdBuf = NULL;/*临时变量*/
	UINT16 wFloodGateId = 0U;		/*防淹门ID*/
	UINT8 floodState = 0u;/*防淹门状态*/
	UINT8 FSwitchFlagOpenLock = 0U;
	UINT8 FSwitchFlagCloseReq = 0U;

	FSwitchFlagOpenLock = GetCiFunctionSwitchConfig(FUNC_FLOODGATE_NO_OPEN_LOCK_CHECK);
	FSwitchFlagCloseReq = GetCiFunctionSwitchConfig(FUNC_FLOODGATE_NO_CLOSE_REQ_CHECK);
	wPhySecId = GetLgcSecRelativePhySecId(wLogicSecId);			/*获取逻辑区段所属物理区段ID*/
	if (0U < wPhySecId)
	{
		floodGateSum = GetPhySecLocatedFloodSum(wPhySecId);		/*数量为0说明没有防淹门，无需检查，依旧返回成功*/
		if (0U < floodGateSum)
		{
			floodGateIdBuf = GetPhySecLocatedFloodId(wPhySecId);
			if (NULL != floodGateIdBuf)
			{
				for (jj = 0U; jj < floodGateSum; jj++)
				{
					wFloodGateId = floodGateIdBuf[jj];
					/*检查1：检查防淹门开启锁闭状态为开启锁闭*/
					if (FUNC_SWITCH_ON == FSwitchFlagOpenLock)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						floodState = GetFloodGateCurOpenLockState(wFloodGateId);
						if (FLOOD_GATE_OPENLOCK == floodState)
						{
							reResult = CI_SUCCESS;
						}
						else
						{
							reResult = CI_ERROR;
							SetErrorData(functionId, CI_DEVICE_TYPE_FLOODGATE, wFloodGateId, ETYPE_FLOODGATE_OPENLOCKSTATE, floodState, sendLevel);
						}
					}

					/*检查2：检查防淹门关门请求状态为未关门请求*/
					if (CI_SUCCESS == reResult)
					{
						if (FUNC_SWITCH_ON == FSwitchFlagCloseReq)
						{
							;	/*不检查*/
						}
						else
						{
							floodState = GetFloodGateCurCloseRequestSta(wFloodGateId);
							if (FLOOD_GATE_NOT_CLOSEREQ == floodState)
							{
								reResult = CI_SUCCESS;
							}
							else
							{
								reResult = CI_ERROR;
								SetErrorData(functionId, CI_DEVICE_TYPE_FLOODGATE, wFloodGateId, ETYPE_FLOODGATE_CLOSEREQSTATE, floodState, sendLevel);
							}
						}
					}

					/*检查3：检查防淹门当前同意关门输入状态为不同意关门*/
					if (CI_SUCCESS == reResult)
					{
						floodState = GetFloodGateCurAgreeCloseSta(wFloodGateId);
						if (FLOOD_GATE_NOT_AGREE_CLOSE == floodState)
						{
							reResult = CI_SUCCESS;
						}
						else
						{
							reResult = CI_ERROR;
							SetErrorData(functionId, CI_DEVICE_TYPE_FLOODGATE, wFloodGateId, ETYPE_FLOODGATE_AGREECLOSESTATE, floodState, sendLevel);
						}
					}

					if (CI_SUCCESS != reResult)
					{
						break;		/*有一个防淹门不满足条件，返回ERROR*/
					}
				}
			}
			else
			{
				reResult = CI_ERROR;		/*获取数据失败，反馈失败*/
			}
		}
		else
		{
			reResult = CI_SUCCESS;/*逻辑区段关联物理区段不包含防淹门ID，返回成功，无需检查防淹门条件*/
		}
	}
	return reResult;
}

/*
* 功能描述： 检查逻辑区段及锁闭所属进路的CBTC区域属性
* 参数说明： const UINT16 wLogSecId 逻辑区段ID
*            UINT8* pDevState 设备状态
* 返回值  ： CI_ERROR 0 不具有CBTC属性
*            CI_SUCCESS 1 具有CBTC属性
* Created By LQ 2023.12.08
*/
UINT8 CheckLogSecCbtcProperty(const UINT16 wLogSecId, UINT8* pDevState)
{
	UINT8 retVal = CI_ERROR;
	UINT8 cLogSecCbtcProperty = LOGSEC_CBTC_PROPERTY_NO;  /*逻辑区段CBTC区域属性*/
	UINT16 wLogSecRLockRouteId = 0U;  /*逻辑区段进路锁闭所属进路ID*/
	UINT16 wLogSecPLockRouteId = 0U;  /*逻辑区段防护锁闭所属进路ID*/
	UINT8 cRouteCbtcProperty = ROUTE_CBTC_PROPERTY_NO;  /*进路锁闭所属进路的CBTC区域属性*/

	if ((0U != wLogSecId) && (LOGIC_SECTION_SUM_MAX > wLogSecId) && (NULL != pDevState))
	{
		retVal = CI_SUCCESS;
		wLogSecRLockRouteId = GetLogSecLockBelongRoute(wLogSecId);
		wLogSecPLockRouteId = GetLogSecPLockRouteId(wLogSecId);

		if ((0U < wLogSecRLockRouteId) && (ROUTE_SUM_MAX > wLogSecRLockRouteId))
		{
			cLogSecCbtcProperty = GetLogSecCbtcProperty(wLogSecId);
			if (LOGSEC_CBTC_PROPERTY_YES == cLogSecCbtcProperty)
			{
				/*检查逻辑区段进路锁闭所属进路的CBTC区域属性*/
				cRouteCbtcProperty = GetRouteCbtcProperty(wLogSecRLockRouteId);
				if (ROUTE_CBTC_PROPERTY_YES == cRouteCbtcProperty)
				{
					/*进路具有CBTC区域属性，返回成功*/
				}
				else
				{
					retVal = CI_ERROR;  /*逻辑区段进路锁闭所属进路不具有CBTC区域属性，返回失败*/
				}
			}
			else
			{
				retVal = CI_ERROR;  /*逻辑区段不具有CBTC区域属性，返回失败*/
			}
		}
		else if ((0U < wLogSecPLockRouteId) && (ROUTE_SUM_MAX > wLogSecPLockRouteId))
		{
			/*检查逻辑区段防护锁闭所属进路的CBTC区域属性*/
			cRouteCbtcProperty = GetRouteCbtcProperty(wLogSecPLockRouteId);
			if (ROUTE_CBTC_PROPERTY_YES == cRouteCbtcProperty)
			{
				/*进路具有CBTC区域属性，返回成功*/
			}
			else
			{
				retVal = CI_ERROR;  /*逻辑区段防护锁闭所属进路不具有CBTC区域属性，返回失败*/
			}
		}
		else
		{
			retVal = CI_ERROR;
		}	

		*pDevState = cLogSecCbtcProperty;
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return retVal;
}

/*
* 功能描述： 检查逻辑进路内逻辑区段的CBTC区域属性
* 参数说明： const UINT8 wLogSecNum 逻辑进路包含的逻辑区段数量
*            const UINT16 pLogSecId[MAX_ROUTE_IN_LT_NUM]  逻辑进路包含的逻辑区段ID
* 返回值  ： CI_ERROR 0 不具有CBTC属性
*            CI_SUCCESS 1 具有CBTC属性
* Created By LQ 2023.12.08
*/
UINT8 CheckLogicRouteCbtcProperty(const UINT8 wLogSecNum, const UINT16 pLogSecId[MAX_ROUTE_IN_LT_NUM])
{
	UINT8 retVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 cLogSecCbtcProperty = LOGSEC_CBTC_PROPERTY_NO;  /*逻辑区段CBTC区域属性*/
	UINT16 wLogSecRLockRouteId = 0U;  /*逻辑区段进路锁闭所属进路ID*/
	UINT16 wLogSecPLockRouteId = 0U;  /*逻辑区段防护锁闭所属进路ID*/
	UINT8 cRouteCbtcProperty = ROUTE_CBTC_PROPERTY_NO;  /*进路锁闭所属进路的CBTC区域属性*/

	if ((0U != wLogSecNum) && (MAX_ROUTE_IN_LT_NUM > wLogSecNum) && (NULL != pLogSecId))
	{
		retVal = CI_SUCCESS;

		for (ii = 0U; ii < wLogSecNum; ii++)
		{
			/*检查逻辑区段的CBTC区域属性*/
			cLogSecCbtcProperty = GetLogSecCbtcProperty(pLogSecId[ii]);
			if (LOGSEC_CBTC_PROPERTY_YES == cLogSecCbtcProperty)
			{
				/*继续遍历*/
			}
			else
			{
				retVal = CI_ERROR;  /*存在逻辑区段非CBTC区域属性，停止遍历，返回失败*/
				break;
			}
		}		
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return retVal;
}

/*
* 功能描述： 进路中途折返解锁 进路解锁条件检查
* 参数说明： const UINT16 routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CANCLE_ROUTE
* BY LC
*/
UINT8 CheckRouteZhefanJiesuo(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_ROUTE_ZHONGTUZHEFAN_UNLOCK;
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;        /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 routepreState = 0u;            /*进路上周期状态*/
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/

	UINT8 sendLevel = ESEND_LEVEL_ATS;		/*发送ATS*//*故障发送级别*/
	UINT8 cRouteType = 0U;  /*进路类型*/
	UINT8 routeState = 0U;  /*进路状态*/
	UINT16 startSignalId = 0U;   /*进路始端信号机ID*/
	UINT8 cSignalColor = 0U;     /*进路始端信号机当前颜色*/
	UINT8 cSignalOpenState = 0U; /*进路始端信号机开放状态*/

	/*联锁条件检查*/

		/*进路始端信号机关闭*/
	startSignalId = GetRouteStartSignalId(routeId);
	cSignalColor = GetSignalCurColor(startSignalId);
	cSignalOpenState = GetSignalOpenCloseState(cSignalColor);
	if (SIGNAL_CLOSE == cSignalOpenState)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		devId = startSignalId;
		devState = cSignalOpenState;
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_SIG_START_OPEN_STATE, devState, sendLevel);
		reResult = CI_ERROR;
	}

	/*进路状态为接近锁闭异常*/
	if (CI_SUCCESS == reResult)
	{
		routeState = GetRouteState(routeId);  /*获取进路状态*/
		if (ROUTE_STATE_NEAR_LOCKERR == routeState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			devId = routeId;
			devState = routeState;
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, devId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


	/* 进路内所有区段锁闭状态【正常锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecLockStateCheck(routeId, PHYSICAL_SECTION_LOCK_NORMAL, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*进路内区段占压检查(非调车)*/
	if (CI_SUCCESS == reResult)
	{
		cRouteType = GetRouteType(routeId);  /*获取进路类型*/
		if (ROUTE_TYPE_DIAOCHE != cRouteType)
		{
			/* 进路内所有区段占用状态【空闲】*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			devId = routeId;
			devState = cRouteType;
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_TYPE, devState, sendLevel);
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/
		
		if ((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
		{
			/*取消继电器有效：取消继电器采集状态为：吸起*/
			relayState = GetRelayCollState(cancleZhaoChaRelayId);/*获取取消继电器采集状态*/
			devId = cancleZhaoChaRelayId;
			devState = relayState;
			if (RELAY_STATE_UP == relayState)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;

			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_RELAY, devId, ETYPE_CANCLE_ZHAOCHA, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}

		}
		else
		{
		}
	}
	else
	{
	}

	return reResult;
}


/*
* 功能描述： 保护区段关联的物理区段包含的非保护区段内的所有逻辑区段锁闭检查
* 参数说明： UINT16 const overlapId,  OverlapID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR  检查失败
*            CI_SUCCESS 检查通过
* BY LC
*/
UINT8 CheckOverlapPhysecOtherLock(UINT16 const overlapId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16 dataIdBuf[OVLP_LOGICSECTION_SUM_MAX] = { 0U };  /*非保护区段内的所有逻辑区段数组*/
	UINT8  checkSum = 0U;                               /*非保护区段内的所有逻辑区段数*/
	UINT8 i = 0U;
	UINT8 reVal = CI_ERROR;
	UINT8 lockState = 0U;              /*逻辑区段被进路锁闭状态*/
	UINT8 logLockState = 0U;            /*逻辑区段被逻辑进路锁闭状态*/
	UINT8 logLockBelongRouteNum = 0U;
	

	if ((0U < overlapId) && (OVERLAP_SUM_MAX > overlapId)
		&& (NULL != pDevId) && (NULL != pDevState))
	{
		/*获取保护区段关联的物理区段包含的非保护区段内的所有逻辑区段*/
		reVal = GetOverlapPhysecOtherLogSec(overlapId, &dataIdBuf,&checkSum);
		if (CI_SUCCESS == reVal)
		{
			if (0u == checkSum)
			{
				/*无检查项,返回成功*/
			}
			else
			{
				/*遍历非保护区段内的所有逻辑区段*/
				for (i = 0U; i < checkSum; i++)
				{
					lockState = GetLogSecLockState(dataIdBuf[i]);
					logLockState = GetLogSecLogLockState(dataIdBuf[i]);
					logLockBelongRouteNum = GetLogSecLockBelLogRouteSum(dataIdBuf[i]);  /*获取逻辑区段逻辑锁闭所属逻辑进路数量*/

					if ((LOG_SECTION_LOCK_NO == lockState) && (LOG_SECTION_LOGLOCK_NO == logLockState) && (0U == logLockBelongRouteNum))
					{
						/* 区段未锁闭且未逻辑锁闭且逻辑锁闭所属进路数量为0，返回成功 */
					}
					else
					{
						/*锁闭状态不满足*/
						*pDevId = dataIdBuf[i];
						if (LOG_SECTION_LOCK_NO == lockState)
						{
							*pDevState = logLockState;
						}
						else
						{
							*pDevState = lockState;
						}

						reVal = CI_ERROR;
						break;
					}
				}
			}
		}
		else
		{
			/*获取逻辑区段失败*/
		}
	}
	else
	{
		/*入参检查不通过*/
	}
	return reVal;
}

/*
* 功能描述：保护区段侧防条件检查
* 参数说明：UINT16 const overlapId,  OverlapID
*           UINT16* pDevId 设备Id（返回）
*           UINT8* pDevState 设备状态（返回）
* 返回值  ：0 检查失败
*           1 检查成功
* Created By LQ 2024.01.05
*/
UINT8 OverlapLateralDfnCheck(UINT16 const overlapId, UINT16* pDevId, UINT8* pDevState)
{
	UINT8 retVal = CI_ERROR;
	UINT8 i = 0U;
	UINT16 wLogSecId = 0U;
	UINT8 cOvlpIncLogSecNum = 0U;  /*保护区段包含的逻辑区段数量*/
	UINT16* pOvlpIncLogSecId = NULL;  /*保护区段包含的逻辑区段ID*/

	if ((0U != overlapId) && (OVERLAP_SUM_MAX > overlapId) && (NULL != pDevId) && (NULL != pDevState))
	{
		cOvlpIncLogSecNum = GetOverlapLogicSectionSum(overlapId);
		pOvlpIncLogSecId = GetOverlapLogicSectionBuf(overlapId);

		if ((0U != cOvlpIncLogSecNum) && (NULL != pOvlpIncLogSecId))
		{
			/*检查保护区段内所有逻辑区段的侧防条件是否满足*/
			for (i = 0U; i < cOvlpIncLogSecNum; i++)
			{
				wLogSecId = pOvlpIncLogSecId[i];
				retVal = LogicSecSwitchLtrlDfncCheck(wLogSecId, pDevId, pDevState);

				if (CI_SUCCESS == retVal)
				{
					/*检查通过，继续遍历*/
				}
				else
				{
					retVal = CI_ERROR;
					break;
				}
			}
		}
		else
		{
			/*获取保护区段包含的逻辑区段信息失败，返回失败*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}
 
	return retVal;
}

/*
* 功能描述： 检查保护区段的CBTC区域属性
* 参数说明： const UINT16 wOverlapId 保护区段ID
* 返回值  ： CI_ERROR 0 不具有CBTC属性
*            CI_SUCCESS 1 具有CBTC属性
* Created By LQ 2024.02.20
*/
UINT8 CheckOverlapCbtcProperty(const UINT16 wOverlapId)
{
	UINT8 retVal = CI_ERROR;
	UINT8 ii;
	UINT8 cOverlapIncLogSecNum = 0U;  /*保护区段包含的逻辑区段数量*/
	UINT16* pOverlapIncLogSecId = NULL;  /*保护区段包含的逻辑区段ID*/
	UINT16 wLogSecPLockRouteId = 0U;  /*逻辑区段防护锁闭所属进路ID*/
	UINT8 cRouteCbtcProperty = ROUTE_CBTC_PROPERTY_NO;  /*进路的CBTC区域属性*/

	if ((0U < wOverlapId) && (OVERLAP_SUM_MAX > wOverlapId))
	{
		retVal = CI_SUCCESS;
		cOverlapIncLogSecNum = GetOverlapLogicSectionSum(wOverlapId);
		pOverlapIncLogSecId = GetOverlapLogicSectionBuf(wOverlapId);

		if ((0U < cOverlapIncLogSecNum) && (OVLP_LOGICSECTION_SUM_MAX > cOverlapIncLogSecNum) && (NULL != pOverlapIncLogSecId))
		{
			/*检查保护区段包含的逻辑区段防护锁闭所属进路的CBTC区域属性*/
			for (ii = 0U; ii < cOverlapIncLogSecNum; ii++)
			{
				wLogSecPLockRouteId = GetLogSecPLockRouteId(pOverlapIncLogSecId[ii]);  /*获取逻辑区段防护锁闭所属进路ID*/
				if ((0U < wLogSecPLockRouteId) && (ROUTE_SUM_MAX > wLogSecPLockRouteId))
				{					
					cRouteCbtcProperty = GetRouteCbtcProperty(wLogSecPLockRouteId);
					if (ROUTE_CBTC_PROPERTY_YES == cRouteCbtcProperty)
					{
						/*进路具有CBTC区域属性，返回1成功*/
					}
					else
					{
						retVal = CI_ERROR;  /*逻辑区段防护锁闭所属进路不具有CBTC区域属性，返回0失败*/
					}
				}
				else
				{
					retVal = CI_ERROR;  /*未被防护锁闭，返回0失败*/
				}

				if (CI_SUCCESS != retVal)
				{
					retVal = CI_ERROR;
					break;
				}
				else
				{
					/*继续检查*/
				}
			}
		}
		else
		{
			retVal = CI_ERROR;  /*获取保护区段包含的逻辑区段失败，返回0失败*/
		}
	}
	else
	{
		/*入参非法，返回0失败*/
	}

	return retVal;
}

#if 0
/*
* 功能描述： 进路是否有区段相同检查
* 参数说明： const UINT16 wSrcRouteId   源进路ID
*			 const UINT16 wSrcRouteId   目标进路ID
* 
* 返回值  ： CI_ERROR     没有区段重叠
*            CI_SUCCESS   有区段重叠
* BY CGH 20240320
*/
UINT8 CheckRoutePhySecSame(const UINT16 wSrcRouteId, const UINT16 wDstRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 chSrcRoutePhySecSum = 0U;/*源进路物理区段数目*/
	RoutePhysicalSectionStruct* pSrcPhySecData = NULL;/*源进路物理区段信息*/
	UINT8 chDstRoutePhySecSum = 0U;/*目标进路物理区段数目*/
	RoutePhysicalSectionStruct* pDstPhySecData = NULL;/*目标进路物理区段信息*/
	UINT8 checkFlag = 0U;

	if ((0U < wSrcRouteId) && (ROUTE_SUM_MAX > wSrcRouteId) && (0U < wDstRouteId) && (ROUTE_SUM_MAX > wDstRouteId))
	{
		chSrcRoutePhySecSum = GetRoutePhysicalSectionSum(wSrcRouteId);
		pSrcPhySecData = GetRouteSectionData(wSrcRouteId);

		if (NULL != pSrcPhySecData)
		{
			for (ii = 0U; ii < chSrcRoutePhySecSum; ii++)
			{
				chDstRoutePhySecSum = GetRoutePhysicalSectionSum(wDstRouteId);
				pDstPhySecData = GetRouteSectionData(wDstRouteId);
				for (jj = 0U; jj < chDstRoutePhySecSum; jj++)
				{
					if (pSrcPhySecData[ii].PhysicalSectionId == pDstPhySecData[jj].PhysicalSectionId)
					{
						chRetVal = CI_SUCCESS;
						checkFlag = 1U;
					}
					else
					{
						; /*继续查找*/
					}
					if (1U == checkFlag)
					{
						break;
					}
					else
					{
						; /*继续查找*/
					}
				}
				if (1U == checkFlag)
				{
					break;
				}
				else
				{
					; /*继续查找*/
				}
			}
		}
		else
		{
			; 
		}

	}
	else
	{
		; /*入参校验不合法*/
	}

	return chRetVal;
}
#endif

/*
* 功能描述： 逻辑区段是否为列车脚下逻辑区段检查
* 参数说明： wLogSecId  逻辑区段ID
*			 const UINT16 wRouteId 进路ID
* 返回值  ： CI_ERROR     不为列车脚下逻辑区段
*            CI_SUCCESS   为列车脚下逻辑区段
* BY CGH 20240325
*/
UINT8 TrainRelateLogSecCheck(const UINT16 wLogSecId, const UINT16 wRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 szItsRouteAppTrainId = 0U;/*ATS申请部分路径列车ID*/
	UINT8 chTrainDir = 0U;    /*列车运行方向*/
	struct_PathPoint start = { 0U };  /*列车逻辑起点*/
	struct_PathPoint end = { 0U };    /*列车逻辑终点*/
	UINT16 wTrainOccLogSum = 0U;      /*列车脚下逻辑区段数量*/
	UINT16 wTrainOccLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };   /*列车占压的逻辑区段ID*/
	UINT16 jj = 0U;

	if ((0U < wLogSecId) && (LOGIC_SECTION_SUM_MAX > wLogSecId) && (0U < wRouteId) && (ROUTE_SUM_MAX > wRouteId))
	{
		szItsRouteAppTrainId = GetHalfRouteResReqTrainId(wRouteId);

		if (0U != szItsRouteAppTrainId)
		{
			chRetVal = CI_SUCCESS;
			chTrainDir = GetTrainDir(szItsRouteAppTrainId);

			if (DIR_SAME == chTrainDir)
			{
				/* 列车沿逻辑正向运行 */
				end.wLinkId = GetTrainMaxHeadLink(szItsRouteAppTrainId);
				end.dwOffset = GetTrainMaxHeadOffset(szItsRouteAppTrainId);
				start.wLinkId = GetTrainMinTailLink(szItsRouteAppTrainId);
				start.dwOffset = GetTrainMinTailOffset(szItsRouteAppTrainId);
			}
			else if (DIR_CONVERT == chTrainDir)
			{
				/* 列车沿逻辑反向运行 */
				start.wLinkId = GetTrainMaxHeadLink(szItsRouteAppTrainId);
				start.dwOffset = GetTrainMaxHeadOffset(szItsRouteAppTrainId);
				end.wLinkId = GetTrainMinTailLink(szItsRouteAppTrainId);
				end.dwOffset = GetTrainMinTailOffset(szItsRouteAppTrainId);
			}
			else
			{
				chRetVal = CI_ERROR;/*方向异常，返回0失败*/
			}

			if (CI_SUCCESS == chRetVal)
			{
				chRetVal = GetLogSecBtwTwoPoints(start, end, &wTrainOccLogSum, wTrainOccLogID);
				if (CI_SUCCESS == chRetVal)
				{
					if ((0U < wTrainOccLogSum) && (SIZE_MAX_SECTION_BT_TRAIN > wTrainOccLogSum))
					{
						for (jj = 0U; jj < wTrainOccLogSum; jj++)
						{
							chRetVal = CI_ERROR;
							if (wLogSecId == wTrainOccLogID[jj])
							{
								/*当前逻辑区段是某一个车的脚下逻辑区段即返回成功*/
								chRetVal = CI_SUCCESS;
								break;
							}
						}
					}
					else
					{
						chRetVal = CI_ERROR;   /*列车脚下逻辑区段数量非法，返回失败*/
					}
				}
				else
				{
					; /*检查错误，返回失败*/
				}	
			}
			else
			{
				;
			}
		}
		else
		{
			; /*只有部分进路等待解锁时才会到此函数，此时列车ID为0不合法*/
		}

	}
	else
	{
		; /*入参校验不合法*/
	}

	return chRetVal;
}


/*
* 功能描述： 进路第一离去逻辑区段检查
* 参数说明： wLogSecId  第一离去逻辑区段ID
* 返回值  ： CI_ERROR     检查失败
*            CI_SUCCESS   检查通过
* BY LC 20240710
*/
UINT8 RouteLeaveLogSecCheck(const UINT16 wLogSecId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16* wAxisIdBuff = NULL;
	UINT8 const functionId = EFUNC_FIRSTLEAVE_LOGSEC_CHECK;
	UINT8 leaveLogOccuState = 0U;
	UINT8 acEnvelopeCount = 0u;  /*计轴上包络数量*/
	EnvelopeStruct envelopeInfo[SECTION_REL_ENVELOPE_SUM_MAX] = { 0u };/*计轴上包络信息*/
	UINT8 i = 0U;
	UINT8 ifCrossFlag = 0U;
	str_Zone strZoneLogic = { 0u };  /*逻辑区段空间位置*/
	str_Zone strZoneEnvolop = { 0u };  /*包络空间位置*/

	LOD_STRU strPointA = { 0u };
	LOD_STRU strPointB = { 0u };
	UINT32 dwLen = 0U;
	UINT16 linkNum = 0U;
	UINT8 crossCount = 0U;  /*存在交集的包络数量*/
	EnvelopeStruct wCrossEnvolopInfo[SECTION_REL_ENVELOPE_SUM_MAX] = {0U}; /*存在交集的包络数据*/
	UINT16 tmpTrainId = 0U;/*包络中的列车ID*/
	UINT16* pLogSecIncLinkBuff = NULL;  /*逻辑区段包含的link ID*/
	UINT16 linkMaxHead = 0U;
	UINT16 linkMinTail = 0U;
	UINT32 offsetMaxHead = 0U;
	UINT32 offsetMinTail = 0U;
	UINT8 checkFlag = CI_ERROR;

	leaveLogOccuState = GetLogSecCurCtOrUtOccupyState(wLogSecId);

	/*查找逻辑区段所属计轴区段*/
	wAxisIdBuff = GetLgcSecRltvAxleSecIdBuf(wLogSecId);
	if (NULL != wAxisIdBuff)
	{
		/*查找该计轴区段的包络信息*/
		acEnvelopeCount = elm_GetEnvelopeInAC(wAxisIdBuff[0], envelopeInfo);
	}
	else
	{
		acEnvelopeCount = SECTION_REL_ENVELOPE_SUM_MAX;
	}
	/*获取逻辑区段的空间位置*/
	strZoneLogic.pLinkSeq.cLinkCnt = GetSecIntrudeLinkSum(wLogSecId);
	pLogSecIncLinkBuff = GetSecIntrudeLinkIdBuf(wLogSecId);
	if (NULL != pLogSecIncLinkBuff)
	{
		for (i = 0U; i < strZoneLogic.pLinkSeq.cLinkCnt; i++)
		{
			strZoneLogic.pLinkSeq.szLinkId[i] = pLogSecIncLinkBuff[i];
		}
	}
	strZoneLogic.pStart.wLinkId = GetLgcSecOrgnLink(wLogSecId);
	strZoneLogic.pStart.dwOffset = GetLgcSecOrgnOffset(wLogSecId);
	strZoneLogic.pEnd.wLinkId = GetLgcSecTmnlLink(wLogSecId);
	strZoneLogic.pEnd.dwOffset = GetLgcSecTmnlOffset(wLogSecId);
	
	
	/*离去逻辑区段空闲*/
	if (LOGICSECTION_OCCUPY_NO == leaveLogOccuState)
	{
		chRetVal = CI_SUCCESS;
	}
	/*离去逻辑区段空闲UT占压*/
	else if (LOGICSECTION_OCCUPY_UT == leaveLogOccuState)
	{
		checkFlag = CI_SUCCESS;
		if (SECTION_REL_ENVELOPE_SUM_MAX != acEnvelopeCount)
		{
			/*遍历计轴上所有的包络*/
			for (i = 0U; i < acEnvelopeCount; i++)
			{
				strZoneEnvolop.pStart.wLinkId = envelopeInfo[i].startPos.Lnk;
				strZoneEnvolop.pStart.dwOffset = envelopeInfo[i].startPos.Off;
				strZoneEnvolop.pEnd.wLinkId = envelopeInfo[i].endPos.Lnk;
				strZoneEnvolop.pEnd.dwOffset = envelopeInfo[i].endPos.Off;

				strPointA.Lnk = strZoneEnvolop.pStart.wLinkId;
				strPointA.Off = strZoneEnvolop.pStart.dwOffset;
				strPointB.Lnk = strZoneEnvolop.pEnd.wLinkId;
				strPointB.Off = strZoneEnvolop.pEnd.dwOffset;
				dwLen = dsuLenByPoint(&strPointA, &strPointB, &linkNum, strZoneEnvolop.pLinkSeq.szLinkId, &strZoneEnvolop.Dir);
				strZoneEnvolop.pLinkSeq.cLinkCnt = (UINT8)linkNum;

				if (UINT32_MAX != dwLen)
				{

					ifCrossFlag = CheckZoneIsCrossing(&strZoneLogic, &strZoneEnvolop);
					if (CI_ERROR == ifCrossFlag)
					{
						/*包络与逻辑区段存在交集*/
						wCrossEnvolopInfo[crossCount] = envelopeInfo[i];
						crossCount++;
					}
				}
				else
				{
					/*区域位置检查失败，返回标志ERROR*/
					checkFlag = CI_ERROR;
				}

				if ((1U < crossCount) || (CI_ERROR == checkFlag))
				{
					/*存在交集的包络数大于1或检查失败，跳出遍历*/
					break;
				}
				else
				{
					/*继续遍历*/
				}
			}

			/*检查与逻辑区段存在交集的包络数等于1*/
			if ((1U != crossCount) || (CI_ERROR == checkFlag))
			{
				/*存在交集的包络数不等于1或查询失败，返回失败*/
				chRetVal = CI_ERROR;
				debug_infor_printf((const)"CheckFirstLeaveLog ERROR: envelope on This LogicSec Number Is %d\n", crossCount);
				
			}
			else
			{
				/*检查包络为UCT包络且不存在可疑 */
				if ((TYPE_UCT_ENVELOPE != wCrossEnvolopInfo[0].envelopeType) || (LINE_MAX_TRAIN == wCrossEnvolopInfo[0].headTrainID) || (LINE_MAX_TRAIN == wCrossEnvolopInfo[0].tailTrainID))
				{
					/*包络不为UCT包络，或者为UCT包络存在可疑*/
					chRetVal = CI_ERROR;
					debug_infor_printf((const)"CheckFirstLeaveLog ERROR: envelope %d on This LogicSec is Not Right\n", wCrossEnvolopInfo[0].id);
				}
				else
				{
					/*检查列车后备位置与逻辑区段没有交集*/
					chRetVal = TrainBackPosCrossLogCheck(wCrossEnvolopInfo[0].id, wLogSecId, functionId);
				}
			}

		}
		else
		{
		    /*返回失败*/
		    chRetVal = CI_ERROR;
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, wLogSecId, ETYPE_LOGSEC_OCC_STATE, leaveLogOccuState, ESEND_LEVEL_ZERO);
        }
		
	}
	/*离去逻辑区段CT占压*/
	else
	{
		chRetVal = CI_ERROR;
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, wLogSecId, ETYPE_LOGSEC_OCC_STATE, leaveLogOccuState, ESEND_LEVEL_ZERO);
	}
	return chRetVal;
}

/*
* 功能描述： 查询包络中列车后备位置是否与逻辑区段相交
* 参数说明： wLogSecId  第一离去逻辑区段ID
*			envolopId  包络ID
* 返回值  ： CI_ERROR     相交
*            CI_SUCCESS   未相交
*/
UINT8 TrainBackPosCrossLogCheck(const UINT16 envolopId, const UINT16 logsecId ,const UINT8 functionId)
{
	UINT8 i = 0U;
	str_Zone strZoneTrainBack = { 0U };
	UINT8 chRetVal = CI_ERROR;
	UINT32 dwLen = 0U;
	UINT16 linkNum = 0U;
	LOD_STRU strPointA = { 0u };
	LOD_STRU strPointB = { 0u };
	UINT8 ifCrossFlag = CI_ERROR;
	const EnvelopeStruct* pTempInfo = NULL; /*包络信息*/
	UINT16 trainId = 0U;
	str_Zone strZoneLogic = { 0u };  /*逻辑区段空间位置*/
	UINT16* pLogSecIncLinkBuff = NULL;  /*逻辑区段包含的link ID*/

	if ((0U != envolopId) && (LINE_MAX_TRAIN != envolopId) && (0U != logsecId) && (LOGIC_SECTION_SUM_MAX > logsecId))
	{
		/*查询逻辑区段位置信息*/
		/*获取逻辑区段的空间位置*/
		strZoneLogic.pLinkSeq.cLinkCnt = GetSecIntrudeLinkSum(logsecId);
		pLogSecIncLinkBuff = GetSecIntrudeLinkIdBuf(logsecId);
		if (NULL != pLogSecIncLinkBuff)
		{
			for (i = 0U; i < strZoneLogic.pLinkSeq.cLinkCnt; i++)
			{
				strZoneLogic.pLinkSeq.szLinkId[i] = pLogSecIncLinkBuff[i];
			}
		}
		strZoneLogic.pStart.wLinkId = GetLgcSecOrgnLink(logsecId);
		strZoneLogic.pStart.dwOffset = GetLgcSecOrgnOffset(logsecId);
		strZoneLogic.pEnd.wLinkId = GetLgcSecTmnlLink(logsecId);
		strZoneLogic.pEnd.dwOffset = GetLgcSecTmnlOffset(logsecId);

		pTempInfo = elm_GetEnvelopeInfoByID(envolopId);
		/*遍历包络中所有列车*/
		for (i = 0U; i < pTempInfo->trianCnt; i++)
		{
			trainId = pTempInfo->trainID[i];

			/*查询列车后备位置信息*/
			strZoneTrainBack.pEnd.wLinkId = GetAblTrainMaxHeadLink(trainId);
			strZoneTrainBack.pEnd.dwOffset = GetAblTrainMaxHeadOffset(trainId);
			strZoneTrainBack.pStart.wLinkId = GetAblTrainMinTailLink(trainId);
			strZoneTrainBack.pStart.dwOffset = GetAblTrainMinTailOffset(trainId);
			strPointA.Lnk = strZoneTrainBack.pStart.wLinkId;
			strPointA.Off = strZoneTrainBack.pStart.dwOffset;
			strPointB.Lnk = strZoneTrainBack.pEnd.wLinkId;
			strPointB.Off = strZoneTrainBack.pEnd.dwOffset;

			dwLen = dsuLenByPoint(&strPointA, &strPointB, &linkNum, strZoneTrainBack.pLinkSeq.szLinkId, &strZoneTrainBack.Dir);

			if (UINT32_MAX != dwLen)
			{
				strZoneTrainBack.pLinkSeq.cLinkCnt = (UINT8)linkNum;

				/*判断该列车后备位置与逻辑区段的关系*/
				chRetVal = CheckZoneIsCrossing(&strZoneLogic, &strZoneTrainBack);
				if (CI_SUCCESS != chRetVal)
				{
					chRetVal = CI_ERROR;
					debug_infor_printf((const)"CheckFirstLeaveLog ERROR: Train %d Is Overlap With FirstLeaveLogSec\n", trainId);
				}

			}
			else
			{
				/*查询后备位置失败*/
				chRetVal = CI_ERROR;
				debug_infor_printf((const)"CheckFirstLeaveLog ERROR: Train %d Do Not Have BackUp Position\n", trainId);
			}
			if (CI_ERROR == chRetVal)
			{
				break;
			}
		}
		if (CI_SUCCESS != chRetVal)
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, logsecId, ETYPE_LOGSEC_OCC_STATE, CI_BACK_PSEC_OCU_YES, ESEND_LEVEL_ZERO);
		}
	}
	return chRetVal;
}

/*
* 功能描述： 检查进路离去区段的ABL列车条件
* 参数说明： leaveLogicSecId  第一离去逻辑区段ID
*			routeId  进路
* 返回值  ： CI_ERROR     检查不通过
*            CI_SUCCESS   检查通过
*/
UINT8 TrainLeaveLogSecABLTrainCheck(const UINT16 leaveLogicSecId)
{
	UINT8 ret = CI_ERROR;
	UINT8 leaveLogCheckFlag = LOGSEC_LEAVE_LOGSEC_REPLY_NO;/*相邻联锁发送的进路离去区段的ABL列车条件检查标志*/
	UINT8 leaveLogBelongCI = 0U;
	UINT8 chLocalCiId = 0U;

	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	leaveLogBelongCI = GetLogSecBelongCiId(leaveLogicSecId);
	/*第一逻辑区段属于本联锁*/
	if (chLocalCiId == leaveLogBelongCI)
	{
		/*检查进路外方第一离去逻辑区段是否满足信号开放条件*/
		ret = RouteLeaveLogSecCheck(leaveLogicSecId);
	}
	/*由相邻联锁发送第一离去逻辑区段检查结果*/
	else
	{
		leaveLogCheckFlag = GetRouteLeaveLogFlag(leaveLogicSecId);
		/*已收到相邻联锁允许开放反馈*/
		if (LOGSEC_LEAVE_LOGSEC_REPLY_YES == leaveLogCheckFlag)
		{
			ret = CI_SUCCESS;
		}
		else
		{
			ret = CI_ERROR;
		}
	}
	return ret;
}

/*
* 功能描述： 检查逻辑区段ABL反向进路属性
* 参数说明： const UINT16 wLogSecId 逻辑区段ID
*            const UINT16 wTrainId  列车ID
* 返回值  ： CI_ERROR 0 具有ABL反向进路属性
*            CI_SUCCESS 1 不具有ABL反向进路属性
* Created By CGH 20240726
*/
UINT8 CheckLogSecAblReverseProperty(const UINT16 wLogSecId, const UINT16 wTrainId)
{
	UINT8 retVal = CI_ERROR;
	UINT8 chTrainLevel = 0U;/*列车等级*/
	UINT16 wLogSecRLockRouteId = 0U;  /*逻辑区段进路锁闭所属进路ID*/
	UINT8 chLogSecReverseProperty = 0U;/*反向进路属性*/

	if ((0U < wLogSecId) && (LOGIC_SECTION_SUM_MAX > wLogSecId) && (0U < wTrainId) && (TRAIN_SUM_MAX > wTrainId))
	{
		chTrainLevel = GetTrainLevel(wTrainId);
		if (TRAIN_LEVEL_ABL == chTrainLevel)
		{
			wLogSecRLockRouteId = GetLogSecLockBelongRoute(wLogSecId);

			if ((0U < wLogSecRLockRouteId) && (ROUTE_SUM_MAX > wLogSecRLockRouteId))
			{
				chLogSecReverseProperty = GetRouteReverseProperty(wLogSecRLockRouteId);
				if (ROUTE_REVERSE_PROPERTY_YES == chLogSecReverseProperty)
				{
					/*逻辑区段锁闭所属进路具备反向属性*/
					retVal = CI_ERROR;
				}
				else
				{
					/*逻辑区段不具有反向属性*/
					retVal = CI_SUCCESS;  
				}
			}
			else
			{
				retVal = CI_ERROR;
			}
		}
		else
		{
			retVal = CI_SUCCESS;  /*列车等级不为ABL此项不进行检查*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return retVal;
}


/*
* 功能描述：物理区段被征用后是否满足被另一条进路征用或保护锁闭条件
* 参数说明： UINT16 switchId, 道岔ID
*            UINT8 switchState, 期望道岔位置
* 返回值  ：CI_SUCCESS：征用检查通过
*            CI_ERROR:征用检查失败
*			2023.07.24 add by mpt
*/
UINT8 CheckPhyUseSecCanOtherUse(UINT16 switchId, UINT8 switchState)
{
	UINT8 retVal = CI_ERROR;
	RouteSwitchStruct *pRouteInnerSwitchIdBuf = NULL;   /*进路内方道岔ID */
	UINT8 routeExpectSwitchState = 0U;                /*进路期望的道岔位置*/
	UINT8 routeSwitchSum = 0U;                        /*进路内包含的道岔数量*/
	UINT16 ii = 0U;                                   /*循环下标*/
	UINT16 phyUseBelongRouteId = 0U;                  /*物理区段征用所属进路ID*/
	UINT8 routeState = 0U;                            /*进路状态*/
	UINT16 switchBelongPhySecId = 0U;                 /*道岔所属物理区段ID*/
	UINT16 phyProtUseBelongRouteId = 0U;              /*道岔所属物理区段ID*/
	UINT8 routeProtSwitchSum = 0U;                        /*进路内包含的道岔数量*/
	RouteProtectSwitchStruct* pRouteProtectSwitchStr = NULL; /*进路防护道岔*/

	switchBelongPhySecId = GetSwitchPhySectionId(switchId); /*获取道岔所属物理区段ID*/

	phyUseBelongRouteId = GetPhySecUseRouteId(switchBelongPhySecId); /*物理区段征用所属进路ID*/
	phyProtUseBelongRouteId = GetPhySecProtectUseRouteId(switchBelongPhySecId); /*物理区段征用所属进路ID*/

	if (0U < phyUseBelongRouteId)
	{
		retVal = CI_ERROR;
		routeSwitchSum = GetRouteSwitchSum(phyUseBelongRouteId); /*进路包含的道岔数量*/
		pRouteInnerSwitchIdBuf = GetRouteSwitchData(phyUseBelongRouteId);/*进路内方包含的道岔ID数组*/
		if (NULL != pRouteInnerSwitchIdBuf)
		{
			for (ii = 0U; ii < routeSwitchSum; ii++)
			{
				if (switchId == pRouteInnerSwitchIdBuf[ii].SwitchId)
				{
					if (switchState == pRouteInnerSwitchIdBuf[ii].SwitchPosition)
					{
						retVal = CI_SUCCESS;/*期望的道岔位置一致则检查通过*/
					}
					else
					{
						retVal = CI_ERROR;
					}
					break;
				}
			}
			if (ii == routeSwitchSum)
			{/*道岔不在征用其进路的进路中则检查通过*/
				retVal = CI_SUCCESS;
			}
		}
	}
	else
	{
		retVal = CI_SUCCESS;
	}


	if (CI_SUCCESS == retVal)
	{
		if (0U < phyProtUseBelongRouteId)
		{
			retVal = CI_ERROR;
			routeProtSwitchSum = GetRouteRelatedProtectSwitchSum(phyProtUseBelongRouteId); /*进路包含的道岔数量*/
			pRouteProtectSwitchStr = GetRouteRelatedProtSwitchData(phyProtUseBelongRouteId);/*进路内方包含的道岔ID数组*/
			if (NULL != pRouteProtectSwitchStr)
			{
				for (ii = 0U; ii < routeProtSwitchSum; ii++)
				{
					if (switchId == pRouteProtectSwitchStr[ii].ProtectSwitchId)
					{
						if (switchState == pRouteProtectSwitchStr[ii].ProtectPosition)
						{
							retVal = CI_SUCCESS;/*期望的道岔位置一致则检查通过*/
						}
						else
						{
							retVal = CI_ERROR;
						}
						break;
					}
				}
				if (ii == routeProtSwitchSum)
				{
					/*道岔不在征用其进路的防护道岔中检查通过*/
					retVal = CI_SUCCESS;
				}
			}
		}
		else
		{
			retVal = CI_SUCCESS;
		}
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0U == phyUseBelongRouteId) && (0U == phyProtUseBelongRouteId))
		{
			retVal = CI_ERROR;/*有征用，但是进路内征用和进路外防护征用都为0，则说明该区段可能是非进路或跳跃锁闭征用，返回失败*/
		}
	}

	return retVal;
}

/*
* 功能描述：通信车车前端可疑检查
* 输入参数：const UINT16 wTrainId 列车ID
*           const UINT8 cLogSecSeqDir ATS下发的逻辑区段序列方向
*			const UINT16 wLogSecId  逻辑区段ID
* 输出参数：无
* 返回值  ：CI_ERROR   检查失败
*           CI_SUCCESS 检查成功
* by cgh 20240819
*/
UINT8 CtTrainHeadSuspCheck(const UINT16 wTrainId, const UINT8 cLogSecSeqDir,const UINT16 wLogSecId)
{
	/*局部变量初始化*/
	UINT8 retVal = CI_ERROR;
	UINT8 cTrainDir = 0U;   /*列车运行方向*/
	UINT8 cSysLogDir = 0U;  /*系统定义的逻辑方向*/
	UINT8 cTrainCommState = 0U;  /*列车通信状态*/
	EnvelopeStruct* pTrainEnvelopeData = NULL;  /*列车包络*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;  /*列车与逻辑区段间的方向变化点数量*/
	UINT16 wTrainMinTailLink = 0U;/*列车小后所在LINK*/
	UINT16 wLogSecOrgnLink = 0U;/*逻辑区段起点LINK*/
	UINT8 cVirHeadScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;	    /*列车虚拟前筛标志*/
	UINT8 cVirTailScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;		/*列车虚拟后筛标志*/

	/*入参检查*/
	cSysLogDir = GetLinkLogicDirUpAndDown();	
	if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) || (CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir)) && ((0x55 == cSysLogDir) || (0xaa == cSysLogDir)))
	{		
		if ((0U != wTrainId) && (UINT16_MAX != wTrainId))  /*列车ID合法，继续判断*/
		{
			cTrainCommState = GetTrainTransitmitStat(wTrainId);
			if (TRAIN_COMM_STATE_GOOD == cTrainCommState)  /*通信车检查前筛*/
			{
				cTrainDir = GetTrainDir(wTrainId);
				/*将列车方向由逻辑方向转为运营方向*/
				if (cTrainDir == DIR_CONVERT)
				{
					cTrainDir = cSysLogDir;
				}
				else if (cTrainDir == DIR_SAME)
				{
					cTrainDir = ~cSysLogDir;
				}
				else
				{
					/*无操作*/
				}

				wTrainMinTailLink = GetTrainMinTailLink(wTrainId);
				wLogSecOrgnLink = GetLgcSecOrgnLink(wLogSecId);
				strCurPoint.Lnk = wTrainMinTailLink;
				strCurPoint.Off = 0U;
				strNxtPoint.Lnk = wLogSecOrgnLink;
				strNxtPoint.Off = 0U;
				cDirChangeNum = GetDirChangeNumBtwPoints(&strCurPoint, &strNxtPoint);  /*查询列车大后到序列中首个逻辑区段间的方向变化点*/
				cTrainDir = TransDirByChangeNum(cTrainDir, cDirChangeNum);

				pTrainEnvelopeData = elm_GetEnvelopeInfoByTrainID((wTrainId & 0xFFU));  /*获取列车所在包络*/
				if (NULL != pTrainEnvelopeData)
				{					
					if (((CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir) && (CI_SYSTEM_DIRECTION_UP == cTrainDir))
						|| ((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) && (CI_SYSTEM_DIRECTION_DOWN == cTrainDir)))
					{
						/*列车运行方向与逻辑区段序列方向相同，检查通信车前端是否可疑*/
						cVirHeadScreStat = GetTrainVirHeadScreenPassFlag(wTrainId);
						if ((0U != pTrainEnvelopeData->headTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != cVirHeadScreStat))
						{
							retVal = CI_ERROR;
						}
						else
						{
							retVal = CI_SUCCESS;
						}
					}
					else if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) && (CI_SYSTEM_DIRECTION_UP == cTrainDir))
						|| ((CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir) && (CI_SYSTEM_DIRECTION_DOWN == cTrainDir)))
					{
						/*列车运行方向与逻辑区段序列方向相反，检查通信车后端是否可疑*/
						cVirTailScreStat = GetTrainVirTailScreenPassFlag(wTrainId);
						if ((0U != pTrainEnvelopeData->tailTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != cVirTailScreStat))
						{
							retVal = CI_ERROR;
						}
						else
						{
							retVal = CI_SUCCESS;
						}
					}
					else
					{
						retVal = CI_ERROR;   /*参数错误，返回失败*/
					}
				}
				else
				{
					/*相邻控区获取不到列车包络，直接让办理*/
					retVal = CI_SUCCESS;
				}
			}
			else
			{
				/*非通信车，直接让办理*/
				retVal = CI_SUCCESS;
			}
		}
		else
		{
			/*车组号无效，返回失败*/
		}
	}
	else
	{
		retVal = CI_ERROR;  /*入参检查失败，返回失败*/
	}

	return retVal;
}

/*
* 功能描述：车辆段部分进路的逻辑区段序列和列车位置检查
* 输入参数：const UINT8 cLogSecSum 逻辑区段数量
*           const UINT16* pLogSecIdBuff 逻辑区段序列
*           const UINT16 wTrainId 列车ID
*           const UINT8 cFunctionId 函数ID
*           const UINT8 cSendLevel 报警发送级别
* 输出参数：无
* 返回值  ：CI_ERROR 0 失败
*           CI_SUCCESS 1 成功
* Edit By cgh 2025.10.17
*/
UINT8 LogSecSeqAndTrainPosCheckCLD(const UINT8 cLogSecSum, const UINT16* pLogSecIdBuff, const UINT16 wTrainId, const UINT8 cFunctionId, const UINT8 cSendLevel)
{
	/*局部变量初始化*/
	UINT8 cRetVal = CI_ERROR;
	UINT8 cLogSecLockState = LOG_SECTION_LOCK_NORMAL;  /*逻辑区段锁闭状态*/
	UINT8 cLogSecLogLockState = LOG_SECTION_LOGLOCK_NORMAL;  /*逻辑区段逻辑锁闭状态*/
	UINT8 cLogSecIncLinkNum = 0U;  /*逻辑区段包含的link数量*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link ID*/
	UINT16 wLogSecRelPhySecId = 0U;  /*逻辑区段关联的物理区段*/
	UINT8 cPhySecType = PHYSICAL_SEC_TYPE_SWITCH;  /*物理区段类型（是否岔区）*/
	UINT8 cSleepWakeAttr = CI_ERROR;  /*休眠唤醒轨属性*/
	UINT8 cTrainCommState = TRAIN_COMM_STATE_UNKNOWN;  /*列车通信状态*/

	/*入参检查*/
	if ((1U == cLogSecSum) && (NULL != pLogSecIdBuff) && ((ESEND_LEVEL_ATS == cSendLevel) || (ESEND_LEVEL_ZERO == cSendLevel)))
	{
		/****** 部分进路包含的逻辑区段数量唯一，继续检查逻辑区段是否未锁闭 ******/
		cLogSecLockState = GetLogSecLockState(pLogSecIdBuff[0]);
		cLogSecLogLockState = GetLogSecLogLockState(pLogSecIdBuff[0]);

		if ((LOG_SECTION_LOCK_NO == cLogSecLockState) && (LOG_SECTION_LOGLOCK_NO == cLogSecLogLockState))
		{
			/****** 部分进路包含的逻辑区段数量唯一且未锁闭，继续检查逻辑区段是否为休眠唤醒轨且非岔区 ******/
			cLogSecIncLinkNum = GetSecIntrudeLinkSum(pLogSecIdBuff[0]);  /*获取逻辑区段包含的link*/
			pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[0]);

			if ((1U == cLogSecIncLinkNum) && (NULL != pLogSecIncLinkId))
			{
				cSleepWakeAttr = IsLinkSwTrack(pLogSecIncLinkId[0]);  /*获取link的休眠唤醒轨属性*/
				wLogSecRelPhySecId = GetLgcSecRelativePhySecId(pLogSecIdBuff[0]);  /*获取逻辑区段关联的物理区段*/
				cPhySecType = GetPhySecType(wLogSecRelPhySecId);  /*获取物理区段类型*/

				if ((CI_SUCCESS == cSleepWakeAttr) && (PHYSICAL_SEC_TYPE_NOSWITCH == cPhySecType))
				{
					/****** 部分进路包含的逻辑区段数量唯一且未锁闭且为休眠唤醒轨且非岔区，继续检查列车是否完全位于此休眠唤醒轨 ******/
					cTrainCommState = GetTrainTransitmitStat(wTrainId);

					if (TRAIN_COMM_STATE_GOOD == cTrainCommState)  /*通信车检查前筛*/
					{
						cRetVal = TrainOccSameSecCheck(wLogSecRelPhySecId, wTrainId);

						if (CI_SUCCESS != cRetVal)
						{
							SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_TRAIN_POS, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
							debug_infor_printf((const)"LogSecSeqAndTrainPosCheckCLD: Train Check Error: Train[%d] Position Is Error\n", wTrainId); 
						}
						else
						{
							/*检查通过*/
							;
						}
					}
					else
					{
						SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_TRAIN_COMM, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
						debug_infor_printf((const)"LogSecSeqAndTrainPosCheckCLD: Train Check Error: Train[%d] CommState Is Error\n", wTrainId);  /*列车通信异常，返回失败*/
					}
				}
				else
				{
					SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SEC_ATTR, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
					debug_infor_printf((const)"LogSecSeqAndTrainPosCheckCLD: LogSec Check Error: LogSec[%d] Attr Is Error\n", pLogSecIdBuff[0]);  /*部分进路的逻辑区段非休眠唤醒轨/道岔区段，返回失败*/
				}
			}
			else
			{
				SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SEC_ATTR, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
				/*获取逻辑区段包含的link失败，返回失败*/
			}
		}
		else
		{
			SetErrorData(cFunctionId, CI_DEVICE_TYPE_LOGICSEC, pLogSecIdBuff[0], ETYPE_LOGSEC_LOCK_STATE, cLogSecLockState, cSendLevel);
			debug_infor_printf((const)"LogSecSeqAndTrainPosCheckCLD: LogSec Check Error: LogSec[%d] State Is Error\n", pLogSecIdBuff[0]);  /*逻辑区段锁闭，返回失败*/
		}
	}
	else
	{
		SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_SEC_ATTR, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：车辆段部分进路的逻辑区段序列与进路匹配检查
* 输入参数：const UINT8 cLogSecSeqDir 逻辑区段序列方向（运营方向）
*           const UINT16 wLogSecId 逻辑区段ID
* 输出参数：UINT16* pMatchedRouteId 与逻辑区段序列匹配的进路ID
* 返回值  ：CI_ERROR 0 匹配失败
*           CI_SUCCESS 1 匹配成功
* Created By LQ 2024.09.05
*/
UINT8 LogSecSeqAndRouteMatchCheckCLD(const UINT8 cLogSecSeqDir, const UINT16 wLogSecId, UINT16* pMatchedRouteId)
{
	/*局部变量初始化*/
	UINT8 cRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 wLogSecIndex = 0U;
	UINT8 cRelatedEndSigSum = 0U;  /*逻辑区段关联的终端信号机数量*/
	UINT16* pRelatedEndSigId = NULL;  /*逻辑区段关联的终端信号机ID数组*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的linkID*/
	UINT8 cQueryLogicDir = DIR_INVALID;  /*查询方向（逻辑方向）*/
	UINT8 cSignalProDir = DIR_INVALID;  /*信号机防护方向（逻辑方向）*/
	UINT16 wSigProLinkId = 0U;  /*信号机防护link*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;
	UINT16 wEndSignalId = 0U;
	UINT8 cRelatedRouteSum = 0U;  /*逻辑区段关联进路数量*/
	UINT16* pRelatedRouteId = NULL;  /*逻辑区段关联进路ID数组*/
	UINT16 wRouteEndSignalId = 0U;  /*进路终端信号机*/
	UINT8 cPossibleRouteSum = { 0U };  /*初筛成功的进路数量*/
	UINT16 szPossibleRouteIdBuff[MAX_ROUTE_IN_LT_NUM] = { 0U };  /*初筛成功的进路ID数组*/

	/*入参检查*/
	wLogSecIndex = GetlogSectionBufIndex(wLogSecId);
	if (((CI_SYSTEM_DIRECTION_DOWN == cLogSecSeqDir) || (CI_SYSTEM_DIRECTION_UP == cLogSecSeqDir)) && (LOGIC_SECTION_SUM_MAX > wLogSecIndex) && (NULL != pMatchedRouteId))
	{
		/****** 1.确定逻辑区段关联的外方信号机 ******/
		cRelatedEndSigSum = GetLogRelateEndSigSum(wLogSecId);
		pRelatedEndSigId = GetLogRelateEndSigData(wLogSecId);
		pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(wLogSecId);

		/*选出逻辑区段关联信号机中防护方向与ATS下发的运行方向相同的信号机*/
		if ((0U != cRelatedEndSigSum) && (NULL != pRelatedEndSigId) && (NULL != pLogSecIncLinkId))
		{
			cQueryLogicDir = ConvertDirectionToLogic(cLogSecSeqDir);  /*将运营方向转换为逻辑方向*/

			for (ii = 0U; ii < cRelatedEndSigSum; ii++)
			{
				cSignalProDir = GetSignalDirection(pRelatedEndSigId[ii]);
				wSigProLinkId = GetSignalProtectLink(pRelatedEndSigId[ii]);
				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 == cQueryLogicDir)
				{
					wEndSignalId = pRelatedEndSigId[ii];
					break;
				}
				else
				{
					/*非同向终端信号机，不处理*/
				}
			}
		}
		else
		{
			/*获取逻辑区段关联的终端信号机失败，不处理*/
		}

		/****** 2.初筛逻辑区段可以匹配的进路 ******/
		cRelatedRouteSum = GetLogRelateRouteSum(wLogSecId);
		pRelatedRouteId = GetLogRelateRouteData(wLogSecId);

		if ((0U != cRelatedRouteSum) && (NULL != pRelatedRouteId))
		{
			for (ii = 0U; ii < cRelatedRouteSum; ii++)
			{
				wRouteEndSignalId = GetRouteEndSignalId(pRelatedRouteId[ii]);

				/*进路终端信号机与逻辑区段终端信号机相同，则添加进路为可能的匹配进路*/
				if (wRouteEndSignalId == wEndSignalId)
				{
					if (MAX_ROUTE_IN_LT_NUM > cPossibleRouteSum)
					{
						szPossibleRouteIdBuff[cPossibleRouteSum] = pRelatedRouteId[ii];
						cPossibleRouteSum++;
					}
					else
					{
						break;  /*数量达到上限，不再继续遍历*/
					}
				}
				else
				{
					/*终端信号机不相同，不处理*/
				}
			}

			if (0U != cPossibleRouteSum)
			{	
				cRetVal = CI_SUCCESS; 
			}
			else
			{
				debug_infor_printf((const)"LogSecSeqAndRouteMatchCheckCLD: No End Signal Matched Route\n");  /*未匹配到进路，返回失败*/
			}
		}
		else
		{
			/*获取逻辑区段关联的进路失败，不处理*/
		}

		/****** 3.确定逻辑区段最终匹配的进路 ******/
		if (CI_SUCCESS == cRetVal)
		{
			cRetVal = MatchLieCheRouteCLD(cPossibleRouteSum, szPossibleRouteIdBuff, pMatchedRouteId);  /*匹配非主进路的列车进路*/
		}
		else
		{
			cRetVal = CI_ERROR;  /*返回失败*/
		}
	}
	else
	{
		/*入参检查失败，不处理*/
	}

	return cRetVal;
}

/*
* 功能描述：车辆段部分进路匹配列车进路
* 输入参数：const UINT8 cRouteSum 进路数量
*           const UINT16 szRouteId[MAX_ROUTE_IN_LT_NUM] 进路ID数组
* 输出参数：UINT16* pMatchedRouteId 与逻辑区段匹配的进路ID
* 返回值  ：CI_ERROR 0 匹配失败
*           CI_SUCCESS 1 匹配成功
* Created By LQ 2024.09.05
*/
UINT8 MatchLieCheRouteCLD(const UINT8 cRouteSum, const UINT16 szRouteId[MAX_ROUTE_IN_LT_NUM], UINT16* pMatchedRouteId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 cRouteType = 0U;  /*进路类型*/
	UINT8 cLieCheIndex = UINT8_MAX;  /*目标列车进路索引*/
	UINT8 cReturnIndex = UINT8_MAX;  /*目标折返进路索引*/

	/*入参检查*/
	if ((MAX_ROUTE_IN_LT_NUM >= cRouteSum) && (NULL != szRouteId) && (NULL != pMatchedRouteId))
	{
		for (ii = 0U; ii < cRouteSum; ii++)
		{
			/*通过进路属性找出进路中的列车进路*/
			cRouteType = GetConfigRouteType(szRouteId[ii]);
			if (ROUTE_TYPE_LIECHE == cRouteType)
			{
				cLieCheIndex = ii;
				break;  /*找到列车进路，确定为最终匹配的进路，置标志有效，停止遍历*/
			}
			else if (ROUTE_TYPE_RETURN == cRouteType)
			{
				cReturnIndex = ii;  /*缓存折返进路索引*/
			}
			else
			{
				/*调车进路，不处理*/
			}
		}

		if (UINT8_MAX != cLieCheIndex)
		{
			*pMatchedRouteId = szRouteId[cLieCheIndex];  /*存在列车进路，以列车进路优先*/
			cRetVal = CI_SUCCESS;
		}
		else if(UINT8_MAX != cReturnIndex)
		{
			*pMatchedRouteId = szRouteId[cReturnIndex];  /*不存在列车进路，使用非主折返进路*/
			cRetVal = CI_SUCCESS;
		}
		else
		{
			debug_infor_printf((const)"MatchLieCheRouteCLD: No Train Route And Return Route\n");  /*只有调车进路，返回失败*/
		}		
	}
	else
	{
		/*入参检查失败，返回0失败*/
	}

	return cRetVal;
}

/*
* 功能描述：通信列车前端与后端可疑检查
* 输入参数：const UINT16 wTrainId 列车ID
* 输出参数：无
* 返 回 值：CI_ERROR 0 检查失败
*           CI_SUCCESS 1 检查成功
* Created By LQ 2024.09.05
*/
UINT8 CtTrainSuspCheck(const UINT16 wTrainId)
{
	/*局部变量初始化*/
	UINT8 cRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	EnvelopeStruct* pTrainEnvelopeData = NULL;  /*列车包络*/
	UINT8 cVirHeadScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;	    /*列车虚拟前筛标志*/
	UINT8 cVirTailScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;		/*列车虚拟后筛标志*/

	/*入参检查*/
	wTrainIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wTrainIndex)
	{
		pTrainEnvelopeData = elm_GetEnvelopeInfoByTrainID((wTrainId & 0xFFU));  /*获取列车所在包络*/
		if (NULL != pTrainEnvelopeData)
		{
			/*列检查通信车前端+后端是否可疑*/
			cVirHeadScreStat = GetTrainVirHeadScreenPassFlag(wTrainId);
			cVirTailScreStat = GetTrainVirTailScreenPassFlag(wTrainId);

			if (((0U == pTrainEnvelopeData->headTrainID) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == cVirHeadScreStat))
				&& ((0U == pTrainEnvelopeData->tailTrainID) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == cVirTailScreStat)))
			{
				cRetVal = CI_SUCCESS;
			}
			else
			{
				/*列车存在前端或后端可以，返回失败*/
			}
		}
		else
		{
			/*获取列车包络失败，返回失败*/
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述： 判断进路是否有锁闭的保护区段
* 参数说明：输入参数 const UINT16 routeId, 进路ID
* 返回值  ： CI_ERROR     没有锁闭的保护区段
*            CI_SUCCESS   有锁闭的保护区段
* BY CGH 20240920
*/
UINT8 CheakRouteHaveLockOverlap(const UINT16 routeId)
{
	UINT8 ii = 0U;
	UINT16 wOverlapBelongRouteId = 0U;/*保护区段锁闭所属进路*/
	UINT16 wRouteOrgnLink = 0U;/*进路起点LINK*/
	UINT8 chReResult = CI_ERROR;
	UINT16 wRouteInFirstLogSecId = 0U;/*进路内方第一逻辑区段ID*/
	UINT16 wOverlapFirstLogSecId = 0U;/*保护区段第一个逻辑区段ID*/
	UINT8 chOverlapFirstSecLockDir = 0U;/*保护区段第一个区段锁闭方向*/
	UINT16 wLogSecOrgnLink = 0U;/*逻辑区段起点LINK*/
	UINT8 chRouteLockDir = 0U;
	UINT8 chOverlapSum = GetRouteOverlapSum(routeId);
	UINT16* pOverlapIdBuf = GetRouteOverlapIdBuf(routeId);
	LOD_STRU pLODAStru = { 0U };
	LOD_STRU pLODBStru = { 0U };
	UINT8 chDirChangeNum = 0U;/*方向变化点数目*/
	UINT16 wOverlapId = 0U;/*进路锁闭保护区段ID*/
	UINT16 wRouteAtsExpLkOverlapId = GetRouteAtsExpLkOverlapId(routeId);

	if ((0U < chOverlapSum) && (NULL != pOverlapIdBuf) && (0U == wRouteAtsExpLkOverlapId))
	{
		for (ii = 0U; ii < chOverlapSum; ii++)
		{
			/*存在保护区段所属进路不为0 则说明保护区段锁闭*/
			wOverlapBelongRouteId = GetOverlapBelongRouteId(pOverlapIdBuf[ii]);

			if (0U != wOverlapBelongRouteId)
			{
				chRouteLockDir = GetRouteDirection(routeId);
				wRouteInFirstLogSecId = GetRouteInFirstLogSecId(routeId);
				wRouteOrgnLink = GetLgcSecOrgnLink(wRouteInFirstLogSecId);
				pLODAStru.Lnk = wRouteOrgnLink;
				pLODAStru.Off = 0U;
				pLODAStru.Dir = EMAP_SAME_DIR;/*方向不使用，仅赋值*/

				wOverlapFirstLogSecId = GetOverlapFirstLogSecId(pOverlapIdBuf[ii]);
				chOverlapFirstSecLockDir = GetLogSecLockDir(wOverlapFirstLogSecId);
				wLogSecOrgnLink = GetLgcSecOrgnLink(wOverlapFirstLogSecId);
				pLODBStru.Lnk = wLogSecOrgnLink;
				pLODBStru.Off = 0U;
				pLODBStru.Dir = EMAP_SAME_DIR;/*方向不使用，仅赋值*/

				chDirChangeNum = GetDirChangeNumBtwPoints(&pLODAStru, &pLODBStru);

				if (UINT8_MAX != chDirChangeNum)
				{
					if (0U == (chDirChangeNum % 2U))
					{
						if (chOverlapFirstSecLockDir == chRouteLockDir)
						{
							/*进路锁闭方向和保护区段锁闭方向一致时*/
							wOverlapId = pOverlapIdBuf[ii];
							chReResult = CI_SUCCESS;
						}
						else
						{
							chReResult = CI_ERROR;
						}
					}
					else
					{
						if (chOverlapFirstSecLockDir == (UINT8)(~chRouteLockDir))
						{
							/*进路锁闭方向和保护区段锁闭方向相反时*/
							wOverlapId = pOverlapIdBuf[ii];
							chReResult = CI_SUCCESS;
						}
						else
						{
							chReResult = CI_ERROR;
						}
					}
				}
				else
				{
					chReResult = CI_ERROR;
				}
				break;
			}
			else
			{
				chReResult = CI_ERROR;
			}
		}
	}
	else
	{
		chReResult = CI_ERROR;
	}


	if ((CI_SUCCESS == chReResult) && (0U != wOverlapId))
	{
		if (wOverlapBelongRouteId != routeId)
		{
			chReResult = CI_SUCCESS;
		}
		else
		{
			/*什么也不做*/
		}
	}
	else
	{
		chReResult = CI_ERROR;
	}

	return chReResult;
}

/*
* 功能描述： 判断待办自动进路中区段未被抵触进路锁闭
* 参数说明：输入参数 const UINT16 checkRouteId 待办进路, const UINT16 opposeRouteId 抵触进路
* 返回值  ： CI_ERROR     被非空闲抵触进路锁闭，检查不通过
*            CI_SUCCESS   检查通过
* BY fan 20241111
*/
UINT8 AutoRouteOpposeSectionCheck(const UINT16 checkRouteId, const UINT16 opposeRouteId)
{
	UINT8 returnValue = CI_ERROR;
	UINT8 i = 0U; /*循环变量*/
	UINT16 wPhySecId = 0U;
	UINT8 curLockState = 0U;
	UINT8  checkSum = 0U;
	RoutePhysicalSectionStruct*  pDataIdBuf =NULL;
	UINT16 wLockBelongRouteId = 0U;/*物理区段锁闭所属进路ID*/
	UINT8 routeState = 0U;

	if ((1u <= checkRouteId) && (ROUTE_SUM_MAX > checkRouteId) 
		&& (1u <= opposeRouteId) && (ROUTE_SUM_MAX > opposeRouteId))
	{
		routeState = GetRouteState(opposeRouteId);
		if (ROUTE_STATE_IDLE != routeState)
		{
			checkSum = GetRoutePhysicalSectionSum(checkRouteId);
			pDataIdBuf = GetRouteSectionData(checkRouteId);
			if((0U != checkSum) && (NULL != pDataIdBuf))
			{
				for (i = 0u; i < checkSum; i++)
				{
					wPhySecId = pDataIdBuf[i].PhysicalSectionId;
					curLockState = GetPhySecLockState(wPhySecId);  /*获取区段当前锁闭状态*/
					if (PHYSICAL_SECTION_LOCK_NO != curLockState)
					{ /*正常锁闭||延时解锁*/

						wLockBelongRouteId = GetPhySecRLockBelongRouteId(wPhySecId);
						if (wLockBelongRouteId == opposeRouteId)
						{
							/*被抵触进路锁闭 检查失败*/
							break;
						}
						else
						{
							; /*继续检查*/
						}
					}
					else
					{
						; /*未锁闭 通过*/
					}
				}
				if (i == checkSum)
				{
					returnValue = CI_SUCCESS;
				}
				else
				{
					returnValue = CI_ERROR;
				}
			}
			else
			{
				/*数据检查失败*/
				returnValue = CI_ERROR;
			}
		}
		else
		{
			returnValue = CI_SUCCESS; /*抵触进路未办理*/
		}
	}
	else
	{
		/*入参检查失败*/
		returnValue = CI_ERROR;
	}
	return returnValue;
}

/*
* 功能描述： 检查道岔位置和动作有效性
* 参数说明： const UINT16 wSwitchId, 道岔ID
* 返回值  ： 
* BY CGH 20241203
*/
UINT8 CheckSwitchPosAndMoveValid(const UINT16 wSwitchId,const UINT8 chSwitchPos, UINT8 sendLevel)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 chDevState = 0U;/*设备状态*/
	UINT8 chResult = CI_ERROR;/*检查结果*/
	UINT8 chFuncSwitch = 0U;     /*功能开关*/
	UINT8 chLocalCiId = 0U;      /*本地联锁ID*/
	UINT8 chCiType = 0U;         /*目标联锁类型*/

	chFuncSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
	chLocalCiId = GetSystemParaLocalCiId();
	chCiType = GetCiType(chLocalCiId);
	
	if ((0U < wSwitchId) && (SWITCH_SUM_MAX > wSwitchId))
	{
		chRetVal = CI_SUCCESS;
		chDevState = GetSwitchCurPosition(wSwitchId);
		if (chSwitchPos == chDevState)
		{
			/* 道岔位置正确 */
			/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
			chResult = checkSwtLastValDrvPosStayorNot(wSwitchId, chSwitchPos);
			if (CI_SUCCESS == chResult)
			{
				; /*检查通过*/
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, wSwitchId, ETYPE_SWT_POSTION_STATE, chDevState, sendLevel);
				chRetVal = CI_ERROR;
			}
		}
		else if (SWITCH_POSITION_SIKAI == chDevState)
		{
			/*四开*/
			/* 记录故障码 */
			SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, wSwitchId, ETYPE_SWT_POSTION_STATE, chDevState, sendLevel);
			chRetVal = CI_ERROR;
		}
		else if (SWITCH_POSITION_JICHA == chDevState)
		{
			/*挤岔*/
			/* 记录故障码 */
			SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, wSwitchId, ETYPE_SWT_POSTION_STATE, chDevState, sendLevel);
			chRetVal = CI_ERROR;
		}
		else
		{
			/* 道岔位置不正确 */
			if (CI_TYPE_CLD == chCiType)
			{
				chDevState = GetSwitchMoveValidState(wSwitchId, SWITCH_OPER_NO_DANCAO, sendLevel);
			}
			else
			{
				if (FUNC_SWITCH_ON == chFuncSwitch)
				{
					/*适配进路提前驱动道岔功能*/
					chDevState = GetSwitchMoveEarlyValidState(wSwitchId, SWITCH_OPER_NO_DANCAO, sendLevel);
				}
				else
				{
					chDevState = GetSwitchMoveValidState(wSwitchId, SWITCH_OPER_NO_DANCAO, sendLevel);
				}
			}

			if (CI_SUCCESS == chDevState)
			{
				; /*道岔可动*/
			}
			else
			{
				/*道岔位置不正确 且 道岔不可动作*/
				/* GetSwitchMoveValidState函数内已经记录故障码 */
				/*SetErrorData(EFUNC_CHECK_SWITCHPOS_MOVEVALID, CI_DEVICE_TYPE_SWITCH, wSwitchId, ETYPE_SWT_POSTION_STATE, chDevState, sendLevel);*/
				chRetVal = CI_ERROR;
			}
		}
	}
	else
	{
		;
	}
	return chRetVal;
}

/*
* 功能描述： 进路其它联锁道岔位置有效性检查
* 参数说明： UINT16 const routeId,    进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* by cgh 20241204
*/
UINT8 RouteOtherCiSwPosValidCheck(UINT16 const routeId)
{
	UINT8 const checkRouteSwSum = GetRouteSwitchSum(routeId);
	RouteSwitchStruct* pRouteSwIdBuf = GetRouteSwitchData(routeId);
	UINT8 const checkRouteProSwSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* pRouteProSwIdBuf = GetRouteRelatedProtSwitchData(routeId);
	UINT8 ii = 0U;           /* 循环变量 */
	UINT8 reVal = CI_ERROR;
	UINT8 chRouteSwitchBelCiCheck = 0U;/*进路道岔是否全部属于进路所在联锁检查*/
	UINT8 chRouteApplySwitchCheckFlag = 0U;/*进路办理道岔检查标志*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chSwitchBelCiId = 0U;/*道岔所属联锁ID*/

	if ((NULL == pRouteSwIdBuf) || (NULL == pRouteProSwIdBuf))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		chLocalCiId = GetSystemParaLocalCiId();
		/*开始检查*/
		for (ii = 0U; ii < checkRouteSwSum; ii++)
		{
			chSwitchBelCiId = GetSwitchBelongCiId(pRouteSwIdBuf[ii].SwitchId);
			if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
			{
				reVal = CheckSwitchPosAndMoveValid(pRouteSwIdBuf[ii].SwitchId, pRouteSwIdBuf[ii].SwitchPosition, ESEND_LEVEL_ZERO);
				if (CI_ERROR == reVal)
				{
					break;
				}
				else
				{
					;
				}
			}
			else
			{
				/*这里找到其他控区道岔不跳出，完全检查本控区的道岔*/
				;
			}
		}

		if (CI_SUCCESS == reVal)
		{
			for (ii = 0U; ii < checkRouteProSwSum; ii++)
			{
				chSwitchBelCiId = GetSwitchBelongCiId(pRouteProSwIdBuf[ii].ProtectSwitchId);
				if ((chLocalCiId == chSwitchBelCiId) && (0U != chLocalCiId))
				{
					reVal = CheckSwitchPosAndMoveValid(pRouteProSwIdBuf[ii].ProtectSwitchId, pRouteProSwIdBuf[ii].ProtectPosition, ESEND_LEVEL_ZERO);
					if (CI_ERROR == reVal)
					{
						break;
					}
					else
					{
						;
					}
				}
				else
				{
					/*这里找到其他控区道岔不跳出，完全检查本控区的道岔*/
					;
				}
			}
		}
		else
		{
			; 
		}
	}

	return reVal;
}

/*
* 功能描述：其它控区保护区段关联的防护道岔动作有效性检查
* 参数说明：const UINT16 wOverlapId 保护区段ID
* 返 回 值：CI_ERROR 0 失败
*           CI_SUCCESS 1 成功
* Created By LQ 2024.12.09
*/
UINT8 OtherCiOvlpRelProSwMovValCheck(const UINT16 wOverlapId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 cOverlapIncProSwNum = 0U;  /*获取保护区段关联防护道岔*/
	OverlapProtectSwitchStruct* pOverlapIncProSwData = NULL;
	UINT8 cLocalCiId = 0U;
	UINT16 ii = 0U;
	UINT16 wProSwId = 0U;  /*防护道岔ID*/
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属控区*/
	UINT8  cProSwCurPos = 0U;  /*防护道岔当前位置*/
	UINT8  cProSwExpPos = 0U;  /*防护道岔期望位置*/
	UINT8 cCheckResult = CI_ERROR;
	UINT8 sendLevel = ESEND_LEVEL_ZERO;  /*故障发送级别，不发送*/

	cOverlapIncProSwNum = GetOverlapRelatedProtSwitSum(wOverlapId);  /*获取保护区段关联防护道岔*/
	pOverlapIncProSwData = GetOverlapRelatedProtSwitStru(wOverlapId);

	if (0U == cOverlapIncProSwNum)
	{		
		cRetVal = CI_SUCCESS;  /*无防护道岔，返回成功*/
	}
	else if (NULL != pOverlapIncProSwData)
	{
		cRetVal = CI_SUCCESS;
		cLocalCiId = GetSystemParaLocalCiId();		

		for (ii = 0U; ii < cOverlapIncProSwNum; ii++)
		{
			wProSwId = pOverlapIncProSwData[ii].ProtectSwitchId;
			cSwitchBelongCiId = GetSwitchBelongCiId(wProSwId);  /*获取道岔所属控区*/

			if ((cLocalCiId == cSwitchBelongCiId) && (0U != cSwitchBelongCiId))
			{
				/*本控区道岔，继续检查可动性*/
				cProSwCurPos = GetSwitchCurPosition(wProSwId);
				cProSwExpPos = pOverlapIncProSwData[ii].ProtectPosition;
				if (cProSwCurPos == cProSwExpPos)
				{
					cCheckResult = checkSwtLastValDrvPosStayorNot(wProSwId, cProSwExpPos);  /*检查道岔是否存在有效的反向驱动*/
					if (CI_SUCCESS == cCheckResult)
					{
						/*无有效的反向驱动，返回成功*/
					}
					else
					{
						cRetVal = CI_ERROR;
					}
				}
				else if (SWITCH_POSITION_SIKAI == cProSwCurPos)
				{
					cRetVal = CI_ERROR;  /*道岔四开，返回失败*/
				}
				else if (SWITCH_POSITION_JICHA == cProSwCurPos)
				{
					cRetVal = CI_ERROR;  /*道岔挤岔，返回失败*/
				}
				else
				{					
					cCheckResult = GetSwitchMoveValidState(wProSwId, SWITCH_OPER_NO_DANCAO, sendLevel);  /*道岔位置不正确，检查是否可动*/
					if (CI_SUCCESS == cCheckResult)
					{
						/*道岔可动，返回成功*/
					}
					else
					{						
						cRetVal = CI_ERROR;  /*道岔位置不正确且道岔不可动作，返回失败*/
					}
				}
			}
			else
			{
				/*非本控区道岔，不处理*/
			}

			if (CI_ERROR == cRetVal)
			{
				break;
			}
			else
			{
				/*继续检查*/
			}
		}
	}
	else
	{
		cRetVal = CI_ERROR;  /*保护区段防护道岔为空，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：保护区段防护道岔征用检查
* 参数说明：const UINT16 wOverlapId 保护区段ID
*           UINT16* pDevId 设备ID（返回）
*           UINT8* pDevState 设备状态（返回）
*           UINT8* pAlarmType 报警类型（返回）
* 返 回 值：CI_ERROR  0 失败
*           CI_SUCCESS 1 成功
*           RETURN_WAIT_SWITCH_USING 0x30 等待道岔征用
* Created By LQ 2024.12.10
*/
UINT8 OverlapProSwUsingCheck(const UINT16 wOverlapId, UINT16* pDevId, UINT8* pDevState, UINT8* pAlarmType)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 cOverlapProSwitchNum = 0U;  /*保护区段防护道岔数量*/
	OverlapProtectSwitchStruct* pOverlapProSwitchData = NULL;  /*保护区段防护道岔数据*/
	UINT8 cLocalCiId = 0U;
	UINT16 ii = 0U;
	UINT16 wProSwitchId = 0U;  /*防护道岔ID*/	
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属控区*/
	UINT16 wProSwitchPhySecId = 0U;  /*防护道岔所在物理区段ID*/
	UINT8 cDevState = 0U;	
	UINT16 wPhySecUseRouteId = 0U;  /*区段征用所属进路ID*/
	UINT16 wPhySecProUseRouteId = 0U;  /*区段防护征用所属进路ID*/
	UINT8 cProSwitchProtectExpPos = 0U;  /*本保护区段要求的道岔位置*/
	UINT8 cCheckResult = CI_ERROR;
	UINT16 wUsingBelongOverlapId = 0U;  /*道岔征用所属保护区段*/
	UINT32 dwXuanPaiStartCycNum = 0U;  /*保护区段防护道岔选排起始周期*/
	UINT8 cAlarmType = FLAG_UNSET;  /*报警类型：0xAA-按物理区段报警；0x55-按道岔报警*/

	cOverlapProSwitchNum = GetOverlapRelatedProtSwitSum(wOverlapId);/*获取保护区段防护道岔数量*/
	pOverlapProSwitchData = GetOverlapRelatedProtSwitStru(wOverlapId);/*获取保护区段防护道岔所在区段数据*/
	cLocalCiId = GetSystemParaLocalCiId();

	if ((NULL != pOverlapProSwitchData) && (NULL != pDevId) && (NULL != pDevState) && (NULL != pAlarmType))
	{
		cRetVal = CI_SUCCESS;

		for (ii = 0U; ii < cOverlapProSwitchNum; ii++)
		{
			wProSwitchId = pOverlapProSwitchData[ii].ProtectSwitchId;  /*防护道岔ID*/
			cSwitchBelongCiId = GetSwitchBelongCiId(wProSwitchId);  /*获取防护道岔所属控区*/
			if (cLocalCiId == cSwitchBelongCiId)
			{
				/*本控区防护道岔，检查所属物理区段征用状态*/
				wProSwitchPhySecId = GetSwitchPhySectionId(wProSwitchId);  /*获取防护道岔所在物理区段ID*/
				cDevState = GetPhySecUseState(wProSwitchPhySecId);  /*获取防护道岔所在区段征用状态*/

				if (PHYSICAL_SECTION_USING_NO == cDevState)
				{
					/*通过检查*/
				}
				else
				{
					wPhySecUseRouteId = GetPhySecUseRouteId(wProSwitchPhySecId);  /*获取征用所属进路ID*/
					wPhySecProUseRouteId = GetPhySecProtectUseRouteId(wProSwitchPhySecId);  /*获取防护征用所属进路ID*/
					if ((0U < wPhySecUseRouteId) || (0U < wPhySecProUseRouteId))
					{
						cProSwitchProtectExpPos = pOverlapProSwitchData[ii].ProtectPosition;  /*防护道岔要求位置*/
						cCheckResult = CheckPhyUseSecCanOtherUse(wProSwitchId, cProSwitchProtectExpPos);
						if (CI_ERROR == cCheckResult)
						{
							cRetVal = CI_ERROR; /*避免从0x30等待防护道岔征用转为1成功*/
						}
						else
						{
							/*继续遍历检查*/
						}
					}
					else
					{
						cRetVal = CI_ERROR;
					}
				}
			}
			else
			{
				/*非本控区防护道岔，检查征用状态*/
				cDevState = GetSwitchUsingState(wProSwitchId);  /*获取防护道岔征用状态*/
				wUsingBelongOverlapId = GetSwitchBelongOverlapId(wProSwitchId);  /*获取防护道岔征用所属保护区段ID*/
				dwXuanPaiStartCycNum = GetOverlapXuanPaiStartCycNum(wOverlapId);  /*获取保护区段选排起始周期号*/

				if ((SWITCH_USING_YES == cDevState) && (wOverlapId == wUsingBelongOverlapId))
				{
					/*防护道岔已被该保护区段征用，检查通过*/
				}
				else if (((SWITCH_USING_APPLY == cDevState) && (wOverlapId == wUsingBelongOverlapId))
					|| ((SWITCH_USING_NO == cDevState) && (0U == dwXuanPaiStartCycNum)))
				{
					cRetVal = RETURN_WAIT_SWITCH_USING;  /*防护道岔处于申请征用或还未开始征用，返回等待征用*/
				}
				else
				{
					wProSwitchPhySecId = wProSwitchId;  /*传参，（再加判断可能导致圈复杂度超限）*/
					cAlarmType = FLAG_SET;  /*按道岔类型报警*/
					cRetVal = CI_ERROR;
				}
			}

			if (CI_ERROR == cRetVal)
			{
				*pDevId = wProSwitchPhySecId;
				*pDevState = cDevState;
				*pAlarmType = cAlarmType;
				break;  /*检查失败，停止遍历，返回失败*/
			}
			else
			{
				/*继续遍历检查*/
			}
		}
	}
	else
	{		
		cRetVal = CI_ERROR;  /*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述： 进路关联所有道岔位置正确检查
* 参数说明： UINT16 const routeId,    进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*输出参数：UINT16* switchID道岔ID、UINT8* chSwitchState道岔状态
* BY CGH 20250224
*/
UINT8 RouteRelAllSwitchPosCheck(UINT16 const routeId, UINT16* switchID, UINT8* chSwitchState)
{
	/* 进路道岔 */
	UINT8 chRouteSwSum = GetRouteSwitchSum(routeId);
	RouteSwitchStruct* szRouteSwDataBuf = GetRouteSwitchData(routeId);
	/* 进路关联防护道岔 */
	UINT8 chRouteProSwSum = GetRouteRelatedProtectSwitchSum(routeId);
	RouteProtectSwitchStruct* szRouteProSwDataBuf = GetRouteRelatedProtSwitchData(routeId);
	/* 局部变量定义初始化 */
	UINT8 ii = 0U;           /* 循环变量 */
	UINT8 reVal = CI_ERROR;
	UINT8 chSwState = 0U;/*道岔状态*/

	if ((NULL != szRouteSwDataBuf) && (NULL != szRouteProSwDataBuf))
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (ii = 0u; ii < chRouteSwSum; ii++)
		{
			chSwState = GetSwitchCurPosition(szRouteSwDataBuf[ii].SwitchId);
			if (chSwState == szRouteSwDataBuf[ii].SwitchPosition)
			{
				/*道岔位置正确*/
				;
			}
			else
			{
				/*道岔位置不正确*/
				reVal = CI_ERROR;
				*switchID = szRouteSwDataBuf[ii].SwitchId;
				*chSwitchState = chSwState;
				break;
			}
		}

		if (CI_SUCCESS == reVal)
		{
			for (ii = 0u; ii < chRouteProSwSum; ii++)
			{
				chSwState = GetSwitchCurPosition(szRouteProSwDataBuf[ii].ProtectSwitchId);
				if (chSwState == szRouteProSwDataBuf[ii].ProtectPosition)
				{
					/*道岔位置正确*/
					;
				}
				else
				{
					/*道岔位置不正确*/
					reVal = CI_ERROR;
					*switchID = szRouteSwDataBuf[ii].SwitchId;
					*chSwitchState = chSwState;
					break;
				}
			}
		}
		else
		{
			; /*返回失败*/
		}
	}
	else
	{
		; /*返回失败*/
	}

	/*全部通过检查*/
	return reVal;
}

/*
*函数功能：保护区段照查继电器检查
*参数说明：const UINT16 wOverlapId保护区段ID
*          UINT8 chSendLevel,       故障码发送级别
*返回值：CI_ERROR               失败
*        CI_SUCCESS             成功
*		 RELAY_STATE_WAITE      本端照查继电器条件不满足--等待
* by cgh 20250617
*/
UINT8 OverlapZhaoChaRelayCheck(const UINT16 wOverlapId, UINT8 chSendLevel)
{
	UINT8 chReval = CI_ERROR;
	UINT16 wThisZhaoChaRelayId = 0U;/*本端照查继电器ID*/
	UINT8 chRelayCollState = 0U; /*继电器采集状态*/
	UINT8 chFunctionId = EFUNC_OVERLAP_ZHAOCHA_CHECK; /*函数名称*/
	UINT16 wThatZhaoChaRelayId = 0U;/*本端照查继电器ID*/

	if ((0U < wOverlapId) && (OVERLAP_SUM_MAX > wOverlapId))
	{
		chReval = CI_SUCCESS;

		wThisZhaoChaRelayId = GetOverlapThisZhaoChaRelayId(wOverlapId);

		if (0U < wThisZhaoChaRelayId)
		{
			chRelayCollState = GetRelayCollState(wThisZhaoChaRelayId);

			if (RELAY_STATE_UP == chRelayCollState)
			{
				/* 记录故障码 */
				SetErrorData(chFunctionId, CI_DEVICE_TYPE_RELAY, wThisZhaoChaRelayId, ETYPE_THIS_ZHAOCHA, RELAY_STATE_UP, ESEND_LEVEL_ZERO);
				/*等待，返回等待标志*/
				chReval = RELAY_STATE_WAITE;
			}
			else
			{
				; /*返回成功*/
			}
		}
		else
		{
			; /*这一步返回成功*/
		}

		/*检查对端照查继电器*/
		wThatZhaoChaRelayId = GetOverlapThatZhaoChaRelayId(wOverlapId);

		if (0U < wThatZhaoChaRelayId)
		{
			chRelayCollState = GetRelayCollState(wThatZhaoChaRelayId);

			if (RELAY_STATE_UP == chRelayCollState)
			{
				/*检查通过*/
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(chFunctionId, CI_DEVICE_TYPE_RELAY, wThatZhaoChaRelayId, ETYPE_THAT_ZHAOCHA, chRelayCollState, chSendLevel);
				/*等待，返回等待标志*/
				chReval = CI_ERROR;
			}
		}
		else
		{
			; /*这一步返回本端照查结果*/
		}

	}
	else
	{
		; /*返回失败*/
	}

	return chReval;
}

/*
* 功能描述： 进路区段全部防护锁闭检查
* 参数说明： UINT16 routeId,    进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS 区段状态均为防护锁闭
* by fan 20250724
*/
UINT8 RouteAllSecProtectLockCheck(UINT16 const routeId)
{
	/* 进路区段*/
	UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
	RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	/* 区段占用检查 */
	if ((0u == checkSum)||(NULL == dataIdBuf))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i<checkSum; i++)
		{
			devId = dataIdBuf[i].PhysicalSectionId;
			devState = GetPhySecLockState(devId);
			if (PHYSICAL_SECTION_LOCK_PROTECT == devState)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回*/
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 逻辑区段关联计轴无休眠车检查
* 参数说明： UINT16 logSectionId,    逻辑区段ID
* 返回值  ： CI_ERROR 存在休眠车
*            CI_SUCCESS 检查通过
* by fan 20250728
*/
UINT8 LogSecRelateNoSleepTrainCheck (UINT16 const logSectionId)
{
	UINT8 reVal = CI_ERROR;
	UINT16* wAxisIdBuff = NULL; /*关联计轴*/
	EnvelopeStruct envelopeInfo[SECTION_REL_ENVELOPE_SUM_MAX] = { 0u };/*计轴上包络信息*/
	UINT8 acEnvelopeCount = 0u;  /*计轴上包络数量*/
	UINT8 cSleepState = 0U; /*包络关联列车休眠状态*/
	UINT8 ii = 0U;
	UINT8 jj = 0U;

	wAxisIdBuff = GetLgcSecRltvAxleSecIdBuf(logSectionId);/*查找逻辑区段所属计轴区段*/
	if (NULL != wAxisIdBuff)
	{
		/*查找计轴区段的包络信息 可能存在休眠车的逻辑区段只关联一个计轴*/
		acEnvelopeCount = elm_GetEnvelopeInAC(wAxisIdBuff[0], envelopeInfo);
		if (SECTION_REL_ENVELOPE_SUM_MAX != acEnvelopeCount)
		{
			/*遍历计轴上所有的包络*/
			reVal = CI_SUCCESS;
			for (ii = 0U; ii < acEnvelopeCount; ii++)
			{
				for (jj = 0U; jj < envelopeInfo[ii].trianCnt; jj++)
				{
					cSleepState = GetTrainSleepState(envelopeInfo[ii].trainID[jj]);
					if (TRAIN_SLEEP_YES == cSleepState)
					{
						reVal = CI_ERROR;
						break;
					}
				}
				if (CI_ERROR == reVal)
				{
					break;
				}
				else
				{
					; /*继续*/
				}
			}
		}
		else
		{
			reVal = CI_ERROR;
		}
	}
	else
	{
		reVal = CI_ERROR;
	}
	return reVal;
}
	
/*
* 功能描述：校验指定进路是否非场段进路或为场段出库/出段进路
* 参数说明：UINT16 wRouteId 进路ID
* 返 回 值：CI_ERROR 其它进路
*           CI_SUCCESS  非场段进路或为场段出库/出段进路
* Created By LQ 2025.08.05
*/
UINT8 RouteCldAttrCheck(UINT16 wRouteId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wIdIndex = 0U;
	UINT8 cRouteBelongCiId = 0U;  /*进路所属控区*/
	UINT8 cCiType = 0U;  /*控区属性*/
	UINT8 cRouteIncPhySecNum = 0U;  /*进路包含的物理区段数量*/
	RoutePhysicalSectionStruct* pstrRouteIncPhySecData = NULL;  /*进路包含的物理区段信息*/
	UINT8 ii = 0U;
	UINT8 cPhySecBelongCiId = 0U;  /*物理区段所属控区*/

	wIdIndex = GetRouteConfigBufIndex(wRouteId);  /*获取进路ID数组下标*/
	if (ROUTE_SUM_MAX > wIdIndex)
	{
		cRouteBelongCiId = GetRouteBelongCiId(wRouteId);
		cCiType = GetCiType(cRouteBelongCiId);

		if ((CI_TYPE_SCX == cCiType) || (CI_TYPE_ZX == cCiType))
		{
			cRetVal = CI_SUCCESS; /*非车辆段，返回成功*/
		}
		else if (CI_TYPE_CLD == cCiType)
		{
			/*进路属于场段，继续检查进路是否存在非场段的区段*/
			cRouteIncPhySecNum = GetRoutePhysicalSectionSum(wRouteId);  /*获取进路包含的物理区段信息*/
			pstrRouteIncPhySecData = GetRouteSectionData(wRouteId);

			if ((0U < cRouteIncPhySecNum) && (NULL != pstrRouteIncPhySecData))
			{
				for (ii = 0U; ii < cRouteIncPhySecNum; ii++)
				{
					cPhySecBelongCiId = GetPhySecBelongCiId(pstrRouteIncPhySecData[ii].PhysicalSectionId);
					cCiType = GetCiType(cPhySecBelongCiId);

					if (CI_TYPE_ZX == cCiType)
					{
						break;  /*存在物理区段非场段，停止遍历*/
					}
					else
					{
						/*继续*/
					}
				}

				if (ii != cRouteIncPhySecNum)
				{
					cRetVal = CI_SUCCESS;  /*存在区段非车辆段，认为出段/出库进路，返回成功*/
				}
				else
				{
					cRetVal = CI_ERROR;  /*返回失败*/
				}
			}
			else
			{
				/*获取信息失败，返回失败*/
			}
		}
		else
		{
			/*返回失败*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：保护区段占用解锁条件检查
* 参数说明：UINT16 overlapId 保护区段ID
*           UINT8 functionId 函数ID
* 返 回 值：CI_ERROR 0 失败
*           CI_SUCCESS 1 成功
* Created By LQ 2025.08.18
*/
UINT8 OverlapOccuUnlockCheck(UINT16 overlapId, UINT8 functionId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT16 wOlapBelongRouteId = 0U;  /*保护区段防护锁闭所属进路ID*/
	UINT8 cRouteState = 0U;  /*进路状态*/
	UINT16 wRouteLatsPhySecId = 0U;  /*进路包含的最后一个物理区段ID*/
	UINT8 cPhySecLockState = 0U;  /*物理区段锁闭状态*/
	UINT8 cOlapIncLogSecNum = 0U;  /*保护区段包含的逻辑区段数量*/
	UINT16* pOlapIncLogSecId = NULL;  /*保护区段包含的逻辑区段ID数组*/
	UINT8 ii = 0U;
	UINT8 cLogSecLockState = 0U;  /*逻辑区段进路锁闭状态*/
	UINT8 cLogSecLogLockState = 0U;  /*逻辑区段逻辑进路锁闭状态*/
	UINT8 cSendLevel = ESEND_LEVEL_ZERO;

	wBufIndex = GetOverlapConfigBufIndex(overlapId);
	if (OVERLAP_SUM_MAX > wBufIndex)
	{
		wOlapBelongRouteId = GetOverlapBelongRouteId(overlapId);
		cRouteState = GetRouteState(wOlapBelongRouteId);
		if (ROUTE_STATE_IDLE == cRouteState)
		{
			wRouteLatsPhySecId = GetRouteLastPhySectionId(wOlapBelongRouteId);
			cPhySecLockState = GetPhySecLockState(wRouteLatsPhySecId);  /*获取防护锁闭所属进路最后一个物理区段的锁闭状态*/
			if (PHYSICAL_SECTION_LOCK_NO == cPhySecLockState)
			{
				cOlapIncLogSecNum = GetOverlapLogicSectionSum(overlapId);  /*获取保护区段包含的逻辑区段信息*/
				pOlapIncLogSecId = GetOverlapLogicSectionBuf(overlapId);
				if ((0U != cOlapIncLogSecNum) && (NULL != pOlapIncLogSecId))
				{
					for (ii = 0U; ii < cOlapIncLogSecNum; ii++)
					{
						cLogSecLockState = GetLogSecLockState(pOlapIncLogSecId[ii]);
						cLogSecLogLockState = GetLogSecLogLockState(pOlapIncLogSecId[ii]);
						if ((LOG_SECTION_LOCK_NORMAL == cLogSecLockState) || (LOG_SECTION_LOGLOCK_NORMAL == cLogSecLogLockState))
						{
							/*继续检查*/
						}
						else
						{
							SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, pOlapIncLogSecId[ii], ETYPE_LOGSEC_LOCK_STATE, cLogSecLockState, cSendLevel);
							cRetVal = CI_ERROR;  /*保护区段包含的逻辑区段未锁闭，返回失败*/
							break;
						}
					}

					if (ii == cOlapIncLogSecNum)
					{
						cRetVal = CI_SUCCESS;  /*保护区段包含的逻辑区段全部正常锁闭，返回成功*/
					}
					else
					{
						cRetVal = CI_ERROR;
					}
				}
				else
				{
					cRetVal = CI_ERROR;  /*获取逻辑区段信息失败，异常分支，返回失败*/
				}
			}
			else
			{
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, wRouteLatsPhySecId, ETYPE_PS_LOCK_STATE, cPhySecLockState, cSendLevel);
				cRetVal = CI_ERROR;  /*防护锁闭所属进路最后一个物理区段锁闭，返回失败*/
			}
		}
		else
		{
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, wOlapBelongRouteId, ETYPE_ROUTE_STATE, cRouteState, cSendLevel);
			cRetVal = CI_ERROR;  /*防护锁闭所属进路未空闲，返回失败*/
		}
	}
	else
	{
		cRetVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车占用完全在指定区段检查
* 输入参数：const UINT16 wPhySecId 物理区段ID
*           const UINT16 wTrainId  列车ID
* 输出参数：无
* 返回值  ：CI_ERROR 0 不完全在
*           CI_SUCCESS 1 完全在
* by cgh 20251017
*/
UINT8 TrainOccSameSecCheck(const UINT16 wPhySecId, const UINT16 wTrainId)
{
	/*局部变量初始化*/
	UINT8 chRetVal = CI_ERROR; /*函数返回值*/
	UINT16  wTrainIndex = 0U; /*列车索引*/
	UINT16 wTrainMaxHeadLink = 0U; /*列车大前LINK*/
	UINT16 wTrainMinHeadLink = 0U; /*列车小前LINK*/
	UINT16 wTrainMaxTailLink = 0U; /*列车大后LINK*/
	UINT16 wTrainMinTailLink = 0U; /*列车小后LINK*/
	UINT16 wTrainMaxHeadPhySecId = 0U; /*列车大前物理区段ID*/
	UINT16 wTrainMinHeadPhySecId = 0U; /*列车小前物理区段ID*/
	UINT16 wTrainMaxTailPhySecId = 0U; /*列车大后物理区段ID*/
	UINT16 wTrainMinTailPhySecId = 0U; /*列车小后物理区段ID*/
	UINT8 chPhySecCurOccState = 0U; /*物理区段当前占用状态*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((0U < wPhySecId) && (PHYSICAL_SECTION_SUM_MAX > wPhySecId) && (0U < wTrainIndex) && (TRAIN_SUM_MAX > wTrainIndex))
	{
		chPhySecCurOccState = GetPhySecCurMergeState(wPhySecId);

		if (SECTION_OCCUPY_YES == chPhySecCurOccState)
		{
			/*获取列车发送的位置*/
			wTrainMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
			wTrainMinHeadLink = GetTrainMinHeadLink(wTrainId);
			wTrainMaxTailLink = GetTrainMaxTailLink(wTrainId);
			wTrainMinTailLink = GetTrainMinTailLink(wTrainId);

			/*获取列车非安全位置对应的物理区段*/
			wTrainMaxHeadPhySecId = GetLinkRelatedPhySec(wTrainMaxHeadLink);
			wTrainMinHeadPhySecId = GetLinkRelatedPhySec(wTrainMinHeadLink);
			wTrainMaxTailPhySecId = GetLinkRelatedPhySec(wTrainMaxTailLink);
			wTrainMinTailPhySecId = GetLinkRelatedPhySec(wTrainMinTailLink);

			if ((wPhySecId == wTrainMaxHeadPhySecId) || (wPhySecId == wTrainMinHeadPhySecId)
				|| (wPhySecId == wTrainMaxTailPhySecId) || (wPhySecId == wTrainMinTailPhySecId))
			{
				/*占用是否属于同一区段检查*/
				chRetVal = OccBelSameSecCheck(wPhySecId, wTrainMaxHeadPhySecId);
				chRetVal &= OccBelSameSecCheck(wPhySecId, wTrainMinHeadPhySecId);
				chRetVal &= OccBelSameSecCheck(wPhySecId, wTrainMaxTailPhySecId);
				chRetVal &= OccBelSameSecCheck(wPhySecId, wTrainMinTailPhySecId);
			}
			else
			{
				/*列车必须有一个位置在指定区段*/
				;
			}	
		}
		else
		{
			/*待检查区段无占用*/

		}
	}
	else
	{
		/*参数合法性校验不通过*/
		;
	}

	return chRetVal;
}

/*
* 功能描述：占用是否属于同一区段检查
* 输入参数：const UINT16 wBasePhySecId 基准物理区段ID
*           const UINT16 wCheckPhySecId 待检查物理区段ID
* 输出参数：无
* 返回值  ：CI_ERROR 0 不属于
*           CI_SUCCESS 1 属于
* by cgh 20251017
*/
UINT8 OccBelSameSecCheck(const UINT16 wBasePhySecId, const UINT16 wCheckPhySecId)
{
	/*局部变量初始化*/
	UINT8 chRetVal = CI_ERROR; /*函数返回值*/
	UINT8 chPhySecCurOccState = 0U; /*物理区段当前占用状态*/

	if ((0U < wBasePhySecId) && (PHYSICAL_SECTION_SUM_MAX > wBasePhySecId) && (0U < wCheckPhySecId) && (PHYSICAL_SECTION_SUM_MAX > wCheckPhySecId))
	{
		if (wBasePhySecId == wCheckPhySecId)
		{
			/*占用属于同一区段*/
			chRetVal = CI_SUCCESS;
		}
		else
		{
			/*大前不在当前区段且在其它区段占用，检查结果为列车占用不完全在指定区段*/
			chPhySecCurOccState = GetPhySecCurMergeState(wCheckPhySecId);

			if (SECTION_OCCUPY_NO != chPhySecCurOccState)
			{
				/*占用不属于同一区段*/
				chRetVal = CI_ERROR;
			}
			else
			{
				/*占用属于同一区段*/
				chRetVal = CI_SUCCESS;
			}
		}
	}
	else
	{
		/*参数合法性校验不通过*/
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}



/*
* 功能描述： 进路风井区段状态检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
* by yx 2026.03.04
*/
UINT8 RouteAirShaftSecOccuCheck(UINT16 const routeId, UINT16 *pDevId, UINT8* pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetRouteAiaShaftSecNum(routeId);
	UINT16* const dataIdBuf = GetRouteAiaShaftSecIdBuf(routeId);

	/* 局部变量定义初始化 */
    UINT8 i = 0u;           /* 循环变量 */
    UINT16 devId = 0u;
    UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

    if ((AIR_SHAFT_ROUTE_SECTION_NUM_MAX < checkSum) || (NULL == dataIdBuf))
    {
        /*风井区段数据错误*/
        reVal = CI_ERROR;
    }
    else
    {
		/* 风井区段占用检查 */
		reVal = CI_SUCCESS;
        /*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecCurMergeState(devId);

			if (SECTION_OCCUPY_NO == devState)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}		
    }

    /*全部通过检查*/
    return reVal;
}


/*
* 功能描述： 进路风井区段锁闭检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* by yx 2026.03.04
*/
UINT8 RouteAirShaftSecLockCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路区段*/
	UINT8 const checkSum = GetRouteAiaShaftSecNum(routeId);
	UINT16* const dataIdBuf = GetRouteAiaShaftSecIdBuf(routeId);

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	if ((AIR_SHAFT_ROUTE_SECTION_NUM_MAX < checkSum)  || (NULL == dataIdBuf))
	{
		/*风井区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/* 风井区段占用检查 */
		reVal = CI_SUCCESS;
		/*开始检查*/
		/*风井区段锁闭检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPhySecLockState(devId);

			/*未锁闭或防护锁闭，不检查防护锁闭方向（之前已检查方向）*/
			if ((PHYSICAL_SECTION_LOCK_NO == devState) || (PHYSICAL_SECTION_LOCK_PROTECT == devState))
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
			
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 计轴区段所有防护道岔位置正确检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add mpt 20260331
*/
UINT8 AxisSecAllProtSwitchPosCheck(UINT16 const axisSecId, UINT16* pDevId, UINT8* pDevState)
{
	/* 计轴区段道岔 */
	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);

	/* 检查封锁状态 */
	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);	/*获取道岔当前位置*/
			reVal = checkSwtLastValDrvPosStayorNot(devId, devState);	/*检查道岔上一次驱动是否还在有效期*/
			if ((devState == dataIdBuf[i].SwitchPosition) && (CI_SUCCESS == reVal))
			{
				/*道岔位置正确且无驱动*/

			}
			else
			{
				/*道岔位置不正确*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 计轴区段防护道岔封锁状态检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* Add by mpt 20260331
*/
UINT8 AxisSecProtSwitchFLockCheck(UINT16 const axisSecId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路道岔 */
	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;


	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);
	/* 检查封锁状态 */
	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchFLockState(devId);
			if (SWITCH_LOCK_FENGSUO_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}
/*
* 功能描述： 检查计轴区段跳跃锁闭是否有防护道岔驱动超时
* 参数说明： const UINT16 routeId, 计轴区段ID
* 返回值  ： UINT8
			 CI_SUCCESS:计轴区段防护道岔无道岔驱动超时
			 CI_ERROR:计轴区段防护道岔驱动超时
add by mpt 20260331
*/
UINT8 ChekJumpLockProtectSwitDrivOvtmStat(const UINT16 axisSecId)
{
	UINT8 retVal = CI_ERROR;

	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;


	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);

	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		/*开始检查计轴区段内道岔*/
		for (i = 0u; i < checkSum; i++)
		{
			SwitchId = dataIdBuf[i].SwitchId;
			SwitchPos = dataIdBuf[i].SwitchPosition;
			SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

			if (SWITCH_POSITION_DINGWEI == SwitchPos)
			{
				/*道岔位置正确*/
				if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
				{
					retVal = CI_ERROR;
					break;
				}

			}
			else if (SWITCH_POSITION_FANWEI == SwitchPos)
			{
				/*道岔位置正确*/
				if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
				{
					retVal = CI_ERROR;
					break;
				}

			}
			else
			{
				/*什么也不做*/
			}
		}
	}

	return retVal;
}

/*
* 功能描述： 计轴区段的防护道岔位置和动作有效性检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add by mpt 20260331
*/
UINT8 AxisSecPorteSwitchPosMoveCheck(UINT16 const axisSecId, UINT16* pDevId, UINT8* pDevState, UINT8 funcId, UINT8 sendLevel)
{
	/* 计轴区段道岔 */

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8  switchPos = 0u;

	UINT8 switchMoveState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8 checkResult = 0u;

	UINT8  checkSum = 0U;
	AxisSwitchStruct* dataIdBuf = NULL;


	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);
	/*联锁检查*/
	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		/* 进路内所有道岔位置正确 且不为【挤岔】 或位置不正确道岔可动作*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchCurPosition(devId);
			switchPos = dataIdBuf[i].SwitchPosition;
			if (devState == switchPos)
			{
				/* 道岔位置正确 */
				/*如果最近一次产生的有效驱动仍在延续，则返回失败*/
				checkResult = checkSwtLastValDrvPosStayorNot(devId, switchPos);
				if (CI_SUCCESS == checkResult)
				{
				}
				else
				{
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			else if (SWITCH_POSITION_SIKAI == devState)
			{
				/*四开*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				reVal = CI_ERROR;
			}
			else if (SWITCH_POSITION_JICHA == devState)
			{
				/*挤岔*/
				*pDevId = devId;
				*pDevState = devState;
				/* 记录故障码 */
				SetErrorData(funcId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				reVal = CI_ERROR;
			}
			else
			{
				/* 道岔位置不正确 */
				switchMoveState = GetSwitchMoveValidState(devId, SWITCH_OPER_NO_DANCAO, sendLevel);
				if (CI_SUCCESS == switchMoveState)
				{
					/*道岔可动*/
				}
				else
				{
					/*道岔位置不正确 且 道岔不可动作*/
					*pDevId = devId;
					*pDevState = devState;
					reVal = CI_ERROR;
				}
			}
			if (CI_ERROR == reVal)
			{
				break;
			}
		}
	}

	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 区段征用、区段防护道岔区段征用、区段内道岔道岔征用检查、区段内防护道岔道岔征用
* 参数说明：const UINT16 axisSecId 计轴区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add by mpt 20260331
*/
UINT8 JumpPhySectionUseCheck(const UINT16 axisSecId)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 phyUseState = 0u;/*物理区段征用检查*/
	UINT16 phyId = 0u;



	/*跳跃锁闭所属物理区段*/
	phyId = GetAxisSecRelativePhySecId(axisSecId);/*获取相关物理区段ID*/
	phyUseState = GetPhySecUseState(phyId);/*获取物理区段征用状态*/
	if (PHYSICAL_SECTION_USING_NO == phyUseState)
	{
		reResult = CI_SUCCESS;
	}
	else
	{
		/*无处理*/
	}

	/*检查计轴区段的防护道岔所在区段和道岔征用*/
	if (CI_SUCCESS == reResult)
	{
		reResult = JumpPhySectionPortectUseCheck(axisSecId);
	}
	else
	{
		/*无处理*/
	}


	/*检查计轴区段的道岔征用*/
	if (CI_SUCCESS == reResult)
	{
		reResult = JumpPhySectionSwitchUseCheck(axisSecId);
	}
	else
	{
		/*无处理*/
	}




	return reResult;
}

/*
* 功能描述：区段防护道岔区段、防护道岔征用检查
* 参数说明：const UINT16 axisSecId 计轴区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*  add by mpt 20260331
*/
UINT8 JumpPhySectionPortectUseCheck(const UINT16 axisSecId)
{
	UINT16* pLogSectionIdBuf = NULL;
	UINT8 chLogSectionSum = 0U;
	UINT8 ii = 0U;
	UINT8 chRetVal = CI_ERROR;

	pLogSectionIdBuf = GetAxisSecLogSectionIdBuf(axisSecId);
	chLogSectionSum = GetAxisSecLogSectionSum(axisSecId);

	if (NULL != pLogSectionIdBuf)
	{
		for (ii = 0U; ii < chLogSectionSum; ii++)
		{
			/*检查逻辑区段防护道岔区段、道岔的征用*/
			chRetVal = JumpLogicSecPortectUseCheck(pLogSectionIdBuf[ii]);
			if (CI_SUCCESS != chRetVal)
			{
				break;
			}
		}
	}
	return chRetVal;
}


/*
* 功能描述：逻辑区段防护道岔区段征用、道岔征用检查
* 参数说明：const UINT16 axisSecId 计轴区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add by mpt 20260331
*/
UINT8 JumpLogicSecPortectUseCheck(const UINT16 wLgcId)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 chDevId = 0U;
	UINT8 chCheckSum = 0U;
	LogsecSwitchStruct* pstLogicSecSwitchBuf = NULL;
	UINT16 phyId = 0U;
	UINT8 phyUseState = 0U;
	UINT8 cSwitchUsingState = 0U;

	chCheckSum = GetLgcRelateProSwSum(wLgcId);/*获取指定ID逻辑区段关联防护道岔数目*/
	pstLogicSecSwitchBuf = GetLgcRelateProSwStru(wLgcId);
	if ((NULL != pstLogicSecSwitchBuf)
		&& (LOGSEC_RELATE_PRO_SW_SUM_MAX > chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		/*遍历逻辑区段关联防护道岔*/
		for (ii = 0U; ii < chCheckSum; ii++)
		{

			chDevId = pstLogicSecSwitchBuf[ii].SwitchId;
			cSwitchUsingState = GetSwitchUsingState(chDevId);
			phyId = GetSwitchPhySectionId(chDevId);
			phyUseState = GetPhySecUseState(phyId);
			if ((PHYSICAL_SECTION_USING_NO != phyUseState) || (SWITCH_USING_NO != cSwitchUsingState))
			{/*存区段征用或存在道岔征用*/
				chRetVal = CI_ERROR;
				break;
			}
			else
			{
				/*无处理*/
			}
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述：计轴区段所在道岔道岔征用检查
* 参数说明：const UINT16 axisSecId 计轴区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*  add by mpt 20260331
*/
UINT8 JumpPhySectionSwitchUseCheck(const UINT16 axisSecId)
{
	UINT8 retVal = CI_ERROR;

	UINT8  checkSum = 0U;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 wSwitchId = 0u;
	UINT8 cSwitchUsingState = 0U;

	checkSum = GetAxisSwitchSum(axisSecId);
	dataIdBuf = GetAxisSwitchIdStru(axisSecId);

	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		/*开始检查计轴区段内道岔*/
		for (i = 0u; i < checkSum; i++)
		{
			wSwitchId = dataIdBuf[i].SwitchId;
			cSwitchUsingState = GetSwitchUsingState(wSwitchId);
			if (SWITCH_USING_NO != cSwitchUsingState)
			{
				retVal = CI_ERROR;
				break;
			}
			else
			{
				/*继续循环*/
			}

		}
	}

	return retVal;
}


/*
* 功能描述：设置跳跃锁闭防护道岔区段征用状态
* 参数说明：const UINT16 axisSecId 计轴区段ID
*           const UINT8 state 状态
* 返回值  ： void
*  add by mpt 20260331
*/
void SetJumpPhySectionPortectSecUse(const UINT16 axisSecId, const UINT8 state)
{
	UINT16* pLogSectionIdBuf = NULL;
	UINT8 chLogSectionSum = 0U;
	UINT8 ii = 0U;

	pLogSectionIdBuf = GetAxisSecLogSectionIdBuf(axisSecId);
	chLogSectionSum = GetAxisSecLogSectionSum(axisSecId);

	if (NULL != pLogSectionIdBuf)
	{
		for (ii = 0U; ii < chLogSectionSum; ii++)
		{
			/*设置逻辑区段防护道岔区段征用*/
			SetJumpLogicSecPortectUse(pLogSectionIdBuf[ii], state);
		}
	}
}

/*
* 功能描述：设置逻辑区段的防护道岔区段征用
* 参数说明：const UINT16 axisSecId 计轴区段ID
*           const UINT8 state 状态
* 返回值  ： void
* add by mpt 20260331
*/
void SetJumpLogicSecPortectUse(const UINT16 wLgcId, const UINT8 state)
{
	/* 局部变量定义初始化 */
	UINT8 chRetVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT16 chDevId = 0U;
	UINT8 chCheckSum = 0U;
	LogsecSwitchStruct* pstLogicSecSwitchBuf = NULL;
	UINT16 phyId = 0U;

	chCheckSum = GetLgcRelateProSwSum(wLgcId);/*获取指定ID逻辑区段关联防护道岔数目*/
	pstLogicSecSwitchBuf = GetLgcRelateProSwStru(wLgcId);
	if ((NULL != pstLogicSecSwitchBuf)
		&& (LOGSEC_RELATE_PRO_SW_SUM_MAX > chCheckSum))
	{
		chRetVal = CI_SUCCESS;
		/*遍历逻辑区段关联防护道岔*/
		for (ii = 0U; ii < chCheckSum; ii++)
		{
			chDevId = pstLogicSecSwitchBuf[ii].SwitchId;
			phyId = GetSwitchPhySectionId(chDevId);
			/*设置物理区段征用*/
			SetPhySecUseState(phyId, state, 0U);
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
}

/*
* 功能描述： 设置计轴区段关联防护道岔防护锁闭状态
* 参数说明： const UINT16 axisSecId, 计轴区段ID
*            const UINT8 lockCommand, 锁闭状态
* 返回值  ： void
* add by mpt 20260331
*/
void SetAxisRelProSwitchLockSta(const UINT16 axisSecId, const UINT8 lockCommand)
{
	UINT8 ii = 0u;                                             /*遍历变量*/
	UINT8 retVal = CI_ERROR;                                /*返回值*/
	UINT16 protectSwitchId = 0u;                                      /*防护道岔ID*/
	UINT8 cSwitchCurPos = 0U;  /*道岔当前位置*/
	UINT8 cFuncRet = CI_ERROR;

	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;


	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);

	if (NULL == dataIdBuf)
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		if ((SWITCH_LOCK_PROTECT_SET != lockCommand) && (SWITCH_LOCK_PROTECT_CANCEL != lockCommand))
		{
			retVal = CI_ERROR;
		}
		else
		{
		}
	}

	if (CI_SUCCESS == retVal)
	{
		for (ii = 0u; ii < checkSum; ii++)
		{
			protectSwitchId = dataIdBuf[ii].SwitchId;
			cSwitchCurPos = GetSwitchCurPosition(protectSwitchId);
			cFuncRet = checkSwtLastValDrvPosStayorNot(protectSwitchId, dataIdBuf[ii].SwitchPosition);
			if ((SWITCH_LOCK_PROTECT_CANCEL == lockCommand)
				|| ((cSwitchCurPos == dataIdBuf[ii].SwitchPosition) && (CI_SUCCESS == cFuncRet)))
			{/*道岔可动作之前已经查了，这里还是重复查下*/
				SetSwitchLockStatus(SWITCH_PLOCKTYPE_AXISSEC, axisSecId, protectSwitchId, lockCommand);  /*设置道岔防护锁闭状态*/

			}
			else
			{
				/*防护道岔不在防护位置或防护道岔存在反向驱动，不设置防护锁闭*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
}


/*
* 功能描述： 计轴区段关联防护道岔防护锁闭检查
* 参数说明： UINT16 const routeId,    计轴区段号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* add mpt 20260331
*/
UINT8 AxisRelatedProSwitchLockCheck(UINT16 const axisSecId, UINT16* pDevId, UINT8* pDevState)
{

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;
	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;


	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);

	if (NULL == dataIdBuf)
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchLockStatus(devId);
			if ((SWITCH_LOCK_STATUS_PROTECT == devState) || (SWITCH_LOCK_STATUS_DAP == devState))
			{
				/*道岔已【防护锁闭】或【单锁且防护锁闭】*/
			}
			else
			{
				/*道岔未【防护锁闭】且未【单锁且防护锁闭】*/
				*pDevId = devId;
				*pDevState = SWITCH_LOCK_STATUS_PROTECT_NO;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 设置逻辑区段关联防护道岔防护锁闭状态
* 参数说明： const UINT16 axisSecId, 计轴区段ID
*            const UINT8 lockCommand, 锁闭状态
* 返回值  ： void
* add by mpt 20260331
*/
void SetLogSecRelProSwitchLockSta(const UINT16 wLgcId, const UINT8 lockCommand)
{
	UINT8 ii = 0u;                                             /*遍历变量*/
	UINT8 retVal = CI_ERROR;                                /*返回值*/
	UINT16 protectSwitchId = 0u;                                      /*防护道岔ID*/
	UINT8 cSwitchCurPos = 0U;  /*道岔当前位置*/
	UINT8 cFuncRet = CI_ERROR;

	UINT8  checkSum = 0u;
	LogsecSwitchStruct* dataIdBuf = NULL;
	UINT16* pLgcSecRltvAxleSecIdBuf = NULL;


	checkSum = GetLgcRelateProSwSum(wLgcId);/*获取指定ID逻辑区段关联防护道岔数目*/
	dataIdBuf = GetLgcRelateProSwStru(wLgcId);
	pLgcSecRltvAxleSecIdBuf = GetLgcSecRltvAxleSecIdBuf(wLgcId);


	if ((NULL == dataIdBuf) || (NULL == pLgcSecRltvAxleSecIdBuf))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		if ((SWITCH_LOCK_PROTECT_SET != lockCommand) && (SWITCH_LOCK_PROTECT_CANCEL != lockCommand))
		{
			retVal = CI_ERROR;
		}
		else
		{/*无处理*/
		}
	}

	if (CI_SUCCESS == retVal)
	{
		for (ii = 0u; ii < checkSum; ii++)
		{
			protectSwitchId = dataIdBuf[ii].SwitchId;
			cSwitchCurPos = GetSwitchCurPosition(protectSwitchId);
			cFuncRet = checkSwtLastValDrvPosStayorNot(protectSwitchId, dataIdBuf[ii].SwitchPosition);
			if ((SWITCH_LOCK_PROTECT_CANCEL == lockCommand)
				|| ((cSwitchCurPos == dataIdBuf[ii].SwitchPosition) && (CI_SUCCESS == cFuncRet)))
			{

				SetSwitchLockStatus(SWITCH_PLOCKTYPE_AXISSEC, pLgcSecRltvAxleSecIdBuf[0], protectSwitchId, lockCommand);  /*设置道岔防护锁闭状态*/

			}
			else
			{
				/*防护道岔不在防护位置或防护道岔存在反向驱动，不设置防护锁闭*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
}

/*
* 功能描述：计轴区段所有道岔是否全部征用
* 参数说明：const UINT16 axisSecId 计轴区段ID
* 返回值  ： CI_ERROR  未全部征用
*            CI_SUCCESS 全部征用
*  add by mpt 20260403
*/
UINT8 JumpPhySecAllUseCheck(const UINT16 axisSecId)
{
	UINT8 retVal = CI_ERROR;
	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 wSwitchId = 0u;
	UINT16 phyId = 0U;
	UINT8 phyUseState = 0U;

	checkSum = GetAxisSecRelateProSwSum(axisSecId);/*计轴区段关联防护道岔*/
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);


	if (NULL == dataIdBuf)
	{
		/*无检查项*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		/*开始检查防护道岔*/
		for (i = 0u; i < checkSum; i++)
		{
			wSwitchId = dataIdBuf[i].SwitchId;

			phyId = GetSwitchPhySectionId(wSwitchId);
			phyUseState = GetPhySecUseState(phyId);

			if (PHYSICAL_SECTION_USING_YES != phyUseState)
			{/*非征用*/
				retVal = CI_ERROR;
				break;
			}
			else
			{
				/*继续循环*/
			}

		}
	}

	if (CI_SUCCESS == retVal)
	{
		phyId = GetAxisSecRelativePhySecId(axisSecId);/*获取相关物理区段ID*/
		phyUseState = GetPhySecUseState(phyId);

		if (PHYSICAL_SECTION_USING_YES != phyUseState)
		{/*非征用*/
			retVal = CI_ERROR;
		}
		else
		{
			/*无执行*/
		}
	}

	return retVal;
}



/*
* 功能描述： 计轴区段防护道岔引导总锁状态检查
* 参数说明： UINT16 const axisSecId,    计轴区段编号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR 0 失败
*            CI_SUCCESS 1 成功
* Add by LQ 20260518
*/
UINT8 AxisSecProtSwtYLockCheck(UINT16 const axisSecId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路道岔 */
	UINT8  checkSum = 0u;
	AxisSwitchStruct* dataIdBuf = NULL;

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	UINT8 reVal = CI_ERROR;

	checkSum = GetAxisSecRelateProSwSum(axisSecId);
	dataIdBuf = GetAxisSecRelateProSwStru(axisSecId);
	/* 检查封锁状态 */
	if ((NULL != dataIdBuf) && (NULL != pDevId) && (NULL != pDevState))
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i].SwitchId;
			devState = GetSwitchYLockState(devId);
			if (SWITCH_LOCK_YINZONG_NO == devState)
			{
				/*未引导总锁，通过检查*/
			}
			else
			{
				/*引导总锁，停止遍历，返回失败*/
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	else
	{
		/*入参非法，返回失败*/
		reVal = CI_ERROR;
	}

	return reVal;
}