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

#include "OverlapConfigDataManage.h"
#include "../Switch/SwitchDataManage.h"



OverlapConfigDataStruct OverlapConfigDataStru[OVERLAP_SUM_MAX];   /*定义OVERLAP数据配置结构体,cgh-合并CID-2539-1：此处声明不进行初始化，统一放到InitAllStaticDataStr函数中进行初始化，为解决生成内核过大得问题*/
UINT16 LocalCiOverlapIdBuf[OVERLAP_SUM_MAX] = {0u};                   /*定义本地联锁保护区段组ID映射数组*/
INT16 OverlapCurSum = 0;   /*OVERLAP当前总数*/


/*
* 功能描述： 获取保护区段当前总数
* 参数说明： void    
* 返回值  ： 0: 获取数据失败
*			>0: 保护区段当前总数
*/
UINT16 GetOverlapCurSum(void)
{
	UINT16 reVal = 0u;
    if (OverlapCurSum >= (INT16)OVERLAP_SUM_MAX)
    {
        reVal = OVERLAP_SUM_MAX;
    }
	else if (OverlapCurSum < 0)
	{
		reVal = 0u;
	}
    else
    {
        reVal = (UINT16)OverlapCurSum;
    }
	return reVal;
}

/*
* 功能描述： 获取指定数组下标对应的保护区段ID
* 参数说明： const UINT16 bufIndex, 数组下标    
* 返回值  ： 0: 获取数据失败
*			>0: 保护区段ID      
*/
UINT16 GetOverlapId(const UINT16 bufIndex)
{
	UINT16 reVal = CI_ERROR;

	if (bufIndex < GetOverlapCurSum())
	{
		reVal = LocalCiOverlapIdBuf[bufIndex];
	}
	return reVal;
}

/*
* 功能描述： 获取保护区段所属联锁ID
* 参数说明： UINT16 overlapId, 保护区段组ID    
* 返回值  ： 0: 获取数据失败
*			>0: 保护区段所属联锁ID
*/
UINT8 GetOverlapBelongCiId(UINT16 overlapId)
{
	UINT8 reVal = CI_ERROR;

	UINT16 bufIndex = GetOverlapConfigBufIndex(overlapId);

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].BelongCiId;
	}
	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段索引号
* 参数说明： const UINT16 overlapId, 保护区段ID
* 返回值  ： OVERLAP_SUM_MAX: 获取数据失败
*			<OVERLAP_SUM_MAX: 查找成功
*/
UINT16 GetOverlapConfigBufIndex(const UINT16 overlapId)
{
	UINT16 reVal = OVERLAP_SUM_MAX;

	if ((1u <= overlapId) && (OVERLAP_SUM_MAX > overlapId))
	{
        reVal = overlapId;
	}
	else
	{
		;
	}
	
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段数据
* 参数说明：    
* 返回值  ： OverlapConfigDataStruct *   
*/
OverlapConfigDataStruct *GetOverlapConfigData(void)
{
    return OverlapConfigDataStru;
}

/*
* 功能描述： 获取指定ID保护区段组包含物理区段数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 包含物理区段数目      
*/
UINT8 GetOverlapPhySecSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].PhySecSum;
	}
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段组包含物理区段ID数组
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： NULL: 获取数据失败
*			!NULL: 包含物理区段ID数组指针      
*/
UINT16* GetOverlapPhySecIdBuf(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16* reVal = NULL;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].PhySecIdBuf;
	}
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段组包含保护区段组数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 包含保护区段组数目      
*/
UINT8 GetOverlapSwitchSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].SwitchSum;
	}
	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段关联防护道岔数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 包含保护区段组数目      
*/
UINT8 GetOverlapRelatedProtSwitSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].ProtectSwitchSum;
	}
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段组包含条件保护区段组结构体数组
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： NULL: 获取数据失败
*			!NULL: 包含条件保护区段组结构体数组指针      
*/
OverlapConditionSwitchStruct* GetOverlapCondSwitchStruct(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	OverlapConditionSwitchStruct* reVal = NULL;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].ConditionSwitchStru;
	}
	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段关联防护道岔结构数组
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： NULL: 获取数据失败
*			!NULL: 包含条件保护区段组结构体数组指针      
*/
OverlapProtectSwitchStruct* GetOverlapRelatedProtSwitStru(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	OverlapProtectSwitchStruct* reVal = NULL;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].ProtectSwitchStru;
	}
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段组自动信号防护道岔触发物理区段数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 自动信号防护道岔触发物理区段数目      
*/
UINT8 GetOverlapTriPhySecSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].TriPhySecSum;
	}
	return reVal;
}


/*
* 功能描述： 获取指定ID保护区段组自动信号防护道岔触发物理区段数组
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： NULL: 获取数据失败
*			!NULL: 自动信号防护道岔触发物理区段数组指针      
*/
UINT16* GetOverlapTriPhySecIdBuf(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16* reVal = NULL;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].TriPhySecIdBuf;
	}
	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段第一个物理区段ID
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 物理区段ID      
*/
UINT16 GetOverlapFirstPhySecId(const UINT16 overlapId)
{
    UINT16 bufIndex = 0u;  /*数组下标*/
    UINT16 reVal = CI_ERROR;
    
    bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/
    
    if (bufIndex < OVERLAP_SUM_MAX)
    {
        reVal = OverlapConfigDataStru[bufIndex].PhySecIdBuf[0];
    }
	return reVal;
}

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

    /*保存保护区段组ID索引数组*/
    overlapConfigDataSum = GetOverlapCurSum();
    if (overlapConfigDataSum >= OVERLAP_SUM_MAX)
    {/*配置数据总数错误*/
        
        reVal = CI_ERROR;
	}
	else
	{
		for (ii = 0u; ii < OVERLAP_SUM_MAX; ii++)
		{
			if (jj == overlapConfigDataSum)
			{/*遍历有效数据完毕*/
	            
				break;
			}
	        
			if (OverlapConfigDataStru[ii].BelongCiId == GetSystemParaLocalCiId())
			{/*该部分为有效数据*/

				LocalCiOverlapIdBuf[jj] = OverlapConfigDataStru[ii].OverlapId;
				jj++; 
			}

		}
	}
    return reVal;
}

/*
* 功能描述： 获取指定ID保护区段锁闭条件包含折返进路数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 包含折返进路数目
*/
UINT8 GetOvlpRetRoutAndTrkPhySecSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].RetRoutAndTrkPhySecSum;
	}

	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段锁闭条件包含折返轨物理区段数目
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 包含折返轨物理区段数目
*/
UINT8 GetOverlapRetTrkPhySecSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].RetRoutAndTrkPhySecSum;
	}

	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段锁闭条件包含折返进路ID
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 折返进路ID
*/
UINT16 GetOverlapReturnRouteId(const UINT16 overlapId, const UINT16 index)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		if(index < OverlapConfigDataStru[bufIndex].RetRoutAndTrkPhySecSum)
		{
			reVal = OverlapConfigDataStru[bufIndex].ReturnRouteIdBuf[index];
		}

	}

	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段锁闭条件包含折返轨物理区段ID
* 参数说明： const UINT16 overlapId, 保护区段ID    
* 返回值  ： 0: 获取数据失败
*			>0: 折返轨物理区段ID
*/
UINT16 GetOverlapRetTrkPhySecId(const UINT16 overlapId, const UINT16 index)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		if(index < OverlapConfigDataStru[bufIndex].RetRoutAndTrkPhySecSum)
		{
			reVal = OverlapConfigDataStru[bufIndex].RetTrkPhySecIdBuf[index];
		}

	}

	return reVal;
}

/*
功能描述: 	获得指定保护区段关联的侵限区段及条件道岔数据数量
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		[1, 65535]侵限区段及条件道岔数据数量
			0 无侵限区段或获取失败
*/
UINT16 GetOverlapInvSecAndConSwiSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		retVal = OverlapConfigDataStru[bufIndex].InvSecAndConSwiSum;
	}

	return retVal;
}


/*
功能描述: 	获得指定保护区段关联的侵限区段及条件道岔数据ID
输入参数:	const UINT16 overlapId 保护区段ID
				const UINT16 index	 侵限区段及条件道岔数据索引
输出参数:	无
返回值:		[1, 65535]侵限区段及条件道岔数据ID
				0 无侵限区段或获取失败
*/
UINT16 GetOverlapInvSecAndConSwiId(const UINT16 overlapId, const UINT16 index)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		if(index < OverlapConfigDataStru[bufIndex].InvSecAndConSwiSum)
		{
			retVal = OverlapConfigDataStru[bufIndex].InvSecAndConSwiIdBuf[index];
		}
	}

	return retVal;
}

/*
功能描述: 	获得指定保护区段关联的侵限敌对保护区段数据数量
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		[1, 65535]侵限敌对保护区段数据数量
				0 无侵限敌对保护区段或获取失败
*/
UINT16 GetOverlapInvOppOverlapSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		retVal = OverlapConfigDataStru[bufIndex].InvOppOverlapSum;
	}

	return retVal;
}

/*
功能描述: 	获得指定保护区段关联的侵限敌对保护区段ID
输入参数:	const UINT16 overlapId 保护区段ID
				const UINT16 index	 侵限敌对保护区段数据索引
输出参数:	无
返回值:		[1, 65535]侵限敌对保护区段ID
				0 无侵限敌对保护区段或获取失败
*/
UINT16 GetOverlapInvOppOverlapId(const UINT16 overlapId, const UINT16 index)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		if(index < OverlapConfigDataStru[bufIndex].InvOppOverlapSum)
		{
			retVal = OverlapConfigDataStru[bufIndex].InvOppOverlapIdBuff[index];
		}
	}

	return retVal;
}

/*
功能描述: 	获得指定保护区段关联的防淹门数据数量
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		[1, 65535]防淹门数据数量
				0 无防淹门或获取失败
*/
UINT16 GetOverlapFloodGateSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		retVal = OverlapConfigDataStru[bufIndex].FloodGateIdSum;
	}

	return retVal;
}

/*
功能描述: 	获得指定保护区段关联的防淹门数据ID
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		防淹门id数组指针
*/
UINT16* GetOverlapFloodGateBuf(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 *pFloodIdBuf = NULL;/*防淹门id数组指针*/

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		pFloodIdBuf = OverlapConfigDataStru[bufIndex].FloodGateIdBuff;
	}

	return pFloodIdBuf;
}

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

	if ((OverlapCurSum + (INT16)overlapSum) >= (INT16)OVERLAP_SUM_MAX)
	{/*入口防护*/
		retVal = 0u;
	}
	else
	{
		index = (UINT16)OverlapCurSum;
		OverlapCurSum += (INT16)overlapSum;
		for(ii = 0u;ii< overlapSum;ii++)
		{
			LocalCiOverlapIdBuf[index+ii] = overlapIdBuff[ii];/*追加到LocalCiOverlapIdBuf*/
		}
	}

	return retVal;
}

/*
* 功能描述： 获取保护区段所属虚拟联锁ID
* 参数说明： UINT16 overlapId, 保护区段组ID    
* 返回值  ： 0: 获取数据失败
*			>0: 保护区段所属虚拟联锁ID
*/
UINT8 GetOverlapBelongVirCiId(UINT16 overlapId)
{
	UINT8 reVal = CI_ERROR;

	UINT16 bufIndex = GetOverlapConfigBufIndex(overlapId);

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].BelongVirCiId;
	}
	return reVal;
}


/*
*功能描述: 	获得指定保护区段包含的逻辑区段数量
*输入参数:	const UINT16 overlapId 保护区段ID
*输出参数:	无
*返回值:	[0, 255]逻辑区段数量
*/
UINT8 GetOverlapLogicSectionSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT8 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		if (OVLP_LOGICSECTION_SUM_MAX > OverlapConfigDataStru[bufIndex].cLogicSectionSum)
		{
			retVal = OverlapConfigDataStru[bufIndex].cLogicSectionSum;
		}
		else
		{
			retVal = CI_ERROR;
		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
功能描述: 	获获得指定保护区段包含的逻辑区段ID数组
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		逻辑区段id数组指针
*/
UINT16* GetOverlapLogicSectionBuf(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 *pLogicSectionIdBuf = NULL;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (OVERLAP_SUM_MAX > bufIndex)
	{
		pLogicSectionIdBuf = OverlapConfigDataStru[bufIndex].szLogicSectionIdBuf;
	}
	else
	{
		;
	}

	return pLogicSectionIdBuf;
}
/*
功能描述: 	获得指定保护区段所属的进路ID数量
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		[1, 65535]所属的进路ID数量
0 获取失败
修改：cgh-合并CID-2341-8：
*/
UINT16 GetOverlapRouteIdSum(const UINT16 overlapId)
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT16 retVal = 0;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		retVal = OverlapConfigDataStru[bufIndex].OverlapRouteSum;
	}

	return retVal;
}

/*
功能描述: 	获得指定保护区段所属的进路ID数组
输入参数:	const UINT16 overlapId 保护区段ID
输出参数:	无
返回值:		进路id数组指针
修改：cgh-合并CID-2341-8：
*/
UINT16* GetOverlapRouteIdBuf(const UINT16 overlapId)
{
	UINT16 bufIndex = 0;  /*数组下标*/
	UINT16* pRouteIdBuf = NULL;/*进路id数组指针*/

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		pRouteIdBuf = OverlapConfigDataStru[bufIndex].OverlapRouteIdBuf;
	}

	return pRouteIdBuf;
}

/*
*功能描述: 	获得指定保护区段包含的最远端计轴
*输入参数:	const UINT16 overlapId 保护区段ID
*输出参数:	无
*返回值:	0 查询失败
*       >0 计轴区段ID
*/
UINT16 GetOverlapFarLogicSecID(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 retVal = 0u;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		retVal = OverlapConfigDataStru[bufIndex].AxisSecFarId;
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
* 功能描述： 获取指定ID保护区段第一个逻辑区段ID
* 参数说明： const UINT16 overlapId, 保护区段ID
* 返回值  ： 0: 获取数据失败
*			>0: 逻辑区段ID
* by cgh 20240923
*/
UINT16 GetOverlapFirstLogSecId(const UINT16 overlapId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	UINT16 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].szLogicSectionIdBuf[0];
	}
	return reVal;
}

/*
* 功能描述：判断其它控区保护区段是否存在防护道岔属于本控区
* 参数说明：const UINT16 wOverlapId 保护区段ID
* 返 回 值：0 不存在防护道岔跨控区的保护区段
*		   >0 保护区段所属联锁ID
* Created By LQ 2024.12.03
*/
UINT8 CheckOtherCiOlpHaveLocalCiPSw(const UINT16 wOverlapId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 cLocalCiId = 0U;  /*本地联锁ID*/
	UINT8 cOverlapBelongCiId = 0U;  /*保护区段所属联锁ID*/	
	UINT8 cOverlapProSwtNum = 0U;  /*保护区段防护道岔数目*/
	OverlapProtectSwitchStruct* pOverlapProSwtData = NULL;  /*保护区段防护道岔数据*/
	UINT8 ii = 0U;
	UINT8 cSwitchBelongCiId = 0U;  /*道岔所属联锁ID*/
	
	wBufIndex = GetOverlapConfigBufIndex(wOverlapId);

	if (OVERLAP_SUM_MAX > wBufIndex)
	{
		cLocalCiId = GetSystemParaLocalCiId();
		cOverlapBelongCiId = GetOverlapBelongCiId(wOverlapId);
		if ((0U != cLocalCiId) && (0U != cOverlapBelongCiId) && (cLocalCiId != cOverlapBelongCiId))
		{
			/****** 保护区段非本控区，继续检查保护区段是否存在防护道岔属于本控区 ******/
			cOverlapProSwtNum = GetOverlapRelatedProtSwitSum(wOverlapId);
			pOverlapProSwtData = GetOverlapRelatedProtSwitStru(wOverlapId);
			if (NULL != pOverlapProSwtData)
			{
				for (ii = 0U; ii < cOverlapProSwtNum; ii++)
				{
					cSwitchBelongCiId = GetSwitchBelongCiId(pOverlapProSwtData[ii].ProtectSwitchId);
					if (cLocalCiId == cSwitchBelongCiId)
					{
						cRetVal = cOverlapBelongCiId;
						break;
					}
					else
					{
						; /*继续检查*/
					}
				}
			}
			else
			{
				/*获取数据失败，返回0*/
			}
		}
		else
		{
			/*本控区保护区段，不处理*/
		}
	}
	else
	{
		/*入参检查失败，返回0*/
	}

	return cRetVal;

}

/*
* 功能描述：获取保护区段指定防护道岔的防护位置
* 参数说明：const UINT16 wOverlapId 保护区段ID
*           const UINT16 wProSwitchId 防护道岔ID
* 返 回 值：0 失败
*			其它 防护位置
* Created By LQ 2024.12.05
*/
UINT8 GetOverlapProSwitchPos(const UINT16 wOverlapId, const UINT16 wProSwitchId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wOverlapIndex = 0U;  /*数组下标*/
	UINT16 wSwitchIndex = 0U;  /*数组下标*/
	UINT8 ii = 0U;

	wOverlapIndex = GetOverlapConfigBufIndex(wOverlapId);  /*获取数组下标*/
	wSwitchIndex = GetSwitchConfigBufIndex(wProSwitchId);

	if ((OVERLAP_SUM_MAX > wOverlapIndex) && (SWITCH_SUM_MAX > wSwitchIndex))
	{
		for (ii = 0U; ii < OverlapConfigDataStru[wOverlapIndex].ProtectSwitchSum; ii++)
		{
			if (wProSwitchId == OverlapConfigDataStru[wOverlapIndex].ProtectSwitchStru[ii].ProtectSwitchId)
			{
				cRetVal = OverlapConfigDataStru[wOverlapIndex].ProtectSwitchStru[ii].ProtectPosition;
				break;
			}
			else
			{
				/*继续检查*/
			}
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述： 获取指定ID保护区段本端照查继电器ID
* 参数说明： const UINT16 overlapId, 保护区段ID
* 返回值  ： 本端照查继电器ID
* by cgh 20250617
*/
UINT16 GetOverlapThisZhaoChaRelayId(const UINT16 overlapId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT16 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].wOverlapThisZhaoChaRelayId;
	}
	else
	{
		; 
	}

	return reVal;
}

/*
* 功能描述： 获取指定ID保护区段对端照查继电器ID
* 参数说明： const UINT16 overlapId, 保护区段ID
* 返回值  ： 对端照查继电器ID
* by cgh 20250617
*/
UINT16 GetOverlapThatZhaoChaRelayId(const UINT16 overlapId)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT16 reVal = CI_ERROR;

	bufIndex = GetOverlapConfigBufIndex(overlapId);  /*获取数组下标*/

	if (bufIndex < OVERLAP_SUM_MAX)
	{
		reVal = OverlapConfigDataStru[bufIndex].wOverlapThatZhaoChaRelayId;
	}
	else
	{
		;
	}

	return reVal;
}