#include "LogicalRouteDataManage.h"
#include "PhysicalSectionDataManage.h"
#include "InterlockCommonManage.h"
#include "LogicalRouteLogicCheck.h"
#include "InterlockLogicCheck.h"

/**
* @brief 逻辑进路办理条件检查
* @param  wLogRouteId 逻辑进路ID
* @return CI_SUCCESS，检查通过  CI_ERROR，检查不通过
* @note：
*/
UINT8 SetLogRouteCheckProcess(UINT16 const logRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_SetLogRouteCheckProcess;

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 devState = 0u;                 /*设备状态*/


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

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

	}

	/*照查联锁条件正确(预留)*/


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

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

	/*防淹门联锁条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLogRouteFloodGateCheck(logRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		;	/*不处理*/
	}

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

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

	/*道岔关联区段锁闭条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogRouteSwitchRelaySecCheck(logRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	else
	{
		; /*不处理*/
	}


	/* 返回成功 */
	return reResult;
}
/**
* @brief 逻辑进路锁闭条件检查
* @param  wLogRouteId 逻辑进路ID
* @return 1，检查通过  0，检查不通过
* @note：
*/
UINT8 LockLogRouteCheckProcess(UINT16 const logRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LockLogRouteCheckProcess;

	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 devState = 0u;                 /*设备状态*/


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

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

	}


	/* 照查联锁条件正确(预留) */


	/* 逻辑进路区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogRouteSectionCheck(logRouteId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

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

	/*防淹门联锁条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLogRouteFloodGateCheck(logRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		;	/*不处理*/
	}
	/* 道岔关联区段锁闭条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogRouteSwitchRelaySecCheck(logRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;
		}
	}
	/* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = LockLogRouteSwitchCheck(logRouteId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = checkResult;

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

	/*侵限条件检查*/
	if (CI_SUCCESS == reResult)
	{
		checkResult = LogRouteIntruSecCheck(logRouteId, functionId, sendLevel);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;

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

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


/**
* @brief 逻辑进路关联的物理区段封锁检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRoutePhySecFengSuoCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 devId = 0U; /*关联物理区段ID*/
	UINT8 devState = 0U;
	UINT8 retval = CI_ERROR;

	LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(logRouteId);
	if ((NULL != LogSecIdBuff) && (0U != logSecSum) && (NULL!= pDevId) && (NULL != pDevState))
	{
		retval = CI_SUCCESS;
		for (ii = 0U; ii < logSecSum; ii++)
		{
			devId = GetLgcSecRelativePhySecId(LogSecIdBuff[ii]);
			devState = GetPhySecFLockState(devId);

			/* 状态如果不是未封锁状态，则认为检查失败 */
			if (PHYSICAL_SECTION_FLOCK_NO != devState )
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				retval = CI_ERROR;
				break;
			}
			else
			{
				/*继续检查*/
			}
		}
	}
	else
	{
		/*返回失败*/
	}
	return retval;
}


/**
* @brief 逻辑进路逻辑区段锁闭检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRouteSectionLockCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 devId = 0U; /*逻辑区段ID*/
	UINT8 devState = 0U;  /*逻辑区段锁闭状态*/

	UINT8 retVal = CI_ERROR;
	UINT8 funcRet = CI_ERROR;
	UINT8 routeDirection = 0U;
	UINT8 secLockDirection = 0U;
	UINT16 protectLockedId = 0U;

	LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(logRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum) && (NULL != pDevId) && (NULL != pDevState))
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		routeDirection = GetLogicalRouteDir(logRouteId);
		for (ii = 0u; ii < logSecSum; ii++)
		{
			devId = LogSecIdBuff[ii];
			devState = GetLogSecLockState(devId); /*逻辑进路锁闭状态*/

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

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

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

			}
			else if ((LOG_SECTION_LOCK_NORMAL == devState) || (LOG_SECTION_LOCK_DELAY == devState))
			{
				/* 区段【正常锁闭】或 【延时锁闭】 */
				secLockDirection = GetLogSecLockDir(devId);
				protectLockedId = GetLogSecPLockRouteId(devId);
				/*获取指定ID逻辑进路列车脚下资源包含该逻辑区段*/
				funcRet = CheckLgcSecHaveTrainLocRoute(logRouteId, devId);

				/*方向不一致*/
				if ((CI_SUCCESS == funcRet) && (0U == protectLockedId))
				{
					/*列车脚下区段从头开始遍历, 记录时，从列车大前到小后的逻辑区段*/
				}
				else
				{/*检查不通过*/
					*pDevId = devId;
					*pDevState = devState;
					retVal = CI_ERROR;
				}
			}
			else
			{
				/*锁闭状态不满足*/  /*异常锁闭无法办理*/
				*pDevId = devId;
				*pDevState = devState;
				retVal = CI_ERROR;
			}
			if (CI_ERROR == retVal)
			{
				break;
			}
			else
			{
				/*继续循环*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 逻辑区段被逻辑进路锁闭条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRouteLockBylogRouteCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT8 logRouteNum = 0U;   /*逻辑区段上存在的逻辑进路数量*/
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 devId = 0U;     /*逻辑区段ID*/
	UINT8 devState = 0U;  /*逻辑区段被逻辑进路锁闭状态*/
	UINT8 logSecLockDir = 0U;  /*逻辑区段被逻辑进路锁闭方向,只能锁闭在同一方向上*/
	UINT8 logRoutDirection = 0U;  /*逻辑进路方向*/
	UINT8 retVal = CI_ERROR;
	UINT8 funcRet = CI_ERROR;
	UINT16 protectLockedId = 0U;
	

	LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(logRouteId);
	logRoutDirection = GetLogicalRouteDir(logRouteId);
	if ((NULL != LogSecIdBuff) && (0U != logSecSum))
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		for ( ii = 0; ii < logSecSum; ii++)
		{
			devId = LogSecIdBuff[ii];
			devState = GetLogSecLogLockState(devId);
			logRouteNum = GetLogSecLockBelLogRouteSum(devId);
			logSecLockDir = GetLogSecLogLockDir(devId);
			funcRet = CheckLgcSecHaveTrainLocRoute(logRouteId, devId);
			protectLockedId = GetLogSecPLockRouteId(devId);

			/*逻辑区段异常锁闭*/
			if (LOG_SECTION_LOGLOCK_EXCEPT == devState)
			{
				retVal = CI_ERROR;
			}
			else if (LOG_SECTION_LOGLOCK_NORMAL == devState)
			{
				if ((logRoutDirection == logSecLockDir) && ((CI_SYSTEM_DIRECTION_UP == logRoutDirection) || (CI_SYSTEM_DIRECTION_DOWN == logRoutDirection)))
				{
					/*逻辑区段被逻辑进路锁闭,锁闭方向与本进路一致 检查通过*/
				}
				else if (((CI_SYSTEM_DIRECTION_UP == logRoutDirection) && (CI_SYSTEM_DIRECTION_DOWN == logSecLockDir))
					|| ((CI_SYSTEM_DIRECTION_DOWN == logRoutDirection) && (CI_SYSTEM_DIRECTION_UP == logSecLockDir)))
				{
					/*方向不一致*/
					if ((CI_SUCCESS == funcRet) && (0U == protectLockedId))
					{
						;  /*当车脚下的逻辑进路锁闭的逻辑区段，且此区段没被保护区段锁闭，则可以办理逻辑进路*/
					}
					else
					{
						retVal = CI_ERROR;
					}
				}
				else
				{
					retVal = CI_ERROR;  /*方向不合法，返回0失败*/
				}
			}
			else if (LOG_SECTION_LOGLOCK_NO == devState)
			{
				/*逻辑区段未被逻辑进路锁闭，检查通过*/
			}
			else
			{
				/*非法值，检查不通过*/
				retVal = CI_ERROR;
			}

			if (CI_ERROR == retVal)
			{
				/*检查不通过*/
				*pDevId = devId;
				*pDevState = devState;
				break;
			}
			
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 逻辑区段是否被引导进路锁闭条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRouteYDLockCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 wlogSecId = 0u;
	UINT16 devId = 0U;     /*逻辑区段锁闭所属进路ID*/
	UINT8 devState = 0U;  /*关联进路状态*/
	UINT8 retVal = CI_ERROR;

	LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(logRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum) && (NULL != pDevId) && (NULL != pDevState))
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		for (ii = 0; ii < logSecSum; ii++)
		{
			wlogSecId = LogSecIdBuff[ii];
			/*获取逻辑区段关联进路ID*/
			devId = GetLogSecLockBelongRoute(wlogSecId);
			/*存在锁闭所属进路*/
			if (0U != devId)
			{
				devState = GetRouteState(devId);
				if ((ROUTE_STATE_LEAD_LOCK == devState)
					|| (ROUTE_STATE_LEAD_LOCKERR == devState)
					|| (ROUTE_STATE_LEAD_OPEN == devState))
				{
					/*被引导进路锁闭*/
					*pDevId = devId;
					*pDevState = devState;
					retVal = CI_ERROR;
					break;
				}
				else
				{
					/*继续检查*/
				}
			}
			else
			{
				/*继续检查*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief  逻辑区段跳跃锁闭检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @note：
*/
UINT8 LogRouteJumpLockCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 wlogSecId = 0u;
	UINT16 devId = 0U;     /*逻辑区段关联物理区段ID*/
	UINT8 devState = 0U;  /*跳跃锁闭状态*/
	UINT8 retVal = CI_ERROR;
	LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(logRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum) && (NULL != pDevId) && (NULL != pDevState))
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		for (ii = 0; ii < logSecSum; ii++)
		{
			wlogSecId = LogSecIdBuff[ii];
			devId = GetLgcSecRelativePhySecId(LogSecIdBuff[ii]);
			devState = GetPhySecJumpLockState(devId);

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

	/*全部通过检查*/
	return retVal;
}
/**
* @brief 逻辑进路区段条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @note：
*/
UINT8 LogRouteSectionCheck(UINT16 logRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT8 reResult = CI_ERROR;          /*返回值*/

	/*逻辑进路关联的物理区段未封锁*/
	devId = 0u;
	devState = 0u;
	checkResult = LogRoutePhySecFengSuoCheck(logRouteId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/* 进路内所有区段锁闭状态【未锁闭】或
	   方向相同的【防护锁闭】或
	   区段为列车脚下区段且未防护锁闭
	*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;

		checkResult = LogRouteSectionLockCheck(logRouteId, &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 = LogRouteLockBylogRouteCheck(logRouteId, &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 = LogRouteYDLockCheck(logRouteId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_ROUTE, devId, ETYPE_ROUTE_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*逻辑区段未被跳跃锁闭*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;

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



/**
* @brief 办理逻辑进路道岔条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @note：
*/
UINT8 SetLogRouteSwitchCheck(UINT16 logRouteId, 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 = LogRouteSwitchFLockCheck(logRouteId, &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 = LogRouteProSwitchFLockCheck(logRouteId, &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;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteCeFangSwitchCheck(logRouteId, &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 = LogRouteContactLineDevSwitCheck(logRouteId, functionId, sendLevel);
			if (CI_SUCCESS == checkResult)
			{
				/* 通过检查 */
				reResult = CI_SUCCESS;
			}
			else
			{
				/* 失败返回 */
				reResult = CI_ERROR;
			}
		}
	}

	/*进路内所有道岔位置正确或位置不正确但可动作*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteSwitchMoveValidCheck(logRouteId, &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)
	{
		
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteProSwitchMoveValidCheck(logRouteId, &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;
}


/**
* @brief 锁闭逻辑进路道岔条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @note：
*/
UINT8 LockLogRouteSwitchCheck(UINT16 logRouteId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 cYLockAlarmFlag = FLAG_UNSET;  /*引导总锁报警标志*/
	UINT32 dwXuanPaiStartCycNum = 0U;/*逻辑进路选排起始周期*/
	UINT32 dwRouteXuanPaiCount = 0U;/*进路选排超限周期数*/
	UINT8 chRouteTimeState = 0U;    /*判断选排是否超时*/

	UINT8 chConnetCheckFunc = 0U;

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

	dwXuanPaiStartCycNum = GetLogRouteXuanPaiStartCycNum(logRouteId);  
	dwRouteXuanPaiCount = GetSystemParaRouteXuanPaiCyc();     
	chRouteTimeState = SystemOverTimeCheck(dwXuanPaiStartCycNum, dwRouteXuanPaiCount);

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

		}
		else
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
	}
	else
	{
		; /*不处理*/
	}

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteCeFangSwitchCheck(logRouteId, &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
	{
		; /*不处理*/
	}

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

	/*进路内所有道岔位置正确或位置不正确但可动作*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteSwitchMoveValidCheck(logRouteId, &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
	{
		; /*不处理*/
	}

	/*进路关联防护道岔位置正确或位置不正确但可动作*/
	if (CI_SUCCESS == reResult)
	{

		devId = 0u;
		devState = 0u;
		checkResult = LogRouteProSwitchMoveValidCheck(logRouteId, &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
	{
		; /*不处理*/
	}
	
	/*检查道岔位置是否正确*/
	if (CI_SUCCESS == reResult)
	{
		/*  进路内所有道岔位置正确 		正确：CI_SUCCESS   不正确待转动：RETURN_LOCK_ERR_SWITPOS*/
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteSwitchPosCheck(logRouteId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, ESEND_LEVEL_ZERO);
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

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

	/*检查防护道岔位置是否正确*/
	if (CI_SUCCESS == reResult)
	{
		/*  进路内所有防护道岔位置正确 		正确：CI_SUCCESS   不正确待转动：RETURN_LOCK_ERR_SWITPOS*/
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteProSwitchPosCheck(logRouteId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, ESEND_LEVEL_ZERO);
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

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

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

/**
* @brief 逻辑进路道岔封锁条件检查
* @param  UINT16 routeId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* @note：CI_ERROR  CI_SUCCESS
*/
UINT8 LogRouteSwitchFLockCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState, UINT8* pYLockAlarmFlag)
{
	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8 ret = CI_ERROR;
	
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRelSwitchFLockCheck(devId, pDevId, pDevState, pYLockAlarmFlag);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/

				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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

/*
* 功能描述： 逻辑进路防护道岔封锁条件检查
* 参数说明： UINT16 routeId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
*            UINT8* pYLockAlarmFlag  引导总锁报警标志（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteProSwitchFLockCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState, UINT8* pYLockAlarmFlag)
{
	
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8 ret = CI_ERROR;
	/* 进路区段*/
	UINT16  checkSum = 0U;
	UINT16* pDataIdBuf = NULL;
	checkSum = GetLogicalRouteInLogSecSum(routeId);
	pDataIdBuf= GetLogicalRouteInLogSecId(routeId);

	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRltvPrtctSwFLockCheck(devId, pDevId, pDevState, pYLockAlarmFlag);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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

/*
* 功能描述： 逻辑进路侧防条件满足检查
* 参数说明： UINT16 routeId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteCeFangSwitchCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const dataIdBuf = GetLogicalRouteInLogSecId(routeId);

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

	if ((0u == checkSum) || (NULL == pDevId) || (NULL == pDevState))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			reVal = LogicSecSwitchLtrlDfncCheck(devId, pDevId, pDevState);
			if (CI_SUCCESS == reVal)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 逻辑进路区段全部联络线设备条件满足检查
* 参数说明： UINT16 logRouteId,    逻辑进路ID号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteContactLineDevSwitCheck(UINT16 const logRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reVal = CI_ERROR;
	UINT16 LogSectionSum = 0U;
	UINT16 ii = 0U;
	UINT16 *pLogicSecId = NULL;

	/*逻辑区段联络线道岔条件满足*/
	LogSectionSum = GetLogicalRouteInLogSecSum(logRouteId);		/*获取逻辑进路包含的逻辑区段*/
	pLogicSecId = GetLogicalRouteInLogSecId(logRouteId);
	if (0u == LogSectionSum)
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (ii = 0U; ii < LogSectionSum; ii++)
		{
			reVal = LogicContactLineDevCheck(pLogicSecId[ii], functionId, sendLevel);
			if (reVal == CI_SUCCESS)
			{
				;		/*通过检查*/
			}
			else
			{
				reVal = CI_ERROR;
				break;
			}
		}
	}
	return reVal;
}

/*
* 功能描述： 逻辑进路防护道岔防护锁闭条件满足检查
* 参数说明： UINT16 routeId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteProtectLockSwitchCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const dataIdBuf = GetLogicalRouteInLogSecId(routeId);

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

	if ((0u == checkSum) || (NULL == pDevId) || (NULL == pDevState))
	{
		/*区段数据错误*/
		reVal = CI_ERROR;
	}
	else
	{
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			reVal = LogicSecRltvPrtctSwLockCheck(devId, pDevId, pDevState);
			if (CI_SUCCESS == reVal)
			{
				/* 通过检查*/
			}
			else
			{
				/*状态不一致返回故障状态*/
				reVal = CI_ERROR;
				break;
			}
		}
	}
	/*全部通过检查*/
	return reVal;
}

/*
* 功能描述： 逻辑进路道岔位置与是否可动条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteSwitchMoveValidCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 logRouteSwitchMoveFlag = 0U;

	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(routeId);
	
	
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		logRouteSwitchMoveFlag = GetLogicalRouteSwitchMoveFlag(routeId);
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSwitchMoveValidCheck(devId, logRouteSwitchMoveFlag, pDevId, pDevState, (UINT8)1U);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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

/*
* 功能描述： 逻辑进路防护道岔位置与是否可动条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteProSwitchMoveValidCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(routeId);

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8 ret = CI_ERROR;
	UINT8 logRouteSwitchMoveFlag = 0U;
	
	if (0U == checkSum)
	{
		/*区段数据错误*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		logRouteSwitchMoveFlag = GetLogicalRouteSwitchMoveFlag(routeId);
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicProSwitchMoveValidCheck(devId, logRouteSwitchMoveFlag, pDevId, pDevState, (UINT8)1U);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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


/**
* @brief 逻辑进路道岔关联区段锁闭条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @note：
*/
UINT8 LogRouteSwitchRelaySecCheck(UINT16 logRouteId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

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

	/*逻辑进路内道岔关联另一逻辑区段未锁闭*/
	devId = 0u;
	devState = 0u;
	checkResult = LogRouteSwOtherLogLockCheck(logRouteId, &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 (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteOutLogSecLockCheck(logRouteId, &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;
		}
	}
	else
	{
		/* 失败返回 */
		reResult = CI_ERROR;
	}
	/* 返回结果 */
	return reResult;
}



/*
* 功能描述： 逻辑进路内道岔关联另一逻辑区段锁闭检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteSwOtherLogLockCheck(UINT16 const logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16 checkOtherSum = 0U; /*逻辑区段数*/
	UINT16* dataOtherIdBuf = NULL;
	UINT16 i = 0U;  /* 循环变量 */
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT8  cLogicLockState = 0U;
	UINT8 reVal = CI_ERROR;
	UINT8 cLogicLockBelongRouteNum = 0U;

	checkOtherSum = GetLogRInSwitOtherPosLogSecSum(logRouteId);
	dataOtherIdBuf = GetLogRInSwitOtherPosLogSecID(logRouteId);

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

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

	return reVal;

}

/**
* @brief 逻辑进路内道岔关联物理区段的非进路内且非道岔关联的逻辑区段锁闭检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRouteOutLogSecLockCheck(UINT16 logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	/* 进路包含的物理区段内非进路内且非道岔关联的逻辑区段*/
	UINT16 checkSum = 0u; /*逻辑区段数*/
	UINT16* dataIdBuf = NULL;

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

	checkSum = GetLogicalRouteOutLogSecSum(logRouteId);
	dataIdBuf = GetLogicalRouteOutLogSecID(logRouteId);


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

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

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


/**
* @brief 逻辑进路侵限条件检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,      调用函数编号
*         UINT8 sendLevel,       故障码发送级别
* @return CI_ERROR  不通过
*         CI_SUCCESS  通过
* @note：by LC
*/
UINT8 LogRouteIntruSecCheck(UINT16 logRouteId, UINT8 functionId, UINT8 sendLevel)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;    /*逻辑区段ID*/
	UINT8  devState = 0u; /**/
	UINT8 reResult = CI_ERROR;
	UINT8 checkResult = CI_ERROR;
	/*进路内逻辑区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(logRouteId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(logRouteId);

	/* 区段占用检查 */
	if (0U == checkSum)
	{
		/*区段数据错误*/
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];
			/*逻辑区段侵限条件检查*/
			checkResult = LogicIntruSecVainCheck(devId, &devId, &devState);

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

		}
	}

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


/**
* @brief 检查逻辑进路征用是否成功
* @param  wLogRouteId 逻辑进路ID
*         UINT8 functionId,调用函数编号
*         UINT8 sendLevel,故障码发送级别
* @return CI_ERROR  不通过
*         CI_SUCCESS  通过
* @note：by LC
*/
UINT8 LogRouteUseStateCheck(UINT16 logRouteId)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 wPhySecId = 0u;    /*逻辑区段关联的物理区段ID*/

	UINT8 reResult = CI_ERROR;
	
	UINT16 wUsingRouteId = 0U;/*物理区段内被征用的逻辑进路ID*/
	UINT8 wUsingState = 0U;  /*物理区段征用状态*/


	/*进路内逻辑区段*/
	UINT16 const logSecSum = GetLogicalRouteInLogSecSum(logRouteId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(logRouteId);

	if (0U == logSecSum)
	{
		/*区段数据错误*/
		reResult = CI_ERROR;
	}
	else
	{
		reResult = CI_SUCCESS;
		/*遍历逻辑区段，开始检查*/
		for (i = 0u; i < logSecSum; i++)
		{
			wPhySecId = GetLgcSecRelativePhySecId(pDataIdBuf[i]);
			wUsingRouteId = GetPhySecUseLogRouteId(wPhySecId);
			wUsingState = GetPhySecUseState(wPhySecId);

			/*被逻辑区段征用状态：存在征用，且征用的逻辑进路为本逻辑进路*/
			if ((logRouteId == wUsingRouteId)&&(PHYSICAL_SECTION_USING_YES==wUsingState))
			{
				/*检查通过*/
			}
			else
			{
				reResult = CI_ERROR;
				break;
			}

		}

		if (CI_ERROR == reResult)
		{/*设置逻辑进路未征用*/
			SetLogRouteSectionUsingState(logRouteId, PHYSICAL_SECTION_USING_NO);
		}
	}

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

/*
* 功能描述： 锁闭逻辑进路道岔位置条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteSwitchPosCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{

	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;      /*逻辑区段ID*/
	UINT8 ret = CI_ERROR;

	/* 进路逻辑区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(routeId);

	if ((0U == checkSum) || (NULL == pDevId) || (NULL == pDevState))
	{
		/*区段数据错误或参数指针为空*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRelativeSwitchPosCheck(devId, pDevId, pDevState);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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

}

/*
* 功能描述： 锁闭逻辑进路防护道岔位置条件检查
* 参数说明： UINT16 routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteProSwitchPosCheck(UINT16 const routeId, UINT16* pDevId, UINT8* pDevState)
{
	
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8 ret = CI_ERROR;

	/* 进路区段*/
	UINT16 const checkSum = GetLogicalRouteInLogSecSum(routeId);
	UINT16* const pDataIdBuf = GetLogicalRouteInLogSecId(routeId);

	if ((0U== checkSum) || (NULL == pDevId) || (NULL == pDevState))
	{
		/*区段数据错误或参数指针为空*/
		ret = CI_ERROR;
	}
	else
	{
		ret = CI_SUCCESS;

		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = pDataIdBuf[i];

			ret = LogicSecRltvPrtctSwPosCheck(devId, pDevId, pDevState);

			/* 检查失败 */
			if (CI_SUCCESS != ret)
			{
				/*状态不一致返回故障状态*/
				ret = CI_ERROR;
				break;
			}
			else
			{
				/* 继续执行*/
			}

		}
	}

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

/* 逻辑进路信号保持区段联锁条件检查 */
/*
* 功能描述： 逻辑进路信号保持区段联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 KeepLogRouteSectionCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/

	/* 逻辑进路内所有区段未被封锁 */
	checkResult = LogRoutePhySecFengSuoCheck(wLogRouteId, &devId, &devState);
	if (CI_SUCCESS == checkResult)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_FLOCK_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;
	}

	 /*逻辑进路内所有区段锁闭状态【逻辑正常锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0U;
		devState = 0U;

		checkResult = LogNormalLockBylogRouteCheck(wLogRouteId, LOG_SECTION_LOGLOCK_NORMAL, &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
	{
		; /*不处理*/
	}

	/* 逻辑进路内所有区段锁闭状态非【异常锁闭】
	动态进路第一逻辑区段未被进路锁闭
	*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0U;
		devState = 0U;

		checkResult = LogRouteSectionExceptLockCheck(wLogRouteId, &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;
		}
	}
	else
	{
		; /*不处理*/
	}

	/*侵限区段侵限条件不满足检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0U;
		devState = 0U;
		checkResult = LogRouteIntruSecCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS== checkResult)
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			reResult = CI_ERROR;

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

	/* 进路内所有区段【未设置跳跃锁闭】*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0U;
		devState = 0U;
		checkResult = LogRouteJumpLockCheck(wLogRouteId, &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;
		/*CBTC进路内方第一逻辑区段条件检查*/
		checkResult = LogRouteFirstLgcSecCheck(wLogRouteId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
		{
			/*列车跨压，通过检查*/
			reResult = LOG_ROUTE_TRAIN_CROSS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_LOGICSEC, devId, ETYPE_LOGSEC_OCC_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	else
	{
		; /*不处理*/
	}
	return reResult;
}


/**
* @brief 逻辑区段被逻辑进路锁闭状态检查
* @param  UINT16 wLogRouteId 逻辑进路ID
*		  UINT8 checkState		需要检查的逻辑锁闭状态
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogNormalLockBylogRouteCheck(UINT16 wLogRouteId, UINT8 checkState,UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT8 logRoutDirection = 0U;  /*逻辑进路方向*/
	UINT8 retVal = CI_ERROR;
	UINT16 ii = 0U;
	UINT16 devId = 0U;     /*逻辑区段ID*/
	UINT8 devState = 0U;  /*逻辑区段被逻辑进路锁闭状态*/
	UINT8 logSecLockDir = 0U;  /*逻辑区段被逻辑进路锁闭方向,只能锁闭在同一方向上*/

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	logRoutDirection = GetLogicalRouteDir(wLogRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum))
	{
		retVal = CI_SUCCESS;

		/*开始检查*/
		for (ii = 0; ii < logSecSum; ii++)
		{
			devId = LogSecIdBuff[ii];
			devState = GetLogSecLogLockState(devId);

			if (devState == checkState)
			{
				if (LOG_SECTION_LOGLOCK_NO == checkState)
				{
					/*【未锁闭】不检查方向*/
					/* 通过检查*/
				}
				else
				{
					logSecLockDir = GetLogSecLogLockDir(devId);
					if (logRoutDirection == logSecLockDir)
					{
						/*逻辑区段未被逻辑进路锁闭或锁闭方向一致*/

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

/**
* @brief 逻辑进路逻辑区段异常锁闭以及第一逻辑区段未被进路锁闭检查
* @param  wLogRouteId 逻辑进路ID
*         UINT8 pDevId,设备ID
*          UINT8 pDevState,设备状态
* @note：
*/
UINT8 LogRouteSectionExceptLockCheck(UINT16 wLogRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT8 retVal = CI_ERROR;
	UINT16 ii = 0U;
	UINT16 devId = 0U; /*逻辑区段ID*/
	UINT8 devState = 0U;  /*逻辑区段锁闭状态*/

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum) && (NULL != pDevId) && (NULL!= pDevState))
	{
		retVal = CI_SUCCESS;
		/*开始检查*/
		devId = LogSecIdBuff[0];		/*动态第一逻辑区段，不能被进路锁闭*/
		devState = GetLogSecLockState(devId); /*逻辑进路锁闭状态*/
		if (LOG_SECTION_LOCK_NO != devState)
		{
			if (LOG_SECTION_LOCK_PROTECT == devState)		
			{
				;	/*防护锁闭可以开信号，返回成功*/
			}
			else
			{
				retVal = CI_ERROR;
			}
		}
		else
		{
			; /*不处理*/
		}
		if (CI_SUCCESS == retVal)
		{
			for (ii = 0u; ii < logSecSum; ii++)
			{
				devId = LogSecIdBuff[ii];
				devState = GetLogSecLockState(devId); /*逻辑进路锁闭状态，不能为异常锁闭*/

				if (LOG_SECTION_LOCK_EXCEPT == devState)
				{
					retVal = CI_ERROR;
					break;
				}
				else
				{
					; /*不处理*/
				}

				if (CI_SUCCESS == retVal)
				{
					devState = GetLogSecLogLockState(devId);		/*查逻辑区段逻辑锁闭区段故障*/
					if (LOG_SECTION_LOGLOCK_EXCEPT == devState)
					{
						retVal = CI_ERROR;
						break;
					}
					else
					{
						; /*不处理*/
					}
				}
				else
				{
					; /*不处理*/
				}
			}
		}
		else
		{
			; /*不处理*/
		}

		if (CI_ERROR == retVal)
		{
			*pDevId = devId;
			*pDevState = devState;			/*记录故障状态和设备ID*/
		}
		else
		{
			; /*不处理*/
		}
	}
	return retVal;
}
/*
* 功能描述： 逻辑进路第一逻辑区段检查
* 参数说明：
*            UINT16 const wLogRouteId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR   检查失败
*            CI_SUCCESS 检查通过
*/
UINT8 LogRouteFirstLgcSecCheck(UINT16 const wLogRouteId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT16 wLogRouteApplyResTrainId = 0U;
	UINT8  chTrainEnterState = 0U;
	UINT8 reResult = CI_ERROR;        /*返回值定义*/
	UINT16* LogSecIdBuff = NULL;
	UINT8 devState = 0u;                 /*第一逻辑区段融合占压状态*/

	/*检查列车是否跨压*/
	wLogRouteApplyResTrainId = GetLogicalRouteApplyResTrainId(wLogRouteId);
	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	devState = GetLogSecCurOccupyState(LogSecIdBuff[0U]);
	chTrainEnterState = dsuLogRouteTrainCrossSignal(wLogRouteApplyResTrainId, wLogRouteId);

	if ((NULL != pDevId) && (NULL != pDevState))
	{
		if (TRAIN_ENTER_ROUTE_FULL == chTrainEnterState)
		{
			/*列车完全驶入逻辑进路进路，关灯 by cgh 20231128*/
			reResult = LOG_ROUTE_TRAIN_CROSS;
		}
		else if (TRAIN_ENTER_ROUTE_HEAD == chTrainEnterState)
		{
			/*列车驶入逻辑进路但未跨压，不关灯*/
			reResult = CI_SUCCESS;
		}
		else if (TRAIN_ENTER_ROUTE_CROSS == chTrainEnterState)
		{
			/*列车跨压信号机，需判断第一逻辑区段占压状态*/

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

		if (CI_ERROR == reResult)
		{
			*pDevId = LogSecIdBuff[0U];
			*pDevState = devState;
		}
	}
	return reResult;
}

/**
* @brief 检查逻辑进路内部逻辑区段是否全部解锁
* @param  wLogRouteId 逻辑进路ID
* @return CI_ERROR  不通过
*         CI_SUCCESS  通过
* 创建:  fan 2023-10-11
*/
UINT8 LogRouteLogSecReleaseCheck(UINT16 logRouteId)
{
	/* 局部变量定义初始化 */
	UINT16 ii = 0u;           /* 循环变量 */
	UINT16 devId = 0u;    /*逻辑区段ID*/
	UINT8 reResult = CI_SUCCESS;
	UINT8 checkResult = CI_ERROR;
	/*进路内逻辑区段*/
	UINT16 routeLogNum = GetLogicalRouteInLogSecSum(logRouteId);
	UINT16* routeLogSecId = GetLogicalRouteInLogSecId(logRouteId);/*逻辑区段ID数组*/
	for (ii = 0u; ii < routeLogNum; ii++)
	{
		devId = routeLogSecId[ii];/*获取当前逻辑区段ID*/
											
		/*检查某个逻辑区段对该逻辑进路的解锁条件*/
		checkResult = CheckLogRouteIdBelLogSec(devId, logRouteId);
		if (0U == checkResult)
			/*未锁闭或者不关联该逻辑进路*/
		{
			reResult = CI_SUCCESS;
		}
		else
		{
			/*返回失败*/
			reResult = CI_ERROR;
			break;
		}
	}

	/*全部通过检查*/
	return reResult;
}
/* 逻辑进路信号保持信号机联锁条件检查 */
/*
* 功能描述： 逻辑进路信号保持信号机联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 KeepLogRouteSignalCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/
	UINT8 devColor = 0U;                 /*信号机颜色*/
	UINT16 wLogRouteSignalId = 0U;
	UINT8 FSwitchFlag = 0u;

	wLogRouteSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);

	/* 联锁逻辑检查 */

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

	}


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

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

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

			}
		}
		else
		{
			/*不做处理*/
		}
	}
	return reResult;
}

/* 逻辑进路信号开放信号机联锁条件检查 */
/*
* 功能描述： 逻辑进路信号开放信号机联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OpenLogRouteSignalCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/
	UINT16 wLogRouteSignalId = 0U;
	UINT8 FSwitchFlag = 0u;
	UINT8 signalCurColor = 0u;

	wLogRouteSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);

	/* 联锁逻辑检查 */

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

	}

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

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

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

			}
		}
		else
		{
			/*不做处理*/
		}
	}
	return reResult;
}

/*
* 功能描述： 逻辑进路信号机封锁状态检查
* 参数说明： UINT16 const wLogRouteId, 逻辑进路ID
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteSignalFLockCheck(UINT16 const wLogRouteId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT8 signalEndSum = 0U;
	UINT8 signalBeginSum = 0U;
	UINT16* signalEndIdBuff = NULL;
	UINT16* signalBeginIdBuff = NULL;
	UINT8 retVal = CI_ERROR;
	UINT16 wLogSecId = 0U;
	UINT16 ii = 0U;
	UINT16 jj = 0U;
	UINT16 devId = 0U;     /*信号机ID*/
	UINT8 devState = 0U;  /*信号机封锁状态*/

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);

	if ((NULL != LogSecIdBuff) && (0U != logSecSum)&& (NULL != pDevId) && (NULL != pDevState))
	{
		retVal = CI_SUCCESS;

		/*开始检查*/
		for (ii = 0U; ii < logSecSum; ii++)
		{
			wLogSecId = LogSecIdBuff[ii];
			signalBeginSum = GetLogRelateBeginSigSum(wLogSecId);
			signalBeginIdBuff = GetLogRelateBeginSigData(wLogSecId);
			signalEndSum = GetLogRelateEndSigSum(wLogSecId);
			signalEndIdBuff = GetLogRelateEndSigData(wLogSecId);

			if ((0U != signalBeginSum) && (NULL != signalBeginIdBuff))
			{
				for (jj = 0U; jj < signalBeginSum; jj++)
				{
					devId = signalBeginIdBuff[jj];
					devState = GetSignalFLockState(devId);
					if (SIGNAL_FENGSUO_NO == devState)
					{
						/* 通过检查*/
						retVal = CI_SUCCESS;
					}
					else
					{
						/*状态不一致返回故障状态*/
						*pDevId = devId;
						*pDevState = devState;
						retVal = CI_ERROR;
						break;
					}

				}
			}

			if (CI_SUCCESS == retVal)
			{
				if ((0U != signalEndSum) && (NULL != signalEndIdBuff))
				{
					devId = 0U;     
					devState = 0U;  
					for (jj = 0U; jj < signalEndSum; jj++)
					{
						devId = signalEndIdBuff[jj];
						devState = GetSignalFLockState(devId);
						if (SIGNAL_FENGSUO_NO == devState)
						{
							/* 通过检查*/
							retVal = CI_SUCCESS;
						}
						else
						{
							/*状态不一致返回故障状态*/
							*pDevId = devId;
							*pDevState = devState;
							retVal = CI_ERROR;
							break;
						}

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

/* 逻辑进路信号保持道岔联锁条件检查 */
/*
* 功能描述： 逻辑进路信号保持道岔联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 KeepLogRouteSwitchCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/
	UINT8 cYLockAlarmFlag = FLAG_UNSET;  /*引导总锁报警标志*/

	/*逻辑进路内所有道岔【未封锁】 未引导总锁*/
	checkResult = LogRouteSwitchFLockCheck(wLogRouteId, &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 = LogRouteProSwitchFLockCheck(wLogRouteId, &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_SUCCESS   不正确待转动：RETURN_LOCK_ERR_SWITPOS*/
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteSwitchPosCheck(wLogRouteId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

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

	/*检查防护道岔位置是否正确*/
	if (CI_SUCCESS == reResult)
	{
		/*  进路内所有防护道岔位置正确 		正确：CI_SUCCESS   不正确待转动：RETURN_LOCK_ERR_SWITPOS*/
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteProSwitchPosCheck(wLogRouteId, &devId, &devState);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SWITCH, devId, ETYPE_SWT_POSTION_STATE, devState, sendLevel);
			/* 失败返回 */
			reResult = RETURN_LOCK_ERR_SWITPOS;

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

	/*进路侧防道岔条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteCeFangSwitchCheck(wLogRouteId, &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
	{
		; /*不处理*/
	}

	if (CI_SUCCESS == reResult)
	{
		/*逻辑进路联络线设备条件检查*/
		checkResult = LogRouteContactLineDevSwitCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/*进路防护道岔防护锁闭条件检查*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteProtectLockSwitchCheck(wLogRouteId, &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
	{
		; /*不处理*/
	}

	return reResult;
}

/*
* 功能描述： 逻辑区段为逻辑进路锁闭的第一区段检查
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* 返回值  ：CI_ERROR 检查不通过
*			CI_SUCCESS 检查通过
* by cgh 20231013
*/
UINT8 LogSecLogRouteFirstLockCheck(const UINT16 wLogSectionId)
{
	UINT8 chReVal = CI_ERROR;
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT8 ii = 0U;
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/
	UINT16 wFirstNormalLockLogId = 0U;     /*逻辑进路第一个锁闭得逻辑区段ID*/

	if ((0U < wLogSectionId) && (LOGIC_SECTION_SUM_MAX > wLogSectionId))
	{
		chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSectionId);
		szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSectionId);

		if (NULL != szLogSecLockBelLogRouteData)
		{
			if (1U == chLogSecLockBelLogRouteSum)
			{
				chReVal = CI_SUCCESS;
			}
			else if ((1U < chLogSecLockBelLogRouteSum) && (LOGSEC_RELATE_ROUTE_SUM_MAX > chLogSecLockBelLogRouteSum))
			{
				chReVal = CI_SUCCESS;
				for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
				{
					wLogSecBelLogRouteId = szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
					wFirstNormalLockLogId = GetLogRouteFirNormalLockLogId(wLogSecBelLogRouteId);
					if ((wLogSectionId != wFirstNormalLockLogId) && (0U != wFirstNormalLockLogId))
					{
						/*当前逻辑区段被多个逻辑进路锁闭，如果不是多个逻辑进路第一个正常锁闭的逻辑区段，则不能区故解*/
						chReVal = CI_ERROR;
						break;
					}
				}
			}
			else
			{
				; /*不处理，默认检查不通过*/
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
	return chReVal;
}

/* 逻辑进路信号保持站台联锁条件检查 */
/*
* 功能描述： 逻辑进路信号保持站台联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 OpenLogRoutePlatformCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/
	UINT16 devId = 0U;                   /*设备ID*/
	UINT8 devState = 0U;                 /*设备状态*/

	/* 联锁逻辑检查 */

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

	/*站台安全屏蔽门关闭或互锁解除*/
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRoutePsdCloseCheck(wLogRouteId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_PSD, devId, ETYPE_PSD_CLOSE_NO, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	/*站台未实施扣车作业*/
	
	if (CI_SUCCESS == reResult)
	{
		devId = 0u;
		devState = 0u;
		checkResult = LogRouteDetainCheck(wLogRouteId, &devId, &devState);
		if (checkResult == CI_SUCCESS)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 记录故障码 */
			SetErrorData(functionId, CI_DEVICE_TYPE_SIGNAL, devId, ETYPE_PLAT_DETAIN, devState, sendLevel);
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	return reResult;
}

/*
* 功能描述： 逻辑进路站台紧急关闭按钮无效检查
* 参数说明： UINT16 const wLogRouteId,    逻辑进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteEsbVainCheck(UINT16 const wLogRouteId, UINT16 *pDevId, UINT8 *pDevState)
{
	/*ESB数据*/
	UINT8 checkSum = 0U;
	UINT16 *dataIdBuf = NULL;
	UINT8 reVal = CI_ERROR;
	UINT16 wLogRouteSignalId = 0U;
	UINT8 i = 0U;           /* 循环变量 */
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT8  devCutState = 0U;

	wLogRouteSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	checkSum = GetSignalRelatedEsbSum(wLogRouteSignalId);
	dataIdBuf = GetSignalRelatedEsbBuf(wLogRouteSignalId);
	
	if ((NULL == pDevId) || (NULL == pDevState) || (NULL == dataIdBuf))
	{
		/*参数指针检查失败*/
		reVal = CI_ERROR;
	}
	else if (0u == checkSum)
	{
		/*无ESB按钮，无检查项，无需检查*/
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetEsbState(devId);
			devCutState = GetEsbCutState(devId);
			if ((devState == ESB_STATE_VALID_NO) || (ESB_CUT_YES == devCutState))
			{
				/* 无效*/

			}
			else
			{
				/*有效*/
				*pDevId = (UINT16)devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}
	
	return reVal;
}

/*
* 功能描述： 逻辑进路站台屏蔽门关闭检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRoutePsdCloseCheck(UINT16 const wLogRouteId, UINT16 *pDevId, UINT8 *pDevState)
{
	/*PSD数据*/
	UINT8 checkSum = 0U;
	UINT16 *dataIdBuf = NULL;
	UINT16 i = 0U;           /* 循环变量 */
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT8 reVal = CI_ERROR;
	UINT16 wLogRouteSignalId = 0U;
	UINT8 psdMutualLockState = 0u;

	wLogRouteSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	checkSum = GetSignalRelatedPsdSum(wLogRouteSignalId);
	dataIdBuf = GetSignalRelatedPsdBuf(wLogRouteSignalId);

	if ((NULL == pDevId) || (NULL == pDevState) || (NULL == dataIdBuf))
	{
		/*参数指针为空返回失败*/
		reVal = CI_ERROR;
	}
	/* 站台屏蔽门状态 */
	else if (0u == checkSum)
	{
		/*无PSD，无需检查，无检查项*/
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查*/
		for (i = 0u; i < checkSum; i++)
		{
			devId = dataIdBuf[i];
			devState = GetPsdState(devId);
			psdMutualLockState = GetPsdMutualLockRemoveState(devId);
			if ((PSD_STATE_CLOSE == devState) || (PSD_MUTUALLOCK_REMOVE_YES == psdMutualLockState)
				|| (PSD_ATS_MUTUALLOCK_REMOVE_YES == psdMutualLockState) || (PSD_ATS_AND_JD_MUTUALLOCK_REMOVE_YES == psdMutualLockState))
			{
				/* 站台安全屏蔽门关闭或互锁解除 */

			}
			else
			{
				/* 开启 */
				*pDevId = devId;
				*pDevState = devState;
				reVal = CI_ERROR;
				break;
			}
		}
	}

	return reVal;
}

/*
* 功能描述： 逻辑进路站台未扣车检查
* 参数说明： UINT16 const routeId,    进路号
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteDetainCheck(UINT16 const wLogRouteId, UINT16 *pDevId, UINT8 *pDevState)
{
	UINT16 devId = 0U;
	UINT8  devState = 0U;
	UINT8 reVal = CI_ERROR;

	devId = GetLogicalRouteRelateBeginSigId(wLogRouteId);		/*获取逻辑进路关联信号机*/
	devState = GetSignalDetainFlag(devId);

	if ((NULL == pDevId) || (NULL == pDevState))
	{
		reVal = CI_ERROR;
	}
	else if (SIGNAL_DETAIN_NO == devState)
	{
		/* 通过检查 */
		reVal = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		*pDevId = devId;
		*pDevState = devState;
		/* 失败返回 */
		reVal = CI_ERROR;

	}
	return reVal;
}


/*
* 功能描述： 物理区段是否存在逻辑进路锁闭检查
* 参数说明： UINT16 const wPhySectionId, 物理区段ID
* 返回值  ： 0 数据非法，校验失败
*            >0 物理区段逻辑进路锁闭状态
* by cgh 20231014
*/
UINT8 PhySecLogLockStateCheck(UINT16 const wPhySectionId)
{
	UINT8 chReval = CI_ERROR;
	UINT16 wPhyIncLogSecSum = 0U;/*物理区段包含逻辑区段数目*/
	UINT16* szPhyIncLogSecIdBuf = NULL;/*物理区段包含逻辑区段ID数组*/
	UINT16 ii = 0U;
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/

	if ((0U < wPhySectionId) && (PHYSICAL_SECTION_SUM_MAX > wPhySectionId))
	{
		wPhyIncLogSecSum = GetPhySecIncLogSecSum(wPhySectionId);
		szPhyIncLogSecIdBuf = GetPhySecIncLogSecIdBuf(wPhySectionId);
		
		if (NULL != szPhyIncLogSecIdBuf)
		{
			for (ii = 0U; ii < wPhyIncLogSecSum; ii++)
			{
				chLogSecLogLockState = GetLogSecLogLockState(szPhyIncLogSecIdBuf[ii]);
				if (LOG_SECTION_LOGLOCK_NO != chLogSecLogLockState)
				{
					/*有一个逻辑区段状态为逻辑未锁闭，跳出*/
					break;
				}
			}

			if (wPhyIncLogSecSum == ii)
			{
				/*所有的逻辑区段均为未锁闭，检查通过*/
				chReval = LOG_SECTION_LOGLOCK_NO;
			}
			else
			{
				/*存在逻辑区段逻辑锁闭状态不为未锁闭，返回锁闭状态*/
				chReval = chLogSecLogLockState;
			}
		}
		else
		{
			chReval = CI_ERROR; /*默认返回检查失败*/
		}
		
	}
	else
	{
		chReval = CI_ERROR; /*默认返回检查失败*/
	}
	return chReval;                                                                                                      
}

/*
* 功能描述： 计轴区段是否存在逻辑进路锁闭检查
* 参数说明： UINT16 const wPhySectionId, 计轴区段ID
* 返回值  ： 0 数据非法，校验失败
*            >0 物理区段逻辑进路锁闭状态
* by cgh 20231014
*/
UINT8 AixsSecLogLockStateCheck(UINT16 const wAxisSectionId)
{
	UINT8 chReval = CI_ERROR;
	UINT16 axisRelativeLogSecNum = 0U;/*计轴区段包含逻辑区段数目*/
	UINT16* axisRelativeLogSecIdBuf = NULL;/*计轴区段包含逻辑区段ID数组*/
	UINT16 ii = 0U;
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/

	if ((0U < wAxisSectionId) && (AXIS_SECTION_SUM_MAX > wAxisSectionId))
	{

		/** 获取计轴区段关联的逻辑区段数量和ID*/
		axisRelativeLogSecNum = GetAxisSecLogSectionSum(wAxisSectionId);
		axisRelativeLogSecIdBuf = GetAxisSecLogSectionIdBuf(wAxisSectionId);

		if (NULL != axisRelativeLogSecIdBuf)
		{
			for (ii = 0U; ii < axisRelativeLogSecNum; ii++)
			{
				chLogSecLogLockState = GetLogSecLogLockState(axisRelativeLogSecIdBuf[ii]);
				if (LOG_SECTION_LOGLOCK_NO != chLogSecLogLockState)
				{
					/*有一个逻辑区段状态为逻辑未锁闭，跳出*/
					break;
				}
			}

			if (axisRelativeLogSecNum == ii)
			{
				/*所有的逻辑区段均为未锁闭，检查通过*/
				chReval = LOG_SECTION_LOGLOCK_NO;
			}
			else
			{
				/*存在逻辑区段逻辑锁闭状态不为未锁闭，返回锁闭状态*/
				chReval = chLogSecLogLockState;
			}
		}
		else
		{
			chReval = CI_ERROR; /*默认返回检查失败*/
		}

	}
	else
	{
		chReval = CI_ERROR; /*默认返回检查失败*/
	}
	return chReval;
}

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

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

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

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

	return reVal;
}


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

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


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

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

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

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

/*
* 功能描述： 检查逻辑进路第一个锁闭的逻辑区段的上一个逻辑区段锁闭状态
* 参数说明： const UINT16 wLogRouteId  逻辑进路ID
*           const UINT16 wLogSecId  逻辑区段ID
* 返回值  ： CI_ERROR   上一个逻辑区段锁闭状态检查不通过
*            CI_SUCCESS 上一个逻辑区段锁闭状态检查通过
* by cgh 20231016
*/
UINT8 CheckLogRouteLogSecLastSecLock(const UINT16 wLogRouteId, const UINT16 wLogSecId)
{
	UINT8 ii = 0U;
	UINT8 chReval = CI_ERROR;
	UINT8 chLogSecLastSecSum = 0U;/*逻辑区段上一个逻辑区段数目*/
	UINT16* wLogSecLastSecIdBuf = NULL;/*逻辑区段上一个逻辑区段ID*/
	UINT8 chLastLogSecLockState = 0U;/*上一个逻辑区段锁闭状态*/
	UINT8 chLastLogSecLogLockState = 0U;/*上一个逻辑区段逻辑锁闭状态*/
	UINT8 chLogRouteDir = 0U;/*逻辑进路运营方向*/
	UINT8 chLogRouteLogicDir = 0U;/*逻辑进路逻辑方向*/
	UINT8 chLogSecLogLockDir = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT8 chLastLogSecLockDir = 0U;/*上一个逻辑区段锁闭方向*/
	UINT8 chLastLogSecLogLockDir = 0U;/*上一个逻辑区段逻辑锁闭方向*/
	UINT8 chCheckFlag = 0U;/*检查标志*/

	chLogRouteDir = GetLogicalRouteDir(wLogRouteId);
	chLogRouteLogicDir = ConvertDirectionToLogic(chLogRouteDir);
	chLogSecLogLockDir = GetLogSecLogLockDir(wLogSecId);

	if (DIR_SAME == chLogRouteLogicDir)
	{
		chLogSecLastSecSum = GetLogBeginLogSecSum(wLogSecId);
		wLogSecLastSecIdBuf = GetLogBeginLogSecData(wLogSecId);
	}
	else if(DIR_CONVERT == chLogRouteLogicDir)
	{
		chLogSecLastSecSum = GetLogEndLogSecSum(wLogSecId);
		wLogSecLastSecIdBuf = GetLogEndLogSecData(wLogSecId);
	}
	else
	{
		;/*返回错误*/
	}

	if (NULL != wLogSecLastSecIdBuf)
	{
		if (0U != chLogSecLastSecSum)
		{
			for (ii = 0U; ii < chLogSecLastSecSum; ii++)
			{
				chLastLogSecLockState = GetLogSecLockState(wLogSecLastSecIdBuf[ii]);
				chLastLogSecLogLockState = GetLogSecLogLockState(wLogSecLastSecIdBuf[ii]);
				chLastLogSecLockDir = GetLogSecLockDir(wLogSecLastSecIdBuf[ii]);
				chLastLogSecLogLockDir = GetLogSecLogLockDir(wLogSecLastSecIdBuf[ii]);

				if ((LOG_SECTION_LOCK_NO == chLastLogSecLockState) && (LOG_SECTION_LOGLOCK_NO == chLastLogSecLogLockState))
				{
					; /*逻辑区段锁闭状态及逻辑锁闭状态均为未锁闭，继续检查*/
				}
				else
				{
					if (LOG_SECTION_LOCK_NO == chLastLogSecLockState)
					{
						if (chLastLogSecLogLockDir != chLogSecLogLockDir)
						{
							;/*逻辑区段未锁闭但是逻辑锁闭状态不为未锁闭，此时方向不同，检查通过*/
						}
						else
						{
							chCheckFlag = 1U;
						}
					}
					else if (LOG_SECTION_LOGLOCK_NO == chLastLogSecLogLockState)
					{
						if (chLastLogSecLockDir != chLogSecLogLockDir)
						{
							;/*逻辑区段不为未锁闭但是逻辑锁闭状态为未逻辑锁闭，此时方向不同，检查通过*/
						}
						else
						{
							chCheckFlag = 1U;
						}
					}
					else
					{
						/*两个锁闭状态均为锁闭*/
						if ((chLastLogSecLockDir != chLogSecLogLockDir) && (chLastLogSecLogLockDir != chLogSecLogLockDir))
						{
							;/*检查通过*/
						}
						else
						{
							chCheckFlag = 1U;
						}
					}

					if (1U == chCheckFlag)
					{
						SetErrorData(EFUNC_LOGSEC_LAST_SECLOCK, CI_DEVICE_TYPE_LOGICSEC, wLogSecLastSecIdBuf[ii],
							ETYPE_LOGSEC_LOCK_STATE, chCheckFlag, ESEND_LEVEL_ZERO);
						break; /*跳出*/
					}
					else
					{
						; /*继续检查*/
					}
					
				}
			}
			if (chLogSecLastSecSum == ii)
			{
				/*所有区段均为未锁闭，返回成功*/
				chReval = CI_SUCCESS;
			}
		}
		else
		{
			/*数目为0，线路尽头，返回成功*/
			chReval = CI_SUCCESS;
		}
	}
	else
	{
		; /*不处理*/
	}

	return chReval;
}

/*
* 功能描述： 获取指定ID逻辑进路资源包含该逻辑区段
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
*			 const UINT16 lgcSecId
* 返回值  ： CI_SUCCESS: 在逻辑进路预锁闭中
*            CI_ERROR: 不在逻辑进路预锁闭中
*/
UINT8  CheckLgcSecInLogRoute(const UINT16 wLogRouteId, const UINT16 lgcSecId)
{
	UINT8 reVal = CI_ERROR;
	UINT16 wLogRouteLogSecSum = 0U;				/*列车逻辑区段数量*/
	UINT16* wLogRouteLogSecIdBuf = NULL;
	UINT8 ii = 0U;

	wLogRouteLogSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	wLogRouteLogSecIdBuf = GetLogicalRouteInLogSecId(wLogRouteId);

	for (ii = 0U; ii < wLogRouteLogSecSum; ii++)
	{
		if (lgcSecId == wLogRouteLogSecIdBuf[ii])
		{
			reVal = CI_SUCCESS;
			break;
		}
	}

	if (ii == wLogRouteLogSecSum)
	{
		reVal = CI_ERROR;
	}
	return reVal;
}

/*
* 功能描述： 获取指定ID逻辑进路资源包含该物理区段
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
*			 const UINT16 phySecId
* 返回值  ： CI_SUCCESS: 在逻辑进路预锁闭中
*            CI_ERROR: 不在逻辑进路预锁闭中
*/
UINT8  CheckPhySecInLogRoute(const UINT16 wLogRouteId, const UINT16 phySecId)
{
	UINT8 reVal = CI_ERROR;
	UINT16 pRoutePhySecIdBuf[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };  /*进路包含脚下的物理区段ID数组*/
	UINT8  routePhySecSum = 0U;  /*进路包含的物理区段数目*/
	UINT8 ii = 0U;

	/*获取逻辑进路包含物理区段信息*/
	routePhySecSum = GetLogicRouteIncPhySec(wLogRouteId, &pRoutePhySecIdBuf);
	for (ii = 0U; ii < routePhySecSum; ii++)
	{
		if (phySecId == pRoutePhySecIdBuf[ii])
		{
			reVal = CI_SUCCESS;
			break;
		}
	}

	if (ii == routePhySecSum)
	{
		reVal = CI_ERROR;
	}
	return reVal;
}

/*
* @brief 检查是否为同一列车重复办理同一逻辑进路
* @param const UINT16 wLogSecSum 逻辑进路包含的逻辑区段数目
* @param const UINT16* pLogSecIdbuf 逻辑进路包含的逻辑区段ID数组
* @param const UINT16 wTrainId 办理逻辑进路的列车ID
* @return 1 成功
*         0 失败
* @note：Created by LQ 2023.11.01
*/
UINT8 RepeatSetLogicRouteCheck(const UINT16 wLogSecSum, const UINT16* pLogSecIdbuf, const UINT16 wTrainId)
{
	UINT8 retVal = CI_ERROR;
	UINT8 cKeepWorkFlag = CI_ERROR;
	UINT16 ii = 0U;
	UINT16 jj = 0U;
	UINT16 wLogicRouteID = 0U;  /*逻辑进路ID*/
	UINT8 cLogicRouteState = 0U;  /*逻辑进路状态*/
	UINT16 wLogicRouteIncLogSecNum = 0U;  /*逻辑进路包含的逻辑区段数量*/
	UINT16* pLogicRouteIncLogSecId = NULL;  /*逻辑进路包含的逻辑区段ID*/
	UINT16 wLogicRouteResTrainId = 0U;  /*逻辑进路资源列车ID*/

	if ((0U != wLogSecSum) && (NULL != pLogSecIdbuf))
	{
		for (ii = 0U; ii < ROUTE_LOGICAL_SUM_MAX; ii++)
		{
			wLogicRouteID = GetLogicalRouteId(ii);
			cLogicRouteState = GetLogicalRouteState(wLogicRouteID);

			if (ROUTE_LOGICAL_STATE_IDLE != cLogicRouteState)
			{
				wLogicRouteIncLogSecNum = GetLogicalRouteInLogSecSum(wLogicRouteID);  /*获取逻辑进路包含的逻辑区段*/
				pLogicRouteIncLogSecId = GetLogicalRouteInLogSecId(wLogicRouteID);
				wLogicRouteResTrainId = GetLogicalRouteApplyResTrainId(wLogicRouteID);  /*获取逻辑进路的资源列车*/

				if ((wLogicRouteIncLogSecNum == wLogSecSum) && (NULL != pLogicRouteIncLogSecId) && (wLogicRouteResTrainId == wTrainId))
				{
					for (jj = 0U; jj < wLogicRouteIncLogSecNum; jj++)
					{
						if (pLogicRouteIncLogSecId[jj] == pLogSecIdbuf[jj])
						{
							cKeepWorkFlag = CI_ERROR;  /*继续遍历*/
						}
						else
						{
							cKeepWorkFlag = CI_SUCCESS;  /*序列内的逻辑区段不重复，停止遍历*/
							break;
						}			
					}
				}
				else
				{
					cKeepWorkFlag = CI_SUCCESS;  /*逻辑区段数量不等或资源列车不等，代表为非重复办理的逻辑进路，继续遍历*/
				}
			}
			else
			{
				retVal = CI_SUCCESS;  /*找到第一个空闲的逻辑进路，代表前面非空闲的逻辑进路均未被重复办理，停止遍历，返回成功*/
			}

			if ((CI_ERROR == cKeepWorkFlag) || (CI_SUCCESS == retVal))
			{
				break;  /*存在重复办理的逻辑进路或找到第一个空闲的逻辑进路，停止遍历，返回执行结果*/
			}
			else
			{
				/*继续遍历*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return retVal;
}

/*
* @brief 检查逻辑进路是否需要添加始端信号机
* @param const UINT16 wFstLogSecId 逻辑进路包含的第一个逻辑区段ID
* @param const UINT8 cLogicRouteDir 逻辑进路方向（逻辑方向）
* @param const UINT16 wTrainId 办理逻辑进路的列车ID
* @return 0 不添加始端信号机
*        >0 待添加的始端信号机ID
* @note：Created by LQ 2023.11.01
*/
UINT16 LogicRouteAddStartSignalCheck(const UINT16 wFstLogSecId, const UINT8 cLogicRouteDir, const UINT16 wTrainId)
{
	UINT16 wStartSignalId = 0U;  /*逻辑进路始端信号机ID*/
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wBufIndex = 0U;
	struct_PathPoint start = { 0U };  /*列车逻辑起点*/
	struct_PathPoint end = { 0U };  /*列车逻辑终点*/
	UINT16 wCTOccLogSum = 0U;  /*通信列车脚下逻辑区段数量*/
	UINT16 wCTOccLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };  /*通信列车占压的逻辑区段ID*/
	UINT8 cRelatedStartSigNum = 0U;  /*逻辑区段关联的始端信号机数量*/
	UINT16* pRelatedStartSigId = NULL;  /*逻辑区段关联的始端信号机ID数组*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link ID*/
	UINT8 cSignalProDir = 0U;  /*信号机防护方向*/
	UINT16 wSigProLinkId = 0U;  /*信号机防护link*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;  /*方向变化点数量*/
	UINT8 cKeepWork = CI_ERROR;
	UINT8 cCommStateWithTrain = CI_ERROR;  /*与车通信状态*/

	wBufIndex = GetTrainBufIndex(wTrainId);	

	if ((0U != wFstLogSecId) && (LOGIC_SECTION_SUM_MAX != wFstLogSecId)
		&& ((DIR_CONVERT == cLogicRouteDir) || (DIR_SAME == cLogicRouteDir))
		&& (TRAIN_SUM_MAX > wBufIndex))
	{
		cCommStateWithTrain = GetTrainTransitmitStat(wTrainId);
		if (TRAIN_COMM_STATE_GOOD == cCommStateWithTrain)
		{
			end.wLinkId = GetTrainMaxHeadLink(wTrainId);
			end.dwOffset = GetTrainMaxHeadOffset(wTrainId);
			start.wLinkId = GetTrainMinTailLink(wTrainId);
			start.dwOffset = GetTrainMinTailOffset(wTrainId);
			cKeepWork = GetLogSecBtwTwoPoints(start, end, &wCTOccLogSum, wCTOccLogID);  /*获取通信车脚下逻辑区段信息，此处不用考虑方向*/
		}
		else
		{
			cKeepWork = CI_SUCCESS;
		}

		if (CI_SUCCESS == cKeepWork)
		{
			/*判断列车是否占压逻辑进路内方第一区段*/
			for (ii = 0U; ii < wCTOccLogSum; ii++)
			{
				if (wCTOccLogID[ii] == wFstLogSecId)
				{
					cKeepWork = CI_ERROR;  /*列车占压逻辑进路内方第一区段，停止遍历*/
					break;
				}
				else
				{
					/*继续遍历*/
				}
			}

			if (CI_SUCCESS == cKeepWork)
			{
				/*列车未占压逻辑进路内方第一区段，判断逻辑区段是否关联有同向始端信号机*/
				cRelatedStartSigNum = GetLogRelateBeginSigSum(wFstLogSecId);
				pRelatedStartSigId = GetLogRelateBeginSigData(wFstLogSecId);
				pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(wFstLogSecId);

				if ((0U != cRelatedStartSigNum) && (NULL != pRelatedStartSigId) && (NULL != pLogSecIncLinkId))
				{
					for (jj = 0U; jj < cRelatedStartSigNum; jj++)
					{
						cSignalProDir = GetSignalDirection(pRelatedStartSigId[jj]);
						wSigProLinkId = GetSignalProtectLink(pRelatedStartSigId[jj]);
						strCurPoint.Lnk = pLogSecIncLinkId[0U];
						strCurPoint.Off = 0U;
						strNxtPoint.Lnk = wSigProLinkId;
						strNxtPoint.Off = 0U;
						cDirChangeNum = GetDirChangeNumBtwPoints(&strCurPoint, &strNxtPoint);  /*查询当前link到信号机防护link间的方向变化点*/
						cSignalProDir = TransDirByChangeNum(cSignalProDir, cDirChangeNum);
						if (cSignalProDir == cLogicRouteDir)
						{
							wStartSignalId = pRelatedStartSigId[jj];  /*查找到同向始端信号机，返回此信号机ID，停止遍历*/
							break;
						}
						else
						{
							/*继续遍历*/
						}
					}
				}
				else
				{
					/*获取逻辑区段始端信号机或包含的link失败，返回0*/
				}
			}
			else
			{
				/*列车占压逻辑进路内方第一区段，返回0*/
			}
		}
		else
		{
			/*列车脚下区段计算失败，返回0*/
		}
	}
	else
	{
		/*入参非法，返回0*/
	}

	return wStartSignalId;
}

/*
* @brief 检查逻辑区段是否非道岔区段且具有停车区域属性
* @param const UINT16 wLogSecId 逻辑区段ID
* @return 0 道岔区段或不具有停车区域属性
*         1 非道岔区段且具有停车区域属性
* @note：Created by LQ 2023.11.03
*/
UINT8 LogSecIsSwitchAndStopAreaCheck(const UINT16 wLogSecId)
{
	UINT8 retVal = CI_ERROR;
	UINT16 wStopAreaId = 0U;  /*停车区域ID*/
	UINT8 cLogSecIncLinkNum = 0;  /*逻辑区段包含的link数量*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link ID*/
	UINT16 wLogSecRelPhySecId = 0U;  /*逻辑区段关联的物理区段ID*/
	UINT8 cPhySecType = 0U;  /*物理区段类型*/

	if ((0U != wLogSecId) && (LOGIC_SECTION_SUM_MAX > wLogSecId))
	{		
		cLogSecIncLinkNum = GetSecIntrudeLinkSum(wLogSecId);  /*获取逻辑区段包含的link*/
		pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(wLogSecId);
		wLogSecRelPhySecId = GetLgcSecRelativePhySecId(wLogSecId);  /*获取逻辑区段关联的物理区段*/
		cPhySecType = GetPhySecType(wLogSecRelPhySecId);  /*获取物理区段类型*/

		/*判断逻辑区段是否非道岔区段且具有停车区域属性*/
		if ((1U == cLogSecIncLinkNum) && (NULL != pLogSecIncLinkId) && (PHYSICAL_SEC_TYPE_NOSWITCH == cPhySecType))
		{
			wStopAreaId = GetLinkStopAreaId(pLogSecIncLinkId[0U]);  /*获取link停车区域ID*/
			if (0U != wStopAreaId)
			{
				retVal = CI_SUCCESS;  /*存在停车区域，返回成功*/
			}
			else
			{
				retVal = CI_ERROR;  /*非停车区域，返回失败*/
			}
		}
		else
		{
			retVal = CI_ERROR;  /*条件不满足，返回失败*/
		}
	}
	else
	{
		retVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return retVal;
}

/* 逻辑进路信号保持防淹门联锁条件检查 */
/*
* 功能描述： 逻辑进路信号保持防淹门联锁条件检查
* 参数说明：
*            UINT16 wLogRouteId,    逻辑进路号
*            UINT8 functionId,  调用函数编号
*            UINT8 sendLevel,   故障码发送级别
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 KeepLogRouteFloodGateCheck(UINT16 wLogRouteId, UINT8 functionId, UINT8 sendLevel)
{
	UINT8 reResult = CI_ERROR;
	UINT16 wPhySecId = 0U;		/*物理区段ID*/
	UINT16 LogSectionSum = 0U;
	UINT16 ii = 0U;
	UINT16 *pLogicSecId = NULL;
	UINT16 jj = 0U;
	UINT16 floodGateSum = 0U;		/*防淹门数量*/
	UINT16* floodGateIdBuf = NULL;/*临时变量*/
	UINT16 wFloodGateId = 0U;		/*物理区段所在防淹门ID*/
	UINT8 floodState = 0u;/*防淹门状态*/

	LogSectionSum = GetLogicalRouteInLogSecSum(wLogRouteId);		/*获取逻辑进路包含的逻辑区段*/
	pLogicSecId = GetLogicalRouteInLogSecId(wLogRouteId);

	if (( 0U < LogSectionSum) && (NULL != pLogicSecId))
	{
		for (ii = 0U; ii < LogSectionSum; ii++)
		{
			wPhySecId = GetLgcSecRelativePhySecId(pLogicSecId[ii]);			/*获取逻辑区段所属物理区段ID*/
			if (0U < wPhySecId)
			{
				floodGateSum = GetPhySecLocatedFloodSum(wPhySecId);		/*数量为0说明没有防淹门，无需检查，依旧返回成功*/
				if (0U < floodGateSum)
				{
					floodGateIdBuf = GetPhySecLocatedFloodId(wPhySecId);
					if (NULL != floodGateIdBuf)
					{
						for (jj = 0U; jj < floodGateSum; jj++)
						{
							wFloodGateId = floodGateIdBuf[jj];

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

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

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

							if (CI_SUCCESS != reResult)
							{
								break;		/*有一个防淹门不满足条件，返回ERROR*/
							}
						}
					}
					else
					{
						reResult = CI_ERROR;		/*获取数据失败，反馈失败*/
					}
				}
				else
				{
					reResult = CI_SUCCESS;/*逻辑区段关联物理区段不包含防淹门ID，返回成功，无需检查防淹门条件*/
				}
				if (CI_ERROR == reResult)
				{
					break;			/*防淹门检查不通过，跳出循环*/
				}
			}
		}	
	}

	return reResult;
}