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

#include "PhysicalSectionConfigDataManage.h"
#include "AxisSectionConfigDataManage.h"



PhysicalSectionConfigDataStruct PhysicalSectionConfigDataStru[PHYSICAL_SECTION_SUM_MAX];   /*定义物理区段数据配置结构体,cgh-合并CID-2539-1：此处声明不进行初始化，统一放到InitAllStaticDataStr函数中进行初始化，为解决生成内核过大得问题*/
UINT16 LocalCiPhysicalSectionIdBuf[PHYSICAL_SECTION_SUM_MAX] = {0u};                   /*定义本地联锁物理区段ID映射数组*/
INT16 PhysicalSectionCurSum = 0;   /*物理区段当前总数*/
UINT16 totalPhysicalSectionNum = 0u;/*本联锁和相邻联锁发送给本联锁物理区段总数*/


/*
* 功能描述： 获取指定ID物理区段索引号
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： PHYSICAL_SECTION_SUM_MAX: 获取数据失败
*			<PHYSICAL_SECTION_SUM_MAX: 查找成功
*/
UINT16 GetPhySecConfigBufIndex(const UINT16 phySectionId)
{
	UINT16 retVal = PHYSICAL_SECTION_SUM_MAX;
	if((phySectionId >= 1u) && (phySectionId < PHYSICAL_SECTION_SUM_MAX))
    {
        retVal = phySectionId;
    }
	else
	{
		;
	}

	return retVal;
}


/*
* 功能描述： 获取物理区段当前总数
* 参数说明： void    
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段当前总数
*/
UINT16 GetPhySecCurSum(void)
{
	UINT16 retVal = 0u;
    if (PhysicalSectionCurSum >= (INT16)PHYSICAL_SECTION_SUM_MAX )
    {
        retVal = PHYSICAL_SECTION_SUM_MAX;
    }
	else if (PhysicalSectionCurSum < 0)
	{
		retVal = 0u;
	}
    else
    {/*在[0,PHYSICAL_SECTION_SUM_MAX)区间强转，保证安全*/
        retVal = (UINT16)PhysicalSectionCurSum;
    }
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段数据
* 参数说明：  
* 返回值  ： 
			PhysicalSectionConfigDataStruct*      
*/
PhysicalSectionConfigDataStruct* GetPhySecConfigData(void)
{
    return PhysicalSectionConfigDataStru;
}

/*
* 功能描述： 获取指定数组下标对应的物理区段ID
* 参数说明： const UINT16 bufIndex, 数组下标    
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段ID      
*/
UINT16 GetPhySecId(const UINT16 bufIndex)
{
	UINT16 retVal = CI_ERROR;
	UINT16 phySecTotalNum = GetTotalPhySecCurNum();
	if (bufIndex < phySecTotalNum)
	{
		retVal = LocalCiPhysicalSectionIdBuf[bufIndex];
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段所属联锁ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 所属联锁ID      
*/
UINT8 GetPhySecBelongCiId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].BelongCiId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段类型
* 参数说明： const UINT16 phySectionId, 区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段类型      
*/
UINT8 GetPhySecType(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal  = CI_ERROR;


	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].PhySecType;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段列检库区段标志
* 参数说明： const UINT16 phySectionId, 区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 列检库区段标志      
*/
UINT8 GetPhySecLjkFlag(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].LjkSecFlag;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段牵出线区段标志
* 参数说明： const UINT16 phySectionId, 区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 牵出线区段标志：0x55非牵出线 0xAA牵出线区段
* Create fan 20260415
*/
UINT8 GetPhySecQcxFlag(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].QcxSecFlag;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段轨道继电器ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 轨道继电器ID      
*/
UINT16 GetPhySecGdRelayId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].GdRelayId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段轨道继电器ID2
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 轨道继电器ID
*/
UINT16 GetPhySecGdRelayId2(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].wGdRelayId2;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述： 获取指定ID物理区段复位继电器ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 复位继电器ID      
*/
UINT16 GetPhySecFWRelayId(const UINT16 phySectionId)
{

    UINT16 bufIndex = 0u;  /*数组下标*/
    UINT16 retVal = CI_ERROR;
    
    bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/
    
    if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
    {
        retVal = PhysicalSectionConfigDataStru[bufIndex].FWRelayId;
    }
    else
    {
        retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述：	整理读入的物理区段配置数据
* 参数说明：	无
* 返回值  ：	CI_SUCCESS,整理成功
*				CI_ERROR,整理失败
*/
UINT8 PhySectionConfigDataManage(void)
{
    UINT16 ii = 0u;      /*游标*/
    UINT16 jj = 0u;      /*游标*/
    UINT16 phySectionConfigDataSum = 0u;      /*物理区段设备配置数据总数*/
	UINT8 retVal = CI_SUCCESS;

    /*保存物理区段ID索引数组*/
    phySectionConfigDataSum = GetPhySecCurSum();
	totalPhysicalSectionNum = phySectionConfigDataSum;
    if (phySectionConfigDataSum >= PHYSICAL_SECTION_SUM_MAX)
    {/*配置数据总数错误*/
        
        retVal = CI_ERROR;
	}
	else
	{
		for (ii = 0u; ii < PHYSICAL_SECTION_SUM_MAX; ii++)
		{
			if (jj == phySectionConfigDataSum)
			{/*遍历有效数据完毕*/

				break;
			}

			if (PhysicalSectionConfigDataStru[ii].BelongCiId == GetSystemParaLocalCiId())
			{/*该部分为有效数据*/
				LocalCiPhysicalSectionIdBuf[jj] = PhysicalSectionConfigDataStru[ii].PhysicalSectionId;
				jj++; 
			}


		}
	}

    return retVal;
}

/*
* 功能描述： 获取指定物理区段SPKS的开关数
* 参数说明： phySecId
* 返回值  ： spks数量
*/
UINT8 GetPhySecSpksSum(UINT16 phySecId)
{
	UINT8 spksNum = 0u; 
	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		spksNum = PhysicalSectionConfigDataStru[bufIndex].spksNum;
	}
	
	return spksNum;
}

/*
* 功能描述： 获取指定物理区段 指定下表的SPKS的ID
* 参数说明： phySecId，物理区段
*			 spksIdIdx Spks下标
* 返回值  ： >0 spksId 0 :出错
*/
UINT16 GetPhySecSpksIdBySpksIdx(UINT16 phySecId,UINT16 idx)
{
	UINT8 spksNum = 0u; 
	UINT16 spksId = 0u;
	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		spksNum = PhysicalSectionConfigDataStru[bufIndex].spksNum;
	}
	if (idx < spksNum)
	{
		spksId = PhysicalSectionConfigDataStru[bufIndex].spksIdBuff[idx];
	}

	return spksId;
}

/*
* 功能描述： 获取以指定物理区段为外方第一物理区段的信号机数目
* 参数说明： phySecId
* 返回值  ： 信号机数量
*/
UINT8 GetPhySecAsOutFirstPhySecSigSum(UINT16 phySecId)
{
	UINT8 sigNum = 0u; 
	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		sigNum = PhysicalSectionConfigDataStru[bufIndex].relateOutStationSignalNum;
	}

	return sigNum;
}

/*
* 功能描述： 获取以指定物理区段为外方第一物理区段的信号机ID
* 参数说明： phySecId，物理区段
*			 idx， 信号机下标
* 返回值  ： >0 sigId 0 :出错
*/
UINT16 GetPhySecAsOutFstPhySecSigId(UINT16 phySecId,UINT16 idx)
{
	UINT8 sigNum = 0u; 
	UINT16 sigId = 0u;
	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		sigNum = PhysicalSectionConfigDataStru[bufIndex].relateOutStationSignalNum;
		if (idx < sigNum)
		{
			sigId = PhysicalSectionConfigDataStru[bufIndex].relateOutStationSignalIdBuff[idx];
		}
	}
	
	return sigId;
}

/*
* 功能描述：	整理读入的相邻联锁物理区段配置数据
* 参数说明：	phySecSum 物理区段数量
*				phySecIdBuff 相邻联锁发送给本联锁的物理区段ID配置数据
* 返回值  ：	1,整理成功
*				0,整理失败
*/
UINT8 AddExtendPhySecIdDataManage(UINT16 phySecSum,const UINT16 *phySecIdBuff)
{
	UINT16  index = 0u;  /*数组下标*/
	UINT16  ii = 0u;
	UINT8 retVal = 1u;

	if ((totalPhysicalSectionNum + phySecSum) >= PHYSICAL_SECTION_SUM_MAX)
	{/*入口防护*/
		retVal = 0u;
	}
	else
	{
		index = totalPhysicalSectionNum;
		totalPhysicalSectionNum += phySecSum;
		for(ii = 0u;ii< phySecSum;ii++)
		{
			LocalCiPhysicalSectionIdBuf[index+ii] = phySecIdBuff[ii];/*追加到LocalCiPhysicalSectionIdBuf*/
		}
	}

	return retVal;
}

/*
* 功能描述： 获取相邻联锁发送给本联锁以及本联锁物理区段当前总数
* 参数说明： void    
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段当前总数
*/
UINT16 GetTotalPhySecCurNum(void)
{
	UINT16 retVal  = 0u;
	if (totalPhysicalSectionNum > PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = 0u;
	}
	else
	{
		retVal = totalPhysicalSectionNum;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID轨道区段所属的物理区段ID
* 参数说明： const UINT16 trackSectionId, 轨道区段ID
* 返回值  ： ERROR: 获取数据失败
*			>0: 物理区段ID
*/
UINT16 GetTrackToPhySectionId(const UINT32 trackSectionId)
{
	UINT16 i=0u;
	UINT16 j=0u;
	UINT16 phySec = 0u;
	UINT8 foundFlag = 0u;
	for (i = 0u;i<PHYSICAL_SECTION_SUM_MAX;i++)
	{
		for (j = 0u;j<PhysicalSectionConfigDataStru[i].trackSecNum;j++)
		{
			if (trackSectionId==PhysicalSectionConfigDataStru[i].trackSecBuf[j])
			{
				phySec=PhysicalSectionConfigDataStru[i].PhysicalSectionId;
				foundFlag = 1u;
				break;
			}
		}
		if (1u == foundFlag)
		{
			break;
		}
	}
	return phySec;
}

/*
* 功能描述： 获取指定物理区段保护锁闭时可能对应的进路ID数组
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ：
指定物理区段保护锁闭时可能对应的进路ID数组
*/
UINT16* GetPhySecProLockRouteIdBuf(const UINT16 phySecId)
{
	UINT16* retBuf = NULL;

	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retBuf = PhysicalSectionConfigDataStru[bufIndex].proLockRouteIdBuf;
	}

	return retBuf;
}
/*
* 功能描述： 获取指定物理区段保护锁闭时可能对应的进路ID数量
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ：
指定物理区段保护锁闭时可能对应的进路ID数量
*/
UINT8 GetPhySecProLockRouteSum(const UINT16 phySecId)
{
	UINT8 routeSum = 0u;

	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		routeSum = PhysicalSectionConfigDataStru[bufIndex].proLockRouteSum;
	}

	return routeSum;
}

/*
* 功能描述： 获取指定ID物理区段总复位继电器ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 总复位继电器ID      
*/
UINT16 GetPhySecZFWRelayId(const UINT16 phySectionId)
{

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

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].ZFWRelayId;	/*获取总复位继电器ID并返回*/
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段是否属于ZC管辖区域标志
* 参数说明： const UINT16 phySectionId, 区段ID    
* 返回值  ： 0: 获取数据失败
*			0x55: 物理区段属于ZC管辖区域 
*			0xAA: 物理区段不属于ZC管辖区域
*/
UINT8 GetPhySecManagedByZcFlag(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].managedByZcFlag;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID包含计轴区段数目
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 征用状态      
*/
UINT8 GetPAxisSectionSum(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].AxisSectionSum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段包含计轴区段数组
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 计轴区段ID数组指针  
*/
UINT16* GetPAxisSectionIdBuf(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 * retVal = NULL;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].AxisSectionIdBuf;
	}
	else
	{
		retVal = NULL;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段侵限物理区段数目
* 参数说明： const UINT16 phySectionId, 物理区段ID      
* 返回值  ： 0: 获取数据失败
*			>0: 侵限物理区段数目
*/
UINT8 GetSecIntrudePhySectionSum(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取进路数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].SecInvSecAndConSwiSum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}


/*
* 功能描述： 获取指定ID物理区段侵限区段数组
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： NULL: 获取数据失败
*			!NULL: 侵限物理区段结构指针
*/
UINT16* GetSecIntrudePhySectionData(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16* retVal = NULL;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取进路数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].SecInvSecAndConSwiId;
	}
	else
	{
		retVal = NULL;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段计轴预复位状态继电器ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 计轴预复位状态继电器ID      
*/
UINT16 GetPhySecPreResetRelayId(const UINT16 phySectionId)
{

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

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].PreResetRelayId;	/*获取计轴预复位状态继电器ID并返回*/
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段所在的防淹门数量
* 参数说明： const UINT16 phySectionId, 区段ID
* 返回值  ： 0: 没有防淹门
*			>0:	防淹门数量
*/
UINT16 GetPhySecLocatedFloodSum(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;


	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].LocatedFloodGateSum;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段所在的防淹门Id数组
* 参数说明： const UINT16 phySectionId, 区段ID    
* 返回值  ： NULL: 没有防淹门
*			!NULL: 防淹门Id      
*/
UINT16* GetPhySecLocatedFloodId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16* retVal  = NULL;


	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].LocatedFloodGateId;
	}
	else
	{
		retVal = NULL;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID 物理区段复示轨道继电器ID
* 参数说明： const UINT16 phyId
* 返回值  ：  0: 获取数据失败
*		 >0: 物理区段复视轨道继电器ID
*/
UINT16 GetPhySecRepGdRelayId(const UINT16 phyId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/

	UINT16 retVal = CI_ERROR;
	bufIndex = GetPhySecConfigBufIndex(phyId);  /*获取物理区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].RepGdRelayId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段所属的计轴子系统Id
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ： 0: 获取失败
*			 >0: 计轴子系统Id
*/
UINT8 GetPhySecBelongAxisSysId(const UINT16 phySecId)
{
	UINT16 bufIndex = 0u;		/*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取物理区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = (UINT8)PhysicalSectionConfigDataStru[bufIndex].BelongAxleSysID;
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}
/*
* 功能描述： 获取指定ID物理区段所属虚拟联锁ID
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 所属虚拟联锁ID      
*/
UINT8 GetPhySecBelongVirCiId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].BelongVirCI;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段是否本线路
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 是否本线路      
*/
UINT8 GetPhyIsThisLineState(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].PhyIsThisLine;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段总复位表示灯
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 总复位表示灯      
*/
UINT16 GetPhySecZFWShowRelayId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].ZFWShowRelayId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}
/*
* 功能描述： 设置指定ID物理区段包含道岔
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0: 失败
*			 1:成功       
*/
UINT8 SetPhySecIncludeSwitch(const UINT16 phySectionId)
{
	UINT8 reVal = CI_ERROR;
	UINT8 axisSecSum = 0u;
	UINT16* pAxisSecIdBuf=NULL;
	UINT16 devId = 0u;
	UINT8 axisSwitchSum=0u; 
	AxisSwitchStruct*  pAxisSwitchStruct = NULL;
	UINT16 i = 0u; /* 循环变量 */
	UINT16 j = 0u; /* 循环变量 */
	UINT16 k = 0u; /* 循环变量 */
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 includeSwitchSum = 0u;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		reVal = CI_SUCCESS;
	}
	else
	{
		reVal = CI_ERROR;
	}

	if(CI_SUCCESS==reVal)
	{
		axisSecSum = GetPAxisSectionSum(phySectionId);
		pAxisSecIdBuf = GetPAxisSectionIdBuf(phySectionId);
		if(NULL != pAxisSecIdBuf)
		{
			reVal = CI_SUCCESS;
		}
		else
		{
			reVal = CI_ERROR;
		}
	}

	if(CI_SUCCESS==reVal)
	{		
		for(i=0u;(axisSecSum > i)&&(PHYSICAL_INCLUDE_AXIS_SUM_MAX > i);i++)
		{
			axisSwitchSum = GetAxisSwitchSum(pAxisSecIdBuf[i]);/*计轴区段包含道岔数*/
			pAxisSwitchStruct= GetAxisSwitchIdStru(pAxisSecIdBuf[i]);/*计轴区段包含道岔数组*/
			if(NULL == pAxisSwitchStruct)
			{
				reVal = CI_ERROR;
			}
			else
			{
				/*什么也不做*/
			}
			if(CI_SUCCESS == reVal)
			{					
				for(j = 0u;(j < axisSwitchSum)&&(AXIS_INCLUDE_SWITCH_SUM_MAX > j);j++)
				{
					devId = pAxisSwitchStruct[j].SwitchId;/*道岔编号*/
					if(PHYSICAL_INCLUDE_SWITCH_SUM_MAX > includeSwitchSum)
					{
						for(k = 0u;k < PHYSICAL_INCLUDE_SWITCH_SUM_MAX;k++)/*查找该道岔ID是否已经存在*/
						{
							if(devId == PhysicalSectionConfigDataStru[bufIndex].PhyIncludeSwitch[k])
							{
								break;
							}
						}
						if(PHYSICAL_INCLUDE_SWITCH_SUM_MAX == k)/*不存在则添加*/
						{
							PhysicalSectionConfigDataStru[bufIndex].PhyIncludeSwitch[includeSwitchSum++] = devId;
						}
						
					}
					else
					{
						reVal = CI_ERROR;
					}
				}

			}
		 }
	}

	if(CI_SUCCESS == reVal)
	{
		PhysicalSectionConfigDataStru[bufIndex].PhyIncludeSwitchSum = includeSwitchSum;
	}

	return reVal;
}
/*
* 功能描述： 获取指定ID物理区段包含道岔
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 返回道岔ID数组		       
*/
UINT16* GetPhySecIncludeSwitch(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16* pPhyIncludeSwitch = NULL;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		pPhyIncludeSwitch = PhysicalSectionConfigDataStru[bufIndex].PhyIncludeSwitch;
	}
	else
	{
		pPhyIncludeSwitch = NULL;
	}
	return pPhyIncludeSwitch;
}
/*
* 功能描述： 获取指定ID物理区段包含道岔数目
* 参数说明： const UINT16 phySectionId, 物理区段ID    
* 返回值  ： 0:失败
*            >0:成功
*			       
*/
UINT8 GetPhyIncludeSwitchSum(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 phyIncludeSwitchSum = 0u;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		phyIncludeSwitchSum = PhysicalSectionConfigDataStru[bufIndex].PhyIncludeSwitchSum;
	}
	
	return phyIncludeSwitchSum;
}

/*
* 功能描述： 获取指定ID物理区段关联车库门ID
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： 物理区段关联车库门ID
*/
UINT16 GetPhySecReleatedGdId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].wReleatedGd;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定物理区段关联的逻辑区段Id数组
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ：获取指定物理区段关联的逻辑区段Id数组
*/
UINT16* GetPhySecIncLogSecIdBuf(const UINT16 phySecId)
{
	UINT16* retBuf = NULL;

	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if ( PHYSICAL_SECTION_SUM_MAX>bufIndex)
	{
		retBuf = PhysicalSectionConfigDataStru[bufIndex].LogSectionIdBuf;
	}
	else
	{
		; /*DO NOTHING*/
	}

	return retBuf;
}
/*
* 功能描述： 获取指定物理区段关联的逻辑区段数量
* 参数说明： const UINT16 phySecId, 物理区段ID
* 返回值  ： 获取指定物理区段关联的逻辑区段数量
*/
UINT8 GetPhySecIncLogSecSum(const UINT16 phySecId)
{
	UINT8 routeSum = 0u;

	UINT16 bufIndex = GetPhySecConfigBufIndex(phySecId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX >bufIndex)
	{
		routeSum = PhysicalSectionConfigDataStru[bufIndex].LogSectionSum;
	}

	return routeSum;
}

/*
* 功能描述： 获取指定ID物理区段轨道驱动继电器ID
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 轨道驱动继电器ID
*/
UINT16 GetPhySecGdDrvRelayId(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].GdDrvRelayId;
	}
	else
	{
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段长度
* 参数说明： const UINT16 phySectionId, 物理区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段关联最短计轴区段长度
*/
UINT32 GetPhySecRelayMinAcLen(const UINT16 phySectionId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT32 retVal = 0U;

	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (bufIndex < PHYSICAL_SECTION_SUM_MAX)
	{
		retVal = PhysicalSectionConfigDataStru[bufIndex].wPhySecLen;
	}
	else
	{
		retVal = 0U;
	}
	return retVal;
}

/*
* 功能描述：添加物理区段直接相邻区段数组 设置物理区段长度
* 参数说明： const UINT16 wPhySecId
* 返回值  ：无
*Create fan 20240822
*/
void AddAdjacentPhySec(const UINT16 wPhySecId)
{
	UINT32 dwAcLen = 0U;
	UINT8 phyAcNum = 0; /*物理区段计轴*/
	UINT16 bufIndex = 0U;
	UINT8 jj = 0U;
	UINT8 k = 0U;
	UINT16* pACBuff = NULL; /*物理区段计轴数组*/
	UINT16 wAcStratLink = 0U;/*计轴始端link*/
	UINT16 wAcTerminLink = 0U; /*计轴终端link*/
	UINT8 chAcLinkSum = 0;
	UINT16* pAclinkBuf = NULL;
	UINT16 wStartNearLink = 0U; /*计轴始端相邻link*/
	UINT16 wTmmNearLink = 0U;/*计轴终端相邻link*/
	UINT16 wStartNearSec = 0U;
	UINT16 wTmmNearSec = 0U;
	UINT8 chStartAddFlag = CI_ERROR;
	UINT8 chTmmAddFlag = CI_ERROR;

	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (  PHYSICAL_SECTION_SUM_MAX>  bufIndex)
	{
		phyAcNum = GetPAxisSectionSum(wPhySecId);
		pACBuff = GetPAxisSectionIdBuf(wPhySecId);
		PhysicalSectionConfigDataStru[bufIndex].wPhySecLen = UINT32_MAX;
		PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum = 0U;
		PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum = 0U;
		PhysicalSectionConfigDataStru[bufIndex].chArbPossibleTag = CI_SUCCESS;
		if ((0U != phyAcNum) && (NULL != pACBuff))
		{
			/*遍历关联计轴*/
			for (jj = 0u; jj < phyAcNum; jj++)
			{
				dwAcLen = GetAxisSecTotalLen(pACBuff[jj]);/*计轴区段长度*/
				chAcLinkSum = GetAxisLinkSum(pACBuff[jj]);
				pAclinkBuf = GetAxisLinkIdBuf(pACBuff[jj]);
				wAcStratLink = pAclinkBuf[0];
				wAcTerminLink = pAclinkBuf[chAcLinkSum-(UINT8)1U];
				if (PhysicalSectionConfigDataStru[bufIndex].wPhySecLen > dwAcLen)
				{
					PhysicalSectionConfigDataStru[bufIndex].wPhySecLen = dwAcLen;/*最短计轴*/
				}
				else
				{
					; /*不处理*/
				}
				/*获取始端相邻物理区段*/
				wStartNearLink = GetLinkOrgnJointMainLkIdById(wAcStratLink);
				wStartNearSec = GetLinkRelatedPhySec(wStartNearLink); /*终端计轴处可能为0*/
				chStartAddFlag = CI_ERROR;

				/*获取终端相邻物理区段*/
				wTmmNearLink = GetLinkTmnlJointMainLkById(wAcTerminLink);
				wTmmNearSec = GetLinkRelatedPhySec(wTmmNearLink);
				chTmmAddFlag = CI_ERROR;

				for (k = 0; k <  PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum; k++)
				{
					if (PhysicalSectionConfigDataStru[bufIndex].AdjacentPhySecBuf[k] == wStartNearSec)
					{
						chStartAddFlag = CI_SUCCESS;
						/*已存在，增加可达条件计轴*/
						AddNeighborPhyConditionAc(wPhySecId, k, pACBuff[jj]);
					}
					if (PhysicalSectionConfigDataStru[bufIndex].AdjacentPhySecBuf[k] == wTmmNearSec)
					{
						chTmmAddFlag = CI_SUCCESS;
						/*已存在，增加可达条件计轴*/
						AddNeighborPhyConditionAc(wPhySecId, k, pACBuff[jj]);
					}
				}
				/*添加直接相邻区段*/
				if((CI_ERROR == chStartAddFlag) && (0U != wStartNearSec) 
					&&  (PHYSEC_ADJACENT_SEC_SUM_MAX> PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum))
				{
					PhysicalSectionConfigDataStru[bufIndex].AdjacentPhySecBuf[PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum] = wStartNearSec;
					/*增加可达条件计轴*/
					AddNeighborPhyConditionAc(wPhySecId, PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum, pACBuff[jj]);
					PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum++;
				}
				else
				{
					; /*不处理前方区段*/
				}
				if ((CI_ERROR == chTmmAddFlag) && (0U != wTmmNearSec)
					&& (PHYSEC_ADJACENT_SEC_SUM_MAX>PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum))
				{
					PhysicalSectionConfigDataStru[bufIndex].AdjacentPhySecBuf[PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum] = wTmmNearSec;
					AddNeighborPhyConditionAc(wPhySecId, PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum, pACBuff[jj]);
					PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum++;
				}
				else
				{
					; /*不处理后方区段*/
				}
			}
		}
		else
		{
			PhysicalSectionConfigDataStru[bufIndex].wPhySecLen = 0U;;
		}
	}

}

/*
* 功能描述：添加物理区段范围内相邻区段数组
* 参数说明： const UINT16 wPhySecId
* 返回值  ：无
*Create fan 20240822
*/
void AddNearPhySec(const UINT16 wPhySecId)
{
	UINT32 dwPhySecLen = 0U; /*长度*/
	UINT32 dwCheckNearLen = 0U; /*需配置的接近长度范围*/
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT16 wAdjacentPhySec = 0U; /*直接相连区段*/
	UINT16* wAdjacentPhyBuf = NULL; /*直接相连区段数组*/
	UINT8 chAdjacentPhyNum = 0U; /*直接相连区段数量*/
	UINT8 chNearSecNum = 0U; /*间接相邻数量*/
	UINT16* dwNearSecBuf = NULL; /*间接相连区段数组*/
	UINT8 chTwoStepNearSecNum = 0U; /*间隔两步相邻数量*/
	UINT16* dwTwoStepNearSecBuf = NULL; /*间隔两步相连区段数组*/
	UINT8 chAddCheck = CI_ERROR;
	UINT32 dwIndirectLen = 0U; /*间接找到长度*/
	UINT8 chBelongCi = 0U; /*待检查区段所属ci*/
	UINT8 chCiType = 0U;
	UINT16 wArbProtectDis = GetSystemParaValue(ARB_CHECK_ALXE_SEC_LEN);
	dwCheckNearLen = (UINT32)(wArbProtectDis * 100U);
	if (0U == dwCheckNearLen)
	{
		debug_infor_printf((const)"AddNearPhySec   Fail:  ArbCheckDistance =%d .\n", dwCheckNearLen);
	}
	chAdjacentPhyNum = GetAdjacentPhySecNum(wPhySecId);
	wAdjacentPhyBuf = GetAdjacentPhySecBuf(wPhySecId);/*本联锁直接相邻*/
	for (ii = 0U; ii < chAdjacentPhyNum; ii++)
	{
		wAdjacentPhySec = wAdjacentPhyBuf[ii];
		dwPhySecLen = GetPhySecRelayMinAcLen(wAdjacentPhySec);
		chBelongCi = GetPhySecBelongCiId(wAdjacentPhySec);
		chCiType = GetCiType(chBelongCi);
		if (CI_TYPE_CLD == chCiType)
		{
			;  /*直接相邻在车辆段 不管*/
		}
		else if (dwPhySecLen < dwCheckNearLen)
		{
			/*直接相邻的长度不足*/
			chNearSecNum = GetAdjacentPhySecNum(wAdjacentPhySec);
			dwNearSecBuf = GetAdjacentPhySecBuf(wAdjacentPhySec);
			for (jj = 0U; jj < chNearSecNum; jj++)
			{
				/*添加间接邻近的区段*/
				dwIndirectLen = GetPhySecRelayMinAcLen(dwNearSecBuf[jj]);
				chBelongCi = GetPhySecBelongCiId(dwNearSecBuf[jj]);
				chCiType = GetCiType(chBelongCi);
				if (0u == dwIndirectLen)
				{
					/*已经超出复视区域*/
					SetPhyPossibleArbTag(wPhySecId, CI_ERROR);
					debug_infor_printf((const)"AddNearPhy Sec：%d  Fail:  Search %d  Out Range.\n", wPhySecId, dwNearSecBuf[jj]);
					break;  /*长度不足且越过相邻RC传输范围 本区段无法Arb*/
				}
				else
				{
					/*待检查区域仍在本联锁和相邻RC发送范围*/
					chAddCheck = CheckNearPhySec(dwNearSecBuf[jj], wPhySecId, wAdjacentPhySec, 0U);
					chBelongCi = GetPhySecBelongCiId(dwNearSecBuf[jj]);
					chCiType = GetCiType(chBelongCi);
					if (CI_SUCCESS == chAddCheck)
					{
						/*添加成功*/
		
						/*判断是否再找一轮*/
						if (CI_TYPE_CLD == chCiType)
						{
							;  /*间隔一个相邻车辆段 不再加*/
						}
						else if (dwPhySecLen + dwIndirectLen < dwCheckNearLen)  /*直接相邻 + 间隔一步相邻的最短区段小于查找长度 等于不再查找*/
						{
							chTwoStepNearSecNum = GetAdjacentPhySecNum(dwNearSecBuf[jj]);
							dwTwoStepNearSecBuf = GetAdjacentPhySecBuf(dwNearSecBuf[jj]);
							for (kk = 0U; kk < chTwoStepNearSecNum; kk++)
							{
								/*添加间隔两步邻近的区段*/
								dwIndirectLen = GetPhySecRelayMinAcLen(dwTwoStepNearSecBuf[kk]);
								if (0U == dwIndirectLen)
								{
									/*距离不到且越界*/
									SetPhyPossibleArbTag(wPhySecId, CI_ERROR);
									debug_infor_printf((const)"AddNearPhy Sec：%d  Fail:  Search %d  Out Range.\n", wPhySecId, dwTwoStepNearSecBuf[kk]);
									break;  /*长度不足且越过相邻RC传输范围 本区段无法Arb*/
								}
								else
								{
									chAddCheck = CheckNearPhySec(dwTwoStepNearSecBuf[kk], wPhySecId, wAdjacentPhySec,dwNearSecBuf[jj]);
									/*暂不再查*/
								}
							}
						}
						else
						{
							; /*长度足够*/
						}
					}
				}
			}
		}
		else
		{
			; /*已经满足判断范围长度 不添加*/
		}
	}
}
/*
* 功能描述：获取物理区段范围内直接相邻区段数量
* 参数说明： const UINT16 wPhySecId
* 返回值  ：直接相邻区段数量
* Create fan 20240822
*/
UINT8 GetAdjacentPhySecNum(const UINT16 wPhySecId)
{
	UINT16 bufIndex = 0U;
	UINT8 retValue = 0U;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retValue = PhysicalSectionConfigDataStru[bufIndex].chAdjacentPhySecNum;
	}
	return retValue;
}

/*
* 功能描述： 获取物理区段范围内直接相邻区段数组
* 参数说明： const UINT16 wPhySecId, 区段ID
* 返回值  ： NULL: 无
*			!NULL: 直接相邻区段数组id
* Create fan 20240822
*/
UINT16* GetAdjacentPhySecBuf(const UINT16 wPhySecId)
{
	UINT16 bufIndex = 0U;
	UINT16* retValue = NULL;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retValue = PhysicalSectionConfigDataStru[bufIndex].AdjacentPhySecBuf;
	}
	return retValue;
}
/*
* 功能描述：检查物理区段已有邻近范围内有无该区段 无则添加
* 参数说明： const UINT16 wPhySecId 待检查区段，UINT16 basePhysec基准，wAdjPhySecId 直接相邻跳转区段,wSndPreSec一步间接跳转
* 返回值  ：CI_SUCCESS 新添加 CI_ERROR 已有 
*Create fan 20240822
*/
UINT8 CheckNearPhySec(const UINT16 wPhySecId, const UINT16 basePhysec, const UINT16 wPrePhySecId,const UINT16 wSndPreSec)
{
	UINT8 retValue = CI_SUCCESS;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT16* wAdjacentPhyBuf = NULL; /*直接相连区段数组*/
	UINT8 chAdjacentPhyNum = 0U; /*直接相连区段数量*/
	UINT8 chNearSecNum = 0U; /*间接相邻数量*/
	UINT16 bufIndex = 0U;
	UINT16 wTransitAc = 0U; /*跳转计轴*/
	UINT8 chTransitAcNum = 0U;/*跳转计轴数量*/
	bufIndex = GetPhySecConfigBufIndex(basePhysec);  /*获取区段数组下标*/
	chAdjacentPhyNum = GetAdjacentPhySecNum(basePhysec);
	wAdjacentPhyBuf = GetAdjacentPhySecBuf(basePhysec);
	chNearSecNum = PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum;
	/*不是基准区段*/
	if (wPhySecId == basePhysec)
	{
		retValue = CI_ERROR;
	}

	/*第一步 检查直接相邻*/
	if (CI_ERROR != retValue)
	{
		for (ii = 0; ii < chAdjacentPhyNum; ii++)
		{
			if (wPhySecId == wAdjacentPhyBuf[ii])
			{
				retValue = CI_ERROR;
				break;
			}
		}
	}
	/*第二步 检查上一区段中存在跳转计轴*/
	if (CI_SUCCESS == retValue)
	{
		if (0U == wSndPreSec)
		{
			/*一步间接*/
			wTransitAc = GetTransitAcFromPreSec(wPhySecId, basePhysec, wPrePhySecId);
		}
		else
		{
			/*二步间接*/
			wTransitAc = GetSndTransitAcFromPreSce(wPhySecId, basePhysec, wPrePhySecId, wSndPreSec);
		}
		if (0U == wTransitAc)
		{
			/*未获取到满足条件的计轴*/
			retValue = CI_ERROR;
		}
	}
	
	/*第三步 检查已有间接相邻*/
	if (CI_SUCCESS == retValue)
	{
		for (jj = 0; jj < chNearSecNum; jj++)
		{
			if (wPhySecId == PhysicalSectionConfigDataStru[bufIndex].IndirectNearPhySecBuf[jj])
			{
				/*增加跳转计轴*/
				chTransitAcNum = PhysicalSectionConfigDataStru[bufIndex].TransitAcData[jj].RelateAcNum;
				if (PHYSICAL_INCLUDE_AXIS_SUM_MAX > chTransitAcNum)
				{
					PhysicalSectionConfigDataStru[bufIndex].TransitAcData[jj].AcIdBuf[chTransitAcNum] = wTransitAc;
					PhysicalSectionConfigDataStru[bufIndex].TransitAcData[jj].RelateAcNum++;
				}
				retValue = CI_ERROR;/*不需要添加为间接相邻区段*/
			}
		}
	}

	if ((CI_SUCCESS == retValue) &&(PHYSEC_INDIRECTNEAR_SEC_SUM_MAX>chNearSecNum))
	{
		/*新增间接相邻区段 记录第一个跳转计轴*/
		PhysicalSectionConfigDataStru[bufIndex].IndirectNearPhySecBuf[chNearSecNum] = wPhySecId;
		PhysicalSectionConfigDataStru[bufIndex].TransitAcData[chNearSecNum].AcIdBuf[0] = wTransitAc;
		PhysicalSectionConfigDataStru[bufIndex].TransitAcData[chNearSecNum].RelateAcNum++;
		PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum++;
	}
	else
	{
		retValue = CI_ERROR; 
	}
	return retValue;
}

/*
* 功能描述：获取物理区段范围内间接相邻区段数量
* 参数说明： const UINT16 wPhySecId
* 返回值  ：间接相邻区段数量
* Create fan 20240822
*/
UINT8 GetNearPhySecNum(const UINT16 wPhySecId)
{
	UINT16 bufIndex = 0U;
	UINT8 retValue = 0U;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retValue = PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum;
	}
	return retValue;
}

/*
* 功能描述： 获取物理区段范围内间接相邻区段数组
* 参数说明： const UINT16 wPhySecId, 区段ID
* 返回值  ： NULL: 无
*			!NULL:间接相邻区段数组id
* Create fan 20240822
*/
UINT16* GetIndirectNearPhySecBuf(const UINT16 wPhySecId)
{
	UINT16 bufIndex = 0U;
	UINT16* retValue = NULL;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retValue = PhysicalSectionConfigDataStru[bufIndex].IndirectNearPhySecBuf;
	}
	return retValue;
}

/*
* 功能描述：	整理读入的物理区段配置数据
* 参数说明：	无
* 返回值  ：	CI_SUCCESS,整理成功
*				CI_ERROR,整理失败
* 创建： fan 2024/08/23
*/
UINT8 PhySectionNearConfigDataManage(void)
{
	UINT16 ii = 0u;      /*游标*/
	UINT16 jj = 0u;      /*游标*/
	UINT16 wPhySecId = 0U;
	UINT8 retVal = CI_SUCCESS;
	UINT16* wAdjacentPhyBuf = NULL; /*直接相连区段数组*/
	UINT8 chAdjacentPhyNum = 0U; /*直接相连区段数量*/
	UINT8 chNearSecNum = 0U; /*间接相邻数量*/
	UINT16* dwNearSecBuf = NULL; /*间接相连区段数组*/
	UINT8 chLocal = GetSystemParaLocalCiId();
	UINT8 chBelongCi = 0U;

	/*保存物理区段ID索引数组*/

	if (totalPhysicalSectionNum >= PHYSICAL_SECTION_SUM_MAX)
	{/*配置数据总数错误*/

		retVal = CI_ERROR;
	}
	else
	{
		/*第一步 整理直接复视范围相邻区段 设置物理区段长度*/
		for (ii = 0u; ii < totalPhysicalSectionNum; ii++)
		{
			wPhySecId = LocalCiPhysicalSectionIdBuf[ii];
			AddAdjacentPhySec(wPhySecId);
		}

		/* 第二步： 初始化整理本联锁物理区段配置范围内间接相邻区段数据*/
		for (ii = 0u; ii < totalPhysicalSectionNum; ii++)
		{
			wPhySecId = LocalCiPhysicalSectionIdBuf[ii];
			chBelongCi = GetPhySecBelongCiId(wPhySecId);
			if (chBelongCi == chLocal)
			{
				AddNearPhySec(wPhySecId);
			}
			else
			{
				; /*不处理*/
			}
		}

#if 1
		/*打印*/
		for (ii = 0u; ii < totalPhysicalSectionNum; ii++)
		{
			wPhySecId = LocalCiPhysicalSectionIdBuf[ii];
			chAdjacentPhyNum = GetAdjacentPhySecNum(wPhySecId);
			wAdjacentPhyBuf = GetAdjacentPhySecBuf(wPhySecId);

			debug_infor_printf((const)"\nInitNear Sec:%d:  belongCI :%d  Add_Adjacent：-", wPhySecId, GetPhySecBelongCiId(wPhySecId));
			for (jj = 0U; jj < chAdjacentPhyNum; jj++)
			{
				debug_infor_printf((const)"%d-", wAdjacentPhyBuf[jj]);
			}
			debug_infor_printf((const)"Total_Adjacent  :  %d", chAdjacentPhyNum);
			if (chLocal == GetPhySecBelongCiId(wPhySecId))
			{
				debug_infor_printf((const)"\nPossibleTag  : %d ", GetPhyPossibleArbTag(wPhySecId));
				chNearSecNum = GetNearPhySecNum(wPhySecId); /*间接相邻数量*/
				dwNearSecBuf = GetIndirectNearPhySecBuf(wPhySecId); /*间接相连区段数组*/
				debug_infor_printf((const)"Add_Near：--");
				for (jj = 0U; jj < chNearSecNum; jj++)
				{
					debug_infor_printf((const)"%d: --", dwNearSecBuf[jj]);
				}
				debug_infor_printf((const)"Total_Near  %d .", chNearSecNum);
			}
		}

#endif
	}
	return retVal;
}

/*
* 功能描述： 获取物理区段可否判断为Arb
* 参数说明： const UINT16 wPhySecId, 区段ID
* 返回值  ：CI_SUCCESS CI_ERROR配置数据不满足
* Create fan 20240822
*/
UINT8 GetPhyPossibleArbTag(const UINT16 wPhySecId)
{
	UINT16 bufIndex = 0U;
	UINT8 retValue = CI_ERROR;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		retValue = PhysicalSectionConfigDataStru[bufIndex].chArbPossibleTag;
	}
	return retValue;
}

/*
* 功能描述： 设置物理区段可否判断为Arb
* 参数说明： const UINT16 wPhySecId, 区段ID，UINT8 chArbTag
* 返回值  ：void
* Create fan 20240822
*/
void SetPhyPossibleArbTag(const UINT16 wPhySecId, UINT8 chArbTag)
{
	UINT16 bufIndex = 0U;
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if ((PHYSICAL_SECTION_SUM_MAX > bufIndex)&&
		((CI_SUCCESS == chArbTag)||(CI_ERROR == chArbTag)))
	{
		PhysicalSectionConfigDataStru[bufIndex].chArbPossibleTag = chArbTag;
	}
}

/*
* 功能描述： 通过计轴系统的区段序号获取物理区段ID
* 参数说明： const UINT8 chAxleId 计轴系统ID
* 参数说明： const UINT16 wIndexInAxle, 计轴系统的区段序号
* 返回值  ： 0:失败
*            >0:物理区段ID
* by cgh 20250415
*/
UINT16 GetPhyIdByIndexInAxle(const UINT8 chAxleId, const UINT16 wIndexInAxle)
{
	UINT16 wPhyCurNum = 0U; /*当前物理区段总数*/
	UINT16 ii = 0U;
	UINT16 wCurPhyId = 0U; /*当前物理区段ID*/
	UINT16 wPhyIndex = 0U; /*物理区段索引*/
	UINT16 wReval = 0U; /*返回的物理区段ID*/

	if (AXIS_TO_CI_SECTION_SUM_MAX > wIndexInAxle)
	{
		wPhyCurNum = GetPhySecCurSum(); /*物理区段总数*/

		for (ii = 0U; ii < wPhyCurNum; ii++)
		{
			wCurPhyId = GetPhySecId(ii);
			wPhyIndex = GetPhySecConfigBufIndex(wCurPhyId);/*物理区段下标*/

			if ((PhysicalSectionConfigDataStru[wPhyIndex].wIndexInAxle == wIndexInAxle)
				&& (PhysicalSectionConfigDataStru[wPhyIndex].BelongAxleSysID == chAxleId))
			{
				wReval = wCurPhyId;
				break;
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不做处理*/
	}

	return wReval;
}

/*
* 功能描述：添加直接相邻区段检查计轴数据
* 参数说明： const UINT16 wPhySecId 物理区段 UINT8 chIndex相邻区段索引 UINT16 AcId计轴ID
* 返回值  ：无
*Create fan 20260303
*/
void AddNeighborPhyConditionAc(const UINT16 wPhySecId, UINT8 chIndex, UINT16 AcId)
{
	UINT16 bufIndex = 0U;
	UINT8 chAcIndec = 0U;/*计轴索引*/
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/	
	if ((PHYSICAL_SECTION_SUM_MAX > bufIndex)&&(PHYSEC_ADJACENT_SEC_SUM_MAX>chIndex))
	{
		chAcIndec = PhysicalSectionConfigDataStru[bufIndex].AdjacentSecAcData[chIndex].RelateAcNum;
		if (PHYSICAL_INCLUDE_AXIS_SUM_MAX > chAcIndec)
		{
			PhysicalSectionConfigDataStru[bufIndex].AdjacentSecAcData[chIndex].AcIdBuf[chAcIndec] = AcId;
			PhysicalSectionConfigDataStru[bufIndex].AdjacentSecAcData[chIndex].RelateAcNum++;
		}
		else
		{
			;/*数组上限 不添加*/
		}
	}
	else
	{
		;/*不处理*/
	}
}

/*
* 功能描述： 获取指定ID物理区段的ARB防护范围区段的跳转计轴序列
* 参数说明： const UINT16 phySectionId, 物理区段ID  UINT16 wNearSecID 相邻区段
* 返回值  ： 0: 获取数据失败
*			>0: 计轴区段ID数组指针
*Create fan 202604010
*/
UINT16* GetPhySecNearSecTransitAcBuf(const UINT16 phySectionId, const UINT16 wNearSecID)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 * retVal = NULL;
	UINT8 i = 0U;
	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX> bufIndex)
	{
		for (i = 0U; i < PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum; i++)
		{
			if (PhysicalSectionConfigDataStru[bufIndex].IndirectNearPhySecBuf[i] == wNearSecID)
			{
				retVal = PhysicalSectionConfigDataStru[bufIndex].TransitAcData[i].AcIdBuf;
				break;
			}
		}
		
	}
	else
	{
		retVal = NULL;
	}
	return retVal;
}

/*
* 功能描述： 获取指定ID物理区段到某个临近区段的直接跳转计轴数量
* 参数说明： const UINT16 phySectionId, 物理区段ID  UINT16 wNearSecID 相邻区段
* 返回值  ： 0: 获取数据失败
*			>0: 计轴区段ID数组指针
*Create fan 202604010
*/
UINT8 GetPhySecNearSecTransitAcNum(const UINT16 phySectionId, const UINT16 wNearSecID)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = 0U;
	UINT8 i = 0U;
	bufIndex = GetPhySecConfigBufIndex(phySectionId);  /*获取区段数组下标*/

	if (PHYSICAL_SECTION_SUM_MAX> bufIndex)
	{
		for (i = 0U; i < PhysicalSectionConfigDataStru[bufIndex].chNearPhySecNum; i++)
		{
			if (PhysicalSectionConfigDataStru[bufIndex].IndirectNearPhySecBuf[i] == wNearSecID)
			{
				retVal = PhysicalSectionConfigDataStru[bufIndex].TransitAcData[i].RelateAcNum;
				break;
			}
		}
	}
	else
	{
		retVal = 0U;
	}
	return retVal;
}
/*
* 功能描述：检查间接相邻区段的上一跳转区段是否属于区段的直接相邻范围
* 参数说明： const UINT16 wPhySecId，const UINT16 wPreSecId
* 返回值  ：CI_SUCCESS 是 CI_ERROR否
* Create fan 20260303
*/
UINT8 CheckPhySecIfAdjacent(const UINT16 wPhySecId, const UINT16 wPreSecId)
{
	UINT8 retVal = CI_ERROR;
	UINT16* wAdjacentPhyBuf = NULL; /*直接相连区段数组*/
	UINT8 chAdjacentPhyNum = 0U; /*直接相连区段数量*/
	UINT8 ii = 0U;
	chAdjacentPhyNum = GetAdjacentPhySecNum(wPhySecId);
	wAdjacentPhyBuf = GetAdjacentPhySecBuf(wPhySecId);/*直接相邻数组*/
	for (ii = 0U; ii < chAdjacentPhyNum; ii++)
	{
		if (wPreSecId == wAdjacentPhyBuf[ii])
		{
			retVal = CI_SUCCESS;
			break;
		}
		else
		{
			;/*继续*/
		}
	}
	return retVal;
}
/*
* 功能描述：获取物理区段直接相邻区段条件计轴检查结果(是否可达)
* 参数说明： const UINT16 wPhySecId UINT16 wNearSec 直接相邻区段
* 返回值  ：直接相邻区段条件计轴检查结果 CI_ERROR不可达 CI_SUCCESS可达
* Create fan 20260303
*/
UINT8 GetAdjacentPhySecAcCheck(const UINT16 wPhySecId, UINT16 wNearSec)
{
	UINT16 bufIndex = 0U;
	UINT8 retValue = CI_SUCCESS;/*SUCCESS时检查对应区段，为安全态*/
	UINT8 k = 0U;/*计轴索引*/
	UINT8 jj = 0U;
	UINT8 ii = 0U;
	UINT16 wAcId = 0U;
	UINT8 chCheckAcNum = 0U;
	UINT16* ConditionAcBuf = NULL; /*条件计轴数组*/
	AxisSwitchStruct* axisSwitchStru = NULL;
	UINT8 axisSwitchSum = 0U;/*计轴条件道岔数量*/
	UINT16 curSwitchId = 0U;/*计轴关联道岔*/
	UINT8 switchCurPosition = 0U;/*道岔位置*/
	UINT8 chAcCheckResult = CI_ERROR;/*单个条件计轴检查结果*/
	UINT16* wAdjacentPhyBuf = NULL; /*直接相连区段数组*/
	UINT8 chAdjacentPhyNum = 0U; /*直接相连区段数量*/
	chAdjacentPhyNum = GetAdjacentPhySecNum(wPhySecId);
	wAdjacentPhyBuf = GetAdjacentPhySecBuf(wPhySecId);/*直接相邻数组*/
	bufIndex = GetPhySecConfigBufIndex(wPhySecId);  /*获取区段数组下标*/
	if (PHYSICAL_SECTION_SUM_MAX > bufIndex)
	{
		for (ii = 0U; ii < chAdjacentPhyNum; ii++)
		{
			if (wNearSec == wAdjacentPhyBuf[ii])
			{
				chCheckAcNum = PhysicalSectionConfigDataStru[bufIndex].AdjacentSecAcData[ii].RelateAcNum;
				ConditionAcBuf = PhysicalSectionConfigDataStru[bufIndex].AdjacentSecAcData[ii].AcIdBuf;
				for (k = 0U; k <chCheckAcNum; k++)
				{
					wAcId = ConditionAcBuf[k];
					axisSwitchStru = GetAxisSwitchIdStru(wAcId);
					axisSwitchSum = GetAxisSwitchSum(wAcId);
					chAcCheckResult = CI_SUCCESS;/*无岔认为一定可达*/
					for (jj = 0U; jj < axisSwitchSum; jj++)
					{
						curSwitchId = axisSwitchStru[jj].SwitchId;
						switchCurPosition = GetSwitchCurPosition(curSwitchId);	/*获取道岔当前位置*/
						/*四开时保留可达性*/
						if (((SWITCH_POSITION_FANWEI == switchCurPosition) || (SWITCH_POSITION_DINGWEI == switchCurPosition))
							&& (axisSwitchStru[jj].SwitchPosition != switchCurPosition))
						{
							chAcCheckResult = CI_ERROR;
							break;
						}
						else
						{
							/*四开或道岔位置满足*/
							/*计轴关联多个道岔时需所有道岔满足*/
						}
					}
					if (CI_SUCCESS == chAcCheckResult)
					{
						/*只要有一个条件计轴满足，则相邻区段可达, 无岔必可达*/
						retValue = CI_SUCCESS;
						break;
					}
					else
					{
						retValue = CI_ERROR;
					}
				}
				break;/*已找到对应区段 停止检查*/
			}
			else
			{
				;/*非检查区段 不处理*/
			}
		}

	}
	else
	{
		;/*返回需进行检查*/
	}
	return retValue;
}

/*
* 功能描述：获取存在跳转计轴时 间隔相邻区段是否可达
* 参数说明： constUINT16 wBasePhySec基准区段  wTransitAcId 上一跳转计轴区段
* 返回值  ：CI_ERROR不可达 CI_SUCCESS可达
* Create fan 20260410
*/
UINT8 GetTransitPhySecAcCheck(const UINT16 wBasePhySec, UINT16 wTransitAcId)
{
	UINT8 retValue = CI_SUCCESS;/*SUCCESS时检查对应区段，为安全态*/
	UINT16 wPreSec = 0U;
	UINT8 jj = 0U;
	UINT8 chAdvacentCheck = CI_ERROR;/*是否一步间接*/
	UINT16 wFiestStepSec = 0U;
	UINT8 chTransitAcNum = 0U; /*跳转计轴数量*/
	UINT16* chTransitAcBuf = NULL; /*跳转计轴数组*/
	UINT8 chStepCheck = CI_SUCCESS;
	wPreSec = GetAxisSecRelativePhySecId(wTransitAcId);
	if (0U != wPreSec)
	{
		/*待检查区段与上一区段之间的可达性由跳转计轴保证*/
		retValue = GetAcSwitchPosCheck(wTransitAcId);
		chAdvacentCheck = CheckPhySecIfAdjacent(wBasePhySec, wPreSec);
		if (CI_SUCCESS == chAdvacentCheck)
		{		
			/*一步间接：检查条件计轴+基准区段的道岔位置*/
			retValue &= GetAdjacentPhySecAcCheck(wBasePhySec, wPreSec);/*基准区段的道岔满足*/
		}
		else
		{
			/*二步间接：检查条件计轴+一步间接区段的所有条件计轴中存在满足且基准道岔位置满足的区段*/
			chTransitAcNum = GetPhySecNearSecTransitAcNum(wBasePhySec, wPreSec);
			chTransitAcBuf = GetPhySecNearSecTransitAcBuf(wBasePhySec, wPreSec);
			if ((NULL != chTransitAcBuf)&&(0U < chTransitAcNum))
			{
				for (jj = 0; jj < chTransitAcNum; jj++)
				{
					wFiestStepSec = GetAxisSecRelativePhySecId(chTransitAcBuf[jj]);
					chStepCheck = GetAcSwitchPosCheck(chTransitAcBuf[jj]);
					chStepCheck &= GetAdjacentPhySecAcCheck(wBasePhySec, wFiestStepSec);/*基准区段到直接相邻的道岔满足*/
					if (CI_SUCCESS == chStepCheck)
					{
						break;
					}
				}
			}
			else
			{
				chStepCheck = CI_ERROR;/*不存在跳转条件*/
			}
			retValue &= chStepCheck;
		}
	}
	
	/*检查跳转区段中存在*/
	return retValue;
}

/*
* 功能描述：检查在物理区段中获取符合条件的跳转计轴ID
* 参数说明： const UINT16 wPhySecId 待检查区段，UINT16 basePhysec基准区段，wAdjPhySecId 间接区段的上一跳转区段
* 返回值  ：CI_SUCCESS 新添加 CI_ERROR 已有
*Create fan 20260410
*/
UINT16 GetTransitAcFromPreSec(const UINT16 wPhySecId, const UINT16 basePhysec, const UINT16 wPrePhySecId)
{
	UINT16 retAcId = 0U;
	UINT8 phyAcNum = 0; /*物理区段计轴*/
	UINT16* pACBuff = NULL; /*物理区段计轴数组*/
	UINT16 wAcStratLink = 0U; /*计轴始端link*/
	UINT16 wAcTerminLink = 0U; /*计轴终端link*/
	UINT8 chAcLinkSum = 0;
	UINT16* pAclinkBuf = NULL;
	UINT16 wStartNearLink = 0U; /*计轴始端相邻link*/
	UINT16 wTmmNearLink = 0U;/*计轴终端相邻link*/
	UINT16 wStartNearSec = 0U;
	UINT16 wTmmNearSec = 0U;
	UINT8 jj = 0U;
	/*跳转区段中找一端链接基准 一端为待检查的区段跳转计轴*/
	phyAcNum = GetPAxisSectionSum(wPrePhySecId);
	pACBuff = GetPAxisSectionIdBuf(wPrePhySecId);
	if ((0U != phyAcNum) && (NULL != pACBuff))
	{
		/*遍历跳转区段的关联计轴*/
		for (jj = 0u; jj < phyAcNum; jj++)
		{
			chAcLinkSum = GetAxisLinkSum(pACBuff[jj]);
			pAclinkBuf = GetAxisLinkIdBuf(pACBuff[jj]);
			wAcStratLink = pAclinkBuf[0];
			wAcTerminLink = pAclinkBuf[chAcLinkSum - (UINT8)1U];
			/*获取始端相邻物理区段*/
			wStartNearLink = GetLinkOrgnJointMainLkIdById(wAcStratLink);
			wStartNearSec = GetLinkRelatedPhySec(wStartNearLink);

			/*获取终端相邻物理区段*/
			wTmmNearLink = GetLinkTmnlJointMainLkById(wAcTerminLink);
			wTmmNearSec = GetLinkRelatedPhySec(wTmmNearLink);

			if (((wStartNearSec == basePhysec) && (wTmmNearSec == wPhySecId))
				|| ((wStartNearSec == wPhySecId) && (wTmmNearSec == basePhysec)))
			{
				/*在跳转区段中找到跳转计轴*/
				retAcId = pACBuff[jj];
				break;
			}
		}
	}
	return retAcId;
}

/*
* 功能描述：检查在二步间接物理区段中获取符合条件的跳转计轴ID
* 参数说明： const UINT16 wPhySecId 待检查区段，UINT16 basePhysec基准，wAdjPhySecId 直接相邻跳转区段,wSndPreSec一步间接跳转
* 返回值  ：0未找到 >0 计轴ID
*Create fan 20260410
*/
UINT16 GetSndTransitAcFromPreSce(const UINT16 wPhySecId, const UINT16 basePhysec, const UINT16 wAdjPhySecId, const UINT16 wSndPreSec)
{
	UINT16 retAcId = 0U;/*符合条件二步跳转计轴*/
	UINT16 wAcStratLink = 0U; /*计轴始端link*/
	UINT16 wAcTerminLink = 0U; /*计轴终端link*/
	UINT8 chAcLinkSum = 0;
	UINT16* pAclinkBuf = NULL;
	UINT16 wFirstStartNearLink = 0U; /*第一跳转计轴始端相邻link*/
	UINT16 wFirstTmmNearLink = 0U;/*第一跳转计轴终端相邻link*/
	UINT16 wFirstStepAc = 0U;/*基准到一步间接中的跳转计轴*/
	UINT16 wSndStepAc = 0U;/*直接相邻到二步间接中的跳转计轴*/
	wFirstStepAc = GetTransitAcFromPreSec(wSndPreSec, basePhysec, wAdjPhySecId);
	wSndStepAc = GetTransitAcFromPreSec(wPhySecId, wAdjPhySecId, wSndPreSec);
	if ((0U != wFirstStepAc) && (0U != wSndStepAc))
	{
		chAcLinkSum = GetAxisLinkSum(wFirstStepAc);
		pAclinkBuf = GetAxisLinkIdBuf(wFirstStepAc);
		wAcStratLink = pAclinkBuf[0];
		wAcTerminLink = pAclinkBuf[chAcLinkSum - (UINT8)1U];
		/*获取始端相邻link*/
		wFirstStartNearLink = GetLinkOrgnJointMainLkIdById(wAcStratLink);
		/*获取终端相邻link*/
		wFirstTmmNearLink = GetLinkTmnlJointMainLkById(wAcTerminLink);


		/*获取第二跳转计轴的始端终端*/
		chAcLinkSum = GetAxisLinkSum(wSndStepAc);
		pAclinkBuf = GetAxisLinkIdBuf(wSndStepAc);
		wAcStratLink = pAclinkBuf[0];
		wAcTerminLink = pAclinkBuf[chAcLinkSum - (UINT8)1U];

		/*是否相等*/
		if ((wFirstStartNearLink == wAcStratLink)
			|| (wFirstStartNearLink == wAcTerminLink)
			|| (wFirstTmmNearLink == wAcStratLink)
			|| (wFirstTmmNearLink == wAcTerminLink))
		{
			retAcId = wSndStepAc;
		}
		else
		{
			retAcId = 0U;
		}
		
	}
	return retAcId;
}