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

#include "LogicSectionDataManage.h"
#include "../Route/RouteDataManage.h"
#include "../Route/RouteDefine.h"
#include "../Switch/SwitchDefine.h"
#include "SectionStateProcess_api.h"
#include "AxisSort_api.h"
#include "AxisAssertManageAPI.h"
#include "LogicalRouteDataManage.h"
#include "InterlockCommonManage.h"

LogicSectionDataStruct LogicSectionDataStru[LOGIC_SECTION_SUM_MAX];   /*定义逻辑区段数据结构体*/
static TsrDataStruct g_TsrDataStru[TSR_MAX_SUM] = { 0u };			  /*临时限速数据*/
static UINT8 g_TsrSum = 0u;											  /* 临时限速数量 */

UINT8 WholeLineLinShiXianSuFlag = WHOLE_LINE_LINSHIXIANSUSET_NO;      /*全线临时限速标志，默认无*/

/*
* 功能描述： 获取逻辑区段数据
* 参数说明： void    
* 返回值  ： 0: 获取数据失败
*			>0: 逻辑当前总数
*/
LogicSectionDataStruct* GetLogicSecData(void)
{
	return LogicSectionDataStru;
}

/*
* 功能描述： 获取指定ID逻辑区段之前占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 之前占用状态      
*/
UINT8 GetLogSecPreOccupyState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
        if (LogicSectionDataStru[bufIndex].PreOccupyState == LOGICSECTION_OCCUPY_NO)
        {
            retVal = SECTION_OCCUPY_NO;
        }
        else
        {
            retVal = SECTION_OCCUPY_YES;
        }
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID逻辑区段当前占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 当前占用状态      
*/
UINT8 GetLogSecCurOccupyState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
        if (LogicSectionDataStru[bufIndex].CurOccupyState == LOGICSECTION_OCCUPY_NO)
        {
            retVal = SECTION_OCCUPY_NO;
        }
        else
        {
            retVal = SECTION_OCCUPY_YES;
        }
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID逻辑区段当前CT或UT占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 当前占用状态      
*/
UINT8 GetLogSecCurCtOrUtOccupyState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		retVal = LogicSectionDataStru[bufIndex].CurOccupyState;
    }
    else
    {
        retVal = CI_ERROR;
    }
	return retVal;
}


/*
* 功能描述： 获取指定ID逻辑区段临时限速设置状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 当前临时限速设置状态   
*/
UINT8 GetLogSecLinShiXianSuSetState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8  funRetVal = 0u;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
        funRetVal = LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag;
    }
    else
    {
        funRetVal = CI_ERROR;
    }	
	return funRetVal;
}

/*
* 功能描述： 设置指定ID逻辑区段当前占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 curOccupyState, 当前占用状态
* 返回值  ： 无
*			       
*/
void SetLogSecCurOccupyState(const UINT16 logSectionId, const UINT8 curOccupyState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取道岔数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		if ((LOGICSECTION_OCCUPY_UT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_CT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_NO == curOccupyState))
		{
			LogicSectionDataStru[bufIndex].CurOccupyState = curOccupyState;  /*逻辑区段当前占用状态*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 设置指定ID逻辑区段之前占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 curOccupyState, 之前占用状态
* 返回值  ： 无
*			      
*/
void SetLogSecPreOccupyState(const UINT16 logSectionId, const UINT8 curOccupyState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取道岔数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		if ((LOGICSECTION_OCCUPY_UT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_CT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_NO == curOccupyState))
		{
			LogicSectionDataStru[bufIndex].PreOccupyState = curOccupyState;  /*逻辑区段之前占用状态*/

		}
		else
		{
			/*不设置*/
		}
	}
	else
	{
		/*不设置*/
	}
}



/*
* 功能描述： 设置指定ID逻辑区段临时限速设置状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 linShiXianSuSetState, 临时限速设置状态
* 返回值  ： 无
*			        
*/
void SetLogSecLinShiXianSuState(const UINT16 logSectionId, const UINT8 linShiXianSuSetState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGSEC_LSXS_SET_STATE_NO == linShiXianSuSetState) ||
            (LOGSEC_LSXS_SET_STATE_YES == linShiXianSuSetState) ||
            (LOGSEC_LSXS_SET_STATE_INVALID == linShiXianSuSetState))
		{
			LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag= linShiXianSuSetState;  /*逻辑区段临时限速设置状态*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 设置指定码位对应的逻辑区段占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 occupyStateMask, 当前占用码位
* 返回值  ： 无
*			        
*/
void SetLogSecMask(const UINT16 logSectionId, const UINT8 occupyStateMask)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取道岔数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		LogicSectionDataStru[bufIndex].zcMaskData |= occupyStateMask;
		LogicSectionDataStru[bufIndex].maskCount++;
		if (LogicSectionDataStru[bufIndex].maskCount == 2u)
		{
			if (LOGIC_MASK_CT == LogicSectionDataStru[bufIndex].zcMaskData)
			{
				SetLogSecPreOccupyState(logSectionId, GetLogSecCurCtOrUtOccupyState(logSectionId));
				SetLogSecOccupyState(logSectionId, LOGICSECTION_OCCUPY_CT);

			}
			else if (LOGIC_MASK_UT == LogicSectionDataStru[bufIndex].zcMaskData)
			{
				SetLogSecPreOccupyState(logSectionId, GetLogSecCurCtOrUtOccupyState(logSectionId));
				SetLogSecOccupyState(logSectionId, LOGICSECTION_OCCUPY_UT);
			}
			else if (LOGIC_MASK_NO ==  LogicSectionDataStru[bufIndex].zcMaskData)
			{
				SetLogSecPreOccupyState(logSectionId, GetLogSecCurCtOrUtOccupyState(logSectionId));
				SetLogSecOccupyState(logSectionId, LOGICSECTION_OCCUPY_NO);
			} 
			else
			{	/* l码位出现，CT UT 同时满足，则认为是ZC发送错误，已UT占用 */
				SetLogSecPreOccupyState(logSectionId, GetLogSecCurCtOrUtOccupyState(logSectionId));
				SetLogSecOccupyState(logSectionId, LOGICSECTION_OCCUPY_UT);
			}

			LogicSectionDataStru[bufIndex].zcMaskData = 0u;
			LogicSectionDataStru[bufIndex].maskCount = 0u;
		}
	}
	else
	{
		/*不做处理*/
	}
}


/*
* 功能描述： 获取指定逻辑区段占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 0: 设置失败
*			 1: 设置成功      
*/
UINT8 GetLogSecOccupyState(const UINT16 logSectionId)
{

    UINT16 bufIndex = 0u;  /*数组下标*/
    UINT8 retVal = CI_ERROR;

    bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

    if (bufIndex < LOGIC_SECTION_SUM_MAX)
    {
        retVal = LogicSectionDataStru[bufIndex].OccupyState;
    }
    else
    {
        retVal = CI_ERROR;
    }
    return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 curOccupyState, 当前占用状态
* 返回值  ： 无
*			     
*/
void SetLogSecOccupyState(const UINT16 logSectionId, const UINT8 curOccupyState)
{
    UINT16 bufIndex = 0u;  /*数组下标*/

    bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取道岔数组下标*/

    if (LOGIC_SECTION_SUM_MAX > bufIndex)
    {
        if ((LOGICSECTION_OCCUPY_UT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_CT == curOccupyState) ||
            (LOGICSECTION_OCCUPY_NO == curOccupyState))
        {
            LogicSectionDataStru[bufIndex].OccupyState = curOccupyState;  /*逻辑区段当前占用状态*/

        }
        else
        {
            /*不设置*/
        }
    }
    else
    {
        /*不设置*/
    }
}


/*
* 功能描述： 设置指定ID逻辑区段通信车（有位置RM车）占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 curOccupyState, 当前占用状态
* 返回值  ：无
*备注：增加逻辑区段通信车（有位置RM车）占用状态设置函数，A by yt 2022年5月19日
*/
void SetLogSecTXOccupyState(const UINT16 logSectionId, const UINT8 curOccupyState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取道岔数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGICSECTION_OCCUPY_TX == curOccupyState) ||
			(LOGICSECTION_OCCUPY_NO_TX == curOccupyState))
		{
			LogicSectionDataStru[bufIndex].TXOccupyState = curOccupyState;  /*逻辑区段当前占用状态*/
		}
		else
		{
			; /*占用状态错误，不执行赋值操作*/
		}
	}
	else
	{
		; /*数组下标错误，不执行赋值操作*/
	}

}

/*
* 功能描述： 获取指定ID逻辑区段通信车占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0: 设置失败
*			 0x55：无车占用
*			 0xaa：通信车占用
*/
UINT8 GetLogSecTXOccupyState(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].TXOccupyState;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取全线临时限速标志
* 参数说明： 无
*			 
* 返回值  ： 全线临时限速标志    
*/
UINT8 GetWholeLineLinShiXianSuFlag(void)
{
    return WholeLineLinShiXianSuFlag;
}

/*
* 功能描述： 设置全线临时限速标志
* 参数说明： UINT8 flag,限速标志
*			 
* 返回值  ： 无
*			        
*/
void SetWholeLineLinShiXianSuFlag(UINT8 flag)
{
	if((WHOLE_LINE_LINSHIXIANSUSET_NO == flag) ||(WHOLE_LINE_LINSHIXIANSUSET_YES == flag) )
	{
		WholeLineLinShiXianSuFlag = flag;	
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 获取指定ID逻辑区段之前CT/UT占用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 之前CT/UT占用状态      
*/
UINT8 GetLogSecPreCtOrUtOccupyState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/
	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		retVal = LogicSectionDataStru[bufIndex].PreOccupyState;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定逻辑区段锁闭状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段锁闭状态     
*/
UINT8 GetLogSecLockState(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogLockState;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}



/*
* 功能描述： 获取指定逻辑区段锁闭方向
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段锁闭方向     
*/
UINT8 GetLogSecLockDir(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogLockDir;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定逻辑区段锁闭状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 无
* 修复bug YF0083-119		 
*/
void SetLogSecLockState(const UINT16 logSectionId,const UINT8 lockState,const UINT16 routeId, const UINT8 lockDir)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/*未锁闭*/
		if(LOG_SECTION_LOCK_NO == lockState)
		{
			if ((LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[bufIndex].LogLockState)
				|| (LOG_SECTION_LOCK_EXCEPT == LogicSectionDataStru[bufIndex].LogLockState)
				|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[bufIndex].LogLockState))
			{
				/*锁闭属于本进路*/
				if (routeId == LogicSectionDataStru[bufIndex].LogLockBelongRoute)
				{
					if (0u == LogicSectionDataStru[bufIndex].wPLockBelongRouteId)
					{
						/*设置未锁闭状态、锁闭进路为0*/
						LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;
						LogicSectionDataStru[bufIndex].wPLockBelongRouteId = 0u;
						LogicSectionDataStru[bufIndex].LogLockDir = 0u;
					}
					else
					{
						/* 同时存在其他进路的防护锁闭，需要还原成防护锁闭状态 */
						LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_PROTECT;
					}

					/*清除逻辑区段资源信息*/
					ClearLgcSecResTrain(logSectionId);		
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0u;
					LogicSectionDataStru[bufIndex].LogUnlockStartCycNum = 0u;
				}
				else if(LogicSectionDataStru[bufIndex].wPLockBelongRouteId == routeId)
				{
					/* 仅清除防护锁闭 */
					LogicSectionDataStru[bufIndex].wPLockBelongRouteId = 0u;
				}
				else
				{
					/* 不属于本进路 */
				}
			}
			else if((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[bufIndex].LogLockState)
				&& (routeId != LogicSectionDataStru[bufIndex].wPLockBelongRouteId))
			{
				;/* 仅剩其他进路的防护锁闭，无处理 */
			}
			else
			{
				/*设置未锁闭状态*/
				LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;
				LogicSectionDataStru[bufIndex].wPLockBelongRouteId = 0u;
				LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0u;
				LogicSectionDataStru[bufIndex].LogUnlockStartCycNum = 0u;
				LogicSectionDataStru[bufIndex].LogLockDir = 0u;
				ClearLgcSecResTrain(logSectionId);
			}
		}
		/*正常锁闭*/
		else if(LOG_SECTION_LOCK_NORMAL == lockState)
		{
			/*设置锁闭状态、锁闭进路*/
			LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NORMAL;
			LogicSectionDataStru[bufIndex].LogLockBelongRoute = routeId;
			LogicSectionDataStru[bufIndex].LogLockDir = lockDir;

		}
		else if (LOG_SECTION_LOCK_PROTECT == lockState)
		{ /*防护锁闭*/
			if(LOG_SECTION_LOCK_NO == LogicSectionDataStru[bufIndex].LogLockState)
			{
				/* 设置成防护锁闭 */
				LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_PROTECT;
			}
			else
			{

			}

			LogicSectionDataStru[bufIndex].wPLockBelongRouteId = routeId;
			LogicSectionDataStru[bufIndex].LogLockDir = lockDir;
		}
		/*故障锁闭、延时锁闭*/
		else
		{
			SetRouFirDelayErlockStaCycNum(routeId, 0U);
			LogicSectionDataStru[bufIndex].LogLockState = lockState;
			LogicSectionDataStru[bufIndex].LogUnlockStartCycNum = 0u;
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 获取指定逻辑区段锁闭所属进路
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段锁闭所属进路     
*/
UINT16 GetLogSecLockBelongRoute(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogLockBelongRoute;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定逻辑区段延时解锁起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 
* 返回值  ： 0:  获取失败
*			 >0: 逻辑区段延时解锁起始周期号     
*/
UINT32 GetLogUnlockStartCycNum(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogUnlockStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 设置指定逻辑区段延时解锁起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT32 startCycNum 起始周期号
* 返回值  ： 无
*			   
*/
void SetLogUnlockStartCycNum(const UINT16 logSectionId, const UINT32 startCycNum)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		LogicSectionDataStru[bufIndex].LogUnlockStartCycNum = startCycNum;
	}
	else
	{
		/*不做处理*/
	}
}


/*
* 功能描述： 设置非本联锁指定ID逻辑区段锁闭状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 lockState, 锁闭状态
*            const UINT16 routeId, 进路ID
*            const UINT8 lockDirection, 锁闭方向
* 返回值  ： 无
* 修复bug YF0083-119		       
*/
void SetLogSecLockStateOtherCI(const UINT16 logSectionId, const UINT8 lockState, const UINT16 routeId, const UINT8 lockDirection)
{
	/*变量初始化*/
	UINT8 localCiId = 0u;
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 wCurRouteId = 0U;
	UINT8 cCurRouteBelongCiId = 0U;
	UINT8 cCurRouteState = 0U;
	UINT8 routeBelongCi = 0u;
	UINT8 logBelongCi = 0u;
	UINT8 expRouteBelongCi = 0u;
	UINT8 chNewRouteCurState = 0U;/*新的进路当前状态*/
	UINT8 chNewRoutePreState = 0U;/*新的进路之前状态*/
	UINT8 chOldRoutePreState = 0U;/*旧的进路之前状态*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/
	localCiId = GetSystemParaLocalCiId();


	if(LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		logBelongCi = GetLogSecBelongCiId(logSectionId);
		expRouteBelongCi = GetRouteBelongCiId(routeId);
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[bufIndex].LogLockState) && (logBelongCi == localCiId)
			&& ((LOG_SECTION_LOCK_NORMAL != lockState) || (localCiId == expRouteBelongCi)))
		{/*保护区段的锁闭状态是由保护区段所属的联锁来更新处理的，若待设置锁闭状态为正常锁闭且锁闭所属进路非本控区，考虑为ZHG由防护锁闭转为正常锁闭，需正常刷新锁闭状态*/
			
		}
		/*上电锁闭*/
		else if(LOG_SECTION_LOCK_START == lockState)
		{
			/*设置锁闭状态*/
			LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_START;
		}
		/*空闲*/
		else if(LOG_SECTION_LOCK_NO == lockState)
		{
			/*正常锁闭、延时解锁、故障锁闭*/
			if((LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[bufIndex].LogLockState) ||
				(LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[bufIndex].LogLockState)||
				(LOG_SECTION_LOCK_EXCEPT == LogicSectionDataStru[bufIndex].LogLockState))
			{
				routeBelongCi = GetRouteBelongCiId(LogicSectionDataStru[bufIndex].LogLockBelongRoute);
				/*锁闭进路不是本联锁*/
				if(routeBelongCi != localCiId)
				{
					if ((0U != LogicSectionDataStru[bufIndex].wPLockBelongRouteId) && (logBelongCi == localCiId))
					{
						/*20241030增加检查条件“区段属于本控区”，解决成都30防护锁闭互刷问题：某一条进路属于控区1但跨控区，进路内方第一区段（属于控区1）又是保护区段；
						当该区段同时被进路锁闭和防护锁闭，在该区段解锁时，控区1需要给相邻控区发这个逻辑区段的未锁闭状态，相邻控区在此处设置不了未锁闭，
						只能遗留防护锁闭且没有防护锁闭所属进路，所以相邻控区又会给控区1刷新这个状态，导致该区段一直无法解锁*/
						LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_PROTECT;  /*存在防护锁闭所属进路（且区段属于本控区），设置为防护锁闭*/
					}
					else
					{
						LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;  /*设置为未锁闭*/
						LogicSectionDataStru[bufIndex].LogLockDir = 0U;
					}

					LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0U;
					ClearLgcSecResTrain(logSectionId);
				}
				else
				{

				}
			}
			else
			{
				if (LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[bufIndex].LogLockState)
				{/*本物逻辑区段不属于本联锁且当前锁闭状态是保护锁闭，本逻辑区段的锁闭状态采用此物理区段所属联锁发来的锁闭状态*/
					LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;  /*###设置未锁闭*/

					LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0U;     /*设置区段进路锁闭所属进路ID*/
					LogicSectionDataStru[bufIndex].wPLockBelongRouteId = 0U;     /*设置区段防护锁闭所属进路ID*/
					LogicSectionDataStru[bufIndex].LogLockDir = 0U;  /*清除区段锁闭方向*/
					ClearLgcSecResTrain(logSectionId);
				}
				else
				{

				}

				if (0U == LogicSectionDataStru[bufIndex].LogLockState)
				{/*此逻辑区段不属于本联锁，且还未收到过本逻辑区段的锁闭状态信息时本物理区段的锁闭状态采用此逻辑区段所属联锁发来的锁闭状态*/
					LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0u;
					LogicSectionDataStru[bufIndex].LogLockDir = 0u;

					ClearLgcSecResTrain(logSectionId);
				}
				else
				{

				}

				logBelongCi = GetLogSecBelongCiId(logSectionId);
				/*逻辑区段不是本联锁*/
				if((logBelongCi != localCiId) && ((LOG_SECTION_LOCK_START == LogicSectionDataStru[bufIndex].LogLockState)
					|| (0U == LogicSectionDataStru[bufIndex].LogLockState)))
				{
					/*设置状态*/
					LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NO;
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0u;
					LogicSectionDataStru[bufIndex].LogLockDir = 0u;

					ClearLgcSecResTrain(logSectionId);
				}
				else
				{

				}
			}
		}
		/*正常锁闭*/
		else if(LOG_SECTION_LOCK_NORMAL == lockState)
		{
			routeBelongCi = GetRouteBelongCiId(routeId);
			if(routeBelongCi != localCiId)
			{
				wCurRouteId = GetLogSecLockBelongRoute(logSectionId);
				cCurRouteBelongCiId = GetRouteBelongCiId(wCurRouteId);
				cCurRouteState = GetRouteState(wCurRouteId);
				chOldRoutePreState = GetRoutePreState(wCurRouteId);
				chNewRouteCurState = GetRouteState(routeId);
				chNewRoutePreState = GetRoutePreState(routeId);

				if ((routeId != wCurRouteId) && (localCiId == cCurRouteBelongCiId)
					&& ((ROUTE_STATE_HALF_UNLOCK == cCurRouteState)
						|| (ROUTE_STATE_FIRST_LOCK == chNewRouteCurState) || (ROUTE_STATE_FIRST_LOCK == chNewRoutePreState)
						|| (ROUTE_STATE_FIRST_LOCK == cCurRouteState) || (ROUTE_STATE_FIRST_LOCK == chOldRoutePreState)))
				{
					/*冲锁闭时，新的不属于本控区的进路当前为初锁或之前为初锁，保持原状态（之前初锁主要考虑通信不好）*/
				}
				else
				{
					/*设置状态*/
					LogicSectionDataStru[bufIndex].LogLockState = LOG_SECTION_LOCK_NORMAL;
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = routeId;
					LogicSectionDataStru[bufIndex].LogLockDir = lockDirection;
				}
			}
			else
			{

			}
		}
		/*故障锁闭*/
		else if(LOG_SECTION_LOCK_EXCEPT == lockState)
		{
			SetRouFirDelayErlockStaCycNum(routeId, 0U);
			routeBelongCi = GetRouteBelongCiId(LogicSectionDataStru[bufIndex].LogLockBelongRoute);
			/*之前锁闭不属于本联锁*/
			if(routeBelongCi != localCiId)
			{
				/*再次锁闭不属于本联锁，或属于本联锁，但是状态是初始值*/
				if((expRouteBelongCi != localCiId) || (LOG_SECTION_LOCK_START == LogicSectionDataStru[bufIndex].LogLockState)
					|| (0U == LogicSectionDataStru[bufIndex].LogLockState))
				{
					/*设置状态*/
					LogicSectionDataStru[bufIndex].LogLockState = lockState;
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = routeId;
					LogicSectionDataStru[bufIndex].LogLockDir = lockDirection;  /*YF0083-2431：当进路属于其他控区，区段属于本控区，列车在此区段飞车后，区段出现故障锁闭，重启后会设置该逻辑区段方向为0*/
				}
				else
				{

				}
			}
			else
			{

			}
		}
		/*延时解锁*/
		else if(LOG_SECTION_LOCK_DELAY == lockState)
		{
			if(expRouteBelongCi != localCiId)
			{
				if(LOG_SECTION_LOCK_NO != LogicSectionDataStru[bufIndex].LogLockState)
				{
					/*设置状态*/
					LogicSectionDataStru[bufIndex].LogLockState = lockState;
					LogicSectionDataStru[bufIndex].LogLockDir = lockDirection;
					LogicSectionDataStru[bufIndex].LogLockBelongRoute = routeId;
				}
				else
				{

				}
			}
			else
			{

			}
		}
		else if (LOG_SECTION_LOCK_PROTECT == lockState)
		{
			/*防护锁闭*/
			cCurRouteBelongCiId = GetRouteBelongCiId(LogicSectionDataStru[bufIndex].LogLockBelongRoute);
			if (logBelongCi != localCiId)
			{
				if ((localCiId == cCurRouteBelongCiId) && (localCiId == expRouteBelongCi))
				{
					/*解决ZHG锁闭问题，当前进路锁闭所属进路和防护锁闭所属进路均为本控区，不刷新锁闭状态*/
				}
				else
				{
					LogicSectionDataStru[bufIndex].LogLockState = lockState;

					LogicSectionDataStru[bufIndex].wPLockBelongRouteId = routeId;
					LogicSectionDataStru[bufIndex].LogLockDir = lockDirection;  /*设置区段锁闭方向*/
					if (LogicSectionDataStru[bufIndex].LogLockBelongRoute != 0u)
					{
						LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0u;
					}
					else
					{

					}
				}
			}
			else
			{
				if ((localCiId != cCurRouteBelongCiId) && (cCurRouteBelongCiId == expRouteBelongCi))
				{
					/*考虑为ZHG进路锁闭所属进路解锁但防护锁闭所属进路未解锁场景，需更新锁闭状态*/
					LogicSectionDataStru[bufIndex].LogLockState = lockState;
					LogicSectionDataStru[bufIndex].wPLockBelongRouteId = routeId;
					LogicSectionDataStru[bufIndex].LogLockDir = lockDirection;  /*设置区段锁闭方向*/
					if (0U != LogicSectionDataStru[bufIndex].LogLockBelongRoute)
					{
						LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0U;
					}
					else
					{
						/*不处理*/
					}
				}
				else
				{
					/*逻辑区段为本联锁，此区段防护锁闭由自己处理，无需更新*/
				}
			}
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{

	}
}

/*
* 功能描述： 获取指定逻辑区资源列车数量
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 资源列车数量
*/
UINT8 GetLogSecTrainInfoSum(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (LOGIC_SECTION_RES_SUM_MAX > LogicSectionDataStru[wBufIndex].chTrainInfoSum)
		{
			chRetVal = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	return chRetVal;
}

/*
* 功能描述： 获取指定逻辑区所有资源列车信息
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： NULL:  获取失败
*			 !NULL: 逻辑区资源列车信息
*/
LogicTrainResStruct *GetLogSecTrainInfo(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pRetVal = NULL;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		pRetVal = (LogicTrainResStruct *)LogicSectionDataStru[wBufIndex].szTrainResData;
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}

/*
* 功能描述： 获取指定逻辑区资源列车信息
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： NULL:  获取失败
*			 !NULL: 逻辑区资源列车信息
* 修复bug YF0083-119
*/
LogicTrainResStruct *GetLogSecTrainInfoById(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8  chTrainSum = 0U;
	UINT8 ii = 0U;
	LogicTrainResStruct * pRetVal = NULL;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
		if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
		{
			for (ii = 0U; ii < chTrainSum; ii++)
			{
				if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
				{
					pRetVal = (LogicTrainResStruct *)(&LogicSectionDataStru[wBufIndex].szTrainResData[ii]);
					break;
				}
				else
				{

				}
			}
		}
		else
		{
			pRetVal = NULL;
		}
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}

/*
* 功能描述： 移出指定逻辑区资源列车信息
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 无
* 
*/
void RemoveLogSecTrainInfoById(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8  chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chNeedKeepSum = 0U;
	LogicTrainResStruct * pLogicTrainInfo = NULL;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
		if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
		{
			for (ii = 0U; ii < chTrainSum; ii++)
			{
				if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
				{
					; /*不处理，继续执行*/
				}
				else
				{
					LogicSectionDataStru[wBufIndex].szTrainResData[chNeedKeepSum++] = LogicSectionDataStru[wBufIndex].szTrainResData[ii];
				}
			}
			LogicSectionDataStru[wBufIndex].chTrainInfoSum = chNeedKeepSum;
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
}
/*
* 功能描述： 获取是否发送列车逻辑区段锁闭标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR	：不发送
*		  ： CI_SUCCESS ：发  送
*/
UINT8 GetLogSecTrainLockSendFlag(const UINT16 wLogSectionId,const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = CI_ERROR;
	UINT8 chRRouteCheck = CI_ERROR;
	UINT16 wRLockBelongRouteId = 0U;
	UINT8 chLgcResShrFlag = 0U;
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
		chRRouteCheck = CheckRouteStateNotYinDaoLock(wRLockBelongRouteId);

		chLgcResShrFlag = GetLogSecResShareFlag(wLogSectionId);
		if (CI_SUCCESS == chRRouteCheck)
		{
			if ((LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
				|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState))
			{
				if (LOGIC_SECTION_RES_SHARE_YES==chLgcResShrFlag)
				{
					chRetVal = CI_SUCCESS;
				}
				else if (NULL != pLogicSecTrainResInfo)
				{
					chRetVal = CI_SUCCESS;
				}
				else
				{
					chRetVal = CI_ERROR;
				}
			}
			else
			{
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	return chRetVal;
}


/*
* 功能描述： 获取是列车逻辑区段折返状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR	：错误
*		  ： CI_SUCCESS ：发  送
* 修复bug YF0083-119
*/
UINT8 GetLogSecTrainReturnState(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = CI_ERROR;
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (NULL != pLogicSecTrainResInfo)
		{
			chRetVal = pLogicSecTrainResInfo->chLogicReturnState;
		}
		else
		{

		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	return chRetVal;
}

/*
* 功能描述： 获取是列车逻辑区段资源可用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： LOGIC_SECTION_RES_UNUSABLE	：错误
*		  ： LOGIC_SECTION_RES_USABLE ：发  送
*/
UINT8 GetLogSecTrainResUsableState(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = LOGIC_SECTION_RES_UNUSABLE;
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (NULL != pLogicSecTrainResInfo)
		{
			chRetVal = pLogicSecTrainResInfo->chLogicResUsable;
		}
		else
		{
			chRetVal = LOGIC_SECTION_RES_UNUSABLE;
		}
	}
	else
	{
		chRetVal = LOGIC_SECTION_RES_UNUSABLE;
	}
	return chRetVal;
}
/*
* 功能描述： 设置是列车逻辑区段折返状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR	：错误
*		  ： CI_SUCCESS ：发  送
* 修复bug YF0083-119
*/
void SetLogSecTrainReturnState(const UINT16 wLogSectionId, const UINT16 wTrnId, const UINT8 chResReturnState)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (NULL != pLogicSecTrainResInfo)
		{
			if ((LOGIC_SECTION_TRAIN_RETURN_NO == chResReturnState)
				|| (LOGIC_SECTION_TRAIN_RETURN_YES == chResReturnState))
			{
				pLogicSecTrainResInfo->chLogicReturnState = chResReturnState;
			}
			else
			{

			}
		}
		else
		{

		}
	}
	else
	{
		;
	}
}
/*
* 功能描述： 为列车申请逻辑区段请求
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： VOID
* 创    建： qw.liu 2022-03-03
*/
void AddLogSecTrainRes(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	UINT16 wRLockBelongRouteId = 0U;
	UINT8 autoRouteType = 0U;
	UINT8 autoProtRouteType = 0U;/*防护锁闭所属进路自动属性*/
	UINT8 autoSigRouteType = 0U;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭进路所属ID*/
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
		if (0u != wRLockBelongRouteId)
		{
			/*获取自动进路类型:普通自动进路、自动折返进路*/
			autoRouteType = GetRouteAutoRouteSetState(wRLockBelongRouteId);
			/*获取进路当前是否为自动信号进路*/
			autoSigRouteType = GetRouteAutoSigSetState(wRLockBelongRouteId);
		}

		if ((NULL == pLogicSecTrainResInfo)
			&& ((LOGIC_SECTION_RES_SUM_MAX-1U)> LogicSectionDataStru[wBufIndex].chTrainInfoSum))
		{
			/*当前逻辑区段为办理进路锁闭，无任何所属列车*/
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].wTrainId = wTrnId;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_NO;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicReturnState = LOGIC_SECTION_TRAIN_RETURN_NO;
			LogicSectionDataStru[wBufIndex].chTrainInfoSum += 1U;
		}
		else
		{
		}

		if ((ROUTE_AUTOROUTE_NORMAL == autoRouteType)
			|| (ROUTE_AUTOROUTE_NORMAL == autoProtRouteType)
			|| (ROUTE_AUTOSIGROUTE_YES == (ROUTE_AUTOSIGROUTE_YES & autoSigRouteType)))
		{
			; /*自动进路或自动信号 不取消共享资源属性*/
		}
		else
		{
			SetLogSecResShareFlag(wLogSectionId, LOGIC_SECTION_RES_SHARE_NO);
		}
	}
	else
	{

	}
}

/*
* 功能描述： 相邻联锁列车申请逻辑区段请求
* 参数说明： const UINT16 logSectionId, 逻辑区段ID,
*					const UINT16 wTrnId 申请列车ID
* 返回值  ： VOID
*/
void AddLogSecTrainResFromCI(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	UINT16 wRLockBelongRouteId = 0U;
	UINT8 autoRouteType = 0U;
	UINT8 autoProtRouteType = 0U;/*防护锁闭所属进路自动属性*/
	UINT8 autoSigRouteType = 0U;
	UINT8 trainTransSta = 0U;
	UINT8 trainInRoutePos = 0U;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	trainTransSta = GetTrainTransitmitStat(wTrnId);

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭进路所属ID*/
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
		if (0u != wRLockBelongRouteId)
		{
			/*获取自动进路类型:普通自动进路、自动折返进路*/
			autoRouteType = GetRouteAutoRouteSetState(wRLockBelongRouteId);
			/*获取进路当前是否为自动信号进路*/
			autoSigRouteType = GetRouteAutoSigSetState(wRLockBelongRouteId);
		}

		if ((NULL == pLogicSecTrainResInfo)
			&& ((LOGIC_SECTION_RES_SUM_MAX - 1U)> LogicSectionDataStru[wBufIndex].chTrainInfoSum))
		{
			/*当前逻辑区段为办理进路锁闭，无任何所属列车*/
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].wTrainId = wTrnId;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_NO;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicReturnState = LOGIC_SECTION_TRAIN_RETURN_NO;
			LogicSectionDataStru[wBufIndex].chTrainInfoSum += 1U;
		}
		else
		{
		}

		if (TRANSMIT_STATE_GOOD == trainTransSta)
		{
			trainInRoutePos = dsuTrainMinHeadCrossSignal(wTrnId, wRLockBelongRouteId);
			if ((ROUTE_AUTOROUTE_NORMAL == autoRouteType)
				|| (ROUTE_AUTOROUTE_NORMAL == autoProtRouteType)
				|| (ROUTE_AUTOSIGROUTE_YES == (ROUTE_AUTOSIGROUTE_YES & autoSigRouteType))
				|| (TRAIN_ENTER_ROUTE_FULL == trainInRoutePos) 
				|| (TRAIN_ENTER_ROUTE_TAIL == trainInRoutePos))
			{
				; /*自动进路或自动信号 不取消共享资源属性*/
			}
			else
			{
				SetLogSecResShareFlag(wLogSectionId, LOGIC_SECTION_RES_SHARE_NO);
			}
		}
	}
	else
	{

	}
}

/*
* 功能描述： 设置逻辑进路逻辑区段资源的列车ID
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
*            const UINT16 wTrainId 列车编号
* 返回值  ： 无
*/
void SetLogRouteLogSecResTrainId(const UINT16 wLogRouteId, const UINT16 wTrainId)
{
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT16 ii = 0U;
	UINT16 wLogicSecId = 0U;
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;

	if ((0U < wLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogRouteId) && (0U != wTrainId))
	{
		/*获取进路包含逻辑区段信息*/
		logSectionSum = GetLogicalRouteInLogSecSum(wLogRouteId);
		pLogIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
		if ((0U != logSectionSum) && (NULL != pLogIdBuff))
		{
			for (ii = 0U; ii < logSectionSum; ii++)
			{
				wLogicSecId = pLogIdBuff[ii];
				wBufIndex = GetlogSectionBufIndex(wLogicSecId);  /*获取区段数组下标*/
				pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogicSecId, wTrainId);
				if (LOGIC_SECTION_SUM_MAX > wBufIndex)
				{
					if ((NULL == pLogicSecTrainResInfo)
						&& ((LOGIC_SECTION_RES_SUM_MAX - 1U) > LogicSectionDataStru[wBufIndex].chTrainInfoSum))
					{
						/*当前逻辑区段为办理进路锁闭，无任何所属列车*/
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].wTrainId = wTrainId;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_NO;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicReturnState = LOGIC_SECTION_TRAIN_RETURN_NO;
						LogicSectionDataStru[wBufIndex].chTrainInfoSum += 1U;
					}
					else
					{
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicReturnState = LOGIC_SECTION_TRAIN_RETURN_NO;
					}
				}
			}
		}
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述： 其他TIOC列车申请逻辑区段请求
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 cTrainSum，列车数量
*	         UINT16* pTrainId，列车编号
* 返回值  ： VOID
* 创    建： qw.liu 2022-03-03
* 修复bug YF0083-119
*/
void AddLogSecOtherTIOCTrainRes(const UINT16 wLogSectionId, const UINT8 cTrainSum,UINT16* pTrainId)
{
	UINT16 bufIndex = 0u;
	LogicSectionDataStruct * tmpLogicSectionDataStru = NULL; 
	UINT8 cTmpTrainSum = 0u;
	LogicTrainResStruct szTmpTrainResData[LOGIC_SECTION_RES_SUM_MAX] = {0u};
	UINT8 i = 0u;
	UINT8 j = 0u;

	if ((NULL != pTrainId) && (LOGIC_SECTION_RES_SUM_MAX >= cTrainSum))
	{
		tmpLogicSectionDataStru = GetLogicSecData();/*不会返回NULL*/
		bufIndex = GetlogSectionBufIndex(wLogSectionId);
		if  (LOGIC_SECTION_SUM_MAX > bufIndex)
		{
			if (0u == cTrainSum)
			{
				tmpLogicSectionDataStru[bufIndex].chTrainInfoSum = 0u;
			}
			else
			{
				for (i = 0u; i < cTrainSum;i++)
				{
					for (j = 0u; j < tmpLogicSectionDataStru[bufIndex].chTrainInfoSum;j++)
					{
						if (pTrainId[i] == tmpLogicSectionDataStru[bufIndex].szTrainResData[j].wTrainId)
						{
							if (LOGIC_SECTION_RES_SUM_MAX > cTmpTrainSum)
							{
								szTmpTrainResData[cTmpTrainSum] = tmpLogicSectionDataStru[bufIndex].szTrainResData[j];
								cTmpTrainSum++;
							}
							else
							{

							}
							break;
						}
						else
						{
							;/* 无处理 */
						}
					}

					if (j == tmpLogicSectionDataStru[bufIndex].chTrainInfoSum)
					{
						/* 未找到，加车 */
						if (LOGIC_SECTION_RES_SUM_MAX > cTmpTrainSum)
						{
							szTmpTrainResData[cTmpTrainSum].wTrainId = pTrainId[i];
							szTmpTrainResData[cTmpTrainSum].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_NO;
							szTmpTrainResData[cTmpTrainSum].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
							szTmpTrainResData[cTmpTrainSum].chLogicReturnState = LOGIC_SECTION_TRAIN_RETURN_NO;
							szTmpTrainResData[cTmpTrainSum].chLogicUnlockState = LOGIC_SECTION_TRAIN_UNLOCK_NO;
							szTmpTrainResData[cTmpTrainSum].dwRcvUnlockCmdCyc = 0u;
							cTmpTrainSum++;
						}
						else
						{

						}
					}
					else
					{

					}
				}

				/* 将融合之后的资源信息写回逻辑区段中 */
				for (i = 0u; i < cTmpTrainSum; i++)
				{
					tmpLogicSectionDataStru[bufIndex].szTrainResData[i] = szTmpTrainResData[i];
				}
				tmpLogicSectionDataStru[bufIndex].chTrainInfoSum = cTmpTrainSum;
			}
		}
		else
		{

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



/*
* 功能描述： 清空逻辑区段列车资源信息
* 参数说明： UINT16 wLogSecId,   逻辑区段ID
* 返回值  ：
*修改：保留逻辑进路的列车信息
*/
void ClearLgcSecResTrain(UINT16 wLogSecId)
{
	UINT8 chTrainResSum = 0U;
	UINT16 wBufIndex = 0U;
	UINT8 ii = 0U;
	UINT8 logRouteSum = 0;
	UINT16 wTrainId = 0U;			/*列车ID*/
	UINT16 chFlag = 0U;
	UINT8 chNeedKeepSum = 0U;
	chTrainResSum = GetLogSecTrainInfoSum(wLogSecId);
	wBufIndex = GetlogSectionBufIndex(wLogSecId);
	if ((LOGIC_SECTION_SUM_MAX <= wBufIndex))
	{
		; /*参数错误*/
	}
	else
	{
		for (ii = 0U; ii<LOGIC_SECTION_RES_SUM_MAX; ii++)
		{
			wTrainId = LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId;
			chFlag = GetLogSecBelongLogRouteId(wLogSecId, wTrainId);
			if (0U != chFlag)
			{
				/*需要保留含有逻辑进路的列车*/
				(void)CommonMemCpy((void*)&(LogicSectionDataStru[wBufIndex].szTrainResData[chNeedKeepSum]),  (UINT32)sizeof(LogicTrainResStruct),
					(void*)&(LogicSectionDataStru[wBufIndex].szTrainResData[ii]), (UINT32)sizeof(LogicTrainResStruct));
				chNeedKeepSum++;				
			}
			else
			{
				; /*不处理，继续执行*/
			}
		}
		/*清0防脏*/
		for (ii = chNeedKeepSum; ii < LOGIC_SECTION_RES_SUM_MAX; ii++)
		{
			(void)ComMemSet(&(LogicSectionDataStru[wBufIndex].szTrainResData[ii]), (UINT16)sizeof(LogicTrainResStruct), 0U);
		}
		LogicSectionDataStru[wBufIndex].chTrainInfoSum = chNeedKeepSum;
	}
}


/*
* 功能描述： 拷贝逻辑区段列车资源信息
* 参数说明： UINT16 wLogSecId,   逻辑区段ID
* 返回值  ：
*/
void CpyLgcSecResTrain(UINT16 wLogSecId,UINT8 chTrainSum, LogicTrainResStruct *pstLgcResInfo)
{
	UINT8 chTrainResSum = 0U;
	UINT16 wBufIndex = 0U;

	chTrainResSum = GetLogSecTrainInfoSum(wLogSecId);
	wBufIndex = GetlogSectionBufIndex(wLogSecId);
	if ((LOGIC_SECTION_SUM_MAX <= wBufIndex)
		||(NULL==pstLgcResInfo)
		||(LOGIC_SECTION_RES_SUM_MAX <= chTrainSum))
	{
		; /*参数错误*/
	}
	else
	{
		(void)ComMemCopy(pstLgcResInfo, (LogicSectionDataStru[wBufIndex].szTrainResData), (UINT16)(sizeof(LogicTrainResStruct)*LOGIC_SECTION_RES_SUM_MAX));
		LogicSectionDataStru[wBufIndex].chTrainInfoSum = chTrainSum;
	}
}
/*
* 功能描述： 列车申请逻辑区段请求
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： VOID
* 修复bug YF0083-119
*/
void SetLogSecTrainLockApply(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRRouteCheck = CI_ERROR;
	UINT16 wLgcRelativePhy = 0U;
	UINT16 wRouteLastPhy = 0U;
	UINT16 wRLockBelongRouteId = 0U;
	UINT8 chRouteType = 0U;
	UINT8 chLgcResReturn = 0U;
	UINT8 autoRouteType = 0U;
	UINT8 autoSigRouteType = 0U;
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	UINT8 cRouteCId = 0u;
	UINT8 cLocalCiId = 0u;
	UINT8 chLgcResShareFlag = 0U;
	UINT8 autoProtRouteType = 0U;
	UINT8 chLgcSecResCanAdd = 0U;
	UINT8 trainInLockRoute = 0U;
	UINT8 chLocalCiType = 0U;/*本地联锁类型*/
	UINT8 trainInRoutePos = 0U;
	UINT16 wMinTailPointBelongLogSecId = 0U;
	struct_PathPoint strTrainMinTail = { 0u };
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	cLocalCiId = GetSystemParaLocalCiId();
	chLocalCiType = GetLocalCiType();

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭进路所属ID*/
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);

		/*获取锁闭所属进路是否是引导进路检查结果*/
		chRRouteCheck = CheckRouteStateNotYinDaoLock(wRLockBelongRouteId);
		
		if ((CI_TYPE_TCC == chLocalCiType) || (CI_TYPE_CLD == chLocalCiType))
		{
			/* 获取进路类型*/
			chRouteType = GetConfigRouteType(wRLockBelongRouteId);
		}
		else
		{
			/* 获取进路类型*/
			chRouteType = GetRouteType(wRLockBelongRouteId);
		}

		/*获取逻辑区段管理物理区段、进路最后一个物理区段*/
		wLgcRelativePhy = GetLgcSecRelativePhySecId(wLogSectionId);
		wRouteLastPhy = GetRouteLastPhySectionId(wRLockBelongRouteId);

		/*获取资源公共标志*/
		chLgcResShareFlag = GetLogSecResShareFlag(wLogSectionId);

		/*自动进路 || 自动信号 :自动办理*/
		
		if (0u != wRLockBelongRouteId)
		{
			cRouteCId = GetRouteBelongCiId(wRLockBelongRouteId);
		}
		else
		{
			/*无操作*/
		}

		if (0u != wRLockBelongRouteId)
		{
			/*获取自动进路类型:普通自动进路、自动折返进路*/
			autoRouteType = GetRouteAutoRouteSetState(wRLockBelongRouteId);
			/*获取进路当前是否为自动信号进路*/
			autoSigRouteType = GetRouteAutoSigSetState(wRLockBelongRouteId);
		}
		else
		{
			; /*不处理*/
		}

		if ((ROUTE_TYPE_RETURN == chRouteType)&&(wLgcRelativePhy ==wRouteLastPhy))
		{
			chLgcResReturn = LOGIC_SECTION_TRAIN_RETURN_YES;
		}
		else
		{
			chLgcResReturn = LOGIC_SECTION_TRAIN_RETURN_NO;
		}
		strTrainMinTail.wLinkId = GetTrainMinTailLink(wTrnId);
		strTrainMinTail.dwOffset = GetTrainMinTailOffset(wTrnId);
		wMinTailPointBelongLogSecId = GetPointBelongLogSec(strTrainMinTail);
		trainInLockRoute = GetTrainInLgcPRLock(wLogSectionId, wMinTailPointBelongLogSecId);
		chLgcSecResCanAdd = GetLgcSecResCanAdd(wLogSectionId, wTrnId);
		if ((CI_SUCCESS == chRRouteCheck) && (ROUTE_TYPE_DIAOCHE != chRouteType))
		{
			if (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			{
				if ((NULL == pLogicSecTrainResInfo)
					&& (((LOGIC_SECTION_RES_SHARE_YES == chLgcResShareFlag)&&(CI_SUCCESS == chLgcSecResCanAdd))
						|| (CI_SUCCESS== trainInLockRoute)))
				{
					/*没有该列车资源，且公共资源或列车在进路中*/
					if ((0u != cLocalCiId) && ((cLocalCiId == cRouteCId)))
					{
						/*当前逻辑区段为办理进路锁闭，无任何所属列车*/
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].wTrainId = wTrnId;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_YES;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
						LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum].chLogicReturnState = chLgcResReturn;
						LogicSectionDataStru[wBufIndex].chTrainInfoSum += 1U;

						
						if ((ROUTE_AUTOROUTE_NORMAL == autoRouteType)
							|| (ROUTE_AUTOROUTE_NORMAL == autoProtRouteType)
							|| (ROUTE_AUTOSIGROUTE_YES == (ROUTE_AUTOSIGROUTE_YES & autoSigRouteType)))
						{
							; /*自动进路或自动信号 不取消共享资源属性*/
						}
						else
						{
							trainInRoutePos = dsuTrainMinHeadCrossSignal(wTrnId, wRLockBelongRouteId);
							if ((TRAIN_ENTER_ROUTE_FULL == trainInRoutePos) || (TRAIN_ENTER_ROUTE_TAIL == trainInRoutePos))
							{
								; /*不处理 V12.0.2变更2*/
							}
							else
							{
								SetLogSecResShareFlag(wLogSectionId, LOGIC_SECTION_RES_SHARE_NO);
							}
						}
						
					}
					else if(0u != cRouteCId)
					{
						/* 向相邻联锁发送逻辑区段资源申请 */
						SetLogSecResReqOtherCIId(wLogSectionId,cRouteCId);
						SetLogSecResReqTrainId(wLogSectionId, wTrnId);
					}
					else
					{
						/*无操作*/
					}
				}
				else if (NULL != pLogicSecTrainResInfo)
				{
					pLogicSecTrainResInfo->chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_YES;
				}
				else
				{
					/*无操作*/
				}
			}
			else
			{

			}
		}
		else
		{

		}
	}
	else
	{
		
	}
}

/*
* 功能描述： 获取指定列车逻辑区段锁闭关联逻辑进路ID
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		申请列车ID
* 返回值  ：=0，不存在该车逻辑进路；>0 该车逻辑进路ID
*/
UINT16 GetLogSecBelongLogRouteId(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16 wRLockBelongLogRouteId = 0U;
	UINT8 wLogSecLockBelLogRouteSum = 0U;
	UINT16 wLogicalRouteApplyResTrainId = 0U;
	UINT16 retVal = 0U;
	UINT8 ii = 0U;
	LogSecLockBelLogRouteStruct* pLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSectionId);
		pLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSectionId);
		if (NULL != pLogSecLockBelLogRouteData)
		{
			for (ii = 0U; ii < wLogSecLockBelLogRouteSum; ii++)
			{
				wRLockBelongLogRouteId = pLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
				wLogicalRouteApplyResTrainId = GetLogicalRouteApplyResTrainId(wRLockBelongLogRouteId);

				if (wTrnId == wLogicalRouteApplyResTrainId)
				{
					retVal = wRLockBelongLogRouteId;
					break;
				}
			}
		}
	}
	return retVal;
}


/*
* 功能描述： 逻辑进路列车申请逻辑区段请求
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		申请列车ID
* 返回值  ： VOID
*/
void SetLogRouteLogSecTrainLockApply(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT8 wLogSecLogLockState = 0U;
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;

	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	wLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);
	if (LOG_SECTION_LOGLOCK_NORMAL == wLogSecLogLockState)
	{
		if (NULL != pLogicSecTrainResInfo)
		{
			pLogicSecTrainResInfo->chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_YES;
		}
		else
		{
			/*无操作*/
		}
	}
}

/*
* 功能描述： 获取指定逻辑区资源列车信息
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： NULL:  获取失败
*			 !NULL: 逻辑区资源列车信息
*/
UINT8 GetLgcSecResCanAdd(const UINT16 wLogSectionId,const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16 wRLockBelongRouteId = 0U;
	UINT16 wRLockStartSignalId = 0U;
	UINT16 wPLockStartSignalId = 0U;
	UINT16 wPLockEndSignalId = 0U;
	UINT16 wRLockLightUpTrainId = 0U;
	UINT16 wPLockLightUpTrainId = 0U;
	UINT16 wRouteLockOverLapId = 0U;
	UINT8  chOverLapBelongCiId = 0U;
	UINT8 chTrainCrossPLockStt = 0U;
	UINT8 chTrainCrossRLockStt = 0U;
	UINT8 cRouteCId = 0u;
	UINT8 cLocalCiId = 0u;
	UINT8 chLgcResShareFlag = 0U;
	UINT8 autoRouteType = 0U;
	UINT8 autoSigRouteType = 0U;
	UINT8 autoProtRouteType = 0U;
	UINT8 chLocalTiocCanAddFlag = CI_ERROR;
	UINT8 chHitSoftWallSwitch = 0U;/*撞软墙开关状态*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	cLocalCiId = GetSystemParaLocalCiId();
	chHitSoftWallSwitch = GetHitSoftWallSwitch();

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭进路所属ID*/
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);

		if (0u != wRLockBelongRouteId)
		{
			cRouteCId = GetRouteBelongCiId(wRLockBelongRouteId);
		}
		else
		{
			/*无操作*/
		}
		if (0u != wRLockBelongRouteId)
		{
			/*获取自动进路类型:普通自动进路、自动折返进路*/
			autoRouteType = GetRouteAutoRouteSetState(wRLockBelongRouteId);
			/*获取进路当前是否为自动信号进路*/
			autoSigRouteType = GetRouteAutoSigSetState(wRLockBelongRouteId);
			/* 获取进路锁闭始端信号机ID*/
			wRLockStartSignalId = GetRouteStartSignalId(wRLockBelongRouteId);
			wRLockLightUpTrainId = GetSignalLightUpTrainId(wRLockStartSignalId);
			chTrainCrossRLockStt = dsuTrainCrossSignal(wTrnId, wRLockBelongRouteId);
		}
		else
		{
			; /*不处理*/
		}

		if (0U != cLocalCiId)
		{
			if (cLocalCiId == cRouteCId)
			{
				if ((wTrnId & 0x00ffU) == wRLockLightUpTrainId)
				{
					chLocalTiocCanAddFlag = CI_SUCCESS;
				}
				else
				{
					if ((TRAIN_ENTER_ROUTE_FULL == chTrainCrossRLockStt) || (TRAIN_ENTER_ROUTE_TAIL == chTrainCrossRLockStt))  /*修缺陷YF0083-952，2023-07-03*/
					{

						chLocalTiocCanAddFlag = CI_SUCCESS;
					}
					else
					{
						; /*不处理*/
					}
				}
			}
			else if (0U != wRLockBelongRouteId)
			{
				chLocalTiocCanAddFlag = CI_SUCCESS;
			}
			else
			{
				; /*不处理*/
			}

			/*增加撞软墙开关，若开关关闭，自动进路/自动信号也只允许最接近列车申请资源*/
			if (((ROUTE_AUTOROUTE_NORMAL == autoRouteType)
				|| (ROUTE_AUTOROUTE_NORMAL == autoProtRouteType)
				|| (ROUTE_AUTOSIGROUTE_YES == (ROUTE_AUTOSIGROUTE_YES & autoSigRouteType)))
				&& (FUNC_HITSOFTWALL_ON == chHitSoftWallSwitch))
			{
				chLocalTiocCanAddFlag = CI_SUCCESS; /*自动进路或自动信号 不取消共享资源属性*/
			}
			else
			{
				; /*不处理*/
			}
		}
		else
		{
			chLocalTiocCanAddFlag = CI_ERROR;
		}
	}
	return chLocalTiocCanAddFlag;
}


/*
* 功能描述： 获取列车是否在逻辑区段锁闭所处进路中
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR:  不在
*			 CI_SUCCESS:在 
*/
UINT8 GetTrainInLgcPRLock(const UINT16 wLogSectionId, const UINT16 wMinTailPointBelongLogSecId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16 wRLockBelongRouteId = 0U;
	UINT16 wTrainMinTailLockBelongRouteId = 0U;
	UINT8 cLocalCiId = 0u;
	UINT8 chLocalTiocCanAddFlag = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	cLocalCiId = GetSystemParaLocalCiId();
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭进路所属ID*/
		wRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);

		if ((0U != cLocalCiId)&&(0U!=wRLockBelongRouteId))
		{

			wTrainMinTailLockBelongRouteId = GetLogSecLockBelongRoute(wMinTailPointBelongLogSecId);
			if (wRLockBelongRouteId == wTrainMinTailLockBelongRouteId)
			{
				chLocalTiocCanAddFlag = CI_SUCCESS;
			}
			else
			{
				; /*DO NOTHING*/
			}
		}
		else
		{
			; /*DO NOTHING*/
		}
	}
	else
	{
		chLocalTiocCanAddFlag = CI_ERROR; /*异常下标，返回错误*/
	}
	return chLocalTiocCanAddFlag;
}

/*
* 功能描述： 获取指定逻辑区资源列车信息
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： NULL:  获取失败
*			 !NULL: 逻辑区资源列车信息
*/
UINT16 GetLogSecTrainIdByIndex(const UINT16 wLogSectionId, const UINT8 chIndex)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16  wRetVal = 0U;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		
		if (LOGIC_SECTION_RES_SUM_MAX > chIndex)
		{
			
			wRetVal = LogicSectionDataStru[wBufIndex].szTrainResData[chIndex].wTrainId;
		}
		else
		{
			wRetVal = 0U;
		}
	}
	else
	{
		wRetVal = 0U;
	}
	return wRetVal;
}

/*
* 功能描述： 列车逻辑区段可用状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		 列车ID
*			 const UINT8  chUseState	 状态可用
* 返回值  ： VOID
* 修复bug YF0083-119
*/
void SetLogSecTrainUseState(const UINT16 wLogSectionId, const UINT16 wTrnId,const UINT8 chUseState)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chLogRouteLogicLockState = 0U;		/*逻辑进路逻辑区段锁闭状态*/
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	chLogRouteLogicLockState = GetLogSecLogLockState(wLogSectionId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOGLOCK_NORMAL == chLogRouteLogicLockState))
		{
			if ((LOGIC_SECTION_RES_USABLE == chUseState)
				|| (LOGIC_SECTION_RES_UNUSABLE == chUseState))
			{

				if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
				{
					for (ii = 0U; ii < chTrainSum; ii++)
					{
						if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
						{
							LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicResUsable = chUseState;
							break;
						}
						else
						{

						}
					}
				}
				else
				{

				}
			}
			else
			{

			}
		}
		else
		{
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
					{
						LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicResUsable = LOGIC_SECTION_RES_UNUSABLE;
						break;
					}
					else
					{

					}
				}
			}
			else
			{

			}
		}
	}
	else
	{

	}
}

/*
* 功能描述： 获取列车逻辑区段申请状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		 列车ID
* 返回值  ： 0失败 0x55:已申请 0xaa:未申请
* 修复bug YF0083-119
*/
UINT8 GetLogSecTrainApply(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chRetVal = 0U;
	UINT8 chLogRouteLogicLockState = 0U;		/*逻辑进路逻辑区段锁闭状态*/
	chLogRouteLogicLockState = GetLogSecLogLockState(wLogSectionId);
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOGLOCK_NORMAL == chLogRouteLogicLockState))
		{

			chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
					{
						chRetVal = LogicSectionDataStru[wBufIndex].szTrainResData[ii].chTrainApplyState;
						break;
					}
					else
					{

					}
				}
			}
			else
			{
				chRetVal = 0U;
			}
		}
		else
		{
			chRetVal = 0U;
		}
	}
	else
	{
		chRetVal = 0U;
	}

	return chRetVal;
}

/*
* 功能描述： 设置列车逻辑区段释放状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		 列车ID
*			 const UINT8  chUseState	 状态可用
*			const UINT8 chTrainlevel 列车级别：本联锁解锁命令：0  相邻联锁设置VBTV级为0X03 其他设置UR 0X01
* 返回值  ： VOID
* 修复bug YF0083-119
*/
void SetLogSecTrainRelease(const UINT16 wLogSectionId, const UINT16 wTrnId, const UINT8 chTrainlevel)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT32 dwCurCycNum = 0U;
	UINT8 wLogSecLogLockState = 0U;
	dwCurCycNum = Get2oo2CurCycleNum();
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOGLOCK_NORMAL == wLogSecLogLockState))
		{
			chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
					{
						LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicUnlockState = LOGIC_SECTION_TRAIN_UNLOCK_YES;
						LogicSectionDataStru[wBufIndex].szTrainResData[ii].dwRcvUnlockCmdCyc = dwCurCycNum;
						LogicSectionDataStru[wBufIndex].szTrainResData[ii].chTrainLevel = chTrainlevel;
						break;
					}
					else
					{

					}
				}
			}
			else
			{
				; /**/
			}
		}
		else
		{
			; /**/
		}
	}
	else
	{
		; /**/
	}
}

/*
* 功能描述： 获取列车逻辑区段释放状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		 列车ID
* 返回值  ： 0失败 0x55:已申请 0xaa:未申请
*/
UINT8 GetLogSecTrainRelease(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chRetVal = 0U;
	UINT32 dwCurCycNum = 0U;
	UINT8 wLogSecLogLockState = 0U;
	dwCurCycNum = Get2oo2CurCycleNum();
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOGLOCK_NORMAL == wLogSecLogLockState))
		{

			chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
					{
						if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].dwRcvUnlockCmdCyc == dwCurCycNum)
						{
							/*当周期收到才算 申请有效*/
							chRetVal = LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicUnlockState;
						}
						else
						{
							chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
						}
						break;
					}
				}
			}
			else
			{
				chRetVal = 0U;
			}
		}
		else
		{
			chRetVal = 0U;
		}
	}
	else
	{
		chRetVal = 0U;
	}

	return chRetVal;
}

/*
* 功能描述： 获取逻辑区段资源释放状态（有列车申请过，则返回已申请）
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* 返回值  ： 0失败 0x55:已申请 0xaa:未申请
*/
UINT8 GetLogSecReleaseFlag(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
	UINT32 dwCurCycNum = 0U;
	dwCurCycNum = Get2oo2CurCycleNum();
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState))
		{

			chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if ((LogicSectionDataStru[wBufIndex].szTrainResData[ii].dwRcvUnlockCmdCyc == dwCurCycNum)
						&&(LOGIC_SECTION_TRAIN_UNLOCK_YES == LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicUnlockState))
					{
						/*当周期收到才算 申请有效*/
						chRetVal = LogicSectionDataStru[wBufIndex].szTrainResData[ii].chLogicUnlockState;
						break;
					}
					else
					{
						chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
					}
				}
			}
			else
			{
				chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
			}
		}
		else
		{
			chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
		}
	}
	else
	{
		chRetVal = LOGIC_SECTION_TRAIN_UNLOCK_NO;
	}

	return chRetVal;
}

/*
* 功能描述： 获取逻辑区段释放列车级别
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT16 wTrnId		 列车ID
* 返回值  ： 0本联锁列车  0x03:相邻联锁VBTC 0x01:相邻联锁非VBTC
*/
UINT8 GetLogSecReleaseTrainLevel(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chTrainSum = 0U;
	UINT8 ii = 0U;
	UINT8 chRetVal = TRAIN_LEVEL_UR;
	UINT32 dwCurCycNum = 0U;
	UINT8 wLogSecLogLockState = 0U;
	dwCurCycNum = Get2oo2CurCycleNum();
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wLogSecLogLockState = GetLogSecLogLockState(wLogSectionId);
		if ((LOG_SECTION_LOCK_PROTECT == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)
			|| (LOG_SECTION_LOGLOCK_NORMAL == wLogSecLogLockState))
		{

			chTrainSum = LogicSectionDataStru[wBufIndex].chTrainInfoSum;
			if (LOGIC_SECTION_RES_SUM_MAX > chTrainSum)
			{
				for (ii = 0U; ii < chTrainSum; ii++)
				{
					if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].wTrainId == wTrnId)
					{
						if (LogicSectionDataStru[wBufIndex].szTrainResData[ii].dwRcvUnlockCmdCyc == dwCurCycNum)
						{
							/*当周期收到才算 申请有效*/
							chRetVal = LogicSectionDataStru[wBufIndex].szTrainResData[ii].chTrainLevel;
						}
						else
						{
							chRetVal = TRAIN_LEVEL_UR;
						}
						break;
					}
				}
			}
			else
			{
				chRetVal = 0U;
			}
		}
		else
		{
			chRetVal = 0U;
		}
	}
	else
	{
		chRetVal = 0U;
	}

	return chRetVal;
}

#if 0
/*
* 功能描述： 列车释放逻辑区段资源请求
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT16 wTrnId，列车ID
* 返回值  ： VOID
*/
void LogSecTrainLockRelease(const UINT16 wLogSectionId, const UINT16 wTrnId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	LogicTrainResStruct * pLogicSecTrainResInfo = NULL;
	UINT8 routeDir = 0u;
	UINT16 i = 0u;
	UINT16 j = 0u;
	UINT16 routeId = 0u;
	UINT16 logBelongAxisId = 0u;  /*逻辑区段所属的计轴区段*/
	UINT16 logBelongPhyId = 0u; 
	UINT8 checkValue = 0u;
	UINT16 logRoute = 0u;
	UINT8 logUlockState = 0u;
	UINT16* routeLogIdBuf = NULL;
	UINT16 fLockLogId = 0u;
	UINT16 dlockLogId = 0u;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取逻辑区段数组下标*/
	pLogicSecTrainResInfo = GetLogSecTrainInfoById(wLogSectionId, wTrnId);
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if((NULL != pLogicSecTrainResInfo)
			&&(1u == LogicSectionDataStru[wBufIndex].chTrainInfoSum)
			&&((LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)||(LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)))
		{
			/*逻辑区段只有一列车申请了资源,清本车资源*/
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum-1u].wTrainId = 0u;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum-1u].chTrainApplyState = LOGIC_SECTION_TRAIN_APPLY_NO;
			LogicSectionDataStru[wBufIndex].szTrainResData[LogicSectionDataStru[wBufIndex].chTrainInfoSum-1u].chLogicResUsable = LOGIC_SECTION_RES_USABLE;	
			LogicSectionDataStru[wBufIndex].chTrainInfoSum -= 1u;
			/*获取进路ID，进路方向，进路第一个正常锁闭的逻辑区段*/
			routeId = GetLogSecLockBelongRoute(wLogSectionId);
			routeDir = GetRouteDirection(routeId);
			routeLogIdBuf = GetRouteLogSectionIdBuf(routeId);
			fLockLogId = GetRouteFirstNormalLockLogId(routeId);
			dlockLogId = GetRouteFirstDelayLockLogId(routeId);
			if((wLogSectionId == routeLogIdBuf[0])&&((wLogSectionId == fLockLogId)||(wLogSectionId == dlockLogId)))
			{/*设置逻辑区段立即解锁,清延时，进路状态转移*/
				SetLogSecLockState(wLogSectionId,LOG_SECTION_LOCK_NO,routeId,routeDir);
				SetLogUnlockStartCycNum(wLogSectionId,0u);
			    SetRouteStateManage(routeId, ROUTE_STATE_AUTO_UNLOCK);
		    }
			else if((wLogSectionId == fLockLogId)||(wLogSectionId == dlockLogId))
			{/*设置逻辑区段解锁，清延时*/
				SetLogSecLockState(wLogSectionId,LOG_SECTION_LOCK_NO,routeId,routeDir);
				SetLogUnlockStartCycNum(wLogSectionId,0u);
			}
			else
			{
				/*不满足顺序出清，不解锁*/
			}
			logBelongAxisId = GetLogSecBelongAxisSecId(wLogSectionId);
			logBelongPhyId = GetAxisSecRelativePhySecId(logBelongAxisId);
			checkValue = CheckPhyInLogUlock(logBelongPhyId,routeId,&logRoute);
			if(CI_SUCCESS == checkValue)
			{
				if(logBelongPhyId == GetRouteLastSwichPhySecId(routeId))
				{
					/*将本进路防护锁闭道岔解锁,此处可以解锁跨联锁的防护道岔*/
					SetRouteRelatedProtectSwitchLockState(routeId, SWITCH_LOCK_PROTECT_CANCEL);
				}
				if(0u == logRoute)
				{ /*逻辑区段全部解锁，且不存在逻辑区段锁闭属于其他进路,设置物理区段解锁*/
					SetPhySecLockState(logBelongPhyId, PHYSICAL_SECTION_LOCK_NO, routeId, routeDir);
				}
			}
			logUlockState = CheckRouteLogSecHaveUnLock(routeId);
			if(CI_SUCCESS == logUlockState)
			{
				/*进路区段全部解锁*/
				if (ROUTE_STATE_FLAG_YES == GetRouteStateFlag(routeId))
				{/*CBTC追踪办理进路标志有效，则不改变进路状态，继续保持自动解锁正常（此时进路区段已全部解锁）*/
				}
				else
				{/*CBTC追踪办理进路标志无效，则设置进路空闲*/
					SetRouteStateManage(routeId, ROUTE_STATE_IDLE);  /*设置进路空闲*/
				} 
			}
		}
		else if((NULL != pLogicSecTrainResInfo)
		    	&&(1u < LogicSectionDataStru[wBufIndex].chTrainInfoSum)
		        &&((LOG_SECTION_LOCK_NORMAL == LogicSectionDataStru[wBufIndex].LogLockState)||(LOG_SECTION_LOCK_DELAY == LogicSectionDataStru[wBufIndex].LogLockState)))
		{
			/*逻辑区段有多列车申请了资源,清本车ID,整理逻区段列车数组*/
			for(i = 0u;i < LogicSectionDataStru[wBufIndex].chTrainInfoSum;i++)
			{
				if(wTrnId == LogicSectionDataStru[wBufIndex].szTrainResData[i].wTrainId)
				{
					j = i;
				}
				else
				{
					LogicSectionDataStru[wBufIndex].szTrainResData[j].wTrainId = LogicSectionDataStru[wBufIndex].szTrainResData[i].wTrainId;
					LogicSectionDataStru[wBufIndex].szTrainResData[j].chTrainApplyState == LogicSectionDataStru[wBufIndex].szTrainResData[i].chTrainApplyState;
					LogicSectionDataStru[wBufIndex].szTrainResData[j].chLogicResUsable == LogicSectionDataStru[wBufIndex].szTrainResData[i].chLogicResUsable;
					j += 1u;
				}
			}
			LogicSectionDataStru[wBufIndex].chTrainInfoSum -= 1u;
		}
		else
		{
			/*逻辑区段无列车申请，不处理*/
		}

	}
	else
	{
		/*逻辑区段ID不合法*/
	}

}
#endif

/*
* 功能描述：设置指定逻辑区段防护锁闭所属进路ID
* 参数说明：const UINT16 wLogSectionId 逻辑区段ID
*           const UINT16 wPLockRouteId 防护锁闭所属进路ID
* 返 回 值：无
* Created By LQ 2024.06.11
*/
void SetLogSecPLockRouteId(const UINT16 wLogSectionId, const UINT16 wPLockRouteId)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if ((LOGIC_SECTION_SUM_MAX > wBufIndex) && (ROUTE_SUM_MAX > wPLockRouteId))
	{
		LogicSectionDataStru[wBufIndex].wPLockBelongRouteId = wPLockRouteId;  /*设置防护锁闭所属进路ID*/
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述： 获取指定逻辑防护区段锁闭所属进路
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段锁闭所属进路
*/
UINT16 GetLogSecPLockRouteId(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].wPLockBelongRouteId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取逻辑区段发送资源请求的其他联锁ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0u	：错误
*		  ： 其他 ：联锁ID
*/
UINT8 GetLogSecResReqOtherCIId(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = 0u;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicSectionDataStru[wBufIndex].cResReqOtherCIId;
	}
	else
	{
		;/* 返回0u */
	}
	return chRetVal;
}
/*
* 功能描述： 设置逻辑区段发送资源请求的其他联锁ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			const UINT8 cOtherId,其他联锁ID
*
*/
void SetLogSecResReqOtherCIId(const UINT16 wLogSectionId, const UINT8 cOtherId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		LogicSectionDataStru[wBufIndex].cResReqOtherCIId = cOtherId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取逻辑区段发送其他CI资源请求的列车ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0u	：错误
*		  ： 其他 ：列车ID
*/
UINT16 GetLogSecResReqTrainId(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT16 chRetVal = 0u;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicSectionDataStru[wBufIndex].wResReqTrainId;
	}
	else
	{
		;/* 返回0u */
	}
	return chRetVal;
}
/*
* 功能描述： 设置逻辑区段发送其他CI资源请求的列车ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			const UINT16 wTrainId,列车ID
*
*/
void SetLogSecResReqTrainId(const UINT16 wLogSectionId, const UINT16 wTrainId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		LogicSectionDataStru[wBufIndex].wResReqTrainId = wTrainId;
	}
	else
	{
		;
	}
}

/**
* @brief 设置逻辑区段所有资源的折返状态
* @param UINT16 wLogicId
* @param UINT8 chFlag
* @return 无
*/
void SetLogSecAllTrainReturnState(const UINT16 wLogicId, const UINT8 chFlag)
{
	UINT8 chTrainSum = 0u;
	LogicTrainResStruct * pTrainInLogic = NULL;
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;

	chTrainSum = GetLogSecTrainInfoSum(wLogicId);
	pTrainInLogic = GetLogSecTrainInfo(wLogicId);
	
	if (0u == chTrainSum) 
	{
		;
	}
	else
	{
		for (chTrainIndex = 0u; chTrainIndex < chTrainSum; chTrainIndex++)
		{
			wTrainId = pTrainInLogic[chTrainIndex].wTrainId;
			SetLogSecTrainReturnState(wLogicId, wTrainId, chFlag);
		}
	}
}

/**
* @brief 设置所有逻辑区段占用状态
* @param 无
* @return 无
*/
void SetAllLgcOccupyState(void)
{
	UINT16 wLgcSum = 0u;
	UINT16 wIndex = 0u;
	UINT16 wLgcId = 0u;
	UINT8 chLgcStatus = 0u;

	wLgcSum = GetTotalLogSecCurNum();
	for (wIndex = 0u; wIndex < wLgcSum; wIndex++)
	{
		wLgcId = GetLogicSecId(wIndex);
		chLgcStatus = ssp_GetSecStatus(wLgcId);
		if (STATUS_CT == chLgcStatus)
		{/* 逻辑区段VBTC占用，有通信车 */
			SetLogSecOccupyState(wLgcId, LOGICSECTION_OCCUPY_CT);
			SetLogSecTXOccupyState(wLgcId, LOGICSECTION_OCCUPY_TX);
		}
		else if (STATUS_FREE == chLgcStatus)
		{/* 逻辑区段空闲，无通信车 */
			SetLogSecOccupyState(wLgcId, LOGICSECTION_OCCUPY_NO);
			SetLogSecTXOccupyState(wLgcId, LOGICSECTION_OCCUPY_NO_TX);
			
		}
		else if(STATUS_AT == chLgcStatus)
		{/* 逻辑区段有通信RM车占用，设置UT，且有通信车 */
			SetLogSecOccupyState(wLgcId, LOGICSECTION_OCCUPY_UT);
			SetLogSecTXOccupyState(wLgcId, LOGICSECTION_OCCUPY_TX);
		}
		else
		{/* 逻辑区段UT占用 */
			SetLogSecOccupyState(wLgcId, LOGICSECTION_OCCUPY_UT);
			SetLogSecTXOccupyState(wLgcId, LOGICSECTION_OCCUPY_NO_TX);
		}
	}
}

/*
* @brief： 获取指定ID逻辑区段共享资源标志
* @param： const UINT16 wLgcSecId, 逻辑区段ID
* @return  ： 0x55: 共享资源
*			  0xaa: 非共享资源
*             CI_ERROR:失败
*/
UINT8 GetLogSecResShareFlag(const UINT16 wLgcSecId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8  funRetVal = 0u;

	/*获取区段数组下标*/
	bufIndex = GetlogSectionBufIndex(wLgcSecId);  

	/*下标是否合法*/
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/*返回存储下标*/
		funRetVal = LogicSectionDataStru[bufIndex].chResShareFlag;
	}
	else
	{
		/*返回错误*/
		funRetVal = CI_ERROR;
	}
	return funRetVal;
}

/*
* @brief： 设置指定ID逻辑区段共享资源标志
* @param： const UINT16 wLgcSecId, 逻辑区段ID
* @param： const UINT16 chShrFlag, 公共资源标志
* @return 无
*/
void SetLogSecResShareFlag(const UINT16 wLgcSecId, const UINT8 chShrFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(wLgcSecId);  /*获取道岔数组下标*/

	/*下标是否合法*/
	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		/*标志状态是否合法*/
		if ((LOGIC_SECTION_RES_SHARE_YES == chShrFlag) ||
			(LOGIC_SECTION_RES_SHARE_NO == chShrFlag))
		{
			/*设置标志位*/
			LogicSectionDataStru[bufIndex].chResShareFlag = chShrFlag;  /*逻辑区段共享资源标志*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 删除指定逻辑区段列车资源
* 参数说明： UINT16 wLogSecId,   逻辑区段ID
*			 UINT8 chTrainId  删除列车资源下标
* 返回值  ：
*/
void RemoveLgcSecResTrain(UINT16 wLogSecId, UINT16 wTrainId)
{
	UINT8 jj = 0U;
	UINT16 wLgcResTrainId= 0U;
	UINT8 chLgcResTrainSum = 0U;
	UINT8 chKeepWork = CI_ERROR;
	UINT16 wLgcBufIndex = 0U;
	UINT8 chNeedKeepSum = 0U;

	LogicSectionDataStruct *pstLgcSecInfo = NULL;
	chLgcResTrainSum = GetLogSecTrainInfoSum(wLogSecId);
	pstLgcSecInfo = GetLogicSecData();
	wLgcBufIndex = GetlogSectionBufIndex(wLogSecId);
	if ((NULL!=pstLgcSecInfo)
		&&(CI_ERROR != chLgcResTrainSum))
	{
		chKeepWork = CI_SUCCESS; /*继续执行*/
	}
	else
	{
		chKeepWork = CI_ERROR;
	}

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

			if (wLgcResTrainId == wTrainId) 
			{
				/*删除该列车对应逻辑区段资源*/
				(void)ComMemSet((void *)&pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj], (UINT16)sizeof(LogicTrainResStruct), 0U);
				debug_infor_printf((const)"LogSecRes Remove LgcId: %d TrainId:%d  Cyc\n"
					, wLogSecId
					, wTrainId
					, Get2oo2CurCycleNum());
			}
			else
			{
				pstLgcSecInfo[wLgcBufIndex].szTrainResData[chNeedKeepSum++] = pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj];
			}

		}
		pstLgcSecInfo[wLgcBufIndex].chTrainInfoSum = chNeedKeepSum;
	}
	else
	{
	}
}

/*
* 功能描述： 清除本TIOC的逻辑区段临时限速标志
* 参数说明：
* 返回值  ： 
*/
void ClearLocalTiocLogSecTsr(void)
{
	UINT16 wLgcSum = 0u;
	UINT16 wIndex = 0u;
	UINT16 wLgcId = 0u;
	UINT8 cLogSecTiocId = 0u;
	UINT8 cLocalTiocId = 0u;

	cLocalTiocId = GetSystemParaLocalCiId();
	wLgcSum = GetLogicSecCurSum();
	for (wIndex = 0u; wIndex < wLgcSum; wIndex++)
	{
		wLgcId = GetLogicSecId(wIndex);
		cLogSecTiocId = GetLogSecBelongCiId(wLgcId);

		if ((cLocalTiocId == cLogSecTiocId) && (0u != cLocalTiocId))
		{
			/* 仅重置本联锁的标志位 */
			SetLogSecLinShiXianSuState(wLgcId, LOGSEC_LSXS_SET_STATE_NO);
		}
	}
}

/*
* 功能描述： 获取临时限速数量
* 参数说明： 
* 返回值  ： 限速数量
*/
UINT8 GetTsrSum(void)
{
	return g_TsrSum;
}

/*
* 功能描述： 获取指定逻辑区段反位内最小临时限速值
* 参数说明：UINT16* minSpeed	最小临时限速值(出参)
*			UINT16 logSum		逻辑区段数量(入参)
*			UINT16 szLogId[]	逻辑区段ID(入参)
* 返回值  ： CI_ERROR	获取失败
*			CI_SUCCESS	获取成功
*/
UINT8 GetBackUpVobcMinTsr(UINT16* minSpeed, UINT16 logSum, UINT16 szLogId[])
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 cTsrSum = 0U;
	TsrDataStruct* pTsrData = NULL;
	UINT8 jj = 0u;
	UINT8 kk = 0U;
	UINT8 mm = 0U;

	pTsrData = GetTsrData();

	if (NULL != szLogId)
	{
		/* 获取限速数量 */
		cTsrSum = GetTsrSum();

		if (TSR_MAX_SUM >= cTsrSum)
		{
			chRetVal = CI_SUCCESS;
			for (jj = 0u; jj < cTsrSum; jj++)
			{
				if (pTsrData[jj].cSpeed < *minSpeed)
				{
					for (mm == 0U; mm < pTsrData[jj].cLogSecSum; mm++)
					{
						for (kk = 0U; kk < logSum; kk++)
						{
							if (pTsrData[jj].szLogSecId[mm] == szLogId[kk])
							{
								*minSpeed = pTsrData[jj].cSpeed;
							}
							else
							{
								;	/*不属于查询范围内的不进行判断，查询范围：车前到站台外方第一逻辑区段*/
							}
						}
					}
				}
				else
				{
					;		/*速度大的不考虑，继续查最小的限速*/
				}
			}
		}
		else
		{
			/*临时限速数量错误 停止组包*/
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		;	/*入参错误返回失败*/
	}

	return chRetVal;
}
/*
* 功能描述： 设置临时限速数量
* 参数说明： UINT8 cTsrSum 限速数量
* 返回值  ： 限速数量
*/
void SetTsrSum(UINT8 cTsrSum)
{
	if (TSR_MAX_SUM >= cTsrSum)
	{
		g_TsrSum = cTsrSum;
	}
}

/*
* 功能描述： 获取临时限速数据
* 参数说明：
* 返回值  ： 限速数据
*/
TsrDataStruct* GetTsrData(void)
{
	return &g_TsrDataStru;
}

/*
* 功能描述： 设置临时本地临时限速数据
* 参数说明： UINT8 cTsrSum 限速数量
*			 TsrDataStruct* TsrData 限速数据
* 返回值  ： CI_ERROR失败;CI_SUCCESS 成功
*/
UINT8 SetLocalTsrData(UINT8 cTsrSum, TsrDataStruct* pTsrData,UINT8 cAllLineTsrState, UINT8 cAllLineTsrSpeed)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 i = 0u;
	UINT8 j = 0u;
	UINT8 x = 0u;
	UINT16 wLocalLogSecSum = 0u;
	UINT16 wLogSecId = 0u;
	UINT8 cLogSecTiocId = 0u;
	UINT8 cTiocId = 0u;
	UINT8 cLogSecTsrState = LOGSEC_LSXS_SET_STATE_INVALID;
	UINT8 cLogSecSwitchSum = 0u;
	LogsecSwitchStruct* pLgcSecSwitchStru = NULL;
	UINT8 cLogSecPosFlag = FLAG_UNSET;  /*逻辑区段定反位标志*/

	if ((TSR_MAX_SUM >= cTsrSum) && (NULL != pTsrData))
	{

		/* 更新全线临时限速信息 */
		if (0xAAu == cAllLineTsrState)
		{
			/* 存在全线临时限速 */
			SetAllLineTsrState(CI_ALL_LINE_TSR_VALID);
			SetAllLineTsrSpeed(cAllLineTsrSpeed);
		}
		else
		{
			/* 不存在全线临时限速 */
			SetAllLineTsrState(CI_ALL_LINE_TSR_UNVALID);
			SetAllLineTsrSpeed(0u);
		}

		/* 更新临时限速 */
		SetTsrSum(cTsrSum);
		/* 更新数据 */
		for (i = 0u; i < cTsrSum; i++)
		{
			g_TsrDataStru[i].cSpeed = pTsrData[i].cSpeed;
			g_TsrDataStru[i].cLogSecSum = pTsrData[i].cLogSecSum;

			for (j = 0u; j < g_TsrDataStru[i].cLogSecSum;j++)
			{
				g_TsrDataStru[i].szLogSecId[j] = pTsrData[i].szLogSecId[j];
			}
		}

		/* 更新逻辑区段上的临时限速 */
		cTiocId = GetSystemParaLocalCiId();
		wLocalLogSecSum = GetLogicSecCurSum();
		if (LOGIC_SECTION_SUM_MAX > wLocalLogSecSum)
		{
			for (x = 0u; x < wLocalLogSecSum;x++)
			{
				wLogSecId = GetLogicSecId(x);
				cLogSecTiocId = GetLogSecBelongCiId(wLogSecId);
				cLogSecPosFlag = FLAG_UNSET;  /*每遍历一个逻辑区段，清一次标志*/

				if ((0u != wLogSecId) && (UINT16_MAX != wLogSecId) && (0u != cLogSecTiocId) && (cLogSecTiocId == cTiocId))
				{
					/* 判断是否在临时限速中 */
					cRetVal = IsInTsrLogSecIdBuf(wLogSecId);
					cLogSecTsrState = GetLogSecLinShiXianSuSetState(wLogSecId);
					/*在临时限速中*/
					if (0U != cRetVal)
					{
						/*设置临时限速取值*/
						SetLogSecXiansuSpeed(wLogSecId, cRetVal);
						/* 需要设置临时限速 */
						if (LOGSEC_LSXS_SET_STATE_YES != cLogSecTsrState)
						{
							SetLogSecLinShiXianSuState(wLogSecId, LOGSEC_LSXS_SET_STATE_YES);
							ClearLgcSecBelongRtXsCfm(wLogSecId);
 						}
					}
					else
					{
						SetLogSecXiansuSpeed(wLogSecId, 0U);
						if (0xAAu == cAllLineTsrState)
						{
							/*未处于临时限速但全线临时限速有效，设置非道岔反位逻辑区段临时限速标志有效*/
							cLogSecSwitchSum = GetLogicSecSwitchSum(wLogSecId);  /*获取逻辑区段包含的道岔数量*/
							pLgcSecSwitchStru = GetLogicSecSwitchIdStru(wLogSecId);    /*获取逻辑区段包含的道岔ID*/
							if (NULL != pLgcSecSwitchStru)
							{
								for (j = 0u; j < cLogSecSwitchSum; j++)
								{
									if (SWITCH_POSITION_DINGWEI == pLgcSecSwitchStru->SwitchPosition)
									{
										/*继续遍历*/
									}
									else
									{
										cLogSecPosFlag = FLAG_SET;  /*逻辑区段存在道岔处于反位，停止遍历*/
										break;
									}
								}

								if ((FLAG_UNSET == cLogSecPosFlag) && (LOGSEC_LSXS_SET_STATE_YES != cLogSecTsrState))
								{
									/*逻辑区段未过道岔反位，且临时限速标志不是有效，设置临时限速标志有效*/
									SetLogSecLinShiXianSuState(wLogSecId, LOGSEC_LSXS_SET_STATE_YES);
									ClearLgcSecBelongRtXsCfm(wLogSecId);  /*清除临时限速确认状态*/
								}
								else
								{
									/*保持既有临时限速标志，不处理*/
								}
							}
							else
							{
								/*不处理*/
							}
						}
						else
						{
							/*未处于临时限速且全线临时限速无效，设置逻辑区段临时限速无效*/
							if (LOGSEC_LSXS_SET_STATE_NO != cLogSecTsrState)
							{
								SetLogSecLinShiXianSuState(wLogSecId, LOGSEC_LSXS_SET_STATE_NO);
							}
						}
					}
				}
			}
		}
		cRetVal = CI_SUCCESS;
	}
	else
	{
		; /* 返回失败 */
	}

	return cRetVal;
}

/************************************跳跃锁闭相关****************************************************/


/*
* 功能描述： 获取指定ID逻辑区段申请或释放跳跃锁闭命令的列车ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 列车ID
*/
UINT16 GetLogSecJumpLockTrainId(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);
	
	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取申请或释放跳跃锁闭命令的列车ID */
		retVal = LogicSectionDataStru[bufIndex].JumpLockTrainId;
	}
	else
	{
		/** 获取数据失败 */
		retVal = 0u;
	}
	return retVal;
}

/*
* 功能描述： 设置指定ID逻辑区段申请或释放跳跃锁闭命令的列车ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT16 trainId, 列车ID
* 返回值  ： 无
*
*/
void SetLogSecJumpLockTrainId(const UINT16 logSectionId, const UINT16 trainId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	
	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);  

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 无列车申请或释放过跳跃锁闭命令 */
		if (((TRAIN_ID_MIN < trainId) && (TRAIN_ID_MAX > trainId))
			&& (0u == LogicSectionDataStru[bufIndex].JumpLockTrainId))
		{
			/** 设置申请或释放跳跃锁闭命令的列车ID */
			LogicSectionDataStru[bufIndex].JumpLockTrainId = trainId;
		}
		else
		{
			/** 不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述： 清除指定ID逻辑区段申请跳跃锁闭命令的列车ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 无
*
*/
void ClearLogSecJumpLockTrainId(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 清除申请跳跃锁闭命令的列车ID */
		LogicSectionDataStru[bufIndex].JumpLockTrainId = 0u;
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述： 判断跳跃锁闭命令的列车ID与所存逻辑区段跳跃锁闭列车ID是否相同
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT16 trainId, 列车ID
* 返回值  ： CI_ERROR 不是同一列车
			 CI_SUCCESS 是同一列车
*
*/
UINT8 JudgeLogSecJumpLockRelTrainId(const UINT16 logSectionId, const UINT16 trainId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;
	UINT16 logSecTrainId = 0u;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 跳跃锁闭释放命令列车与申请列车ID相同 */
		if ((TRAIN_ID_MIN < trainId) && (TRAIN_ID_MAX > trainId))
		{
			logSecTrainId = GetLogSecJumpLockTrainId(logSectionId);
			if (trainId == logSecTrainId)
			{
				/** 命令ID和跳跃锁闭列车ID相同 */
				retVal = CI_SUCCESS;
			}
			else
			{
				retVal = CI_ERROR;/** 不做处理 */
			}
		}
		else
		{
			/** 不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
	return retVal;
}

#if 0

/*HERE
* 功能描述： 获取指定ID逻辑区段跳跃锁闭申请标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭申请标志
*/
UINT8 GetLogSecJumpLockApplyFlag(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogJumpLockApplyFlag;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭申请标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpLockApplyFlag, 跳跃锁闭申请标志
* 返回值  ： 无
*
*/
void SetLogSecJumpLockApplyFlag(const UINT16 logSectionId, const UINT8 jumpLockApplyFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGIC_SECTION_JUMPLOCK_APPLY_NO == jumpLockApplyFlag) || (LOGIC_SECTION_JUMPLOCK_APPLY_YES == jumpLockApplyFlag))
		{
			LogicSectionDataStru[bufIndex].LogJumpLockApplyFlag = jumpLockApplyFlag;  /*逻辑区段跳跃锁闭申请标志*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭释放标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭申请标志
*/
UINT8 GetLogSecJumpLockRelaseFlag(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogJumpLockRelaseFlag;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭释放标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpLockCancelApplyFlag, 跳跃锁闭取消申请标志
* 返回值  ： 0: 设置失败
*			 1: 设置成功
*/
void SetLogSecJumpLockRelaseFlag(const UINT16 logSectionId, const UINT8 jumpLockApplyRelaseFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGSEC_JUMPLOCK_RELE_NO == jumpLockApplyRelaseFlag) ||
			(LOGSEC_JUMPLOCK_RELE_YES == jumpLockApplyRelaseFlag))
		{
			LogicSectionDataStru[bufIndex].LogJumpLockRelaseFlag = jumpLockApplyRelaseFlag;  /*逻辑区段跳跃锁闭释放标志*/

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


/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭申请周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭申请周期号
*/
UINT32 GetLogSecJumpLockApplyCylce(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = 0u;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogJumpLockApplyCylce; /** 逻辑区段跳跃锁闭申请周期号 */
	}
	else
	{
		retVal = 0u;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭申请周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT32 jumpLockApplyCycle, 跳跃锁闭申请周期号
* 返回值  ： 无
*/
void SetLogSecJumpLockApplyCylce(const UINT16 logSectionId, const UINT32 jumpLockApplyCycle)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		LogicSectionDataStru[bufIndex].LogJumpLockApplyCylce = jumpLockApplyCycle;  /*逻辑区段跳跃锁闭申请周期号*/
	}
	else
	{
		/*不做处理*/
	}
}

#endif

/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭状态
*/
UINT8 GetLogSecJumpLockState(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;                               /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogJumpLockState; /*逻辑区段跳跃锁闭状态*/
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpLockState, 跳跃锁闭状态
* 返回值  ： 无
*
*/
void SetLogSecJumpLockState(const UINT16 logSectionId, const UINT8 jumpLockState)
{
	UINT16 bufIndex = 0u;                                                                    /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGIC_SECTION_JUMP_LOCK_NO == jumpLockState) || (LOGIC_SECTION_JUMP_LOCK_YES == jumpLockState))
		{
			LogicSectionDataStru[bufIndex].LogJumpLockState = jumpLockState;      /*逻辑区段跳跃锁闭状态*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭延时解锁起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭延时解锁起始周期号
*/
UINT32 GetLogSecJumpDelayUnlocStartCyc(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = 0u;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取逻辑区段跳跃锁闭延时解锁起始周期号 */
		retVal = LogicSectionDataStru[bufIndex].LogSecJumpDelayUnlockStartCyc;
	}
	else
	{
		/** 获取数据失败 */
		retVal = 0u;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭延时解锁起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT32 startCycNum, 起始周期号
* 返回值  ： 无
*
*/
void SetLogSecJumpDelayUnlocStartCyc(const UINT16 logSectionId, const UINT32 startCycNum)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 设置逻辑区段跳跃锁闭延时解锁起始周期号 */
		LogicSectionDataStru[bufIndex].LogSecJumpDelayUnlockStartCyc = startCycNum;
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭延时解锁设置标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭延时解锁设置标志
*/
UINT8 GetLogSecJumpDelayUnlockFlag(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取逻辑区段跳跃锁闭延时解锁起始周期号 */
		retVal = LogicSectionDataStru[bufIndex].LogJumpLockDelayUnlockFlag;
	}
	else
	{
		/** 获取数据失败 */
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭延时解锁设置标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpDelayUnlockFlag, 延时解锁设置标志
* 返回值  ： 无
*
*/
void SetLogSecJumpDelayUnlockFlag(const UINT16 logSectionId, const UINT8 jumpDelayUnlockFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 入参合法 */
		if ((LOGIC_JUMPUNLOCK_DELAY_SET_NO == jumpDelayUnlockFlag) || (LOGIC_JUMPUNLOCK_DELAY_SET_YES == jumpDelayUnlockFlag))
		{
			/** 设置逻辑区段跳跃锁闭延时解锁设置标志 */
			LogicSectionDataStru[bufIndex].LogJumpLockDelayUnlockFlag = jumpDelayUnlockFlag;
		}
		else
		{
			/** 不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述： 获取指定ID逻辑区段跳跃锁闭允许标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID		 
* 返回值  ： 0: 获取数据失败
*			>0: 跳跃锁闭允许标志
*/
UINT8 GetLogSecJumpLockPermFlag(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取逻辑区段跳跃锁闭允许标志 */
		retVal = LogicSectionDataStru[bufIndex].LogSecJumpLockPermFlag;
	}
	else
	{
		/** 获取数据失败 */
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段跳跃锁闭允许标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpLockPermFlag, 跳跃锁闭允许标志
* 返回值  ： 无
*
*/
void SetLogSecJumpLockPermFlag(const UINT16 logSectionId, const UINT8 jumpLockPermFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 入参合法 */
		if ((LOGIC_JUMPUNLOCK_PERMISSIVE_YES == jumpLockPermFlag) || (LOGIC_JUMPUNLOCK_PERMISSIVE_NO == jumpLockPermFlag))
		{
			/** 设置逻辑区段跳跃锁闭延时解锁设置标志 */
			LogicSectionDataStru[bufIndex].LogSecJumpLockPermFlag = jumpLockPermFlag;
		}
		else
		{
			/** 不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
}

#if 0
/* HERE
* 功能描述： 获取指定ID计轴区段所属虚拟联锁ID
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 所属虚拟联锁ID
*/
UINT8 GetAxisSectionBelongVirCiId(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取区段数组下标*/

	if (bufIndex < AXIS_SECTION_SUM_MAX)
	{
		retVal = AxisSectionDataStru[bufIndex].BelongVirCIid;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

#endif 

/*
* 功能描述： 逻辑区段跳跃锁闭命令逻辑处理
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 jumpLockState, 跳跃锁闭状态
* 返回值  ： 无
*
*/
void LogJumpLockCmdManage(const UINT16 logSectionId, const UINT8 jumpLockState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 checkResult = CI_ERROR;
	UINT16 devId = 0u;                   /*设备ID*/
	UINT8 devState = 0u;                 /*设备状态*/
	UINT8 retVal = 0u;

	/** 获取逻辑区段数组下标*/
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法*/
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 逻辑区段跳跃锁闭*/
		if (LOGIC_SECTION_JUMP_LOCK_YES == jumpLockState)
		{
			/** 检查逻辑区段跳跃锁闭条件 */
			checkResult = CheckLogJumpLockApply(logSectionId);
			/** 逻辑区段跳跃锁闭条件不满足 */
			if (CI_ERROR == checkResult)
			{
				/** 设置跳跃锁闭允许标志为禁止 */
				SetLogSecJumpLockPermFlag(logSectionId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
			}
			else
			{
				/** 设置跳跃锁闭允许标志为允许 */


				ClearLogSeceSwitchDanCaoPos(logSectionId);/*清除单操位置*/
				/** 设置逻辑区段跳跃锁闭 */
				SetLogSecJumpLockState(logSectionId, LOGIC_SECTION_JUMP_LOCK_YES);

				SetLogSecRelProSwitchLockSta(logSectionId, SWITCH_LOCK_PROTECT_SET);

				devId = 0u;
				devState = 0u;
				retVal = LogicSecRltvPrtctSwLockCheck(logSectionId, &devId, &devState);
				if (CI_SUCCESS == retVal)
				{/*防护道岔锁检查*/
					SetLogSecJumpLockPermFlag(logSectionId, LOGIC_JUMPUNLOCK_PERMISSIVE_YES);
				}
				else
				{
					SetLogSecJumpLockPermFlag(logSectionId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
				}

			}
		}
		/** 逻辑区段跳跃锁闭未锁闭*/
		else if (LOGIC_SECTION_JUMP_LOCK_NO == jumpLockState)
		{
			/** 设置跳跃锁闭允许标志为禁止 */
			SetLogSecJumpLockPermFlag(logSectionId, LOGIC_JUMPUNLOCK_PERMISSIVE_NO);
			/** 设置跳跃锁闭未锁闭 */
			SetLogSecJumpLockState(logSectionId, LOGIC_SECTION_JUMP_LOCK_NO);

			SetLogSecRelProSwitchLockSta(logSectionId, SWITCH_LOCK_PROTECT_CANCEL);
		}
		else
		{
			/** 不做处理 */
		}

		SetLogRelaPhySecJumpLockSta(logSectionId);
	}
	else
	{
		/** 不做处理 */
	}
}


/*
* 功能描述： 获取临时限速跟随数据
* 参数说明： pData 数据地址
*			 dwIndex 数据索引
* 返回值  ： 写入后的数据索引
*/
UINT32 GetTsrFollowData(UINT8* pData, UINT32 dwIndex)
{
	UINT32 dwRetVal = 0u;
	UINT8 ii = 0u;
	UINT8 jj = 0u;

	if ((NULL != pData) && (UINT32_MAX >= dwIndex))
	{
		dwRetVal = dwIndex;
		
		/* 限速数量 */
		pData[dwRetVal] = g_TsrSum;
		dwRetVal++;

		for (ii = 0u; ii < g_TsrSum;ii++)
		{
			/* 限速值 */
			pData[dwRetVal] = g_TsrDataStru[ii].cSpeed;
			dwRetVal++;

			/* 限速数量 */
			pData[dwRetVal] = g_TsrDataStru[ii].cLogSecSum;
			dwRetVal++;

			for (jj = 0u;jj < g_TsrDataStru[ii].cLogSecSum;jj++)
			{
				/* 限速区段的ID */
				ShortToChar(g_TsrDataStru[ii].szLogSecId[jj], &pData[dwRetVal]);
				dwRetVal += 2u;
			}
		}

	}
	else
	{
		dwRetVal = dwIndex;
	}

	return dwRetVal;
}

/*
* 功能描述： 设置临时限速跟随数据
* 参数说明： pData 数据地址
*			 dwIndex 数据索引
* 返回值  ： 解析后的数据索引
*/
UINT32 SetTsrFollowData(UINT8* pData, UINT32 dwIndex)
{
	UINT32 dwRetVal = 0u;
	UINT8 ii = 0u;
	UINT8 jj = 0u;

	if ((NULL != pData) && (UINT32_MAX >= dwIndex))
	{
		dwRetVal = dwIndex;

		/* 限速数量 */
		g_TsrSum = pData[dwRetVal];
		dwRetVal++;

		for (ii= 0u; ii < g_TsrSum;ii++)
		{
			/* 限速速度 */
			g_TsrDataStru[ii].cSpeed = pData[dwRetVal];
			dwRetVal++;

			g_TsrDataStru[ii].cLogSecSum = pData[dwRetVal];
			dwRetVal++;

			for (jj = 0u; jj < g_TsrDataStru[ii].cLogSecSum; jj++)
			{
				g_TsrDataStru[ii].szLogSecId[jj] = ShortFromChar(&pData[dwRetVal]);
				dwRetVal += 2u;
			}
		}
	}
	else
	{
		dwRetVal = dwIndex;
	}

	return dwRetVal;
}

/**
* @brief 逻辑区段是否有隐藏车
* @param wLgcId 逻辑区段ID
* @return CI_SUCCESS无隐藏车；CI_ERROR有隐藏车
* @note 此函数仅在判断逻辑区段为CT占用后调用
*/
UINT8 IsLogicHaveNoSupicTrain(UINT16 wLgcId)
{
	UINT8 chLinkNum = 0u;
	UINT16 *pLinkId = NULL;
	UINT8 chIndex = 0u;
	UINT8 chRtn = CI_ERROR;
	TRAIN_SEQUANCE_s strTmpF = { 0u };
	TRAIN_SEQUANCE_s strTmpB = { 0u };
	UINT8 chTrainNum = 0u;
	chLinkNum = GetSecIntrudeLinkSum(wLgcId);
	pLinkId = GetSecIntrudeLinkIdBuf(wLgcId);
	if (0u != chLinkNum) 
	{
		for (chIndex = 0u; chIndex < chLinkNum; chIndex++)
		{
			chTrainNum = as_GetLinkTrainNum(pLinkId[chIndex]);
			if (0u != chTrainNum)
			{
				strTmpF = as_GetLinkLastTrain(pLinkId[chIndex]);
				
				strTmpB = as_GetLinkFirstTrain(pLinkId[chIndex]);
				if ((TRAIN_SUM_MAX == strTmpB.u16TrainID) || (TRAIN_SUM_MAX == strTmpF.u16TrainID))
				{
					break;
				}
				else
				{
					;
				}
			}
			else
			{
				;
			}
		}
		if (chIndex == chLinkNum)
		{
			chRtn = CI_SUCCESS;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
	return chRtn;
}

/************************************跳跃锁闭相关****************************************************/

/*
* @brief 设置逻辑区段限速切除状态
* @details 设置限速切除后，点式进路不检查限速状态
* @param const UINT16 routeId 进路ID
*        const UINT8 chCiId   CiID
* @return 无
*/
void SetLgcXianSuRemoveState(const UINT16 wLgcId, const UINT8 chXianSuRemoveStt)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

						   /** 获取进路数组下标*/
	bufIndex = GetlogSectionBufIndex(wLgcId);
	/** 若数组下标合法且列车ID数量合法*/
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if ((LOGIC_XIANSU_REMOVE_YES == chXianSuRemoveStt)
			|| (LOGIC_XIANSU_REMOVE_NO == chXianSuRemoveStt))
		{
			LogicSectionDataStru[bufIndex].chXianSuRemoveState = chXianSuRemoveStt;
		}
		else
		{
			/*无处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

#if 0
/*
* 功能描述： 获取逻辑区段限速切除状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0u	：错误
*		  ： 其他 ：限速切除状态
*/
UINT8 GetLgcXianSuRemoveState(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = 0u;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicSectionDataStru[wBufIndex].chXianSuRemoveState;
	}
	else
	{
		;/* 返回0u */
	}
	return chRetVal;
}
#endif

/**
* @brief 逻辑区段是否在临时限速中
* @param wLogSecId 逻辑区段ID
* @return UINT8_MAX 数据异常
*		  0 不在临时限速中
*	      >0 临时限速取值
* @note by cgh 20240411
*/
UINT8 IsInTsrLogSecIdBuf(UINT16 wLogSecId)
{
	UINT8 cRetVal = UINT8_MAX;
	UINT8 i = 0U;
	UINT8 j = 0U;

	if ((0U != wLogSecId) && (UINT16_MAX != wLogSecId))
	{
		cRetVal = 0U;
		for (i = 0U; i < g_TsrSum; i++)
		{
			for (j = 0U; j < g_TsrDataStru[i].cLogSecSum; j++)
			{
				if (g_TsrDataStru[i].szLogSecId[j] == wLogSecId)
				{
					/* 查找到改逻辑区段 */
					cRetVal = g_TsrDataStru[i].cSpeed;
					break;
				}
				else
				{
					; /*继续查找*/
				}
			}
			if (0U != cRetVal)
			{
				/*已经找到*/
				break;
			}
		}
	}
	else
	{
		; /*非法*/
	}

	return cRetVal;
}

/*
* 功能描述： 清除指定逻辑区段关联物理区段锁闭所属进路的限速确认状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 无
*
*/
void ClearLgcSecBelongRtXsCfm(const UINT16 wLgcSecId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 cTiocId = 0u;
	UINT8 cRouteBelongCiId = 0U;
	UINT16 wPLockRouteId = 0U;
	UINT16 wRLockRouteId = 0U;  /** 获取逻辑区段数组下标 */
	UINT16 wRelPhySecId = 0U;  /*逻辑区段关联物理区段ID*/

	bufIndex = GetlogSectionBufIndex(wLgcSecId);
	cTiocId = GetSystemParaLocalCiId();
	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		wRelPhySecId = GetLgcSecRelativePhySecId(wLgcSecId);
		wRLockRouteId = GetPhySecRLockBelongRouteId(wRelPhySecId);
		wPLockRouteId = GetPhySecPLockBelongRouteId(wRelPhySecId);
		if (0U != wRLockRouteId)
		{
			cRouteBelongCiId = GetRouteBelongCiId(wRLockRouteId);
			if (cRouteBelongCiId == cTiocId)
			{
				SetRouteXianSuConfirmStt(wRLockRouteId, ROUTE_XIANSU_CONFIRM_NO);
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (0U != wPLockRouteId)
		{
			cRouteBelongCiId = GetRouteBelongCiId(wPLockRouteId);
			if (cRouteBelongCiId == cTiocId)
			{
				SetRouteXianSuConfirmStt(wPLockRouteId, ROUTE_XIANSU_CONFIRM_NO);
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}
	}
	else
	{
		/** 不做处理 */
	}
} 

/*
* 功能描述： 设置其他TIOC指定ID逻辑区段临时限速设置状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 linShiXianSuSetState, 临时限速设置状态
* 返回值  ： 无
*
*/
void SetLogSecXSSttOtherTioc(const UINT16 logSectionId, const UINT8 linShiXianSuSetState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取逻辑区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if (LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag == LOGSEC_LSXS_SET_STATE_NO)
		{
			if (LOGSEC_LSXS_SET_STATE_YES == linShiXianSuSetState)
			{
				ClearLgcSecBelongRtXsCfm(logSectionId);
				LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag = linShiXianSuSetState;
			}
			else if ((LOGSEC_LSXS_SET_STATE_NO == linShiXianSuSetState)||
				(LOGSEC_LSXS_SET_STATE_INVALID == linShiXianSuSetState))
			{
				LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag = linShiXianSuSetState;
			}
			else
			{
				/*不处理*/
				;
			}
		}
		else
		{
			if ((LOGSEC_LSXS_SET_STATE_NO == linShiXianSuSetState) ||
				(LOGSEC_LSXS_SET_STATE_YES == linShiXianSuSetState) ||
				(LOGSEC_LSXS_SET_STATE_INVALID == linShiXianSuSetState))
			{
				LogicSectionDataStru[bufIndex].LinShiXianSuSetFlag = linShiXianSuSetState;  /*逻辑区段临时限速设置状态*/
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不做处理*/
	}
}
#if 0
/*
* @func： 逻辑区段是否包含可用资源检查
* @param： UINT16 wLgcSecId, 逻辑区段ID

* @return CI_ERROR   不包含
*		  CI_SUCCESS 包含
*/
UINT8 LgcHaveUseableRes(UINT16 wLgcSecId)
{
	/*变量初始化*/
	UINT8 ii = 0u;           /* 循环变量 */
	UINT8  chLogResTrainSum = 0u;
	UINT16 wLgcSecResTrainId = 0U;
	LogicTrainResStruct * pstLogicResTrainInfo = NULL;

	UINT8 chRetVal = CI_ERROR;

	chLogResTrainSum = GetLogSecTrainInfoSum(wLgcSecId);

	/*遍历逻辑区段所有资源信息*/
	for (ii = 0U; ii < chLogResTrainSum; ii++)
	{
		wLgcSecResTrainId = GetLogSecTrainIdByIndex(wLgcSecId, ii);
		pstLogicResTrainInfo = GetLogSecTrainInfoById(wLgcSecId, wLgcSecResTrainId);
		/*获取列车资源信息不为空*/
		if (NULL != pstLogicResTrainInfo)
		{
			if (LOGIC_SECTION_RES_USABLE == pstLogicResTrainInfo->chLogicResUsable)
			{
				chRetVal = CI_SUCCESS;
				break;
			}
			else
			{
				; /*不处理*/
			}
		}
		else
		{
			; /*不可能分支*/
		}
	}


	return (chRetVal);
}
#endif

/*
* 功能描述： 获取指定逻辑区段ARB状态
* 参数说明： const UINT16 wLgcId, 逻辑区段ID
*
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段ARB状态
*/
UINT8 GetLgcArbState(const UINT16 wLgcId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(wLgcId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].chArbState;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 设置制定逻辑区段ARB状态
* 参数说明： const UINT16 wLgcId, 逻辑区段ID
*			const UINT8 chArb ARB状态
* 返回值  ： 无
*/
void SetLgcArbState(const UINT16 wLgcId, const UINT8 chArb)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(wLgcId);  /*获取区段数组下标*/

	if ((LOGIC_SECTION_SUM_MAX > bufIndex)
		&& ((LGC_SECTION_ARB_NO == chArb) || (LGC_SECTION_ARB_YES == chArb)))
	{
		LogicSectionDataStru[bufIndex].chArbState = chArb;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置逻辑区段ARB状态处理
* 参数说明： 无
* 返回值  ： 无
*/
void SetLgcArbStateProc(void)
{
	UINT8 chLocalId = 0u;
	UINT8 chBelongTioc = 0u;
	UINT16 wLgcNum = 0u;
	UINT16 wLgcIndex = 0u;
	UINT8 chAcNum = 0u;
	UINT16 wLgcId = 0u;
	UINT16 * pAcId = NULL;
	UINT8 chAcIndex = 0u;
	UINT8 chAcArbState = 0u;
	UINT8 cRcWorkMode = 0U;
	UINT8 cflag = 0U;

	cRcWorkMode = GetLocalRcWorkMode();

	chLocalId = GetSystemParaLocalCiId();

	/* 获取逻辑区段数量 */
	wLgcNum = GetTotalLogSecCurNum();/*大于等于LOGIC_SECTION_SUM_MAX返回0*/
	for (wLgcIndex = 0u; wLgcIndex < wLgcNum; wLgcIndex++)
	{

		wLgcId = GetLogicSecId(wLgcIndex);
		chBelongTioc = GetLogSecBelongCiId(wLgcId);
		chAcNum = GetLgcSecRelativeAxleSecSum(wLgcId);
		pAcId = GetLgcSecRltvAxleSecIdBuf(wLgcId);
		if ((0u != chAcNum) && (NULL != pAcId) && (chLocalId == chBelongTioc))
		{
			for (chAcIndex = 0u; chAcIndex < chAcNum; chAcIndex++)
			{
				cflag = 0U;
				if (RC_WORK_MODE_TIOC == cRcWorkMode)
				{
					chAcArbState = aam_GetAxisStatusAPI(pAcId[chAcIndex]);
					if (AAM_STATUS_ARB == chAcArbState)
					{/* 计轴区段ARB，设置逻辑区段ARB */
						SetLgcArbState(wLgcId, LGC_SECTION_ARB_YES);
						cflag = 1U;
					}
					else
					{/* 计轴区段非ARB，设置逻辑区段非ARB */
						SetLgcArbState(wLgcId, LGC_SECTION_ARB_NO);
					}
				}
				else if (RC_WORK_MODE_CI == cRcWorkMode)
				{
					chAcArbState = GetAxisSecArbState(pAcId[chAcIndex]);
					if (AXIS_SECTION_ARB_YES == chAcArbState)
					{/* 计轴区段ARB，设置逻辑区段ARB */
						SetLgcArbState(wLgcId, LGC_SECTION_ARB_YES);
						cflag = 1U;
					}
					else
					{/* 计轴区段非ARB，设置逻辑区段非ARB */
						SetLgcArbState(wLgcId, LGC_SECTION_ARB_NO);
					}
				}
				else
				{
					/*RC工作模式错误*/
				}
				if (1U == cflag)
				{
					break;
				}
			}
		}
		else
		{
			/* 数据获取失败或者不为本控区逻辑区段，不处理 */
		}
	}
}
/*
* 功能描述： 获取指定逻辑区段延时故障锁闭起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： 0:  获取失败
*			 >0: 逻辑区段延时故障锁闭起始周期号
*/
UINT32 GetLogDelayErrlockStartCycNum(const UINT16 logSectionId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		retVal = LogicSectionDataStru[bufIndex].LogErrlockStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述： 设置指定逻辑区段延时故障锁闭起始周期号
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT32 startCycNum 起始周期号
* 返回值  ： 无
*
*/
void SetLogDelayErrlockStartCycNum(const UINT16 logSectionId, const UINT32 startCycNum)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		if (0U == startCycNum)
		{
			LogicSectionDataStru[bufIndex].LogErrlockStartCycNum = 0U;
		}
		else
		{
			if (0U == LogicSectionDataStru[bufIndex].LogErrlockStartCycNum)
			{
				LogicSectionDataStru[bufIndex].LogErrlockStartCycNum = startCycNum;
			}
			else
			{
				; /*已经有效不再继续设置*/
			}
		}		
	}
	else
	{
		/*不做处理*/
	}
}


/**
* @brief 获取逻辑区段是否有隐藏车
* @param wLgcId 逻辑区段ID
* @return CI_SUCCESS无隐藏车；CI_ERROR有隐藏车
* @note 获取所有列车查看是否有可疑列车
*/
UINT8 GetLogicSupicTrainStat(UINT16 wLgcId)
{
	UINT8 chLinkNum = 0u;
	UINT8 trainIndex = 0U;
	UINT16 *pLinkId = NULL;
	UINT8 chIndex = 0u;
	UINT8 chRtn = CI_ERROR;
	TRAIN_SEQUANCE_s strTmp[SIZE_MAX_TRAINOFAC] = { 0u };
	TRAIN_SEQUANCE_s strTmpB = { 0u };
	UINT8 chTrainNum = 0u;
	chLinkNum = GetSecIntrudeLinkSum(wLgcId);
	pLinkId = GetSecIntrudeLinkIdBuf(wLgcId);
	
	/*link数量不为0*/
	if (0u != chLinkNum)
	{
		/*遍历所有Link*/
		for (chIndex = 0u; chIndex < chLinkNum; chIndex++)
		{
			/*获取Link上列车排序信息*/
			chTrainNum = as_GetLinkTrainList(pLinkId[chIndex], strTmp, SIZE_MAX_TRAINOFAC);
			if (0u != chTrainNum)
			{
				for (trainIndex = 0U; trainIndex < chTrainNum; trainIndex++)
				{
					if (NAME_FAILUREAREA == strTmp[trainIndex].u16TrainID)
					{
						/*找到隐藏车，退出*/
						break;
					}
					else
					{
						;
					}
				}

				if (trainIndex != chTrainNum)
				{
					/*隐藏车导致退出*/
					break;
				}
				
			}
		}
		if (chIndex == chLinkNum)
		{
			/*遍历完成，无隐藏车*/
			chRtn = CI_SUCCESS;
		}
		else
		{
			chRtn = CI_ERROR;
		}
	}
	else
	{
		chRtn = CI_ERROR;
	}

	return chRtn;
}

/*
* 功能描述： 设置逻辑区段保护锁闭资源可用状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT8  chUseState	 可用状态
* 返回值  ： VOID
* by cgh 20230630 单独记录保护锁闭资源状态
*/
void SetLogSecProResUseState(const UINT16 wLogSectionId, const UINT8 chUseState)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if ((LOGIC_SECTION_PRO_RES_USABLE == chUseState) || (LOGIC_SECTION_PRO_RES_UNUSABLE == chUseState))
		{
			LogicSectionDataStru[wBufIndex].chLogicProResUsable = chUseState;
		}
	}
}

/*
* 功能描述： 获取逻辑区段保护锁闭资源可用状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： LOGIC_SECTION_PRO_RES_UNUSABLE	：不可用
*		  ： LOGIC_SECTION_PRO_RES_USABLE   ：可用
* * by cgh 20230630 单独记录保护锁闭资源状态
*/
UINT8 GetLogSecProResUseState(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 chRetVal = LOGIC_SECTION_RES_UNUSABLE;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicSectionDataStru[wBufIndex].chLogicProResUsable;
	}
	else
	{
		; /*索引非法，返回不可用*/
	}
	return chRetVal;
}

/*
* 功能描述： 获取指定逻辑区段锁闭方向是否应该取反
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR: 不取反
*			 CI_SUCCESS: 取反
* by cgh 20230802 给ATS组锁闭方向码位时使用
*/
UINT8 GetLogSecLockDirOpposedFlag(const UINT16 wLogSectionId)
{
	UINT8 retVal = CI_ERROR;
	UINT16 wRLockRouteId = 0U;/*逻辑区段锁闭所属进路*/
	UINT16 wLogSecBelongPhyId = 0U;/*逻辑区段所属物理区段*/
	UINT8 chLockDirOpposedFlag = 0U;/*锁闭方向是否取反标志*/

	wRLockRouteId = GetLogSecLockBelongRoute(wLogSectionId);
	wLogSecBelongPhyId = GetLgcSecRelativePhySecId(wLogSectionId);
	chLockDirOpposedFlag = GetRoutePhySecShouldLockOppose(wRLockRouteId, wLogSecBelongPhyId);

	if (ROUTE_PHYSEC_SHOULD_OPPOSE_LOCK == chLockDirOpposedFlag)
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		; /*物理区段锁闭方向不需要取反，则说明逻辑区段也不需要取反*/
	}
	return retVal;
}

/*
* 功能描述： 获取指定逻辑区段是否具备资源对顶的前提条件
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR: 不具备
*			 CI_SUCCESS: 具备
* by cgh 20230802 给IVOC组包资源对顶信息
*/
UINT8 GetLogSecHaveResOpp(const UINT16 wLogicSecId)
{
	UINT8 retVal = CI_ERROR;
	UINT16 wRLockRouteId = 0U;/*逻辑区段锁闭所属进路*/
	UINT16 wPLockRouteId = 0U;/*逻辑区段防护锁闭所属进路*/
	UINT16 wRouteLogSecSum = 0U;/*进路包含逻辑区段数目*/
	UINT16* pRouteLogSecId = NULL;/*进路包含逻辑区段ID*/
	UINT16 wOverlapLockedId = 0U;/*进路保护区段ID*/
	UINT8 chLogicSectionSum = 0U;/*保护区段对应逻辑区段数目*/
	UINT16* pLogicSectionIdBuf = NULL;/*保护区段包含逻辑区段ID*/
	UINT8 chLogSecLockState = 0U;/*逻辑区段锁闭状态*/
	UINT8 chLogSecLockDir = 0U;/*逻辑区段锁闭运营方向*/
	UINT8 chLogSecLockSysDir = 0U;/*逻辑区段锁闭逻辑方向*/

	wRLockRouteId = GetLogSecLockBelongRoute(wLogicSecId);
	wPLockRouteId = GetLogSecPLockRouteId(wLogicSecId);
	chLogSecLockState = GetLogSecLockState(wLogicSecId);

	if (0U < wRLockRouteId)
	{
		/*当前逻辑区段具备进路锁闭或着进路锁闭兼防护锁闭*/
		wRouteLogSecSum = GetRouteLogSectionSum(wRLockRouteId);
		pRouteLogSecId = GetRouteLogSectionIdBuf(wRLockRouteId);

		if (NULL != pRouteLogSecId)
		{
			if ((pRouteLogSecId[wRouteLogSecSum - 1U] == wLogicSecId) && (LOG_SECTION_LOCK_NORMAL == chLogSecLockState))
			{
				/*当前待查询逻辑区段为进路最后一个区段并且是正常锁闭，满足条件*/
				retVal = CI_SUCCESS;
			}
			else
			{
				; /*不满足条件*/
			}
		}
		else
		{
			; /*可能相邻联锁进路，为空初始化失败*/
		}
		
	}
	else if (0U < wPLockRouteId)
	{
		/*当前逻辑区段仅为防护锁闭，为保护区段内最后一个区段满足条件*/
		wOverlapLockedId = GetRouteOverlapLockedId(wPLockRouteId);
		chLogicSectionSum = GetOverlapLogicSectionSum(wOverlapLockedId);
		pLogicSectionIdBuf = GetOverlapLogicSectionBuf(wOverlapLockedId);
		chLogSecLockDir = GetLogSecLockDir(wLogicSecId);
		chLogSecLockSysDir = ConvertDirectionToLogic(chLogSecLockDir);

		if (NULL != pLogicSectionIdBuf)
		{
			if (((pLogicSectionIdBuf[chLogicSectionSum - 1U] == wLogicSecId) && (DIR_SAME == chLogSecLockSysDir))
				|| ((pLogicSectionIdBuf[0] == wLogicSecId) && (DIR_CONVERT == chLogSecLockSysDir)))
			{
				/*当前待查询逻辑区段锁闭方向与逻辑方向相同，则保护区段最后一个区段满足条件；与逻辑方向相反，保护区段第一个逻辑区段满足条件*/
				retVal = CI_SUCCESS;
			}
			else
			{
				; /*可能相邻联锁数据，为空初始化失败*/
			}
		}
		else
		{
			; /*可能相邻联锁进路，为空初始化失败*/
		}
	}
	else
	{
		; /*不具备前提条件*/
	}
	return retVal;
}


/*
* 功能描述： 清除区段防护锁闭状态
* 参数说明： const UINT16 logicSecId, 逻辑区段ID
* 返回值:	无
*/
void ClearLogicSecPLock(const UINT16 logicSecId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_SUCCESS;
	bufIndex = GetlogSectionBufIndex(logicSecId);  /*获取区段数组下标*/


	if (bufIndex >= LOGIC_SECTION_SUM_MAX)
	{
		retVal = CI_ERROR;
	}

	else
	{
		LogicSectionDataStru[bufIndex].wPLockBelongRouteId = 0;
	}
}

/*
* 功能描述： 设置逻辑区段SPKS封锁状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*			 const UINT8  chLogicSpksFLockState	 逻辑区段SPKS封锁状态
* 返回值  ： VOID
* by cgh 20230919
*/
void SetLogSecSpksFLockState(const UINT16 wLogSectionId, const UINT8 chLogicSpksFLockState)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if ((LOGIC_SECTION_SPKS_FLOCK_NO == chLogicSpksFLockState) || (LOGIC_SECTION_SPKS_FLOCK_YES == chLogicSpksFLockState))
		{
			LogicSectionDataStru[wBufIndex].chLogicSpksFLockState = chLogicSpksFLockState;
		}
	}
}

/*
* 功能描述： 获取逻辑区段SPKS封锁状态
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*
* 返回值  ： LOGIC_SECTION_SPKS_FLOCK_NO	：未封锁
*		  ： LOGIC_SECTION_SPKS_FLOCK_YES   ：封锁
* by cgh 20230919
*/
UINT8 GetLogSecSpksFLockState(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	UINT8 chRetVal = LOGIC_SECTION_SPKS_FLOCK_YES;
	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicSectionDataStru[wBufIndex].chLogicSpksFLockState;
	}
	else
	{
		; /*索引非法，返回不可用*/
	}
	return chRetVal;
}

/*
* 功能描述： 获取指定ID逻辑区段锁闭所属逻辑进路数量
* 参数说明：const UINT16 wLgcId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 逻辑区段锁闭所属逻辑进路数量
* 创建	  ： cgh 2023-10-10
*/
UINT8 GetLogSecLockBelLogRouteSum(const UINT16 wLgcId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLgcId);  /*获取逻辑区段下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		retVal = LogicSectionDataStru[wBufIndex].chLogSecLockBelLogRouteSum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID逻辑区段锁闭所属逻辑进路数据
* 参数说明： const UINT16 wLgcId, 逻辑区段ID
* 返回值  ： NULL: 获取数据失败
*			!NULL: 逻辑区段锁闭所属逻辑进路数据
* 创建	  :  cgh 2023-10-10
*/
LogSecLockBelLogRouteStruct* GetLogSecLockBelLogRouteData(const UINT16 wLgcId)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	LogSecLockBelLogRouteStruct* pRetVal = NULL;

	wBufIndex = GetlogSectionBufIndex(wLgcId);  /*获取逻辑区段下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		pRetVal = LogicSectionDataStru[wBufIndex].szLogSecLockBelLogRouteData;
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}



/*
* 功能描述： 查找指定逻辑区段是否关联指定逻辑进路
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*					const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ：CI_SUCCESS逻辑区段关联该逻辑进路；CI_ERROR不关联
* 创建	  ： fan 2023-10-11
*/
UINT8 CheckLogRouteIdBelLogSec(const UINT16 logSectionId, const UINT16 wLogRouteId)
{

	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 logRoutSum = 0U;  /*逻辑区段所属逻辑进路数组数量*/
	LogSecLockBelLogRouteStruct* logRoutBuf = NULL;  /*逻辑区段所属逻辑进路数据组*/

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		logRoutBuf = LogicSectionDataStru[bufIndex].szLogSecLockBelLogRouteData;
		logRoutSum = LogicSectionDataStru[bufIndex].chLogSecLockBelLogRouteSum;
		for (ii = 0U; ii < logRoutSum; ii++)
		{
			if (logRoutBuf[ii].wLogSecLockBelLogRouteId == wLogRouteId)
			{
				retVal = CI_SUCCESS;
				break;
			}
			else
			{
				; /*继续*/
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 从指定逻辑区段删除指定逻辑进路ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
const UINT16 wLogRouteId, 逻辑进路ID
*
* 返回值  ： CI_ERROR 删除失败 Ci_SUCCESSS 删除成功
* 创建	  ： fan 2023-10-11
*/
UINT8 DelLogSecBelongLogRouteId(const UINT16 logSectionId, const UINT16 wLogRouteId)
{

	UINT16 bufIndex = 0U;  /*数组下标*/
	LogSecLockBelLogRouteStruct* logRoutBuf = NULL;  /*逻辑区段所属逻辑进路数据组*/
	UINT8 logRoutSum = 0U;  /*逻辑区段所属逻辑进路数组数量*/
	UINT8 retVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 chNeedKeepSum = 0U;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		logRoutBuf = LogicSectionDataStru[bufIndex].szLogSecLockBelLogRouteData;
		logRoutSum = LogicSectionDataStru[bufIndex].chLogSecLockBelLogRouteSum;
		if (LOGSEC_RELATE_ROUTE_SUM_MAX >= logRoutSum)
		{
			for (ii = 0U; ii < logRoutSum; ii++)
			{
				if (LogicSectionDataStru[bufIndex].szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId == wLogRouteId)
				{
					; /*不处理，继续执行*/
				}
				else
				{
					(void)CommonMemCpy((void*)(&logRoutBuf[chNeedKeepSum]), (UINT32)sizeof(LogSecLockBelLogRouteStruct), (void*)(&logRoutBuf[ii]), (UINT32)sizeof(LogSecLockBelLogRouteStruct));
					chNeedKeepSum++;
				}
			}
			/* 清0防止脏数据*/
			(void)ComMemSet(&logRoutBuf[chNeedKeepSum], (UINT16)sizeof(LogSecLockBelLogRouteStruct), 0U);
			LogicSectionDataStru[bufIndex].chLogSecLockBelLogRouteSum = chNeedKeepSum;/*修改所属逻辑进路数量*/
			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 从指定逻辑区段增加指定逻辑进路ID
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
const UINT16 wLogRouteId, 逻辑进路ID
*
* 返回值  ： CI_ERROR 增加失败 Ci_SUCCESSS 增加成功
* 创建	  ： fan 2023-10-11
*/
UINT8 AddLogSecBelongLogRouteId(const UINT16 logSectionId, const UINT16 wLogRouteId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	LogSecLockBelLogRouteStruct* logRoutBuf = NULL;  /*逻辑区段所属逻辑进路数组*/
	UINT16 logRoutSum = 0U;  /*逻辑区段所属逻辑进路数组数量*/
	UINT8 retVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 chNeedKeepSum = 0U;

	bufIndex = GetlogSectionBufIndex(logSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		logRoutSum = LogicSectionDataStru[bufIndex].chLogSecLockBelLogRouteSum;
		if (LOGSEC_RELATE_ROUTE_SUM_MAX > logRoutSum)
		{
			logRoutBuf = LogicSectionDataStru[bufIndex].szLogSecLockBelLogRouteData;
			logRoutBuf[logRoutSum].wLogSecLockBelLogRouteId = wLogRouteId;
			logRoutBuf[logRoutSum].wLogSecLockBelLogRouteId = 0U;
			logRoutBuf[logRoutSum].chLogSecLockBelLogRouteState = LOG_SECTION_LOGLOCK_NO;
			LogicSectionDataStru[bufIndex].chLogSecLockBelLogRouteSum++;
			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}



/*
* 功能描述： 获取指定逻辑区段逻辑锁闭状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段逻辑锁闭状态
* by cgh 20231012
*/
UINT8 GetLogSecLogLockState(const UINT16 wLogSectionId)
{

	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		retVal = LogicSectionDataStru[wBufIndex].LogSecLogLockState;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定逻辑区段逻辑锁闭方向
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*
* 返回值  ： 0: 获取失败
*			 >0: 逻辑区段逻辑锁闭方向
* by cgh 20231013
*/
UINT8 GetLogSecLogLockDir(const UINT16 wLogSectionId)
{

	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		retVal = LogicSectionDataStru[wBufIndex].LogSecLogLockDir;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 设置指定逻辑区段锁闭状态与方向
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*            const UINT8 chLogLockState 逻辑区段逻辑锁闭状态
*			 const UINT8 chLogLockDir 逻辑区段逻辑锁闭方向
* 返回值  ： 无
* by cgh 20231012
*/
void SetLogSecLogLockState(const UINT16 wLogSectionId, const UINT8 chLogLockState, const UINT8 chLogLockDir)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	UINT16 LogSecLockBelongRouteId = 0U;

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (LOG_SECTION_LOGLOCK_NO == chLogLockState)
		{
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = 0U;

			LogSecLockBelongRouteId = GetLogSecLockBelongRoute(wLogSectionId);
			if (0U != LogSecLockBelongRouteId)
			{
				/*脚下还有进路锁闭，考虑逻辑进路折返部分进路情况，不删除列车资源*/
			}
			else
			{
				LogicSectionDataStru[wBufIndex].chTrainInfoSum = 0U;
				(void)CommonMemSet(LogicSectionDataStru[wBufIndex].szTrainResData, \
					(UINT32)sizeof(LogicSectionDataStru[wBufIndex].szTrainResData), \
					0U, (UINT32)sizeof(LogicSectionDataStru[wBufIndex].szTrainResData));
			}

		}
		else if (LOG_SECTION_LOGLOCK_NORMAL == chLogLockState)
		{
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = chLogLockDir;
		}
		else if (LOG_SECTION_LOGLOCK_EXCEPT == chLogLockState)
		{ 
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = chLogLockDir;

			SetLogSecRelAllLogRouteState(wLogSectionId);
		}
		else
		{
			; /*不处理，不可达分支*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

#if 0
/*
* 功能描述： 获取逻辑进路中某一区段是否具备资源对顶前提
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
*
* 返回值  ： CI_ERROR: 不是最后一个逻辑区段
*			 CI_SUCCESS: 是最后一个逻辑区段
* by cgh 20231016
*/
UINT8 CheckLogRouteSecHaveResOpp(const UINT16 wLogicSecId)
{
	UINT8 chLogSecBelLogRouteSum = 0U;/*逻辑区段所属逻辑进路ID*/
	UINT8 ii = 0U;
	LogSecLockBelLogRouteStruct* szLogSecBelLogRouteData = NULL;/*逻辑区段所属逻辑进路数据*/
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段所属逻辑进路ID*/
	UINT16 wLogRouteIncLogSecSum = 0U;/*逻辑进路包含逻辑区段数目*/
	UINT16* szLogRouteIncLogSecIdBuf = NULL;/*逻辑进路包含逻辑区段ID数组*/
	UINT8 chReval = CI_ERROR;
	UINT8 chLogSecLogLockState = 0U;/*逻辑区段逻辑锁闭状态*/
	UINT8 chKeepFlag = 0U;

	chLogSecBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogicSecId);
	szLogSecBelLogRouteData = GetLogSecLockBelLogRouteData(wLogicSecId);

	if ((NULL != szLogSecBelLogRouteData) && (0U < chLogSecBelLogRouteSum))
	{
		for (ii = 0U; ii < chLogSecBelLogRouteSum; ii++)
		{
			wLogSecBelLogRouteId = szLogSecBelLogRouteData[ii].wLogSecLockBelLogRouteId;
			if ((0U < wLogSecBelLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogSecBelLogRouteId))
			{
				wLogRouteIncLogSecSum = GetLogicalRouteInLogSecSum(wLogSecBelLogRouteId);
				szLogRouteIncLogSecIdBuf = GetLogicalRouteInLogSecId(wLogSecBelLogRouteId);

				if (NULL != szLogRouteIncLogSecIdBuf)
				{
					if (wLogicSecId == szLogRouteIncLogSecIdBuf[wLogRouteIncLogSecSum - 1])
					{
						/*当前逻辑区段为逻辑进路最后一个逻辑区段，继续查找*/
					}
					else
					{
						chKeepFlag = 1U;/*当前逻辑区段不为逻辑进路最后一个逻辑区段，跳出*/
					}
				}
				else
				{
					chKeepFlag = 1U; /*异常情况，跳出*/
				}
			}
			else
			{
				chKeepFlag = 1U; /*异常情况，跳出*/
			}

			if (1U == chKeepFlag)
			{
				break;
			}
		}

		if (chLogSecBelLogRouteSum == ii)
		{
			/*当前区段为所有逻辑进路最后一个区段，继续查询锁闭状态*/
			chLogSecLogLockState = GetLogSecLogLockState(wLogicSecId);

			if (LOG_SECTION_LOGLOCK_NORMAL == chLogSecLogLockState)
			{
				/*当前区段状态为逻辑正常锁闭，前提条件检查通过*/
				chReval = CI_SUCCESS;
			}
			else
			{
				; /*维持检查不通过*/
			}
		}
		else
		{
			; /*不处理*/
		}
	}
	else
	{
		; /*不处理*/
	}
}
#endif


/**
* @brief 设置逻辑区段锁闭所属逻辑进路
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteRelatePsdId 逻辑进路关联屏蔽门ID
* @return 无
* @note：by cgh 20231011
*/
void SetLogSecRelateLogRouteData(const UINT16 wLogRouteId, const UINT16 wLogSecId)
{
	UINT16 wBufIndex = 0U;
	UINT8 chLogSecRelateLogRouteSum = 0U;
	UINT16 ii = 0U;
	

	wBufIndex = GetlogSectionBufIndex(wLogSecId);

	if ((LOGIC_SECTION_SUM_MAX > wBufIndex)&& (0U != wLogRouteId))
	{
		chLogSecRelateLogRouteSum = LogicSectionDataStru[wBufIndex].chLogSecLockBelLogRouteSum;

		if (LOGSEC_RELATE_ROUTE_SUM_MAX > chLogSecRelateLogRouteSum)
		{
			for (ii = 0U; ii < chLogSecRelateLogRouteSum; ii++)
			{
				if (LogicSectionDataStru[wBufIndex].szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId == wLogRouteId)
				{
					break;
				}
				else
				{
					; /*继续检查*/
				}
			}

			if (chLogSecRelateLogRouteSum == ii)
			{
				LogicSectionDataStru[wBufIndex].szLogSecLockBelLogRouteData[chLogSecRelateLogRouteSum].wLogSecLockBelLogRouteId = wLogRouteId;
				LogicSectionDataStru[wBufIndex].chLogSecLockBelLogRouteSum = chLogSecRelateLogRouteSum + 1U;
			}
			else
			{
				; /*已存在不添加*/
			}
		}
		else
		{
			; /*非法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/*
* 功能描述： 设置非联锁指定ID逻辑区段的逻辑锁闭状态与方向
* 参数说明： const UINT16 logSectionId 逻辑区段ID
*            const UINT8 chLogLockState 逻辑区段逻辑锁闭状态
*			 const UINT8 chLogLockDir 逻辑区段逻辑锁闭方向
*            const UINT8 cLogLockBelLogRouteSum 逻辑区段逻辑锁闭所属逻辑进路数量
* 返回值  ： 无
* Created By LQ 2023/10/20
*/
void SetLogSecLogLockStateOtherCi(const UINT16 wLogSectionId, const UINT8 chLogLockState, const UINT8 chLogLockDir, const UINT8 cLogLockBelLogRouteSum)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	UINT8 cLogSecLockState = 0U;  /*逻辑区段锁闭状态*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if (LOG_SECTION_LOGLOCK_NO == chLogLockState)
		{
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = 0U;

			cLogSecLockState = GetLogSecLockState(wLogSectionId);
			if (LOG_SECTION_LOCK_NO == cLogSecLockState)
			{
				/*进路锁闭和逻辑锁闭均未锁闭，清除逻辑区段资源列车信息*/
				LogicSectionDataStru[wBufIndex].chTrainInfoSum = 0U;
				(void)CommonMemSet(LogicSectionDataStru[wBufIndex].szTrainResData, (UINT32)sizeof(LogicSectionDataStru[wBufIndex].szTrainResData), 0U, (UINT32)sizeof(LogicSectionDataStru[wBufIndex].szTrainResData));
			}
			else
			{
				/*存在进路锁闭，不清资源*/
			}
		}
		else if (LOG_SECTION_LOGLOCK_NORMAL == chLogLockState)
		{
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = chLogLockDir;
		}
		else if (LOG_SECTION_LOGLOCK_EXCEPT == chLogLockState)
		{
			LogicSectionDataStru[wBufIndex].LogSecLogLockState = chLogLockState;
			LogicSectionDataStru[wBufIndex].LogSecLogLockDir = chLogLockDir;
		}
		else
		{
			/*不做处理*/
		}

		/*新增逻辑进路数量，用于跨控区部分进路追逻辑进路（部分进路检查逻辑区段锁闭时需检查逻辑进路数量为1）——Added By LQ 2025.03.10*/
		LogicSectionDataStru[wBufIndex].chLogSecLockBelLogRouteSum = cLogLockBelLogRouteSum;
	}
	else
	{
		/*不做处理*/
	}
}

/**
* @brief 按照方向获取计轴区段内指定ID列车资源可用的逻辑区段
* @param const UINT16 wAxleId 计轴区段ID
*        const UINT16 wTrainId 列车ID
*        const UINT8 cDir 逻辑方向
*        UINT16 pOutLgcSec[TRAIN_INCLUDE_RES_MAX_SUM]  资源可用的逻辑区段ID数组（出参）
* @return <UINT8_MAX 资源可用的逻辑区段数量  
*         UINT8_MAX 获取失败
* @note Created By LQ 2024.04.02
*/
UINT8 GetResUsableLogSecNumInAxis(const UINT16 wAxleId, const UINT16 wTrainId, const UINT8 cDir, UINT16 pOutLgcSec[TRAIN_INCLUDE_RES_MAX_SUM])
{
	UINT8 retVal = UINT8_MAX;
	UINT8 cOutLgcSecSum = 0U;
	UINT8 ii = 0U;
	UINT8 wAxisSecIncLogicSum = 0U;  /*计轴区段包含的逻辑区段数量*/
	UINT16* pAxisSecIncLogicSecIdBuf = NULL;  /*计轴区段包含的逻辑区段ID*/
	UINT8 cResUsableState = LOGIC_SECTION_RES_UNUSABLE;  /*资源可用状态*/
	UINT8 cQueryFlag = FLAG_UNSET;

	if (((0U < wAxleId) && (AXIS_SECTION_SUM_MAX > wAxleId)) 
		&& ((0U < (wTrainId & 0x00FFU)) && (0x00FFU > (wTrainId & 0x00FFU))) 
		&& ((DIR_SAME == cDir) || (DIR_CONVERT == cDir))
		&& (NULL != pOutLgcSec))
	{
		wAxisSecIncLogicSum = GetAxisSecLogSectionSum(wAxleId);
		pAxisSecIncLogicSecIdBuf = GetAxisSecLogSectionIdBuf(wAxleId);

		if ((0U < wAxisSecIncLogicSum) && (NULL != pAxisSecIncLogicSecIdBuf))
		{
			if (DIR_SAME == cDir)
			{
				for (ii = 0U; ii < wAxisSecIncLogicSum; ii++)
				{
					cResUsableState = GetLogSecTrainResUsableState(pAxisSecIncLogicSecIdBuf[ii], wTrainId);  /*获取逻辑区段对应列车的资源可用性*/
					if (LOGIC_SECTION_RES_USABLE == cResUsableState)
					{
						pOutLgcSec[cOutLgcSecSum] = pAxisSecIncLogicSecIdBuf[ii];  /*按顺序输出逻辑区段*/
						cOutLgcSecSum++;
						cQueryFlag = FLAG_SET;
					}
					else if(FLAG_SET == cQueryFlag)
					{						
						(void)CommonMemSet(pOutLgcSec, (UINT32)(cOutLgcSecSum * sizeof(UINT16)), 0U, (UINT32)(cOutLgcSecSum * sizeof(UINT16)));  /*中途查到不可用资源，将之前存储的逻辑区段清空*/
						cOutLgcSecSum = 0U;
						cQueryFlag = FLAG_UNSET;  /*重新置位*/
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			else
			{
				for (ii = wAxisSecIncLogicSum; ii > 0U; ii--)
				{
					cResUsableState = GetLogSecTrainResUsableState(pAxisSecIncLogicSecIdBuf[ii - 1U], wTrainId);  /*获取逻辑区段对应列车的资源可用性*/
					if (LOGIC_SECTION_RES_USABLE == cResUsableState)
					{
						pOutLgcSec[cOutLgcSecSum] = pAxisSecIncLogicSecIdBuf[ii - 1U];  /*按顺序输出逻辑区段*/
						cOutLgcSecSum++;
						cQueryFlag = FLAG_SET;
					}
					else if (FLAG_SET == cQueryFlag)
					{
						(void)CommonMemSet(pOutLgcSec, (UINT32)(cOutLgcSecSum * sizeof(UINT16)), 0U, (UINT32)(cOutLgcSecSum * sizeof(UINT16)));  /*中途查到不可用资源，将之前存储的逻辑区段清空*/
						cOutLgcSecSum = 0U;
						cQueryFlag = FLAG_UNSET;  /*重新置位*/
					}
					else
					{
						/*继续检查*/
					}
				}
			}
			retVal = cOutLgcSecSum;
		}
		else
		{
			/*获取计轴区段包含的逻辑区段失败，返回UINT8_MAX失败*/
		}
	}
	else
	{
		/*入参非法，返回UINT8_MAX失败*/
	}

	return retVal;
}

/*
* 功能描述： 获取指定ID逻辑区段ABL接近可用标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： 0: 获取数据失败
*			>0: ABL列车关联逻辑区段允许使用标志
*/
UINT8 GetLogSecAblUseFlag(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取ABL列车关联逻辑区段允许使用标志 */
		retVal = LogicSectionDataStru[bufIndex].chAblRelLogSecUsableFlag;
	}
	else
	{
		/** 获取数据失败 */
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段ABL接近可用标志
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 ablUseFlag, ABL接近可用标志
* 返回值  ： 无
*
*/
void SetLogSecAblUseFlag(const UINT16 logSectionId, const UINT8 ablUseFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 入参合法 */
		if ((LOGIC_ABLNEAR_USE_FLAG_YES == ablUseFlag) || (LOGIC_ABLNEAR_USE_FLAG_NO == ablUseFlag))
		{
			/** 设置指定ID逻辑区段ABL接近可用标志*/
			LogicSectionDataStru[bufIndex].chAblRelLogSecUsableFlag = ablUseFlag;
		}
		else
		{
			/** 不做处理 */
		}
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述： 获取指定ID逻辑区段临时限速取值
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
* 返回值  ： UINT8_MAX: 获取数据失败
*			>0: 临时限速取值
* BY CGH 20240415
*/
UINT8 GetLogSecXiansuSpeed(const UINT16 logSectionId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT8 retVal = UINT8_MAX;

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 获取指定ID逻辑区段临时限速取值 */
		retVal = LogicSectionDataStru[bufIndex].chLinShiXianSuSetSpeed;
	}
	else
	{
		; /*返回MAX*/
	}
	return retVal;
}


/*
* 功能描述： 设置指定ID逻辑区段临时限速取值
* 参数说明： const UINT16 logSectionId, 逻辑区段ID
*			 const UINT8 ablUseFlag, 临时限速取值
* 返回值  ： 无
* BY CGH 20240415
*/
void SetLogSecXiansuSpeed(const UINT16 logSectionId, const UINT8 chXiansuSpeed)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	/** 获取逻辑区段数组下标 */
	bufIndex = GetlogSectionBufIndex(logSectionId);

	/** 区段下标合法 */
	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/** 设置指定ID逻辑区段临时限速取值*/
		LogicSectionDataStru[bufIndex].chLinShiXianSuSetSpeed = chXiansuSpeed;
	}
	else
	{
		/** 不做处理 */
	}
}

/*
* 功能描述：设置其它CI发送的逻辑区段防护锁闭所属进路ID
* 参数说明：const UINT16 wLogSectionId 逻辑区段ID
*           const UINT16 wPLockRouteId 防护锁闭所属进路ID
* 返 回 值：无
* Created By LQ 2024.06.11
*/
void SetLogSecOtherCiPLockRouteId(const UINT16 wLogSectionId, const UINT16 wPLockRouteId)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId) ;  /*获取区段数组下标*/

	if ((LOGIC_SECTION_SUM_MAX > wBufIndex) && (ROUTE_SUM_MAX > wPLockRouteId))
	{
		LogicSectionDataStru[wBufIndex].OtherCiPLockBelongRouteId = wPLockRouteId;  /*设置其它CI防护锁闭所属进路ID*/
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：获物其它CI发送的逻辑区段防护锁闭所属进路ID
* 参数说明：const UINT16 wLogSectionId 逻辑区段ID
* 返 回 值：其它CI发送的逻辑区段防护锁闭所属进路ID
* Created By LQ 2024.06.11
*/
UINT16 GetLogSecOtherCiPLockRouteId(const UINT16 wLogSectionId)
{
	UINT16 wRetVal = 0U;
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wRetVal = LogicSectionDataStru[wBufIndex].OtherCiPLockBelongRouteId;  /*返回其它CI防护锁闭所属进路ID*/
	}
	else
	{
		/*入参非法，不处理*/
	}

	return wRetVal;
}

/*
* 功能描述：获取指定ID逻辑区段防护锁闭所属进路命令发送标志
* 参数说明：const UINT16 wLogSecId 逻辑区段ID
* 返回值  ：CI_ERROR 0 不发送
*			CI_SUCCESS 1 发送
* Created By LQ 2024.06.11
*/
UINT8 GetLogSecPLockRouteCmdSendFlag(const UINT16 wLogSecId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 bufIndex = 0U;
	UINT8 cLocalCiId = 0U;
	UINT8 cSecBelongCiId = 0U;  /*区段所属CI*/
	UINT8 cSecLockState = PHYSICAL_SECTION_LOCK_NO;  /*区段锁闭状态*/
	UINT16 wSecRLockBelongRouteId = 0U;  /*区段进路锁闭所属进路*/
	UINT16 wSecPLockBelongRouteId = 0U;  /*区段防护锁闭所属进路*/
	UINT8 cRRouteBelongCiId = 0u;  /*进路锁闭所属进路的所属CI*/
	UINT8 cPRouteBelongCiId = 0u;  /*防护锁闭所属进路的所属CI*/
	UINT16 OtherCiPLockRouteId = 0U;  /*其它CI发送的逻辑区段防护锁闭所属进路ID*/

	bufIndex = GetlogSectionBufIndex(wLogSecId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > bufIndex)
	{
		/******** 1.判断是否为本控区区段 ********/
		cLocalCiId = GetSystemParaLocalCiId();
		cSecBelongCiId = GetLogSecBelongCiId(wLogSecId);		

		if ((0U != cLocalCiId) && (cLocalCiId == cSecBelongCiId))
		{
			/******** 2.判断是否区段为正常锁闭或延时解锁 ********/
			cSecLockState = GetLogSecLockState(wLogSecId);

			if ((LOG_SECTION_LOCK_NORMAL == cSecLockState) || (LOG_SECTION_LOCK_DELAY == cSecLockState))
			{
				/********* 3.判断是否进路锁闭所属进路非本控区且（防护锁闭所属进路也非本控区或无防护锁闭所属进路） ********/
				wSecRLockBelongRouteId = GetLogSecLockBelongRoute(wLogSecId);  /*获取进路锁闭所属进路*/
				cRRouteBelongCiId = GetRouteBelongCiId(wSecRLockBelongRouteId);
				wSecPLockBelongRouteId = GetLogSecPLockRouteId(wLogSecId);  /*获取防护锁闭所属进路*/
				cPRouteBelongCiId = GetRouteBelongCiId(wSecPLockBelongRouteId);

				if ((cLocalCiId != cRRouteBelongCiId) && (0U != cRRouteBelongCiId) && ((cRRouteBelongCiId == cPRouteBelongCiId) || (0U == cPRouteBelongCiId)))
				{
					/********* 4.判断是否本控区的区段防护锁闭所属进路与进路锁闭所属进路控区的区段防护锁闭所属进路不同 ********/
					OtherCiPLockRouteId = GetLogSecOtherCiPLockRouteId(wLogSecId);
					if (OtherCiPLockRouteId != wSecPLockBelongRouteId)
					{
						cRetVal = CI_SUCCESS;  /*本控区的区段防护锁闭所属进路与进路锁闭所属进路控区的区段防护锁闭所属进路不同，返回1*/
					}
					else
					{
						/*防护锁闭所属进路相同，不处理*/
					}
				}
				else
				{
					/*进路锁闭所属进路不满足，不处理*/
				}
			}
			else
			{
				/*区段锁闭状态不满足，不处理*/
			}
		}
		else
		{
			/*非本控区区段，不处理*/
		}
	}
	else
	{
		cRetVal = CI_ERROR;  /*逻辑区段ID非法，返回0*/
	}

	return cRetVal;
}


/*
* 功能描述：设置进路离去区段的ABL列车条件检查标志
* 参数说明：UINT16 wLogSectionId 离去逻辑区段ID
*           UINT8 setFlag  离去区段的ABL列车条件检查标志
* 返回值  ：无
*/
void SetRouteLeaveLogSecFlag(UINT16 wLogSectionId, UINT8 setFlag)
{
	
	UINT16 wBufIndex = 0u;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		if ((LOGSEC_LEAVE_LOGSEC_REPLY_YES == setFlag) || (LOGSEC_LEAVE_LOGSEC_REPLY_NO == setFlag))
		{
			LogicSectionDataStru[wBufIndex].cRouteLeaveLogFlag = setFlag;
		}
	}

}

/*
* 功能描述： 获取逻辑区段的ABL列车条件检查标志
* 参数说明： const UINT16 wLogSectionId 离去逻辑区段ID
* 返回值  ： >0 离去区段的ABL列车条件检查标志
*             0 获取失败
*/
UINT8 GetRouteLeaveLogFlag(const UINT16 wLogSectionId)
{
	UINT8 wRetVal = 0U;
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		wRetVal = LogicSectionDataStru[wBufIndex].cRouteLeaveLogFlag;  /*返回逻辑区段的ABL列车条件检查标志*/
	}
	else
	{
		/*入参非法，不处理*/
	}
	return wRetVal;
}

/*
* 功能描述： 获取指定ID逻辑区段锁闭所属逻辑进路数组
* 参数说明： const UINT16 wLgcId, 逻辑区段ID
*	        OUT LogSecLockBelLogRouteStruct szLogSecLockBelLogRouteData[LOGSEC_RELATE_ROUTE_SUM_MAX]  指定ID逻辑区段锁闭所属逻辑进路数组
* 返回值  ： 指定ID逻辑区段锁闭所属逻辑进路数目
* 创建	  :  cgh 2024-09-10
*/
UINT8 GetLogSecLockBelLogRouteBuf(const UINT16 wLgcId,OUT LogSecLockBelLogRouteStruct szLogSecLockBelLogRouteData[LOGSEC_RELATE_ROUTE_SUM_MAX])
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	UINT8 chReval = CI_ERROR;

	wBufIndex = GetlogSectionBufIndex(wLgcId);  /*获取逻辑区段下标*/

	if ((LOGIC_SECTION_SUM_MAX > wBufIndex) && (NULL != szLogSecLockBelLogRouteData))
	{
		chReval = LogicSectionDataStru[wBufIndex].chLogSecLockBelLogRouteSum;
		(void)CommonMemCpy((void*)(szLogSecLockBelLogRouteData), (UINT32)(LOGSEC_RELATE_ROUTE_SUM_MAX * (UINT32)sizeof(LogSecLockBelLogRouteStruct)), (void*)(LogicSectionDataStru[wBufIndex].szLogSecLockBelLogRouteData), (UINT32)(LOGSEC_RELATE_ROUTE_SUM_MAX * (UINT32)sizeof(LogSecLockBelLogRouteStruct)));
	}
	else
	{
		
	}
	return chReval;
}

/*
* 功能描述： 设置互联互通其它联锁逻辑区段锁闭状态
* 参数说明：UINT16 wLogSectionId, 物理区段ID
            const UINT8 lockState,锁闭状态
* 返回值  ：无
* by cgh 20250117
*/
void SetLogSecLockStateHlht(UINT16 wLogSectionId, const UINT8 lockState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 preLockState = 0u;

	bufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		LogicSectionDataStru[bufIndex].LogLockState = lockState;
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：设置互联互通其它联锁逻辑区段上电锁闭状态
* 参数说明：UINT16 wLogSectionId 逻辑区段ID
*			const UINT8 lockState 上电锁闭状态
* 返 回 值：无
*/
void SetLogSecStartLockStateHlht(UINT16 wLogSectionId, const UINT8 lockState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 preLockState = 0u;

	bufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		preLockState = LogicSectionDataStru[bufIndex].LogLockState;

		if (LOG_SECTION_LOCK_START != preLockState)
		{
			if (LOG_SECTION_LOCK_START == lockState)
			{
				LogicSectionDataStru[bufIndex].LogLockState = lockState;
			}
			else
			{
				/*维持当前锁闭状态*/
			}
		}
		else
		{
			LogicSectionDataStru[bufIndex].LogLockState = lockState;
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：设置互联互通其它联锁逻辑区段的锁闭方向
* 参数说明：UINT16 wLogSectionId, 逻辑区段ID
            const UINT8 lockDir,锁闭方向
* 返回值  ：无
* by cgh 20250117
*/
void SetLogSecLockDirHlht(UINT16 wLogSectionId, const UINT8 lockDir)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		if (CI_SYSTEM_DIRECTION_NONE == lockDir)
		{
			LogicSectionDataStru[bufIndex].LogLockDir = CI_SYSTEM_DIRECTION_NONE;
		}
		else
		{
			LogicSectionDataStru[bufIndex].LogLockDir = lockDir;
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：设置互联互通其它联锁逻辑区段保护锁闭所属的进路ID
* 参数说明：UINT16 wLogSectionId, 逻辑区段ID
	        const UINT16 routeId,保护锁闭所属的进路ID
* 返回值  ：无
* by 20250117
*/
void SetLogSecPLockRouteIdHlht(UINT16 wLogSectionId, const UINT16 routeId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		LogicSectionDataStru[bufIndex].wPLockBelongRouteId = routeId;
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：设置互联互通其它联锁逻辑区段锁闭所属的进路ID
* 参数说明：UINT16 wLogSectionId, 逻辑区段ID
			const UINT16 routeId,锁闭所属的进路ID
* 返回值  ：无
* by 20250117
*/
void SetLogSecRLockRouteIdHlht(UINT16 wLogSectionId, const UINT16 routeId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/

	if (bufIndex < LOGIC_SECTION_SUM_MAX)
	{
		LogicSectionDataStru[bufIndex].LogLockBelongRoute = 0U;
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述： 设置逻辑区段关联的所有逻辑进路状态
* 参数说明： const UINT16 wLogSectionId, 逻辑区段ID
* 返回值  ： VOID
* by cgh 20250416
*/
void SetLogSecRelAllLogRouteState(const UINT16 wLogSectionId)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/
	UINT8 ii = 0U;
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数量*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/

	wBufIndex = GetlogSectionBufIndex(wLogSectionId);  /*获取区段数组下标*/
	if (LOGIC_SECTION_SUM_MAX > wBufIndex)
	{
		/*获取逻辑区段锁闭所属逻辑进路数据*/
		chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSectionId);
		szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSectionId);
		if (NULL != szLogSecLockBelLogRouteData)
		{
			for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
			{
				(void)SetLogicalRouteState(szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKDELAY);
				/*设置逻辑进路状态会设置延时解锁起始周期号，故障时必然为0此处同步更新*/
				SetLogRouteDelayErrLockStartCyc(szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId, 0U);
			}
		}
		else
		{
			; /*不执行*/
		}
	}
	else
	{

	}
}