/********************************************************
*                                                                                                            
* 文 件 名： InterlockCommonManage.c   
* 版权说明： 北京交控科技有限公司 
* 创建时间： 2015-06-30
* 作    者： 联锁组
* 功能描述： 联锁车辆段和正线公用逻辑管理函数 
* 修改记录：   
*
********************************************************/ 

#include "InterlockCommonManage.h"
#include "RouteRecoverManage.h"
#include "../SGBJ/SGBJConfigDataManage.h"
#include "../Route/LogicalRouteDataManage.h"
#include "../Section/LogicSectionDataManage.h"
#include "LogicalRouteDataManage.h"
#include "../LogicProcess/LogicalRouteLogicCheck.h"

/* C01_进路监督级别确认 */
/*
* 功能描述： 进路监督级别确认
* 参数说明： UINT16 const routeId   进路号
* 返回值  ： ROUTE_LEVEL_BLOC（点式）
*            ROUTE_LEVEL_CBTC（CBTC）
* 故障编码： EFC_ROUTE_LEVEL
*/
UINT8 RouteLevelConfirmLogicProcess(UINT16 const routeId)
{
    /* 局部变量定义初始化 */
    /*始端信号机*/
	UINT16 starSignalId = 0u;
    /*始端信号机开放状态*/
	UINT8 stateSignalOpen = 0u;
    UINT8 reVal = ROUTE_LEVEL_BLOC;
	UINT8 cmainState = 0u;  /*单个信号机维修点灯状态*/
	UINT8 routeType = 0U; /*进路类型*/
	
	starSignalId = GetRouteStartSignalId(routeId);
	cmainState = GetSignalMaintainState(starSignalId);
	stateSignalOpen = GetSignalLightExtinctState(starSignalId);
	routeType = GetRouteType(routeId);      /*获取进路类型*/
	
	/* 联锁逻辑检查 */
	/*进路始端信号机【灭灯】且 不在维修点灯状态 且 进路不为调车进路*/
	if ((SIGNAL_LIGHT_EXTICT_STATE_NO == stateSignalOpen)
		&& (MAINTAIN_STATE_NO == cmainState)
		&& (ROUTE_TYPE_DIAOCHE != routeType))
	{
		/*CBTC*/
		reVal = ROUTE_LEVEL_CBTC;
	}
	/*进路始端信号机不为【灭灯】*/
	else
	{
		/* 点式 */
		reVal = ROUTE_LEVEL_BLOC;
	}


	return reVal;
}

/*
* 功能描述： 获取指定信号机ID所关联的引导进路ID
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： routeIdBuf[jj]   进路ID
*           0: 获取失败
*/
UINT16 GetStartSignalRouteId(const UINT16 signalId)
{
    UINT8 routeType = 0u;	   /*进路类型*/
    UINT8 leadProperty = 0u;    /*进路引导属性*/

    UINT16 routeId = 0u;
    UINT16 starSigRouteSum = 0u;    /*以相同信号机为始端的进路数目*/
    UINT16* starSigRouteBuf = NULL;  /*以相同信号机为始端的进路ID数组*/
    UINT16 ii = 0u;
    UINT8 flag = 0u;    /*列车引导进路是否办理成功标志*/
    UINT8 switchSum = 0u; /*进路所包含的道岔数目*/
	UINT8 protSwitchSum = 0u; /*进路所包含的防护道岔数目*/

    RouteSwitchStruct* switchBuf = NULL; /*进路所包含的道岔数据*/
	RouteProtectSwitchStruct* protSwitchBuf = NULL; /*进路所包含的防护道岔数据*/

    UINT8 switchPosition = 0u;      /*当前道岔位置*/
    UINT16 routeIdBuf[SIGNAL_EQUAL_ROUTE_MAX_SUM] = {0u};    /*存放满足条件的引导进路ID*/
    UINT8 routeSum = 0u;             /*存放满足条件的引导进路数目*/
    UINT8 jj = 0u;
	UINT8 kk = 0u;
    UINT16 reVal = 0u;
    UINT8 localCiId = 0u;       /*本地联锁ID*/
    UINT8 belongCiId = 0u;      /*信号机所属联锁ID*/
	UINT8 routeLeadProperty = 0u;/*进路引导属性*/

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

    if ((belongCiId == localCiId) && (0u != localCiId))
    {
		starSigRouteSum = GetStartSignalRouteSum(signalId);
		starSigRouteBuf = GetStartSignalRouteBuf(signalId);

		if ((NULL != starSigRouteBuf) && (0u != starSigRouteSum))
		{/*获取所有满足道岔条件的进路ID*/
			for (ii = 0u; (starSigRouteSum > ii)&&(SIGNAL_EQUAL_ROUTE_MAX_SUM >ii); ii++)
			{
				routeId = starSigRouteBuf[ii];
				routeLeadProperty = GetRouteLeadProperty(routeId);
				if ((ROUTE_LEAD_PROPERTY_YES == routeLeadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == routeLeadProperty))
				{
					switchSum = GetRouteSwitchSum(routeId);
					switchBuf = GetRouteSwitchData(routeId);
					protSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);
					protSwitchBuf = GetRouteRelatedProtSwitchData(routeId);
					if ((NULL != switchBuf) && (NULL != protSwitchBuf))
					{
						if (0u < switchSum)
						{
							for (jj = 0u; jj < switchSum; jj++)     /*找出所有满足道岔位置的进路*/
							{
								switchPosition = GetSwitchCurPosition(switchBuf[jj].SwitchId);
								if (switchPosition == switchBuf[jj].SwitchPosition)
								{
									flag = 1u;

								}
								else
								{
									flag = 0u;
									break;           /*有一个道岔不满足条件则退出*/
								}
							}
							switchPosition = 0u;      /*当前道岔位置*/
							if (1u == flag)
							{
								if (0u < protSwitchSum)
								{
									for (kk = 0u; kk < protSwitchSum; kk++)     /*找出所有满足防护道岔位置的进路*/
									{
										switchPosition = GetSwitchCurPosition(protSwitchBuf[kk].ProtectSwitchId);
										if (switchPosition == protSwitchBuf[kk].ProtectPosition)
										{
											flag = 1u;
										}
										else
										{
											flag = 0u;
											break;           /*有一个道岔不满足条件则退出*/
										}
									}
								}
							}
							if (1u == flag)
							{
								routeIdBuf[routeSum] = routeId;
								routeSum++;
							}
						}
						else     /*引导进路不包含道岔,则只有一条*/
						{
							routeIdBuf[routeSum] = routeId;
							routeSum++;
						}
					}
				}
			}
			if (0u == routeSum)    /*未查找到*/
			{
				/* 记录故障码 */
				SetErrorData(EFUNC_LEAD_ROUTE_MANAGE_ERROR,CI_DEVICE_TYPE_SIGNAL,signalId,ETYPE_SIG_YDROUTE_SEARCH_ERR,0,ESEND_LEVEL_ATS); 
				
			}
			for(jj = 0u; jj < routeSum; jj++)
			{

				routeType = GetRouteType(routeIdBuf[jj]);             /*获取进路类型*/
				leadProperty = GetRouteLeadProperty(routeIdBuf[jj]);  /*获取进路引导属性*/

				if ((routeSum > 1u) && (ROUTE_TYPE_LIECHE == routeType)
					&& ((ROUTE_LEAD_PROPERTY_YES == leadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == leadProperty)))
				{
					/*满足条件的最多有两条进路，一条为列车进路，一条为折返进路,列车进路且可引导*/
					reVal = routeIdBuf[jj];
				}
				else if ((1u == routeSum) && ((ROUTE_TYPE_LIECHE == routeType) || (ROUTE_TYPE_RETURN == routeType))
					&& ((ROUTE_LEAD_PROPERTY_YES == leadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == leadProperty)))
				{
					reVal = routeIdBuf[jj];
				}
				else if ((1u == routeSum) && (ROUTE_TYPE_DIAOCHE == routeType)
					&& ((ROUTE_LEAD_PROPERTY_YES == leadProperty) || (ROUTE_LEAD_PROPERTY_CBTC_YES == leadProperty)))
				{/*进路类型为调车进路且始端信号机可以引导*/
					reVal = routeIdBuf[jj];
				}
				else
				{
					/*不做处理*/
				}
				if (0u != reVal)
				{
					break;
				}
			}
		}

		     
    }
   

    return reVal;
}

/*
* 功能描述： 清除进路物理区段之前占用状态
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_ERROR:清除失败
*			 CI_SUCCESS:清除成功 
*/
UINT8 CleanRoutePhySecPreOccupyState(const UINT16 routeId)
{
    UINT8 ii = 0u;
    UINT8 PhySecSum = 0u;
    UINT16 PhySecId = 0u;
    RoutePhysicalSectionStruct* routePhySecStru = NULL;

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

    PhySecSum = GetRoutePhysicalSectionSum(routeId);
    routePhySecStru = GetRouteSectionData(routeId);

    if (0u == PhySecSum) 
    {
        return CI_ERROR;
    }
	else
	{
	    ;
	}

    if (ROUTE_PHYSICALSECTION_SUM_MAX>=PhySecSum )
    {
        for (ii = 0u; ii < PhySecSum; ii++)
        {
            PhySecId = routePhySecStru[ii].PhysicalSectionId;

            CleanPhySecPreMergeState(PhySecId);
        }

        /*清除接近区段之前占用*/
        PhySecId = GetSignalOutFirstPhySecId(GetRouteStartSignalId(routeId));
        CleanPhySecPreMergeState(PhySecId);

#if 0
        /*清除离去区段之前占用*/
       PhySecId = GetRouteLeavePhySecId(routeId);
       CleanPhySecPreMergeState(PhySecId);
#endif

        return CI_SUCCESS;
    }
    else
    {
        return CI_ERROR;
    }    
}

/*
* 功能描述： 设置进路物理区段征用状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 useState, 征用状态
* 返回值  ： 无
*/
void SetRoutePhySectionOccupyState(const UINT16 routeId, const UINT8 setUseState)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 localCiId = 0u;  /*本机联锁ID*/
	UINT8 ii = 0u;  /*遍历变量*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT8 reVal = CI_ERROR;
	UINT16 routeProSwitchSum = 0u;/*进路防护道岔数量*/
	RouteProtectSwitchStruct*  pRouteProSwitchData = NULL;/*进路防护道岔数据*/
	UINT16 switchId = 0u;/*道岔ID*/
	UINT16 phyId = 0u;/*物理区段ID*/
	UINT8 curUseState = 0u;/*征用状态*/
	UINT8 phySecBelongId = 0u;/*物理区段所属联锁ID*/

	UINT8 commState = 0u;/*通信状态*/
	/*相邻联锁是否支持继电接口*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/
	
	localCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	phySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/

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

	if ((setUseState != PHYSICAL_SECTION_USING_YES) &&
		(setUseState != PHYSICAL_SECTION_USING_NO))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;

		if ((0u == localCiId) || (0u == phySecSum) || (NULL == pPhySecDataStru))
		{
			reVal = CI_ERROR; 
		}
	}

	

	if (CI_SUCCESS == reVal)
	{/*进路内的征用，与取消征用*/
		for (ii= 0u; ii < phySecSum; ii++)
		{
			phySecBelongId = GetPhySecBelongCiId(pPhySecDataStru[ii].PhysicalSectionId);
			curUseState = GetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId);

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

			if (PHYSICAL_SECTION_USING_YES == setUseState)
			{ /*设置区段征用*/
				
				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/
					/*直接设置区段征用*/
					SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_YES, routeId);
				}
				else
				{
					if ((TRANSMIT_STATE_BAD == commState) && 
						(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
						(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
					{
						/*如果物理区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则直接设置该物理区段为征用*/
						SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_YES, routeId);
					}
					else
					{
						/*非本联锁区段*/
						/*设置区段申请征用*/
						SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_APPLY, routeId);

					}
				}
			}
			else
			{ /*设置区段未征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

					/*设置区段未征用*/
					SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_NO, routeId);
				}
				else
				{ /*非本联锁区段*/
					if ((TRANSMIT_STATE_BAD == commState) && 
						(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
						(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
					{
						/*如果物理区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则直接设置该物理区段为未征用*/
						SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_NO, routeId);
					}
					else
					{
						SetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_USING_CANCEL, routeId);
					}
				}
			}
		}
	}

	if (CI_SUCCESS == reVal)
	{/*防护道岔所在区段征用与取消征用*/
		for (ii= 0u; ii < routeProSwitchSum; ii++)
		{
			switchId = pRouteProSwitchData[ii].ProtectSwitchId;
					
			phyId = GetSwitchPhySectionId(switchId);
			curUseState = GetPhySecUseState(phyId);
			phySecBelongId = GetPhySecBelongCiId(phyId);

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

			if (PHYSICAL_SECTION_USING_YES == setUseState)
			{ /*设置区段征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

					/*设置区段防护征用*/
					SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_YES, routeId);
				}
				else
				{ /*非本联锁区段*/
					if ((TRANSMIT_STATE_BAD == commState) && 
						(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
						(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
					{
						/*如果物理区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则设置该物理区段征用状态*/
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_YES, routeId);
					}
					else
					{
						/*设置区段申请征用*/
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_APPLY, routeId);
					}
				}
			}
			else
			{ /*设置区段未征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

					/*设置区段未征用*/
					SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_NO, routeId);
				}
				else
				{ /*非本联锁区段*/
					if ((TRANSMIT_STATE_BAD == commState) && 
						(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
						(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
					{
						/*如果物理区段所属联锁与本联锁不同，且本联锁与该联锁通信中断，且运营人员已下发确认继电接口命令，
							且已配置支持继电接口，则可以不设置该物理区段征用状态*/
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_NO, routeId);
					}
					else
					{
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_CANCEL, routeId);
					}
				}
			}
		}
	}
}

/*
* 功能描述： 设置进路物理区段锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRoutePhySectionLockState(const UINT16 routeId, const UINT8 lockState)
{
	UINT8 phySecSum = 0U;  /*物理区段总数*/
	UINT8 curLockState = 0U;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0U;  /*需要处理有效进路ID*/
	UINT8 ii = 0U;  /*遍历变量*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT8 chKeepFlag = CI_ERROR;/*继续执行标志*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chRouteBelCiId = 0U;/*进路所属联锁ID*/
	UINT8 chRouteDir = 0U;/*进路方向*/
	UINT8 chRLockBelOtherCiFlag = CI_ERROR;/*进路属于其它联锁标志*/
	UINT8 chRouteBelOtherCiId = 0U;/*进路所属其它联锁ID*/

	phySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/
	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/

	if (NULL == pPhySecDataStru)
	{
		; /*不处理*/
	}
	else
	{
		chKeepFlag = CI_SUCCESS;
		chRouteDir = GetRouteDirection(routeId);
		for (ii = 0u; ii < phySecSum; ii++)
		{
			if (PHYSICAL_SECTION_LOCK_NORMAL == lockState)
			{ /*正常锁闭*/

				curLockState = 0u;
				curLockState = GetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId);  /*获取区段当前锁闭状态*/

				if ((PHYSICAL_SECTION_LOCK_NORMAL == curLockState)
					|| (PHYSICAL_SECTION_LOCK_DELAY == curLockState)
					|| (PHYSICAL_SECTION_LOCK_EXCEPT == curLockState))
				{ /*正常锁闭||延时解锁||故障锁闭*/

					validRouteId = GetPhySecRLockBelongRouteId(pPhySecDataStru[ii].PhysicalSectionId);  /*获取物理区段锁闭所属进路ID*/
					SetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, validRouteId, 0U);  /*设置区段未锁闭*/

					chRouteBelCiId = GetRouteBelongCiId(validRouteId);
					if ((chLocalCiId != chRouteBelCiId) && (0U != chLocalCiId))
					{
						chRouteBelOtherCiId = chRouteBelCiId;
						chRLockBelOtherCiFlag = CI_SUCCESS;
					}
					else
					{
						;
					}
				}
				else
				{
					;
				}

				SetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId, lockState, routeId, chRouteDir);  /*设置区段锁闭状态*/
			}
			else if (PHYSICAL_SECTION_LOCK_NO == lockState)
			{
				SetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId, lockState, routeId, chRouteDir);  /*设置区段锁闭状态*/
			}
			else if (PHYSICAL_SECTION_LOCK_EXCEPT == lockState)
			{
				SetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId, lockState, routeId, chRouteDir);  /*设置区段锁闭状态*/
			}
			else
			{
				/*其他状态不设置*/
				chKeepFlag = CI_ERROR;
			}
		}


		if ((CI_SUCCESS == chKeepFlag) && (0U < validRouteId) && (validRouteId != routeId) && (CI_ERROR == chRLockBelOtherCiFlag))
		{
			/*锁闭所属进路属于本控区*/
			/*处理本次进路办理冲掉的进路*/
			DealValidRouteState(validRouteId);
		}
		else if(CI_SUCCESS == chRLockBelOtherCiFlag)
		{
			AddCiSendToCiCmdInfo((UINT8)CI_CMD_ROUTE_SEC_LOCK_APPLY, routeId, validRouteId, chRouteBelOtherCiId);
		}
		else
		{
			; /*不处理*/
		}
	}
}

/*
* 功能描述： 设置进路关联防护道岔防护锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockCommand, 锁闭状态
* 返回值  ： void
*/
void SetRouteRelProSwitchLockSta(const UINT16 routeId, const UINT8 lockCommand)
{
	UINT8 ii = 0u;                                             /*遍历变量*/
	UINT8 retVal = CI_SUCCESS;                                /*返回值*/
	UINT16 protectSwitchId = 0u;                                      /*防护道岔ID*/
	UINT8 routeProtectSwitchSum = 0u; 	                      /*防护道岔数目*/
	RouteProtectSwitchStruct* routeProtectSwitchStru = NULL;  /*防护道岔数据*/
	
	routeProtectSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);      /*获取防护道岔数目*/
	routeProtectSwitchStru = GetRouteRelatedProtSwitchData(routeId);    /*获取防护道岔数据*/

	if (NULL == routeProtectSwitchStru)
	{
		retVal = CI_ERROR;
	}
	else
	{
	}

	if((SWITCH_LOCK_PROTECT_SET != lockCommand) && (SWITCH_LOCK_PROTECT_CANCEL != lockCommand))
	{
		retVal = CI_ERROR;
	}
	else
	{
	}

	if (CI_SUCCESS == retVal)
	{
		for (ii= 0u; ii < routeProtectSwitchSum; ii++)
		{
			protectSwitchId = routeProtectSwitchStru[ii].ProtectSwitchId;
			SetSwitchLockStatus(SWITCH_PLOCKTYPE_ROUTE,routeId,protectSwitchId, lockCommand);                        /*设置道岔防护锁闭状态*/
			/*RC 13.0.0 修：不检查防护道岔中双动道岔另一端*/
#if 0
			if (SWITCH_TYPE_DOUBLE == GetSwitchType(protectSwitchId))
			{ /*双动道岔*/
				SetSwitchLockStatus(SWITCH_PLOCKTYPE_ROUTE,routeId,GetDSwitchOtherId(protectSwitchId), lockCommand); /*设置道岔防护锁闭状态*/
			}
			else
			{
			}
#endif
		}
	} 
	else
	{
		retVal = CI_ERROR;
	}
}

/*
* 功能描述： 进路初选处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8   
*/
UINT8 RouteFirstXuanProc(const UINT16 routeId)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 localCiId = 0u;  /*本机联锁ID*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 waitSetFlag = 0u;  /*等待征用标志*/
	UINT8 waitCancelFlag = 0u;  /*等待取消征用标志*/
	UINT8 setFlag = 0u;  /*征用标志*/
	UINT8 cancelFlag = 0u;  /*未征用标志*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT8 chAllPhyBelCiCheck = CI_ERROR;/*进路内方物理区段所属联锁检查*/
	UINT8 reval = CI_ERROR;
	UINT8 chPhySecUseState = 0U;/*物理区段征用状态*/
	UINT8 chRouteProSwitchSum = 0U; 							/*防护道岔数目*/
	RouteProtectSwitchStruct* pRouteProtectSwitchStru = NULL;    /*防护道岔数据*/
	UINT16 wProSwRelPhySecId = 0U;/*防护道岔关联物理区段ID*/


	localCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	phySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/
	chRouteProSwitchSum = GetRouteRelatedProtectSwitchSum(routeId);
	pRouteProtectSwitchStru = GetRouteRelatedProtSwitchData(routeId);


	if ((0u == localCiId) || (NULL == pPhySecDataStru) || (NULL == pRouteProtectSwitchStru))
	{
		reval = CI_ERROR;
	}
	else
	{
		reval = CI_SUCCESS;
	}

	if (CI_SUCCESS == reval)
	{
		for (ii = 0u; ii < phySecSum; ii++)
		{
			chPhySecUseState = GetPhySecUseState(pPhySecDataStru[ii].PhysicalSectionId);

			if (PHYSICAL_SECTION_USING_APPLY == chPhySecUseState)
			{
				waitSetFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_CANCEL == chPhySecUseState)
			{
				waitCancelFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_YES == chPhySecUseState)
			{
				setFlag = 1u;
			}
			else
			{
				cancelFlag = 1u;
			}
		}

		for (ii = 0u; ii < chRouteProSwitchSum; ii++)
		{
			wProSwRelPhySecId = GetSwitchPhySectionId(pRouteProtectSwitchStru[ii].ProtectSwitchId);
			chPhySecUseState = GetPhySecUseState(wProSwRelPhySecId);

			if (PHYSICAL_SECTION_USING_APPLY == chPhySecUseState)
			{
				waitSetFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_CANCEL == chPhySecUseState)
			{
				waitCancelFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_YES == chPhySecUseState)
			{
				setFlag = 1u;
			}
			else
			{
				cancelFlag = 1u;
			}
		}

		if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (0u == cancelFlag))
		{ /*征用*/

			reval = CI_SUCCESS;
		}
		else if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (0u == setFlag) && (1u == cancelFlag))
		{  /*未征用*/

			reval = CI_ERROR;
		}
		else if ((1u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (0u == cancelFlag))
		{  /*征用&&等待征用*/

			reval = RETURN_FIRSTXUANPAI_ERR_WAIT;
		}
		else if ((0u == waitSetFlag) && (1u == waitCancelFlag) && (0u == setFlag) && (1u == cancelFlag))
		{  /*未征用&&等待取消征用*/

			reval = RETURN_FIRSTXUANPAI_ERR_WAIT;
		}
		else if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (1u == cancelFlag))
		{  /*征用&&未征用*/

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

			reval = CI_ERROR;
		}
		else
		{
			chAllPhyBelCiCheck = RouteAllPhyBelongCiCheck(routeId);
			if (CI_SUCCESS == chAllPhyBelCiCheck)
			{/*by cgh 20230606 - 成都27出段进路属于车辆段，区段全部属于正线特殊需求*/

				if ((1U == waitSetFlag) && (0U == waitCancelFlag) && (0U == setFlag) && (0U == cancelFlag))
				{  /*等待征用*/

					reval = RETURN_FIRSTXUANPAI_ERR_WAIT;
				}
				else if ((0U == waitSetFlag) && (1U == waitCancelFlag) && (0U == setFlag) && (0U == cancelFlag))
				{  /*等待取消征用*/

					reval = RETURN_FIRSTXUANPAI_ERR_WAIT;
				}
				else
				{
					/*设置进路物理区段未征用*/
					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
					reval = CI_ERROR;
				}
			}
			else
			{
				/*设置进路物理区段未征用*/
				SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
				reval = CI_ERROR;
			}
		}
	}
	return reval;
}

/*
* 功能描述： 物理区段故障解锁逻辑管理
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： void
*/
void PhySecFaultUnlockLogicManage(const UINT16 phySectionId,const UINT8 virCIid)
{
	UINT8 phySecLockState = 0U;     /*物理区段状态*/
	UINT16 lockBelongRouteId = 0U;  /*区段锁闭所属进路ID*/
	UINT8 routeBelongCi = 0U;/*进路所属联锁*/
	UINT8 routeState = 0U;          /*进路状态*/
	UINT8 localCiId = 0U;           /*本地联锁ID*/
	UINT8 localCiType = GetLocalCiType();
	UINT16 routeLastSwiPhySecId = 0U;    /*进路最远端道岔区段ID*/
	UINT8 routeAutoSig = 0U;/*进路自动信号属性*/
	UINT8 recoverFlag = 0U;/*恢复标志*/
	UINT8 phyFaultUnLockRes = 0U;/*物理区段故障解锁处理结果*/
	UINT8 routeDir = 0U;/*进路方向*/
	UINT8 routePhySecHaveUnLock = 0U;/*进路区段是否已解锁*/
	UINT8 routeType = 0U;/*进路类型*/

	UINT8 phyBelongCi = 0U;/*区段所属联锁*/
	UINT8 commState = 0U;/*通信状态*/
	/*支持继电接口功能开关是否已打开*/
	UINT8 funcSwitchSupportRelayInterface = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	UINT8 confirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	UINT8 neighbourCi = 0U;/*相邻联锁ID*/
	UINT8 havePhySecFromNeighbourCi = 0U;/*是否有区段属于相邻联锁*/

	UINT8 goExec = CI_ERROR;
	UINT8 autoTriggerType = 0U;
	UINT8 belongvirCIid = 0U;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT16 wLogLockBelongRouteId = 0U;  /*逻辑区段锁闭所属进路ID*/
	UINT8 ii = 0U;
	UINT8 chPhyAllUnlockFlag = 0U;/*物理区段包含逻辑区段需要全部解锁标志*/
	UINT8 chRouteLogSecHaveUnLock = 0U;/*逻辑区段锁闭所属进路的区段已经全部解锁*/

	if ((0u == phySectionId) || (phySectionId >= PHYSICAL_SECTION_SUM_MAX))
	{
		/*物理区段ID无效*/
		goExec = CI_ERROR;
	}
	else
	{
		/*物理区段是否可以继续区故解检查*/
		goExec = PhySecFaultUnlockRouteCheck(phySectionId, virCIid);
	}
		
	if (CI_SUCCESS == goExec)
	{
		lockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId);  /*获取物理区段进路锁闭所属进路ID*/
		LogRouteErrLockFaultManage(phySectionId);/*逻辑进路区故解处理*/
		DelayErrLockCmdDeal(phySectionId);/*任意位置折返后下发区故解命令，延时设置区段故障处理*/
		localCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
		routeBelongCi = GetRouteBelongCiId(lockBelongRouteId);


		if ((localCiId == routeBelongCi)&& (localCiId > 0u))
		{/*进路属于本联锁*/
			
			goExec = CheckPhySecFaultUnlockCanDo(phySectionId,virCIid);
			if(CI_SUCCESS == goExec)
			{
				routeState = GetRouteState(lockBelongRouteId);
				if ((ROUTE_STATE_YUXIAN_OPEN == routeState) ||
					(ROUTE_STATE_NEAR_OPEN == routeState))
				{ /*进路状态为 预先开放||接近开放*/
					routeAutoSig = GetRouteAutoSigProperty(lockBelongRouteId);
					if(ROUTE_AUTOSIG_PROPERTY_YES != routeAutoSig)
					{
						(void)DriveSignalClose(GetRouteStartSignalId(lockBelongRouteId));  /*驱动信号关闭*/

						/*设置进路自动进路无效*/
						SetAutoRouteSetFlag(GetRouteAutoRouteId(lockBelongRouteId), AUTO_ROUTE_SET_NO);
						SetAutoReturnSetFlag(GetRouteAutoReturnId(lockBelongRouteId), AUTO_RETURN_SET_NO);
						SetAllAutoReturnSetFlag(GetRouteAllAutoReturnId(lockBelongRouteId), ALL_AUTO_RETURN_SET_NO);
						autoTriggerType = GetAutoTriggerType(lockBelongRouteId);
						if (ROUTE_TYPE_AUTO_TRIGGER == autoTriggerType)
						{/*虚拟联锁兼容*/
							SetRouteAutoTriggerFlag(lockBelongRouteId, AUTO_TRIGGER_SET_NO);
						}
					}
				}
				else if (ROUTE_STATE_LEAD_OPEN == routeState)
				{/*进路状态为 引导开放*/
					(void)DriveSignalClose(GetRouteStartSignalId(lockBelongRouteId));  /*驱动信号关闭*/
				}
				else
				{
					phySecLockState = GetPhySecLockState(phySectionId);  /*获取物理区段锁闭状态*/
					/* 优化代码：判断如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到区故解命令时进行清除重开标志 */
					recoverFlag = GetRouteRecoverOpenFlag(lockBelongRouteId);
					if(ROUTE_RECOVER_STA_WAIT == recoverFlag)
					{/*重开等待时，区段故障锁闭，清除重开标志*/
						SetRouteOpenSigStartCycNum(lockBelongRouteId, 0u);  /*重置信号开放时间*/

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

						SetRouteXianSuConfirmStt(lockBelongRouteId, ROUTE_XIANSU_CONFIRM_NO);

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

					if ((PHYSICAL_SECTION_LOCK_EXCEPT != phySecLockState) && (ROUTE_STATE_HALF_UNLOCKDELAY != routeState))
					{/*物理区段锁闭状态不为"异常锁闭"*/
						SetCiSendCmdBackInfoData(CI_BACK_PSEC_QGJ_UNLOCK, CI_DEVICE_TYPE_PHYSEC, phySectionId, 0u, 0u);
					}
					else
					{/*区段为故障锁闭时*/
						if ((ROUTE_STATE_AUTO_UNLOCKERR == routeState) || (ROUTE_STATE_IDLE == routeState))
						{
							/*本联锁办理一条进路包含相邻联锁的物理区段，此时本联锁宕机。相邻联锁会将此物理区段设置为故障锁闭。
							在本联锁重启后，相邻联锁将此物理区段的故障锁闭状态发给本联锁。本联锁将此物理区段锁闭状态更新为
							异常锁闭，本联锁此条进路状态在重启后更新为	ROUTE_STATE_IDLE。为了能区故解此物理区段，加入
							ROUTE_STATE_IDLE == routeState此条件
							*/

							/*正常情况下区故解绿光带*/
							phyFaultUnLockRes = PhySecFaultUnlockLogicProcess(phySectionId);
							if (CI_SUCCESS == phyFaultUnLockRes)
							{ /*成功*/
								routeDir = GetRouteDirection(lockBelongRouteId);
								chPhyIncLogSum = GetPhySecIncLogSecSum(phySectionId);
								pPhyIncLogId = GetPhySecIncLogSecIdBuf(phySectionId);
								SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_NO, lockBelongRouteId, routeDir);  /*设置物理区段未锁闭*/

								if (NULL != pPhyIncLogId)
								{
									for (ii = 0U; ii < chPhyIncLogSum; ii++)
									{
										wLogLockBelongRouteId = GetLogSecLockBelongRoute(pPhyIncLogId[ii]);
										if (lockBelongRouteId != wLogLockBelongRouteId)
										{
											chPhyAllUnlockFlag = 1U;
											break;
										}
									}
								}
								if (1U != chPhyAllUnlockFlag)
								{
									/*同时设置物理区段其他属于本进路锁闭的逻辑区段未锁闭*/
									SetPhyIncludeLogLockState(phySectionId, LOG_SECTION_LOCK_NO, lockBelongRouteId);
								}
								else
								{
									/*同时设置物理区段所有的逻辑区段未锁闭*/
									SetPhyIncAllLogLockState(phySectionId, LOG_SECTION_LOCK_NO);
								}

								chRouteLogSecHaveUnLock = CheckRouteLogSecHaveUnLock(wLogLockBelongRouteId);
								if (CI_SUCCESS == chRouteLogSecHaveUnLock)
								{
									/*全部区段解锁*/
									SetRouteStateManage(wLogLockBelongRouteId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
								}

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

								havePhySecFromNeighbourCi = RouteHavePhySecBelongOtherCi(lockBelongRouteId, &neighbourCi);
							
								if ((1u== havePhySecFromNeighbourCi) && (neighbourCi > 0u))
								{/*进路存在其它联锁的区段*/
									commState = GetLocalCiAndOtherCiTransSta(neighbourCi);

								}
								if ((1U== havePhySecFromNeighbourCi) && (neighbourCi > 0u) &&
									(TRANSMIT_STATE_BAD == commState) &&
									(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
									(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
								{/*有其它联锁的区段,且本联锁与该联锁通信中断，且支持继电接口功能开关已打开，且继电接口已确认*/
									routePhySecHaveUnLock = CheckLocalCiRoutePhySecUnLock(lockBelongRouteId);
								}
								else
								{
									routePhySecHaveUnLock = CheckRoutePhySecHaveUnLock(lockBelongRouteId);
								}
								if (CI_SUCCESS == routePhySecHaveUnLock)
								{
									/*设置进路自动进路无效*/
									SetAutoRouteSetFlag(GetRouteAutoRouteId(lockBelongRouteId), AUTO_ROUTE_SET_NO);

									SetAutoReturnSetFlag(GetRouteAutoReturnId(lockBelongRouteId), AUTO_RETURN_SET_NO);
									
									SetAllAutoReturnSetFlag(GetRouteAllAutoReturnId(lockBelongRouteId), ALL_AUTO_RETURN_SET_NO);
									
									if (ROUTE_TYPE_AUTO_TRIGGER == GetAutoTriggerType(lockBelongRouteId))
									{/*虚拟联锁兼容*/
										SetRouteAutoTriggerFlag(lockBelongRouteId, AUTO_TRIGGER_SET_NO);
									}

									SetRouteStateManage(lockBelongRouteId, ROUTE_STATE_IDLE);  /*区段全部解锁，设置进路空闲*/
								}
								else
								{
									/*车辆段,若当前区段为调车进路的非最后一个区段，区故解当前区段后，相邻区段为无岔区段则带动解锁*/
									routeType = GetRouteType(lockBelongRouteId);
									if ((CI_TYPE_CLD == localCiType) && (ROUTE_TYPE_DIAOCHE == routeType))
									{/*车辆段调车进路内区段区故解特殊处理*/
										(void)CLDPhySectionFaultUnlockDeal(phySectionId,lockBelongRouteId);
									}
								}

							}

						}
					}
				}
			}
			
		}
		else if ((localCiId != routeBelongCi) && (localCiId > 0u))
		{/*进路不为本联锁，且本联锁ID合法*/
			/*继电接口下，区故解区段属于本联锁，但区段锁闭所属进路属于相邻联锁，需检查：
			1. 区段属于本联锁	/
			2. 继电接口已配置	/
			3. 继电接口已确认	/
			4. 本联锁与进路所属联锁通信中断	/
			5. 区故解检查通过：PhySecFaultUnlockLogicProcess	
				1~5通过，可以区故解此区段；
			6. 如果进路属于本联锁的区段都空闲，且未锁闭，进路状态设为空闲。
			*/
			phyBelongCi = GetPhySecBelongCiId(phySectionId);

			commState = GetLocalCiAndOtherCiTransSta(routeBelongCi);

			if ((phyBelongCi == localCiId) && (TRANSMIT_STATE_BAD == commState) && 
				(CICI_RELAY_INTERFACE_CONFIRM_YES == confirmRelayInterfaceFlag)&&
				(FUNC_SWITCH_ON == funcSwitchSupportRelayInterface))
			{
				phyFaultUnLockRes = PhySecFaultUnlockLogicProcess(phySectionId);
				if (CI_SUCCESS == phyFaultUnLockRes)
				{ /*成功*/
					routeDir = GetRouteDirection(lockBelongRouteId);
					SetPhySecLockState(phySectionId, PHYSICAL_SECTION_LOCK_NO, lockBelongRouteId, routeDir);  /*设置物理区段未锁闭*/
					/*同时设置物理区段其他属于本进路锁闭的逻辑区段未锁闭*/
					SetPhyIncludeLogLockState(phySectionId,LOG_SECTION_LOCK_NO,lockBelongRouteId);
					routeLastSwiPhySecId = GetRouteLastSwichPhySecId(lockBelongRouteId);
					if (phySectionId == routeLastSwiPhySecId)
					{/*解锁进路关联防护道岔*/
						SetRouteRelProSwitchLockSta(lockBelongRouteId, SWITCH_LOCK_PROTECT_CANCEL);/*取消进路关联防护道岔的防护锁闭*/ 
					}

					/*继电接口下检查非本联锁的进路内，属于本联锁的物理区段是否都已解锁*/
					routePhySecHaveUnLock = CheckNoLocalCiRoutePhySecUnLock(lockBelongRouteId);
					if (CI_SUCCESS == routePhySecHaveUnLock)
					{
						SetRouteStateManage(lockBelongRouteId, ROUTE_STATE_IDLE);  /*全部区段解锁，设置进路空闲*/
					}
					else
					{
						/*车辆段,若当前区段为调车进路的非最后一个区段，区故解当前区段后，相邻区段为无岔区段则带动解锁*/
						routeType = GetRouteType(lockBelongRouteId);
						if ((CI_TYPE_CLD == localCiType) && (ROUTE_TYPE_DIAOCHE == routeType))
						{/*车辆段调车进路内区段区故解特殊处理*/
							(void)CLDPhySectionFaultUnlockDeal(phySectionId,lockBelongRouteId);
						}
					}

				
				}
			}
			else if((phyBelongCi == localCiId)&&(TRANSMIT_STATE_GOOD == commState))
			{
				if(FUNC_SWITCH_ON == includeVirFlag)
				{
					belongvirCIid = GetPhySecBelongVirCiId(phySectionId);
					if((belongvirCIid == virCIid)&&(0u != virCIid))/*区故解可以由相邻虚拟联锁现地操作，不相邻不能操作*/
					{
						/*进路属于相邻联锁，且区段属于本联锁时，传递区段故障解锁命令	*/	
						AddCiSendToCiCmdInfo(CI_CMD_SECTION_FAULT_UNLOCK,phySectionId,0u,routeBelongCi);
					}
				}
				else
				{
					/*进路属于相邻联锁，且区段属于本联锁时，传递区段故障解锁命令	*/	
					AddCiSendToCiCmdInfo(CI_CMD_SECTION_FAULT_UNLOCK,phySectionId,0u,routeBelongCi);
				}
			}
			else
			{
               	/*异常情况，不处理区故解命令*/
			}
		}
		else
		{/*异常情况，不处理*/

		}
		
	}
	
}

/*
* 功能描述： 将进路内第一个占用的物理区段之前的区段设置成异常锁闭
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void SetRoutePhySecExpLockToOccupy(const UINT16 routeId)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 ii = 0u;  /*遍历变量*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/


	phySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/


	if  (NULL == pPhySecDataStru)
	{
		return;
	}
	else
	{
	    ;
	}


	for (ii = 0u; ii < phySecSum; ii++)
	{
		if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(pPhySecDataStru[ii].PhysicalSectionId))/*判断放到前面，保证当前占用的区段不会被置成异常锁闭*/
		{
			break;
		}
		else
		{
		    ;
		}

		SetPhySecLockState(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/

		/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
		SetPhyIncludeLogLockState(pPhySecDataStru[ii].PhysicalSectionId,LOG_SECTION_LOCK_EXCEPT,routeId);
	}
}

/*
* 功能描述：判断进路始端信号机内外方物理区段同时占压
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_ERROR：非同时占压
*            CI_SUCCESS：同时占压
*/
UINT8 RouteInOutSecOccupy(const UINT16 routeId)
{
	UINT16 startSigId = 0u;     /*进路始端信号机ID*/
	UINT16 outPhySecId = 0u;    /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u;     /*信号机内方第一区段ID*/

	UINT8 retResult = CI_ERROR;

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

	if (0u == startSigId)
	{
		retResult = CI_ERROR;
	}
	else
	{
		inPhySecId = GetSignalInFirstPhySecId(startSigId,routeId);    /*信号机内方第一物理区段ID*/
		outPhySecId = GetSignalOutFirstPhySecId(startSigId);  /*信号机外方第一物理区段ID*/

		if (0u == inPhySecId)
		{
			retResult = CI_ERROR;
		}
		else
		{
			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(inPhySecId))
			{ /*内方区段占用*/

				if (0u == outPhySecId)
				{
					retResult = CI_SUCCESS;
				}
				else
				{
					if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(outPhySecId))
					{ /*外方区段占用*/

						retResult = CI_SUCCESS;
					}
				}
			}
		}
	}

	return retResult;
}

/*
* 功能描述： 判断是否需要清除列车驶入进路标志，如果需要清除，则清除
* 参数说明： const UINT16 routeId，进路ID
* 返回值  ： void
*/
void TryClearRouteTrainEnterFlag(UINT16 routeId)
{
	UINT16 tempDevId = 0u;    /*设备ID*/
	UINT8 tempDevSta = 0u;     /*设备状态*/

	if (0u != routeId)
	{
		/*如果进路状态为空闲，或是进路内所有物理区段均没有占用，则清除列车驶入标志*/
		if (ROUTE_STATE_IDLE == GetRouteState(routeId))
		{
			SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_NO);
		}
		else
		{
			if (CI_SUCCESS == RouteAllSecOccuClearCheck(routeId, &tempDevId, &tempDevSta))
			{
				SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_NO);
			}
		}
	}
}

#if 0
/*
* 功能描述： 扣车、SPKS、PSD导致信号关闭又重开处理
* 参数说明： const UINT16 routeId，进路ID
* 返回值  ： void
*/
void RouteAutoReOpenProc(const UINT16 routeId)
{
	UINT8 routeState;     /*进路状态*/
	UINT16 startSig;      /*进路始端信号机ID*/
	UINT16 *psdBuf = NULL;   /*信号机关联的PSD ID数组*/
	UINT8 psdSum = 0u;        /*信号机关联的PSD数目*/

	UINT8 psdFlag = 0u;
	UINT8 detainFlag = 0u;
	UINT8 spksFlag = 0u;
	UINT8 toOpenFlag = 0u;
	UINT8 i;
	UINT16 psdCloseRoute, psdReOpenRoute;

	if (0u != routeId)
	{
		routeState = GetRouteState(routeId);
		startSig = GetRouteStartSignalId(routeId);
		psdBuf = GetSignalRelatedPsdBuf(startSig);
		psdSum = GetSignalRelatedPsdSum(startSig);
		/*只认为此种场景正常，判断第一个逻辑区段空闲是为了对列车闯红灯进行监控*/
		if (((ROUTE_STATE_NEAR_LOCKERR == routeState) || (ROUTE_STATE_YUXIAN_LOCK == routeState)) && (GetLogSecCurOccupyState(GetRouteInFirstLogSecId(routeId)) == LOGICSECTION_OCCUPY_NO))
		{
			if ((NULL == psdBuf)|| (0u == psdSum))
			{
				psdFlag = 1u;
			}
			else
			{
				psdFlag = 1u;
				for (i = 0u;i < psdSum;i++)
				{
					psdCloseRoute = GetPsdClosedRouteId(psdBuf[i]);
					psdReOpenRoute = GetPsdToBeOpenedRoute(psdBuf[i]);

					if (routeId == psdReOpenRoute)
					{
						/*一次有效，需清除psd导致信号重开的进路状态*/
						SetPsdToBeOpenedRoute(psdBuf[i], 0u);
						toOpenFlag = 1u;/*有重开场景需求*/
					}
					else
					{
						if ((0u == psdReOpenRoute) && (0u == psdCloseRoute))
						{
							/*do nothing*/
						}
						else
						{/*PSD未恢复*/
							psdFlag = 0u;

							break;
						}
					}
				}
			}

			detainFlag = 1u;
			if (ROUTE_DETAIN_RE_OPEN_SIG_YES == GetRouteDetainReOpenSigFlag(routeId))
			{
				/*一次有效*/
				SetRouteDetainReOpenSigFlag(routeId, ROUTE_DETAIN_RE_OPEN_SIG_NO);
				toOpenFlag = 1u;/*有重开场景需求*/
			}
			else
			{
				if (ROUTE_DETAIN_CLOSE_SIG_YES == GetRouteDetainToRouteCloseFlag(routeId))
				{/*扣车未恢复*/
					detainFlag = 0u;
				}
			}

			spksFlag = 1u;
			if (ROUTE_SPKS_RE_OPEN_SIG_YES == GetRouteSpksReOpenSigFlag(routeId))
			{
				/*一次有效*/
				SetRouteSpksReOpenSigFlag(routeId, ROUTE_SPKS_RE_OPEN_SIG_NO);
				toOpenFlag = 1u;/*有重开场景需求*/
			}
			else
			{
				if (ROUTE_CLOSE_SPKS_YES == GetSPKSToRouteCloseFlag(routeId))
				{/*spks未恢复*/
					spksFlag = 0u;
				}
			}

			if ((1u == psdFlag) && (1u == detainFlag) && (1u == spksFlag) && (1u == toOpenFlag))
			{
				SetRouteOpenSigStartCycNum(routeId, Get2oo2CurCycleNum());
				SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_YES);/*设置进路信号重开标志*/
			}
		}
		else
		{
			/*自动重开信号的场景已经不再满足，需要清除所有关于自动重开信号的标记*/
			SetSPKSToRouteCloseFlag(routeId, ROUTE_CLOSE_SPKS_NO);
			SetRouteSpksReOpenSigFlag(routeId, ROUTE_SPKS_RE_OPEN_SIG_NO);

			SetRouteDetainCloseFlag(routeId, ROUTE_DETAIN_CLOSE_SIG_NO);
			SetRouteDetainReOpenSigFlag(routeId, ROUTE_DETAIN_RE_OPEN_SIG_NO);

			if (NULL != psdBuf)
			{
				for (i = 0u;i < psdSum;i++)
				{
					psdCloseRoute = GetPsdClosedRouteId(psdBuf[i]);
					psdReOpenRoute = GetPsdToBeOpenedRoute(psdBuf[i]);

					if ((routeId == psdCloseRoute) || (routeId == psdReOpenRoute))
					{
						SetPsdClosedRouteId(psdBuf[i], 0u);
						SetPsdToBeOpenedRoute(psdBuf[i], 0u);
					}
				}
			}
		}
	}
}
#endif
/*
* 功能描述： 进路异常锁闭物理区段传递
* 参数说明： const UINT16 routeId，进路ID
* 返回值  ：无
*/
void RouteExpLockContinue(UINT16 routeId)
{
	UINT16 dwRouteLogSum = 0U; /*获得进路包含的逻辑区段数目*/
	UINT16* pRouteLogId = NULL; /*进路包含逻辑区段ID*/
	UINT16 i = 0U;
	UINT16 wFirstNormalLockLogId = 0U;/*第一个正常锁闭的逻辑区段id*/
	UINT8 chLogSecState = 0U;/*逻辑区段锁闭状态*/
	UINT16 wLockRouteId = 0U;/*逻辑区段锁闭所属进路ID*/
	UINT16 wRelativePhySecId = 0U;/*逻辑区段所属物理区段*/
	UINT16 wRelativePhyLockRoute = 0U;   /*逻辑区段关联物理区段锁闭所属进路*/

	/*如果进路第一个占用的物理区段以前的所有物理区段已经没有绿光带，则需要将第一个正常锁闭的白光带置成绿光带，保证用户能继续解锁*/
	dwRouteLogSum = GetRouteLogSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteLogId = GetRouteLogSectionIdBuf(routeId); /*进路区段数据*/

	for (i = 0u;i < dwRouteLogSum;i++)
	{
		chLogSecState = GetLogSecLockState(pRouteLogId[i]);
		wLockRouteId = GetLogSecLockBelongRoute(pRouteLogId[i]);

		if ((LOG_SECTION_LOCK_NORMAL == chLogSecState) && (wLockRouteId == routeId))
		{
			if (0u == wFirstNormalLockLogId)
			{
				wFirstNormalLockLogId = pRouteLogId[i];/*记录进路内第一个处于正常锁闭的物理区段*/
			}
		}

		if (((LOG_SECTION_LOCK_EXCEPT == chLogSecState)) && (wLockRouteId == routeId))
		{
			break;
		}
	}

	if (i == dwRouteLogSum)
	{/*说明进路内已经不存在绿光带*/
		if (0u != wFirstNormalLockLogId)
		{
			wRelativePhySecId = GetLgcSecRelativePhySecId(wFirstNormalLockLogId);
			wRelativePhyLockRoute = GetPhySecRLockBelongRouteId(wRelativePhySecId);
			if (SECTION_OCCUPY_NO == GetPhySecCurMergeState(wRelativePhySecId))
			{
				if (routeId == wRelativePhyLockRoute)
				{/*逻辑区段所属物理区段锁闭所属进路为本进路，则同时设置物理区段异常锁闭*/
					SetPhySecLockState(wRelativePhySecId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));
				}
				else
				{
					/*不同时进行物理区段故障锁闭处理*/
				}
				/*同时设置物理区段其他属于本进路锁闭的逻辑区段异常锁闭*/
				SetPhyIncludeLogLockState(wRelativePhySecId,LOG_SECTION_LOCK_EXCEPT,routeId);
			}
		}
	}
}

/*
* 功能描述： SPKS、PSD、扣车恢复重开信号处理
* 参数说明： const UINT16 routeId，进路ID
* 返回值  ： void
*/
void RouteRecoverOpenProc(const UINT16 routeId)
{
	UINT8 routeState;     /*进路状态*/
	UINT8 recoverState = ROUTE_RECOVER_STA_STAY;/*当前恢复重开状态*/
	UINT8 errType = CI_ERROR;
	UINT8 localCiType = GetLocalCiType();/*获得联锁类型*/
	UINT16 wStartSignalId = 0U;  /*进路始端信号机ID*/

	routeState = GetRouteState(routeId);
	recoverState = GetRouteRecoverOpenFlag(routeId);

	if ((ROUTE_STATE_NEAR_LOCKERR == routeState) || (ROUTE_STATE_YUXIAN_LOCK == routeState) || (ROUTE_STATE_FIRST_LOCKERR == routeState))
	{
		if (ROUTE_RECOVER_STA_WAIT == recoverState)
		{
			if ((CI_TYPE_ZX == localCiType) || (CI_TYPE_SCX == localCiType))
			{
				errType = RecoverOpenRouteCheck(routeId);
			}
			else
			{
				errType = RecoverOpenRouteCheckCLD(routeId);
			}
			
			wStartSignalId = GetRouteStartSignalId(routeId);  /*获取进路始端信号机ID*/
			if (errType == CI_SUCCESS)
			{
				SetRouteOpenSigStartCycNum(routeId, Get2oo2CurCycleNum());
				SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_YES);  /*设置进路信号重开标志*/

				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);/*一次有效，防止反复重开*/
			}
			else if (errType == CI_ROUTE_RECOVER_ERR)
			{
				/*继续等待*/
			}
			else
			{
				SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);/*一旦出现PSD、SPKS、扣车以外的条件不满足，将进路恢复状态设置为不可恢复*/

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

}

/* 功能描述： ATS或现地锁闭保护区段命令处理
* 参数说明： const UINT16 expLkOverlapId, ATS或现地发送的期望锁闭区段ID
* 返回值  ： void
*/
void SetAtsExpectLockOverlapIdProc(const UINT16 expLkOverlapId,const UINT8 lockType)
{
	/*遍历所有进路，判断进路是否包含该保护区段，且进路状态是否满足锁闭保护区段条件，
		若成立，则设置进路的期望锁闭保护区段。*/
	UINT16 routeCurSum = 0u;	/*进路总数目*/
	UINT16 ii = 0u;
	UINT16 routeOverlapSum = 0u;	/*进路保护区段数目*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT16 routedLockOverlapId = 0u;	/*进路锁闭过OverlapId*/
	UINT8 retVal = CI_SUCCESS;	/*执行检查*/
	UINT8 routeState = 0u;	/*进路状态*/
	UINT16 preOverlepId = 0u;
	UINT32 startXuanPaiCyc = 0u;
	UINT16 phySectionId = 0u;
	UINT8 phySectionSta = 0u;
	UINT8 flag = 0u;
	UINT8 belongCiId = 0u;
	UINT8 localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 virCIid = 0u;
	UINT8 ciCtrModeFlag = 0u;

	if ((0u == expLkOverlapId) || (UINT16_MAX == expLkOverlapId))
	{/*判断输入参数有效性*/
		retVal = CI_ERROR;
	}

	/*判断是否要传递保护区段建立命令给相邻联锁*/
	if (CI_SUCCESS == retVal)
	{
	     belongCiId =  GetOverlapBelongCiId(expLkOverlapId);

		 if(localCiId != belongCiId)
		 {
		    if(0u < belongCiId)
			{
				AddCiSendToCiCmdInfo(CI_CMD_LOCK_OVERLAP_CMD,expLkOverlapId,lockType,belongCiId);/*发送相邻联锁保护区段建立命令*/		
		    }
			retVal = CI_ERROR;
		 }
	}

	if (CI_SUCCESS == retVal)
	{
		routeCurSum = GetRouteCurSum();		        /*获取进路总数*/

		for (ii = 0u; ii < routeCurSum; ii++)
		{
			routeId = GetRouteId(ii);                           /*获取进路ID*/

			if ((0u == routeId) || (routeId > ROUTE_SUM_MAX))
			{
				/*进路ID无效，继续执行*/
			}
			else
			{
				routeOverlapSum = GetRouteOverlapSum(routeId);	/*获取进路包含的保护区段数目*/

				if (routeOverlapSum >= 1u)
				{/*只有当进路的保护区段数目大于等于1个时，ATS或现地才发送期望锁闭保护区段ID*/
					/*输入参数保护区段ID是否属于当前进路 且进路保护区段未锁闭过*/
					if (1u == checkExpOverlapBelongToRtOrNot(routeId,expLkOverlapId))
					{/*期望锁闭的保护区段ID属于进路的保护区段ID*/
					    flag = 1u;/*有任意一条匹配到了，则置为1*/
						retVal = CI_SUCCESS;
					}
					else
					{
						retVal = CI_ERROR;
					}

					/*add by shl*/
					if (retVal == CI_SUCCESS)
					{
						preOverlepId = GetRouteAtsExpLkOverlapId(routeId);

						if (preOverlepId > 0u)
						{
							startXuanPaiCyc = GetOverlapXuanPaiStartCycNum(preOverlepId);
							if (startXuanPaiCyc > 0u)
							{
								retVal = CI_ERROR;
							}
						}
					}
					/*判断当前保护区段所属联锁控制模式是否可以响应锁闭保护区段命令*/
					if (CI_SUCCESS == retVal)
					{
						virCIid= GetOverlapBelongVirCiId(expLkOverlapId);
						if(FUNC_SWITCH_ON == includeVirFlag)
						{
							ciCtrModeFlag = GetVirCImode(virCIid);/*获取联锁控制模式*/
						}	
						else
						{
							ciCtrModeFlag = GetCiModeFlag();	/*获取联锁控制模式*/
						}

						if((CI_MODE_CI_LOCAL ==ciCtrModeFlag)||(0u ==ciCtrModeFlag))/*处于联锁控或者获取错误，发送现地不能响应人工锁闭命令*/
						{
							retVal = CI_ERROR;
						}
					}

					/*add by shl*/

					if (CI_SUCCESS == retVal)
					{

						routedLockOverlapId = GetRouteOverlapLockedId(routeId);	/*获取进路锁闭过保护区段ID*/

						if (0u == routedLockOverlapId)
						{
							/*判断进路状态，是否满足锁闭保护区段条件，若满足则设置期望锁闭保护区段*/
							routeState = GetRouteState(routeId);

							if ((routeState == ROUTE_STATE_FIRST_XUANPAI) ||
								(routeState == ROUTE_STATE_XUANPAI) ||
								(routeState == ROUTE_STATE_FIRST_LOCK) ||
								(routeState == ROUTE_STATE_FIRST_LOCKERR) ||
								(routeState == ROUTE_STATE_YUXIAN_OPEN) ||
								(routeState == ROUTE_STATE_YUXIAN_LOCK) ||
								(routeState == ROUTE_STATE_NEAR_OPEN) ||
								(routeState == ROUTE_STATE_NEAR_LOCK) ||
								(routeState == ROUTE_STATE_NEAR_LOCKERR) ||
								(routeState == ROUTE_STATE_AUTO_UNLOCK) ||
								(routeState == ROUTE_STATE_HALF_UNLOCK)
								)
							{/*设置指定ID进路的期望锁闭保护区段ID*/
							    if(LABOR_LOCK_OVERLAP == lockType)/*人工锁闭*/
								{
									SetOverlapAtsOrlaborLockCmdFlag(expLkOverlapId,LOCK_OVERLAP_CMD_YES);/*设置保护区段锁闭命令标志，用于保护区段解锁倒计时计算*/
									SetOverlaplaborLockCmdFlag(expLkOverlapId,LOCK_OVERLAP_CMD_YES);/*设置人工锁闭标志，用于人工命令一次有效处理*/
								}
								else if(ATS_LOCK_OVERLAP == lockType)/*ATS锁闭*/
								{ 
								    phySectionId = GetRouteLastPhySectionId(routeId);
									phySectionSta = GetPhySecCurMergeState(phySectionId);
									if(SECTION_OCCUPY_YES==phySectionSta)
									{
										SetOverlapAtsOrlaborLockCmdFlag(expLkOverlapId,LOCK_OVERLAP_CMD_YES);/*设置保护区段锁闭命令标志*/
									}
								}
								else
								{
									/*什么也不做*/
								}
								SetRouteAtsExpLkOverlapId(routeId,expLkOverlapId);
								SetOverlapFromSetRouteCmdFlag(expLkOverlapId, OVERLAP_ROUTE_FLAG_NO);/*清除标志*/
								retVal = CI_SUCCESS;
							}
							else
							{
								retVal = CI_ERROR;
							}
							

						}
						
					}

				}
			}
		}
		if(0U == flag)
		{/*发送的这个区段不属于任何进路的保护区段或者进路的期望锁闭保护区段未设置上*/
		 /*发送现地*/
			SetErrorData(EFUNC_SetAtsExpectLockOverlapIdProc, CI_DEVICE_TYPE_OVERLAP, expLkOverlapId, ETYPE_ROUTE_OVERLAP_UNLOCK, 0U, ESEND_LEVEL_ATS);
		}
		
	}
}

/*
* 功能描述： 物理区段故障解锁检查
* 参数说明： const UINT16 phySectionId, 物理区段ID
*           const UINT8 virCIid  操作的Rtu(虚拟联锁现地)  ID  
* 返回值  ： CI_ERROR CI_SUCCESS
*/
UINT8 CheckPhySecFaultUnlockCanDo(const UINT16 phySectionId,const UINT8 virCIid)
{
	UINT16 lockBelongRouteId = 0u;  /*区段锁闭所属进路ID*/
	UINT8 reVal = CI_ERROR;
	UINT8 belongvirCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 isErrLock = CI_ERROR;   
	UINT8 phyLockState = 0U;


	if ((0u == phySectionId) || (PHYSICAL_SECTION_SUM_MAX <= phySectionId))
	{
		/*物理区段ID无效*/
		reVal = CI_ERROR;
	}
	else
	{
		lockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId);  /*获取物理区段进路锁闭所属进路ID*/

		if ((0u == lockBelongRouteId) || (ROUTE_SUM_MAX <= lockBelongRouteId))
		{
			/*锁闭所属进路ID无效*/
			reVal = CI_ERROR;
		}
		else
		{
			reVal = CI_SUCCESS;
		}
	}
	if(CI_SUCCESS == reVal)
	{
		if(FUNC_SWITCH_ON == includeVirFlag)
		{
			belongvirCIid = GetRouteBelongVirCiId(lockBelongRouteId);
			if(0u < virCIid)
			{
				if(virCIid == belongvirCIid)
				{	
					reVal = CI_SUCCESS;	/*本Rtu(虚拟联锁现地)可以操作属于本虚拟联锁的进路锁闭的物理区段区故解，无论该物理区段是否属于该Rtu*/
				}
				else
				{
					belongvirCIid = GetPhySecBelongVirCiId(phySectionId);
					if(belongvirCIid == virCIid)
					{
						reVal = CI_SUCCESS;/*本虚拟联锁物理区段由相邻虚拟联锁进路锁闭的，可以在该物理区段所属Rtu上操作区故解*/	
					}
					else
					{
						reVal = CI_ERROR;
					}
				}
			}
			else
			{
				reVal = CI_ERROR;
			}

		}
		else  
		{
			reVal = CI_SUCCESS;
		}
	}	

	/*按顺序解锁进路异常锁闭*/
	if (CI_SUCCESS == reVal)
	{
		isErrLock = RouteFirstLockErrCheck(lockBelongRouteId);
		phyLockState = GetPhySecLockState(phySectionId);
		/*第一个锁闭的区段是故障锁闭*/
		if (CI_SUCCESS == isErrLock )
		{
			/*命令下达的区段为故障锁闭*/
			if (PHYSICAL_SECTION_LOCK_EXCEPT == phyLockState)
			{
				/*可解锁，继续检查余下条件*/
			}
			else
			{
				/*失败，报警未按顺序解锁*/
				reVal = CI_ERROR;
				SetCiSendCmdBackInfoData(CI_BACK_PSEC_QGJ_LOCKERROR, CI_DEVICE_TYPE_PHYSEC, phySectionId, 0U, 0U);
			}
		}
		else
		{
			/*继续执行*/
		}
	}

	return reVal;
}

/*
* 功能描述： 设置进路逻辑区段锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRouteLogSectionLockState(const UINT16 routeId, const UINT8 lockState)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT8 curLockState = 0u;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0u;
	UINT8 routeDir = 0u;
	UINT8 validRouteDir = 0u;
	UINT8 chTrainSum = 0U;
	LogicTrainResStruct stTmpResInfo[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	LogicTrainResStruct *pstLgcResInfo = NULL;
	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetRouteLogSectionSum(routeId);
	pLogIdBuff = GetRouteLogSectionIdBuf(routeId);
	routeDir = GetRouteDirection(routeId);


	/*检查数据合法*/
	if((0u != logSectionSum) && (NULL != pLogIdBuff))
	{
		for(i = 0u; i < logSectionSum; i++)
		{
			/*正常锁闭*/
			if(LOG_SECTION_LOCK_NORMAL == lockState)
			{
				curLockState = 0u;
				/*获取当前锁闭状态*/
				curLockState = GetLogSecLockState(pLogIdBuff[i]);
				/*区段正常锁闭或延时解锁*/
				if((LOG_SECTION_LOCK_NORMAL == curLockState) || (LOG_SECTION_LOCK_DELAY == curLockState))
				{
					validRouteId = GetLogSecLockBelongRoute(pLogIdBuff[i]);
					validRouteDir = GetRouteDirection(validRouteId);
					/*设置区段锁闭所属之前进路未锁闭*/
					chTrainSum = GetLogSecTrainInfoSum(pLogIdBuff[i]);
					pstLgcResInfo = GetLogSecTrainInfo(pLogIdBuff[i]);
					if (NULL != pstLgcResInfo)
					{
						(void)ComMemCopy(pstLgcResInfo, stTmpResInfo,(UINT16)(sizeof(LogicTrainResStruct)*LOGIC_SECTION_RES_SUM_MAX));
					}
					SetLogSecLockState(pLogIdBuff[i],LOG_SECTION_LOCK_NO,validRouteId,validRouteDir);/*设置区段锁闭所属之前进路未锁闭*/
				}

				/*设置区段属于当前进路锁闭*/
				SetLogSecLockState(pLogIdBuff[i],LOG_SECTION_LOCK_NORMAL,routeId,routeDir);
				
				if (NULL != pstLgcResInfo)
				{
					CpyLgcSecResTrain(pLogIdBuff[i], chTrainSum, stTmpResInfo);/*拷贝逻辑区段列车资源信息*/
				}
			}
			/*设置区段未锁闭*/
			else if(LOG_SECTION_LOCK_NO == lockState)
			{
				SetLogSecLockState(pLogIdBuff[i],LOG_SECTION_LOCK_NO,routeId,routeDir);
			}
			/*设置区段故障锁闭*/
			else if (LOG_SECTION_LOCK_EXCEPT == lockState)
			{
				SetLogSecLockState(pLogIdBuff[i],LOG_SECTION_LOCK_EXCEPT,routeId,routeDir);
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* @brief ： 设置进路公共资源标志
* @param ： const UINT16 wRouteId, 进路ID
*           const UINT8 chShrFlag, 共享状态
* @return  ： void
*/
void SetRouteLgcSecShareFlag(const UINT16 wRouteId, const UINT8 chShrFlag)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT8 chLogLockState = 0u;

	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetRouteLogSectionSum(wRouteId);
	pLogIdBuff = GetRouteLogSectionIdBuf(wRouteId);

	/*检查数据合法*/
	if ((MAX_ROUTE_IN_LT_NUM >logSectionSum)
		&& (NULL != pLogIdBuff))
	{
		/*参数合法*/
		for (i = 0u; i < logSectionSum; i++)
		{
			if (LOGIC_SECTION_RES_SHARE_NO == chShrFlag)
			{/*进路解锁时，区段无锁闭才置非公共资源*/
				chLogLockState = GetLogSecLockState(pLogIdBuff[i]);
				if (LOG_SECTION_LOCK_NO == chLogLockState)
				{
					/*设置逻辑区段共享资源标志*/
					SetLogSecResShareFlag(pLogIdBuff[i], chShrFlag);
				}
				else
				{
					; /*被锁闭时不置非公共资源*/
				}
			}
			else
			{
				/*设置逻辑区段共享资源标志*/
				SetLogSecResShareFlag(pLogIdBuff[i], chShrFlag);
			}	
		}

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

/*
* @brief ： 设置进路保护区段公共资源标志
* @param ： const UINT16 wRouteId, 进路ID
*			 const UINT16 wOverlapId 保护区段ID
*           const UINT8 chShrFlag, 共享状态
* @return  ： void
*/
void SetRouteOvlpOtherCiShrFlg(const UINT16 wRouteId, const UINT16 wOverlapId,const UINT8 chShrFlag)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 wOverlapIncLgcIdSum = 0U;
	UINT16 *pOverLapIncLgcIdBuf = NULL;
	UINT16 wRouteLockedOverlapId = 0U;
	UINT8 chOverlapBelongCiId = 0U;
	UINT8 chLocalCiId = 0U;

	chLocalCiId = GetSystemParaLocalCiId();

	
	wRouteLockedOverlapId = GetRouteOverlapLockedId(wRouteId);
	chOverlapBelongCiId = GetOverlapBelongCiId(wRouteLockedOverlapId);
	

	if ((0U != wRouteLockedOverlapId) && (wOverlapId== wRouteLockedOverlapId))
	{
		if ((chLocalCiId == chOverlapBelongCiId)
			&& (0U != chLocalCiId))
		{
			wOverlapIncLgcIdSum = GetOverlapLogicSectionSum(wRouteLockedOverlapId);
			pOverLapIncLgcIdBuf = GetOverlapLogicSectionBuf(wRouteLockedOverlapId);

			if ((OVLP_LOGICSECTION_SUM_MAX > wOverlapIncLgcIdSum)
				&& (NULL != pOverLapIncLgcIdBuf))
			{
				for (i = 0u; i < wOverlapIncLgcIdSum; i++)
				{
					/*设置保护区段逻辑区段共享资源标志*/
					SetLogSecResShareFlag(pOverLapIncLgcIdBuf[i], chShrFlag);
				}
			}
		}
		else
		{
			; /*无需操作*/
		}
	}
}

/*
* 功能描述： 根据进路状态，清理相关标志
* 参数说明： const UINT16 routeId 进路ID
* 返回值  ： void
* cgh-合并CID-2341-5：
*/
void ClearSomeFlagDependRouteState(const UINT16 routeId)
{
	UINT8 routeState = GetRouteState(routeId);
	UINT16 startSignalId = 0u;
	UINT16  EnginVehicCroCloBelongRoute = 0u;

	/*清理工程车跨压关信号所属进路,清理工程车跨压状态*/
	if ((ROUTE_STATE_YUXIAN_LOCK != routeState)
		&& (ROUTE_STATE_NEAR_LOCK != routeState)
		&& (ROUTE_STATE_NEAR_LOCKERR != routeState)
		&& (ROUTE_STATE_DELAY_UNLOCK != routeState)
		&& (ROUTE_STATE_AUTO_UNLOCK != routeState)
		&& (ROUTE_STATE_AUTO_UNLOCKERR != routeState)
		&& (ROUTE_STATE_LEAD_LOCK != routeState)
		&& (ROUTE_STATE_LEAD_LOCKERR != routeState)
		&& (ROUTE_LONG_STATE_LOCK != routeState))/*进路不处于锁闭状态*/
	{

		startSignalId = GetRouteStartSignalId(routeId);
		EnginVehicCroCloBelongRoute = GetEnginVehicCroCloBelongRoute(startSignalId);

		if (EnginVehicCroCloBelongRoute == routeId)
		{
			SetSigEnginVehicCrossCloseSte(startSignalId, ENGIN_VEHIC_CROSSCLOSE_STE_NO);/*根据进路状态，清理工程车跨压状态*/
			SetEnginVehicCroCloBelongRoute(startSignalId, 0u);/*清理工程车跨压关信号所属进路*/
		}

	}

	/*若进路不以下状态，清除进路的组合进路命令标志*/
	if ((ROUTE_STATE_YUXIAN_LOCK != routeState)
		&& (ROUTE_STATE_NEAR_LOCK != routeState)
		&& (ROUTE_STATE_FIRST_LOCK != routeState)
		&& (ROUTE_STATE_FIRST_LOCKERR != routeState)
		&& (ROUTE_STATE_NEAR_LOCKERR != routeState)
		&& (ROUTE_STATE_YUXIAN_OPEN != routeState)
		&& (ROUTE_STATE_NEAR_OPEN != routeState)
		)/*进路不处于初锁，初锁异常，预先锁闭，预先开放，接近锁闭，接近开放，接近锁闭异常*/
	{
		SetRouteGroupRouteCmdFlag(routeId, ROUTE_GROUPROUTE_CMD_NO);	/*清除进路的组合进路命令标志*/
	}
}

/*
* 功能描述： 任意位置折返后下发区故解命令，延时设置区段故障处理
* 参数说明： const UINT16 phySectionId  物理区段ID
* 返回值  ： void
* cgh-20230508创建
*/
void DelayErrLockCmdDeal(const UINT16 phySectionId)
{
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT8 ii = 0U;               /*物理区段包含逻辑区段循环索引*/
	UINT16 wLogLockBelongRouteId = 0U;  /*逻辑区段锁闭所属进路ID*/
	UINT8 chLogSecLockState = 0U;     /*逻辑区段锁闭状态*/
	UINT16 wFirstNormalLockLogId = 0U;     /*进路第一个锁闭得逻辑区段ID*/
	UINT8 chLogLockRouteState = 0U;      /*逻辑区段锁闭所属进路状态*/
	UINT16 wPhyLockBelongRouteId = 0U;/*物理区段锁闭所属进路*/
	UINT8 chPhyLockState = 0U;/*物理区段锁闭状态*/
	UINT8 chPhyLockRouteState = 0U;/*物理区段锁闭所属进路状态*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段融合状态*/


	chPhyIncLogSum = GetPhySecIncLogSecSum(phySectionId);
	pPhyIncLogId = GetPhySecIncLogSecIdBuf(phySectionId);
	wPhyLockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId);
	chPhySecCurMergeState = GetPhySecCurMergeState(phySectionId);
	chPhyLockState = GetPhySecLockState(phySectionId);

	if ((NULL != pPhyIncLogId) && (SECTION_OCCUPY_NO == chPhySecCurMergeState))
	{
		for (ii = 0U; ii < chPhyIncLogSum; ii++)
		{
			wLogLockBelongRouteId = GetLogSecLockBelongRoute(pPhyIncLogId[ii]);
			if (wLogLockBelongRouteId >= ROUTE_SUM_MAX)
			{
				/*锁闭所属进路ID无效*/
				break;
			}
			else
			{
				/*继续以下逻辑*/
			}

			chLogLockRouteState = GetRouteState(wLogLockBelongRouteId);
			chLogSecLockState = GetLogSecLockState(pPhyIncLogId[ii]);
			wFirstNormalLockLogId = GetRouteFirstNormalLockLogId(wLogLockBelongRouteId);
			if ((ROUTE_STATE_HALF_UNLOCK == chLogLockRouteState) && (LOG_SECTION_LOCK_NORMAL == chLogSecLockState) && (wFirstNormalLockLogId == pPhyIncLogId[ii]))
			{
				/*该逻辑区段锁闭所属进路处于等待人工解锁&&正常锁闭&&该逻辑区段是对应进路第一个锁闭的逻辑区段,则将该区段开始故障解锁计时，并设置对应进路状态*/
				/*设置进路状态为逻辑区段延时故障锁闭状态；进路第一个锁闭的逻辑区段延时设置区段故障起始周期号*/
				SetRouteStateManage(wLogLockBelongRouteId, ROUTE_STATE_HALF_UNLOCKDELAY);  

				/*by cgh 20231002 物理区段与当前逻辑区段锁闭所属进路不同，且当前只有一个逻辑区段处于锁闭状态，此时需要设置物理区段锁闭的进路状态为逻辑区段延时故障锁闭状态*/
				chPhyLockRouteState = GetRouteState(wPhyLockBelongRouteId);
				if ((0U != wPhyLockBelongRouteId) && (wLogLockBelongRouteId != wPhyLockBelongRouteId)
					&& (ROUTE_STATE_HALF_UNLOCK == chPhyLockRouteState) && (PHYSICAL_SECTION_LOCK_NORMAL == chPhyLockState))
				{
					SetRouteStateManage(wPhyLockBelongRouteId, ROUTE_STATE_HALF_UNLOCKDELAY);
				}

			}
			else
			{
				/*无操作*/
			}		
		}
	}
}


/*
* 功能描述： 设置进路部分锁闭物理区段锁闭状态, 需要先执行逻辑区段锁闭处理
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRouteHalfPhySectionLockState(const UINT16 routeId, const UINT8 lockState)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 curLockState = 0u;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0u;  /*需要处理有效进路ID*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 jj = 0U;
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT16 szRouteHalfPhySecData[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };
	UINT8 phyLgcSecSum = 0U;
	UINT8 keepWork = CI_ERROR;
	UINT16 *pPhyLgcSecBuf = NULL;
	UINT16 lgcRLockId = 0U;


	phySecSum = GetRouteHalfPhysicalSecData(routeId, szRouteHalfPhySecData);
	if (0u == phySecSum)
	{
		keepWork = CI_ERROR;
	}
	else
	{
		keepWork = CI_SUCCESS;

		for (ii = 0u; ii < phySecSum; ii++)
		{

			phyLgcSecSum = GetPhySecIncLogSecSum(szRouteHalfPhySecData[ii]);
			pPhyLgcSecBuf = GetPhySecIncLogSecIdBuf(szRouteHalfPhySecData[ii]);
			if (PHYSICAL_SECTION_LOCK_NORMAL == lockState)
			{ /*正常锁闭*/

				curLockState = 0u;
				curLockState = GetPhySecLockState(szRouteHalfPhySecData[ii]);  /*获取区段当前锁闭状态*/

				if ((PHYSICAL_SECTION_LOCK_NORMAL == curLockState)
					|| (PHYSICAL_SECTION_LOCK_DELAY == curLockState)
					|| (PHYSICAL_SECTION_LOCK_EXCEPT == curLockState))
				{ /*正常锁闭||延时解锁||故障锁闭*/
					for (jj = 0U; jj < phyLgcSecSum; jj++)
					{
						lgcRLockId = GetLogSecLockBelongRoute(pPhyLgcSecBuf[jj]);
						if ((0U == lgcRLockId) || (lgcRLockId == routeId))
						{
							; /*锁闭属于本进路或未锁闭，继续执行*/
						}
						else
						{
							break;
						}
					}

					if (jj == phyLgcSecSum)
					{
						validRouteId = GetPhySecRLockBelongRouteId(szRouteHalfPhySecData[ii]);  /*获取物理区段锁闭所属进路ID*/

						SetPhySecLockState(szRouteHalfPhySecData[ii], PHYSICAL_SECTION_LOCK_NO, validRouteId, GetRouteDirection(validRouteId));  /*设置区段未锁闭*/
						SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
					}
					else
					{
						; /*不执行*/
					}
				}
				else if((PHYSICAL_SECTION_LOCK_NO ==curLockState)||
					(PHYSICAL_SECTION_LOCK_PROTECT == curLockState))
				{
					SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
				}
				else
				{
					keepWork = CI_ERROR;
				}

			}
			else if (PHYSICAL_SECTION_LOCK_NO == lockState)
			{
				SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
			}
			else if (PHYSICAL_SECTION_LOCK_EXCEPT == lockState)
			{
				SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
			}
			else
			{
				/*其他状态不设置*/
				keepWork = CI_ERROR;
			}

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

	if (CI_SUCCESS == keepWork)
	{
		phySecSum = 0u;
		pPhySecDataStru = NULL;
		/*处理本次进路办理冲掉的进路*/
		if ((0u < validRouteId) && (validRouteId != routeId))
		{
			

			phySecSum = GetRoutePhysicalSectionSum(validRouteId);  /*获取进路物理区段总数*/
			pPhySecDataStru = GetRouteSectionData(validRouteId);  /*获取进路物理区段数据*/

			if ((0u == phySecSum) || (NULL == pPhySecDataStru))
			{
				keepWork = CI_ERROR;

			}
			else
			{
				;
			}
		}
		else
		{
			keepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == keepWork)
	{
		for (ii = 0u; ii < phySecSum; ii++)
		{

			if (validRouteId == GetPhySecRLockBelongRouteId(pPhySecDataStru[ii].PhysicalSectionId))
			{
				break;
			}
			else
			{
				;
			}
		}

		if (ii == phySecSum)
		{
			(void)SetRouteState(validRouteId, ROUTE_STATE_IDLE);
			/*取消进路关联防护道岔的防护锁闭*/
			SetRouteRelProSwitchLockSta(validRouteId, SWITCH_LOCK_PROTECT_CANCEL);

		}
	}
}

/*
* 功能描述： 设置进路部分物理区段征用状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 useState, 征用状态
* 返回值  ： 无
*/
void SetRouteHalfPhySecUsingState(const UINT16 routeId, const UINT8 setUseState)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 localCiId = 0u;  /*本机联锁ID*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT16 szPhySecData[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };
	UINT8 reVal = CI_ERROR;
	UINT16 routeProSwitchSum = 0u;/*进路防护道岔数量*/
	RouteProtectSwitchStruct szRouteProSwitchData[ROUTE_PROTECTSWI_SUM_MAX] = {0U};/*进路防护道岔数据*/
	UINT16 switchId = 0u;/*道岔ID*/
	UINT16 phyId = 0u;/*物理区段ID*/
	UINT8 curUseState = 0u;/*征用状态*/
	UINT8 phySecBelongId = 0u;/*物理区段所属联锁ID*/

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

	
	routeProSwitchSum = GetRouteHalfProSwData(routeId, szRouteProSwitchData);/*获取进路防护道岔数量*/

	if ((setUseState != PHYSICAL_SECTION_USING_YES) &&
		(setUseState != PHYSICAL_SECTION_USING_NO))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;

		if ((0u == localCiId) || (0u == phySecSum) )
		{
			reVal = CI_ERROR;
		}
	}



	if (CI_SUCCESS == reVal)
	{/*进路内的征用，与取消征用*/
		for (ii = 0u; ii < phySecSum; ii++)
		{
			phySecBelongId = GetPhySecBelongCiId(szPhySecData[ii]);
			curUseState = GetPhySecUseState(szPhySecData[ii]);


			if (PHYSICAL_SECTION_USING_YES == setUseState)
			{ /*设置区段征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/
				  /*直接设置区段征用*/
					SetPhySecUseState(szPhySecData[ii], PHYSICAL_SECTION_USING_YES, routeId);
				}
				else
				{
					/*非本联锁区段*/
					if (PHYSICAL_SECTION_USING_NO == curUseState)
					{/*当前征用状态为no*/
					 /*设置区段申请征用*/
						SetPhySecUseState(szPhySecData[ii], PHYSICAL_SECTION_USING_APPLY, routeId);
					}
					else
					{
						/*其他状态不设置*/

					}
				}
			}
			else
			{ /*设置区段未征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

				  /*设置区段未征用*/
					SetPhySecUseState(szPhySecData[ii], PHYSICAL_SECTION_USING_NO, routeId);
				}
				else
				{ /*非本联锁区段*/
					
					if ((PHYSICAL_SECTION_USING_YES == curUseState) ||
						(PHYSICAL_SECTION_USING_APPLY == curUseState))
					{/*进路初选时，进路办理条件不满足时办理失败，进路包含的相邻联锁区段为申请征用，也给相邻联锁发送取消征用申请*/
					 /*设置区段申请取消征用*/
						SetPhySecUseState(szPhySecData[ii], PHYSICAL_SECTION_USING_CANCEL, routeId);
					}
					else
					{
						/*其他状态不设置*/

					}
					
				}
			}
		}
	}

	if (CI_SUCCESS == reVal)
	{/*防护道岔所在区段征用与取消征用*/
		for (ii = 0u; ii < routeProSwitchSum; ii++)
		{
			switchId = szRouteProSwitchData[ii].ProtectSwitchId;

			phyId = GetSwitchPhySectionId(switchId);
			curUseState = GetPhySecUseState(phyId);
			phySecBelongId = GetPhySecBelongCiId(phyId);


			if (PHYSICAL_SECTION_USING_YES == setUseState)
			{ /*设置区段征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

				  /*设置区段防护征用*/
					SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_YES, routeId);
				}
				else
				{ /*非本联锁区段*/
					if (PHYSICAL_SECTION_USING_NO == curUseState)
					{
						/*设置区段申请征用*/
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_APPLY, routeId);
					}
					else
					{
						/*其他状态不设置*/

					}
				}
			}
			else
			{ /*设置区段未征用*/

				if (localCiId == phySecBelongId)
				{ /*本联锁区段*/

				  /*设置区段未征用*/
					SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_NO, routeId);
				}
				else
				{ /*非本联锁区段*/
					if ((PHYSICAL_SECTION_USING_YES == curUseState) ||
						(PHYSICAL_SECTION_USING_APPLY == curUseState))
					{/*进路初选时，进路办理条件不满足时办理失败，进路包含的相邻联锁区段为申请征用，也给相邻联锁发送取消征用申请*/
					 /*设置区段申请取消征用*/
						SetPhySecProtectUseState(phyId, PHYSICAL_SECTION_USING_CANCEL, routeId);
					}
					else
					{
						/*其他状态不设置*/

					}
				}
			}
		}
	}
}

/*
* 功能描述： 设置进路部分逻辑区段锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRouteHalfLogSecLockState(const UINT16 routeId, const UINT8 lockState)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT8 curLockState = 0u;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0u;
	UINT8 routeDir = 0u;
	UINT8 validRouteDir = 0u;
	UINT8 chTrainSum = 0U;
	UINT8 funcRet = 0U;
	LogicTrainResStruct stTmpResInfo[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	LogicTrainResStruct *pstLgcResInfo = NULL;
	/*获取进路包含逻辑区段信息*/
	logSectionSum =GetHalfRouteLockLgcSecSum (routeId);
	pLogIdBuff = GetHalfRouteLockLgcSecIdBuf(routeId);
	routeDir = GetRouteDirection(routeId);


	/*检查数据合法*/
	if ((0u != logSectionSum) && (NULL != pLogIdBuff))
	{
		for (i = 0u; i < logSectionSum; i++)
		{
			/*正常锁闭*/
			if (LOG_SECTION_LOCK_NORMAL == lockState)
			{
				funcRet = CheckLgcSecNotInTrainLoc(routeId, pLogIdBuff[i]);
				if (CI_SUCCESS == funcRet)
				{
					curLockState = 0u;
					/*获取当前锁闭状态*/
					curLockState = GetLogSecLockState(pLogIdBuff[i]);
					if ((LOG_SECTION_LOCK_NORMAL == curLockState) || (LOG_SECTION_LOCK_DELAY == curLockState))
					{
						validRouteId = GetLogSecLockBelongRoute(pLogIdBuff[i]);
						validRouteDir = GetRouteDirection(validRouteId);
						/*设置区段锁闭所属之前进路未锁闭*/
						chTrainSum = GetLogSecTrainInfoSum(pLogIdBuff[i]);
						pstLgcResInfo = GetLogSecTrainInfo(pLogIdBuff[i]);
						if (NULL != pstLgcResInfo)
						{
							(void)ComMemCopy(pstLgcResInfo, stTmpResInfo, (UINT16)(sizeof(LogicTrainResStruct)*LOGIC_SECTION_RES_SUM_MAX));
						}
						SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NO, validRouteId, validRouteDir);
					}

					/*设置区段属于当前进路锁闭*/
					SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NORMAL, routeId, routeDir);

					if (NULL != pstLgcResInfo)
					{
						CpyLgcSecResTrain(pLogIdBuff[i], chTrainSum, stTmpResInfo);
					}
				}
			}
			/*未锁闭*/
			else if (LOG_SECTION_LOCK_NO == lockState)
			{
				SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NO, routeId, routeDir);
			}
			/*故障锁闭*/
			else if (LOG_SECTION_LOCK_EXCEPT == lockState)
			{
				SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_EXCEPT, routeId, routeDir);
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* @brief ： 设置进路部分公共资源标志
* @param ： const UINT16 wRouteId, 进路ID
*           const UINT8 chShrFlag, 共享状态
* @return  ： void
*/
void SetRouteHalfLgcSecShareFlag(const UINT16 wRouteId, const UINT8 chShrFlag)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT8 chLogLockState = 0u;
	UINT8 funcRet = 0U;

	/*获取进路包含逻辑区段信息*/
	logSectionSum =GetHalfRouteLockLgcSecSum (wRouteId);
	pLogIdBuff = GetHalfRouteLockLgcSecIdBuf(wRouteId);


	/*检查数据合法*/
	if ((MAX_ROUTE_IN_LT_NUM >logSectionSum)
		&& (NULL != pLogIdBuff))
	{
		/*参数合法*/
		for (i = 0u; i < logSectionSum; i++)
		{
			funcRet = CheckLgcSecNotInTrainLoc(wRouteId, pLogIdBuff[i]);
			if (CI_SUCCESS == funcRet)
			{
				if (LOGIC_SECTION_RES_SHARE_NO == chShrFlag)
				{/*进路解锁时，区段无锁闭才置非公共资源*/
					chLogLockState = GetLogSecLockState(pLogIdBuff[i]);
					if (LOG_SECTION_LOCK_NO == chLogLockState)
					{
						/*设置逻辑区段共享资源标志*/
						SetLogSecResShareFlag(pLogIdBuff[i], chShrFlag);
					}
					else
					{
						; /*被锁闭时不置非公共资源*/
					}
				}
				else
				{
					/*设置逻辑区段共享资源标志*/
					SetLogSecResShareFlag(pLogIdBuff[i], chShrFlag);
				}
			}
		}

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

/*
*
* 功能描述： 设置进路部分防护道岔防护锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockCommand, 锁闭状态
* 返回值  ： void
*/
void SetRouteHalfProSwLockState(const UINT16 routeId, const UINT8 lockCommand)
{
	UINT8 ii = 0u;                                             /*遍历变量*/
	UINT16 protectSwitchId = 0u;                                      /*防护道岔ID*/
	UINT8 routeProtectSwitchSum = 0u; 	                      /*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = {0U};  /*防护道岔数据*/

	routeProtectSwitchSum =GetRouteHalfProSwData(routeId, routeProtectSwitchStru);      /*获取防护道岔数据*/

	if ((0U != routeProtectSwitchSum) 
		&& ((SWITCH_LOCK_PROTECT_SET == lockCommand) || (SWITCH_LOCK_PROTECT_CANCEL == lockCommand)))
	{

		for (ii = 0u; ii < routeProtectSwitchSum; ii++)
		{
			protectSwitchId = routeProtectSwitchStru[ii].ProtectSwitchId;
			SetSwitchLockStatus(SWITCH_PLOCKTYPE_ROUTE, routeId, protectSwitchId, lockCommand);                        /*设置道岔防护锁闭状态*/
			/*RC 13.0.0 修：不检查防护道岔中双动道岔另一端*/
#if 0
			if (SWITCH_TYPE_DOUBLE == GetSwitchType(protectSwitchId))
			{ /*双动道岔*/
				SetSwitchLockStatus(SWITCH_PLOCKTYPE_ROUTE, routeId, GetDSwitchOtherId(protectSwitchId), lockCommand); /*设置道岔防护锁闭状态*/
			}
			else
			{
			}
#endif
		}
	}
	else
	{
		; /*防护道岔为0或命令不合法不处理*/
	}
}

/*
* 功能描述： 进路初选处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8
*/
UINT8 RouteHalfFirstXuanProc(const UINT16 routeId)
{
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	UINT8 localCiId = 0u;  /*本机联锁ID*/
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 waitSetFlag = 0u;  /*等待征用标志*/
	UINT8 waitCancelFlag = 0u;  /*等待取消征用标志*/
	UINT8 setFlag = 0u;  /*征用标志*/
	UINT8 cancelFlag = 0u;  /*未征用标志*/
	UINT8 phySecUseStt = 0U;
	UINT16 szPhySecIdBuf[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };
	UINT8 retVal = CI_ERROR;
	UINT8 cPhySecBelongCiId = 0U;  /*物理区段所属CI*/
	UINT8 cPhyBelongOtherCiNum = 0U;  /*属于其它联锁的物理区段数量*/

	localCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	phySecSum =GetRouteHalfPhysicalSecData (routeId, szPhySecIdBuf);  /*获取进路物理区段总数*/
	
	if ((0u == localCiId) || (0U == phySecSum))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		for (ii = 0u; ii < phySecSum; ii++)
		{
			phySecUseStt = GetPhySecUseState(szPhySecIdBuf[ii]);
			if (PHYSICAL_SECTION_USING_APPLY == phySecUseStt)
			{
				waitSetFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_CANCEL == phySecUseStt)
			{
				waitCancelFlag = 1u;
			}
			else if (PHYSICAL_SECTION_USING_YES == phySecUseStt)
			{
				setFlag = 1u;
			}
			else
			{
				cancelFlag = 1u;
			}

			cPhySecBelongCiId = GetPhySecBelongCiId(szPhySecIdBuf[ii]);
			if ((cPhySecBelongCiId != localCiId) && (0U != cPhySecBelongCiId))
			{
				cPhyBelongOtherCiNum++;
			}
			else
			{
				/*不处理*/
			}
		}

		if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (0u == cancelFlag))
		{ /*征用*/

			retVal= CI_SUCCESS;
		}
		else if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (0u == setFlag) && (1u == cancelFlag))
		{  /*未征用*/

			retVal = CI_ERROR;
		}
		else if ((1u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (0u == cancelFlag))
		{  /*征用&&等待征用*/

			retVal = RETURN_FIRSTXUANPAI_ERR_WAIT;
		}
		else if ((0u == waitSetFlag) && (1u == waitCancelFlag) && (0u == setFlag) && (1u == cancelFlag))
		{  /*未征用&&等待取消征用*/

			retVal = RETURN_FIRSTXUANPAI_ERR_WAIT;
		}
		else if ((0u == waitSetFlag) && (0u == waitCancelFlag) && (1u == setFlag) && (1u == cancelFlag))
		{  /*征用&&未征用*/

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

			retVal = CI_ERROR;
		}
		else
		{
			if (phySecSum == cPhyBelongOtherCiNum)  /*半截进路包含的区段全属于其他联锁*/
			{
				if ((1U == waitSetFlag) && (0U == waitCancelFlag) && (0U == setFlag) && (0U == cancelFlag))
				{
					retVal = RETURN_FIRSTXUANPAI_ERR_WAIT;  /*等待取消征用*/
				}
				else if ((0U == waitSetFlag) && (1U == waitCancelFlag) && (0U == setFlag) && (0U == cancelFlag))
				{
					retVal = RETURN_FIRSTXUANPAI_ERR_WAIT;  /*等待取消征用*/
				}
				else
				{
					/*设置进路物理区段未征用*/
					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
					retVal = CI_ERROR;
				}
			}
			else
			{
				/*设置进路物理区段未征用*/
				SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);
				retVal = CI_ERROR;
			}
		}
	}

	return retVal;
}


/*
* 功能描述： 设置进路部分锁闭列车脚下锁闭状态
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRouteTrainLocLogSecState(const UINT16 routeId, const UINT8 lockState)
{
	/*变量初始化*/
	UINT16 i = 0u;
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT8 curLockState = 0u;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0u;
	UINT8 routeDir = 0u;
	UINT8 validRouteDir = 0u;
	UINT8 chTrainSum = 0U;
	UINT8 funcRet = 0U;
	LogicTrainResStruct stTmpResInfo[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	LogicTrainResStruct *pstLgcResInfo = NULL;
	UINT8 keepWork = CI_ERROR;
	UINT16 cPhySecId = 0U;
	UINT16 wPhySecRLockRouteId = 0U;  /*物理区段进路锁闭所属进路ID*/
	UINT16 wByLogSecDelRouteId = 0U;  /*通过逻辑区段冲掉的进路ID*/
	UINT16 wByPhySecDelRouteId = 0U;  /*通过物理区段冲掉的进路ID*/

	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetHalfRouteTrainLocLgcSecNum(routeId);
	pLogIdBuff = GetHalfRouteTrainLocLgcSecIdBuf(routeId);
	routeDir = GetRouteDirection(routeId);

	/*检查数据合法*/
	if ((0u != logSectionSum) && (NULL != pLogIdBuff))
	{
		for (i = 0u; i < logSectionSum; i++)
		{
			/*正常锁闭*/
			funcRet = CheckLgcSecInHalfRoute(routeId, pLogIdBuff[i]);
			if (CI_SUCCESS == funcRet)
			{
				if (LOG_SECTION_LOCK_NORMAL == lockState)
				{
					curLockState = 0u;
					/*获取当前锁闭状态*/
					curLockState = GetLogSecLockState(pLogIdBuff[i]);      
					if ((LOG_SECTION_LOCK_NORMAL == curLockState) || (LOG_SECTION_LOCK_DELAY == curLockState))
					{
						validRouteId = GetLogSecLockBelongRoute(pLogIdBuff[i]);
						validRouteDir = GetRouteDirection(validRouteId);
						/*设置区段锁闭所属之前进路未锁闭*/
						chTrainSum = GetLogSecTrainInfoSum(pLogIdBuff[i]);
						pstLgcResInfo = GetLogSecTrainInfo(pLogIdBuff[i]);
						if (NULL != pstLgcResInfo)
						{
							(void)ComMemCopy(pstLgcResInfo, stTmpResInfo, (UINT16)(sizeof(LogicTrainResStruct) * LOGIC_SECTION_RES_SUM_MAX));
						}
						SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NO, validRouteId, validRouteDir);

						cPhySecId = GetLgcSecRelativePhySecId(pLogIdBuff[i]);
						wPhySecRLockRouteId = GetPhySecRLockBelongRouteId(cPhySecId);
						if (validRouteId == wPhySecRLockRouteId)
						{
							/*原进路存在物理区段锁闭，不再通过逻辑区段冲掉原进路*/
							wByPhySecDelRouteId = validRouteId;

							if (wByLogSecDelRouteId == wPhySecRLockRouteId)
							{
								wByLogSecDelRouteId = 0U;  /*清除需要通过逻辑区段冲掉的进路*/
							}
							else
							{
								/*不处理*/
							}
						}
						else if ((validRouteId != wPhySecRLockRouteId) && ((0U == wByPhySecDelRouteId) || (wByPhySecDelRouteId != wByLogSecDelRouteId)))
						{
							wByLogSecDelRouteId = validRouteId;  /*YF0083-1953：当前逻辑区段锁闭但其关联的物理区段非原进路锁闭，需要在处理列车脚下逻辑区段时冲掉原进路*/
						}
						else
						{
							/*不处理*/
						}
					}

					/*设置区段属于当前进路锁闭*/
					SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NORMAL, routeId, routeDir);

					if (NULL != pstLgcResInfo)
					{
						CpyLgcSecResTrain(pLogIdBuff[i], chTrainSum, stTmpResInfo);
					}

					/*检查逻辑区段逻辑锁闭状态*/
					keepWork = LogSecLockInHalfRouteProcess(pLogIdBuff[i], routeId);
					if (CI_ERROR == keepWork)
					{
						break;		/*逻辑进路数量异常，不再处理*/
					}
				}
				/*未锁闭*/
				else if (LOG_SECTION_LOCK_NO == lockState)
				{
					SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_NO, routeId, routeDir);
				}
				/*故障锁闭*/
				else if (LOG_SECTION_LOCK_EXCEPT == lockState)
				{
					SetLogSecLockState(pLogIdBuff[i], LOG_SECTION_LOCK_EXCEPT, routeId, routeDir);
				}
				else
				{
					/*不做处理*/
				}
			}
		}

		if (0U != wByLogSecDelRouteId)
		{
			CleanOldRouteProcByLogSec(wByLogSecDelRouteId);  /*部分进路通过逻辑区段冲掉原进路处理*/
		}
		else
		{
			/*无需冲掉的进路，不处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 设置进路部分锁闭列车脚下物理区段锁闭状态, 需要先执行逻辑区段锁闭处理
* 参数说明： const UINT16 routeId, 进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetRouteTrainLocPhySecState(const UINT16 routeId, const UINT8 lockState)
{
	UINT8 phySecSum = 0U;  /*物理区段总数*/
	UINT8 curLockState = 0U;  /*区段当前锁闭状态*/
	UINT8 validRouteSum = 0U;
	UINT16 validRouteIdBuf[ROUTE_TRAIN_LOC_MAX_SUM] = {0U};  /*需要处理有效进路ID*/
	UINT16 validRouteId = 0U;
	UINT8 ii = 0u;  /*遍历变量*/
	UINT8 jj = 0U;
	UINT16 phySecRLockId = 0U;
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT16 szRouteHalfPhySecData[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };
	UINT8 phyLgcSecSum = 0U;
	UINT8 keepWork = CI_ERROR;
	UINT16 *pPhyLgcSecBuf = NULL;
	UINT16 lgcRLockId = 0U;

	UINT8 cLocalCiId = 0U;
	UINT8 cRouteBelongCiId = 0U;



	phySecSum = GetRouteTrainLocPhySecData(routeId, szRouteHalfPhySecData);
	if (0u == phySecSum)
	{
		keepWork = CI_ERROR;
	}
	else
	{
		keepWork = CI_SUCCESS;
	}

	if (CI_SUCCESS == keepWork)
	{
		for (ii = 0u; ii < phySecSum; ii++)
		{

			phyLgcSecSum = GetPhySecIncLogSecSum(szRouteHalfPhySecData[ii]);
			pPhyLgcSecBuf = GetPhySecIncLogSecIdBuf(szRouteHalfPhySecData[ii]);
			if (PHYSICAL_SECTION_LOCK_NORMAL == lockState)
			{ /*正常锁闭*/

				curLockState = 0u;
				curLockState = GetPhySecLockState(szRouteHalfPhySecData[ii]);  /*获取区段当前锁闭状态*/

				if ((PHYSICAL_SECTION_LOCK_NORMAL == curLockState) ||
					(PHYSICAL_SECTION_LOCK_DELAY == curLockState))
				{ /*正常锁闭||延时解锁*/
					for (jj = 0U; jj < phyLgcSecSum; jj++)
					{
						lgcRLockId = GetLogSecLockBelongRoute(pPhyLgcSecBuf[jj]);
						if ((0U == lgcRLockId) || (lgcRLockId == routeId))
						{
							; /*锁闭属于本进路或未锁闭，继续执行*/
						}
						else
						{
							break;
						}
					}

					validRouteId = GetPhySecRLockBelongRouteId(szRouteHalfPhySecData[ii]);  /*获取物理区段锁闭所属进路ID*/
																							/*记录有效进路ID*/
					if (jj == phyLgcSecSum)
					{
						SetPhySecLockState(szRouteHalfPhySecData[ii], PHYSICAL_SECTION_LOCK_NO, validRouteId, GetRouteDirection(validRouteId));  /*设置区段未锁闭*/
						SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/

					}
					else
					{

					}

					for (jj = 0U; jj < validRouteSum; jj++)
					{
						if ((validRouteId == validRouteIdBuf[jj])&&(validRouteId!= routeId))
						{
							/*去重添加*/
							break;
						}
					}

					if (validRouteSum == jj)
					{
						/*未重复*/
						if (ROUTE_TRAIN_LOC_MAX_SUM > validRouteSum)
						{
							validRouteIdBuf[validRouteSum++] = validRouteId;
						}
						else
						{
							keepWork = CI_ERROR;
						}
					}
				}
				else if (PHYSICAL_SECTION_LOCK_NO == curLockState)
				{
					SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
				}
				else
				{
					keepWork = CI_ERROR;
				}

			}
			else if (PHYSICAL_SECTION_LOCK_NO == lockState)
			{
				SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
			}
			else if (PHYSICAL_SECTION_LOCK_EXCEPT == lockState)
			{
				SetPhySecLockState(szRouteHalfPhySecData[ii], lockState, routeId, GetRouteDirection(routeId));  /*设置区段锁闭状态*/
			}
			else
			{
				/*其他状态不设置*/
				keepWork = CI_ERROR;
			}

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


	if (CI_SUCCESS == keepWork)
	{
		/*处理本次进路办理冲掉的进路*/
		for (ii = 0U; ii < validRouteSum; ii++)
		{
			if ((0u < validRouteIdBuf[ii]) && (validRouteIdBuf[ii] != routeId))
			{
				phySecSum = 0u;
				pPhySecDataStru = NULL;

				phySecSum = GetRoutePhysicalSectionSum(validRouteIdBuf[ii]);  /*获取进路物理区段总数*/
				pPhySecDataStru = GetRouteSectionData(validRouteIdBuf[ii]);  /*获取进路物理区段数据*/

				if ((0u == phySecSum) || (NULL == pPhySecDataStru))
				{
					keepWork = CI_ERROR;

				}
				else
				{
					for (jj = 0u; jj < phySecSum; jj++)
					{
						phySecRLockId = GetPhySecRLockBelongRouteId(pPhySecDataStru[jj].PhysicalSectionId);
						if (validRouteIdBuf[ii] == phySecRLockId)
						{
							break;
						}
						else
						{
							;
						}
					}

					cLocalCiId = GetSystemParaLocalCiId();
					cRouteBelongCiId = GetRouteBelongCiId(validRouteIdBuf[ii]);
					if (jj == phySecSum)
					{
						if ((0U != cLocalCiId) && (cLocalCiId == cRouteBelongCiId))
						{
							(void)SetRouteState(validRouteIdBuf[ii], ROUTE_STATE_IDLE);
							/*取消进路关联防护道岔的防护锁闭*/
							SetRouteRelProSwitchLockSta(validRouteIdBuf[ii], SWITCH_LOCK_PROTECT_CANCEL);
						}
						else
						{
							/*添加相邻联锁间命令，适配跨RC办动态进路*/
							AddCiSendToCiCmdInfo((UINT8)CI_CMD_ROUTE_SEC_LOCK_APPLY, routeId, validRouteIdBuf[ii], cRouteBelongCiId);
						}
					}
					else
					{
						if ((0U != cLocalCiId) && (cLocalCiId == cRouteBelongCiId))
						{
							(void)SetRouteState(validRouteIdBuf[ii], ROUTE_STATE_HALF_UNLOCK);
						}
						else
						{
							/*添加相邻联锁间命令，适配跨RC办动态进路*/
							AddCiSendToCiCmdInfo(CI_CMD_DR_ROUTE_STATE, validRouteIdBuf[ii], (UINT16)ROUTE_STATE_HALF_UNLOCK, cRouteBelongCiId);
						}
					}
				}
			}
		}
	}

	
}
/*
* 功能描述： 获取指定进路第一个正常锁闭的逻辑区段延时故障锁闭起始周期号
* 参数说明： const UINT16 routeId, 进路ID
*
* 返回值  ： 0:  获取失败
*			 >0: 进路第一个正常锁闭的逻辑区段延时故障锁闭起始周期号
*/
UINT32 GetRouFirDelayErlockStaCycNum(const UINT16 routeId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;
	UINT16 wFirstNormalLockLogId = 0U;

	bufIndex = GetRouteConfigBufIndex(routeId);  /*获取进路数组下标*/

	if (bufIndex < ROUTE_SUM_MAX)
	{
		wFirstNormalLockLogId = GetRouteFirstNormalLockLogId(routeId);
		retVal = GetLogDelayErrlockStartCycNum(wFirstNormalLockLogId);
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述： 设置指定进路第一个正常锁闭的逻辑区段延时故障锁闭起始周期号
* 参数说明：const UINT16 routeId, 进路ID
*			 const UINT32 startCycNum 起始周期号
* 返回值  ： 无
*
*/
void SetRouFirDelayErlockStaCycNum(const UINT16 routeId, const UINT32 startCycNum)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 wFirstNormalLockLogId = 0U;

	bufIndex = GetRouteConfigBufIndex(routeId);  /*获取进路数组下标*/

	if (bufIndex < ROUTE_SUM_MAX)
	{
		wFirstNormalLockLogId = GetRouteFirstNormalLockLogId(routeId);
		SetLogDelayErrlockStartCycNum(wFirstNormalLockLogId, startCycNum);
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：校验进路是否需要驱动声光报警器
* 参数说明：const UINT16 routeId 进路ID
* 返回值  ：无
*/
void RouteNeedDriveSGBJCheck(const UINT16 routeId)
{
	UINT8 ii = 0U;
	UINT16 wStartSigId = 0U;  /*进路始端信号机ID*/
	UINT16 wInStorePhySecId = 0U;  /*库内第一区段（列检库属性）*/
	UINT16 wOutStorePhySecId = 0U;  /*库外第一区段（非列检库属性）*/
	UINT8 cInStorePhySecCurOccState = 0U;  /*库内第一区段当前占用状态*/
	UINT8 cOutStorePhySecCurOccState = 0U;  /*库外第一区段当前占用状态*/
	UINT8 cOutStorePhySecPreOccState = 0U;  /*库外第一区段之前占用状态*/
	UINT16 wPhySecLockedBelongRoute = 0U;  /*物理区段锁闭所属进路*/
	UINT8 cRouteIncPhySecNum = 0U;  /*进路包含的物理区段数量*/
	RoutePhysicalSectionStruct* pRouteIncPhySecStr = NULL;  /*进路包含的物理区段数据*/
	UINT8 cPhySecLJKproperty = 0U;  /*列检库属性*/
	UINT16 wOutFstPhySecId = 0U;  /*进路外方第一区段ID*/
	UINT8 cOutFstPhySecCurOccState = 0U;  /*信号机外方第一区段当前占用状态*/
	UINT8 cRouteTrainEnterFlag = 0U;  /*进路列车驶入标志*/
	UINT8 cSGBJDelayOpenFlag = 0U;  /*进路声光报警延时开放标志*/
	UINT8 cPhySecLockState = 0U;  /*区段锁闭状态*/
	UINT8 cRouteDriveSGBJFlag = ROUTE_DRIVE_SGBJ_INVALID;  /*进路驱动声光报警标志*/
	UINT8 cDrivedSGBJFlag = ROUTE_HAS_DRIVED_SGBJ_INVALID;  /*进路驱动过声光报警标志*/
	
	if ((0U < routeId) && (ROUTE_SUM_MAX > routeId))
	{
		cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(routeId);
		cRouteIncPhySecNum = GetRoutePhysicalSectionSum(routeId);
		pRouteIncPhySecStr = GetRouteSectionData(routeId);

		if ((0U != cRouteIncPhySecNum) && (NULL != pRouteIncPhySecStr))
		{
			if (ROUTE_SGBJ_DELAY_OPEN_INVALID == cSGBJDelayOpenFlag)
			{
				/*进路内外方第一区段均不具有列检库属性的声光报警器驱动标志处理：占压库外方第一区段时需驱动声光报警器，列车驶入库内方第一区段后停止驱动声光报警器*/
				for (ii = 0U; ii < cRouteIncPhySecNum; ii++)
				{
					/*寻找进路内的库内外第一物理区段*/
					cPhySecLJKproperty = GetPhySecLjkFlag(pRouteIncPhySecStr[ii].PhysicalSectionId);  /*获取物理区段列检库属性*/
					if ((PHYSICAL_SECTION_LJK_YES == cPhySecLJKproperty) && (0U < ii))
					{
						/*找到第一个列检库区段，记录库内外方第一区段，停止遍历*/
						wInStorePhySecId = pRouteIncPhySecStr[ii].PhysicalSectionId;
						wOutStorePhySecId = pRouteIncPhySecStr[ii - 1U].PhysicalSectionId;
						break;
					}
					else
					{
						/*继续遍历*/
					}
				}

				if ((0U != wInStorePhySecId) && (0U != wOutStorePhySecId))
				{
					cInStorePhySecCurOccState = GetPhySecCurMergeState(wInStorePhySecId);
					cOutStorePhySecCurOccState = GetPhySecCurMergeState(wOutStorePhySecId);
					cOutStorePhySecPreOccState = GetPhySecPreMergeState(wOutStorePhySecId);

					/*根据库内外方区段占用状态设置是否驱动声光报警器*/
					if (SECTION_OCCUPY_NO != cOutStorePhySecCurOccState)
					{
						wPhySecLockedBelongRoute = GetPhySecRLockBelongRouteId(wOutStorePhySecId);
						if (wPhySecLockedBelongRoute == routeId)
						{
							/*库外第一区段非空闲且被进路锁闭，设置进路需驱动声光报警标志有效*/
							SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_VALID);
						}
						else
						{
							/*库外区段未被本进路锁闭，不驱动声光报警（修复缺陷YF0083-2338+YF0083-2299：列车1通过DG-A驶入AG1后，列车2通过DG-B驶入AG2时会驱动AG1声光报警问题）*/
						}
					}
					else if ((SECTION_OCCUPY_NO != cInStorePhySecCurOccState) && (SECTION_OCCUPY_NO != cOutStorePhySecPreOccState))
					{
						/*库内第一区段当前非空闲且库外第一区段之前非空闲，设置进路需驱动声光报警标志无效*/
						SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_INVALID);
					}
					else
					{
						/*不处理*/
					}
				}
				else
				{
					/*未找到库外第一区段，不处理*/
				}
			}
			else
			{
				/*进路内/外方第一区段均具有列检库属性的声光报警器驱动标志处理：进路锁闭则需驱动声光报警器，列车完全驶入进路后停止驱动声光报警器*/
				wStartSigId = GetRouteStartSignalId(routeId);  /*获取进路起始信号机ID*/
				wOutFstPhySecId = GetSignalOutFirstPhySecId(wStartSigId);  /*信号机外方第一物理区段ID*/

				if (0U != wOutFstPhySecId)
				{
					cOutFstPhySecCurOccState = GetPhySecCurMergeState(wOutFstPhySecId);
					cRouteTrainEnterFlag = GetRouteTrainEnterFlag(routeId);
					cRouteDriveSGBJFlag = GetRouteDriveSGBJFlag(routeId);  /*获取进路当前驱动声光报警标志*/

					/*根据进路列车驶入标志和外方第一区段占用状态设置是否驱动声光报警器*/
					if ((ROUTE_TRAIN_ENTER_FLAG_YES == cRouteTrainEnterFlag) && (SECTION_OCCUPY_NO == cOutFstPhySecCurOccState))
					{
						/*进路列车驶入标志有效且进路外方第一区段当前空闲，设置进路需驱动声光报警标志无效*/
						SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_INVALID);
						if (ROUTE_DRIVE_SGBJ_VALID == cRouteDriveSGBJFlag)
						{
							SetRouteHasDrivedSGBJFlag(routeId, ROUTE_HAS_DRIVED_SGBJ_VALID);  /*设置进路已驱动过声光报警*/
						}
						else
						{
							/*未驱动过，不处理*/
						}
					}
					else
					{						
						cPhySecLockState = GetPhySecLockState(pRouteIncPhySecStr[cRouteIncPhySecNum - 1U].PhysicalSectionId);  /*获取进路内方最后一个物理区段的锁闭状态*/
						if ((PHYSICAL_SECTION_LOCK_NORMAL != cPhySecLockState) && (SECTION_OCCUPY_NO == cOutFstPhySecCurOccState))
						{
							/*进路内方最后一区段不为正常锁闭，此时已清除列车驶入标志，需置声光报警标志无效，避免声光报警器在此时又被驱动*/
							SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_INVALID);
							if (ROUTE_DRIVE_SGBJ_VALID == cRouteDriveSGBJFlag)
							{
								SetRouteHasDrivedSGBJFlag(routeId, ROUTE_HAS_DRIVED_SGBJ_VALID);  /*设置进路已驱动过声光报警*/
							}
							else
							{
								/*未驱动过，不处理*/
							}
						}
						else
						{
							cDrivedSGBJFlag = GetRouteHasDrivedSGBJFlag(routeId);  /*进路驱动过声光报警标志*/
							if (ROUTE_HAS_DRIVED_SGBJ_INVALID == cDrivedSGBJFlag)
							{
								/*未驱动过声光报警器，列车未驶入或进路外方第一区段占用则设置进路需驱动声光报警标志有效*/
								SetRouteDriveSGBJFlag(routeId, ROUTE_DRIVE_SGBJ_VALID);
							}
							else
							{
								/*已驱动过，不再重新驱动：解决列车1从AG完全进入BG后，列车2又进入AG时，BG关联的声光报警再次报警问题*/
							}
						}
					}
				}
				else
				{
					/*获取外方区段ID失败，不处理*/
				}
			}
		}
		else
		{
			/*获取进路包含的物理区段，不处理*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}
}

/*
* 功能描述： 逻辑区段故障解锁逻辑管理
* 参数说明： const UINT16 wPhySectionId, 物理区段ID
* const UINT8 chVirCIid  操作的Rtu(虚拟联锁现地)  ID
* 返回值  ： void
* by cgh 20231002
*/
void LogicSecFaultUnlockLogicManage(const UINT16 wPhySectionId, const UINT8 chVirCIid)
{
	UINT8 ii = 0U;
	UINT8 chGoExec = CI_ERROR;
	UINT8 chPhyIncLogSum = 0U;/*物理区段包含的逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;/*物理区段包含的逻辑区段ID*/
	UINT16 wLogLockBelongRouteId = 0U;/*逻辑区段锁闭所属进路*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chRouteBelongCiId = 0U;/*进路所属联锁ID*/

	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	chPhyIncLogSum = GetPhySecIncLogSecSum(wPhySectionId);
	pPhyIncLogId = GetPhySecIncLogSecIdBuf(wPhySectionId);

	if (NULL != pPhyIncLogId)
	{
		/*逻辑进路区故解逻辑*/
		LogRouteErrLockFaultManage(wPhySectionId);

		for (ii = 0U; ii < chPhyIncLogSum; ii++)
		{
			wLogLockBelongRouteId = GetLogSecLockBelongRoute(pPhyIncLogId[ii]);
			if ((0U < wLogLockBelongRouteId) && (ROUTE_SUM_MAX > wLogLockBelongRouteId))
			{
				DelayErrLockCmdDeal(wPhySectionId);/*任意位置折返后下发区故解命令，延时设置区段故障处理*/
			}
			else
			{
				;
			}

			/*逻辑区段区故解正常逻辑*/
			chGoExec = CheckLogSecFaultUnlockCanDo(pPhyIncLogId[ii], chVirCIid);
			chRouteBelongCiId = GetRouteBelongCiId(wLogLockBelongRouteId);
			if ((chLocalCiId == chRouteBelongCiId) && (0U < chLocalCiId) && (CI_SUCCESS == chGoExec))
			{
				/*进路属于本联锁*/
				LocalCiLogSecFaultUnlockProcess(pPhyIncLogId[ii], chVirCIid);
			}
			else if ((chLocalCiId != chRouteBelongCiId) && (0U < chLocalCiId))
			{
				/*进路属于相邻联锁，物理区段属于本联锁*/
				OtherCiLogSecFaultUnlockProcess(pPhyIncLogId[ii], chVirCIid);
			}
			else
			{
				; /*异常情况，不处理*/
			}
		}
	}
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述： 逻辑区段故障解锁逻辑处理-进路属于本联锁
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* const UINT8 chVirCIid  操作的Rtu(虚拟联锁现地)  ID
* 返回值  ： void
* by cgh 20231002
*/
void LocalCiLogSecFaultUnlockProcess(const UINT16 wLogSectionId, const UINT8 chVirCIid)
{
	UINT16 wLogLockBelongRouteId = 0U;/*逻辑区段锁闭所属进路*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chRouteState = 0U;/*进路状态*/
	UINT8 chRouteAutoSig = 0U;/*进路自动信号属性*/
	UINT16 wRouteStartSigId = 0U;/*进路始端信号机ID*/
	UINT16 wRouteAutoRouteId = 0U;/*进路对应自动进路ID*/
	UINT16 wRouteAutoReturnId = 0U;/*进路对应自动折返进路ID*/
	UINT16 wRouteAllAutoReturnId = 0U;/*进路对应全自动折返进路ID*/
	UINT8 chAutoTriggerType = 0U;/*进路自动触发属性*/
	UINT8 chLogSecLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 chRouteRecoverFlag = 0U;/*进路信号重开标志*/
	UINT8 chLogFaultUnLockRes = 0U;/*逻辑区段故障解锁条件检查结果*/
	UINT8 chLogSecBelongRouteDir = 0U;/*逻辑区段锁闭所属进路方向*/
	UINT8 chHaveLogSecFromOtherCi = 0U;/*进路是否存在逻辑区段属于其他联锁*/
	UINT8 chNeighbourCi = 0U;/*相邻联锁ID*/
	UINT8 chCommState = 0U;/*和其他联锁通信状态*/
	UINT8 chFuncSwitch = 0U; 	/*相邻联锁是否支持继电接口*/
	UINT8 chConfirmRelayInterfaceFlag = 0U;/*继电接口确认状态*/
	UINT8 chRouteLogSecHaveUnLock = 0u;/*进路逻辑区段是否已解锁*/

	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	wLogLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
	chFuncSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	chConfirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	if ((0U < wLogLockBelongRouteId) && (ROUTE_SUM_MAX > wLogLockBelongRouteId))
	{
		chRouteState = GetRouteState(wLogLockBelongRouteId);
		chRouteAutoSig = GetRouteAutoSigProperty(wLogLockBelongRouteId);
		wRouteStartSigId = GetRouteStartSignalId(wLogLockBelongRouteId);
		wRouteAutoRouteId = GetRouteAutoRouteId(wLogLockBelongRouteId);
		wRouteAutoReturnId = GetRouteAutoReturnId(wLogLockBelongRouteId);
		wRouteAllAutoReturnId = GetRouteAllAutoReturnId(wLogLockBelongRouteId);
		chAutoTriggerType = GetAutoTriggerType(wLogLockBelongRouteId);

		if (((ROUTE_STATE_YUXIAN_OPEN == chRouteState) || (ROUTE_STATE_NEAR_OPEN == chRouteState)) && (ROUTE_AUTOSIG_PROPERTY_YES != chRouteAutoSig))
		{
			/*进路状态为预先开放或者接近开放，但不是自动信号*/
			(void)DriveSignalClose(wRouteStartSigId);  /*驱动信号关闭*/
			/*设置进路自动属性无效*/
			SetAutoRouteSetFlag(wRouteAutoRouteId, AUTO_ROUTE_SET_NO);
			SetAutoReturnSetFlag(wRouteAutoReturnId, AUTO_RETURN_SET_NO);
			SetAllAutoReturnSetFlag(wRouteAllAutoReturnId, ALL_AUTO_RETURN_SET_NO);
			if (ROUTE_TYPE_AUTO_TRIGGER == chAutoTriggerType)
			{
				SetRouteAutoTriggerFlag(wLogLockBelongRouteId, AUTO_TRIGGER_SET_NO);
			}
		}
		else if (ROUTE_STATE_LEAD_OPEN == chRouteState)
		{
			(void)DriveSignalClose(wRouteStartSigId);  /*驱动信号关闭*/
		}
		else
		{
			chLogSecLockState = GetLogSecLockState(wLogSectionId);
			chRouteRecoverFlag = GetRouteRecoverOpenFlag(wLogLockBelongRouteId);
			/*如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到区故解命令时进行清除重开标志*/
			if (ROUTE_RECOVER_STA_WAIT == chRouteRecoverFlag)
			{/*重开等待时，区段故障锁闭，清除重开标志*/
				SetRouteOpenSigStartCycNum(wLogLockBelongRouteId, 0U);  /*重置信号开放时间*/

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

				SetRouteXianSuConfirmStt(wLogLockBelongRouteId, ROUTE_XIANSU_CONFIRM_NO);

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

			if ((LOG_SECTION_LOCK_EXCEPT != chLogSecLockState) && (ROUTE_STATE_HALF_UNLOCKDELAY != chRouteState))
			{
				/*逻辑区段锁闭状态不为"异常锁闭"且进路状态也不为延时解锁*/
				SetCiSendCmdBackInfoData(CI_BACK_PSEC_QGJ_UNLOCK, CI_DEVICE_TYPE_LOGICSEC, wLogSectionId, 0U, 0U);
			}
			else
			{
				/*区段为故障锁闭时*/
				if ((ROUTE_STATE_AUTO_UNLOCKERR == chRouteState) || (ROUTE_STATE_IDLE == chRouteState))
				{
					/*本联锁办理一条进路包含相邻联锁的物理区段，此时本联锁宕机。相邻联锁会将此物理区段设置为故障锁闭。
					在本联锁重启后，相邻联锁将此物理区段的故障锁闭状态发给本联锁。本联锁将此物理区段锁闭状态更新为
					异常锁闭，本联锁此条进路状态在重启后更新为	ROUTE_STATE_IDLE。为了能区故解此物理区段，加入
					ROUTE_STATE_IDLE == routeState此条件*/

					/*正常情况下区故解绿光带*/
					chLogFaultUnLockRes = LogSecFaultUnlockLogicProcess(wLogSectionId);
					if (CI_SUCCESS == chLogFaultUnLockRes)
					{
						chLogSecBelongRouteDir = GetRouteDirection(wLogLockBelongRouteId);
						SetLogSecLockState(wLogSectionId, LOG_SECTION_LOCK_NO, wLogLockBelongRouteId, chLogSecBelongRouteDir);
						/*物理区段如果存在锁闭所属进路，在收到命令时物理区段故障解锁逻辑处理，此处不处理*/

						chHaveLogSecFromOtherCi = RouteHaveLogSecBelongOtherCi(wLogLockBelongRouteId, &chNeighbourCi);
						if ((1U == chHaveLogSecFromOtherCi) && (0U < chNeighbourCi))
						{
							chCommState = GetLocalCiAndOtherCiTransSta(chNeighbourCi);
						}
						if ((1U == chHaveLogSecFromOtherCi) && (0U < chNeighbourCi) && (TRANSMIT_STATE_BAD == chCommState)
							&& (CICI_RELAY_INTERFACE_CONFIRM_YES == chConfirmRelayInterfaceFlag) &&
							(FUNC_SWITCH_ON == chFuncSwitch))
						{
							/*有其它联锁的区段,且本联锁与该联锁通信中断，且支持继电接口功能开关已打开，且继电接口已确认*/
							chRouteLogSecHaveUnLock = CheckLocalCiRouteLogSecUnLock(wLogLockBelongRouteId);
						}
						else
						{
							chRouteLogSecHaveUnLock = CheckRouteLogSecHaveUnLock(wLogLockBelongRouteId);
						}
						if (CI_SUCCESS == chRouteLogSecHaveUnLock)
						{
							/*解锁进路关联防护道岔*/
							SetRouteRelProSwitchLockSta(wLogLockBelongRouteId, SWITCH_LOCK_PROTECT_CANCEL);/*取消进路关联防护道岔的防护锁闭*/
							/*设置进路自动属性无效*/
							SetAutoRouteSetFlag(wRouteAutoRouteId, AUTO_ROUTE_SET_NO);
							SetAutoReturnSetFlag(wRouteAutoReturnId, AUTO_RETURN_SET_NO);
							SetAllAutoReturnSetFlag(wRouteAllAutoReturnId, ALL_AUTO_RETURN_SET_NO);
							if (ROUTE_TYPE_AUTO_TRIGGER == chAutoTriggerType)
							{
								SetRouteAutoTriggerFlag(wLogLockBelongRouteId, AUTO_TRIGGER_SET_NO);
							}
							/*全部区段解锁*/
							SetRouteStateManage(wLogLockBelongRouteId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
						}
						else
						{
							/*车辆段,暂不考虑逻辑区段区故解*/
							;
						}
					}
				}
			}
		}
	}
}

/*
* 功能描述： 逻辑区段故障解锁逻辑处理-进路属于相邻联锁
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* const UINT8 chVirCIid  操作的Rtu(虚拟联锁现地)  ID
* 返回值  ： void
* by cgh 20231002
*/
void OtherCiLogSecFaultUnlockProcess(const UINT16 wLogSectionId, const UINT8 chVirCIid)
{
	UINT8 chLogSecBelongCiId = 0U;/*逻辑区段所属联锁ID*/
	UINT16 wLogLockBelongRouteId = 0U;/*逻辑区段所属进路Id*/
	UINT8 chRouteBelongCiId = 0U;/*进路所属联锁ID*/
	UINT8 chCommState = 0U;/*与其他联锁通信状态*/
	UINT8 chLocalCiId = 0U;/*本地联锁ID*/
	UINT8 chFuncSwitch = 0U; 	/*相邻联锁是否支持继电接口*/
	UINT8 chConfirmRelayInterfaceFlag = 0U;/*继电接口确认状态*/
	UINT8 chLogFaultUnLockRes = 0U;/*逻辑区段故障解锁条件检查结果*/
	UINT8 chLogSecBelongRouteDir = 0U;/*逻辑区段锁闭所属进路方向*/
	UINT8 chRouteLogSecHaveUnLock = 0u;/*进路逻辑区段是否已解锁*/
	UINT8 chIncludeVirFlag = 0U;/*是否支持虚拟联锁*/
	UINT8 chBelongVirCiId = 0U;/*逻辑区段所属虚拟联锁ID*/
	UINT16 wLogSecBelongPhySecId = 0U;/*逻辑区段所属物理区段ID*/

	chLocalCiId = GetSystemParaLocalCiId();  /*获取本机联锁ID*/
	wLogLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
	chFuncSwitch = GetCiFunctionSwitchConfig(FUNC_SWITCH_USE_RELAY_INTERFACE_BETWEEN_NEIGHBOURCI);
	chIncludeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	chConfirmRelayInterfaceFlag = GetCiCiRelayInterfConfirmFlag();/*继电接口确认状态*/

	if ((0U < wLogLockBelongRouteId) && (ROUTE_SUM_MAX > wLogLockBelongRouteId))
	{
		chLogSecBelongCiId = GetLogSecBelongCiId(wLogSectionId);
		chRouteBelongCiId = GetRouteBelongCiId(wLogLockBelongRouteId);
		chCommState = GetLocalCiAndOtherCiTransSta(chRouteBelongCiId);
		if ((chLocalCiId == chLogSecBelongCiId) && (TRANSMIT_STATE_BAD == chCommState) &&
			(CICI_RELAY_INTERFACE_CONFIRM_YES == chConfirmRelayInterfaceFlag) &&
			(FUNC_SWITCH_ON == chFuncSwitch))
		{
			chLogFaultUnLockRes = LogSecFaultUnlockLogicProcess(wLogSectionId);
			if (CI_SUCCESS == chLogFaultUnLockRes)
			{
				chLogSecBelongRouteDir = GetRouteDirection(wLogLockBelongRouteId);
				SetLogSecLockState(wLogSectionId, LOG_SECTION_LOCK_NO, wLogLockBelongRouteId, chLogSecBelongRouteDir);
				/*物理区段如果存在锁闭所属进路，在收到命令时物理区段故障解锁逻辑处理，此处不处理*/
				chRouteLogSecHaveUnLock = CheckRouteLogSecUnLock(wLogLockBelongRouteId);
				if (CI_SUCCESS == chRouteLogSecHaveUnLock)
				{
					SetRouteRelProSwitchLockSta(wLogLockBelongRouteId, SWITCH_LOCK_PROTECT_CANCEL);/*取消进路关联防护道岔的防护锁闭*/
					SetRouteStateManage(wLogLockBelongRouteId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
				}
			}
			else
			{
				/*车辆段,暂不考虑逻辑区段区故解*/
				;
			}
		}
		else if ((chLocalCiId == chLogSecBelongCiId) && (TRANSMIT_STATE_GOOD == chCommState))
		{
			wLogSecBelongPhySecId = GetLgcSecRelativePhySecId(wLogSectionId);
			if (FUNC_SWITCH_ON == chIncludeVirFlag)
			{
				chBelongVirCiId = GetLogSecBelongVirCiId(wLogSectionId);
				if ((chVirCIid == chBelongVirCiId) && (0U != chVirCIid))
				{
					/*进路属于相邻联锁，且区段属于本联锁时，传递区段故障解锁命令	*/
					AddCiSendToCiCmdInfo(CI_CMD_SECTION_FAULT_UNLOCK, wLogSecBelongPhySecId, 0U, chRouteBelongCiId);
				}
			}
			else
			{
				/*进路属于相邻联锁，且区段属于本联锁时，传递区段故障解锁命令	*/
				AddCiSendToCiCmdInfo(CI_CMD_SECTION_FAULT_UNLOCK, wLogSecBelongPhySecId, 0U, chRouteBelongCiId);

			}
		}
		else
		{
			; 	/*异常情况，不处理区故解命令*/
		}
	}
}

/*
* 功能描述： 逻辑区段故障解锁检查
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*           const UINT8 chVirCIid  操作的Rtu(虚拟联锁现地)  ID
* 返回值  ：CI_ERROR 检查不通过
*			CI_SUCCESS 检查通过
*/
UINT8 CheckLogSecFaultUnlockCanDo(const UINT16 wLogSectionId, const UINT8 chVirCIid)
{
	UINT16 wLockBelongRouteId = 0U;  /*区段锁闭所属进路ID*/
	UINT8 reVal = CI_ERROR;
	UINT8 chBelongvirCIid = 0U;
	UINT8 chIncludeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);

	if ((0u == wLogSectionId) || (LOGIC_SECTION_SUM_MAX <= wLogSectionId))
	{
		/*逻辑区段ID无效*/
		reVal = CI_ERROR;
	}
	else
	{
		wLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);  /*获取逻辑区段进路锁闭所属进路ID*/

		if ((0U == wLockBelongRouteId) || (ROUTE_SUM_MAX <= wLockBelongRouteId))
		{
			/*锁闭所属进路ID无效*/
			reVal = CI_ERROR;
		}
		else
		{
			reVal = CI_SUCCESS;
		}
	}
	if (CI_SUCCESS == reVal)
	{
		if (FUNC_SWITCH_ON == chIncludeVirFlag)
		{
			chBelongvirCIid = GetRouteBelongVirCiId(wLockBelongRouteId);
			if (0U < chVirCIid)
			{
				if (chVirCIid == chBelongvirCIid)
				{
					reVal = CI_SUCCESS;	/*本Rtu(虚拟联锁现地)可以操作属于本虚拟联锁的进路锁闭的逻辑区段区故解，无论该逻辑区段是否属于该Rtu*/
				}
				else
				{
					chBelongvirCIid = GetLogSecBelongVirCiId(wLogSectionId);
					if (chVirCIid == chBelongvirCIid)
					{
						reVal = CI_SUCCESS;/*本虚拟联锁逻辑区段由相邻虚拟联锁进路锁闭的，可以在该逻辑区段所属Rtu上操作区故解*/
					}
					else
					{
						reVal = CI_ERROR;
					}
				}
			}
			else
			{
				reVal = CI_ERROR;
			}

		}
		else
		{
			reVal = CI_SUCCESS;
		}
	}

	return reVal;
}

/*
* 功能描述： 区故解检查失败驱动相关信号关闭
* 参数说明： const UINT16 wPhySectionId  物理区段ID
* 返回值  ： 无
* cgh-20231011创建
*/
void SecFaultUnlockDrvRelSigClose(const UINT16 wPhySectionId)
{
	UINT16 wPhySecLockBelRouteId = 0U;/*物理区段锁闭所属进路*/
	UINT8 chRouteState = 0U;/*进路状态*/
	UINT8 chRouteAutoSig = 0U;/*进路自动信号属性*/
	UINT16 wRouteStartSigId = 0U;/*进路始端信号机ID*/
	UINT16 wRouteAutoRouteId = 0U;/*进路对应自动进路ID*/
	UINT16 wRouteAutoReturnId = 0U;/*进路对应自动折返进路ID*/
	UINT16 wRouteAllAutoReturnId = 0U;/*进路对应全自动折返进路ID*/
	UINT8 chAutoTriggerType = 0U;/*进路自动触发属性*/
	UINT8 chPhyIncLogSum = 0U;            /*包含逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;   /*物理区段包含逻辑区段ID数组*/
	UINT8 ii = 0U;               /*物理区段包含逻辑区段循环索引*/
	UINT8 jj = 0U;               /*逻辑区段锁闭所属逻辑进路数目*/
	UINT8 wLogLockBelLogRouteSum = 0U;  /*逻辑区段锁闭所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* pLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT16 wBeginSigId = 0U;/*始端信号机ID*/
	UINT8 chSigOpenState = 0U;/*信号机开放状态*/
	UINT8 chStartSigCurColor = 0U;/*信号机当前显示颜色*/

	if ((0U == wPhySectionId) || (PHYSICAL_SECTION_SUM_MAX < wPhySectionId))
	{
		; /*物理区段ID无效不执行*/
	}
	else
	{
		wPhySecLockBelRouteId = GetPhySecRLockBelongRouteId(wPhySectionId);  /*获取物理区段进路锁闭所属进路ID*/

		if ((ROUTE_SUM_MAX < wPhySecLockBelRouteId) || (0U == wPhySecLockBelRouteId))
		{
			; /*锁闭所属进路ID无效不执行*/
		}
		else
		{
			chRouteState = GetRouteState(wPhySecLockBelRouteId);
			chRouteAutoSig = GetRouteAutoSigProperty(wPhySecLockBelRouteId);
			wRouteStartSigId = GetRouteStartSignalId(wPhySecLockBelRouteId);
			wRouteAutoRouteId = GetRouteAutoRouteId(wPhySecLockBelRouteId);
			wRouteAutoReturnId = GetRouteAutoReturnId(wPhySecLockBelRouteId);
			wRouteAllAutoReturnId = GetRouteAllAutoReturnId(wPhySecLockBelRouteId);
			chAutoTriggerType = GetAutoTriggerType(wPhySecLockBelRouteId);

			if (((ROUTE_STATE_YUXIAN_OPEN == chRouteState) || (ROUTE_STATE_NEAR_OPEN == chRouteState) || (ROUTE_STATE_LEAD_OPEN == chRouteState)) 
				&& (ROUTE_AUTOSIG_PROPERTY_YES != chRouteAutoSig))
			{
				/*进路状态为预先开放或者接近开放或者引导开放，但不是自动信号*/
				(void)DriveSignalClose(wRouteStartSigId);  /*驱动信号关闭*/
				/*设置进路自动属性无效*/
				SetAutoRouteSetFlag(wRouteAutoRouteId, AUTO_ROUTE_SET_NO);
				SetAutoReturnSetFlag(wRouteAutoReturnId, AUTO_RETURN_SET_NO);
				SetAllAutoReturnSetFlag(wRouteAllAutoReturnId, ALL_AUTO_RETURN_SET_NO);
				if (ROUTE_TYPE_AUTO_TRIGGER == chAutoTriggerType)
				{
					SetRouteAutoTriggerFlag(wPhySecLockBelRouteId, AUTO_TRIGGER_SET_NO);
				}
			}
			else
			{
				; /*不处理*/
			}

			chPhyIncLogSum = GetPhySecIncLogSecSum(wPhySectionId);
			pPhyIncLogId = GetPhySecIncLogSecIdBuf(wPhySectionId);
			if (NULL != pPhyIncLogId)
			{
				for (ii = 0U; ii < chPhyIncLogSum; ii++)
				{
					wLogLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(pPhyIncLogId[ii]);
					pLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(pPhyIncLogId[ii]);
					if (NULL != pLogSecLockBelLogRouteData)
					{
						/*逻辑区段有锁闭所属逻辑进路，此时逻辑区段逻辑锁闭状态只能为逻辑正常锁闭或逻辑异常锁闭*/
						for (jj = 0U; jj < wLogLockBelLogRouteSum; jj++)
						{
							wBeginSigId = GetLogicalRouteRelateBeginSigId(pLogSecLockBelLogRouteData[jj].wLogSecLockBelLogRouteId);
							if ((0U < wBeginSigId) && (SIGNAL_SUM_MAX > wBeginSigId))
							{
								chStartSigCurColor = GetSignalCurColor(wBeginSigId);
								chSigOpenState = GetSignalOpenCloseState(chStartSigCurColor);
								if (SIGNAL_OPEN == chSigOpenState)
								{
									(void)DriveSignalClose(wBeginSigId);  /*驱动信号关闭*/
								}
								else
								{
									; /*不处理*/
								}
							}
							else
							{
								; /*无始端信号机不处理*/
							}
						}
					}
					else
					{
						; /*不处理*/
					}
				}
			}
			else
			{
				; /*不处理*/
			}
		}
	}
}

/*
* 功能描述：逻辑进路保持信号开放处理
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_ERROR：检查失败
*            CI_SUCCESS：检查成功
*/
UINT8 KeepOpenLogRouteSignalProc(const UINT16 wLogRouteId)
{
	UINT8 returnValue = CI_ERROR;        /*返回值定义*/
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/
	UINT16* LogSecIdBuff = NULL;
	UINT8 chRouteFirstLgcTrainSum = 0U;
	UINT16 wSignalInFirstLogSecId = 0U;
	
	wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	returnValue = KeepLogRouteSignalProcess(wLogRouteId);
	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);

	/*根据开放信号返回值处理*/
	if (CI_SUCCESS == returnValue)
	{
		DriveLogRouteSignalOpen(wLogRouteId);			/*无车跨压，保持开放检查通过保持开放信号*/
	}
	else if (LOG_ROUTE_TRAIN_CROSS == returnValue)
	{
		/*检查第一逻辑区段的列车信息，当第一逻辑区段有多个列车资源时不关信号*/
		chRouteFirstLgcTrainSum = GetLogSecTrainInfoSum(LogSecIdBuff[0U]);

		if (1U < chRouteFirstLgcTrainSum)
		{
			;		/*不对信号机进行处理*/
		}
		else
		{
			DriveLogRouteSignalClose(wLogSignalId);			/*第一逻辑区段只有一个列车资源，且跨压逻辑进路信号机,或者获取到没有列车(异常情况)关信号*/
		}
	}
	else
	{
		wSignalInFirstLogSecId = GetLogSecLockBelongRoute(LogSecIdBuff[0U]);
		if (0U != wSignalInFirstLogSecId)
		{
			/*信号机内方第一逻辑区段被进路锁闭，则不驱动信号机，维持信号机既有状态*/
		}
		else
		{
			DriveLogRouteSignalClose(wLogSignalId);
			/*设置异常驱关闭的标志*/
			SetLogRouteSignalErrCloseFlag(wLogSignalId, LOG_ROUTE_SIGNAL_CLOSE_ERR);
		}
	}
	return returnValue;
}


/*
* 功能描述：逻辑进路信号开放处理
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_ERROR：检查失败
*            CI_SUCCESS：检查成功
*/
UINT8 OpenLogRouteSignalProc(const UINT16 wLogRouteId)
{
	UINT8 returnValue = CI_ERROR;        /*返回值定义*/
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/

	wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	returnValue = OpenLogRouteSignalProcess(wLogRouteId);

	if (CI_SUCCESS == returnValue)
	{
		DriveLogRouteSignalOpen(wLogRouteId);
	}
	else
	{
		/*开放检查不通过*/
		/*出现异常，或者出现跨压信号机*/
		DriveLogRouteSignalClose(wLogSignalId);
	}

	return returnValue;
}
/**
* @brief 查询列车小前处于逻辑进路位置(列车小前)
* @param UINT16 wTrainId 列车ID
* @param UINT16 wLogRouteId 逻辑进路ID
* @return 0：查询失败
*			1：列车未驶入进路
*			2：列车车头驶入进路但未跨压
*           3：列车跨压信号机
*			4：列车完全驶入进路
*			5：列车车头出清进路
*/
UINT8 dsuLogRouteTrainCrossSignal(const UINT16 wTrainId, const UINT16 wLogRouteId)
{
	UINT8 chRtnVal = CI_ERROR;
	UINT16 wStartSignal = 0u;
	UINT8 chRouteDir = 0u;
	struct_PathPoint strTrainMinHead = { 0u };
	struct_PathPoint strTrainMinTail = { 0u };
	str_Zone strRouteZone = { 0u };
	str_Zone strTrainZone = { 0u };
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 wLogId = 0U;				
	RouteSwitchStruct pRouteSwitchStruct[ROUTE_SWITCH_SUM_MAX] = { 0U }; /*进路包含的道岔ID数组*/
	UINT8 chSwitchNum = 0u;
	UINT8 chIndex = 0u;
	str_PointInArea strRouteSwitch = { 0u };
	UINT16 wLinkNum = 0u;
	UINT8 chFunRtn = 0u;
	UINT32 dwLen = UINT32_MAX;
	UINT32 dwSglCrossLen = 0u; /*跨压距离 配置数据*/
	UINT8 chDirTemp = 0u;
	LOD_STRU sLODTrain = { 0U };  /*列车前端位置*/
	LOD_STRU sLODRoute = { 0U };  /*进路始端位置*/
	UINT8 wLogLockDir = 0U;

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	wLogId = LogSecIdBuff[logSecSum - 1U];			/*取序列最后一个逻辑区段*/

	wStartSignal = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	chRouteDir = GetSignalDirection(wStartSignal);  /*进路方向采用信号机防护方向，需确认信号机防护方向与内方第一link */

	strTrainMinHead.wLinkId = GetTrainMinHeadLink(wTrainId);
	strTrainMinHead.dwOffset = GetTrainMinHeadOffset(wTrainId);
	strTrainMinTail.wLinkId = GetTrainMinTailLink(wTrainId);
	strTrainMinTail.dwOffset = GetTrainMinTailOffset(wTrainId);
	
	strRouteZone.Dir = chRouteDir;
	strRouteZone.pStart.wLinkId = GetSignalProtectLink(wStartSignal);
	strRouteZone.pStart.dwOffset = GetSignalProtectLinkOff(wStartSignal);
	
	wLogLockDir = GetLogSecLogLockDir(wLogId);
	wLogLockDir = ConvertDirectionToLogic(wLogLockDir);	/*运营转逻辑方向*/
	if (DIR_SAME == wLogLockDir)
	{
		/*同向，取终点*/
		strRouteZone.pEnd.wLinkId = GetLgcSecTmnlLink(wLogId);
		strRouteZone.pEnd.dwOffset = GetLgcSecTmnlOffset(wLogId);
	}
	else if (DIR_CONVERT == wLogLockDir)
	{
		/*反向，取起点*/
		strRouteZone.pEnd.wLinkId = GetLgcSecOrgnLink(wLogId);
		strRouteZone.pEnd.dwOffset = GetLgcSecOrgnOffset(wLogId);
	}
	else
	{
		chRtnVal = CI_ERROR;
	}

	strTrainZone.Dir = GetTrainDir(wTrainId);
	strTrainZone.pStart.wLinkId = strTrainMinTail.wLinkId;
	strTrainZone.pStart.dwOffset = strTrainMinTail.dwOffset;
	strTrainZone.pEnd.wLinkId = strTrainMinHead.wLinkId;
	strTrainZone.pEnd.dwOffset = strTrainMinHead.dwOffset;

	chSwitchNum = GetLogRouteSWData(wLogRouteId, pRouteSwitchStruct); /*正在办理的这条进路内的道岔数据*/
	if ((DIR_SAME == chRouteDir) || (DIR_CONVERT == chRouteDir))
	{
		chRtnVal = CI_SUCCESS;
	}
	else
	{
		;/* 入参不合法 */
	}
	if (CI_SUCCESS == chRtnVal)
	{
		chRtnVal = CheckLinkValid(strTrainMinHead.wLinkId, strTrainMinHead.dwOffset);
		chRtnVal &= CheckLinkValid(strTrainMinTail.wLinkId, strTrainMinTail.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pStart.wLinkId, strRouteZone.pStart.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pEnd.wLinkId, strRouteZone.pEnd.dwOffset);
	}
	else
	{
		;/* 入参不合法 */
	}
	if (CI_SUCCESS == chRtnVal)
	{
		for (chIndex = 0u; chIndex < chSwitchNum; chIndex++)
		{
			strRouteSwitch.SwitchInfo[chIndex].pointID = pRouteSwitchStruct[chIndex].SwitchId;
			strRouteSwitch.SwitchInfo[chIndex].status = pRouteSwitchStruct[chIndex].SwitchPosition;
		}
		strRouteSwitch.SwitchNum = chSwitchNum;
		/* 获取进路包含的link序列 */
		chRtnVal = dsuLinkSeqInAreaBaseSwitchInfo(strRouteZone.pStart, strRouteZone.pEnd, strRouteZone.Dir, &strRouteSwitch, &strRouteZone.pLinkSeq);
		chRtnVal &= DsuLinkSeqBtwPoints(&strTrainZone.pStart, &strTrainZone.pEnd, &strTrainZone.Dir, &wLinkNum, strTrainZone.pLinkSeq.szLinkId);
		strTrainZone.pLinkSeq.cLinkCnt = (UINT8)wLinkNum;
	}
	else
	{
		;
	}
	if (CI_SUCCESS == chRtnVal)
	{
		chFunRtn = IsPointInPath(strTrainMinHead, strRouteZone);
		if (CI_SUCCESS == chFunRtn)
		{
			/* 列车最小安全前端不在进路内，判断列车车尾 */
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				chRtnVal = TRAIN_ENTER_ROUTE_NO;/* 列车车尾不在进路内 */
				chFunRtn = IsPointInPath(strRouteZone.pStart, strTrainZone);
				if (CI_ERROR == chFunRtn)
				{
					chFunRtn = IsPointInPath(strRouteZone.pEnd, strTrainZone);
					if (CI_ERROR == chFunRtn)
					{
						chRtnVal = TRAIN_ENTER_ROUTE_TAIL;
					}
					else
					{
						;
					}
				}
				else
				{
					;
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_TAIL;/* 列车车头不在进路内，车尾在进路内 */
			}
		}
		else
		{
			/* 列车最小安全车头在进路内 */

			/*判断小尾在不在进路中*/
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);

			/*判断小尾不在进路中*/
			if (CI_SUCCESS == chFunRtn)
			{

				dwLen = DsuAPointToBPoint(&strRouteZone.pStart, &strTrainMinHead, &chDirTemp);
				dwSglCrossLen = (UINT32)GetSigCrossMaxLen() * 100U;

				if (0U == dwLen)
				{
					sLODTrain.Lnk = strTrainZone.pStart.wLinkId;
					sLODTrain.Off = strTrainZone.pStart.dwOffset;
					sLODTrain.Dir = strTrainZone.Dir;
					sLODRoute.Lnk = strRouteZone.pStart.wLinkId;
					sLODRoute.Off = strRouteZone.pStart.dwOffset;
					sLODRoute.Dir = strRouteZone.Dir;
					chFunRtn = IsPointABSameDir(sLODTrain, sLODRoute);

					if (FLAG_SET == chFunRtn)
					{
						/*列车驶入进路认为列车车头已驶入*/
						chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入*/
					}
					else
					{
						chRtnVal = CI_ERROR;  /*方向相反，返回失败*/
					}

				}
				else if ((UINT32_MAX == dwLen) || (chDirTemp != chRouteDir))
				{
					chRtnVal = CI_ERROR;/* 查询出错 */
				}
				else if (dwLen > dwSglCrossLen)
				{
					chRtnVal = TRAIN_ENTER_ROUTE_CROSS;/* 列车跨压信号机 */
				}
				else
				{
					chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入进路，但未跨压 */
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_FULL;/* 列车完全驶入进路 */
			}
		}
	}
	else
	{
		;
	}
	return chRtnVal;
}

/**
* @brief 查询列车小前处于逻辑进路位置(列车小前)
* @param UINT16 wTrainId 列车ID
* @param UINT16 wLogRouteId 逻辑进路ID
* @return 0：查询失败
*			1：列车未驶入进路
*			2：列车车头驶入进路但未跨压
*			3：列车跨压始端信号机
*			4：列车完全驶入进路
*			5：列车车头出清进路
*/
UINT8 dsuLogRouteMinHeadTrainCrosSig(const UINT16 wTrainId, const UINT16 wLogRouteId)
{
	UINT8 chRtnVal = CI_ERROR;
	UINT16 wStartSignal = 0u;
	UINT8 chRouteDir = 0u;
	struct_PathPoint strTrainMinHead = { 0u };
	struct_PathPoint strTrainMinTail = { 0u };
	str_Zone strRouteZone = { 0u };
	str_Zone strTrainZone = { 0u };
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 wLogId = 0U;
	RouteSwitchStruct pRouteSwitchStruct[ROUTE_SWITCH_SUM_MAX] = { 0U }; /*进路包含的道岔ID数组*/
	UINT8 chSwitchNum = 0u;
	UINT8 chIndex = 0u;
	str_PointInArea strRouteSwitch = { 0u };
	UINT16 wLinkNum = 0u;
	UINT8 chFunRtn = 0u;
	UINT32 dwLen = UINT32_MAX;
	UINT32 dwSglCrossLen = 0u;
	UINT8 chDirTemp = 0u;
	LOD_STRU sLODTrain = { 0U };  /*列车前端位置*/
	LOD_STRU sLODRoute = { 0U };  /*进路始端位置*/
	UINT8 wLogLockDir = 0U;

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	wLogId = LogSecIdBuff[logSecSum - 1U];			/*取序列最后一个逻辑区段*/

	wStartSignal = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	chRouteDir = GetSignalDirection(wStartSignal);  /*进路方向采用信号机防护方向，需确认信号机防护方向与内方第一link */

	strTrainMinHead.wLinkId = GetTrainMinHeadLink(wTrainId);
	strTrainMinHead.dwOffset = GetTrainMinHeadOffset(wTrainId);
	strTrainMinTail.wLinkId = GetTrainMinTailLink(wTrainId);
	strTrainMinTail.dwOffset = GetTrainMinTailOffset(wTrainId);

	strRouteZone.Dir = chRouteDir;
	strRouteZone.pStart.wLinkId = GetSignalProtectLink(wStartSignal);
	strRouteZone.pStart.dwOffset = GetSignalProtectLinkOff(wStartSignal);
	wLogLockDir = GetLogSecLogLockDir(wLogId);
	wLogLockDir = ConvertDirectionToLogic(wLogLockDir);	/*运营转逻辑方向*/
	if (DIR_SAME == wLogLockDir)
	{
		/*同向，取终点*/
		strRouteZone.pEnd.wLinkId = GetLgcSecTmnlLink(wLogId);
		strRouteZone.pEnd.dwOffset = GetLgcSecTmnlOffset(wLogId);
	}
	else if (DIR_CONVERT == wLogLockDir)
	{
		/*反向，取起点*/
		strRouteZone.pEnd.wLinkId = GetLgcSecOrgnLink(wLogId);
		strRouteZone.pEnd.dwOffset = GetLgcSecOrgnOffset(wLogId);
	}
	else
	{
		chRtnVal = CI_ERROR;
	}

	strTrainZone.Dir = GetTrainDir(wTrainId);
	strTrainZone.pStart.wLinkId = strTrainMinTail.wLinkId;
	strTrainZone.pStart.dwOffset = strTrainMinTail.dwOffset;
	strTrainZone.pEnd.wLinkId = strTrainMinHead.wLinkId;
	strTrainZone.pEnd.dwOffset = strTrainMinHead.dwOffset;

	chSwitchNum = GetLogRouteSWData(wLogRouteId, pRouteSwitchStruct); /*正在办理的这条进路内的道岔数据*/
	if ((DIR_SAME == chRouteDir) || (DIR_CONVERT == chRouteDir))
	{
		chRtnVal = CI_SUCCESS;
	}
	else
	{
		;/* 入参不合法 */
	}
	if (CI_SUCCESS == chRtnVal)
	{
		chRtnVal = CheckLinkValid(strTrainMinHead.wLinkId, strTrainMinHead.dwOffset);
		chRtnVal &= CheckLinkValid(strTrainMinTail.wLinkId, strTrainMinTail.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pStart.wLinkId, strRouteZone.pStart.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pEnd.wLinkId, strRouteZone.pEnd.dwOffset);
	}
	else
	{
		;/* 入参不合法 */
	}
	if (CI_SUCCESS == chRtnVal)
	{
		for (chIndex = 0u; chIndex < chSwitchNum; chIndex++)
		{
			strRouteSwitch.SwitchInfo[chIndex].pointID = pRouteSwitchStruct[chIndex].SwitchId;
			strRouteSwitch.SwitchInfo[chIndex].status = pRouteSwitchStruct[chIndex].SwitchPosition;
		}
		strRouteSwitch.SwitchNum = chSwitchNum;
		/* 获取进路包含的link序列 */
		chRtnVal = dsuLinkSeqInAreaBaseSwitchInfo(strRouteZone.pStart, strRouteZone.pEnd, strRouteZone.Dir, &strRouteSwitch, &strRouteZone.pLinkSeq);
		chRtnVal &= DsuLinkSeqBtwPoints(&strTrainZone.pStart, &strTrainZone.pEnd, &strTrainZone.Dir, &wLinkNum, strTrainZone.pLinkSeq.szLinkId);
		strTrainZone.pLinkSeq.cLinkCnt = (UINT8)wLinkNum;
	}
	else
	{
		;
	}
	if (CI_SUCCESS == chRtnVal)
	{
		chFunRtn = IsPointInPath(strTrainMinHead, strRouteZone);
		if (CI_SUCCESS == chFunRtn)
		{
			/* 列车最小安全前端不在进路内，判断列车车尾 */
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				chRtnVal = TRAIN_ENTER_ROUTE_NO;/* 列车车尾不在进路内 */
				chFunRtn = IsPointInPath(strRouteZone.pStart, strTrainZone);
				if (CI_ERROR == chFunRtn)
				{
					chFunRtn = IsPointInPath(strRouteZone.pEnd, strTrainZone);
					if (CI_ERROR == chFunRtn)
					{
						dwSglCrossLen = (UINT32)GetSigCrossMaxLen() * 100U;
						dwLen = DsuAPointToBPoint(&strRouteZone.pStart, &strTrainMinHead, &chDirTemp);
						if ((dwLen > dwSglCrossLen) && ((chDirTemp == chRouteDir)))
						{
							/*车头驶出进路，车尾不在进路内，查车头跨压距离，若大于跨压距离算跨压*/
							chRtnVal = TRAIN_ENTER_ROUTE_CROSS;/* 列车跨压信号机 */
						}
						else
						{
							chRtnVal = TRAIN_ENTER_ROUTE_TAIL;
						}
					}
					else
					{
						;
					}
				}
				else
				{
					;
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_TAIL;/* 列车车头不在进路内，车尾在进路内 */
			}
		}
		else
		{
			/* 列车最小安全车头在进路内 */
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				dwSglCrossLen = (UINT32)GetSigCrossMaxLen() * 100U;
				dwLen = DsuAPointToBPoint(&strRouteZone.pStart, &strTrainMinHead, &chDirTemp);

				if (0U == dwLen)
				{
					sLODTrain.Lnk = strTrainZone.pStart.wLinkId;
					sLODTrain.Off = strTrainZone.pStart.dwOffset;
					sLODTrain.Dir = strTrainZone.Dir;
					sLODRoute.Lnk = strRouteZone.pStart.wLinkId;
					sLODRoute.Off = strRouteZone.pStart.dwOffset;
					sLODRoute.Dir = strRouteZone.Dir;
					chFunRtn = IsPointABSameDir(sLODTrain, sLODRoute);

					if (FLAG_SET == chFunRtn)
					{
						/*列车驶入进路认为列车车头已驶入*/
						chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入*/
					}
					else
					{
						chRtnVal = CI_ERROR;  /*方向相反，返回失败*/
					}

				}
				else if ((UINT32_MAX == dwLen) || (chDirTemp != chRouteDir))
				{
					chRtnVal = CI_ERROR;/* 查询出错 */
				}
				else if (dwLen > dwSglCrossLen)
				{
					chRtnVal = TRAIN_ENTER_ROUTE_CROSS;/* 列车跨压信号机 */
				}
				else
				{
					chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入进路，但未跨压 */
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_FULL;/* 列车完全驶入进路 */
			}
		}
	}
	else
	{
		;
	}
	return chRtnVal;
}


/*
* 功能描述：逻辑进路开放保持信号检查处理
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_ERROR：检查失败
*            CI_SUCCESS：检查成功
* 故障编码： EFUNC_KeepLogRouteSignalProcess
*/
UINT8 KeepLogRouteSignalProcess(const UINT16 wLogRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_KeepLogRouteSignalProcess;
	UINT8 sendLevel = ESEND_LEVEL_ZERO;			/*检查报警不向ATS发送，不然在锁闭检查开放到维持信号开放过程中，会一直报警*/
	UINT8 devState = 0u;                 /*设备状态*/
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

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

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

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

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

	/* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenLogRoutePlatformCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLogRouteSectionCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
		{
			/*列车跨压，通过检查*/
			reResult = LOG_ROUTE_TRAIN_CROSS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	return reResult;
}

/*
* 功能描述：逻辑进路开放信号检查处理
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_ERROR：检查失败
*            CI_SUCCESS：检查成功
* 故障编码： EFUNC_LogRouteSignalProcess
*/
UINT8 OpenLogRouteSignalProcess(const UINT16 wLogRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_OpenLogRouteSignalProcess;
	UINT8 sendLevel = ESEND_LEVEL_ZERO;			/*检查报警不向ATS发送，不然在锁闭检查开放到维持信号开放过程中，会一直报警*/
	UINT8 devState = 0u;                 /*设备状态*/
	/* 局部变量定义初始化 */
	UINT8 reResult = CI_ERROR;          /*返回值*/
	UINT8 checkResult = CI_ERROR;       /*检查结果*/

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

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

		}
	}

	/* 信号机联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenLogRouteSignalCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	/*照查联锁条件检查(预留)*/
	/*开放检查条件区段，道岔和接发车检查条件同步维持信号机的检查*/
	  /* 道岔联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLogRouteSwitchCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

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

	/* 接发车联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = OpenLogRoutePlatformCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}

	/* 区段联锁条件检查 */
	if (CI_SUCCESS == reResult)
	{
		checkResult = KeepLogRouteSectionCheck(wLogRouteId, functionId, sendLevel);
		if (CI_SUCCESS == checkResult)
		{
			/* 通过检查 */
			reResult = CI_SUCCESS;
		}
		else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
		{
			/*列车跨压，通过检查*/
			reResult = LOG_ROUTE_TRAIN_CROSS;
		}
		else
		{
			/* 失败返回 */
			reResult = CI_ERROR;
		}
	}
	return reResult;
}
/*
* 功能描述：逻辑进路驱动信号机开放
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： void
*/
void DriveLogRouteSignalOpen(const UINT16 wLogRouteId)
{
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/
	UINT8 oriDriveColor = 0u;    /*进路本应驱动信号开放颜色*/
	UINT8 lightExtinctState = 0u;/*信号机亮灭信息*/
	UINT8 signalIsfushiFlag = 0u;
	UINT8 signalCurDriveColor = 0u;

	wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	oriDriveColor = GetLogicalRouteOpenColor(wLogRouteId);		/*获取逻辑进路开放颜色*/
	lightExtinctState = GetSignalLightExtinctState(wLogSignalId);/*信号机亮灭状态*/

	signalIsfushiFlag = GetSignalIsfushiFlag(wLogSignalId);
	signalCurDriveColor = GetSignalCurDriveColor(wLogSignalId);
	if ((0u == wLogSignalId) || (SIGNAL_SUM_MAX <= wLogSignalId))
	{
		/*不做处理*/
	}
	else
	{
		if ((SIGNAL_DRIVECOLOUR_NULL == signalCurDriveColor) && (SIGNALTYPE_FUSHI_YES != signalIsfushiFlag)
			&& (SIGNAL_LIGHT_EXTICT_STATE_NO == lightExtinctState))
		{/*未驱动过的信号机，且针对逻辑进路的信号机，只允许处理灭灯情况，CBTC情况下的信号机*/
			switch (oriDriveColor)
			{
			case SIGNAL_SHOWCOLOUR_GREENCLOSE:
				SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_GREENCLOSE);
				break;
			case SIGNAL_SHOWCOLOUR_YELLOWCLOSE:
				SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_YELLOWCLOSE);
				break;
			default:	/*无效颜色不进行处理*/
				break;
			}
		}
	}
}

/*
* 功能描述：逻辑进路驱动信号机关闭
* 参数说明： const UINT16 wLogSignalId, 驱动信号机ID
* 返回值  ：void
*/
void DriveLogRouteSignalClose(const UINT16 wLogSignalId)
{
	UINT8 allSignalBrightFlag = 0u;  /*全站亮灯标志*/
	UINT8 belongVirCIid = 0u;
	UINT8 signalIsfushiFlag = 0u;
	UINT8 lightExtinctState = 0u;
	UINT8 sigalMaintainState = 0u;
	UINT8 detainOpenRedBright = 0u;
	UINT8 signalDetainFlag = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	if ((0u == wLogSignalId) || (SIGNAL_SUM_MAX <= wLogSignalId))
	{
		/*不做处理*/
	}
	else
	{
		/*虚拟联锁兼容*/
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			belongVirCIid = GetSignalBelongVirCiId(wLogSignalId);
			allSignalBrightFlag = GetVirCIAllSignalBrightState(belongVirCIid); /*全站亮灯标志*/
		}
		else
		{
			allSignalBrightFlag = GetAllSignalBrightFlag();  /*全站亮灯标志*/
		}

		/*无论什么时候，复示信号机关闭都驱动红灭*/
		signalIsfushiFlag = GetSignalIsfushiFlag(wLogSignalId);
		if (SIGNALTYPE_FUSHI_YES == signalIsfushiFlag)
		{
			/*是复视信号机则驱动红灭*/
			SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_REDCLOSE);
		}
		else
		{
			lightExtinctState = GetSignalLightExtinctState(wLogSignalId);
			sigalMaintainState = GetSignalMaintainState(wLogSignalId);/*信号机维修点灯状态*/

			if ((CI_ALL_SIGNAL_BRIGHT_YES == allSignalBrightFlag) ||
				(SIGNAL_LIGHT_EXTICT_STATE_YES == lightExtinctState) ||
				(MAINTAIN_STATE_YES == sigalMaintainState)
				)
			{/*亮灯信息*/

				SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_RED);
			}
			else if (SIGNAL_LIGHT_EXTICT_STATE_NO == lightExtinctState)
			{
				detainOpenRedBright = GetCiFunctionSwitchConfig(FUNC_DETAIN_OPEN_RED);
				if (FUNC_SWITCH_ON == detainOpenRedBright)
				{  /*配置了扣车后开放红灯*/
					signalDetainFlag = GetSignalDetainFlag(wLogSignalId);
					if (SIGNAL_DETAIN_NO == signalDetainFlag)
					{
						SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_REDCLOSE);
					}
					else
					{
						SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_RED);
					}

				}
				else
				{
					SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_REDCLOSE);
				}
			}
			else
			{/*未收到或受到错误的信号机亮灭信息*/

				SetSignalCurDriveColor(wLogSignalId, SIGNAL_DRIVECOLOUR_RED);
			}
		}
	}
}

/*
* 功能描述： 逻辑进路监督级别确认
* 参数说明： const UINT16 wLogRouteId 逻辑进路ID
* 返回值  ： ROUTE_LEVEL_BLOC 点式级别
*            ROUTE_LEVEL_CBTC CBTC级别
* Created by LQ 2023/10/11
*/
void LogicRouteLevelConfirmProcess(const UINT16 wLogRouteId)
{
	UINT8 cLogicRouteLevel = ROUTE_LEVEL_BLOC;
	UINT8 cSignalOpenState = 0U;  /*信号机亮灭状态*/
	UINT8 cMaintainState = 0U;  /*信号机维修点灯状态*/
	UINT16 signalId = 0U;

	signalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	if ((0U < signalId) && (SIGNAL_SUM_MAX > signalId))
	{
		cSignalOpenState = GetSignalLightExtinctState(signalId);
		cMaintainState = GetSignalMaintainState(signalId);

		if ((SIGNAL_LIGHT_EXTICT_STATE_NO == cSignalOpenState) && (MAINTAIN_STATE_NO == cMaintainState))
		{
			cLogicRouteLevel = ROUTE_LEVEL_CBTC;  /*进路始端信号机【灭灯】且不在维修点灯状态，返回CBTC级别*/
		}
		else
		{
			cLogicRouteLevel = ROUTE_LEVEL_BLOC;   /*进路始端信号机【亮灯】或在维修点灯状态，返回点式级别*/
		}
	}
	else
	{
		cLogicRouteLevel = ROUTE_LEVEL_BLOC;  /*信号机ID非法，返回点式级别*/
	}
	SetLogicalRouteLevel(wLogRouteId, cLogicRouteLevel);  /*设置逻辑进路监督级别*/
}

/*
* 功能描述： 逻辑进路下发区故解命令，延时设置逻辑区段逻辑故障处理
* 参数说明： const UINT16 wLogSectionId  逻辑区段ID
* 返回值  ： void
* cgh-20231012创建
*/
void LogRouteErrLockCmdDeal(const UINT16 wLogSectionId)
{
	UINT8 chLogSecBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* szLogSecBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/
	UINT8 ii = 0U;
	UINT8 chLogSecLogLockState = 0U;     /*逻辑区段逻辑锁闭状态*/
	UINT16 wFirstNormalLockLogId = 0U;     /*逻辑进路第一个锁闭得逻辑区段ID*/
	UINT8 chLogSecLockBelLogRouteSta = 0U;  /*物理区段所进路状态*/
	UINT16 wLogSecRelatePhyId = 0U;/*逻辑区段关联物理区段ID*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段当前融合状态*/
	UINT16 wLogRouteRelateSigId = 0U;/*逻辑进路关联信号机*/
	UINT8 chKeepFlag = 0U;/*继续执行标志*/

	if ((0U < wLogSectionId) && (LOGIC_SECTION_SUM_MAX > wLogSectionId))
	{
		chLogSecBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSectionId);
		szLogSecBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSectionId);
		if (NULL != szLogSecBelLogRouteData)
		{
			for (ii = 0U; ii < chLogSecBelLogRouteSum; ii++)
			{
				chKeepFlag = 0U;
				wLogSecBelLogRouteId = szLogSecBelLogRouteData[ii].wLogSecLockBelLogRouteId;
				
				if (ROUTE_LOGICAL_SUM_MAX < wLogSecBelLogRouteId)
				{
					/*锁闭所属逻辑进路ID无效*/
					break;
				}
				else
				{
					chLogSecLockBelLogRouteSta = GetLogicalRouteState(wLogSecBelLogRouteId);
					chLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);
					wFirstNormalLockLogId = GetLogRouteFirNormalLockLogId(wLogSecBelLogRouteId);
					wLogSecRelatePhyId = GetLgcSecRelativePhySecId(wLogSectionId);
					chPhySecCurMergeState = GetPhySecCurMergeState(wLogSecRelatePhyId);
					wLogRouteRelateSigId = GetLogicalRouteRelateBeginSigId(wLogSecBelLogRouteId);

					if ((0U < wLogRouteRelateSigId) && (SIGNAL_SUM_MAX > wLogRouteRelateSigId))
					{
						chKeepFlag = 1U;
					}
					else
					{
						if (wFirstNormalLockLogId == wLogSectionId)
						{
							/*逻辑进路关联始端信号机无效，需要查询第一个锁闭的区段前一区段未锁闭*/
							chKeepFlag = CheckLogRouteLogSecLastSecLock(wLogSecBelLogRouteId, wLogSectionId);
						}
						else
						{
							/*不是第一个锁闭的逻辑区段，不检查*/
							chKeepFlag = 1U;
						}

					}

#if 1
					if ((1U == chKeepFlag) && ((ROUTE_LOGICAL_STATE_UNLOCKWAIT == chLogSecLockBelLogRouteSta) || (ROUTE_LOGICAL_STATE_LOCKERR == chLogSecLockBelLogRouteSta)) &&
						(LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState) && (wFirstNormalLockLogId == wLogSectionId) && (SECTION_OCCUPY_NO == chPhySecCurMergeState))
#endif
#if 0
						if ((1U == chKeepFlag) && (LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState)
							&& (wFirstNormalLockLogId == wLogSectionId) && (SECTION_OCCUPY_NO == chPhySecCurMergeState))
#endif
					{
						/*逻辑区段锁闭所属逻辑进路状态为等待解锁或锁闭异常&&逻辑区段逻辑锁闭状态为逻辑正常锁闭
						&&该逻辑区段是对应逻辑进路第一个锁闭的区段&&逻辑区段对应物理区段为占用*/
						SetLogRouteStateManage(wLogSecBelLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKDELAY);
					}
					else
					{
						; /*不处理*/
					}
				}
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}	
}

/*
* 功能描述： 逻辑进路区段故障解锁及传递处理
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* 返回值  ： void
* by cgh 20231013
*/
void LogRouteErrLockFaultProcess(const UINT16 wLogSectionId)
{
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/
	UINT8 ii = 0U;
	UINT8 chLogRouteState = 0U;/*逻辑进路状态*/
	UINT16 wLogRouteRelateBeginSigId = 0U;/*逻辑进路关联始端信号机ID*/
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT16 wLogSecRelatePhyId = 0U;/*逻辑区段关联物理区段ID*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段当前融合状态*/
	UINT8 chLogLockDir = 0U;/*逻辑区段逻辑锁闭所属进路方向*/

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

		if (NULL != szLogSecLockBelLogRouteData)
		{
			for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
			{
				wLogSecBelLogRouteId = szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
				if ((0U < wLogSecBelLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogSecBelLogRouteId))
				{
					chLogRouteState = GetLogicalRouteState(wLogSecBelLogRouteId);
					if (ROUTE_LOGICAL_STATE_OPEN == chLogRouteState)
					{
						/*逻辑进路具有始端信号机且信号机开放，此时需要关闭信号机*/
						wLogRouteRelateBeginSigId = GetLogicalRouteRelateBeginSigId(wLogSecBelLogRouteId);
						if ((0U < wLogRouteRelateBeginSigId) && (SIGNAL_SUM_MAX > wLogRouteRelateBeginSigId))
						{
							(void)DriveSignalClose(wLogRouteRelateBeginSigId);  /*驱动信号关闭*/
											/*逻辑进路响应区故解延时设置逻辑区段故障*/

							/*关闭信号以后设置逻辑进路状态为等待解锁，继续执行延时*/
							SetLogRouteStateManage(wLogSecBelLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKWAIT);
							LogRouteErrLockCmdDeal(wLogSectionId);
						}
						else
						{
							; /*不处理*/
						}
					}
					else
					{
						chLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);

						if ((LOG_SECTION_LOGLOCK_EXCEPT != chLogSecLogLockState) && (ROUTE_LOGICAL_STATE_UNLOCKDELAY != chLogRouteState))
						{
							/*逻辑区段锁闭状态不为"异常锁闭"且进路状态也不为延时解锁*/
							SetCiSendCmdBackInfoData(CI_BACK_PSEC_QGJ_UNLOCK, CI_DEVICE_TYPE_LOGICSEC, wLogSectionId, 0U, 0U);
						}
						else
						{
							wLogSecRelatePhyId = GetLgcSecRelativePhySecId(wLogSectionId);
							chPhySecCurMergeState = GetPhySecCurMergeState(wLogSecRelatePhyId);
							if ((LOG_SECTION_LOGLOCK_EXCEPT == chLogSecLogLockState) && (SECTION_OCCUPY_NO == chPhySecCurMergeState))
							{

								chLogLockDir = GetLogicalRouteDir(wLogSecBelLogRouteId);
								SetLogSecLogLockState(wLogSectionId, LOG_SECTION_LOGLOCK_NO, chLogLockDir);
								/*逻辑进路当前逻辑区段已经异常解锁，此逻辑进路需要继续异常传递*/
								LogRouteExpLockContinue(wLogSecBelLogRouteId);
								/*解锁逻辑进路处理*/
								ErrLockFaultUnLockLogRoute(wLogSectionId, wLogSecBelLogRouteId);
							}
							else
							{
								; /*不处理*/
							}
						}
					}
				}
				else
				{
					; /*不处理*/
				}
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述： 逻辑进路逻辑区段故障传递
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： void
* by cgh 20231013
*/
void LogRouteExpLockContinue(const UINT16 wLogRouteId)
{
	UINT8 chReVal = CI_ERROR;
	UINT16 wLogRouteInLogSecSum = 0U;/*逻辑进路包含逻辑区段数目*/
	UINT16* szLogRouteInLogSecIdBuf = NULL;/*逻辑进路包含逻辑区段ID数组*/
	UINT16 ii = 0U;
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT16 wFirstNormalLockLogId = 0U;/*第一个正常锁闭的逻辑区段id*/
	UINT16 wLogSecRelatePhyId = 0U;/*逻辑区段关联物理区段ID*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段当前融合状态*/
	UINT16 wOtherLogRouteId = 0U;/*其他逻辑进路ID*/

	if ((0U < wLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogRouteId))
	{
		wLogRouteInLogSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
		szLogRouteInLogSecIdBuf = GetLogicalRouteInLogSecId(wLogRouteId);

		if (NULL != szLogRouteInLogSecIdBuf)
		{
			for (ii = 0U; ii < wLogRouteInLogSecSum; ii++)
			{
				chReVal = CheckLogSecLockBelLogRoute(szLogRouteInLogSecIdBuf[ii], wLogRouteId);
				if (CI_SUCCESS == chReVal)
				{
					chLogSecLogLockState = GetLogSecLogLockState(szLogRouteInLogSecIdBuf[ii]);

					if (LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState)
					{
						if (0U == wFirstNormalLockLogId)
						{
							wFirstNormalLockLogId = szLogRouteInLogSecIdBuf[ii];
						}
						else
						{
							; /*已有第一个锁闭的逻辑区段*/
						}
					}
					else if (LOG_SECTION_LOGLOCK_EXCEPT == chLogSecLogLockState)
					{
						/*异常锁闭跳出*/
						break;
					}
					else
					{
						; /*不处理*/
					}
				}
				else
				{
					; /*不处理*/
				}
			}

			if (wLogRouteInLogSecSum == ii)
			{
				if (0U != wFirstNormalLockLogId)
				{
					wOtherLogRouteId = wLogRouteId;/*本逻辑进路继续传递*/
				}
				else
				{
					/*检查一下当前逻辑进路最后一个逻辑区段关联其他逻辑进路有无区段传递*/
					wFirstNormalLockLogId = GetOtherLogRouteFirNormalLogId(szLogRouteInLogSecIdBuf[wLogRouteInLogSecSum-1U], wLogRouteId,&wOtherLogRouteId);
				}
				/*说明逻辑进路内不存在故障区段*/
				if ((0U != wFirstNormalLockLogId) && (0U < wOtherLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wOtherLogRouteId))
				{
					wLogSecRelatePhyId = GetLgcSecRelativePhySecId(wFirstNormalLockLogId);
					chPhySecCurMergeState = GetPhySecCurMergeState(wLogSecRelatePhyId);

					if (SECTION_OCCUPY_NO == chPhySecCurMergeState)
					{
						/*设置下一逻辑区段对应物理区段属于本逻辑进路锁闭的逻辑区段均异常锁闭*/
						SetPhyIncLogSecLogLockState(wLogSecRelatePhyId, LOG_SECTION_LOGLOCK_EXCEPT, wOtherLogRouteId);
					}
					else
					{
						; /*有占压不传递*/
					}
				}
				else
				{
					; /*已经没有锁闭的区段，不传递*/
				}
			}
			else
			{
				; /*有故障区段不传递*/
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述： 获取其他逻辑进路第一个锁闭的逻辑区段ID
* 参数说明： const UINT16 wLogSecId 逻辑区段ID
			 const UINT16 wLogRouteId, 逻辑进路ID
			 UINT16* wOtherLogRouteId 其他逻辑进路ID
* 返回值  ： 其他逻辑进路第一个锁闭的逻辑区段ID
* by cgh 20231020
*/
UINT16 GetOtherLogRouteFirNormalLogId(const UINT16 wLogSecId, const UINT16 wLogRouteId, UINT16* wOtherLogRouteId)
{
	UINT16 wFirstNormalLockLogId = 0U;/*其他逻辑进路第一个锁闭的逻辑区段ID*/
	UINT16 chReVal = 0U;
	UINT16 wLogRouteInLogSecSum = 0U;/*逻辑进路包含逻辑区段数目*/
	UINT16* szLogRouteInLogSecIdBuf = NULL;/*逻辑进路包含逻辑区段ID数组*/
	UINT16 ii = 0U;
	UINT16 jj = 0U;
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/

	chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSecId);
	szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSecId);
	*wOtherLogRouteId = 0U;

	if (NULL != szLogSecLockBelLogRouteData)
	{
		for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
		{
			wLogSecBelLogRouteId = szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
			if ((0U < wLogSecBelLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogSecBelLogRouteId) && (wLogRouteId != wLogSecBelLogRouteId))
			{
				wLogRouteInLogSecSum = GetLogicalRouteInLogSecSum(wLogSecBelLogRouteId);
				szLogRouteInLogSecIdBuf = GetLogicalRouteInLogSecId(wLogSecBelLogRouteId);

				if (NULL != szLogRouteInLogSecIdBuf)
				{
					for (jj = 0U; jj < wLogRouteInLogSecSum; jj++)
					{
						chReVal = CheckLogSecLockBelLogRoute(szLogRouteInLogSecIdBuf[jj], wLogSecBelLogRouteId);
						if (CI_SUCCESS == chReVal)
						{
							chLogSecLogLockState = GetLogSecLogLockState(szLogRouteInLogSecIdBuf[jj]);

							if (LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState)
							{
								if (0U == wFirstNormalLockLogId)
								{
									wFirstNormalLockLogId = szLogRouteInLogSecIdBuf[jj];
								}
								else
								{
									; /*已有第一个锁闭的逻辑区段*/
								}
							}
							else if (LOG_SECTION_LOGLOCK_EXCEPT == chLogSecLogLockState)
							{
								/*异常锁闭跳出*/
								break;
							}
							else
							{
								; /*不处理*/
							}
						}
						else
						{
							; /*不处理*/
						}
					}

					if (wLogRouteInLogSecSum == jj)
					{
						/*说明逻辑进路内不存在故障区段*/
						if (0U != wFirstNormalLockLogId)
						{
							*wOtherLogRouteId = wLogSecBelLogRouteId;
							/*在其他逻辑锁闭所属进路中找到第一个锁闭的逻辑区段，传递，不继续查找*/
							break;
						}
						else
						{
							; /*继续找*/
						}
					}
					else
					{
						; /*有故障区段不传递*/
					}
				}
				else
				{
					; /*不处理*/
				}
			}
			else
			{
				; /*不处理*/
			}
		}
	}
	else
	{
		; /*不执行*/
	}
	return wFirstNormalLockLogId;
}

/*
* 功能描述： 获取指定逻辑进路第一个逻辑正常锁闭的逻辑区段延时故障锁闭起始周期号
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
*
* 返回值  ： 0:  获取失败
*			 >0: 逻辑进路第一个逻辑正常锁闭的逻辑区段延时故障锁闭起始周期号
* by cgh 20231017
*/
UINT32 GetLogRouFirDelayErLockStaCyc(const UINT16 wLogRouteId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;
	UINT16 wFirstNormalLockLogId = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取逻辑进路数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		wFirstNormalLockLogId = GetLogRouteFirNormalLockLogId(wLogRouteId);
		retVal = GetLogDelayErrlockStartCycNum(wFirstNormalLockLogId);
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述： 设置指定逻辑进路第一个逻辑正常锁闭的逻辑区段延时故障锁闭起始周期号
* 参数说明：const UINT16 wLogRouteId, 逻辑进路ID
*			 const UINT32 startCycNum 起始周期号
* 返回值  ： 无
* by cgh 20231017
*
*/
void SetLogRouFirDelayErLockStaCyc(const UINT16 wLogRouteId, const UINT32 startCycNum)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16 wFirstNormalLockLogId = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取逻辑进路数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		wFirstNormalLockLogId = GetLogRouteFirNormalLockLogId(wLogRouteId);
		SetLogDelayErrlockStartCycNum(wFirstNormalLockLogId, startCycNum);
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 逻辑进路区故解管理
* 参数说明： const UINT16 wPhySectionId, 物理区段ID
* 返回值  ： void
* by cgh 20231002
*/
void LogRouteErrLockFaultManage(const UINT16 wPhySectionId)
{
	UINT8 ii = 0U;
	UINT8 chPhyIncLogSum = 0U;/*物理区段包含的逻辑区段数目*/
	UINT16* pPhyIncLogId = NULL;/*物理区段包含的逻辑区段ID*/
	UINT8 chLogRouteFirstLgcSecCheck = 0U;/*逻辑区段是否为逻辑进路锁闭的第一个区段检查结果*/

	chPhyIncLogSum = GetPhySecIncLogSecSum(wPhySectionId);
	pPhyIncLogId = GetPhySecIncLogSecIdBuf(wPhySectionId);

	if (NULL != pPhyIncLogId)
	{
		for (ii = 0U; ii < chPhyIncLogSum; ii++)
		{
			/*逻辑区段如果被多个逻辑进路锁闭，此时必须为多个逻辑进路第一个锁闭的逻辑区段才允许区故解*/
			chLogRouteFirstLgcSecCheck = LogSecLogRouteFirstLockCheck(pPhyIncLogId[ii]);

			if (CI_SUCCESS == chLogRouteFirstLgcSecCheck)
			{
				/*逻辑进路响应区故解延时设置逻辑区段故障*/
				LogRouteErrLockCmdDeal(pPhyIncLogId[ii]);
			}
			else
			{
				SetErrorData(EFUNC_LOGSEC_FAULT_FIRST_SECLOCK, CI_DEVICE_TYPE_LOGICSEC, pPhyIncLogId[ii],
					ETYPE_LOGSEC_FIRSTLOCK_STATE, chLogRouteFirstLgcSecCheck, ESEND_LEVEL_ZERO);
			}
			/*逻辑进路区段故障解锁及传递*/
			LogRouteErrLockFaultProcess(pPhyIncLogId[ii]);
		}
	}
	else
	{
		; /*不处理*/
	}
}

/* 功能描述： 带进路ID的保护区段办理命令
* 参数说明： const UINT16 expLkOverlapId, ATS或现地发送的期望锁闭区段ID
*            const UINT16 routeId 进路ID
* 返回值  ： 无
*/
void SetAtsLockOverlapHaveRouteId(const UINT16 expLkOverlapId, const UINT16 routeId)
{
	UINT16 routeOverlapSum = 0U;	/*进路保护区段数目*/
	UINT16 routedLockOverlapId = 0U;	/*进路锁闭过OverlapId*/
	UINT8 retVal = CI_SUCCESS;	/*返回值*/
	UINT8 routeState = 0U;	/*进路状态*/
	UINT16 preOverlepId = 0U;
	UINT32 startXuanPaiCyc = 0U;
	UINT16 phySectionId = 0U;
	UINT8 phySectionSta = 0U;
	UINT8 belongCiId = 0U;
	UINT8 localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 virCIid = 0U;
	UINT8 ciCtrModeFlag = 0U;
	UINT8 routeStateFlag = 0U;
	UINT8 flag = 0U;

	routeStateFlag = GetRouteStateFlag(routeId);

	if ((0U == expLkOverlapId) || (UINT16_MAX == expLkOverlapId))
	{/*判断输入参数有效性*/
		retVal = CI_ERROR;
	}
	/*判断是否要传递保护区段建立命令给相邻联锁*/
	if (CI_SUCCESS == retVal)
	{
		belongCiId = GetOverlapBelongCiId(expLkOverlapId);
		if (localCiId != belongCiId)
		{
			if (0U < belongCiId)/****************相邻联锁需加接口*/
			{
				AddCiSendToCiCmdInfo(LOCK_OVERLAP_HAVE_ROUTE_CMD, expLkOverlapId, routeId, belongCiId);/*发送相邻联锁保护区段建立命令*/
			}
			retVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == retVal)
	{
		routeOverlapSum = GetRouteOverlapSum(routeId);	/*获取进路包含的保护区段数目*/
		if (0U < routeOverlapSum)
		{
			/*输入参数保护区段ID是否属于当前进路*/
			if (1U == checkExpOverlapBelongToRtOrNot(routeId, expLkOverlapId))
			{/*期望锁闭的保护区段ID属于进路的保护区段ID*/
				flag = 1U;
				retVal = CI_SUCCESS;
			}
			else
			{
				retVal = CI_ERROR;
			}

			/*检查当前进路的保护区段是否在选排过程中*/
			if (CI_SUCCESS == retVal)
			{
				preOverlepId = GetRouteAtsExpLkOverlapId(routeId);
				if (0U < preOverlepId)
				{
					startXuanPaiCyc = GetOverlapXuanPaiStartCycNum(preOverlepId);
					if (0U < startXuanPaiCyc)
					{
						retVal = CI_ERROR;
					}
					else
					{
						/*什么也不做*/
					}
				}
				else
				{
					/*什么也不做*/
				}
			}
			/*判断当前保护区段所属联锁控制模式是否可以响应锁闭保护区段命令*/
			if (CI_SUCCESS == retVal)
			{
				virCIid = GetOverlapBelongVirCiId(expLkOverlapId);
				if (FUNC_SWITCH_ON == includeVirFlag)
				{
					ciCtrModeFlag = GetVirCImode(virCIid);/*获取联锁控制模式*/
				}
				else
				{
					ciCtrModeFlag = GetCiModeFlag();	/*获取联锁控制模式*/
				}

				if ((CI_MODE_CI_LOCAL == ciCtrModeFlag) || (0U == ciCtrModeFlag))/*处于联锁控或者获取错误，发送现地不能响应人工锁闭命令*/
				{
					retVal = CI_ERROR;
				}
			}

			if (CI_SUCCESS == retVal)
			{
				routedLockOverlapId = GetRouteOverlapLockedId(routeId);	/*获取进路锁闭过保护区段ID*/

				if (0U == routedLockOverlapId)
				{
					/*判断进路状态，是否满足锁闭保护区段条件，若满足则设置期望锁闭保护区段*/
					routeState = GetRouteState(routeId);

					if ((ROUTE_STATE_FIRST_XUANPAI == routeState)
						|| (ROUTE_STATE_XUANPAI == routeState)
						|| (ROUTE_STATE_FIRST_LOCK == routeState)
						|| (ROUTE_STATE_FIRST_LOCKERR == routeState)
						|| (ROUTE_STATE_YUXIAN_OPEN == routeState)
						|| (ROUTE_STATE_YUXIAN_LOCK == routeState)
						|| (ROUTE_STATE_NEAR_OPEN == routeState)
						|| (ROUTE_STATE_NEAR_LOCK == routeState)
						|| (ROUTE_STATE_NEAR_LOCKERR == routeState)
						|| ((ROUTE_STATE_AUTO_UNLOCK == routeState) && (ROUTE_STATE_FLAG_YES == routeStateFlag))
						)
					{/*设置指定ID进路的期望锁闭保护区段ID*/
						/*仅处理ATS办理保护区段，不处理人工办理保护区段*/
						phySectionId = GetRouteLastPhySectionId(routeId);
						phySectionSta = GetPhySecCurMergeState(phySectionId);
						if (SECTION_OCCUPY_YES == phySectionSta)
						{
							SetOverlapAtsOrlaborLockCmdFlag(expLkOverlapId, LOCK_OVERLAP_CMD_YES);/*设置保护区段锁闭命令标志，用于保护区段解锁倒计时计算*/
						}
						else
						{
							/*nothing do*/
						}

						SetRouteAtsExpLkOverlapId(routeId, expLkOverlapId);/*设置期望锁闭保护区段*/

						SetOverlapFromSetRouteCmdFlag(expLkOverlapId, OVERLAP_ROUTE_FLAG_YES);/*设置保护区段由进路连带标识*/

						retVal = CI_SUCCESS;
					}
					else
					{
						retVal = CI_ERROR;
					}
				}
				else
				{
					;	/*当前进路保护区段已锁，不处理*/
				}
			}

		}

		if (0U == flag)
		{/*发送的这个区段不属于任何进路的保护区段*/
		 
			/*发送现地*/
			SetErrorData(EFUNC_SetAtsLockOverlapHaveRouteId, CI_DEVICE_TYPE_OVERLAP, expLkOverlapId, ETYPE_ROUTE_OVERLAP_UNLOCK, 0U, ESEND_LEVEL_ATS);

		}

	}
}


/**
* @brief 部分进路脚下逻辑区段逻辑锁闭处理
* @param const UINT16 wLogSecId 逻辑区段ID
*        const UINT16 routeId 当前锁闭的进路ID
* @return CI_SUCCESS：处理部分进路脚下逻辑锁闭成功
*		  CI_ERROR：处理部分进路脚下逻辑锁闭失败
*/
UINT8 LogSecLockInHalfRouteProcess(const UINT16 wLogSecId, const UINT16 routeId)
{
	UINT8 funcRet = CI_ERROR;
	UINT8 curLogLockState = 0u;  /*区段当前逻辑锁闭状态*/
	UINT8 validLogRouteIdBuf[ROUTE_LOGICAL_SUM_MAX] = { 0U };  /*需要处理有效逻辑进路ID*/
	UINT8 LogSecLockBelLogRouteSum = 0U;
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT8 ii = 0U;
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT8 validRouteSum = 0U;		/*处理冲掉的逻辑进路数量*/
	UINT16 validRouteId = 0u;		/*当前锁闭的进路*/
	UINT16 LogicalRouteInLogSecSum = 0U;
	UINT16* wLogicalRouteInLogSecIdBuf = NULL;
	UINT8 oldLogLockState = 0U;
	UINT16 wRouteIndex = 0U;
	UINT8 cLocalCiId = 0U;  /*本地CI*/
	UINT8 cLogSecBelongCiId = 0U;  /*逻辑区段所属CI*/
	UINT8 cPartRouteDir = 0U;  /*部分进路锁闭方向*/
	UINT8 cLogRouteDir = 0U;  /*逻辑进路锁闭方向*/

	curLogLockState = GetLogSecLogLockState(wLogSecId);
	LogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSecId);
	szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSecId);
	wRouteIndex = GetRouteConfigBufIndex(routeId);  /*获取进路数组下标*/
	
	if ((NULL != szLogSecLockBelLogRouteData) && (ROUTE_SUM_MAX > wRouteIndex))
	{
		funcRet = CI_SUCCESS;


		if (0U < LogSecLockBelLogRouteSum)
		{
			if (LOG_SECTION_LOGLOCK_NORMAL == curLogLockState)
			{
				cLocalCiId = GetSystemParaLocalCiId();
				cLogSecBelongCiId = GetLogSecBelongCiId(wLogSecId);
				if (cLocalCiId == cLogSecBelongCiId)
				{
					for (jj = 0U; jj < LogSecLockBelLogRouteSum; jj++)
					{
						/*将逻辑区段所有逻辑锁闭出清*/
						validRouteId = szLogSecLockBelLogRouteData[jj].wLogSecLockBelLogRouteId;

						SetLogSecLogLockState(wLogSecId, LOG_SECTION_LOGLOCK_NO, szLogSecLockBelLogRouteData[jj].wLogSecLockBelLogRouteDir);

						/*清除逻辑区段锁闭的所属进路*/
						funcRet = DelLogSecBelongLogRouteId(wLogSecId, validRouteId);

						if (CI_SUCCESS == funcRet)
						{
							for (kk = 0U; kk < validRouteSum; kk++)
							{
								if (validRouteId == validLogRouteIdBuf[kk])
								{
									/*去重添加*/
									break;
								}
							}
							if (validRouteSum == kk)
							{
								/*未重复*/
								if (ROUTE_LOGICAL_SUM_MAX > validRouteSum)
								{
									validLogRouteIdBuf[validRouteSum++] = (UINT8)validRouteId;
								}
								else
								{
									funcRet = CI_ERROR;		/*逻辑进路超限，失败处理*/
								}
							}
						}
						else
						{
							;		/*错误，不处理*/
						}

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

					if (CI_SUCCESS == funcRet)
					{
						/*处理冲掉的逻辑进路*/
						for (ii = 0U; ii < validRouteSum; ii++)
						{
							if (0U < validLogRouteIdBuf[ii])
							{
								LogicalRouteInLogSecSum = GetLogicalRouteInLogSecSum(validLogRouteIdBuf[ii]);
								wLogicalRouteInLogSecIdBuf = GetLogicalRouteInLogSecId(validLogRouteIdBuf[ii]);

								for (kk = 0U; kk < LogicalRouteInLogSecSum; kk++)
								{
									oldLogLockState = GetLogSecLogLockState(wLogicalRouteInLogSecIdBuf[kk]);

									if (LOG_SECTION_LOGLOCK_NO != oldLogLockState)
									{
										break;		/*进路中还存在逻辑锁闭，不可以将此进路置为空闲，需要最后车释放*/
									}
								}

								if (kk == LogicalRouteInLogSecSum)
								{
									/*逻辑进路中所有逻辑区段都已未锁闭，已经是逻辑进路的最后一个逻辑区段，设置该逻辑进路空闲，其余的等车释放*/
									SetLogRouteStateManage(validLogRouteIdBuf[ii], ROUTE_LOGICAL_STATE_IDLE);
								}
							}
						}
					}
				}
				else
				{
					cPartRouteDir = GetRouteDirection(routeId);
					cLogRouteDir = GetLogSecLogLockDir(wLogSecId);
					if ((1U == LogSecLockBelLogRouteSum) && (cPartRouteDir != cLogRouteDir))
					{
						/*其它控区的逻辑区段被逻辑进路锁闭，通过命令清除锁闭*/
						AddCiSendToCiCmdInfo(CI_CMD_ROUTE_SEC_LOCK_APPLY, routeId, 0U, cLogSecBelongCiId);
					}
					else
					{
						/*不处理*/
					}
				}
			}
		}
		else
		{
			;		/*逻辑区段无逻辑锁闭的逻辑区段，直接返回成功*/
		}

	}
	else
	{
		;	/*数据不合法，返回失败*/
	}

	return funcRet;
}

/**
* @brief 获取进路总人解延时解锁周期数
* @param const UINT16 wRouteId 进路ID
* @return 进路总人解延时解锁周期数
* BY CGH 20240605
*/
UINT32 GetRouteDelayCycleCount(const UINT16 wRouteId)
{
	UINT32 dwReval = UINT32_MAX;
	UINT8 chRouteLevel = 0U;         /*进路监督级别*/
	UINT8 chRouteType = 0U;          /*进路类型*/
	UINT8 chRouteBelCiId = 0U;/*进路所属联锁ID*/
	UINT8 chCiType = 0U; /*联锁类型*/
	OtherCiParaStruct otherCiParaStr = {0U};
	UINT8 chCbtcNearSecSum = 0U;/*CBTC接近区段数目*/
	RouteNearLogicSectionStruct* pCbtcNearSecData = NULL;/*CBTC接近区段数据*/
	UINT8 chBlocNearSecSum = 0U;/*点式接近区段数目*/
	RouteNearPhySectionStruct* BlocNearSecData = NULL;/*点式接近区段数据*/
	UINT8 ii = 0U;
	UINT8 chLogSecBelongCiId = 0u;/*区段所属联锁ID*/
	UINT32 dwTempDelayCyc = 0U;/*临时延时周期数*/

	if ((0U < wRouteId) && (ROUTE_SUM_MAX > wRouteId))
	{
		/*获取进路动态字段*/
		chRouteLevel = GetRouteLevel(wRouteId);                       /*获取进路监督级别*/
		chRouteType = GetRouteType(wRouteId);
		chRouteBelCiId = GetRouteBelongCiId(wRouteId);
		chCiType = GetCiType(chRouteBelCiId);

		if (ROUTE_TYPE_DIAOCHE == chRouteType)
		{
			dwReval = GetSystemParaFaultUnlockCyc();   /*获取调车进路延时周期数*/
		}
		else
		{
			if (CI_TYPE_CLD == chCiType)
			{
				if (ROUTE_LEVEL_CBTC == chRouteLevel)
				{
					dwReval = GetSystemParaCbtcRouteDelayCyc();   /*获取CBTC进路延时周期数*/
					chCbtcNearSecSum = GetRouteCbtcNearSecConditionSum(wRouteId);	/*获取进路CBTC接近逻辑区段条件数目*/
					pCbtcNearSecData = GetRouteCbtcNearLogSectionStru(wRouteId);/*获取进路CBTC接近逻辑区段数据*/

					if (NULL != pCbtcNearSecData)
					{
						for (ii = 0U; ii < chCbtcNearSecSum; ii++)
						{
							chLogSecBelongCiId = GetLogSecBelongCiId(pCbtcNearSecData[ii].NearLogicSecIdBuf[(pCbtcNearSecData[ii].NearLogicSecSum) - 1U]);
							if ((0U != chLogSecBelongCiId) && (chRouteBelCiId != chLogSecBelongCiId))
							{
								otherCiParaStr = GetOtherCiPara(chLogSecBelongCiId);
								dwTempDelayCyc = otherCiParaStr.wOtherCiCTNearUnLockCyc;
								if (dwReval < dwTempDelayCyc)
								{
									dwReval = dwTempDelayCyc;
								}
								else
								{
									; /*不更新*/
								}
							}
							else
							{
								; /*不更新*/
							}
						}
					}
					else
					{
						;
					}
				}
				else
				{
					/*点式*/
					dwReval = GetSystemParaBlocRouteDelayCyc();   /*获取点式进路延时周期数*/
					chBlocNearSecSum = GetRouteBlocNearSecConditionSum(wRouteId);	/*获取进路点式接近逻辑区段条件数目*/
					BlocNearSecData = GetRouteBlocNearPhySectionStru(wRouteId);/*获取进路点式接近逻辑区段数据*/

					if (NULL != BlocNearSecData)
					{
						for (ii = 0U; ii < chBlocNearSecSum; ii++)
						{
							chLogSecBelongCiId = GetLogSecBelongCiId(BlocNearSecData[ii].BlocNearLogSecIdBuf[(BlocNearSecData[ii].BlocNearLogSecSum) - 1U]);
							if ((0U != chLogSecBelongCiId) && (chRouteBelCiId != chLogSecBelongCiId))
							{
								otherCiParaStr = GetOtherCiPara(chLogSecBelongCiId);
								dwTempDelayCyc = otherCiParaStr.wOtherCiUTNearUnLockCyc;
								if (dwReval < dwTempDelayCyc)
								{
									dwReval = dwTempDelayCyc;
								}
								else
								{
									; /*不更新*/
								}
							}
							else
							{
								; /*不更新*/
							}
						}
					}
					else
					{
						;
					}
				}
			}
			else
			{
				if (ROUTE_LEVEL_CBTC == chRouteLevel)
				{ 
					/*CBTC*/
					dwReval = GetSystemParaCbtcRouteDelayCyc();   /*获取CBTC进路延时周期数*/
				}
				else
				{ 
					/*点式*/
					dwReval = GetSystemParaBlocRouteDelayCyc();   /*获取点式进路延时周期数*/
				}
			}
		}
	}
	else
	{
		; /*返回MAX*/
	}

	return dwReval;	
}

/*
* 功能描述：部分进路通过逻辑区段清除原进路处理
* 参数说明：const UINT16 wRouteId, 进路ID
* 返 回 值：无
* Created By LQ  2024.09.10
*/
void CleanOldRouteProcByLogSec(const UINT16 wRouteId)
{
	UINT16 wRouteIndex = 0U;
	UINT16 ii = 0U;
	UINT16 wRouteIncLogSecNum = 0U;  /*进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecId = NULL;  /*进路包含的逻辑区段ID*/
	UINT16 wLogSecRLockBelongRoute = 0U;  /*逻辑区段进路锁闭所属进路*/
	UINT8 cLocalCiId = 0U;
	UINT8 cRouteBelongCiId = 0U;

	wRouteIndex = GetRouteConfigBufIndex(wRouteId);

	if (ROUTE_SUM_MAX > wRouteIndex)
	{
		wRouteIncLogSecNum = GetRouteLogSectionSum(wRouteId);  /*获取进路包含的逻辑区段*/
		pRouteIncLogSecId = GetRouteLogSectionIdBuf(wRouteId);

		if ((0U != wRouteIncLogSecNum) && (NULL != pRouteIncLogSecId))
		{
			/*遍历进路内所有逻辑区段，检查是否还存在逻辑区段被当前进路锁闭*/
			for (ii = 0U; ii < wRouteIncLogSecNum; ii++)
			{
				wLogSecRLockBelongRoute = GetLogSecLockBelongRoute(pRouteIncLogSecId[ii]);
				if (wRouteId != wLogSecRLockBelongRoute)
				{
					/*继续遍历*/
				}
				else
				{
					break;  /*存在逻辑区段被当前进路锁闭，停止遍历*/
				}
			}

			cLocalCiId = GetSystemParaLocalCiId();
			cRouteBelongCiId = GetRouteBelongCiId(wRouteId);

			if (ii == wRouteIncLogSecNum)
			{
				/*进路内所有逻辑区段均未被本进路锁闭，置进路空闲*/
				if ((0U != cLocalCiId) && (cLocalCiId == cRouteBelongCiId))
				{
					SetRouteStateManage(wRouteId, ROUTE_STATE_IDLE);
					SetRouteRelProSwitchLockSta(wRouteId, SWITCH_LOCK_PROTECT_CANCEL);
				}
				else
				{
					/*跨控区场景预留*/
				}
			}
			else
			{
				/*进路内存在逻辑区段被本进路锁闭，无需处理*/
			}
		}
		else
		{
			/*获取进路包含的逻辑区段失败，不处理*/
		}
	}
	else
	{
		/*进路ID非法，不处理*/
	}
}

/*
* 功能描述：处理有效进路进路状态
* 参数说明： const UINT16 wRouteId, 进路ID
* 返回值  ： void
* BY CGH 20241204
*/
void DealValidRouteState(const UINT16 wRouteId)
{
	UINT8 chRoutePhySecSum = 0U;  /*进路物理区段总数*/
	UINT8 ii = 0U;  /*遍历变量*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT16 wPhySecRLockBelRouteId = 0U;/*物理区段锁闭所属进路*/

	if ((0U < wRouteId) && (ROUTE_SUM_MAX > wRouteId))
	{
		chRoutePhySecSum = GetRoutePhysicalSectionSum(wRouteId);  /*获取进路物理区段总数*/
		pPhySecDataStru = GetRouteSectionData(wRouteId);  /*获取进路物理区段数据*/

		if (NULL != pPhySecDataStru)
		{
			for (ii = 0u; ii < chRoutePhySecSum; ii++)
			{
				wPhySecRLockBelRouteId = GetPhySecRLockBelongRouteId(pPhySecDataStru[ii].PhysicalSectionId);
				if (wRouteId == wPhySecRLockBelRouteId)
				{
					break;
				}
				else
				{
					;
				}
			}

			if (ii == chRoutePhySecSum)
			{
				(void)SetRouteState(wRouteId, ROUTE_STATE_IDLE);
				/*取消进路关联防护道岔的防护锁闭*/
				SetRouteRelProSwitchLockSta(wRouteId, SWITCH_LOCK_PROTECT_CANCEL);
			}
			else
			{
				/*不处理*/
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}