#include "LogicalRouteDataManage.h"
#include "PhysicalSectionDataManage.h"
#include "InterlockCommonManage.h"
#include "../LogicProcess/LogicalRouteLogicCheck.h"
#include "LogicSectionDataManage.h"

LogicalRouteDataStruct LogicalRouteDataStru[ROUTE_LOGICAL_SUM_MAX];
UINT16 LogicalRouteSum = 0U;
UINT16 LogicalRouteIdBuff[ROUTE_LOGICAL_SUM_MAX] = { 0U };

/**
* @brief 逻辑进路状态主处理函数
* @param 无
* @return 无
* @note：
*/
void LogicalRouteProcess(void)
{
	UINT8 chLogRouteState = 0u; /*逻辑进路状态*/
	UINT16 wLogRouteId = 0u; /*逻辑进路ID*/
	UINT16 ii = 0u; /*循环索引*/
	UINT16 logicRouteSum = 0U;
	UINT8 chStartLockFlag = CI_START_LOCK_YES;
	UINT16 wSignalId = 0U;

	chStartLockFlag = GetStartLockFlag();
	if (CI_START_LOCK_NO != chStartLockFlag)
	{ /*未上电解锁*/
		; /* 不处理 */
	}
	else
	{
		logicRouteSum = GetLogicalRouteSum();
		/*处理逻辑进路*/
		for (ii = 0u; ii < logicRouteSum; ii++)
		{
			wLogRouteId = GetLogicalRouteId(ii);
			if (0U != wLogRouteId)
			{
				chLogRouteState = GetLogicalRouteState(wLogRouteId);
				LogicRouteLevelConfirmProcess(wLogRouteId);
				switch (chLogRouteState)
				{
				case ROUTE_LOGICAL_STATE_IDLE:
					/* 逻辑进路空闲 */
					; /* 不处理 */
					break;
				case ROUTE_LOGICAL_STATE_FIRST_XUANPAI:
					/* 逻辑进路初选 */
					LogRouteFirstXuanPaiProc(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_XUANPAI:
					/* 逻辑进路选排 */
					LogRouteXuanPaiProc(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_LOCK:
					/* 逻辑进路锁闭 */
					LogRouteLockProc(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_OPEN:
					/* 逻辑进路开放*/
					LogRouteOpenManage(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_LOCKERR:
					LogRouteLockErrManage(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_UNLOCKWAIT:
					/* 逻辑进路等待解锁*/
					LogRouteLgcSecResUnlockManage(wLogRouteId);
					break;
				case ROUTE_LOGICAL_STATE_UNLOCKDELAY:
					/* 逻辑进路延时解锁*/
					LogRouteUnlockDelayManage(wLogRouteId);
					break;
				default:
					/* 状态异常 */
					SetPlatOverFlag();
					SetErrorData(EFUNC_PLAT_OVER, CI_DEVICE_TYPE_ROUTE, wLogRouteId, ETYPE_ROUTE_STATE, chLogRouteState, ESEND_LEVEL_ZERO);/*记录宕机故障码*/
					break;
				}
			}
		}
		/*每周期出清所有逻辑进路进路信号机异常关闭的标志位(处理完进路逻辑后)*/
		for (ii = 0u; ii < logicRouteSum; ii++)
		{
			wLogRouteId = GetLogicalRouteId(ii);
			wSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);

			if ((0U != wLogRouteId) && (0U != wSignalId))
			{
				SetLogRouteSignalErrCloseFlag(wSignalId, LOG_ROUTE_SIGNAL_CLOSE_NOERR);
			}
		}
	}
}

/**
* @brief 初始化逻辑进路数据
* @param 无
* @return 逻辑进路总数
* @note：by cgh 20231010
*/
void InitialLogicalRouteData(void)
{
	UINT16 ii = 0U;								/*游标*/

	for (ii = 1U; ii < ROUTE_LOGICAL_SUM_MAX; ii++)
	{
		LogicalRouteDataStru[ii].wLogRouteId = ii;								                 /*逻辑进路ID */
		LogicalRouteDataInitial(ii);
		LogicalRouteIdBuff[LogicalRouteSum++] = LogicalRouteDataStru[ii].wLogRouteId;
	}
}

/**
* @brief 逻辑进路数据初始化
* @param const UINT16 wIndex 逻辑进路索引
* @return 逻辑进路总数
* @note：by cgh 20231012
*/
void LogicalRouteDataInitial(const UINT16 wIndex)
{
	UINT16 kk = 0U;

	if (wIndex < ROUTE_LOGICAL_SUM_MAX)
	{
		LogicalRouteDataStru[wIndex].chLogRouteDir = CI_SYSTEM_DIRECTION_NONE;								             /*逻辑进路方向（运营方向） */
		LogicalRouteDataStru[wIndex].chLogicRouteState = ROUTE_LOGICAL_STATE_IDLE;										 /*逻辑进路状态*/
		LogicalRouteDataStru[wIndex].chLogRouteLevel = ROUTE_LEVEL_BLOC;							                 /*逻辑进路监督级别(点式/CBTC) (动态字段)*/
		LogicalRouteDataStru[wIndex].chLogRouteBelongCiId = 0U;                                      /*逻辑进路所属联锁*/
		LogicalRouteDataStru[wIndex].chLogicRouteOpenColor = SIGNAL_SHOWCOLOUR_INVALID;									 /*逻辑进路开放颜色*/
		LogicalRouteDataStru[wIndex].wLogRouteInLogSecSum = 0U;                                     /*逻辑进路包含的逻辑区段数量*/
		for (kk = 0U; kk < MAX_ROUTE_IN_LT_NUM; kk++)
		{
			LogicalRouteDataStru[wIndex].szLogRouteInLogSecIdBuf[kk] = 0U;            /*逻辑进路包含的逻辑区段ID数组*/
			LogicalRouteDataStru[wIndex].szLogRouteTrainLogSecIdBuf[kk] = 0U;          /*逻辑进路列车脚下逻辑区段ID数组*/
		}
		LogicalRouteDataStru[wIndex].chLogRouteSwitchMoveFlag = ROUTE_LOGICAL_SWITCH_MOVE_INVALID;                                  /*逻辑进路是否可动道岔标志*/
		LogicalRouteDataStru[wIndex].wLogRouteTrainLogSecSum = 0U;                                  /*逻辑进路列车脚下逻辑区段数量*/
		LogicalRouteDataStru[wIndex].wLogRouteRelateBeginSigId = 0U;                                /*逻辑进路关联始端信号机ID*/
		LogicalRouteDataStru[wIndex].dwLogRouteChuXuanStartCycNum = 0U;                            /*逻辑进路初选起始周期号*/
		LogicalRouteDataStru[wIndex].dwLogRouteXuanPaiStartCycNum = 0U;						     /*逻辑进路选排起始周期号*/
		LogicalRouteDataStru[wIndex].dwLogRouteLockStartCycNum = 0U;							     /*逻辑进路锁闭起始周期号*/
		LogicalRouteDataStru[wIndex].dwDelayErrLockStartCycNum = 0U;                                /*区故解延时解锁起始周期号*/
		LogicalRouteDataStru[wIndex].chLogRouteRecoverOpenState = ROUTE_REPEATOPEN_SET_NO;                                /*逻辑进路信号重开标志*/

		LogicalRouteDataStru[wIndex].szLogRouteApplyResTrainId = 0U;  /*逻辑进路ATS请求资源列车ID*/
		LogicalRouteDataStru[wIndex].chLogRouteRelatePsdSum = 0U;                                    /*逻辑进路关联屏蔽门数量*/
		LogicalRouteDataStru[wIndex].routeInSwitOtherPosLogSecSum = 0U;   /*进路内道岔关联的非进路内逻辑区段数量*/
		LogicalRouteDataStru[wIndex].routeOutLogSecSum = 0U;  /*进路包含物理区段关联的非进路内且非道岔关联的逻辑区段数量 */

		for (kk = 0U; kk < ROUTE_PSD_SUM_MAX; kk++)
		{
			LogicalRouteDataStru[wIndex].szLogRouteRelatePsdIdBuf[kk] = 0U;              /*逻辑进路关联屏蔽门ID数组*/
		}
		LogicalRouteDataStru[wIndex].chLogRouteRelateEsbSum = 0U;                                    /*逻辑进路关联紧急停车按钮数量*/
		for (kk = 0U; kk < ROUTE_ESB_SUM_MAX; kk++)
		{
			LogicalRouteDataStru[wIndex].szLogRouteRelateEsbIdBuf[kk] = 0U;              /*逻辑进路关联紧急停车按钮ID数组*/
		}
		for (kk = 0U; kk < MAX_ROUTE_IN_LT_NUM; kk++)
		{
			LogicalRouteDataStru[wIndex].routeInSwitOtherPosLogSecIdBuf[kk] = 0U;             /*进路内道岔关联的非进路内逻辑区段ID数组*/
		}
		for (kk = 0U; kk < MAX_ROUTE_IN_LT_NUM; kk++)
		{
			LogicalRouteDataStru[wIndex].routeOutLogSecSumIdBuf[kk] = 0U;             /*进路包含物理区段关联的非进路内且非道岔关联的逻辑区段ID数组 */
		}
	}
	else
	{
		; /*不操作*/
	}
}

/**
* @brief 获取逻辑进路总数
* @param 无
* @return 逻辑进路总数
* @note：by cgh 20231010
*/
UINT16 GetLogicalRouteSum(void)
{
	UINT16 wRetVal = 0U;
	if (ROUTE_LOGICAL_SUM_MAX <= LogicalRouteSum)
	{
		wRetVal = ROUTE_LOGICAL_SUM_MAX;
	}
	else
	{
		wRetVal = LogicalRouteSum;
	}
	return wRetVal;
}

/**
* @brief 获取逻辑进路结构体
* @param 无
* @return 逻辑进路结构体
* @note：by lq 20231016
*/
LogicalRouteDataStruct* GetLogicalRouteStr(void)
{
	return LogicalRouteDataStru;
}

/**
* @brief 获取逻辑进路ID数组
* @param const UINT16 wIndex 逻辑进路索引
* @return 逻辑进路ID
* @note：by cgh 20231010
*/
UINT16 GetLogicalRouteId(const UINT16 wIndex)
{
	UINT16 wRetVal = 0U;
	UINT16 wLogicalRouteSum = GetLogicalRouteSum();

	if (wIndex < wLogicalRouteSum)
	{
		wRetVal = LogicalRouteIdBuff[wIndex];
	}
	else
	{
		/* 不处理 */
	}
	return wRetVal;
}

/**
* @brief 获取逻辑进路索引
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路索引
* @note：by cgh 20231010
*/
UINT16 GetLogRouteBufIndex(const UINT16 wLogRouteId)
{
	UINT16 wRetVal = ROUTE_LOGICAL_SUM_MAX;

	if (ROUTE_LOGICAL_SUM_MAX > wLogRouteId)
	{
		wRetVal = wLogRouteId;
	}
	else
	{
		/* 不处理 */
	}
	return wRetVal;
}

/**
* @brief 获取最小可用逻辑进路（ID最小，状态空闲）
* @param 无
* @return 逻辑进路ID
* @note：by cgh 20231011
*/
UINT16 GetUsableLogicalRouteId(void)
{
	UINT16 ii = 0U;								/*游标*/
	UINT16 wLogicalRouteId = 0U;

	for (ii = 1U; ii < ROUTE_LOGICAL_SUM_MAX; ii++)
	{
		if (ROUTE_LOGICAL_STATE_IDLE == LogicalRouteDataStru[ii].chLogicRouteState)
		{
			wLogicalRouteId = LogicalRouteDataStru[ii].wLogRouteId;
			break;
		}
	}
	return wLogicalRouteId;
}

/**
* @brief 设置逻辑进路方向
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteDir 逻辑进路方向
* @return 无
* @note：by cgh 20231010
*/
void SetLogicalRouteDir(const UINT16 wLogRouteId, const UINT8 chLogRouteDir)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((CI_SYSTEM_DIRECTION_DOWN == chLogRouteDir) || (CI_SYSTEM_DIRECTION_UP == chLogRouteDir))
		{
			LogicalRouteDataStru[wBufIndex].chLogRouteDir = chLogRouteDir;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路方向
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路方向
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteDir(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_SYSTEM_DIRECTION_NONE;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteDir;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 逻辑进路状态设置管理，逻辑进路状态设置必须通过本函数
* @param const UINT16 wLogRouteId, 逻辑进路ID      const UINT8 chLogRouteState 逻辑进路状态
* @return CI_ERROR
			CI_SUCCESS
* @note：by cgh 20231012
*/
void SetLogRouteStateManage(const UINT16 wLogRouteId,const UINT8 chLogRouteState)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wResReqTrainId = 0U;
	UINT16 wLogRouteTrainId = 0U;
	UINT32 dwCurCycNum = 0U;

	chRetVal = LogRouteStateValidCheck(chLogRouteState);
		
	dwCurCycNum = Get2oo2CurCycleNum();

	if (CI_SUCCESS == chRetVal)
	{
		switch (chLogRouteState)
		{
		case ROUTE_LOGICAL_STATE_IDLE:
			/* 逻辑进路空闲 */
			
			/*设置进路物理区段未征用*/
			SetLogRouteSectionUsingState(wLogRouteId, PHYSICAL_SECTION_USING_NO);
			/*设置进路逻辑区段: 未锁闭*/
			SetLogRouteSecLockState(wLogRouteId, LOG_SECTION_LOGLOCK_NO);
			/*取消进路关联防护道岔的防护锁闭*/
			SetLogRouteProSwLockState(wLogRouteId, SWITCH_LOCK_PROTECT_CANCEL);


			break;
		case ROUTE_LOGICAL_STATE_FIRST_XUANPAI:
			/* 逻辑进路初选 */

			/*设置进路逻辑区段征用*/
			SetLogRouteSectionUsingState(wLogRouteId, PHYSICAL_SECTION_USING_YES);

			break;
		case ROUTE_LOGICAL_STATE_XUANPAI:
			/* 逻辑进路选排 */

			/*无特殊处理*/

			break;
		case ROUTE_LOGICAL_STATE_LOCK:
			/* 逻辑进路锁闭 */

			/*设置进路物理区段未征用*/
			SetLogRouteSectionUsingState(wLogRouteId, PHYSICAL_SECTION_USING_NO);
			/*设置进路逻辑区段: 正常锁闭*/
			SetLogRouteSecLockState(wLogRouteId, LOG_SECTION_LOGLOCK_NORMAL);

			/*设置道岔不可动标志*/
			SetLogicalRouteSwitchMoveFlag(wLogRouteId, ROUTE_LOGICAL_SWITCH_MOVE_INVALID);

			/*设置逻辑进路防护道岔: 防护锁闭*/
			SetLogRouteProSwLockState(wLogRouteId, SWITCH_LOCK_PROTECT_SET);

			/*清除进路相关道岔期望驱动位置*/
			ClearLogRouteSwitchDrivePos(wLogRouteId);
			/*清除进路相关道岔单操位置*/
			ClearLogRouteSwitchDanCaoPos(wLogRouteId);
			

			/*添加锁闭列车资源——韦创*/
			wLogRouteTrainId = GetLogicalRouteApplyResTrainId(wLogRouteId);
			SetLogRouteLogSecResTrainId(wLogRouteId, wLogRouteTrainId);
		
			break;
		case ROUTE_LOGICAL_STATE_OPEN:
			/* 逻辑进路开放*/
			CleanLogRoutePhySecPreOccuSta(wLogRouteId);
			break;
		case ROUTE_LOGICAL_STATE_LOCKERR:
			/*逻辑进路异常锁闭*/

			break;
		case ROUTE_LOGICAL_STATE_UNLOCKWAIT:
			/* 逻辑进路等待解锁*/

			break;
		case ROUTE_LOGICAL_STATE_UNLOCKDELAY:
			/* 逻辑进路延时解锁*/
			SetLogRouFirDelayErLockStaCyc(wLogRouteId, dwCurCycNum);
			break;

		default:

			/*进路状态异常*/
			/*xxxxx宕机*/
			break;
		}

		/*设置进路状态*/
		(void)SetLogicalRouteState(wLogRouteId, chLogRouteState);

	}
	else
	{
		/*记录系统故障*/
		SetErrorData(EFUNC_LOGIC_MANAGE_SYETEM,
			EFUNC_LOGIC_MANAGE_SYETEM,
			CI_ERROR,
			ETYPE_SYSTEM_EXCEPT,
			CI_ERROR, ESEND_LEVEL_ZERO);

	}
	
}

/**
* @brief 逻辑进路状态有效性检查
* @param const UINT8 chLogRouteState 逻辑进路状态
* @return CI_ERROR: 数据无效   CI_SUCCESS: 数据有效
* @note：by cgh 20231010
*/
UINT8 LogRouteStateValidCheck(const UINT8 chLogRouteState)
{
	UINT8 retVal = CI_ERROR;

	if ((ROUTE_LOGICAL_STATE_IDLE == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_FIRST_XUANPAI == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_XUANPAI == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_LOCK == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_OPEN == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_UNLOCKWAIT == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_UNLOCKDELAY == chLogRouteState) ||
		(ROUTE_LOGICAL_STATE_LOCKERR == chLogRouteState))
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 设置逻辑进路状态
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogicRouteState 逻辑进路状态
* @return CI_ERROR 设置失败
*         CI_SUCCESS  设置成功
* @note：by cgh 20231010
*/
UINT8 SetLogicalRouteState(const UINT16 wLogRouteId, const UINT8 chLogicRouteState)
{
	UINT16 wBufIndex = 0U;
	UINT8 chRetVal = CI_ERROR;
	UINT32 dwCurCycNum = 0U;/*当前周期号*/
	UINT16 kk = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);
	dwCurCycNum = Get2oo2CurCycleNum();

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}
	if (CI_SUCCESS == chRetVal)
	{
		chRetVal = LogRouteStateValidCheck(chLogicRouteState);
	}
	else
	{
		; /*不处理*/
	}
	if (CI_SUCCESS == chRetVal)
	{
		if (ROUTE_LOGICAL_STATE_IDLE == chLogicRouteState)
		{
			/*初始化结构体中的数据为初始值*/
			LogicalRouteDataInitial(wBufIndex);
		}
		else if (ROUTE_LOGICAL_STATE_FIRST_XUANPAI == chLogicRouteState)
		{
			/*设置逻辑进路初选周期号*/
			LogicalRouteDataStru[wBufIndex].dwLogRouteChuXuanStartCycNum = dwCurCycNum;
		}
		else if (ROUTE_LOGICAL_STATE_XUANPAI == chLogicRouteState)
		{
			/*设置逻辑进路选排周期号*/
			LogicalRouteDataStru[wBufIndex].dwLogRouteXuanPaiStartCycNum = dwCurCycNum;
		}
		else if (ROUTE_LOGICAL_STATE_LOCK == chLogicRouteState)
		{
			/*清除逻辑进路初选及选排周期号，设置逻辑进路锁闭周期号*/
			LogicalRouteDataStru[wBufIndex].dwLogRouteChuXuanStartCycNum = 0U;
			LogicalRouteDataStru[wBufIndex].dwLogRouteXuanPaiStartCycNum = 0U;
			LogicalRouteDataStru[wBufIndex].dwLogRouteLockStartCycNum = dwCurCycNum;
		}
		else if (ROUTE_LOGICAL_STATE_OPEN == chLogicRouteState)
		{

		}
		else if (ROUTE_LOGICAL_STATE_LOCKERR == chLogicRouteState)
		{

		}
		else if (ROUTE_LOGICAL_STATE_UNLOCKWAIT == chLogicRouteState)
		{

		}
		else if (ROUTE_LOGICAL_STATE_UNLOCKDELAY == chLogicRouteState)
		{
			LogicalRouteDataStru[wBufIndex].dwDelayErrLockStartCycNum = dwCurCycNum;
		}
		else
		{
			; /*不处理*/
		}

		LogicalRouteDataStru[wBufIndex].chLogicRouteState = chLogicRouteState; /*逻辑进路状态*/
	}
	else
	{
		; /*不处理*/
	}
	return chRetVal;
}


/*
* 功能描述： 清除逻辑进路物理区段之前占用状态
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_ERROR:清除失败
*			 CI_SUCCESS:清除成功
*/
void CleanLogRoutePhySecPreOccuSta(const UINT16 wLogRouteId)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 wLogRouteSignalId = 0U;
	UINT16 PhySecId = 0u;
	UINT8 ii = 0u;

	LogSecIdBuff = GetLogicalRouteInLogSecId(wLogRouteId);
	logSecSum = GetLogicalRouteInLogSecSum(wLogRouteId);
	wLogRouteSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	if ((NULL != LogSecIdBuff) && (0U != logSecSum))
	{
		for (ii = 0U; ii < logSecSum; ii++)
		{
			PhySecId = GetLgcSecRelativePhySecId(LogSecIdBuff[ii]);

			CleanPhySecPreMergeState(PhySecId);
		}
	}

	/*清除接近区段之前占用*/
	PhySecId = GetSignalOutFirstPhySecId(wLogRouteSignalId);
	CleanPhySecPreMergeState(PhySecId);
}
/**
* @brief 获取逻辑进路状态
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路状态
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteState(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogicRouteState;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路监督级别
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteLevel 逻辑进路监督级别
* @return 无
* @note：by cgh 20231010
*/
void SetLogicalRouteLevel(const UINT16 wLogRouteId, const UINT8 chLogRouteLevel)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((ROUTE_LEVEL_CBTC == chLogRouteLevel) || (ROUTE_LEVEL_BLOC == chLogRouteLevel))
		{
			LogicalRouteDataStru[wBufIndex].chLogRouteLevel = chLogRouteLevel;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路监督级别
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路监督级别
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteLevel(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteLevel;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路所属联锁
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteBelongCiId 逻辑进路所属联锁
* @return 无
* @note：by cgh 20231010
*/
void SetLogicalRouteBelongCiId(const UINT16 wLogRouteId, const UINT8 chLogRouteBelongCiId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if (0U < chLogRouteBelongCiId) 
		{
			LogicalRouteDataStru[wBufIndex].chLogRouteBelongCiId = chLogRouteBelongCiId;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路所属联锁
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路所属联锁
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteBelongCiId(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteBelongCiId;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路开放颜色
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteDir 逻辑进路开放颜色
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteOpenColor(const UINT16 wLogRouteId, const UINT8 chLogRouteOpenColor)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((SIGNAL_SHOWCOLOUR_YELLOWCLOSE == chLogRouteOpenColor) || (SIGNAL_SHOWCOLOUR_GREENCLOSE == chLogRouteOpenColor)
			|| (SIGNAL_SHOWCOLOUR_INVALID == chLogRouteOpenColor))
		{
			LogicalRouteDataStru[wBufIndex].chLogicRouteOpenColor = chLogRouteOpenColor;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路开放颜色
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路方向
* @note：by cgh 20231011
*/
UINT8 GetLogicalRouteOpenColor(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogicRouteOpenColor;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路包含的逻辑区段数据
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT8 wLogRouteInLogSecSum 逻辑进路包含的逻辑区段数目
* @param const UINT16* wLogRouteInLogSecIdbuf 逻辑进路包含的逻辑区段ID数组
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteInLogSecData(const UINT16 wLogRouteId, const UINT8 wLogRouteInLogSecSum, const UINT16* wLogRouteInLogSecIdbuf)
{
	UINT16 wBufIndex = 0U;
	UINT16 ii = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((NULL != wLogRouteInLogSecIdbuf) && (MAX_ROUTE_IN_LT_NUM > wLogRouteInLogSecSum))
		{
			(void)CommonMemSet(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf, \
				(UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf), \
				0U, (UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf));

			for (ii = 0U; ii < wLogRouteInLogSecSum; ii++)
			{
				LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf[ii] = wLogRouteInLogSecIdbuf[ii];
			}
			LogicalRouteDataStru[wBufIndex].wLogRouteInLogSecSum = wLogRouteInLogSecSum;
		}
		else
		{
			(void)CommonMemSet(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf, \
				(UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf), \
				0U, (UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf));

			LogicalRouteDataStru[wBufIndex].wLogRouteInLogSecSum = 0U;
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路包含的逻辑区段数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段数量
* @note：by cgh 20231011
*/
UINT16 GetLogicalRouteInLogSecSum(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].wLogRouteInLogSecSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取逻辑进路包含的逻辑区段ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段ID
* @note：by cgh 20231011
*/
UINT16* GetLogicalRouteInLogSecId(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].szLogRouteInLogSecIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取进路内道岔关联的非进路内逻辑区段数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段数量
* @note：by cgh 20231011
*/
UINT16 GetLogRInSwitOtherPosLogSecSum(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].routeInSwitOtherPosLogSecSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取进路内道岔关联的非进路内逻辑区段ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段ID
* @note：by cgh 20231011
*/
UINT16* GetLogRInSwitOtherPosLogSecID(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].routeInSwitOtherPosLogSecIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取进路包含物理区段关联的非进路内且非道岔关联的逻辑区段数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段数量
* @note：by cgh 20231011
*/
UINT16 GetLogicalRouteOutLogSecSum(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].routeOutLogSecSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取进路包含物理区段关联的非进路内且非道岔关联的逻辑区段ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路包含的逻辑区段ID
* @note：by cgh 20231011
*/
UINT16* GetLogicalRouteOutLogSecID(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].routeOutLogSecSumIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路是否可动道岔标志
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteLevel 逻辑进路是否可动道岔标志
* @return 无
* @note：by cgh 20231010
*/
void SetLogicalRouteSwitchMoveFlag(const UINT16 wLogRouteId, const UINT8 chLogRouteSwitchMoveFlag)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((ROUTE_LOGICAL_SWITCH_MOVE_VALID == chLogRouteSwitchMoveFlag) || (ROUTE_LOGICAL_SWITCH_MOVE_INVALID == chLogRouteSwitchMoveFlag))
		{
			LogicalRouteDataStru[wBufIndex].chLogRouteSwitchMoveFlag = chLogRouteSwitchMoveFlag;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路是否可动道岔标志
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路是否可动道岔标志
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteSwitchMoveFlag(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteSwitchMoveFlag;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路列车脚下的逻辑区段数据
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteTrainLogSecSum 逻辑进路列车脚下的逻辑区段数目
* @param const UINT16 wLogRouteTrainLogSecId 逻辑进路列车脚下的逻辑区段ID数组
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteTrainLogSecData(const UINT16 wLogRouteId,const UINT16 wLogRouteTrainLogSecSum,const UINT16* wLogRouteTrainLogSecId)
{
	UINT16 wBufIndex = 0U;
	UINT16 ii = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((NULL != wLogRouteTrainLogSecId) && (MAX_ROUTE_IN_LT_NUM > wLogRouteTrainLogSecSum))
		{
			(void)CommonMemSet(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf, \
				(UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf), \
				0U, (UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf));

			for (ii = 0U; ii < wLogRouteTrainLogSecSum; ii++)
			{
				LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf[ii] = wLogRouteTrainLogSecId[ii];
			}
			LogicalRouteDataStru[wBufIndex].wLogRouteTrainLogSecSum = wLogRouteTrainLogSecSum;
		}
		else
		{
			(void)CommonMemSet(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf, \
				(UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf), \
				0U, (UINT32)sizeof(LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf));

			LogicalRouteDataStru[wBufIndex].wLogRouteTrainLogSecSum = 0U;
		}
	}
	else
	{
		; /*不处理*/
	}
}

/**
* @brief 获取逻辑进路列车脚下的逻辑区段数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路列车脚下的逻辑区段数量
* @note：by cgh 20231011
*/
UINT16 GetLogicalRouteTrainLogSecSum(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].wLogRouteTrainLogSecSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取逻辑进路列车脚下的逻辑区段ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路列车脚下的逻辑区段ID
* @note：by cgh 20231011
*/
UINT16* GetLogicalRouteTrainLogSecId(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].szLogRouteTrainLogSecIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路关联始端信号机ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteRelateBeginSigId 逻辑进路关联始端信号机ID
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteRelateBeginSigId(const UINT16 wLogRouteId, const UINT16 wLogRouteRelateBeginSigId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if (SIGNAL_SUM_MAX > wLogRouteRelateBeginSigId)
		{
			LogicalRouteDataStru[wBufIndex].wLogRouteRelateBeginSigId = wLogRouteRelateBeginSigId;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路关联始端信号机ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路关联始端信号机ID
* @note：by cgh 20231011
*/
UINT16 GetLogicalRouteRelateBeginSigId(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].wLogRouteRelateBeginSigId;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路初选起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 dwCyc 逻辑进路初选起始周期号
* @return 无
* @note：by cgh 20231011
*/
void SetLogRouteChuXuanStartCycNum(const UINT16 wLogRouteId, const UINT32 dwCyc)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取进路数组下标*/
	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		LogicalRouteDataStru[wBufIndex].dwLogRouteChuXuanStartCycNum = dwCyc;
	}
	else
	{
		/*不做处理*/
	}
}

/**
* @brief 获取逻辑进路初选起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路初选起始周期号
* @note：by cgh 20231011
*/
UINT32 GetLogRouteChuXuanStartCycNum(const UINT16 wLogRouteId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		retVal = LogicalRouteDataStru[wBufIndex].dwLogRouteChuXuanStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 设置逻辑进路选排起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 dwCyc 逻辑进路选排起始周期号
* @return 无
* @note：by cgh 20231011
*/
void SetLogRouteXuanPaiStartCycNum(const UINT16 wLogRouteId, const UINT32 dwCyc)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取进路数组下标*/
	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		LogicalRouteDataStru[wBufIndex].dwLogRouteXuanPaiStartCycNum = dwCyc;
	}
	else
	{
		/*不做处理*/
	}
}

/**
* @brief 获取逻辑进路选排起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路选排起始周期号
* @note：by cgh 20231011
*/
UINT32 GetLogRouteXuanPaiStartCycNum(const UINT16 wLogRouteId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		retVal = LogicalRouteDataStru[wBufIndex].dwLogRouteXuanPaiStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 设置逻辑进路锁闭起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 dwCyc 逻辑进路锁闭起始周期号
* @return 无
* @note：by cgh 20231011
*/
void SetLogRouteLockStartCycNum(const UINT16 wLogRouteId, const UINT32 dwCyc)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取进路数组下标*/
	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		LogicalRouteDataStru[wBufIndex].dwLogRouteLockStartCycNum = dwCyc;
	}
	else
	{
		/*不做处理*/
	}
}

/**
* @brief 获取逻辑进路锁闭起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路锁闭起始周期号
* @note：by cgh 20231011
*/
UINT32 GetLogRouteLockStartCycNum(const UINT16 wLogRouteId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		retVal = LogicalRouteDataStru[wBufIndex].dwLogRouteLockStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 设置逻辑进路区故解延时解锁起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 dwCyc 逻辑进路区故解延时解锁起始周期号
* @return 无
* @note：by cgh 20231011
*/
void SetLogRouteDelayErrLockStartCyc(const UINT16 wLogRouteId, const UINT32 dwCyc)
{
	UINT16 wBufIndex = 0U;  /*数组下标*/

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取进路数组下标*/
	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		LogicalRouteDataStru[wBufIndex].dwDelayErrLockStartCycNum = dwCyc;
	}
	else
	{
		/*不做处理*/
	}
}

/**
* @brief 获取逻辑进路区故解延时解锁起始周期号
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路区故解延时解锁起始周期号
* @note：by cgh 20231011
*/
UINT32 GetLogRouteDelayErrLockStartCyc(const UINT16 wLogRouteId)
{
	UINT16 wBufIndex = 0u;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);  /*获取数组下标*/

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		retVal = LogicalRouteDataStru[wBufIndex].dwDelayErrLockStartCycNum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/**
* @brief 设置逻辑进路信号重开标志
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param  const UINT8 chLogRouteRecoverOpenState 逻辑进路信号重开标志
* @return 无
* @note：by cgh 20231010
*/
void SetLogicalRouteRecoverOpenState(const UINT16 wLogRouteId, const UINT8 chLogRouteRecoverOpenState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		if ((ROUTE_REPEATOPEN_SET_YES == chLogRouteRecoverOpenState) || (ROUTE_REPEATOPEN_SET_NO == chLogRouteRecoverOpenState))
		{
			LogicalRouteDataStru[wBufIndex].chLogRouteRecoverOpenState = chLogRouteRecoverOpenState;
		}
		else
		{
			; /*不合法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路信号重开标志
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路信号重开标志
* @note：by cgh 20231010
*/
UINT8 GetLogicalRouteRecoverOpenState(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteRecoverOpenState;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路ATS请求资源列车数据
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteApplyResTrainId 逻辑进路ATS请求资源列车ID
* @return 无
* @note：by cgh 20231011
*/
void SetLogRouteApplyResTrainData(const UINT16 wLogRouteId, const UINT16 wLogRouteApplyResTrainId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		LogicalRouteDataStru[wBufIndex].szLogRouteApplyResTrainId = wLogRouteApplyResTrainId;
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路ATS请求资源列车ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路ATS请求资源列车ID
* @note：by cgh 20231011
*/
UINT16 GetLogicalRouteApplyResTrainId(const UINT16 wLogRouteId)
{
	UINT16 chRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].szLogRouteApplyResTrainId;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路关联屏蔽门数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteRelatePsdId 逻辑进路关联屏蔽门ID
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteRelatePsdIdData(const UINT16 wLogRouteId, const UINT16 wLogRouteRelatePsdId)
{
	UINT16 wBufIndex = 0U;
	UINT8 chLogRouteRelatePsdSum = 0U;
	UINT16 ii = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if ((ROUTE_LOGICAL_SUM_MAX > wBufIndex) && (0U != wLogRouteRelatePsdId))
	{
		chLogRouteRelatePsdSum = LogicalRouteDataStru[wBufIndex].chLogRouteRelatePsdSum;

		if (MAX_ROUTE_IN_LT_NUM > chLogRouteRelatePsdSum)
		{
			for (ii = 0U; ii < chLogRouteRelatePsdSum; ii++)
			{
				if (LogicalRouteDataStru[wBufIndex].szLogRouteRelatePsdIdBuf[ii] == wLogRouteRelatePsdId)
				{
					break;
				}
				else
				{
					; /*继续检查*/
				}
			}

			if (chLogRouteRelatePsdSum == ii)
			{
				LogicalRouteDataStru[wBufIndex].szLogRouteRelatePsdIdBuf[chLogRouteRelatePsdSum] = wLogRouteRelatePsdId;
				LogicalRouteDataStru[wBufIndex].chLogRouteRelatePsdSum = chLogRouteRelatePsdSum + 1U;
			}
			else
			{
				; /*已存在不添加*/
			}
		}
		else
		{
			; /*非法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路关联屏蔽门数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路关联屏蔽门数量
* @note：by cgh 20231011
*/
UINT8 GetLogicalRouteeRelatePsdSum(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteRelatePsdSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取逻辑进路关联屏蔽门ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路关联屏蔽门ID
* @note：by cgh 20231011
*/
UINT16* GetLogicalRouteRelatePsdId(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].szLogRouteRelatePsdIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 设置逻辑进路关联紧急停车按钮数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogRouteRelateEsbId 逻辑进路关联紧急停车按钮ID
* @return 无
* @note：by cgh 20231011
*/
void SetLogicalRouteRelateEsbIdData(const UINT16 wLogRouteId, const UINT16 wLogRouteRelateEsbId)
{
	UINT16 wBufIndex = 0U;
	UINT8 chLogRouteRelateEsbSum = 0U;
	UINT16 ii = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if ((ROUTE_LOGICAL_SUM_MAX > wBufIndex) && (0U != wLogRouteRelateEsbId))
	{
		chLogRouteRelateEsbSum = LogicalRouteDataStru[wBufIndex].chLogRouteRelateEsbSum;

		if (MAX_ROUTE_IN_LT_NUM > chLogRouteRelateEsbSum)
		{
			for (ii = 0U; ii < chLogRouteRelateEsbSum; ii++)
			{
				if (LogicalRouteDataStru[wBufIndex].szLogRouteRelateEsbIdBuf[ii] == wLogRouteRelateEsbId)
				{
					break;
				}
				else
				{
					; /*继续检查*/
				}
			}

			if (chLogRouteRelateEsbSum == ii)
			{
				LogicalRouteDataStru[wBufIndex].szLogRouteRelateEsbIdBuf[chLogRouteRelateEsbSum] = wLogRouteRelateEsbId;
				LogicalRouteDataStru[wBufIndex].chLogRouteRelateEsbSum = chLogRouteRelateEsbSum + 1U;
			}
			else
			{
				; /*已存在不添加*/
			}
		}
		else
		{
			; /*非法不处理*/
		}
	}
	else
	{
		; /* 不处理 */
	}
}

/**
* @brief 获取逻辑进路关联紧急停车按钮数量
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路关联紧急停车按钮数量
* @note：by cgh 20231011
*/
UINT8 GetLogicalRouteeRelateEsbSum(const UINT16 wLogRouteId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].chLogRouteRelateEsbSum;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 获取逻辑进路关联紧急停车按钮ID
* @param const UINT16 wLogRouteId 逻辑进路ID
* @return 逻辑进路关联紧急停车按钮ID
* @note：by cgh 20231011
*/
UINT16* GetLogicalRouteRelateEsbId(const UINT16 wLogRouteId)
{
	UINT16* chRetVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetLogRouteBufIndex(wLogRouteId);

	if (ROUTE_LOGICAL_SUM_MAX > wBufIndex)
	{
		chRetVal = LogicalRouteDataStru[wBufIndex].szLogRouteRelateEsbIdBuf;
	}
	else
	{
		; /* 不处理 */
	}
	return chRetVal;
}

/**
* @brief 逻辑进路初选处理
* @param  wLogRouteId 逻辑进路ID
* @return 无
* @note：
*/
void LogRouteFirstXuanPaiProc(const UINT16 wLogRouteId)
{
	UINT8 chFunRtn = CI_ERROR;

	/*逻辑进路办理条件检查*/
	chFunRtn = SetLogRouteCheckProcess(wLogRouteId);

	if (CI_SUCCESS == chFunRtn)
	{/*检查条件通过*/

		/*判断逻辑进路征用是否成功*/
		chFunRtn = LogRouteUseStateCheck(wLogRouteId);
		if (CI_SUCCESS == chFunRtn)
		{/*设置逻辑进路选排状态*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_XUANPAI);
			LogRouteXuanPaiProc(wLogRouteId);
		}
		else
		{
			/*征用失败，设置进路空闲*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
		}
	}
	else
	{
		/*办理条件检查不通过 ，设置进路空闲*/
		SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
	}
	
	

}

/**
* @brief 逻辑进路选排处理
* @param  wLogRouteId 逻辑进路ID
* @return 无
* @note：
*/
void LogRouteXuanPaiProc(const UINT16 wLogRouteId)
{
	UINT8 chFunRtn = CI_ERROR;
	UINT8 chDriveRtn = CI_ERROR;
	UINT16 ii = 0U;
	UINT8 routSwitDrvOvtmFlag = CI_ERROR;
	UINT8 routeSWPositionFlag = CI_ERROR;


	/*逻辑进路锁闭条件检查*/
	chFunRtn = LockLogRouteCheckProcess(wLogRouteId);
	/*进路内道岔是否驱动超时*/
	routSwitDrvOvtmFlag = ChekLogRouteSwDrvOvTime(wLogRouteId);

	if (CI_SUCCESS == chFunRtn)
	{/*锁闭条件检查通过*/
		
		routeSWPositionFlag= ChekLogRouteSwPosRight(wLogRouteId);

		/*再检查道岔位置正确性*/
		if (CI_SUCCESS== routeSWPositionFlag)
		{
			/*设置逻辑进路锁闭*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_LOCK);
			LogRouteLockProc(wLogRouteId);
		}
		else
		{
			/*检查进路内方道岔驱动是否超时*/
			if (CI_SUCCESS == routSwitDrvOvtmFlag)
			{
				/*保持驱动*/
			}
			else
			{
				/*检查不通过，设置进路空闲*/
				SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
			}
			
		}
		
	}
	else if (RETURN_LOCK_ERR_SWITPOS == chFunRtn)
	{/*道岔位置不正确 驱动道岔*/

		if (CI_SUCCESS == routSwitDrvOvtmFlag)
		{/*道岔驱动未超时*/
			chDriveRtn = LogRouteLockDriveSwitch(wLogRouteId);
			if (CI_SUCCESS == chDriveRtn)
			{
				/*驱动成功，不处理*/
			}
			else
			{
				/*驱动失败，设置进路空闲*/
				SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
			}
		}
		else
		{/*道岔驱动超时*/

			/*设置进路空闲*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
		}
	}
	else 
	{
		/*检查不通过，设置进路空闲*/
		SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
	}

}

/**
* @brief 逻辑进路锁闭处理
* @param  wLogRouteId 逻辑进路ID
* @return 无
* @note：
*/
void LogRouteLockProc(const UINT16 wLogRouteId)
{
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/
	UINT16 wLogRouteTrainLogSecSum = 0U;				/*列车脚下逻辑区段数量*/
	UINT16* wLogRouteTrainLogSecIdBuf = NULL;
	UINT8 checkResult = CI_ERROR;

	if ((0U != wLogRouteId) && (ROUTE_LOGICAL_SUM_MAX != wLogRouteId))
	{
		wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
		wLogRouteTrainLogSecSum = GetLogicalRouteTrainLogSecSum(wLogRouteId);
		if (0U == wLogRouteTrainLogSecSum)
		{
			/*无列车脚下资源,不处理*/
		}
		else
		{
			/*处理列车脚下资源换向*/
			SetLogRouteTrainLocLogSecState(wLogRouteId, LOG_SECTION_LOGLOCK_NORMAL);
			SetLogRouteTrainLocPhySecState(wLogRouteId, PHYSICAL_SECTION_LOCK_NORMAL);
		}
		if (0U == wLogSignalId)
		{
			/*进路未有信号机，走向等待解锁*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKWAIT);
		}
		else
		{
			startSignalCurColor = GetSignalCurColor(wLogSignalId);
			openCloseState = GetSignalOpenCloseState(startSignalCurColor);
			if (SIGNAL_OPEN == openCloseState)
			{

				/*信号机已开放,设置逻辑进路开放*/
				SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_OPEN);
				/*开放逻辑处理*/
				LogRouteOpenManage(wLogRouteId);

			}
			else
			{
				/*信号机未开放，检查开放逻辑，驱信号机开放*/
				checkResult = OpenLogRouteSignalProc(wLogRouteId);
				if (CI_SUCCESS == checkResult)
				{
					/*检查条件通过，继续在锁闭状态下驱信号机,等信号机驱开导向逻辑进路开放*/
				}
				else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
				{
					/*跨压信号机*/
					/*设置逻辑进路状态为等待解锁*/
					SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKWAIT);

					/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
					SetDetCutBtnState(wLogSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
				}
				else
				{
					/*开放检查失败，导向逻辑进路锁闭异常*/
					SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_LOCKERR);

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

/**
* @brief 逻辑进路异常锁闭处理
* @param  wLogRouteId 逻辑进路ID
* @return 无
* @note：
*/
void LogRouteLockErrManage(const UINT16 wLogRouteId)
{
	UINT8 openCloseState = 0u;       /*进路始端信号机开放状态*/
	UINT8 startSignalCurColor = 0u;      /*始端信号机当前颜色*/
	UINT16 wLogSignalId = 0U;	/*逻辑进路包含的信号机*/
	UINT8 wLogRouteSignalErrCloseFlag = 0U;
	UINT8 checkResult = CI_ERROR;

	wLogSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	startSignalCurColor = GetSignalCurColor(wLogSignalId);
	openCloseState = GetSignalOpenCloseState(startSignalCurColor);

	if (SIGNAL_OPEN == openCloseState)
	{
		wLogRouteSignalErrCloseFlag = GetLogRouteSignalErrCloseFlag(wLogSignalId);
		if (LOG_ROUTE_SIGNAL_CLOSE_ERR == wLogRouteSignalErrCloseFlag)
		{
			DriveLogRouteSignalClose(wLogSignalId);		/*两条动态进路共有一个信号机有一条保持信号机保持不通过，驱一周期关闭未关闭，继续驱关闭*/
		}
		else
		{
			/*信号机已开放,设置逻辑进路开放*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_OPEN);
			/*开放逻辑处理*/
			LogRouteOpenManage(wLogRouteId);
		}
	}
	else
	{
		/*信号机未开放，检查开放逻辑，驱信号机开放*/
		checkResult = OpenLogRouteSignalProc(wLogRouteId);
		if (CI_SUCCESS == checkResult)
		{
			/*检查条件通过，继续驱信号机开放，直到信号机开放后走开放逻辑*/
		}
		else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
		{
			/*跨压信号机*/
			/*设置逻辑进路状态为等待解锁*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKWAIT);

			/*开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(wLogSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
		else
		{
			/*开放检查失败，导向逻辑进路锁闭异常*/
			/*设置异常驱关闭的标志*/
			SetLogRouteSignalErrCloseFlag(wLogSignalId, LOG_ROUTE_SIGNAL_CLOSE_ERR);

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

}

/*
* 功能描述： 设置逻辑进路锁闭列车脚下锁闭状态
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
*            const UINT8 lockState, 锁闭状态
* 返回值  ： void
*/
void SetLogRouteTrainLocLogSecState(const UINT16 wLogRouteId, const UINT8 lockState)
{
	UINT16 wLogRouteTrainLogSecSum = 0U;				/*列车脚下逻辑区段数量*/
	UINT16* wLogRouteTrainLogSecIdBuf = NULL;
	UINT8 wLogrouteDir = 0u;
	UINT16 i = 0u;
	UINT8 curLockState = 0u;  /*区段当前锁闭状态*/
	UINT16 validRouteId = 0u;		/*当前锁闭的进路*/
	UINT8 validRouteDir = 0u;
	UINT8 funcRet = 0U;
	UINT8 keepWork = CI_ERROR;

	wLogRouteTrainLogSecSum = GetLogicalRouteTrainLogSecSum(wLogRouteId);
	wLogRouteTrainLogSecIdBuf = GetLogicalRouteTrainLogSecId(wLogRouteId);
	/*进路方向*/
	wLogrouteDir = GetLogicalRouteDir(wLogRouteId);
	/*检查数据合法*/
	if ((0u != wLogRouteTrainLogSecSum) && (NULL != wLogRouteTrainLogSecIdBuf))
	{
		for (i = 0u; i < wLogRouteTrainLogSecSum; i++)
		{
			funcRet = CheckLgcSecInLogRoute(wLogRouteId, wLogRouteTrainLogSecIdBuf[i]);
			if (CI_SUCCESS == funcRet)
			{
				if (LOG_SECTION_LOGLOCK_NORMAL == lockState)
				{
					funcRet = CI_SUCCESS;
					curLockState = 0u;
					/*获取当前锁闭状态*/
					curLockState = GetLogSecLockState(wLogRouteTrainLogSecIdBuf[i]);
					if ((LOG_SECTION_LOCK_NORMAL == curLockState) || (LOG_SECTION_LOCK_DELAY == curLockState))
					{
						validRouteId = GetLogSecLockBelongRoute(wLogRouteTrainLogSecIdBuf[i]);
						validRouteDir = GetRouteDirection(validRouteId);
						/*设置区段锁闭所属之前进路未锁闭*/
						SetLogSecLockState(wLogRouteTrainLogSecIdBuf[i], LOG_SECTION_LOCK_NO, validRouteId, validRouteDir);
					}

					/*获取当前逻辑锁闭状态*/
					keepWork = LogSecLockInLogRouteProcess(wLogRouteId, wLogRouteTrainLogSecIdBuf[i]);
					if (CI_ERROR == keepWork)
					{
						break;
					}
				}
				else
				{
					/*不做处理*/
				}
			}
		}
	}
	else
	{
		/*不做处理*/
	}
}

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

	/*获取逻辑进路包含脚下物理区段信息*/
	routePhySecSum = GetLogicRouteTrainLogIncPhySec(wLogRouteId, &pRoutePhySecIdBuf);
	
	if (0u == routePhySecSum)
	{
		keepWork = CI_ERROR;
	}
	else
	{
		keepWork = CI_SUCCESS;
	}

	if (CI_SUCCESS == keepWork)
	{
		for (ii = 0u; ii < routePhySecSum; ii++)
		{
			phyLgcSecSum = GetPhySecIncLogSecSum(pRoutePhySecIdBuf[ii]);
			pPhyLgcSecBuf = GetPhySecIncLogSecIdBuf(pRoutePhySecIdBuf[ii]);
			if (PHYSICAL_SECTION_LOCK_NORMAL == lockState)
			{ /*正常锁闭*/
				curLockState = 0u;
				curLockState = GetPhySecLockState(pRoutePhySecIdBuf[ii]);  /*获取区段当前锁闭状态*/

				if ((PHYSICAL_SECTION_LOCK_NORMAL == curLockState) ||
					(PHYSICAL_SECTION_LOCK_DELAY == curLockState))
				{ /*正常锁闭||延时解锁*/
					for (jj = 0U; jj < phyLgcSecSum; jj++)
					{
						wCurLogicRouteLogLockState = GetLogSecLogLockState(pPhyLgcSecBuf[jj]);
						if (LOG_SECTION_LOGLOCK_NORMAL == wCurLogicRouteLogLockState)
						{
							/*逻辑区段已设置逻辑进路锁闭则已出清了逻辑取区段的正常锁闭*/
						}
						else
						{
							/*未设置逻辑进路锁闭的逻辑区段考虑是否有其他车占压且正常锁闭在其他进路*/
							lgcRLockId = GetLogSecLockBelongRoute(pPhyLgcSecBuf[jj]);
							if (0U == lgcRLockId)
							{
								;	/*说明此逻辑区段是空闲的，没有其他车锁闭*/
							}
							else
							{
								break;	
							}
						}
					}

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

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

					if (validRouteSum == jj)
					{
						/*未重复*/
						if (ROUTE_TRAIN_LOC_MAX_SUM > validRouteSum)
						{
							validRouteIdBuf[validRouteSum++] = validRouteId;
						}
						else
						{
							keepWork = CI_ERROR;
						}
					}
				}
				else
				{
					/*不处理*/
				}
				if (CI_ERROR == keepWork)
				{
					break;
				}
			}
			else
			{
				/*不处理*/
			}
		}
	}

	if (CI_SUCCESS == keepWork)
	{
		for (ii = 0U; ii < validRouteSum; ii++)
		{
			if (0u < validRouteIdBuf[ii])
			{
				phySecSum = 0u;
				pPhySecDataStru = NULL;

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

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

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

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

/*
* 功能描述： 设置逻辑进路内的物理区段征用状态
* 参数说明： const UINT16 wLogRouteId, 进路ID
*            const UINT8 useState, 征用状态
* 返回值  ： 无
* LC
*/
void SetLogRouteSectionUsingState(const UINT16 logRouteId,const UINT8 useState)
{
	UINT16* LogSecIdBuff = NULL;
	UINT16 logSecSum = 0U;
	UINT16 ii = 0U;
	UINT16 wPhySecId = 0U;
	
	if ((0U != logRouteId)&&(ROUTE_LOGICAL_SUM_MAX > logRouteId)
		&&((PHYSICAL_SECTION_USING_YES == useState)|| (PHYSICAL_SECTION_USING_NO == useState)))
	{/*获取逻辑进路包含的逻辑区段*/
		LogSecIdBuff = GetLogicalRouteInLogSecId(logRouteId);
		logSecSum = GetLogicalRouteInLogSecSum(logRouteId);

		/*遍历逻辑区段，获取关联的物理区段*/
		for (ii = 0; ii < logSecSum; ii++)
		{
			wPhySecId = GetLgcSecRelativePhySecId(LogSecIdBuff[ii]);

			if (PHYSICAL_SECTION_USING_YES == useState)
			{/*设置物理区段征用*/
				(void)SetPhySecUseStateByLogRoute(wPhySecId, PHYSICAL_SECTION_USING_YES, logRouteId);
			}
			else if (PHYSICAL_SECTION_USING_NO == useState)
			{/*设置物理区段未征用*/
				(void)SetPhySecUseStateByLogRoute(wPhySecId, PHYSICAL_SECTION_USING_NO, logRouteId);
			}
			else
			{
				/*不可达分支，不处理*/
			}

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

/*
* 功能描述： 逻辑进路的逻辑区段资源解锁管理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： void
* 创建：  fan 2023-10-11
*/
void LogRouteLgcSecResUnlockManage(const UINT16 logRouteId)
{
	/*变量初始化*/
	UINT16 routeLogNum = 0u;
	UINT16 wTrainId = 0U;
	UINT16 ii = 0U;
	UINT16* routeLogSecId = NULL;
	UINT16 wUnlockLgcSecId = 0U;   /*逻辑区段ID*/
	UINT16 wPreUnlockLgcSecId = 0U; /*进路内逻辑区段上一个逻辑区段*/
	UINT8 chLgcLockState = 0U;/*逻辑区段状态*/
	UINT8 chPreLgcLockState = 0U;/*上一个逻辑区段状态*/
	UINT8 chPreLgcLogRouteId = 0U;/*上一个逻辑区段所属逻辑进路*/
	UINT8 checkFlag = 0U;

	/*获取逻辑进路逻辑区段数据*/
	routeLogNum = GetLogicalRouteInLogSecSum(logRouteId);
	routeLogSecId = GetLogicalRouteInLogSecId(logRouteId);/*逻辑区段ID数组*/
	if ((0u < routeLogNum)
		&& (MAX_ROUTE_IN_LT_NUM > routeLogNum))
	{
		/*每周期获取第一个没解锁逻辑区段*/
		for (ii = 0U; ii < routeLogNum; ii++)
		{

			wPreUnlockLgcSecId = wUnlockLgcSecId;/*上一逻辑区段ID*/
			wUnlockLgcSecId = routeLogSecId[ii];/*获取当前逻辑区段ID*/
			/*检查某个逻辑区段对该逻辑进路的解锁条件*/
			/*每周期检查第一个锁闭的逻辑区段*/
			checkFlag = CheckLogRouteIdBelLogSec(wUnlockLgcSecId, logRouteId);  /*判断待解锁逻辑区段是否被本逻辑进路锁闭*/
			if (CI_SUCCESS == checkFlag)
			{
				chLgcLockState = GetLogSecLogLockState(wUnlockLgcSecId);
				if ((LOG_SECTION_LOGLOCK_EXCEPT == chLgcLockState))
				{
					break; /*非正常状态*/
				}
				if (LOG_SECTION_LOGLOCK_NORMAL == chLgcLockState)
				{
					checkFlag = CheckLogRouteLgcSecResUnlock(wUnlockLgcSecId, wPreUnlockLgcSecId, logRouteId);
					if (CI_SUCCESS == checkFlag)
					{
						LgcSecLogicalUnlockProc(logRouteId, wUnlockLgcSecId, wPreUnlockLgcSecId);  /*从当前逻辑区段删除该逻辑进路且逻辑区段内逻辑进路数量--*/
					}
					else
					{
						break; /*本周期不继续解锁*/
					}
				}
				else
				{
					; /*继续遍历*/
				}
			}
			else
			{
				/*非本逻辑进路锁闭的逻辑区段，不执行解锁处理*/
			}
		}
		/*处理某条进路所有逻辑区段全部解锁的情况*/
		checkFlag = LogRouteLogSecReleaseCheck(logRouteId);
		if (CI_SUCCESS == checkFlag)
		{
			/*解锁全部防护道岔*/
			SetLogRouteProSwLockState(logRouteId, SWITCH_LOCK_PROTECT_CANCEL);
			/*设置空闲*/
			(void)SetLogicalRouteState(logRouteId, ROUTE_LOGICAL_STATE_IDLE);
		}
		else
		{
			;/*不处理  暂无延时解锁状态*/
		}
	}
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述： 检查逻辑区段的逻辑进路解锁条件
* 参数说明： const UINT16 logSecId, 逻辑区段ID
					const UINT16 preLogSecId, 上一个逻辑区段ID
					const UINT16 wLogRouteId, 逻辑进路ID
* 返回值  ： CI_SUCCESS检查通过 CI_ERROR检查失败
* 创建 ： fan  2023-10-11
*/
UINT8 CheckLogRouteLgcSecResUnlock(const UINT16 logSecId, const UINT16 preLogSecId, const UINT16 logRouteId)
{
	UINT8 chKeepWork = CI_SUCCESS;
	UINT8 occupyFlag = CI_ERROR;
	UINT8 chLgcLockState = 0U;/*逻辑区段状态*/
	UINT8 chLogSecReleaseFlag = 0U; /*逻辑区段列车的释放申请标志*/
	UINT8 logRouteCheck = 0U; /*逻辑区段内该逻辑进路数组下标*/
	UINT8 chLgcResTrainSum = 0U;
	UINT16 wTrainId = 0U; /*列车ID*/

	if (0U == preLogSecId)
	{
		/*进路第一个逻辑区段*/
		chKeepWork = CI_SUCCESS;
	}
	else
	{
		/*检查上逻辑一区段锁闭和占用情况*/
		logRouteCheck = CheckLogRouteIdBelLogSec(preLogSecId, logRouteId);
		if (CI_SUCCESS == logRouteCheck)
		{
			/*上一个逻辑区段还包含该进路，不能解锁*/
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		logRouteCheck = CheckLogRouteIdBelLogSec(logSecId, logRouteId);
		if (CI_SUCCESS == logRouteCheck)/*含有该逻辑进路*/
		{
			occupyFlag = GetLogSecCurCtOrUtOccupyState(logSecId);/*获取当前逻辑区段占用状态*/
			if (LOGICSECTION_OCCUPY_NO == occupyFlag)
			{
				chLgcLockState = GetLogSecLogLockState(logSecId);/*逻辑区段的逻辑锁闭标志*/
				wTrainId = GetLogicalRouteApplyResTrainId(logRouteId);
			}
			else
			{
				/*被占用*/
				chKeepWork = CI_ERROR;
			}
		}
		else
		{
			/*该逻辑区段已经不包含此进路*/
			chKeepWork = CI_ERROR;
		}
	}

	if (CI_SUCCESS == chKeepWork)
	{
		chKeepWork = CI_ERROR;
		/*逻辑区段正常锁闭*/
		if (LOG_SECTION_LOGLOCK_NORMAL == chLgcLockState)
		{
			/*确定是该进路的列车本周期申请解锁逻辑区段*/
			chLogSecReleaseFlag = GetLogSecTrainRelease(logSecId, wTrainId);

			if(LOGIC_SECTION_TRAIN_UNLOCK_YES == chLogSecReleaseFlag)
			{
				/*逻辑区段的为正常逻辑锁闭*/
				chKeepWork = CI_SUCCESS;
			}
			else
			{
				chKeepWork = CI_ERROR;
			}
		}
		else
		{
			chKeepWork = CI_ERROR;
		}
	}
	debug_infor_printf((const)"LogSecRes Unlock LgcId: %d TrainId:%d  Cyc  Checkstatus:%d\n", logSecId, wTrainId, Get2oo2CurCycleNum(), chKeepWork);
	return chKeepWork;
}

/*
* 功能描述： 逻辑区段的逻辑进路解锁处理
* 参数说明： const UINT16 wLogRouteId, 逻辑进路ID
const UINT16 logSectionId 逻辑区段ID
const UINT16 preLogSecId 上一个逻辑区段ID
* 返回值  ： void
* 创建 ： fan  20231012
*/
void LgcSecLogicalUnlockProc(const UINT16 logRouteId, const UINT16 logSectionId, const UINT16 preLogSecId)
{
	/*初始化变量*/
	UINT8 checkValue = 0u;
	UINT8 logRouteSum = 0u; /*逻辑区段关联的逻辑进路数量*/
	UINT8 chCheckSum = 0u;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT16 chDevId = 0U;
	UINT8 chDevState = 0U;
	UINT8 chProSwState = 0U;
	LogsecSwitchStruct* pstLogicSecSwitchBuf = NULL; /*逻辑区段的道岔结构体*/
	UINT16 wTrainId = 0U;
	UINT16 wLgcBufIndex = 0U;
	LogicSectionDataStruct *pstLgcSecInfo = GetLogicSecData();
	LogicTrainResStruct * pstTrainResInfo = NULL;
	UINT8 checkPre = 0U;
	UINT8 chLogSecReleaseFlag = 0U; /*获取逻辑区段资源列车释放标志*/
	UINT8 chLgcResTrainSum = 0U;  /*逻辑区段资源列车数量*/
	UINT8 chTrainSum = 0U;

	wLgcBufIndex = GetlogSectionBufIndex(logSectionId);

	/*处理列车资源信息*/

	/*上一区段已经无该车资源*/
	wTrainId = GetLogicalRouteApplyResTrainId(logRouteId);
	if (0U != preLogSecId)
	{
		checkPre = CheckLogRouteIdBelLogSec(preLogSecId, logRouteId);
	}
	
	if ((0U == preLogSecId) || (CI_ERROR == checkPre))
	{
		/*是否收到指定列车解锁命令*/
		chLogSecReleaseFlag = GetLogSecTrainRelease(logSectionId, wTrainId);
		if (((LOGIC_SECTION_TRAIN_UNLOCK_YES == chLogSecReleaseFlag) || (0U == wTrainId))
			&& (NULL == pstTrainResInfo))
		{
			chLgcResTrainSum = GetLogSecTrainInfoSum(logSectionId);
			for (jj = 0U; jj < chLgcResTrainSum; jj++)
			{
				/*删除该列车对应逻辑区段资源*/
				if (pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj].wTrainId == wTrainId)
				{
					; /*不处理*/
				}
				else
				{
					(void)CommonMemCpy((void*)(&pstLgcSecInfo[wLgcBufIndex].szTrainResData[chTrainSum++]), (UINT32)sizeof(LogicTrainResStruct),
						(void*)(&pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj]), (UINT32)sizeof(LogicTrainResStruct));
				}
			}
			debug_infor_printf((const)"LogSecRes Release LgcId: %d Cyc%d \n", logSectionId, Get2oo2CurCycleNum());
			/*清0 防脏数据*/
			for (jj = chTrainSum; jj < chLgcResTrainSum; jj++)
			{
				(void)ComMemSet(&(pstLgcSecInfo[wLgcBufIndex].szTrainResData[jj]), (UINT16)sizeof(LogicTrainResStruct), 0U);
			}
			pstLgcSecInfo[wLgcBufIndex].chTrainInfoSum = chTrainSum;

			/*逻辑区段不再关联该逻辑进路*/
			checkValue = DelLogSecBelongLogRouteId(logSectionId, logRouteId);

			/*检查逻辑区段的逻辑锁闭状态*/
			logRouteSum = GetLogSecLockBelLogRouteSum(logSectionId);
			if ((0u == logRouteSum) && (CI_SUCCESS == checkValue))
			{
				/*删除成功，逻辑区段关联逻辑进路数目为0，设置逻辑锁闭状态未锁闭*/
				SetLogSecLogLockState(logSectionId, LOG_SECTION_LOGLOCK_NO, 0U);

			}
			else
			{
				; /*不处理*/
			}
		}		
	}
	else
	{
		debug_infor_printf((const)"LogSecRes Release ERROR LgcId: %d TrainId:%d  Cyc%d \n"
			, logSectionId, wTrainId, Get2oo2CurCycleNum());
	}
}


/**
* @brief 逻辑进路信号开放处理
* @param  wLogRouteId 逻辑进路ID
* @return 无
* @note：
*/
void LogRouteOpenManage(const UINT16 wLogRouteId)
{
	UINT16 wSignalId = 0U;
	UINT8 curColor = 0u;
	UINT8 sigState = 0u;
	UINT8 checkResult = CI_ERROR;
	UINT8 funcId = EFUNC_LogRouteOpenManage;/*函数ID*/
	UINT8 wSignalCrossState = 0U;

	wSignalId = GetLogicalRouteRelateBeginSigId(wLogRouteId);
	curColor = GetSignalCurColor(wSignalId);
	sigState = GetSignalOpenCloseState(curColor);

	if (SIGNAL_OPEN == sigState)
	{
		/*信号机已经开放，维持信号机开放，检查条件，异常关闭后导向锁闭，正常跨压关闭走向等待解锁状态*/
		checkResult = KeepOpenLogRouteSignalProc(wLogRouteId);
		if (CI_SUCCESS == checkResult)
		{
			/*保持成功*/
		}
		else if (LOG_ROUTE_TRAIN_CROSS == checkResult)
		{
			/*跨压信号机*/
			/*设置逻辑进路状态为等待解锁*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_UNLOCKWAIT);

			/*保持开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(wSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
		else
		{
			/*保持失败,设置逻辑进路状态为逻辑异常锁闭*/
			SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_LOCKERR);

			/*保持开放条件检查失败，设置对应始端信号机扣车旁路按钮无效*/
			SetDetCutBtnState(wSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
		}
	}
	else
	{
		/*设置逻辑进路状态为逻辑异常锁闭*/
		SetLogRouteStateManage(wLogRouteId, ROUTE_LOGICAL_STATE_LOCKERR);

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

		/*保持开放期间信号异常关闭，设置对应始端信号机扣车旁路按钮无效*/
		SetDetCutBtnState(wSignalId, SIGNAL_DETAIN_CUT_VALID_NO);
	}
}

/*
* 功能描述： 检查指定ID逻辑进路列车脚下资源是否包含该逻辑区段
* 参数说明： const UINT16 routeId, 进路ID
*			 const UINT16 lgcSecId
* 返回值  ： CI_SUCCESS: 在列车脚下资源中
*            CI_ERROR: 不在列车脚下资源中
*/
UINT8  CheckLgcSecHaveTrainLocRoute(const UINT16 logRouteId, const UINT16 lgcSecId)
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT8 reVal = CI_ERROR;
	UINT8 ii = 0U;

	bufIndex = GetLogRouteBufIndex(logRouteId);  /*获取进路数组下标*/
	if (ROUTE_LOGICAL_SUM_MAX > bufIndex)
	{

		for (ii = 0U; ii < LogicalRouteDataStru[bufIndex].wLogRouteTrainLogSecSum; ii++)
		{
			if (lgcSecId == LogicalRouteDataStru[bufIndex].szLogRouteTrainLogSecIdBuf[ii])
			{
				reVal = CI_SUCCESS;
				break;
			}
			else
			{
				; /*继续执行*/
			}
		}

		if (ii == LogicalRouteDataStru[bufIndex].wLogRouteTrainLogSecSum)
		{
			/*未找到相同的逻辑区段*/
			reVal = CI_ERROR;
		}
		else
		{

		}

	}
	else
	{
		/*不做处理*/
		reVal = CI_ERROR;
	}
	return reVal;
}

/*
* 功能描述： 确定指定ID逻辑进路始端信号机开放颜色处理
* 参数说明： const UINT16 routeId, 进路ID
* 返回值  ： 无
* Created By LQ 2023/10/11
*/
void LogicRouteOpenColorProc(const UINT16 logRouteId)
{
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wLogicRouteIncLogSecNum = 0U;  /*逻辑进路包含的逻辑区段数量*/
	UINT16* pLogicRouteIncLogSecId = NULL;  /*逻辑进路包含的逻辑区段ID*/
	UINT8 cLogSecIncSwitchNum = 0U;  /*逻辑区段包含的道岔数量*/
	LogsecSwitchStruct * pLogSecIncSwitchStru = NULL;  /*逻辑区段包含的道岔结构体*/
	UINT16 wStartSignalId = 0U;  /*逻辑进路始端信号机ID*/
	UINT8 cSiganlFengDengType = SIGNAL_TYPE_FENG_NO;  /*信号机封灯类型*/
	UINT8 cSignalDrvColor = SIGNAL_SHOWCOLOUR_INVALID;  /*需驱动的信号机颜色*/
	UINT8 cSwitchFanWeiFlag = FLAG_UNSET;  /*逻辑区段道岔反位标志*/

	if ((0U < logRouteId) && (ROUTE_LOGICAL_SUM_MAX > logRouteId))
	{
		wLogicRouteIncLogSecNum = GetLogicalRouteInLogSecSum(logRouteId);
		pLogicRouteIncLogSecId = GetLogicalRouteInLogSecId(logRouteId);

		if ((0U != wLogicRouteIncLogSecNum) && (NULL != pLogicRouteIncLogSecId))
		{
			/*遍历逻辑进路的所有逻辑区段，判断是否存在过道岔反位的逻辑区段*/
			for (ii = 0U; ii < wLogicRouteIncLogSecNum; ii++)
			{
				cLogSecIncSwitchNum = GetLogicSecSwitchSum(pLogicRouteIncLogSecId[ii]);
				pLogSecIncSwitchStru = GetLogicSecSwitchIdStru(pLogicRouteIncLogSecId[ii]);
				if ((0U != cLogSecIncSwitchNum) && (NULL != pLogSecIncSwitchStru))
				{
					for (jj = 0U; jj < cLogSecIncSwitchNum; jj++)
					{
						if (SWITCH_POSITION_FANWEI == pLogSecIncSwitchStru[jj].SwitchPosition)
						{
							cSwitchFanWeiFlag = FLAG_SET;  /*存在逻辑区段过道岔反位，停止遍历*/
							break;
						}
						else
						{
							/*继续遍历*/
						}
					}
				}
				else
				{
					/*逻辑区段不包含道岔，继续遍历*/
				}

				if (FLAG_SET == cSwitchFanWeiFlag)
				{
					break;  /*存在逻辑区段过道岔反位，停止遍历*/
				}
				else
				{
					/*继续遍历*/
				}
			}

			wStartSignalId = GetLogicalRouteRelateBeginSigId(logRouteId);
			cSiganlFengDengType = GetSignalFengDengType(wStartSignalId);  /*获取信号机封灯类型*/

			/*根据道岔位置和封灯类型确定逻辑进路始端信号机开放颜色*/
			if (FLAG_SET == cSwitchFanWeiFlag)
			{
				/*存在逻辑区段过道岔反位*/
				switch (cSiganlFengDengType)
				{
				case SIGNAL_TYPE_FENG_NO:
				case SIGNAL_TYPE_FENG_GREEN:
				{
					/*存在道岔在反位，且未封黄灯，设置信号机驱动颜色为黄灭*/
					cSignalDrvColor = SIGNAL_SHOWCOLOUR_YELLOWCLOSE;
					break;
				}
				case SIGNAL_TYPE_FENG_YELLOW:
				{
					/*存在道岔在反位，且封黄灯，设置信号机驱动颜色为绿灭*/
					cSignalDrvColor = SIGNAL_SHOWCOLOUR_GREENCLOSE;
					break;
				}
				default:
					/*不可达分支*/
					break;
				}
			}
			else
			{
				/*不存在逻辑区段过道岔反位*/
				switch (cSiganlFengDengType)
				{
				case SIGNAL_TYPE_FENG_NO:
				case SIGNAL_TYPE_FENG_YELLOW:
				{
					/*不存在道岔在反位，且未封绿灯，设置信号机驱动颜色为绿灭*/
					cSignalDrvColor = SIGNAL_SHOWCOLOUR_GREENCLOSE;
					break;
				}
				case SIGNAL_TYPE_FENG_GREEN:
				{
					/*不存在道岔在反位，且封绿灯，设置信号机驱动颜色为黄灭*/
					cSignalDrvColor = SIGNAL_SHOWCOLOUR_YELLOWCLOSE;
					break;
				}
				default:
					/*不可达分支*/
					break;
				}
			}
		}
		else
		{
			/*获取逻辑区段失败，不处理*/
		}		

		SetLogicalRouteOpenColor(logRouteId, cSignalDrvColor);
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/**
* @brief 逻辑进路区故解延时解锁处理
* @param const UINT16 wLogicalRouteId 逻辑进路ID
* @return 无
* @note：by cgh 20231012
*/
void LogRouteUnlockDelayManage(const UINT16 wLogicalRouteId)
{
	UINT32 dwDelayStartCycNum = 0U;        /*逻辑进路区段故障解锁延时开始周期*/
	UINT32 dwDelayTotalCycSum = 0U;        /*逻辑进路区段故障解锁延时周期数*/
	UINT8 chCheckTimeState = 0U;           /*时间参数检查结果*/
	UINT16 wFirstNormalLockLogId = 0U;     /*逻辑进路第一个锁闭的逻辑区段ID*/
	UINT16 wRelativePhySecId = 0U;         /*逻辑区段关联的物理区段ID*/
	UINT8 chPhySecCurMergeState = 0U;/*物理区段当前融合状态*/

	/*超时时间复用总人解时间*/
	dwDelayTotalCycSum = GetSystemParaBlocRouteDelayCyc();   /*获取点式进路延时周期数*/
	dwDelayStartCycNum = GetLogRouteDelayErrLockStartCyc(wLogicalRouteId);  /*获取逻辑进路故障解锁起始周期*/
	/*延时计时*/
	chCheckTimeState = SystemOverTimeCheck(dwDelayStartCycNum, dwDelayTotalCycSum);

	if (CI_TIME_OUT == chCheckTimeState)
	{
		wFirstNormalLockLogId = GetLogRouteFirNormalLockLogId(wLogicalRouteId);
		wRelativePhySecId = GetLgcSecRelativePhySecId(wFirstNormalLockLogId);

		chPhySecCurMergeState = GetPhySecCurMergeState(wRelativePhySecId);
		if (SECTION_OCCUPY_NO == chPhySecCurMergeState)
		{
			SetLogRouFirDelayErLockStaCyc(wLogicalRouteId, 0U);
			/*设置物理区段其他属于本逻辑进路锁闭的逻辑区段逻辑异常锁闭*/
			SetPhyIncLogSecLogLockState(wRelativePhySecId, LOG_SECTION_LOGLOCK_EXCEPT, wLogicalRouteId);
			/*设置逻辑进路区故解延时周期号为0*/
			SetLogSecLogRDelayErrLockCyc(wFirstNormalLockLogId, 0U);
		}
		else
		{
			; /*占用继续等待*/
		}
	}
	else
	{
		; /*时间不到继续等待*/
	}

	dwDelayStartCycNum = GetLogRouteDelayErrLockStartCyc(wLogicalRouteId);  /*获取逻辑进路故障解锁起始周期*/
	if (0U == dwDelayStartCycNum)
	{
		/*逻辑进路已经进行过区故解，但下一区段占用，区故解命令时故障无法传递，使用逻辑进路状态监测空闲时继续异常传递*/
		LogRouteExpLockContinue(wLogicalRouteId);
	}
	else
	{
		;
	}
}

/*
功能描述: 逻辑进路锁闭驱动道岔处理
输入参数:	const UINT16 logRouteId 进路ID
输出参数:	无
返回值:		CI_SUCCESS,如果道岔锁闭处理成功
CI_ERROR,如果道岔锁闭处理失败
*/
UINT8 LogRouteLockDriveSwitch(const UINT16 logRouteId)
{
	UINT8 ii = 0u;
	UINT8 switchSum = 0u;
	UINT16 switchId = 0u;
	UINT8 switchExpPosition = SWITCH_POSITION_INVALID;			/*道岔期望位置*/
	UINT8 switchDancaoPosition = SWITCH_POSITION_INVALID; 		/*单操有效位置*/
	RouteSwitchStruct pRouteSwitchStru[ROUTE_SWITCH_SUM_MAX] = {0U};					/*道岔数据结构指针*/
	UINT8 innerSwitchRetVal = CI_ERROR;							/*检查进路内道岔是否可被驱动的结果*/
	UINT8 assocSwitchRetVal = CI_ERROR; 						/*检查带动道岔是否可被驱动的结果*/
	UINT8 assocSwitchSum = 0u; 									/*道岔数目*/
	RouteAssocSwitchStruct routeAssocSwitchStru = { 0,0 }; 		        /*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct pRouteProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };    /*防护道岔数据*/

	if ((0u == logRouteId) || (logRouteId >= ROUTE_SUM_MAX))
	{
		innerSwitchRetVal = CI_ERROR;
	}
	else
	{
		innerSwitchRetVal = CI_SUCCESS;

		/*获取逻辑进路内道岔数据*/
		switchSum = GetLogRouteSWData(logRouteId, pRouteSwitchStru);
		/*获取逻辑进路内防护道岔数据*/
		routeProtectSwitchSum = GetLogRouteProSwData(logRouteId, pRouteProtectSwitchStru);

		/* 单操相反位置取消进路检查 */
		for (ii = 0u; ii < switchSum; ii++)
		{
			switchId = pRouteSwitchStru[ii].SwitchId;
			switchExpPosition = pRouteSwitchStru[ii].SwitchPosition;
			switchDancaoPosition = GetSwitchDanCaoPostition(switchId);

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

		if (CI_SUCCESS == innerSwitchRetVal)
		{
			

			/* 单操相反位置取消进路检查 */
			for (ii = 0u; ii < routeProtectSwitchSum; ii++)
			{
				switchId = pRouteProtectSwitchStru[ii].ProtectSwitchId;
				switchExpPosition = pRouteProtectSwitchStru[ii].ProtectPosition;
				switchDancaoPosition = GetSwitchDanCaoPostition(switchId);

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

		

		if (CI_SUCCESS == innerSwitchRetVal)
		{
			/*驱动进路道岔*/
			LogRouteDrvInnerSwitch(logRouteId, SWITCH_NEED_DRIV_TRUE);
		}
		else
		{
			LogRouteDrvInnerSwitch(logRouteId, SWITCH_NEED_DRIV_FALSE);
		}

	}

	return innerSwitchRetVal;




}

/*
* 功能描述： 获取逻辑进路内逻辑区段防护道岔信息
* 参数说明： const UINT16 logRouteId, 进路ID
*            OUT RouteProtectSwitchStruct szRouteProtectSwitchStruct[ROUTE_PHYSICALSECTION_SUM_MAX] 输出防护道岔ID数组
*
* 返回值  ： 0失败 >0防护道岔数量
*
*/
UINT8 GetLogRouteProSwData(const UINT16 logRouteId, OUT RouteProtectSwitchStruct szRouteProSwitchStruct[ROUTE_PROTECTSWI_SUM_MAX])
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT8 reVal = 0u;
	UINT8 keepWork = CI_ERROR;
	UINT8 ii = 0U; /*循环变量*/
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT16 phySecId = 0U;
	UINT8 phySecSum = 0U;
	UINT8 proSwSum = 0U;
	UINT8 outTmpProSwSum = 0U;
	RouteProtectSwitchStruct szTmpProSwStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };
	LogsecSwitchStruct* pLgcProSwStru = NULL;   /*逻辑区段关联防护道岔信息*/
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;

	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);

	/*入参检查*/
	if (NULL != szRouteProSwitchStruct)
	{
		keepWork = CI_SUCCESS;
		/*遍历进路所有逻辑区段*/
		for (ii = 0U; ii < logSectionSum; ii++)
		{

			proSwSum = GetLgcRelateProSwSum(pLogIdBuff[ii]);
			pLgcProSwStru = GetLgcRelateProSwStru(pLogIdBuff[ii]);

			if (NULL != pLgcProSwStru)
			{
				/*去重并添加*/
				for (jj = 0U; jj < proSwSum; jj++)
				{
					for (kk = 0U; kk < outTmpProSwSum; kk++)
					{
						if (pLgcProSwStru[jj].SwitchId == szTmpProSwStru[kk].ProtectSwitchId)
						{
							break;
						}
						else
						{
							/*继续执行*/
						}
					}
					if (kk == outTmpProSwSum)
					{
						if (ROUTE_PROTECTSWI_SUM_MAX > outTmpProSwSum)
						{
							szTmpProSwStru[outTmpProSwSum].ProtectSwitchId = pLgcProSwStru[jj].SwitchId;
							szTmpProSwStru[outTmpProSwSum].ProtectPosition = pLgcProSwStru[jj].SwitchPosition;
							outTmpProSwSum++;
						}
						else
						{
							break;
						}
					}
				}
			}
			else
			{
				keepWork = CI_ERROR;
			}

			/*未重复*/
			if (jj != proSwSum)
			{
				keepWork = CI_ERROR;
			}
			else
			{
				;
			}

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

		/*执行完成，未越界*/
		if (ii == logSectionSum)
		{
			reVal = outTmpProSwSum;
			for (ii = 0U; ii < outTmpProSwSum; ii++)
			{
				szRouteProSwitchStruct[ii] = szTmpProSwStru[ii];
			}
		}


	}
	else
	{
		/*检查失败*/
		reVal = 0u;
	}

	return reVal;
}

/*
* 功能描述： 获取逻辑进路内道岔信息
* 参数说明： const UINT16 logRouteId, 进路ID
*            OUT RouteProtectSwitchStruct szRouteProtectSwitchStruct[ROUTE_PHYSICALSECTION_SUM_MAX] 输出道岔ID数组
*
* 返回值  ： 0失败 >0道岔数量
*
*/
UINT8 GetLogRouteSWData(const UINT16 logRouteId, OUT RouteSwitchStruct szRouteSwitchStruct[ROUTE_SWITCH_SUM_MAX])
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT8 reVal = 0u;
	UINT8 keepWork = CI_ERROR;
	UINT8 ii = 0U; /*循环变量*/
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT16 phySecId = 0U;
	UINT8 phySecSum = 0U;
	UINT8 switchSum = 0U;
	UINT8 outTmpProSwSum = 0U;

	RouteSwitchStruct szTmpSwStru[ROUTE_SWITCH_SUM_MAX] = { 0U };
	LogsecSwitchStruct* pLgcSwStru = NULL;   /*逻辑区段关联防护道岔信息*/
	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;

	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);

	/*入参检查*/
	if (NULL != szRouteSwitchStruct)
	{
		keepWork = CI_SUCCESS;
		/*遍历进路所有逻辑区段*/
		for (ii = 0U; ii < logSectionSum; ii++)
		{
			switchSum = GetLogicSecSwitchSum(pLogIdBuff[ii]);
			pLgcSwStru = GetLogicSecSwitchIdStru(pLogIdBuff[ii]);

			if (NULL != pLgcSwStru)
			{
				/*去重并添加*/
				for (jj = 0U; jj < switchSum; jj++)
				{
					for (kk = 0U; kk < outTmpProSwSum; kk++)
					{
						if (pLgcSwStru[jj].SwitchId == szTmpSwStru[kk].SwitchId)
						{
							break;
						}
						else
						{
							/*继续执行*/
						}
					}
					if (kk == outTmpProSwSum)
					{
						if (ROUTE_PROTECTSWI_SUM_MAX > outTmpProSwSum)
						{
							szTmpSwStru[outTmpProSwSum].SwitchId = pLgcSwStru[jj].SwitchId;
							szTmpSwStru[outTmpProSwSum].SwitchPosition = pLgcSwStru[jj].SwitchPosition;
							outTmpProSwSum++;
						}
						else
						{
							break;
						}
					}
				}
			}
			else
			{
				keepWork = CI_ERROR;
			}

			/*未重复*/
			if (jj != switchSum)
			{
				keepWork = CI_ERROR;
			}
			else
			{
				;
			}

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

		/*执行完成，未越界*/
		if (ii == logSectionSum)
		{
			reVal = outTmpProSwSum;
			for (ii = 0U; ii < outTmpProSwSum; ii++)
			{
				szRouteSwitchStruct[ii] = szTmpSwStru[ii];
			}
		}


	}
	else
	{
		/*检查失败*/
		reVal = 0u;
	}

	return reVal;
}


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

	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	routeDir = GetLogicalRouteDir(logRouteId);

	/*检查数据合法*/
	if ((0u != logSectionSum) && (NULL != pLogIdBuff))
	{
		for (i = 0u; i < logSectionSum; i++)
		{
			/*正常锁闭*/
			if (LOG_SECTION_LOGLOCK_NORMAL == lockState)
			{
				SetLogSecLogLockState(pLogIdBuff[i], LOG_SECTION_LOGLOCK_NORMAL, routeDir);
				SetLogSecRelateLogRouteData(logRouteId, pLogIdBuff[i]);
			}
			/*未锁闭*/
			else if (LOG_SECTION_LOGLOCK_NO == lockState)
			{
				(void)DelLogSecBelongLogRouteId(pLogIdBuff[i], logRouteId);
				logRouteSum = GetLogSecLockBelLogRouteSum(pLogIdBuff[i]);
				if (0U == logRouteSum)
				{
					SetLogSecLogLockState(pLogIdBuff[i], LOG_SECTION_LOGLOCK_NO, routeDir);
				}
			}
			/*故障锁闭*/
			else if (LOG_SECTION_LOGLOCK_EXCEPT == lockState)
			{
				SetLogSecLogLockState(pLogIdBuff[i], LOG_SECTION_LOGLOCK_EXCEPT, routeDir);
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不做处理*/
	}
}

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

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

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

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

/**
* @brief 设置逻辑区段对应所有逻辑进路区故解延时解锁周期
* @param const UINT32 dwCyc 周期号
* @return 无
* @note：by cgh 20231013
*/
void SetLogSecLogRDelayErrLockCyc(const UINT16 wLogSectionId, const UINT32 dwCyc)
{
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT8 ii = 0U;
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/
	UINT32 dwLogRouteDelayErrLockStartCyc = 0U;/*逻辑进路区故解延时解锁起始周期号*/

	chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSectionId);
	szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSectionId);

	if (NULL != szLogSecLockBelLogRouteData)
	{
		for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
		{
			wLogSecBelLogRouteId = szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
			dwLogRouteDelayErrLockStartCyc = GetLogRouteDelayErrLockStartCyc(wLogSecBelLogRouteId);
			if (0U != dwLogRouteDelayErrLockStartCyc)
			{
				SetLogRouteDelayErrLockStartCyc(wLogSecBelLogRouteId, dwCyc);
			}
			else
			{
				; /*不处理*/
			}
		}
	}
	else
	{
		; /*不处理*/
	}
}

/*
* 功能描述： 逻辑进路区段征用检查处理
* 参数说明： const UINT16 logRouteId   逻辑进路号
* 返回值  ： CI_ERROR
*            CI_SUCCESS
* 故障编码： EFUNC_CHECK_SECTION_USE
*/
UINT8 LogRoutePhySecUseLogicProcess(const UINT16 logRouteId)
{
	/*函数故障码*/
	UINT8 const functionId = EFUNC_LogRoureUsingStateCheck;

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

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

	
	/* 进路全部区段 = 【未征用】*/
	devId = 0u;
	devState = 0u;
	checkResult = LogRouteAllSecUseVainCheck(logRouteId, &devId, &devState);
	if (checkResult == CI_SUCCESS)
	{
		/* 通过检查 */
		reResult = CI_SUCCESS;
	}
	else
	{
		/* 记录故障码 */
		SetErrorData(functionId, CI_DEVICE_TYPE_PHYSEC, devId, ETYPE_PS_USE_STATE, devState, sendLevel);
		/* 失败返回 */
		reResult = CI_ERROR;

	}

	return reResult;
}

/*
* 功能描述： 逻辑进路内区段未征用状态检查
* 参数说明： UINT16 const routeId
*            UINT16 *pDevId,    设备Id（返回）
*            UINT8 *pDevState,  设备状态（返回）
* 返回值  ： CI_ERROR
*            CI_SUCCESS
*/
UINT8 LogRouteAllSecUseVainCheck(UINT16 const logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;


	UINT8 reVal = CI_ERROR;

	/* 进路区段*/
	UINT8 routeSecSum = 0u;/*进路内区段数量*/
	RoutePhysicalSectionStruct* pRouteSecDataBuf = NULL;/*进路内区段数据*/


	UINT8 phyBelongCi = 0u;/*区段所属联锁*/
	UINT8 commState = 0u;/*通信状态*/
	
	UINT16 phySecProtectUseRouteId = 0u;
	UINT16 phySecUseRouteId = 0u;
	UINT16 phySecUseByLogRouteId = 0u;


	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	UINT16 wPhySecId = 0U;
	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);


	/* 指针防空检查 */
	if ((0u == logSectionSum) || (NULL == pLogIdBuff))
	{
		/*区段数据错误或指针为空*/
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
		/*开始检查进路内区段征用*/
		for (i = 0u; i < logSectionSum; i++)
		{
			wPhySecId = GetLgcSecRelativePhySecId(pLogIdBuff[i]);
			devId = wPhySecId;
			devState = GetPhySecUseState(devId);
			
				/* 需检查本区段 */
			if (PHYSICAL_SECTION_USING_NO == devState)
			{
				/* 通过检查*/

			}
			else
			{
				phySecProtectUseRouteId = GetPhySecProtectUseRouteId(devId);
				phySecUseRouteId = GetPhySecUseRouteId(devId);
				phySecUseByLogRouteId = GetPhySecUseLogRouteId(devId);
				if (CI_SUCCESS == reVal)
				{
					if (0u == phySecProtectUseRouteId)
					{
						reVal = CI_ERROR;/*执行到此处phySecProtectUseRouteId为0说明运算错误，导向安全*/
					}
				}
				/*①当前区段被其他进路“进路征用”，则不能办理本进路*/
				if (CI_SUCCESS == reVal)
				{
					if ((0u < phySecUseRouteId) || (0u < phySecUseByLogRouteId))
					{
						reVal = CI_ERROR;
					}
				}
				/*②检查该区段防护征用时，当前道岔位置或期望动作位置是否与本进路要求的位置相同*/
				if (CI_SUCCESS == reVal)
				{
					reVal = CheckPhysecUseStateInLogRoute(devId, logRouteId);
				}

				if (CI_SUCCESS != reVal)
				{
					/*状态不一致返回故障状态*/
					*pDevId = devId;
					*pDevState = devState;
					break;
				}
			}

		}

		/*检查逻辑进路防护道岔所在区段的征用*/
		if (CI_SUCCESS == reVal)
		{
			reVal = CheckProSwUseStateInLogRoute(logRouteId, &devId, &devState);
			/*若返回失败，则退出*/
			if (CI_SUCCESS != reVal)
			{
				/*状态不一致返回故障状态*/
				*pDevId = devId;
				*pDevState = devState;
				
			}
		}
	}


	return reVal;
}

/*
*函数功能：区段处于进路征用时，检查区段道岔状态与进路内要求的是否一致
*参数说明：const UINT16 devId 物理区段ID
*          const UINT16 routeId 已经征用或要征用该区段的进路
*返回值：0：失败
*        1：成功
*/
UINT8 CheckPhysecUseStateInLogRoute(const UINT16 devId, const UINT16 logRouteId)
{
	RouteSwitchStruct pRouteSwitchStruct[ROUTE_SWITCH_SUM_MAX] = { 0U };
	UINT8 routeSwitchSum = 0u;
	UINT8 reVal = CI_ERROR;
	UINT16* pPhySecIncludeSwitch = NULL;
	UINT8 phyIncludeSwitchSum = 0u;
	UINT8 i = 0u;
	UINT16 routeSwitchID = 0u;
	UINT8 routeSwitchPos = 0u;
	UINT8 j = 0u;
	UINT16 phySecIncludeSwitchID = 0u;
	UINT8 phySecIncludeSwitchPos = 0u;
	UINT8 SwitchExpDrvPos = 0u;/*道岔期望动作位置*/

	routeSwitchSum = GetLogRouteSWData(logRouteId, pRouteSwitchStruct); /*正在办理的这条进路内的道岔数据*/

	pPhySecIncludeSwitch = GetPhySecIncludeSwitch(devId);/*获取物理区段包含道岔*/
	phyIncludeSwitchSum = GetPhyIncludeSwitchSum(devId);

	if ((NULL == pRouteSwitchStruct) || (NULL == pPhySecIncludeSwitch))
	{
		reVal = CI_ERROR;
	}
	else
	{
		reVal = CI_SUCCESS;
	}
	/*检查区段当前道岔位置与本进路内道岔位置是否相同*/
	if (CI_SUCCESS == reVal)
	{
		for (j = 0u; j < phyIncludeSwitchSum; j++)
		{
			phySecIncludeSwitchID = pPhySecIncludeSwitch[j];
			phySecIncludeSwitchPos = GetSwitchCurPosition(phySecIncludeSwitchID);
			/*遍历进路的每一个道岔*/
			for (i = 0u; i < routeSwitchSum; i++)/*防护征用进路的道岔数*/
			{
				routeSwitchID = pRouteSwitchStruct[i].SwitchId;
				routeSwitchPos = pRouteSwitchStruct[i].SwitchPosition;
				if (phySecIncludeSwitchID == routeSwitchID)
				{
					if (phySecIncludeSwitchPos == routeSwitchPos)
					{
						reVal = CI_SUCCESS;
					}
					else
					{/*检查该道岔的期望驱动位置是否与这个进路要求的位置相同*/
						SwitchExpDrvPos = GetSwitchPreExpDrvPosition(routeSwitchID);
						if ((SWITCH_POSITION_DINGWEI == routeSwitchPos) && (SWITCH_DRIVE_POS_DINGWEI == SwitchExpDrvPos))
						{
							reVal = CI_SUCCESS;
						}
						else if ((SWITCH_POSITION_FANWEI == routeSwitchPos) && (SWITCH_DRIVE_POS_FANWEI == SwitchExpDrvPos))
						{
							reVal = CI_SUCCESS;
						}
						else
						{
							reVal = CI_ERROR;
						}

					}
				}
				/*失败后跳出*/
				if (CI_ERROR == reVal)
				{
					break;
				}
			}
			/*失败后跳出*/
			if (CI_ERROR == reVal)
			{
				break;
			}
		}

	}
	return reVal;
}



/*
*函数功能：检查逻辑进路防护道岔所在区段的征用
*参数说明：const UINT16 logRouteId  逻辑进路
*输出参数：UINT16* pDevId , UINT8* pDevState
*返回值：0：失败
*        1：成功
*/
UINT8 CheckProSwUseStateInLogRoute(UINT16 const logRouteId, UINT16* pDevId, UINT8* pDevState)
{
	UINT8 reVal = CI_ERROR;
	UINT8 i = 0u;           /* 循环变量 */
	UINT16 devId = 0u;
	UINT8  devState = 0u;
	/*进路防护道岔*/
	UINT8 routeProSwitchSum = 0u;/*进路防护道岔数量*/
	RouteProtectSwitchStruct pRouteProSwitchDataBuf[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };/*进路防护道岔数据*/
	UINT16 phySecProtectUseRouteId = 0u;
	UINT16 phySecUseRouteId = 0u;
	UINT16 phySecUseByLogRouteId = 0u;

	UINT8 switchCurPosition = 0u;
	UINT8 SwitchDrvPos = 0u;
	UINT16 proSwitchId = 0u;/*防护道岔ID*/
	UINT16 proSwitchSecId = 0u;/*防护道岔所在区段ID*/
	UINT8 proSwitchRoutePos = 0u;/*进路要求的防护道岔位置*/

	if ((0U < logRouteId) && (ROUTE_LOGICAL_SUM_MAX > logRouteId) && (NULL != pDevId) && (NULL != pDevState))
	{
		/*获取进路包含防护道岔信息*/
		routeProSwitchSum = GetLogRouteProSwData(logRouteId, pRouteProSwitchDataBuf);
		if (0U != routeProSwitchSum)
		{
			/*检查逻辑进路防护道岔所在区段的征用*/
			for (i = 0u; i < routeProSwitchSum; i++)
			{
				proSwitchId = pRouteProSwitchDataBuf[i].ProtectSwitchId;/*防护道岔id*/
				proSwitchRoutePos = pRouteProSwitchDataBuf[i].ProtectPosition;/*进路要求的防护道岔位置*/
				switchCurPosition = GetSwitchCurPosition(proSwitchId);
				proSwitchSecId = GetSwitchPhySectionId(proSwitchId);/*获取防护道岔所在区段id*/
				devState = GetPhySecUseState(proSwitchSecId); /*获取防护道岔所在区段征用状态*/

					/* 需检查本区段 */
				if (PHYSICAL_SECTION_USING_NO == devState)
				{
					/* 通过检查*/
					reVal = CI_SUCCESS;
				}
				else
				{
					phySecUseRouteId = GetPhySecUseRouteId(proSwitchSecId);
					phySecProtectUseRouteId = GetPhySecProtectUseRouteId(proSwitchSecId);
					if ((0u < phySecUseRouteId) || (0u < phySecProtectUseRouteId))
					{
						reVal = CI_SUCCESS;/*执行到了此处，必须保证这两个值至少一个大于0*/
					}
					else
					{
						reVal = CI_ERROR;
					}

					if (CI_SUCCESS == reVal)
					{
						/*检查当前道岔位置或道岔期望动作位置是否与本进路要求的防护道岔位置相同*/
						if (proSwitchRoutePos == switchCurPosition)
						{
							reVal = CI_SUCCESS;
						}
						else
						{
							/*检查该道岔驱动位置是否与这个进路要求的位置相同*/
							SwitchDrvPos = GetSwitchPreExpDrvPosition(proSwitchId);
							if ((SWITCH_POSITION_DINGWEI == proSwitchRoutePos) && (SWITCH_DRIVE_POS_DINGWEI == SwitchDrvPos))
							{
								reVal = CI_SUCCESS;
							}
							else if ((SWITCH_POSITION_FANWEI == proSwitchRoutePos) && (SWITCH_DRIVE_POS_FANWEI == SwitchDrvPos))
							{
								reVal = CI_SUCCESS;
							}
							else
							{
								reVal = CI_ERROR;
							}
						}

					}

					/*若返回失败，则退出*/
					if (CI_SUCCESS != reVal)
					{
						/*状态不一致返回故障状态*/
						*pDevId = proSwitchSecId;
						*pDevState = devState;
						break;
					}
				}
			}
		}
		else
		{
			reVal = CI_SUCCESS;  /*无防护道岔，返回成功*/
		}
	}
	else
	{
		/*入参非法，返回失败*/
	}

	return reVal;
}

/*
*函数功能：获取指定ID逻辑进路包含的物理区段
*参数说明：const UINT16 wlogicRouteId 逻辑进路ID
*          UINT16 szPhySecId[] 逻辑进路包含的物理区段ID数组（返回）
*返回值：0: 获取失败
*        >0: 获取成功
* Created By LQ 2023/10/14
*/
UINT8 GetLogicRouteIncPhySec(const UINT16 wlogicRouteId, UINT16 szPhySecId[])
{
	UINT8 retVal = CI_ERROR;
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wRouteIncLogSecNum = 0U;  /*逻辑进路包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecId = NULL;  /*逻辑进路包含的逻辑区段ID数组*/
	UINT16 wLogSecRelPhySecId = 0U;  /*逻辑区段关联的物理区段Id*/
	UINT8 cRouteIncPhySecNum = 0U;  /*逻辑进路包含的物理区段数量*/

	if ((0U < wlogicRouteId) && (ROUTE_LOGICAL_SUM_MAX > wlogicRouteId) && (NULL != szPhySecId))
	{
		wRouteIncLogSecNum = GetLogicalRouteInLogSecSum(wlogicRouteId);
		pRouteIncLogSecId = GetLogicalRouteInLogSecId(wlogicRouteId);

		if ((0U != wRouteIncLogSecNum) && (NULL != pRouteIncLogSecId))
		{
			for (ii = 0U; ii < wRouteIncLogSecNum; ii++)
			{
				wLogSecRelPhySecId = GetLgcSecRelativePhySecId(pRouteIncLogSecId[ii]);  /*获取逻辑进路关联的物理区段*/
				if (0U != wLogSecRelPhySecId)
				{
					if (0U == cRouteIncPhySecNum)
					{
						szPhySecId[cRouteIncPhySecNum] = wLogSecRelPhySecId;
						cRouteIncPhySecNum++;
					}
					else
					{
						for (jj = 0U; jj < cRouteIncPhySecNum; jj++)
						{
							if (wLogSecRelPhySecId == szPhySecId[jj])
							{
								break;  /*物理区段ID已包含，停止遍历*/
							}
							else
							{
								/*物理区段未重复，继续遍历*/
							}
						}

						if (jj == cRouteIncPhySecNum)
						{
							szPhySecId[cRouteIncPhySecNum] = wLogSecRelPhySecId;  /*为逻辑进路添加包含的物理区段*/
							cRouteIncPhySecNum++;
						}
						else
						{
							/*物理区段ID已包含，不添加*/
						}
					}

					retVal = cRouteIncPhySecNum;  /*返回数量*/
				}
				else
				{
					retVal = CI_ERROR;  /*获取逻辑进路关联的物理区段失败，返回失败*/
				}
			}
		}
		else
		{
			retVal = CI_ERROR;  /*获取逻辑进路包含的逻辑区段失败，返回失败*/
		}
	}
	else
	{
		retVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return retVal;
}

/*
*函数功能：获取指定ID逻辑进路车脚下包含的物理区段(且物理区段包含在逻辑进路中才计入)
*参数说明：const UINT16 wlogicRouteId 逻辑进路ID
*          UINT16 szPhySecId[] 逻辑进路车脚下包含的物理区段ID数组（返回）
*返回值：0: 获取失败
*        >0: 获取成功
*/
UINT8 GetLogicRouteTrainLogIncPhySec(const UINT16 wlogicRouteId, UINT16 szPhySecId[])
{
	UINT8 retVal = CI_ERROR;
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wRouteIncLogSecNum = 0U;  /*逻辑进路车脚下包含的逻辑区段数量*/
	UINT16* pRouteIncLogSecId = NULL;  /*逻辑进路车脚下包含的逻辑区段ID数组*/
	UINT16 wLogSecRelPhySecId = 0U;  /*逻辑区段车脚下关联的物理区段Id*/
	UINT8 cRouteIncPhySecNum = 0U;  /*逻辑进路车脚下包含的物理区段数量*/
	UINT8 keepWork = CI_ERROR;

	if ((0U < wlogicRouteId) && (ROUTE_LOGICAL_SUM_MAX > wlogicRouteId) && (NULL != szPhySecId))
	{
		wRouteIncLogSecNum = GetLogicalRouteTrainLogSecSum(wlogicRouteId);
		pRouteIncLogSecId = GetLogicalRouteTrainLogSecId(wlogicRouteId);

		if ((0U != wRouteIncLogSecNum) && (NULL != pRouteIncLogSecId))
		{
			for (ii = 0U; ii < wRouteIncLogSecNum; ii++)
			{
				wLogSecRelPhySecId = GetLgcSecRelativePhySecId(pRouteIncLogSecId[ii]);  /*获取逻辑区段关联的物理区段*/
				if (0U != wLogSecRelPhySecId)
				{
					keepWork = CheckPhySecInLogRoute(wlogicRouteId, wLogSecRelPhySecId);		/*包含在逻辑进路中的物理区段才计入*/
					if (CI_ERROR != keepWork)
					{
						if (0U == cRouteIncPhySecNum)
						{
							szPhySecId[cRouteIncPhySecNum] = wLogSecRelPhySecId;
							cRouteIncPhySecNum++;
						}
						else
						{
							for (jj = 0U; jj < cRouteIncPhySecNum; jj++)
							{
								if (wLogSecRelPhySecId == szPhySecId[jj])
								{
									break;  /*物理区段ID已包含，停止遍历*/
								}
								else
								{
									/*物理区段未重复，继续遍历*/
								}
							}

							if (jj == cRouteIncPhySecNum)
							{
								szPhySecId[cRouteIncPhySecNum] = wLogSecRelPhySecId;  /*为逻辑进路添加包含的物理区段*/
								cRouteIncPhySecNum++;
							}
							else
							{
								/*物理区段ID已包含，不添加*/
							}
						}

						retVal = cRouteIncPhySecNum;  /*返回数量*/
					}
					else
					{
						;		/*不是本逻辑进路内物理区段，不计入*/
					}
				}
				else
				{
					retVal = CI_ERROR;  /*获取逻辑进路关联的物理区段失败，返回失败*/
				}
			}
		}
		else
		{
			retVal = CI_ERROR;  /*获取逻辑进路包含的逻辑区段失败，返回失败*/
		}
	}
	else
	{
		retVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return retVal;
}

/*
*函数功能：初始化逻辑进路内属于同一进路物理区段，不属于本进路，且不属于道岔防护区域逻辑区段+属于同一道岔防护区段逻辑区段，不属于本进路的逻辑区段
* 参数说明：UINT16 const logRouteId 逻辑进路ID
* 返回值：0，失败；1，成功
* ********************************************/
void LogRouteOutLgcSecConfigDataInit(UINT16 const logRouteId)
{
	UINT16 i = 0U, j = 0U;
	UINT8 k = 0U;
	UINT8 rtnvalue = CI_ERROR;

	UINT8 szHitSwProLgcSec[LOGIC_SECTION_SUM_MAX] = { 0U };/*逻辑进路道岔关联的逻辑区段标志位记录*/
	UINT8 szHitRouteLgcSec[LOGIC_SECTION_SUM_MAX] = { 0U };/*逻辑进路包含的逻辑区段标志位记录*/
	UINT16 wSwitchId = 0U;
	
	UINT16 logRouteIndex = 0U; /*逻辑进路索引*/
	UINT16 logSecBelSwitchSum = 0U;  /*道岔关联的逻辑区段数目*/
	UINT16* logSecBelSwitchBuf = NULL;/*道岔关联的逻辑区段ID数组*/

	UINT16 routeInSwitOtherPosLogSecSum = 0U;                               /*进路内道岔关联的非进路内逻辑区段数量*/
	UINT16 routeInSwitOtherPosLogSecIdBuf[MAX_ROUTE_IN_LT_NUM] = { 0U };    /*进路内道岔关联的非进路内逻辑区段ID数组*/
	UINT16 routeOutLogSecSum = 0U;								          /*进路包含物理区段关联的非进路内且非道岔关联的逻辑区段数量 */
	UINT16 routeOutLogSecSumIdBuf[MAX_ROUTE_IN_LT_NUM] = { 0U };		  /*进路包含物理区段关联的非进路内且非道岔关联的逻辑区段ID数组 */

	UINT16  routeLogSecSum = 0U;  /*进路包含的逻辑区段数目*/
	UINT16* pRouteLogSecIdBuf = NULL;  /*进路包含的逻辑区段ID数组*/
	UINT8  routePhySecSum = 0U;  /*进路包含的物理区段数目*/
	UINT16 pRoutePhySecIdBuf[ROUTE_PHYSICALSECTION_SUM_MAX] = { 0U };  /*进路包含的物理区段ID数组*/

	UINT8 routeSwitchSum = 0U;  /*进路包含的道岔数目*/
	RouteSwitchStruct pRouteSwitchStruct[ROUTE_SWITCH_SUM_MAX] = {0U}; /*进路包含的道岔ID数组*/

	UINT16* pPhySecIncludeSwitch = NULL;   /*物理区段包含的道岔ID数组*/
	UINT8 chPhyIncludeSwitchSum = 0u;   /*物理区段包含的道岔数量*/

	/*获取进路包含逻辑区段信息*/
	routeLogSecSum = GetLogicalRouteInLogSecSum(logRouteId);
	pRouteLogSecIdBuf =GetLogicalRouteInLogSecId(logRouteId);
	/*获取进路包含道岔信息*/
	routeSwitchSum = GetLogRouteSWData(logRouteId, pRouteSwitchStruct);
	/*获取进路包含物理区段信息*/
	routePhySecSum = GetLogicRouteIncPhySec(logRouteId, &pRoutePhySecIdBuf);


	rtnvalue = CI_SUCCESS;
	for (i = 0u; i < routeLogSecSum; i++)
	{
		if (LOGIC_SECTION_SUM_MAX > pRouteLogSecIdBuf[i])
		{
			/*把该进路包含的逻辑区段设标志位1*/
			szHitRouteLgcSec[pRouteLogSecIdBuf[i]] = 1U;
		}
		else
		{
			rtnvalue = CI_ERROR;
			break;
		}
	}

	if ((CI_SUCCESS == rtnvalue) && (NULL != pRouteSwitchStruct))
	{
		routeInSwitOtherPosLogSecSum = 0U;
		/*遍历进路包含的所有道岔*/
		for (i = 0u; i < routeSwitchSum; i++)
		{
			wSwitchId = pRouteSwitchStruct[i].SwitchId;/*获取道岔区段索引*/

			logSecBelSwitchSum = GetSwitchLogSecSum(wSwitchId);
			logSecBelSwitchBuf = GetSwitchLogSecBuf(wSwitchId);

			/*遍历道岔关联的逻辑区段*/
			for (j = 0U; j < logSecBelSwitchSum; j++)
			{
				if (LOGIC_SECTION_SUM_MAX > logSecBelSwitchBuf[j])
				{
					/*道岔关联的逻辑区段不在进路关联逻辑区段内*/
					if (1U != szHitRouteLgcSec[logSecBelSwitchBuf[j]])
					{
						routeInSwitOtherPosLogSecIdBuf[routeInSwitOtherPosLogSecSum] = logSecBelSwitchBuf[j];
						routeInSwitOtherPosLogSecSum++;
					}
					szHitSwProLgcSec[logSecBelSwitchBuf[j]] = 1U;
				}
				else
				{
					rtnvalue = CI_ERROR;
					break;
				}
			}
		}
	}

	if (CI_SUCCESS == rtnvalue) 
	{
		/*遍历逻辑进路关联的所有物理区段*/
		for (k = 0U; k < routePhySecSum; k++)
		{
			/*获取该物理区段包含道岔数据*/
			chPhyIncludeSwitchSum = GetPhyIncludeSwitchSum(pRoutePhySecIdBuf[k]);

			/*物理区段存在道岔时才进行判断*/
			if(0U<chPhyIncludeSwitchSum)
			{ 
				logSecBelSwitchSum = GetPhySecIncLogSecSum(pRoutePhySecIdBuf[k]);
				logSecBelSwitchBuf = GetPhySecIncLogSecIdBuf(pRoutePhySecIdBuf[k]);
				/*遍历道岔关联的所有逻辑区段*/
				for (j = 0U; j < logSecBelSwitchSum; j++)
				{
					if (LOGIC_SECTION_SUM_MAX > logSecBelSwitchBuf[j])
					{
						/*该逻辑区段不在逻辑进路包含的逻辑区段中  且不在逻辑进路道岔关联的逻辑区段中 */
						if ((1U != szHitRouteLgcSec[logSecBelSwitchBuf[j]])
							&& (1U != szHitSwProLgcSec[logSecBelSwitchBuf[j]]))
						{
							/*该逻辑区段已被包含在数组中*/
							routeOutLogSecSumIdBuf[routeOutLogSecSum] = logSecBelSwitchBuf[j];
							routeOutLogSecSum++;
						}
					}
					else
					{
						rtnvalue = CI_ERROR;
						break;
					}
				}
			}
		}
	}

	/*计算结果拷贝*/
	if (CI_SUCCESS == rtnvalue)
	{
		logRouteIndex = GetLogRouteBufIndex(logRouteId);
		LogicalRouteDataStru[logRouteIndex].routeInSwitOtherPosLogSecSum = routeInSwitOtherPosLogSecSum;
		LogicalRouteDataStru[logRouteIndex].routeOutLogSecSum = routeOutLogSecSum;
		for (i = 0U; i < routeInSwitOtherPosLogSecSum; i++)
		{
			LogicalRouteDataStru[logRouteIndex].routeInSwitOtherPosLogSecIdBuf[i] = routeInSwitOtherPosLogSecIdBuf[i];
		}
		for (i = 0U; i < routeOutLogSecSum; i++)
		{
			LogicalRouteDataStru[logRouteIndex].routeOutLogSecSumIdBuf[i] = routeOutLogSecSumIdBuf[i];
		}
	}

	
}


/*
功能描述: 逻辑进路驱动道岔处理
输入参数 : const UINT16 routeId 进路ID
输出参数 : const UINT8 DrivFlag 道岔驱动标志
返回值 : 无
*/
void LogRouteDrvInnerSwitch(const UINT16 logRouteId, const UINT8 DrivFlag)
{
	UINT8 ii = 0u;
	UINT8 jj = 0U;
	UINT8 funRtn = 0U;

	UINT16 switchId = 0u;
	UINT8 switchExpPos = SWITCH_POSITION_INVALID;			/*道岔期望位置*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };  /*防护道岔数据*/
	UINT8 switchSum = 0U;							/*道岔数量*/
	RouteSwitchStruct pSwitchData[ROUTE_SWITCH_SUM_MAX] = {0U};/*道岔数据*/

	/*获取进路包含逻辑区段信息*/

	switchSum = GetLogRouteSWData(logRouteId, pSwitchData);
	routeProtectSwitchSum = GetLogRouteProSwData(logRouteId, routeProtectSwitchStru);      /*获取防护道岔数据*/

	if (SWITCH_NEED_DRIV_TRUE == DrivFlag)
	{/*需要驱动进路内道岔*/

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

			switchId = pSwitchData[ii].SwitchId;
			switchExpPos = pSwitchData[ii].SwitchPosition;
			funRtn = SwitchDriveProcess(switchId, switchExpPos); /*设置进路内道岔的驱动状态为驱动中*/

		}

		for (ii = 0u; ii < routeProtectSwitchSum; ii++)
		{
			switchId = routeProtectSwitchStru[ii].ProtectSwitchId;
			switchExpPos = routeProtectSwitchStru[ii].ProtectPosition;
			funRtn = SwitchDriveProcess(switchId, switchExpPos); /*设置进路关联防护道岔的驱动状态为驱动中*/
		}
	}
}

/*
* 功能描述： 检查逻辑进路内道岔及防护道岔位置正确
* 参数说明： const UINT16 wLogRouteId, 进路ID
* 返回值  ： UINT8
*	CI_SUCCESS:道岔位置正确
*	CI_ERROR:道岔位置不正确
*/
UINT8 ChekLogRouteSwPosRight(const UINT16 logRouteId)
{
	UINT8 retVal = CI_ERROR;

	UINT8 lgcSecSwitchSum = 0U;							/*逻辑区段关联道岔数量*/
	LogsecSwitchStruct* pLgcSecSwitchData = NULL;
	UINT8 ii = 0u;											/*循环变量*/
	UINT8 jj = 0U;
	RouteSwitchStruct* pRouteSwitchStru = NULL; 				/*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };  /*防护道岔数据*/

	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;
	/* 局部变量定义初始化 */
	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 switchCurPos = SWITCH_POSITION_INVALID;
	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	/*获取防护道岔数据*/
	routeProtectSwitchSum = GetLogRouteProSwData(logRouteId, routeProtectSwitchStru);


	if ((0u == logSectionSum) || (NULL == pLogIdBuff))
	{
		/*无逻辑区段，错误场景*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		for (ii = 0u; ii < logSectionSum; ii++)
		{
			lgcSecSwitchSum = GetLogicSecSwitchSum(pLogIdBuff[ii]);
			pLgcSecSwitchData = GetLogicSecSwitchIdStru(pLogIdBuff[ii]);
			if ((NULL != pLgcSecSwitchData)
				&& (lgcSecSwitchSum < LOGSEC_INCLUDE_SWITCH_SUM_MAX))
			{
				/*开始检查进路内道岔*/
				for (i = 0u; i < lgcSecSwitchSum; i++)
				{
					SwitchId = pLgcSecSwitchData[i].SwitchId;
					SwitchPos = pLgcSecSwitchData[i].SwitchPosition;
					switchCurPos = GetSwitchCurPosition(SwitchId);

					if ((switchCurPos == SwitchPos)
						&& ((SWITCH_POSITION_DINGWEI == SwitchPos)
							|| (SWITCH_POSITION_FANWEI == SwitchPos)))
					{


					}

					else
					{
						retVal = CI_ERROR;
					}

					if (CI_SUCCESS != retVal)
					{
						/*存在超时*/
						break;
					}
				}
			}
		}
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0u == routeProtectSwitchSum))
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查进路关联防护道岔*/
			for (i = 0u; i < routeProtectSwitchSum; i++)
			{
				SwitchId = routeProtectSwitchStru[i].ProtectSwitchId;
				SwitchPos = routeProtectSwitchStru[i].ProtectPosition;
				switchCurPos = GetSwitchCurPosition(SwitchId);

				if ((switchCurPos == SwitchPos)
					&& ((SWITCH_POSITION_DINGWEI == SwitchPos)
						|| (SWITCH_POSITION_FANWEI == SwitchPos)))
				{
					/*道岔位置一致*/
				}

				else
				{
					retVal = CI_ERROR;
				}

				if (CI_SUCCESS != retVal)
				{
					/*存在超时*/
					break;
				}
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
* 功能描述： 检查逻辑进路锁闭是否有道岔驱动超时
* 参数说明： const UINT16 wLogRouteId, 进路ID
* 返回值  ： UINT8
CI_SUCCESS:进路无道岔驱动超时
CI_ERROR:进路有道岔驱动超时
*/
UINT8 ChekLogRouteSwDrvOvTime(const UINT16 logRouteId)
{
	UINT8 retVal = CI_ERROR;

	UINT8 lgcSecSwitchSum = 0U;							/*逻辑区段关联道岔数量*/
	LogsecSwitchStruct* pLgcSecSwitchData = NULL;
	UINT8 ii = 0u;											/*循环变量*/
	RouteSwitchStruct* pRouteSwitchStru = NULL; 				/*道岔数据*/
	UINT8 routeProtectSwitchSum = 0u; 							/*防护道岔数目*/
	RouteProtectSwitchStruct routeProtectSwitchStru[ROUTE_PROTECTSWI_SUM_MAX] = { 0U };  /*防护道岔数据*/

	UINT16 logSectionSum = 0u; /*逻辑区段数*/
	UINT16* pLogIdBuff = NULL;

	UINT16 i = 0u;           /* 循环变量 */
	UINT16 SwitchId = 0u;
	UINT8  SwitchPos = SWITCH_POSITION_INVALID;
	UINT8 SwitchDrivOvtmDrvPos = SWITCH_DRIVE_POS_INVALID;

	/*获取进路包含逻辑区段信息*/
	logSectionSum = GetLogicalRouteInLogSecSum(logRouteId);
	pLogIdBuff = GetLogicalRouteInLogSecId(logRouteId);
	/*获取防护道岔数据*/
	routeProtectSwitchSum = GetLogRouteProSwData(logRouteId, routeProtectSwitchStru);


	if ((0u == logSectionSum) || (NULL == pLogIdBuff))
	{
		/*无逻辑区段，错误场景*/
		retVal = CI_ERROR;
	}
	else
	{
		retVal = CI_SUCCESS;
		for (ii = 0u; ii < logSectionSum; ii++)
		{
			lgcSecSwitchSum = GetLogicSecSwitchSum(pLogIdBuff[ii]);
			pLgcSecSwitchData = GetLogicSecSwitchIdStru(pLogIdBuff[ii]);
			if ((NULL != pLgcSecSwitchData)
				&& (lgcSecSwitchSum < LOGSEC_INCLUDE_SWITCH_SUM_MAX))
			{
				/*开始检查进路内道岔*/
				for (i = 0u; i < lgcSecSwitchSum; i++)
				{
					SwitchId = pLgcSecSwitchData[i].SwitchId;
					SwitchPos = pLgcSecSwitchData[i].SwitchPosition;
					SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

					if (SWITCH_POSITION_DINGWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
						}

					}
					else if (SWITCH_POSITION_FANWEI == SwitchPos)
					{
						/*道岔位置正确*/
						if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
						{
							retVal = CI_ERROR;
						}

					}
					else
					{
						/*数据配置错误*/
						retVal = CI_ERROR;
					}

					if (CI_SUCCESS != retVal)
					{
						/*存在超时*/
						break;
					}
				}
			}
		}
	}

	if (CI_SUCCESS == retVal)
	{
		if ((0u == routeProtectSwitchSum))
		{
			/*无检查项*/
			retVal = CI_SUCCESS;
		}
		else
		{
			/*开始检查进路关联防护道岔*/
			for (i = 0u; i < routeProtectSwitchSum; i++)
			{
				SwitchId = routeProtectSwitchStru[i].ProtectSwitchId;
				SwitchPos = routeProtectSwitchStru[i].ProtectPosition;
				SwitchDrivOvtmDrvPos = GetSwitchDrivOvtmDrvPosition(SwitchId);

				if (SWITCH_POSITION_DINGWEI == SwitchPos)
				{
					if (SWITCH_DRIVE_POS_DINGWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
					}

				}
				else if (SWITCH_POSITION_FANWEI == SwitchPos)
				{
					if (SWITCH_DRIVE_POS_FANWEI == SwitchDrivOvtmDrvPos)
					{
						retVal = CI_ERROR;
					}

				}
				else
				{
					/*数据配置错误*/
					retVal = CI_ERROR;
				}

				if (CI_SUCCESS != retVal)
				{
					/*存在超时*/
					break;
				}
			}
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/**
* @brief 区故解解锁逻辑进路
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogSecId 逻辑区段ID
* @return 无
* @note：by cgh 20231020
*/
void ErrLockFaultUnLockLogRoute(const UINT16 wLogSecId, const UINT16 wLogRouteId)
{
	UINT8 chLogRouteLogSecHaveUnLock = 0U;/*逻辑进路内方逻辑区段是否已经全部解锁*/
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数目*/
	LogSecLockBelLogRouteStruct szLogSecLockBelLogRouteData[LOGSEC_RELATE_ROUTE_SUM_MAX] = { 0U };
	UINT16 ii = 0U;
	UINT16 wLogSecBelLogRouteId = 0U;/*逻辑区段锁闭所属逻辑进路ID*/

	if ((0U < wLogSecId) && (LOGIC_SECTION_SUM_MAX > wLogSecId) && (0U < wLogRouteId) && (ROUTE_LOGICAL_SUM_MAX > wLogRouteId))
	{
		chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteBuf(wLogSecId, szLogSecLockBelLogRouteData);

		if (0U != chLogSecLockBelLogRouteSum)
		{
			for (ii = 0U; ii < chLogSecLockBelLogRouteSum; ii++)
			{
				wLogSecBelLogRouteId = szLogSecLockBelLogRouteData[ii].wLogSecLockBelLogRouteId;
				chLogRouteLogSecHaveUnLock = CheckLogRouteLogSecHaveUnLock(wLogSecBelLogRouteId);
				chLogRouteLogSecHaveUnLock &= DelLogSecBelongLogRouteId(wLogSecId, wLogSecBelLogRouteId);

				if (CI_SUCCESS == chLogRouteLogSecHaveUnLock)
				{
					/*逻辑进路对应的逻辑区段已经全部解锁，设置对应逻辑进路空闲*/
					SetLogRouteStateManage(wLogSecBelLogRouteId, ROUTE_LOGICAL_STATE_IDLE);
				}
				else
				{
					; /*不解锁*/
				}			
			}
		}
		else
		{
			; /*不执行*/
		}
	}
	else
	{
		; /*不处理*/
	}
}
/**
* @brief 逻辑进路脚下逻辑区段逻辑锁闭处理
* @param const UINT16 wLogRouteId 逻辑进路ID
* @param const UINT16 wLogSecId 逻辑区段ID
* @return CI_SUCCESS：处理逻辑进路脚下逻辑锁闭成功
*		  CI_ERROR：处理逻辑进路脚下逻辑锁闭失败
*/
UINT8 LogSecLockInLogRouteProcess(const UINT16 wLogRouteId,const UINT16 wLogSecId)
{
	UINT8 funcRet = CI_ERROR;
	UINT8 curLogLockState = 0u;  /*区段当前逻辑锁闭状态*/
	UINT8 validLogRouteIdBuf[ROUTE_LOGICAL_SUM_MAX] = { 0U };  /*需要处理有效逻辑进路ID*/
	UINT8 LogSecLockBelLogRouteSum = 0U;
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT8 ii = 0U;
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT8 validRouteSum = 0U;		/*处理冲掉的逻辑进路数量*/
	UINT16 validRouteId = 0u;		/*当前锁闭的进路*/
	UINT16 LogicalRouteInLogSecSum = 0U;
	UINT16* wLogicalRouteInLogSecIdBuf = NULL;
	UINT8 oldLogLockState = 0U;
	UINT8 retValue = CI_ERROR;
	UINT8 wLogrouteDir = 0u;

	curLogLockState = GetLogSecLogLockState(wLogSecId);
	LogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(wLogSecId);
	szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(wLogSecId);
	wLogrouteDir = GetLogicalRouteDir(wLogRouteId);
	if ((0U < LogSecLockBelLogRouteSum) && (NULL != szLogSecLockBelLogRouteData))
	{
		funcRet = CI_SUCCESS;
		if (LOG_SECTION_LOGLOCK_NORMAL == curLogLockState)
		{
			for (jj = 0U; jj < LogSecLockBelLogRouteSum; jj++)
			{
				if (wLogRouteId != szLogSecLockBelLogRouteData[jj].wLogSecLockBelLogRouteId)
				{
					validRouteId = szLogSecLockBelLogRouteData[jj].wLogSecLockBelLogRouteId;
					/*设置为当前逻辑进路的锁闭方向，列车资源维持*/
					SetLogSecLogLockState(wLogSecId, LOG_SECTION_LOGLOCK_NORMAL, wLogrouteDir);
					/*清除逻辑区段锁闭的所属进路*/
					funcRet = DelLogSecBelongLogRouteId(wLogSecId, validRouteId);

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

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

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

						for (kk = 0U; kk < LogicalRouteInLogSecSum; kk++)
						{
							oldLogLockState = GetLogSecLogLockState(wLogicalRouteInLogSecIdBuf[kk]);
							retValue = CheckLgcSecHaveTrainLocRoute(wLogRouteId, wLogicalRouteInLogSecIdBuf[kk]);
							if ((LOG_SECTION_LOGLOCK_NO != oldLogLockState) && (CI_ERROR == retValue))
							{
								break;  /*进路中还存在逻辑锁闭且不是车脚下的逻辑区段(车脚下已经分配给新的逻辑进路)，不可以将此进路置为空闲，需要最后车释放*/
							}
						}

						if (kk == LogicalRouteInLogSecSum)
						{
							/*逻辑进路中所有逻辑区段都已未锁闭，已经是逻辑进路的最后一个逻辑区段，设置该逻辑进路空闲，其余的等车释放*/
							(void)SetLogicalRouteState(validLogRouteIdBuf[ii], ROUTE_LOGICAL_STATE_IDLE);
						}
					}
				}
			}
		}
	}
	else
	{
		;	/*数据不合法，返回失败*/
	}

	return funcRet;
}

/*
* 功能描述： 找到逻辑进路内第一个逻辑锁闭的逻辑区段
* 参数说明： const UINT16 wLogRouteId 逻辑进路ID
* 返回值  ： = 0 无效
*            > 0 逻辑区段ID
* by cgh 20250529
*/
UINT16 GetLogRouteFirLogLockLogId(const UINT16 wLogRouteId)
{
	UINT16 wLogRouteLogSecNum = 0U;/*逻辑进路包含的逻辑区段数量*/
	UINT16* pLogRouteLogSecIdBuf = NULL;/*逻辑进路包含的逻辑区段ID*/
	UINT16 ii = 0U;
	UINT16 wReVal = CI_ERROR;
	UINT8 chCheckFlag = 0U;/*检查标志*/
	UINT8 chLogSecLogLockSta = 0U;/*逻辑区段逻辑锁闭状态*/

	if (ROUTE_LOGICAL_SUM_MAX > wLogRouteId)
	{
		/*获取逻辑进路逻辑区段数据*/
		wLogRouteLogSecNum = GetLogicalRouteInLogSecSum(wLogRouteId);
		pLogRouteLogSecIdBuf = GetLogicalRouteInLogSecId(wLogRouteId);

		if (NULL != pLogRouteLogSecIdBuf)
		{
			for (ii = 0U; ii < wLogRouteLogSecNum; ii++)
			{
				chCheckFlag = CheckLogSecLockBelLogRoute(pLogRouteLogSecIdBuf[ii], wLogRouteId);
				if (CI_SUCCESS == chCheckFlag)
				{
					wReVal = pLogRouteLogSecIdBuf[ii];
					break;
				}
				else
				{
					;/*继续查找下一个*/
				}
			}
		}
		else
		{
			; /*不执行*/
		}
	}
	else
	{
		; /*不执行*/
	}


	return wReVal;

}