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

#include "InterlockLogicProcess.h"
#include "AxisSort_api.h"
#include "DynamicRouteDataManage.h"
#include "LogicalRouteLogicCheck.h"



/* C02_办理点式级别列车进路 */
/*
* 功能描述： 办理点式级别列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_BLOC_T_ROUTE
*/
UINT8 SetBlocLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_BLOC_T_ROUTE;  

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

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

/*故障发送级别*/
    UINT8 sendLevel = 0u; 
	UINT8 triggerFlag = 0u;

	triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/
    if ((AutoSignalOrRouteValid(routeId) == CI_SUCCESS) ||
		 (AUTO_TRIGGER_SET_YES == triggerFlag))
    {
        /*自动进路或自动触发进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }


/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_BLOC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【列车进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    if (CI_SUCCESS == reResult)
    {
		/* 进路状态为【进路空闲】或 【进路预选】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) || (ROUTE_STATE_FIRST_XUANPAI == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
    }

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
	       
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}

/* C03_办理CBTC级别列车进路 */
/*
* 功能描述： 办理CBTC级别列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_CBTC_T_ROUTE
*/
UINT8 SetCbtcLTrainRouteLogicProcess(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_SET_CBTC_T_ROUTE;

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

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

	/*虚拟联锁兼容*/
	UINT8 triggerFlag = 0u;
	/*故障发送级别*/
	UINT8 sendLevel = 0u;

	triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/
	if ((AutoSignalOrRouteValid(routeId) == CI_SUCCESS) ||
		(AUTO_TRIGGER_SET_YES == triggerFlag))
	{
		/*自动进路不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}

	/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
	devState = GetRouteLevel(routeId);
	if ((devState == ROUTE_LEVEL_CBTC))
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_LEVEL, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【列车进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_TYPE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【进路空闲】或【自动解锁正常】或 【进路预选】或【自动解锁异常（ARB且故障锁闭修改）】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) || (ROUTE_STATE_AUTO_UNLOCK == devState) || (ROUTE_STATE_FIRST_XUANPAI == devState)
			|| (ROUTE_STATE_AUTO_UNLOCKERR == devState) || (ROUTE_STATE_HALF_UNLOCK == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetCbtcRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}
	/*风井区段占用检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAirShaftSecOccuCheck(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
	{
		/*不处理*/
	}

	/*风井区段锁闭检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAirShaftSecLockCheck(routeId, &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)
	{
		/* 道岔联锁条件检查 */
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* RR1_办理具有反向属性的列车进路 */
/*
* 功能描述： 具有反向属性的列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_REVERSE_T_ROUTE
*/
UINT8 SetRevrLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_REVERSE_T_ROUTE;  

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

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

/*故障发送级别*/
    UINT8 sendLevel = 0u;            
	UINT8 isAutoSigRoute = CI_ERROR;

	isAutoSigRoute = AutoSignalOrRouteValid(routeId);
    if (CI_SUCCESS == isAutoSigRoute)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }


/* 联锁逻辑检查 */

    /* 进路类型是【列车进路】*/
	if(CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
    }
	
	
    /* 进路状态为【进路空闲】或 【进路预选】*/
	if(CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) || (ROUTE_STATE_FIRST_XUANPAI == devState) || (ROUTE_STATE_HALF_UNLOCK == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
    }
    /* 信号机联锁条件检查 */
	if(CI_SUCCESS == reResult)
	{
		checkResult = SetReverseRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /*照查联锁条件正确*/
	if(CI_SUCCESS == reResult)
    {	

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}
#if 0
	/*反向进路包含的自动信号进路状态检查*/
	if(CI_SUCCESS == reResult)
    {	
		devId = 0u;
		devState = 0u;
		checkResult = SetRevrRouteAutoSigStaCheck(routeId,functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
#endif	

    /* 区段联锁条件检查 */
	if(CI_SUCCESS == reResult)
    {	
		checkResult = SetReverseRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 道岔联锁条件检查 */
	if(CI_SUCCESS == reResult)
	{
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}






/* C04_办理点式级别折返进路 */
/*
* 功能描述： 办理点式级别折返进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_BLOC_R_ROUTE
*/
UINT8 SetBlocReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_BLOC_R_ROUTE;  

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

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

	UINT8 autoSignalOrRouteValid = 0u;

/*故障发送级别*/
    UINT8 sendLevel = 0u;  
	autoSignalOrRouteValid = AutoSignalOrRouteValid(routeId);
    if (CI_SUCCESS == autoSignalOrRouteValid)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((ROUTE_LEVEL_BLOC==devState ))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }
	
	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【折返进路】*/
		devState = GetRouteType(routeId);
		if (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)
	{
		/* 进路状态为【进路空闲】或 【进路预选】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE==devState) || (ROUTE_STATE_FIRST_XUANPAI==devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_RETURN_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
 
	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS==checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* C05_办理CBTC级别折返进路 */
/*
* 功能描述： 办理CBTC级别折返进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_CBTC_R_ROUTE
*/
UINT8 SetCbtcReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_CBTC_R_ROUTE;  

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

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

/*故障发送级别*/
    UINT8 sendLevel = 0u;                
    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_CBTC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【折返进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【进路空闲】或 【进路预选】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) || (ROUTE_STATE_FIRST_XUANPAI == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_RETURN_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* RR2_办理具有反向属性的折返进路 */
/*
* 功能描述： 办理具有反向属性的折返进路 
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_REVERSE_R_ROUTE
*/
UINT8 SetReverseRtnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_REVERSE_R_ROUTE;  

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

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

/*故障发送级别*/
    UINT8 sendLevel = 0u;                
    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路类型是【折返进路】*/
    if(CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 进路状态为【进路空闲】或 【进路预选】*/
	if(CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) || (ROUTE_STATE_FIRST_XUANPAI == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
    }
    /* 信号机联锁条件检查 */
	if(CI_SUCCESS == reResult)
	{
		checkResult = SetReverseRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /*照查联锁条件正确*/
	if(CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
#if 0
	/*反向进路包含的自动信号进路状态检查*/
	if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = SetRevrRouteAutoSigStaCheck(routeId,functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
#endif
	
    /* 区段联锁条件检查 */
	if(CI_SUCCESS == reResult)
	{
		checkResult = SetReverseRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
    }
	
    /* 道岔联锁条件检查 */
	if(CI_SUCCESS == reResult)
	{
		checkResult = SetBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    /* 返回成功 */
    return reResult;
}




/* C06_锁闭引导进路 */
/*
* 功能描述： 锁闭引导进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_LEAD_ROUTE
*/
UINT8 LockLeadRouteLogicProcess(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOCK_LEAD_ROUTE;

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

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

/*故障发送级别*/
	UINT8 sendLevel = 0u;
	UINT8 cFuncSwitch = FUNC_SWITCH_ON;  /*引导进路是否检查防淹门开关*/


	if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
	{
		/*自动进路不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}


	/* 联锁逻辑检查 */

		/* 进路引导属性是【可引导】*/
	devState = GetRouteLeadProperty(routeId);
	if ((ROUTE_LEAD_PROPERTY_YES == devState) || (ROUTE_LEAD_PROPERTY_CBTC_YES == devState))
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_LEAD_PROPERTY, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*  进路状态为【引导选排】*/
		devState = GetRouteState(routeId);
		if (devState == ROUTE_STATE_LEAD_XUANPAI)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetLeadRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_LEADROUTE_FLOODGATE_CHECK);

		if (FUNC_SWITCH_OFF == cFuncSwitch)
		{
			/*引导进路锁闭不检查防淹门状态*/
		}
		else
		{
			/*引导进路锁闭检查防淹门状态*/
			checkResult = BlocRouteFloodGateCheck(routeId, functionId, sendLevel);
		}

		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{

		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段有效性检查*/
		checkResult = LockLeadRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}


	}
	/* 返回成功 */
	return reResult;
}



/* C07_锁闭点式列车进路 */
/*
* 功能描述： 锁闭点式列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_BLOC_T_ROUTE
*/
UINT8 LockBlocLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_LOCK_BLOC_T_ROUTE;  

/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT16 devId = 0u;					 /*设备ID*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;  /*故障发送级别*/  
	UINT8 cAutoStateFlag = CI_ERROR;

	cAutoStateFlag = AutoSignalOrRouteValid(routeId);  /*获取自动属性*/
	if (cAutoStateFlag == CI_SUCCESS)
	{
		/*自动进路或自动信号不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}

/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_BLOC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }
	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【列车进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【进路选排】*/
		devState = GetRouteState(routeId);
		if (ROUTE_STATE_XUANPAI == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}
	if (CI_SUCCESS == reResult)
	{
		/*侵限区段侵限条件不满足检查*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId, &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)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段检查*/
		checkResult = LockBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* C08_锁闭CBTC列车进路 */
/*
* 功能描述： 锁闭CBTC列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_CBTC_T_ROUTE
*/
UINT8 LockCbtcLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_LOCK_CBTC_T_ROUTE;  

/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT8 devState = 0u;                 /*设备状态*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;  /*故障发送级别*/
    UINT16 devId = 0u;                   /*设备ID*/
	UINT8 routeStateFlag = ROUTE_STATE_FLAG_NO;   /*进路状态转移标志*/
	UINT8 cAutoStateFlag = CI_ERROR;

	cAutoStateFlag = AutoSignalOrRouteValid(routeId);  /*获取自动属性*/
	if (cAutoStateFlag == CI_SUCCESS)
	{
		/*自动进路或自动信号不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}

	routeStateFlag = GetRouteStateFlag(routeId);			   /* 获取进路状态转移标志*/
	

/* 联锁逻辑检查 */
    
    /* 进路监督模式为【CBTC】*/
    devState = GetRouteLevel(routeId);
    if (ROUTE_LEVEL_CBTC == devState)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【列车进路】*/
		devState = GetRouteType(routeId);
		if (ROUTE_TYPE_LIECHE == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
	   /* 进路状态为【进路选排】*/
		devState = GetRouteState(routeId);
		if (ROUTE_STATE_XUANPAI == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if ((ROUTE_STATE_AUTO_UNLOCK == devState) || (ROUTE_STATE_AUTO_UNLOCKERR == devState) || (ROUTE_STATE_HALF_UNLOCK == devState))
		{			
			if (ROUTE_STATE_FLAG_YES == routeStateFlag)
			{
				/*进路状态转移锁闭检查时，进路状态仍然为【自动解锁正常】或【自动解锁异常（ARB且故障锁闭修改）】*/
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
 
	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetCbtcRouteSectionCheck(routeId, functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	/*风井区段占用检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAirShaftSecOccuCheck(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
	{
		/*不处理*/
	}

	/*风井区段锁闭检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAirShaftSecLockCheck(routeId, &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)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*侵限区段侵限条件不满足检查*/
		checkResult = RouteIntruSecVainCheck(routeId, &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)
	{
		if ((ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId)) || (ROUTE_TYPE_AIRSHAFT == GetAirShaftRouteType(routeId)))
		{  /*反向进路需检查所有区段的占用状态，之前由于不检查占用状态导致信号出清进路内方第一逻辑区段，信号机重开的问题*/
			/*风井进路不允许追踪办进路*/
			devId = 0u;
			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)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段有效性检查*/
		checkResult = LockCBTCRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
     /* 返回成功 */
    return reResult;
}

/* C09_锁闭点式折返进路 */
/*
* 功能描述： 锁闭点式折返进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_BLOC_R_ROUTE
*/
UINT8 LockBlocReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_LOCK_BLOC_R_ROUTE;  

/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT16 devId = 0u;					/*设备ID*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;  /*故障发送级别*/
	UINT8 cAutoStateFlag = CI_ERROR;

	cAutoStateFlag = AutoSignalOrRouteValid(routeId);  /*获取自动属性*/
	if (cAutoStateFlag == CI_SUCCESS)
	{
		/*自动进路或自动信号不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}

/* 联锁逻辑检查 */
    
    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_BLOC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【折返进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【进路选排】*/
		devState = GetRouteState(routeId);
		if (ROUTE_STATE_XUANPAI == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}

	/*侵限区段侵限条件不满足检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId, &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)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段检查*/
		checkResult = LockBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* C10_锁闭CBTC折返进路 */
/*
* 功能描述： 锁闭CBTC折返进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_CBTC_R_ROUTE
*/
UINT8 LockCbtcReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_LOCK_CBTC_R_ROUTE;  

/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT16 devId = 0u;					/*设备ID*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;  /*故障发送级别*/
	UINT8 cAutoStateFlag = CI_ERROR;

	cAutoStateFlag = AutoSignalOrRouteValid(routeId);  /*获取自动属性*/
	if (cAutoStateFlag == CI_SUCCESS)
	{
		/*自动进路或自动信号不发送ATS*/
		sendLevel = ESEND_LEVEL_ZERO;
	}
	else
	{
		sendLevel = ESEND_LEVEL_ATS;
	}

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_CBTC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
       
    }

	if (CI_SUCCESS == reResult)
	{
		/* 进路类型是【折返进路】*/
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【进路选排】*/
		devState = GetRouteState(routeId);
		if (ROUTE_STATE_XUANPAI == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{ 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*侵限区段侵限条件不满足检查*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId, &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)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*进路包含的物理区段的非进路内且非道岔关联的逻辑区段检查*/
		checkResult = LockBlocRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    
    /* 返回成功 */
    return reResult;
}


/* C11_锁闭进路overlap逻辑处理 */
/*
* 功能描述： 锁闭进路overlap逻辑处理
* 参数说明： UINT16 const routeId, UINT16 const overlapId
* 返回值  ： CI_ERROR 0 失败
*            CI_SUCCESS 1 成功
*            RETURN_LOCK_ERR_SWITPOS 0x22 道岔位置错误
*            RETURN_WAIT_SWITCH_USING 0x30 等待防护道岔征用
*            RETURN_WAIT_SWITCH_CHECK 0x31 等待防护道岔检查
* 故障编码： EFUNC_LOCK_OVER_LAP
*/
UINT8 LockRouteOverlapLogicProcess(UINT16 const routeId, UINT16 const overlapId,UINT8 lockType)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_LOCK_OVER_LAP;  
    
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
	UINT8	devStateType = 0u;		/*设备状态类型*/
    UINT8 devState = 0u;                 /*设备状态*/
    
/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;		/*不发送ATS*/

	UINT8 lineIdentity = CI_TRADITION_RAILWAY;
	UINT8 secStopFlag = 0u;/*物理区段停稳状态*/
	UINT8 laborLockCmdFlag = 0u;
	UINT16 belongRouteId = 0u;
	UINT8 chOverlapFromRouteFlag = 0U;/*保护区段带进路ID命令*/
	UINT16 wRouteLeavePhySecId = 0U;/*进路离去区段ID*/
	UINT8 chLeavePhyCurOcuState = 0U;/*离去区段占用状态*/
	UINT8 cAlarmType = FLAG_UNSET;

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


	/* 联锁条件检查 */

	if(ATS_LOCK_OVERLAP == lockType)
	{
		chOverlapFromRouteFlag = GetOverlapFromSetRouteCmdFlag(overlapId);
		if (OVERLAP_ROUTE_FLAG_YES == chOverlapFromRouteFlag)
		{
			devId = GetRouteLastPhySectionId(routeId);
			devState = GetPhySecCurMergeState(devId);
			if (devState == SECTION_OCCUPY_NO)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				wRouteLeavePhySecId = GetRouteLeavePhySecId(routeId);
				chLeavePhyCurOcuState = GetPhySecCurMergeState(wRouteLeavePhySecId);
				if (SECTION_OCCUPY_NO == chLeavePhyCurOcuState)
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, wRouteLeavePhySecId, ETYPE_PS_MERGY_OCU_STATE, chLeavePhyCurOcuState, sendLevel);
					/* 失败返回 */
					reResult = CI_ERROR;
				}
				else
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
			}
		}
		else
		{
			/*非带进路ID的ATS办理保护区段不再检查进路最后一个区段占用状态*/
			reResult = CI_SUCCESS;
		}	
	}
	else
	{
		/*进路最后一个区段【空闲】*/
		devId = GetRouteLastPhySectionId(routeId);
		devState = GetPhySecCurMergeState(devId);
		if (devState == SECTION_OCCUPY_NO)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
#if 0
			/*检查保护区段道岔征用状态*/
			overlapSwitchUsing = OvlpIncludeAndProtSwitchCheck(overlapId);

			/*保护区区段道岔征用*/
			if(CI_SUCCESS == overlapSwitchUsing)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
#endif
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}

	}

	/*检查物理区段停稳状态*/
	if (CI_SUCCESS == reResult)
	{
		devId = GetRouteLastPhySectionId(routeId);
		secStopFlag = GetPhySecStopSteadyFlag(devId);
		if(PHYSICAL_SECTION_STOPSTEADY_NO == secStopFlag)
		{/*未收到停稳信息*/
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_STOPSTEADY_STATE,secStopFlag,sendLevel);/*只记录不发送*/
			/* 失败返回 */
			reResult = CI_ERROR;
		}

	}

	/*进路最后一个区段【正常锁闭】且属于当前进路*/
	if (CI_SUCCESS == reResult)
	{
		
		devId = GetRouteLastPhySectionId(routeId);
		devState = GetPhySecLockState(devId);
		belongRouteId = GetPhySecRLockBelongRouteId(devId);
		if ((PHYSICAL_SECTION_LOCK_NORMAL == devState) &&
			(belongRouteId == 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;

		if(ATS_LOCK_OVERLAP ==lockType)
		{
			reResult = AtsLockOverlapSecOccupyCheck(overlapId,&devId,&devState);
			if (CI_SUCCESS != reResult)
			{	/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
			}
		}
		else if(CI_LOCK_OVERLAP ==lockType)
		{
			reResult = OverlapAllSecOccuClearCheck(overlapId,&devId,&devState);
			if (CI_SUCCESS != reResult)
			{
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel);
			}
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	/*保护区段照查条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = OverlapZhaoChaRelayCheck(overlapId, sendLevel);

		if (CI_ERROR == checkResult)
		{
			reResult = CI_ERROR;
		}
		else
		{
			; /*保持之前检查结果，锁闭时先不检查本端是否满足*/
		}
	}

	/*保护区段 内所有区段及保护区段防护道岔所在区段【未征用】*/
	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, SWITCH_USING_YES, sendLevel);
			}
			else
			{
				/*按物理区段报警*/
				SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_USE_STATE, devState, sendLevel);
			}
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段内道岔和防护道岔未征用或属于本保护区段征用*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		checkResult = CheckOverlapSwitchUseState(overlapId, &devId);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查，保持当前状态 */
		}
		else if (RETURN_WAIT_SWITCH_USING == checkResult)
		{
			reResult = RETURN_WAIT_SWITCH_USING;
		}
		else
		{
			/* 记录故障码 */
			/*设置错误码：道岔已征用*/
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_USE_STATE,SWITCH_USING_YES,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

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

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

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

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

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

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

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

		if (checkResult == 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) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapAllSecJumpLockStateCheck(overlapId,&devId,&devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查，保持当前状态 */
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_JUMP_LOCK,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*保护区段关联的物理区段包含的非保护区段内的所有逻辑区段未被进路、逻辑进路锁闭*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		checkResult = CheckOverlapPhysecOtherLock(overlapId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查，保持当前状态 */
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}

	}


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

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

	/*保护区段内所有防淹门状态检查*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		checkResult = OverlapFloodGateStateCheck(overlapId,&devId,&devStateType,&devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查，保持当前状态 */
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,devId,devStateType,devState,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

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

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

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

	/*保护区段内所有道岔位置正确或位置不正确但可动作*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		if (CI_TRADITION_RAILWAY == lineIdentity)
		{/*传统线路*/
			checkResult = OverlapSwitchMoveValidCheck(overlapId,&devId,&devState);
		}/* zt 删除单轨相关代码 2022-02-15 */
		else
		{/*线路类型错误*/
			checkResult = CI_ERROR;
		}

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查，保持当前状态 */
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_POSTION_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	} 
	/*线路类型检查*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{/* zt 删除单轨相关代码 2022-02-15 */
		if (CI_TRADITION_RAILWAY == lineIdentity)
		{/*传统线路*/
			/* 通过检查，保持当前状态 */
		}
		else
		{/*线路类型错误*/
			reResult = CI_ERROR;
		}
	}

	/*保护区段道岔位置检查
     * RETURN_LOCK_ERR_SWITPOS： 保护区段道岔位置不正确
	 * CI_SUCCESS： 保护区段内所有道岔位置正确
		*/
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult))
	{
		devId = 0u;
		devState = 0u;
		if(CI_TRADITION_RAILWAY == lineIdentity)
		{/*传统线路*/
			checkResult = OverlapSwitchPosCheck(overlapId,&devId,&devState);
		}/* zt 删除单轨相关代码 2022-02-15 */
		else
		{/*线路类型错误*/
			checkResult = CI_ERROR;
		}

		if (checkResult == CI_ERROR)
		{
			/* 道岔位置不正确 */
			if (RETURN_WAIT_SWITCH_USING == reResult)
			{
				/*等待征用优先*/
			}
			else
			{
				reResult = RETURN_LOCK_ERR_SWITPOS;  /*返回道岔位置错误*/
			}
		}	
		else
		{
			/* 道岔位置正确 通过检查，保持当前状态 */
		}
	}
	
	if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult) || (RETURN_LOCK_ERR_SWITPOS == reResult))
	{/*如果保护区段内道岔位置正确或者位置不正确但可动，才继续做保护区段关联防护道岔相关检查*/
		/*保护区段关联防护道岔【未引导总锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = OvlpRelatedProSwitchYLockCheck(overlapId,&devId,&devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查，保持当前状态 */
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,devId,ETYPE_SWT_YLOCK_STATE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}

		/*保护区段关联防护道岔位置正确或位置不正确但可动作*/
		if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult) || (RETURN_LOCK_ERR_SWITPOS == reResult))
		{
			devId = 0u;
			devState = 0u;
			checkResult = OvlpRelatedProtSwiMovValCheck(overlapId, &devId, &devState, &cAlarmType);

			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查，保持当前状态 */
			}
			else if (RETURN_WAIT_SWITCH_CHECK == checkResult)
			{				
				if (RETURN_WAIT_SWITCH_USING == reResult)
				{
					/*等待征用优先，优先级：等待征用>等待检查>道岔位置错误*/
				}
				else
				{
					reResult = RETURN_WAIT_SWITCH_CHECK;  /*其它控区防护道岔可动性检查结果未确认，返回等待防护道岔检查*/
				}
			}
			else
			{
				/* 记录故障码 */
				if (FLAG_SET == cAlarmType)
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_MOVE_CHECK_RESULT, devState, sendLevel);
				}
				else
				{
					SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
				}
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}

		/*保护区段关联防护道岔位置正确*/
		if ((CI_SUCCESS == reResult) || (RETURN_WAIT_SWITCH_USING == reResult) || (RETURN_WAIT_SWITCH_CHECK == reResult) || (RETURN_LOCK_ERR_SWITPOS == reResult))
		{
			devId = 0u;
			devState = 0u;
			checkResult = OvlpRelatedProtSwitchPosCheck(overlapId,&devId,&devState);
			
			if (checkResult == CI_ERROR)
			{
				if ((RETURN_WAIT_SWITCH_USING == reResult) || (RETURN_WAIT_SWITCH_CHECK == reResult))
				{
					/*维持当前返回值，优先级：等待征用>等待检查>道岔位置错误*/
				}
				else
				{
					/* 道岔位置不正确 */
					reResult = RETURN_LOCK_ERR_SWITPOS;
				}
			}	
			else
			{
				/* 道岔位置正确 通过检查，保持当前状态 */
			}
		}
	}

	if(CI_ERROR == reResult)
	{
		laborLockCmdFlag = GetOverlaplaborLockCmdFlag(overlapId);
		if((LOCK_OVERLAP_CMD_YES == laborLockCmdFlag)&&(ATS_LOCK_OVERLAP ==lockType))
		{/*是人工锁闭保护区段*/
			SetOverlaplaborLockCmdFlag(overlapId,LOCK_OVERLAP_CMD_NO);

			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_OVERLAP,overlapId,ETYPE_OVERLAP_LABORUNLOCK_FAIL,0u,ESEND_LEVEL_ATS);

			SetRouteAtsExpLkOverlapId(routeId,0u);	/*人工锁闭，一次有效。清除期望锁闭保护区段ID*/
		}
	}

    return reResult;
}

/* C12_开放点式级别列车进路信号 */
/*
* 功能描述： 开放点式级别列车进路信号
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            RETURN_OPEN_ERR_SIGOPEN
*            CI_SUCCESS
* 故障编码： EFUNC_OPEN_BLOC_T_SIGNAL
*/
UINT8 OpenBlocLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_OPEN_BLOC_T_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u;                
    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }


/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_BLOC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

    /* 进路类型是列车进路*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【进路初锁】
        【进路初锁异常】
        【预先锁闭】
        【接近锁闭异常】
		【接近锁闭正常】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_FIRST_LOCK)||
			(devState == ROUTE_STATE_FIRST_LOCKERR)||
			(devState == ROUTE_STATE_YUXIAN_LOCK)||
			(devState == ROUTE_STATE_NEAR_LOCKERR) ||
			(devState == ROUTE_STATE_NEAR_LOCK))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{ 
			/* 失败返回 */
			reResult = checkResult;
		}
	}
    
    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSectionCheck(routeId, functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
       
    /* 站台联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
  
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    /* 返回 */
    return reResult;
}


/* C13_点式列车进路信号保持 */
/*
* 功能描述： 点式列车进路信号保持
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_KEEP_BLOC_T_SIGNAL
*/
UINT8 KeepBlocLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_KEEP_BLOC_T_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u; 

/* 自动信号属性检查结果 */
	UINT8 autoValueCheck = 0u;

	autoValueCheck = AutoSignalOrRouteValid(routeId);
    if (CI_SUCCESS == autoValueCheck)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if (ROUTE_LEVEL_BLOC == devState)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

    /* 进路类型是列车进路*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (ROUTE_TYPE_LIECHE == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【预先开放】或
        【接近开放】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_YUXIAN_OPEN == devState)||
			(ROUTE_STATE_NEAR_OPEN == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((ROUTE_ZONGQUXIAO_SET_NO == zxqFlag)&&
			(ROUTE_ZONGRENJIE_SET_NO == zrjFlag))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLTrainRouteSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}   
	}
    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSectionCheck(routeId, functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepRouteSwitchCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 站台联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	/*进路终端信号机CBTC检查*/
	if (CI_SUCCESS == reResult)
	{
		reResult = CheckRouteEndSignalNotCbtc(routeId,functionId,sendLevel);

	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    
    return reResult;
}


/* C14_开放CBTC级别列车进路信号 */
/*
* 功能描述： 开放CBTC级别列车进路信号
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_OPEN_CBTC_T_SIGNAL
*/
UINT8 OpenCbtcLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_OPEN_CBTC_T_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);
	UINT16 devId = 0u;                   /*设备ID*/
/*故障发送级别*/
    UINT8 sendLevel = 0u;                
    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteLevel(routeId);
		if ((devState == ROUTE_LEVEL_CBTC))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 进路类型是列车进路*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_LIECHE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【进路初锁】
        【进路初锁异常】
        【预先锁闭】
        【接近锁闭异常】
		【接近锁闭正常】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_FIRST_LOCK)||
			(devState == ROUTE_STATE_FIRST_LOCKERR)||
			(devState == ROUTE_STATE_YUXIAN_LOCK)||
			(devState == ROUTE_STATE_NEAR_LOCKERR)||
			(devState == ROUTE_STATE_NEAR_LOCK))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}

    
    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenCbtcRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*风井区段占用检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAirShaftSecOccuCheck(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
	{
		/*不处理*/
	}
	
    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 站台联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenCbtcRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
 
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	if (CI_SUCCESS == reResult)
	{
		if ((ROUTE_REVERSE_PROPERTY_YES == GetRouteReverseProperty(routeId)) || (ROUTE_TYPE_AIRSHAFT == GetAirShaftRouteType(routeId)))
		{  /*反向进路需检查所有区段的占用状态，之前由于不检查占用状态导致信号出清进路内方第一区段，信号机重开的问题*/
			/*风井进路不允许追踪办理，故开放条件需增加对进路内方所有区段的占用状态检查*/
			devId = 0u;
			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)
			{
				checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 失败返回 */
					reResult = checkResult;
				}
			}

			if (CI_SUCCESS == reResult)
			{
				/*反向或者风井进路，防淹门联锁条件检查*/
				checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
				if (CI_SUCCESS == checkResult)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}
		}
		else
		{
			/*既不是反向进路，也不是风井进路*/
			if (CI_SUCCESS == reResult)
			{
				/*防淹门联锁条件检查*/
				checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
				if (CI_SUCCESS == checkResult)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}
		}
	}
    
	

    return reResult;
}



/* C15_CBTC列车进路信号保持 */
/*
* 功能描述： CBTC列车进路信号保持
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_KEEP_CBTC_T_SIGNAL
* 修复bug YF0083-72
*/
UINT8 KeepCbtcLTrainRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_KEEP_CBTC_T_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u;  
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 autoValueCheck = 0u;   /* 自动信号属性检查结果 */
	UINT16 firstPhySecId = 0u;   /* 进路内方第一个物理区段ID */
	UINT8 trainEnterRouteState = CI_ERROR;   /* 列车驶入进路状态 */
	UINT16 startSigId = 0u;      /* 始端信号机ID */
	UINT8 signalCrossState = CI_ERROR;   /* 跨压信号机状态 */
	UINT8 routeRevProperty = 0u;      /* 进路反向属性 */
	UINT8 airShaftRouteType = 0u;   /* 风井进路属性 */

	autoValueCheck = AutoSignalOrRouteValid(routeId);
    if (CI_SUCCESS == autoValueCheck)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
    devState = GetRouteLevel(routeId);
    if (ROUTE_LEVEL_CBTC == devState)
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

    /* 进路类型是列车进路*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (ROUTE_TYPE_LIECHE == devState)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
    /* 进路状态为
        【预先开放】或
        【接近开放】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_YUXIAN_OPEN == devState)||
			(ROUTE_STATE_NEAR_OPEN == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((ROUTE_ZONGQUXIAO_SET_NO == zxqFlag)&&
			(ROUTE_ZONGRENJIE_SET_NO == zrjFlag))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLTrainRouteSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		} 
	}
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepCbtcRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepRouteSwitchCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    
    /* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
        
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepCBTCRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/* 进路内所有区段占用状态【空闲】*/
	if(CI_SUCCESS == reResult)
	{
		routeRevProperty = GetRouteReverseProperty(routeId);
		airShaftRouteType = GetAirShaftRouteType(routeId);
		if ((ROUTE_REVERSE_PROPERTY_YES == routeRevProperty) || (ROUTE_TYPE_AIRSHAFT == airShaftRouteType))
		{  /*反向进路或风井进路需对进路内方所有区段的占压状态进行检查*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSecOccuClearCheck(routeId,&devId, &devState);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				firstPhySecId = GetRouteFirstPhySectionId(routeId);
				trainEnterRouteState = GetTrainEnteringRouteState(routeId);
				startSigId = GetRouteStartSignalId(routeId);
				signalCrossState = GetSignalCrossState(startSigId);
				if((devId == firstPhySecId) 
					&& ((CI_SUCCESS == trainEnterRouteState) && (SIGNAL_CROSS_STATE_NO == signalCrossState)))
				{
					/*CBTC反向进路列车正驶入时跨压信息未到,此时不关信号*/
					reResult = CI_SUCCESS;
				}
				else
				{
				     if(devId == firstPhySecId)
					 {
					     reResult = CheckEngineerVehicleNear(routeId);/*检查是否是工程车接近的跨压*/
					 }
					 else
					 {
						 reResult = CI_ERROR; 
					 }
				    if(CI_SUCCESS != reResult)
					{
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,devId,ETYPE_PS_MERGY_OCU_STATE,devState,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
					}
				}

			}
			/* 防护进路联锁条件检查 */
			if (CI_SUCCESS == reResult)
			{
				checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
				if (CI_SUCCESS == checkResult)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}

			if (CI_SUCCESS == reResult)
			{
				/*防淹门联锁条件检查*/
				checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
				if (CI_SUCCESS == checkResult)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}

		}
		else
		{
			/*既不是反向，也不是风井*/
			if (CI_SUCCESS == reResult)
			{
				/*防淹门联锁条件检查*/
				checkResult = CBTCRouteFloodGateCheck(routeId,functionId,sendLevel);
				if (CI_SUCCESS == checkResult)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}
		}
		
	}
    
	

    return reResult;
}


/* C16_开放点式级别折返进路信号 */
/*
* 功能描述： 开放点式级别折返进路信号
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            RETURN_OPEN_ERR_SIGOPEN
*            CI_SUCCESS
* 故障编码： EFUNC_OPEN_BLOC_R_SIGNAL
*/
UINT8 OpenBlocReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_OPEN_BLOC_R_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u;
	UINT16 endSigId = 0u;				/*获取中途折返信号机ID*/
	UINT8 endSigState = SIGNAL_OPEN; 

    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_BLOC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

    /* 进路类型是【折返进路】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【进路初锁】
        【进路初锁异常】
        【预先锁闭】
        【接近锁闭异常】
		【接近锁闭正常】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_FIRST_LOCK)||
			(devState == ROUTE_STATE_FIRST_LOCKERR)||
			(devState == ROUTE_STATE_YUXIAN_LOCK)||
			(devState == ROUTE_STATE_NEAR_LOCKERR)||
			(devState == ROUTE_STATE_NEAR_LOCK))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{/*等待驱动将照查驱落和检查成功*/
			reResult = checkResult;
		}
	}

    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSectionCheck(routeId, functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    
    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
  
       
    /* 站台联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
  
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
   

	/* 进路终端信号机状态为未开放*/
	if (CI_SUCCESS == reResult)
	{
		endSigId = GetRouteEndSignalId(routeId); /*获取中途折返信号机ID*/
		endSigState = GetSignalOpenCloseState(GetSignalCurColor(endSigId));
		if (endSigState == SIGNAL_CLOSE)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		} 
	}
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    return reResult;
}


/* C17_点式折返进路信号保持 */
/*
* 功能描述： 点式折返进路信号保持
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_KEEP_BLOC_R_SIGNAL
*/
UINT8 KeepBlocReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_KEEP_BLOC_R_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u;                
    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【点式】*/

	devState = GetRouteLevel(routeId);
	if ((devState == ROUTE_LEVEL_BLOC))
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}


    /* 进路类型是【折返进路】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【预先开放】或
        【接近开放】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_YUXIAN_OPEN)||
			(devState == ROUTE_STATE_NEAR_OPEN))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
 
    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepBlocReturnSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{ 
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSectionCheck(routeId, functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
        
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
  
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	/*进路终端信号机CBTC检查*/
	if (CI_SUCCESS == reResult)
	{
		reResult = CheckRouteEndSignalNotCbtc(routeId,functionId,sendLevel);
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* C18_开放CBTC级别折返进路信号 */
/*
* 功能描述： 开放CBTC级别折返进路信号
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            RETURN_OPEN_ERR_SIGOPEN
*            CI_SUCCESS
* 故障编码： EFUNC_OPEN_CBTC_R_SIGNAL
*/
UINT8 OpenCbtcReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_OPEN_CBTC_R_SIGNAL;  

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

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

/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

    /*故障发送级别*/
    UINT8 sendLevel = 0u;         


    UINT16 devId = 0u;                   /*设备ID*/


    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteLevel(routeId);
		if ((devState == ROUTE_LEVEL_CBTC))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 进路类型是【折返进路】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 进路状态为
        【进路初锁】
        【进路初锁异常】
        【预先锁闭】
        【接近锁闭异常】
		【接近锁闭正常】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_FIRST_LOCK)||
			(devState == ROUTE_STATE_FIRST_LOCKERR)||
			(devState == ROUTE_STATE_YUXIAN_LOCK)||
			(devState == ROUTE_STATE_NEAR_LOCKERR)||
			(devState == ROUTE_STATE_NEAR_LOCK))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = SetBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{ 
			/* 失败返回 */
			reResult = checkResult;
		}
	}

    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenCbtcRouteSectionCheck(routeId, functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    
    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}
  
       
    /* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
  
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
		}
	}

	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 进路内所有区段占用状态【空闲】*/
    if(CI_SUCCESS == reResult)
    {
        devId = 0u;
        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)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    
    return reResult;
}


/* C19_CBTC折返进路信号保持 */
/*
* 功能描述： CBTC折返进路信号保持
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_KEEP_CBTC_R_SIGNAL
*/
UINT8 KeepCbtcReturnRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_KEEP_CBTC_R_SIGNAL;  

/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT8 devState = 0u;                 /*设备状态*/
/* 进路内设备数据 */
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);

/*故障发送级别*/
    UINT8 sendLevel = 0u;                

    UINT16 devId = 0u;                   /*设备ID*/
	UINT16 routeFirstPhyId = 0u;
	UINT8 rcWorkMode = GetLocalRcWorkMode();

    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路监督模式为【CBTC】*/
    devState = GetRouteLevel(routeId);
    if ((devState == ROUTE_LEVEL_CBTC))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEVEL,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
    }

    /* 进路类型是【折返进路】*/
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteType(routeId);
		if (devState == ROUTE_TYPE_RETURN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_TYPE,devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 进路状态为
        【预先开放】或
        【接近开放】
    */
	if (CI_SUCCESS == reResult)
	{
		devState = GetRouteState(routeId);
		if ((devState == ROUTE_STATE_YUXIAN_OPEN)||
			(devState == ROUTE_STATE_NEAR_OPEN))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*进路未设置【总取消】且未设置【总人解】*/
	if (CI_SUCCESS == reResult)
	{
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}


    /* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLTrainRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /*照查联锁条件正确*/
	if (CI_SUCCESS == reResult)
	{

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepCbtcRouteSectionCheck(routeId, functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 防护进路联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenBlocRouteOverlapCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    
    /* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
    /* 其他信号联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
  

	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    /* 进路内所有区段占用状态【空闲】*/
    if(CI_SUCCESS == reResult)
    {
		if (RC_WORK_MODE_TIOC == rcWorkMode)
		{/*TIOC*/
			checkResult = KeepCbtcReturnRouteSecOccCheck(routeId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				reResult = CI_ERROR;
			}
		}
		else if (RC_WORK_MODE_CI == rcWorkMode)
		{/*CI*/
			devId = 0u;
			devState = 0u;
			checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				routeFirstPhyId = GetRouteFirstPhySectionId(routeId);

				if ((devId == routeFirstPhyId) && ((GetTrainEnteringRouteState(routeId) == CI_SUCCESS) &&
					(GetSignalCrossState(GetRouteStartSignalId(routeId)) == SIGNAL_CROSS_STATE_NO)))
				{
					/*CBTC折返进路列车正驶入时跨压信息未到,此时不关信号*/
					reResult = CI_SUCCESS;
				}
				else
				{
					if (devId == routeFirstPhyId)
					{
						reResult = CheckEngineerVehicleNear(routeId);/*检查是否是工程车接近的跨压*/
					}
					else
					{
						reResult = CI_ERROR;
					}
					if (CI_SUCCESS != reResult)
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
						/* 失败返回 */
						reResult = CI_ERROR;
					}
				}

			}
		}
		else
		{
			reResult = CI_ERROR;/*模式错误返回失败*/
		}
    }
    
	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = BlocRouteFloodGateCheck(routeId,functionId,sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

    return reResult;
}


/* C20_开放引导进路逻辑处理 */
/*
* 功能描述： 开放引导进路逻辑处理
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_OPEN_LEAD_SIGNAL
*/
UINT8 OpenLeadRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_OPEN_LEAD_SIGNAL;  

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

/*故障发送级别*/
	UINT8 sendLevel = 0u;
	UINT8 cDetainCloseLeadFlag = 0u;

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

/* 进路内设备数据 */

    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);
	UINT8 cFuncSwitch = FUNC_SWITCH_ON;  /*引导进路是否检查防淹门开关*/


	/* 获取扣车后是否关闭引导信号标志 */
	cDetainCloseLeadFlag = GetCiFunctionSwitchConfig(FUNC_KOUCHE_CLOSE_YINDAO_FLAG);

    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }

/* 联锁逻辑检查 */

    /* 进路的引导属性为【可引导】*/
    devState = GetRouteLeadProperty(routeId);
    if ((ROUTE_LEAD_PROPERTY_YES == devState)||(ROUTE_LEAD_PROPERTY_CBTC_YES == devState))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEAD_PROPERTY,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
       
    }

    if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【引导锁闭】或【进路初锁异常】或【预先锁闭】或【接近锁闭正常】或【接近锁闭异常】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_LEAD_LOCK == devState) ||
			(ROUTE_STATE_FIRST_LOCKERR == devState) ||
			(ROUTE_STATE_YUXIAN_LOCK == devState) ||
			(ROUTE_STATE_NEAR_LOCK == devState) ||
			(ROUTE_STATE_NEAR_LOCKERR == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}	
	}

	if (CI_SUCCESS == reResult)
	{
	   /*进路未设置【总取消】且未设置【总人解】*/
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
 
	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = OpenBlocRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = OpenLeadRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = OpenBlocRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		} 
	}  
   
	if (CI_SUCCESS == reResult)
	{
		/* 其他信号联锁条件检查 */
		checkResult = OpenBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;
			
		}
	}
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_LEADROUTE_FLOODGATE_CHECK);

		if (FUNC_SWITCH_OFF == cFuncSwitch)
		{
			/*引导进路开放不检查防淹门状态*/
		}
		else
		{
			/*引导进路开放检查防淹门状态*/
			checkResult = BlocRouteFloodGateCheck(routeId, functionId, sendLevel);
		}

		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/*cgh-合并CID-2341-3： 功能开关-引导信号检查扣车可配置*/
	if (FUNC_SWITCH_ON == cDetainCloseLeadFlag)
	{
		/* 站台扣车联锁条件检查 */
		if (CI_SUCCESS == reResult)
		{
			checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	/*功能开关-是否执行引导总锁新功能*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = LeadzLockCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    return reResult;
}


/* C21_保持开放引导进路逻辑处理 */
/*
* 功能描述： 保持开放引导进路逻辑处理
* 参数说明： UINT16 const routeId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_KEEP_LEAD_SIGNAL
*/
UINT8 KeepLeadRouteLogicProcess(UINT16 const routeId)
{  
/*函数故障码*/
    UINT8 const functionId = EFUNC_KEEP_LEAD_SIGNAL;  

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

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

	/*故障发送级别*/
	UINT8 sendLevel = 0u;
	UINT8 cDetainCloseLeadFlag = 0u;

/* 进路内设备数据 */
    /* 始端信号机Id */
    UINT16 const startSignalId = GetRouteStartSignalId(routeId);
    /* 取消标志 */
    UINT8 const zxqFlag = GetRouteZongQuXiaoFlag(routeId);
    UINT8 const zrjFlag = GetRouteZongRenJieFlag(routeId);
	UINT8 cFuncSwitch = FUNC_SWITCH_ON;  /*引导进路是否检查防淹门开关*/

    /*引导信号开放时间状态*/
    UINT8 const leadSinalOpenState = SystemOverTimeCheck(GetRouteLeadFaultOpenStartCyc(routeId),
                                                         GetSystemParaLeadFaultOpenCyc());

    /*进路始端信号机内方第一区段*/
    UINT16 const routeInFirstSecId = GetSignalInFirstPhySecId(startSignalId, routeId);
    UINT8 const inSecCurOccupyState = GetPhySecCurMergeState(routeInFirstSecId);
    /*进路始端信号机外方第一区段*/
    UINT16 const routeOutFirstSecId = GetSignalOutFirstPhySecId(startSignalId);
    UINT8 const outSecPreOccupyState = GetPhySecPreMergeState(routeOutFirstSecId);
    UINT8 const outSecCurOccupyState = GetPhySecCurMergeState(routeOutFirstSecId);

	/* 获取扣车后是否关闭引导信号标志 */
	cDetainCloseLeadFlag = GetCiFunctionSwitchConfig(FUNC_KOUCHE_CLOSE_YINDAO_FLAG);

    if (AutoSignalOrRouteValid(routeId) == CI_SUCCESS)
    {
        /*自动进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }


/* 联锁逻辑检查 */

    /* 进路的引导属性为【可引导】*/
    devState = GetRouteLeadProperty(routeId);
    if ((ROUTE_LEAD_PROPERTY_YES == devState)||(ROUTE_LEAD_PROPERTY_CBTC_YES == devState))
    {
        /* 通过检查 */
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_LEAD_PROPERTY,devState,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
       
    }
	if (CI_SUCCESS == reResult)
	{
		/* 进路状态为【引导开放】*/
		devState = GetRouteState(routeId);
		if (devState == ROUTE_STATE_LEAD_OPEN)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
	   /*进路未设置【总取消】且未设置【总人解】*/
		if ((zxqFlag == ROUTE_ZONGQUXIAO_SET_NO)&&
			(zrjFlag == ROUTE_ZONGRENJIE_SET_NO))        
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_CANCEL, CI_ERROR,sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 信号机联锁条件检查 */
		checkResult = KeepLTrainRouteSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
    
	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = OpenLeadRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = KeepRouteSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
       
	if (CI_SUCCESS == reResult)
	{
		/* 其他信号联锁条件检查 */
		checkResult = KeepBlocRouteOtherSignalCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}	
	}
	/* 其他联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OtherCiValidCheck(routeId,functionId,sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	if (CI_SUCCESS == reResult)
	{
		if (leadSinalOpenState == CI_TIME_NO)
		{
			/*1.未设置延时*/
			if (inSecCurOccupyState != SECTION_OCCUPY_NO)
			{
				/*信号机内方区段【当前占用】或【故障】，引导信号立即关闭*/
				reResult = CI_ERROR;
			}
			else
			{
				/*1.3 内方区段【当前空闲】*/
				reResult = CI_SUCCESS;
			}
		}
		else if (leadSinalOpenState == CI_TIME_IN)
		{
			/*2.延时中*/
			
			if(0u < routeOutFirstSecId)
			{
				/*2.1 内方区段【当前占用】，外方区段【当前空闲】且【之前占用】（列车完全驶入）*/
				if ((inSecCurOccupyState != SECTION_OCCUPY_NO) && 
					(outSecCurOccupyState != SECTION_OCCUPY_YES) && (outSecPreOccupyState != SECTION_OCCUPY_NO))
				{
					reResult = CI_ERROR;
					/*立即关闭信号机*/
				
				}
				else
				{
					/*延时未到*/
					reResult = CI_SUCCESS;
				}
			}
			else
			{
				/*延时未到*/
				reResult = CI_SUCCESS;
			}
		}
		else 
		{
			/* 3.超时*/
			/*3.1信号开放时间超时*/
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		cFuncSwitch = GetCiFunctionSwitchConfig(FUNC_LEADROUTE_FLOODGATE_CHECK);

		if (FUNC_SWITCH_OFF == cFuncSwitch)
		{
			/*引导进路保持开放不检查防淹门状态*/
		}
		else
		{
			/*引导进路保持开放检查防淹门状态*/
			checkResult = BlocRouteFloodGateCheck(routeId, functionId, sendLevel);
		}

		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/*cgh-合并CID-2341-3： 功能开关-引导信号检查扣车可配置*/
	if (FUNC_SWITCH_ON == cDetainCloseLeadFlag)
	{
		/* 站台扣车联锁条件检查 */
		if (CI_SUCCESS == reResult)
		{
			checkResult = OpenRoutePlatformCheck(routeId, functionId, sendLevel);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	/*功能开关-是否执行引导总锁新功能*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = LeadzLockCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /* 返回成功 */
    return reResult;
}


/* C22_进路第一区段自动解锁 */
/*
* 功能描述： 进路第一区段自动解锁
* 参数说明： UINT16 const routeId，进路号
*            UINT16* phySectionId，解锁区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_UNLOCK_1ST_SECTION
*/
UINT8 RouteFirstSecAutoUnlockProcess(UINT16 const routeId, UINT16* phySectionId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_UNLOCK_1ST_SECTION;  
/* 局部变量定义初始化 */
    UINT8 reResult = CI_SUCCESS;        /*返回值*/
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/
/* 进路数据 */
    /*第一个属于当前进路的【正常锁闭】区段*/
	UINT16 nlockSectionId = 0U;
    /*进路属性*/
    UINT8 routeType = 0U;
    /*下一区段*/
    UINT16 nextSecId = 0U;
    /*有效折返信号机*/
    UINT16 validReturnSigId = 0U;
    /*折返区段*/
    UINT16 returnSecId = 0U;
    /*折出区段*/
    UINT16 backSecId = 0U;
    /*折出进路状态*/
    UINT8 backRouteState = 0U;
    /*折返进路锁闭时间*/
    UINT32 returnRouteLockTime = 0U;
    /*折出进路锁闭时间*/
    UINT32 backRouteLockTime = 0U;
	/*物理区段融合占用状态*/
	UINT8 mergeState = 0U;
	/*物理区段之前融合占用状态*/
	UINT8 mergePreState = 0U;
	/*下一物理区段融合占用状态*/
	UINT8 nextMergeState = 0U;
	/*物理区段锁闭所属进路*/
	UINT16 belongRouteID = 0U;
	/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO;    /*不发送ATS*/

	/*第一个属于当前进路的【正常锁闭】区段*/
	nlockSectionId = GetRouteFirstNormalLockSection(routeId);
	/*进路属性*/
	routeType = GetRouteType(routeId);
	/*下一区段*/
	nextSecId = GetRouteNextPhySecId(routeId, nlockSectionId);
	/*有效折返信号机*/
	validReturnSigId = GetValidReturnSinalId(routeId, nlockSectionId);
	/*折返区段*/
	returnSecId = GetSignalOutFirstPhySecId(validReturnSigId);
	/*折出区段*/
	backSecId = GetSignalInFirstLockedPhySecId(validReturnSigId);
	/*物理区段锁闭所属进路*/
	belongRouteID = GetPhySecRLockBelongRouteId(backSecId);
	/*折出进路状态*/
	backRouteState = GetRouteState(belongRouteID);
	/*折返进路锁闭时间*/
	returnRouteLockTime = GetRouteLockStartCycNum(routeId);
	/*折出进路锁闭时间*/
	backRouteLockTime = GetRouteLockStartCycNum(belongRouteID);

	if(CI_SUCCESS == reResult)
	{
		/*找到属于当前进路的第一个【正常锁闭】区段*/
		if (nlockSectionId > 0u)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
	        
			/*返回ID = 0*/
			*phySectionId = 0u;

		}
	}
#if 0
	if(CI_SUCCESS == reResult)
	{
		cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId);
		if((0u != cancleZhaoChaRelayId) && (0xFFFF != cancleZhaoChaRelayId))
		{
			/*取消继电器有效：取消继电器采集状态为：吸起*/
			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_CANCLE_ZHAOCHA_FAIL;
				/*返回ID = 0*/
				*phySectionId = nlockSectionId;

			}

		}

	}
#endif

	if(CI_SUCCESS == reResult)
	{
		/*进路为【折返进路】且解锁区段为折返区段*/
		if ((routeType == ROUTE_TYPE_RETURN)
			&& (nlockSectionId == returnSecId))
		{
			/*折返解锁*/
			/*折返区段【空闲】之前【占用】*/
			mergeState = GetPhySecCurMergeState(returnSecId);
			mergePreState = GetPhySecPreMergeState(returnSecId);
			if ((SECTION_OCCUPY_NO== mergeState) && (SECTION_OCCUPY_YES== mergePreState))
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
				*phySectionId = nlockSectionId;
			}
			/*进路内方第一区段由占用变空闲时才触发解锁流程，检查取消照查继电器(如果配置了)状态*/
			if(CI_SUCCESS == reResult)
			{
				cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/
				
				if((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
				{
					/*取消继电器有效：取消继电器采集状态为：吸起*/
					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_CANCLE_ZHAOCHA_FAIL;
						/*返回ID = 0*/
						*phySectionId = nlockSectionId;

					}
				}
			}
            if(CI_SUCCESS == reResult)
			{
				/*折出进路第一个区段【占用】*/
				mergeState = GetPhySecCurMergeState(backSecId);
				if (SECTION_OCCUPY_YES== mergeState)
				{
					/*折返正常*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*折返异常*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,backSecId,ETYPE_PS_RUNLOCK_ERROR, mergeState, sendLevel);
					/* 失败返回 */
					reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
					*phySectionId = nlockSectionId;

				}
			}
			if(CI_SUCCESS == reResult)
			{
				/*折返进路锁闭时间早于折出进路 且 折出进路状态为【接近锁闭正常】【自动解锁】*/
				if ((returnRouteLockTime < backRouteLockTime)
					&&(( ROUTE_STATE_NEAR_LOCK == backRouteState)
						||(ROUTE_STATE_AUTO_UNLOCK == backRouteState)))
				{
					reResult = CI_SUCCESS;
					*phySectionId = nlockSectionId;
				}
				else
				{
					/*折返异常*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE, belongRouteID,ETYPE_PS_RUNLOCK_ERROR, backRouteState,sendLevel);
					/* 失败返回 */
					reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
					*phySectionId = nlockSectionId;
				}
			}
		}
		else
		{
			/*正常解锁*/
			/*当前区段之前【当前空闲】【之前占用】*/
			mergeState = GetPhySecCurMergeState(nlockSectionId);
			mergePreState = GetPhySecPreMergeState(nlockSectionId);
			if ((SECTION_OCCUPY_NO == mergeState) &&
				(SECTION_OCCUPY_YES == mergePreState))
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
				*phySectionId = nlockSectionId;	
			}
			/*进路内方第一区段由占用变空闲时才触发解锁流程，检查取消照查继电器(如果配置了)状态*/
			if(CI_SUCCESS == reResult)
			{
				cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/
				
				if((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
				{
					/*取消继电器有效：取消继电器采集状态为：吸起*/
					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_CANCLE_ZHAOCHA_FAIL;
						/*返回ID = 0*/
						*phySectionId = nlockSectionId;

					}

				}
			}
			if(CI_SUCCESS == reResult)
			{
				/* 下一区段【占用】*/
				nextMergeState = GetPhySecCurMergeState(nextSecId);
				if (SECTION_OCCUPY_YES == nextMergeState)
				{
					/*正常解锁区段*/
					reResult = CI_SUCCESS;
					*phySectionId = nlockSectionId;
				}
				else
				{
					if (0U < validReturnSigId)/*通过进路转折返进路*/
					{
						/*折出进路第一个区段占用*/
						mergeState = GetPhySecCurMergeState(backSecId);
						if (SECTION_OCCUPY_YES == mergeState)
						{
							/*折返正常*/
							reResult = CI_SUCCESS;
						}
						else
						{
							/*折返异常*/
							/* 记录故障码 */
							SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, backSecId, ETYPE_PS_RUNLOCK_ERROR, mergeState , sendLevel);
							/* 失败返回 */
							reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
							*phySectionId = nlockSectionId;
						}

						if (CI_SUCCESS == reResult)
						{
							/*折返进路锁闭时间早于折出进路 且 折出进路状态为【接近锁闭正常】*/
							if ((backRouteLockTime > returnRouteLockTime) && (ROUTE_STATE_NEAR_LOCK== backRouteState))
							{
								reResult = CI_SUCCESS;
								*phySectionId = nlockSectionId;
							}
							else
							{
								/*折返异常*/
								/* 记录故障码 */
								SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, belongRouteID, ETYPE_PS_RUNLOCK_ERROR, backRouteState, sendLevel);
								/* 失败返回 */
								reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
								*phySectionId = nlockSectionId;
							}
						}
					}
					else
					{/*通过进路解锁异常*/
					/*下一区段【空闲】（飞车）*/
					/* 解锁异常 */
					/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, nextSecId, ETYPE_PS_AUNLOCK_ERROR,nextMergeState, sendLevel);
						/* 失败返回 */
						reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
						*phySectionId = nlockSectionId;
					}
				}
			}
		}
	}
	return reResult;
}


/* C23_进路其余区段自动解锁 */
/*
* 功能描述： 进路其余区段自动解锁
* 参数说明： UINT16 const routeId，进路号
*            UINT16* phySectionId，解锁区段ID
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_UNLOCK_OTHERS_SECTION
*/
UINT8 RouteOtherSecAutoUnlockProcess(UINT16 const routeId, UINT16* phySectionId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_UNLOCK_OTHERS_SECTION;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_SUCCESS;        /*返回值*/
/* 进路数据 */
    /*第一个属于当前进路的【正常锁闭】区段*/
    UINT16 const nlockSectionId = GetRouteFirstNormalLockSection(routeId); 
    /*进路属性*/
    UINT8 const routeType = GetRouteType(routeId);
    /*下一区段*/
    UINT16 const nextSecId = GetRouteNextPhySecId(routeId,nlockSectionId);
    /*有效折返信号机*/
    UINT16 const validReturnSigId = GetValidReturnSinalId(routeId,nlockSectionId);
    /*折返区段*/
    UINT16 const returnSecId = GetSignalOutFirstPhySecId(validReturnSigId);
    /*折出区段*/
    UINT16 const backSecId = GetSignalInFirstLockedPhySecId(validReturnSigId);
	/*物理区段锁闭所属进路*/
	UINT16 const wPhySecRLockId = GetPhySecRLockBelongRouteId(backSecId);
    /*折出进路状态*/
    UINT8 const backRouteState = GetRouteState(wPhySecRLockId);
    /*折返进路锁闭时间*/
    UINT32 const returnRouteLockTime = GetRouteLockStartCycNum(routeId);
    /*折出进路锁闭时间*/
    UINT32 const backRouteLockTime = GetRouteLockStartCycNum(wPhySecRLockId);
/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO; 	/*不发送ATS*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段当前融合状态*/
	UINT8 chPhySecPreMergeState = 0U;/*物理区段之前融合状态*/

/*联锁检查*/
	
	if(CI_SUCCESS == reResult)
	{
		/*找到属于当前进路的第一个【正常锁闭】区段*/
		if (nlockSectionId > 0u)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

			/*返回ID = 0*/
			*phySectionId = 0u;

		}
	}
    if(CI_SUCCESS == reResult)
	{
		/*进路为【折返进路】且解锁区段为折返区段*/
		if ((routeType == ROUTE_TYPE_RETURN)
			&& (nlockSectionId == returnSecId))
		{
			/*折返解锁*/
			/*折返区段【空闲】之前【占用】*/
			chPhySecCurMergeState = GetPhySecCurMergeState(returnSecId);
			chPhySecPreMergeState = GetPhySecPreMergeState(returnSecId);

			if ((SECTION_OCCUPY_NO == chPhySecCurMergeState) &&
				(SECTION_OCCUPY_YES == chPhySecPreMergeState))
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
				*phySectionId = nlockSectionId;
			}
			
			if(CI_SUCCESS == reResult)
			{
				/*折出进路第一个区段【占用】*/
				chPhySecCurMergeState = GetPhySecCurMergeState(backSecId);

				if (SECTION_OCCUPY_YES == chPhySecCurMergeState)
				{
					/*折返正常*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*折返异常*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,backSecId,ETYPE_PS_RUNLOCK_ERROR,chPhySecCurMergeState,sendLevel);
					/* 失败返回 */
					reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
					*phySectionId = nlockSectionId;
				}
			}
			if(CI_SUCCESS == reResult)
			{
				/*折返进路锁闭时间早于折出进路 且 折出进路状态为【接近锁闭正常】*/
				if ((returnRouteLockTime < backRouteLockTime)
					&& ((ROUTE_STATE_NEAR_LOCK == backRouteState)
						|| (ROUTE_STATE_AUTO_UNLOCK == backRouteState)))
				{
					reResult = CI_SUCCESS;
					*phySectionId = nlockSectionId;
				}
				else
				{
					/*折返异常*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE, wPhySecRLockId,ETYPE_PS_RUNLOCK_ERROR, backRouteState,sendLevel);
					/* 失败返回 */
					reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
					*phySectionId = nlockSectionId;
				}
			}
		}
		else
		{
			/*正常解锁*/
			/*当前区段之前【当前空闲】【之前占用】*/
			chPhySecCurMergeState = GetPhySecCurMergeState(nlockSectionId);
			chPhySecPreMergeState = GetPhySecPreMergeState(nlockSectionId);

			if ((SECTION_OCCUPY_NO == chPhySecCurMergeState) &&
				(SECTION_OCCUPY_YES == chPhySecPreMergeState))
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
				*phySectionId = nlockSectionId;
				
			}
			if(CI_SUCCESS == reResult)
			{
				/* 下一区段【占用】*/
				chPhySecCurMergeState = GetPhySecCurMergeState(nextSecId);
				if (SECTION_OCCUPY_YES == chPhySecCurMergeState)
				{
					/*正常解锁区段*/
					reResult = CI_SUCCESS;
					*phySectionId = nlockSectionId;
				}
				else
				{
					if (validReturnSigId > 0u)/*通过进路转折返进路*/
					{
						/*折出进路第一个区段占用*/
						chPhySecCurMergeState = GetPhySecCurMergeState(backSecId);

						if (SECTION_OCCUPY_YES == chPhySecCurMergeState)
						{
							/*折返正常*/
							reResult = CI_SUCCESS;
						}
						else
						{
							/*折返异常*/
							/* 记录故障码 */
							SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,backSecId,ETYPE_PS_RUNLOCK_ERROR, chPhySecCurMergeState,sendLevel);
							/* 失败返回 */
							reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
							*phySectionId = nlockSectionId;
						}
						if(CI_SUCCESS == reResult)
						{
							/*折返进路锁闭时间早于折出进路 且 折出进路状态为【接近锁闭正常】*/
							if ((((INT32)(backRouteLockTime- returnRouteLockTime)) > 0 )
								&&(backRouteState == ROUTE_STATE_NEAR_LOCK))
							{
								reResult = CI_SUCCESS;
								*phySectionId = nlockSectionId;
							}
							else
							{
								/*折返异常*/
								/* 记录故障码 */
								SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE, wPhySecRLockId,ETYPE_PS_RUNLOCK_ERROR, backRouteState,sendLevel);
								/* 失败返回 */
								reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
								*phySectionId = nlockSectionId;
							}
						}
					}
					else
					{/*通过进路解锁异常*/
						/*下一区段【空闲】（飞车）*/
						/* 解锁异常 */
						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,nextSecId,ETYPE_PS_AUNLOCK_ERROR, chPhySecCurMergeState,sendLevel);
						/* 失败返回 */
						reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
						*phySectionId = nlockSectionId;
					}
				}
			}
		}
	}
	return reResult;
}


/* C24_区段延时解锁*/
/*
* 功能描述： 区段延时解锁
* 参数说明： UINT16 const routeId，进路号
*            UINT16* phySectionId，解锁区段ID
* 返回值  ： CI_ERROR
*            RETURN_DELAYUNLOCK_ERR_TIMECOUNT
*            CI_SUCCESS
* 故障编码： EFUNC_DLOCK_SECTION
*/
UINT8 PhySectionDelayUnlockProcess(UINT16 const routeId, UINT16* phySectionId)
{
/*函数故障码*/
    /*UINT8 const functionId = EFUNC_DLOCK_SECTION;*/  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/

	UINT32 cycNum = 0u;
	UINT32 cycNumSysPara = 0u;/*系统参数区段延时解锁周期*/

	UINT8 routeTimeState = CI_TIME_OUT;
    
    /* 进路数据 */
    /*第一个属于当前进路的【延时锁闭】区段*/
    UINT16 const dlockSectionId = GetRouteFirstDelayLockSection(routeId); 
    /*占用状态*/
    UINT8 const secOccypyState = GetPhySecCurMergeState(dlockSectionId);

	cycNum = GetPhySecAutoUnlockStartCycNum(dlockSectionId);
	cycNumSysPara = GetSystemParaSecDelayUnlockCyc();
    /* 区段延时解锁时间状态*/
    routeTimeState = SystemOverTimeCheck(cycNum, cycNumSysPara);

    
/*联锁检查*/

    /*进路第一个区段【延时锁闭】且属于当前进路*/
    if (dlockSectionId > 0u)
    {
        reResult = CI_SUCCESS;
    }
    else
    {
        /* 失败返回 */
        reResult = CI_ERROR;

        /*返回ID = 0*/
        *phySectionId = 0u;

    }

	if (CI_SUCCESS == reResult)
	{
		/*区段占用状态 = 【空闲】*/
		if (secOccypyState == SECTION_OCCUPY_NO)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			/* 重置延时 */
			*phySectionId = dlockSectionId;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*延时解锁时间检查*/
		if (routeTimeState == CI_TIME_NO)
		{
			/*延时未设置*/
			/* 失败返回 */
			reResult = CI_ERROR;
			/* 重置延时 */
			*phySectionId = dlockSectionId;
			
		}
		else if (routeTimeState == CI_TIME_IN)
		{
			/*时间未到*/
			/* 失败返回 */
			reResult = RETURN_DELAYUNLOCK_ERR_TIMECOUNT;
			/* 继续延时 */
			*phySectionId = dlockSectionId;
			
		}
		else
		{
			/* 时间到时 */
			reResult = CI_SUCCESS;
			/* 解锁区段 */
			*phySectionId = dlockSectionId;
			
		}
	}

	return reResult;
}

/* C25_解锁进路overlap逻辑处理 */
/*
* 功能描述： 解锁进路overlap逻辑处理
* 参数说明： const UINT16 routeId   进路号
* 返回值  ： CI_ERROR 0x00 失败
*            CI_SUCCESS 0x01 成功
*            CI_UNLOCK_OVERLAP_REQURE 0x02 向ZC/车申请解锁保护区段
*            CI_OVERLAP_OCC_UNLOCK 0x06 保护区段执行占用特殊解锁
* 故障编码： EFUNC_UNLOCK_OVER_LAP
*/
UINT8 UnlockRouteOverlapLogicProcess(UINT16 const routeId, UINT16* overlapId,UINT16* pTrainId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_UNLOCK_OVER_LAP;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

	UINT8 secStopTimeState = CI_TIME_NO;			/*倒计时是否超时检查参数*/
	/*物理区段CT或UT占用状态，设置为(UT)占用状态*/
	UINT8 utOrCtOccFlag = LOGICSECTION_OCCUPY_UT;
	UINT8 functionSwitchFlag = 0u;
    
    /*进路最后一个区段*/
    UINT16 const routeLastSecId = GetRouteLastPhySectionId(routeId);
    UINT16 const secStopFlag = GetPhySecStopSteadyFlag(routeLastSecId);

    /*防护进路*/
    UINT8 const overlapSum = GetRouteOverlapSum(routeId);
    UINT16 const overlapLockedId = GetRouteOverlapLockedId(routeId);

	UINT8 tmpRouteBelongCiId = 0u;
	UINT8 localCiId = 0u;
	UINT8 overlapBelongCiId = 0u;
	UINT16 overlapUnLockCount = 0u;/*保护区段解锁周期数*/

	UINT32 relyonStartCycNum = 0u;/*依赖时间*/
/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ZERO; 	/*不发送ATS*/
	UINT8 cIvocUnlockOverlapFlag = 0U;  /*列车同意解锁保护区段标志*/
	UINT8 cRcWorkMode = 0U;
	UINT8 chABLFlag = 0U; /*物理区段ABL占用标志*/
	UINT8 chProtectCheck = 0U;

	localCiId = GetSystemParaLocalCiId();

	SetOverlapCanLaborUnlockFlag(overlapLockedId,CANNOT_LABOR_UNLOCK_OVERLAP);/*每周期先设置不可人工解锁*/
	/*防护进路检查*/
    /*进路有防护锁闭区段*/
    if ((overlapSum > 0u) && (overlapLockedId >0u) && (NULL != pTrainId))
    {
        /*有防护进路*/
        reResult = CI_SUCCESS;      
    }
    else
    {
        /*无防护进路不检查*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_OVERLAP_UNLOCK,CI_ERROR,sendLevel);
        /* 失败返回 */
        reResult = CI_ERROR;
        *overlapId = overlapLockedId;
        
    }

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

#if 0
	if (CI_SUCCESS == reResult)
	{
		/* 保护区段内的逻辑区段资源只有一辆列车获取无车占用 */
		checkResult = OverlapLogicSectionTrainCheck(overlapLockedId, &wTmpTrainId);

		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			*pTrainId = wTmpTrainId;
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			*overlapId = overlapLockedId;

		}
	}
#endif

	if (CI_SUCCESS == reResult)
	{
		/*进路内最后一个区段【未锁闭】
		或【锁闭方向相反】
		或【锁闭且占用，满足延迟解锁或停稳解锁条件】
		或【区段未占用，且进路内区段均防护锁闭】*/
		devId = GetRouteLastPhySectionId(routeId);
		devState = GetPhySecLockState(devId);

		tmpRouteBelongCiId = GetRouteBelongCiId(routeId);
		overlapBelongCiId = (UINT8)GetOverlapBelongCiId(overlapLockedId);

		if (PHYSICAL_SECTION_LOCK_NO==devState)
		{
			/*最后一个物理区段未锁闭则可以解锁*/
			/* 直接解锁保护区段 */
			reResult = CI_SUCCESS;
			*overlapId = overlapLockedId;
		}
		else
		{
			if (GetRouteDirection(routeId) == GetPhySecLockDirection(devId))
			{/*说明进路最后的物理区段锁闭方向与进路的方向相同*/
				if (GetPhySecCurMergeState(devId) == SECTION_OCCUPY_YES)
				{
					utOrCtOccFlag = GetPhySecPreOccState(devId);	/*获取物理区段CT或UT占用状态*/
					functionSwitchFlag = GetCiFunctionSwitchConfig(UNLOCK_OVERLAP_SWITCH_CONF);
					/*停稳解锁保护区段倒计时参数超时检查：非通信车占用检查45s倒计时；通信车占用检查180s倒计时*/
					if (LOGICSECTION_OCCUPY_UT == utOrCtOccFlag)
					{/*当前周期物理区段为非通信车占用，非ABL车检查45s倒计时；ABL车检查180S RC16.0改*/
						chABLFlag = GetPhySecABLTrainFlag(devId);
						if ((tmpRouteBelongCiId == localCiId) && (overlapBelongCiId == localCiId))/*进路属于本联锁，且保护区段属于本联锁*/
						{/*此时保护区段解锁周期数为系统参数*/
							if (PHYSICAL_SECTION_ABLOCCUPY_YES != chABLFlag)
							{
								overlapUnLockCount = (UINT16)GetSystemParaProtSecUnlockCyc();
							}
							else
							{
								/*ABL车采用CT车时间解锁*/
								overlapUnLockCount = (UINT16)GetSystemParaCtProtSecUnlockCyc();
							}
						}
						else if ((tmpRouteBelongCiId != localCiId) && (overlapBelongCiId == localCiId))/*进路不属于本联锁，且保护区段属于本联锁*/
						{
							if (PHYSICAL_SECTION_ABLOCCUPY_YES != chABLFlag)
							{
								overlapUnLockCount = GetOtherCIRouteOvlpUTUnlockCnt(routeId);
							}
							else
							{
								/*ABL车采用CT车时间解锁*/
								overlapUnLockCount = GetOtherCIRouteOverlapCTUnlockCount(routeId);
							}
							
						}
						else
						{
							/*进路属于本联锁；保护区段不属于本联锁；此种情况在上一个函数已经拦截，暂不考虑*/

						}

						relyonStartCycNum = CalculaOverlapUnlockStartCycNum(overlapLockedId, devId);/*计算解锁起始倒计时*/


						secStopTimeState = SystemOverTimeCheck(relyonStartCycNum, overlapUnLockCount);
						if (((PHYSICAL_SECTION_STOPSTEADY_YES == secStopFlag) && (CI_TIME_IN == secStopTimeState)) || (CI_TIME_OUT == secStopTimeState))
						{/*未超时且收到停稳信息，或是倒计时超时，则解锁保护区段*/
							reResult = CI_SUCCESS;
							*overlapId = overlapLockedId;
						}
						else
						{
							/*未超时且未收到停稳信息，不能解锁保护区段*/
							reResult = CI_ERROR;
							*overlapId = overlapLockedId;
						}
						if (CI_SUCCESS != reResult)
						{/*执行到此处，说明其他条件均成立，可以设置人工解锁标志*/

							SetOverlapCanLaborUnlockFlag(overlapLockedId, CAN_LABOR_UNLOCK_OVERLAP);/*设置可以人工解锁保护区段*/

							checkResult = CheckOverlapLaborUnlock(overlapLockedId, (UINT32)overlapUnLockCount, relyonStartCycNum);
							if (CI_SUCCESS == checkResult)
							{
								reResult = CI_SUCCESS;
							}
							else
							{
								/*保留reResult结果，什么也不处理*/
							}
						}
					}
					else if (LOGICSECTION_OCCUPY_CT == utOrCtOccFlag)
					{/*当前周期物理区段为通信车占用，检查180s倒计时*/

						if ((tmpRouteBelongCiId == localCiId) && (overlapBelongCiId == localCiId))/*进路属于本联锁，且保护区段属于本联锁*/
						{/*此时保护区段解锁周期数为系统参数*/
							overlapUnLockCount = (UINT16)GetSystemParaCtProtSecUnlockCyc();
						}
						else if ((tmpRouteBelongCiId != localCiId) && (overlapBelongCiId == localCiId))/*进路不属于本联锁，且保护区段属于本联锁*/
						{
							overlapUnLockCount = GetOtherCIRouteOverlapCTUnlockCount(routeId);
						}
						else
						{
							/*进路属于本联锁；保护区段不属于本联锁；此种情况在上一个函数已经拦截，暂不考虑*/

							/*进路不属于本联锁，保护区段不属于本联锁；此种情况在上一个函数已经拦截，暂不考虑*/
						}

						/*通信车解锁保护区段需要检查车或ZC发送的停稳信息，有停稳则解锁否则不解锁*/
						relyonStartCycNum = CalculaOverlapUnlockStartCycNum(overlapLockedId, devId);/*计算解锁起始倒计时*/
						secStopTimeState = SystemOverTimeCheck(relyonStartCycNum, overlapUnLockCount);
						if (FUNC_SWITCH_ON == functionSwitchFlag)
						{
							if (PHYSICAL_SECTION_STOPSTEADY_YES == secStopFlag)
							{/*CT车解锁保护区段，收到停稳信息，则解锁保护区段*/
								reResult = CI_SUCCESS;
								*overlapId = overlapLockedId;

							}
							else
							{
								/*未超时且未收到停稳信息，不能解锁保护区段*/
								if (CI_TIME_OUT == secStopTimeState)
								{
									/*倒计时超时后向ZC/IVOC发送申请保护区段解锁*/
									cRcWorkMode = GetLocalRcWorkMode();
									if (RC_WORK_MODE_TIOC == cRcWorkMode)
									{
										reResult = GetNearstVBTCTrainToOverlap(routeId, pTrainId);  /*寻找最接近保护区段的列车*/
										if (CI_SUCCESS == reResult)
										{
											cIvocUnlockOverlapFlag = GetOverlapIvocAllowUnlockFlag(overlapLockedId);  /*获取列车同意解锁保护区段标志*/
											if (IVOC_ALLOW_UNLOCK_OVERLAP_YES == cIvocUnlockOverlapFlag)
											{
												reResult = CI_SUCCESS;  /*同意解锁，返回成功，解锁保护区段*/
											}
											else
											{
												reResult = CI_UNLOCK_OVERLAP_REQURE;  /*不同意解锁，向车申请解锁保护区段*/
											}
										}
										else
										{
											reResult = CI_ERROR;
										}
									}
									else
									{
										reResult = CI_UNLOCK_OVERLAP_REQURE;  /*向ZC申请解锁保护区段*/
									}

									*overlapId = overlapLockedId;
								}
								else
								{
									reResult = CI_ERROR;
									*overlapId = overlapLockedId;
								}

							}

						}
						else if (FUNC_SWITCH_OFF == functionSwitchFlag)
						{
							if (((PHYSICAL_SECTION_STOPSTEADY_YES == secStopFlag) && (CI_TIME_IN == secStopTimeState)) || (CI_TIME_OUT == secStopTimeState))
							{/*未超时且收到停稳信息，或是倒计时超时，则解锁保护区段*/
								reResult = CI_SUCCESS;
								*overlapId = overlapLockedId;
							}
							else
							{
								/*未超时且未收到停稳信息，不能解锁保护区段*/
								reResult = CI_ERROR;
								*overlapId = overlapLockedId;
							}
						}
						else
						{   /*数据配置错误*/
							reResult = CI_ERROR;
							*overlapId = overlapLockedId;
						}
						if (CI_SUCCESS != reResult)
						{/*执行到此处，说明其他条件均成立，可以设置人工解锁标志*/

							SetOverlapCanLaborUnlockFlag(overlapLockedId, CAN_LABOR_UNLOCK_OVERLAP);/*设置可以人工解锁保护区段*/

							checkResult = CheckOverlapLaborUnlock(overlapLockedId, (UINT32)overlapUnLockCount, relyonStartCycNum);
							if (CI_SUCCESS == checkResult)
							{
								reResult = CI_SUCCESS;
							}
							else
							{
								/*保留reResult结果，什么也不处理*/
							}
							*overlapId = overlapLockedId;
						}

					}
					else
					{
						/*列车类型故障*/
						reResult = CI_ERROR;
						*overlapId = overlapLockedId;
					}

				}
				else
				{
					/*如果进路内所有区段状态均为防护锁闭，可解锁*/
					chProtectCheck = RouteAllSecProtectLockCheck(routeId);
					
					if (CI_SUCCESS == chProtectCheck)
					{
						reResult = CI_SUCCESS;
						*overlapId = overlapLockedId;
					}
					else
					{
						/*最后一个物理区段进路锁闭但未占用，不可以解锁*/
						/*在此处清除人工锁闭标志，并打印记录*/
						SetOverlapAtsOrlaborLockCmdFlag(overlapLockedId, LOCK_OVERLAP_CMD_NO);/*清除人工锁闭标志，使得区段下次占用时可以以占用起始时间作为自动解锁倒计时参考时间*/
						SetlaborUnlockStartCycNum(overlapLockedId, 0u);/*清除人工解锁起始周期，保证向ZC，LEU发送保护区段建立*/
						reResult = CI_ERROR;
						*overlapId = overlapLockedId;
					}
				}
			}
			else
			{
				/*最后一个物理区段已经反方向锁闭，保护区段可以解锁*/
				reResult = CI_SUCCESS;
				*overlapId = overlapLockedId;
			}
		}
#if 0
		if ((routeState == ROUTE_STATE_IDLE) && (devState == PHYSICAL_SECTION_LOCK_NO))
		{
			/* 直接解锁保护区段 */
			reResult = CI_SUCCESS;
			*overlapId = overlapLockedId;
			
		}
		else
		{
			/*收到最后一个区段停稳*/
			if (((secStopFlag == PHYSICAL_SECTION_STOPSTEADY_YES)&&(secStopTimeState == CI_TIME_IN)) 
				|| (PHYSICAL_SECTION_LOCK_NO == secLockState))
			{/*未超时收到停稳，立即解锁*/

				reResult = CI_SUCCESS;
				*overlapId = overlapLockedId;
			}
			else if (secStopTimeState == CI_TIME_OUT)
			{/*无论是否收到停稳，超时则解锁*/

				reResult = CI_SUCCESS;
				*overlapId = overlapLockedId;

			}
			else
			{/*其他情况不解锁*/

				reResult = CI_ERROR;
				*overlapId = overlapLockedId;

			}
		}
#endif
	}

	return reResult;
}


/* C26_进路取消 */
/*
* 功能描述： 进路取消
* 参数说明： const UINT16 routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CANCLE_ROUTE
*/
UINT8 RouteCancelLogicProcess(UINT16 const routeId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_CANCLE_ROUTE;     
/* 局部变量定义初始化 */
    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;  /*进路类型*/

/*联锁条件检查*/
	/* 进路内所有区段锁闭状态【正常锁闭】*/
	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)
		{
			/*检查调车进路中除列检库和不检查占压外的其他区段都空闲*/
			checkResult = CheckDTrainRoutePhySecOccupy(routeId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/*通过检查*/
				reResult = CI_SUCCESS;
			}
			else
			{
				/*失败返回*/
				reResult = CI_ERROR;
			}
		}
		else
		{
			routepreState = GetRoutePreState(routeId);/*获取上已周期进路状态*/
			if ((ROUTE_STATE_LEAD_LOCK != routepreState) &&
				(ROUTE_STATE_LEAD_LOCKERR != routepreState))   /*非引导进路才检查进路空闲*/
			{ /* 进路内所有区段占用状态【空闲】*/

				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
			{
			}
		}
	}
	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;
}


/* C27_区段征用检查 */
/*
* 功能描述： 区段征用检查
* 参数说明： const UINT16 routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CHECK_SECTION_USE
*/
UINT8 RoutePhySectionUseLogicProcess(const UINT16 routeId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_CHECK_SECTION_USE;  
    
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

	/*虚拟联锁兼容*/
	UINT8 triggerFlag = 0u;
    UINT8 sendLevel = 0u;		/*发送ATS*/

	triggerFlag = GetRouteAutoTriggerFlag(routeId); /*获取进路的自动触发标志*/
	if ((AutoSignalOrRouteValid(routeId) == CI_SUCCESS) ||
		(AUTO_TRIGGER_SET_YES == triggerFlag))
    {
        /*自动进路/自动触发进路不发送ATS*/
        sendLevel = ESEND_LEVEL_ZERO;
    }
    else
    {
        sendLevel = ESEND_LEVEL_ATS;
    }
    
/*联锁条件检查*/

    /* 进路全部区段 = 【未征用】*/
    devId = 0u;
    devState = 0u;
    checkResult = RouteAllSecUseVainCheck(routeId,&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;
       
    }
    
    return reResult;
}

/* C29_道岔单操*/
/*
* 功能描述： 道岔单操
* 参数说明：
* 输入参数： UINT16 const switchId, UINT8 const switchSetPos
* 输出参数：UINT8 chSwitchTestFlag CI_SUCCESS道岔定/反位测试时，道岔已在指定位置标志；CI_ERROR 非道岔定/反位或者道岔定/反位测试时，道岔不在指定位置标志；
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SWITCH_POS
* cgh-合并CID-3037-6：
*/
UINT8 SetSwitchPositionLogicProcess(UINT16 const switchId, UINT8 const switchSetPos, const UINT8 chCmdType, UINT8* chSwitchTestFlag)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_SET_SWITCH_POS;

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 lineType = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取轨道交通线路类型*/

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

	/*联锁检查*/
	(*chSwitchTestFlag) = CI_ERROR;
	/*道岔位置不在指定位置*/
	checkResult = GetSwitchCurPosition(switchId);
	if (checkResult != switchSetPos)
	{
		/*道岔不在单操位置*/
		reResult = CI_SUCCESS;
	}
	else
	{
		/*道岔已在指定位置*/
		if ((ATS_CMD_SWITCH_DINGWEI_TEST_TWO == chCmdType) || (ATS_CMD_SWITCH_FANWEI_TEST_TWO == chCmdType))
		{
			*chSwitchTestFlag = CI_SUCCESS; /*执行道岔定/反位测试时，不进行报警*/


		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_POSTION_STATE, checkResult, sendLevel);

		}
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔区段状态为【未锁闭】*/
		/*道岔区段状态 =【道岔空闲】*/
		/*道岔引导总锁状态 =【未引导总锁】*/
		/*道岔单锁状态 =【未单锁】*/
		if (CI_TRADITION_RAILWAY == lineType)
		{/*城轨线路*/
			checkResult = GetSwitchMoveValidState(switchId, SWITCH_OPER_DANCAO, sendLevel);
		} /* zt 删除单轨相关代码 2022-02-15 */
		else
		{/*不存在的线路类型*/
			checkResult = CI_ERROR;
		}

		if (checkResult == CI_SUCCESS)
		{
			/*道岔可单操*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔征用有效性检查通过*/
		reResult = GetSwitchUsingValidState(switchId, functionId, sendLevel);
	}
	else
	{
		;
	}

	return reResult;
}


/* C30_设置道岔单锁*/
/*
* 功能描述： 设置道岔单锁
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SWITCH_DLOCK
*/
UINT8 SetSwitchDLockLogicProcess(UINT16 const switchId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_SWITCH_DLOCK;  
    
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
/*设备数据*/
    /*道岔属性*/
    UINT8 const switchType = GetSwitchType(switchId);
    /*道岔1*/
    UINT8 const switch1stLockStatus = GetSwitchLockStatus(switchId);
    UINT8 const switch1stYLockState = GetSwitchYLockState(switchId);
    UINT8 const switch1stFLockState = GetSwitchFLockState(switchId);
    
    /*道岔2*/
    UINT16 const switch2ndId = GetDSwitchOtherId(switchId);
    UINT8 const switch2ndLockStatus = GetSwitchLockStatus(switch2ndId);
    UINT8 const switch2ndYLockState =  GetSwitchYLockState(switch2ndId);
    UINT8 const switch2ndFLockState = GetSwitchFLockState(switch2ndId);

/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ATS;/*发送ATS*/
	UINT8 CiFunctionFLock = 0u;         /*获取单锁道岔时检查道岔封锁标志*/
	CiFunctionFLock = GetCiFunctionSwitchConfig(FUNC_CHECK_FLOCK_BEFORE_DANSUO);
    
/*联锁检查*/

    /*道岔1锁闭状态 =【未锁闭】或【防护锁闭】*/
    checkResult = switch1stLockStatus;
    if ((SWITCH_LOCK_STATUS_NO == checkResult) || (SWITCH_LOCK_STATUS_PROTECT == checkResult))
    {
        /*【未锁闭】或【防护锁闭】*/
        reResult = CI_SUCCESS;
    }
    else
    {
		if ((SWITCH_LOCK_STATUS_DANSUO == checkResult) || (SWITCH_LOCK_STATUS_DAP == checkResult))
		{
			/*【单锁】或【单锁且防护锁闭】*/
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,checkResult,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔1引导总锁状态 =【未引导总锁】*/
		checkResult = switch1stYLockState;
		if (checkResult == SWITCH_LOCK_YINZONG_NO)
		{
			/*【未引导总锁】*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/*【引导总锁】*/
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_YLOCK_STATE,checkResult,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		if (FUNC_SWITCH_OFF == CiFunctionFLock)
		{/*cgh-合并CID-2349-2：*/
			/*不检查道岔封锁*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/*道岔1封锁状态=【未封锁】*/
			checkResult = switch1stFLockState;
			if (checkResult == SWITCH_LOCK_FENGSUO_NO)
			{
				/*【未封锁】*/
				reResult = CI_SUCCESS;
			}
			else
			{
				/*【封锁】*/
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, checkResult, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;

			}
		}
	}

	if (CI_SUCCESS == reResult)
	{
		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2锁闭状态 =【未锁闭】或【防护锁闭】*/
			checkResult = switch2ndLockStatus;
			if ((SWITCH_LOCK_STATUS_NO == checkResult) || (SWITCH_LOCK_STATUS_PROTECT == checkResult))
			{
				/*【未锁闭】或【防护锁闭】*/
				reResult = CI_SUCCESS;
			}
			else
			{
				if ((SWITCH_LOCK_STATUS_DANSUO == checkResult) || (SWITCH_LOCK_STATUS_DAP == checkResult))
				{
					/*【单锁】或【单锁且防护锁闭】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}        
			if (CI_SUCCESS == reResult)
			{
				/*道岔2引导总锁状态 =【未引导总锁】*/
				checkResult = switch2ndYLockState;
				if (checkResult == SWITCH_LOCK_YINZONG_NO)
				{
					/*【未引导总锁】*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*【引导总锁】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_YLOCK_STATE,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
					
				}
			}
			
			if (CI_SUCCESS == reResult)
			{/*cgh-合并CID-2349-2：*/
				if (FUNC_SWITCH_OFF == CiFunctionFLock)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					/*道岔2封锁状态=【未封锁】*/
					checkResult = switch2ndFLockState;
					if (checkResult == SWITCH_LOCK_FENGSUO_NO)
					{
						/*【未封锁】*/
						reResult = CI_SUCCESS;
					}
					else
					{
						/*【封锁】*/
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, switchId, ETYPE_SWT_FLOCK_STATE, checkResult, sendLevel);
						/* 失败返回 */
						reResult = CI_ERROR;

					}
				}
			}

		}
		else
		{
			/*单动道岔可单锁*/
		}
	}
 
    return reResult;
}

/* C31_取消道岔单锁*/
/*
* 功能描述： 取消道岔单锁
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CANCEL_SWITCH_DLOCK
*/
UINT8 CancelSwitchDLockLogicProcess(UINT16 const switchId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_CANCEL_SWITCH_DLOCK;  
    
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
/*设备数据*/
    /*道岔属性*/
    UINT8 const switchType = GetSwitchType(switchId);
    /*道岔1*/
    UINT8 const switch1stLockStatus = GetSwitchLockStatus(switchId);
    
    /*道岔2*/
    UINT16 const switch2ndId = GetDSwitchOtherId(switchId);
    UINT8 const switch2ndLockStatus = GetSwitchLockStatus(switch2ndId);

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

    
/*联锁检查*/

    /*道岔1锁闭状态 =【单锁】或【单锁且防护锁闭】*/
    checkResult = switch1stLockStatus;
    if ((SWITCH_LOCK_STATUS_DANSUO == checkResult) || (SWITCH_LOCK_STATUS_DAP == checkResult))
    {
        /*【单锁】或【单锁且防护锁闭】*/
        reResult = CI_SUCCESS;
    }
    else
    {
        /*【未锁闭】或【防护锁闭】*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,SWITCH_LOCK_STATUS_DANSUO_NO,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
    }

	if (CI_SUCCESS == reResult)
	{
		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2锁闭状态 =【单锁】或【单锁且防护锁闭】*/
			checkResult = switch2ndLockStatus;
			if ((SWITCH_LOCK_STATUS_DANSUO == checkResult) || (SWITCH_LOCK_STATUS_DAP == checkResult))
			{
				/*双动道岔【单锁】或【单锁且防护锁闭】*/
				reResult = CI_SUCCESS;
			}
			else
			{
				/*【未锁闭】或【防护锁闭】*/
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,SWITCH_LOCK_STATUS_DANSUO_NO,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
				
			}
		}
		else
		{
			/*单动道岔可单解*/
		}
	}

    return reResult;
}


/* C32_设置道岔封锁*/
/*
* 功能描述： 设置道岔封锁
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SWITCH_FLOCK
*/
UINT8 SetSwitchFLockLogicProcess(UINT16 const switchId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_SWITCH_FLOCK;  
    
    /* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
	UINT8 lineIdentity = CI_TRADITION_RAILWAY;		/*线路类型*/
	UINT16 phySecId = 0u;	/*物理区段ID*/
	UINT8 devState = 0u;		/*设备状态*/
/*设备数据*/
    /*道岔属性*/
    UINT8 const switchType = GetSwitchType(switchId);
    /*道岔1*/
    UINT8 const switch1stLockStatus = GetSwitchLockStatus(switchId);
    UINT8 const switch1stYLockState = GetSwitchYLockState(switchId);
    UINT8 const switch1stFLockState = GetSwitchFLockState(switchId);
    UINT16 const switch1stSecId = GetSwitchPhySectionId(switchId);
    UINT8 const switch1stSecLockState = GetPhySecLockState(switch1stSecId);
	UINT8 const chSw1PhySecLogLockState = PhySecLogLockStateCheck(switch1stSecId);/*道岔相关物理区段逻辑进路锁闭状态*/
    
    /*道岔2*/
    UINT16 const switch2ndId = GetDSwitchOtherId(switchId);
    UINT8 const switch2ndLockStatus = GetSwitchLockStatus(switch2ndId);
    UINT8 const switch2ndYLockState =  GetSwitchYLockState(switch2ndId);
    UINT8 const switch2ndFLockState = GetSwitchFLockState(switch2ndId);
    UINT16 const switch2ndSecId = GetSwitchPhySectionId(switch2ndId);
    UINT8 const switch2ndSecLockState = GetPhySecLockState(switch2ndSecId);
	UINT8 const chSw2PhySecLogLockState = PhySecLogLockStateCheck(switch2ndSecId);/*双动道岔相关物理区段逻辑进路锁闭状态*/

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

	UINT8 CiFunctionDLock = 0u;    /*获取封锁道岔时检查道岔单锁标志*/
	UINT8 CiFunctionLock = 0u;    /*获取封锁道岔时检查道岔锁闭标志*/

	lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF); /*获取线路类型*/
/*联锁检查*/

	CiFunctionDLock = GetCiFunctionSwitchConfig(CHECK_SWITCH_DANLOCK_FLOCKING_SWITCH_CONF);
	CiFunctionLock = GetCiFunctionSwitchConfig(CHECK_SWITCH_LOCKING_BEFORE_LOCKING_SWITCH_CONF);

	if(FUNC_SWITCH_ON == CiFunctionDLock)
	{
	    /*道岔1锁闭状态 =【未锁闭】*/
	    checkResult = switch1stLockStatus;
	    if (checkResult == SWITCH_LOCK_STATUS_NO)
	    {
	        /*【未锁闭】*/
	        reResult = CI_SUCCESS;
	    }
	    else
	    {
	        /*【锁闭】*/
	        /* 记录故障码 */
	        SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,checkResult,sendLevel); 
	        /* 失败返回 */
	        reResult = CI_ERROR;
	       
	    }
	}
	else if(FUNC_SWITCH_OFF == CiFunctionDLock)
	{
		reResult = CI_SUCCESS;
	}
	else
	{
		/*功能开关配置错误 不进行逻辑检查*/
		reResult = CI_ERROR;
	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔1引导总锁状态 =【未引导总锁】*/
		checkResult = switch1stYLockState;
		if (checkResult == SWITCH_LOCK_YINZONG_NO)
		{
			/*【未引导总锁】*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/*【引导总锁】*/
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_YLOCK_STATE,checkResult,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔1封锁状态=【未封锁】*/
		checkResult = switch1stFLockState;
		if (checkResult == SWITCH_LOCK_FENGSUO_NO)
		{
			/*【未封锁】*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/*【封锁】*/
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_FLOCK_STATE,checkResult,sendLevel); 
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}

	if (CI_SUCCESS == reResult)
	{

		if(FUNC_SWITCH_ON == CiFunctionLock)
		{
			if (CI_TRADITION_RAILWAY == lineIdentity)
			{/*传统线路*/
				/*道岔1区段状态为【未锁闭】*/
				checkResult = switch1stSecLockState;
				if (checkResult == PHYSICAL_SECTION_LOCK_NO)
				{
					/*【未锁闭】*/
					reResult = CI_SUCCESS;

					if (LOG_SECTION_LOGLOCK_NO == chSw1PhySecLogLockState)
					{
						/*【未被逻辑进路锁闭】*/
						reResult = CI_SUCCESS;
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, switch1stSecId, ETYPE_PS_LOCK_STATE, chSw1PhySecLogLockState, sendLevel);
						/* 失败返回 */
						reResult = CI_ERROR;
					}
				}
				else
				{
					/*【锁闭】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,switch1stSecId,ETYPE_PS_LOCK_STATE,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}/* zt 删除单轨相关代码 2022-02-15 */
			else
			{/*线路类型错误*/
				reResult = CI_ERROR;
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,phySecId,ETYPE_PS_LOCK_STATE,devState,sendLevel);
			}
				
		}
		else if(FUNC_SWITCH_OFF == CiFunctionLock)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
    }

	if (CI_SUCCESS == reResult)
	{
		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2锁闭状态 =【未锁闭】*/			
			if(FUNC_SWITCH_ON == CiFunctionDLock)
			{
				checkResult = switch2ndLockStatus;
				if (checkResult == SWITCH_LOCK_STATUS_NO)
				{
					/*【未锁闭】*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*【锁闭】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_LOCK_STATUS,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
				}
	        }
			else if(FUNC_SWITCH_OFF == CiFunctionDLock)
			{
				reResult = CI_SUCCESS;
			}
			else
			{
				/*功能开关配置错误 不进行逻辑检查*/
				reResult = CI_ERROR;
			}
 
			if (CI_SUCCESS == reResult)
			{
				/*道岔2引导总锁状态 =【未引导总锁】*/
				checkResult = switch2ndYLockState;
				if (checkResult == SWITCH_LOCK_YINZONG_NO)
				{
					/*【未引导总锁】*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*【引导总锁】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_YLOCK_STATE,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
					
				}
			}

			if (CI_SUCCESS == reResult)
			{
				/*道岔2封锁状态=【未封锁】*/
				checkResult = switch2ndFLockState;
				if (checkResult == SWITCH_LOCK_FENGSUO_NO)
				{
					/*【未封锁】*/
					reResult = CI_SUCCESS;
				}
				else
				{
					/*【封锁】*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_FLOCK_STATE,checkResult,sendLevel); 
					/* 失败返回 */
					reResult = CI_ERROR;
					
				}
			}

			if (CI_SUCCESS == reResult)
			{
				if(FUNC_SWITCH_ON == CiFunctionLock)
				{
					if (CI_TRADITION_RAILWAY == lineIdentity)
					{/*传统线路*/
						/*道岔2区段状态为【未锁闭】*/
						checkResult = switch2ndSecLockState;
						if (checkResult == PHYSICAL_SECTION_LOCK_NO)
						{
							/*【未锁闭】*/
							reResult = CI_SUCCESS;
							if (LOG_SECTION_LOGLOCK_NO == chSw2PhySecLogLockState)
							{
								/*【未被逻辑进路锁闭】*/
								reResult = CI_SUCCESS;
							}
							else
							{
								/* 记录故障码 */
								SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, switch2ndSecId, ETYPE_PS_LOCK_STATE, chSw2PhySecLogLockState, sendLevel);
								/* 失败返回 */
								reResult = CI_ERROR;
							}
						}
						else
						{
							/*【锁闭】*/
							/* 记录故障码 */
							SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,switch2ndSecId,ETYPE_PS_LOCK_STATE,checkResult,sendLevel); 
							/* 失败返回 */
							reResult = CI_ERROR;

						}
					}/* zt 删除单轨相关代码 2022-02-15 */
					else
					{/*线路类型错误*/
						reResult = CI_ERROR;
						/* 记录故障码 */
						SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,phySecId,ETYPE_PS_LOCK_STATE,devState,sendLevel);
					}
				}
				else if(FUNC_SWITCH_OFF == CiFunctionLock)
				{
					reResult = CI_SUCCESS;
				}
				else
				{
					reResult = CI_ERROR;
				}
			}

		}
		else
		{
			/*单动道岔可封锁*/
		}
	}

    return reResult;
}


/* C33_取消道岔封锁*/
/*
* 功能描述： 取消道岔封锁
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CANCEL_SWITCH_FLOCK
*
*/
UINT8 CancelSwitchFLockLogicProcess(UINT16 const switchId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_CANCEL_SWITCH_FLOCK;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
/*设备数据*/
    /*道岔属性*/
    UINT8 const switchType = GetSwitchType(switchId);
    /*道岔1*/
    UINT8 const switch1stFLockState = GetSwitchFLockState(switchId);
    
    /*道岔2*/
    UINT16 const switch2ndId = GetDSwitchOtherId(switchId);
    UINT8 const switch2ndFLockState = GetSwitchFLockState(switch2ndId);

/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ATS;/*发送ATS*/
    
    
/*联锁检查*/
    
    /*道岔1单锁状态 =【封锁】*/
    checkResult = switch1stFLockState;
    if (checkResult == SWITCH_LOCK_FENGSUO_YES)
    {
        /*【封锁】*/
        reResult = CI_SUCCESS;
    }
    else
    {
        /*【未封锁】*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_FLOCK_STATE,checkResult,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
       
    }
    
	if (CI_SUCCESS == reResult)
	{
		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2单锁状态 =【封锁】*/
			checkResult = switch2ndFLockState;
			if (checkResult == SWITCH_LOCK_FENGSUO_YES)
			{
				/*双动道岔可解封*/
				reResult = CI_SUCCESS;
			}
			else
			{
				/*【未封锁】*/
				/* 记录故障码 */
				SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_FLOCK_STATE,checkResult,sendLevel); 
				/* 失败返回 */
				reResult = CI_ERROR;
				
			}
		}
		else
		{
			/*单动道岔可解封*/
		}
	}
 
    return reResult;
}

/* C34_信号机封锁*/
/*
* 功能描述： 信号机封锁
* 参数说明： UINT16 const signalId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SIGNAL_FLOCK
*
*/
UINT8 SetSignalFLockLogicProcess(UINT16 const signalId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_SET_SIGNAL_FLOCK;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
/*设备数据*/
    UINT8 const signalFLockState = GetSignalFLockState(signalId);

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

/*联锁检查*/
    
    /*信号机封锁状态 =【未封锁】*/
    checkResult = signalFLockState;
    if (checkResult == SIGNAL_FENGSUO_NO)
    {
        /*【未封锁】*/
        reResult = CI_SUCCESS;
    }
    else
    {
        /*【封锁】*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,signalId,ETYPE_SIG_FLOCK_STATE,checkResult,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }

    return reResult;
}


/* C35_取消信号机封锁*/
/*
* 功能描述： 取消信号机封锁
* 参数说明： UINT16 const signalId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CANCEL_SIGNAL_FLOCK
*
*/
UINT8 CancelSignalFLockLogicProcess(UINT16 const signalId)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_CANCEL_SIGNAL_FLOCK;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
/*设备数据*/
    UINT8 const signalFLockState = GetSignalFLockState(signalId);

/*故障发送级别*/
    UINT8 sendLevel = ESEND_LEVEL_ATS;/*发送ATS*/
    
/*联锁检查*/
    
    /*信号机封锁状态 =【封锁】*/
    checkResult = signalFLockState;
    if (checkResult == SIGNAL_FENGSUO_YES)
    {
        /*【封锁】*/
        reResult = CI_SUCCESS;
    }
    else
    {
        /*【未封锁】*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,signalId,ETYPE_SIG_FLOCK_STATE,checkResult,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }
    
    return reResult;
}

/* C36_道岔强扳*/
/*
* 功能描述： 道岔强扳
* 参数说明： UINT16 const switchId, UINT8 const switchSetPos
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_FORCE_SET_SWITCH_POS
*/
UINT8 ForceSetSwitchPosLogicProcess(UINT16 const switchId, UINT8 const switchSetPos)
{
/*函数故障码*/
    UINT8 const functionId = EFUNC_FORCE_SET_SWITCH_POS;  
    
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 lineType = CI_TRADITION_RAILWAY;
/*设备数据*/
    /*故障发送级别*/
    UINT8 sendLevel = 0u;
    sendLevel = ESEND_LEVEL_ATS;       /*发送ATS*/



	lineType = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取轨道交通线路类型*/

/*联锁检查*/

    /*道岔位置不在指定位置*/
    checkResult = GetSwitchCurPosition(switchId);
    if (checkResult != switchSetPos)
    {
        /*道岔不在单操位置*/
        reResult = CI_SUCCESS;
    }
    else
    {
        /*道岔已在指定位置*/
        /* 记录故障码 */
        SetErrorData(functionId,CI_DEVICE_TYPE_SWITCH,switchId,ETYPE_SWT_POSTION_STATE,checkResult,sendLevel); 
        /* 失败返回 */
        reResult = CI_ERROR;
        
    }




	if (CI_SUCCESS == reResult)
	{
		/*道岔区段状态为【未锁闭】*/
		/*道岔区段状态 =【道岔占用】*/
		/*道岔引导总锁状态 =【未引导总锁】*/
		/*道岔单锁状态 =【未单锁】*/

		if(CI_TRADITION_RAILWAY == lineType)
		{
			checkResult = GetSwitchForceMoveValidState(switchId,sendLevel);
		}/* zt 删除单轨相关代码 2022-02-15 */
		else
		{
			/* 失败返回 */
			checkResult = CI_ERROR;
		}
		


		if(checkResult == CI_SUCCESS)
		{
			/*道岔可单操*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == reResult)
	{
		/*道岔征用有效性检查通过*/
		reResult = GetSwitchUsingValidState(switchId, functionId, sendLevel);
	}
	else
	{
		;
	}

	return reResult;
}

/* R_R_S_C1办理反向进路信号机联锁条件检查 */
/*
* 功能描述： 反向进路信号机联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetReverseRouteSignalCheck( 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 = GetSignalOpenCloseState(GetSignalCurColor(startSignalId));
		if (SIGNAL_CLOSE == 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 (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			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 = ReverseRouteSigEnemyVainCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId,CI_DEVICE_TYPE_SIGNAL,devId,ETYPE_SIG_ENEMY_STATE,devState,sendLevel);        
			/* 失败返回 */
			reResult = CI_ERROR;
		}
    }
	else
	{
	}
    /* 返回结果 */
    return reResult;
}




/* L02_点式进路区段联锁条件检查 */
/*
* 功能描述： 点式进路区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetBlocRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

	UINT8 funcSwitch = 0u;               /*功能开关*/

	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
    
    
/* 联锁逻辑检查 */  
    /* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221007 适配进路驱动道岔提前扳动功能*/
			checkResult = RouteAllLogSecOccuClearCheck(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
		{
			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;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221007 适配进路驱动道岔提前扳动功能*/
			checkResult = BlockRouteLogSecLockValidCheck(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
		{
			checkResult = BlockRouteSecLockValidCheck(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 = RouteIncLogSecLogicLockCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

#if 0
    /*侵限区段侵限条件不满足检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId,&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;
		}
	}
#endif
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecJumpLockStateCheck(routeId,&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 = RouteSwOtherLogLockValidCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 返回结果 */
    return reResult;
}


/* R_L_L_01反向进路区段联锁条件检查 */
/*
* 功能描述： 反向进路区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetReverseRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_SUCCESS;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 funcSwitch = 0u;               /*功能开关*/

	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
    
    
/* 联锁逻辑检查 */  
    
	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221008 适配进路驱动道岔提前扳动功能*/
			checkResult = RouteAllLogSecOccuClearCheck(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
		{
			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;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221008 适配进路驱动道岔提前扳动功能*/
			checkResult = ReverseRouteLogSecLockValCheck(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
		{
			checkResult = ReverseRouteSecLockValidCheck(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 = RouteIncLogSecLogicLockCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    
#if 0
    /*侵限区段侵限条件不满足检查*/
	if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId,&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;
		}
	}
#endif
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecJumpLockStateCheck(routeId,&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 = RouteSwOtherLogLockValidCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

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

/* R_L_L_02反向进路自动信号进路状态检查 */
/*
* 功能描述： 反向进路自动信号进路状态检查 
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetRevrRouteAutoSigStaCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_SUCCESS;          /*返回值*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

	UINT8 reverseRouteAutoSigRouteSum = 0u;       /*反向进路包含自动信号进路数目*/
    UINT16 * reverseRouteAutoSigRouteBuf = NULL; /*反向进路包含自动信号进路Id数组*/	

	UINT8 i = 0u;
    
    
/* 联锁逻辑检查 */  
  
    /*反向进路内包含的所有自动信号进路状态不为:接近开放、接近锁闭异常*/
    devId = 0u;
    devState = 0u;
	reverseRouteAutoSigRouteSum = GetReverseRouteIncludeRouteSum(routeId);/*获取反向进路包含自动信号进路数目*/
	reverseRouteAutoSigRouteBuf = GetReverseRouteIncludeRouteBuf(routeId);/*或取反向进路包含自动信号进路ID数组*/

	for(i = 0u;i < reverseRouteAutoSigRouteSum;i++)
	{
		devId = reverseRouteAutoSigRouteBuf[i];/*获取自动信号进路ID*/
		devState = GetRouteState(devId);/*获取自动信号进路状态*/
		if((ROUTE_STATE_NEAR_OPEN == devState) || (ROUTE_STATE_NEAR_LOCKERR == devState))
		{/*自动信号进路状态若为(接近开放) || (接近锁闭异常)，检查失败*/
		
			reResult = CI_ERROR;
	        /* 记录故障码 */
	        SetErrorData(functionId,CI_DEVICE_TYPE_ROUTE,devId,ETYPE_ROUTE_STATE,devState,sendLevel);			
			break;
		}
	}
	   
    /* 返回结果 */
    return reResult;
}






/* L03_点式进路办理道岔联锁条件检查 */
/*
* 功能描述： 点式进路道岔联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetBlocRouteSwitchCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 chConnetCheckFunc = 0U;

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

	/* 联锁逻辑检查 */  
    
    /*进路内所有道岔【未引导总锁】*/
    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 (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			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)
	{
		/*进路防护道岔【未封锁】*/
		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)
	{
		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)
	{
		/*进路内所有道岔位置正确或位置不正确但可动作*/
		devId = 0u;
		devState = 0u;

		checkResult = RouteSwitchPosAndMoveValidCheck(routeId,sendLevel);

		if ((CI_SUCCESS == checkResult) || (RETURN_LOCK_ERR_WAIT_SWCHECK == checkResult))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		/*do nothing*/
	}


	if(CI_SUCCESS == reResult)
	{/*进路办理防护道岔检查*/
	 /*进路关联防护道岔【未引导总锁】*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteRelatedProSwitchYLockCheck(routeId, &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 = RouteRelProSwiPosAndMovValCheck(routeId,sendLevel);
			if ((CI_SUCCESS == checkResult) || (RETURN_LOCK_ERR_WAIT_SWCHECK == checkResult))
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			reResult = CI_ERROR;
		}

	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	
    /* 返回结果 */
    return reResult;
}

/* L04_Cbtc进路办理区段联锁条件检查 */
/*
* 功能描述： Cbtc进路办理区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetCbtcRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/

	UINT8 funcSwitch = 0u;               /*功能开关*/
	UINT8 CiFunctionJLock = 0u;			/*是否检查跳跃锁闭标志*/
	UINT8 cRcWorkMode = 0u;

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

	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
    
    
/* 进路内设备数据 */
   

    
    
/* 联锁逻辑检查 */
	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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 1
    /* 进路内第一逻辑区段占用状态【空闲】*/
	if (CI_SUCCESS == reResult)
	{
		if (RC_WORK_MODE_CI == cRcWorkMode)
		{
			devId = GetRouteInFirstLogSecId(routeId);
			devState = GetLogSecCurOccupyState(devId);
			if (devState == SECTION_OCCUPY_NO)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else if(RC_WORK_MODE_TIOC == cRcWorkMode)
		{
			;/* 继续检查 */
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
#endif
    /* 进路内所有区段锁闭状态【未锁闭】或
        方向相同的【防护锁闭】或 
        (方向相同的【正常锁闭】或 方向相同的【延时锁闭】且锁闭进路为【列车进路】故障锁闭且ARB且方向一致)
    */
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221005 适配进路驱动道岔提前扳动功能*/
			checkResult = RouteCbtcLogSecLockValidCheck(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
		{
			checkResult = RouteCbtcSecLockValidCheck(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 = RouteIncLogSecLogicLockCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

#if 0
    /*侵限区段侵限条件不满足检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId,&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;
		}  
	}
#endif
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{/*cgh-合并CID-2349-1：*/
		devId = 0u;
		devState = 0u;
		CiFunctionJLock = GetCiFunctionSwitchConfig(FUNC_CBTC_CHECK_JUMPLOCK_FLAG);
		if (FUNC_SWITCH_OFF == CiFunctionJLock)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			checkResult = RouteAllSecJumpLockStateCheck(routeId, &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 = RouteSwOtherLogLockValidCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	
    /* 返回结果 */
    return reResult;
}

/* L05_引导进路锁闭区段联锁条件检查 */
/*
* 功能描述： 引导进路锁闭区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 SetLeadRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 checkSecFlockFlag = 0u;     /*是否检查区段封锁*/
	UINT8 funcSwitch = 0u;               /*功能开关*/

	funcSwitch = GetCiFunctionSwitchConfig(FUNC_ROUTE_DRV_SWITCH_EARLY);
	checkSecFlockFlag = GetCiFunctionSwitchConfig(FUNC_YDROUTE_SEC_FLOCK_CHECK_FLAG);

    
/* 联锁逻辑检查 */  
	if(NON_CHECK_SECFLOCK == checkSecFlockFlag)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{   /* 检查进路内所有区段未被封锁 */
		checkResult = RouteSecFLockCheck(routeId,&devId,&devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
	    else
	    {
			/*cgh-合并CID-2539-1：根据物理区段封锁类型设置errorcode*/
			AccToPhySecFlockTypeSetErrcode(devId, functionId, sendLevel, devState);
			/* 失败返回 */
			reResult = CI_ERROR;		
		}
	}

    /* 进路内全部区段锁闭状态【未锁闭】或
    全部区段为方向相同的【正常锁闭】或
    全部区段为方向相同的【防护锁闭】||【未锁闭】20220804修改进路内有区段防护锁闭，其他区段空闲，允许锁闭引导进路*/
    if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		if (FUNC_SWITCH_ON == funcSwitch)
		{
			/*modify 20221007 适配进路驱动道岔提前扳动功能*/
			checkResult = LeadRouteLogSecLockValidCheck(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
		{
			checkResult = RouteAllSecLockStateCheck(routeId, PHYSICAL_SECTION_LOCK_NO, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				devId = 0u;
				devState = 0u;
				checkResult = RouteAllSecLockStateCheck(routeId, PHYSICAL_SECTION_LOCK_NORMAL, &devId, &devState);
				if (checkResult == CI_SUCCESS)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					devId = 0u;
					devState = 0u;
					checkResult = LeadRouteSecLockStateCheck(routeId, PHYSICAL_SECTION_LOCK_PROTECT, &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 = RouteIncLogSecLogicLockCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

    /*引导进路不检查侵限区段*/
#if 0
    /*侵限区段侵限条件不满足检查*/
	if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId,&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;
		}
	}
#endif
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecJumpLockStateCheck(routeId,&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 = RouteSwOtherLogLockValidCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_LOCK_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
    /* 返回结果 */
    return reResult;
}

/*
* 功能描述： 点式折返进路开放信号联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenBlocReturnRouteSignalCheck(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 = 0u;             /*终端信号机开放状态 */
    
    
/* 进路内设备数据 */
    /* 始端信号机Id */
    UINT16 const startSignalId = GetRouteStartSignalId(routeId);
    UINT8 flag = 0u;
 /* 联锁逻辑检查 */  

    /* 进路始端信号机颜色为【红灯】*/
    devState = GetSignalCurColor(startSignalId);
    if (devState == SIGNAL_SHOWCOLOUR_RED)
    {
        /* 通过检查 */
        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
    {
        /*进路内所有信号机【未封锁】*/
        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;
        }
        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;
			    }
		    }
		}
    }
    /* 返回结果 */
    return reResult;
}

/* L08_点式进路开放信号区段联锁条件检查 */
/*
* 功能描述： 点式进路开放信号区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenBlocRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
    UINT16 startSignalId = 0u;			/*进路始端信号机ID*/  
	UINT8 ciType = 0u;
	UINT8 cPhySecCurMergeState = 0U;	/*融合占压状态*/

	UINT8 routeState = 0u;
	UINT8 chDsnFuncSwitch = 0U;		/* 无直轨计轴占用功能开关 */
	UINT8 chXianSuFuncSwitch = 0U; /*后备模式信号开放是否检查区段临时限速开关*/
	UINT8 cCrossState = 0U;  /*信号机跨压状态*/

	chDsnFuncSwitch = GetCiFunctionSwitchConfig(FUNC_TOA_SWITCH);
	chXianSuFuncSwitch = GetCiFunctionSwitchConfig(FUNC_XIANSU_SWITCH);

	ciType = GetCiType(LocalCiId);
	 
	/* 联锁逻辑检查 */  
	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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;
		startSignalId = GetRouteStartSignalId(routeId);/*获取进路始端信号机ID*/
		checkResult = RouteAllSecOccuClearCheck(routeId,&devId, &cPhySecCurMergeState);
		routeState = GetRouteState(routeId);
		if ((CI_TYPE_CLD == ciType) && ((ROUTE_STATE_YUXIAN_OPEN == routeState) ||(ROUTE_STATE_NEAR_OPEN == routeState)))
		{/*车辆段进路预先开放或接近开放*/
			reResult = CLDKeepOpenSecCheck(routeId,functionId,sendLevel);
		}
		else
		{
			cCrossState = GetSignalCrossState(startSignalId);
			if ((SIGNAL_CROSS_STATE_NO == cCrossState) && (CI_SUCCESS == checkResult))
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				if (FUNC_SWITCH_ON != chDsnFuncSwitch)
				{
					/* 记录故障码 */
					if (CI_SUCCESS == checkResult)
					{
						/*仅跨压，区段未占用，记录跨压报警*/
						SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_CROSS, cCrossState, sendLevel);
					}
					else
					{
						/*存在区段占用，记录占用报警*/
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, cPhySecCurMergeState, sendLevel);
					}
					
					/* 失败返回 */
					reResult = CI_ERROR;
				}
				else
				{
					checkResult = RouteAllSecColOccuClearCheck(routeId, &devId, &devState);

					if (CI_SUCCESS == checkResult)
					{
						checkResult = RouteFaultOccuCheck(routeId, &devId, &devState);
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
						/* 失败返回 */
						reResult = CI_ERROR;
					}

					if (CI_SUCCESS == checkResult)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, cPhySecCurMergeState, sendLevel);		/*修复缺陷YF8803-1019,当在RouteFaultOccuCheck中检查不过返回devState状态为0，不是占用状态*/
						/* 失败返回 */
						reResult = CI_ERROR;
					}
				}
			}
		}
	}
    /* 进路内所有区段锁闭状态【正常锁闭】*/
	if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecLockStateCheck(routeId,PHYSICAL_SECTION_LOCK_NORMAL,&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 = RouteIntruSecVainCheck(routeId,&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 = RouteAllSecJumpLockStateCheck(routeId,&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)
	{
		if (FUNC_SWITCH_ON == chXianSuFuncSwitch)
		{/*后备模式信号开放是否检查区段临时限速开关打开*/

			devId = 0u;
			devState = 0u;
			checkResult = RouteAllLgcSecXianSuCheck(routeId, &devId, &devState);
			if (checkResult == CI_SUCCESS)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 记录故障码 */
				SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_XIANSU_STATE, devState, sendLevel);
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
		else
		{
			/* 功能开关关闭,不检查 */
		}
		
	}
    /* 返回结果 */
    return reResult;
}


/*
* 功能描述： 车辆段点式进路开放信号区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 CLDKeepOpenSecCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT16 startSignalId = 0u;			/*进路始端信号机ID*/

	UINT16 routeInFirstLogSecId = 0u;/*进路内方第一逻辑区段Id*/
	UINT8 routeInFirstLogSecState = 0u;/*进路内方第一逻辑区段占用状态*/

	UINT16 routeOutLastLogSecId = 0u;/*进路外方最后一逻辑区段Id*/
	UINT8 routeOutLastLogSecState = 0u;/*进路外方最后一逻辑区段占用状态*/


	UINT8 crossState = 0u;/*跨压状态*/
	UINT16 ii = 0u;/*索引*/
	UINT16 phyId = 0u;/*物理区段ID*/
	UINT16 phyOccupyFlag = 0u;/*物理区段占用标志*/
	UINT8 hasUtFlag = 0u;/*有UT占用*/
	UINT8 hasCtFlag = 0u;/*有CT占用*/

	UINT8 sigConfigCross = 0u;/*是否配置了跨压码位*/

	UINT32 curCycle = 0u;/*当前周期号*/

	RoutePhysicalSectionStruct* pRoutePhySecData = NULL;/*进路物理区段*/
	UINT16 routePhyNum = 0u;
	UINT8 chFunRet = CI_ERROR;
	UINT8  chTrainEnterState = 0U;
	UINT8  chReadyEnterRouteTrainSum = 0U;
	UINT16 wszReadyEtRouteTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT8 rcWorkMode = GetLocalRcWorkMode();

	pRoutePhySecData = GetRouteSectionData(routeId);
	routePhyNum = GetRoutePhysicalSectionSum(routeId);
	curCycle = Get2oo2CurCycleNum();
	devId = 0u;
	devState = 0u;
	startSignalId = GetRouteStartSignalId(routeId);/*获取进路始端信号机ID*/
	checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);

	sigConfigCross = (UINT8)GetSigConfZcCiSignalCrossMask(startSignalId);/*是否配置了信号机跨压码位*/

	routeInFirstLogSecId = GetRouteInFirstLogSecId(routeId);/*获取进路内方第一逻辑区段Id*/
	routeInFirstLogSecState = GetLogSecCurCtOrUtOccupyState(routeInFirstLogSecId);/*获取进路内方第一逻辑区段占用状态*/

	routeOutLastLogSecId = GetSignalOutFirstLogSec(startSignalId);
	routeOutLastLogSecState = GetLogSecCurCtOrUtOccupyState(routeOutLastLogSecId);/*获取进路外方最后一逻辑区段占用状态*/
	crossState = GetSignalCrossState(startSignalId);

	if (SIGNAL_CROSS_STATE_NO == crossState)
	{
		/*未跨压*/
		checkResult = RouteAllSecOccuClearCheck(routeId, &devId, &devState);

		if (CI_SUCCESS == checkResult)
		{
			/*全部出清,通过检查，保持信号*/
			reResult = CI_SUCCESS;
		}
		else
		{
			/*进路内区段，有UT占用，信号保持失败*/
			/*进路内区段，有CT，且第一逻辑区段和外方第一物理区段最后一个逻辑区段CT占用，信号保持成功，其它失败*/
			hasUtFlag = 0u;
			hasCtFlag = 0u;
			for (ii = 0u; ii < routePhyNum; ii++)
			{
				phyId = pRoutePhySecData[ii].PhysicalSectionId;
				phyOccupyFlag = GetPhySecPreOccState(phyId);
				if (LOGICSECTION_OCCUPY_UT == phyOccupyFlag)
				{
					hasUtFlag = 1u;
				}
				else if (LOGICSECTION_OCCUPY_CT == phyOccupyFlag)
				{
					hasCtFlag = 1u;
				}
				else
				{
					/*没有CT UT占用*/
				}
			}

			debug_infor_printf((const)"\r\ncurCycle:%d, RouteId:%d, hasUtFlag:%d, hasCtFlag:%d,startSignalId:%d, sigConfigCross:%d \r\n", curCycle, routeId, hasUtFlag, hasCtFlag, startSignalId, sigConfigCross);

			debug_infor_printf((const)"\r\ncurCycle:%d, RouteId:%d, routeInFirstLogSecId:%d, routeInFirstLogSecState:%d,routeOutLastLogSecId:%d, routeOutLastLogSecState:%d \r\n",
				curCycle, routeId, routeInFirstLogSecId, routeInFirstLogSecState,
				routeOutLastLogSecId, routeOutLastLogSecState);

			if (1u == hasUtFlag)
			{
				/*信号保持失败*/
				reResult = CI_ERROR;
				SetErrorData(functionId,
					CI_DEVICE_TYPE_PHYSEC, devId,
					ETYPE_PS_MERGY_OCU_STATE, devState,
					sendLevel);
			}
			else if ((0u == hasUtFlag) && (1u == hasCtFlag))
			{
				if (RC_WORK_MODE_TIOC == rcWorkMode)
				{
					/*RC模式下，需要用列车位置判断跨压*/
					chFunRet = GetRouteInOutFstLgcTrainInfo(routeId, &chReadyEnterRouteTrainSum, wszReadyEtRouteTrainId);
					if (CI_SUCCESS == chFunRet)
					{
						chTrainEnterState = dsuTrainMinHeadCrossSignal(wszReadyEtRouteTrainId[0], routeId);
						if (TRAIN_ENTER_ROUTE_FULL == chTrainEnterState)
						{
							/*列车完全驶入进路，关灯 by cgh 20231128*/
							reResult = CI_ERROR;
						}
						else if (TRAIN_ENTER_ROUTE_HEAD == chTrainEnterState)
						{
							/*列车驶入进路未跨压，不关灯 */
							reResult = CI_SUCCESS;
						}
						else if (TRAIN_ENTER_ROUTE_CROSS == chTrainEnterState)
						{
							/*列车跨压信号机，需判断第一逻辑区段占压状态*/

							if (LOGICSECTION_OCCUPY_NO == routeInFirstLogSecState)
							{/*第一逻辑区段融合状态未占压，不关灯，等待占压 */
								reResult = CI_SUCCESS;
							}
							else
							{/*第一逻辑区段融合状态占压 关灯*/
								reResult = CI_ERROR;
							}
						}
						else if ((TRAIN_ENTER_ROUTE_NO == chTrainEnterState)
							|| (CI_ERROR == chTrainEnterState)
							|| (TRAIN_ENTER_ROUTE_TAIL == chTrainEnterState))
						{
							/*列车已驶出，或列车未上线，或列车未跨压*/
							reResult = CI_SUCCESS;
						}
						else
						{

							reResult = CI_ERROR;
						}

						if ((LOGICSECTION_OCCUPY_CT == routeInFirstLogSecState) &&
							(LOGICSECTION_OCCUPY_CT == routeOutLastLogSecState))
						{
							/*保持当前检查状态*/
						}
						else
						{
							reResult = CI_ERROR;  /*返回失败，解决场景：VBTC1在进路外方第一区段且VBTC2（前车）后溜进入进路内方最后一个逻辑区段时，进路未关信号*/
							SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);  /*修复缺陷YF0083-2282：占用报警区段ID错误问题*/
						}
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
					}
				}
				/*有CT占用，第一逻辑区段CT占用，外方第一物理区段最后一个逻辑区段CT占用，且配置了跨压码位，则保持成功，其它失败*/
				else
				{
					if (SIGNAL_CONFIG_CROSS_MASK_YES == sigConfigCross)
					{/*配置了跨压码位，等跨压才关灯*/
						if ((LOGICSECTION_OCCUPY_CT == routeInFirstLogSecState) &&
							(LOGICSECTION_OCCUPY_CT == routeOutLastLogSecState))
						{
							reResult = CI_SUCCESS;
						}
						else
						{
							reResult = CI_ERROR;
							SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
						}
					}
					else
					{/*没有配置跨压码位*/
						/*进路物理区段有CT占用就关灯*/
						reResult = CI_ERROR;
						SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_MERGY_OCU_STATE, devState, sendLevel);
					}
				}
			}
			else
			{
				/*都没有占用，信号保持成功*/
				reResult = CI_SUCCESS;
			}
		}
	}
	else
	{
		/*跨压，信号保持失败*/
		reResult = CI_ERROR;
		SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, startSignalId, ETYPE_SIG_CROSS, crossState, sendLevel);
	}

	return reResult;
}

/* L15_Cbtc进路信号开放区段联锁条件检查 */
/*
* 功能描述： Cbtc进路信号开放区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenCbtcRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 CiFunctionJLock = 0u;			/*是否检查跳跃锁闭标志*/
	UINT8 rcWorkMode = GetLocalRcWorkMode();
	UINT8 cLocalCiType = 0U;  /*控区类型*/
    
/* 进路内设备数据 */
    /*信号机*/
    UINT16 startSignalId = 0u;
	UINT8 signalCrossState = 0u;

    
    
/* 联锁逻辑检查 */  
	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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;		
	}

	/*CBTC进路内方第一逻辑区段条件检查，车辆段进路需内方区段空闲*/
	if (CI_SUCCESS == reResult)
	{
		cLocalCiType = GetLocalCiType();
		if (CI_TYPE_CLD != cLocalCiType)
		{
			/*非车辆段，按CBTC既有逻辑处理*/
			if (RC_WORK_MODE_TIOC == rcWorkMode)
			{/*TIOC*/

				/*CBTC进路内方第一逻辑区段条件检查*/
				reResult = RouteCbtcFirstLgcSecCheck(routeId, &devId, &devState);
				if (CI_SUCCESS == reResult)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}
			else if (RC_WORK_MODE_CI == rcWorkMode)
			{/*CI*/

				/* 进路始端信号机【未跨压】且内方第一逻辑区段【空闲】*/
				startSignalId = GetRouteStartSignalId(routeId);
				devId = GetRouteInFirstLogSecId(routeId);
				devState = GetLogSecCurOccupyState(devId);
				signalCrossState = GetSignalCrossState(startSignalId);
				if (SIGNAL_CROSS_STATE_NO == signalCrossState)
				{
					if (devState == SECTION_OCCUPY_NO)
					{
						/* 通过检查 */
						reResult = CI_SUCCESS;
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
						/* 返回失败 */
						reResult = CI_ERROR;
					}

				}
				else
				{
					reResult = CheckEngineerVehicleNear(routeId);/*检查是否是工程车接近的跨压*/
					if (CI_SUCCESS == reResult)
					{
						/*不处理*/
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
						/* 返回失败 */
						reResult = CI_ERROR;
					}
				}
			}
			else
			{
				reResult = CI_ERROR;/*模式错误返回失败*/
			}
		}
		else
		{
			/*车辆段，进路不可追踪，需检查进路内方区段空闲*/
			reResult = CLDKeepOpenSecCheck(routeId, functionId, sendLevel);
		}
	}
    /* 进路内所有区段锁闭状态【正常锁闭】*/
	if(CI_SUCCESS == reResult)
	{

		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecLockStateCheck(routeId,PHYSICAL_SECTION_LOCK_NORMAL,&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 = RouteIntruSecVainCheck(routeId,&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 1
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		CiFunctionJLock = GetCiFunctionSwitchConfig(FUNC_CBTC_CHECK_JUMPLOCK_FLAG);
		if (FUNC_SWITCH_OFF == CiFunctionJLock)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			checkResult = RouteAllSecJumpLockStateCheck(routeId, &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
	{
		; /*不处理*/
	}

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

/* L16_引导进路信号开放区段联锁条件检查 */
/*
* 功能描述： 引导进路信号开放区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 OpenLeadRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 checkSecFlockFlag = 0u;     /*是否检查区段封锁*/
	checkSecFlockFlag = GetCiFunctionSwitchConfig(FUNC_YDROUTE_SEC_FLOCK_CHECK_FLAG);
/* 进路内设备数据 */

	if(NON_CHECK_SECFLOCK == checkSecFlockFlag)
	{   
        /* 联锁逻辑检查 */  
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 进路内所有区段未被封锁 */
		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 = RouteAllSecLockStateCheck(routeId,PHYSICAL_SECTION_LOCK_NORMAL,&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 0
    /*侵限区段侵限条件不满足检查*/
	if(CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteIntruSecVainCheck(routeId,&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;
		}
	}
#endif
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecJumpLockStateCheck(routeId,&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;
}

/* L17_Cbtc进路信号保持区段联锁条件检查 */
/*
* 功能描述： Cbtc进路信号保持区段联锁条件检查
* 参数说明：
*            UINT16 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
* mod by qw.liu 修改 CBTC下保持信号第一逻辑区段检查
*/
UINT8 KeepCbtcRouteSectionCheck(UINT16 routeId,UINT8 functionId,UINT8 sendLevel)
{
/* 局部变量定义初始化 */
    UINT8 reResult = CI_ERROR;          /*返回值*/
    UINT8 checkResult = CI_ERROR;       /*检查结果*/
    UINT16 devId = 0u;                   /*设备ID*/
    UINT8 devState = 0u;                 /*设备状态*/
	UINT8 CiFunctionJLock = 0u;			/*是否检查跳跃锁闭标志*/
	UINT8 rcWorkMode = GetLocalRcWorkMode();
    
/* 进路内设备数据 */
    /*信号机*/
    UINT16 startSignalId = 0u;
	UINT8 signalCrossState = 0u;
	UINT8 preLogDevState = 0u;			/*之前逻辑区段占用状态*/
	UINT8 LogSecCurCtOrUtOcc = 0U;
	UINT16 outPhySecId = 0U; /*进路外方第一物理区段*/
	UINT8 outPhySecState = 0U;
	UINT8 cLocalCiType = 0U;  /*本控区类型*/

/* 联锁逻辑检查 */  

	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 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;		
	}

    /*CBTC进路内方第一逻辑区段条件检查*/
	if(CI_SUCCESS == reResult)
	{
		cLocalCiType = GetLocalCiType();
		if (CI_TYPE_CLD != cLocalCiType)
		{
			/*非车辆段，按CBTC既有逻辑处理*/
			if (RC_WORK_MODE_TIOC == rcWorkMode)
			{/*TIOC*/

			 /*CBTC进路内方第一逻辑区段条件检查*/
				reResult = RouteCbtcFirstLgcSecCheck(routeId, &devId, &devState);
				if (CI_SUCCESS == reResult)
				{
					/* 通过检查 */
					reResult = CI_SUCCESS;
				}
				else
				{
					/* 记录故障码 */
					SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
					/* 失败返回 */
					reResult = CI_ERROR;
				}
			}
			else if (RC_WORK_MODE_CI == rcWorkMode)
			{/*CI*/

			/* 进路始端信号机【未跨压】且 非（进路外方区段【空闲】且内方第一逻辑区段【占用】）*/
				startSignalId = GetRouteStartSignalId(routeId);
				devId = GetRouteInFirstLogSecId(routeId);
				devState = GetLogSecCurOccupyState(devId);
				LogSecCurCtOrUtOcc = GetLogSecCurCtOrUtOccupyState(devId);
				preLogDevState = GetLogSecPreCtOrUtOccupyState(devId);
				signalCrossState = GetSignalCrossState(startSignalId);
				if (SIGNAL_CROSS_STATE_NO == signalCrossState)
				{
					if (!((SECTION_OCCUPY_NO == devState) && (LOGICSECTION_OCCUPY_CT == preLogDevState)))
					{ /*非（内方第一逻辑区段区段当前【空闲】且之前【占用CT】，说明已经出清第一逻辑区段），只要未出清第一逻辑区段，则继续等跨压*/
						if (LOGICSECTION_OCCUPY_UT != LogSecCurCtOrUtOcc)
						{
							/*只有当为CT占压和空闲时，防止UT异常占压 通过检查 */
							reResult = CI_SUCCESS;
						}
						else
						{
							/* 记录故障码 */
							SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, LogSecCurCtOrUtOcc, sendLevel);
							reResult = CI_ERROR;	/*UT占压异常*/
						}

					}
					else
					{
						outPhySecId = GetSignalOutFirstPhySecId(startSignalId);  /*信号机外方第一物理区段ID*/
						outPhySecState = GetPhySecCurMergeState(outPhySecId);
						/*若进路外方第一区段任处于占用状态，不关闭信号(考虑CT列车追踪，前车驶出时，后车轮对未进路，包络进入，造成第一区段异常出清，信号机关闭的场景)*/
						if (SECTION_OCCUPY_YES == outPhySecState)
						{
							reResult = CI_SUCCESS;
						}
						else
						{
							/* 记录故障码 */
							SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
							reResult = CI_ERROR;
						}
					}
				}
				else
				{
					reResult = CheckEngineerVehicleNear(routeId);/*检查是否是工程车接近的跨压以及列车的真实跨压*/
					if (CI_SUCCESS == reResult)
					{
						/*不处理*/
					}
					else
					{
						/* 记录故障码 */
						SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
						/* 返回失败 */
						reResult = CI_ERROR;
					}
				}
			}
			else
			{
				reResult = CI_ERROR;/*模式错误返回失败*/
			}
		}
		else
		{
			/*车辆段，进路不可追踪，需检查进路内方区段空闲*/
			reResult = CLDKeepOpenSecCheck(routeId, functionId, sendLevel);
		}
	}

    
    /* 进路内所有区段锁闭状态【正常锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = RouteAllSecLockStateCheck(routeId,PHYSICAL_SECTION_LOCK_NORMAL,&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 = RouteIntruSecVainCheck(routeId,&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 1
	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		CiFunctionJLock = GetCiFunctionSwitchConfig(FUNC_CBTC_CHECK_JUMPLOCK_FLAG);
		if (FUNC_SWITCH_OFF == CiFunctionJLock)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			checkResult = RouteAllSecJumpLockStateCheck(routeId, &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
	{
		; /*不处理*/
	}

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


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

	UINT16 devId = 0u;                   /*设备ID*/

	UINT16 floodSum = 0u;
	UINT16 *pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/


	UINT16 ii=0u;

	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	UINT8 floodState = 0u;/*防淹门状态*/

	/*0.获取进路管理防淹门*/
	floodSum = GetRouteFloodGateSum(routeId);
	pFloodIdBuf = GetRouteFloodGateBuf(routeId);

	if (NULL == pFloodIdBuf)
	{
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		for (ii =0u;ii<floodSum;ii++)
		{
			devId = pFloodIdBuf[ii];

			floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

			if (floodGateId > 0u)
			{

				/*检查1：检查防淹门开启锁闭状态为开启锁闭*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurOpenLockState(floodGateId);
					if (FLOOD_GATE_OPENLOCK == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_OPENLOCKSTATE,floodState,sendLevel);
						break;
					}
				}



				/*检查2：检查防淹门关门请求状态为未关门请求*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurCloseRequestSta(floodGateId);
					if (FLOOD_GATE_NOT_CLOSEREQ == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_CLOSEREQSTATE,floodState,sendLevel);
						break;
					}
				}

				/*检查3：检查防淹门当前同意关门输入状态为不同意关门*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurAgreeCloseSta(floodGateId);
					if (FLOOD_GATE_NOT_AGREE_CLOSE == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_AGREECLOSESTATE,floodState,sendLevel);
						break;
					}
				}
			}
			else
			{
				reResult = CI_ERROR;
				break;
			}


		}
	}

	return reResult;
}




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

	UINT16 devId = 0u;                   /*设备ID*/

	UINT16 floodSum = 0u;
	UINT16 *pFloodIdBuf = NULL;/*临时变量：进路管理防淹门数量和id数组指针*/


	UINT16 ii=0u;

	UINT16 floodGateId = 0u;/*临时变量：防淹门id*/
	UINT8 floodState = 0u;/*防淹门状态*/

	/*0.获取进路管理防淹门*/
	floodSum = GetRouteFloodGateSum(routeId);
	pFloodIdBuf = GetRouteFloodGateBuf(routeId);

	if (NULL == pFloodIdBuf)
	{
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
	}

	if (CI_SUCCESS == reResult)
	{
		for (ii =0u;ii<floodSum;ii++)
		{
			devId = pFloodIdBuf[ii];

			floodGateId = GetFloodGateBufIndex(devId);/*防淹门id合法性判断*/

			if (floodGateId > 0u)
			{

				/*检查1：检查防淹门开启锁闭状态为开启锁闭*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurOpenLockState(floodGateId);
					if (FLOOD_GATE_OPENLOCK == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_OPENLOCKSTATE,floodState,sendLevel);
						break;
					}
				}



				/*检查2：检查防淹门关门请求状态为未关门请求*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurCloseRequestSta(floodGateId);
					if (FLOOD_GATE_NOT_CLOSEREQ == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_CLOSEREQSTATE,floodState,sendLevel);
						break;
					}
				}

				/*检查3：检查防淹门当前同意关门输入状态为不同意关门*/
				if (CI_SUCCESS == reResult)
				{
					floodState = GetFloodGateCurAgreeCloseSta(floodGateId);
					if (FLOOD_GATE_NOT_AGREE_CLOSE == floodState)
					{
						reResult = CI_SUCCESS;
					}
					else
					{
						reResult = CI_ERROR;
						SetErrorData(functionId,CI_DEVICE_TYPE_FLOODGATE,floodGateId,ETYPE_FLOODGATE_AGREECLOSESTATE,floodState,sendLevel);
						break;
					}
				}
				
			}
			else
			{
				reResult = CI_ERROR;
				break;
			}

		}
	}

	return reResult;
}


/*
* 功能描述： 处理取消自动信号命令函数
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS:成功
			 CI_ERROR:失败
*/
void CancleAutoSigCmdProcc(const UINT16 routeId)
{
	/*变量初始化*/
	UINT8 autoSigCmdFlag = 0u;
	UINT8 cancleRouteState = 0u;

	autoSigCmdFlag = GetCancleAutoSigCmdFlag(routeId);
	/*取消自动信号命令有效*/
	if(AUTO_ROUTE_CANCLE_CMD_YES == autoSigCmdFlag)
	{
		/*获取处理结果*/
		cancleRouteState = AutoSigRouteQuXiaoProc(routeId);
		if(RETURN_FIRSTXUANPAI_QUXIAOAUTOSIG_WAIT == cancleRouteState)
		{
			/*设置取消等待状态*/
			SetAutoSigCancleState(routeId,AUTO_ROUTE_CANCLE_WAIT);
		}
		else if(CI_SUCCESS == cancleRouteState)
		{
			/*设置取消成功状态*/
			SetAutoSigCancleState(routeId,AUTO_ROUTE_CANCLE_SUCCESS);
			/*设置命令无效*/
			SetCancleAutoSigCmdFlag(routeId,AUTO_ROUTE_CANCLE_CMD_NO);
		}
		else
		{
			/*设置取消失败状态*/
			SetAutoSigCancleState(routeId,AUTO_ROUTE_CANCLE_FAIL);
			/*设置命令无效*/
			SetCancleAutoSigCmdFlag(routeId,AUTO_ROUTE_CANCLE_CMD_NO);
		}
	}
	else 
	{
		/*设置取消无效状态*/
		SetAutoSigCancleState(routeId,AUTO_ROUTE_CANCLE_NO);
	}
}



/*
* 功能描述： 保护区段出清检查
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS:成功
			 CI_ERROR:失败
*/
UINT8 BlocOverlapOccClearProc(const UINT16 routeId)
{
	
	UINT8 rtVal = CI_ERROR;
	UINT8 checkResult = CI_ERROR;
	UINT16 devId = 0u;
	UINT8 devState = 0u;

	/* 进路内设备数据 */    
	/*防护进路*/
	UINT8 const overlapSum = GetRouteOverlapSum(routeId);
	UINT16 const overlapId = GetRouteOverlapLockedId(routeId);

	if (overlapSum > 0u)
	{
		if (overlapId > 0U)
		{/*保护区段锁闭*/
			devId = 0u;
			devState = 0u;
			checkResult = OpenBlockOvlpAllSecOccuClrCheck(overlapId,&devId,&devState);
			if (CI_SUCCESS == checkResult)
			{
				/*保护区段锁闭，且没有占用，通过检查 */
				rtVal = CI_SUCCESS;
			}
			else
			{
				/*有占用，返回保护区段占用*/
				rtVal = CI_ERROR;
			}
		}
	}
	else
	{/*没有保护区段,返回成功*/
		rtVal = CI_SUCCESS;
	}

	return rtVal;
}

/*
* 功能描述： 进路第一个逻辑区段解锁条件检查
* 参数说明： const UINT16 routeId, 进路ID
*            
* 返回值  ： CI_ERROR 失败
*            CI_SUCCESS 成功
*            CI_CANCLE_ZHAOCHA_FAIL 照查检查失败
*            RETURN_AUTOLOCK_ERR_EXCEPT 正常解锁失败
*/
UINT8 RouteLogSecAutoUnlockProcess(UINT16 const routeId, UINT16* logSectionId)
{
	/*初始化变量*/
	UINT8 const functionId = EFUNC_ROUTE_FIRST_LOG_UNLOCK; 
	UINT16 nlockLogId = 0u;
	UINT16 nextLogId = 0u;     /*下一逻辑区段*/
	UINT16 cancleZhaoChaRelayId = 0u;    /*取消照查继电器ID*/
	UINT8  relayState = 0u;              /*继电器采集状态*/
	UINT8 logCurOccupyState = 0u;
	UINT8 logPreOccupyState = 0u;
	UINT16 routeLeavePhyId = 0u;
	UINT8 leavePhyCurOccState = 0u;
	UINT8 reResult = CI_ERROR; /*返回值*/
	UINT8 sendLevel = ESEND_LEVEL_ZERO;    /*不发送ATS*/

	/*第一个属于当前进路的正常锁闭逻辑区段*/
	nlockLogId = GetRouteFirstNormalLockLogId(routeId);

	/*找到进路第一个锁闭逻辑区段*/
	if(0u < nlockLogId)
	{
		reResult = CI_SUCCESS;
	}
	else
	{
		reResult = CI_ERROR;
		*logSectionId = 0u;
	}
	/*检查区段占用*/
	if(CI_SUCCESS == reResult)
	{
		/*获取占用信息*/
		logCurOccupyState = GetLogSecCurCtOrUtOccupyState(nlockLogId);
		logPreOccupyState = GetLogSecPreCtOrUtOccupyState(nlockLogId);
		/*当前区段当前空闲之前CT占用*/
		if((LOGICSECTION_OCCUPY_NO == logCurOccupyState) && (LOGICSECTION_OCCUPY_CT == logPreOccupyState))
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
			*logSectionId = nlockLogId;
		}
		/*进路内方第一区段由占用变空闲时才触发解锁流程，检查取消照查继电器(如果配置了)状态*/
		if(CI_SUCCESS == reResult)
		{
			cancleZhaoChaRelayId = GetRouteCancleZhaoChaRelayId(routeId); /*取消照查继电器ID*/
			
			if((0u != cancleZhaoChaRelayId) && (0xFFFFu != cancleZhaoChaRelayId))
			{
				/*取消继电器有效：取消继电器采集状态为：吸起*/
				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_CANCLE_ZHAOCHA_FAIL;
					*logSectionId = nlockLogId;
				}

			}
		}
		/*检查下一逻辑区段占用状态*/
		if(CI_SUCCESS == reResult)
		{
			/*获取下一逻辑区段*/
			nextLogId = GetRouteNextLogSecId(routeId,nlockLogId);
			if(0u != nextLogId)
			{
				/*和待解锁区段相等，说明是进路的最后一个逻辑区段*/
				if(nlockLogId == nextLogId)
				{
					/*获取进路的离去区段*/
					routeLeavePhyId = GetRouteLeavePhySecId(routeId);
					leavePhyCurOccState = GetPhySecCurMergeState(routeLeavePhyId);
					/*离去区段占用*/
					if(SECTION_OCCUPY_YES == leavePhyCurOccState)
					{
						/*返回成功*/
						reResult = CI_SUCCESS;
						*logSectionId = nlockLogId;
					}
					/*飞车*/
					else
					{
						/* 失败返回未开始解锁 */
						SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,routeLeavePhyId,ETYPE_PS_AUNLOCK_ERROR,leavePhyCurOccState,sendLevel); 
						reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
						*logSectionId = nlockLogId;
					}
				}
				/*不是进路最后一个逻辑区段*/
				else
				{
					logCurOccupyState = GetLogSecCurOccupyState(nextLogId);
					/*下一逻辑区段占用*/
					if(SECTION_OCCUPY_YES == logCurOccupyState)
					{
						/*返回成功*/
						reResult = CI_SUCCESS;
						*logSectionId = nlockLogId;
					}
					else
					{
						/* 失败返回未开始解锁 */
						SetErrorData(functionId,CI_DEVICE_TYPE_LOGICSEC,nextLogId,ETYPE_PS_AUNLOCK_ERROR,logCurOccupyState,sendLevel); 
						reResult = RETURN_AUTOLOCK_ERR_EXCEPT;
						*logSectionId = nlockLogId;
					}
				}
			}
		}
	}
	return(reResult);
}


/*
* 功能描述： 进路逻辑区段三点检查延时解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void LogSecDelayUnlockProc(const UINT16 routeId)
{
	/*初始化变量*/
	UINT16 logSectionId = 0u;        /*逻辑区段ID*/
	UINT16 nextLogId = 0u;          /*下一逻辑区段ID*/
	UINT8 logLockState = 0u;         /*逻辑区段锁闭状态*/
	UINT8 returnValue = 0u;          /*函数返回值*/
	UINT8 logUlockState = 0u;         /*逻辑区段解锁状态*/
	UINT8 routeFlag = 0u;
	UINT32 cycNum = 0u;
	UINT8 checkValue = 0u;
	UINT16 logBelongPhyId = 0u; 
	UINT16 logRoute = 0u;
	UINT8 routeDir = 0u;
	UINT16 routeLastSwiPhySecId = 0u;

	/*信息获取*/
	routeDir = GetRouteDirection(routeId);
	cycNum = Get2oo2CurCycleNum();
	/*逻辑区段延时检查*/
	returnValue = LogSecDelayUnlockProcess(routeId, &logSectionId);
	/*没有延时解锁的逻辑区段*/
	if(0u == logSectionId)
	{
		/*不做处理*/
	}
	else
	{
		/*逻辑区段延时检查成功*/
		if(CI_SUCCESS == returnValue)
		{
			/*设置逻辑区段未锁闭*/
			SetLogSecLockState(logSectionId,LOG_SECTION_LOCK_NO,routeId,routeDir);
			/*获取逻辑区段所属物理区段*/
			logBelongPhyId = GetLgcSecRelativePhySecId(logSectionId);
			checkValue = CheckPhyInLogUlock(logBelongPhyId,routeId,&logRoute);
			/*物理区段中属于本进路锁闭的逻辑区段全部解锁*/
			if(CI_SUCCESS == checkValue)
			{
				routeLastSwiPhySecId = GetRouteLastSwichPhySecId(routeId);
				/*区段相等*/
				if(routeLastSwiPhySecId == logBelongPhyId)
				{
					/*将本进路防护锁闭道岔解锁*/
					SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL);
				}
				/*逻辑区段全部解锁，且不存在逻辑区段锁闭属于其他进路*/
				if(0u == logRoute)
				{
					/*设置物理区段解锁*/
					SetPhySecLockState(logBelongPhyId, PHYSICAL_SECTION_LOCK_NO, routeId, routeDir);
				}
			}
			/*进路逻辑区段全部解锁*/
			logUlockState = CheckRouteLogSecHaveUnLock(routeId);
			if(CI_SUCCESS == logUlockState)
			{
				/*进路区段全部解锁*/
				routeFlag = GetRouteStateFlag(routeId);
				if (ROUTE_STATE_FLAG_YES == routeFlag)
				{/*CBTC追踪办理进路标志有效，则不改变进路状态，继续保持自动解锁正常（此时进路区段已全部解锁）*/
				}
				else
				{/*CBTC追踪办理进路标志无效，则设置进路空闲*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
				} 
			}
			else
			{
				/*获取下一个逻辑区段锁闭状态*/
				nextLogId = GetRouteNextLogSecId(routeId,logSectionId);
				logLockState = GetLogSecLockState(nextLogId);
				/*存在下一区段,且是延时解锁状态*/
				if((0u < nextLogId) && (logSectionId != nextLogId)
					&& (LOG_SECTION_LOCK_DELAY == logLockState))
				{
					/*设置下一逻辑区段延时解锁计时*/
					SetLogUnlockStartCycNum(nextLogId,cycNum);
				}
				else
				{
					/*不做处理*/
				}
			}
		}
		/*计时未到*/
		else if(RETURN_DELAYUNLOCK_ERR_TIMECOUNT == returnValue)
		{
			/*不做处理*/
		}
		/*失败*/
		else
		{
			/*设置延时解锁起始周期*/
			SetLogUnlockStartCycNum(logSectionId,cycNum);
		}
	}
}


/*
* 功能描述： 区段延时解锁
* 参数说明： UINT16 const routeId，进路号
*            UINT16* phySectionId，解锁区段ID
* 返回值  ： CI_ERROR
*            RETURN_DELAYUNLOCK_ERR_TIMECOUNT
*            CI_SUCCESS
*/
UINT8 LogSecDelayUnlockProcess(UINT16 const routeId, UINT16* logSectionId)
{
	/*变量初始化*/
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT32 cycNum = 0u;
	UINT32 cycNumSysPara = 0u;/*系统参数区段延时解锁周期*/
	UINT8 routeTimeState = 0u;
	UINT16 dlockLogId = 0u;
	UINT8 logOccState = 0u; /*逻辑区段占用状态*/


	/*第一个延时延时区段*/
	dlockLogId = GetRouteFirstDelayLockLogId(routeId);
	logOccState = GetLogSecCurOccupyState(dlockLogId);
	/*获取周期*/
	cycNum = GetLogUnlockStartCycNum(dlockLogId);
	cycNumSysPara = GetSystemParaSecDelayUnlockCyc();
	/* 区段延时解锁时间状态*/
	routeTimeState = SystemOverTimeCheck(cycNum, cycNumSysPara);

	/*进路第一个区段【延时锁闭】且属于当前进路*/
	if (dlockLogId > 0U)
	{
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
		/*返回ID = 0*/
		*logSectionId = 0;

	}
	if(CI_SUCCESS == reResult)
	{
		/*区段空闲*/
		if(SECTION_OCCUPY_NO == logOccState)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			/* 重置延时 */
			*logSectionId = dlockLogId;

		}
	}
	if(CI_SUCCESS == reResult)
	{
		/*未计时*/
		if (CI_TIME_NO == routeTimeState)
		{
			/* 失败返回 */
			reResult = CI_ERROR;
			/* 重置延时 */
			*logSectionId = dlockLogId;
		}
		/*计时中*/
		else if(CI_TIME_IN == routeTimeState)
		{
			/*时间未到*/
			/* 失败返回 */
			reResult = RETURN_DELAYUNLOCK_ERR_TIMECOUNT;
			/* 继续延时 */
			*logSectionId = dlockLogId;
		}
		/*计时到了*/
		else
		{
			/* 时间到时 */
			reResult = CI_SUCCESS;
			*logSectionId = dlockLogId;
		}
	}
	return(reResult);
}

/*
* 功能描述： 进路逻辑区段资源列车解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLgcSecResUnlockProcess(const UINT16 wRouteId)
{
	/*变量初始化*/
	UINT8 chLgcCurOccupyState = 0u;
	UINT16 ii = 0U;
	UINT16 wBelongRouteId = 0U;
	UINT16 wPreBelongRouteId = 0U;
	UINT16 wRouteFirstLgcSecId = 0U;
	UINT16 wUnlockLgcSecId = 0U; /*当前锁闭逻辑区段id*/
	UINT16 wPreUnlockLgcSecId = 0U; /*进路内逻辑区段上一个逻辑区段*/
	UINT8 chLgcLockState = 0U;
	UINT8 chPreLgcLockState = 0U;
	UINT8 chLgcResTrainSum = 0U;
	UINT8 chLogSecReleaseFlag = 0U;
	UINT8 chKeepWork = CI_ERROR;
	UINT16 wRelayZhaoCId = 0U;
	UINT8 chRelayState = 0U;
	UINT16 routeLogNum = 0u;
	UINT16 wTrainId = 0U;
	UINT16* routeLogIdBuf = NULL;
	UINT8 cRouteState = 0U;
	UINT8 chTrainLevel = 0U;
	UINT8 chThreePointCheck = CI_ERROR;
	UINT8 chLocalCi = 0U;
	UINT8 chLogSecBelongCi = 0U;


	/*获取进路逻辑区段数据*/
	routeLogNum = GetRouteLogSectionSum(wRouteId);
	routeLogIdBuf = GetRouteLogSectionIdBuf(wRouteId);
	

	if ((0u < routeLogNum)
		&& (MAX_ROUTE_IN_LT_NUM > routeLogNum))
	{
		wRelayZhaoCId = GetRouteCancleZhaoChaRelayId(wRouteId); /*取消照查继电器ID*/
		
		if ((0u != wRelayZhaoCId) && (0xFFFFU != wRelayZhaoCId))
		{
			/*取消继电器有效：取消继电器采集状态为：吸起*/
			chRelayState = GetRelayCollState(wRelayZhaoCId);/*获取取消继电器采集状态*/
			if (RELAY_STATE_UP == chRelayState)
			{
				/* 通过检查 */
				chKeepWork = CI_SUCCESS;
			}
			else
			{

				chKeepWork = CI_ERROR;
			}

		}
		else
		{
			/* 通过检查 */
			chKeepWork = CI_SUCCESS;
		}

		/*照查继电器检查通过后开始解锁*/
		if (CI_SUCCESS == chKeepWork)
		{
			for (ii = 0u; ii < routeLogNum; ii++)
			{
				chKeepWork = CI_ERROR;
				wPreUnlockLgcSecId = wUnlockLgcSecId;
				wUnlockLgcSecId = routeLogIdBuf[ii];
				if (0U == wPreUnlockLgcSecId)
				{
					chKeepWork = CI_SUCCESS;
				}
				else
				{
					chPreLgcLockState = GetLogSecLockState(wPreUnlockLgcSecId);
					wPreBelongRouteId = GetLogSecLockBelongRoute(wPreUnlockLgcSecId);
					if (wPreBelongRouteId == wRouteId)
					{
						if ((LOG_SECTION_LOCK_NO == chPreLgcLockState)
							|| (LOG_SECTION_LOCK_PROTECT == chPreLgcLockState))
						{
							chKeepWork = CI_SUCCESS;
						}
						else
						{
							chKeepWork = CI_ERROR;
						}
					}
					else
					{
						/* 上一个区段锁闭不属于自己*/
						chKeepWork = CI_SUCCESS;
					}

		
				}
				if (CI_SUCCESS == chKeepWork)
				{

					wBelongRouteId = GetLogSecLockBelongRoute(wUnlockLgcSecId);
					/*锁闭所属进路等于本进路*/
					if (wBelongRouteId == wRouteId)
					{
						chLgcCurOccupyState = GetLogSecCurCtOrUtOccupyState(wUnlockLgcSecId);
						if (LOGICSECTION_OCCUPY_NO == chLgcCurOccupyState)
						{
							chLgcLockState = GetLogSecLockState(wUnlockLgcSecId);
							chLogSecReleaseFlag = GetLogSecReleaseFlag(wUnlockLgcSecId);
							chLgcResTrainSum = GetLogSecTrainInfoSum(wUnlockLgcSecId);
							
							wTrainId = GetLogSecTrainIdByIndex(wUnlockLgcSecId, 0);
						}
						else
						{
							chKeepWork = CI_ERROR;
						}

					}
					else
					{
						chKeepWork = CI_ERROR;
					}
				}
				else
				{
				}
				if (CI_SUCCESS == chKeepWork)
				{
					chLocalCi = GetSystemParaLocalCiId();
					chLogSecBelongCi = GetLogSecBelongCiId(wUnlockLgcSecId);
					if (chLocalCi != chLogSecBelongCi)
					{
						/*释放请求来自相邻控区*/
						chTrainLevel = GetLogSecReleaseTrainLevel(wUnlockLgcSecId, wTrainId);
					}
					else
					{
						/*属于本控区 要求VBTC车释放解锁*/
						chTrainLevel = GetTrainLevel(wTrainId);
					}
					if (TRAIN_LEVEL_VBTC == chTrainLevel)
					{
						chThreePointCheck = RouteLgcSecResUnlockNextSecCheck(wRouteId, wUnlockLgcSecId);
					}
					else
					{
						chThreePointCheck = CI_ERROR;
					}

					/*正常锁闭*/
					if (LOG_SECTION_LOCK_NORMAL == chLgcLockState)
					{
						cRouteState = GetRouteState(wRouteId);
						/*仅当逻辑区段列车资源数量为1且本控区VBTC车解锁 或相邻联锁检查VBTC车释放*/
						if ((1U == chLgcResTrainSum) && (LOGIC_SECTION_TRAIN_UNLOCK_YES == chLogSecReleaseFlag)
							&& ((CI_SUCCESS == chThreePointCheck) || (ROUTE_STATE_HALF_UNLOCK == cRouteState)))
						{
							/*进路状态为部分进路等待解锁时，不考虑列车级别，解决场景：列车任意位置折返关钥匙换端会导致列车级别非VBTC，这时释放资源将导致原进路的逻辑区段无法解锁*/
							LgcSecUnlockProc(wRouteId, wUnlockLgcSecId);
							cRouteState = GetRouteState(wRouteId); /*设置逻辑区段解锁后需重新更新进路状态*/
							wRouteFirstLgcSecId = GetRouteInFirstLogSecId(wRouteId);							
							if ((wRouteFirstLgcSecId == wUnlockLgcSecId) && (ROUTE_STATE_NEAR_LOCK == cRouteState)) /*修缺陷YF0083-922，2023-07-14*/
							{
								SetRouteStateManage(wRouteId, ROUTE_STATE_AUTO_UNLOCK);
							}
							else
							{
							}
							debug_infor_printf((const)"LogSecRes Unlock LgcId: %d TrainId:%d  Cyc\n"
								, wUnlockLgcSecId
								, wTrainId
								, Get2oo2CurCycleNum());
						}
						else
					    {
					    }
					}
					
					/*延时锁闭 收到解锁命令后立即解锁*/
					else if (LOG_SECTION_LOCK_DELAY == chLgcLockState)
					{
						/*仅当逻辑区段列车资源数量为1且本控区VBTC车解锁 或相邻联锁检查VBTC车释放*/
						if ((1U == chLgcResTrainSum) && (LOGIC_SECTION_TRAIN_UNLOCK_YES == chLogSecReleaseFlag) && (CI_SUCCESS == chThreePointCheck))
						{
							LgcSecUnlockProc(wRouteId, wUnlockLgcSecId);
						}
						else
						{
						}
					}
					else
					{
						/*无操作*/
					}
				}
				else
				{
				}
			}
		}
		else
		{
		}
	}
	else
	{
	}
}

/*
* 功能描述： 进路逻辑区段解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void LgcSecUnlockProc(const UINT16 routeId, const UINT16 logSectionId)
{
	/*初始化变量*/
	UINT16 nextLogId = 0u;          /*下一逻辑区段ID*/
	UINT8 logLockState = 0u;         /*逻辑区段锁闭状态*/
	UINT8 logUlockState = 0u;         /*逻辑区段解锁状态*/
	UINT8 routeFlag = 0u;
	UINT8 checkValue = 0u;
	UINT16 logBelongPhyId = 0u;
	UINT16 logRoute = 0u;
	UINT8 routeDir = 0u;
	UINT16 routeLastSwiPhySecId = 0u;
	UINT32 cycNum = 0U;

	cycNum = Get2oo2CurCycleNum();

	/*信息获取*/
	routeDir = GetRouteDirection(routeId);

	/*设置逻辑区段未锁闭*/
	SetLogSecLockState(logSectionId, LOG_SECTION_LOCK_NO, routeId, routeDir);
	/*获取逻辑区段所属物理区段*/
	logBelongPhyId = GetLgcSecRelativePhySecId(logSectionId);
	checkValue = CheckPhyInLogUlock(logBelongPhyId, routeId, &logRoute);
	/*物理区段中属于本进路锁闭的逻辑区段全部解锁*/
	if (CI_SUCCESS == checkValue)
	{
		routeLastSwiPhySecId = GetRouteLastSwichPhySecId(routeId);
		/*区段相等*/
		if (routeLastSwiPhySecId == logBelongPhyId)
		{
			/*将本进路防护锁闭道岔解锁*/
			SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL);
		}
		/*设置物理区段解锁*/
		SetPhySecLockState(logBelongPhyId, PHYSICAL_SECTION_LOCK_NO, routeId, routeDir);
	}
	/*进路逻辑区段全部解锁*/
	logUlockState = CheckRouteLogSecHaveUnLock(routeId);
	if (CI_SUCCESS == logUlockState)
	{
		/*进路区段全部解锁*/
		routeFlag = GetRouteStateFlag(routeId);
		if (ROUTE_STATE_FLAG_YES == routeFlag)
		{/*CBTC追踪办理进路标志有效，则不改变进路状态，继续保持自动解锁正常（此时进路区段已全部解锁）*/
		}
		else
		{/*CBTC追踪办理进路标志无效，则设置进路空闲*/
			SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
		}
	}
	else
	{
		/*获取下一个逻辑区段锁闭状态*/
		nextLogId = GetRouteNextLogSecId(routeId, logSectionId);
		logLockState = GetLogSecLockState(nextLogId);
		/*存在下一区段,且是延时解锁状态*/
		if ((0u < nextLogId) && (logSectionId != nextLogId)
			&& (LOG_SECTION_LOCK_DELAY == logLockState))
		{
			/*设置下一逻辑区段延时解锁计时*/
			SetLogUnlockStartCycNum(nextLogId, cycNum);
		}
		else
		{
			/*不做处理*/
		}
	}
}


/*
* 功能描述： 进路逻辑区段资源列车释放处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void RouteLgcSecResReleaseProcess(const UINT16 wRouteId)
{
	/*变量初始化*/
	UINT16 ii = 0U;
	UINT16 wTrainId = 0U;
	UINT8 jj = 0U;
	UINT16 wBelongRouteId = 0U;
	UINT16 wUnlockLgcSecId = 0U;
	UINT16 wPreUnlockLgcSecId = 0U; /*进路内逻辑区段上一个逻辑区段*/
	UINT8 chLgcResTrainSum = 0U;
	UINT8 chLogSecReleaseFlag = 0U;
	UINT8 chKeepWork = CI_ERROR;
	UINT16 routeLogNum = 0u;
	UINT16 wLgcBufIndex = 0U;
	UINT8 chNeedKeepSum = 0U;
	UINT16* routeLogIdBuf = NULL;
	LogicTrainResStruct * pstTrainResInfo = NULL;
	LogicSectionDataStruct *pstLgcSecInfo = NULL;
	/*获取进路逻辑区段数据*/
	routeLogNum = GetRouteLogSectionSum(wRouteId);
	routeLogIdBuf = GetRouteLogSectionIdBuf(wRouteId);
	pstLgcSecInfo = GetLogicSecData();

	if ((0u < routeLogNum)
		&& (MAX_ROUTE_IN_LT_NUM > routeLogNum)
		&&(NULL!= pstLgcSecInfo))
	{
		for (ii = 0u; ii < routeLogNum; ii++)
		{
			chKeepWork = CI_ERROR;
			wPreUnlockLgcSecId = wUnlockLgcSecId;
			wUnlockLgcSecId = routeLogIdBuf[ii];
			wBelongRouteId = GetLogSecLockBelongRoute(wUnlockLgcSecId);
			wLgcBufIndex = GetlogSectionBufIndex(wUnlockLgcSecId);

			if (LOGIC_SECTION_SUM_MAX > wLgcBufIndex)
			{
				chKeepWork = CI_SUCCESS;
			}
			else
			{
				chKeepWork = CI_ERROR;
			}

			if (CI_SUCCESS == chKeepWork)
			{
				/*锁闭所属进路等于本进路*/
				if (wBelongRouteId == wRouteId)
				{
					chLgcResTrainSum = GetLogSecTrainInfoSum(wUnlockLgcSecId);
					if (LOGIC_SECTION_RES_SUM_MAX > chLgcResTrainSum)
					{
						; /*继续执行*/
					}
					else
					{
						chKeepWork = CI_ERROR;
					}
				}
				else
				{
					chKeepWork = CI_ERROR;
				}
			}
			else
			{
			}

			
			if (CI_SUCCESS == chKeepWork)
			{
				chNeedKeepSum = 0U;
				for (jj = 0U; jj < chLgcResTrainSum; jj++)
				{
					wTrainId = GetLogSecTrainIdByIndex(wUnlockLgcSecId, jj);

					/*是否收到列车解锁命令*/
					chLogSecReleaseFlag = GetLogSecTrainRelease(wUnlockLgcSecId, wTrainId);

					/*上一区段是否已解锁*/
					pstTrainResInfo = GetLogSecTrainInfoById(wPreUnlockLgcSecId, wTrainId);
					if (((LOGIC_SECTION_TRAIN_UNLOCK_YES == chLogSecReleaseFlag)||(0U==wTrainId))
						&& (NULL == pstTrainResInfo))
					{
						/*删除该列车对应逻辑区段资源*/
						(void)ComMemSet((void *)&pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj], (UINT16)sizeof(LogicTrainResStruct), 0U);
						debug_infor_printf((const)"LogSecRes Release LgcId: %d TrainId:%d  Cyc\n"
							, wUnlockLgcSecId
							, wTrainId
							, Get2oo2CurCycleNum());
					}
					else
					{
						pstLgcSecInfo[wLgcBufIndex].szTrainResData[chNeedKeepSum++] = pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj];
					}

				}
				pstLgcSecInfo[wLgcBufIndex].chTrainInfoSum = chNeedKeepSum;
				if (0U == chNeedKeepSum)
				{
					SetLogSecResShareFlag(wUnlockLgcSecId,LOGIC_SECTION_RES_SHARE_YES);
				}
			}
			else
			{
			}
		}
	}
}
/*
* 功能描述： 检查保护区段人工解锁是否可执行
* 参数说明： const UINT16 overlapId, 保护区段ID
*            const UINT32 dwOverlapUnlockCount 保护区段自动解锁周期数
*            const UINT32 dwOverlapUnlockStartCyc 保护区段自动解锁起始周期
* 返回值  ： CI_SUCCESS:成功
			 CI_ERROR:失败
*/
UINT8 CheckOverlapLaborUnlock(const UINT16 overlapId, const UINT32 dwOverlapUnlockCount, const UINT32 dwOverlapUnlockStartCyc)
{	
	UINT8 rtVal = CI_ERROR;
	UINT8 OverlapLaborUnlockSetState = 0u;
	UINT32 laborUnlockOverlapTimeCount = 0u;
	UINT32 laborUnlockStartCycNum =0u;
	UINT8 laborUnlockStopTimeState =0u;
	UINT8 cTimeCheckFlag = CI_TIME_NO;

	if ((0U < overlapId) && (OVERLAP_SUM_MAX > overlapId))
	{
		OverlapLaborUnlockSetState = GetOverlapLaborUnlockSetState(overlapId);
		if (LABOR_UNLOCK_OVERLAP_YES == OverlapLaborUnlockSetState)
		{
			/*收到人工命令，倒计时到，解锁保护区段*/
			laborUnlockOverlapTimeCount = GetlabarUnlockOverlapTimeCount();/*人工解锁延时时间*/
			laborUnlockStartCycNum = GetlaborUnlockStartCycNum(overlapId);
			laborUnlockStopTimeState = SystemOverTimeCheck(laborUnlockStartCycNum, laborUnlockOverlapTimeCount);
			if (CI_TIME_OUT == laborUnlockStopTimeState)
			{
				rtVal = CI_SUCCESS;
			}
			else
			{
				/*修复缺陷YF0083-1554，根据最短时间解锁*/
				cTimeCheckFlag = SystemOverTimeCheck(dwOverlapUnlockStartCyc, dwOverlapUnlockCount);

				if (CI_TIME_OUT == cTimeCheckFlag)
				{
					rtVal = CI_SUCCESS;  /*自动解锁时间超时，返回1成功*/
				}
				else
				{
					rtVal = CI_ERROR;
				}
			}
		}
		else
		{
			rtVal = CI_ERROR;
		}
	}
	else
	{
		/*入参非法，返回0失败*/
	}

	return rtVal;
}
/*
* 功能描述： 计算保护区段解锁倒计时开始周期
* 参数说明： const UINT16 overlapId, 保护区段ID
*            const UINT16 phySecId  进路最后物理区段ID
* 返回值  ： 倒计时
*/
UINT32 CalculaOverlapUnlockStartCycNum(const UINT16 overlapId,const UINT16 phySecId)
{

	UINT32 rtVal = 0u;
	UINT8 atsOrlaborLockCmdFlag = 0u;
	UINT32 OverlaplockSucessStartCycNum = 0u;
	UINT32 phyOccuStartCycNum = 0u;



	atsOrlaborLockCmdFlag = GetOverlapAtsOrlaborLockCmdFlag(overlapId);
	OverlaplockSucessStartCycNum = GetOverlaplockSucessStartCycNum(overlapId);
	phyOccuStartCycNum = GetSecUtOrCtOccuStartCycNum(phySecId);
	if(LOCK_OVERLAP_CMD_YES == atsOrlaborLockCmdFlag)/*站台轨占用的情况下，有人工锁闭或ATS锁闭保护区段命令存在*/
	{
		if((0u <OverlaplockSucessStartCycNum)&&(0u < phyOccuStartCycNum))
		{
			if(phyOccuStartCycNum >OverlaplockSucessStartCycNum)/*之前锁闭的保护区段，现在占用的进路最后一个区段*/
			{
				rtVal = phyOccuStartCycNum;/*用占用起始周期*/
			}
			else
			{  /*之前占用的进路最后一个区段，现在锁闭保护区段*/
				rtVal = OverlaplockSucessStartCycNum;/*用锁闭起始起始周期*/
			}
		}
		else
		{
			rtVal = phyOccuStartCycNum;/*最不利情况，以占用起始周期为起始周期*/
		}	
	}
	else
	{
		rtVal = phyOccuStartCycNum;
	}

	(void)SetOverlapUnlockStartCycNum(overlapId,rtVal);/*此变量未使用，在此利用。设置保护区段起始周期号，方便问题分析*/

	return rtVal;
}

/* C81_办理部分路径锁闭列车进路 */
/*
* 功能描述： 办理部分路径锁闭列车进路
* 参数说明： UINT16 const routeId   进路编号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_HALF_ROUTE_LOGIC
*/
UINT8 SetHalfTrainRouteLogicProcess(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_SET_HALF_ROUTE_LOGIC;

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

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

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

	/* 进路类型是【列车进路】【折返进路】*/
	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)
	{
		/* 进路状态为【进路空闲】或【进路部分锁闭解锁】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_IDLE == devState) 
			|| (ROUTE_STATE_HALF_UNLOCK == devState)
			|| (ROUTE_STATE_AUTO_UNLOCK == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}



	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetHalfRouteSectionCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = SetRouteHalfSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/* 返回成功 */
	return reResult;
}

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

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

	UINT8 CiFunctionJLock = 0u;			/*是否检查跳跃锁闭标志*/



	/* 进路内设备数据 */

	/* 联锁逻辑检查 */
	/* 进路内所有区段未被封锁 */
	devId = 0u;
	devState = 0u;
	checkResult = RouteHalfSecFLockCheck(routeId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/*cgh-合并CID-2539-1：根据物理区段封锁类型设置errorcode*/
		AccToPhySecFlockTypeSetErrcode(devId, functionId, sendLevel, devState);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/* 进路内所有区段锁闭状态【未锁闭】或
	方向相同的【防护锁闭】或
	(方向相同的【正常锁闭】或 方向相同的【延时锁闭】且锁闭进路为【列车进路】故障锁闭且ARB且方向一致)
	*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		
		checkResult = RouteHalfSecLockCheck(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)
	{/*cgh-合并CID-2349-1：*/
		devId = 0u;
		devState = 0u;
		CiFunctionJLock = GetCiFunctionSwitchConfig(FUNC_CBTC_CHECK_JUMPLOCK_FLAG);
		if (FUNC_SWITCH_OFF == CiFunctionJLock)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			checkResult = RouteHalfSecJumpLockStateCheck(routeId, &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 RouteId,    进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 SetRouteHalfSwitchCheck(UINT16 routeId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 cYLockAlarmFlag = FLAG_UNSET;  /*引导总锁报警标志*/
	UINT8 chConnetCheckFunc = 0U;

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

	/*进路内所有道岔【未封锁】 未引导总锁*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteHalfSwitchFLockCheck(routeId, &devId, &devState, &cYLockAlarmFlag);
	if (CI_SUCCESS == checkResult)
	{
		/* 通过检查 */
		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 = RouteHalfProSwitchFLockCheck(routeId, &devId, &devState, &cYLockAlarmFlag);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			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;
		checkResult = RouteHalfLtrlDfncSwitchCheck(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 = RouteHalfContactLineDevCheck(routeId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	if (CI_SUCCESS == reResult)
	{

		/*进路内所有道岔位置正确或位置不正确但可动作*/
		devId = 0u;
		devState = 0u;

		checkResult = RouteHalfSwitchMoveValidCheck(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 = RouteHalfProSwitchMoveValCheck(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;
		}

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

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

/* C82_锁闭进路部分路径处理 */
/*
* 功能描述： 锁闭CBTC列车进路
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_LOCK_CBTC_T_ROUTE
*/
UINT8 LockRouteHalfLogicProcess(UINT16 const routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LOCK_HALF_ROUTE_LOGIC;

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

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

										 /*故障发送级别*/
	UINT8 sendLevel = ESEND_LEVEL_ATS;		/*不发送ATS*/
	UINT16 devId = 0u;                   /*设备ID*/


	/* 联锁逻辑检查 */


	
	/* 进路类型是【列车进路】【折返进路】*/
	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)
	{
		/* 进路状态为【部分进路选排】【部分进路解锁】【自动解锁】【空闲】*/
		devState = GetRouteState(routeId);
		if ((ROUTE_STATE_HALF_XUANPAI == devState)
			|| (ROUTE_STATE_HALF_UNLOCK == devState)
			||(ROUTE_STATE_IDLE == devState)
			|| (ROUTE_STATE_AUTO_UNLOCK == devState))
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*照查联锁条件正确*/

		checkResult = RouteRelayZhaoChaCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 区段联锁条件检查 */
		checkResult = SetHalfRouteSectionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*分段进路联锁条件检查*/
		checkResult = RouteFenDuanConditionCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	if (CI_SUCCESS == reResult)
	{
		/* 道岔联锁条件检查 */
		checkResult = LockRouteHalfSwitchCheck(routeId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;

		}
	}

	if (CI_SUCCESS == reResult)
	{
		/*侵限区段侵限条件不满足检查*/
		checkResult =RouteHalfIntruSecCheck(routeId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 选排之前不再检查侵限，检查失败后直接发送给ATS*/
			SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_INTRU_OCU_STATE, devState, ESEND_LEVEL_ATS);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	
	if (CI_SUCCESS == reResult)
	{
		/*防淹门联锁条件检查*/
		checkResult = CBTCRouteFloodGateCheck(routeId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}

	
	/* 返回成功 */
	return reResult;
}

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

	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT32 dwXuanPaiStartCycNum = 0U;/*进路选排起始周期*/
	UINT32 dwRouteXuanPaiCount = 0U;/*进路选排超限周期数*/
	UINT8 chRouteTimeState = 0U;
	UINT8 cYLockAlarmFlag = FLAG_UNSET;  /*引导总锁报警标志*/
	UINT8 chConnetCheckFunc = 0U;

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

	dwXuanPaiStartCycNum = GetRouteXuanPaiStartCycNum(routeId);
	dwRouteXuanPaiCount = GetSystemParaRouteXuanPaiCyc();
	chRouteTimeState = SystemOverTimeCheck(dwXuanPaiStartCycNum, dwRouteXuanPaiCount);
	/*进路内所有道岔【未封锁】 未引导总锁*/
	devId = 0u;
	devState = 0u;
	checkResult = RouteHalfSwitchFLockCheck(routeId, &devId, &devState, &cYLockAlarmFlag);
	if (CI_SUCCESS == checkResult)
	{
		/* 通过检查 */
		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 = RouteHalfProSwitchFLockCheck(routeId, &devId, &devState, &cYLockAlarmFlag);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			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)
	{
		/*进路锁闭时间超时检查*/
		/*判断为CI_TIME_IN时会存在普通进路转引导时此处超时(因为选排时间为0)*/
		if (CI_TIME_OUT == chRouteTimeState)
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_XUANPAI_OVERTIME, chRouteTimeState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;

		}
		else
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
	}
	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = RouteHalfLtrlDfncSwitchCheck(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 = RouteHalfContactLineDevCheck(routeId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	if (CI_SUCCESS == reResult)
	{

		/*进路内所有道岔位置正确或位置不正确但可动作*/
		devId = 0u;
		devState = 0u;

		checkResult = RouteHalfSwitchMoveValidCheck(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 = RouteHalfProSwitchMoveValCheck(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;
		}
	}
	else
	{
		reResult = CI_ERROR;
	}

	
	if (CI_SUCCESS == reResult)
	{
		
		/*
		进路内所有道岔位置正确
		不正确：RETURN_LOCK_ERR_SWITPOS
		正确：CI_SUCCESS
		*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteHalfSwitchPosCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

		}
	}
	if (CI_SUCCESS == reResult)
	{

		/*
		进路内所有防护道岔位置正确
		不正确：RETURN_LOCK_ERR_SWITPOS
		正确：CI_SUCCESS
		*/
		devId = 0u;
		devState = 0u;
		checkResult = RouteHalfProSwitchPosCheck(routeId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

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

/*
* 功能描述：获取最接近进路保护区段的VBTC列车
* 输入参数：UINT16 const routeId 保护区段锁闭所属进路ID
* 输出参数：UINT16* pTrainId 最接近保护区段的列车ID
* 返回值  ：CI_SUCCESS 获取成功
*           CI_ERROR 获取失败
*/
UINT8 GetNearstVBTCTrainToOverlap(UINT16 const routeId, UINT16* pTrainId)
{
	UINT16 wTempTrainId = 0U;
	UINT16 wEndSignalId = 0U;  /*保护区段锁闭所属进路的终端信号机ID*/
	UINT8 cTrainLevel = 0U;
	UINT8 retVal = CI_ERROR;

	if ((0U != routeId) && (ROUTE_SUM_MAX > routeId) && (NULL != pTrainId))
	{
		wEndSignalId = GetRouteEndSignalId(routeId);  /*获取进路终端信号机*/
		wTempTrainId = GetSignalLightUpTrainId(wEndSignalId);  /*获取终端信号机的点灯列车ID*/
		cTrainLevel = GetTrainLevel(wTempTrainId);

		if (TRAIN_LEVEL_VBTC == cTrainLevel)
		{
			*pTrainId = wTempTrainId;
			retVal = CI_SUCCESS;
		}
		else
		{
			/*返回失败*/
		}
	}
	else
	{
		/*返回失败*/
	}

	return retVal;
}

/*
* 功能描述： 部分进路区段征用检查
* 参数说明： const UINT16 routeId   部分进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CHECK_HALFROUTE_USEING
*/
UINT8 HalfRoutePhySecUseLogicProcess(const UINT16 routeId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_CHECK_HALFROUTE_USEING;

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

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

	UINT8 sendLevel = 0u;		/*发送ATS*/


	sendLevel = ESEND_LEVEL_ATS;


	/*联锁条件检查*/

	/* 部分进路全部区段 = 【未征用】*/
	devId = 0u;
	devState = 0u;
	checkResult = HalfRouteAllSecUseVainCheck(routeId, &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;

	}

	return reResult;
}

/*
* 功能描述：其它控区保护区段的防护道岔征用申请处理
* 参数说明：const UINT16 wSwitchId 道岔ID
*           const UINT16 wOverlapId 保护区段ID
* 返 回 值：无
* Created By LQ 2024.12.04
*/
void OtherCiOlpProSwUseApplyPro(const UINT16 wSwitchId, const UINT16 wOverlapId)
{
	UINT16 wSwitchIndex = 0U;
	UINT16 wOverlapIndex = 0U;
	UINT8 cLocalCiId = 0U;  /*本地联锁ID*/
	UINT8 cOverlapBelongCiId = 0U;  /*保护区段所属联锁ID*/
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属联锁ID*/
	UINT16 wProSwitchPhySecId = 0U;  /*防护道岔物理区段ID*/
	UINT8 cPhySecUsingState = 0U;  /*防护道岔物理区段征用状态*/
	UINT16 wPhySecUsingRouteId = 0U;  /*防护道岔物理区段进路征用所属进路ID*/
	UINT16 wPhySecProUsingRouteId = 0U;  /*防护道岔物理区段防护征用所属进路ID*/
	UINT16 wUsingBelongOverlapId = 0U;  /*道岔征用所属保护区段ID*/
	UINT8 cCheckFlag = CI_ERROR;
	UINT8 cProSwitchPos = 0U;  /*防护道岔防护位置*/
	UINT8 cSwitchUsingState = 0U;  /*防护道岔征用状态*/

	wSwitchIndex = GetSwitchConfigBufIndex(wSwitchId);
	wOverlapIndex = GetOverlapConfigBufIndex(wOverlapId);	

	if ((SWITCH_SUM_MAX > wSwitchIndex) && (OVERLAP_SUM_MAX > wOverlapIndex))
	{
		cLocalCiId = GetSystemParaLocalCiId();
		cSwitchBelongCiId = GetSwitchBelongCiId(wSwitchId);
		cOverlapBelongCiId = GetOverlapBelongCiId(wOverlapId);
		if ((0U != cLocalCiId) && (cLocalCiId == cSwitchBelongCiId) && (0U != cOverlapBelongCiId) && (cLocalCiId != cOverlapBelongCiId))
		{
			cCheckFlag = CI_SUCCESS;

			/****** 1.检查防护道岔所属物理区段是否被进路征用 ******/
			wProSwitchPhySecId = GetSwitchPhySectionId(wSwitchId);  /*获取防护道岔所属物理区段ID*/
			cPhySecUsingState = GetPhySecUseState(wProSwitchPhySecId);  /*获取防护道岔所属物理区段征用状态*/

			if (PHYSICAL_SECTION_USING_NO == cPhySecUsingState)
			{
				/*检查通过*/
			}
			else
			{
				cProSwitchPos = GetOverlapProSwitchPos(wOverlapId, wSwitchId);  /*获取防护道岔的防护位置*/
				wPhySecUsingRouteId = GetPhySecUseRouteId(wProSwitchPhySecId);  /*获取防护道岔物理区段征用的进路*/
				wPhySecProUsingRouteId = GetPhySecProtectUseRouteId(wProSwitchPhySecId);  /*获取防护道岔物理区段防护征用的进路*/

				if ((CI_ERROR != cProSwitchPos) && ((0U < wPhySecUsingRouteId) || (0U < wPhySecProUsingRouteId)))
				{
					cCheckFlag = CheckPhyUseSecCanOtherUse(wSwitchId, cProSwitchPos);  /*检查进路征用道岔位置是否一致*/
				}
				else
				{
					cCheckFlag = CI_ERROR;
				}
			}

			/****** 2.检查防护道岔是否被其它保护区段征用 ******/
			if (CI_SUCCESS == cCheckFlag)
			{
				cSwitchUsingState = GetSwitchUsingState(wSwitchId);  /*获取防护道岔征用状态*/
				wUsingBelongOverlapId = GetSwitchBelongOverlapId(wSwitchId);  /*获取防护道岔征用所属的保护区段ID*/
				if (((SWITCH_USING_NO == cSwitchUsingState) && (0U == wUsingBelongOverlapId))
					|| ((SWITCH_USING_YES == cSwitchUsingState) && (wUsingBelongOverlapId == wOverlapId)))
				{
					/*检查通过*/
				}
				else
				{
					cCheckFlag = CI_ERROR;  /*防护道岔被其它保护区段征用，失败*/
				}
			}
			else
			{
				/*防护道岔区段征用检查失败，不处理*/
			}

			if (CI_SUCCESS == cCheckFlag)
			{
				SetSwitchUsingState(wSwitchId, SWITCH_USING_YES, wOverlapId);  /*设置防护道岔的被该保护区段征用*/
			}
			else
			{
				AddCiSendToCiCmdInfo(CI_CMD_OLP_PROSWT_USE_FAILURE, wSwitchId, wOverlapId, cOverlapBelongCiId);  /*征用申请检查失败，添加失败反馈命令*/
			}
		}
		else
		{
			/*非本控区道岔或本控区保护区段，不处理*/
		}
	}
	else
	{
		/*道岔/保护区段ID非法，不处理*/
	}
}

/*
* 功能描述：其它控区保护区段的防护道岔征用取消处理
* 参数说明：const UINT16 wSwitchId 道岔ID
*           const UINT16 wOverlapId 保护区段ID
* 返 回 值：无
* Created By LQ 2024.12.04
*/
void OtherCiOlpProSwUseCancelPro(const UINT16 wSwitchId, const UINT16 wOverlapId)
{
	UINT16 wSwitchIndex = 0U;
	UINT16 wOverlapIndex = 0U;
	UINT8 cLocalCiId = 0U;  /*本地联锁ID*/
	UINT8 cOverlapBelongCiId = 0U;  /*保护区段所属联锁ID*/
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属联锁ID*/
	UINT16 wUsingBelongOverlapId = 0U;  /*道岔征用所属保护区段ID*/
	UINT8 cSwitchUsingState = 0U;  /*防护道岔征用状态*/

	wSwitchIndex = GetSwitchConfigBufIndex(wSwitchId);
	wOverlapIndex = GetOverlapConfigBufIndex(wOverlapId);

	if ((SWITCH_SUM_MAX > wSwitchIndex) && (OVERLAP_SUM_MAX > wOverlapIndex))
	{
		cLocalCiId = GetSystemParaLocalCiId();
		cSwitchBelongCiId = GetSwitchBelongCiId(wSwitchId);
		cOverlapBelongCiId = GetOverlapBelongCiId(wOverlapId);
		if ((0U != cLocalCiId) && (cLocalCiId == cSwitchBelongCiId) && (0U != cOverlapBelongCiId) && (cLocalCiId != cOverlapBelongCiId))
		{
			cSwitchUsingState = GetSwitchUsingState(wSwitchId);  /*获取防护道岔征用状态*/
			wUsingBelongOverlapId = GetSwitchBelongOverlapId(wSwitchId);  /*获取防护道岔征用所属的保护区段ID*/
			if ((SWITCH_USING_YES == cSwitchUsingState) && (wUsingBelongOverlapId == wOverlapId))
			{
				SetSwitchUsingState(wSwitchId, SWITCH_USING_NO, wOverlapId);  /*防护道岔被此保护区段征用，清除征用所属保护区段*/
			}
			else
			{
				AddCiSendToCiCmdInfo(CI_CMD_OLP_PROSWT_USE_FAILURE, wSwitchId, wOverlapId, cOverlapBelongCiId);  /*征用取消检查失败，添加失败反馈命令*/
			}
		}
		else
		{
			/*非本控区道岔或本控区保护区段，不处理*/
		}
	}
	else
	{
		/*保护区段ID非法，不处理*/
	}
}
/*
* 功能描述：列车释放解锁逻辑区段三点检查
* 参数说明：const UINT16 wRouteId 进路id
*           const UINT16 wUnlockLgcSecId 待解锁区段ID
* 返 回 值：无
* Created By fan 2025.03.10
*/
UINT8 RouteLgcSecResUnlockNextSecCheck(const UINT16 wRouteId, const UINT16 wUnlockLgcSecId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 chRouteType = 0U; /*进路类型*/
	UINT8 chRouteState = 0U; /*进路状态*/
	UINT16 wLogBelongPhy = 0U; /*待解锁区段所属物理区段*/
	UINT16 wValidReturnSigId = 0U; /*折返信号机*/
	UINT16 wReturnSecId = 0U; /*折返区段id*/
	UINT16 wNextLogId = 0U; /*下一个逻辑区段id*/
	UINT8 chNextLogSecOccupy = 0U; /*下一逻辑区段占用状态*/							 
	UINT16 wNextPhyId = 0U; /*待检查下一物理区段id*/
	UINT8 chNextPhyState = 0U; /*下一物理区段状态*/

	wLogBelongPhy = GetLgcSecRelativePhySecId(wUnlockLgcSecId);/*获取对应物理区段*/
	chRouteType = GetRouteType(wRouteId);
	chRouteState = GetRouteState(wRouteId); /*进路状态*/

	if ((0U != chRouteState) && (0U != wLogBelongPhy))
	{
		wNextLogId = GetRouteNextLogSecId(wRouteId, wUnlockLgcSecId);

		/*获取进路信息*/
		wValidReturnSigId = GetValidReturnSinalId(wRouteId, wLogBelongPhy);
		wReturnSecId = GetSignalOutFirstPhySecId(wValidReturnSigId);
	
		if (ROUTE_STATE_HALF_UNLOCK == chRouteState)
		{
			/*任意位置折返后 等待解锁进路收到释放即解锁逻辑区段*/
			chRetVal = CI_SUCCESS;
		}
		else
		{
			if ((ROUTE_TYPE_RETURN == chRouteType) && (wLogBelongPhy == wReturnSecId))
			{
				chRetVal = RouteLgcSecResReturnSecCheck(wValidReturnSigId, wRouteId);
			}
			else if ((ROUTE_TYPE_RETURN != chRouteType) && (0U < wValidReturnSigId) && (wLogBelongPhy == wReturnSecId))
			{
				/*检查下一物理区段占用 或折出进路状态正确*/
				wNextPhyId = GetRouteNextPhySecId(wRouteId, wLogBelongPhy);
				chNextPhyState = GetPhySecCurMergeState(wNextPhyId);
				if (SECTION_OCCUPY_YES == chNextPhyState)
				{
					chRetVal = CI_SUCCESS;
				}
				else
				{
					/*通过转折返 检查折出区段*/
					chRetVal = RouteLgcSecResReturnSecCheck(wValidReturnSigId, wRouteId);
				}
			}
			else
			{
				wNextLogId = GetRouteNextLogSecId(wRouteId, wUnlockLgcSecId);
				if (0u != wNextLogId)
				{
					/*和待解锁区段相等，说明是进路的最后一个逻辑区段*/
					if (wNextLogId == wUnlockLgcSecId)
					{
						/*获取进路的离去区段*/
						wNextPhyId = GetRouteLeavePhySecId(wRouteId);
						chNextPhyState = GetPhySecCurMergeState(wNextPhyId);
						if (SECTION_OCCUPY_YES == chNextPhyState)
						{
							chRetVal = CI_SUCCESS;
						}
						else
						{
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*检查下一区段占用状态*/
						chNextLogSecOccupy = GetLogSecCurOccupyState(wNextLogId);
						if (SECTION_OCCUPY_YES == chNextLogSecOccupy)
						{
							chRetVal = CI_SUCCESS;
						}
						else
						{
							chRetVal = CI_ERROR;
						}
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
		}
	}
	else
	{
		/*进路ID或带解锁区段ID非法*/
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}


/*
* 功能描述：列车释放解锁折返区段三点检查
* 参数说明：const UINT16 wValidReturnSigId 折返信号机
*           const UINT16 wRouteId 折入进路ID
* 返 回 值：无
* Created By fan 2025.03.10
*/
UINT8 RouteLgcSecResReturnSecCheck(UINT16 wValidReturnSigId, const UINT16 wRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wPhySecRLockId = 0U;  /*物理区段锁闭所属进路*/
	UINT8 chBackRouteState = 0U;/*折出进路状态*/
	UINT32 dwUnlockRouteStartCyc = 0U; /*待解锁进路锁闭时间*/
	UINT32 dwBackRouteLockTime = 0U; /*折出进路锁闭时间*/
	UINT16 wNextPhyId = 0U; /*待检查下一物理区段id*/
	UINT8 chNextPhyState = 0U; /*下一物理区段状态*/
	UINT8 chErrorLog = 0U;
	if ((0U != wValidReturnSigId)&&(0U != wRouteId))
	{
		/*检查折返信号机内方区段*/
		wNextPhyId = GetSignalInFirstLockedPhySecId(wValidReturnSigId); /*获取信号机内方区段*/
		chNextPhyState = GetPhySecCurMergeState(wNextPhyId);
		wPhySecRLockId = GetPhySecRLockBelongRouteId(wNextPhyId);  /*物理区段锁闭所属进路*/
		chBackRouteState = GetRouteState(wPhySecRLockId);/*折出进路状态*/
		dwUnlockRouteStartCyc = GetRouteLockStartCycNum(wRouteId);
		dwBackRouteLockTime = GetRouteLockStartCycNum(wPhySecRLockId);

		chErrorLog++;
		/*检查折出进路状态*/
		if (SECTION_OCCUPY_YES == chNextPhyState)
		{
			chErrorLog++;
			/*折返进路锁闭时间早于折出进路 且 折出进路状态为【接近锁闭正常】*/
			if ((((INT32)(dwUnlockRouteStartCyc - dwBackRouteLockTime)) > 0U)
				&& (ROUTE_STATE_NEAR_LOCK == chBackRouteState))
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				/*折返异常*/
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	if (CI_ERROR == chRetVal)
	{
		debug_infor_printf((const)"Return_Sec RouteLgcSecResReturnSecCheck Fail %d Step\n", chErrorLog);
	}
	return chRetVal;
}