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

#include "AxisSectionDataManage.h"


AxisSectionDataStruct AxisSectionDataStru[AXIS_SECTION_SUM_MAX] = { 0 };   /*定义计轴区段数据结构体*/

/*
* 功能描述： 获取计轴区段数据
* 参数说明：    
* 返回值  ： 
            AxisSectionDataStruct*
*/
AxisSectionDataStruct *GetAxisSecData(void)
{
    return AxisSectionDataStru;
}
/*
* 功能描述： 获取指定ID计轴区段所属联锁ID
* 参数说明： const UINT16 axisSectionId, 计轴区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 所属联锁ID      
*/
UINT8 GetAxisSectionBelongCiId(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;
	
	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取区段数组下标*/
	
	if (bufIndex < AXIS_SECTION_SUM_MAX)
	{
		retVal = AxisSectionDataStru[bufIndex].BelongCiId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

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

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

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


/*
* 功能描述： 设置指定ID计轴区段ARB状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 arbState, ARB状态
* 返回值  ： 无
*			      
*/
void SetAxisSecArbState(const UINT16 axisSectionId, const UINT8 arbState)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

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

	if (bufIndex < AXIS_SECTION_SUM_MAX)
	{
		if ((AXIS_SECTION_ARB_NO == arbState) || (AXIS_SECTION_ARB_YES == arbState))
		{
			AxisSectionDataStru[bufIndex].AxisArbState = arbState;  /*计轴区段ARB状态*/
			SetAxisIncludeLogSecArbState(axisSectionId,arbState);/*设置计轴区段包含的逻辑区段ARB状态*/
			SetAxisRelatePhySecArbState(axisSectionId, arbState);/*设置计轴区段关联的物理区段ARB状态*/
		}
		else
		{
			; /*不设置*/
		}
	}
	else
	{
		; /*不设置*/
	}
}

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

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

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

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


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

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取道岔数组下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		if ((AXIS_SECTION_JUMPLOCK_APPLY_NO == jumpLockApplyFlag) || (AXIS_SECTION_JUMPLOCK_APPLY_YES == jumpLockApplyFlag))
		{
			AxisSectionDataStru[bufIndex].AxisJumpLockApplyFlag = jumpLockApplyFlag;  /*计轴区段跳跃锁闭申请标志*/
		}
		else
		{
			/*不做处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*-----分隔符------*/

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

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

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


/*
* 功能描述： 设置指定ID计轴区段跳跃锁闭取消申请标志
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 jumpLockCancelApplyFlag, 跳跃锁闭取消申请标志
* 返回值  ： 0: 设置失败
*			 1: 设置成功      
*/
UINT8 SetAxisSecJLockCancelApplyFlag(const UINT16 axisSectionId, const UINT8 jumpLockCancelApplyFlag)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取道岔数组下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		if ((AXSEC_CANCEL_JUMPLOCK_APPLY_NO == jumpLockCancelApplyFlag) || 
			(AXSEC_CANCEL_JUMPLOCK_APPLY_YES == jumpLockCancelApplyFlag))
		{
			AxisSectionDataStru[bufIndex].AxisJumpLockCancelApplyFlag = jumpLockCancelApplyFlag;  /*计轴区段跳跃锁闭取消申请标志*/

			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*-----分隔符------*/

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

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

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


/*
* 功能描述： 设置指定ID计轴区段跳跃锁闭取消申请标志
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 jumpLockApplyCycle, 跳跃锁闭申请周期号
* 返回值  ： 0: 设置失败
*			 1: 设置成功      
*/
UINT8 SetAxisSecJumpLockApplyCylce(const UINT16 axisSectionId, const UINT32 jumpLockApplyCycle)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取道岔数组下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		AxisSectionDataStru[bufIndex].AxisJumpLockApplyCylce = jumpLockApplyCycle;  /*计轴区段跳跃锁闭取消申请标志*/

		retVal = CI_SUCCESS;
		
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*-----分隔符------*/

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

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

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


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

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取道岔数组下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		if ((AXIS_SECTION_JUMPLOCK_STATE_IDLE == jumpLockState) ||
			(AXIS_SECTION_JUMPLOCK_STATE_XUANPAI == jumpLockState) ||
			(AXIS_SECTION_JUMPLOCK_STATE_LOCK == jumpLockState) )
		{/*跳跃锁闭状态为空闲、选排、锁闭*/
			AxisSectionDataStru[bufIndex].AxisJumpLockState = jumpLockState;  /*跳跃锁闭状态*/
		}
		else
		{
		}
	}
	else
	{
		/*不做处理*/
	}
}
/*
* 功能描述： 获取指定ID计轴区段所属虚拟联锁ID
* 参数说明： const UINT16 axisSectionId, 计轴区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 所属虚拟联锁ID      
*/
UINT8 GetAxisSectionBelongVirCiId(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

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

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


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


/*
* 功能描述： 获取指定ID计轴区段占用状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID    
* 返回值  ： AXIS_SECTION_OCCUPY_NO: 未占用
*			AXIS_SECTION_OCCUPY_YES: 占用      
*/
UINT8 GetAxisOccupyState(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = AXIS_SECTION_OCCUPY_YES;

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

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		retVal = AxisSectionDataStru[bufIndex].AxisOccStatus;
	}
	else
	{
		retVal = AXIS_SECTION_OCCUPY_YES;
	}
	return retVal;
}

/*
* 功能描述： 设置指定ID计轴区段占用状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 occupyState, 占用状态
* 返回值  ： 无
*			        
*/
void SetAxisOccupyState(const UINT16 axisSectionId, const UINT8 occupyState)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT32 dwCycNum = 0U;/*计轴占用起始周期*/

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);  /*获取道岔数组下标*/
	dwCycNum = Get2oo2CurCycleNum();

	if (AXIS_SECTION_SUM_MAX > bufIndex )
	{
		if ((AXIS_SECTION_OCCUPY_YES == occupyState) ||
			(AXIS_SECTION_OCCUPY_NO == occupyState))
		{
			AxisSectionDataStru[bufIndex].AxisOccStatus = occupyState;  /*占用空闲状态*/

			if (AXIS_SECTION_OCCUPY_YES == occupyState)
			{
				if (0U == AxisSectionDataStru[bufIndex].dwAxisOccCycNum)
				{
					AxisSectionDataStru[bufIndex].dwAxisOccCycNum = dwCycNum;
				}
				else
				{
					; /*不等于0说明已经设置过*/
				}
			}
			else
			{
				AxisSectionDataStru[bufIndex].dwAxisOccCycNum = 0U;
			}
		}
		else
		{

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

/**
* @brief 获取计轴区段锁闭所属进路ID
* @param 计轴区段ID
* @return 计轴区段锁闭所属进路ID，0:未锁闭
*/
UINT16 GetAxisSecLockBelongRoute(const UINT16 wAcId)
{
	UINT16 wPhyId = 0u;
	UINT16 wRouteId = 0u;
	wPhyId = GetAxisSecRelativePhySecId(wAcId);
	wRouteId = GetPhySecRLockBelongRouteId(wPhyId);
	return wRouteId;
}

/*
* 功能描述： 设置指定ID计轴区段包含的逻辑区段跳跃锁闭状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 jumpLockState, 跳跃锁闭状态
* 返回值  ： void
* 备注：仅用于给ATS发码位显示，不参与逻辑检查,by-cgh-2023.06.28
*/
void SetAxisInCludeLogJumpLockState(const UINT16 axisSectionId, const UINT8 jumpLockState)
{
	UINT16* pLogSectionIdBuf = NULL;
	UINT8 chLogSectionSum = 0U;
	UINT8 ii = 0U;

	pLogSectionIdBuf = GetAxisSecLogSectionIdBuf(axisSectionId);
	chLogSectionSum = GetAxisSecLogSectionSum(axisSectionId);

	if (NULL != pLogSectionIdBuf)
	{
		for (ii = 0U; ii < chLogSectionSum; ii++)
		{
			if ((LOGIC_SECTION_JUMP_LOCK_NO == jumpLockState) || (LOGIC_SECTION_JUMP_LOCK_YES == jumpLockState))
			{
				SetLogSecJumpLockState(pLogSectionIdBuf[ii], jumpLockState);
			}
		}
	}
}

/*
* 功能描述： 设置指定计轴区段包含的逻辑区段ARB状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 chState,ARB状态
* 返回值  ： void
* 备注：by-cgh-2023.09.05
*/
void SetAxisIncludeLogSecArbState(const UINT16 wAxisSectionId, const UINT8 chState)
{
	UINT16* pLogSectionIdBuf = NULL;/*计轴区段包含逻辑区段ID*/
	UINT8 chLogSectionSum = 0U;/*计轴区段包含逻辑区段数目*/
	UINT8 ii = 0U;

	pLogSectionIdBuf = GetAxisSecLogSectionIdBuf(wAxisSectionId);
	chLogSectionSum = GetAxisSecLogSectionSum(wAxisSectionId);

	if (NULL != pLogSectionIdBuf)
	{
		for (ii = 0U; ii < chLogSectionSum; ii++)
		{
			if ((LGC_SECTION_ARB_NO == chState) || (LGC_SECTION_ARB_YES == chState))
			{
				SetLgcArbState(pLogSectionIdBuf[ii], chState);
			}
		}
	}
}

/*
* 功能描述： 设置指定计轴区段关联的物理区段ARB状态
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
*			 const UINT8 chState,ARB状态
* 返回值  ： void
* 备注：by-cgh-2023.09.05
*/
void SetAxisRelatePhySecArbState(const UINT16 wAxisSectionId, const UINT8 chState)
{
	UINT16 wAxisRelatePhySecId = 0U;/*计轴区段关联的物理区段ID*/
	UINT8 ii = 0U;
	UINT16* pAxisSecIdBuf = NULL;/*计轴区段关联物理区段包含的计轴区段ID*/
	UINT8 chAxisSecSum = 0U;/*计轴区段关联物理区段包含的计轴区段数目*/
	UINT8 chAxisArbState = 0U;/*计轴区段ARB状态*/

	wAxisRelatePhySecId = GetAxisSecRelativePhySecId(wAxisSectionId);

	if (AXIS_SECTION_ARB_YES == chState)
	{
		SetPhySecArbState(wAxisRelatePhySecId, chState);/*任意一个计轴区段设置ARB则物理区段设置ARB状态*/
	}
	else
	{
		/*设置非ARB则需要检查物理区段内所有的计轴区段都处于非ARB状态*/
		pAxisSecIdBuf = GetPAxisSectionIdBuf(wAxisRelatePhySecId);
		chAxisSecSum = GetPAxisSectionSum(wAxisRelatePhySecId);

		if (NULL != pAxisSecIdBuf)
		{
			for (ii = 0U; ii < chAxisSecSum; ii++)
			{
				chAxisArbState = GetAxisSecArbState(pAxisSecIdBuf[ii]);
				if (AXIS_SECTION_ARB_YES == chAxisArbState)
				{
					break;
				}
			}
			if (ii == chAxisSecSum)
			{
				SetPhySecArbState(wAxisRelatePhySecId, chState);/*设置物理区段ARB状态*/
			}
		}
	}
}

/*
* 功能描述： 获取指定ID计轴区段占用起始周期号
* 参数说明： const UINT16 axisSectionId, 计轴区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 占用起始周期号
* by cgh 20240815
*/
UINT32 GetAxisSecOccCyc(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT32 retVal = CI_ERROR;

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

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

/*
* 功能描述：设置指定ID计轴区段位置监督有效的列车ID
* 参数说明：const UINT16 wAxisSectionId 计轴区段ID
*			const UINT16 wTrainId 列车ID
* 返 回 值：无
* Created By LQ 2024.08.18
*/
void SetAxisPosMonitorTrainId(const UINT16 wAxisSectionId, const UINT16 wTrainId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetAxisSecConfigBufIndex(wAxisSectionId);  /*获取计轴区段索引下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		if (TRAIN_SUM_MAX > (wTrainId & 0x00FFU))
		{
			AxisSectionDataStru[bufIndex].wPosMonitorTrainId = wTrainId;
		}
		else
		{
			/*ID非法，不处理*/
		}
	}
	else
	{
		/*入参检查失败，不处理*/
	}
}

/*
* 功能描述：获取指定ID计轴区段位置监督有效的列车ID
* 参数说明：const UINT16 wAxisSectionId 计轴区段ID
* 返 回 值：255 获取失败
*           <255 列车ID
* Created By LQ 2024.08.18
*/
UINT16 GetAxisPosMonitorTrainId(const UINT16 wAxisSectionId)
{
	UINT16 wRetVal = TRAIN_SUM_MAX;
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetAxisSecConfigBufIndex(wAxisSectionId);  /*获取计轴区段索引下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		wRetVal = AxisSectionDataStru[bufIndex].wPosMonitorTrainId;
	}
	else
	{
		/*入参检查失败，返回255*/
	}

	return wRetVal;
}

/*
* 功能描述：获取指定ID计轴区段最近坏车占用周期号
* 参数说明：const UINT16 wAxisSectionId 计轴区段ID
* 返 回 值：UINT32_MAX 获取失败 其他：最近坏车占用周期号
* Created By fan 2024.08.19
*/
UINT32 GetAxisRecentUtOccupyCyc(const UINT16 wAxisSectionId)
{
	UINT32 wRetVal = UINT32_MAX;
	UINT16 bufIndex = 0u;  /*数组下标*/

	bufIndex = GetAxisSecConfigBufIndex(wAxisSectionId);  /*获取计轴区段索引下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		wRetVal = AxisSectionDataStru[bufIndex].dwUtOccupyCycNum;
	}
	else
	{
		/*入参检查失败，返回UINT32_MAX*/
	}

	return wRetVal;
}

/*
* 功能描述：设置指定ID计轴区段最近坏车占用周期号
* 参数说明：const UINT16 wAxisSectionId 计轴区段ID UINT32 周期号
* 返 回 值：无
* Created By fan 2024.08.19
*/
void SetAxisRecentUtOccupyCyc(const UINT16 wAxisSectionId, const UINT32 dwCycNum)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetAxisSecConfigBufIndex(wAxisSectionId);  /*获取计轴区段索引下标*/

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		AxisSectionDataStru[bufIndex].dwUtOccupyCycNum = dwCycNum;
	}
	else
	{
		; /*获取失败不处理*/
	}
}
/**
* 功能：查询更新计轴上坏车占用状态
* 输入参数：无
* 返回值：无
* Create:  fan 2024/08/20
*/
void AxisSecUtOccpyUpdate(void)
{
	UINT16 i = 0u;
	UINT16 wPhyNum = 0u;
	UINT8 chLocalCiId = 0u;/*本联锁id*/
	UINT8 chPhyCiId = 0u; /*物理区段所属Ci*/
	UINT16 wPhyId = 0u; /*物理区段id*/
	UINT16 wAxisSecId = 0U; /*计轴区段id*/
	UINT8 phySecContainAxisSecSum; /*物理区段关联计轴区段数量*/
	UINT16* phySecContainAxisSecIdBuf = NULL; /*物理区段关联计轴数组*/
	UINT8 linkNum = 0U; /*ilnk数量*/
	UINT16* pLinkBuf = NULL; /*link数组*/
	UINT8 j = 0U;
	UINT8 jj = 0U;
	UINT8 k = 0U;
	UINT8 chOccState = 0U; /*物理区段占用标志*/
	UINT8 chUtOccupyFlag = CI_ERROR; /*是否更新计轴Ut占用 ERROR需更新*/
	UINT8 cLinkIncTrainSum = 0u; /*link列车数量*/
	TRAIN_SEQUANCE_s linkInctrainList[SIZE_MAX_TRAINOFAC] = { 0u };  /*link上的列车序列*/
	UINT8 isUseNvram = TRAIN_NVRAM_POS_FLAG_YES;
	UINT32 dwCurCyc = Get2oo2CurCycleNum(); /*当前周期号*/
	chLocalCiId = GetSystemParaLocalCiId();
	wPhyNum = GetPhySecCurSum();
	for (i = 0u; i < wPhyNum; i++)
	{
		/* 遍历物理区段 */		
		wPhyId = GetPhySecId(i);
		chPhyCiId = GetPhySecBelongCiId(wPhyId);
		chOccState = GetPhySecCurOccupyState(wPhyId);
		/* 仅更新本TIOC控区上有车占用的物理区段 */
		if ((chLocalCiId == chPhyCiId) &&(SECTION_OCCUPY_YES == chOccState))
		{
			phySecContainAxisSecSum = GetPAxisSectionSum(wPhyId);
			phySecContainAxisSecIdBuf = GetPAxisSectionIdBuf(wPhyId);

			if ((0u != phySecContainAxisSecSum) && (NULL != phySecContainAxisSecIdBuf))
			{
				for (j = 0u; j < phySecContainAxisSecSum; j++)
				{
					/*检查计轴上link有无坏车*/
					wAxisSecId = phySecContainAxisSecIdBuf[j];
					linkNum = GetAxisLinkSum(wAxisSecId);
					pLinkBuf = GetAxisLinkIdBuf(wAxisSecId);
					if ((0U != linkNum) && (NULL != pLinkBuf))
					{
						chUtOccupyFlag = CI_SUCCESS;
						for (jj = 0; jj < linkNum; jj++)
						{
							cLinkIncTrainSum = as_GetLinkTrainList(pLinkBuf[jj], linkInctrainList, SIZE_MAX_TRAINOFAC);
							for (k = 0U; k < cLinkIncTrainSum; k++)
							{
								
								if (NAME_FAILUREAREA != linkInctrainList[k].u16TrainID)
								{
									/*非故障 继续检查*/
									/*fan0824 Nvram车也设置坏车占用*/
									isUseNvram = GetTrainNvramPosFlag(linkInctrainList[k].u16TrainID);
									if (TRAIN_NVRAM_POS_FLAG_NO != isUseNvram)
									{
										chUtOccupyFlag = CI_ERROR;    /*Nvram车，停止检查。返回失败*/
										break;
									}
									else
									{
										; /*继续检查*/
									}
								}
								else
								{
									chUtOccupyFlag = CI_ERROR;    /*存在故障车，停止检查。返回失败*/
									break;
								}

							}


						}
					}
					else
					{
						/*获取失败 更新*/
						chUtOccupyFlag = CI_ERROR;
					}

					/*有坏车则更新计轴最近坏车占用周期*/
					if (CI_ERROR == chUtOccupyFlag)
					{
						SetAxisRecentUtOccupyCyc(wAxisSecId, dwCurCyc);
					}
					else
					{
						;/*不更新最近坏车周期*/
					}
				}
			}
		}
		else
		{
			; /*由相邻联锁设置*/
		}
	}
}

/*
* 功能描述：获取指定ID计轴区段列车安全位置覆盖标志
* 参数说明：const UINT16 axisSectionId 计轴区段ID
* 返 回 值：0x55 无效
*			0xAA 有效
* Created By LQ 2025.12.01
*/
UINT8 GetAxisTXSafeLocFlag(const UINT16 axisSectionId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT8 retVal = AXIS_SECTION_SAFELOC_NO;

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

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		retVal = AxisSectionDataStru[bufIndex].cAxisTXSafeLocFlag;
	}
	else
	{
		retVal = AXIS_SECTION_SAFELOC_NO;
	}

	return retVal;
}

/*
* 功能描述：设置指定ID计轴区段列车安全位置覆盖标志
* 参数说明：const UINT16 axisSectionId 计轴区段ID
*			const UINT8 cFlag 标志
* 返 回 值：无
* Created By LQ 2025.12.01
*/
void SetAxisTXSafeLocFlag(const UINT16 axisSectionId, const UINT8 cFlag)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetAxisSecConfigBufIndex(axisSectionId);

	if (AXIS_SECTION_SUM_MAX > bufIndex)
	{
		if ((AXIS_SECTION_SAFELOC_NO == cFlag) || (AXIS_SECTION_SAFELOC_YES == cFlag))
		{
			AxisSectionDataStru[bufIndex].cAxisTXSafeLocFlag = cFlag;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不做处理*/
	}
}

/*
* 功能描述：清除计轴区段列车安全位置覆盖标志
* 参数说明：无
* 返 回 值：无
* Created By LQ 2025.12.01
*/
void ClearAxisTXSafeLocFlag(void)
{
	UINT16 aAxisSecDataSum = 0U;  /*计轴区段总数*/
	UINT16 wAxisSecId = 0U;  /*计轴区段ID*/
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT16 ii = 0U;

	aAxisSecDataSum = GetTotalAxisCurNum();

	for (ii = 0U; ii < aAxisSecDataSum; ii++)
	{
		wAxisSecId = GetAxisSecId(ii);
		bufIndex = GetAxisSecConfigBufIndex(wAxisSecId);
		if (AXIS_SECTION_SUM_MAX > bufIndex)
		{
			AxisSectionDataStru[wAxisSecId].cAxisTXSafeLocFlag = AXIS_SECTION_SAFELOC_NO;  /*重置计轴区段无通信车安全位置覆盖标志无效*/
		}
		else
		{
			/*ID非法，不处理*/
		}
	}
}

/*
* 功能描述：获取存在计轴道岔位置是否满足（四开视为满足）
* 参数说明：UINT16 wAcId 计轴区段
* 返回值  ：CI_ERROR  CI_SUCCESS满足 
* Create fan 20260410
*/
UINT8 GetAcSwitchPosCheck(UINT16 wAcId)
{
	AxisSwitchStruct* axisSwitchStru = NULL;
	UINT8 axisSwitchSum = 0U;/*计轴条件道岔数量*/
	UINT8 jj = 0U;
	UINT8 retValue = CI_SUCCESS;/*本函数检查ARB使用 成功时需要检查未安全侧*/
	UINT8 switchCurPosition = 0U;/*道岔位置*/
	axisSwitchStru = GetAxisSwitchIdStru(wAcId);
	axisSwitchSum = GetAxisSwitchSum(wAcId);
	if (NULL != axisSwitchStru)
	{
		for (jj = 0U; jj < axisSwitchSum; jj++)
		{
			switchCurPosition = GetSwitchCurPosition(axisSwitchStru[jj].SwitchId);	/*获取道岔当前位置*/
																					/*四开时保留可达性*/
			if (((SWITCH_POSITION_FANWEI == switchCurPosition) || (SWITCH_POSITION_DINGWEI == switchCurPosition))
				&& (axisSwitchStru[jj].SwitchPosition != switchCurPosition))
			{
				retValue = CI_ERROR;
				break;
			}
			else
			{
				/*四开或道岔位置满足*/
				/*计轴关联多个道岔时需所有道岔满足*/
			}
		}
	}
	else
	{
		;
	}
	return retValue;
}