#include "CiSystemDefine.h"
#include "SystemParameterManage.h"
#include "CutoffPointDataManage.h"
#include "CutoffPointConfigDataManage.h"
#include "LinkConfigDataManage.h"
#include "AxisSort_api.h"
#include "EnvelopeManageAPI.h"
#include "ELMDataPrepare.h"
#include "../Section/PhysicalSectionDataManage.h"
#include "RRMManageAPI.h"


CfpDataStru g_CutoffPointDataBuf[CUTOFF_POINT_SUM_MAX] = { 0u };

/**
* @brief 基于边界点的占用序列计算
* @param wCutoffPointId 边界点编号
* @param pLinkNum 输出的link数量
* @param szLinkIdBuf 输出的link序列
* @return CI_SUCCESS成功；CI_ERROR失败
*/
static UINT8 CalCutoffPointOccupyLinkSeq(IN const UINT16 wCutoffPointId, OUT UINT16 * pLinkNum, OUT UINT16 szLinkIdBuf[]);

/*
* 功能描述： 分界点数据初始化
* 参数说明： 无
* 返回值  ： 0: 设置失败
*			 1: 设置成功
*/
UINT8 CutoffPointDataManageInit(void)
{
	UINT8 ret = CI_ERROR;
	UINT16 dwCutoffPointSum = 0u;
	UINT16 dwCutoffPointId = 0u;
	UINT16 i = 0u;
	UINT16 dwIndex = 0u;

	/* 获取本联锁边界点数量 */
	dwCutoffPointSum = GetCfpSum();
	if (dwCutoffPointSum < CUTOFF_POINT_SUM_MAX)
	{
		for (i = 0u; i < dwCutoffPointSum; i++)
		{
			/* 获取边界点ID */
			dwCutoffPointId = GetCfpId(i);
			dwIndex = GetCfpBufIndex(dwCutoffPointId);
			g_CutoffPointDataBuf[dwIndex].wId = dwCutoffPointId;
			g_CutoffPointDataBuf[dwIndex].localTiocTrainInfo.wTrainId = 0u;
			g_CutoffPointDataBuf[dwIndex].localTiocTrainInfo.chTrainLevel = 0u;
			g_CutoffPointDataBuf[dwIndex].localTiocTrainInfo.dwDis = 0u;

			g_CutoffPointDataBuf[dwIndex].otherTiocTrainInfo.wTrainId = 0u;
			g_CutoffPointDataBuf[dwIndex].otherTiocTrainInfo.chTrainLevel = 0u;
			g_CutoffPointDataBuf[dwIndex].otherTiocTrainInfo.dwDis = 0u;

			g_CutoffPointDataBuf[dwIndex].szCfpRRMData.cRrmSrcRcId = 0U;
			g_CutoffPointDataBuf[dwIndex].szCfpRRMData.wRrmTrainId = 0U;
			g_CutoffPointDataBuf[dwIndex].szCfpRRMData.wRrmTrainNextStaId = 0U;
			g_CutoffPointDataBuf[dwIndex].szCfpRRMData.chRrmSrcApplyState = TRAIN_RRM_LOCALCI_NOT_APPLY;
			g_CutoffPointDataBuf[dwIndex].szCfpRRMData.chRrmDstAllowState = TRAIN_RRM_OTHERCI_NOT_ALLOW;
			g_CutoffPointDataBuf[dwIndex].cSignalLightUpFlag = SIGNAL_SLEEP_TRAIN_LIGHTUP_NO;
		}
		ret = CI_SUCCESS;
	}
	else
	{
		;/* 初始化失败 */
	}


	return ret;
}

/*
* 功能描述： 获取边界点数据存储地址
* 参数说明： 无
* 返回值  ： 边界点数据存储地址
*/
CfpDataStru * GetCfpData(void)
{
	return (CfpDataStru *)(&g_CutoffPointDataBuf[0]);
}

/**
* @brief 获取分界点相邻OC发来的列车信息
* @param wCfpId 分界点ID
* @return 列车信息
*/
CfpTrainInfoStru GetCfpOtherOcTrainInfo(const UINT16 wCfpId)
{
	CfpTrainInfoStru dwRetVal = {0u};
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		dwRetVal = g_CutoffPointDataBuf[wIndex].otherTiocTrainInfo;
	}
	else
	{
		dwRetVal.wTrainId = UINT16_MAX;
	}
	return dwRetVal;
}

/**
* @brief 获取分界点本地OC发送的列车信息
* @param wCfpId 分界点ID
* @return 列车信息
*/
CfpTrainInfoStru GetCfpLocalOcTrainInfo(const UINT16 wCfpId)
{
	CfpTrainInfoStru dwRetVal = { 0u };
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		dwRetVal = g_CutoffPointDataBuf[wIndex].localTiocTrainInfo;
	}
	else
	{
		dwRetVal.wTrainId = UINT16_MAX;
	}
	return dwRetVal;
}


/**
* @brief 设置分界点相邻OC发来的列车信息
* @param wCfpId 分界点ID trainInfo 列车信息
* @return 列车信息
*/
void SetCfpOtherOcTrainInfo(const UINT16 wCfpId, CfpTrainInfoStru trainInfo)
{
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		g_CutoffPointDataBuf[wIndex].otherTiocTrainInfo = trainInfo;
	}
	else
	{
		;
	}
}

/**
* @brief 设置分界点本地OC发送的列车信息
* @param wCfpId 分界点ID trainInfo 列车信息
* @return 列车信息
*/
void SetCfpLocalOcTrainInfo(const UINT16 wCfpId, CfpTrainInfoStru trainInfo)
{
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		g_CutoffPointDataBuf[wIndex].localTiocTrainInfo = trainInfo;
	}
	else
	{
		;
	}
}


/**
* @brief 基于边界点的占用序列计算
* @param wCutoffPointId 边界点编号
* @param pLinkNum 输出的link数量
* @param szLinkIdBuf 输出的link序列
* @return CI_SUCCESS成功；CI_ERROR失败
*/
static UINT8 CalCutoffPointOccupyLinkSeq(IN const UINT16 wCutoffPointId, OUT UINT16 * pLinkNum, OUT UINT16 szLinkIdBuf[])
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 cKeepWork = CI_ERROR;
	UINT16 wLinkSum = 0u;
	UINT16 wszLinkIdBuf[MAX_CFG_LIGHTUPLINK_NUM] = { 0u };
	UINT16 wCutoffPointInFirstLinkId = 0u;
	UINT32 dwCutoffPointInFirstLinkLen = 0u;
	UINT32 dwFindLen = 0u; /*信号机点灯距离*/
	UINT8 cCutoffPointDir = UINT8_MAX;
	UINT32 dwSearchLen = UINT32_MAX;
	UINT16 wCurrentLink = UINT16_MAX;
	UINT16 wNextLink = UINT16_MAX;
	UINT16 wPointId = UINT16_MAX;
	UINT8 cRetMem = 0u;
	UINT8 cDirectionPointFlag = 0U;			/*是否具有方向变化点标志*/
	UINT8 cDirectionPointCnt = 0U;			/*方向变化点数量*/

	dwFindLen = GetSystemParaValue(SIGNAL_LIGHTUP_SEC_LEN_ID);
	dwFindLen *= 100u;

	/*入参检查*/
	if ((0u < wCutoffPointId) && (CUTOFF_POINT_SUM_MAX > wCutoffPointId))
	{
		cKeepWork = CI_SUCCESS;
	}
	else
	{
		cKeepWork = CI_ERROR;
	}

	if (CI_SUCCESS == cKeepWork)
	{
		/*入参检查*/
		if ((NULL != pLinkNum) && (NULL != szLinkIdBuf))
		{
			cKeepWork = CI_SUCCESS;
		}
		else
		{
			cKeepWork = CI_ERROR;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == cKeepWork)
	{
		/* 查到距离检查 */
		if ((0u != dwFindLen) && (UINT32_MAX != dwFindLen))
		{
			cKeepWork = CI_SUCCESS;
		}
		else
		{
			cKeepWork = CI_ERROR;
		}
	}
	else
	{
		;
	}

	if (CI_SUCCESS == cKeepWork)
	{
		/* 获取内方linkID */
		wCutoffPointInFirstLinkId = GetCfpInFirstLink(wCutoffPointId);
		dwCutoffPointInFirstLinkLen = GetLinkLengthById(wCutoffPointInFirstLinkId);
		wCurrentLink = wCutoffPointInFirstLinkId;
		/*返回值检查*/
		if ((UINT16_MAX != wCutoffPointInFirstLinkId) && (UINT32_MAX != dwCutoffPointInFirstLinkLen))
		{
			/* 获取查询方向 */
			cCutoffPointDir = GetCfpLocDir(wCutoffPointId);

			dwSearchLen = dwCutoffPointInFirstLinkLen;
			/*信号机防护方向反向搜索*/
			if ((DIR_SAME == cCutoffPointDir) || (DIR_CONVERT == cCutoffPointDir))
			{
				;/* 方向有效 */
			}
			else
			{
				cCutoffPointDir = DIR_INVALID;
				cKeepWork = CI_ERROR;
			}

			if (CI_SUCCESS == cKeepWork)
			{
				do
				{
					/*获取下一linkID*/
					wNextLink = FindAdjacentLinkIDSafe(wCurrentLink, cCutoffPointDir, &wPointId, &cDirectionPointFlag);

					if (MAX_CFG_LIGHTUPLINK_NUM > wLinkSum)
					{
						wszLinkIdBuf[wLinkSum] = wCurrentLink;
						wLinkSum++;
					}
					else
					{
						;
					}

					if ((UINT16_MAX != wNextLink) && (0u != wNextLink) && (dwSearchLen < dwFindLen))
					{
						cKeepWork = dsuCheckLinkFitPointSafe(wCurrentLink, cCutoffPointDir, &wPointId);
						if (CI_SUCCESS == cKeepWork)
						{
							/*获取成功*/
							wCurrentLink = wNextLink;
							/*根据方向变化点信息转换查询下一link方向*/
							cCutoffPointDir = TransDirectionPointDir(cDirectionPointFlag, cCutoffPointDir, &cDirectionPointCnt);

							dwSearchLen += GetLinkLengthById(wCurrentLink);
							if ((dwSearchLen >= dwFindLen) && (MAX_CFG_LIGHTUPLINK_NUM > wLinkSum))
							{
								wszLinkIdBuf[wLinkSum] = wCurrentLink;
								wLinkSum++;
							}
							else
							{
								;
							}
						}
						else
						{
							/*道岔不在期望位置，停止搜索*/
							dwSearchLen = UINT32_MAX;
							cKeepWork = CI_SUCCESS;
						}
					}
					else
					{
						dwSearchLen = UINT32_MAX;
					}
				} while (dwSearchLen < dwFindLen);

			}
			else
			{
				;
			}
		}
		else
		{
			/*外放第一区段无效*/
			cKeepWork = CI_SUCCESS;
		}
	}
	else
	{
		;
	}



	if (CI_SUCCESS == cKeepWork)
	{
		/*检查通过，将结果拷贝到输出数组*/
		cRetMem = CommonMemCpy(szLinkIdBuf, (UINT32)(MAX_CFG_LIGHTUPLINK_NUM * sizeof(UINT16)), wszLinkIdBuf, (UINT32)(wLinkSum * sizeof(UINT16)));
		if (CI_SUCCESS == cRetMem)
		{
			/*将数量输出*/
			*pLinkNum = wLinkSum;
			cRetVal = CI_SUCCESS;
		}
		else
		{
			;
		}

	}
	else
	{
		cRetVal = CI_ERROR;
	}

	return cRetVal;
}

/*
* 功能描述： 分界点数据输出处理
* 参数说明： 无
* 返回值  ： 无
*/
void  CutoffPointOutput(void)
{
	UINT16 wCutoffPointSum = 0u;
	UINT16 wCutoffPointId = 0u;
	UINT16 i = 0u;
	UINT16 j = 0u;
	UINT16 wLinkSum = 0u;
	UINT16 wszLinkIdBuf[MAX_CFG_LIGHTUPLINK_NUM] = { 0u };
	UINT16 wLinkId = 0u;
	UINT16 wPhySecId = 0u;
	UINT8 chOccState = 0u;
	UINT8 cDir = 0u;
	UINT8 cFunRetVal = CI_ERROR;
	CfpTrainInfoStru tmpTrainInfo = { 0u };
	struct_PathPoint LinkPoint = { 0u };
	UINT32 dwFindLen = 0u;/*信号机点灯防护距离*/
	UINT8 chTrainNum = 0u; 
	UINT8 cDirectionPointfirst = 0U;			/*方向变化点1*/
	UINT8 cDirectionPointsecond = 0U;			/*方向变化点2*/
	UINT16 wOtherCfpId = 0u; /*其他分界点ID*/
	UINT8 chLocalId = 0u; /*本联锁id*/
	UINT8 chLinkCIId = 0u; /*link所属联锁id*/
	UINT8 chOtherFlag = FLAG_UNSET;
	UINT8 chBreakFlag = FLAG_UNSET;
	UINT32 dwLinkLen = 0U;/*本联锁已计算分界点距离*/
	dwFindLen = GetSystemParaValue(SIGNAL_LIGHTUP_SEC_LEN_ID);
	dwFindLen *= 100U;
	chLocalId = GetSystemParaLocalCiId();

	/* 获取本联锁边界点数量 */
	wCutoffPointSum = GetCfpSum();
	if (wCutoffPointSum < CUTOFF_POINT_SUM_MAX)
	{
		for (i = 0u; i < wCutoffPointSum; i++)
		{
			/* 获取边界点ID */
			wCutoffPointId = GetCfpId(i);

			/* 获取查询方向 */
			cDir = GetCfpLocDir(wCutoffPointId);
			
			/* 计算边界点的点灯link */
			(void)CommonMemSet(wszLinkIdBuf, (UINT32)(sizeof(UINT16)*MAX_CFG_LIGHTUPLINK_NUM), 0U, (UINT32)(sizeof(UINT16)*MAX_CFG_LIGHTUPLINK_NUM));
			cFunRetVal = CalCutoffPointOccupyLinkSeq(wCutoffPointId, &wLinkSum, wszLinkIdBuf);

			/*重置计算位置 */
			LinkPoint.wLinkId =0U;
			LinkPoint.dwOffset = 0U;

			wOtherCfpId = 0U;
			chOtherFlag = FLAG_UNSET;
			chBreakFlag = FLAG_UNSET;
			dwLinkLen = 0U;
			if ((CI_SUCCESS == cFunRetVal)&&(MAX_CFG_LIGHTUPLINK_NUM>=wLinkSum))
			{
				/* 区段查找成功,查到区段上的列车 */
				for (j = 0u;j < wLinkSum;j++)
				{
					wLinkId = wszLinkIdBuf[j];
					chLinkCIId = (UINT8)GetLinkManageTiocById(wLinkId);				
					if (chLinkCIId == chLocalId)
					{
						wPhySecId = GetLinkRelatedPhySec(wLinkId);
						chOccState = GetPhySecCurOccupyState(wPhySecId);
						chTrainNum = as_GetLinkTrainNum(wLinkId);

						if ((SECTION_OCCUPY_NO != chOccState) && (0u != chTrainNum))
						{
							/* 找到有车占用的区段 */
							chBreakFlag = FLAG_SET;
						}
						else
						{
							;
						}
					}
					else
					{
						chOtherFlag = FLAG_SET;
					}
					if (j < wLinkSum)
					{
						/* 更新已经计算的最远无车位置*/
						LinkPoint.wLinkId = wLinkId;
						if ((FLAG_SET == chOtherFlag)||(FLAG_SET == chBreakFlag))
						{
							if (DIR_SAME == cDir)
							{
								LinkPoint.dwOffset = 0U;
							}
							else
							{
								LinkPoint.dwOffset = GetLinkLengthById(wLinkId);
							}
						}
						else
						{
							if (DIR_SAME == cDir)
							{
								LinkPoint.dwOffset = GetLinkLengthById(wLinkId);
							}
							else
							{
								LinkPoint.dwOffset = 0U;
							}
							if (j < wLinkSum - 1U)
							{	/*检查是否有方向变化点，此处检查，当前link已按既定方向查找完，查下一link，若此时中间有方向变化点，则跨过方向变化点，到下一link改变方向查*/
								cDirectionPointfirst = GetLinkLogicDirChangedById(wszLinkIdBuf[j]);
								cDirectionPointsecond = GetLinkLogicDirChangedById(wszLinkIdBuf[(j + 1U)]);		/*wLinkSum已检查越界*/
								if (((LINK_DIRCHANGE_BEGIN == cDirectionPointfirst) || (LINK_DIRCHANGE_END == cDirectionPointfirst))
									&& (cDirectionPointsecond == cDirectionPointfirst))
								{
									cDir = ConvertTrainDir(cDir);			/*有方向变化点，转换方向*/
								}
								else
								{
									;	/*没有反向变换点，不考虑变方向*/
								}
							}
							dwLinkLen += GetLinkLengthById(wLinkId); /*未中断遍历，无车且属于本联锁，更新已计算link总长*/
						}
					}
					else
					{
						; /*最后一个link 无需更新*/
					}
					
					if ((dwFindLen <= dwLinkLen)|| (FLAG_SET == chOtherFlag) || (FLAG_SET == chBreakFlag))
					{
						/*距离足够 或查找到相邻RC，或查找到占用，停止计算*/
						break;
					}
					else
					{
						; /*无处理*/
					}
				}

				/* 获取列车ID 获取距离分界点最近的列车*/
				if ((j < wLinkSum) && (dwFindLen > dwLinkLen))
				{
					if (FLAG_UNSET == chOtherFlag)
					{
						CfpTrainInfoCal(LinkPoint.wLinkId, LinkPoint.dwOffset, dwLinkLen, &tmpTrainInfo, cDir);
					}
					else
					{
						/*找到不属于本联锁link 寻找对应联锁及分界点列车信息*/
						OtherCfpTrainInfoCal(LinkPoint.wLinkId, LinkPoint.dwOffset, dwLinkLen, &tmpTrainInfo);
					}
				}
				else
				{
					/* 未找到有车占用 或空闲距离足够发送无车 */
					tmpTrainInfo.wTrainId = 0u;
					tmpTrainInfo.chTrainLevel = 0u;
					tmpTrainInfo.dwDis = 0u;
				}
			}
			else
			{
				/* 点灯区段查找失败发送故障车 */
				tmpTrainInfo.wTrainId = SIZE_MAX_LINETRAIN;
				tmpTrainInfo.chTrainLevel = 0u;
				tmpTrainInfo.dwDis = 0u;
			}

			SetCfpLocalOcTrainInfo(wCutoffPointId, tmpTrainInfo);
			SetCfpLocalOcEData(wCutoffPointId);
			SetCfpLocalOcCtData(wCutoffPointId);
			CutoffPointRRMDataClearPro(wCutoffPointId);  /*周期检查，清除对应分界点中的RRM数据*/
		}
	}
	else
	{
		;/* 无处理 */
	}
}

/**
* @brief 获取分界点相邻OC发来的包络数量
* @param wCfpId 分界点ID
* @return 包络数量
*/
UINT16 GetCfpOtherOcENum(const UINT16 wCfpId)
{
	UINT16 wRetVal = 0u;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		wRetVal = g_CutoffPointDataBuf[wIndex].chOtherTiocEnvelopeNum;
	}
	else
	{
		wRetVal = UINT16_MAX;
	}
	return wRetVal;
}

/**
* @brief 获取分界点相邻OC发来的包络存储地址
* @param wCfpId 分界点ID
* @return 包络存储地址
*/
CfpEnvelopeStruct * GetCfpOtherOcEData(const UINT16 wCfpId)
{
	CfpEnvelopeStruct * pRetVal = NULL;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		pRetVal = g_CutoffPointDataBuf[wIndex].szOtherEnvelope;
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}

/**
* @brief 获取分界点发送给相邻OC的包络数量
* @param wCfpId 分界点ID
* @return 包络数量
*/
UINT8 GetCfpLocalOcENum(const UINT16 wCfpId)
{
	UINT8 chRetVal = 0u;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}
	return chRetVal;
}

/**
* @brief 获取分界点发送给相邻OC的包络存储地址
* @param wCfpId 分界点ID
* @return 包络存储地址
*/
CfpEnvelopeStruct * GetCfpLocalOcEData(const UINT16 wCfpId)
{
	CfpEnvelopeStruct * pRetVal = NULL;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		pRetVal = g_CutoffPointDataBuf[wIndex].szLocalEnvelope;
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}

/**
* @brief 设置分界点相邻OC发来的包络数量
* @param wCfpId 分界点ID
* @param UINT16 wNum 包络数量
* @return 无
*/
void SetCfpOtherOcENum(const UINT16 wCfpId, const UINT16 wNum)
{
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		g_CutoffPointDataBuf[wIndex].chOtherTiocEnvelopeNum = (UINT8)wNum;
	}
	else
	{
		;
	}
}

/**
* @brief 设置分界点相邻OC发来的包络数据
* @param wCfpId 分界点ID
* @param UINT8 chEnvelopeIndex 包络索引
* @param CfpEnvelopeStruct strEnvelope 包络数据
* @return 无
*/
void SetCfpOtherOcEData(const UINT16 wCfpId, const UINT8 chEnvelopeIndex, const CfpEnvelopeStruct strEnvelope)
{
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if ((CUTOFF_POINT_SUM_MAX > wIndex) && (SECTION_REL_ENVELOPE_SUM_MAX > chEnvelopeIndex))
	{
		g_CutoffPointDataBuf[wIndex].szOtherEnvelope[chEnvelopeIndex] = strEnvelope;
	}
	else
	{
		;
	}
}

/**
* @brief 设置分界点发送给相邻OC的包络数据
* @param wCfpId 分界点ID
* @return 无
* @note 内部优化 20220419 wqm 编码规范：函数dsuCheckSameLoc返回值需要变量承接
* @note 内部优化 20260413 相邻联锁发送按照分界点计轴向内方计算一个ARB防护距离
*/
void SetCfpLocalOcEData(const UINT16 wCfpId)
{
	UINT16 wIndex = 0u;
	UINT8 chEnvelopeNum = 0u;
	UINT16 wLinkId = 0u;
	UINT16 tmpACCnt = 0U;
	UINT16 tmpAcIdBuf[AC_MAXCNT_IN_SWITCH] = { 0U };
	UINT8 chEnvelopeIndex = 0u;
	EnvelopeStruct szTmpEnvelope[SECTION_REL_ENVELOPE_SUM_MAX] = { 0u };
	UINT8 chLocalId = 0u;
	UINT16 wLinkTioc = 0u;
	UINT16 wArbProtectDis = GetSystemParaValue(ARB_CHECK_ALXE_SEC_LEN);
	UINT32 dwCheckAcLen = 0U; /*找到计轴长度*/
	UINT32 dwFirstStepAcLen = 0U; /*找到计轴长度*/
	UINT32 dwArbProtectLen = 0U;/*ARB防护距离*/
	UINT8 chLocalCiType = 0U;
	UINT8 chDir = 0U; /*分界点计轴方向*/
	UINT8 chFirstStepAcCnt = 0U;
	UINT16 wFirstStepID[AC_MAXCNT_IN_SWITCH] = { 0U };
	UINT8 chSndStepAcCnt = 0U;
	UINT16 wSndStepID[AC_MAXCNT_IN_SWITCH] = { 0U }; 
	UINT8 chChangePoint = 0U;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 chCfpAcIndex = 0U;
	UINT8 chStepCheck = CI_ERROR;
	UINT8 chNextDir = 0U;
	UINT8 chPointNum = 0u;					
	UINT8 chAcBelongTioc = 0U;
	UINT8 chFail = CI_SUCCESS;
	wIndex = GetCfpBufIndex(wCfpId);
	chLocalId = GetSystemParaLocalCiId();
	dwArbProtectLen = (UINT32)(wArbProtectDis * 100U);
	chLocalCiType = GetLocalCiType();
	/* 输入合法 */
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		wLinkId = GetCfpInFirstLink(wCfpId);
		/*清除脏数据*/
		g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum = 0U;
		(void)CommonMemSet(&g_CutoffPointDataBuf[wIndex].szLocalEnvelope, (UINT32)((OTHER_RC_SEND_ENVELOPE_SUM_MAX)*sizeof(CfpEnvelopeStruct)), 0U, (UINT32)((OTHER_RC_SEND_ENVELOPE_SUM_MAX)*sizeof(CfpEnvelopeStruct)));
		chStepCheck = GetAxisSeqFromLinkSeq(&wLinkId, 1u, tmpAcIdBuf, &tmpACCnt, AC_MAXCNT_IN_SWITCH);
		chDir = GetCfpLocDir(wCfpId);
		if ((CI_SUCCESS == chStepCheck) && (0u != tmpACCnt))
		{
			for (chCfpAcIndex = 0U; chCfpAcIndex < tmpACCnt; chCfpAcIndex++)
			{
				chEnvelopeNum = elm_GetEnvelopeInAC(tmpAcIdBuf[chCfpAcIndex], szTmpEnvelope);
				chFail = CI_SUCCESS;
				if (SECTION_REL_ENVELOPE_SUM_MAX == chEnvelopeNum)
				{
					/*查找失败 添加坏车包络*/
					chEnvelopeNum = 1U;
					(void)elm_CreatTempUKTEnvelope(tmpAcIdBuf[chCfpAcIndex], chDir, &szTmpEnvelope[0]);
				}
				/*将包络信息添加到分界点动态数据 */
				g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum += chEnvelopeNum;
				
				for (chEnvelopeIndex = 0U; chEnvelopeIndex < chEnvelopeNum; chEnvelopeIndex++)
				{
					chStepCheck = CutCfpOtherOcEData(tmpAcIdBuf[chCfpAcIndex], &szTmpEnvelope[chEnvelopeIndex], chDir);
					if (CI_ERROR == chStepCheck)
					{
						/*截取失败设置坏车*/
						(void)elm_CreatTempUKTEnvelope(tmpAcIdBuf[chCfpAcIndex], chDir, &szTmpEnvelope[chEnvelopeIndex]);
					}
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].envelopeType = szTmpEnvelope[chEnvelopeIndex].envelopeType;
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].headTrainID = szTmpEnvelope[chEnvelopeIndex].headTrainID;
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].tailTrainID = szTmpEnvelope[chEnvelopeIndex].tailTrainID;
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos = szTmpEnvelope[chEnvelopeIndex].startPos;
					wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk);
					/* 内部优化 20220419 wqm 编码规范：函数dsuCheckSameLoc返回值需要变量承接*/
					if (wLinkTioc != chLocalId)
					{
						(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk, \
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Off, \
							&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk, \
							&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Off);
					}
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos = szTmpEnvelope[chEnvelopeIndex].endPos;
					wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk);
					if (wLinkTioc != chLocalId)
					{
						(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk, \
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Off, \
							&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk, \
							&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Off);
					}
					g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trianCnt = szTmpEnvelope[chEnvelopeIndex].trianCnt;
					(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trainID, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trainID), \
						szTmpEnvelope[chEnvelopeIndex].trainID, (UINT32)sizeof(szTmpEnvelope[chEnvelopeIndex].trainID));

					(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].ACTPort, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].ACTPort), \
						szTmpEnvelope[chEnvelopeIndex].ACTPort, (UINT32)sizeof(szTmpEnvelope[chEnvelopeIndex].ACTPort));
				}

				if (0U == chEnvelopeNum)
				{
					/*分界点无包络计轴 向本联锁内方继续查找*/
					chStepCheck = GetAcSwitchPosCheck(tmpAcIdBuf[chCfpAcIndex]);/*本计轴道岔位置不满足时停止检查*/
					dwCheckAcLen = GetAxisSecTotalLen(tmpAcIdBuf[chCfpAcIndex]);
					if ((dwArbProtectLen > dwCheckAcLen) && (CI_TYPE_CLD != chLocalCiType)&&(CI_SUCCESS == chStepCheck))
					{
						chFirstStepAcCnt = elm_PrepareAdjacentAC(tmpAcIdBuf[chCfpAcIndex], chDir, wFirstStepID, &chChangePoint);
						if (AC_MAXCNT_IN_SWITCH < chFirstStepAcCnt)
						{
							chFail = CI_ERROR;
							(void)elm_CreatTempUKTEnvelope(tmpAcIdBuf[chCfpAcIndex], chDir, &szTmpEnvelope[0]);
							(void)CutCfpOtherOcEData(tmpAcIdBuf[chCfpAcIndex], &szTmpEnvelope[0], chDir);
						}
						else
						{
							for (ii = 0U; ii < chFirstStepAcCnt; ii++)
							{
								chAcBelongTioc = GetAxisSectionBelongCiId(tmpAcIdBuf[chCfpAcIndex]);
								if (chAcBelongTioc == chLocalId)
								{
									chStepCheck = SetCfpLocalArbDistanceData(wFirstStepID[ii], wCfpId, chDir);
									dwFirstStepAcLen = GetAxisSecTotalLen(wFirstStepID[ii]);
									if ((dwArbProtectLen > (dwCheckAcLen + dwFirstStepAcLen)) && (CI_SUCCESS == chStepCheck))
									{
										chNextDir = TransDirectionPointDir(chChangePoint, chDir, &chPointNum);
										chSndStepAcCnt = elm_PrepareAdjacentAC(wFirstStepID[ii], chNextDir, wSndStepID, &chChangePoint);
										if (AC_MAXCNT_IN_SWITCH < chFirstStepAcCnt)
										{
											chFail = CI_ERROR;
											(void)elm_CreatTempUKTEnvelope(wFirstStepID[ii], chNextDir, &szTmpEnvelope[0]);
											(void)CutCfpOtherOcEData(wFirstStepID[ii], &szTmpEnvelope[0], chNextDir);
										}
										else
										{
											for (jj = 0U; jj < chSndStepAcCnt; jj++)
											{
												chAcBelongTioc = GetAxisSectionBelongCiId(tmpAcIdBuf[chCfpAcIndex]);
												if (chAcBelongTioc == chLocalId)
												{
													(void)SetCfpLocalArbDistanceData(wSndStepID[jj], wCfpId, chNextDir);
												}
												/*不继续添加*/
											}
										}
									}
									else
									{
										;/*不查找下一计轴*/
									}
								}
							}
						}
						if (CI_ERROR == chFail)
						{
							/* 异常防护 生成UKT*/
							chEnvelopeIndex = g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum;
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].envelopeType = szTmpEnvelope[0].envelopeType;
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].headTrainID = szTmpEnvelope[0].headTrainID;
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].tailTrainID = szTmpEnvelope[0].tailTrainID;
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos = szTmpEnvelope[0].startPos;
							wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk);
							/* 内部优化 20220419 wqm 编码规范：函数dsuCheckSameLoc返回值需要变量承接*/
							if (wLinkTioc != chLocalId)
							{
								(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk, \
									g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Off, \
									&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Lnk, \
									&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].startPos.Off);
							}
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos = szTmpEnvelope[0].endPos;
							wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk);
							if (wLinkTioc != chLocalId)
							{
								(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk, \
									g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Off, \
									&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Lnk, \
									&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].endPos.Off);
							}
							g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trianCnt = szTmpEnvelope[0].trianCnt;
							(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trainID, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].trainID), \
								szTmpEnvelope[0].trainID, (UINT32)sizeof(szTmpEnvelope[0].trainID));

							(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].ACTPort, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[chEnvelopeIndex].ACTPort), \
								szTmpEnvelope[0].ACTPort, (UINT32)sizeof(szTmpEnvelope[0].ACTPort));
							g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum++;
						}
					}
				}
				else
				{
					;/*找到列车包络 不再查找该计轴后续方向*/
				}
			}
		}
		else
		{

		}
	
	
	}
	else
	{
		;
	}
}

/**
* @brief 获取相邻OC发来的包络
* @param UINT16 wOtherOc 相邻OC编号
* @param CfpEnvelopeStruct szEnvelope 包络数据
* @return 包络数量
*/
UINT8 GetOtherOcEnvelope(const UINT16 wOtherOc, CfpEnvelopeStruct szEnvelope[OTHER_RC_SEND_ENVELOPE_SUM_MAX * ONE_OTHER_CFP_SUM_MAX])
{
	UINT16 wCfpIndex = 0u;
	UINT16 wCfpId = 0u;
	UINT16 wOcId = 0u;
	UINT8 chEnvelopeNum = 0u;
	UINT16 chCfpENum = 0u;
	CfpEnvelopeStruct * pCfpEData = NULL;
	UINT16 wCfgSum = GetCfpSum();
	for (wCfpIndex = 0u; wCfpIndex < wCfgSum; wCfpIndex++)
	{
		wCfpId = GetCfpId(wCfpIndex);
		wOcId = GetCfpOtherTioc(wCfpId);
		if (wOcId == wOtherOc)
		{/* 获取指定分界点相邻TIOC发来的包络信息 */
			chCfpENum = GetCfpOtherOcENum(wCfpId);
			pCfpEData = GetCfpOtherOcEData(wCfpId);
			if ((NULL != pCfpEData) && (0u != chCfpENum) && (UINT16_MAX != chCfpENum))
			{/* 将相同TIOC，不通分界点的包络组合在一起 */
				(void)CommonMemCpy(&szEnvelope[chEnvelopeNum], (UINT32)(chCfpENum * sizeof(CfpEnvelopeStruct)), \
					pCfpEData, (UINT32)(chCfpENum * sizeof(CfpEnvelopeStruct)));
				chEnvelopeNum += (UINT8)chCfpENum;
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}
	}
	return chEnvelopeNum;
}

/**
* @brief 设置分界点发送给相邻OC的通信列车数据
* @param wCfpId 分界点ID
* @return 无
* @note
*/
void SetCfpLocalOcCtData(const UINT16 wCfpId)
{
	UINT16 wIndex = 0u;
	UINT8 chCtNum = 0u;
	UINT16 wLinkId = 0u;
	UINT16 wAcId = 0u;
	UINT8 chCtIndex = 0u;
	UINT16 szCtTrainId[TRAIN_SUM_MAX] = { 0u };
	UINT8 chSendNum = 0u;
	UINT8 chFunRtn = CI_ERROR;
	struct_PathPoint strPoint = { 0u };

	wIndex = GetCfpBufIndex(wCfpId);
	/* 输入合法 */
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		strPoint.wLinkId = GetCfpLink(wCfpId);
		strPoint.dwOffset = GetCfpOffset(wCfpId);
		wLinkId = GetCfpInFirstLink(wCfpId);
		wAcId = GetLinkBelongAcId(wLinkId);
		chCtNum = GetTrainInAc(wAcId, szCtTrainId);
		for (chCtIndex = 0u; chCtIndex < chCtNum; chCtIndex++)
		{
			chFunRtn = IsTrainMoveToPoint(szCtTrainId[chCtIndex], strPoint);
			if (CI_SUCCESS == chFunRtn)
			{
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wTrainId = szCtTrainId[chCtIndex];
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].chLevel = GetTrainLevel(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].dwDelay = GetTrainMsgDelayTime(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wSpeed = GetTrainSpeed(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].chSpeedDir = GetTrainSpeedDir(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].chTrainDir = GetTrainDir(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wMaxHeadLink = GetTrainMaxHeadLink(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].dwMaxHeadOff = GetTrainMaxHeadOffset(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wMinHeadLink = GetTrainMinHeadLink(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].dwMinHeadOff = GetTrainMinHeadOffset(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wMaxTailLink = GetTrainMaxTailLink(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].dwMaxTailOff = GetTrainMaxTailOffset(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].wMinTailLink = GetTrainMinTailLink(szCtTrainId[chCtIndex]);
				g_CutoffPointDataBuf[wIndex].szLocalCtTrain[chSendNum].dwMinTailOff = GetTrainMinTailOffset(szCtTrainId[chCtIndex]);
				chSendNum++;
			}
			else
			{
				;
			}
		}
		g_CutoffPointDataBuf[wIndex].chCtNum = chSendNum;
	}
	else
	{
		;
	}
}

/**
* @brief 获取分界点发送给相邻OC的通信车地址
* @param wCfpId 分界点ID
* @return 通信车存储地址
*/
CfpCtTrainStruct * GetCfpLocalOcCtData(const UINT16 wCfpId)
{
	CfpCtTrainStruct * pRetVal = NULL;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		pRetVal = g_CutoffPointDataBuf[wIndex].szLocalCtTrain;
	}
	else
	{
		pRetVal = NULL;
	}
	return pRetVal;
}

/**
* @brief 获取分界点发送给相邻OC的通信车数量
* @param wCfpId 分界点ID
* @return 通信车数量
*/
UINT8 GetCfpLocalOcCtNum(const UINT16 wCfpId)
{
	UINT8 chRtn = 0u;
	UINT16 wIndex = 0u;
	wIndex = GetCfpBufIndex(wCfpId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRtn = g_CutoffPointDataBuf[wIndex].chCtNum;
	}
	else
	{
		chRtn = UINT8_MAX;
	}
	return chRtn;
}

/**
* @brief 截取分界点相邻OC发来的包络数据
* @param wAcId 截取计轴ID UINT8 chDir 方向
* @param EnvelopeStruct* strEnvelope 包络数据
* @return CI_ ERROR 截取失败
*	      CI_ SUCCESS 截取成功
* by cgh 20240111
* modify fan20260413：按照计轴进行包络截取
*/
UINT8 CutCfpOtherOcEData(const UINT16 wAcId, EnvelopeStruct* strEnvelope, UINT8 chDir)
{
	UINT8 chReval = CI_ERROR;
	UINT8 chAxieIncLinkSum = 0U;/*计轴区段包含LINK数目*/
	UINT16* szAxieIncLink = NULL;/*计轴区段包含LINK*/
	UINT8 ii = 0U;
	UINT8 chKeepFlag = 0U;/*继续执行标志*/
	UINT8 chEnvelopeStartFlag = 0U;/*包络始端是否在计轴区段标志*/
	UINT8 chEnvelopeEndFlag = 0U;/*包络终端是否在计轴区段标志*/
	ELM_AxisLocStruct tmpAxieSecLoc = { 0U };/*计轴区段位置*/

	if (AXIS_SECTION_SUM_MAX > wAcId)
	{
		/*只截取UCT包络*/
		if ((TYPE_UCT_ENVELOPE == strEnvelope->envelopeType) || (TYPE_CT_ENVELOPE == strEnvelope->envelopeType))
		{
			chAxieIncLinkSum = GetAxisLinkSum(wAcId);
			szAxieIncLink = GetAxisLinkIdBuf(wAcId);
			chKeepFlag = elm_PrepareACLoc(wAcId, chDir, &tmpAxieSecLoc);

			if (CI_SUCCESS == chKeepFlag)
			{
				for (ii = 0U; ii < chAxieIncLinkSum; ii++)
				{
					if (szAxieIncLink[ii] == strEnvelope->startPos.Lnk)
					{
						chEnvelopeStartFlag = CI_SUCCESS;
						break;
					}
					else
					{
						; /*继续找*/
					}
				}

				for (ii = 0U; ii < chAxieIncLinkSum; ii++)
				{
					if (szAxieIncLink[ii] == strEnvelope->endPos.Lnk)
					{
						chEnvelopeEndFlag = CI_SUCCESS;
						break;
					}
					else
					{
						; /*继续找*/
					}
				}

				chReval = CI_SUCCESS;
				if ((CI_SUCCESS == chEnvelopeStartFlag) && (CI_SUCCESS == chEnvelopeEndFlag))
				{
					; /*包络始端端均在计轴区段内，不截取*/
				}
				else if (CI_SUCCESS == chEnvelopeStartFlag)
				{
					/*包络始端在计轴区段内*/
					strEnvelope->endPos.Dir = strEnvelope->startPos.Dir;
					if (EMAP_SAME_DIR == strEnvelope->startPos.Dir)
					{
						/*包络始端方向为逻辑正方向，截取的包络终端为计轴区段终点*/
						strEnvelope->endPos.Lnk = tmpAxieSecLoc.endPos.Lnk;
						strEnvelope->endPos.Off = tmpAxieSecLoc.endPos.Off;
					}
					else
					{
						/*包络始端方向为逻辑反方向，截取的包络终端为计轴区段起点*/
						strEnvelope->endPos.Lnk = tmpAxieSecLoc.startPos.Lnk;
						strEnvelope->endPos.Off = tmpAxieSecLoc.startPos.Off;
					}
				}
				else if (CI_SUCCESS == chEnvelopeEndFlag)
				{
					/*包络终端在计轴区段内*/
					strEnvelope->startPos.Dir = strEnvelope->endPos.Dir;
					if (EMAP_SAME_DIR == strEnvelope->endPos.Dir)
					{
						/*包络尾方向为逻辑正方向，截取的包络终端为计轴区段起点*/
						strEnvelope->startPos.Lnk = tmpAxieSecLoc.startPos.Lnk;
						strEnvelope->startPos.Off = tmpAxieSecLoc.startPos.Off;
					}
					else
					{
						/*包络尾方向为逻辑反方向，截取的包络终端为计轴区段终点*/
						strEnvelope->startPos.Lnk = tmpAxieSecLoc.endPos.Lnk;
						strEnvelope->startPos.Off = tmpAxieSecLoc.endPos.Off;
					}
				}
				else
				{
					chReval = CI_ERROR;
				}
			}
			else
			{
				;  /*返回失败*/
			}
		}
		else
		{
			/*其他包络类型不截取，保留原数据*/
			chReval = CI_SUCCESS;
		}
	}
	else
	{
		; /*分界点ID超限，返回失败*/
	}

	return chReval;
}

/**
* @brief 获取分界点跨控区RRM源RC ID
* @param const UINT16 wCfpId 分界点ID
* @return 0 获取失败，其它 源RC ID
* Created By LQ 20240229
*/
UINT8 GetCfpRrmSrcRcId(const UINT16 wCfpId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].szCfpRRMData.cRrmSrcRcId;
	}
	else
	{
		;
	}

	return chRetVal;
}

/**
* @brief 设置分界点跨控区RRM源RC ID
* @param wCfpId 分界点ID
* @param const UINT8 chSrcRcId 源RC ID
* @return 无
* Created By LQ 20240229
*/
void SetCfpRrmSrcRcId(const UINT16 wCfpId, const UINT8 chSrcRcId)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && ((0U < chSrcRcId) || (CI_SUM_MAX > chSrcRcId)))
	{
		g_CutoffPointDataBuf[wIndex].szCfpRRMData.cRrmSrcRcId = chSrcRcId;
	}
	else
	{
		;
	}
}

/**
* @brief 获取分界点跨控区RRM源TIOC申请状态
* @param wCfpId 分界点ID
* @return 跨控区RRM源TIOC申请状态
* by cgh 20240220
*/
UINT8 GetCfpRrmSrcApplyState(const UINT16 wCfpId)
{
	UINT8 chRetVal = TRAIN_RRM_LOCALCI_NOT_APPLY;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmSrcApplyState;
	}
	else
	{
		; 
	}
	return chRetVal;
}

/**
* @brief 设置分界点跨控区RRM源TIOC申请状态
* @param wCfpId 分界点ID
* @param const UINT8 chRrmSrcApplyState RRM源TIOC申请状态
* @return 无
* by cgh 20240221
*/
void SetCfpRrmSrcApplyState(const UINT16 wCfpId,const UINT8 chRrmSrcApplyState)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && ((TRAIN_RRM_LOCALCI_NOT_APPLY == chRrmSrcApplyState) || (TRAIN_RRM_LOCALCI_APPLY == chRrmSrcApplyState)))
	{
		g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmSrcApplyState = chRrmSrcApplyState;
	}
	else
	{
		;
	}
}

/**
* @brief 获取分界点跨控区RRM目标TIOC允许状态
* @param wCfpId 分界点ID
* @return 跨控区RRM目标TIOC允许状态
* by cgh 20240220
*/
UINT8 GetCfpRrmDstAllowState(const UINT16 wCfpId)
{
	UINT8 chRetVal = TRAIN_RRM_OTHERCI_NOT_ALLOW;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmDstAllowState;
	}
	else
	{
		;
	}
	return chRetVal;
}

/**
* @brief 设置分界点跨控区RRM目标TIOC允许状态
* @param wCfpId 分界点ID
* @param const UINT8 chRrmSrcApplyState RRM目标TIOC允许状态
* @return 无
* by cgh 20240221
*/
void SetCfpRrmDstAllowState(const UINT16 wCfpId, const UINT8 chRrmDstAllowState)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && ((TRAIN_RRM_OTHERCI_ALLOW == chRrmDstAllowState) || (TRAIN_RRM_OTHERCI_NOT_ALLOW == chRrmDstAllowState)))
	{
		g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmDstAllowState = chRrmDstAllowState;
	}
	else
	{
		;
	}
}

/**
* @brief 获取分界点跨控区RRM列车ID
* @param wCfpId 分界点ID
* @return 跨控区RRM列车ID
* by cgh 20240221
*/
UINT16 GetCfpRrmTrainId(const UINT16 wCfpId)
{
	UINT16 chRetVal = 0U;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainId;
	}
	else
	{
		;
	}
	return chRetVal;
}

/**
* @brief 设置分界点跨控区RRM列车ID
* @param wCfpId 分界点ID
* @param const UINT16 wRrmTrainId 跨控区RRM列车ID
* @return 无
* by cgh 20240221
*/
void SetCfpRrmTrainId(const UINT16 wCfpId, const UINT16 wRrmTrainId)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && (LINE_MAX_TRAIN > wRrmTrainId))
	{
		g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainId = wRrmTrainId;
	}
	else
	{
		;
	}
}

/**
* @brief 获取分界点跨控区RRM列车申请的下一站台ID
* @param wCfpId 分界点ID
* @return RRM列车申请的下一站台ID
* by cgh 20240221
*/
UINT16 GetCfpRrmTrainNextStaId(const UINT16 wCfpId)
{
	UINT16 chRetVal = 0U;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		chRetVal = g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainNextStaId;
	}
	else
	{
		;
	}
	return chRetVal;
}

/**
* @brief 设置分界点跨控区RRM列车申请的下一站台ID
* @param wCfpId 分界点ID
* @param const UINT16 wRrmTrainNextStaId RRM列车申请的下一站台ID
* @return 无
* by cgh 20240221
*/
void SetCfpRrmTrainNextStaId(const UINT16 wCfpId, const UINT16 wRrmTrainNextStaId)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && (UINT16_MAX > wRrmTrainNextStaId))
	{
		g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainNextStaId = wRrmTrainNextStaId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 相邻TIOC通信良好，RRM处理
* 参数说明： UINT8 chTiocId 相邻TIOC编号
* 返回值  ： 无
* by cgh 20240221
*/
void NeighborGoodRrmProc(UINT8 chTiocId)
{
	UINT8 ii = 0U;
	UINT16 wCutoffPointSum = 0U;/*本TIOC分界点数目*/
	UINT16 wCutoffPointId = 0U;/*分界点ID*/
	UINT16 wOtherTiocId = 0U;/*分界点对方TIOC ID*/
	UINT8 cLocalCiId = 0U;
	UINT8 cRrmSrcRcId = 0U;  /*RRM源RCID*/
	UINT16 wRrmTrainId = 0U;  /*RRM列车ID*/
	UINT16 wRrmStationId = 0U;  /*RRM站台ID*/
	UINT8 cRrmSrcRcApplyState = TRAIN_RRM_LOCALCI_NOT_APPLY;
	UINT8 chCheckResult = CI_ERROR;/*检查结果*/
	UINT16 wCfpAxisSecIdBuf[CUTOFF_POINT_SUM_MAX] = { 0U };/*分界点计轴区段*/
	UINT8 chAxisSecSum = 0U;/*计轴区段数目*/
	UINT8 chLocDir = 0U;
	UINT16 wCfpAxisSecId = 0U;  /*本分界点处的计轴区段ID*/

	if ((0U < chTiocId) && (CI_SUM_MAX > chTiocId))
	{
		wCutoffPointSum = GetCfpSum();
		cLocalCiId = GetSystemParaLocalCiId();
		for (ii = 0U; ii < wCutoffPointSum; ii++)
		{
			wCutoffPointId = GetCfpId(ii);
			wOtherTiocId = GetCfpOtherTioc(wCutoffPointId);
			cRrmSrcRcId = GetCfpRrmSrcRcId(wCutoffPointId);
			cRrmSrcRcApplyState = GetCfpRrmSrcApplyState(wCutoffPointId);
			if ((chTiocId == wOtherTiocId) && (cLocalCiId != cRrmSrcRcId) && (TRAIN_RRM_LOCALCI_APPLY == cRrmSrcRcApplyState))
			{
				/*仅当本RC非源RC且源RC申请RMM，才进行处理*/
				chAxisSecSum = elm_PrepareCfpAc(wCfpAxisSecIdBuf);
				chLocDir = GetCfpLocDir(wCutoffPointId);
				
				if ((0U < chAxisSecSum) && (CUTOFF_POINT_SUM_MAX > chAxisSecSum) && ((EMAP_CONVER_DIR == chLocDir) || (EMAP_SAME_DIR == chLocDir)))
				{
					wCfpAxisSecId = GetAxisSecIdAccordCfpId(wCutoffPointId, chAxisSecSum, wCfpAxisSecIdBuf);  /*获取分界点处的计轴区段ID*/

					if (CI_ERROR != wCfpAxisSecId)
					{
						wRrmTrainId = GetCfpRrmTrainId(wCutoffPointId);
						wRrmStationId = GetCfpRrmTrainNextStaId(wCutoffPointId);
						chCheckResult = rrm_OtherCiConditionsCheck(wRrmTrainId, wRrmStationId, wCfpAxisSecId, chLocDir);
					}
					else
					{
						/*获取计轴区段失败，不处理*/
					}
				}
				else
				{
					; /*不检查，默认失败*/
				}

				if (CI_SUCCESS == chCheckResult)
				{
					SetCfpRrmDstAllowState(wCutoffPointId, TRAIN_RRM_OTHERCI_ALLOW);
				}
				else
				{
					/*分界点相邻CI 条件检查不通过，目标TIOC不允许*/
					SetCfpRrmDstAllowState(wCutoffPointId, TRAIN_RRM_OTHERCI_NOT_ALLOW);
				}
			}
			else
			{
				/*分界点对方CI ID不是指定CI或无RRM跨控区申请，不处理*/
			}
		}
	}
	else
	{
		; /*相邻联锁ID不合法不处理*/
	}
}


/*
* 功能描述：根据分界点ID获取本分界点处的计轴区段ID
* 参数说明：UINT16 wCfpId 分界点ID
*           UINT8 cAxisSecNum 计轴区段数量
*           UINT16 pAxisSecIdBuf[CUTOFF_POINT_SUM_MAX] 计轴区段ID数组
* 返回值  ：CI_ERROR 0 获取失败
*           其它 计轴区段ID
* Created by LQ 20240227
*/
UINT16 GetAxisSecIdAccordCfpId(UINT16 wCfpId, UINT8 cAxisSecNum, UINT16 pAxisSecIdBuf[CUTOFF_POINT_SUM_MAX])
{
	UINT16 retVal = CI_ERROR;
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wCutoffPointFstLinkId = 0U;  /*分界点内方第一link ID*/
	UINT16* pAxleSecIncLinkId = NULL;  /*计轴区段包含的link ID*/
	UINT8 cAxleSecIncLinkNum = 0U;  /*计轴区段包含的link数量*/

	if ((0U < wCfpId) && (CUTOFF_POINT_SUM_MAX > wCfpId) && (0U < cAxisSecNum) && (CUTOFF_POINT_SUM_MAX >= cAxisSecNum) && (NULL != pAxisSecIdBuf))
	{
		wCutoffPointFstLinkId = GetCfpInFirstLink(wCfpId);

		for (ii = 0U; ii < cAxisSecNum; ii++)
		{
			pAxleSecIncLinkId = GetAxisLinkIdBuf(pAxisSecIdBuf[ii]);
			cAxleSecIncLinkNum = GetAxisLinkSum(pAxisSecIdBuf[ii]);

			if ((0U < cAxleSecIncLinkNum) && (AXIS_INCLUDE_LINK_SUM_MAX >= cAxleSecIncLinkNum) && (NULL != pAxleSecIncLinkId))
			{
				for (jj = 0U; jj < cAxleSecIncLinkNum; jj++)
				{
					if ((wCutoffPointFstLinkId == pAxleSecIncLinkId[jj]) && (0U != wCutoffPointFstLinkId))
					{
						retVal = pAxisSecIdBuf[ii];  /*计轴区段包含的link为分界点内方第一link，即为分界点处的计轴区段*/
						break;
					}
					else
					{
						/*继续检查*/
					}
				}

				if (CI_ERROR != retVal)
				{
					break;  /*找到分界点处计轴区段，停止遍历*/
				}
				else
				{
					/*继续检查*/
				}
			}
			else
			{
				/*不处理*/
			}
		}
	}
	else
	{
		/*入参非法，返回0失败*/
	}

	return retVal;
}

/*
* 功能描述：分界点RRM数据清除处理
* 参数说明：const UINT16 wCutoffPointId  分界点ID
* 返回值  ：无
* Created By CGH 2024.07.29
*/
void CutoffPointRRMDataClearPro(const UINT16 wCutoffPointId)
{
	UINT16 ii = 0U;
	UINT16 wIndex = 0u;
	UINT16 wTrainId = 0U;
	UINT8 cLocalCiId = 0U;
	UINT8 cRrmSrcRcId = 0U;
	UINT8 cElmNum = 0u;
	EnvelopeStruct* pEnvelop = NULL;
	UINT16 szEnvelopeId[TRAIN_REL_ENVELOPE_SUM_MAX] = { 0u };
	UINT8 cRRMRequstState = TRAIN_RRM_RQST_NO;
	UINT8 cClearFlag = FLAG_UNSET;
	UINT16 wCutoffPointSum = 0U;  /*本控区分界点数量*/
	UINT16 wOtherCfpId = 0U;  /*其它分界点ID*/
	UINT16 wOtherCfpTrainId = 0U;  /*其它分界点RRM列车ID*/
	UINT8 cOtherCfpSrcRcId = 0U;  /*其它分界点RRM源RCID*/
	UINT8 cRrmReason = TRAIN_RRM_RESON_FF;
	UINT8 cOtherRcRrmReason = TRAIN_RRM_RESON_FF;

	wIndex = GetCfpBufIndex(wCutoffPointId);
	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		wTrainId = GetCfpRrmTrainId(wCutoffPointId);

		/*判断分界点内是否存在跨控区的RRM列车*/
		if ((0U < (wTrainId & 0x00FFU)) && (TRAIN_SUM_MAX > (wTrainId & 0x00FFU)))
		{
			cLocalCiId = GetSystemParaLocalCiId();
			cRrmSrcRcId = GetCfpRrmSrcRcId(wCutoffPointId);

			/*判断分界点RRM内的源RC是否为本控区*/
			if ((cLocalCiId == cRrmSrcRcId) && (0U != cRrmSrcRcId))
			{
				cElmNum = elm_GetTrainRelELM(wTrainId, szEnvelopeId);
				pEnvelop = elm_GetEnvelopeInfoByID(szEnvelopeId[0u]);

				/*判断列车是否为UCT或CT包络*/
				if ((1U == cElmNum) && (NULL != pEnvelop) && ((TYPE_UCT_ENVELOPE == pEnvelop->envelopeType) || (TYPE_CT_ENVELOPE == pEnvelop->envelopeType)))
				{
					cRRMRequstState = GetTrainRrmRqst(wTrainId);

					/*判断列车是否申请RRM*/
					if (TRAIN_RRM_RQST_YES == cRRMRequstState)
					{
						/*不处理*/
					}
					else
					{
						cClearFlag = FLAG_SET;  /*列车未申请RRM，清除对应分界点内的RRM数据*/
					}
				}
				else
				{
					wCutoffPointSum = GetCfpSum();  /*获取当前控区的所有的分界点*/
					for (ii = 0u; ii < wCutoffPointSum; ii++)
					{
						wOtherCfpId = GetCfpId(ii);
						if (wOtherCfpId != wCutoffPointId)
						{
							wOtherCfpTrainId = GetCfpRrmTrainId(wOtherCfpId);
							cOtherCfpSrcRcId = GetCfpRrmSrcRcId(wOtherCfpId);
							if ((wOtherCfpTrainId == wTrainId) && (cOtherCfpSrcRcId != cLocalCiId))
							{
								break;  /*在其它分界点中找到此车，表示该RMM从其它控区传来，本RC不能独立清除分界点内的RRM数据*/
							}
						}
						else
						{
							/*本分界点不处理*/
						}
					}

					if (ii == wCutoffPointSum)
					{
						cClearFlag = FLAG_SET;  /*有车且非UCT或CT包络，且其它分界点无车，清除对应分界点内的RRM数据*/
					}
					else
					{
						/*其它分界点有此车，表示RMM由其它控区传来，不能清除对应分界点内的RRM数据*/
					}					
				}

				cRrmReason = GetTrainRrmReson(wTrainId);
				cOtherRcRrmReason = GetTrainOtherRcRrmReson(wTrainId);
				if (((TRAIN_RRM_RESON_15 != cRrmReason) && (TRAIN_RRM_RESON_FF != cRrmReason)) || ((TRAIN_RRM_RESON_15 != cOtherRcRrmReason) && (TRAIN_RRM_RESON_FF != cOtherRcRrmReason)))
				{
					cClearFlag = FLAG_SET;  /*本控区检查不通过，不再向相邻控区发送检查，清除分界点RRM*/
				}
				else
				{
					/*不清除*/
				}

			}
			else
			{
				/*源RC非本控区，不处理*/
			}
		}
		else
		{
			/*无列车，不处理*/
		}

		if (FLAG_SET == cClearFlag)
		{
			/*清除分界点内的RRM数据*/
			g_CutoffPointDataBuf[wIndex].szCfpRRMData.cRrmSrcRcId = 0U;
			g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainId = 0U;
			g_CutoffPointDataBuf[wIndex].szCfpRRMData.wRrmTrainNextStaId = 0U;
			g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmSrcApplyState = TRAIN_RRM_LOCALCI_NOT_APPLY;
			g_CutoffPointDataBuf[wIndex].szCfpRRMData.chRrmDstAllowState = TRAIN_RRM_OTHERCI_NOT_ALLOW;
			SetTrainOtherRcRrmReson(wTrainId, TRAIN_RRM_RESON_FF);
		}
		else
		{
			/*无需清除*/
		}
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/**
* @brief 获取分界点信号机点亮标志
* @param const UINT16 wCfpId 分界点ID
* @return 0x55 点亮标志无效
*         0xAA 点亮标志有效
* Created By LQ 2024.09.03
*/
UINT8 GetCfpSignalLightUpFlag(const UINT16 wCfpId)
{
	UINT8 cRetVal = SIGNAL_SLEEP_TRAIN_LIGHTUP_YES;
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if (CUTOFF_POINT_SUM_MAX > wIndex)
	{
		cRetVal = g_CutoffPointDataBuf[wIndex].cSignalLightUpFlag;
	}
	else
	{
		;
	}

	return cRetVal;
}

/**
* @brief 设置分界点信号机亮灯标志
* @param const UINT16 wCfpId 分界点ID
* @param const UINT8 cLightUpFlag 亮灯标志
* @return 无
* Created By LQ 2024.09.03
*/
void SetCfpSignalLightUpFlag(const UINT16 wCfpId, const UINT8 cLightUpFlag)
{
	UINT16 wIndex = 0U;

	wIndex = GetCfpBufIndex(wCfpId);

	if ((CUTOFF_POINT_SUM_MAX > wIndex) && ((SIGNAL_SLEEP_TRAIN_LIGHTUP_YES == cLightUpFlag) || (SIGNAL_SLEEP_TRAIN_LIGHTUP_NO == cLightUpFlag)))
	{
		g_CutoffPointDataBuf[wIndex].cSignalLightUpFlag = cLightUpFlag;
	}
	else
	{
		;
	}
}
/*
* 功能描述： 根据其他分界点信息更新本联锁发送分界点列车数据
* 参数说明：UINT16 wLinkId 分界点link  ,UINT32 dwOffSet偏移量, UINT32 dwLocalOffSet 本联锁已经查找距离
*			[输出参数]: CfpTrainInfoStru* trainInfo 列车数据
* 返回值  ：无
* Created By fan 2025.05.26
*/
void OtherCfpTrainInfoCal(UINT16 wLinkId,UINT32 dwOffSet,UINT32 dwLocalOffSet, CfpTrainInfoStru* trainInfo)
{
	UINT16 wCfpId = 0U;/*分界点id*/
	UINT8 chTransmitStat = TRANSMIT_STATE_BAD;
	CfpTrainInfoStru strCfpInfo = { 0u };
	UINT8 chLinkTiocId = 0U;
	UINT32 dwDdLen = 0U;/*信号机点灯距离*/
	UINT32 dwLeftOffset = 0U;/*剩余需计算距离*/
	/*数据初始化*/
	dwDdLen =	GetSystemParaValue(SIGNAL_LIGHTUP_SEC_LEN_ID);
	dwDdLen *= 100u;
	wCfpId = GetCfpIdByPoint(wLinkId, dwOffSet);
	if (NULL != trainInfo)
	{
		/*初始化为在该分界点存在故障车*/
		trainInfo->wTrainId = SIZE_MAX_LINETRAIN;
		trainInfo->dwDis = dwLocalOffSet;
		trainInfo->chTrainLevel = 0U;
		if (dwDdLen > dwLocalOffSet)
		{
			dwLeftOffset = dwDdLen - dwLocalOffSet;
		}
		else
		{
			;/*无处理*/
		}
		if (0U != wCfpId)
		{
			chLinkTiocId = (UINT8)GetLinkManageTiocById(wLinkId);
			strCfpInfo = GetCfpOtherOcTrainInfo(wCfpId);
			chTransmitStat = GetCiTransmitState(CI_SYSTEM_TYPE_CI, chLinkTiocId);
			if ((TRANSMIT_STATE_GOOD != chTransmitStat) || (UINT16_MAX == strCfpInfo.wTrainId))
			{
				;/*通信不良好，或者分界点列车信息获取失败*/
			}
			else if ((0u == strCfpInfo.wTrainId) ||
				((UINT32_MAX != strCfpInfo.dwDis) && (dwLeftOffset < strCfpInfo.dwDis)))
			{
				/*相邻Tioc无车 或 距离分界点距离大于剩余查找距离*/
				trainInfo->wTrainId = 0U;
				trainInfo->dwDis = 0U;
				trainInfo->chTrainLevel = 0U;
			}
			else
			{
				/*传递分界点信息*/
				trainInfo->wTrainId = strCfpInfo.wTrainId;
				trainInfo->dwDis = strCfpInfo.dwDis + dwLocalOffSet;
				trainInfo->chTrainLevel = strCfpInfo.chTrainLevel;
			}
		}
		else
		{
			;/*分界点获取失败*/
		}
	}
}

/*
* 功能描述： 本联锁列车数据更新本联锁发送分界点列车数据
* 参数说明：UINT16 wLinkId 分界点link  ,UINT32 dwOffSet偏移量, UINT32 dwLocalOffSet 本联锁已经查找距离 UINT8 cDir 方向
*			[输出参数]: CfpTrainInfoStru* trainInfo 列车数据
* 返回值  ：无
* Created By fan 2025.06.04
*/
void CfpTrainInfoCal(UINT16 wLinkId, UINT32 dwOffSet, UINT32 dwLocalOffSet, CfpTrainInfoStru* trainInfo,UINT8 cDir)
{
	TRAIN_SEQUANCE_s strTmp = { 0u };
	UINT16 wTrainId = 0u;
	UINT32 dwDis = UINT32_MAX;
	UINT32 dwDisTail = UINT32_MAX;
	UINT32 dwDisHead = UINT32_MAX;
	struct_PathPoint TrainHeadPoint = { 0u };
	struct_PathPoint TrainTailPoint = { 0u };
	struct_PathPoint LinkPoint = { 0u };
	UINT8 cTrainTailDir = 0U;			/*列车安全车尾方向*/
	UINT8 cTrainHeadDir = 0U;			/*列车安全车头方向*/
	if ((NULL != trainInfo)&&(0U!= wLinkId))
	{
		LinkPoint.wLinkId = wLinkId;
		LinkPoint.dwOffset = dwOffSet;
		/*占用link属于本联锁*/
		if (DIR_SAME == cDir)
		{
			strTmp = as_GetLinkFirstTrain(wLinkId);
		}
		else
		{
			strTmp = as_GetLinkLastTrain(wLinkId);
		}
		wTrainId = strTmp.u16TrainID;
		/* 存在占用，判断列车类型 */
		if (NAME_FAILUREAREA == strTmp.u16TrainID)
		{
			/* 故障区域 */
			trainInfo->wTrainId = SIZE_MAX_LINETRAIN;
			trainInfo->chTrainLevel = 0u;
			trainInfo->dwDis = dwLocalOffSet;
		}
		else
		{
			/* 正常车 */
			trainInfo->wTrainId = strTmp.u16TrainID;
			trainInfo->chTrainLevel = GetTrainLevel(trainInfo->wTrainId);

			/*获取安全车尾点*/
			TrainTailPoint.wLinkId = GetTrainSafeTailLink(wTrainId);
			TrainTailPoint.dwOffset = GetTrainSafeTailOffset(wTrainId);
			/*获取安全车头点*/
			TrainHeadPoint.wLinkId = GetTrainSafeHeadLink(wTrainId);
			TrainHeadPoint.dwOffset = GetTrainSafeHeadOffset(wTrainId);

			/*获取车尾到已计算link最远端距离*/
			dwDisTail = DsuAPointToBPoint(&TrainTailPoint, &LinkPoint, &cTrainTailDir);

			/*获取车头到已计算link最远端距离*/
			dwDisHead = DsuAPointToBPoint(&TrainHeadPoint, &LinkPoint, &cTrainHeadDir);

			if (dwDisTail < dwDisHead)
			{
				dwDis = dwDisTail;
			}
			else
			{
				dwDis = dwDisHead;
			}
			trainInfo->dwDis = dwLocalOffSet + dwDis;
		}
	}
}
/**
* @brief 根据分界点内方计轴向内查找ARB防护距离内可达计轴上包络
* 输入参数： wAcId 本联锁分界点计轴 wCfpId分界点 UINT8 chDir 方向
* 返回值： CI_SUCCESS(计轴无包络 需继续查找) CI_ERROR（计轴存在包络）
* Create fanwen 2026.4.13
**/
UINT8 SetCfpLocalArbDistanceData(const UINT16 wAcId, const UINT16 wCfpId,UINT8 chDir)
{
	UINT8 retVal = CI_ERROR;
	UINT8 chEnvelopeNum = 0U;
	EnvelopeStruct szTmpEnvelope[SECTION_REL_ENVELOPE_SUM_MAX] = { 0u };
	UINT16 wIndex = GetCfpBufIndex(wCfpId);
	UINT8 ii = 0u;/*索引*/
	UINT8 chLocalId = 0u;
	UINT16 wLinkTioc = 0u;
	UINT8 chCurNum = 0U;
	UINT8 chStepCheck = CI_ERROR;
	chLocalId = GetSystemParaLocalCiId();
	chEnvelopeNum = elm_GetEnvelopeInAC(wAcId, szTmpEnvelope);
	chCurNum = g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum;
	if (SECTION_REL_ENVELOPE_SUM_MAX == chEnvelopeNum)
	{
		/*查找失败 添加坏车包络*/
		chEnvelopeNum = 1U;
		(void)elm_CreatTempUKTEnvelope(wAcId, chDir, &szTmpEnvelope[0]);
	}
	if (0U != chEnvelopeNum)
	{
		if (OTHER_RC_SEND_ENVELOPE_SUM_MAX > chCurNum + chEnvelopeNum)
		{
			/* 将包络信息添加到分界点动态数据 */
			g_CutoffPointDataBuf[wIndex].chLocalTiocEnvelopeNum = chCurNum + chEnvelopeNum;
			for (ii  = 0U;  ii < chEnvelopeNum; ii ++)
			{
				/*仅截取本计轴*/
				chStepCheck = CutCfpOtherOcEData(wAcId, &szTmpEnvelope[ii], chDir);
				if (CI_ERROR == chStepCheck)
				{
					/*截取失败设置坏车*/
					(void)elm_CreatTempUKTEnvelope(wAcId, chDir, &szTmpEnvelope[ii]);
				}
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].envelopeType = szTmpEnvelope[ii].envelopeType;
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].headTrainID = szTmpEnvelope[ii].headTrainID;
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].tailTrainID = szTmpEnvelope[ii].tailTrainID;
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos = szTmpEnvelope[ii].startPos;
				wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos.Lnk);
				/* 内部优化 20220419 wqm 编码规范：函数dsuCheckSameLoc返回值需要变量承接*/
				if (wLinkTioc != (UINT16)chLocalId)
				{
					(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos.Lnk, \
						g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos.Off, \
						&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos.Lnk, \
						&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].startPos.Off);
				}
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos = szTmpEnvelope[ii].endPos;
				wLinkTioc = GetLinkManageTiocById(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos.Lnk);
				if (wLinkTioc != (UINT16)chLocalId)
				{
					(void)dsuCheckSameLoc(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos.Lnk, \
						g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos.Off, \
						&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos.Lnk, \
						&g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].endPos.Off);
				}
				g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].trianCnt = szTmpEnvelope[ii].trianCnt;
				(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].trainID, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].trainID), \
					szTmpEnvelope[ii].trainID, (UINT32)sizeof(szTmpEnvelope[ii].trainID));

				(void)CommonMemCpy(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].ACTPort, (UINT32)sizeof(g_CutoffPointDataBuf[wIndex].szLocalEnvelope[ii + chCurNum].ACTPort), \
					szTmpEnvelope[ii].ACTPort, (UINT32)sizeof(szTmpEnvelope[ii].ACTPort));
			}
		}
		else
		{
			;
		}
	}
	else
	{
		retVal = CI_SUCCESS;/*对应计轴无包络*/
	}
	return retVal;
}