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

#include "TradInterlockLogicManage.h"
#include "RouteRecoverManage.h"


void ClosSigByGrgdoorCloseCmd(UINT16 grgdoorId);

/*
* 功能描述： 联锁逻辑主处理
* 参数说明： void
* 返回值  ：    
*/
void TradInterlockLogicMainProc(void)
{
    /*应急盘功能处理*/
	JKJRelayLogicProcess();

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

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

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

/*
* 功能描述： 应急盘功能处理
* 参数说明： void
* 返回值  ：    
*/
void JKJRelayLogicProcess(void)
{
	UINT16 wJkjRelayId = 0u;
	UINT8 JkjRelayState = CI_ERROR;
	UINT32 yjValidCycNum = 0u;
	UINT32 curCycNum = 0u;
	UINT8 checkRes = CI_TIME_OUT;
	UINT8 ii = 0u;
	UINT8 haveYjkBreakFlag = 0u;
	UINT8 ocYjkBreakFlag = 0u;

	wJkjRelayId = GetJkjRelayId();
	JkjRelayState =	GetRelayCollState(wJkjRelayId);                 /*JKJ应急盘继电器采集状态*/
	yjValidCycNum = GetJkjRelayValidCycNum();                     /*JKJ应急盘状态有效周期*/
	curCycNum = Get2oo2CurCycleNum();
	
	for (ii = 0u; ii < m_OcToCiOrginDataNum; ii++)
	{
		if (OC_HAVE_YJK == m_OcToCiOrginDataArr[ii].chHaveYjk)
		{/*任意一个OC具备应急控*/
			haveYjkBreakFlag = 1u;
			break;
		}
		else
		{
			; /*继续*/
		}
	}

	for (ii = 0u; ii < m_OcToCiOrginDataNum; ii++)
	{
		if (OC_CTLMODE_YJK == m_OcToCiOrginDataArr[ii].chControlMode)
		{/*任意一个OC是应急控*/
			ocYjkBreakFlag = 1u;
			break;
		}
		else
		{
			; /*继续*/
		}
	}

	if (wJkjRelayId > 0u)
	{
		/*配置了继电器*/
		if (RELAY_STATE_DOWN == JkjRelayState)
		{/*落下*/
			if (0u == yjValidCycNum)
			{/*未计时*/
				SetJkjRelayValidCycNum(curCycNum);   /*设置应急有效周期*/
			}
			else
			{
				; /*不做处理*/
			}
			checkRes = SystemOverTimeCheck(yjValidCycNum, JKJ_REYLAY_VALID_CYCLE_NUM);
			if (CI_TIME_OUT == checkRes)
			{ /*应急有效*/
				SetCiJkjFlag(JKJ_REYLAY_VALID);    /*设置应急盘有效标志为有效*/
			}
			else
			{
				; /*不做处理*/
			}
		}
		else if (RELAY_STATE_UP == JkjRelayState)
		{/*吸起*/
			/*应急无效*/
			SetCiJkjFlag(JKJ_REYLAY_INVALID);           /*设置应急盘有效标志为无效*/
			SetJkjRelayValidCycNum(0u);   /*设置应急无效周期*/
		}
		else
		{
			/*应急无效*/
			SetCiJkjFlag(JKJ_REYLAY_VALID);           /*设置应急盘有效标志为无效*/
			SetJkjRelayValidCycNum(curCycNum);   /*设置应急无效周期*/
		}
	}
	else if(1u == haveYjkBreakFlag)
	{
		/*OC具备应急控*/
		if (1u == ocYjkBreakFlag)
		{/*有一个OC处于应急控,则应急有效*/
			if (0u == yjValidCycNum)
			{/*未计时*/
				SetJkjRelayValidCycNum(curCycNum);   /*设置应急有效周期*/
			}
			else
			{
				; /*不做处理*/
			}
			checkRes = SystemOverTimeCheck(yjValidCycNum, JKJ_REYLAY_VALID_CYCLE_NUM);
			if (CI_TIME_OUT == checkRes)
			{ /*应急有效*/
				SetCiJkjFlag(JKJ_REYLAY_VALID);    /*设置应急盘有效标志为有效*/
			}
			else
			{
				; /*不做处理*/
			}
		}
		else
		{/*应急无效*/
			SetCiJkjFlag(JKJ_REYLAY_INVALID);           /*设置应急盘有效标志为无效*/
			SetJkjRelayValidCycNum(0u);   /*设置应急无效周期*/
		}
	}
	else
	{
		/*JKJ未配置，OC无应急控功能，应急盘无效*/
		SetCiJkjFlag(JKJ_REYLAY_INVALID);           /*设置应急盘有效标志为无效*/
		SetJkjRelayValidCycNum(0u);   /*设置应急无效周期*/
	}

}

/*
* 功能描述： 非进路逻辑处理
* 参数说明： void
* 返回值  ：    
*/
void NonRouteLogicProcess(void)
{
	UINT8 nonRouteState = 0u;	    /*非进路状态*/

	UINT8 i = 0u;

	for (;i<NONROUTE_ID_NUM_MAX;i++)
	{
		NonRouteDataStruct* pNonRoute = GetNonRouteDataPtr()+i;

		if (pNonRoute->NonRouteId == 0u)
		{
			continue;
		}

		nonRouteState = pNonRoute->NonRouteState;              /*获取非进路状态*/

		if (NONROUTE_STATE_IDLE == nonRouteState)
		{ /*非进路空闲*/
			; 
		}
		else if (NONROUTE_STATE_XUANPAI == nonRouteState)
		{ /*非进路调车选排*/
		
			NonRouteXuanPaiDeal(pNonRoute->NonRouteId); /*非进路选排处理*/
		}
		else if (NONROUTE_STATE_LOCK == nonRouteState)
		{ /*非进路调车锁闭*/
		
			NonRouteLockDeal(pNonRoute->NonRouteId); /*非进路锁闭处理*/
		}
		else if (NONROUTE_STATE_LOCKERR == nonRouteState)
		{ /*非进路调车故障锁闭*/
		
		}
		else if (NONROUTE_STATE_OPEN == nonRouteState)
		{ /*非进路调车开放*/
		
			NonRouteOpenDeal(pNonRoute->NonRouteId); /*非进路开放处理*/
		}
		else if (NONROUTE_STATE_DELAY_UNLOCK == nonRouteState)
		{ /*非进路调车在延时解锁阶段*/
		
			NonRouteDelayUnlockDeal(pNonRoute->NonRouteId); /*非进路调车延时解锁逻辑检查*/
		}
		else if (NONROUTE_STATE_FAULTDELAY_UNLOCK == nonRouteState)
		{ /*故障延时解锁*/
		
			NonRouteFaultDelayUnlockDeal(pNonRoute->NonRouteId); /*非进路调车故障延时解锁逻辑检查*/
		}
		else
		{
			/*进路数据错误*/
		}

    
		/*取消非进路*/
		if ((NONROUTE_CANCEL_FLAG_YES ==pNonRoute->CancelFlag) 
		 && (NONROUTE_CANCEL_FLAG_NO ==pNonRoute->HaveCancelFlag))
		{ 
			NonRouteCancelDeal(pNonRoute->NonRouteId); /*非进路取消处理*/
		}
	}
}


/*
* 功能描述： 非进路调车选排管理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void   
*/
void NonRouteXuanPaiDeal(UINT8 nonRouteId)
{
	NonRouteDataStruct *pNonRoute = GetNonRouteDataById(nonRouteId);
	if (CI_SUCCESS == LockNonRouteP(nonRouteId))
	{ /*锁闭成功*/
        
        if (CI_SUCCESS == CheckNonRouteSwitchPosRight(nonRouteId,0u,0u))
		{ /*进路道岔位置正确*/
			SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_LOCK); /*设置非进路为锁闭*/
		}
		else
		{ /*道岔未动作到位*/
		
            /*非进路锁闭驱动道岔*/
		    if (CI_ERROR == NonRouteLockDrvSwitchDeal(nonRouteId))
		    {
                SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_IDLE); /*设置非进路为空闲*/
		    }

		}
    }
	else
	{ /*进路锁闭失败*/
        
		SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_IDLE); /*设置非进路为空闲*/
	}
}


/*
* 功能描述： 非进路调车锁闭管理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void   
*/
void NonRouteLockDeal(UINT8 nonRouteId)
{
	if (CI_SUCCESS == CheckNonRouteSignalAllOpen(nonRouteId))
	{ /*所有信号都开放*/
		
		SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_OPEN); /*设置非进路开放*/

		NonRouteOpenDeal(nonRouteId); /*非进路信号开放处理*/
	}
	else
	{ /*信号关闭*/

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

			DriveNonRouteSignalOpen(nonRouteId); /*驱动非进路信号开放*/
		}
		else
		{ /*开放失败*/
			
			DriveNonRouteSignalClose(nonRouteId); /*驱动非进路信号关闭*/
			
			SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路锁闭异常*/

		}
	}
}


/*
* 功能描述： 非进路调车开放管理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void   
*/
void NonRouteOpenDeal(UINT8 nonRouteId)
{
	NonRouteDataStruct *pNonRoute = GetNonRouteDataById(nonRouteId);
	if (pNonRoute !=NULL)
	{
	
		if (CI_SUCCESS == CheckNonRouteSignalAllOpen(nonRouteId))
		{ /*所有信号都开放*/
		
			if (CI_SUCCESS == KeepOpenNonRouteP(nonRouteId))
			{ /*保持开放成功*/

				DriveNonRouteSignalOpen(nonRouteId); /*驱动非进路信号开放*/
			}
			else
			{ /*开放失败*/
			
				DriveNonRouteSignalClose(nonRouteId); /*驱动非进路信号关闭*/
			
				SetNonRouteStateDeal(pNonRoute->NonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路锁闭异常*/
			}
		}
		else
		{ /*信号关闭*/

			DriveNonRouteSignalClose(nonRouteId); /*驱动非进路信号关闭*/
			
			SetNonRouteStateDeal(pNonRoute->NonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路锁闭异常*/
		}
	}
}


/*
* 功能描述： 非进路调车延时解锁处理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void   
*/
void NonRouteDelayUnlockDeal(UINT8 nonRouteId)
{
    UINT32 delayStartCycNum = 0u;  /*延时解锁起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时解锁总周期数*/
	

	/*驱动非进路信号关闭*/
	DriveNonRouteSignalClose(nonRouteId);

	delayStartCycNum = GetNonRouteDelayUnlockStartCyc(nonRouteId); /*获取非进路延时解锁起始周期*/
	delayTotalCycSum = GetSystemParaNonRDelayUnlockCnt(); /*获取非进路延时周期数*/
	
	if ((0u == Get2oo2CurCycleNum()) || (delayTotalCycSum == 0u) || (delayStartCycNum == 0u))
	{ /*延时时间无效*/
		
		return;
	}

	if (CI_SUCCESS == CancelNonRouteP(nonRouteId))
	{ /*取消成功*/
        
		if(CI_TIME_OUT == SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum))
		{ /*时间已到*/
            		 
		    SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_IDLE); /*设置非进路为空闲*/
		}
		else
		{
            /*时间未到或未设置*/
		}
	}
	else
	{ /*取消失败*/
	    
		SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路锁闭异常*/
	} 
}


/*
* 功能描述： 非进路调车故障延时解锁处理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void   
*/
void NonRouteFaultDelayUnlockDeal(UINT8 nonRouteId)
{
    UINT32 delayStartCycNum = 0u;  /*延时解锁起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时解锁总周期数*/
	

	/*驱动非进路信号关闭*/
	DriveNonRouteSignalClose(nonRouteId);

	delayStartCycNum = GetNonRouteDelayUnlockStartCyc(nonRouteId); /*获取非进路延时解锁起始周期*/
	delayTotalCycSum = GetSystemParaNonRDelayUnlockCnt(); /*获取非进路延时周期数*/
	
	if ((0u == Get2oo2CurCycleNum()) || (delayTotalCycSum == 0u) || (delayStartCycNum == 0u))
	{ /*延时时间无效*/
		
		return;
	}

	if (CI_SUCCESS == FaultCancelNonRouteP(nonRouteId))
	{ /*取消成功*/
        
		if(CI_TIME_OUT == SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum))
		{ /*时间已到*/
            		 
		    SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_IDLE); /*设置非进路为空闲*/
		}
		else
		{
            /*时间未到或未设置*/
		}
	}
	else
	{ /*取消失败*/
	    
		SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路锁闭异常*/
	} 
}


/*
* 功能描述： 长调进路逻辑处理
* 参数说明： void
* 返回值  ：    
*/
void LongRouteLogicProcess(void)
{
	UINT16 longRouteCurSum = 0u; /*长进路总数目*/
	UINT8 longRouteState = 0u; /*长进路状态*/
	UINT16 longRouteId = 0u; /*长进路ID*/
	UINT16 ii = 0u; /*循环索引*/
	UINT8 longRouteSubRouteSum = 0u;
	UINT16* longRouteSubRouteIdBuf = NULL;
	UINT8 virCIid = 0u;
	UINT16 recordErrorNum = 0u;
	
	longRouteCurSum = GetLongRouteCurSum(); /*获取进路总数*/

	if (GetStartLockFlag() != CI_START_LOCK_NO)
	{ /*未上电解锁*/
	
		return;
	}
	
	/*处理进路*/
	for (ii = 0u; ii <= longRouteCurSum; ii++)
	{
		longRouteId = 0u; /*进路ID*/
	    longRouteState = 0u; /*进路状态*/
		
		longRouteId = GetLongRouteId(ii); /*获取进路ID*/
		longRouteState = GetLongRouteState(longRouteId); /*获取长调进路状态*/

		/*cgh-合并CID-2349-5：*/
		longRouteSubRouteSum = GetLongRouteSubRouteSum(longRouteId);
		longRouteSubRouteIdBuf = GetLongRouteSubRouteIdBuf(longRouteId);
		if ((0u < longRouteSubRouteSum) && (NULL != longRouteSubRouteIdBuf))
		{
			virCIid = GetRouteBelongVirCiId(longRouteSubRouteIdBuf[0]);
		}
		recordErrorNum = GetErrorDataCurSum();
		/*#####进路状态处理#####*/
		if (ROUTE_LONG_STATE_IDLE == longRouteState)
		{ /*进路空闲*/
#if 0
			RouteIdleManage(routeId);
#endif
		}
		else if (ROUTE_LONG_STATE_XUANPAI == longRouteState)
		{/*长调进路选排*/
		    
			LongRouteXuanPaiDeal(longRouteId); /*长调选排处理*/
		}
		else if (ROUTE_LONG_STATE_LOCK == longRouteState)
		{/*长调进路锁闭*/
		    
			LongRouteLockDeal(longRouteId); /*长调锁闭处理*/
		}
        else
		{
            /*状态异常*/
            /*xxxxx 宕机*/
		}
		/*cgh-合并CID-2349-5：*/
		SetErrorDataBelongVirCiId(recordErrorNum, virCIid);/*将检查过程中产生的ErrorCode赋值*/
	}
}


/*
* 功能描述： 长调进路选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void LongRouteXuanPaiDeal(const UINT16 longRouteId)
{
	UINT8 subRouteSum = 0u; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0u;
    UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE;/*带动道岔是否需要被驱动*/
	UINT8 cSGBJDelayOpenFlag = 0U;  /*声光报警延时开放标志*/

    subRouteSum = GetLongRouteSubRouteSum(longRouteId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(longRouteId); /*子进路号*/

	if (1U>=subRouteSum) 
	{
		return;
	}
	else
	{
	    ;
	}

	if (CI_SUCCESS == LockLongDTrainRouteP(longRouteId))
	{ /*锁闭成功*/
        
        for (ii = 0u; ii < subRouteSum; ii++)
		{
            NeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(pSubRouteIdBuf[ii]);/*检查带动道岔是否需要被驱动*/

			if((CI_SUCCESS == CheckRouteSwitchPosRight(pSubRouteIdBuf[ii])) && (SWITCH_NEED_DRIV_FALSE == NeedForDrvRoutAssoSwit))
			{ /*进路道岔位置正确*/
			}
			else
			{ /*道岔未动作到位*/
			
                if (CI_ERROR == RouteLockDriveSwitch(pSubRouteIdBuf[ii], NeedForDrvRoutAssoSwit))
                {
                    /*道岔驱动失败*/

					SetRoutAssoSwitSingOperStat(pSubRouteIdBuf[ii], SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

                    SetRouteStateDeal(pSubRouteIdBuf[ii], ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
                    
                    SetRoutePhySectionOccupyState(pSubRouteIdBuf[ii], PHYSICAL_SECTION_USING_NO); /*清除区段征用*/

                    SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
		        }
				else
    	    	{
	        	    ;
    	    	}
				
				return;
			}
			
		}
		
		for (ii = 0u; ii < subRouteSum; ii++)
		{
			if ((subRouteSum - 1U) != ii)
			{
				SetRelZuHeRouteSGBJDelayFlag(pSubRouteIdBuf[ii], ROUTE_SGBJ_DELAY_OPEN_INVALID);  /*非组合进路最始端的子进路，设置关联组合进路声光报警延时标志无效*/
			}
			else
			{
				cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(pSubRouteIdBuf[ii]);
				if (ROUTE_SGBJ_DELAY_OPEN_VALID == cSGBJDelayOpenFlag)
				{
					SetRelZuHeRouteSGBJDelayFlag(pSubRouteIdBuf[ii], ROUTE_SGBJ_DELAY_OPEN_VALID);  /*组合进路最始端的子进路声光报警延时标志有效，表示组合进路为出库方向，设置关联组合进路声光报警延时标志有效*/
				}
				else
				{
					SetRelZuHeRouteSGBJDelayFlag(pSubRouteIdBuf[ii], ROUTE_SGBJ_DELAY_OPEN_INVALID);  /*组合进路最始端的子进路声光报警延时标志无效，表示组合进路为入库方向，设置关联组合进路声光报警延时标志有效*/
				}
			}

			SetRoutAssoSwitSingOperStat(pSubRouteIdBuf[ii], SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

		    SetRouteStateDeal(pSubRouteIdBuf[ii], ROUTE_STATE_FIRST_LOCK); /*-->设置进路初锁*/

			SetRouteStateDeal(pSubRouteIdBuf[ii], ROUTE_STATE_FIRST_LOCKERR); /*-->设置进路初锁异常*/
			
			SetRouteBelongLongRouteId(pSubRouteIdBuf[ii],longRouteId); /*设置进路所属长调进路Id*/

			SetRouteGroupRouteCmdFlag(pSubRouteIdBuf[ii], ROUTE_GROUPROUTE_CMD_YES);/*设置进路存在组合进路命令标志*/
		}
		
		SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_LOCK); /*-->设置长调进路锁闭*/
    }
	else
	{ /*进路锁闭失败*/
        
		SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
	}
}


/*
* 功能描述： 长调进路锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void LongRouteLockDeal(const UINT16 longRouteId)
{
	UINT8 subRouteSum = 0u; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0u;
	
    subRouteSum = GetLongRouteSubRouteSum(longRouteId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(longRouteId); /*子进路号*/
	

	if (1U >= subRouteSum ) 
	{
		return;
	}
	else
	{
	    ;
	}
	
	for (ii = 0u; ii < subRouteSum; ii++)
	{
		if ((GetRouteState(pSubRouteIdBuf[ii]) == ROUTE_STATE_FIRST_LOCKERR) &&
            (GetRouteBelongLongRouteId(pSubRouteIdBuf[ii]) != longRouteId))
		{ /*子进路状态不为初锁异常*/
		    
			SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
			return;
		}
		else
		{
		    ;
		}
	}
    
	for (ii = 0u; ii < subRouteSum; ii++)
	{
		if ((ROUTE_STATE_YUXIAN_OPEN == GetRouteState(pSubRouteIdBuf[ii])) ||
		    (ROUTE_STATE_NEAR_OPEN == GetRouteState(pSubRouteIdBuf[ii])))
		{ /*子进路状态为预先开放||接近开放*/
		    
			continue;
		}
		else if (ROUTE_STATE_FIRST_LOCK == GetRouteState(pSubRouteIdBuf[ii]))
		{ /*进路初锁*/
		    
			break;
		}
		else
		{
		    if ((GetRouteState(pSubRouteIdBuf[ii]) != ROUTE_STATE_FIRST_LOCKERR) ||
		        (GetRouteBelongLongRouteId(pSubRouteIdBuf[ii]) != longRouteId))
			{ /*子进路状态不为初锁异常||所属长调不为本进路*/
				
				SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
			}
			else
			{
			    SetRouteStateDeal(pSubRouteIdBuf[ii], ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/
			}

			break;
		}
	}
}


/*
* 功能描述： 进路逻辑处理
* 参数说明： void
* 返回值  ：    
*/
void RouteLogicProcess(void)
{
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 routeState = 0u;        /*进路状态*/
	UINT8 zongQuXiaoFlag = 0u;    /*进路总取消标志*/
	UINT8 zongRenJieFlag = 0u;    /*进路总人解标志*/
	UINT16 ii = 0u;               /*循环索引*/
	UINT8 virCIid = 0u;
	UINT16 recordErrorNum = 0u;
	
	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/

	if (GetStartLockFlag() != CI_START_LOCK_NO)
	{ /*未上电解锁*/
	
		return;
	}

 
 	/*引导总锁信号开放管理*/
    YLockSignalOpenManage();
	
	/*处理调车中途折返*/
    DTrainReturnUnlockP();

	/*处理进路状态*/
	for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = 0u;	         /*进路ID*/
	    belongCiId = 0u;          /*进路所属联锁ID*/
	    routeState = 0u;          /*进路状态*/
	    zongQuXiaoFlag = 0u;      /*进路总取消标志*/
	    zongRenJieFlag = 0u;      /*进路总人解标志*/
		routeId = GetRouteId(ii);                           /*获取进路ID*/
		belongCiId = GetRouteBelongCiId(routeId);           /*获取进路所属联锁ID*/

		virCIid = GetRouteBelongVirCiId(routeId);
		recordErrorNum = GetErrorDataCurSum();
		
		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
		    continue;
		}
		
		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			/*************非本联锁Overlap逻辑管理***************/
            /*处理站间保护区段锁闭逻辑处理*/
            LockOverlapLogicManage(routeId);
            
            /*解锁保护区段*/
            UnlockOverlapLogicManage(routeId);
            
            /*****************进路逻辑管理**********************/
			continue;
		}
		
		/*获取进路动态字段*/
		routeState = GetRouteState(routeId);                       /*获取进路状态*/
		zongQuXiaoFlag = GetRouteZongQuXiaoFlag(routeId);          /*获取进路总取消标志*/
		zongRenJieFlag = GetRouteZongRenJieFlag(routeId);          /*获取进路总人解标志*/
		

		/*#####进路状态处理#####*/
		if (ROUTE_STATE_IDLE == routeState)
		{ /*进路空闲*/
#if 0
			RouteIdleManage(routeId);
#endif
		}
		else if (ROUTE_STATE_FIRST_XUANPAI == routeState)
		{/*进路预选*/
		}
		else if (ROUTE_STATE_XUANPAI == routeState)
		{ /*进路选排*/
		    
			CommonRouteXuanPaiDeal(routeId); /*普通进路选排处理*/
		}
		else if (ROUTE_STATE_LEAD_XUANPAI == routeState)
		{ /*进路引导选排*/
		    
			LeadRouteXuanPaiDeal(routeId); /*引导进路选排处理*/
		}
		else if (ROUTE_STATE_FIRST_LOCK == routeState)
		{ /*进路初锁*/
			
			RouteFirstLockDeal(routeId); /*进路初锁处理*/
		}
		else if (ROUTE_STATE_FIRST_LOCKERR == routeState)
		{ /*进路初锁异常*/
			
			RouteFirstLockErrDeal(routeId); /*进路初锁异常处理*/
		}
		else if (ROUTE_STATE_YUXIAN_LOCK == routeState)
		{ /*预先锁闭*/
            
			RouteYuXianLockDeal(routeId); /*进路预先锁闭处理*/
		}
		else if (ROUTE_STATE_YUXIAN_OPEN == routeState)
		{ /*预先开放*/
            
			RouteYuXianOpenDeal(routeId); /*进路预先锁闭处理*/
		}
		else if (ROUTE_STATE_NEAR_LOCK == routeState)
		{ /*接近锁闭正常*/
		    
			RouteNearLockDeal(routeId); /*进路接近锁闭处理*/
		}
		else if (ROUTE_STATE_NEAR_LOCKERR == routeState)
		{ /*接近锁闭异常*/
		
		    RouteNearLockErrDeal(routeId); /*进路接近锁闭异常处理*/
		}
		else if (ROUTE_STATE_NEAR_OPEN == routeState)
		{ /*接近开放*/
		    
			RouteNearOpenDeal(routeId);  /*进路接近开放处理*/
		}
		else if (ROUTE_STATE_DELAY_UNLOCK == routeState)
		{ /*延时解锁*/
		    
			RouteDelayUnlockDeal(routeId); /*进路延时解锁处理*/
		}
		else if (ROUTE_STATE_AUTO_UNLOCK == routeState)
		{ /*自动解锁正常*/
		    
			RouteSecAutoUnlockDeal(routeId); /*进路自动解锁处理*/
		}
		else if (ROUTE_STATE_AUTO_UNLOCKERR == routeState)
		{ /*自动解锁异常*/
		    
			RouteSecAutoUnlockErrDeal(routeId); /*进路自动解锁异常处理*/
		}
		else if (ROUTE_STATE_LEAD_LOCK == routeState)
		{ /*引导锁闭*/
		
		    RouteLeadLockDeal(routeId); /*引导进路锁闭处理*/
		}
		else if (ROUTE_STATE_LEAD_OPEN == routeState)
		{ /*引导开放*/
		    
			RouteLeadOpenDeal(routeId); /*引导进路开放处理*/
		}
		else if (ROUTE_STATE_LEAD_LOCKERR == routeState)
		{
            RouteLeadLockErrDeal(routeId); /*引导进路锁闭异常处理*/
		}
        else
		{
            /*状态异常*/
            /*xxxxx 宕机*/
		}

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

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

		TryClearRouteTrainEnterFlag(routeId);
		/*#####进路取消处理#####*/
		if (ROUTE_ZONGQUXIAO_SET_YES == zongQuXiaoFlag)
		{ /*已办理总取消*/

			RouteZongQuXiaoDeal(routeId);
		}
		else if(ROUTE_ZONGRENJIE_SET_YES == zongRenJieFlag)
		{ /*已办理总人解*/
		
			RouteZongRenJieDeal(routeId);
		}
		else
		{/*不处理*/
		}
		/*************本联锁Overlap逻辑管理***************/
		/*处理站间保护区段锁闭逻辑处理*/
		LockOverlapLogicManage(routeId);

		/*解锁保护区段*/
		UnlockOverlapLogicManage(routeId);
		/*****************进路逻辑管理********************/

		/*扣车、SPKS、PSD导致信号关闭又重开处理*/
		RouteRecoverOpenProc(routeId);

		/*根据进路状态清理相关标志*/
		ClearSomeFlagDependRouteState(routeId);
		/*cgh-合并CID-2349-5：*/
		SetErrorDataBelongVirCiId(recordErrorNum, virCIid);
	}
}


/*
* 功能描述： 进路选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void CommonRouteXuanPaiDeal(const UINT16 routeId)
{
	UINT8 routeType = 0u;      /*进路类型*/
	UINT8 returnValue = 0u;    /*返回值定义*/
	UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE;	/*带动道岔是否需要被驱动*/
	UINT8 usingCheck = 0u;
	UINT8 xuanPaiOvertime = 0u;/*选排超时*/
	UINT8 switchCheak = 0u;
	UINT8 switchDriveOvertime = 0u;
	UINT8 switchDrive= 0u;
	UINT8 checkVainResult = 0u;/*进路侵线检查*/
	UINT16 deviceId = 0u;
	UINT8 deviceState = 0u;
	UINT8 functionId = EFUNC_RouteLockVainCheak;/*侵线条件检查函数*/
	routeType = GetRouteType(routeId);      /*获取进路类型*/
	usingCheck = RouteFirstXuanProc(routeId);
	
	if (CI_ERROR == usingCheck)
	{
		/*征用失败*/

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

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

		if (ROUTE_TYPE_LIECHE == routeType)
		{ /*列车进路*/
			
			returnValue = LockLTrainRouteP(routeId);
		}
		else if (ROUTE_TYPE_DIAOCHE == routeType)
		{ /*调车进路*/
		    
			returnValue = LockDTrainRouteP(routeId);
		}
		else
		{ /*进路类型错误*/
		
			return;
		}
		if(CI_SUCCESS == returnValue)
		{
			/*检查带动道岔是否需要被驱动*/
			NeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(routeId);
			switchCheak = CheckRouteSwitchPosRight(routeId);
			if ((CI_SUCCESS == switchCheak) && (SWITCH_NEED_DRIV_FALSE == NeedForDrvRoutAssoSwit))
			{ /*进路道岔位置正确及带动道岔无需被驱动*/
				checkVainResult = RouteIntruSecVainCheck(routeId,&deviceId,&deviceState);
				SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/
				if(CI_SUCCESS == checkVainResult)
				{
					/*侵线检查成功*/
					SetRouteStateDeal(routeId, ROUTE_STATE_FIRST_LOCK);  /*-->设置进路初锁*/
				}
				else
				{
					/*进路侵线检查失败*/

					SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
					/* 记录故障码 */
					SetErrorData(functionId,CI_DEVICE_TYPE_PHYSEC,deviceId,ETYPE_PS_INTRU_OCU_STATE,deviceState,ESEND_LEVEL_ATS); 
				}
			}
			else
			{ /*道岔未动作到位或者带动道岔仍需被驱动*/
				switchDriveOvertime = ChekRoutSwitDrivOvtmStat(routeId);
				if (CI_SUCCESS == switchDriveOvertime)
				{/*检查进路内方道岔驱动是否超时*/
					switchDrive = RouteLockDriveSwitch(routeId, NeedForDrvRoutAssoSwit);
					if (CI_ERROR == switchDrive)
					{ /*未超时，继续驱动道岔*/
						SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

						SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

						SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
					}
					else
					{
						/*继续*/
					}
				} 
				else
				{/*进路内方道岔驱动超时，则设置进路空闲*/
					SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除带动道岔被单操过的历史*/

					SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
				}
			}
		}
		else
		{ /*进路锁闭失败*/
	        
			SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除带动道岔被单操过的历史*/

			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
		}
	}
	/*等待*/
	else if(RETURN_FIRSTXUANPAI_ERR_WAIT == usingCheck)
	{
		xuanPaiOvertime = RouteFirstXuanOverTime(routeId);
		if (OVERTIME_YES == xuanPaiOvertime)
		{/*选排超时*/
			/*设置进路物理区段未征用*/
			SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO);

			/*设置进路空闲*/
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  
			/*增加进路初选超时错误码打印*/
			SetErrorData(EFUNC_CommonRouteXuanPaiDeal,CI_DEVICE_TYPE_ROUTE,routeId,
				ETYPE_ROUTE_FIRST_XUANPAI_OVERTIME,ROUTE_STATE_FIRST_XUANPAI,ESEND_LEVEL_ZERO);
		}
		else
		{
			/*不处理*/
		}
	}
	else	
	{
		/*无操作*/
	}

}


/*
* 功能描述： 引导进路选排管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   无
*/
void LeadRouteXuanPaiDeal(const UINT16 routeId)
{
    UINT8 NeedForDrvRoutAssoSwit = SWITCH_NEED_DRIV_FALSE;/*带动道岔是否需要被驱动*/
	
    if (CI_SUCCESS == LockLeadTrainRouteP(routeId))
	{ /*锁闭成功*/

		/*检查进路带动道岔组是否需要被驱动*/
        NeedForDrvRoutAssoSwit = CheckRoutAssoSwitNeedDriv(routeId);

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

			SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCK);  /*-->设置引导锁闭*/
		}
		else
		{ /*道岔未动作到位*/
			if (CI_SUCCESS == ChekRoutSwitDrivOvtmStat(routeId))
			{/*检查进路内方道岔驱动是否超时*/
				if (RouteLockDriveSwitch(routeId, NeedForDrvRoutAssoSwit) == CI_ERROR)
				{ /*未超时，继续驱动道岔*/
					SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/

					SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

					SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
				}

			} 
			else
			{/*进路内方道岔驱动超时，则设置进路空闲*/
				SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除带动道岔被单操过的历史*/

				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

				SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
			}
		
		}
    }
	else
	{ /*进路锁闭失败*/
		SetRoutAssoSwitSingOperStat(routeId, SWITCH_SINGLE_OPERATED_FALSE);/*清除进路带动道岔组被单操过的历史*/
        
		SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/

		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*清除区段征用*/
	}
}


/*
* 功能描述： 进路初锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteFirstLockDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT8 openCloseState = 0u; /*信号机开放关闭状态*/

	UINT8 returnValue = 0u;          /*是否继续执行*/

	/* 开放信号时间状态*/
	UINT8 const routeTimeState = SystemOverTimeCheck(GetRouteOpenSigStatrtCycNum(routeId),
		GetSystemParaRouteOpenSigCyc());
	
	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId); /*获取进路始端信号机ID*/
	openCloseState = GetSignalOpenCloseState(GetSignalCurColor(startSignalId)); /*获取进路始端信号机开放关闭状态*/

	/*列车进路*/
	if (ROUTE_OVERLAP_SET_NO == GetRouteOverlapLockFlag(routeId))
	{ 
		/*进路保护区段未锁闭*/
		if (CI_TIME_IN != routeTimeState)
		{
			/*信号开放超时*/
			SetRouteStateManage(routeId, ROUTE_STATE_FIRST_LOCKERR);  /*-->设置初锁异常*/
			returnValue = CI_ERROR;
		}
		else
		{
			/*未超时等待保护区段锁闭*/
			returnValue = CI_ERROR;
		}
	}
	else
	{
		/*保护区段已锁或没有保护区段*/

		/*保护区段已锁或没有保护区段*/

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

		}
	}

	if (CI_SUCCESS == returnValue)
	{
		if (SIGNAL_OPEN == openCloseState)
		{ /*信号开放*/
		
			if (CI_SUCCESS == RouteHaveTrainNear(routeId))
			{
				SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_OPEN); /*设置接近开放*/
			
				RouteNearOpenDeal(routeId); /*进路接近开放处理*/
			}
			else
			{
				SetRouteStateDeal(routeId, ROUTE_STATE_YUXIAN_OPEN); /*设置预先开放*/
			
				RouteYuXianOpenDeal(routeId); /*进路预先开放处理*/
			}
		}
		else
		{ /*信号关闭*/
	
			/*开放进路信号处理*/
			if (OpenCommRouteSigProc(routeId) == CI_SUCCESS)
			{
				return;
			}
			else
			{
				/*初锁异常*/
				SetRouteStateDeal(routeId, ROUTE_STATE_FIRST_LOCKERR);
			}
		}
	}
}


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

	UINT8 dctyReOpenFlag = ROUTE_DCTY_REOPEN_NO;/*调车同意重开标志*/

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

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

			RouteYuXianOpenDeal(routeId);  /*进路预先开放管理*/
		}
		else
		{
			needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
			/*获取调车同意重开标志*/
			dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);
			if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag )
				|| (ROUTE_DCTY_REOPEN == dctyReOpenFlag))
			{
#if 0
				SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0);
#endif
				SetRouteStateDeal(routeId,ROUTE_STATE_YUXIAN_OPEN); /*设置进路状态【预先开放】*/

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

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

			
		}
	}
	else
	{ 
		
		/*信号关闭*/
		if  (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
		{ 
			/*重开信号信号处理*/
			(void)OpenCommRouteSigProc(routeId);
		}
		else
		{
			/* 保持进路异常锁闭状态*/
			needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
			/*获取调车同意重开标志*/
			dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);
			if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag) ||
				(ROUTE_DCTY_REOPEN == dctyReOpenFlag) )
			{/*处理需开发不满足，需开放重开标志有效/调车同意重开标志有效时*/
				(void)OpenCommRouteSigProc(routeId);
			}
			else
			{
#if 0
				(void)DriveSignalClose(startSignalId);
#endif
			}
		}
	}
}


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

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

    startSignalCurColor = GetSignalCurColor(startSignalId);
    startSigPreDrvColor = GetSignalPreDriveColor(startSignalId);
    
    
	if (SIGNAL_OPEN == GetSignalOpenCloseState(startSignalCurColor))
	{ /*信号开放*/
        
        if (SIGNAL_CLOSE == GetSignalOpenCloseState(startSigPreDrvColor))
		{ /*之前驱动关闭*/
		    
			return;
		}
        
		if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
        { /*信号重开有效*/
            
		    if (CI_SUCCESS == RouteHaveTrainNear(routeId))
		    { /*进路有车接近*/
		    
			    SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/
				
				RouteNearOpenDeal(routeId); /*进路接近开放处理*/
		    }
		    else
		    {
			    SetRouteStateDeal(routeId, ROUTE_STATE_YUXIAN_OPEN);  /*-->设置预先开放*/
				
				RouteYuXianOpenDeal(routeId); /*进路预先开放处理*/
		    }
        }
        else
        {
            /*信号机异常开放*/
            /*xxxxx宕机*/
        }
	}
	else
	{ 
        /*信号关闭*/
	
	    if (CI_SUCCESS == RouteHaveTrainNear(routeId))
		{ /*有车接近*/
            
			SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/

			RouteNearLockErrDeal(routeId); /*进路接近锁闭异常处理*/
		}
		else
		{ /*无车接近*/
            
			if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
			{ /*信号重开有效*/
                
				 (void)OpenCommRouteSigProc(routeId); /*开放进路信号处理*/
			}
            else
            {
                /*无重开或自动信号*/
            }
		}
    }
}


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

	curColor = GetSignalCurColor(startSignalId);

	sigState = GetSignalOpenCloseState(curColor);
	
	if (SIGNAL_OPEN == sigState)
	{ /*信号开放*/
		needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
		if (ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag )
		{
			SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
			SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
		}
		else
		{
		    ;
		}
		dctyReOpenFlag = GetRouteDCTYNotSatisfySignalReOpenFlag(routeId);
		if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
		{
			SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN_NO);
			SetRouteDCTYNotSatisfyStartCnt(routeId,0u);
		}
		else
		{
		    ;
		}
		/*保持开放进路信号处理*/
		checkResult = KeepCommRouteSigProc(routeId);
		if (CI_SUCCESS == checkResult)
		{ 
            /*保持成功*/
			checkResult = RouteHaveTrainNear(routeId);
            if (CI_SUCCESS == checkResult)
            { 
                /*进路有车接近*/                
                SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_OPEN); /*-->接近开放*/
				
				RouteNearOpenDeal(routeId); /*进路接近开放处理*/
	        }
            else
            {
                /*保持预先开放*/
                return;
            }            
		}
		else
		{ 
            /*保持失败*/
			checkResult = RouteHaveTrainNear(routeId);
            if (CI_SUCCESS == checkResult)
            { /*有车接近*/
                		
                SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);    /*-->设置接近锁闭异常*/
            }
            else
            { /*无车接近*/
                
                SetRouteStateDeal(routeId, ROUTE_STATE_YUXIAN_LOCK);     /*-->设置预先锁闭*/
		    }
		}
	}
	else
	{ /*信号关闭*/
        checkResult = RouteHaveTrainNear(routeId);
	    if (CI_SUCCESS == checkResult)
		{ /*有车接近*/
            		
			SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);    /*-->设置接近锁闭异常*/
		}
		else
		{ /*无车接近*/
            
		    SetRouteStateDeal(routeId, ROUTE_STATE_YUXIAN_LOCK);     /*-->设置预先锁闭*/
		}

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


/*
* 功能描述： 进路接近锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteNearLockDeal(const UINT16 routeId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
    UINT16 nextSecId = 0u; /*下一物理区段ID*/
	UINT8 rtUnlockExceptFlag = 0u;/*进路是否自动解锁异常标志*/
	UINT8 routeType = 0u;/*进路类型*/

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

	if (0u == sectionSum)
	{ /*进路区段数据错误*/
	
	    return;
	}
	else
	{
	}
	
	if ((GetPhySecLockState(pRouteSecStru[0].PhysicalSectionId) != PHYSICAL_SECTION_LOCK_NORMAL) ||
		(GetPhySecRLockBelongRouteId(pRouteSecStru[0].PhysicalSectionId) != routeId))
	{ /*区段锁闭错误*/
	
		return;
	}
	else
	{
	}
	
	/*解锁处理*/
	if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(pRouteSecStru[0].PhysicalSectionId))
	{ /*第一区段占用*/
		
		if ((ROUTE_TYPE_DIAOCHE == routeType)&&
			(PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(pRouteSecStru[0].PhysicalSectionId)) &&
			(1u == sectionSum))
		{ /*调车进路&&只有一个区段&&无岔区段*/
		    
			SetPhySecLockState(pRouteSecStru[0].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId));  /*设置物理区段未锁闭*/
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
		}
		else
	    {
	    }

		return;
	}
	else
	{
	}
	
	/*第一区段空闲*/
	if (SECTION_OCCUPY_YES == GetPhySecPreMergeState(pRouteSecStru[0].PhysicalSectionId))
	{ /*第一区段之前占用*/
		
		nextSecId = GetRouteNextPhySecId(routeId, pRouteSecStru[0].PhysicalSectionId); /*获取下一物理区段*/

		if (0xFFFFu != nextSecId)
		{/*下一个物理区段存在*/
			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(nextSecId))
			{/*下一物理区段占用*/
				SetPhySecLockState(pRouteSecStru[0].PhysicalSectionId, PHYSICAL_SECTION_LOCK_DELAY, 0, 0); /*设置物理区段延时解锁*/
				SetPhySecAutoUnlockStartCycNum(pRouteSecStru[0].PhysicalSectionId, Get2oo2CurCycleNum()); /*设置物理区段延时解锁起始周期*/
				SetRouteStateDeal(routeId, ROUTE_STATE_AUTO_UNLOCK);   /*-->设置自动解锁正常*/

				rtUnlockExceptFlag = 0u;/*设置进路异常解锁标志无效*/
			}
			else
			{/*下一物理区段未占用*/
				rtUnlockExceptFlag = 1u;/*需要设置异常锁闭*/

			}
		}
		else
		{/*下一物理区段不存在*/
			rtUnlockExceptFlag = 1u;/*需要设置异常锁闭*/
		}
	}
	else
	{
	}

	if ((1u== rtUnlockExceptFlag) && (ROUTE_TYPE_LIECHE == routeType))
	{/*进路内方第一区段绿光带只对列车进路设置，不然调车中途折返无意义 修改于20170911ByWuRenju*/
		SetPhySecLockState(pRouteSecStru[0].PhysicalSectionId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));
		/*-->设置自动解锁异常*/
		SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
	}
	else if ((1u== rtUnlockExceptFlag) && (ROUTE_TYPE_DIAOCHE == routeType))
	{/*设置接近锁闭异常，修改于20170911ByWuRenju*/
		SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR); 
	}
	else
	{
		/*什么都不做*/
	}
}

/*
* 功能描述： 进路接近锁闭异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteNearLockErrDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u; /*进路始端信号机ID*/
    UINT8 startSignalCurColor = 0u; /*始端信号机当前颜色*/
    UINT8 startSigPreDrvColor = 0u; /*始端信号机上周期驱动颜色*/
	UINT16 sigInfirPhySecId = 0u;/*信号机内方第一区段*/

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

    startSignalCurColor = GetSignalCurColor(startSignalId);
    startSigPreDrvColor = GetSignalPreDriveColor(startSignalId);
    sigInfirPhySecId = GetSignalInFirstPhySecId(startSignalId, routeId);
    
	if (SIGNAL_OPEN == GetSignalOpenCloseState(startSignalCurColor))
	{ /*信号开放*/
        
        if (SIGNAL_CLOSE == GetSignalOpenCloseState(startSigPreDrvColor))
		{ /*之前驱动关闭*/
		    
			return;
		}
        
		if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
        { /*信号重开有效*/
            
		    SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_OPEN);   /*-->设置接近开放*/
			
			RouteNearOpenDeal(routeId); /*进路接近开放处理*/
        }
        else
        {
            /*信号机异常开放*/
            /*xxxxx宕机*/
        }
	}
	else
	{ /*信号关闭*/
		/*如果列车进路信号机跨压且内方第一区段空闲，则设置第一区段故障锁闭，并给现地反馈：信号异常关闭，信号机内方第一区段空闲*/
		if ((SIGNAL_CROSS_STATE_YES == GetSignalCrossState(startSignalId)) && (SECTION_OCCUPY_NO == GetPhySecCurMergeState(sigInfirPhySecId))
			&& (ROUTE_TYPE_LIECHE == GetRouteType(routeId)))
		{
			/*添加给现地反馈：信号异常关闭，信号机内方第一区段空闲*/
			SetCiSendCmdBackInfoData(CI_BACK_SIG_CLOSE_EXCEPT,CI_DEVICE_TYPE_SIGNAL,startSignalId,0u,0u);
			/*设置内方第一区段故障锁闭*/
			SetPhySecLockState(sigInfirPhySecId, PHYSICAL_SECTION_LOCK_EXCEPT, routeId, GetRouteDirection(routeId));  
			/*-->设置自动解锁异常*/
			SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCKERR); 
		}
		else
		{
			if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
			{ /*信号重开有效*/

				(void)OpenCommRouteSigProc(routeId); /*开放进路信号处理*/
			}
			else
			{
				/*无重开或自动信号*/
			}
		}
    }
}


/*
* 功能描述： 进路接近开放管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteNearOpenDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT16 errorCodeCurSum = 0u;  /*错误码总数目*/
	ErrorDataStruct* errorCodeStu = NULL; /*错误码数据*/
	UINT16 ii = 0u;  /*循环索引*/
	UINT8 curColor = 0u;
	UINT8 sigState = 0u;
	UINT8 funcId = EFUNC_RouteNearOpenDeal;/*函数ID*/
	UINT8 checkResult = 0u;
	/*如果始端信号内外方同时占压，认为列车驶入；注意：该驶入标志，只用于总人解判断，与正常的列车驶入判断存在差异*/
	checkResult = RouteInOutSecOccupy(routeId); 
	if (CI_SUCCESS == checkResult)
	{
		SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_YES);
	}

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

	curColor = GetSignalCurColor(startSignalId);

	sigState = GetSignalOpenCloseState(curColor);
	
	if (SIGNAL_OPEN == sigState)
	{ /*信号开放*/
		
		/*保持开放进路信号处理*/
		checkResult =  KeepCommRouteSigProc(routeId);
		if (CI_SUCCESS == checkResult)
		{ /*保持成功*/
            
            return;
		}
		else
		{ /*保持失败*/
			checkResult = CheckTrainEnterRoute(routeId);
			if (CI_SUCCESS == checkResult)
			{ /*列车驶入*/

				errorCodeCurSum = GetErrorDataCurSum();  /*获取错误码总数*/
				/*处理错误码*/
				for (ii = 0u; ii < errorCodeCurSum; ii++)
				{
					errorCodeStu = GetErrorData(ii);  /*获取错误码数据*/

					if (NULL != errorCodeStu)
					{    

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

						}

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

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


/*
* 功能描述： 进路延时解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteDelayUnlockDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;     /*进路始端信号机ID*/
	UINT32 delayStartCycNum = 0u;  /*延时解锁起始周期号*/
	UINT32 delayTotalCycSum = 0u;  /*延时解锁总周期数*/
	UINT8 routeLevel = 0u;         /*进路监督级别*/

	UINT8 zrjDelayType;/*进路总人解延时类型*/
	UINT8 zrjExe = CI_ERROR;/*总人解是否可执行*/
	UINT8 routePreState = 0u;/*进路之间状态*/

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

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

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

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

	if ((GetRouteType(routeId) == ROUTE_TYPE_LIECHE) || (GetRouteType(routeId) == ROUTE_TYPE_RETURN))
	{
		delayTotalCycSum = GetSystemParaBlocRouteDelayCyc();/*获取列车进路延时周期数*/
	}
	else if (GetRouteType(routeId) == ROUTE_TYPE_DIAOCHE)
	{
		delayTotalCycSum = GetSystemParaFaultUnlockCyc();   /*获取调车进路延时周期数*/
	} 
	else
	{
		/*不做处理*/
	}

	if ((0u == Get2oo2CurCycleNum()) || (delayTotalCycSum == 0u) || (delayStartCycNum == 0u))
	{ /*延时时间无效*/
		
		return;
	}

	zrjDelayType = GetRouteZongRenJieDelayType(routeId);/*获得进路总人接延时类型*/

	if (ROUTE_ZRJ_DELAY_TYPE_IDLE == zrjDelayType)
	{
		if (CI_SUCCESS == CommRouteDelayUnlockProc(routeId))
		{ /*取消成功*/

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

				SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

				/*设置进路逻辑区段: 未锁闭*/
				SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);

				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
			}
			else
			{
				/*时间未到或未设置*/
			}
		}
		else
		{ /*取消失败*/
			routePreState = GetRoutePreState(routeId);
			if ((ROUTE_STATE_LEAD_LOCKERR == routePreState) || (ROUTE_STATE_LEAD_LOCK == routePreState))
			{
				SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
			}
			else
			{
				SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
			}

			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
		}
	}
	else if ((ROUTE_ZRJ_DELAY_TYPE_ALL_EXP == zrjDelayType) || (ROUTE_ZRJ_DELAY_TYPE_EXP_TO_OCCUPY == zrjDelayType))
	{
		zrjExe = CheckRouteZongRenJieFeasibility(routeId);

		if (CI_SUCCESS == zrjExe)
		{
			if ((CI_TIME_OUT == SystemOverTimeCheck(delayStartCycNum, delayTotalCycSum)) ||
				(ROUTE_STOPENSURE_YES == GetRouteStopensureFlag(routeId)))
			{ /*解锁超时或收到停车保证*/
				if (ROUTE_ZRJ_DELAY_TYPE_ALL_EXP == zrjDelayType)
				{
					/*将进路的所有物理区段设置成异常锁闭*/
					SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_EXCEPT);

					/*进路逻辑区段都故障锁闭*/
					SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_EXCEPT);
				}
				else
				{
					/*将进路内第一个占压的物理区段之前区段设置为异常锁闭*/
					SetRoutePhySecExpLockToOccupy(routeId);
				}
				SetRouteStateDeal(routeId, ROUTE_STATE_AUTO_UNLOCKERR);  /*-->设置进路自动解锁异常*/
				SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
			}
			else
			{
				/*时间未到或未设置*/
			}
		}
		else
		{
			SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
		}
	}
	else
	{
		SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR);  /*-->设置接近锁闭异常*/
		SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_INVALID);
	}
}


/*
* 功能描述： 进路物理区段自动解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteSecAutoUnlockDeal(const UINT16 routeId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
	UINT16 nextSecId = 0u; /*下一物理区段ID*/
	UINT16 waitUnlockSecId = 0u; /*等待解锁区段ID*/
	UINT8 unlockSecIndex = 0xFFu; /*待解锁区段索引*/
	UINT8 ii= 0u;
	UINT16 preSec = 0u;/*上一物理区段ID*/
	UINT16 returnSigId = 0u;/*并置信号机ID*/
	UINT8 rtUnlockExceptFlag = 0u;/*进路是否自动解锁异常标志*/

	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	
	if (0u == sectionSum) 
	{
	    return;
	}
	else
	{
	}
	/*进路区段延时解锁处理*/
    RouteSecDelayUnlockProc(routeId);

	for(ii = 0u; ii < sectionSum; ii++)
	{
		if ((GetPhySecLockState(pRouteSecStru[ii].PhysicalSectionId) == PHYSICAL_SECTION_LOCK_NORMAL) &&
			(GetPhySecRLockBelongRouteId(pRouteSecStru[ii].PhysicalSectionId) == routeId))
		{ /*进路第一个正常锁闭区段*/
		
			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(pRouteSecStru[ii].PhysicalSectionId))
			{ /*第一个锁闭区段占用*/
    
				return;
			}
			else
			{ /*区段空闲*/
			
			    unlockSecIndex = ii;
			    break;
			}
		}
		else
	    {
	    }
	}
	
	if (0xFFu == unlockSecIndex)
	{ /*没找到待解锁区段*/
	
	    return;
	}
	else
	{
	}
	
	/*等待解锁区段ID*/
	waitUnlockSecId = pRouteSecStru[unlockSecIndex].PhysicalSectionId;
	
	/*待解锁区段当前空闲*/
	if (SECTION_OCCUPY_YES == GetPhySecPreMergeState(waitUnlockSecId))
	{ /*待解锁区段之前占用*/
		
		nextSecId = GetRouteNextPhySecId(routeId, waitUnlockSecId); /*获取下一物理区段*/

		if (0xFFFFu != nextSecId)
		{/*下一物理区段存在*/
			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(nextSecId))
			{/*下一物理区段占用*/
				/*解锁成功*/
				SetPhySecLockState(waitUnlockSecId, PHYSICAL_SECTION_LOCK_DELAY, 0, 0); /*设置物理区段延时解锁*/
				SetPhySecAutoUnlockStartCycNum(waitUnlockSecId, Get2oo2CurCycleNum()); /*设置物理区段延时解锁起始周期*/

				/*进路区段延时解锁处理*/
				RouteSecDelayUnlockProc(routeId);
			}
			else
			{/*下一物理区段空闲*/
				/*由于前面有中途折返逻辑，如果满足中途折返逻辑，则不会走到这里。所以这里不处理中途折返情况，直接设置绿光带*/
				rtUnlockExceptFlag = 1;/*设置进路异常解锁标志有效*/
			}
		}
		else
		{/*下一物理区段不存在*/
			/*获得中途折返信号机，如果存在中途折返信号机，则直接设置成绿光带。原因：如果有中途折返信号机，在满足条件的情况下，中途折返逻辑会把不完整锁闭的进路剩余锁闭区段全部解锁，进而进路状态变成空闲，不会走到这里。之所以会走到这里，证明不满足中途折返逻辑，又不满足三点检查，所以直接设置成绿光带*/
			returnSigId = GetRouteMidwayReturnSignalId(routeId);
			
			if ((0u != returnSigId)&&(GetStartSignalCIRouteSum(returnSigId)>0U))
			{/*存在中途折返信号机*/
				rtUnlockExceptFlag = 1u;/*设置进路异常解锁标志有效*/
			}
			else
			{
				/*不存在中途折返信号机，如果区段是进路的最后一个物理区段，且上一区段占用且未锁闭，则也可以解锁。增加该逻辑，主要应对燕房线，B库停车后，往回走到C库情况*/
				if (sectionSum >= 2u)
				{/*进路区段区段数防护*/
					if (unlockSecIndex == (sectionSum - 1u))
					{
						preSec = pRouteSecStru[unlockSecIndex - 1U].PhysicalSectionId;

						if ((SECTION_OCCUPY_YES == GetPhySecCurMergeState(preSec)) && (PHYSICAL_SECTION_LOCK_NO == GetPhySecLockState(preSec)))
						{
							/*解锁成功*/
							SetPhySecLockState(waitUnlockSecId, PHYSICAL_SECTION_LOCK_DELAY, 0u, 0u); /*设置物理区段延时解锁*/
							SetPhySecAutoUnlockStartCycNum(waitUnlockSecId, Get2oo2CurCycleNum()); /*设置物理区段延时解锁起始周期*/
							RouteSecDelayUnlockProc(routeId);/*进路区段延时解锁处理*/
						}
						else
						{
							rtUnlockExceptFlag = 1u;/*设置进路异常解锁标志有效*/
						}
					}
					else
					{
						rtUnlockExceptFlag = 1u;/*设置进路异常解锁标志有效*/
					}
				}
				else
				{
					/*如果区段数小于2，不可能走到自动解锁环节，此处代码处理导向安全*/
					rtUnlockExceptFlag = 1u;/*设置进路异常解锁标志有效*/
				}
			}		
		}
	}
	else
	{
	}
	
	if (1u == rtUnlockExceptFlag)
	{/*进路异常解锁标志有效*/
		/*设置物理区段异常锁闭*/
		SetPhySecLockState(waitUnlockSecId, PHYSICAL_SECTION_LOCK_EXCEPT, 0u, 0u);  

		/*-->设置自动解锁异常*/
		SetRouteStateDeal(routeId, ROUTE_STATE_AUTO_UNLOCKERR);

		/*进路区段延时解锁处理*/
		RouteSecDelayUnlockProc(routeId);
	}
	else
	{
	}
}


/*
* 功能描述： 进路物理区段自动解锁异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteSecAutoUnlockErrDeal(const UINT16 routeId)
{
	/*进路区段延时解锁处理*/
	RouteSecDelayUnlockProc(routeId);
	/*异常锁闭区段传递*/
	RouteExpLockContinue(routeId);
}


/*
* 功能描述： 进路引导锁闭管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteLeadLockDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 returnValue = 0u;
	
	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

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

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

		RouteLeadOpenDeal(routeId); /*进路引导开放处理*/
	}
	else
	{ /*信号关闭*/

		returnValue = OpenLeadRouteP(routeId);

		/*开放引导进路信号处理*/
		if (CI_SUCCESS == returnValue)
		{ /*检查成功*/
			
			DriveSignalOpen(startSignalId, routeId);  /*驱动进路信号开放*/
		}
		else if (RETURN_OPEN_ERR_SIGOPEN == returnValue)
		{ /*需关闭信号未关闭*/
			(void)DriveSignalClose(startSignalId);    /*驱动信号关闭*/
		}
		else if (RELAY_STATE_WAITE == returnValue)
		{
			   /*等待驱落*/
		}
		else
		{ /*检查失败*/
			
			SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
		}
	}
}


/*
* 功能描述： 进路引导开放管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteLeadOpenDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 returnValue = 0u;          /*返回值定义*/
	
	
	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/
	
	/*如果始端信号内外方同时占压，认为列车驶入；注意：该驶入标志，只用于总人解判断，与正常的列车驶入判断存在差异*/
	if (CI_SUCCESS == RouteInOutSecOccupy(routeId))
	{
		SetRouteTrainEnterFlag(routeId, ROUTE_TRAIN_ENTER_FLAG_YES);
	}

	if (SIGNAL_OPEN == GetSignalOpenCloseState(GetSignalCurColor(startSignalId)))
	{ /*信号开放*/
		
		/*保持开放引导进路信号处理*/
		returnValue = KeepLeadRouteP(routeId);
		
		if (CI_SUCCESS == returnValue)
		{ /*保持成功*/
			if (GetPhySecCurMergeState(GetSignalInFirstPhySecId(startSignalId, routeId)) == SECTION_OCCUPY_NO)
			{/*内方第一区段未占用*/

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

			DriveSignalOpen(startSignalId, routeId);  /*驱动进路信号开放*/
		}
		else
		{ /*保持失败*/
			
			(void)DriveSignalClose(startSignalId);  /*驱动进路信号关闭*/
			
			SetRouteLeadFaultOpenStartCyc(routeId, 0u);  /*设置引导故障延时时间*/
			SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
		}
	}
	else
	{ /*信号关闭*/
        
	    SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCKERR);  /*-->设置引导锁闭异常*/
	}
}


/*
* 功能描述： 进路引导锁闭异常管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteLeadLockErrDeal(const UINT16 routeId)
{
	UINT16 startSignalId = 0u;       /*进路始端信号机ID*/
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 returnValue = 0u;
	/*获取进路动态字段*/
	startSignalId = GetRouteStartSignalId(routeId);            /*获取进路始端信号机ID*/

    openCloseState = GetSignalOpenCloseState(GetSignalCurColor(startSignalId));
	
	if (SIGNAL_OPEN == openCloseState)
	{ /*信号开放*/
        
        if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
		{ /*信号重开有效*/
            
		    SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_OPEN);   /*-->设置引导开放*/
			
			RouteLeadOpenDeal(routeId); /*引导进路开放处理*/
        }
        else
        {
            /*信号异常开放*/
            /*xxxxx宕机*/
        }
	}
	else
	{ /*信号关闭*/

        
	    if (ROUTE_REPEATOPEN_SET_YES == GetRouteRepeatOpenFlag(routeId))
		{ 
			returnValue = OpenLeadRouteP(routeId);
			/*根据开放信号返回值处理*/
			if (CI_SUCCESS == returnValue)
			{ /*检查成功*/

				DriveSignalOpen(startSignalId, routeId); /*驱动信号开放*/
			}
			else if (RETURN_OPEN_ERR_SIGOPEN == returnValue)
			{ /*需关闭信号未关闭*/
				(void)DriveSignalClose(startSignalId);    /*驱动信号关闭*/
			}
			else if (RELAY_STATE_WAITE == returnValue)
			{
				/*等待驱落*/
			}
			else
			{ /*开放失败*/
				
				(void)DriveSignalClose(startSignalId); /*驱动信号关闭*/

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

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


/*
* 功能描述： 开放进路信号处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： CI_SUCCESS
*            CI_ERROR
*/
UINT8 OpenCommRouteSigProc(const UINT16 routeId)
{
	UINT8 routeType = 0u; /*进路类型*/
	UINT8 returnValue = 0u; /*返回值定义*/
	UINT16 startSignalId = 0u;

	UINT8 errType = CI_ERROR;/*定义检查失败时的错误类型*/
	UINT8 recoverState = ROUTE_RECOVER_STA_STAY;/*当前恢复重开状态*/
	UINT8 routeState = 0u;/*进路状态*/
	UINT32 curCycle = 0u;/*当前周期*/
	UINT8 needOpenNotTrueRepeatFlag = ROUTE_NEEDOPEN_REOPEN_NO;/*需开放未满足，重开标志*/
	UINT32 needOpenRepeatStartCount = 0u;/*需开放未满足，重开起始周期*/
	UINT32 sysparaRepeatCount = 0u;/*系统参数重开维持周期*/
	UINT8 routeTimeState = CI_TIME_NO;

	UINT8 dctyReOpenFlag = ROUTE_DCTY_REOPEN_NO;/*调车同意重开标志*/
	UINT32 dctyStartCount = 0u;/*调车同意起始周期*/

	routeType = GetRouteType(routeId); /*获取进路类型*/
	startSignalId = GetRouteStartSignalId(routeId);
	routeState = GetRouteState(routeId);
	curCycle = Get2oo2CurCycleNum();

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

	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/
		
		returnValue = OpenLTrainRouteP(routeId); /*开放列车进路*/
		errType = OpenLTrainRouteErrP(routeId, OPEN_CHECK_STEP_OPEN);/*检查失败原因*/
	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{ /*调车进路*/
		
		returnValue = OpenDTrainRouteP(routeId); /*开放调车进路*/
		errType = OpenDTrainRouteErrP(routeId, OPEN_CHECK_STEP_OPEN); /*检查失败原因*/
	}
	else
	{ /*进路类型错误*/
		
		returnValue = CI_ERROR;
	}

	if ((ROUTE_TYPE_LIECHE == routeType) || (ROUTE_TYPE_DIAOCHE == routeType))
	{
		/*根据开放信号返回值处理*/
		if (CI_SUCCESS == returnValue)
		{ /*检查成功*/

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

			/*满足开放条件后也清除进路恢复状态，用于下一次进路状态流转*/
			SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);

			
			

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

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

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

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

			if (ROUTE_STATE_FIRST_LOCK == routeState/*初锁*/)
			{
				/*设置重开标志，设置未开放不满足重开开始时间*/
				/*判断条件：列车进路、需开放信号机为虚拟信号机，且关闭*/
				if (ROUTE_TYPE_LIECHE == routeType)
				{
					SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_YES);
					SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,curCycle);
				}
				else
				{
					SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
					SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
				}
			}
			else if(ROUTE_STATE_FIRST_LOCKERR == routeState/*初锁异常*/)
			{
				/*获取重开标志*/
				/*检查超时*/
				needOpenNotTrueRepeatFlag = GetRouteNeedOpenReopenFlag(routeId);
				needOpenRepeatStartCount = GetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId);
				sysparaRepeatCount = GetSystemParaRouteOpenSigCyc();/*开放需开放等待时间采用进路信号开放周期时间*/
				if ((ROUTE_NEEDOPEN_REOPEN_YES == needOpenNotTrueRepeatFlag) && (needOpenRepeatStartCount>0u))
				{
					/*检查超时，超时，清标志*/
					/* 开放信号时间状态*/
					routeTimeState = SystemOverTimeCheck(needOpenRepeatStartCount,sysparaRepeatCount);
					if (CI_TIME_OUT == routeTimeState)/*超时*/
					{
						SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
						SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
					}
					else if (CI_TIME_NO == routeTimeState)/*未计时*/
					{
						SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
						SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
					}
					else if(CI_TIME_IN == routeTimeState)/*计时中*/
					{
						/*继续重开*/
					}
					else
					{
						/*非法*/
						SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
						SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
					}

					/*因为处于开放需开放不满足时自动重开中，所以，清除信号自动重开标志，避免重复*/
					SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*清除进路信号重开标志*/
					SetRouteOpenSigStartCycNum(routeId,0u); /*重置信号开放时间*/

				}

			}
			else
			{
				/*清开放未开放重开标志，清未开放不满足重开开始时间*/
				SetRouteNeedOpenReopenFlag(routeId,ROUTE_NEEDOPEN_REOPEN_NO);
				SetRouteNeedOpenNotTrueSigRepeatOpenStartCycNum(routeId,0u);
			}
			if (ROUTE_DCTY_REOPEN == dctyReOpenFlag)
			{
				SetErrorData(EFUNC_CLD_OpenCommRouteSigProc,
					CI_DEVICE_TYPE_ROUTE,routeId,
					ETYPE_DCTY_REOPEN_TIMING_BREAK,dctyReOpenFlag,ESEND_LEVEL_ATS);
				SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN_NO);
				SetRouteDCTYNotSatisfyStartCnt(routeId,0u);
			}
			
			returnValue = CI_ERROR;
		}
		else if ((ROUTE_TYPE_DIAOCHE == routeType)&&(RETURN_DCTY_NOT_SATISIFY == returnValue)/*调车同意不满足*/)
		{
			(void)DriveSignalClose(startSignalId);/*先驱信号关闭*/
			if (ROUTE_STATE_FIRST_LOCK == routeState/*初锁*/)
			{
				SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN);
				SetRouteDCTYNotSatisfyStartCnt(routeId,curCycle);
			}
			else if(ROUTE_STATE_FIRST_LOCKERR == routeState/*初锁异常*/)
			{
				sysparaRepeatCount = 0u;
				/*检查超时*/
				dctyStartCount = GetRouteDCTYNotSatisfyStartCnt(routeId);/*获取调车同意不满足起始周期*/
				sysparaRepeatCount = GetSysParaDCTYWaitSigOpenCnt();/*获取系统参数调车同意等待信号重开时间时间*/
				if ((ROUTE_DCTY_REOPEN == dctyReOpenFlag) && (dctyStartCount>0u))
				{
					/*检查超时，超时，清标志*/
					/* 开放信号时间状态*/
					routeTimeState = SystemOverTimeCheck(dctyStartCount,sysparaRepeatCount);
					if (CI_TIME_OUT == routeTimeState)/*超时*/
					{
						SetErrorData(EFUNC_CLD_OpenCommRouteSigProc,
							CI_DEVICE_TYPE_ROUTE,routeId,
							ETYPE_DCTY_REOPEN_TIMEOUT,dctyReOpenFlag,ESEND_LEVEL_ATS);

						SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN_NO);
						SetRouteDCTYNotSatisfyStartCnt(routeId,0u);
					}
					else if (CI_TIME_NO == routeTimeState)/*未计时*/
					{
						SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN_NO);
						SetRouteDCTYNotSatisfyStartCnt(routeId,0u);
					}
					else if(CI_TIME_IN == routeTimeState)/*计时中*/
					{
						/*继续重开*/
					}
					else
					{
						/*非法*/
						SetRouteDCTYNotSatisfySignalReOpenFlag(routeId,ROUTE_DCTY_REOPEN_NO);
						SetRouteDCTYNotSatisfyStartCnt(routeId,0u);
					}

					

				}
			}
			else
			{
				/*不做处理*/
			}
			/*因为处于开放需开放不满足时自动重开中，所以，清除信号自动重开标志，避免重复*/
			SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*清除进路信号重开标志*/
			SetRouteOpenSigStartCycNum(routeId,0u); /*重置信号开放时间*/

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

			returnValue = CI_SUCCESS;   /*等待驱落*/
		}
		else
		{ /*开放失败*/
		
			(void)DriveSignalClose(startSignalId); /*驱动信号关闭*/

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

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

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

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

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

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

			returnValue = CI_ERROR;
		}
	}
	
	return returnValue;
}


/*
* 功能描述： 保持开放进路信号处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8   
*/
UINT8 KeepCommRouteSigProc(const UINT16 routeId)
{
    UINT8 routeType = 0u; /*进路类型*/
	UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT16 outPhySecId = 0u; /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u; /*信号机内方第一区段ID*/
	UINT8 returnValue = 0u; /*返回值定义*/

	UINT8 errType = CI_ERROR;/*定义检查失败时的错误类型*/

	routeType = GetRouteType(routeId);                /*获取进路类型*/
	startSignalId = GetRouteStartSignalId(routeId);   /*获取进路始端信号机ID*/
	inPhySecId = GetSignalInFirstPhySecId(startSignalId, routeId);    /*信号机内方第一物理区段ID*/
	outPhySecId = GetSignalOutFirstPhySecId(startSignalId);  /*信号机外方第一物理区段ID*/
	
	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/
		
		returnValue = KeepLTrainRouteP(routeId); /*保持列车进路信号*/
		errType = KeepLTrainRouteErrP(routeId);/*检查失败原因*/
	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{ /*调车进路*/
	    
		returnValue = KeepDTrainRouteP(routeId); /*保持调车进路信号*/
		errType = KeepDTrainRouteErrP(routeId);/*检查失败原因*/

		/*判断列车驶入:（内方第一区段当前占用 && 之前空闲） ）&& （始端信号机外方第一区段当前占用*/
		if ((SECTION_OCCUPY_YES == GetPhySecCurMergeState(inPhySecId)) && (SECTION_OCCUPY_NO == GetPhySecPreMergeState(inPhySecId)))
		{
			if ((0U == outPhySecId) || (SECTION_OCCUPY_YES == GetPhySecCurMergeState(outPhySecId)))
			{
				SetTrainEnterRouteFlag(routeId, TRAIN_ENTER_ROUTE_FLAG_YES);
			}
		}
	}
	else
	{ /*进路类型错误*/
	
	    (void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/
		return CI_ERROR;
	}
	
	/*根据开放信号返回值处理*/
	if (CI_SUCCESS == returnValue)
	{ /*成功*/
	
		DriveSignalOpen(startSignalId, routeId); /*驱动信号开放*/
		
		return CI_SUCCESS;
	}
	else
	{ /*失败*/

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

		SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/

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

		return CI_ERROR;
	}
}


/*
* 功能描述： 进路延时解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8   
*/
UINT8 CommRouteDelayUnlockProc(const UINT16 routeId)
{
    UINT8 routeType = 0u; /*进路类型*/
	UINT8 returnValue = 0u; /*返回值定义*/


	routeType = GetRouteType(routeId);                /*获取进路类型*/
	
	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/
		
		returnValue = RouteCancelLogicProcess(routeId); /*列车进路延时解锁处理*/
	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{ /*调车进路*/
	    
		returnValue = CancelDTrainRouteP(routeId); /*调车进路延时解锁处理*/
	}
	else
	{ /*进路类型错误*/
	    
		return CI_ERROR;
	}
	
	
	/*根据开放信号返回值处理*/
	if (CI_SUCCESS == returnValue)
	{ /*成功*/
		
		return CI_SUCCESS;
	}
	else
	{ /*失败*/
	
		return CI_ERROR;
	}
}



/*
* 功能描述： 物理区段延时解锁处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteSecDelayUnlockProc(const UINT16 routeId)
{
	UINT16 delayUnlockSecId = 0u; /*延时解锁区段ID*/
	UINT16 nextPhySecId = 0u; /*下一物理区段ID*/
	UINT8 secUnlockTime = 0u; /*区段解锁时间*/
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *pRouteSecStru = NULL; /*区段数据*/
	UINT8 ii= 0u;
	UINT32 delayTotalCycSum = 0u;  /*延时解锁总周期数*/
	UINT16 routeLastSwiPhySecId = 0u;    /*进路最远端道岔区段ID*/
	
	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	pRouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	routeLastSwiPhySecId = GetRouteLastSwichPhySecId(routeId);/*获取进路最远端道岔区段*/


	if (0u == sectionSum) 
	{
	    return;
	}
	else
	{
	}

	/*#####处理区故解延时#####*/
	for(ii = 0u; ii < sectionSum; ii++)
	{
		if (PHYSICAL_SECTION_LOCK_FAULTDELAY ==GetPhySecLockState(pRouteSecStru[ii].PhysicalSectionId))
		{ /*进路第一个区故解延时区段*/
			/*判断区段锁闭所属的进路*/
			/*前一版本未进行此判断，会导致如下问题：区段被锁闭给进路A，进路A未能正常自动解锁，通过区故解将异常锁闭区段变成空闲，但仍有占用的区段，此时A仍处于自动解锁异常*/
			/*之后该区段被锁闭给进路B，然后进路B也需要区故解，由于进路A在进路B前被遍历，所以本属于进路B的区故解延时逻辑变成了属于A*/
			if(GetPhySecRLockBelongRouteId(pRouteSecStru[ii].PhysicalSectionId) == routeId)
			{
				delayUnlockSecId = pRouteSecStru[ii].PhysicalSectionId;
				break;
			}
			else
        	{
	        }
		}
		else
	    {
	    }
	}

	/*不同进路类型区故解延时不同*/
	if ((ROUTE_TYPE_LIECHE==GetRouteType(routeId)) || (ROUTE_TYPE_RETURN ==GetRouteType(routeId)))
	{
		delayTotalCycSum = GetSystemParaBlocRouteDelayCyc();/*获取列车进路延时周期数*/
	}
	else if (ROUTE_TYPE_DIAOCHE==GetRouteType(routeId))
	{
		delayTotalCycSum = GetSystemParaFaultUnlockCyc();   /*获取调车进路延时周期数*/
	} 
	else
	{
		/*不做处理*/
	}

	if (delayUnlockSecId > 0u)
	{
	    if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(delayUnlockSecId))
		{ /*区段占用*/
			
            /*设置区段正常锁闭*/
            SetPhySecLockState(delayUnlockSecId, PHYSICAL_SECTION_LOCK_NORMAL, routeId, GetRouteDirection(routeId)); /*设置区段正常锁闭*/
            
            /*设置进路接近锁闭异常*/
            SetRouteStateDeal(routeId, ROUTE_STATE_NEAR_LOCKERR); /*设置进路接近锁闭异常*/

			/*设置区段延时解锁起始周期*/
			(void)SetPhySecFaultUnlockStartCycNum(delayUnlockSecId, 0u);
		}
		else
		{ /*区段空闲*/
		    
			secUnlockTime = SystemOverTimeCheck(GetPhySecFaultUnlockStartCycNum(delayUnlockSecId),delayTotalCycSum);
			
			if (CI_TIME_OUT == secUnlockTime)
			{ /*时间已到*/
			
				SetPhySecLockState(delayUnlockSecId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId)); /*设置区段未锁闭*/
				
				if (routeLastSwiPhySecId == delayUnlockSecId)
				{
					/*解锁进路关联防护道岔*/
					SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL);/*取消进路关联防护道岔的防护锁闭*/ 
				}
				else
        		{
				    ;
	      	    }

				PhySecFaultRelatedUnLockDeal(delayUnlockSecId, routeId); /*处理相关区段锁闭状态*/

				if (CI_SUCCESS == CheckRoutePhySecHaveUnLock(routeId))
				{ /*进路已完全解锁*/
					
					SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
				}
				else
        		{
				    ;
	      	    }
			}
			else
        	{
			    ;
	        }
		}
		
		return;
	}

	/*#####处理自动解锁延时#####*/
	delayUnlockSecId = 0u;
	for(ii = 0u; ii < sectionSum; ii++)
	{
		if ((GetPhySecLockState(pRouteSecStru[ii].PhysicalSectionId) == PHYSICAL_SECTION_LOCK_DELAY) &&
			(GetPhySecRLockBelongRouteId(pRouteSecStru[ii].PhysicalSectionId) == routeId))
		{ /*进路第一个延时解锁区段*/
		
			delayUnlockSecId = pRouteSecStru[ii].PhysicalSectionId;
			break;
		}
		else
		{
		}
	}
	
	if (0u == delayUnlockSecId)
	{ /*未找到区段*/
	    
		return;
	}
	else
	{
	}
	
	
	if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(delayUnlockSecId))
	{ /*区段占用*/
		
		/*设置区段延时解锁起始周期*/
		SetPhySecAutoUnlockStartCycNum(delayUnlockSecId, Get2oo2CurCycleNum());
		
		return;
	}
	else
	{ /*区段空闲*/
	
		secUnlockTime = SystemOverTimeCheck(GetPhySecAutoUnlockStartCycNum(delayUnlockSecId),
											GetSystemParaSecDelayUnlockCyc());
														 
		if (CI_TIME_OUT == secUnlockTime)
		{ /*时间已到*/
			
			/*设置物理区段未锁闭*/
			SetPhySecLockState(delayUnlockSecId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId));

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

			/*最后一个无岔区段连带解锁*/
			if ((ROUTE_TYPE_DIAOCHE == GetRouteType(routeId)) &&
				(sectionSum >= 2u) &&
				(delayUnlockSecId == pRouteSecStru[sectionSum-2U].PhysicalSectionId) &&
			    (PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(pRouteSecStru[sectionSum-1U].PhysicalSectionId)))
			{ /*调车进路 && 区段数大于2 && 进路倒数第二个区段 && 最后一个区段无岔*/
				
				SetPhySecLockState(pRouteSecStru[sectionSum-1U].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, routeId, GetRouteDirection(routeId));  /*设置物理区段未锁闭*/
			}
			else
        	{
			    ;
	        }


			if (CI_SUCCESS == CheckRoutePhySecHaveUnLock(routeId))
			{ /*进路区段全部解锁*/
				
				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);  /*-->设置进路空闲*/
			}
			else
			{
				nextPhySecId = GetRouteNextPhySecId(routeId, delayUnlockSecId);  /*获取下一物理区段ID*/
				
				if (PHYSICAL_SECTION_LOCK_DELAY == GetPhySecLockState(nextPhySecId))
				{ /*下一区段延时解锁*/
				
					/*更新下一区段计时*/
					SetPhySecAutoUnlockStartCycNum(nextPhySecId, Get2oo2CurCycleNum());
				}
				else
				{
					return;
				}
			}
		}
		else
		{
			return;
		}
	}
}


/*
* 功能描述： 上电解锁逻辑处理
* 参数说明： void
* 返回值  ： 
*/
void StartupUnlockM(void)
{
	UINT16 phySecId = 0u; /*物理区段ID*/
	UINT16 phySecSum = 0u; /*物理区段总数*/
    UINT8 localCiId = 0u; /*本地联锁ID*/    
	UINT8 belongCiId = 0u; /*进路所属联锁ID*/
	UINT16 ii = 0u; /*游标*/


    if (GetStartLockFlag() != CI_START_LOCK_YES)
    {
	    return;
    }

	phySecSum = GetPhySecCurSum(); /*获取物理区段总数*/
    localCiId = GetSystemParaLocalCiId(); /*获取本机联锁ID*/

    for (ii = 0u; ii < phySecSum; ii++)
    {/*遍历物理区段*/

        belongCiId = 0u;          /*进路所属联锁ID*/
        
        phySecId = GetPhySecId(ii); /*获取物理区段ID*/
        belongCiId = GetPhySecBelongCiId(phySecId);

        if ((0u == phySecId) || (phySecId >= PHYSICAL_SECTION_SUM_MAX))
        {
            continue;
        }
        
        if ((belongCiId != localCiId) || (localCiId == 0u))
        {
            continue;
		}
        
        
        if (PHYSICAL_SECTION_LOCK_START == GetPhySecLockState(phySecId))
        { /*物理区段上电解锁*/

            SetPhySecLockState(phySecId, PHYSICAL_SECTION_LOCK_NO, 0u, 0u);/*设置物理区段锁闭状态为未锁闭*/
        }
	}
    
    SetStartLockFlag(CI_START_LOCK_NO); /*上电解锁成功*/
}


/*
* 功能描述： 办理普通进路逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void SetCommonRouteLogicM(const UINT16 routeId)
{
    UINT8 routeType = 0u;	   /*进路类型*/
	UINT8 localCiId = 0u;       /*本地联锁ID*/
	UINT8 belongCiId = 0u;      /*进路所属联锁ID*/

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

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/
	
	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}

	routeType = GetRouteType(routeId); /* 获取进路类型*/
	
	if (ROUTE_TYPE_LIECHE == routeType)
	{ /*列车进路*/
		
		if (CI_SUCCESS == SetLTrainRouteP(routeId))
		{ /*检查通过*/

			SetRouteStateDeal(routeId, ROUTE_STATE_XUANPAI); /*设置进路状态为选排*/
			
			CommonRouteXuanPaiDeal(routeId); /*普通进路选排处理*/
		}
		else 
		{
			/*不做处理*/
		}
	}
	else if (ROUTE_TYPE_DIAOCHE == routeType)
	{ /*调车进路*/

		/*设置进路停止检查标志*/
		SetRouteStopFlagManage(routeId, GetStopCheckFlag()); 
		
		if (CI_SUCCESS == SetDTrainRouteP(routeId))
		{ /*检查通过*/

			SetRouteStateDeal(routeId, ROUTE_STATE_XUANPAI); /*设置进路状态为选排*/
			
			CommonRouteXuanPaiDeal(routeId); /*普通进路选排处理*/
		}
		else 
		{
			SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
		}
	}
	else
	{
		/*无操作*/
	}
}


/*
* 功能描述： 办理组合进路逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void SetZuHeRouteLogicM(const UINT16 routeId)
{
    UINT8 subRouteSum = 0U; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0U;
    UINT8 routeType = 0U;
	UINT8 reVal = CI_ERROR;
	UINT16 longRouteLastRouteId = 0U;
	UINT8 stopCheckFlag = 0U;
	UINT8 phySecUseFlag = 0U;

	subRouteSum = GetLongRouteSubRouteSum(routeId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(routeId); /*子进路号*/


	if (1u >= subRouteSum ) 
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	/*检查所有子进路物理区段征用标志*/
	if (CI_SUCCESS == reVal)
	{
		/*遍历子进路*/
		for (ii = 0u; ii < subRouteSum; ii++)
		{
			phySecUseFlag = RoutePhySectionUseLogicProcess(pSubRouteIdBuf[ii]);
			if (CI_SUCCESS == phySecUseFlag)
			{
				/*检查通过*/
			}
			else
			{
				reVal = CI_ERROR;

				break;
			}
		}
	}
	else
	{
		/*返回失败*/
	}
	

	if(CI_SUCCESS == reVal)
	{
		routeType = GetRouteType(pSubRouteIdBuf[0]);
		longRouteLastRouteId = GetLongRouteLastRouteId(routeId);/*获取组合进路最后一个子进路ID*/
		stopCheckFlag = GetStopCheckFlag();/*获取停止股道检查标志*/
		/*设置组合调车进路最后一条子进路停止检查标志*/
		if(ROUTE_TYPE_DIAOCHE == routeType)
		{  
			SetRouteStopFlagManage(longRouteLastRouteId, stopCheckFlag); 
		}

		reVal = SetLongDTrainRouteP(routeId);
		if (CI_SUCCESS == reVal)
		{ /*检查通过*/

			for (ii = 0u; ii < subRouteSum; ii++)
			{
				SetRoutePhySectionOccupyState(pSubRouteIdBuf[ii], PHYSICAL_SECTION_USING_YES); /*设置进路物理区段征用*/
			}

			SetLongRouteStateDeal(routeId, ROUTE_LONG_STATE_XUANPAI); /*设置长调进路状态为选排*/
		}
		else 
		{
			if(ROUTE_TYPE_DIAOCHE == routeType)
			{
				/*只有调车进路才检查停止检查标志*/
				SetRouteStopFlagManage(longRouteLastRouteId, ROUTE_STOPCHECK_SET_NO); /*清除最后一条进路停止检查标志*/
			}
		}
    }

}

/*
* 功能描述： 取消组合调车进路逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void CancelZuHeRouteLogicM(const UINT16 routeId)
{
	UINT8 subRouteSum = 0U; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0U;
	UINT8 chRouteType = 0U;
	UINT8 chRouteState = 0U;

	subRouteSum = GetLongRouteSubRouteSum(routeId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(routeId); /*子进路号*/
	if ((1U >= subRouteSum) || (NULL == pSubRouteIdBuf))
	{
		; /*数据配置错误，不处理*/
	}
	else
	{
		for (ii = 0U; ii < subRouteSum; ii++)
		{
			/*子进路均为调车进路类型*/
			chRouteType = GetRouteType(pSubRouteIdBuf[ii]); /*获取进路类型*/
			chRouteState = GetRouteState(pSubRouteIdBuf[ii]);/*获取进路状态*/
			if (ROUTE_TYPE_DIAOCHE == chRouteType)
			{
				if ((ROUTE_STATE_IDLE == chRouteState) || (ROUTE_STATE_AUTO_UNLOCK == chRouteState) || (ROUTE_STATE_AUTO_UNLOCKERR == chRouteState))
				{
					SetCiSendCmdBackInfoData(CI_BACK_ROUTE_LOCK_NOTALL, CI_DEVICE_TYPE_ROUTE, pSubRouteIdBuf[ii], 0U, 0U);
				}
				else
				{
					ZongQuXiaoRouteM(pSubRouteIdBuf[ii]);/*对子进路进行取消操作*/
				}
			}
		}
	}

}

/*
* 功能描述： 取消组合列车进路逻辑管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
*/
void CancelZuHeLieCheRouteLogicM(const UINT16 routeId)
{
	UINT8 subRouteSum = 0U; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0U;
	UINT8 chRouteType = 0U;
	UINT8 chRouteState = 0U;

	subRouteSum = GetLongRouteSubRouteSum(routeId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(routeId); /*子进路号*/
	if ((subRouteSum <= 1U) || (NULL == pSubRouteIdBuf))
	{
		; /*数据配置错误，不处理*/
	}
	else
	{
		for (ii = 0U; ii < subRouteSum; ii++)
		{
			/*子进路均为列车进路类型*/
			chRouteType = GetRouteType(pSubRouteIdBuf[ii]); /*获取进路类型*/
			chRouteState = GetRouteState(pSubRouteIdBuf[ii]);/*获取进路状态*/
			if (ROUTE_TYPE_LIECHE == chRouteType)
			{
				if ((ROUTE_STATE_IDLE == chRouteState) || (ROUTE_STATE_AUTO_UNLOCK == chRouteState) || (ROUTE_STATE_AUTO_UNLOCKERR == chRouteState))
				{
					SetCiSendCmdBackInfoData(CI_BACK_ROUTE_LOCK_NOTALL, CI_DEVICE_TYPE_ROUTE, pSubRouteIdBuf[ii], 0U, 0U);
				}
				else
				{
					ZongQuXiaoRouteM(pSubRouteIdBuf[ii]);/*对子进路进行取消操作*/
				}
			}
		}
	}

}

/*
* 功能描述： 办理引导进路逻辑处理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ：    
*/
void SetLeadRouteM(const UINT16 signalId)
{
	UINT8 routeState = 0u; /*进路状态*/
    UINT16 routeId = 0u;
	UINT8 sigExtinctState = 0U;
	UINT8 maintLightState = 0U;
	UINT8 routeLevel = 0U;

	routeId = GetStartSignalRouteId(signalId);   /*获取信号机ID*/
	routeState = GetRouteState(routeId); /*获取进路状态*/
	sigExtinctState = GetSignalLightExtinctState(signalId);
	maintLightState = GetSignalMaintainState(signalId);
	routeLevel = GetRouteLevel(routeId);
	

	if ((0u != routeId) && (routeId < ROUTE_SUM_MAX))
	{/*cgh-合并CID-3037-8：*/
		if (((SIGNAL_LIGHT_EXTICT_STATE_NO == sigExtinctState) && (MAINTAIN_STATE_YES == maintLightState))
			|| (SIGNAL_LIGHT_EXTICT_STATE_ALL_YES == sigExtinctState) || (SIGNAL_LIGHT_EXTICT_STATE_YES == sigExtinctState))
		{
			if (ROUTE_STATE_IDLE == routeState)
			{ /*进路空闲*/

				if (CI_SUCCESS == SetLeadRouteP(routeId))
				{/*检查通过*/

					SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_XUANPAI); /*设置进路状态为引导选排*/

				}
				else
				{
					/*区段有征用*/

					/*保持原进路状态*/

				}
			}
			else if ((routeState == ROUTE_STATE_FIRST_LOCKERR) ||
				(routeState == ROUTE_STATE_YUXIAN_LOCK) ||
				(routeState == ROUTE_STATE_NEAR_LOCK) ||
				(routeState == ROUTE_STATE_NEAR_LOCKERR))
			{
				/*锁闭转引导进路*/

				   /*【进路初锁异常】或
				   【预先锁闭】或
				   【接近锁闭正常】或
				   【接近锁闭异常】*/
				if (CI_SUCCESS == LockLeadTrainRouteP(routeId))
				{
					/*锁闭成功*/
					SetRouteStateDeal(routeId, ROUTE_STATE_LEAD_LOCK);  /*设置进路引导锁闭*/

				}
				else
				{
					/*锁闭失败*/

					/*保持原进路状态*/

				}
			}
			else
			{
				SetErrorData(EFUNC_CLD_OPEN_LEAD_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, ESEND_LEVEL_ATS);
			}
		}
		else
		{
			SetErrorData(EFUNC_CLD_OPEN_LEAD_ROUTE, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_LEVEL, routeLevel, ESEND_LEVEL_ATS);
		}
	}
}


/*
* 功能描述： 总取消进路逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void ZongQuXiaoRouteM(const UINT16 routeId)
{
	UINT8 localCiId = 0u;        /*本地联锁ID*/
	UINT8 belongCiId = 0u;       /*进路所属联锁ID*/
	
	
	if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
	{
	    return;
	}
	
	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/
	
	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}
	
	if (ROUTE_ZONGQUXIAO_SET_NO == GetRouteZongQuXiaoFlag(routeId))
	{ /*进路未总取消*/
	    
		SetRouteZongQuXiaoFlag(routeId, ROUTE_ZONGQUXIAO_SET_YES); /*设置进路总取消标志*/
		/* 优化代码：判断如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到区故解命令时进行清除重开标志 */
		if(GetRouteRecoverOpenFlag(routeId) == ROUTE_RECOVER_STA_WAIT)
		{
			SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

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

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


/*
* 功能描述： 总人解进路逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void ZongRenJieRouteM(const UINT16 routeId)
{
	UINT8 localCiId = 0u;        /*本地联锁ID*/
	UINT8 belongCiId = 0u;       /*进路所属联锁ID*/
	UINT8 cRouteZongRenJieFlag = 0u;
	UINT8 cRouteRecoverOpenFlag = 0u;
	
	if ((0u == routeId) || (ROUTE_SUM_MAX <= routeId))
	{
		;/* 无处理 */
	}
	else
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetRouteBelongCiId(routeId);      /*获取进路所属联锁ID*/

		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			;/* 无处理 */
		}
		else
		{
			cRouteZongRenJieFlag = GetRouteZongRenJieFlag(routeId);
			if (ROUTE_ZONGRENJIE_SET_NO == cRouteZongRenJieFlag)
			{ /*进路未总人解*/

				(void)SetRouteZongRenJieFlag(routeId, ROUTE_ZONGRENJIE_SET_YES); /*设置进路总人解标志*/
				/* 优化代码：判断如果由PSD、SPKS、扣车导致的信号关闭，重开标志位等待重开时，当收到区故解命令时进行清除重开标志 */
				cRouteRecoverOpenFlag = GetRouteRecoverOpenFlag(routeId);
				if (ROUTE_RECOVER_STA_WAIT == cRouteRecoverOpenFlag)
				{
					SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/

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

					SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_STAY);/*防止后面逻辑重开*/
				}
				else
				{
					;/* 无处理 */
				}
			}
			else
			{
				;/* 无处理 */
			}
		}
	}
}


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

	routeCurSum = GetRouteCurSum();	  /*获取进路总数*/
	
	/*处理进路*/
	for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = 0u;	      /*进路ID*/
	    belongCiId = 0u;       /*进路所属联锁ID*/
		routeState = 0u;       /*进路状态*/
		
		
		routeId = GetRouteId(ii);   /*获取进路ID*/
		
		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
		    continue;
		}
		
		belongCiId = GetRouteBelongCiId(routeId);   /*获取进路所属联锁ID*/
		
		if ((belongCiId != localCiId) || (0u == localCiId))
		{
		    continue;
		}

		if (signalId != GetRouteStartSignalId(routeId))
		{ /*不为进路始端信号机ID*/
		
		    continue;
		}
		
		routeState = GetRouteState(routeId);  /*获取进路状态*/
		
		if ((routeState != ROUTE_STATE_FIRST_LOCKERR) && 
		    (routeState != ROUTE_STATE_YUXIAN_LOCK) && 
			(routeState != ROUTE_STATE_NEAR_LOCKERR))
		{ /*进路状态不为: 初锁异常&&预先锁闭&&接近锁闭异常*/
			if (ROUTE_STATE_DELAY_UNLOCK == routeState)
			{/*总人解延时解锁期间，信号重开无效，记录故障并给现地和ATS发送反馈*/
				SetErrorData(EFUNC_CANCLE_ROUTE,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_CANCEL,CI_ERROR,ESEND_LEVEL_ATS);
			}
			continue;
		}

		if ((ROUTE_ZONGQUXIAO_SET_YES == GetRouteZongQuXiaoFlag(routeId)) ||
		    (ROUTE_ZONGRENJIE_SET_YES == GetRouteZongRenJieFlag(routeId)))
		{ /*总取消或总人解*/
			SetErrorData(EFUNC_CANCLE_ROUTE,CI_DEVICE_TYPE_ROUTE,routeId,ETYPE_ROUTE_CANCEL,CI_ERROR,ESEND_LEVEL_ATS);/*总取消或总人解时，信号重开无效，记录故障并给现地和ATS发送反馈*/
		    return;
		}
	
		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_YES);  /*设置进路信号重开标志*/
		SetRouteStopFlagManage(routeId, GetStopCheckFlag());  /*设置进路停止检查标志*/

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

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

		return;
	}
}


/*
* 功能描述： 设置道岔封锁逻辑处理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： void   
*/
void SetSwitchFengSuoM(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 const switchType = GetSwitchType(switchId);
	UINT16 switch2ndId = 0U;
	UINT8 chNonRouteCheck = CI_ERROR;
	UINT8 chKeepwork = CI_SUCCESS;
	UINT8 funRet = CI_ERROR;
	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		chKeepwork = CI_ERROR;
	}
	
	if (CI_SUCCESS == chKeepwork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

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

	if (CI_SUCCESS == chKeepwork)
	{
		chNonRouteCheck = CheckSwitchBelongNonRoute(switchId);
		if (CI_SUCCESS == chNonRouteCheck)
		{ /*道岔属于已办理非进路*/

			chKeepwork = CI_ERROR;
		}

		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2不属于非进路*/
			switch2ndId = GetDSwitchOtherId(switchId);
			chNonRouteCheck = CheckSwitchBelongNonRoute(switch2ndId);
			if (CI_SUCCESS == chNonRouteCheck)
			{
				/*另一端属于已办理非进路*/
				chKeepwork = CI_ERROR;
			}
		}
	}

	
	if (CI_SUCCESS == chKeepwork)
	{
		/*设置道岔封锁逻辑处理*/
		funRet = SetSwitchFLockLogicProcess(switchId);
		if (CI_SUCCESS == funRet)
		{ /*检查通过*/

			SetSwitchFengSuoStateDeal(switchId, SWITCH_LOCK_FENGSUO_YES); /*设置道岔封锁*/
		}
		else
		{ /*封锁失败*/
		}
	}
}


/*
* 功能描述： 设置道岔单锁逻辑处理
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： void   
*/
void SetSwitchDanSuoM(const UINT16 switchId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT8 const switchType = GetSwitchType(switchId);
	UINT16 switch2ndId = 0U;
	UINT8 chNonRouteCheck = CI_ERROR;
	UINT8 chKeepwork = CI_SUCCESS;
	UINT8 funRet = CI_ERROR;
	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		chKeepwork = CI_ERROR;
	}
	
	if (CI_SUCCESS == chKeepwork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

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

	if (CI_SUCCESS == chKeepwork)
	{

		chNonRouteCheck = CheckSwitchBelongNonRoute(switchId);
		if (CI_SUCCESS == chNonRouteCheck)
		{ /*道岔属于已办理非进路*/

			chKeepwork = CI_ERROR;
		}

		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2不属于非进路*/
			switch2ndId = GetDSwitchOtherId(switchId);
			chNonRouteCheck = CheckSwitchBelongNonRoute(switch2ndId);
			if (CI_SUCCESS == chNonRouteCheck)
			{
				/*另一端属于已办理非进路*/
				chKeepwork = CI_ERROR;
			}
		}
	}
	
	if (CI_SUCCESS == chKeepwork)
	{
		/*设置道岔单锁逻辑处理*/
		funRet = SetSwitchDLockLogicProcess(switchId);
		if (CI_SUCCESS == funRet)
		{ /*检查通过*/

			SetSwitchDanSuoStateDeal(switchId, SWITCH_LOCK_DANSUO_SET); /*设置道岔单锁*/
		}
		else
		{ /*单锁失败*/
		}
	}
}


/*
* 功能描述： 设置信号封锁逻辑处理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ：    
*/
void SetSignalFengSuoM(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	
    
	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
	    return;
	}
	
	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/
	
	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}
	
	if (CI_SUCCESS == CheckSignalBelongNonRoute(signalId))
	{ /*信号机属于已办理非进路*/
	
	    return;
	}
	
	if (SIGNAL_FENGSUO_NO == GetSignalFLockState(signalId))
	{ /*信号机未封锁*/
	    
		SetSignalFLockState(signalId, SIGNAL_FENGSUO_YES);  /*设置信号机封锁*/
	}
	else 
	{
	}
}


/*
* 功能描述： 取消道岔封锁逻辑处理
* 参数说明： UINT16 switchId, 道岔ID
* 返回值  ：    
*/
void CancelSwitchFengSuoM(const UINT16 switchId)
{
	UINT8 localCiId = 0u; /*本地联锁ID*/
	UINT8 belongCiId = 0u; /*进路所属联锁ID*/
	UINT8 const switchType = GetSwitchType(switchId);
	UINT16 switch2ndId = 0U;
	UINT8 chNonRouteCheck = CI_ERROR;
	UINT8 chKeepwork = CI_SUCCESS;
	UINT8 funRet = CI_ERROR;
    
	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		chKeepwork = CI_ERROR;
	}
	if (CI_SUCCESS == chKeepwork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

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

	if (CI_SUCCESS == chKeepwork)
	{
		chNonRouteCheck = CheckSwitchBelongNonRoute(switchId);
		if (CI_SUCCESS == chNonRouteCheck)
		{ /*道岔属于已办理非进路*/

			chKeepwork = CI_ERROR;
		}

		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2不属于非进路*/
			switch2ndId = GetDSwitchOtherId(switchId);
			chNonRouteCheck = CheckSwitchBelongNonRoute(switch2ndId);
			if (CI_SUCCESS == chNonRouteCheck)
			{
				/*另一端属于已办理非进路*/
				chKeepwork = CI_ERROR;
			}
		}
	}
	
	if (CI_SUCCESS == chKeepwork)
	{
		/*取消道岔封锁逻辑处理*/
		funRet = CancelSwitchFLockLogicProcess(switchId);
		if (CI_SUCCESS == funRet)
		{ /*检查通过*/

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


/*
* 功能描述： 取消道岔单锁逻辑处理
* 参数说明： UINT16 switchId, 道岔ID
* 返回值  ：    
*/
void CancelSwitchDanSuoM(const UINT16 switchId)
{
	UINT8 localCiId = 0u; /*本地联锁ID*/
	UINT8 belongCiId = 0u; /*进路所属联锁ID*/
	UINT8 const switchType = GetSwitchType(switchId);
	UINT16 switch2ndId = 0U;
	UINT8 chNonRouteCheck = CI_ERROR;
	UINT8 chKeepwork = CI_SUCCESS;
	UINT8 funRet = CI_ERROR;
    
	if ((0u == switchId) || (switchId >= SWITCH_SUM_MAX))
	{
		chKeepwork = CI_ERROR;
	}
	
	if (CI_SUCCESS == chKeepwork)
	{
		localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
		belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/

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

	if (CI_SUCCESS == chKeepwork)
	{
		chNonRouteCheck = CheckSwitchBelongNonRoute(switchId);
		if (CI_SUCCESS == chNonRouteCheck)
		{ /*道岔属于已办理非进路*/

			chKeepwork = CI_ERROR;
		}

		if (switchType == SWITCH_TYPE_DOUBLE)
		{
			/*双动道岔*/
			/*道岔2不属于非进路*/
			switch2ndId = GetDSwitchOtherId(switchId);
			chNonRouteCheck = CheckSwitchBelongNonRoute(switch2ndId);
			if (CI_SUCCESS == chNonRouteCheck)
			{
				/*另一端属于已办理非进路*/
				chKeepwork = CI_ERROR;
			}
		}
	}

	if (CI_SUCCESS == chKeepwork)
	{
		/*取消道岔封锁逻辑处理*/
		funRet = CancelSwitchDLockLogicProcess(switchId);
		if (CI_SUCCESS == funRet)
		{ /*检查通过*/

			SetSwitchDanSuoStateDeal(switchId, SWITCH_LOCK_DANSUO_CANCEL); /*取消道岔单锁*/
		}
		else
		{ /*取消道岔单锁失败*/
		}
	}
}


/*
* 功能描述： 取消信号封锁逻辑处理
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ：    
*/
void CancelSignalFengSuoM(const UINT16 signalId)
{
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	
    
	if ((0u == signalId) || (signalId >= SIGNAL_SUM_MAX))
	{
	    return;
	}
	
	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSignalBelongCiId(signalId);    /*获取信号机所属联锁ID*/
	
	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}
	
	if (CI_SUCCESS == CheckSignalBelongNonRoute(signalId))
	{ /*信号机属于已办理非进路*/
	
	    return;
	}
	
	if (SIGNAL_FENGSUO_YES == GetSignalFLockState(signalId))
	{ /*信号机封锁*/
	    
		SetSignalFLockState(signalId, SIGNAL_FENGSUO_NO);  /*设置信号机未封锁*/
	}
	else 
	{
	}
}


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

	localCiId = GetSystemParaLocalCiId();          /*获取本机联锁ID*/
	belongCiId = GetSwitchBelongCiId(switchId);    /*获取道岔所属联锁ID*/
	
	if ((belongCiId != localCiId) || (0u == localCiId))
	{
		return;
	}
	
	if (CI_TRADITION_RAILWAY == lineType)
	{/*城轨线路*/
		if ((switchSetPos != SWITCH_POSITION_DINGWEI) && (switchSetPos != SWITCH_POSITION_FANWEI))
		{/*单操位置无效*/
			check_Result = CI_ERROR;
		}
		else
		{/*单操位置有效*/
			check_Result = CI_SUCCESS;
		}
	} /* zt 删除单轨相关代码 2022-02-15 */ 
	else
	{/*无效线路类型*/
		check_Result = CI_ERROR;
	}
	
/*此段代码注释掉，SetSwitchPositionLogicProcess()也有检查道岔当前位置是否已经是单操位置*/
#if 0
	if (switchSetPos == GetSwitchCurPosition(switchId))
	{/*道岔位置已在单操位置*/
	    return;
	}
#endif
	
	if (CI_SUCCESS == check_Result)
	{/*单操位置有效*/
		/*单操道岔处理*/
		if (CI_SUCCESS == SetSwitchPositionLogicProcess(switchId, switchSetPos, 0u, &chTemp))
		{ /*检查通过*/

			(void)SetSwitchDanCaoPosition(switchId, switchSetPos); /*设置单操位置标志*/
		}
		else
		{ /*单操失败*/
		}
	}
}

/*
* 功能描述： 办理非进路逻辑处理
* 参数说明： 
* 返回值  ：    
*/
void SetNonRouteM(UINT8 nonRouteId)
{
    /*办理非进路处理*/
	UINT8 interfaceType = GetCiFunctionSwitchConfig(SCX_CLD_INTERFACE_TYPE);/*获取试车线与车辆段接口方式*/

	if (CI_SUCCESS == SetNonRouteP(nonRouteId))
	{ /*检查通过*/

		SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_XUANPAI); /*设置非进路为选排*/
		if (SCX_CLD_INTERFACE_RELAY == interfaceType)
		{/*继电器接口*/
			/* SQJ检查 */
			if (GetRelayCollState(GetNonRouteAppTryRelayIdById(nonRouteId)) == RELAY_STATE_UP)
			{ /*没有试车申请*/

				(void)SetNonRouteRunModeById(nonRouteId,NONROUTE_RUN_MODE_TRAIN); /*设置非进路为试车模式*/
			}
			else
			{ /*有试车申请*/

				(void)SetNonRouteRunModeById(nonRouteId,NONROUTE_RUN_MODE_APPLY); /*设置非进路为试信号模式*/
			}
		} 
		else if((SCX_CLD_INTERFACE_COMM  == interfaceType)||(SCX_CLD_SERIAL_PORT_COMM == interfaceType))
		{/*通信接口*/
			if (COMM_TRAIN_TEST_DEV_STATE_INVALID == GetCommTrainTestCLDSQJStatus())
			{/*无试车申请*/
				(void)SetNonRouteRunModeById(nonRouteId,NONROUTE_RUN_MODE_TRAIN); /*设置非进路为试车模式*/
			} 
			else
			{/*有试车申请*/
				(void)SetNonRouteRunModeById(nonRouteId,NONROUTE_RUN_MODE_APPLY); /*设置非进路为试信号模式*/
			}
		}
		else
		{
			/*无操作*/
		}
	}
	else 
	{ /*办理失败*/
	}
}


/*
* 功能描述： 取消非进路逻辑处理
* 参数说明： 
* 返回值  ：    
*/
void CancelNonRouteM(UINT8 nonRouteId)
{
	/*变量初始化*/
	UINT8 ciFunctionSwitchConfig = 0u;
	UINT8 routeCancelFlag = 0u;
	UINT8 routeHaveCancelFlag = 0u;
	UINT8 routeRunMode = 0u;
	UINT8 trainRelayState = 0u;
	UINT16 tryTrainRelayId = 0u;
	UINT8 nonRouteState = 0u;
	UINT8 CLDSQJStatus = 0u;
	UINT8 retvalue = CI_ERROR;

	/*获取状态*/
	routeCancelFlag = GetNonRouteCancelFlagById(nonRouteId);
	routeHaveCancelFlag = GetNonRouteHaveCancelFlagById(nonRouteId);


	if (NONROUTE_CANCEL_FLAG_YES == routeCancelFlag)
	{ /*取消标志有效*/
		debug_infor_printf((const)"CancelNonRouteM %d failed, cause the NONROUTE_CALCEL_FLAG is YES.",nonRouteId);
	    retvalue = CI_ERROR;
	}
	else
	{
		retvalue = CI_SUCCESS;
	}
	
	if(CI_SUCCESS == retvalue)
	{
		if (NONROUTE_CANCEL_FLAG_YES == routeHaveCancelFlag)
		{ /*取消过标志有效*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause the NONROUTE_HAVE_CALCEL_FLAG is YES.",nonRouteId);
			retvalue = CI_ERROR;
		}
		else
		{
		}
	}
	else
	{
	}

	if(CI_SUCCESS == retvalue)
	{
		/*获取模式和通信方式*/
		routeRunMode = GetNonRouteRunModeById(nonRouteId);
		ciFunctionSwitchConfig = GetCiFunctionSwitchConfig(SCX_CLD_INTERFACE_TYPE);
		tryTrainRelayId = GetNonRouteAppTryRelayIdById(nonRouteId);
		trainRelayState = GetRelayCollState(tryTrainRelayId);
		CLDSQJStatus = GetCommTrainTestCLDSQJStatus();

		/*试信号模式，且继电模式下，继电器落下；通信模式，设备有效*/
		if (((NONROUTE_RUN_MODE_APPLY == routeRunMode) &&
			((RELAY_STATE_DOWN == trainRelayState) && (SCX_CLD_INTERFACE_RELAY == ciFunctionSwitchConfig)))
			|| ((COMM_TRAIN_TEST_DEV_STATE_VALID == CLDSQJStatus) && ((SCX_CLD_INTERFACE_COMM == ciFunctionSwitchConfig)
			|| (SCX_CLD_SERIAL_PORT_COMM == ciFunctionSwitchConfig))))
		{ /*试信号模式且未申请试车结束*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause the mode is APPLY,and ApplyTryTrain is not finished.",nonRouteId);
			retvalue = CI_ERROR;
		}
		else
		{
		}
	}
	else
	{
	}
	if(CI_SUCCESS == retvalue)
	{
		nonRouteState = GetNonRouteStateById(nonRouteId);
		if ((NONROUTE_STATE_XUANPAI != nonRouteState) &&
			(NONROUTE_STATE_LOCK != nonRouteState) &&
			(NONROUTE_STATE_LOCKERR != nonRouteState) &&
			(NONROUTE_STATE_OPEN != nonRouteState))
		{ /*非进路状态不为选排||锁闭||故障锁闭||开放*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause the nonRoute state is %d.",nonRouteId,GetNonRouteStateById(nonRouteId));
			retvalue = CI_ERROR;
		}
		else
		{
		}
	}
	else
	{
	}
	if(CI_SUCCESS == retvalue)
	{
		(void)SetNonRouteCancelFlagById(nonRouteId,NONROUTE_CANCEL_FLAG_YES); /*设置非进路取消标志*/
	}
	else
	{
	}
}


/*
* 功能描述： 故障取消非进路逻辑处理
* 参数说明： 
* 返回值  ：    
*/
void FaultCancelNonRouteM(UINT8 nonRouteId)
{
	/*变量初始化*/
	UINT8 ciFunctionSwitchConfig = 0u;
	UINT8 routeCancelFlag = 0u;
	UINT8 routeHaveCancelFlag = 0u;
	UINT8 routeRunMode = 0u;
	UINT8 trainRelayState = 0u;
	UINT16 tryTrainRelayId = 0u;
	UINT8 faultCancelState = 0u;
	UINT8 CLDSQJStatus = 0u;
	UINT8 nonRouteState = 0u;
	UINT8 signalAllClose = 0u;
	UINT8 retvalue = CI_ERROR;

	/*获取取消标志状态*/
	routeCancelFlag = GetNonRouteCancelFlagById(nonRouteId);
	routeHaveCancelFlag = GetNonRouteHaveCancelFlagById(nonRouteId);

	if (NONROUTE_CANCEL_FLAG_YES == routeCancelFlag)
	{ /*取消标志有效*/
		debug_infor_printf((const)"CancelNonRouteM %d failed, cause the NONROUTE_CALCEL_FLAG is YES.",nonRouteId);
	    retvalue = CI_ERROR;
	}
	else
	{
		retvalue = CI_SUCCESS;
	}
	if(CI_SUCCESS == retvalue)
	{
		if (NONROUTE_CANCEL_FLAG_NO == routeHaveCancelFlag)
		{ /*取消过标志无效*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause the NONROUTE_HAVE_CALCEL_FLAG is YES.",nonRouteId);
			retvalue = CI_ERROR;
		}
	}
	if(CI_SUCCESS == retvalue)
	{
		/*获取模式和通信方式*/
		routeRunMode = GetNonRouteRunModeById(nonRouteId);
		ciFunctionSwitchConfig = GetCiFunctionSwitchConfig(SCX_CLD_INTERFACE_TYPE);
		tryTrainRelayId = GetNonRouteAppTryRelayIdById(nonRouteId);
		trainRelayState = GetRelayCollState(tryTrainRelayId);
		CLDSQJStatus = GetCommTrainTestCLDSQJStatus();

		/*试信号模式，且继电模式下，继电器落下；通信模式，设备有效*/
		if (((NONROUTE_RUN_MODE_APPLY == routeRunMode) &&
			((RELAY_STATE_DOWN == trainRelayState) && (SCX_CLD_INTERFACE_RELAY == ciFunctionSwitchConfig))) 
			|| ((COMM_TRAIN_TEST_DEV_STATE_VALID == CLDSQJStatus) && ((SCX_CLD_INTERFACE_COMM == ciFunctionSwitchConfig)
			|| (SCX_CLD_SERIAL_PORT_COMM == ciFunctionSwitchConfig))))
		{ 
			/*试信号模式且未申请试车结束*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause the mode is APPLY,and ApplyTryTrain is not finished.",nonRouteId);
			retvalue = CI_ERROR;
		}
	}
	if(CI_SUCCESS == retvalue)
	{
		nonRouteState = GetNonRouteStateById(nonRouteId);
		if (NONROUTE_STATE_LOCKERR != nonRouteState)
		{ /*非进路状态故障锁闭*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause nonRoute STATE is %d, not NONROUTE_STATE_LOCKERR.",nonRouteId,GetNonRouteStateById(nonRouteId));
			retvalue = CI_ERROR;
		}
	}
	if(CI_SUCCESS == retvalue)
	{
		signalAllClose = CheckNonRouteSignalAllClose(nonRouteId);
		if (CI_ERROR == signalAllClose)
		{ /*非进路有信号开放*/
			debug_infor_printf((const)"CancelNonRouteM %d failed, cause CheckNonRouteSignalAllClose failed.",nonRouteId);
			retvalue = CI_ERROR;
		}
	}

	if(CI_SUCCESS == retvalue)
	{
		faultCancelState = FaultCancelNonRouteP(nonRouteId);
		/*故障取消非进路处理*/
		if (CI_SUCCESS == faultCancelState)
		{
			(void)SetNonRouteStateById(nonRouteId,NONROUTE_STATE_FAULTDELAY_UNLOCK); /*设置非进路为故障延时解锁*/
		}
	}
	
}


/*
* 功能描述： 设置停止检查
* 参数说明： void
* 返回值  ：    
*/
void SetStopCheckM(void)
{
	SetStopCheckFlag();	/*设置停止检查*/
}


/*
* 功能描述： 取消停止检查
* 参数说明： void
* 返回值  ：    
*/
void CancelStopCheckM(void)
{
	CancelStopCheckFlag(); /*取消停止检查*/
}


/*
* 功能描述： 进路总取消处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void      
*/
void RouteZongQuXiaoDeal(const UINT16 routeId)
{
	UINT8 routeState = 0u; /*进路状态*/
    UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT8 routeType = 0u; /*进路类型*/
	

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

	/*###关信号*/
	if (GetSignalOpenCloseState(GetSignalCurColor(startSignalId)) == SIGNAL_OPEN)
	{ /*信号未关闭*/

        (void)DriveSignalClose(startSignalId);  /*驱动信号关闭*/
        return;
    }
    else
    { /*信号已关闭*/

        SetRouteZongQuXiaoFlag(routeId, ROUTE_ZONGQUXIAO_SET_NO);  /*取消进路总取消标志*/
    }
	
	
	/*###取消进路*/
	if (ROUTE_STATE_IDLE == routeState)
	{ /*进路空闲*/

		CancelLongRouteXuanPai(routeId); /*取消长调进路选排*/
	}
	else if (ROUTE_STATE_XUANPAI == routeState)
    { /*进路选排*/
        
		CancelRouteXuanPai(routeId); /*取消进路选排*/
	}
    else if ((ROUTE_STATE_FIRST_LOCK == routeState) || 
             (ROUTE_STATE_FIRST_LOCKERR == routeState) || 
             (ROUTE_STATE_YUXIAN_LOCK == routeState))
    { /*进路初锁||进路初锁异常||进路预先锁闭*/
        	    
        routeType = GetRouteType(routeId); /*获取进路类型*/
		
		if (ROUTE_TYPE_LIECHE == routeType)
		{ /*列车进路*/
		
			if (CI_SUCCESS == RouteCancelLogicProcess(routeId))
			{ /*总取消列车进路成功*/
				
				SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

				/*设置进路逻辑区段: 未锁闭*/
				SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			
				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
			}
			else
			{ /*总取消失败*/
			}
		}
		else if (ROUTE_TYPE_DIAOCHE == routeType)
		{ /*调车进路*/
		    
			if (CI_SUCCESS == CancelDTrainRouteP(routeId))
			{ /*总取消调车进路成功*/
				
				SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

				/*设置进路逻辑区段: 未锁闭*/
				SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			
				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
			}
			else
			{ /*总取消失败*/
			}
		}
		else
		{ /*进路类型错误*/
		}
	}
	else if ((ROUTE_STATE_NEAR_LOCK == routeState) || 
            (ROUTE_STATE_NEAR_LOCKERR == routeState))
	{
        /*反馈接近锁闭*/
        SetCiSendCmdBackInfoData(CI_BACK_ROUTE_NEAR_LOCK_YES,CI_DEVICE_TYPE_ROUTE,routeId,0,0);
    }
	else if ((ROUTE_STATE_LEAD_LOCK == routeState) ||
		(ROUTE_STATE_LEAD_LOCKERR == routeState) ||
		(ROUTE_STATE_LEAD_OPEN == routeState) ||
		(ROUTE_STATE_LEAD_XUANPAI == routeState))
	{
		/*引导进路总取消不反馈信息*/
	}
    else
    {
        /*反馈未完整锁闭*/
        SetCiSendCmdBackInfoData(CI_BACK_ROUTE_LOCK_NOTALL,CI_DEVICE_TYPE_ROUTE,routeId,0,0);
    }
}


/*
* 功能描述： 进路总人解处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void   
*/
void RouteZongRenJieDeal(const UINT16 routeId)
{
	UINT8 routeState = 0u; /*进路状态*/
    UINT16 startSignalId = 0u; /*进路始端信号机ID*/
	UINT8 routeType = 0u; /*进路类型*/

	UINT8 checkResult = 0u;/*区段是否有车占用*/
	UINT16 firstOccuSecId = 0u;/*进路内方第一个占用的物理区段ID*/
	UINT8 devState = 0u;
	UINT8 trainEnterSta = 0u;/*进路列车驶入标志*/
	/*UINT8 zrjCloseSigFlag;*//*总人解导致关信号标志*/
	UINT8 zrjExe = CI_ERROR;/*总人解能否执行*/
	UINT8 checkResultSecAndQXZC = 0u;   /*RouteExceptLastSecOccuClrCheck此函数的检查结果*/
	
	/*获取进路动态字段*/
	routeState = GetRouteState(routeId);  /*获取进路状态*/
	startSignalId = GetRouteStartSignalId(routeId);

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

        (void)DriveSignalClose(startSignalId); /*驱动信号关闭*/
#if 0
		SetRouteZongRenJieCloseFlag(routeId, ROUTE_ZRJ_CLOSE_FLAG_YES);/*进路信号关闭是总人解导致*/
#endif
        return;
    }
    else
    { /*信号已关闭*/

		(void)SetRouteZongRenJieFlag(routeId, ROUTE_ZONGRENJIE_SET_NO); /*取消进路总人解标志*/
#if 0
		zrjCloseSigFlag = GetRouteZongRenJieCloseFlag(routeId);/*或取进路的总人解关信号标志*/
		SetRouteZongRenJieCloseFlag(routeId, ROUTE_ZRJ_CLOSE_FLAG_NO);/*用完清除*/
#endif
    }
	
	trainEnterSta = GetRouteTrainEnterFlag(routeId);
	routeType = GetRouteType(routeId); /*获取进路类型*/

	if (ROUTE_TYPE_DIAOCHE==routeType)
	{
		checkResult = CheckDTrainRoutePhySecOccupy(routeId, EFUNC_ROUTE_ZRJ_DEAL, ESEND_LEVEL_ZERO);
	}
	else if (ROUTE_TYPE_LIECHE == routeType)
	{
		checkResult = RouteAllSecOccuClearCheck(routeId, &firstOccuSecId, &devState);
	}
	else
	{
    /*什么都不做*/
	}

	/*总人解进路处理*/
	if (ROUTE_STATE_IDLE == routeState)
	{ /*进路空闲*/

		CancelLongRouteXuanPai(routeId); /*取消长调进路选排*/
	}
	else if (ROUTE_STATE_XUANPAI == routeState)
	{ /*进路选排*/

        CancelRouteXuanPai(routeId); /*取消进路选排*/
	}
    else  if ((ROUTE_STATE_FIRST_LOCK == routeState) || 
              (ROUTE_STATE_FIRST_LOCKERR == routeState) || 
              (ROUTE_STATE_YUXIAN_LOCK == routeState))
	{ /*进路初锁||进路初锁异常||进路预先锁闭*/

		zrjExe = CheckRouteZongRenJieFeasibility(routeId);
		if (CI_SUCCESS == zrjExe)
		{
			if (CI_SUCCESS == checkResult)
			{/*已无占用*/
				SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

				/*设置进路逻辑区段: 未锁闭*/
				SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);

				SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
			}
			else
			{
				if (ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta)
				{/*无车驶入，全部变绿光带*/
					/*将进路内所有物理区段变成绿光带*/
					SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_EXCEPT);

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

				SetRouteStateDeal(routeId, ROUTE_STATE_AUTO_UNLOCKERR);
			}
		}
		else
		{
			/*进路不能取消*/
		}
    }
	else  if ((ROUTE_STATE_LEAD_LOCK == routeState) ||
              (ROUTE_STATE_LEAD_LOCKERR == routeState))
	{ /*进路引导锁闭||进路引导锁闭异常*/
	    		/*人解引导进路解锁原则：修改20180809
		当进路内方空闲或最后一个区段占用时，立即解锁；
		当非最后一个区段占用且无驶入，则延时解锁，其他场景不解锁*/
		checkResultSecAndQXZC = RouteExceptLastSecOccuClrCheck(routeId);
		if (CI_SUCCESS == checkResultSecAndQXZC)
		{   /*所有区段空闲或最后一个区段占用*/

			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);

			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		} 
		else if ((ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta) && (CI_ERROR_QXZC != checkResultSecAndQXZC))
		{  /*列车未驶入且非最后一个区段，延时解锁*/
			SetRouteStateManage(routeId, ROUTE_STATE_DELAY_UNLOCK);  /*设置进路延时解锁*/
			SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);  /*延时结束后所有区段解锁*/
		} 
		else
		{
			/*不解锁*/
		}
	}
    else if (ROUTE_STATE_NEAR_LOCKERR == routeState)
    { 
		zrjExe = CheckRouteZongRenJieFeasibility(routeId);

		/*总人解可执行*/
		if (CI_SUCCESS==zrjExe)
		{
			SetRouteStateDeal(routeId, ROUTE_STATE_DELAY_UNLOCK); /*设置进路状态为延时解锁*/

			if (CI_SUCCESS == checkResult)
			{
				/*无车占用，延时后全部解锁*/
				SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_IDLE);
			}
			else
			{
				if (ROUTE_TRAIN_ENTER_FLAG_NO == trainEnterSta)
				{
					/*无列车驶入过，延时后全部边绿光带*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_ALL_EXP);
				}
				else
				{
					/*车身后变绿光带*/
					SetRouteZongRenJieDelayType(routeId, ROUTE_ZRJ_DELAY_TYPE_EXP_TO_OCCUPY);
				}
			}
		}
    }
    else
    {
        /*进路不满足总人解条件*/
		/*进路状态不满足*/
		/* 记录故障码 */
		SetErrorData(EFUNC_ROUTE_ZRJ_DEAL, CI_DEVICE_TYPE_ROUTE, routeId, ETYPE_ROUTE_STATE, routeState, ESEND_LEVEL_ATS);
    }
}


/*
* 功能描述： 非进路取消处理
* 参数说明： UINT8 nonRouteId，非进路ID
* 返回值  ： void      
*/
void NonRouteCancelDeal(UINT8 nonRouteId)
{
	UINT8 nonRouteState = 0u; /*进路状态*/

	if (CI_ERROR == CheckNonRouteSignalAllClose(nonRouteId))
	{ /*非进路有信号开放*/

		DriveNonRouteSignalClose(nonRouteId); /*驱动非进路信号关闭*/
		return;
	}

	(void)SetNonRouteHaveCancelFlagById(nonRouteId,NONROUTE_CANCEL_FLAG_YES);/*设置非进路取消过标志*/
	(void)SetNonRouteCancelFlagById(nonRouteId,NONROUTE_CANCEL_FLAG_NO); /*清除非进路取消标志*/

	nonRouteState = GetNonRouteStateById(nonRouteId); /*获取非进路状态*/

	if (NONROUTE_STATE_XUANPAI == nonRouteState)
	{ /*选排*/

		CancelNonRouteXuanPai(nonRouteId); /*取消非进路选排*/
	}
	else if (NONROUTE_STATE_LOCK == nonRouteState)
	{ /*锁闭*/

		if (CI_SUCCESS == CancelNonRouteP(nonRouteId))
		{
			SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_DELAY_UNLOCK); /*设置非进路为延时解锁*/
		}
		else
		{
			SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_LOCKERR); /*设置非进路故障锁闭*/
		}
	}
	else if (NONROUTE_STATE_LOCKERR == nonRouteState)
	{ /*故障锁闭*/

		if (CI_SUCCESS == CancelNonRouteP( nonRouteId))
		{
			SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_DELAY_UNLOCK); /*设置非进路为延时解锁*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}



/*
* 功能描述： 更新照查继电器
* 参数说明： 
            const UINT16 routeId, UINT8 routeState
* 返回值  ：    
            CI_ERROR
            CI_SUCCESS
*/
void UpdateZhaoChaDeal(const UINT16 routeId, const UINT8 routeState)
{
	UINT16 wSelfRealyId = 0U; /*本模式本端照查ID*/
	UINT8 relauDrvState = 0U;
	UINT8 chOverTimeCheck = 0U;
	UINT32 dwTimeOutCycCount = 0U;
	UINT32 dwRouteLockStartCycNum = 0U;

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

	if (0U < wSelfRealyId)
	{
		if ((routeState == ROUTE_STATE_IDLE) ||
			(routeState == ROUTE_STATE_FIRST_XUANPAI) ||
			(routeState == ROUTE_STATE_XUANPAI) ||
			(routeState == ROUTE_STATE_LEAD_FIRST_XUANPAI) ||
			(routeState == ROUTE_STATE_LEAD_XUANPAI))
		{
			relauDrvState = GetRelayDriveState(wSelfRealyId);
			if (RELAY_DRIVE_STATE_NULL == relauDrvState)
			{
				(void)SetRelayDriveState(wSelfRealyId, RELAY_STATE_UP);
			}
		}
		else
		{
			(void)SetRelayDriveState(wSelfRealyId, RELAY_STATE_DOWN);
			relauDrvState = GetRelayCollState(wSelfRealyId);

			if (RELAY_STATE_DOWN != relauDrvState)
			{ /*照查继电器未落下*/
				chOverTimeCheck = SystemOverTimeCheck(dwRouteLockStartCycNum, dwTimeOutCycCount);
				if (CI_TIME_OUT == chOverTimeCheck)
				{/*照查超时超时*/

					/*xxxxx宕机*/
					SetPlatOverFlag(); /*设置平台宕机*/
					SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_RELAY, wSelfRealyId, ETYPE_ZHAOCHA_ROUTE_OVERTIME, RELAY_STATE_UP, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
				}
			}
		}
	}
}



/*
* 功能描述： 非进路锁闭驱动道岔处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8 
*/
UINT8 NonRouteLockDrvSwitchDeal(const UINT8 nonRouteId)
{
	UINT16 switchId = 0u; /*道岔ID*/
	UINT8 switchPos = 0u; /*道岔位置*/
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteSwitchStruct* pNonRouteSwitchStru = NULL; /*道岔数据*/
	UINT8 protectSwitchSum = 0u; /*防护道岔总数*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL; /*防护道岔数据*/
	UINT8 switchDancaoPosition = 0u;
	UINT8 ii = 0u;
	
	switchSum = GetNonRouteSwitchSumById(nonRouteId); /*非进路道岔总数*/
	pNonRouteSwitchStru = GetNonRouteSwitchStructBufById(nonRouteId); /*非进路道岔数据*/
	protectSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId); /*非进路防护道岔总数*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru(nonRouteId); /*非进路防护道岔数据*/
	
    if ((0u == switchSum) || (NULL == pNonRouteSwitchStru))
    {
        return CI_ERROR;
    }

	/* 非进路道岔单操相反位置取消进路检查 */
    for (ii = 0u; ii < switchSum; ii++)
    {
        switchId = pNonRouteSwitchStru[ii].SwitchId;
        switchPos = pNonRouteSwitchStru[ii].SwitchPos;
        switchDancaoPosition = GetSwitchDanCaoPostition(switchId);
        
        if ((switchDancaoPosition == SWITCH_POSITION_INVALID)
            || (switchDancaoPosition == switchPos))
        {
            /*单操无效 或者 单操位置与动作位置一样*/
            continue;
        }
        else
        {
            /*单操到相反位置取消进路*/
            return CI_ERROR;
        }
	}

	/* 非进路防护道岔单操相反位置取消进路检查 */
	for (ii = 0u; ii < protectSwitchSum; ii++)
	{
		switchId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
		switchPos = pNonRouteProtectSwitchStru[ii].ProtectPosition;
		switchDancaoPosition = GetSwitchDanCaoPostition(switchId);

		if ((switchDancaoPosition == SWITCH_POSITION_INVALID)
			|| (switchDancaoPosition == switchPos))
		{
			/*单操无效 或者 单操位置与动作位置一样*/
			continue;
		}
		else
		{
			/*单操到相反位置取消进路*/
			return CI_ERROR;
		}
	}

	/*错峰驱动道岔*/
	for (ii = 0u; ii < switchSum; ii++)
	{
		switchId = pNonRouteSwitchStru[ii].SwitchId;
		switchPos = pNonRouteSwitchStru[ii].SwitchPos;

		(void)SwitchDriveProcess(switchId, switchPos); /*驱动道岔*/
	}

	for (ii = 0u; ii < protectSwitchSum; ii++)
	{
		switchId = pNonRouteProtectSwitchStru[ii].ProtectSwitchId;
		switchPos = pNonRouteProtectSwitchStru[ii].ProtectPosition;

		(void)SwitchDriveProcess(switchId, switchPos); /*驱动道岔*/
	}

    return CI_SUCCESS;
}


/*
* 功能描述： 区段故障解锁异常锁闭处理
* 参数说明： UINT16 phySecId 物理区段ID
*	返回值：1：有
*         0: 无
*/
void PhySecFaultRelatedUnLockDeal(const UINT16 phySecId, const UINT16 belongRouteId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 ii= 0u;


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

	if (0u == sectionSum) 
	{
		return;
	}

	for (ii = 0u; ii < sectionSum; ii++)
	{
		if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId)) &&
			(belongRouteId == GetPhySecRLockBelongRouteId(RouteSecStru[ii].PhysicalSectionId)))
		{ /*正常锁闭且为本进路锁闭*/

			SetPhySecLockState(RouteSecStru[ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_EXCEPT, 0, 0); /*设置区段异常锁闭*/
		}
		else
		{
		}
	}
}

#if 0
void PhySecFaultRelatedUnLockDeal(const UINT16 phySecId, const UINT16 belongRouteId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 phySecOccupyIndex = 0xFF; /*物理区段占用下标*/
	UINT8 ii= 0u;
	
	
	sectionSum = GetRoutePhysicalSectionSum(belongRouteId); /*获得进路包含的区段数目*/
	RouteSecStru = GetRouteSectionData(belongRouteId); /*进路区段数据*/
	
	if ((0u == sectionSum) || (NULL == RouteSecStru))
	{
	    return;
	}
	else
	{
	}

	for (ii = 0u; ii < sectionSum; ii++)
	{
	    if (phySecId == RouteSecStru[ii].PhysicalSectionId)
		{ /*找到物理区段*/
		    
			phySecOccupyIndex = ii;
			break;
		}
		else
	    {
	    }
	}
	
	if (0xFFu == phySecOccupyIndex)
	{
	    return;
	}
	else
	{
	}
	
	/*遍历已解锁区段左侧所有区段*/
	for (ii = 0u; ii < phySecOccupyIndex; ii++)
	{
		if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(RouteSecStru[phySecOccupyIndex-1-ii].PhysicalSectionId)) &&
			(belongRouteId == GetPhySecRLockBelongRouteId(RouteSecStru[phySecOccupyIndex-1-ii].PhysicalSectionId)))
        { /*正常锁闭且为本进路锁闭*/
		
		    if (PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(RouteSecStru[phySecOccupyIndex-1-ii].PhysicalSectionId))
			{ /*无岔区段*/
			    
				SetPhySecLockState(RouteSecStru[phySecOccupyIndex-1-ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, belongRouteId, GetRouteDirection(belongRouteId)); /*设置区段未锁闭*/
			}
			else
			{ /*有岔区段*/
			
			    SetPhySecLockState(RouteSecStru[phySecOccupyIndex-1-ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_EXCEPT, 0, 0); /*设置区段异常锁闭*/
			    break;
			}
		}
        else
		{
			break;
		}
	}
	
	/*遍历已解锁区段右侧所有区段*/
	for (ii = phySecOccupyIndex+1u; ii < sectionSum; ii++)
	{
		if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId)) &&
			(belongRouteId == GetPhySecRLockBelongRouteId(RouteSecStru[ii].PhysicalSectionId)))
        { /*正常锁闭*/
		
		    if (PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(RouteSecStru[ii].PhysicalSectionId))
			{ /*无岔区段*/
			    
				SetPhySecLockState(RouteSecStru[ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_NO, belongRouteId, GetRouteDirection(belongRouteId)); /*设置区段未锁闭*/
			}
			else
			{ /*有岔区段*/
			
			    SetPhySecLockState(RouteSecStru[ii].PhysicalSectionId, PHYSICAL_SECTION_LOCK_EXCEPT, 0u, 0u); /*设置区段异常锁闭*/
			    break;
			}
		}
        else
		{
			break;
		}
	}
}
#endif



/*
* 功能描述： 设置进路状态处理
* 参数说明： UINT16 routeId 进路号
*	返回值：void
*/
void SetRouteStateDeal(const UINT16 routeId, const UINT8 routeState)
{
	UINT8 cSGBJDelayOpenFlag = 0U;  /*声光报警延时开放标志*/
	UINT8 cRelZuHeSGBJDelayOpenFlag = 0U;  /*关联组合进路声光报警延时开放标志*/
	UINT32 dwCurDelayOpenStartCycNum = 0U;  /*进路声光报警延时开放起始周期*/
	UINT32 dwCurCycNum = 0U;

	dwCurCycNum = Get2oo2CurCycleNum();
	
	if (ROUTE_STATE_IDLE == routeState)
	{ /*进路空闲*/
	
		SetRouteStopFlagManage(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
		
		if (GetRouteBelongLongRouteId(routeId) > 0u)
		{
		    SetLongRouteStateDeal(GetRouteBelongLongRouteId(routeId), ROUTE_LONG_STATE_IDLE);  /*-->设置长调进路空闲*/
		}
		else
		{
		}
		
		SetRouteBelongLongRouteId(routeId, 0u); /*清除进路所属长调*/
		
		SetRouteOpenSigStartCycNum(routeId, 0u); /*重置信号开放时间*/

		SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);/*空闲也清除进路恢复状态，用于下一次进路状态流转*/

		SetTrainEnterRouteFlag(routeId,TRAIN_ENTER_ROUTE_FLAG_NO);/*进路空闲后清除列车驶入进路标志*/

		SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_CANCEL); /*取消进路关联防护道岔的防护锁闭*/

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

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

		/*设置进路未驱动过声光报警*/
		SetRouteHasDrivedSGBJFlag(routeId, ROUTE_HAS_DRIVED_SGBJ_INVALID);
	}
	else if (ROUTE_STATE_XUANPAI == routeState)
	{ /*进路选排*/
	
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES); /*设置进路物理区段征用*/
#if 0
        SetRouteStopFlagManage(routeId,ROUTE_STOPCHECK_SET_YES);/*设置进路停止检查标志*/
#endif
	}
	else if (ROUTE_STATE_FIRST_LOCK ==routeState)
	{ /*进路初锁*/
	    
		SetRouteBelongLongRouteId(routeId, 0u); /*清除进路所属长调*/
		
		SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NORMAL); /*设置进路区段正常锁闭*/

		/*设置进路逻辑区段: 正常锁闭*/
		SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NORMAL);
		
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*设置进路物理区段未征用*/

		SetRouteRelProSwitchLockSta(routeId, SWITCH_LOCK_PROTECT_SET); /*设置进路关联防护道岔为防护锁闭*/       
		
		/*清除进路相关道岔期望驱动位置*/
		ClearRouteSwitchDrivePos(routeId);

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

		SetRouteRecoverState(routeId, ROUTE_RECOVER_STA_INIT);/*初锁意味着重新完整锁闭，准备开信号*/

		/*设置声光报警延时开放起始周期时间*/
		cSGBJDelayOpenFlag = GetRouteSGBJDelayFlag(routeId);
		cRelZuHeSGBJDelayOpenFlag = GetRelZuHeRouteSGBJDelayFlag(routeId);
		dwCurDelayOpenStartCycNum = GetRouteDelayOpenStartCyc(routeId);

		if ((0U == dwCurDelayOpenStartCycNum) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cSGBJDelayOpenFlag) && (ROUTE_SGBJ_DELAY_OPEN_VALID == cRelZuHeSGBJDelayOpenFlag))
		{
			SetRouteDelayOpenStartCyc(routeId, dwCurCycNum);
			SetRouteOpenSigStartCycNum(routeId, 0U);  /*若存在声光报警延时，先清除进路信号开放时间，避免因声光报警延时导致进路信号开放时间超限*/
		}
		else if ((ROUTE_SGBJ_DELAY_OPEN_VALID != cSGBJDelayOpenFlag) || (ROUTE_SGBJ_DELAY_OPEN_VALID != cRelZuHeSGBJDelayOpenFlag))
		{			
			SetRouteOpenSigStartCycNum(routeId, dwCurCycNum); /*设置信号开放时间*/
		}
		else
		{
			/*已设置延时起始周期，不处理*/
		}
	}
	else if (ROUTE_STATE_YUXIAN_OPEN ==routeState)
	{ /*进路预先开放*/
	    
		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/
		
		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*取消进路信号重开标志*/

		(void)CleanRoutePhySecPreOccupyState(routeId); /*清除进路相关物理区段之前占用状态*/
		(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
		(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
		SetTrainEnterRouteFlag(routeId,TRAIN_ENTER_ROUTE_FLAG_NO);/*进路空闲后清除列车驶入进路标志*/
	}
	else if (ROUTE_STATE_NEAR_OPEN ==routeState)
	{ /*进路接近开放*/
	    
		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/
		
		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*取消进路信号重开标志*/

		(void)CleanRoutePhySecPreOccupyState(routeId); /*清除进路相关物理区段之前占用状态*/
		if ( ROUTE_STOPCHECK_SET_YES == GetRouteStopCheckFlag(routeId))
		{
			(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
			(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
		}
		else
		{
		}

		SetTrainEnterRouteFlag(routeId,TRAIN_ENTER_ROUTE_FLAG_NO);/*进路开放后清除列车驶入进路标志*/

	}
    else if (ROUTE_STATE_LEAD_XUANPAI == routeState)
    {/*进路引导选排*/

        SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_YES); /*设置进路物理区段征用*/
    }
	else if (ROUTE_STATE_LEAD_LOCK ==routeState)
	{ /*进路引导锁闭*/
	    
		SetRouteBelongLongRouteId(routeId, 0u); /*清除进路所属长调*/
		
		SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NORMAL); /*设置进路区段正常锁闭*/

		/*设置进路逻辑区段: 正常锁闭*/
		SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NORMAL);
		
		SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); /*设置进路物理区段未征用*/

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

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

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

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

		/*清除进路相关道岔单操位置*/
		ClearRouteSwitchDanCaoPos(routeId);
	}
	else if (ROUTE_STATE_LEAD_LOCKERR ==routeState)
	{ /*进路引导锁闭异常*/
	    
		SetRouteLeadFaultOpenStartCyc(routeId, 0u); /*清除引导故障延时时间*/
	}
	else if (ROUTE_STATE_LEAD_OPEN ==routeState)
	{ /*进路引导开放*/
	    
		SetRouteOpenSigStartCycNum(routeId, 0u);  /*重置信号开放时间*/
		
		SetRouteRepeatOpenFlag(routeId, ROUTE_REPEATOPEN_SET_NO); /*取消进路信号重开标志*/

		(void)CleanRoutePhySecPreOccupyState(routeId); /*清除进路相关物理区段之前占用状态*/
		(void)SetRouteStopKeepCheckFlag(routeId, GetRouteStopCheckFlag(routeId));  /*设置进路停止检查保持标志*/
		(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO); /*清除进路停止检查标志*/
	}
	else if (ROUTE_STATE_DELAY_UNLOCK == routeState)
	{ /*进路延时解锁*/

	}
	else
	{/*不处理*/
	}

	(void)SetRouteState(routeId, routeState); /*设置进路状态*/
}


/*
* 功能描述： 设置长调进路状态处理
* 参数说明： UINT16 routeId 进路号
*	返回值：1：有
*         0: 无
*/
void SetLongRouteStateDeal(const UINT16 longRouteId, const UINT8 longRouteState)
{
	UINT8 subRouteSum = 0u; /*子进路数目*/
	UINT16* pSubRouteIdBuf = NULL; /*子进路ID数组*/
	UINT8 ii = 0u;
	
    subRouteSum = GetLongRouteSubRouteSum(longRouteId); /*子进路数量*/
	pSubRouteIdBuf = GetLongRouteSubRouteIdBuf(longRouteId); /*子进路号*/
	
    if (subRouteSum <= 1u) 
	{
		return;
	}
	

	if (ROUTE_LONG_STATE_IDLE == longRouteState)
	{ /*长调空闲*/
	
		for (ii = 0u; ii < subRouteSum; ii++)
		{
		    SetRouteBelongLongRouteId(pSubRouteIdBuf[ii], 0u); /*清除子进路所属长调*/
			
			SetRoutePhySectionOccupyState(pSubRouteIdBuf[ii], PHYSICAL_SECTION_USING_NO); /*清除子进路征用*/
		}
	}
	else if (ROUTE_LONG_STATE_XUANPAI == longRouteState)
	{ /*长调选排*/

	}
	else if (ROUTE_LONG_STATE_LOCK ==longRouteState)
	{ /*长调锁闭*/
	    
		for (ii = 0u; ii < subRouteSum; ii++)
		{
			SetRoutePhySectionOccupyState(pSubRouteIdBuf[ii], PHYSICAL_SECTION_USING_NO); /*清除子进路征用*/
		}
	}
	else
	{
		return;
	}

	/*设置长调状态*/
	(void)SetLongRouteState(longRouteId, longRouteState);
}


/*
* 功能描述： 设置非进路状态处理
* 参数说明： UINT16 routeId 进路号
*	返回值：1：有
*         0: 无
*/
void SetNonRouteStateDeal(UINT8 nonRouteId,const UINT8 nonRouteState)
{
	UINT8 execRes = CI_ERROR;
	if (NONROUTE_STATE_IDLE == nonRouteState)
	{ /*非进路空闲*/
	
		execRes = SetNonRouteCancelFlagById(nonRouteId,NONROUTE_CANCEL_FLAG_NO); /*清除非进路取消标志*/

		execRes &= SetNonRouteHaveCancelFlagById(nonRouteId,NONROUTE_CANCEL_FLAG_NO);/*设置非进路取消过标志*/
		
		SetNonRouteSigOpenStartCycById(nonRouteId,0u); /*清除非进路信号开放时间*/

		SetNonRoutePhySecUsingState(nonRouteId,PHYSICAL_SECTION_USING_NO); /*设置非进路物理区段未征用*/

		SetNonRoutePhySecLockState(nonRouteId,PHYSICAL_SECTION_LOCK_NO); /*设置非进路区段未锁闭*/

		SetNonRouteLogSecLockState(nonRouteId, LOG_SECTION_LOCK_NO); /*设置非进路逻辑区段未锁闭*/

		execRes &= SetNonRouteRelatedProtSwLockSta(nonRouteId,SWITCH_LOCK_PROTECT_CANCEL);/*取消非进路防护道岔防护锁闭*/
		if (CI_ERROR == execRes)
		{
			/*暂时不做处理*/
		}
	}
	else if (NONROUTE_STATE_XUANPAI == nonRouteState)
	{ /*非进路选排*/
	    
		SetNonRoutePhySecUsingState(nonRouteId,PHYSICAL_SECTION_USING_YES); /*设置非进路物理区段征用*/
	}
	else if (NONROUTE_STATE_LOCK ==nonRouteState)
	{ /*非进路锁闭*/
	    
		SetNonRoutePhySecUsingState(nonRouteId,PHYSICAL_SECTION_USING_NO); /*设置非进路物理区段未征用*/

		SetNonRoutePhySecLockState(nonRouteId,PHYSICAL_SECTION_LOCK_NORMAL); /*设置非进路区段正常锁闭*/

		SetNonRouteLogSecLockState(nonRouteId, LOG_SECTION_LOCK_NORMAL); /*设置非进路逻辑区段正常锁闭*/

		execRes = SetNonRouteRelatedProtSwLockSta(nonRouteId,SWITCH_LOCK_PROTECT_SET);/*设置非进路防护道岔防护锁闭*/
		
		execRes &= SetNonRouteStateById(nonRouteId,NONROUTE_STATE_LOCK); /*设置非进路为锁闭*/
		
		SetNonRouteSigOpenStartCycById(nonRouteId,Get2oo2CurCycleNum()); /*设置非进路信号开放时间*/

		/*清除非进路道岔期望驱动位置*/
		execRes &= ClearNonRouteSwitchDrivePos(nonRouteId);

		/*清除非进路关联道岔单操位置*/
		execRes &= ClearNonRouteSwitchDanCaoPos(nonRouteId);

		if (CI_ERROR == execRes)
		{
			/*暂时不做处理*/
		}
	}
	else if (NONROUTE_STATE_LOCKERR ==nonRouteState)
	{ /*非进路异常锁闭*/
	    
	}
	else if (NONROUTE_STATE_OPEN ==nonRouteState)
	{ /*非进路开放*/
	    
		SetNonRouteSigOpenStartCycById(nonRouteId,0u); /*清除非进路信号开放时间*/
	}
	else if (NONROUTE_STATE_DELAY_UNLOCK ==nonRouteState)
	{ /*非进路延时解锁*/
	    
	}
	else if (NONROUTE_STATE_FAULTDELAY_UNLOCK ==nonRouteState)
	{ /*非进路故障延时解锁*/
	    
	}
	else
	{
		return;
	}

	/*设置非进路状态*/
	(void)SetNonRouteStateById(nonRouteId,nonRouteState); 
}

/*
* 功能描述： 设置非进路物理区段征用状态
* 参数说明： UINT16 routeId 进路号
*	返回值：1：有
*         0: 无
*/
void SetNonRoutePhySecUsingState(UINT8 nonRouteId,const UINT8 usingState)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;

	UINT8 nonRouteProSwitchSum = 0u;	/*非进路防护道岔数量*/
	NonRouteProtectSwitchStruct* pNonRouteProSwitchData = NULL;	/*非进路防护道岔数据*/
	UINT16 switchId = 0u;/*道岔ID*/
	UINT16 phyId = 0u;                   /*物理区段ID*/
	UINT8 reVal = CI_ERROR;

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

	nonRouteProSwitchSum = GetNonRouteRelatedProtSwitSum(nonRouteId);/*获取非进路防护道岔数量*/
	pNonRouteProSwitchData = GetNonRouteRelatedProtSwitStru(nonRouteId);/*获取非进路防护道岔数据*/
	
	if ((0u == sectionSum) || (NULL == pPhySecStruBuf))
	{
	    reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	
	if (CI_SUCCESS == reVal)
	{
		if ((PHYSICAL_SECTION_USING_YES!=usingState) &&
			(PHYSICAL_SECTION_USING_NO!=usingState))
		{
			reVal = CI_ERROR;
		}
	}
	
	if (CI_SUCCESS == reVal)
	{
		for(ii = 0u; ii < sectionSum; ii++)
		{
			SetPhySecUseState(pPhySecStruBuf[ii].PhySectionId, usingState, 0u); /*设置非进路区段征用*/
		}

		for (ii=0u;ii<nonRouteProSwitchSum;ii++)
		{
			switchId = pNonRouteProSwitchData[ii].ProtectSwitchId;
			phyId = GetSwitchPhySectionId(switchId);
			SetPhySecUseState(phyId, usingState, 0); /*设置非进路区段征用*/
		}
	}
	
}


/*
* 功能描述： 设置非进路物理区段锁闭状态
* 参数说明： const UINT16 nonRouteId, 非进路ID
*            const UINT8 lockState, 锁闭状态
*	返回值：无
* cgh_2030529_修改输入参数类型
*/
void SetNonRoutePhySecLockState(const UINT8 nonRouteId, const UINT8 lockState)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	NonRoutePhySectionStruct *pPhySecStruBuf = NULL; /*区段数据*/
	UINT8 ii= 0u;

	
	sectionSum = GetNonRoutePhySectionSumById(nonRouteId); /*获得非进路包含的区段数目*/
	pPhySecStruBuf = GetNonRoutePhySecStruBufById(nonRouteId); /*获取非进路区段数据*/
	
	if ((0u == sectionSum) || (NULL == pPhySecStruBuf))
	{
	    return;
	}
	
	if ((lockState != PHYSICAL_SECTION_LOCK_NO) &&
	    (lockState != PHYSICAL_SECTION_LOCK_NORMAL))
	{
	    return;
	}
	
	for(ii = 0u; ii < sectionSum; ii++)
	{
		/*设置非进路区段锁闭状态*/
		SetPhySecLockState(pPhySecStruBuf[ii].PhySectionId, lockState, 0u, 0u);
	}
}

/*
* 功能描述： 设置非进路关联防护道岔防护锁闭状态
* 参数说明： const UINT16 nonRouteId, 进路ID
*            const UINT8 lockCommand, 锁闭状态
* 返回值  ： 0 失败
*			 1 成功
*/
UINT8 SetNonRouteRelatedProtSwLockSta(const UINT16 nonRouteId, const UINT8 lockCommand)
{
	UINT8 ii = 0u;                                             /*遍历变量*/
	UINT8 retVal = CI_SUCCESS;                                /*返回值*/
	UINT16 protectSwitchId = 0u;                               /*防护道岔ID*/
	UINT8 protectSwitchSum = 0u; 	                          /*防护道岔数目*/
	NonRouteProtectSwitchStruct* pNonRouteProtectSwitchStru = NULL;  /*防护道岔数据*/

	protectSwitchSum = GetNonRouteRelatedProtSwitSum((UINT8)nonRouteId);      /*获取防护道岔数目*/
	pNonRouteProtectSwitchStru = GetNonRouteRelatedProtSwitStru((UINT8)nonRouteId);    /*获取防护道岔数据*/

	if ((0u == protectSwitchSum) || (NULL == pNonRouteProtectSwitchStru))
	{
		retVal = CI_ERROR;
	}

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

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

	return retVal;
}


/*
* 功能描述： 清空进路选排状态
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ：    
*/
void CancelLongRouteXuanPai(const UINT16 routeId)
{
	UINT16 longRouteCurSum = 0u;	/*获取进路结构体总数*/
	UINT16 *subRouteBuf = NULL; /*子进路数组*/
	UINT8 subRouteSum = 0u; /*子进路数目*/
	UINT16 longRouteId = 0u; /*长调进路ID*/
	UINT16 ii = 0u;
	UINT8 jj = 0u;
	
	longRouteCurSum = GetLongRouteCurSum();	/*获取长调进路结构体总数*/

	for (ii = 0u; ii <= longRouteCurSum; ii++)
	{/*遍历进路数据结构体*/

		longRouteId = GetLongRouteId(ii); /*获取长调进路ID*/
		
		if (ROUTE_LONG_STATE_XUANPAI == GetLongRouteState(longRouteId))
		{ /*进路状态选排*/
		
			subRouteSum = GetLongRouteSubRouteSum(longRouteId);   /*获取长调子进路数目*/
			subRouteBuf = GetLongRouteSubRouteIdBuf(longRouteId);   /*获取长调进路子进路*/
			
			if ((0u == subRouteSum) || (NULL == subRouteBuf))
			{
				continue;
			}
			
			if (routeId == subRouteBuf[subRouteSum-1U])
			{
				for (jj = 0u; jj < subRouteSum; jj++)
				{
					CancelRouteXuanPai(subRouteBuf[jj]); /*取消子进路选排处理*/
				}
				
				SetLongRouteStateDeal(longRouteId, ROUTE_LONG_STATE_IDLE); /*设置长调进路状态空闲*/
				
				break;
			}
		}
	}
}


/*
* 功能描述： 清空进路选排状态
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ：    
*/
void CancelRouteXuanPai(const UINT16 routeId)
{
    /*设置进路状态为空闲*/	
    SetRouteStateDeal(routeId, ROUTE_STATE_IDLE);
	
	/*设置进路物理区段征用*/
	SetRoutePhySectionOccupyState(routeId, PHYSICAL_SECTION_USING_NO); 
#if 0
	/*更新照查*/
	UpZhaoCha(routeId);
#endif
}


/*
* 功能描述： 取消非进路选排处理
* 参数说明： 
* 返回值  ：    
*/
void CancelNonRouteXuanPai(UINT8 nonRouteId)
{
    SetNonRouteStateDeal(nonRouteId,NONROUTE_STATE_IDLE); /*设置非进路状态为空闲*/
}


/*
* 功能描述： 非进路道岔检查
* 参数说明： const UINT16 switchId, 道岔ID
* 返回值  ： 0: 不属于已办理非进路
*			 1: 属于已办理非进路   
*/
UINT8 CheckSwitchBelongNonRoute(const UINT16 switchId)
{
	UINT8 switchSum = 0u; /*道岔总数*/
	NonRouteSwitchStruct* pNonRouteSwitchStru = NULL; /*道岔数据*/
	UINT8 ii = 0u;
	
	NonRouteConfigDataStruct *pNonRoute = GetNonRouteConfigDataBySwitchId(switchId);
	if (pNonRoute !=NULL)
	{
	
		switchSum = GetNonRouteSwitchSumById(pNonRoute->NonRouteId); /*非进路道岔总数*/
		pNonRouteSwitchStru = GetNonRouteSwitchStructBufById(pNonRoute->NonRouteId); /*非进路道岔数据*/
	
		if ((0u == switchSum) || (NULL == pNonRouteSwitchStru))
		{
			return CI_ERROR;
		}
	
		if (GetNonRouteStateById(pNonRoute->NonRouteId) == NONROUTE_STATE_IDLE)
		{ /*非进路空闲*/
	
			return CI_ERROR;
		}
		
		for (ii = 0u; ii < switchSum; ii++)
		{
			if (switchId == pNonRouteSwitchStru[ii].SwitchId)
			{ /*属于非进路*/
			
				return CI_SUCCESS;	
			}
		}
	}	
	return CI_ERROR;	
}


/*
* 功能描述： 非进路信号机检查
* 参数说明： const UINT16 signalId, 信号机ID
* 返回值  ： 0: 不属于已办理非进路
*			 1: 属于已办理非进路   
*/
UINT8 CheckSignalBelongNonRoute(const UINT16 signalId)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	
	NonRouteConfigDataStruct *pNonRoute = GetNonRouteConfigDataBySignalId(signalId);
	if (pNonRoute !=NULL)
	{
	
		sigSum = GetNonRouteSignalSumById(pNonRoute->NonRouteId); /*获取非进路信号机数目*/
		pSigIdBuf = GetNonRouteSignalIdBufById(pNonRoute->NonRouteId); /*获取非进路信号机ID数组*/
	
		if ((0u == sigSum) || (NULL == pSigIdBuf))
		{
			return CI_ERROR;
		}
	
		if (GetNonRouteStateById(pNonRoute->NonRouteId) == NONROUTE_STATE_IDLE)
		{ /*非进路空闲*/
	
			return CI_ERROR;
		}
	
		for (ii = 0u; ii < sigSum; ii++)
		{
			if (signalId == pSigIdBuf[ii])
			{ /*属于非进路*/
		
				return CI_SUCCESS;
			}
		}
	}

	return CI_ERROR;
}

/*
* 功能描述： 非进路物理区段检查
* 参数说明： const UINT16 phySecId 物理区段ID
* 返回值  ： 0: 不属于已办理非进路
*			 1: 属于已办理非进路
*/
UINT8 CheckPhySecBelongNonRoute(const UINT16 phySecId)
{
	UINT8 phySecSum = 0U; /*物理区段总数*/
	NonRoutePhySectionStruct* pNonRoutePhySecStru = NULL; /*物理区段数据*/
	UINT8 ii = 0U;
	UINT8 retVal = CI_ERROR;
	UINT8 nonRouteFlag = CI_ERROR;
	UINT8 nonRouteState = 0U;/*非进路状态*/

	NonRouteConfigDataStruct* pNonRoute = GetNonRouteConfigDataByPhySecId(phySecId);
	

	if (pNonRoute != NULL)
	{
		retVal = CI_SUCCESS;
		nonRouteState = GetNonRouteStateById(pNonRoute->NonRouteId);
		phySecSum = GetNonRoutePhySectionSumById(pNonRoute->NonRouteId); /*非进路区段总数*/
		pNonRoutePhySecStru = GetNonRoutePhySecStruBufById(pNonRoute->NonRouteId); /*非进路区段数据*/

		if ((0U == phySecSum) || (NULL == pNonRoutePhySecStru))
		{
			retVal = CI_ERROR;
		}
		else
		{
			/*检查通过*/
		}

		if (NONROUTE_STATE_IDLE == nonRouteState)
		{ /*非进路空闲*/

			retVal = CI_ERROR;
		}
		else
		{
			/*检查通过*/
		}

		if (CI_SUCCESS == retVal)
		{
			for (ii = 0U; ii < phySecSum; ii++)
			{
				if (phySecId == pNonRoutePhySecStru[ii].PhySectionId)
				{ /*属于非进路*/

					nonRouteFlag = CI_SUCCESS;
					break;
				}
				else
				{
					/*继续遍历*/
				}
			}
		}
		else
		{
			/*返回失败*/
		}

	}
	if (CI_SUCCESS == nonRouteFlag)
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}


/*
* 功能描述： 驱动非进路信号机关闭
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
void DriveNonRouteSignalClose(UINT8 nonRouteId)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	
	
	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((0u == sigSum) || (NULL == pSigIdBuf))
	{
	    return;
	}
	
	for (ii = 0u; ii < sigSum; ii++)
	{
		/*驱动信号红灯*/
		SetSignalCurDriveColor(pSigIdBuf[ii], SIGNAL_DRIVECOLOUR_RED);
	}
}


/*
* 功能描述： 驱动非进路信号机开放
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
void DriveNonRouteSignalOpen(UINT8 nonRouteId)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	
	
	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((0u == sigSum) || (NULL == pSigIdBuf))
	{
	    return;
	}
	
	for (ii = 0u; ii < sigSum; ii++)
	{
	    /*驱动信号白灯*/
		SetSignalCurDriveColor(pSigIdBuf[ii], SIGNAL_DRIVECOLOUR_WHITE);
	}
}


/*
* 功能描述： 非进路信号机完全关闭检查
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
UINT8 CheckNonRouteSignalAllClose(UINT8 nonRouteId)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	
	
	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((0u == sigSum) || (NULL == pSigIdBuf))
	{
	    return CI_ERROR;
	}
	
	for (ii = 0u; ii < sigSum; ii++)
	{
		if (SIGNAL_OPEN == GetSignalOpenCloseState(GetSignalCurColor(pSigIdBuf[ii])))
		{ /*有信号开放*/
		
		    return CI_ERROR;
		}
	}
	
	return CI_SUCCESS;
}


/*
* 功能描述： 非进路信号机完全开放检查
* 参数说明： 
* 返回值  ： 0:失败
*			 1:成功   
*/
UINT8 CheckNonRouteSignalAllOpen(UINT8 nonRouteId)
{
	UINT8 sigSum = 0u; /*信号机总数*/
	UINT16 *pSigIdBuf = NULL;/*信号数据*/
	UINT8 ii = 0u;
	
	
	sigSum = GetNonRouteSignalSumById(nonRouteId); /*获取非进路信号机数目*/
	pSigIdBuf = GetNonRouteSignalIdBufById(nonRouteId); /*获取非进路信号机ID数组*/
	
	if ((0u == sigSum) || (NULL == pSigIdBuf))
	{
	    return CI_ERROR;
	}
	
	for (ii = 0u; ii < sigSum; ii++)
	{
		if (SIGNAL_CLOSE == GetSignalOpenCloseState(GetSignalCurColor(pSigIdBuf[ii])))
		{ /*有信号关闭*/
		
		    return CI_ERROR;
		}
	}
	
	return CI_SUCCESS;
}




/*
* 功能描述： 清除进路之前占用状态
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： UINT8 
*/
#if 0
void CleanRoutePreOccupyState(const UINT16 routeId)
{
    UINT8 nearSecSum = 0u; /*接近区段总数*/
    UINT8 routeSecSum = 0u; /*进路区段总数*/
    RouteNearPhySectionStruct *pRouteNearSecData = NULL; /*接近区段数据*/
    RoutePhysicalSectionStruct *pRouteSecData = NULL; /*进路区段数据*/
    UINT8 ii = 0u;

    nearSecSum = GetRouteBlocNearSecConditionSum(routeId); /*获取进路接近区段数目*/
    pRouteNearSecData = GetRouteBlocNearPhySectionStru(routeId); /*获取进路接近区段数据*/

    if ((nearSecSum > 0u) && (pRouteNearSecData != NULL))
    {
        if ((pRouteNearSecData[0].NearPhySecSum > 0u) && (pRouteNearSecData[0].NearPhySecIdBuf != NULL))
        {
            CleanPhySecPreMergeState(pRouteNearSecData[0].NearPhySecIdBuf[pRouteNearSecData[0].NearPhySecSum-1]);/*之前状态也设置为空闲*/
        }
    }

    routeSecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段数目*/
    pRouteSecData = GetRouteSectionData(routeId); /*获取进路物理区段数据*/

    if ((routeSecSum > 0u) && (pRouteSecData != NULL))
    {
        for (ii = 0u; ii < routeSecSum; ii++)
        {
            CleanPhySecPreMergeState(pRouteSecData[ii].PhysicalSectionId); /*之前状态设置为空闲*/
        }
    }
}
#endif



/*
* 功能描述： 检查进路物理区段未故障延时
* 参数说明： UINT16 routeId 进路号
*	返回值：1：是
*         0: 否
*/	
UINT8 CheckRoutePhySecUnfaultDelay(const UINT16 routeId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 ii= 0u;
	
	
	sectionSum = GetRoutePhysicalSectionSum(routeId); /*获得进路包含的区段数目*/
	RouteSecStru = GetRouteSectionData(routeId); /*进路区段数据*/
	
	if (0u == sectionSum)
	{
	    return CI_ERROR;
	}
	else
	{
	}
	
	for(ii = 0u; ii < sectionSum; ii++)
	{
		if (PHYSICAL_SECTION_LOCK_FAULTDELAY == GetPhySecLockState(RouteSecStru[ii].PhysicalSectionId))
		{ /*故障延时*/
		    
			return CI_ERROR;
		}
		else
		{
		}
	}
	
	return CI_SUCCESS;
}


/*
* 功能描述：进路有车驶入
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： SUCCESS：成功
*            ERROR：  失败   
*/
UINT8 CheckTrainEnterRoute(const UINT16 routeId)
{
	UINT8 routeType = 0u; /*进路类型*/
	UINT16 startSigId = 0u; /*进路始端信号机ID*/
	UINT16 outPhySecId = 0u; /*信号机外方第一区段ID*/
	UINT16 inPhySecId = 0u; /*信号机内方第一区段ID*/
	UINT16 nextPhySecId = 0u; /*信号机内方第一区段下一区段ID*/
	UINT8 signalType = 0u;	/*信号机点灯电路类型*/
	UINT8 signalCrossCloseType = 0u; /*信号机调车跨压关灯类型*/
	
	startSigId = GetRouteStartSignalId(routeId);  /*获取进路起始信号机ID*/
	signalType = GetSignalType(startSigId);	/*获取信号机点灯逻辑类型*/
	signalCrossCloseType = GetSignalCrossCloseAttr(startSigId);	/*获取信号机调车跨压关灯类型*/
	if (0u == startSigId)
	{ /*始端信号机数据错误*/
	
	    return CI_ERROR;
	}

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

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

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

					return CI_SUCCESS; /*列车驶入*/
				}
			}
		
        }
		else
		{ /*内方之前及当前均空闲*/
			
			return CI_ERROR;
		}
	}
	else
	{ /*进路类型错误*/
	    
		return CI_ERROR;
	}

	return CI_ERROR;
}


/*
* 功能描述： 设置进路停止检查标志管理
* 参数说明： const UINT16 routeId, 进路ID
*            UINT8 setState, 设置状态
* 返回值  ： 无  
*/
void SetRouteStopFlagManage(const UINT16 routeId, UINT8 setState)
{
	UINT8 ii = 0u;				
	UINT8 phySecSum = 0u;  /*物理区段总数*/
	RoutePhysicalSectionStruct* pPhySecDataStru = NULL;  /*物理区段结构指针*/
	UINT8 ljkTag = 0U; /*指定物理区段的列检库标志*/
	UINT8 pyhSecCurState = 0U; /*指定物理区段的当前采集状态*/
	phySecSum = GetRoutePhysicalSectionSum(routeId);  /*获取进路物理区段总数*/
	pPhySecDataStru = GetRouteSectionData(routeId);  /*获取进路物理区段数据*/

    if ((0u == routeId) || (ROUTE_SUM_MAX <= routeId))
    {
		; /*不处理*/
	}
	else if (ROUTE_STOPCHECK_SET_YES == setState)
    {
        /*设置进路停止检查标志 */
        (void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_YES);
        /*办理的进路不包含库线区段，则停止检查仍有效*/
		for(ii = 0u; ii < phySecSum; ii ++)
		{
			/*进路所包含的列检库区段设置*/
			ljkTag = GetPhySecLjkFlag(pPhySecDataStru[ii].PhysicalSectionId);
			if (PHYSICAL_SECTION_LJK_YES == ljkTag)
			{
				/*当办理不是列检库的进路则停止股道标志还需设置*/
				/*清除停止检查标志*/
				CancelStopCheckFlag();
				pyhSecCurState = GetPhySecCurOccupyState(pPhySecDataStru[ii].PhysicalSectionId);
				if(SECTION_OCCUPY_YES == pyhSecCurState)
				{
					SetPhySectionStopCheckFlag(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_STOPCHECK_SET_YES);

				}
			}
		}

    }
    else if (setState == ROUTE_STOPCHECK_SET_NO)
    {
        /*清除进路停止检查标志 */
		(void)SetRouteStopCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO);
		(void)SetRouteStopKeepCheckFlag(routeId, ROUTE_STOPCHECK_SET_NO);

		for(ii = 0u; ii < phySecSum; ii ++)
		{
			/*进路所包含的列检库区段设置*/
			ljkTag = GetPhySecLjkFlag(pPhySecDataStru[ii].PhysicalSectionId);
			if (PHYSICAL_SECTION_LJK_YES == ljkTag)
			{
				SetPhySectionStopCheckFlag(pPhySecDataStru[ii].PhysicalSectionId, PHYSICAL_STOPCHECK_SET_NO);

			}

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


/*
* 功能描述： 设置道岔封锁状态处理
* 参数说明： UINT16 switchId 道岔号
*	返回值：1：有
*         0: 无
*/
void SetSwitchFengSuoStateDeal(const UINT16 switchId, const UINT8 flockState)
{
	if ((flockState != SWITCH_LOCK_FENGSUO_YES) &&
	    (flockState != SWITCH_LOCK_FENGSUO_NO))
	{
	    return;
	}
	
	SetSwitchFLockState(switchId, flockState); /*设置道岔封锁状态*/
	
	if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
	{ /*双动道岔*/
	
	    SetSwitchFLockState(GetDSwitchOtherId(switchId), flockState); /*设置道岔封锁状态*/
	}
}


/*
* 功能描述： 设置道岔单锁状态处理
* 参数说明： UINT16 switchId 道岔号
*	返回值：1：有
*         0: 无
*/
void SetSwitchDanSuoStateDeal(const UINT16 switchId, const UINT8 lockCommand)
{
	if ((lockCommand != SWITCH_LOCK_DANSUO_SET) && (lockCommand != SWITCH_LOCK_DANSUO_CANCEL))
	{
	    return;
	}

	SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO,0u,switchId, lockCommand); /*设置道岔单锁状态*/
	
	if (SWITCH_TYPE_DOUBLE == GetSwitchType(switchId))
	{ /*双动道岔*/
	
	    SetSwitchLockStatus(SWITCH_PLOCKTYPE_DANSUO,0u,GetDSwitchOtherId(switchId), lockCommand); /*设置道岔单锁状态*/
	}
}


/*
* 功能描述： 区段故障解锁延时解锁处理
* 参数说明： UINT16 phySecId 物理区段ID
*	返回值：1：有
*         0: 无
*/
UINT8 CheckPhySecFaultTrainUnEnterR(const UINT16 belongRouteId)
{
    UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 phySecOccupyIndex = 0xFFu; /*物理区段占用下标*/
	UINT8 ii= 0u;
	
	
	sectionSum = GetRoutePhysicalSectionSum(belongRouteId); /*获得进路包含的区段数目*/
	RouteSecStru = GetRouteSectionData(belongRouteId); /*进路区段数据*/
	
	if (0u == sectionSum) 
	{
	    return CI_ERROR;
	}
	else
	{
	}

	for (ii = 0u; ii < sectionSum; ii++)
	{  
		if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(RouteSecStru[ii].PhysicalSectionId))
		{ /*区段占用*/
		
		    phySecOccupyIndex = ii;
			break;
		}
		else
		{
		}
	}
	
	 /*所有区段未占用*/
	if (0xFFu == phySecOccupyIndex)
	{
		return CI_SUCCESS;
	}
	else
	{
	}


	if (0u<phySecOccupyIndex)
	{
		for (ii = 0u; ii < phySecOccupyIndex; ii++)
		{
			if (GetPhySecPreMergeState(RouteSecStru[ii].PhysicalSectionId) != SECTION_OCCUPY_YES)
			{ /*非连续占用*/
				
				return CI_SUCCESS;
			}
			else
			{
			}
		}

		return CI_ERROR;
	}
	else
	{ /*内方第一区段当前占用*/

		return CI_ERROR;
	}
}


/*
* 功能描述： 区段故障解锁不延时处理
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SWITCH_FLOCK
*/
UINT8 SectionFaultUnlockUndelayP(const UINT16 phySectionId)
{
    UINT8 phySecLockState = 0u; /*物理区段状态*/
	UINT16 lockBelongRouteId = 0u; /*锁闭所属进路ID*/
	UINT8 routeState = 0u; /*进路状态*/
	
	
	phySecLockState = GetPhySecLockState(phySectionId); /*获取物理区段锁闭状态*/
	lockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId); /*获取锁闭所属进路ID*/

	
	if (PHYSICAL_SECTION_LOCK_NORMAL == phySecLockState)
    { /*区段正常锁闭*/
	
		routeState = GetRouteState(lockBelongRouteId); /*获取进路状态*/
		
		/*判断车列是否已驶出进路处理*/
		if ((ROUTE_STATE_NEAR_LOCK == routeState) ||
		    (ROUTE_STATE_AUTO_UNLOCK == routeState) ||
			(ROUTE_STATE_AUTO_UNLOCKERR == routeState))
		{ /*接近锁闭正常||自动解锁||自动解锁异常*/
		    
			if (CI_SUCCESS == CheckPhySecFaultTrainCrossRoute(lockBelongRouteId))
			{ /*区段故障车列已驶出进路*/
			
				return CI_SUCCESS;
			}
            else
            {
                /*添加区故解故障反馈*/
                SetCiSendCmdBackInfoData(CI_BACK_PSEC_QGJ_YINMIAN, CI_DEVICE_TYPE_PHYSEC, phySectionId, 0u, 0u);
            }
		}
		
		/*判断车列是否未接近进路处理*/
		if ((ROUTE_STATE_FIRST_LOCKERR == routeState) ||
		    (ROUTE_STATE_YUXIAN_LOCK == routeState))
		{ /*初锁异常||预先锁闭*/

			return CI_SUCCESS;
		}
	}
	else if (PHYSICAL_SECTION_LOCK_EXCEPT == phySecLockState)
	{ /*区段异常锁闭*/
	
		return CI_SUCCESS;
	}
	else
	{
		/*无操作*/
	}
	
	
	return CI_ERROR;
}


/*
* 功能描述： 区段故障解锁延时处理
* 参数说明： UINT16 const switchId
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_SET_SWITCH_FLOCK
*/
UINT8 SectionFaultUnlockDelayP(const UINT16 phySectionId)
{
    UINT8 phySecLockState = 0u; /*物理区段状态*/
	UINT16 lockBelongRouteId = 0u; /*锁闭所属进路ID*/
	
	
	phySecLockState = GetPhySecLockState(phySectionId); /*获取物理区段锁闭状态*/
	lockBelongRouteId = GetPhySecRLockBelongRouteId(phySectionId); /*获取锁闭所属进路ID*/

	
	if (PHYSICAL_SECTION_LOCK_NORMAL == phySecLockState)
    { /*区段正常锁闭*/

		if (ROUTE_STATE_NEAR_LOCKERR == GetRouteState(lockBelongRouteId))
		{ /*接近锁闭异常*/
		    
			if (CI_SUCCESS == CheckPhySecFaultTrainUnEnterR(lockBelongRouteId))
			{ /*区段延时解锁判断成功*/
				
				return CI_SUCCESS;
			}
		}
	}
	else
	{
	}
	
	return CI_ERROR;
}


/*
* 功能描述： 调车折返解锁逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void DTrainReturnUnlockP(void)
{
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT8 localCiId = 0u;         /*本地联锁ID*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 belongCiId = 0u;        /*进路所属联锁ID*/
	UINT16 ii = 0u;               /*循环索引*/
	
	
	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	localCiId = GetSystemParaLocalCiId();       /*获取本机联锁ID*/
	
	/*处理调车中途折返*/
    for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = 0u; /*进路ID*/
		routeId = GetRouteId(ii); /*获取进路ID*/
		belongCiId = GetRouteBelongCiId(routeId); /*获取进路所属联锁ID*/
		
		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
		    continue;
		}
		
		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			continue;
		}

		/*调车中途折返进路完整锁闭处理*/
        DTrainReturnUnlockRouteAllLockP(routeId);
	}

	/*处理调车中途折返*/
    for (ii = 0u; ii < routeCurSum; ii++)
	{
		routeId = 0u; /*进路ID*/
		routeId = GetRouteId(ii); /*获取进路ID*/
		belongCiId = GetRouteBelongCiId(routeId); /*获取进路所属联锁ID*/
		
		if ((0u == routeId) || (routeId >= ROUTE_SUM_MAX))
		{
		    continue;
		}
		
		if ((belongCiId != localCiId) || (0u == localCiId))
		{
			continue;
		}

		/*调车中途折返进路部分锁闭处理*/
        DTrainRtnUnlockRoutePartLockP(routeId);
	}
}


/*
* 功能描述： 获取折返信号机ID
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ： 折返信号机ID
*/
UINT16 GetReturnId(const UINT16	routeId)
{
	UINT8 routeState = 0u; /*进路状态*/
	UINT16 returnSigId = 0u; /*折返信号机ID*/
	UINT16 starSigRouteSum = 0u;    /*以相同信号机为始端的进路数目*/
	UINT16* starSigRouteBuf = NULL;  /*以相同信号机为始端的进路ID数组*/
	UINT8 preRouteState = 0u;	/* 之前进路状态 */
	UINT16 ii = 0u;
	UINT8 toGo = CI_SUCCESS;
	routeState = GetRouteState(routeId); /*获取进路状态*/
	preRouteState = GetRoutePreState(routeId);/*获取进路前一状态*/

	if ((routeState != ROUTE_STATE_NEAR_LOCK) &&
		(routeState != ROUTE_STATE_NEAR_LOCKERR))
	{
		toGo = CI_ERROR;
	}

	if ((CI_ERROR == RouteAllLockSecNoOccupyCheck(routeId)) && (CI_SUCCESS == toGo))
	{ /*进路区段不是都空闲*/

		toGo = CI_ERROR;
	}

	if (CI_SUCCESS == toGo)
	{
		if (ROUTE_STATE_NEAR_LOCK == routeState)
		{
			returnSigId = GetRouteBingZhiSignalId(routeId); /*获取并置信号机ID*/
			if (0u != returnSigId)
			{
				starSigRouteSum = GetStartSignalRouteSum(returnSigId);
				starSigRouteBuf = GetStartSignalRouteBuf(returnSigId);

				if ((starSigRouteSum != 0u) &&(NULL != starSigRouteBuf))
				{
					/*获取所有满足道岔条件的进路ID*/
					for (ii = 0u; ii < starSigRouteSum; ii++)
					{
						/*B库改为两条进路，当8编组车占压两条进路时，此时BG2进路解锁需要检查以差值信号机为始端的进路的状态*/
						if ((ROUTE_STATE_IDLE == GetRouteState(starSigRouteBuf[ii])) &&(CI_SUCCESS == CheckRoutePhysicalType(starSigRouteBuf[ii])) &&
							(SIGNAL_VIRTUAL_YES == GetSignalVirtualAttr(returnSigId)))
						{    
							/*以并置信号机为始端的进路均为空闲且进路包含的区段均为列检库区段，且并置信号机为虚拟信号机,
							该种算法目前只限制在库线中中途折返场景*/
						}
						else
						{
							break;
						}
					}
					if (ii == starSigRouteSum)
					{  /*以折返信号机为始端的进路均为空闲*/

						returnSigId = GetRouteChaZhiSignalId(routeId); /*获取差置信号机ID*/
					}
				}
			}


		}
		else
		{
			/*当前状态是接近锁闭异常*/

			/* 如果是差至，如果列车驶入过进路，同时之前状态必须为接近锁闭开放
			* 否则不认为是同一列车跨入中途折返处理
			*/
			if((ROUTE_STATE_NEAR_OPEN == preRouteState) && (TRAIN_ENTER_ROUTE_FLAG_YES == GetTrainEnterRouteFlag(routeId)))
			{
				returnSigId = GetRouteChaZhiSignalId(routeId); /*获取差置信号机ID*/
			}
			else
			{
				returnSigId = 0U;
			}
		}
	}
	return returnSigId;
}


/*
* 功能描述： 调车折返解锁进路完整锁闭逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void DTrainReturnUnlockRouteAllLockP(const UINT16 routeId)
{
	UINT8 routeState = 0U; /*进路状态*/
	UINT16 returnSigId = 0U; /*折返信号机ID*/
	UINT16 innerSecId = 0U; /*信号机内方区段ID*/
	UINT16 lockBelongRouteId = 0U; /*锁闭所属进路ID*/
	UINT8 routeType = 0U;
	UINT16 starSigRouteSum = 0U;    /*以相同信号机为始端的进路数目*/
	UINT16* starSigRouteBuf = NULL;  /*以相同信号机为始端的进路ID数组*/
	UINT16 ii = 0U;
	UINT16 tmp = 0U;
	UINT16 endSigId = 0U;
	UINT16 endRouteSum =0U;
	UINT16*	endRouteBuf = NULL;
	UINT16 wLockRouteStartSigId = 0U;/*锁闭所属进路始端信号机ID*/
	UINT8 chKeepFlag = CI_ERROR;/*程序继续执行标志*/
	UINT8 chLockBelRouteState = 0U; /*区段锁闭所属进路进路状态*/
	UINT8 chLockBelRouteType = 0U;/*区段锁闭所属进路进路类型*/
	UINT8 chTrainEnterRouteFlag = 0U;/*列车驶入进路标志*/
	UINT8 chRouteInOutSecOccupy = 0U;/*进路内外方同时占压标志*/
	UINT32 dwRoutLockCycNum = 0U;
	UINT32 dwReturnRoutLockCycNum = 0U;

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

	if ((ROUTE_STATE_NEAR_LOCK != routeState) &&
		(ROUTE_STATE_NEAR_LOCKERR != routeState))
	{
		chKeepFlag = CI_ERROR;
	}
	else
	{
		chKeepFlag = CI_SUCCESS;
	}

	if(CI_SUCCESS == chKeepFlag)
	{
		chKeepFlag = RouteAllLockSecNoOccupyCheck(routeId);
		if (CI_SUCCESS == chKeepFlag)
		{
			/*进路区段都空闲*/
			returnSigId = GetReturnId(routeId);
			if (0U != returnSigId)
			{
				/*折返信号机有效*/
				endSigId = GetRouteEndSignalId(routeId);
				endRouteSum = GetStartSignalRouteSum(endSigId);
				endRouteBuf = GetStartSignalRouteBuf(endSigId);
				for (ii = 0U; ii < endRouteSum; ii++)
				{
					DTrainRtnUnlockRemoteRAllLockP(endRouteBuf[ii]);
				}
				innerSecId = GetSignalInFirstPhySecId(returnSigId, routeId); /*获取信号机内方第一区段ID*/
				lockBelongRouteId = GetPhySecRLockBelongRouteId(innerSecId); /*区段锁闭所属进路ID*/
				chLockBelRouteType = GetRouteType(lockBelongRouteId);
				chLockBelRouteState = GetRouteState(lockBelongRouteId);
				if (0U != lockBelongRouteId)
				{
					/*锁闭所属进路有效*/
					wLockRouteStartSigId = GetRouteStartSignalId(lockBelongRouteId);/*获取进路始端信号机ID*/
					chTrainEnterRouteFlag = CheckTrainEnterRoute(lockBelongRouteId);/*获取列车驶入进路标志*/
					chRouteInOutSecOccupy = RouteInOutSecOccupy(lockBelongRouteId);/*进路内外方同时占用标志*/
					dwRoutLockCycNum = GetRouteLockStartCycNum(routeId); /*获取进路锁闭起始周期*/
					dwReturnRoutLockCycNum = GetRouteLockStartCycNum(lockBelongRouteId);/*获取折出进路锁闭起始周期*/

					if ((ROUTE_STATE_NEAR_OPEN == chLockBelRouteState) && (ROUTE_TYPE_DIAOCHE == chLockBelRouteType) &&
						(returnSigId == wLockRouteStartSigId) && (dwReturnRoutLockCycNum > dwRoutLockCycNum) &&
						((CI_SUCCESS == chTrainEnterRouteFlag) ||
							((CI_SUCCESS == chRouteInOutSecOccupy) && (ROUTE_TYPE_LIECHE == routeType))))
					{
						/*折出进路是调车进路&&状态是接近开放&&折出进路始端信号机是本进路折返信号机 &&（有车驶入 或 待解锁进路为列车进路是折出进路时内外方区段同时占压）*/
						/*by cgh 20250414增加条件：折出进路锁闭时间晚于需中途解锁进路*/
						/*解锁成功*/
						SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/

						/*设置进路逻辑区段: 未锁闭*/
						SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);

						SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
					}
					if ((ROUTE_TYPE_LIECHE == chLockBelRouteType) && (ROUTE_STATE_NEAR_LOCK == chLockBelRouteState)
						&& (returnSigId == wLockRouteStartSigId) && (dwReturnRoutLockCycNum > dwRoutLockCycNum))
					{
						/*折出进路是列车进路 且 进路状态是接近锁闭正常 且 折出进路始端信号机是本进路折返信号机*/
						/*by cgh 20250414增加条件：折出进路锁闭时间晚于需中途解锁进路*/
						/*解锁成功*/
						SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
						/*设置进路逻辑区段: 未锁闭*/
						SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
						SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
					}
				}
			}
		}
	}
}

/*
* 功能描述： 调车折返解锁远端进路完整锁闭逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void DTrainRtnUnlockRemoteRAllLockP(const UINT16 routeId)
{
	UINT8 routeState = 0U; /*进路状态*/
	UINT16 returnSigId = 0U; /*折返信号机ID*/
	UINT16 innerSecId = 0U; /*信号机内方区段ID*/
	UINT16 lockBelongRouteId = 0U; /*锁闭所属进路ID*/
	UINT8 routeType = 0U;
	UINT16 starSigRouteSum = 0U;    /*以相同信号机为始端的进路数目*/
	UINT16* starSigRouteBuf = NULL;  /*以相同信号机为始端的进路ID数组*/
	UINT16 ii = 0U;
	UINT16 tmp = 0U;
	UINT16 endSigId = 0U;
	UINT16 endRouteSum =0U;
	UINT16*	endRouteBuf = NULL;
	UINT8 retVal = CI_ERROR;/*程序继续执行标志*/
	UINT16 wLockRouteStartSigId = 0U;/*锁闭所属进路始端信号机ID*/
	UINT8 chLockBelRouteState = 0U; /*区段锁闭所属进路进路状态*/
	UINT8 chLockBelRouteType = 0U;/*区段锁闭所属进路进路类型*/
	UINT8 chTrainEnterRouteFlag = 0U;/*列车驶入进路标志*/
	UINT8 chRouteInOutSecOccupy = 0U;/*进路内外方同时占压标志*/
	UINT32 dwRoutLockCycNum = 0U;
	UINT32 dwReturnRoutLockCycNum = 0U;

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

	if ((routeState != ROUTE_STATE_NEAR_LOCK) &&
		(routeState != ROUTE_STATE_NEAR_LOCKERR))
	{
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == retVal)
	{
		/*进路区段都空闲*/
		retVal = RouteAllLockSecNoOccupyCheck(routeId);
	}

	if (CI_SUCCESS == retVal)
	{
		returnSigId = GetReturnId(routeId);

		if (0u == returnSigId)
		{ /*折返信号机无效*/
			retVal = CI_ERROR;
		}
	}
	
	if (CI_SUCCESS == retVal)
	{
		innerSecId = GetSignalInFirstPhySecId(returnSigId, routeId); /*获取信号机内方第一区段ID*/
		lockBelongRouteId = GetPhySecRLockBelongRouteId(innerSecId); /*区段锁闭所属进路ID*/
		if (0u == lockBelongRouteId)
		{ /*锁闭所属进路无效*/
			retVal = CI_ERROR;
		}
	}

	if (CI_SUCCESS == retVal)
	{
		chLockBelRouteType = GetRouteType(lockBelongRouteId);
		chLockBelRouteState = GetRouteState(lockBelongRouteId);
		wLockRouteStartSigId = GetRouteStartSignalId(lockBelongRouteId);/*获取进路始端信号机ID*/
		chTrainEnterRouteFlag = CheckTrainEnterRoute(lockBelongRouteId);/*获取列车驶入进路标志*/
		chRouteInOutSecOccupy = RouteInOutSecOccupy(lockBelongRouteId);/*进路内外方同时占用标志*/
		dwRoutLockCycNum = GetRouteLockStartCycNum(routeId); /*获取进路锁闭起始周期*/
		dwReturnRoutLockCycNum = GetRouteLockStartCycNum(lockBelongRouteId);/*获取折出进路锁闭起始周期*/

		if ((ROUTE_STATE_NEAR_OPEN == chLockBelRouteState) && (ROUTE_TYPE_DIAOCHE == chLockBelRouteType) &&
			(returnSigId == wLockRouteStartSigId) && (dwReturnRoutLockCycNum > dwRoutLockCycNum) &&
			((CI_SUCCESS == chTrainEnterRouteFlag) ||
			((CI_SUCCESS == chRouteInOutSecOccupy) && (ROUTE_TYPE_LIECHE== routeType))))
		{ 
			/*折出进路是调车进路&&状态是接近开放&&折出进路始端信号机是本进路折返信号机 &&（有车驶入 或 待解锁进路为列车进路是折出进路时内外方区段同时占压）*/
			/*by cgh 20250414增加条件：折出进路锁闭时间晚于需中途解锁进路*/
			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}
		if ((ROUTE_TYPE_LIECHE== chLockBelRouteType) && (ROUTE_STATE_NEAR_LOCK == chLockBelRouteState)
			&& (returnSigId == wLockRouteStartSigId) && (dwReturnRoutLockCycNum > dwRoutLockCycNum))
		{
			/*折出进路是列车进路 且 进路状态是接近锁闭正常 且 折出进路始端信号机是本进路折返信号机*/
			/*by cgh 20250414增加条件：折出进路锁闭时间晚于需中途解锁进路*/
			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}
	}
}


/*
* 功能描述： 调车折返解锁进路部分锁闭逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
void DTrainRtnUnlockRoutePartLockP(const UINT16 routeId)
{
	UINT8 routeState = 0U; /*进路状态*/
	UINT16 returnSigId = 0U; /*折返信号机ID*/
	UINT16 innerSecId = 0U; /*信号机内方区段ID*/
	UINT16 lockBelongRouteId = 0U; /*锁闭所属进路ID*/
	UINT8 routeType = 0U;
	UINT8 chKeepFlag = CI_ERROR;/*程序继续执行标志*/
	UINT8 chLockBelRouteState = 0U; /*区段锁闭所属进路进路状态*/
	UINT8 chTrainEnterRouteFlag = 0U;/*列车驶入进路标志*/
	UINT16 wLockRouteStartSigId = 0U;/*锁闭所属进路始端信号机ID*/
	UINT16 wOutSecId = 0U; /*折返信号机外方区段*/
	UINT8 chOutSecType = 0U;
	UINT8 chSecOccupyState = 0U; /*折出进路外方区段占压状态*/
	UINT8 chSecLockState = 0U;/*外方区段锁闭状态*/

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

    if (routeState != ROUTE_STATE_AUTO_UNLOCK)
	{
		chKeepFlag = CI_ERROR;
	}
	else
	{
		chKeepFlag = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		chKeepFlag = RouteAllLockSecNoOccupyCheck(routeId);
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		returnSigId = GetRouteMidwayReturnSignalId(routeId); /*获取中途折返信号机ID*/
		if (0u == returnSigId)
		{ /*折返信号机无效*/		
			chKeepFlag = CI_ERROR;
			ZHGDTrainRtnUnlockRouteProc(routeId); /*需配置特殊转换轨中途折返信号机*/
			
		}
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		innerSecId = GetSignalInFirstPhySecId(returnSigId, routeId); /*获取信号机内方第一区段ID*/
		lockBelongRouteId = GetPhySecRLockBelongRouteId(innerSecId); /*区段锁闭所属进路ID*/
		if (0u == lockBelongRouteId)
		{ /*锁闭所属进路无效*/
			chKeepFlag = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		routeType = GetRouteType(lockBelongRouteId);
		chLockBelRouteState = GetRouteState(lockBelongRouteId);
		chTrainEnterRouteFlag = CheckTrainEnterRoute(lockBelongRouteId);/*获取列车驶入进路标志*/
		wLockRouteStartSigId = GetRouteStartSignalId(lockBelongRouteId);/*获取进路始端信号机ID*/

		if ((ROUTE_TYPE_DIAOCHE == routeType) && (ROUTE_STATE_NEAR_OPEN == chLockBelRouteState) &&
			(CI_SUCCESS == chTrainEnterRouteFlag) && (returnSigId == wLockRouteStartSigId))
		{ 
			/*折出进路是调车进路，进路状态是接近开放且有车驶入且折出进路始端信号机是本进路折返信号机*/
			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}

		if ((ROUTE_TYPE_LIECHE == routeType) && (ROUTE_STATE_NEAR_LOCK == chLockBelRouteState) 
			&& (returnSigId == wLockRouteStartSigId))
		{
			/*折出进路是列车进路，进路状态是接近锁闭且折出进路始端信号机是本进路折返信号机*/

			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}
	}
}


/*
* 功能描述： 获取进路并置信号机ID
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
UINT16 GetRouteBingZhiSignalId(const UINT16 routeId)
{
	UINT16 startSigId = 0u; /*始端信号机ID*/
	UINT16 signalSum = 0u; /*信号机总数*/
	UINT16 signalId = 0u; /*信号机ID*/
	UINT16 ii = 0u;

    startSigId = GetRouteStartSignalId(routeId); /*获取进路始端信号机ID*/
	signalSum = GetSignalCurSum(); /*获取信号机总数*/

	for (ii = 0u; ii < signalSum; ii++)
	{
		signalId = GetSignalId(ii); /*获取信号机ID*/

		if ((GetSignalInFirstPhySecId(startSigId, routeId) == GetSignalOutFirstPhySecId(signalId)) &&
            (GetSignalOutFirstPhySecId(startSigId) == GetSignalInFirstPhySecId(signalId, routeId)))
		{
			return signalId;
		}
	}

	return 0u;
}


/*
* 功能描述： 获取进路差置信号机ID
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
UINT16 GetRouteChaZhiSignalId(const UINT16 routeId)
{
	UINT16 startSigId = 0u; /*始端信号机ID*/
	UINT16 signalSum = 0u; /*信号机总数*/
	UINT16 signalId = 0u; /*信号机ID*/
	UINT16 routeSecSum = 0u; /*进路区段总数*/
	RoutePhysicalSectionStruct *pRoutePhySecStru = NULL; /*进路区段数据*/
	UINT16 returnOutSecId = 0u; /*折返信号机外方区段ID*/
	UINT16 returnInSecId = 0u; /*折返信号机内方区段ID*/
    UINT16 lockBelongRouteId = 0u; /*锁闭所属进路ID*/
    UINT16 outSecId = 0u; /*外方区段ID*/
	UINT16 ii = 0u;
	UINT16 tmpSigId = 0u;


    startSigId = GetRouteStartSignalId(routeId); /*获取进路始端信号机ID*/
	signalSum = GetSignalCurSum(); /*获取信号机总数*/

	if (PHYSICAL_SEC_TYPE_NOSWITCH == GetPhySecType(GetSignalOutFirstPhySecId(startSigId)))
	{ /*无岔区段*/

		for (ii = 0u; ii < signalSum; ii++)
		{
			signalId = GetSignalId(ii); /*获取信号机ID*/

			if ((GetSignalOutFirstPhySecId(startSigId) == GetSignalOutFirstPhySecId(signalId)) &&
				(startSigId != signalId))
			{
				return signalId;
			}
		}
	}
	else
	{ /*有岔*/

		outSecId = GetSignalOutFirstPhySecId(startSigId); /*进路始端信号机外方区段ID*/
		lockBelongRouteId = GetPhySecRLockBelongRouteId(outSecId); /*区段锁闭所属进路ID*/
		
		routeSecSum = GetRoutePhysicalSectionSum(lockBelongRouteId); /*获取进路区段总数*/
		pRoutePhySecStru = GetRouteSectionData(lockBelongRouteId); /*获取进路区段数据*/
		
		if ((0u == routeSecSum) || (NULL == pRoutePhySecStru))
		{
			return 0u;
		}
		if (routeSecSum == 1u)
		{
			/*if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(pRoutePhySecStru[0].PhysicalSectionId)) &&
				(lockBelongRouteId == GetPhySecRLockBelongRouteId(pRoutePhySecStru[0].PhysicalSectionId)))*/
			{
				returnOutSecId = pRoutePhySecStru[0].PhysicalSectionId;/*折返信号机外方区段ID*/

				tmpSigId = GetRouteStartSignalId(lockBelongRouteId);/*折返信号机内方区段ID*/
				
				returnInSecId = GetSignalOutFirstPhySecId(tmpSigId);
			}
		}
		else if (routeSecSum > 1u)
		{
			for (ii = 0u; ii < routeSecSum; ii++)
			{

				if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(pRoutePhySecStru[ii].PhysicalSectionId)) &&
					(lockBelongRouteId == GetPhySecRLockBelongRouteId(pRoutePhySecStru[ii].PhysicalSectionId)))
				{ /*本进路第一个锁闭的区段*/
				
					returnOutSecId = pRoutePhySecStru[ii].PhysicalSectionId; /*折返信号机外方区段ID*/

					if (ii > 0u)
					{
						returnInSecId = pRoutePhySecStru[ii-1U].PhysicalSectionId; /*折返信号机内方区段ID*/
					}

					break;
				}
			}
		}
		else
		{
			/*无操作*/
		}
		if ((0u == returnOutSecId) || (0u == returnInSecId))
		{
			return 0u;
		}

		for (ii = 0u; ii < signalSum; ii++)
		{
			signalId = GetSignalId(ii); /*获取信号机ID*/

			if ((returnOutSecId == GetSignalOutFirstPhySecId(signalId)) &&
				(returnInSecId == GetSignalInFirstPhySecId(signalId, routeId)))
			{
				return signalId;
			}
		}
	}

	return 0u;
}


/*
* 功能描述： 获取进路中途折返信号机ID
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：    
*/
UINT16 GetRouteMidwayReturnSignalId(const UINT16 routeId)
{
	UINT16 signalSum = 0u; /*信号机总数*/
	UINT16 signalId = 0u; /*信号机ID*/
	UINT16 routeSecSum = 0u; /*进路区段总数*/
	RoutePhysicalSectionStruct *pRoutePhySecStru = NULL; /*进路区段数据*/
	UINT16 ii = 0u;
    UINT16 jj = 0u;
	UINT16 returnOutSecId = 0u; /*折返信号机外方区段ID*/
	UINT16 returnInSecId = 0u; /*折返信号机内方区段ID*/

	signalSum = GetSignalCurSum(); /*获取信号机总数*/
	routeSecSum = GetRoutePhysicalSectionSum(routeId); /*获取进路区段总数*/
	pRoutePhySecStru = GetRouteSectionData(routeId); /*获取进路区段数据*/
	
	if (0u == routeSecSum) 
	{
		return 0u;
	}
	else
	{
	}

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

		if ((PHYSICAL_SECTION_LOCK_NORMAL == GetPhySecLockState(pRoutePhySecStru[ii].PhysicalSectionId)) &&
			(routeId == GetPhySecRLockBelongRouteId(pRoutePhySecStru[ii].PhysicalSectionId)))
		{ /*本进路第一个锁闭的区段*/
			
            for (jj = 0u; jj < signalSum; jj++)
			{
				signalId = GetSignalId(jj); /*获取信号机ID*/
				returnOutSecId = pRoutePhySecStru[ii].PhysicalSectionId;/*折返信号机外方区段*/
				if (ii > 0u)
				{
					returnInSecId = pRoutePhySecStru[ii-1U].PhysicalSectionId;/*折返信号机内方区段*/
					if ((returnOutSecId == GetSignalOutFirstPhySecId(signalId))
						&& (returnInSecId == GetSignalInFirstPhySecId(signalId, routeId)))
					{
						return signalId;
					}
					else
					{
					}
				}
				else
				{
				}
			}

			break;
		}
		else
		{
		}
	}

	return 0u;
}


/*
* 功能描述： 进路区段全部空闲检查
* 参数说明： UINT16 routeId,    进路号
* 返回值  ： CI_ERROR   
*            CI_SUCCESS 
*/
UINT8 RouteAllLockSecNoOccupyCheck(UINT16 const routeId)
{
    UINT8 const checkSum = GetRoutePhysicalSectionSum(routeId);
    RoutePhysicalSectionStruct* const dataIdBuf = GetRouteSectionData(routeId);
    
	UINT16 i = 0u; /* 循环变量 */

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

    for (i = 0u; i < checkSum; i++)
    {
        if (routeId == GetPhySecRLockBelongRouteId(dataIdBuf[i].PhysicalSectionId))
		{ /*属于本进路锁闭的区段*/

			if (SECTION_OCCUPY_YES == GetPhySecCurMergeState(dataIdBuf[i].PhysicalSectionId))
			{
				return CI_ERROR;
			}
			else
			{
			}
		}
		else
		{
		}
    }
    
    return CI_SUCCESS;
}


/*
* 功能描述： 车库门开门逻辑管理
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： void   
*/
void SetGarageDoorOpenLogicM(const UINT16 garageDoorId)
{/*驱动车库门开门*/

	(void)SetGrgdoorCmdProcessState(garageDoorId,GARAGE_DOOR_CMD_OPEN);
}

/*
* 功能描述： 车库门关门逻辑管理
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： void   
*/
void SetGarageDoorCloseLogicM(const UINT16 garageDoorId)
{/*驱动车库门关门*/

	(void)SetGrgdoorCmdProcessState(garageDoorId,GARAGE_DOOR_CMD_CLOSE);
}




/*
* 功能描述： 车库门逻辑处理
* 参数说明： 无
* 返回值  ： 无
*/
void GargeDoorLogicProcess(void)
{
	UINT16 grgDoorSum = GetGaragedoorSum();
	UINT8 ii = 0u;
	UINT8 cmd = 0u;
    UINT8 ret = 0u;
    UINT16 grgdoorId = 0u;
    UINT8 doorDrvState = 0u;               /*车库门当前驱动状态*/
    UINT8 doorCurMode = 0u;                /*车库门当前控制模式*/
    UINT32 waiteZCResbackStartTime = 0u;   /*等待 ZC反馈起始时间*/
	UINT32 waiteIVOCResbackStartTime = 0u;   /*等待 IVOC反馈起始时间*/
    UINT32 curCycCount = Get2oo2CurCycleNum();   /*获取当前周期号*/
	UINT8 closeFlagZC = GARAGE_DOOR_ALLOW_CLOSE_NO;
	UINT8 closeFlagIVOC = GARAGE_DOOR_ALLOW_CLOSE_NO;
	UINT8 RcWorkMode = 0U;             /*工作模式*/
	UINT8 checkFlag = 0U;             /*RC模式车库门关门检查判断标志*/
	UINT32 waitResponseCount = 0U;    /*申请关门等待限时时间*/
	UINT16 applyCloseTrainId = UINT16_MAX;

	waitResponseCount = GetWaitZCResponseCount(); 
	RcWorkMode = GetLocalRcWorkMode();		/*RC工作模式获取*/


	for(ii = 0u; ii < grgDoorSum; ii++)
	{
		grgdoorId = GetGaragedoorId(ii);
		cmd = GetGrgdoorCmdProcessState(grgdoorId);

		if(GARAGE_DOOR_CMD_OPEN == cmd)
		{
			/* 开门命令时需要检查条件 */
            ret = DriveGarageDoorOpenCheck(grgdoorId);
			if(CI_SUCCESS == ret)
			{
				(void)SetDrvGaragedoorState(grgdoorId,GARAGE_DOOR_DRV_OPEN);
				(void)SetGaragedoorOpenStartCycNum(grgdoorId, Get2oo2CurCycleNum());    /*记录开始驱动开门周期*/
			}
			(void)SetGrgdoorCmdProcessState(grgdoorId,GARAGE_DOOR_CMD_NULL);
		}
		else if(GARAGE_DOOR_CMD_CLOSE == cmd)	/* 关门命令 */
		{
			ret = DriveGarageDoorCloseCheck(grgdoorId);        /*驱动车库门关门条件检查*/
			
			/* 驱动信号机关闭 */
			ClosSigByGrgdoorCloseCmd(grgdoorId);

			/* 关门命令时需要检查条件 */
			if(CI_SUCCESS == ret)
			{
				(void)SetDrvGaragedoorState(grgdoorId,GARAGE_DOOR_DRV_CLOSE);
				(void)SetGaragedoorCloseStartCycNum(grgdoorId, Get2oo2CurCycleNum());  /*记录开始驱动关门周期*/
				(void)SetGrgdoorCmdProcessState(grgdoorId,GARAGE_DOOR_CMD_NULL);   /*驱动关门后清除命令*/
			}
			else if(CI_ERROR == ret)
			{			
				/*不满足关门条件，直接清命令*/
				(void)SetGrgdoorCmdProcessState(grgdoorId,GARAGE_DOOR_CMD_NULL);   /*清除命令*/
			}
            else if(RETURN_GRGDOOR_CLSCHK_WAITALLOW == ret)
			{/*存在区段占用*/

				/*TIOC模式下，自行判断是否能关闭屏蔽门*/
				if (RC_WORK_MODE_TIOC == RcWorkMode)
				{
					closeFlagIVOC = GetGaragedoorAllowCloseFlagIVOC(grgdoorId);   /*获取IVOC反馈命令标志*/
					waiteIVOCResbackStartTime = GetWaiteIVOCResponseStartCycNum(grgdoorId);   /*获取指定ID车库门等待IVOC反馈开始时间*/

					/*TIOC模式下存在占用时，车库门关门条件检查*/
					checkFlag = GarageDoorCloseCheckinRCMode(grgdoorId, ESEND_LEVEL_ZERO);
					applyCloseTrainId = GetGaragedoorNearestTrainId(grgdoorId);

					if (CI_SUCCESS == checkFlag)
					{
						
						if ((curCycCount - waiteIVOCResbackStartTime) > waitResponseCount)
						{
							/*超时，清除关门命令*/
							(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);
							SetWaiteIVOCResponseStartCycNum(grgdoorId, 0u);  /*清等待IVOC反馈时间*/
							SetGaragedoorNearestTrainId(grgdoorId, NAME_FAILUREAREA); /*清最接近的列车ID*/
							SetErrorData(EFUNC_CLD_CLOSE_GARAGEDOOR, CI_DEVICE_TYPE_GARAGEDOOR, grgdoorId, ETYPE_GARDOOR_NOT_RECV_IVOC_GMXK, 0, ESEND_LEVEL_ZERO);
							SetGaragedoorAllowCloseFlagIVOC(grgdoorId, GARAGE_DOOR_ALLOW_CLOSE_NO);/*清IVOC允许标志*/
						}
						else
						{
							/* 未超时 */

							/* A库物理区段上无车占压或列车休眠，无需向IVOC发送申请 */ 
							if (0U == applyCloseTrainId)
							{
								/*驱动车库门关闭*/
								(void)SetDrvGaragedoorState(grgdoorId, GARAGE_DOOR_DRV_CLOSE);
								SetGaragedoorCloseStartCycNum(grgdoorId, Get2oo2CurCycleNum());    /*记录开始驱动关门周期*/
								(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);
								SetWaiteIVOCResponseStartCycNum(grgdoorId, 0u);  /*清等待IVOC反馈时间*/
								SetGaragedoorNearestTrainId(grgdoorId, NAME_FAILUREAREA); /*清最接近的列车ID*/
								SetGaragedoorAllowCloseFlagIVOC(grgdoorId, GARAGE_DOOR_ALLOW_CLOSE_NO);/*清IVOC允许标志*/
							}
							
							else if (GARAGE_DOOR_ALLOW_CLOSE_YES == closeFlagIVOC)
							{
								/*检查通过，驱动车库门关闭*/
								(void)SetDrvGaragedoorState(grgdoorId, GARAGE_DOOR_DRV_CLOSE);
								SetGaragedoorCloseStartCycNum(grgdoorId, Get2oo2CurCycleNum());    /*记录开始驱动关门周期*/
								(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);
								SetWaiteIVOCResponseStartCycNum(grgdoorId, 0u);  /*清等待IVOC反馈时间*/
								SetGaragedoorNearestTrainId(grgdoorId, NAME_FAILUREAREA); /*清最接近的列车ID*/
								SetGaragedoorAllowCloseFlagIVOC(grgdoorId, GARAGE_DOOR_ALLOW_CLOSE_NO);/*清IVOC允许标志*/

							}
							else
							{
								/*未超时且未收到IVOC反馈处于等待状态，下周期继续检查是否满足关门命令,不清除命令*/
							}
						}
					}
					else
					{
						/*检查条件不通过，驱动关门失败*/
						(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);  /*清除命令清除*/
						SetWaiteIVOCResponseStartCycNum(grgdoorId, 0u);  /*清等待IVOC反馈时间*/
						SetGaragedoorNearestTrainId(grgdoorId, NAME_FAILUREAREA); /*清最接近的列车ID*/
						SetGaragedoorAllowCloseFlagIVOC(grgdoorId, GARAGE_DOOR_ALLOW_CLOSE_NO);/*清IVOC允许标志*/
						
					}
				}
				/*CI模式下，等待ZC发送允许关闭信息*/
				else if (RC_WORK_MODE_CI == RcWorkMode)
				{
					closeFlagZC = GetGaragedoorAllowCloseFlag(grgdoorId);   /*获取ZC反馈命令标志*/
					waiteZCResbackStartTime = GetWaiteZCResponseStartCycNum(grgdoorId);   /*获取指定ID车库门等待ZC反馈开始时间*/
					/* 处于等待状态，下周期继续检查是否满足关门命令,不清除命令 */
					if ((curCycCount - waiteZCResbackStartTime) > waitResponseCount)
					{
						/*超时*/
						(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);
						SetWaiteZCResponseStartCycNum(grgdoorId, 0u);  /*清等待ZC反馈时间*/
						SetErrorData(EFUNC_CLD_CLOSE_GARAGEDOOR, CI_DEVICE_TYPE_GARAGEDOOR, grgdoorId, ETYPE_GARDOOR_NOT_RECV_ZC_GMXK, 0, ESEND_LEVEL_ATS);
					}
					else
					{
						/*未超时且未收到ZC反馈，继续等待；未超时收到反馈则立即关门*/
						if (GARAGE_DOOR_ALLOW_CLOSE_YES == closeFlagZC)
						{
							(void)SetDrvGaragedoorState(grgdoorId, GARAGE_DOOR_DRV_CLOSE);
							SetGaragedoorCloseStartCycNum(grgdoorId, Get2oo2CurCycleNum());    /*记录开始驱动关门周期*/
							(void)SetGrgdoorCmdProcessState(grgdoorId, GARAGE_DOOR_CMD_NULL);
							SetWaiteZCResponseStartCycNum(grgdoorId, 0u);  /*清等待ZC反馈时间*/
						}
						else
						{
							/*未超时且未收到ZC反馈处于等待状态，下周期继续检查是否满足关门命令,不清除命令*/
						}
					}
				}

				else
				{
					; /*不处理*/
				}

				
			}
			else
			{
				/*无操作*/
			}

			/* 超时判断 */
		}
		else
		{
			/*无命令*/
		}

		/* 如果当前为驱动模式 ，当门控制模式转换为本地时，停止驱动 */
		doorCurMode = GetGaragedoorModeState(grgdoorId);
		doorDrvState = GetDrvGaragedoorState(grgdoorId);
		if (GARAGE_DOOR_STATE_MODE_LOCAL == doorCurMode)
		{
			if ((GARAGE_DOOR_DRV_OPEN == doorDrvState) || (GARAGE_DOOR_DRV_CLOSE == doorDrvState))
			{
				(void)SetDrvGaragedoorState(grgdoorId, GARAGE_DOOR_DRV_NULL);
			}
		}
	}
}

#if 0
/*
* 功能描述： 驱动车库门关门时，关闭所有防护信号机
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： 无
*/
void ClosSigByGrgdoorCloseCmd(UINT16 grgdoorId)
{
	UINT16 sigNum = 0u;
	UINT16 sigIdx = 0u;
	UINT16 sigId = 0u;
	UINT16 i = 0u;

	sigNum = GetGardoorProtectSigSum(grgdoorId);
	for (i = 0u; i < sigNum;i++)
	{
		/*遍历车库门防护信号机组，驱动防护信号机关闭*/
		
		sigIdx = GetGardoorProtectSigIdByIndex(grgdoorId,i);
		sigId = GetSignalConfigBufIndex(sigIdx);
		if (GetSignalBelongCiId(sigId) == GetSystemParaLocalCiId())
		{
			/*参考试车线驱动关信号处理*/
			SetSignalCurDriveColor(sigId, SIGNAL_DRIVECOLOUR_RED);
		}
	}
}
#endif

/*
* 功能描述： 驱动车库门关门时，关闭所有防护进路的始端信号机
* 参数说明： const UINT16 garageDoorId, 车库门ID
* 返回值  ： 无
*/
void ClosSigByGrgdoorCloseCmd(UINT16 grgdoorId)
{
	UINT16 routeNum = 0u;
	UINT16* routeIdBuf = NULL;
	UINT16 routeId = 0u;
	UINT16 i = 0u;
	UINT8 routeState = 0u;

	routeNum = GetGardoorRouteSum(grgdoorId);
	routeIdBuf = GetGardoorRouteIdBuf(grgdoorId);
	if (routeNum > 0u) 
	{
		for (i = 0u; i < routeNum;i++)
		{
			/*遍历车库门防护进路始端信号机，驱动防护信号机关闭*/
			
			routeId = routeIdBuf[i];
			routeState = GetRouteState(routeId);
			if ((ROUTE_STATE_YUXIAN_OPEN == routeState) || (ROUTE_STATE_NEAR_OPEN == routeState))
			{
				/*驱动进路始端信号机关闭*/
				SetSignalCurDriveColor(GetRouteStartSignalId(routeId), SIGNAL_DRIVECOLOUR_RED);
			}
			else
			{
			}
		}
	}
	else
	{
	}

}

/*
* 功能描述：  若当前区段为调车进路非最后一个区段，相邻区段为无岔区段则带动解锁
* 参数说明： const UINT16 phySectionId, 物理区段ID
*            const UINT16 lockBelongRouteId 锁闭所属进路ID
* 返回值: CI_SUCCESS 成功
*         CI_ERROR   失败
*/
UINT8 CLDPhySectionFaultUnlockDeal(const UINT16 phySectionId,const UINT16 lockBelongRouteId)
{
	UINT8 sectionSum = 0u; /*区段总数*/
	RoutePhysicalSectionStruct *RouteSecStru = NULL; /*区段数据*/
	UINT8 phySecIndex = 0u; /*物理区段占用下标*/
	UINT16 rtNextPhySecId = 0u;
	UINT8 ii = 0u;
	UINT8 jj = 0u;
	UINT8 retVal = CI_SUCCESS;
	UINT8 chLockRouteDirection = 0U;/*物理区段锁闭所属进路方向*/
	UINT8 lockState = 0U;
	UINT8 phySecType = 0U;
	UINT8 unLockFlag = 0U;

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

	if (CI_SUCCESS == retVal)
	{
		sectionSum = GetRoutePhysicalSectionSum(lockBelongRouteId); /*获得进路包含的区段数目*/
		RouteSecStru = GetRouteSectionData(lockBelongRouteId); /*进路区段数据*/
		chLockRouteDirection = GetRouteDirection(lockBelongRouteId);
		if ((0u == sectionSum) || (1u == sectionSum) )
		{/*进路包含物理区段数目为1时不执行此操作*/
			retVal = CI_ERROR;
		}
		else
		{
		}
	}
	else
	{
	}
	
	if (CI_SUCCESS == retVal)
	{
		for (ii = 0u;ii < sectionSum;ii++)
		{
			if (phySectionId == RouteSecStru[ii].PhysicalSectionId)
			{/*找到物理区段*/
				phySecIndex = ii;
				break;
			}
		}
		if (phySecIndex < (sectionSum-1U))
		{/*当前区段不是进路内的最后一个区段*/
			for (jj = phySecIndex+1U;jj < sectionSum;jj++)
			{/*遍历进路剩余的其他区段*/
				rtNextPhySecId = RouteSecStru[jj].PhysicalSectionId;
				lockState = GetPhySecLockState(rtNextPhySecId);
				phySecType = GetPhySecType(rtNextPhySecId);
				

				if ((PHYSICAL_SECTION_LOCK_NORMAL == lockState) || (PHYSICAL_SECTION_LOCK_EXCEPT == lockState))
				{/*区段当前为正常锁闭 || 异常锁闭*/
					if ((PHYSICAL_SEC_TYPE_NOSWITCH == phySecType) && (jj == (sectionSum - 1U)))
					{/*进路下一个物理区段为无岔区段并且是进路最后一个区段则带动解锁*/
						SetPhySecLockState(rtNextPhySecId, PHYSICAL_SECTION_LOCK_NO, lockBelongRouteId, chLockRouteDirection);  /*设置物理区段未锁闭*/
						/*同时设置物理区段其他属于本进路锁闭的逻辑区段未锁闭*/
						SetPhyIncludeLogLockState(rtNextPhySecId, LOG_SECTION_LOCK_NO, lockBelongRouteId);
						unLockFlag = CheckRoutePhySecHaveUnLock(lockBelongRouteId);
						if (CI_SUCCESS == unLockFlag)
						{/*查找到的区段所属进路内全部区段未锁闭，则进路状态变为空闲*/
							SetRouteStateDeal(lockBelongRouteId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
						}
						else
						{
						}
					}
					else
					{/*有岔区段 或区段不是进路最后一个区段*/
						SetPhySecLockState(rtNextPhySecId, PHYSICAL_SECTION_LOCK_EXCEPT, lockBelongRouteId, chLockRouteDirection); /*设置区段异常锁闭*/
						SetPhyIncludeLogLockState(rtNextPhySecId, LOG_SECTION_LOCK_EXCEPT, lockBelongRouteId);

						break;
					}
				}
				else
				{
				}
			}
		}
		else
		{
		}
	}
	else
	{
	}
	
	return retVal;
}

/*
* 功能描述： 取消洗车逻辑管理
* 参数说明： void
* 返回值  ： void   
*/
void CancelWashWorkLogicM(void)
{/*取消洗车命令*/
	UINT16 washMachineId = 0u;
	washMachineId = GetWashMachineId(0u);
#if 0
	SetCancelWashMachineFlag(washMachineId,CANCEL_WASH_FLAG_SET_YES);
#endif
	if (washMachineId >0u)
	{/*收到现地取消洗车命令，直接把洗车同意按钮状逻辑态置为抬起*/
		(void)SetWashmachineXTALogicState(washMachineId,XTA_STATE_RAISE_UP);
	}
}

/*
* 功能描述： 进路调车同意逻辑管理
* 参数说明： void
* 返回值  ： void  
* by cgh 20250523
*/
void RouteDCTYLogic(UINT16 routeId)
{
	UINT8 routeType = 0U;
	UINT8 routeState = 0U;
	UINT16 routeDCQJId = 0U;
	UINT16 routeDCQJTwoId = 0U;

	routeType = GetRouteType(routeId);/*进路类型*/
	routeState = GetRouteState(routeId);/*进路状态*/
	routeDCQJId = GetRouteDCQJId(routeId);
	routeDCQJTwoId = GetRouteDCQJTwoId(routeId);

	if ((0U < routeDCQJId) && (0U < routeDCQJTwoId) && (ROUTE_TYPE_DIAOCHE == routeType))
	{/*调车请求继电器ID存在，且是调车进路*/
		if((ROUTE_STATE_FIRST_LOCK == routeState) ||
			(ROUTE_STATE_FIRST_LOCKERR == routeState) ||
			(ROUTE_STATE_YUXIAN_LOCK == routeState) ||
			(ROUTE_STATE_YUXIAN_OPEN == routeState) ||
			(ROUTE_STATE_NEAR_OPEN == routeState) ||
			(ROUTE_STATE_NEAR_LOCK == routeState) ||
			(ROUTE_STATE_NEAR_LOCKERR == routeState)||
			(ROUTE_STATE_AUTO_UNLOCK == routeState) ||
			(ROUTE_STATE_AUTO_UNLOCKERR == routeState) ||
			(ROUTE_STATE_DELAY_UNLOCK == routeState))
		{
			/*进路存在锁闭:进路初锁、进路初锁异常、预先锁闭、预先开放、接近开放、接近锁闭异常、接近锁闭正常、延时解锁、自动解锁正常、自动解锁异常*/
			SetRouteDCQState(routeId,ROUTE_DCQ_REQUEST);/*设置进路调车请求状态调车请求有效*/
		}
		else
		{
			/*其它情况设置进路调车请求状态为调车请求无效;调车同意状态无效*/
			SetRouteDCQState(routeId,ROUTE_DCQ_NOT_REQUEST);
			SetRouteDCTYState(routeId, ROUTE_DCT_NOT_AGREE);
		}
	}	
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述：设置非进路逻辑区段锁闭状态
* 参数说明： const UINT16 nonRouteId, 非进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
* cgh-20230529-修复YF0083-823
*/
void SetNonRouteLogSecLockState(const UINT8 nonRouteId, const UINT8 lockState)
{
	UINT8 chSectionSum = 0u; /*非进路包含物理区段总数*/
	NonRoutePhySectionStruct* pPhySecStruBuf = NULL; /*非进路对应物理区段区段数据*/
	UINT8 chLogicSecSum = 0u; /*物理区段包含逻辑区段总数*/
	UINT16* pLogicSecIdBuf = NULL;/*物理区段包含逻辑区段Id数组*/
	UINT8 chKeepFlag = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT8 chNonRouteLogSecCheck = CI_ERROR;/*对应逻辑区段是否为非进路内方区段检查*/

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


	if ((0u == chSectionSum) || (NULL == pPhySecStruBuf))
	{
		chKeepFlag = CI_ERROR;
	}
	else
	{
		chKeepFlag = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		if ((lockState != LOG_SECTION_LOCK_NO) &&
			(lockState != LOG_SECTION_LOCK_NORMAL))
		{/*非进路只有未锁闭和正常锁闭*/
			chKeepFlag = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		for (ii = 0u; ii < chSectionSum; ii++)
		{/*获取物理区段对应的逻辑区段数据*/
			chLogicSecSum = GetPhySecIncLogSecSum(pPhySecStruBuf[ii].PhySectionId);
			pLogicSecIdBuf = GetPhySecIncLogSecIdBuf(pPhySecStruBuf[ii].PhySectionId);
			for (jj = 0U; jj < chLogicSecSum; jj++)
			{
				chNonRouteLogSecCheck = NonRouteLogSecCheck(nonRouteId, pLogicSecIdBuf[jj]);
				if (CI_SUCCESS == chNonRouteLogSecCheck)
				{/*此逻辑区段为非进路内方逻辑区段，则设置对应逻辑区段状态*/
					SetLogSecLockState(pLogicSecIdBuf[jj], lockState, 0U, 0U);
				}
			}
		}
	}
}

/*
* 功能描述：检查非进路是否包含此逻辑区段
* 参数说明： const UINT16 chNonRouteId, 非进路ID
*            const UINT16 wLogSecId    逻辑区段ID
* 返回值  ： CI_ERROR 不包含
*            CI_SUCCESS  包含
* cgh-20230529-修复YF0083-823
*/
UINT8 NonRouteLogSecCheck(const UINT8 chNonRouteId, const UINT16 wLogSecId)
{
	UINT8 reval = CI_ERROR;
	UINT8 chNonRouteSwitchSum = 0U;/*非进路包含道岔数目*/
	NonRouteSwitchStruct* pNonRouteSwitchStr = NULL;/*非进路包含道岔数据*/
	UINT8 chLogSecSwitchSum = 0U;/*逻辑区段包含道岔数目*/
	LogsecSwitchStruct* pLgcSecSwitchStru = NULL;/*逻辑区段包含道岔数据*/
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 chCheckPassFlag = 0U;/*逻辑区段道岔与非进路包含道岔匹配标志*/

	chNonRouteSwitchSum = GetNonRouteSwitchSumById(chNonRouteId);
	pNonRouteSwitchStr = GetNonRouteSwitchStructBufById(chNonRouteId);
	chLogSecSwitchSum = GetLogicSecSwitchSum(wLogSecId);
	pLgcSecSwitchStru = GetLogicSecSwitchIdStru(wLogSecId);

	if((NULL == pNonRouteSwitchStr) || (NULL == pLgcSecSwitchStru))
	{
		reval = CI_ERROR;
	}
	else
	{
		for (ii = 0U; ii < chLogSecSwitchSum; ii++)
		{/*检查逻辑区段包含的道岔ID与位置是否与非进路包含的道岔数据一致*/
			for (jj = 0U; jj < chNonRouteSwitchSum; jj++)
			{
				if ((pNonRouteSwitchStr[jj].SwitchId == pLgcSecSwitchStru[ii].SwitchId) && (pNonRouteSwitchStr[jj].SwitchPos == pLgcSecSwitchStru[ii].SwitchPosition))
				{
					chCheckPassFlag++;
				}
			}
		}
		if (chLogSecSwitchSum == chCheckPassFlag)
		{/*逻辑区段包含的所有的道岔都可以在非进路中匹配到，则检查成功*/
			reval = CI_SUCCESS;
		}
	}
	return reval;
}

/*
* 功能描述： 转换轨调车折返解锁进路部分锁闭逻辑处理
* 参数说明： UINT16 routeId, 进路ID
* 返回值  ：无
* 创建 ： fan0824
*/
void ZHGDTrainRtnUnlockRouteProc(const UINT16 routeId)
{
	UINT8 routeState = 0U; /*进路状态*/
	UINT16 returnSigId = 0U; /*折返信号机ID*/
	UINT16 innerSecId = 0U; /*信号机内方区段ID*/
	UINT16 lockBelongRouteId = 0U; /*锁闭所属进路ID*/
	UINT8 routeType = 0U;
	UINT8 chKeepFlag = CI_ERROR;/*程序继续执行标志*/
	UINT8 chLockBelRouteState = 0U; /*区段锁闭所属进路进路状态*/
	UINT16 wLockRouteStartSigId = 0U;/*锁闭所属进路始端信号机ID*/
	UINT16 wOutSecId = 0U; /*折返信号机外方区段*/
	UINT8 chOutSecType = 0U;
	UINT8 chSecOccupyState = 0U; /*折出进路外方区段占压状态*/
	UINT8 chSecLockState = 0U;/*外方区段锁闭状态*/

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

	if (routeState != ROUTE_STATE_AUTO_UNLOCK)
	{
		chKeepFlag = CI_ERROR;
	}
	else
	{
		chKeepFlag = CI_SUCCESS;
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		chKeepFlag = RouteAllLockSecNoOccupyCheck(routeId);
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		returnSigId = GetRouteTransRoutZFSigID(routeId);
		if (0u == returnSigId)
		{
			chKeepFlag = CI_ERROR;
		}
		else
		{
			/*fan：修复转换轨折返区段曾完全出清场景，需配置转换轨折返信号机*/
			wOutSecId = GetSignalOutFirstPhySecId(returnSigId);/*获取信号机外方区段ID 即转换轨前一区段*/
			innerSecId = GetSignalInFirstPhySecId(returnSigId, routeId);
			chSecLockState = GetPhySecLockState(wOutSecId);
			chSecOccupyState = GetPhySecCurMergeState(wOutSecId);
			chOutSecType = GetPhySecType(wOutSecId);

			if ((PHYSICAL_SEC_TYPE_NOSWITCH == chOutSecType) && (SECTION_OCCUPY_YES == chSecOccupyState) && (PHYSICAL_SECTION_LOCK_NO == chSecLockState))
			{
				/*转换轨前一区段需满足占压、是无岔区段且未锁闭，否则不解锁*/
				chKeepFlag = CI_SUCCESS;
			}
			else
			{
				chKeepFlag = CI_ERROR;/*不解锁*/
			}
		}
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		innerSecId = GetSignalInFirstPhySecId(returnSigId, routeId); /*获取信号机内方第一区段ID*/
		lockBelongRouteId = GetPhySecRLockBelongRouteId(innerSecId); /*区段锁闭所属进路ID*/
		if (0u == lockBelongRouteId)
		{ /*锁闭所属进路无效*/
			chKeepFlag = CI_ERROR;
		}
		else
		{
			; /*继续解锁*/
		}
	}

	if (CI_SUCCESS == chKeepFlag)
	{
		routeType = GetRouteType(lockBelongRouteId);
		chLockBelRouteState = GetRouteState(lockBelongRouteId);
		wLockRouteStartSigId = GetRouteStartSignalId(lockBelongRouteId);/*获取进路始端信号机ID*/
		chSecOccupyState = GetPhySecCurMergeState(innerSecId); /*已经检查折出外方区段占压，此处检查内方区段占压*/
		if ((ROUTE_TYPE_DIAOCHE == routeType) && (ROUTE_STATE_NEAR_OPEN == chLockBelRouteState) &&
			(SECTION_OCCUPY_YES == chSecOccupyState) && (returnSigId == wLockRouteStartSigId))
		{
			/*折出进路是调车进路，进路状态是接近开放且有车驶入且折出进路始端信号机是本进路折返信号机*/
			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
																			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}

		else if ((ROUTE_TYPE_LIECHE == routeType) && (ROUTE_STATE_NEAR_LOCK == chLockBelRouteState)
			&& (returnSigId == wLockRouteStartSigId))
		{
			/*折出进路是列车进路，进路状态是接近锁闭且折出进路始端信号机是本进路折返信号机*/

			/*解锁成功*/
			SetRoutePhySectionLockState(routeId, PHYSICAL_SECTION_LOCK_NO); /*设置进路区段未锁闭*/
																			/*设置进路逻辑区段: 未锁闭*/
			SetRouteLogSectionLockState(routeId, LOG_SECTION_LOCK_NO);
			SetRouteStateDeal(routeId, ROUTE_STATE_IDLE); /*设置进路状态为空闲*/
		}
		else
		{
			; /*不解锁*/
		}
	}
}