#include "TrainDataManage.h"
#include "CiSystemDefine.h"
#include "CommonMemory.h"
#include "../Section/LinkConfigDataManage.h"
#include "dquCbtcConfigData.h"
#include "../Route/RouteConfigDataManage.h"
#include "HLHTHeadContexManage.h"
#include "ELMDataPrepare.h"
#include "SignalDataManage.h"
#include "ParsePackGateWayData.h"
#include "CRC32.h"
#include "dquCIInterFace.h"
#include "EnvelopeManageAPI.h"
#include "EnvelopeManage.h"
#include "WLBrakeDataManage.h"
#include "SectionStateProcess_define.h"
#include "AxisSort_api.h"

TrainInfoStru gstTrainInfo[TRAIN_SUM_MAX] = { 0 };
UINT16 gszTrainId[TRAIN_SUM_MAX] = { 0U };
UINT16 gTrainSum = 0U;

UINT8 gDyTestNum = 0u;
TrainDyInfoStru gszDyTestInfo[TRAIN_DYN_TEST_SUM_MAX] = { 0u };

UINT8 gAtsScreenNum = 0u;
TrainAtsScreenStru gszAtsScreenInfo[TRAIN_SUM_MAX] = { 0u };

UINT8 gFlyTrainCnt = 0U;			/*飞车宕机报警列车数量*/
TrainFlyProtectStru gFlyTrainData[SHUT_DOWN_TRAIN_NUMMAX] = { 0U };/*飞车宕机报警列车数据*/

UINT8 gNvramFlyTrainCnt = 0U;  /*使用NVRAM且位置监督无效的飞车列车数量*/
UINT16 gNvramFlyTrainId[SHUT_DOWN_TRAIN_NUMMAX] = { 0U };  /*飞使用NVRAM且位置监督无效的飞车列车ID*/

/**
* @brief 根据列车非安全信息计算列车安全位置函数
* @param UINT16  trainID
* @param UINT32 tailDistance
* @param UINT8 trainDirection
* @return 无
*/
static void CalTailTrainSafePosFromUnSafe(UINT16  trainID, UINT32 tailDistance, UINT8 trainDirection);

/**
* @brief 根据列车非安全信息计算列车安全位置函数
* @param UINT16  trainID
* @param UINT32 dwHeadDistance
* @param UINT8 chDir
* @return 无
*/
static void CalHeadTrainSafePosFromUnSafe(UINT16 wTrainId, UINT32 dwHeadDistance, UINT8 chDir);

/**
* @brief 判断列车安全车头是否落在占用且四开岔区
* @param wLinkId 列车安全车头所在link
* @return CI_ERROR:列车安全车头落在占用且四开岔区；CI_SUCCESS:列车安全车头未落在占用且四开岔区
* @note：
*/
static UINT8 IsTrainInSafeArea(UINT16 wLinkId, UINT32 dwOffset);

#if 0
/**
* @brief VBTC列车安全位置处理函数
* @param UINT8 rtnValue
* @param UINT16 trainID
* @param TrainSafeLocStru *temp_TrainSafeLoc
* @return 无
*/
static void UpdateVbtcTrainSafePos(UINT8 rtnValue, UINT16 trainID, TrainSafeLocStru *temp_TrainSafeLoc);
#endif

#if 0
/**
* @brief 列车安全位置处理函数
* @param UINT8 rtnValue
* @param UINT16 trainID
* @param TrainSafeLocStru *temp_TrainSafeLoc
* @param p_strPointInArea pSwitchInfo
* @return 无
*/
static void UpdateTrainSafePos(UINT8 rtnValue, UINT16 trainID, TrainSafeLocStru *temp_TrainSafeLoc);
#endif

/* 计算列车安全位置 */
static UINT8 CalTrainSafeLoc(UINT8 chFlag, UINT8 safeFlag, UINT16 wLink, UINT32 dwOffset, UINT32 dwDistance, UINT8 chDirection,
	UINT16 *pSwitchId, TrainSafeLocStru *pStrSafeLoc);

/*
* 功能描述： 判断列车是否在动态测试列表内
* 参数说明： const UINT16 wTrainId 列车ID
* 返回值  ： CI_ERROR:列车不在动态测试列表内；CI_SUCCESS:列车在动态测试列表内
*/
static UINT8 IsTrainDyTesting(const UINT16 wTrainId);

/*
* 功能描述： 将列车添加进动态测试列表
* 参数说明： const UINT16 wTrainId 列车ID
* 返回值  ： 无
*/
static void AddTrainDyTesting(const UINT16 wTrainId, const UINT16 wLinkId);

/*
* 功能描述： 判断link是否有列车正在动态测试
* 参数说明： const UINT16 wLinkId linkID
* 返回值  ： CI_ERROR:有车正在动态测试；CI_SUCCESS:无
*/
static UINT8 IsLinkTesting(UINT16 wLinkId);

/**
* @brief 列车安全位置计算函数
* @param 无
* @return 无
*/
static void CalTrainSafePosition(void);

/*
* 功能描述： 列车动态测试处理
* 参数说明： 无
* 返回值  ： 无
*/
static void TrainDynProc(void);

/*
* 功能描述： 列车唤醒处理
* 参数说明： 无
* 返回值  ： 无
* note：列车唤醒状态为正在唤醒，维持该车为休眠车，否则变为非休眠车
*/
static void TrainWakeProc(void);

/*
* 功能描述： 原地筛选处理
* 参数说明： 无
* 返回值  ： 无
*/
static void TrainScreenProc(void);

/**
* @brief 整理远程筛选发送数据
* @param 无
* @return 无
*/
static void TrainAtsScreenTidy(void);

/**
* @brief 远程筛选首次确认
* @param 无
* @return 无
*/
static void TrainAtsScreenFst(void);

/**
* @brief 判断ATS远程筛选两次消息是否一致
* @param 无
* @return CI_ERROR:不一致；CI_SUCCESS:一致
*/
static UINT8 IsAtsFstSndSame(void);

/**
* @brief 远程筛选再次确认
* @param 无
* @return 无
*/
static void TrainAtsScreenSnd(void);

/**
* @brief 远程筛选处理
* @param 无
* @return 无
*/
static void TrainAtsScreenProc(void);

/**
* @brief 设置远程筛选确认处理
* @param 无
* @return 无
*/
static void SetTrainAtsScreenProc(void);

/*
* 功能描述： 获取指定列车通信中断周期号
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车通信中断周期号
*/
static UINT32 GetTrainTransBadCyc(const UINT16 wTrainId);

/*
* 功能描述： 设置指定列车包络能否转为UCT
* 参数说明： const UINT16 wTrainId, 列车ID
const UINT8 chFlag 标志
* 返回值  ： 无
* note：休眠车包络不可转为UCT
*/
static void SetTrainCanUct(const UINT16 wTrainId, const UINT8 chFlag);
/*==================================================================================
*函数功能：初始化列车信息结构体。
*函数描述：该函数实现列车信息结构体的初始化。
*入口参数;无
*出口参数;无
*返回值:无
*关键变量：
*备注：
1、创建，2021年6月19日
=====================================================================================*/
UINT8 TrainDataModuleInit(void)
{
	UINT8 chCycle = 0U;
	UINT8 cRetVal = CI_ERROR;
	UINT8 ii = 0U;

	/*清空所有的列车信息结构体*/
	(void)CommonMemSet((void*)&gstTrainInfo, (UINT32)(sizeof(TrainInfoStru)*TRAIN_SUM_MAX), 0U, (UINT32)(sizeof(TrainInfoStru)*TRAIN_SUM_MAX));

	/*遍历所有的列车，设置列车未上线*/
	for (chCycle = 1U; chCycle < TRAIN_SUM_MAX; chCycle++)
	{
		cRetVal = CI_SUCCESS;
		gstTrainInfo[chCycle].wTrainId = (UINT16)((((UINT16)CI_SYSTEM_TYPE_VOBC) << 8) + chCycle);
		gstTrainInfo[chCycle].dwIvocCycle = 0U;
		gstTrainInfo[chCycle].chTrainDir = DIR_INVALID;
		gstTrainInfo[chCycle].chTrainDir_MaxTail = DIR_INVALID;
		gstTrainInfo[chCycle].chTrainDir_MaxHead = DIR_INVALID;
		gstTrainInfo[chCycle].chTrainDir_MinHead = DIR_INVALID;
		gstTrainInfo[chCycle].wTrainMaxHeadLink = 0U;
		gstTrainInfo[chCycle].dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].wTrainMinTailLink = 0U;
		gstTrainInfo[chCycle].dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[chCycle].wTrainMinHeadLink = 0U;
		gstTrainInfo[chCycle].dwTrainMinHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].wTrainMaxTailLink = 0U;
		gstTrainInfo[chCycle].dwTrainMaxTailOffset = UINT32_MAX;
		gstTrainInfo[chCycle].chSpeedDir = 0U;
		gstTrainInfo[chCycle].wTrainSpeed = 0U;
		gstTrainInfo[chCycle].chTransmitStat = TRAIN_COMM_STATE_UNKNOWN;
		gstTrainInfo[chCycle].chTailScreenStat = 0U;
		gstTrainInfo[chCycle].chHeadScreenStat = 0U;
		gstTrainInfo[chCycle].strSafeLoc.wHeadLink = 0U;
		gstTrainInfo[chCycle].strSafeLoc.wTailLink = 0U;
		gstTrainInfo[chCycle].strSafeLoc.dwHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].strSafeLoc.dwTailOffset = UINT32_MAX;
		gstTrainInfo[chCycle].chMsgFromTiocId = 0u;
		gstTrainInfo[chCycle].chSwState = TRAIN_SLEEP_NO;
		gstTrainInfo[chCycle].wSleepLink = 0u;
		gstTrainInfo[chCycle].chWakeState = TRAIN_WAKE_DEFAULT;
		gstTrainInfo[chCycle].chTrainReportState = 0U;
		gstTrainInfo[chCycle].chDynCmd = TRAIN_CMD_DYM_NO;
		gstTrainInfo[chCycle].chDynRpl = TRAIN_DYN_RPL_DEFAULT;
		gstTrainInfo[chCycle].chScreenApply = TRAIN_SCREEN_DEFAULT;
		gstTrainInfo[chCycle].chTrainHeadScreenConfirm = TRAIN_HEAD_CONFIRM_NO;
		gstTrainInfo[chCycle].chTrainTailScreenConfirm = TRAIN_TAIL_CONFIRM_NO;
		gstTrainInfo[chCycle].chAtsScreenConfirm = TRAIN_ATS_CONFIRM_NO;
		gstTrainInfo[chCycle].chStopSteadyState = TRAIN_SS_NO;
		gstTrainInfo[chCycle].chSleepCancleFlag = TRAIN_SLEEP_CANCLE_NO;
		gstTrainInfo[chCycle].chEaCmd = EA_PROTECT_DEFAULT;
		gstTrainInfo[chCycle].chTrainCanUct = FLAG_UNSET;
		gstTrainInfo[chCycle].chActive = TRAIN_ACTIVE_NONE;
		gstTrainInfo[chCycle].chRrmRqst = TRAIN_RRM_RQST_NO;
		gstTrainInfo[chCycle].chRrmState = TRAIN_RRM_DEFAULT;
		gstTrainInfo[chCycle].chRrmReson = TRAIN_RRM_RESON_FF;
		gstTrainInfo[chCycle].chRrmResonFromOtherRc = TRAIN_RRM_RESON_FF;
		gstTrainInfo[chCycle].wAtsLgcStation = 0u;
		gstTrainInfo[chCycle].wNextTioc = 0u;
		gstTrainInfo[chCycle].chDerailment = TRAIN_DERAIL_NO;
		gstTrainInfo[chCycle].chNvramPosFlag = TRAIN_NVRAM_POS_FLAG_YES;

		gstTrainInfo[chCycle].strHeadTrainLocData.wHeadVobcId = UINT32_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.chHeadTrainLocFlag = HEAD_TRAIN_LOC_DEFAULT;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainAtpLoc.chTrainDir = TRAIN_DIR_DEF;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainAtpLoc.wTrainMaxHeadLink = 0U;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainAtpLoc.dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainAtpLoc.wTrainMinTailLink = 0U;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainAtpLoc.dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.wTrainMaxHeadLink = 0U;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.wTrainMinTailLink = 0U;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.chTrainDir = TRAIN_DIR_DEF;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.wLocHeadLoss = UINT16_MAX;
		gstTrainInfo[chCycle].strHeadTrainLocData.strHeadTrainIteLoc.wLocTailLoss = UINT16_MAX;

		/*初始化ITE发送的列车数据*/
		for (ii = 0U; ii < TRAIN_INC_ITE_SUM_MAX; ii++)
		{
			gstTrainInfo[chCycle].szTrainIteData[ii].wTrainHeadLinkId = 0U;
			gstTrainInfo[chCycle].szTrainIteData[ii].dwTrainHeadLinkOffset = UINT32_MAX;
			gstTrainInfo[chCycle].szTrainIteData[ii].wTrainTailLinkId = 0U;
			gstTrainInfo[chCycle].szTrainIteData[ii].dwTrainTailLinkOffset = UINT32_MAX;
			gstTrainInfo[chCycle].szTrainIteData[ii].cTrainDir = TRAIN_DIR_DEF;
			gstTrainInfo[chCycle].szTrainIteData[ii].wForWardOffset = UINT16_MAX;
			gstTrainInfo[chCycle].szTrainIteData[ii].wBackOffset = UINT16_MAX;
		}

		/*清空所有的后备列车ABL信息结构体*/
		(void)CommonMemSet((void*)&gstTrainInfo[chCycle].strAblTrainNeedData, (UINT32)sizeof(ABLTrainInfoStru), 0U, (UINT32)sizeof(ABLTrainInfoStru));
		gstTrainInfo[chCycle].wTrainHeadSigId = 0U;
		gstTrainInfo[chCycle].wTrainHeadTrainId = TRAIN_ID_MAX;
		gstTrainInfo[chCycle].chTrainLocReverseRouteFlag = TRAIN_LOC_REV_ROUTE_FLAG_NONE;

		gstTrainInfo[chCycle].chAblTrainDir = DIR_INVALID;
		gstTrainInfo[chCycle].wAblTrainMaxHeadLink = 0U;
		gstTrainInfo[chCycle].dwAblTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[chCycle].wAblTrainMinTailLink = 0U;
		gstTrainInfo[chCycle].dwAblTrainMinTailOffset = UINT32_MAX;
		/*初始化时虚拟筛选标志应无效*/
		gstTrainInfo[chCycle].chVirHeadScreenPassFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
		gstTrainInfo[chCycle].chVirTailScreenPassFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
		gstTrainInfo[chCycle].wEnterLjkLinkId = 0U;
		gstTrainInfo[chCycle].dwTrainFullEnterLjkCycNum = 0U;

		gstTrainInfo[chCycle].chTrainPosMonitorState = TRAIN_POS_MONITOR_INVALID;  /*列车位置监督状态初始化为无效*/
		gstTrainInfo[chCycle].wTrainPosMonitorInLink = 0U;  /*列车位置监督有效时所处link为0*/
		gstTrainInfo[chCycle].dwStartFlyCycNum = 0U;  /*飞车记录周期初始化*/
		gstTrainInfo[chCycle].chEaCmdState = TRAIN_EA_CMD_STATE_INVALID;  /*列车区间疏散命令初始化为无效*/
		gstTrainInfo[chCycle].strJumpBackData.chJumpBackApplyState = TRAIN_JUMP_BACK_STATE_INVALID;/*初始化未申请*/
		gstTrainInfo[chCycle].strJumpBackData.chJumpBackReplyState = TRAIN_JUMP_BACK_STATE_NONE;/*初始化允许默认值*/
		gstTrainInfo[chCycle].strJumpBackData.dwJumpBackApplySn = 0U;/*初始化默认序列号*/
		gszTrainId[gTrainSum] = gstTrainInfo[chCycle].wTrainId;
		gTrainSum++;

	}

	return cRetVal;
}

/*
* 功能描述： 获取列车总数
* 参数说明： void
* 返回值  ： UINT16 初始化的列车总数
* 创建: qw.liu 2022-02-25
*/
UINT16 GetTrainSum(void)
{
	UINT16 wRetVal = 0U;
	if (TRAIN_SUM_MAX <= gTrainSum )
	{
		wRetVal = TRAIN_SUM_MAX;
	}
	else
	{
		wRetVal = gTrainSum;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定数组下标对应的列车ID
* 参数说明： const UINT16 bufIndex, 数组下标
* 返回值  ： 0: 获取数据失败
*			>0: 列车ID
*/
UINT16 GetTrainId(const UINT16 bufIndex)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wTrainSum = GetTrainSum();
	if (bufIndex < wTrainSum)
	{
		wRetVal = gszTrainId[bufIndex];
	}
	else
	{
		wRetVal = CI_ERROR;
	}
	return wRetVal;
}

/*
* 功能描述： 获取列车信息结构体
* 参数说明： void
* 返回值  ： TrainInfoStru * 列车信息结构体
* 创建: qw.liu 2022-02-24
* 修复bug YF0083-120
*/
TrainInfoStru * GetTrainInfoData(void)
{
	TrainInfoStru * ret = NULL;
	if (NULL != gstTrainInfo)
	{
		ret = (TrainInfoStru *)gstTrainInfo;
	}
	else
	{
		ret = NULL;
	}
	return ret;
}

/*
* 功能描述： 获取指定列车索引
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： TRAIN_SUM_MAX: 获取数据失败
*			 <TRAIN_SUM_MAX: 列车索引
* 创建: qw.liu 2022-02-24  
*/
UINT16 GetTrainBufIndex(const UINT16 wTrainId)
{
	UINT16 wRetVal = TRAIN_SUM_MAX;

	if ((TRAIN_ID_MIN < wTrainId) && (TRAIN_ID_MAX > wTrainId))
	{
		wRetVal = wTrainId & 0x00FFU;
	}
	else if((TRAIN_SUM_MAX > wTrainId) && (0u != wTrainId))
	{
		wRetVal = wTrainId;
	}
	else
	{
		wRetVal = TRAIN_SUM_MAX;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车通信状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 通信状态良好
*			 0xAA: 丢失通信
*			 0xFF: 通信状态未知
* 创建: qw.liu 2022-02-24
*/
UINT8 GetTrainTransitmitStat(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTransmitStat;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车等级
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x03: UR
*			 0x04: ABL
*			 0x01: VBTC
*			 0x02: ITC
*			 0xff : 默认/清除状态
* 创建: qw.liu 2022-02-24
*/
UINT8 GetTrainLevel(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainLevel;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车等级
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车速度
*			 
* 创建: qw.liu 2022-02-25
*/
UINT16 GetTrainSpeed(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainSpeed;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车运行方向（最小安全后端）
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 与逻辑方向同向
*			 0xAA: 与逻辑方向反向
*			 0xFF: 无效方向
* 创建: qw.liu 2022-02-24
*/
UINT8 GetTrainDir(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainDir;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车最大安全后端的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 与逻辑方向同向
*			 0xAA: 与逻辑方向反向
*			 0xFF: 无效方向
*/
UINT8 GetTrainDir_MaxTail(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainDir_MaxTail;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车最大安全前端的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 与逻辑方向同向
*			 0xAA: 与逻辑方向反向
*			 0xFF: 无效方向
*/
UINT8 GetTrainDir_MaxHead(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainDir_MaxHead;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}


/*
* 功能描述： 获取指定列车最小安全前端的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 与逻辑方向同向
*			 0xAA: 与逻辑方向反向
*			 0xFF: 无效方向
*/
UINT8 GetTrainDir_MinHead(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainDir_MinHead;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车前筛标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 前端筛选通过
*			 0xAA: 前端未筛选通过
* 创建: wsd 2022-03-10
*/
UINT8 GetTrainHeadScrStat(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chHeadScreenStat;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}
/*
* 功能描述： 获取指定列车后筛标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 后端筛选通过
*			 0xAA: 后端未筛选通过
* 创建: wsd 2022-03-10
*/
UINT8 GetTrainTailScrStat(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTailScreenStat;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}
/*
* 功能描述： 获取指定列车速度方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 速度方向上行
*			 0xAA: 速度方向下行
* 创建: qw.liu 2022-02-24
*/
UINT8 GetTrainSpeedDir(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chSpeedDir;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车是否在本控区
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 0x55: 列车在本控区
*			 0xAA: 列车不在本控区
* 创建: qw.liu 2022-02-24
*/
UINT8 GetTrainInCtrlZone(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainInZone;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车最大安全前端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* 创建: qw.liu 2022-02-24
*/
UINT16 GetTrainMaxHeadLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainMaxHeadLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车最大安全后端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* 创建: qw.liu 2022-02-24
*/
UINT16 GetTrainMaxTailLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainMaxTailLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车最小安全前端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* 创建: 2022.3.2
*/
UINT16 GetTrainMinHeadLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainMinHeadLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车最小安全后端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* 创建: 2022.3.2
*/
UINT16 GetTrainMinTailLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainMinTailLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车消息延迟时间
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 消息延迟时间
* 创建: 2022.3.2
*/
UINT32 GetTrainMsgDelayTime(const UINT16 wTrainId)
{
	UINT32 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].dwDelayTime;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车最大安全前端偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* 创建: qw.liu 2022-02-24
*/
UINT32 GetTrainMaxHeadOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTrainMaxHeadOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车最大安全后偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* 创建: qw.liu 2022-02-24
*/
UINT32 GetTrainMaxTailOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTrainMaxTailOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车最小安全前端偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* 创建: 2022.3.2
*/
UINT32 GetTrainMinHeadOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTrainMinHeadOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车最小安全后偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* 创建: 2022.3.2
*/
UINT32 GetTrainMinTailOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTrainMinTailOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车最小安全前端偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车零速状态
* 创建: 2022.3.2
*/
UINT8 GetTrainZeroState(const UINT16 wTrainId)
{
	UINT8 dwRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].chTrainZeroState;
	}
	else
	{
		dwRetVal = UINT8_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 设置指定列车通信状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainmitStat 通信状态
* 返回值  ：CI_ERROR: 设置数据失败
			CI_SUCCESS:设置数据成功
* 0x55 : 通信状态良好
* 0xAA : 丢失通信
* 0xFF : 通信状态未知
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainTransmitStat(const UINT16 wTrainId,const UINT8 chTrainmitStat)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_COMM_STATE_GOOD == chTrainmitStat)
			|| (TRAIN_COMM_STATE_BAD == chTrainmitStat)
			|| (TRAIN_COMM_STATE_UNKNOWN == chTrainmitStat))
		{
			gstTrainInfo[wBufIndex].chTransmitStat = chTrainmitStat;
			gstTrainInfo[wBufIndex].dwTransBadCyc = Get2oo2CurCycleNum();
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车运行等级
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainLevel 列车运行等级
* 返回值  ： 0: 获取数据失败
			1:	设置数据成功
*			 0x03: UR
*			 0x04: ABL
*			 0x01: VBTC
*			 0x02: ITC
*			 0xff : 默认/清除状态
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainLevel(const UINT16 wTrainId, const UINT8 chTrainLevel)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		/*RC16.0 更新主用备用统一运行级别宏值*/
		if ((TRAIN_LEVEL_UR == chTrainLevel)
			|| (TRAIN_LEVEL_ABL == chTrainLevel)
			|| (TRAIN_LEVEL_VBTC == chTrainLevel)
			||(TRAIN_LEVEL_ITC == chTrainLevel)
			|| (TRAIN_LEVEL_BACKUP_UNKNOWN == chTrainLevel))
		{
			gstTrainInfo[wBufIndex].chTrainLevel = chTrainLevel;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最小安全后端指向车头的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainDir 列车运行方向
* 返回值  ： 0: 获取数据失败
1:	设置数据成功
*			0x55: 运行方向上行
*			 0xAA: 运行方向下行
*			 0xFF: 列车默认运行方向
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainDir(const UINT16 wTrainId, const UINT8 chTrainDir)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 chDir = 0u;
	UINT8 chLinkLogicDirUpAndDown = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_DIR_UP == chTrainDir) || (TRAIN_DIR_DOWN == chTrainDir))
		{
			chLinkLogicDirUpAndDown = GetLinkLogicDirUpAndDown();

			if (chLinkLogicDirUpAndDown == chTrainDir)
			{
				chDir = DIR_CONVERT;
			}
			else
			{
				chDir = DIR_SAME;
			}

			/*设置列车最小安全后端的运行方向*/
			gstTrainInfo[wBufIndex].chTrainDir = chDir;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车零速状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainZeroStt 列车零速状态
* 返回值  ： 0: 获取数据失败
1:	设置数据成功
*			0x55: 运行零速
*			0xAA: 运行非零速
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainZeroState(const UINT16 wTrainId, const UINT8 chTrainZeroStt)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_SPEED_ZERO_YES == chTrainZeroStt)
			|| (TRAIN_SPEED_ZERO_NO == chTrainZeroStt))
		{
			gstTrainInfo[wBufIndex].chTrainZeroState = chTrainZeroStt;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车是否在本控区
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainCtrlZonStat 是否在本控区
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
*			0x55: 在本控区
*			0xAA: 不在本控区
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainInCtrlZoneStat(const UINT16 wTrainId, const UINT8 chTrainCtrlZonStat)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_IN_CTRL_ZONE == chTrainCtrlZonStat)
			|| (TRAIN_NOT_IN_CTRL_ZONE == chTrainCtrlZonStat))
		{
			gstTrainInfo[wBufIndex].chTrainInZone = chTrainCtrlZonStat;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最大安全前端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainHeadLinkId 列车最大安全前端Lk
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMaxHeadLink(const UINT16 wTrainId, const UINT16 wTrainHeadLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainHeadLinkId)
		{
			gstTrainInfo[wBufIndex].wTrainMaxHeadLink = wTrainHeadLinkId;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最大安全前端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainHeadOff 列车安全前端Off
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMaxHeadOffset(const UINT16 wTrainId, const UINT32 dwTrainHeadOff)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwTrainMaxHeadOffset = dwTrainHeadOff;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最大安全后端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainTailLinkId 列车安全后端所处Lk
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMaxTailLink(const UINT16 wTrainId, const UINT16 wTrainTailLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainTailLinkId)
		{
			gstTrainInfo[wBufIndex].wTrainMaxTailLink = wTrainTailLinkId;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最大安全后端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainTailOff 列车安全后端Off
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMaxTailOffset(const UINT16 wTrainId, const UINT32 dwTrainTailOff)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwTrainMaxTailOffset = dwTrainTailOff;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}


/*
* 功能描述： 设置指定列车最小安全前端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainHeadLinkId 列车最大安全前端Lk
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMinHeadLink(const UINT16 wTrainId, const UINT16 wTrainHeadLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainHeadLinkId)
		{
			gstTrainInfo[wBufIndex].wTrainMinHeadLink = wTrainHeadLinkId;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最小安全前端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainHeadOff 列车安全前端Off
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMinHeadOffset(const UINT16 wTrainId, const UINT32 dwTrainHeadOff)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwTrainMinHeadOffset = dwTrainHeadOff;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最小安全后端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainTailLinkId 列车安全后端所处Lk
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMinTailLink(const UINT16 wTrainId, const UINT16 wTrainTailLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainTailLinkId)
		{
			gstTrainInfo[wBufIndex].wTrainMinTailLink = wTrainTailLinkId;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车最小安全后端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainTailOff 列车安全后端Off
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 24
*/
UINT8 SetTrainMinTailOffset(const UINT16 wTrainId, const UINT32 dwTrainTailOff)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwTrainMinTailOffset = dwTrainTailOff;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}
/*
* 功能描述： 设置指定列车速度
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainTailLinkId 列车安全后端所处Lk
* 返回值  ： 0: 获取数据失败
* 1 : 设置数据成功
* 创建 : qw.liu 2022 - 02 - 26
*/
UINT8 SetTrainSpeed(const UINT16 wTrainId, const UINT16 wTrainSpd)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainSpd)
		{
			gstTrainInfo[wBufIndex].wTrainSpeed = wTrainSpd;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车速度方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainTailOff 列车安全后端Off
* 返回值  ： 0: 获取数据失败
*			 1:	设置数据成功
* 创建 : qw.liu 2022 - 02 - 26
*/
UINT8 SetTrainSpeedDir(const UINT16 wTrainId, const UINT8 chSpdDir)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_SPEED_DIR_BACKWARD==chSpdDir)
			|| (TRAIN_SPEED_DIR_FORWARD== chSpdDir))
		{
			gstTrainInfo[wBufIndex].chSpeedDir = chSpdDir;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车头所处link
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wLinkId   
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeHeadLink(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.wHeadLink = wLinkId;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车头所处link偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwOffset  偏移量
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeHeadOffset(const UINT16 wTrainId, const UINT32 dwOffset)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.dwHeadOffset = dwOffset;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车头方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chDir
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeHeadDir(const UINT16 wTrainId, const UINT8 chDir)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	if ((DIR_SAME == chDir) || (DIR_CONVERT == chDir))
	{
		chRetVal = CI_SUCCESS;
	}

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (CI_SUCCESS == chRetVal)
		{
			gstTrainInfo[wBufIndex].strSafeLoc.chHeadDir = chDir;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车头所处link
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wLinkId
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeTailLink(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.wTailLink = wLinkId;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车头所处link偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwOffset  偏移量
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeTailOffset(const UINT16 wTrainId, const UINT32 dwOffset)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.dwTailOffset = dwOffset;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车安全车尾方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chDir
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainSafeTailDir(const UINT16 wTrainId, const UINT8 chDir)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	if ((DIR_SAME == chDir) || (DIR_CONVERT == chDir))
	{
		chRetVal = CI_SUCCESS;
	}

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (CI_SUCCESS == chRetVal)
		{
			gstTrainInfo[wBufIndex].strSafeLoc.chTailDir = chDir;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车安全车头所处link
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车头所处link
* 创建 : 2022.3.1
*/
UINT16 GetTrainSafeHeadLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = UINT16_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].strSafeLoc.wHeadLink;
	}
	else
	{
		wRetVal = UINT16_MAX;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车安全车头所处link偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车头所处link偏移量
* 创建 : 2022.3.1
*/
UINT32 GetTrainSafeHeadOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].strSafeLoc.dwHeadOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车安全车头方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车头方向
* 创建 : 2022.3.1
*/
UINT8 GetTrainSafeHeadDir(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strSafeLoc.chHeadDir;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车安全车尾所处link
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车尾所处link
* 创建 : 2022.3.1
*/
UINT16 GetTrainSafeTailLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = UINT16_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].strSafeLoc.wTailLink;
	}
	else
	{
		wRetVal = UINT16_MAX;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定列车安全车头所处link偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车尾所处link偏移量
* 创建 : 2022.3.1
*/
UINT32 GetTrainSafeTailOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].strSafeLoc.dwTailOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车安全车尾方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：安全车头方向
* 创建 : 2022.3.1
*/
UINT8 GetTrainSafeTailDir(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strSafeLoc.chTailDir;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车消息延迟时间
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwDelayTime
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
*/
UINT8 SetTrainMsgDelayTime(const UINT16 wTrainId, const UINT32 dwDelayTime)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT32_MAX != dwDelayTime)
		{
			gstTrainInfo[wBufIndex].dwDelayTime = dwDelayTime;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/****************************************************************************************
函数功能：输入标识信息（表示计算的位置为车头安全位置或车尾安全位置），列车的非安全位置
（车头非安全位置或车尾非安全位置），列车本周期运行的距离（考虑测距误差、延时等因素综合
计算得到）以及列车的运行方向，查询结果，返回计算得到的列车安全位置（车头安全位置或车尾
安全位置），若计算成功返回0x03，若计算失败根据失败的原因，分别返回对应的信息
PS：注意，该函数的局部结构体内包含了车头和车尾的Link和Offset信息，DSU应根据标识信息填
写相应的信息（具体见结构体定义）
注：根据沟通确定，对于由于道岔原因导致安全位置计算失败的情况，将导致失败的道岔ID作为返
回值的一部分返回，对于其他情况的失败，该返回值为保留值0xffff。（对应接口中的wSwitchID变量）
入口参数：UINT8 chFlag		计算车头还是车尾的标识信息
UINT8 safeFlag    是否安全位置计算标志位
UINT16 wLink1		所处link编号
UINT32 dwOffset1	所处link偏移量
UINT32 dwDistance	距离
UINT8 chDirection	列车运行方向
struct_DSU_SwitchInfo SwitchArray[DSU_SWITCH_NUM]	ZC管辖范围内道岔信息结构体
出口参数：struct_DSU_TrainSafeLoc *TrainSafeLoc		列车位置信息结构体
返回值：UINT8 chReturnValue
0x03：安全位置计算成功
0x02：安全位置计算失败（原因道岔位置错误）
0x01：安全位置计算失败（原因线路尽头）
0x00：安全位置计算失败（原因入口参数错误）
*******************************************************************************************/
/*8	列车安全位置计算*/
static UINT8 CalTrainSafeLoc(UINT8 chFlag, UINT8 safeFlag, UINT16 wLink, UINT32 dwOffset, UINT32 dwDistance, UINT8 chDirection,
	UINT16 *pSwitchId, TrainSafeLocStru *pStrSafeLoc)
{
	UINT8 chReturnValue = 0u;/*函数返回值*/
	UINT8 chFunRtn = 0u;/*调用功能函数“已知旧位置和位移判断新位置”函数返回值*/
	UINT8 bTailDir = 0u;/*计算车尾安全位置时的方向*/
	struct_PathPoint strPoint = { 0u };
	struct_PathPoint strPointResult = { 0u };

	chFunRtn = CheckLinkValid(wLink, dwOffset);

	/*判断列车位置ID数据输入的有效性*/
	if ((CI_SUCCESS != chFunRtn) || ((DIR_SAME != chDirection) && (DIR_CONVERT != chDirection))
		|| (NULL == pSwitchId) || (NULL == pStrSafeLoc))
	{
		;
	}
	else
	{
		strPoint.wLinkId = wLink;
		strPoint.dwOffset = dwOffset;

		if (CALSAFEPOSFLAG == safeFlag)
		{
			/*查询车头安全位置*/
			if (FINDHEADSAFEFLAG == chFlag)
			{
				/*调用功能函数“已知旧位置和位移判断新位置进行查询”*/
				chFunRtn = dsuNewLocAndObsByOffsetDis(strPoint, dwDistance, chDirection, &strPointResult, pSwitchId);

				chReturnValue = chFunRtn;

				/*函数因线路尽头查询失败或查询成功*/
				if ((3u == chFunRtn) || (1u == chFunRtn))
				{
					/*设置车头安全位置*/
					pStrSafeLoc->wHeadLink = strPointResult.wLinkId;
					pStrSafeLoc->dwHeadOffset = strPointResult.dwOffset;
				}
				else
				{
					if (2u == chFunRtn)
					{
						/*将道岔所处汇合区段位置(离列车最近的LINK区段内方的点)作为列车安全位置*/
						pStrSafeLoc->wHeadLink = strPointResult.wLinkId;
						pStrSafeLoc->dwHeadOffset = strPointResult.dwOffset;
					}
					else
					{
						/*函数调用失败*/
					}
				}
			}
			else
			{
				/*查询车尾安全位置*/
				if (FINDTAILSAFEFLAG == chFlag)
				{
					/*查询车尾位置需要按照列车运行方向的反向计算，进行方向的颠倒*/
					if (DIR_SAME == chDirection)
					{
						bTailDir = DIR_CONVERT;
					}
					else
					{
						bTailDir = DIR_SAME;
					}
					/*调用功能函数“已知旧位置和位移判断新位置进行查询”*/
					chFunRtn = dsuNewLocAndObsByOffsetDis(strPoint, dwDistance, bTailDir, &strPointResult, pSwitchId);

					chReturnValue = chFunRtn;

					/*函数查询成功或由于尽头线查询失败时*/
					if ((3u == chFunRtn) || (1u == chFunRtn))
					{
						/*计算成功，输出参数，返回查询成功*/
						pStrSafeLoc->wTailLink = strPointResult.wLinkId;
						pStrSafeLoc->dwTailOffset = strPointResult.dwOffset;
					}
					else
					{

						if (2u == chFunRtn)
						{
							/*将道岔所处汇合区段位置(离列车最近的LINK区段内方的点)作为列车安全位置*/
							pStrSafeLoc->wTailLink = strPointResult.wLinkId;
							pStrSafeLoc->dwTailOffset = strPointResult.dwOffset;
						}
						else
						{
							/*不处理*/
						}
					}
				}
				else
				{
					/*计算失败，返回默认值*/
					chReturnValue = 0u;
				}
			}
		}
		else if (CALOTHERFLAG == safeFlag)
		{
			/*查询车头安全位置*/
			if (FINDHEADSAFEFLAG == chFlag)
			{
				/*调用功能函数“已知旧位置和位移判断新位置进行查询”*/
				chFunRtn = dsuNewLocAndObsByOffsetDis(strPoint, dwDistance, chDirection, &strPointResult, pSwitchId);

				chReturnValue = chFunRtn;

				/*函数因线路尽头或查询成功*/
				if ((3u == chFunRtn) || (1u == chFunRtn))
				{
					/*设置车头安全位置*/
					pStrSafeLoc->wHeadLink = strPointResult.wLinkId;
					pStrSafeLoc->dwHeadOffset = strPointResult.dwOffset;
				}
				else
				{
					/*不处理*/
				}
			}
			else
			{
				/*查询车尾安全位置*/
				if (FINDTAILSAFEFLAG == chFlag)
				{
					/*查询车尾位置需要按照列车运行方向的反向计算，进行方向的颠倒*/
					if (DIR_SAME == chDirection)
					{
						bTailDir = DIR_CONVERT;
					}
					else
					{
						bTailDir = DIR_SAME;
					}
					chFunRtn = dsuNewLocAndObsByOffsetDis(strPoint, dwDistance, bTailDir, &strPointResult, pSwitchId);

					chReturnValue = chFunRtn;

					/*函数调用失败，返回查询失败*/
					if ((3u == chFunRtn) || (1u == chFunRtn))
					{
						/*计算成功，输出参数，返回查询成功*/
						pStrSafeLoc->wTailLink = strPointResult.wLinkId;
						pStrSafeLoc->dwTailOffset = strPointResult.dwOffset;
					}
					else
					{
						/*不处理*/
					}
				}
				else
				{
					/*计算失败，返回默认值*/
					chReturnValue = 0u;
				}
			}

		}
		else
		{
			/*不处理*/
			chReturnValue = 0u;
		}
	}
	return chReturnValue;
}

#if 0
/**
* @brief 列车安全车头位置处理函数
* @param UINT8 rtnValue
* @param UINT16 trainID
* @param TrainSafeLocStru *temp_TrainSafeLoc
* @param p_strPointInArea pSwitchInfo
* @return 无
* @note 修复bug YF0083-115、120
*/
void UpdateTrainSafePos(UINT8 rtnValue, UINT16 trainID, TrainSafeLocStru *temp_TrainSafeLoc)
{
	UINT16 trainMaxHeadLink = 0u;       /*列车最大安全前所处区段*/
	UINT32 trainMaxHeadOffset = 0u;     /*列车最大安全前所处区段偏移量*/
	UINT8 trainDir = CI_ERROR;          /*列车方向*/
	UINT16 wAcId = 0u;
	UINT8 chSleepStt = 0u;
	ELM_AxisLocStruct tmpACLoc = { 0u };       /* 计轴端点位置*/
	UINT8 chFunRtn = CI_ERROR;
	UINT16 wSleepLink = 0u;
	UINT8 safeDir = 0u;
	UINT8 changePNum = 0u;
	LOD_STRU pSafeHead = { 0u };
	LOD_STRU pMaxHead = { 0u };
	UINT8 cDirectionPointCnt = 0U;			/*方向变化点数量*/
	UINT8 changePointFlag = 0u;
	
	/** 入参检查*/
	if (NULL != temp_TrainSafeLoc)
	{
		wSleepLink = GetTrainSleepLink(trainID);
		trainMaxHeadLink = GetTrainMaxHeadLink(trainID);
		trainMaxHeadOffset = GetTrainMaxHeadOffset(trainID);
		pMaxHead.Lnk = trainMaxHeadLink;
		pMaxHead.Off = trainMaxHeadOffset;
		trainDir = GetTrainDir_MaxHead(trainID);/*最大安全前端位置*/
		wAcId = GetLinkBelongAcId(wSleepLink);
		
		chSleepStt = GetTrainSleepState(trainID);
		if ((TRAIN_SLEEP_YES == chSleepStt) && (wSleepLink == temp_TrainSafeLoc->wHeadLink))
		{
			chFunRtn = elm_PrepareACLoc(wAcId, trainDir, &tmpACLoc);
			/*休眠轨旁存在方向变化点，列车休眠失败*/
			changePointFlag = GetLinkLogicDirChangedById(wSleepLink);

			if ((0u == wAcId) || (CI_SUCCESS != chFunRtn)
				|| (LINK_DIRCHANGE_NONE != changePointFlag))
			{/* 数据查询失败，清除休眠车状态 */
				SetTrainSleepState(trainID, TRAIN_SLEEP_NO);
				SetTrainSleepLink(trainID, 0u);
				debug_infor_printf((const)"Train%x delete sleep state because data error.\n", trainID);
			}
			else
			{
				(void)SetTrainSafeHeadLink(trainID, tmpACLoc.endPos.Lnk);
				(void)SetTrainSafeHeadOffset(trainID, tmpACLoc.endPos.Off);
				(void)SetTrainSafeHeadDir(trainID, trainDir);
			}
		}
		else
		{
			pSafeHead.Lnk = temp_TrainSafeLoc->wHeadLink;
			pSafeHead.Off = temp_TrainSafeLoc->dwHeadOffset;
			changePNum = GetDirChangeNumBtwPoints(&pSafeHead, &pMaxHead);
			safeDir = TransDirByChangeNum(trainDir, changePNum);			/*根据方向变化点数量奇偶转方向*/
			
			/*安全位置查询成功*/
			if ((3u == rtnValue) || (1u == rtnValue))
			{
				(void)SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
				(void)SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwHeadOffset);
				(void)SetTrainSafeHeadDir(trainID, safeDir);
			}
			else if (2u == rtnValue)
			{
				/*安全位置由于道岔而查询失败，列车紧急，将安全位置置为岔尖*/
				(void)SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
				(void)SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwHeadOffset);
				(void)SetTrainSafeHeadDir(trainID, safeDir);
			}
			else
			{
				/*安全位置由于入口参数查询失败，列车紧急，将非安全位置作为安全位置*/
				(void)SetTrainSafeHeadLink(trainID, trainMaxHeadLink);
				(void)SetTrainSafeHeadOffset(trainID, trainMaxHeadOffset);
				(void)SetTrainSafeHeadDir(trainID, safeDir);
			}
		}
		(void)SetTrainSafeHeadFlag(trainID);
	}
	else
	{

	}
}
#endif

#if 0
/**
* @brief VBTC列车安全位置处理函数
* @param UINT8 rtnValue
* @param UINT16 trainID
* @param TrainSafeLocStru *temp_TrainSafeLoc
* @return 无
*/
void UpdateVbtcTrainSafePos(UINT8 rtnValue, UINT16 trainID, TrainSafeLocStru *temp_TrainSafeLoc)
{
	UINT8 returnValue = 0u;                  /*比较安全位置与MA终点顺序的返回值*/
	UINT8 trainDirection = 0u;               /*列车运行方向*/
	UINT8 checkSafeBackRtn = 0u;              /*比较安全位置是否越过MA的返回值*/
	UINT8  chDirIsSame = 0u;
	UINT8 checkUnSafeBackRtn = 0u;              /*比较列车汇报位置是否越过MA的返回值*/
	UINT8 chTrainDir = 0u;
	UINT8 chMaDir = 0u;
	struct_PathPoint strTemp = { 0u };
	struct_PathPoint strMaTemp = { 0u };
	UINT32 dwLen = UINT32_MAX;
	UINT8 chPointDir = 0u;
														  /*获得列车运行方向*/
	chTrainDir = GetTrainDir(trainID);
	chMaDir = GetTrainMaDir(trainID);
	if (0x02 == rtnValue)
	{
		/*安全位置若由于道岔而查询失败，则列车降级，安全位置为岔芯*/
		SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
		SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
	}
	else if ((0x01 == rtnValue) || (0x03 == rtnValue))
	{
		/*判断MA的方向与列车的运行方向是否一致,暂考虑方向变化点，列车折返时有一周期会不一致*/
		if (chTrainDir != chMaDir)
		{
			/*若方向不一致，对于列车的安全位置不进行修正*/
			SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
			SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
		}
		else
		{
			/*若方向一致*/
			/*若为查询成功，需要判断列车安全位置是否越过缓存的具有停车保证的MA*/
			strTemp.wLinkId = temp_TrainSafeLoc->wHeadLink;
			strTemp.dwOffset = temp_TrainSafeLoc->dwHeadOffset;
			strMaTemp.wLinkId = GetTrainMaEndLink(trainID);
			strMaTemp.dwOffset = GetTrainMaEndOffset(trainID);

			dwLen = DsuAPointToBPoint(&strTemp, &strMaTemp, &chPointDir);
			if ((UINT32_MAX == dwLen) || ((DIR_SAME != chPointDir) && (DIR_CONVERT != chPointDir)))
			{
				/* 查询失败，不进行修正 */
				SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
				SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
			}
			else if (chPointDir == chMaDir)
			{
				/*未越过MA终点，安全位置不进行修正*/
				SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
				SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
			}
			else
			{
				/*安全包络计算值越过MA终点，计算实际列车是否越过*/
				strTemp.wLinkId = GetTrainMaxHeadLink(trainID);
				strTemp.dwOffset = GetTrainMaxHeadOffset(trainID);

				dwLen = DsuAPointToBPoint(&strTemp, &strMaTemp, &chPointDir);
				if ((UINT32_MAX == dwLen) || ((DIR_SAME != chPointDir) && (DIR_CONVERT != chPointDir)))
				{
					/* 查询失败，不进行修正 */
					SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
					SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
				}
				else if (chPointDir == chMaDir)
				{
					/*列车汇报位置未越过MA终点，安全位置越过，安全位置需要回撤至该MA终点(列车能保证停下的点)*/
					SetTrainSafeHeadLink(trainID, strMaTemp.wLinkId);
					SetTrainSafeHeadOffset(trainID, strMaTemp.dwOffset);
				}
				else
				{
					/*列车汇报位置越过MA终点或者查询失败，对于列车的安全位置不进行修正*/
					SetTrainSafeHeadLink(trainID, temp_TrainSafeLoc->wHeadLink);
					SetTrainSafeHeadOffset(trainID, temp_TrainSafeLoc->dwTailOffset);
				}
			}
		}
	}
	else
	{
		/*由于入口参数查询失败，列车紧急降级*/
		SetTrainSafeHeadLink(trainID, GetTrainMaxHeadLink(trainID));
		SetTrainSafeHeadOffset(trainID, GetTrainMaxHeadOffset(trainID));
	}
}
#endif

/**
* @brief 根据列车非安全信息计算列车安全车头位置函数
* @param UINT16  trainID
* @param UINT32 dwHeadDistance
* @param UINT8 chDir
* @return 无
*/
static void CalHeadTrainSafePosFromUnSafe(UINT16 wTrainId, UINT32 dwHeadDistance, UINT8 chDir)
{
	UINT16 wTrainHeadLink = 0u;			/*列车车头LINK*/
	UINT32 dwTrainHeadOffset = 0u;			/*列车车头LINK偏移量*/
	UINT16 wSwitchId = 0u;
	UINT8 chFunRtn = 0u;                    /*安全位置计算返回值*/
	TrainSafeLocStru Temp_TrainSafeLoc;          /*列车安全位置结构体*/
	UINT16 wHeadAcId = 0U;/*计轴区段ID*/
	ELM_AxisLocStruct tmpHeadACLoc = { 0U };       /* 计轴端点位置*/
	UINT8 chTempCheckFlag = CI_ERROR;/*临时检查标志*/
	UINT8 chNvramPosFlag = 0U;/*NVRAM位置标识*/
	UINT8 chSleepStt = 0U;/*列车休眠状态*/
	UINT16 wSleepLink = 0U;
	UINT16 wAcId = 0U;
	ELM_AxisLocStruct tmpACLoc = { 0U };       /* 计轴端点位置*/
	UINT8 changePointFlag = 0U;
	LOD_STRU pSafeHead = { 0U };
	LOD_STRU pMaxHead = { 0U };
	UINT8 safeDir = 0U;
	UINT8 changePNum = 0U;

	/*清空结构体*/
	(void)memset(&Temp_TrainSafeLoc, 0x00, sizeof(TrainSafeLocStru));
	wTrainHeadLink = GetTrainMaxHeadLink(wTrainId);
	dwTrainHeadOffset = GetTrainMaxHeadOffset(wTrainId);
	chNvramPosFlag = GetTrainNvramPosFlag(wTrainId);
	chSleepStt = GetTrainSleepState(wTrainId);
	chTempCheckFlag = IsLinkSwTrack(wTrainHeadLink);

	/*计算安全位置*/
	wSwitchId = (UINT16)UINT16_MAX;
	chFunRtn = CalTrainSafeLoc(FINDHEADSAFEFLAG, CALSAFEPOSFLAG, wTrainHeadLink, dwTrainHeadOffset, dwHeadDistance, chDir, &wSwitchId, &Temp_TrainSafeLoc);

	wSleepLink = GetTrainSleepLink(wTrainId);
	pMaxHead.Lnk = wTrainHeadLink;
	pMaxHead.Off = dwTrainHeadOffset;
	wAcId = GetLinkBelongAcId(wSleepLink);

	if ((TRAIN_SLEEP_YES == chSleepStt) && (wSleepLink == Temp_TrainSafeLoc.wHeadLink))
	{
		chTempCheckFlag = elm_PrepareACLoc(wAcId, chDir, &tmpACLoc);
		/*休眠轨旁存在方向变化点，列车休眠失败*/
		changePointFlag = GetLinkLogicDirChangedById(wSleepLink);

		if ((0u == wAcId) || (CI_SUCCESS != chTempCheckFlag)
			|| (LINK_DIRCHANGE_NONE != changePointFlag))
		{/* 数据查询失败，清除休眠车状态 */
			SetTrainSleepState(wTrainId, TRAIN_SLEEP_NO);
			SetTrainSleepLink(wTrainId, 0U);
			debug_infor_printf((const)"Train%x delete sleep state because data error.\n", wTrainId);

			SetTrainVirHeadScreenPassFlag(wTrainId,TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainFullEnterLjkCycNum(wTrainId, 0U);
			SetTrainEnterLjkLinkId(wTrainId, 0U);

			/*获取休眠唤醒轨的计轴区段信息失败或休眠唤醒轨存在方向变化点，置监督状态为无效*/
			SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_INVALID);
			SetTrainPosMonitorInLink(wTrainId, 0U);
		}
		else
		{
			(void)SetTrainSafeHeadLink(wTrainId, tmpACLoc.endPos.Lnk);
			(void)SetTrainSafeHeadOffset(wTrainId, tmpACLoc.endPos.Off);
			(void)SetTrainSafeHeadDir(wTrainId, chDir);
		}
	}
	else if ((TRAIN_NVRAM_POS_FLAG_NO != chNvramPosFlag) && (TRAIN_SLEEP_YES != chSleepStt) && (CI_SUCCESS == chTempCheckFlag) && (wTrainHeadLink == Temp_TrainSafeLoc.wHeadLink))
	{
		/*非休眠列车完全在休眠唤醒轨使用NVRAM位置，延伸到计轴区段终点*/
		wHeadAcId = GetLinkBelongAcId(wTrainHeadLink);
		chTempCheckFlag = elm_PrepareACLoc(wHeadAcId, chDir, &tmpHeadACLoc);

		if (CI_SUCCESS == chTempCheckFlag)
		{
			(void)SetTrainSafeHeadLink(wTrainId, tmpHeadACLoc.endPos.Lnk);
			(void)SetTrainSafeHeadOffset(wTrainId, tmpHeadACLoc.endPos.Off);
			(void)SetTrainSafeHeadDir(wTrainId, chDir);
		}
		else
		{
			(void)SetTrainSafeHeadLink(wTrainId, 0U);
			(void)SetTrainSafeHeadOffset(wTrainId, UINT32_MAX);
			ClearTrainSafeHeadDir(wTrainId);
			SetTrainVirHeadScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainFullEnterLjkCycNum(wTrainId, 0U);
			SetTrainEnterLjkLinkId(wTrainId, 0U);

			/*获取列车大前的计轴区段信息失败，置监督状态为无效*/
			SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_INVALID);
			SetTrainPosMonitorInLink(wTrainId, 0U);
		}
	}
	else
	{
		pSafeHead.Lnk = Temp_TrainSafeLoc.wHeadLink;
		pSafeHead.Off = Temp_TrainSafeLoc.dwHeadOffset;
		changePNum = GetDirChangeNumBtwPoints(&pSafeHead, &pMaxHead);
		safeDir = TransDirByChangeNum(chDir, changePNum);                        /*根据方向变化点数量奇偶转方向*/

		/*安全位置查询成功*/
		if ((3u == chFunRtn) || (1u == chFunRtn))
		{
			(void)SetTrainSafeHeadLink(wTrainId, Temp_TrainSafeLoc.wHeadLink);
			(void)SetTrainSafeHeadOffset(wTrainId, Temp_TrainSafeLoc.dwHeadOffset);
			(void)SetTrainSafeHeadDir(wTrainId, safeDir);
		}
		else if (2u == chFunRtn)
		{
			/*安全位置由于道岔而查询失败，列车紧急，将安全位置置为岔尖*/
			(void)SetTrainSafeHeadLink(wTrainId, Temp_TrainSafeLoc.wHeadLink);
			(void)SetTrainSafeHeadOffset(wTrainId, Temp_TrainSafeLoc.dwHeadOffset);
			(void)SetTrainSafeHeadDir(wTrainId, safeDir);
		}
		else
		{
			/*安全位置由于入口参数查询失败*/
			(void)SetTrainSafeHeadLink(wTrainId, 0U);
			(void)SetTrainSafeHeadOffset(wTrainId, UINT32_MAX);
			ClearTrainSafeHeadDir(wTrainId);
		}
	}
	(void)SetTrainSafeHeadFlag(wTrainId);
}



/**
* @brief 根据列车非安全信息计算列车安全车尾位置函数
* @param UINT16  trainID
* @param UINT32 tailDistance
* @param UINT8 trainDirection  最小安全后端方向
* @return 无
*/
static void CalTailTrainSafePosFromUnSafe(UINT16  trainID, UINT32 tailDistance, UINT8 trainDirection)
{
	UINT16 trainTailLink = 0u;			/*列车车尾LINK*/
	UINT32 trainTailOffset = 0u;			/*列车车尾LINK偏移量*/
	UINT16 wSwitchId = UINT16_MAX;                /*道岔ID*/
	TrainSafeLocStru strTrainSafeLoc;          /*列车安全位置结构体*/
	UINT8 calTailReturn = 0u;                    /*车尾安全位置计算返回值*/
	UINT16 wAcId = 0u;
	UINT8 chSleepStt = 0u;
	ELM_AxisLocStruct tmpACLoc = { 0u };       /* 计轴端点位置*/
	UINT8 chFunRtn = CI_ERROR;
	UINT16 wSleepLink = 0u;
	UINT8 safeDir = 0u;
	UINT8 changePNum = 0u;
	LOD_STRU pSafeTail = { 0u };
	LOD_STRU pMinTail = { 0u };
	UINT16 wTailAcId = 0U;/*小后所处计轴区段ID*/
	ELM_AxisLocStruct tmpTailACLoc = { 0U };       /* 小后所处计轴端点位置*/
	UINT8 chTempCheckFlag = CI_ERROR;/*临时检查标志*/
	UINT8 chNvramPosFlag = 0U;/*NVRAM位置标识*/


	(void)memset(&strTrainSafeLoc, 0, sizeof(TrainSafeLocStru));
	/*获取列车非安全车尾信息*/
	trainTailLink = GetTrainMinTailLink(trainID);
	trainTailOffset = GetTrainMinTailOffset(trainID);
	chSleepStt = GetTrainSleepState(trainID);
	chNvramPosFlag = GetTrainNvramPosFlag(trainID);

	chTempCheckFlag = IsLinkSwTrack(trainTailLink);

	pMinTail.Lnk = trainTailLink;
	pMinTail.Off = trainTailOffset;
	wSleepLink = GetTrainSleepLink(trainID);
	wAcId = GetLinkBelongAcId(wSleepLink);

	/*计算安全位置*/
	calTailReturn = CalTrainSafeLoc(FINDTAILSAFEFLAG, CALSAFEPOSFLAG, trainTailLink, trainTailOffset, tailDistance, trainDirection, &wSwitchId, &strTrainSafeLoc);
	if ((TRAIN_SLEEP_YES == chSleepStt) && (wSleepLink == strTrainSafeLoc.wTailLink))
	{
		chFunRtn = elm_PrepareACLoc(wAcId, trainDirection, &tmpACLoc);
		if ((0u == wAcId) || (CI_SUCCESS != chFunRtn))
		{/* 数据查询失败，清除休眠车状态 */
			SetTrainSleepState(trainID, TRAIN_SLEEP_NO);
			SetTrainSleepLink(trainID, 0u);
			debug_infor_printf((const)"Train%x delete sleep state because data error.\n", trainID);

			SetTrainVirHeadScreenPassFlag(trainID, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainVirTailScreenPassFlag(trainID, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainFullEnterLjkCycNum(trainID, 0U);
			SetTrainEnterLjkLinkId(trainID, 0U);

			/*获取休眠唤醒轨的计轴区段信息失败，置监督状态为无效*/
			SetTrainPosMonitorState(trainID, TRAIN_POS_MONITOR_INVALID);
			SetTrainPosMonitorInLink(trainID, 0U);
		}
		else
		{
			(void)SetTrainSafeTailLink(trainID, tmpACLoc.startPos.Lnk);
			(void)SetTrainSafeTailOffset(trainID, tmpACLoc.startPos.Off);
			(void)SetTrainSafeTailDir(trainID, trainDirection);/*休眠车，安全车尾到最小安全后端未经过方向变化点，采用最小安全后端方向*/
		}
	}
	else if ((TRAIN_NVRAM_POS_FLAG_NO != chNvramPosFlag) && (TRAIN_SLEEP_YES != chSleepStt) && (CI_SUCCESS == chTempCheckFlag) && (trainTailLink == strTrainSafeLoc.wTailLink))
	{
		/*非休眠列车完全在休眠唤醒轨使用NVRAM位置，延伸到计轴去段终点*/
		wTailAcId = GetLinkBelongAcId(trainTailLink);
		chTempCheckFlag = elm_PrepareACLoc(wTailAcId, trainDirection, &tmpTailACLoc);

		if (CI_SUCCESS == chTempCheckFlag)
		{
			(void)SetTrainSafeTailLink(trainID, tmpTailACLoc.startPos.Lnk);
			(void)SetTrainSafeTailOffset(trainID, tmpTailACLoc.startPos.Off);
			(void)SetTrainSafeTailDir(trainID, trainDirection);/*休眠车，安全车尾到最小安全后端未经过方向变化点，采用最小安全后端方向*/
		}
		else
		{
			(void)SetTrainSafeTailLink(trainID, 0U);
			(void)SetTrainSafeTailOffset(trainID, UINT32_MAX);
			ClearTrainSafeTailDir(trainID);

			SetTrainVirHeadScreenPassFlag(trainID, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainVirTailScreenPassFlag(trainID, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
			SetTrainFullEnterLjkCycNum(trainID, 0U);
			SetTrainEnterLjkLinkId(trainID, 0U);

			/*获取列车小后的计轴区段信息失败，置监督状态为无效*/
			SetTrainPosMonitorState(trainID, TRAIN_POS_MONITOR_INVALID);
			SetTrainPosMonitorInLink(trainID, 0U);
		}

	}
	else
	{
		pSafeTail.Lnk = strTrainSafeLoc.wTailLink;
		pSafeTail.Off = strTrainSafeLoc.dwTailOffset;
		changePNum = GetDirChangeNumBtwPoints(&pSafeTail, &pMinTail);
		safeDir = TransDirByChangeNum(trainDirection, changePNum);			/*根据方向变化点数量奇偶转方向*/

		if (2u == calTailReturn)
		{
			/*由于道岔安全位置计算失败，列车紧急，安全位置置于四开道岔*/
			(void)SetTrainSafeTailLink(trainID, strTrainSafeLoc.wTailLink);
			(void)SetTrainSafeTailOffset(trainID, strTrainSafeLoc.dwTailOffset);
			(void)SetTrainSafeTailDir(trainID, safeDir);
		}
		else if ((3u == calTailReturn) || (1u == calTailReturn))
		{
			/*安全位置计算成功*/
			(void)SetTrainSafeTailLink(trainID, strTrainSafeLoc.wTailLink);
			(void)SetTrainSafeTailOffset(trainID, strTrainSafeLoc.dwTailOffset);
			(void)SetTrainSafeTailDir(trainID, safeDir);
		}
		else
		{
			(void)SetTrainSafeTailLink(trainID, 0U);
			(void)SetTrainSafeTailOffset(trainID, UINT32_MAX);
			ClearTrainSafeTailDir(trainID);
		}
	}
}

/**
* @brief 列车安全位置计算函数
* @param 无
* @return 无
*/
static void CalTrainSafePosition(void)
{
	UINT16 trainCycle = 0u;/*列车管理数组循环控制变量*/
	UINT16 wTailDis = 0u;  /*站台追踪时，列车间隔距离 即退行防护距离，单位：cm*/
	UINT8 chDirHead = 0u;/*车头列车运行方向*/
	UINT8 chDirTail = 0u;/*车尾列车运行方向*/
	UINT16 trainSpeed = 0u;/*列车运行速度*/
	FLOAT64  trainRedundancy = 0.0;          
	FLOAT64 gradeAcc = 0.0;
	INT32  dwHeadDistance = 0;                /*车头包络距离*/
	UINT16 wTrainId = UINT16_MAX;
	UINT8 chTrainType = 0u;
	CBTC_TRAIN_INFO_STRU strTrainInfo = { 0u };
	UINT32 dwDelayTime = 0u;
	UINT8 chTrainSpeedDir = 0u;
	UINT16 wMaxHeadLink = 0u;
	UINT32 dwMaxHeadOffset = UINT32_MAX;
	UINT16 wMinTailLink = 0u;
	UINT32 dwMinTailOffset = UINT32_MAX;
	UINT8 chFunRtn = CI_ERROR;
	UINT8 chTransmitStat = TRAIN_COMM_STATE_BAD;
	UINT8 chSleepState = 0u;
	UINT32 dwTransBadCyc = 0u;
	UINT32 dwCurCyc = 0u;
	UINT8 chSss = 0u;
	UINT8 chResult = CI_ERROR;
	UINT32 dwTailDistance = 0U;/*退行距离*/
	UINT8 chTrainIsSwTrackFlag = CI_ERROR;/*列车休眠唤醒轨标志*/
	ELM_TrainSafeLocStruct strTrainSafeLoc = { 0U };    /*列车安全位置*/
	UINT8 ii = 0U;
	UINT8 cSafeLocRelAcNum = 0U;  /*安全位置覆盖的计轴区段数量*/
	UINT16 szSafeLocRelAcId[SECTION_IN_ENVELOPE_SUM_MAX] = { 0U };      /*安全位置覆盖的计轴区段ID*/
	
	/*计算列车安全位置前，周期清除计轴区段列车安全位置覆盖标志为无效*/
	ClearAxisTXSafeLocFlag();

	/*遍历所有列车*/
	for (trainCycle = 0u; trainCycle < TRAIN_SUM_MAX; trainCycle++)
	{
		wTrainId = GetTrainId(trainCycle);
		wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
		dwMaxHeadOffset = GetTrainMaxHeadOffset(wTrainId);
		wMinTailLink = GetTrainMinTailLink(wTrainId);
		dwMinTailOffset = GetTrainMinTailOffset(wTrainId);
		chFunRtn = CheckLinkValid(wMaxHeadLink, dwMaxHeadOffset);
		chFunRtn &= CheckLinkValid(wMinTailLink, dwMinTailOffset);
		/*OC为位置有效列车计算安全包络*/
		if (CI_SUCCESS == chFunRtn)
		{
			/*获得列车非安全位置信息*/
			chDirHead = GetTrainDir_MaxHead(wTrainId);
			chDirTail = GetTrainDir(wTrainId);
			/*获取列车速度*/
			trainSpeed = GetTrainSpeed(wTrainId);

			/*获取列车类型*/
			chFunRtn = dquGetTrainType(wTrainId, &chTrainType);

			/*获取列车性能参数*/
			chFunRtn &= dquGetCbtcTrainInfo(chTrainType, &strTrainInfo);

			if (CI_SUCCESS == chFunRtn)
			{
				/*列车的通信协议延迟时间计算*/
				dwDelayTime = GetTrainMsgDelayTime(wTrainId);
				trainRedundancy = (FLOAT64)dwDelayTime / 1000.0;

				gradeAcc = (FLOAT64)strTrainInfo.WorstGrade / 10.0;

				chSss = GetTrainStopSteadyState(wTrainId);
				chTrainIsSwTrackFlag = CheckTrainIsSwTrack(wTrainId);

				if ((TRAIN_SS_YES == chSss) && (CI_SUCCESS == chTrainIsSwTrackFlag))
				{
					/*列车在休眠唤醒轨停准停稳后，车头向前计算距离为0*/
					dwHeadDistance = 0;
				}
				else
				{
					/*避免计算Vt及1/2at^2时丢掉小数位，然后各加1*/
					dwHeadDistance = (INT32)((FLOAT64)trainSpeed * trainRedundancy) + 1 +
						((INT32)((FLOAT64)((FLOAT64)strTrainInfo.TrainMaxTracAcc + gradeAcc) * trainRedundancy * trainRedundancy / 2.0) + 1);
				}
				

				/*通过列车的非安全位置信息以及车头安全包络距离计算出车头安全位置*/
				CalHeadTrainSafePosFromUnSafe(wTrainId, (UINT32)dwHeadDistance, chDirHead);

				/*计算车列车的车尾安全包络距离*/
				/*判断列车此时是处于零速状态并且未停准停稳，或者期望运行方向与实际运行方向相反*/
				chTrainSpeedDir = GetTrainSpeedDir(wTrainId);
				
				/*by cgh 20240417 列车安全位置计算，当判断列车速度方向向后且非停准停稳，加退行包络不区分站台区间；*/
				if ((TRAIN_SPEED_FRONT != chTrainSpeedDir) && (TRAIN_SS_YES != chSss))
				{
					wTailDis = strTrainInfo.StationTrackDistance;
					if (wTailDis < (UINT32)dwHeadDistance)
					{
						/* 最大退行防护距离 */
						dwTailDistance = wTailDis;
					}
					else
					{
						dwTailDistance = (UINT32)dwHeadDistance;
					}
				}
				else
				{
					/*计算列车车尾运行距离信息*/
					dwTailDistance = 0U;
				}

				/*通过列车的非安全位置信息以及车尾安全包络距离计算出车尾的安全位置*/
				CalTailTrainSafePosFromUnSafe(wTrainId, dwTailDistance, chDirTail);
				chTransmitStat = GetTrainTransitmitStat(wTrainId);
				dwTransBadCyc = GetTrainTransBadCyc(wTrainId);
				dwCurCyc = Get2oo2CurCycleNum();
				chSleepState = GetTrainSleepState(wTrainId);
				
				if ((dwCurCyc != dwTransBadCyc) && (TRAIN_COMM_STATE_BAD == chTransmitStat) && (TRAIN_SLEEP_NO == chSleepState))
				{
					chResult = SetTrainMaxHeadLink(wTrainId, 0u);
					chResult &= SetTrainMaxHeadOffset(wTrainId, UINT32_MAX);
					chResult &= SetTrainMinHeadLink(wTrainId, 0u);
					chResult &= SetTrainMinHeadOffset(wTrainId, UINT32_MAX);
					chResult &= SetTrainMaxTailLink(wTrainId, 0u);
					chResult &= SetTrainMaxTailOffset(wTrainId, UINT32_MAX);
					chResult &= SetTrainMinTailLink(wTrainId, 0u);
					chResult &= SetTrainMinTailOffset(wTrainId, UINT32_MAX);
					if (CI_ERROR == chResult)
					{
						; /*暂不处理*/
					}
				}
				else
				{
					/*安全位置更新后，根据列车安全位置设置计轴区段列车安全位置覆盖标志为有效（该标志用于ARB连续占用判断）*/
					chResult = elm_PrepareTrainSafeLoc(wTrainId, &strTrainSafeLoc);  /*获取列车安全位置*/
					if (CI_SUCCESS == chResult)
					{
						cSafeLocRelAcNum = elm_PrepareACBtwPoints(strTrainSafeLoc.startPos, strTrainSafeLoc.endPos, szSafeLocRelAcId);  /*获取列车安全位置包含的计轴区段*/
						for (ii = 0U; ii < cSafeLocRelAcNum; ii++)
						{
							SetAxisTXSafeLocFlag(szSafeLocRelAcId[ii], AXIS_SECTION_SAFELOC_YES);  /*设置对应计轴区段列车安全位置覆盖标志为有效*/
						}
					}
					else
					{
						/*获取列车安全位置失败，不处理*/
					}					
				}
			}
			else
			{
				chResult = SetTrainTransmitStat(wTrainId, TRAIN_COMM_STATE_BAD);
				chResult &= SetTrainMaxHeadLink(wTrainId, 0u);
				chResult &= SetTrainMaxHeadOffset(wTrainId, UINT32_MAX);
				chResult &= SetTrainMinHeadLink(wTrainId, 0u);
				chResult &= SetTrainMinHeadOffset(wTrainId, UINT32_MAX);
				chResult &= SetTrainMaxTailLink(wTrainId, 0u);
				chResult &= SetTrainMaxTailOffset(wTrainId, UINT32_MAX);
				chResult &= SetTrainMinTailLink(wTrainId, 0u);
				chResult &= SetTrainMinTailOffset(wTrainId, UINT32_MAX);
				if (CI_ERROR == chResult)
				{
					; /*暂不处理*/
				}
			}
		}
		else
		{
			/*不进行安全通过列车的非安全位置计算*/
			ClearTrainSafeHeadDir(wTrainId);
			ClearTrainSafeTailDir(wTrainId);
			chResult = SetTrainSafeHeadLink(wTrainId, 0u);
			chResult &= SetTrainSafeHeadOffset(wTrainId, UINT32_MAX);
			chResult &= SetTrainSafeTailLink(wTrainId, 0u);
			chResult &= SetTrainSafeTailOffset(wTrainId, UINT32_MAX);
			if (CI_ERROR == chResult)
			{
				; /*暂不处理*/
			}
		}
	}
}

/**
* @brief 计算消息延迟时间
* @param UINT32 CurrentOwnSN 本方的当前周期号
* @param UINT32 SNPeriod 本方的通信周期，在CI系统中，认为是应用的周期
* @param UINT32 srcRecvCiMsgSN,对方上次收到的本方的序号
* @param UINT32 srcCrntOwnMsgSN,对方发送最近数据时其当前的序号
* @param UINT32 srcPreOwnMsgSN,对方上次收到本方数据时其当时的序号
* @param UINT32 srcPeriod,对方的通信周期
* @return 消息延迟时间
*/
INT32 CalVobcMsgDelayTime(
	const UINT32 CurrentOwnSN,
	const UINT32 SNPeriod,
	const UINT32 srcRecvCiMsgSN,
	const UINT32 srcCrntOwnMsgSN,
	const UINT32 srcPreOwnMsgSN,
	const UINT32 srcPeriod)
{
	INT32 RemainValidity = 0;

	/*通过收到消息中的回复本方"上一条"消息的时间戳（即RcvOppSN）,计算出总的延迟,
	再减去消息在对方设备内的时间,从而得到双向的传输延迟,将其作为最大传输延迟*/
	RemainValidity = (((INT32)CurrentOwnSN - (INT32)(srcRecvCiMsgSN))*((INT32)(SNPeriod)) -
		((INT32)(srcCrntOwnMsgSN)-(INT32)(srcPreOwnMsgSN))*((INT32)(srcPeriod)));
	
	return RemainValidity;
}

/*
* 功能描述： 清除列车信息
* 参数说明： void
* 返回值  ： void
* 创建: qw.liu 2022-03-04
*/
void ClearTrainInfo(UINT16 wTrainId)
{
	UINT16 wBufIndex = 0U;
	UINT8 ii = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].chTrainLevel = TRAIN_LEVEL_UR;
		gstTrainInfo[wBufIndex].dwIvocCycle = 0U;
		gstTrainInfo[wBufIndex].chTrainDir = DIR_INVALID;
		gstTrainInfo[wBufIndex].chTrainDir_MaxTail = DIR_INVALID;
		gstTrainInfo[wBufIndex].chTrainDir_MaxHead = DIR_INVALID;
		gstTrainInfo[wBufIndex].chTrainDir_MinHead = DIR_INVALID;
		gstTrainInfo[wBufIndex].wTrainMaxHeadLink = 0U;
		gstTrainInfo[wBufIndex].dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].wTrainMinTailLink = 0U;
		gstTrainInfo[wBufIndex].dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].wTrainMinHeadLink = 0U;
		gstTrainInfo[wBufIndex].dwTrainMinHeadOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].wTrainMaxTailLink = 0U;
		gstTrainInfo[wBufIndex].dwTrainMaxTailOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].chSpeedDir = 0U;
		gstTrainInfo[wBufIndex].wTrainSpeed = 0U;
		gstTrainInfo[wBufIndex].chTransmitStat = TRAIN_COMM_STATE_UNKNOWN;
		gstTrainInfo[wBufIndex].chTailScreenStat = 0U;
		gstTrainInfo[wBufIndex].chHeadScreenStat = 0U;
		gstTrainInfo[wBufIndex].chTrainModel = TRAIN_MODE_DEFAULT;
		gstTrainInfo[wBufIndex].chSwState = TRAIN_SLEEP_NO;
		gstTrainInfo[wBufIndex].wSleepLink = 0u;
		gstTrainInfo[wBufIndex].chWakeState = TRAIN_WAKE_DEFAULT;
		gstTrainInfo[wBufIndex].chTrainReportState = 0U;
		gstTrainInfo[wBufIndex].chDynCmd = TRAIN_CMD_DYM_NO;
		gstTrainInfo[wBufIndex].chDynRpl = TRAIN_DYN_RPL_DEFAULT;
		gstTrainInfo[wBufIndex].chScreenApply = TRAIN_SCREEN_DEFAULT;
		gstTrainInfo[wBufIndex].chTrainHeadScreenConfirm = TRAIN_HEAD_CONFIRM_NO;
		gstTrainInfo[wBufIndex].chTrainTailScreenConfirm = TRAIN_TAIL_CONFIRM_NO;
		gstTrainInfo[wBufIndex].chAtsScreenConfirm = TRAIN_ATS_CONFIRM_NO;
		gstTrainInfo[wBufIndex].chStopSteadyState = TRAIN_SS_NO;
		gstTrainInfo[wBufIndex].chSleepCancleFlag = TRAIN_SLEEP_CANCLE_NO;
		gstTrainInfo[wBufIndex].chEaCmd = EA_PROTECT_DEFAULT;
		gstTrainInfo[wBufIndex].chRrmRqst = TRAIN_RRM_RQST_NO;
		gstTrainInfo[wBufIndex].chRrmState = TRAIN_RRM_DEFAULT;
		gstTrainInfo[wBufIndex].chRrmReson = TRAIN_RRM_RESON_FF;
		gstTrainInfo[wBufIndex].chRrmResonFromOtherRc = TRAIN_RRM_RESON_FF;
		gstTrainInfo[wBufIndex].wAtsLgcStation = 0u;
		gstTrainInfo[wBufIndex].wNextTioc = 0u;
		gstTrainInfo[wBufIndex].chDerailment = TRAIN_DERAIL_NO;
		gstTrainInfo[wBufIndex].chNvramPosFlag = TRAIN_NVRAM_POS_FLAG_YES;

		gstTrainInfo[wBufIndex].strHeadTrainLocData.wHeadVobcId = UINT32_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.chHeadTrainLocFlag = HEAD_TRAIN_LOC_DEFAULT;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainAtpLoc.chTrainDir = TRAIN_DIR_DEF;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainAtpLoc.wTrainMaxHeadLink = 0U;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainAtpLoc.dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainAtpLoc.wTrainMinTailLink = 0U;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainAtpLoc.dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.wTrainMaxHeadLink = 0U;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.dwTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.wTrainMinTailLink = 0U;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.dwTrainMinTailOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.chTrainDir = TRAIN_DIR_DEF;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.wLocHeadLoss = UINT16_MAX;
		gstTrainInfo[wBufIndex].strHeadTrainLocData.strHeadTrainIteLoc.wLocTailLoss = UINT16_MAX;

		/*清除ITE发送的列车数据为默认值*/
		for (ii = 0U; ii < TRAIN_INC_ITE_SUM_MAX; ii++)
		{
			gstTrainInfo[wBufIndex].szTrainIteData[ii].wTrainHeadLinkId = 0U;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].dwTrainHeadLinkOffset = UINT32_MAX;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].wTrainTailLinkId = 0U;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].dwTrainTailLinkOffset = UINT32_MAX;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].cTrainDir = TRAIN_DIR_DEF;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].wForWardOffset = UINT16_MAX;
			gstTrainInfo[wBufIndex].szTrainIteData[ii].wBackOffset = UINT16_MAX;
		}

		/*清空所有的后备列车ABL信息结构体*/
		(void)CommonMemSet((void*)&gstTrainInfo[wBufIndex].strAblTrainNeedData, (UINT32)sizeof(ABLTrainInfoStru), 0U, (UINT32)sizeof(ABLTrainInfoStru));
		gstTrainInfo[wBufIndex].wTrainHeadSigId = 0U;
		gstTrainInfo[wBufIndex].wTrainHeadTrainId = TRAIN_ID_MAX;
		gstTrainInfo[wBufIndex].chTrainLocReverseRouteFlag = TRAIN_LOC_REV_ROUTE_FLAG_NONE;

		gstTrainInfo[wBufIndex].chAblTrainDir = DIR_INVALID;
		gstTrainInfo[wBufIndex].wAblTrainMaxHeadLink = 0U;
		gstTrainInfo[wBufIndex].dwAblTrainMaxHeadOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].wAblTrainMinTailLink = 0U;
		gstTrainInfo[wBufIndex].dwAblTrainMinTailOffset = UINT32_MAX;

		gstTrainInfo[wBufIndex].chVirHeadScreenPassFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
		gstTrainInfo[wBufIndex].chVirTailScreenPassFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
		gstTrainInfo[wBufIndex].wEnterLjkLinkId = 0U;
		gstTrainInfo[wBufIndex].dwTrainFullEnterLjkCycNum = 0U;
		
		gstTrainInfo[wBufIndex].chTrainPosMonitorState = TRAIN_POS_MONITOR_INVALID;  /*列车位置监督状态初始化为无效*/
		gstTrainInfo[wBufIndex].wTrainPosMonitorInLink = 0U;  /*列车位置监督有效时所处link为0*/

		gstTrainInfo[wBufIndex].dwStartFlyCycNum = 0U;
		gstTrainInfo[wBufIndex].chEaCmdState = TRAIN_EA_CMD_STATE_INVALID;  /*列车区间疏散命令无效*/
		gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackApplyState = TRAIN_JUMP_BACK_STATE_INVALID;/*初始化未申请*/
		gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackReplyState = TRAIN_JUMP_BACK_STATE_NONE;/*初始化允许默认值*/
		gstTrainInfo[wBufIndex].strJumpBackData.dwJumpBackApplySn = 0U;/*初始化默认序列号*/
	}
	else
	{
		
	}

	
}

/*
* 功能描述：清除指定列车ITE信息
* 参数说明：const UINT16 wTrainId 列车ID
*           const UINT16 wIteLogId Ite逻辑ID
* 返 回 值：void
* Created By LQ 2024.06.06
*/
void ClearTrainIteInfo(const UINT16 wTrainId, const UINT16 wIteLogId)
{
	UINT16 wBufIndex = 0U;
	UINT16 wIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		/*清除ITE发送的列车数据为默认值*/
		wIndex = wIteLogId - 1U;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].wTrainHeadLinkId = 0U;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].dwTrainHeadLinkOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].wTrainTailLinkId = 0U;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].dwTrainTailLinkOffset = UINT32_MAX;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].cTrainDir = TRAIN_DIR_DEF;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].wForWardOffset = UINT16_MAX;
		gstTrainInfo[wBufIndex].szTrainIteData[wIndex].wBackOffset = UINT16_MAX;
	}
	else
	{
		/*列车ID非法，不处理*/
	}
}

/*
* 功能描述： 清除后备列车发送信息
* 参数说明： void
* 返回值  ： void
*/
void ClearBackUpTrainInfo(UINT16 wTrainId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		/*清空所有的后备列车ABL信息结构体*/
		(void)CommonMemSet((void*)&gstTrainInfo[wBufIndex].strAblTrainNeedData, (UINT32)sizeof(ABLTrainInfoStru), 0U, (UINT32)sizeof(ABLTrainInfoStru));
	}
}

/**
* @brief 查询列车处于进路位置（使用列车大前、小后）
* @param UINT16 wTrainId 列车ID
* @param UINT16 wRouteId 进路ID
* @return 0：查询失败
*			1：列车未驶入进路
*			2：列车车头驶入进路但未跨压
*			3：列车跨压始端信号机
*			4：列车完全驶入进路
*			5：列车车头出清进路
*/
UINT8 dsuTrainCrossSignal(const UINT16 wTrainId, const UINT16 wRouteId)
{
	UINT8 chRouteDir = 0u;
	UINT16 wStartSignal = 0u;
	UINT16 wEndSignal = 0u;
	struct_PathPoint strTrainMaxHead = { 0u };
	struct_PathPoint strTrainMinTail = { 0u };
	str_Zone strRouteZone = { 0u };
	UINT8 chRtnVal = CI_ERROR;
	str_PointInArea strRouteSwitch = { 0u };
	UINT8 chSwitchNum = 0u;
	RouteSwitchStruct * pRouteSwitch = NULL;
	UINT8 chIndex = 0u;
	UINT8 chFunRtn = 0u;
	UINT32 dwLen = UINT32_MAX;
	UINT32 dwSglCrossLen = 0u;
	UINT8 chDirTemp = 0u;
	str_Zone strTrainZone = { 0u };
	UINT16 wLinkNum = 0u;
	LOD_STRU sLODTrain = { 0U };  /*列车前端位置*/
	LOD_STRU sLODRoute = { 0U };  /*进路始端位置*/
	
	wStartSignal = GetRouteStartSignalId(wRouteId);
	wEndSignal = GetRouteEndSignalId(wRouteId);
	chRouteDir = GetSignalDirection(wStartSignal);  /*进路方向采用信号机防护方向，需确认信号机防护方向与内方第一link */
	strTrainMaxHead.wLinkId = GetTrainMaxHeadLink(wTrainId);
	strTrainMaxHead.dwOffset = GetTrainMaxHeadOffset(wTrainId);
	strTrainMinTail.wLinkId = GetTrainMinTailLink(wTrainId);
	strTrainMinTail.dwOffset = GetTrainMinTailOffset(wTrainId);
	strRouteZone.Dir = chRouteDir;
	strRouteZone.pStart.wLinkId = GetSignalProtectLink(wStartSignal);
	strRouteZone.pStart.dwOffset = GetSignalProtectLinkOff(wStartSignal);
	strRouteZone.pEnd.wLinkId = GetSignalProtectLink(wEndSignal);
	strRouteZone.pEnd.dwOffset = GetSignalProtectLinkOff(wEndSignal);
	strTrainZone.Dir = GetTrainDir(wTrainId);
	strTrainZone.pStart.wLinkId = strTrainMinTail.wLinkId;
	strTrainZone.pStart.dwOffset = strTrainMinTail.dwOffset;
	strTrainZone.pEnd.wLinkId = strTrainMaxHead.wLinkId;
	strTrainZone.pEnd.dwOffset = strTrainMaxHead.dwOffset;
	
	chSwitchNum = GetRouteSwitchSum(wRouteId);
	pRouteSwitch = GetRouteSwitchData(wRouteId);

	if ((DIR_SAME == chRouteDir) || (DIR_CONVERT == chRouteDir))
	{
		chRtnVal = CI_SUCCESS;
	}
	else
	{
		;/* 入参不合法 */
	}

	if (CI_SUCCESS == chRtnVal)
	{
		chRtnVal = CheckLinkValid(strTrainMaxHead.wLinkId, strTrainMaxHead.dwOffset);
		chRtnVal &= CheckLinkValid(strTrainMinTail.wLinkId, strTrainMinTail.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pStart.wLinkId, strRouteZone.pStart.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pEnd.wLinkId, strRouteZone.pEnd.dwOffset);
	}
	else
	{
		;/* 入参不合法 */
	}

	if (CI_SUCCESS == chRtnVal)
	{
		for (chIndex = 0u; chIndex < chSwitchNum; chIndex++)
		{
			strRouteSwitch.SwitchInfo[chIndex].pointID = pRouteSwitch[chIndex].SwitchId;
			strRouteSwitch.SwitchInfo[chIndex].status = pRouteSwitch[chIndex].SwitchPosition;
		}
		strRouteSwitch.SwitchNum = chSwitchNum;
		/* 获取进路包含的link序列 */
		chRtnVal = dsuLinkSeqInAreaBaseSwitchInfo(strRouteZone.pStart, strRouteZone.pEnd, strRouteZone.Dir, &strRouteSwitch, &strRouteZone.pLinkSeq);
		chRtnVal &= DsuLinkSeqBtwPoints(&strTrainZone.pStart, &strTrainZone.pEnd, &strTrainZone.Dir, &wLinkNum, strTrainZone.pLinkSeq.szLinkId);
		strTrainZone.pLinkSeq.cLinkCnt = (UINT8)wLinkNum;
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chRtnVal)
	{
		chFunRtn = IsPointInPath(strTrainMaxHead, strRouteZone);
		if (CI_SUCCESS == chFunRtn)
		{
			/* 列车最大安全前端不在进路内，判断列车车尾 */
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				chRtnVal = TRAIN_ENTER_ROUTE_NO;/* 列车车尾不在进路内 */
				chFunRtn = IsPointInPath(strRouteZone.pStart, strTrainZone);
				if (CI_ERROR == chFunRtn)
				{
					chFunRtn = IsPointInPath(strRouteZone.pEnd, strTrainZone);
					if (CI_ERROR == chFunRtn)
					{
						chRtnVal = TRAIN_ENTER_ROUTE_TAIL;
					}
					else
					{
						;
					}
				}
				else
				{
					;
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_TAIL;/* 列车车头不在进路内，车尾在进路内 */
			}
		}
		else
		{
			/* 列车最大安全车头在进路内 */
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				dwSglCrossLen = (UINT32)GetSigCrossMaxLen()*100U;
				dwLen = DsuAPointToBPoint(&strRouteZone.pStart, &strTrainMaxHead, &chDirTemp);

				if (0U == dwLen)
				{
					sLODTrain.Lnk = strTrainZone.pStart.wLinkId;
					sLODTrain.Off = strTrainZone.pStart.dwOffset;
					sLODTrain.Dir = strTrainZone.Dir;
					sLODRoute.Lnk = strRouteZone.pStart.wLinkId;
					sLODRoute.Off = strRouteZone.pStart.dwOffset;
					sLODRoute.Dir = strRouteZone.Dir;
					chFunRtn = IsPointABSameDir(sLODTrain, sLODRoute);

					if (FLAG_SET == chFunRtn)
					{
						/*列车驶入进路认为列车车头已驶入*/
						chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入*/
					}
					else
					{
						chRtnVal = CI_ERROR;  /*方向相反，返回失败*/
					}

				}
				else if ((UINT32_MAX == dwLen) || (chDirTemp != chRouteDir))
				{
					chRtnVal = CI_ERROR;/* 查询出错 */
				}
				else if(dwLen > dwSglCrossLen)
				{
					chRtnVal = TRAIN_ENTER_ROUTE_CROSS;/* 列车跨压信号机 */
				}
				else
				{
					chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入进路，但未跨压 */
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_FULL;/* 列车完全驶入进路 */
			}
		}
	}
	else
	{
		;
	}



	return chRtnVal;
}


/**
* @brief 查询列车处于进路位置 使用列车最小前，最小后
* @param UINT16 wTrainId 列车ID
* @param UINT16 wRouteId 进路ID
* @return 0：查询失败
*			1：列车未驶入进路
*			2：列车车头驶入进路但未跨压
*           3：列车跨压信号
*			4：列车完全驶入进路
*			5：列车车头出清进路
*/
UINT8 dsuTrainMinHeadCrossSignal(const UINT16 wTrainId, const UINT16 wRouteId)
{
	UINT8 chRouteDir = 0u;
	UINT16 wStartSignal = 0u;
	UINT16 wEndSignal = 0u;
	struct_PathPoint strTrainMinHead = { 0u };
	struct_PathPoint strTrainMinTail = { 0u };
	str_Zone strRouteZone = { 0u };
	UINT8 chRtnVal = CI_ERROR;
	str_PointInArea strRouteSwitch = { 0u };
	UINT8 chSwitchNum = 0u;
	RouteSwitchStruct * pRouteSwitch = NULL;
	UINT8 chIndex = 0u;
	UINT8 chFunRtn = 0u;
	UINT32 dwLen = UINT32_MAX;
	UINT8 chDirTemp = 0u;
	str_Zone strTrainZone = { 0u };
	UINT16 wLinkNum = 0u;
	LOD_STRU sLODTrain = { 0U };  /*列车前端位置*/
	LOD_STRU sLODRoute = { 0U };  /*进路始端位置*/
	UINT32 dwSglCrossLen = 0U;/*跨压距离，数据配置*/

	dwSglCrossLen = (UINT32)GetSigCrossMaxLen() * 100U;
	wStartSignal = GetRouteStartSignalId(wRouteId);
	wEndSignal = GetRouteEndSignalId(wRouteId);
	chRouteDir = GetSignalDirection(wStartSignal);
	strTrainMinHead.wLinkId = GetTrainMinHeadLink(wTrainId);
	strTrainMinHead.dwOffset = GetTrainMinHeadOffset(wTrainId);
	strTrainMinTail.wLinkId = GetTrainMinTailLink(wTrainId);
	strTrainMinTail.dwOffset = GetTrainMinTailOffset(wTrainId);
	strRouteZone.Dir = chRouteDir;
	strRouteZone.pStart.wLinkId = GetSignalProtectLink(wStartSignal);
	strRouteZone.pStart.dwOffset = GetSignalProtectLinkOff(wStartSignal);
	strRouteZone.pEnd.wLinkId = GetSignalProtectLink(wEndSignal);
	strRouteZone.pEnd.dwOffset = GetSignalProtectLinkOff(wEndSignal);
	strTrainZone.Dir = GetTrainDir(wTrainId);
	strTrainZone.pStart.wLinkId = strTrainMinTail.wLinkId;
	strTrainZone.pStart.dwOffset = strTrainMinTail.dwOffset;
	strTrainZone.pEnd.wLinkId = strTrainMinHead.wLinkId;
	strTrainZone.pEnd.dwOffset = strTrainMinHead.dwOffset;

	chSwitchNum = GetRouteSwitchSum(wRouteId);
	pRouteSwitch = GetRouteSwitchData(wRouteId);

	if ((DIR_SAME == chRouteDir) || (DIR_CONVERT == chRouteDir))
	{
		chRtnVal = CI_SUCCESS;
	}
	else
	{
		;/* 入参不合法 */
	}

	if (CI_SUCCESS == chRtnVal)
	{
		chRtnVal = CheckLinkValid(strTrainMinHead.wLinkId, strTrainMinHead.dwOffset);
		chRtnVal &= CheckLinkValid(strTrainMinTail.wLinkId, strTrainMinTail.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pStart.wLinkId, strRouteZone.pStart.dwOffset);
		chRtnVal &= CheckLinkValid(strRouteZone.pEnd.wLinkId, strRouteZone.pEnd.dwOffset);
	}
	else
	{
		;/* 入参不合法 */
	}

	if (CI_SUCCESS == chRtnVal)
	{
		for (chIndex = 0u; chIndex < chSwitchNum; chIndex++)
		{
			strRouteSwitch.SwitchInfo[chIndex].pointID = pRouteSwitch[chIndex].SwitchId;
			strRouteSwitch.SwitchInfo[chIndex].status = pRouteSwitch[chIndex].SwitchPosition;
		}
		strRouteSwitch.SwitchNum = chSwitchNum;
		/* 获取进路包含的link序列 */
		chRtnVal = dsuLinkSeqInAreaBaseSwitchInfo(strRouteZone.pStart, strRouteZone.pEnd, strRouteZone.Dir, &strRouteSwitch, &strRouteZone.pLinkSeq);
		chRtnVal &= DsuLinkSeqBtwPoints(&strTrainZone.pStart, &strTrainZone.pEnd, &strTrainZone.Dir, &wLinkNum, strTrainZone.pLinkSeq.szLinkId);
		strTrainZone.pLinkSeq.cLinkCnt = (UINT8)wLinkNum;
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chRtnVal)
	{
		chFunRtn = IsPointInPath(strTrainMinHead, strRouteZone);
		/* 列车最小安全前端不在进路内，判断列车车尾 */
		if (CI_SUCCESS == chFunRtn)
		{
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			if (CI_SUCCESS == chFunRtn)
			{
				chRtnVal = TRAIN_ENTER_ROUTE_NO;/* 列车车尾不在进路内 */
				chFunRtn = IsPointInPath(strRouteZone.pStart, strTrainZone);
				if (CI_ERROR == chFunRtn)
				{
					chFunRtn = IsPointInPath(strRouteZone.pEnd, strTrainZone);
					if (CI_ERROR == chFunRtn)
					{
						chRtnVal = TRAIN_ENTER_ROUTE_TAIL;
					}
					else
					{
						;
					}
				}
				else
				{
					;
				}
			}
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_TAIL;/* 列车车头不在进路内，车尾在进路内 */
			}
		}
		/* 列车最小安全车头在进路内 */
		else
		{
			chFunRtn = IsPointInPath(strTrainMinTail, strRouteZone);
			/*车尾不在进路内*/
			if (CI_SUCCESS == chFunRtn)
			{
				dwLen = DsuAPointToBPoint(&strRouteZone.pStart, &strTrainMinHead, &chDirTemp);

				if (0U == dwLen)
				{
					sLODTrain.Lnk = strTrainZone.pStart.wLinkId;
					sLODTrain.Off = strTrainZone.pStart.dwOffset;
					sLODTrain.Dir = strTrainZone.Dir;
					sLODRoute.Lnk = strRouteZone.pStart.wLinkId;
					sLODRoute.Off = strRouteZone.pStart.dwOffset;
					sLODRoute.Dir = strRouteZone.Dir;
					chFunRtn = IsPointABSameDir(sLODTrain, sLODRoute);

					if (FLAG_SET == chFunRtn)
					{
						/*列车驶入进路认为列车车头已驶入*/
						chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入*/
					}
					else
					{
						chRtnVal = CI_ERROR;  /*方向相反，返回失败*/
					}
				}
				else if ((UINT32_MAX == dwLen) || (chDirTemp != chRouteDir))
				{
					chRtnVal = CI_ERROR;/* 查询出错 */
				}
				else if (dwLen > dwSglCrossLen)
				{
					chRtnVal = TRAIN_ENTER_ROUTE_CROSS;/* 列车跨压信号机 */
				}
				else
				{
					chRtnVal = TRAIN_ENTER_ROUTE_HEAD;/* 列车车头驶入*/
				}
			}
			/*车尾在进路内*/
			else
			{
				chRtnVal = TRAIN_ENTER_ROUTE_FULL;/* 列车完全驶入进路 */
			}
		}
	}
	else
	{
		;
	}



	return chRtnVal;
}
/*
* 功能描述： 设置指定列车安全车头是否处于占用不连通岔区
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chFlag
* 返回值  ：CI_ERROR: 设置数据失败
CI_SUCCESS:设置数据成功
* 创建 : 2022.3.1
* 修复bug YF0083-119
*/
UINT8 SetTrainSafeHeadFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 chFunRtn = CI_ERROR;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chFunRtn = IsTrainInSafeArea(gstTrainInfo[wBufIndex].strSafeLoc.wHeadLink, gstTrainInfo[wBufIndex].strSafeLoc.dwHeadOffset);
		if (CI_SUCCESS == chFunRtn)
		{
			gstTrainInfo[wBufIndex].strSafeLoc.chHeadFlag = TRAIN_HEAD_FLAG_NO;
		}
		else
		{
			gstTrainInfo[wBufIndex].strSafeLoc.chHeadFlag = TRAIN_HEAD_FLAG_YES;
		}
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车安全车头处于占用不连通岔区标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：列车安全车头处于占用不连通岔区标志
TRAIN_HEAD_FLAG_YES:列车安全车头处于占用且不连通岔区
TRAIN_HEAD_FLAG_NO:列车安全车头不处于占用且不连通岔区
* 创建 : 2022.3.1
*/
UINT8 GetTrainSafeHeadFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strSafeLoc.chHeadFlag;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/**
* @brief 计算消息延迟时间
* @param UINT16 wTrainId
* @return 消息延迟时间
*/
UINT32 GetVobcMsgDelayTime(UINT16 wTrainId)
{
	UINT32 RemainValidity = 0u;
	INT32 dwFunRtn = 0;
	UINT32 CurrentOwnSN = 0u;
	UINT32 SNPeriod = 0u;
	UINT32 srcRecvCiMsgSN = 0u;
	UINT32 srcCrntOwnMsgSN = 0u;
	UINT32 srcPreOwnMsgSN = 0u;
	UINT32 srcPeriod = 0u;
	UINT8 chId = 0u;

	chId = (UINT8)(wTrainId & UINT8_MAX);

	CurrentOwnSN = Get2oo2CurCycleNum();
	SNPeriod = GetSystemParaAppCycleTime();
	srcRecvCiMsgSN = GetHLHTHeadCtxSrcOppSN(CI_SYSTEM_TYPE_VOBC, chId);
	srcCrntOwnMsgSN = GetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_VOBC, chId);
	srcPreOwnMsgSN = GetHLHTHeadCtxSrcOwnSN(CI_SYSTEM_TYPE_VOBC, chId);
	srcPeriod = GetHLHTHeadCtxComPeriod(CI_SYSTEM_TYPE_VOBC, chId);

	dwFunRtn = CalVobcMsgDelayTime(CurrentOwnSN, SNPeriod, srcRecvCiMsgSN, srcCrntOwnMsgSN, srcPreOwnMsgSN, srcPeriod);

	RemainValidity = (UINT32)dwFunRtn;

	return RemainValidity;
}

/**
* @brief 获取列车跟随数据
* @param UINT8 *pDataBuff 跟随数据存储缓冲区
* @param UINT32 curIndex 当前索引
* @return 计算后的索引
*/
UINT32 GetTrainTransferData(OUT UINT8 *pDataBuff, IN UINT32 curIndex)
{
	UINT32 ret = curIndex;
	UINT32 copyIndex = curIndex + 1u;
	UINT8 chIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chTransmitStat = 0u;
	UINT16 wTrainIndex = 0u;
	UINT8 chTrainNum = 0u;
	if (NULL != pDataBuff)
	{
		for (chIndex = 0u; chIndex < (TRAIN_SUM_MAX - 1U); chIndex++)
		{
			wTrainId = GetTrainId(chIndex);
			chTransmitStat = GetTrainTransitmitStat(wTrainId);
			if (TRAIN_COMM_STATE_UNKNOWN != chTransmitStat)
			{
				wTrainIndex = GetTrainBufIndex(wTrainId);
				(void)CommonMemCpy(&pDataBuff[copyIndex], (UINT32)sizeof(TrainInfoStru), &gstTrainInfo[wTrainIndex], (UINT32)sizeof(TrainInfoStru));
				copyIndex += (UINT32)sizeof(TrainInfoStru);
				chTrainNum++;
			}
		}
		pDataBuff[curIndex] = chTrainNum;
		ret = copyIndex;
	}
	return ret;
}

/**
* @brief 设置列车跟随数据
* @param UINT8 *pDataBuff 跟随数据存储缓冲区
* @param UINT32 curIndex 当前索引
* @return 计算后的索引
*/
UINT32 SetTrainTransferData(OUT UINT8 *pDataBuff, IN UINT32 curIndex)
{
	UINT32 ret = curIndex;
	UINT32 copyIndex = curIndex;
	UINT8 chIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT16 wTrainIndex = 0u;
	UINT8 chTrainNum = 0u;
	if (NULL != pDataBuff)
	{
		chTrainNum = pDataBuff[copyIndex++];
		for (chIndex = 0u; chIndex < chTrainNum; chIndex++)
		{
			wTrainId = ShortFromCharLE(&pDataBuff[copyIndex]);
			wTrainIndex = GetTrainBufIndex(wTrainId);

			if (TRAIN_SUM_MAX > wTrainIndex)
			{
				(void)CommonMemCpy(&gstTrainInfo[wTrainIndex], (UINT32)sizeof(TrainInfoStru), &pDataBuff[copyIndex], (UINT32)sizeof(TrainInfoStru));
				copyIndex += (UINT32)sizeof(TrainInfoStru);
			}
		}
		ret = copyIndex;
	}
	return ret;
}

/**
* @brief 判断列车安全车头是否落在占用且四开岔区
* @param wLinkId 列车安全车头所在link
* @return CI_ERROR:列车安全车头落在占用且四开岔区；CI_SUCCESS:列车安全车头未落在占用且四开岔区
* @note：
*/
static UINT8 IsTrainInSafeArea(UINT16 wLinkId, UINT32 dwOffset)
{
	UINT8 chSwitchNum = 0u;
	LogsecSwitchStruct *pSwitchBuff = NULL;
	UINT8 chIndex = 0u;
	UINT8 chRtn = CI_ERROR;
	UINT16 wSwitchId = 0u;
	UINT8 chSwitchState = SWITCH_POSITION_SIKAI;
	UINT16 szLgcIdBuf[POINT_BELONG_LGC_MAX] = { 0u };
	UINT8 chLgcNum = 0u;
	struct_PathPoint strPoint = { 0u };
	UINT8 chLgcIndex = 0u;
	UINT16 wPhyId = 0u;
	UINT8 chPhyState = SECTION_OCCUPY_YES;

	/* 入参检查 */
	chRtn = CheckLinkValid(wLinkId, dwOffset);
	if (CI_SUCCESS == chRtn)
	{
		strPoint.wLinkId = wLinkId;
		strPoint.dwOffset = dwOffset;
		chLgcNum = GetPointBelongLogSecEx(strPoint, szLgcIdBuf);
		if ((0u == chLgcNum) || (POINT_BELONG_LGC_MAX < chLgcNum))
		{/* 获取逻辑区段失败，直接返回失败 */
			chRtn = CI_ERROR;
		}
		else
		{
			;
		}

		if (CI_SUCCESS == chRtn)
		{
			for (chLgcIndex = 0u; chLgcIndex < chLgcNum; chLgcIndex++)
			{/* 遍历逻辑区段，遍历逻辑区段包含道岔，如果岔区占用且四开，返回失败 */
				wPhyId = GetLgcSecRelativePhySecId(szLgcIdBuf[chLgcIndex]);
				chPhyState = GetPhySecCurOccupyState(wPhyId);
				chSwitchNum = GetLogicSecSwitchSum(szLgcIdBuf[chLgcIndex]);
				pSwitchBuff = GetLogicSecSwitchIdStru(szLgcIdBuf[chLgcIndex]);
				if (NULL == pSwitchBuff)
				{
					chRtn = CI_ERROR;
				}
				else if (SECTION_OCCUPY_YES == chPhyState)
				{
					for (chIndex = 0u; chIndex < chSwitchNum; chIndex++)
					{
						wSwitchId = pSwitchBuff[chIndex].SwitchId;
						chSwitchState = GetSwitchCurPosition(wSwitchId);
						if ((SWITCH_POSITION_DINGWEI != chSwitchState) && (SWITCH_POSITION_FANWEI != chSwitchState))
						{/* 岔区计轴区段占用且道岔四开 */
							chRtn = CI_ERROR;
							break;
						}
						else
						{
							;
						}
					}
				}
				else
				{
					/*不处理*/
					;
				}

				if (CI_ERROR == chRtn)
				{
					break;
				}
				else
				{
					;
				}
			}
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
	return chRtn;
}

/*
* 功能描述： 设置指定列车编组时另一列车ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wGroupOtherTrainId 另一辆编组列车ID
* 返回值  ： 0: 获取数据失败	1:	设置数据成功
* 创建 : wsd 2022 - 06 - 16
*/
UINT8 SetGroupTrainOtherId(const UINT16 wTrainId, const UINT16 wGroupOtherTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (((TRAIN_ID_MIN < wGroupOtherTrainId) && (TRAIN_ID_MAX > wGroupOtherTrainId))
			|| (TRAIN_ID_INVAL == wGroupOtherTrainId))
		{
			gstTrainInfo[wBufIndex].wGroupOtherTrainId = wGroupOtherTrainId;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车编组时另一列车ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：获取成功：（0x1400-0x14ff）或0xffff
*			获取失败：0
* 创建: wsd 2022-06-16
*/
UINT16 GetGroupTrainOtherId(const UINT16 wTrainId)
{
	UINT16 wRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wGroupOtherTrainId;
	}
	else
	{
		wRetVal = 0u;
	}

	return wRetVal;
}

/*
* 功能描述： 设置指定列车编组运行状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chGroupRunState 编组运行状态
* 返回值  ： 0: 获取数据失败	1:	设置数据成功
* 创建 : wsd 2022 - 06 - 16
*/
UINT8 SetGroupTrainRunState(const UINT16 wTrainId, const UINT8 chGroupRunState)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((VOBC_CI_GROUP_NO == chGroupRunState) ||
			(VOBC_CI_GROUP_SET == chGroupRunState) ||
			(VOBC_CI_GROUP_RUN == chGroupRunState) ||
			(VOBC_CI_GROUP_REVERSE == chGroupRunState) ||
			(VOBC_CI_GROUP_EXIT == chGroupRunState))
		{
			gstTrainInfo[wBufIndex].chGroupRunState = chGroupRunState;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车编组状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：获取成功：1非编组，2编组建立，3编组运行，4编组折返，5编组解编
			获取失败：0
* 创建: wsd 2022-06-16
*/
UINT8 GetGroupTrainRunState(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chGroupRunState;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车编组运行前后车关系
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chGroupRunState 编组运行状态
* 返回值  ： 0: 设置数据失败 1:	设置数据成功
* 创建 : wsd 2022 - 06 - 16
*/
UINT8 SetGroupTrainRelation(const UINT16 wTrainId, const UINT8 chGroupTrainReat)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if((VOBC_CI_GROUP_HEAD == chGroupTrainReat) ||
			(VOBC_CI_GROUP_TAIL == chGroupTrainReat) ||
			(VOBC_CI_GROUP_INVAL == chGroupTrainReat))
		{
			gstTrainInfo[wBufIndex].chGroupTrainReat = chGroupTrainReat;
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车编组运行前后车关系
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：获取成功：0x55本车为编组前车 0xaa本车为编组后车 0x5a 不是编组车
*			获取失败：0
* 创建: wsd 2022-06-16
*/
UINT8 GetGroupTrainRelation(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chGroupTrainReat;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述：列车A和列车B互为编组运行车判断
* 参数说明： const UINT16 wTrainA, 编组列车A，编组列车B
* 返回值  ： 0 :不是编组运行车
*			 1:是编组运行车
* 创建: wsd 2022-06-16
*/
UINT8 isTwoGroupRunTrain(const UINT16 wTrainA, const UINT16 wTrainB)
{
	UINT16 wGroupOtherTrainA = 0u;
	UINT16 wGroupOtherTrainB = 0u;
	UINT8 chGroupStateA = 0U;
	UINT8 chGroupStateB = 0U;
	UINT8 chGroupRelateA = 0u;
	UINT8 chGroupRelateB = 0u;
	UINT8 chRetVal = CI_ERROR;

	if ((TRAIN_ID_MIN >= wTrainA) || (TRAIN_ID_MAX <= wTrainA) ||
		(TRAIN_ID_MIN >= wTrainB) || (TRAIN_ID_MAX <= wTrainB))
	{
		chRetVal = CI_ERROR;
	}
	else
	{
		chRetVal = CI_SUCCESS;
	}


	if (CI_SUCCESS == chRetVal)
	{
		/*编组另一辆车ID*/
		wGroupOtherTrainA = GetGroupTrainOtherId(wTrainA);
		wGroupOtherTrainB = GetGroupTrainOtherId(wTrainB);

		/*编组列车状态*/
		chGroupStateA = GetGroupTrainRunState(wTrainA);
		chGroupStateB = GetGroupTrainRunState(wTrainB);

		/*编组列车前后车关系*/
		chGroupRelateA = GetGroupTrainRelation(wTrainA);
		chGroupRelateB = GetGroupTrainRelation(wTrainB);

		/*两车都处于编组运行状态*/
		if ((VOBC_CI_GROUP_RUN == chGroupStateA) &&
			(VOBC_CI_GROUP_RUN == chGroupStateB))
		{
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}

		/*互为编组另一辆车*/
		if (CI_SUCCESS == chRetVal)
		{
			if ((wGroupOtherTrainA == wTrainB) && (wGroupOtherTrainB == wTrainA))
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				chRetVal = CI_ERROR;

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

		/*编组前后车关系正确*/
		if (CI_SUCCESS == chRetVal)
		{
			if ((chGroupRelateA != chGroupRelateB) &&
				(chGroupRelateA != VOBC_CI_GROUP_INVAL) &&
				(chGroupRelateB != VOBC_CI_GROUP_INVAL))
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			/* 不处理*/
		}
	}

	return chRetVal;
}

/*
* 功能描述： 检查指定ID列车是否为编组前车
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：0 不是编组前车
			1 是编组前车
* 创建: wsd 2022-06-16
*/
UINT8 isGroupHeadTrain(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 chGroupState = VOBC_CI_GROUP_NO;
	UINT8 chGroupRelate = VOBC_CI_GROUP_INVAL;
	UINT16 wGroupOther = TRAIN_ID_INVAL;
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	if (CI_SUCCESS == chRetVal)
	{
		chGroupState = GetGroupTrainRunState(wTrainId);
		chGroupRelate = GetGroupTrainRelation(wTrainId);
		wGroupOther = GetGroupTrainOtherId(wTrainId);

		/* 编组建立、运行、折返*/
		if ((VOBC_CI_GROUP_SET == chGroupState) ||
			(VOBC_CI_GROUP_RUN == chGroupState) ||
			(VOBC_CI_GROUP_REVERSE == chGroupState))
		{
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}

		/*编组前车、另一编组车ID有效*/
		if ((CI_SUCCESS == chRetVal)&&
			(VOBC_CI_GROUP_HEAD == chGroupRelate)&&
			(TRAIN_ID_INVAL != wGroupOther))
		{
			chRetVal = CI_SUCCESS;
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}

	return chRetVal;
}

/**
* @brief 获取计轴区段上的通信列车
* @param UINT16 wAcId 计轴区段编号
* @param UINT16 szTrainId[TRAIN_SUM_MAX] 通信列车ID
* @return 计轴区段上通信列车数量
* @note：
*/
UINT8 GetTrainInAc(UINT16 wAcId, UINT16 szTrainId[TRAIN_SUM_MAX])
{
	UINT8 chIndex = 0u;
	UINT8 chCtNum = 0u;
	UINT16 wTrainId = 0u;
	struct_PathPoint strMaxHead = { 0u };
	struct_PathPoint strMinTail = { 0u };
	UINT8 chFunRtn = CI_ERROR;
	UINT8 chTransState = 0u;
	UINT8 chDir = 0u;
	UINT16 wLinkNum = 0u;
	UINT16 szLinkId[LINK_SUM_MAX] = { 0u };
	UINT16 wAcNum = 0u;
	UINT16 szAcId[SECTION_IN_ENVELOPE_SUM_MAX] = { 0u };
	UINT16 wAcIndex = 0u;

	for (chIndex = 0u; chIndex < TRAIN_SUM_MAX; chIndex++)
	{
		wAcIndex = 0u;
		wAcNum = 0u;
		wTrainId = GetTrainId(chIndex);
		chTransState = GetTrainTransitmitStat(wTrainId);
		if (TRAIN_COMM_STATE_GOOD == chTransState)
		{
			strMaxHead.wLinkId = GetTrainMaxHeadLink(wTrainId);
			strMaxHead.dwOffset = GetTrainMaxHeadOffset(wTrainId);
			strMinTail.wLinkId = GetTrainMinTailLink(wTrainId);
			strMinTail.dwOffset = GetTrainMinTailOffset(wTrainId);
			chFunRtn = DsuLinkSeqBtwPoints(&strMaxHead, &strMinTail, &chDir, &wLinkNum, szLinkId);

			if (CI_SUCCESS == chFunRtn)
			{
				chFunRtn = GetAxisSeqFromLinkSeq(szLinkId, wLinkNum, szAcId, &wAcNum, SECTION_IN_ENVELOPE_SUM_MAX);
				if (CI_SUCCESS == chFunRtn)
				{
					for (wAcIndex = 0u; wAcIndex < wAcNum; wAcIndex++)
					{
						if (szAcId[wAcIndex] == wAcId)
						{
							break;
						}
						else
						{
							;
						}
					}
				}
				else
				{
					;
				}
			}
			else
			{
				;
			}

			if ((CI_SUCCESS == chFunRtn) && (wAcIndex < wAcNum))
			{
				szTrainId[chCtNum++] = wTrainId;
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}
	}
	return chCtNum;
}

/**
* @brief 判断列车车尾是否向参考点行驶
* @param UINT16 wTrainId 列车ID
* @param struct_PathPoint strPoint 参照点
* @return CI_SUCCESS:列车向参考点行驶，CI_ERROR:列车驶离参考点
* @note：
*/
UINT8 IsTrainMoveToPoint(UINT16 wTrainId, struct_PathPoint strPoint)
{
	UINT32 dwLen = 0u;
	struct_PathPoint strPointTrain = { 0u };
	UINT8 chDir = 0u;
	UINT8 chTrainDir = 0u;
	UINT8 chRtn = CI_SUCCESS;
	UINT8 chSpeedDir = 0u;
	UINT8 chLocalTiocId = 0u;
	UINT16 wTrainTiocId = 0u;
	UINT8 chConverTrainDir = 0u;

	chLocalTiocId = GetSystemParaLocalCiId();
	
	chSpeedDir = GetTrainSpeedDir(wTrainId);
	if (TRAIN_SPEED_FRONT == chSpeedDir)
	{
		strPointTrain.wLinkId = GetTrainMinTailLink(wTrainId);
		strPointTrain.dwOffset = GetTrainMinTailOffset(wTrainId);
		wTrainTiocId = GetLinkManageTiocById(strPointTrain.wLinkId);
		chTrainDir = GetTrainDir(wTrainId);/*列车采用最小安全后端运行方向*/
		chConverTrainDir = ConvertTrainDir(chTrainDir);
	}
	else
	{
		strPointTrain.wLinkId = GetTrainMaxHeadLink(wTrainId);
		strPointTrain.dwOffset = GetTrainMaxHeadOffset(wTrainId);
		wTrainTiocId = GetLinkManageTiocById(strPointTrain.wLinkId);
		chTrainDir = GetTrainDir_MaxHead(wTrainId);/*列车采用最大安全前端运行方向*/
		chConverTrainDir = ConvertTrainDir(chTrainDir);
	}

	if (0u == chLocalTiocId)
	{
		chRtn = CI_SUCCESS;
	}
	else if (chLocalTiocId == wTrainTiocId)
	{
		dwLen = DsuAPointToBPoint(&strPointTrain, &strPoint, &chDir);
		if (UINT32_MAX == dwLen)
		{
			chRtn = CI_SUCCESS;
		}
		else if (((chDir == chTrainDir) && (TRAIN_SPEED_FRONT == chSpeedDir))
			|| ((chDir == chConverTrainDir) && (TRAIN_SPEED_BACK == chSpeedDir)))
		{
			chRtn = CI_SUCCESS;
		}
		else
		{
			chRtn = CI_ERROR;
		}
	}
	else
	{
		chRtn = CI_ERROR;
	}

	return chRtn;
}

/*
* 功能描述： 设置指定列车消息来源TIOC编号
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTiocId TIOC编号
* 返回值  ： 无
*/
void SetTrainMsgFromTiocId(const UINT16 wTrainId, const UINT8 chTiocId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].chMsgFromTiocId = chTiocId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车来源TIOC编号
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 来源TIOC编号
*/
UINT8 GetTrainMsgFromTiocId(const UINT16 wTrainId)
{
	UINT8 chRetVal = 0u;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chMsgFromTiocId;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 相邻TIOC通信中断，列车处理
* 参数说明： UINT8 chTiocId 相邻TIOC编号
* 返回值  ： 无
*/
void NeighborOutTrainProc(UINT8 chTiocId)
{
	UINT8 chIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chFromId = 0u;
	for (chIndex = 0u; chIndex < TRAIN_SUM_MAX; chIndex++)
	{
		wTrainId = GetTrainId(chIndex);
		chFromId = GetTrainMsgFromTiocId(wTrainId);
		if (chFromId == chTiocId)
		{
			SetTrainMsgFromTiocId(wTrainId, 0u);
			(void)SetTrainTransmitStat(wTrainId, TRAIN_COMM_STATE_BAD);
		}
		else
		{
			;
		}
	}
}

/*
* 功能描述： 相邻TIOC通信良好，列车处理
* 参数说明： UINT8 chTiocId 相邻TIOC编号
* 返回值  ： 无
* note：集成bug YF0083-205
*/
void NeighborGoodTrainProc(UINT8 chTiocId)
{
	UINT8 chIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chFromId = 0u;
	UINT32 dwCurCyc = 0u;
	UINT32 dwRecvCyc = 0u;
	UINT8 chCtNum = 0u;
	UINT16 *pCtIds = NULL;
	UINT8 chCtIndex = 0u;
	UINT16 dwCycTime = 0u;
	UINT32 dwDelayTime = 0u;
	UINT8 chLocalId = 0u;

	chLocalId = GetSystemParaLocalCiId();
	dwCycTime = GetSystemParaValue(AppCycleTime_ID);
	dwCurCyc = Get2oo2CurCycleNum();
	for (chIndex = 0u; chIndex < TRAIN_SUM_MAX; chIndex++)
	{
		wTrainId = GetTrainId(chIndex);
		chFromId = GetTrainMsgFromTiocId(wTrainId);
		if (chFromId == chTiocId)
		{
			dwRecvCyc = GetCiTransmitRecvDataCycNum(chLocalId, CI_SYSTEM_TYPE_CI, chTiocId);
			dwDelayTime = GetTrainMsgDelayTime(wTrainId);
			chCtNum = GetTiocTransmitCtNum(chTiocId);
			pCtIds = GetTiocTransmitCtIds(chTiocId);
			for (chCtIndex = 0u; chCtIndex < chCtNum; chCtIndex++)
			{
				if (wTrainId == pCtIds[chCtIndex])
				{
					break;
				}
				else
				{
					;
				}
			}

			if (chCtIndex == chCtNum)
			{
				SetTrainMsgFromTiocId(wTrainId, 0u);
				(void)SetTrainTransmitStat(wTrainId, TRAIN_COMM_STATE_BAD);
			}
			else
			{
				dwDelayTime += ((dwCurCyc - dwRecvCyc) * ((UINT32)(dwCycTime)));
				(void)SetTrainMsgDelayTime(wTrainId, dwDelayTime);
			}
		}
		else
		{
			;
		}
	}
}

/*
* 功能描述： 设置指定列车休眠状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 休眠状态
* 返回值  ： 无
*/
void SetTrainSleepState(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && ((TRAIN_SLEEP_YES == chState) || (TRAIN_SLEEP_NO == chState)))
	{
		if ((TRAIN_SLEEP_YES == gstTrainInfo[wBufIndex].chSwState) && (TRAIN_SLEEP_NO == chState))
		{
			gstTrainInfo[wBufIndex].chTrainCanUct = FLAG_SET;
		}
		else
		{
			;	/* 不处理 */
		}
		gstTrainInfo[wBufIndex].chSwState = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车休眠状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车休眠状态
*/
UINT8 GetTrainSleepState(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_SLEEP_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chSwState;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车休眠LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wLinkId link编号
* 返回值  ： 无
*/
void SetTrainSleepLink(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wSleepLink = wLinkId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车休眠link
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车休眠link
*/
UINT16 GetTrainSleepLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = 0u;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wSleepLink;
	}
	else
	{
		;
	}

	return wRetVal;
}

/*
* 功能描述： 设置指定列车模式
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chMode 模式
* 返回值  ： 无
*/
void SetTrainMode(const UINT16 wTrainId, const UINT8 chMode)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_MODE_DEFAULT == chMode) || (TRAIN_MODE_RM == chMode)
			|| (TRAIN_MODE_CM == chMode) || (TRAIN_MODE_AM == chMode)
			|| (TRAIN_MODE_EUM == chMode) || (TRAIN_MODE_RD == chMode)
			|| (TRAIN_MODE_AR == chMode) || (TRAIN_MODE_FAM == chMode)
			|| (TRAIN_MODE_CAM == chMode) || (TRAIN_MODE_RRM == chMode)
			|| (TRAIN_MODE_VCM == chMode)))
	{
		gstTrainInfo[wBufIndex].chTrainModel = chMode;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车模式
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车模式
*/
UINT8 GetTrainMode(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_MODE_DEFAULT;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainModel;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车唤醒状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 唤醒状态
* 返回值  ： 无
*/
void SetTrainWakeState(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_WAKE_SUCCESS == chState) || (TRAIN_WAKE_PROCESS == chState)
			|| (TRAIN_WAKE_FAILURE == chState) || (TRAIN_WAKE_DEFAULT == chState)))
	{
		gstTrainInfo[wBufIndex].chWakeState = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车唤醒状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车唤醒状态
*/
UINT8 GetTrainWakeState(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_WAKE_DEFAULT;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chWakeState;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车汇报状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 列车汇报状态
* 返回值  ： 无
*/
void SetTrainReportState(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].chTrainReportState = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车汇报状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车汇报状态
*/
UINT8 GetTrainReportState(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainReportState;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车动态测试命令
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chCmd 动态测试命令
* 返回值  ： 无
*/
void SetTrainDynCmd(const UINT16 wTrainId, const UINT8 chCmd)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_CMD_DYM_YES == chCmd) || (TRAIN_CMD_DYM_NO == chCmd)))
	{
		gstTrainInfo[wBufIndex].chDynCmd = chCmd;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车动态测试命令
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车动态测试命令
*/
UINT8 GetTrainDynCmd(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_CMD_DYM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chDynCmd;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车动态测试回复
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chRpl 动态测试回复
* 返回值  ： 无
*/
void SetTrainDynRpl(const UINT16 wTrainId, const UINT8 chRpl)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_DYN_RPL_AGREE == chRpl) || (TRAIN_DYN_RPL_REFUSE == chRpl)
			|| (TRAIN_DYN_RPL_FAILURE == chRpl) || (TRAIN_DYN_RPL_DEFAULT == chRpl)))
	{
		gstTrainInfo[wBufIndex].chDynRpl = chRpl;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车动态测试回复
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车动态测试回复
*/
UINT8 GetTrainDynRpl(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_DYN_RPL_DEFAULT;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chDynRpl;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 列车动态测试处理
* 参数说明： 无
* 返回值  ： 无
*/
static void TrainDynProc(void)
{
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chDynCmd = 0u;
	UINT16 wMaxHeadLink = 0u;
	UINT16 wMinHeadLink = 0u;
	UINT16 wMaxTailLink = 0u;
	UINT16 wMinTailLink = 0u;
	UINT16 wPhyId = 0u;
	UINT8 chFlockState = 0u;
	UINT16 wSysParamDyMax = GetSystemParaValue(DYTEST_SUM_MAX_ID);
	UINT8 chDyMax = (UINT8)(wSysParamDyMax & 0x00ffu);
	UINT8 chFunRtn = 0u;
	UINT16 wGdId = 0u;
	UINT8 chGdState = 0u;
	UINT16 wElmTrainId = 0u;
	UINT16 wNLink = 0u;
	UINT16 wNNLink = 0u;
	UINT16 wFLink = 0u;
	UINT16 wFFLink = 0u;
	UINT16 wSwitchId = 0u;
	UINT8 chLinkTesting = CI_ERROR;
	UINT16 wFPhyId = 0u;
	UINT16 wNPhyId = 0u;
	UINT8 chFPhyState = 0u;
	UINT8 chNPhyState = 0u;
	UINT8 chLinkSw = 0u;
	UINT8 chDyTestSwitch = 0u;
	UINT8 chZxDyTestSwitch = 0u;
	UINT8 chLocalType = 0u;
	UINT8 chWlbState = 0u;
	const EnvelopeStruct* pElmTemp = NULL;
	UINT8 cDirectionPointFlag = 0U;			/*是否具有方向变化点标志*/
	UINT8 cDirectionPointCnt = 0U;			/*方向变化点数量*/
	UINT8 cDirectionConvert = 0U;			/*变换方向,逻辑反向*/
	UINT8 cDirectionSame = 0U;			/*变换方向,逻辑同向*/
	UINT8 cAwakeCheckSpksSwitch = FUNC_SWITCH_ON;  /*唤醒过程中检查SPKS状态开关*/
	UINT8 cPhySecFLockType = 0U;  /*物理区段封锁类型*/
	UINT8 cAreaUrgentState = PHYSEC_AREA_URGENT_YES;  /*列车脚下物理区段区域紧急标志*/
	UINT16 wGdRelAPhySecId = 0U;  /*车库门关联的AG物理区段ID*/
	UINT8 chVirHeadScreenFlag = 0U;/*虚拟前筛标志*/
	UINT8 chVirTailScreenFlag = 0U;/*虚拟后筛标志*/
	UINT8 chSleepLinkCheckFlag = CI_ERROR;/*休眠唤醒LINK检查标志*/

	/* 获取动态测试开关 */
	chDyTestSwitch = GetDynamicTestSwitch();
	/* 获取正线动态测试开关 */
	chZxDyTestSwitch = GetZXDynamicTestSwitch();
	/* 获取本地TIOC类型 */
	chLocalType = GetLocalCiType();

	cAwakeCheckSpksSwitch = GetAwakeCheckSpksSwitch();

	if ((FUNC_SWITCH_ON == chDyTestSwitch)
		&& ((CI_TYPE_ZX != chLocalType) || (FUNC_SWITCH_ON == chZxDyTestSwitch)))
	{
		/* 遍历所有列车 */
		for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
		{
			cAreaUrgentState = PHYSEC_AREA_URGENT_YES;  /*每遍历一辆车，清除一次区域紧急标志*/
			wTrainId = GetTrainId(chTrainIndex);
			chDynCmd = GetTrainDynCmd(wTrainId);
			cDirectionPointCnt = 0U;			/*遍历一个车后清除其方向变化点数量及方向*/
			cDirectionConvert = 0U;
			cDirectionSame = 0U;

			/* 无动态测试命令，反馈默认值 */
			if (TRAIN_CMD_DYM_NO == chDynCmd)
			{
				SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_DEFAULT);
			}
			else
			{
				chLinkTesting = CI_SUCCESS;
				chFunRtn = IsTrainDyTesting(wTrainId);
				wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
				wMinHeadLink = GetTrainMinHeadLink(wTrainId);
				wMaxTailLink = GetTrainMaxTailLink(wTrainId);
				wMinTailLink = GetTrainMinTailLink(wTrainId);
				wPhyId = GetLinkRelatedPhySec(wMaxHeadLink);
				chFlockState = GetPhySecFLockState(wPhyId);
				cPhySecFLockType = GetPhySecFLockType(wPhyId);
				wElmTrainId = (wTrainId & 0x00ffu);
				pElmTemp = elm_GetEnvelopeInfoByTrainID(wElmTrainId);

				wFLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_CONVERT, &wSwitchId, &cDirectionPointFlag);

				cDirectionConvert = TransDirectionPointDir(cDirectionPointFlag, DIR_CONVERT, &cDirectionPointCnt);		/*若出现方向变换点，计数方向变换点，同时转个方向再查还有无方向变化点*/

				wFFLink = FindAdjacentLinkIDSafe(wFLink, cDirectionConvert, &wSwitchId, &cDirectionPointFlag);

				cDirectionConvert = TransDirectionPointDir(cDirectionPointFlag, cDirectionConvert, &cDirectionPointCnt);		/*若出现方向变换点，再次计数，后面反馈动态测试失败*/

				wNLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_SAME, &wSwitchId, &cDirectionPointFlag);

				cDirectionSame = TransDirectionPointDir(cDirectionPointFlag, DIR_SAME, &cDirectionPointCnt);		/*若出现方向变换点，计数方向变换点，同时转个方向再查还有无方向变化点*/
				
				wNNLink = FindAdjacentLinkIDSafe(wNLink, cDirectionSame, &wSwitchId, &cDirectionPointFlag);

				cDirectionSame = TransDirectionPointDir(cDirectionPointFlag, cDirectionSame, &cDirectionPointCnt);		/*若出现方向变换点，再次计数，后面反馈动态测试失败*/
				
				chWlbState = WlbGetState();

				cAreaUrgentState = GetPhySecAreaUrgentState(wPhyId);  /*获取车脚下物理区段的区域紧急制动标志*/

				wGdId = GetPhySecReleatedGdId(wPhyId);

				chVirHeadScreenFlag = GetTrainVirHeadScreenPassFlag(wTrainId);
				chVirTailScreenFlag = GetTrainVirTailScreenPassFlag(wTrainId);

				if (0u == wGdId)
				{/* 无车库门，不需要检查车库门状态 */
					chGdState = GARAGE_DOOR_STATE_OPEN;
				}
				else
				{
					wGdRelAPhySecId = GetGarageDoorAKuPhySec(wGdId);  /*获取车库门关联的AG*/
					if ((0U != wGdRelAPhySecId) && (wGdRelAPhySecId != wPhyId))
					{
						chGdState = GARAGE_DOOR_STATE_OPEN;  /*列车休眠轨非车库门所在物理区段，动态测试不需要检查车库门状态*/
					}
					else
					{
						/* 获取车库门状态 */
						chGdState = GetGaragedoorState(wGdId);
					}
				}

				if ((0u != wFLink) && (UINT16_MAX != wFLink))
				{
					chLinkTesting &= IsLinkTesting(wFLink);
					chLinkSw = IsLinkSwTrack(wFLink);
					if (CI_SUCCESS == chLinkSw)
					{
						chFPhyState = SECTION_OCCUPY_NO;
					}
					else
					{/* 动态测试相邻区段，非休眠唤醒轨，需检查占用状态 */
						wFPhyId = GetLinkRelatedPhySec(wFLink);
						chFPhyState = GetPhySecCurOccupyState(wFPhyId);
					}
				}
				else if (UINT16_MAX == wFLink)
				{
					chFPhyState = SECTION_OCCUPY_YES;
				}
				else
				{
					chFPhyState = SECTION_OCCUPY_NO;
				}

				if ((0u != wFFLink) && (UINT16_MAX != wFFLink))
				{
					chLinkTesting &= IsLinkTesting(wFFLink);
				}
				else
				{
					;
				}

				if ((0u != wNLink) && (UINT16_MAX != wNLink))
				{
					chLinkTesting &= IsLinkTesting(wNLink);
					chLinkSw = IsLinkSwTrack(wNLink);
					if (CI_SUCCESS == chLinkSw)
					{
						chNPhyState = SECTION_OCCUPY_NO;
					}
					else
					{/* 动态测试相邻区段，非休眠唤醒轨，需检查占用状态 */
						wNPhyId = GetLinkRelatedPhySec(wNLink);
						chNPhyState = GetPhySecCurOccupyState(wNPhyId);
					}
				}
				else if (UINT16_MAX == wNLink)
				{
					chNPhyState = SECTION_OCCUPY_YES;
				}
				else
				{
					chNPhyState = SECTION_OCCUPY_NO;
				}

				if ((0u != wNNLink) && (UINT16_MAX != wNNLink))
				{
					chLinkTesting &= IsLinkTesting(wNNLink);
				}
				else
				{
					;
				}

				chSleepLinkCheckFlag = IsLinkSwTrack(wMaxHeadLink);

				if (0U != cDirectionPointCnt)
				{/*若存在方向变换点，反馈失败*/
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_FAILURE);
					debug_infor_printf((const)"Train:%x dytest refuse: DirectionPointCnt: %d.\n", wTrainId, cDirectionPointCnt);
				}
				else if ((wMaxHeadLink != wMinHeadLink) || (wMinHeadLink != wMaxTailLink)
					|| (wMaxTailLink != wMinTailLink) || (CI_SUCCESS != chSleepLinkCheckFlag)
					|| (NULL == pElmTemp))
				{/* 申请动态测试列车不在休眠唤醒轨，反馈失败 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_FAILURE);
					debug_infor_printf((const)"Train:%x dytest failure:chSleepLinkCheckFlag Error.\n", wTrainId);
				}
				else if ((PHYSICAL_SECTION_FLOCK_NO != chFlockState)
					&& ((FUNC_SWITCH_OFF != cAwakeCheckSpksSwitch) || ((FUNC_SWITCH_OFF == cAwakeCheckSpksSwitch) && (PHY_SEC_FLOCK_TYPE_SPKS != cPhySecFLockType))))
				{/* 物理区段封锁且（检查SPKS封锁或（不检查SPKS封锁且非SPKS封锁类型）），反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: phy flock.\n", wTrainId);
				}
				else if ((gDyTestNum >= chDyMax) && (CI_ERROR == chFunRtn))
				{/* 超出同时动态测试列车最大数量，反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: over max testing.\n", wTrainId);
				}
				else if (GARAGE_DOOR_STATE_OPEN != chGdState)
				{/* 车库门未打开，反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: gd open.\n", wTrainId);
				}
				else if (CI_ERROR == chLinkTesting)
				{/* 库内有其他列车正在动态测试，反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: another train is dytesting.\n", wTrainId);
				}
				else if (((0u != pElmTemp->headTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirHeadScreenFlag))
					|| ((0u != pElmTemp->tailTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirTailScreenFlag)))
				{/* 头/尾有隐藏车，反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: screen.\n", wTrainId);
				}
				else if ((SECTION_OCCUPY_NO != chFPhyState) || (SECTION_OCCUPY_NO != chNPhyState))
				{/* C或D轨非空闲，反馈不同意 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: occ.\n", wTrainId);
				}
				else if ((WLB_UNSET != chWlbState) || (PHYSEC_AREA_URGENT_NO != cAreaUrgentState))
				{/* 全线紧急制动已设置 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_REFUSE);
					debug_infor_printf((const)"Train:%x dytest refuse: UrgentBrake.\n", wTrainId);
				}
				else
				{/* 反馈同意，并将该列车加入动态测试列表 */
					SetTrainDynRpl(wTrainId, TRAIN_DYN_RPL_AGREE);
					debug_infor_printf((const)"Train:%x dytest agree.\n", wTrainId);
					if ((gDyTestNum < chDyMax) && (CI_ERROR == chFunRtn))
					{
						AddTrainDyTesting(wTrainId, wMaxHeadLink);
					}
					else
					{
						;
					}
				}
			}
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 列车唤醒处理
* 参数说明： 无
* 返回值  ： 无
* note：列车唤醒状态为正在唤醒，维持该车为休眠车，否则变为非休眠车
*/
static void TrainWakeProc(void)
{
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chWakeState = 0u;
	UINT8 chTrainMode = 0u;
	UINT16 wMaxHeadLink = 0u;
	UINT16 wMinHeadLink = 0u;
	UINT16 wMaxTailLink = 0u;
	UINT16 wMinTailLink = 0u;
	UINT16 wElmTrainId = 0u;
	UINT16 wNAcId = 0u;
	UINT16 wFAcId = 0u;
	UINT16 wBAcId = 0u;
	UINT8 chNAcState = 0u;
	UINT8 chFAcState = 0u;
	UINT8 chAcNum = 0u;
	UINT16 szAcId[AC_MAXCNT_IN_SWITCH] = { 0u };
	UINT16 wFLink = 0u;
	UINT16 wNLink = 0u;
	UINT16 wSwitchId = 0u;
	UINT8 chSwAttributes = 0u;
	UINT8 chTrainSlpStt = 0U;
	UINT8 chTransState = 0u;
	UINT8 chSleepCancle = 0u;
	UINT8 chFunRtn = CI_ERROR;
	UINT16 wSleepLink = 0u;
	UINT8 chSss = 0u;
	UINT8 chZeroState = 0u;
	UINT8 chFAttributes = 0u;
	UINT8 chNAttributes = 0u;
	const EnvelopeStruct* pElmTemp = NULL;
	UINT8 cDirectionPointFlag = 0U;			/*是否具有方向变化点标志*/
	UINT8 chVirHeadScreenFlag = 0U;/*虚拟前筛标志*/
	UINT8 chVirTailScreenFlag = 0U;/*虚拟后筛标志*/
	UINT8 cLocalCiType = 0U;
	UINT8 chBGAtsScreenAgUtCheck = 0U;/*BG远程筛选AG UT检查*/
	
	/* 遍历所有列车 */
	for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
	{
		wTrainId = GetTrainId(chTrainIndex);
		chWakeState = GetTrainWakeState(wTrainId);
		chTrainMode = GetTrainMode(wTrainId);
		wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
		wMinHeadLink = GetTrainMinHeadLink(wTrainId);
		wMaxTailLink = GetTrainMaxTailLink(wTrainId);
		wMinTailLink = GetTrainMinTailLink(wTrainId);
		wSleepLink = GetTrainSleepLink(wTrainId);
		wElmTrainId = (wTrainId & 0x00ffu);
		chTrainSlpStt = GetTrainSleepState(wTrainId);
		pElmTemp = elm_GetEnvelopeInfoByTrainID(wElmTrainId);
		wBAcId = GetLinkBelongAcId(wMaxHeadLink);
		chAcNum = elm_PrepareAdjacentAC(wBAcId, DIR_CONVERT, szAcId, &cDirectionPointFlag);
		if ((0u != chAcNum) && (UINT8_MAX != chAcNum))
		{/* 有相邻计轴区段 */
			wFLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_CONVERT, &wSwitchId, &cDirectionPointFlag);		/*只查一个link，不考虑方向变化点*/
			chSwAttributes = IsLinkSwTrack(wFLink);
			if (CI_SUCCESS == chSwAttributes)
			{/* 相邻为休眠唤醒轨，不检查占用状态 */
				chFAcState = ELM_AC_FREE;
			}
			else
			{/* 获取相邻计轴区段占用状态 */
				wFAcId = szAcId[0];
				chFAcState = elm_PrepareACStatus(wFAcId);
			}
		}
		else if (UINT8_MAX == chAcNum)
		{/* 查询出错 */
			wFAcId = UINT16_MAX;
			chFAcState = ELM_AC_OCC;
		}
		else
		{/* 无相邻计轴区段，不检查占用状态 */
			wFAcId = 0u;
			chFAcState = ELM_AC_FREE;
		}

		chAcNum = elm_PrepareAdjacentAC(wBAcId, DIR_SAME, szAcId, &cDirectionPointFlag);
		if ((0u != chAcNum) && (UINT8_MAX != chAcNum))
		{/* 有相邻计轴区段 */
			wNLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_SAME, &wSwitchId, &cDirectionPointFlag);			/*只查一个link，不考虑方向变化点*/
			chSwAttributes = IsLinkSwTrack(wNLink);
			if (CI_SUCCESS == chSwAttributes)
			{/* 相邻为休眠唤醒轨，不检查占用状态 */
				chNAcState = ELM_AC_FREE;
			}
			else
			{/* 获取相邻计轴区段占用状态 */
				wNAcId = szAcId[0];
				chNAcState = elm_PrepareACStatus(wNAcId);
			}
		}
		else if (UINT8_MAX == chAcNum)
		{/* 查询出错 */
			wNAcId = UINT16_MAX;
			chNAcState = ELM_AC_OCC;
		}
		else
		{/* 无相邻计轴区段，不检查占用状态 */
			wNAcId = 0u;
			chNAcState = ELM_AC_FREE;
		}

		chZeroState = GetTrainZeroState(wTrainId);
		chSss = GetTrainStopSteadyState(wTrainId);
		chTransState = GetTrainTransitmitStat(wTrainId);
		chSleepCancle = GetTrainSleepCancleFlag(wTrainId);
		chFunRtn = IsLinkSwTrack(wMaxHeadLink);
		chVirHeadScreenFlag = GetTrainVirHeadScreenPassFlag(wTrainId);
		chVirTailScreenFlag = GetTrainVirTailScreenPassFlag(wTrainId);
		chBGAtsScreenAgUtCheck = BGAtsScreenAgUtCheck(wMaxHeadLink);

		/* 列车处于唤醒过程 */
		if (TRAIN_COMM_STATE_GOOD == chTransState)
		{
			if ((wMaxHeadLink != wMinHeadLink) || (wMinHeadLink != wMaxTailLink)
				|| (wMaxTailLink != wMinTailLink) || (CI_SUCCESS != chFunRtn)
				|| (NULL == pElmTemp) || (TRAIN_SPEED_ZERO_YES != chZeroState)
				|| (TRAIN_SS_YES != chSss) || (CI_SUCCESS != chBGAtsScreenAgUtCheck))
			{/* 列车不在休眠唤醒轨或包络获取失败或列车无动态测试命令或不处于零速或未停准停稳或BG筛选时坏车接近及UCT\CT包络侵入BG，不进行筛选申请 */
				SetTrainScreenApply(wTrainId, TRAIN_SCREEN_DEFAULT);
			}
			else
			{
				if ((((0u != pElmTemp->headTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirHeadScreenFlag))
					|| ((0u != pElmTemp->tailTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirTailScreenFlag)))
					&& (ELM_AC_FREE == chNAcState) && (ELM_AC_FREE == chFAcState))
				{
					/* 列车头/尾筛未完成 */
					if (TRAIN_MODE_FAM == chTrainMode)
					{
						/* FAM模式，远程筛选 */
						SetTrainScreenApply(wTrainId, TRAIN_SCREEN_ATS);
					}
					else
					{
						if ((0u != pElmTemp->headTrainID) && (0u != pElmTemp->tailTrainID))
						{
							/* 头尾晒均未完成，人工头尾筛选 */
							SetTrainScreenApply(wTrainId, TRAIN_SCREEN_IVOC);
						}
						else if (0u != pElmTemp->headTrainID)
						{
							/* 头筛未完成，人工头筛 */
							SetTrainScreenApply(wTrainId, TRAIN_HEAD_SCREEN_IVOC);
						}
						else
						{
							/* 尾筛未完成，人工尾筛 */
							SetTrainScreenApply(wTrainId, TRAIN_TAIL_SCREEN_IVOC);
						}
					}
				}
				else
				{/* 头尾筛均已完成或不满足筛选条件，无需筛选申请 */
					SetTrainScreenApply(wTrainId, TRAIN_SCREEN_DEFAULT);
				}
			}
		}
		else
		{/* 通信中断，无需筛选请求 */
			SetTrainScreenApply(wTrainId, TRAIN_SCREEN_DEFAULT);
		}

		/* 通信良好，不为唤醒中，可以取消休眠属性
		休眠车前/后端可疑，清除休眠状态*/
		if (((TRAIN_COMM_STATE_GOOD == chTransState) && (TRAIN_SLEEP_CANCLE_YES == chSleepCancle) 
			&& (TRAIN_WAKE_PROCESS != chWakeState)))
		{
			SetTrainSleepState(wTrainId, TRAIN_SLEEP_NO);
			SetTrainSleepLink(wTrainId, 0u);
			debug_infor_printf((const)"Train%x delete sleep state because not in wakeing.\n", wTrainId);
		}
		else
		{
			;
		}

		if ((TRAIN_COMM_STATE_BAD == chTransState) 
			&& (TRAIN_SLEEP_YES == chTrainSlpStt)
			&& (NULL != pElmTemp)
			&& (((0u != pElmTemp->headTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirHeadScreenFlag))
				|| ((0u != pElmTemp->tailTrainID) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID != chVirTailScreenFlag))))
		{
			SetTrainSleepState(wTrainId, TRAIN_SLEEP_NO);
			debug_infor_printf((const)"Train%x delete sleep state because Suspic.\n", wTrainId);
		}

		if (TRAIN_SLEEP_YES == chTrainSlpStt)
		{
			/* 获取休眠唤醒轨相邻link信息 */
			wFLink = FindAdjacentLinkIDSafe(wSleepLink, DIR_CONVERT, &wSwitchId, &cDirectionPointFlag);		/*只查一个link，不考虑方向变化点*/
			wNLink = FindAdjacentLinkIDSafe(wSleepLink, DIR_SAME, &wSwitchId, &cDirectionPointFlag);
			chFAttributes = IsLinkSwTrack(wFLink);
			chNAttributes = IsLinkSwTrack(wNLink);
			if ((UINT16_MAX == wFLink) || (UINT16_MAX == wNLink))
			{/* 数据获取失败 */
				SetTrainSleepState(wTrainId, TRAIN_SLEEP_NO);
				SetTrainSleepLink(wTrainId, 0u);
				debug_infor_printf((const)"Train%x delete sleep state because neighbor occ.\n", wTrainId);
			}
			else
			{
				cLocalCiType = GetLocalCiType();  /*获取CI类型*/
				if ((CI_TYPE_ZX == cLocalCiType) || (CI_TYPE_SCX == cLocalCiType))
				{
					/*正线/试车线相邻非休眠唤醒轨区段需无占用*/
					chFunRtn = CI_SUCCESS;
					if ((0U != wFLink) && (CI_SUCCESS != chFAttributes))
					{
						if (ELM_AC_FREE == chFAcState)
						{
							; /* 相邻区段空闲，不处理 */
						}
						else
						{
							chFunRtn = CI_ERROR;
						}
					}
					else
					{
						; /* 线路终端或者休眠唤醒轨，不处理 */
					}

					if ((0U != wNLink) && (CI_SUCCESS != chNAttributes))
					{
						if (ELM_AC_FREE == chNAcState)
						{
							; /* 相邻区段空闲，不处理 */
						}
						else
						{
							chFunRtn = CI_ERROR;
						}
					}
					else
					{
						; /* 线路终端或者休眠唤醒轨，不处理 */
					}
				}
				else
				{
					/*场段休眠唤醒轨相邻区段占用检查*/
					chFunRtn = CLDSWAdjacentSecOccCheck(wSleepLink);
				}

				if (CI_SUCCESS != chFunRtn)
				{
					/*检查失败，清除休眠属性*/
					SetTrainSleepState(wTrainId, TRAIN_SLEEP_NO);  /*注：不能删除休眠link，不然无法动态测试*/
					debug_infor_printf((const)"Train[%x] Delete Sleep State Because Adjacent Sectioc Occ.\n", wTrainId);
				}
				else
				{
					/*检查通过，保持休眠属性*/
				}
			}
		}
		else
		{
			; /* 不为休眠列车，不处理 */
		}
	}
}

/*
* 功能描述： 原地筛选处理
* 参数说明： 无
* 返回值  ： 无
*/
static void TrainScreenProc(void)
{
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT16 wMaxHeadLink = 0u;
	UINT16 wMinHeadLink = 0u;
	UINT16 wMaxTailLink = 0u;
	UINT16 wMinTailLink = 0u;
	UINT16 wElmTrainId = 0u;
	UINT8 chZeroState = 0u;
	UINT8 chTrainHeadScreenConfirm = 0u;
	UINT8 chTrainTailScreenConfirm = 0u;
	UINT8 chAtsScreenConfirm = 0u;
	UINT8 chScreenApply = 0u;
	UINT16 wNAcId = 0u;
	UINT16 wFAcId = 0u;
	UINT16 wBAcId = 0u;
	UINT8 chNAcState = 0u;
	UINT8 chFAcState = 0u;
	UINT8 chAcNum = 0u;
	UINT16 szAcId[AC_MAXCNT_IN_SWITCH] = { 0u };
	UINT8 chSss = 0u;
	UINT16 wFLink = 0u;
	UINT16 wNLink = 0u;
	UINT16 wSwitchId = 0u;
	UINT8 chSwAttributes = 0u;
	const EnvelopeStruct* pElmTemp = NULL;
	UINT8 cDirectionPointFlag = 0U;			/*是否具有方向变化点标志*/
	UINT8 chBGAtsScreenAgUtCheck = 0U; /*BG远程筛选AG UT检查结果*/

	/* 遍历所有列车 */
	for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
	{
		wTrainId = GetTrainId(chTrainIndex);
		wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
		wMinHeadLink = GetTrainMinHeadLink(wTrainId);
		wMaxTailLink = GetTrainMaxTailLink(wTrainId);
		wMinTailLink = GetTrainMinTailLink(wTrainId);
		wElmTrainId = (wTrainId & 0x00ffu);
		pElmTemp = elm_GetEnvelopeInfoByTrainID(wElmTrainId);
		chZeroState = GetTrainZeroState(wTrainId);
		chScreenApply = GetTrainScreenApply(wTrainId);
		chTrainHeadScreenConfirm = GetTrainHeadScreenConfirm(wTrainId);
		chTrainTailScreenConfirm = GetTrainTailScreenConfirm(wTrainId);
		chAtsScreenConfirm = GetTrainAtsScreenConfirm(wTrainId);
		wBAcId = GetLinkBelongAcId(wMaxHeadLink);
		chAcNum = elm_PrepareAdjacentAC(wBAcId, DIR_CONVERT, szAcId, &cDirectionPointFlag);
		chSss = GetTrainStopSteadyState(wTrainId);
		if ((0u != chAcNum) && (UINT8_MAX != chAcNum))
		{/* 有相邻计轴区段 */
			wFLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_CONVERT, &wSwitchId, &cDirectionPointFlag);			/*只查一个link，不考虑方向变化点*/
			chSwAttributes = IsLinkSwTrack(wFLink);
			if (CI_SUCCESS == chSwAttributes)
			{/* 相邻为休眠唤醒轨，不检查占用状态 */
				chFAcState = ELM_AC_FREE;
			}
			else
			{/* 获取相邻计轴区段占用状态 */
				wFAcId = szAcId[0];
				chFAcState = elm_PrepareACStatus(wFAcId);
			}
		}
		else if (UINT8_MAX == chAcNum)
		{
			/* 查询出错 */
			wFAcId = UINT16_MAX;
			chFAcState = ELM_AC_OCC;
		}
		else
		{/* 无相邻计轴区段，不检查占用状态 */
			wFAcId = 0u;
			chFAcState = ELM_AC_FREE;
		}

		chAcNum = elm_PrepareAdjacentAC(wBAcId, DIR_SAME, szAcId, &cDirectionPointFlag);
		if ((0u != chAcNum) && (UINT8_MAX != chAcNum))
		{/* 有相邻计轴区段 */
			wNLink = FindAdjacentLinkIDSafe(wMaxHeadLink, DIR_SAME, &wSwitchId, &cDirectionPointFlag);				/*只查一个link，不考虑方向变化点*/
			chSwAttributes = IsLinkSwTrack(wNLink);
			if (CI_SUCCESS == chSwAttributes)
			{/* 相邻为休眠唤醒轨，不检查占用状态 */
				chNAcState = ELM_AC_FREE;
			}
			else
			{/* 获取相邻计轴区段占用状态 */
				wNAcId = szAcId[0];
				chNAcState = elm_PrepareACStatus(wNAcId);
			}
		}
		else if (UINT8_MAX == chAcNum)
		{
			/* 查询出错 */
			wNAcId = UINT16_MAX;
			chNAcState = ELM_AC_OCC;
		}
		else
		{/* 无相邻计轴区段，不检查占用状态 */
			wNAcId = 0u;
			chNAcState = ELM_AC_FREE;
		}

		chSwAttributes = IsLinkSwTrack(wMaxHeadLink);
		chBGAtsScreenAgUtCheck = BGAtsScreenAgUtCheck(wMaxHeadLink);

		if ((TRAIN_HEAD_CONFIRM_YES == chTrainHeadScreenConfirm)
			&& ((TRAIN_SCREEN_IVOC == chScreenApply) || (TRAIN_HEAD_SCREEN_IVOC == chScreenApply)))
		{
			if ((wMaxHeadLink != wMinHeadLink) || (wMinHeadLink != wMaxTailLink)
				|| (wMaxTailLink != wMinTailLink) || (CI_SUCCESS != chSwAttributes)
				|| (NULL == pElmTemp))
			{/* 列车不在原休眠唤醒轨 */
				;
			}
			else if (TRAIN_SPEED_ZERO_YES != chZeroState)
			{/* 列车非零速 */
				;
			}
			else if (TRAIN_SS_YES != chSss)
			{/* 列车未停准停稳 */
				;
			}
			else if((ELM_AC_FREE != chNAcState) || (ELM_AC_FREE != chFAcState))
			{/* 首尾计轴区段非空闲 */
				;
			}
			else if (CI_SUCCESS != chBGAtsScreenAgUtCheck)
			{
				/* AB库(无CG)，需要判断AG计轴区段列车虚拟标志和接近状态 */
				;
			}
			else
			{
				/*虚拟前筛标志有效，对IVOC输出前端无可疑*/
				SetTrainEnterLjkLinkId(wTrainId, wMaxHeadLink);
				SetTrainVirHeadScreenPassFlag(wTrainId,TRAIN_VIR_SCREEN_PASS_FLAG_VALID);

				if (0U == pElmTemp->tailTrainID)
				{
					SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_VALID);
				}
				else
				{
					;
				}

				/*筛选通过后，设置列车位置监督有效*/
				SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_VALID);
				SetTrainPosMonitorInLink(wTrainId, wMaxHeadLink);
			}
		}
		else
		{
			;
		}

		if ((TRAIN_TAIL_CONFIRM_YES == chTrainTailScreenConfirm)
			&& ((TRAIN_SCREEN_IVOC == chScreenApply) || (TRAIN_TAIL_SCREEN_IVOC == chScreenApply)))
		{
			if ((wMaxHeadLink != wMinHeadLink) || (wMinHeadLink != wMaxTailLink)
				|| (wMaxTailLink != wMinTailLink) || (CI_SUCCESS != chSwAttributes)
				|| (NULL == pElmTemp))
			{/* 列车未在原休眠唤醒轨 */
				;
			}
			else if (TRAIN_SPEED_ZERO_YES != chZeroState)
			{/* 列车非零速 */
				;
			}
			else if (TRAIN_SS_YES != chSss)
			{/* 列车未停准停稳 */
				;
			}
			else if ((ELM_AC_FREE != chNAcState) || (ELM_AC_FREE != chFAcState))
			{/* 首位相邻计轴区段非空闲 */
				;
			}
			else if (CI_SUCCESS != chBGAtsScreenAgUtCheck)
			{
				/* AB库(无CG)，需要判断AG计轴区段列车虚拟标志和接近状态 */
				;
			}
			else
			{
				SetTrainEnterLjkLinkId(wTrainId, wMaxHeadLink);
				/*虚拟后筛标志有效，对IVOC输出后端无可疑*/
				SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_VALID);

				if (0U == pElmTemp->headTrainID)
				{
					SetTrainVirHeadScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_VALID);
				}
				else
				{
					;
				}

				/*筛选通过后，设置列车位置监督有效*/
				SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_VALID);
				SetTrainPosMonitorInLink(wTrainId, wMaxHeadLink);
			}
		}
		else
		{
			;
		}

		if ((TRAIN_ATS_CONFIRM_YES == chAtsScreenConfirm)
			&& (TRAIN_SCREEN_ATS == chScreenApply))
		{
			if ((wMaxHeadLink != wMinHeadLink) || (wMinHeadLink != wMaxTailLink)
				|| (wMaxTailLink != wMinTailLink) || (CI_SUCCESS != chSwAttributes)
				|| (NULL == pElmTemp))
			{/* 列车未处于原休眠唤醒轨 */
				;
			}
			else if (TRAIN_SPEED_ZERO_YES != chZeroState)
			{/* 列车非零速 */
				;
			}
			else if (TRAIN_SS_YES != chSss)
			{/* 列车未停准停稳 */
				;
			}
			else if ((ELM_AC_FREE != chNAcState) || (ELM_AC_FREE != chFAcState))
			{/* 首尾相邻计轴区段非空闲 */
				;
			}
			else if (CI_SUCCESS != chBGAtsScreenAgUtCheck)
			{
				/* AB库(无CG)，需要判断AG计轴区段列车虚拟标志和接近状态 */
				;
			}
			else
			{
				/*虚拟前后筛标志有效，对IVOC输出前后端无可疑*/
				SetTrainEnterLjkLinkId(wTrainId, wMaxHeadLink);
				SetTrainVirHeadScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_VALID);
				SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_VALID);
				
				/*筛选通过后，设置列车位置监督有效*/
				SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_VALID);
				SetTrainPosMonitorInLink(wTrainId, wMaxHeadLink);
			}
		}
		else
		{
			;
		}

		SetTrainHeadScreenConfirm(wTrainId, TRAIN_HEAD_CONFIRM_NO);
		SetTrainTailScreenConfirm(wTrainId, TRAIN_TAIL_CONFIRM_NO);
		SetTrainAtsScreenConfirm(wTrainId, TRAIN_ATS_CONFIRM_NO);
	}
}

/**
* @brief 远程筛选首次确认
* @param 无
* @return 无
*/
static void TrainAtsScreenFst(void)
{
	AtsScreenMsgFstStru * strMsgFst = NULL;
	AtsMsgCfmStru * strCfmFst = NULL;
	UINT32 dwCycle = 0u;
	UINT8 chLocalId = 0u;
	UINT8 chLocIndex = 0u;
	UINT8 chAtsIndex = 0u;
	UINT8 chFlag = FLAG_UNSET;
	UINT8 szCrcTmp[1024] = { 0u };
	UINT32 ii = 0u;
	UINT8 chFunRtn = CI_TIME_OUT;
	UINT16 wTrainId = 0u;
	UINT16 wTrainLgcId = 0u;
	UINT8 dquHlhtId2VobcName_ret = 0u;
	chLocalId = GetSystemParaLocalCiId();
	dwCycle = Get2oo2CurCycleNum();
	/*以下消息获取不会返回NULL*/
	strMsgFst = GetAtsMsgFst();
	strCfmFst = GetAtsCfmFst();

	if (strMsgFst->dwCycle == dwCycle)
	{
		strCfmFst->chFlag = FLAG_SET;
		strCfmFst->chTiocId = chLocalId;
		strCfmFst->chStation = strMsgFst->chStation;
		strCfmFst->wIndex = strMsgFst->wIndex;
		strCfmFst->dwTime = dwCycle;

		for (chAtsIndex = 0u; chAtsIndex < strMsgFst->chTrainNum; chAtsIndex++)
		{
			for (chLocIndex = 0u; chLocIndex < gAtsScreenNum; chLocIndex++)
			{
				dquHlhtId2VobcName_ret = dquHlhtId2VobcName(strMsgFst->strTrainInfo[chAtsIndex].dwTrainId, &wTrainId, &wTrainLgcId);  /*待优化*/
				if ((wTrainId == gszAtsScreenInfo[chLocIndex].wTrainId) && (0u != dquHlhtId2VobcName_ret))
				{/* 找到列车，跳出 */
					break;
				}
				else
				{
					;
				}
			}

			if (chLocIndex == gAtsScreenNum)
			{/* 输入序列与本地序列存在不一致列车ID，反馈确认列车 */
				strCfmFst->chOpStatus = CONFIRM_FIRST_TRAINID;
				chFlag = FLAG_SET;
			}
			else
			{
				if (strMsgFst->strTrainInfo[chAtsIndex].wLgcId == gszAtsScreenInfo[chLocIndex].wLgcId)
				{
					;
				}
				else
				{/* 输入列车所在逻辑区段与本地列车所在逻辑区段不一致，反馈确认逻辑区段 */
					strCfmFst->chOpStatus = CONFIRM_FIRST_LGCID;
					chFlag = FLAG_SET;
				}
			}

			if (FLAG_SET == chFlag)
			{
				break;
			}
			else
			{
				;
			}
		}
		szCrcTmp[ii++] = strMsgFst->chAtsId;
		LongToChar(strMsgFst->dwTime, &szCrcTmp[ii]);
		ii += 4u;
		szCrcTmp[ii++] = strMsgFst->chTrainNum;
		for (chAtsIndex = 0u; chAtsIndex < strMsgFst->chTrainNum; chAtsIndex++)
		{
			LongToChar(strMsgFst->strTrainInfo[chAtsIndex].dwTrainId, &szCrcTmp[ii]);
			ii += 4u;
			ShortToChar(strMsgFst->strTrainInfo[chAtsIndex].wLgcId, &szCrcTmp[ii]);
			ii += 2u;
		}
		strCfmFst->dwCrc32 = Tioc_CommonCrc32(szCrcTmp, ii);
		if (FLAG_UNSET == chFlag)
		{/* 检查通过，反馈确认成功 */
			strCfmFst->chOpStatus = CONFIRM_FIRST_SUCCESS;

		}
		else
		{
			ClearAtsMsgFirst(); /**清除1次命令 */
		}
	}
	else
	{/* 接收到ATS远程筛选一次消息非本周期，超时判断 */
		chFunRtn = SystemOverTimeCheck(strMsgFst->dwCycle, CONFIRM_TIMEOUT_CC);
		if (CI_TIME_OUT == chFunRtn)
		{
			ClearAtsMsgFirst();
		}
		else
		{
			;
		}
	}
}

/**
* @brief 判断ATS远程筛选两次消息是否一致
* @param 无
* @return CI_ERROR:不一致；CI_SUCCESS:一致
*/
static UINT8 IsAtsFstSndSame(void)
{
	AtsScreenMsgFstStru * strMsgFst = NULL;
	AtsScreenMsgSndStru * strMsgSnd = NULL;
	UINT8 chRtn = CI_ERROR;
	UINT8 chIndex = 0u;
	/*以下消息获取不会返回NULL*/
	strMsgFst = GetAtsMsgFst();
	strMsgSnd = GetAtsMsgSnd();

	if ((strMsgFst->chAtsId == strMsgSnd->chAtsId)
		&& (strMsgFst->chStation == strMsgSnd->chStation)
		&& (strMsgFst->wIndex == strMsgSnd->wIndex)
		&& (strMsgFst->chTrainNum == strMsgSnd->chTrainNum))
	{/* 输入ATS编号/车站编号/操作站编号/列车数量一致 */
		chRtn = CI_SUCCESS;
	}
	else
	{
		;
	}

	if (CI_SUCCESS == chRtn)
	{
		for (chIndex = 0u; chIndex < strMsgFst->chTrainNum; chIndex++)
		{
			if ((strMsgFst->strTrainInfo[chIndex].dwTrainId != strMsgSnd->strTrainInfo[chIndex].dwTrainId)
				|| (strMsgFst->strTrainInfo[chIndex].wLgcId != strMsgSnd->strTrainInfo[chIndex].wLgcId))
			{/* 两次消息列车ID/逻辑区段ID不一致 */
				chRtn = CI_ERROR;
				break;
			}
		}
	}
	else
	{
		;
	}
	return chRtn;
}

/**
* @brief 设置远程筛选确认处理
* @param 无
* @return 无
*/
static void SetTrainAtsScreenProc(void)
{
	AtsScreenMsgSndStru * strMsgSnd = NULL;
	UINT16 wTrainId = 0u;
	UINT8 chIndex = 0u;
	UINT16 wTrainLgcId = 0u;
	strMsgSnd = GetAtsMsgSnd();/*不会返回NULL*/
	for (chIndex = 0u; chIndex < strMsgSnd->chTrainNum; chIndex++)
	{
		(void)dquHlhtId2VobcName(strMsgSnd->strTrainInfo[chIndex].dwTrainId, &wTrainId, &wTrainLgcId);
		SetTrainAtsScreenConfirm(wTrainId, TRAIN_ATS_CONFIRM_YES);
	}
}

/**
* @brief 远程筛选二次确认
* @param 无
* @return 无
*/
static void TrainAtsScreenSnd(void)
{
	AtsScreenMsgFstStru * strMsgFst = NULL;
	AtsScreenMsgSndStru * strMsgSnd = NULL;
	AtsMsgCfmStru * strCfmFst = NULL;
	AtsMsgCfmStru * strCfmSnd = NULL;
	UINT32 dwCycle = 0u;
	UINT8 chLocalId = 0u;
	UINT8 chLocIndex = 0u;
	UINT8 chAtsIndex = 0u;
	UINT8 chFlag = FLAG_UNSET;
	UINT8 szCrcTmp[1024] = { 0u };
	UINT32 ii = 0u;
	UINT8 chFunRtn = CI_ERROR;
	UINT32 dwCrc = 0u;
	UINT16 wTrainId = 0u;
	UINT16 wTrainLgcId = 0u;
	UINT8 reflag = 0u;
	chLocalId = GetSystemParaLocalCiId();
	dwCycle = Get2oo2CurCycleNum();

	/*以下消息获取不会返回NULL*/
	strMsgFst = GetAtsMsgFst();
	strMsgSnd = GetAtsMsgSnd();
	strCfmFst = GetAtsCfmFst();
	strCfmSnd = GetAtsCfmSnd();

	if (strMsgSnd->dwCycle == dwCycle)
	{
		strCfmSnd->chFlag = FLAG_SET;
		strCfmSnd->chTiocId = chLocalId;
		strCfmSnd->chStation = strMsgSnd->chStation;
		strCfmSnd->wIndex = strMsgSnd->wIndex;
		strCfmSnd->dwTime = dwCycle;
		for (chAtsIndex = 0u; chAtsIndex < strMsgSnd->chTrainNum; chAtsIndex++)
		{
			for (chLocIndex = 0u; chLocIndex < gAtsScreenNum; chLocIndex++)
			{
				reflag = dquHlhtId2VobcName(strMsgSnd->strTrainInfo[chAtsIndex].dwTrainId, &wTrainId, &wTrainLgcId);
				if ((1u == reflag) && (wTrainId == gszAtsScreenInfo[chLocIndex].wTrainId))
				{/* 找到列车，跳出 */
					break;
				}
				else
				{
					;
				}
			}

			if (chLocIndex == gAtsScreenNum)
			{/* 输入序列与本地序列存在不一致列车ID，反馈确认列车 */
				strCfmSnd->chOpStatus = CONFIRM_SECOND_TRAINID;
				chFlag = FLAG_SET;
			}
			else
			{
				if (strMsgSnd->strTrainInfo[chAtsIndex].wLgcId == gszAtsScreenInfo[chLocIndex].wLgcId)
				{
					;
				}
				else
				{/* 输入列车所在逻辑区段与本地列车所在逻辑区段不一致，反馈确认逻辑区段 */
					strCfmSnd->chOpStatus = CONFIRM_SECOND_LGCID;
					chFlag = FLAG_SET;
				}
			}

			if (FLAG_SET == chFlag)
			{
				break;
			}
			else
			{
				;
			}
		}

		if (FLAG_UNSET == chFlag)
		{
			if (FLAG_SET != strMsgFst->chFlag)
			{/* 未进行首次确认 */
				strCfmSnd->chOpStatus = CONFIRM_SECOND_FIRST;
				chFlag = FLAG_SET;
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (FLAG_UNSET == chFlag)
		{
			chFunRtn = IsAtsFstSndSame();
			if (CI_SUCCESS != chFunRtn)
			{/* 两次消息输入内容不一致 */
				strCfmSnd->chOpStatus = CONFIRM_SECOND_DIFF;
				chFlag = FLAG_SET;
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		if (FLAG_UNSET == chFlag)
		{
			ii = 0u;
			szCrcTmp[ii++] = strMsgSnd->chTiocId;
			LongToChar(strCfmFst->dwTime, &szCrcTmp[ii]);
			ii += 4u;
			szCrcTmp[ii++] = strMsgSnd->chTrainNum;
			for (chAtsIndex = 0u; chAtsIndex < strMsgSnd->chTrainNum; chAtsIndex++)
			{
				LongToChar(strMsgSnd->strTrainInfo[chAtsIndex].dwTrainId, &szCrcTmp[ii]);
				ii += 4u;
				ShortToChar(strMsgSnd->strTrainInfo[chAtsIndex].wLgcId, &szCrcTmp[ii]);
				ii += 2u;
			}
			dwCrc = Tioc_CommonCrc32(szCrcTmp, ii);
			if (dwCrc != strMsgSnd->dwCrc32)
			{/* 计算的CRC32与ATS二次消息CRC32不一致 */
				strCfmSnd->chOpStatus = CONFIRM_SECOND_CRC;
				chFlag = FLAG_SET;
			}
			else
			{
				;
			}
		}
		else
		{
			;
		}

		ii = 0u;
		szCrcTmp[ii++] = strMsgFst->chAtsId;
		LongToChar(strMsgFst->dwTime, &szCrcTmp[ii]);
		ii += 4u;
		LongToChar(strMsgSnd->dwTime, &szCrcTmp[ii]);
		ii += 4u;
		szCrcTmp[ii++] = strMsgSnd->chTrainNum;
		for (chAtsIndex = 0u; chAtsIndex < strMsgSnd->chTrainNum; chAtsIndex++)
		{
			LongToChar(strMsgSnd->strTrainInfo[chAtsIndex].dwTrainId, &szCrcTmp[ii]);
			ii += 4u;
			ShortToChar(strMsgSnd->strTrainInfo[chAtsIndex].wLgcId, &szCrcTmp[ii]);
			ii += 2u;
		}
		strCfmSnd->dwCrc32 = Tioc_CommonCrc32(szCrcTmp, ii);
		if (FLAG_UNSET == chFlag)
		{/* 检查通过，反馈确认成功 */
			strCfmSnd->chOpStatus = CONFIRM_FIRST_SUCCESS;

			SetTrainAtsScreenProc();
		}
		else
		{
			;
		}
	}
	else
	{
		; /** 非本周期消息，不处理 */
	}
	ClearAtsMsgFirst();
	ClearAtsMsgSecond();
}

/**
* @brief 远程筛选处理
* @param 无
* @return 无
*/
static void TrainAtsScreenProc(void)
{
	AtsScreenMsgFstStru * strMsgFst = NULL;
	AtsScreenMsgSndStru * strMsgSnd = NULL;
	UINT8 startLockFlag = 0U;
	/*以下消息获取不会返回NULL*/
	strMsgFst = GetAtsMsgFst();
	strMsgSnd = GetAtsMsgSnd();
	startLockFlag = GetStartLockFlag();
	
	/*上电解封后才处理远程筛选*/
	if (CI_START_LOCK_NO == startLockFlag)
	{
		if ((strMsgFst->chFlag != FLAG_SET) && (strMsgSnd->chFlag != FLAG_SET))
		{
			; /* 没有消息，什么也不做 */
		}
		else if ((strMsgFst->chFlag == FLAG_SET) && (strMsgSnd->chFlag != FLAG_SET))
		{/* 远程筛选一次消息 */
			TrainAtsScreenFst();
		}
		else
		{/* 远程筛选二次消息 */
			TrainAtsScreenSnd();
		}
	}
	else
	{
		ClearAtsMsgFirst();
		ClearAtsMsgSecond();
	}
}

/**
* @brief 整理远程筛选发送数据
* @param 无
* @return 无
*/
static void TrainAtsScreenTidy(void)
{
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;
	UINT8 chScreenApply = 0u;
	UINT16 * pLgcId = NULL;
	UINT16 wLinkId = 0u;
	UINT16 wAcId = 0u;

	gAtsScreenNum = 0u;
	(void)CommonMemSet((void*)gszAtsScreenInfo, (UINT32)sizeof(gszAtsScreenInfo), (UINT8)0U , (UINT32)sizeof(gszAtsScreenInfo));
	/* 遍历所有列车 */
	for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
	{
		wTrainId = GetTrainId(chTrainIndex);
		chScreenApply = GetTrainScreenApply(wTrainId);
		if (TRAIN_SCREEN_ATS == chScreenApply)
		{
			wLinkId = GetTrainMaxHeadLink(wTrainId);
			wAcId = GetLinkBelongAcId(wLinkId);
			pLgcId = GetAxisSecLogSectionIdBuf(wAcId);
			if (NULL != pLgcId)
			{
				gszAtsScreenInfo[gAtsScreenNum].wTrainId = wTrainId;
				gszAtsScreenInfo[gAtsScreenNum].chScType = TRAIN_SCREEN_TYPE_LU;
				gszAtsScreenInfo[gAtsScreenNum].wLgcId = pLgcId[0];

				gAtsScreenNum++;
			}
			else
			{
				; /*不做处理*/
			}
		}
		else
		{
			;
		}
	}
}

/*
* 功能描述： 列车模块主处理
* 参数说明： 无
* 返回值  ： 无
* note：无
*/
void TrainMainProc(void)
{
	/* 安全位置计算 */
	CalTrainSafePosition();

	/* 列车动态测试处理 */
	TrainDynProc();

	/* 列车唤醒处理 */
	TrainWakeProc();

	/* 远程筛选 */
	TrainAtsScreenTidy();

	/* 远程筛选处理 */
	TrainAtsScreenProc();

	/* 原地筛选 */
	TrainScreenProc();

	/* 区间疏散处理 */
	EvacuationAreaProcess();

}

/*
* 功能描述： 判断列车是否在动态测试列表内
* 参数说明： const UINT16 wTrainId 列车ID
* 返回值  ： CI_ERROR:列车不在动态测试列表内；CI_SUCCESS:列车在动态测试列表内
*/
static UINT8 IsTrainDyTesting(const UINT16 wTrainId)
{
	UINT8 chDyIndex = 0u;
	UINT8 chRtn = CI_ERROR;
	for (chDyIndex = 0u; chDyIndex < gDyTestNum; chDyIndex++)
	{
		if (wTrainId == gszDyTestInfo[chDyIndex].wTrainId)
		{
			chRtn = CI_SUCCESS;
			break;
		}
		else
		{
			;
		}
	}
	return chRtn;
}

/*
* 功能描述： 将列车添加进动态测试列表
* 参数说明： const UINT16 wTrainId 列车ID
* 返回值  ： 无
*/
static void AddTrainDyTesting(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT16 wSysParamDyMax = GetSystemParaValue(DYTEST_SUM_MAX_ID);
	UINT8 chDyMax = (UINT8)(wSysParamDyMax & 0x00ffu);
	
	if ((chDyMax > gDyTestNum)
		&&(TRAIN_DYN_TEST_SUM_MAX>gDyTestNum))
	{
		gszDyTestInfo[gDyTestNum].wTrainId = wTrainId;
		gszDyTestInfo[gDyTestNum].wLinkId = wLinkId;
		gDyTestNum++;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 将列车移除出动态测试列表
* 参数说明： const UINT16 wTrainId 列车ID
* 返回值  ： 无
*/
void DelTrainDyTesting(const UINT16 wTrainId)
{
	UINT8 chIndex = 0u;
	UINT8 chDelIndex = 0u;
	for (chIndex = 0u; chIndex < gDyTestNum; chIndex++)
	{
		if (gszDyTestInfo[chIndex].wTrainId == wTrainId)
		{
			break;
		}
		else
		{
			;
		}
	}

	/* 找到对应列车 */
	if (chIndex < gDyTestNum)
	{
		for (chDelIndex = chIndex; chDelIndex < gDyTestNum - 1u; chDelIndex++)
		{
			gszDyTestInfo[chDelIndex].wTrainId = gszDyTestInfo[chDelIndex + 1u].wTrainId;
			gszDyTestInfo[chDelIndex].wLinkId = gszDyTestInfo[chDelIndex + 1u].wLinkId;
		}
		gDyTestNum--;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 判断link是否有列车正在动态测试
* 参数说明： const UINT16 wLinkId linkID
* 返回值  ： CI_ERROR:有车正在动态测试；CI_SUCCESS:无
*/
static UINT8 IsLinkTesting(UINT16 wLinkId)
{
	UINT8 chRtn = CI_ERROR;
	UINT8 chIndex = 0u;
	for (chIndex = 0u; chIndex < gDyTestNum; chIndex++)
	{
		if (wLinkId == gszDyTestInfo[chIndex].wLinkId)
		{
			break;
		}
		else
		{
			;
		}
	}

	if (chIndex < gDyTestNum)
	{
		chRtn = CI_ERROR;
	}
	else
	{
		chRtn = CI_SUCCESS;
	}

	return chRtn;
}

/*
* 功能描述： 设置指定列车筛选申请状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chApply 列车筛选申请状态
* 返回值  ： 无
*/
void SetTrainScreenApply(const UINT16 wTrainId, const UINT8 chApply)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_SCREEN_DEFAULT == chApply) || (TRAIN_SCREEN_ATS == chApply)
			|| (TRAIN_HEAD_SCREEN_IVOC == chApply) || (TRAIN_TAIL_SCREEN_IVOC == chApply)
			|| (TRAIN_SCREEN_IVOC == chApply)))
	{
		gstTrainInfo[wBufIndex].chScreenApply = chApply;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车筛选申请状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车筛选申请状态
*/
UINT8 GetTrainScreenApply(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_CMD_DYM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chScreenApply;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车前筛确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chReq 列车前筛确认状态
* 返回值  ： 无
*/
void SetTrainHeadScreenConfirm(const UINT16 wTrainId, const UINT8 chReq)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_HEAD_CONFIRM_YES == chReq) || (TRAIN_HEAD_CONFIRM_NO == chReq)))
	{
		gstTrainInfo[wBufIndex].chTrainHeadScreenConfirm = chReq;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车前筛确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车前筛确认状态
*/
UINT8 GetTrainHeadScreenConfirm(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_HEAD_CONFIRM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainHeadScreenConfirm;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车后筛确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chReq 列车后筛确认状态
* 返回值  ： 无
*/
void SetTrainTailScreenConfirm(const UINT16 wTrainId, const UINT8 chReq)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_TAIL_CONFIRM_YES == chReq) || (TRAIN_TAIL_CONFIRM_NO == chReq)))
	{
		gstTrainInfo[wBufIndex].chTrainTailScreenConfirm = chReq;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车后筛确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车后筛确认状态
*/
UINT8 GetTrainTailScreenConfirm(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_TAIL_CONFIRM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainTailScreenConfirm;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车远程筛选确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chReq 列车远程筛选确认状态
* 返回值  ： 无
*/
void SetTrainAtsScreenConfirm(const UINT16 wTrainId, const UINT8 chReq)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_ATS_CONFIRM_YES == chReq) || (TRAIN_ATS_CONFIRM_NO == chReq)))
	{
		gstTrainInfo[wBufIndex].chAtsScreenConfirm = chReq;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车远程筛选确认状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车远程筛选确认状态
*/
UINT8 GetTrainAtsScreenConfirm(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_ATS_CONFIRM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chAtsScreenConfirm;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 获取需要远程筛选的列车数量
* 参数说明： 无
* 返回值  ： 需要远程筛选的列车数量
*/
UINT8 GetAtsScreenNum(void)
{
	return gAtsScreenNum;
}

/*
* 功能描述： 获取需要远程筛选的列车ID
* 参数说明： 无
* 返回值  ： 需要远程筛选的列车ID
*/
UINT16 GetAtsScreenTrainIdByIndex(const UINT8 chIndex)
{
	return gszAtsScreenInfo[chIndex].wTrainId;
}

/*
* 功能描述： 获取需要远程筛选的列车所处逻辑区段ID
* 参数说明： 无
* 返回值  ： 需要远程筛选的列车所处逻辑区段ID
*/
UINT16 GetAtsScreenLgcIdByIndex(const UINT8 chIndex)
{
	return gszAtsScreenInfo[chIndex].wLgcId;
}

/*
* 功能描述： 获取需要远程筛选类别
* 参数说明： 无
* 返回值  ： 远程筛选类别
*/
UINT8 GetAtsScreenTypeByIndex(const UINT8 chIndex)
{
	return gszAtsScreenInfo[chIndex].chScType;
}

/*
* 功能描述： 设置指定列车停准停稳状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 列车停准停稳状态
* 返回值  ： 无
*/
void SetTrainStopSteadyState(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_SS_YES == chState) || (TRAIN_SS_NO == chState)))
	{
		gstTrainInfo[wBufIndex].chStopSteadyState = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车停准停稳状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车停准停稳状态
*/
UINT8 GetTrainStopSteadyState(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_SS_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chStopSteadyState;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车能否清除休眠状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 列车能否清除休眠状态
* 返回值  ： 无
*/
void SetTrainSleepCancleFlag(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_SLEEP_CANCLE_YES == chState) || (TRAIN_SLEEP_CANCLE_NO == chState)))
	{
		gstTrainInfo[wBufIndex].chSleepCancleFlag = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车能否清除休眠状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车能否清除休眠状态
*/
UINT8 GetTrainSleepCancleFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_SLEEP_CANCLE_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chSleepCancleFlag;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车通信中断周期号
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车通信中断周期号
*/
static UINT32 GetTrainTransBadCyc(const UINT16 wTrainId)
{
	UINT32 dwRetVal = 0u;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTransBadCyc;
	}
	else
	{
		;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定列车反馈区间疏散数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 区间疏散数量
*/
UINT8 GetTrainEaNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = EA_MAX_NUM;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chEaNum;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车反馈区间疏散信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 区间疏散信息
*/
TrainEaStru * GetTrainEaInfo(const UINT16 wTrainId)
{
	TrainEaStru * pRtn = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		pRtn = gstTrainInfo[wBufIndex].strTrainEaInfo;
	}
	else
	{
		;
	}

	return pRtn;
}

/*
* 功能描述： 获取指定列车区间疏散命令
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 区间疏散命令
*/
UINT8 GetTrainEaCmd(const UINT16 wTrainId)
{
	UINT8 chRetVal = EA_PROTECT_BUILD;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chEaCmd;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车区间疏散命令
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chCmd 区间疏散命令
* 返回值  ： 无
*/
void SetTrainEaCmd(const UINT16 wTrainId, const UINT8 chCmd)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((EA_PROTECT_BUILD == chCmd) || (EA_PROTECT_DEFAULT == chCmd)))
	{
		gstTrainInfo[wBufIndex].chEaCmd = chCmd;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定列车区间疏散反馈数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chEaNum 区间疏散反馈数量
* 返回值  ： 无
*/
void SetTrainEaNum(const UINT16 wTrainId, const UINT8 chEaNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].chEaNum = chEaNum;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定列车区间疏散反馈信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 pEaInfo 区间疏散反馈信息
* 返回值  ： 无
*/
void SetTrainEaInfo(const UINT16 wTrainId, const TrainEaStru * pEaInfo)
{
	UINT8 chIndex = 0u;
	UINT16 wBufIndex = 0u;
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		for (chIndex = 0u; chIndex < EA_MAX_NUM; chIndex++)
		{
			gstTrainInfo[wBufIndex].strTrainEaInfo[chIndex].wEaTrainId = pEaInfo[chIndex].wEaTrainId;
			gstTrainInfo[wBufIndex].strTrainEaInfo[chIndex].chAgreeState = pEaInfo[chIndex].chAgreeState;
			gstTrainInfo[wBufIndex].strTrainEaInfo[chIndex].dwBuildCyc = pEaInfo[chIndex].dwBuildCyc;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车包络能否转为UCT
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： FLAG_UNSET:可转为UCT；FLAG_SET:不可转为UCT
* note：休眠车包络不可转为UCT
*/
UINT8 GetTrainCanUct(const UINT16 wTrainId)
{
	UINT8 chRetVal = FLAG_SET;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainCanUct;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车包络能否转为UCT
* 参数说明： const UINT16 wTrainId, 列车ID
			const UINT8 chFlag 标志
* 返回值  ： 无
* note：休眠车包络不可转为UCT
*/
static void SetTrainCanUct(const UINT16 wTrainId, const UINT8 chFlag)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && ((FLAG_SET == chFlag) || (FLAG_UNSET == chFlag)))
	{
		gstTrainInfo[wBufIndex].chTrainCanUct = chFlag;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 将所有列车置为可转为UCT
* 参数说明： 无
* 返回值  ： 无
* note：休眠车包络不可转为UCT
*/
void ClearTrainCanUctFlag(void)
{
	UINT8 chTrainIndex = 0u;
	UINT16 wTrainId = 0u;

	for (chTrainIndex = 0u; chTrainIndex < TRAIN_SUM_MAX; chTrainIndex++)
	{
		wTrainId = GetTrainId(chTrainIndex);
		SetTrainCanUct(wTrainId, FLAG_UNSET);
	}
}

/*
* 功能描述： 设置指定列车当前激活端
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chActive 列车激活端
* 返回值  ： 无
*/
void SetTrainActive(const UINT16 wTrainId, const UINT8 chActive)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_ACTIVE_NONE == chActive) || (TRAIN_ACTIVE_ONE == chActive)
			|| (TRAIN_ACTIVE_TWO == chActive) || (TRAIN_ACTIVE_ALL == chActive)))
	{
		gstTrainInfo[wBufIndex].chActive = chActive;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车当前激活端
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车当前激活端
*/
UINT8 GetTrainActive(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_ACTIVE_NONE;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chActive;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车RRM申请
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chRqst 列车进入RRM申请
* 返回值  ： 无
*/
void SetTrainRrmRqst(const UINT16 wTrainId, const UINT8 chRqst)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_RRM_RQST_YES == chRqst) || (TRAIN_RRM_RQST_NO == chRqst)))
	{
		gstTrainInfo[wBufIndex].chRrmRqst = chRqst;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车RRM申请
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车RRM申请
*/
UINT8 GetTrainRrmRqst(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_RRM_RQST_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chRrmRqst;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车RRM允许状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 列车进入RRM允许状态
* 返回值  ： 无
*/
void SetTrainRrmState(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_RRM_YES == chState) || (TRAIN_RRM_NO == chState) || (TRAIN_RRM_DEFAULT == chState)))
	{
		gstTrainInfo[wBufIndex].chRrmState = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车RRM允许状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车RRM允许状态
*/
UINT8 GetTrainRrmState(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_RRM_NO;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chRrmState;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车RRM不允许原因
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chReson 列车进入RRM不允许原因
* 返回值  ： 无
*/
void SetTrainRrmReson(const UINT16 wTrainId, const UINT8 chReson)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && 
		((TRAIN_RRM_RESON_02 == chReson) || (TRAIN_RRM_RESON_FF == chReson)
			 || ((TRAIN_RRM_RESON_05 <= chReson) && (TRAIN_RRM_RESON_0E >= chReson))
			|| ((TRAIN_RRM_RESON_15 <= chReson) && (TRAIN_RRM_RESON_17 >= chReson))))
	{
		gstTrainInfo[wBufIndex].chRrmReson = chReson;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车RRM不允许原因
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车RRM不允许原因
*/
UINT8 GetTrainRrmReson(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_RRM_RESON_FF;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chRrmReson;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定列车下一逻辑站台ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车下一逻辑站台ID
*/
UINT16 GetTrainAtsLgcStation(const UINT16 wTrainId)
{
	UINT16 wRetVal = 0u;
	UINT16 wBufIndex = 0u;
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wAtsLgcStation;
	}
	else
	{
		;
	}

	return wRetVal;
}

/*
* 功能描述： 设置指定列车下一逻辑站台ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wLgcStation 列车下一逻辑站台ID
* 返回值  ： 无
*/
void SetTrainAtsLgcStation(const UINT16 wTrainId, const UINT16 wLgcStation)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wAtsLgcStation = wLgcStation;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车下一控区ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车下一控区ID
*/
UINT16 GetTrainNextTioc(const UINT16 wTrainId)
{
	UINT16 wRetVal = 0u;
	UINT16 wBufIndex = 0u;
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wNextTioc;
	}
	else
	{
		;
	}

	return wRetVal;
}

/*
* 功能描述： 设置指定列车下一控区ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 wNextTioc 列车下一控区ID(带0x3c）
* 返回值  ： 无
*/
void SetTrainNextTioc(const UINT16 wTrainId, const UINT16 wNextTioc)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wNextTioc = wNextTioc;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定列车脱轨状态
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState 列车脱轨状态
* 返回值  ： 无
*/
void SetTrainDerailment(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex)
		&& ((TRAIN_DERAIL_YES == chState) || (TRAIN_DERAIL_NO == chState)))
	{
		gstTrainInfo[wBufIndex].chDerailment = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车脱轨状态
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车脱轨状态
*/
UINT8 GetTrainDerailment(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_DERAIL_YES;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chDerailment;
	}
	else
	{
		;
	}

	return chRetVal;
}


/*
* 功能描述： 判断列车位置是否有效
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： CI_ERROR:列车位置无效；CI_SUCCESS:列车位置有效
*/
UINT8 IsTrainPosValid(const UINT16 wTrainId)
{
	UINT16 wMaxHeadLink = 0u;
	UINT32 dwMaxHeadOff = 0u;
	UINT16 wMinHeadLink = 0u;
	UINT32 dwMinHeadOff = 0u;
	UINT16 wMaxTailLink = 0u;
	UINT32 dwMaxTailOff = 0u;
	UINT16 wMinTailLink = 0u;
	UINT32 dwMinTailOff = 0u;
	UINT8 chRtn = CI_ERROR;

	wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);
	dwMaxHeadOff = GetTrainMaxHeadOffset(wTrainId);
	wMinHeadLink = GetTrainMinHeadLink(wTrainId);
	dwMinHeadOff = GetTrainMinHeadOffset(wTrainId);
	wMaxTailLink = GetTrainMaxTailLink(wTrainId);
	dwMaxTailOff = GetTrainMaxTailOffset(wTrainId);
	wMinTailLink = GetTrainMinTailLink(wTrainId);
	dwMinTailOff = GetTrainMinTailOffset(wTrainId);

	chRtn = CheckLinkValid(wMaxHeadLink, dwMaxHeadOff);
	chRtn &= CheckLinkValid(wMinHeadLink, dwMinHeadOff);
	chRtn &= CheckLinkValid(wMaxTailLink, dwMaxTailOff);
	chRtn &= CheckLinkValid(wMinTailLink, dwMinTailOff);

	return chRtn;
}

/*
* 功能描述：设置列车前方计轴器编号
*输入参数：wTrainId 列车id wHeadAxis 前方计轴id
*返回值： void
*Created: fan 2024.2.21
*/
void SetHeadAxisId(const UINT16 wTrainId, const UINT16 wHeadAxis)
{

	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wHeadAxisId = wHeadAxis;
	}
	else
	{
		; 
	}
}

/*
* 功能描述：设置列车前方ITE识别结果
*输入参数：wTrainId 列车id devState 前方ITE识别结果
*返回值： void
*Created: fan 2024.2.21
*/
void SetHeadITEResult(const UINT16 wTrainId, const UINT8 devState)
{

	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) &&
		((TRAIN_ITE_RESULT_YES == devState) || (TRAIN_ITE_RESULT_NO == devState)))
	{
		gstTrainInfo[wBufIndex].wHeadITEResult = devState;
	}
	else
	{
		;
	}
}

/*
* 功能描述：设置列车后方计轴器编号
*输入参数：wTrainId 列车id wTailAxis 后方计轴id
*返回值： void
*Created: fan 2024.2.21
*/
void SetTailAxisId(const UINT16 wTrainId, const UINT16 wTailAxis)
{

	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wTailAxisId = wTailAxis;
	}
	else
	{
		;
	}
}
/*
* 功能描述：设置列车后方ITE识别结果
*输入参数：wTrainId 列车id devState 后方ITE识别结果
*返回值： void
*Created: fan 2024.2.21
*/
void SetTailITEResult(const UINT16 wTrainId, const UINT8 devState)
{

	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) &&
		((TRAIN_ITE_RESULT_YES == devState) || (TRAIN_ITE_RESULT_NO == devState)))
	{
		gstTrainInfo[wBufIndex].wTailITEResult = devState;
	}
	else
	{
		;
	}
}

/*
* 功能描述：获取IVOC提供给RC的前方计轴编号和ITE识别结果
*输入参数：wTrainId 列车id
*返回参数：UINT8 *devState （0x55无列车 0xAA有列车)
*返回值：UINT16 AxisId 前方计轴器编号
*Created: fan 2024.2.21
*/
UINT16 GetTrainHeadITEScreen(const UINT16 wTrainId, UINT8* devState)
{
	UINT16 AxisId = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) &&(NULL != devState))
	{
		AxisId = gstTrainInfo[wBufIndex].wHeadAxisId ;
		*devState = gstTrainInfo[wBufIndex].wHeadITEResult;
	}
	else
	{
		AxisId = 0xffff; /*非法值*/
	}

	return AxisId;
}

/**
* 功能描述：获取IVOC提供给RC的后方方计轴编号和ITE识别结果
*输入参数：wTrainID 列车id
*返回参数：UINT8 * devState （0x55无列车 0xAA有列车)
*返回值：UINT16 AxisId
*Created: fan 2024.2.21
*/
UINT16 GetTrainTailITEScreen(const UINT16 wTrainId, UINT8* devState)
{
	UINT16 AxisId = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		AxisId = gstTrainInfo[wBufIndex].wTailAxisId;
		*devState = gstTrainInfo[wBufIndex].wTailITEResult;
	}
	else
	{
		AxisId = 0xffff; /*非法值*/
	}

	return AxisId;
}

/*
* 功能描述： 检查列车脚下资源是否齐全、运行方向是否与ATS下发的运行方向匹配
* 输入参数： const UINT16 wTrainId  列车ID
*            const UINT8 cQueryDir 逻辑区段对应的查询方向（逻辑方向）
*            const UINT8 cLogSecSum 逻辑区段序列数量
*            const UINT16 pLogSecIdBuff[] 逻辑区段ID数组
*            const UINT8 cFunctionId 函数ID
*            const UINT8 cSendLevel 报警发送级别
* 输出参数： UINT8* pHalfRouteSwitchMoveFlag 半截进路道岔可动标志
*            UINT16 *pTrainOccLogSecSum 列车脚下逻辑区段数量
*            UINT16 pTrainOccLogSecID[] 列车脚下逻辑区段ID数组
* 返回值  ：CI_SUCCESS：检查通过
			CI_ERROR: 检查不通过
*/
UINT8 TrainResAndDirCheck(const UINT16 wTrainId, const UINT8 cQueryDir, const UINT8 cLogSecSum, const UINT16 pLogSecIdBuff[],
	UINT8* pHalfRouteSwitchMoveFlag, UINT16* pTrainOccLogSecSum, UINT16 pTrainOccLogSecID[], const UINT8 cFunctionId, const UINT8 cSendLevel)
{
	/*局部变量初始化*/
	UINT8 retVal = CI_ERROR;
	UINT8 cFuncResult = CI_ERROR;
	UINT16 i = 0U;
	UINT8 cTrainLevel = 0U;  /*列车级别*/
	UINT8 cTrainMaxTailDir = 0U;    /*列车大后方向*/
	UINT8 cLogSecQueryDir = 0U;  /*逻辑区段查询方向*/
	struct_PathPoint strMaxTailPoint = { 0U };    /*列车大后所处位置*/
	struct_PathPoint strMaxTailCrossPoint = { 0U };  /*列车大后+跨压距离的位置*/
	struct_PathPoint strMaxHeadPoint = { 0U };  /*列车大前所在位置*/
	struct_PathPoint strMinTailPoint = { 0U };  /*列车小后所在位置*/
	UINT32 dwCrossDis = 0U;  /*配置数据：判断跨压距离*/
	UINT16 wSwitchId = 0U;  /*函数入参需要的变量*/
	UINT16 wLogSecTrainId = 0U;       /*逻辑区段资源列车ID*/
	UINT8 cTrainInfoSum = 0U;         /*逻辑区段资源列车数量*/
	LogicTrainResStruct* pTrainResData = NULL;   /*逻辑区段资源列车信息结构体*/
	UINT8 cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;     /*半截进路道岔可动标志*/
	UINT16 wTrainMinTMaxHLogNum = 0U;  /*列车脚下小后至大前间的逻辑区段数量*/
	UINT16 szTrainMinTMaxHLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };  /*列车脚下小后至大前间的逻辑区段ID*/
	UINT16 wTrainMaxCMaxHLogNum = 0U;  /*列车脚下大后+跨压距离至大前间的逻辑区段数量*/
	UINT16 szTrainMaxCMaxHLogID[SIZE_MAX_SECTION_BT_TRAIN] = { 0U };  /*列车脚下大后+跨压距离至大前间的逻辑区段ID*/
	UINT16 wMaxTailLinkId = 0U;  /*列车大后所处Link*/
	UINT8 cLogSecIncLinkNum = 0U;  /*逻辑区段包含的link数量*/
	UINT16* pLogSecIncLinkId = NULL;  /*逻辑区段包含的link ID*/
	LOD_STRU strCurPoint = { 0U };
	LOD_STRU strNxtPoint = { 0U };
	UINT8 cDirChangeNum = 0U;  /*列车与逻辑区段间的方向变化点数量*/
	UINT8 cStartDir = 0u;  /*列车起点查询方向（逻辑方向）*/
	UINT8 cErrStep = 0U;  /*记录检查失败的变量*/
	UINT8 cLocalCiId = 0U;
	UINT8 cMaxHeadBelongCiId = 0U;  /*列车大前所处控区*/
	UINT8 cMinTailBelongCiId = 0U;  /*列车小后所处控区*/
	UINT8 cTrianAllInOtherRcFlag = FLAG_UNSET;  /*列车在其它控区标志*/
	UINT8 cCommStateWithTrain = CI_ERROR;  /*与车通信状态*/
	UINT8 cLogSecLockState = LOG_SECTION_LOCK_NO;  /*逻辑区段进路锁闭状态*/
	UINT8 cLogSecLogLockState = LOG_SECTION_LOGLOCK_NO;  /*逻辑区段逻辑锁闭状态*/
	UINT16 wOutLogSecNum = 0U;  /*需输出的列车脚下区段数量*/
	UINT8 jj = 0U;
	UINT8 kk = 0U;
	UINT16 wLockBelongRouteId = 0U;  /*逻辑区段进路锁闭所属进路ID*/
	UINT16 wFstLockedLogSecId = 0U;  /*进路第一个锁闭的逻辑区段ID*/
	UINT8 chLogSecLockBelLogRouteSum = 0U;/*逻辑区段锁闭所属逻辑进路数量*/
	LogSecLockBelLogRouteStruct* szLogSecLockBelLogRouteData = NULL;/*逻辑区段锁闭所属逻辑进路数据*/
	UINT16 wFstLogLockedLogSecId = 0U;  /*进路第一个逻辑锁闭的逻辑区段ID*/
	UINT8 mm = 0U;

	/*入参检查（列车ID暂不查）*/
	if (((DIR_SAME == cQueryDir) || (DIR_CONVERT == cQueryDir)) && (0U != cLogSecSum) && (NULL != pLogSecIdBuff) && ((ESEND_LEVEL_ATS == cSendLevel) || (ESEND_LEVEL_ZERO == cSendLevel)))
	{
		retVal = CI_SUCCESS;
		cCommStateWithTrain = GetTrainTransitmitStat(wTrainId);
		if (TRAIN_COMM_STATE_GOOD == cCommStateWithTrain)  /*列车ID合法，继续判断*/
		{
			cTrainMaxTailDir = GetTrainDir_MaxTail(wTrainId);

			if ((DIR_SAME == cTrainMaxTailDir) || (DIR_CONVERT == cTrainMaxTailDir))
			{
				/*获取列车位置*/
				strMaxHeadPoint.wLinkId = GetTrainMaxHeadLink(wTrainId);
				strMaxHeadPoint.dwOffset = GetTrainMaxHeadOffset(wTrainId);
				strMaxTailPoint.wLinkId = GetTrainMaxTailLink(wTrainId);
				strMaxTailPoint.dwOffset = GetTrainMaxTailOffset(wTrainId);
				strMinTailPoint.wLinkId = GetTrainMinTailLink(wTrainId);
				strMinTailPoint.dwOffset = GetTrainMinTailOffset(wTrainId);

				dwCrossDis = (UINT32)GetSigCrossMaxLen();
				dwCrossDis = dwCrossDis * 100U;  /*将跨压距离转换成cm*/
				cFuncResult = dsuNewLocAndObsByOffsetDis(strMaxTailPoint, dwCrossDis, cTrainMaxTailDir, &strMaxTailCrossPoint, &wSwitchId);  /*计算列车脚下起点位置：大后往车头加一个跨压距离*/

				if ((1U == cFuncResult) || (3U == cFuncResult))
				{
					/*计算列车脚下起点位置成功，不处理*/
				}
				else
				{
					cErrStep = 2U;
					retVal = CI_ERROR;  /*计算列车脚下起点位置失败，返回0失败*/
				}
			}
			else
			{
				cErrStep = 2U;
				retVal = CI_ERROR;  /*方向异常，返回0失败*/
			}

			if (CI_SUCCESS == retVal)
			{
				cLocalCiId = GetSystemParaLocalCiId();
				cMaxHeadBelongCiId = (UINT8)GetLinkManageTiocById(strMaxHeadPoint.wLinkId);  /*获取列车大前所属RC*/
				cMinTailBelongCiId = (UINT8)GetLinkManageTiocById(strMinTailPoint.wLinkId);  /*获取列车大前所属RC*/

				if ((0U != cLocalCiId) && ((cLocalCiId == cMaxHeadBelongCiId) || (cLocalCiId == cMinTailBelongCiId)))
				{
					/*获取列车脚下逻辑区段数量/ID*/
					retVal = GetLogSecBtwTwoPoints(strMinTailPoint, strMaxHeadPoint, &wTrainMinTMaxHLogNum, szTrainMinTMaxHLogID);  /*获取列车小后至大前间的逻辑区段*/
					retVal &= GetLogSecBtwTwoPoints(strMaxTailCrossPoint, strMaxHeadPoint, &wTrainMaxCMaxHLogNum, szTrainMaxCMaxHLogID);  /*获取列车大后+跨压距离至大前间的逻辑区段*/

					if ((CI_SUCCESS == retVal) && (0U < wTrainMinTMaxHLogNum) && (SIZE_MAX_SECTION_BT_TRAIN > wTrainMinTMaxHLogNum)
						&& (0U < wTrainMaxCMaxHLogNum) && (SIZE_MAX_SECTION_BT_TRAIN > wTrainMaxCMaxHLogNum))
					{
						/*继续执行*/
					}
					else
					{
						cErrStep = 3U;
						retVal = CI_ERROR;   /*列车脚下逻辑区段数量非法，返回0失败*/
					}
				}
				else if ((0U != cLocalCiId) && (0U != cMaxHeadBelongCiId) && (0U != cMinTailBelongCiId)
					&& (cLocalCiId != cMaxHeadBelongCiId) && (cLocalCiId != cMinTailBelongCiId))
				{
					cTrianAllInOtherRcFlag = FLAG_SET;  /*列车完全不在本控区，继续执行*/
				}
				else
				{
					cErrStep = 3U;
					retVal = CI_ERROR;  /*获取控区失败，返回0失败*/
				}
			}
			else
			{
				/*不处理*/
			}

			if ((CI_SUCCESS == retVal) && (FLAG_UNSET == cTrianAllInOtherRcFlag))
			{
				/*确定列车大后所处逻辑区段的查询方向*/
				cLogSecQueryDir = cQueryDir;
				wMaxTailLinkId = GetTrainMaxTailLink(wTrainId);
				cLogSecIncLinkNum = GetSecIntrudeLinkSum(pLogSecIdBuff[0]);
				pLogSecIncLinkId = GetSecIntrudeLinkIdBuf(pLogSecIdBuff[0]);

				if ((CI_ERROR != wMaxTailLinkId) && (NULL != pLogSecIncLinkId) && (0U < cLogSecIncLinkNum) && (LOGSEC_INCLUDE_LINK_SUM_MAX >= cLogSecIncLinkNum))
				{
					strCurPoint.Lnk = pLogSecIncLinkId[0U];
					strCurPoint.Off = 0U;
					strNxtPoint.Lnk = wMaxTailLinkId;
					strNxtPoint.Off = 0U;
					cDirChangeNum = GetDirChangeNumBtwPoints(&strCurPoint, &strNxtPoint);  /*查询列车大后到序列中首个逻辑区段间的方向变化点*/
					cStartDir = TransDirByChangeNum(cTrainMaxTailDir, cDirChangeNum);
				}
				else
				{
					cErrStep = 4U;
					retVal = CI_ERROR;  /*获取link失败，返回失败*/
				}

				cTrainLevel = GetTrainLevel(wTrainId);
				if ((TRAIN_LEVEL_VBTC == cTrainLevel) && (CI_SUCCESS == retVal))  /*VBTC*/
				{
					/*判断列车大后+跨压距离至大前间的逻辑区段资源是否唯一且齐全*/
					for (i = 0U; i < wTrainMaxCMaxHLogNum; i++)
					{
						cTrainInfoSum = GetLogSecTrainInfoSum(szTrainMaxCMaxHLogID[i]);   /*获取逻辑区段资源列车数量*/
						pTrainResData = GetLogSecTrainInfo(szTrainMaxCMaxHLogID[i]);      /*获取逻辑区段资源列车信息结构体*/
						if ((1U == cTrainInfoSum) && (NULL != pTrainResData))
						{
							/*仅列车资源数为1继续*/
							wLogSecTrainId = pTrainResData[0U].wTrainId;
							if (((wLogSecTrainId & 0xFFU) == (wTrainId & 0xFFU)) && (LOGIC_SECTION_RES_USABLE == pTrainResData[0U].chLogicResUsable))
							{
								retVal = CI_SUCCESS;  /*资源可用，返回成功*/
							}
							else
							{
								retVal = CI_ERROR;  /*无资源，停止检查，返回失败*/
								break;
							}
						}
						else
						{
							retVal = CI_ERROR;
							break;
						}
					}

					if (CI_SUCCESS == retVal)
					{
						cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_VALID;
						retVal = CI_SUCCESS;

					}
					else
					{
						/*VBTC但脚下资源不齐全，设置不可动道岔标志*/
						cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;

						if (((DIR_SAME == cLogSecQueryDir) && (DIR_SAME == cStartDir))
							|| ((DIR_CONVERT == cLogSecQueryDir) && (DIR_CONVERT == cStartDir)))
						{
							retVal = CI_SUCCESS;   /*ATS下发运行方向与当前列车运行方向相同，继续处理*/
						}
						else
						{
							cErrStep = 5U;
							retVal = CI_ERROR;     /*ATS下发运行方向与当前列车运行方向相反，停止处理*/
						}
					}
				}
				else if (CI_SUCCESS == retVal)  /*非VBTC*/
				{
					/*非VBTC，设置不可动道岔标志*/
					cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;

					if (((DIR_CONVERT == cLogSecQueryDir) && (DIR_CONVERT == cStartDir))
						|| ((DIR_SAME == cLogSecQueryDir) && (DIR_SAME == cStartDir)))
					{
						retVal = CI_SUCCESS;   /*ATS下发运行方向与当前列车运行方向相同，继续处理*/
					}
					else
					{
						cErrStep = 5U;
						retVal = CI_ERROR;     /*ATS下发运行方向与当前列车运行方向相反，停止处理*/
					}
				}
				else
				{
					retVal = CI_ERROR;     /*返回失败*/
				}
			}
			else if ((CI_SUCCESS == retVal) && (FLAG_SET == cTrianAllInOtherRcFlag))
			{
				cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;  /*列车完全不在本控区*/
			}
			else
			{
				/*返回失败*/
			}

			if (CI_SUCCESS == retVal)
			{
				/*检查序列内所有逻辑区段的进路锁闭所属进路的第一个待解锁逻辑区段是否均包含在序列内*/
				for (jj = 0U; jj < cLogSecSum; jj++)
				{
					wLockBelongRouteId = GetLogSecLockBelongRoute(pLogSecIdBuff[jj]);
					wFstLockedLogSecId = GetRouteFirstLockedLogSecId(wLockBelongRouteId);  /*获取进路内方第一个锁闭的逻辑区段ID*/
					if (0U != wFstLockedLogSecId)
					{
						for (kk = 0U; kk < cLogSecSum; kk++)
						{
							/*检查该逻辑区段是否处于序列内*/
							if (wFstLockedLogSecId == pLogSecIdBuff[kk])
							{
								break;
							}
							else
							{
								/*继续检查*/
							}				
						}

						if (kk == cLogSecSum)
						{
							retVal = CI_ERROR;
							break;  /*序列未包含进路内方第一个锁闭的逻辑区段，停止遍历返回失败*/
						}
						else
						{
							/*继续检查*/
						}
					}
					else
					{
						/*无锁闭，继续检查*/
					}
				}

				if (CI_SUCCESS == retVal)
				{
					/*检查通过*/
				}
				else
				{
					cLogSecLockState = GetLogSecLockState(wFstLockedLogSecId);
					SetErrorData(cFunctionId, CI_DEVICE_TYPE_LOGICSEC, wFstLockedLogSecId, ETYPE_LOGSEC_LOCK_STATE, cLogSecLockState, cSendLevel);
					cErrStep = 6U;
					retVal = CI_ERROR;  /*返回失败*/
				}
			}
			else
			{
				SetCiSendCmdBackInfoWithTrainId(CI_BACK_DYM_ROUTE_RES, CI_SYSTEM_TYPE_VOBC, wTrainId, 0U, 0U, wTrainId);
				/*不处理*/
			}

			if (CI_SUCCESS == retVal)
			{
				/*检查序列内所有逻辑区段的进路锁闭所属逻辑进路的第一个待解锁逻辑区段是否均包含在序列内*/
				for (jj = 0U; jj < cLogSecSum; jj++)
				{
					chLogSecLockBelLogRouteSum = GetLogSecLockBelLogRouteSum(pLogSecIdBuff[jj]);
					szLogSecLockBelLogRouteData = GetLogSecLockBelLogRouteData(pLogSecIdBuff[jj]);

					if (NULL != szLogSecLockBelLogRouteData)
					{
						for (mm = 0U; mm < chLogSecLockBelLogRouteSum; mm++)
						{
							wFstLogLockedLogSecId = GetLogRouteFirLogLockLogId(szLogSecLockBelLogRouteData[mm].wLogSecLockBelLogRouteId);
							if (0U != wFstLogLockedLogSecId)
							{
								for (kk = 0U; kk < cLogSecSum; kk++)
								{
									/*检查该逻辑区段是否处于序列内*/
									if (wFstLogLockedLogSecId == pLogSecIdBuff[kk])
									{
										break;
									}
									else
									{
										/*继续检查*/
									}
								}

								if (kk == cLogSecSum)
								{
									retVal = CI_ERROR;
									break;  /*序列未包含逻辑进路内方第一个锁闭的逻辑区段，停止遍历返回失败*/
								}
								else
								{
									/*继续检查*/
								}
							}
							else
							{
								/*无锁闭，继续检查*/
							}

							if (CI_ERROR == retVal)
							{
								break;
							}
							else
							{
								; /*继续检查*/
							}
						}
					}
					else
					{
						retVal = CI_ERROR;
					}
					if (CI_ERROR == retVal)
					{
						break;
					}
					else
					{
						; /*继续检查*/
					}
				}

				if (CI_SUCCESS == retVal)
				{
					/*检查通过*/
				}
				else
				{
					cLogSecLogLockState = GetLogSecLogLockState(wFstLogLockedLogSecId);
					SetErrorData(cFunctionId, CI_DEVICE_TYPE_LOGICSEC, wFstLogLockedLogSecId, ETYPE_LOGSEC_LOCK_STATE, cLogSecLogLockState, cSendLevel);
					cErrStep = 7U;
					retVal = CI_ERROR;  /*返回失败*/
				}
			}
			else
			{
				/*不处理*/
			}
		}
		else if (CI_ERROR != cCommStateWithTrain)
		{
			cHrSwitchMoveFlag = ROUTE_HALF_SWITCH_MOVE_INVALID;  /*未与列车通信*/
		}
		else
		{
			/*车组号无效，直接返回成功*/
		}
	}
	else
	{
		cErrStep = 1U;
		retVal = CI_ERROR;  /*入参校验失败*/
	}

	if (CI_SUCCESS == retVal)
	{
		*pHalfRouteSwitchMoveFlag = cHrSwitchMoveFlag;
		if (ROUTE_HALF_SWITCH_MOVE_VALID == cHrSwitchMoveFlag)
		{
			/*可动道岔，记录列车脚下逻辑区段*/
			debug_infor_printf((const)"Dynamic Route TrainOccLogSecID[");
			for (i = 0U; i < wTrainMinTMaxHLogNum; i++)
			{
				cLogSecLockState = GetLogSecLockState(szTrainMinTMaxHLogID[i]);
				cLogSecLogLockState = GetLogSecLogLockState(szTrainMinTMaxHLogID[i]);
				if ((LOG_SECTION_LOCK_NORMAL == cLogSecLockState) || (LOG_SECTION_LOCK_DELAY == cLogSecLockState) || (LOG_SECTION_LOGLOCK_NORMAL == cLogSecLogLockState))
				{
					pTrainOccLogSecID[wOutLogSecNum] = szTrainMinTMaxHLogID[i];
					debug_infor_printf((const)"%d,", szTrainMinTMaxHLogID[i]);
					wOutLogSecNum++;
				}
				else
				{
					/*区段未锁闭，不作为列车脚下区段传出*/
				}
			}
			debug_infor_printf((const)"]\n");

			*pTrainOccLogSecSum = wOutLogSecNum;
		}
		else
		{
			/*不可动道岔，不记录列车脚下逻辑区段*/
		}
	}
	else
	{
		/*1-入参非法；2-计算列车脚下起点失败；3-获取列车脚下逻辑区段失败；4-获取列车大后所处link失败；5-逻辑区段序列方向与列车方向不匹配；6-序列未包含逻辑区段锁闭所属进路的第一个锁闭的逻辑区段*/
		debug_infor_printf((const)"Dynamic Route TrainResAndDirCheck ErrStep[%d]\n", cErrStep);
	}

	return retVal;
}

/*
* 功能描述： 列车资源回收
* 参数说明： 无
* 返回值  ： 无
* note：降级列车完全驶入进路后，回收列车资源
*/
void TrainResRecycle(void)
{
	UINT16 ii = 0u;
	UINT8 trainIndex = 0U;
	UINT16 routeCurSum = 0u;	     /*进路总数目*/
	UINT16 routeId = 0u;	         /*进路ID*/
	UINT8 localCiId = 0U;			/*当前集中区ID*/
	UINT8 routeBelongCiId = 0U;		/*进路所属集中区ID*/

	UINT8 funcRetval = 0U;
	UINT8 routeInTrainNum = 0U;
	UINT8 trainOTStat = 0U;
	UINT16 routeInTrainId[LOGIC_SECTION_RES_SUM_MAX] = { 0U };
	UINT8 chTrainSleepState = 0U;/*列车休眠状态*/
	UINT16 wStartSigID = 0U;
	UINT16 wLightUpTrainID = 0U;/*点灯列车ID*/
	UINT8 chLocalCiType = 0U; /*联锁类型*/
	UINT8 chDelete = 0U;
	UINT8 chRouteState = 0U;
	localCiId = GetSystemParaLocalCiId();
	routeCurSum = GetRouteCurSum();		        /*获取进路总数*/
	chLocalCiType = GetLocalCiType();
	/*处理进路*/
	for (ii = 0u; ii < routeCurSum; ii++)
	{

		routeId = GetRouteId(ii);                           /*获取进路ID*/
		routeBelongCiId = GetRouteBelongCiId(routeId);		/*获取进路所属集中区ID*/

		if ((routeBelongCiId == localCiId) && (0U != routeBelongCiId))
		{
			/*该进路已完整锁闭*/
			funcRetval = RouteAllLockCheck(routeId);
			/*获取要进入进路的列车信息*/
			funcRetval &= GetRouteReadyEnterTrainInfo(routeId, &routeInTrainNum, routeInTrainId);
			wStartSigID = GetRouteStartSignalId(routeId);
			chRouteState = GetRouteState(routeId);
			if (0U < wStartSigID)
			{
				wLightUpTrainID = GetSignalLightUpTrainId(wStartSigID);
			}
			else
			{
				wLightUpTrainID = 0U;
			}
			if (CI_SUCCESS == funcRetval)
			{
				for (trainIndex = 0U; trainIndex < routeInTrainNum; trainIndex++)
				{
					chDelete = CI_SUCCESS;
					trainOTStat = GetTrainResRecycleOTStat(routeInTrainId[trainIndex]);
					chTrainSleepState = GetTrainSleepState(routeInTrainId[trainIndex]);
					if ((0U < wLightUpTrainID)
						&&((ROUTE_STATE_YUXIAN_OPEN == chRouteState) ||(ROUTE_STATE_NEAR_OPEN == chRouteState)))
					{					
						if (((routeInTrainId[trainIndex] & 0x00ffU) != wLightUpTrainID)&&(CI_TYPE_CLD == chLocalCiType))
						{
							/*存在接近车，删除车辆段非最接近车的资源*/
							chDelete = CI_ERROR;
						}
						else
						{
							; /*继续检查*/
						}
					}
					if ((CI_SUCCESS == chDelete)&&(CI_SUCCESS == trainOTStat) && (TRAIN_SLEEP_YES !=chTrainSleepState))
					{
						/*获取进路接近区段是否有可疑列车*/
						funcRetval = GetRouteSuspiciousInNearSec(routeId);
						if (CI_SUCCESS == funcRetval)
						{
							/*资源取消延时超时且不为休眠车才回收资源，休眠车不回收资源*/
							chDelete = CI_ERROR;
						}
						else
						{
							;
						}
					}
					else
					{
						; /*保留资源*/
					}
					if (CI_ERROR == chDelete)
					{
						RemoveRouteInCiRes(routeId, routeInTrainId[trainIndex]);		/*删除该列车进路内资源*/
					}
					else
					{
						; /*保留资源*/
					}
				}
			}
			else
			{
				; 
			}

			/*删除列车资源及接近区段查询状态为有故障车*/
			SetRouteNearSecSearchState(routeId, ROUTE_NEAR_SEC_HAVE_UT);
		}
		else
		{
			; /*不处理*/
		}
	}
}

/*
* 功能描述： 获取指定列车是否满足回收资源时间
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： CI_ERROR 不满足（未超时/未计时） CI_SUCCESS 满足（超时）
*/
UINT8 GetTrainResRecycleOTStat(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 overtimeStat = CI_TIME_NO;
	UINT8 trainTransimitStat = TRAIN_COMM_STATE_BAD;
	UINT32 trainLoseCommCyc = 0U;
	UINT16 wBufIndex = 0U;
	UINT32 overtimeCycleCount = 0U;


	overtimeCycleCount = GetSystemParaTrainReCycleCount();
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		trainTransimitStat = GetTrainTransitmitStat(wTrainId);
		trainLoseCommCyc = GetTrainTransBadCyc(wTrainId);

		/*列车通信不好*/
		if (TRAIN_COMM_STATE_BAD == trainTransimitStat)
		{
			
			overtimeStat = SystemOverTimeCheck(trainLoseCommCyc, overtimeCycleCount);

			if (CI_TIME_OUT == overtimeStat)
			{
				/*超时，*/
				chRetVal = CI_SUCCESS;
			}
			else
			{
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 设置列车各点的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainDir 列车运行方向（已获取的运营方向，最小后端指向车头）
* 返回值  ： CI_ERROR 设置失败  CI_SUCCESS 设置成功
*/
UINT8 SetTrainOtherPointDir(const UINT16 wTrainId, const UINT8 chTrainDir)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	UINT16 linknum_MaxHead = 0u;
	UINT16 linknum_MinHead = 0u;
	UINT16 linknum_MaxTail = 0u;
	LOD_STRU pMaxHead = { 0u }; /*最大安全前端位置*/
	LOD_STRU pMinHead = { 0u }; /*最小安全前端位置*/
	LOD_STRU pMaxTail = { 0u }; /*最大安全后端位置*/
	LOD_STRU pMinTail = { 0u }; /*最小安全后端位置*/
	UINT8 changerPNumtoMaxHead = 0u;/*最小安全后端位置到最大安全前端位置经历的方向变化点*/
	UINT8 changerPNumtoMinHead = 0u;/*最小安全后端位置到最小安全前端位置经历的方向变化点*/
	UINT8 changerPNumtoMaxTail = 0u;/*最小安全后端位置到最大安全后端位置经历的方向变化点*/
	UINT32 dwlen_tomaxhead = 0u;
	UINT32 dwlen_tominhead = 0u;
	UINT32 dwlen_tomaxtail = 0u;
	UINT16 linkID_maxhead[AS_LINK_MAX] = { 0u };
	UINT16 linkID_minhead[AS_LINK_MAX] = { 0u };
	UINT16 linkID_maxtail[AS_LINK_MAX] = { 0u };
	UINT8 dirToMaxhead = 0u;
	UINT8 dirToMinhead = 0u;
	UINT8 dirToMaxTail = 0u;

	UINT8 dirLogic = 0u;

	dirLogic = ConvertDirectionToLogic(chTrainDir);
	wTrainIndex = GetTrainBufIndex(wTrainId);
	pMaxHead.Lnk = gstTrainInfo[wTrainIndex].wTrainMaxHeadLink;
	pMaxHead.Off = gstTrainInfo[wTrainIndex].dwTrainMaxHeadOffset;
	pMinHead.Lnk = gstTrainInfo[wTrainIndex].wTrainMinHeadLink;
	pMinHead.Off = gstTrainInfo[wTrainIndex].dwTrainMinHeadOffset;
	pMaxTail.Lnk = gstTrainInfo[wTrainIndex].wTrainMaxTailLink;
	pMaxTail.Off = gstTrainInfo[wTrainIndex].dwTrainMaxTailOffset;
	pMinTail.Lnk = gstTrainInfo[wTrainIndex].wTrainMinTailLink;
	pMinTail.Off = gstTrainInfo[wTrainIndex].dwTrainMinTailOffset;

	if ((0u == pMinTail.Lnk) && (UINT32_MAX == pMinTail.Off))
	{
		gstTrainInfo[wTrainIndex].chTrainDir_MaxHead = dirLogic;
		gstTrainInfo[wTrainIndex].chTrainDir_MinHead = dirLogic;
		gstTrainInfo[wTrainIndex].chTrainDir_MaxTail = dirLogic;
		chRetVal = CI_SUCCESS;
	}
	else
	{
		/*查车尾到最大安全前端的link序列*/
		dwlen_tomaxhead = dsuLenByPoint_GetDir(&pMinTail, &pMaxHead, &linknum_MaxHead, linkID_maxhead, &dirToMaxhead, &changerPNumtoMaxHead);
		dwlen_tominhead = dsuLenByPoint_GetDir(&pMinTail, &pMinHead, &linknum_MinHead, linkID_minhead, &dirToMinhead, &changerPNumtoMinHead);
		dwlen_tomaxtail = dsuLenByPoint_GetDir(&pMinTail, &pMaxTail, &linknum_MaxTail, linkID_maxtail, &dirToMaxTail, &changerPNumtoMaxTail);

		if ((TRAIN_SUM_MAX > wTrainIndex)
			&& (UINT32_MAX != dwlen_tomaxhead) && (UINT32_MAX != dwlen_tominhead) && (UINT32_MAX != dwlen_tomaxtail))
		{
			
			if ((0u != linknum_MaxHead) && (0u != linknum_MinHead) && (0u != linknum_MaxTail)
				&& (dirToMaxhead == dirLogic) && (dirToMinhead == dirLogic) && (dirToMaxTail == dirLogic))
			{
				if (0u == changerPNumtoMaxHead % 2u)
				{/*列车车尾到最大安全前端有偶数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MaxHead = dirLogic;
				}
				else
				{/*列车车尾到最大安全前端有奇数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MaxHead = ConvertTrainDir(dirLogic);
				}

				if (0u == changerPNumtoMinHead % 2u)
				{/*列车车尾到最小安全前端有偶数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MinHead = dirLogic;
				}
				else
				{/*列车车尾到最小安全前端有奇数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MinHead = ConvertTrainDir(dirLogic);
				}

				if (0u == changerPNumtoMaxTail % 2u)
				{/*列车车尾到最大安全后端有偶数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MaxTail = dirLogic;
				}
				else
				{/*列车车尾到最大安全前端有奇数个方向变化点*/
					gstTrainInfo[wTrainIndex].chTrainDir_MaxTail = ConvertTrainDir(dirLogic);
					
				}
				chRetVal = CI_SUCCESS;
			}
			else
			{
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
	}
	return chRetVal;
}


/*
* 功能描述： 校验列车小后方向是否符合其他三点计算
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainDir 列车运行方向（已获取的，最小后端指向车头）运营方向
* 返回值  ： CI_ERROR 设置失败  CI_SUCCESS 设置成功
*/
UINT8 CheckTrainDirToOtherPointDir(LOD_STRU pMaxHead,LOD_STRU pMinHead,LOD_STRU pMaxTail,LOD_STRU pMinTail, const UINT8 chTrainDir)
{
	UINT8 chRetVal = CI_ERROR;

	UINT16 linknum_MaxHead = 0u;
	UINT16 linknum_MinHead = 0u;
	UINT16 linknum_MaxTail = 0u;

	UINT8 changerPNumtoMaxHead = 0u;/*最小安全后端位置到最大安全前端位置经历的方向变化点*/
	UINT8 changerPNumtoMinHead = 0u;/*最小安全后端位置到最小安全前端位置经历的方向变化点*/
	UINT8 changerPNumtoMaxTail = 0u;/*最小安全后端位置到最大安全后端位置经历的方向变化点*/
	UINT32 dwlen_tomaxhead = 0u;
	UINT32 dwlen_tominhead = 0u;
	UINT32 dwlen_tomaxtail = 0u;
	UINT16 linkID_maxhead[AS_LINK_MAX] = { 0u };
	UINT16 linkID_minhead[AS_LINK_MAX] = { 0u };
	UINT16 linkID_maxtail[AS_LINK_MAX] = { 0u };

	UINT8 dirToMaxhead = 0u;
	UINT8 dirToMinhead = 0u;
	UINT8 dirToMaxTail = 0u;
	UINT8 dirLogic = 0u;
	dirLogic = ConvertDirectionToLogic(chTrainDir);

	if ((0u == pMinTail.Lnk) && (UINT32_MAX == pMinTail.Off))
	{
		chRetVal = CI_SUCCESS;
	}
	else
	{
		/*查车尾到最大安全前端的link序列*/
		dwlen_tomaxhead = dsuLenByPoint_GetDir(&pMinTail, &pMaxHead, &linknum_MaxHead, linkID_maxhead, &dirToMaxhead, &changerPNumtoMaxHead);
		dwlen_tominhead = dsuLenByPoint_GetDir(&pMinTail, &pMinHead, &linknum_MinHead, linkID_minhead, &dirToMinhead, &changerPNumtoMinHead);
		dwlen_tomaxtail = dsuLenByPoint_GetDir(&pMinTail, &pMaxTail, &linknum_MaxTail, linkID_maxtail, &dirToMaxTail, &changerPNumtoMaxTail);

		if ((UINT32_MAX != dwlen_tomaxhead) && (UINT32_MAX != dwlen_tominhead) && (UINT32_MAX != dwlen_tomaxtail)
			&& (dwlen_tomaxhead > dwlen_tominhead) && (dwlen_tomaxhead > dwlen_tomaxtail))
		{

			if ((0u != linknum_MaxHead) && (0u != linknum_MinHead) && (0u != linknum_MaxTail)
				&& (dirToMaxhead == dirLogic) && (dirToMinhead == dirLogic) && (dirToMaxTail == dirLogic))
			{
				/*列车大前 小前 大后 都在小后方向的延长线上*/
				chRetVal = CI_SUCCESS;
			}
			else
			{
				debug_infor_printf((const)"\nCheckTrainDirToOtherPointDir ERR\n");
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			debug_infor_printf((const)"\nCheckTrainDirToOtherPointDir ERR\n");
			chRetVal = CI_ERROR;
		}
	}
	
	return chRetVal;
}

/*
* 功能描述： 设置指定列车其它RC远程RM不允许原因
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chReson 列车其它RC远程RM不允许原因
* 返回值  ： 无
*/
void SetTrainOtherRcRrmReson(const UINT16 wTrainId, const UINT8 chReson)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) &&
		((TRAIN_RRM_RESON_02 == chReson) || (TRAIN_RRM_RESON_FF == chReson)
			|| ((TRAIN_RRM_RESON_05 <= chReson) && (TRAIN_RRM_RESON_0E >= chReson))
			|| ((TRAIN_RRM_RESON_15 <= chReson) && (TRAIN_RRM_RESON_17 >= chReson))))
	{
		gstTrainInfo[wBufIndex].chRrmResonFromOtherRc = chReson;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车RRM不允许原因
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车其它RC远程RM不允许原因
*/
UINT8 GetTrainOtherRcRrmReson(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_RRM_RESON_FF;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chRrmResonFromOtherRc;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车关联逻辑区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelLogSecNum	ABL列车关联逻辑区段数量	
* 返回值  ：无
*/
void SetTrainAblRelLogSecNum(const UINT16 wTrainId, const UINT8 chAblRelLogSecNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chAblRelLogSecNum = chAblRelLogSecNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车关联逻辑区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车关联逻辑区段数量
*/
UINT8 GetTrainAblRelLogSecNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chAblRelLogSecNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车关联逻辑区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelLogStru ablTrainRelLogData[TRAIN_ABL_LOGSEC_SUM]	列车ABL列车关联逻辑区段信息
* 返回值  ： void
*/
void SetTrainAblRelLogSecData(const UINT16 wTrainId, ABLTrainRelLogStru ablTrainRelLogData[TRAIN_ABL_LOGSEC_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelLogData,
			(UINT32)(sizeof(ABLTrainRelLogStru)*TRAIN_ABL_LOGSEC_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelLogStru)*TRAIN_ABL_LOGSEC_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelLogData,		/*设置指定列车ABL列车关联逻辑区段信息*/
			(UINT32)(sizeof(ABLTrainRelLogStru)*TRAIN_ABL_LOGSEC_SUM),
			ablTrainRelLogData, (UINT32)(sizeof(ABLTrainRelLogStru)*TRAIN_ABL_LOGSEC_SUM));
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车ABL列车关联逻辑区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车关联逻辑区段信息
*/
ABLTrainRelLogStru* GetTrainAblRelLogData(const UINT16 wTrainId)
{
	ABLTrainRelLogStru* chRetValablTrainRelLogData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelLogData = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelLogData;
	}
	else
	{
		chRetValablTrainRelLogData = NULL;
	}

	return chRetValablTrainRelLogData;
}


/*
* 功能描述： 设置指定列车ABL列车关联折返逻辑区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelReturnLogNum	ABL列车关联折返逻辑区段数量
* 返回值  ：无
*/
void SetTrainAblRelReturnLogNum(const UINT16 wTrainId, const UINT8 chAblRelReturnLogNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelReturnLogNum = chAblRelReturnLogNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车关联折返逻辑区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车关联折返逻辑区段数量
*/
UINT8 GetTrainAblRelReturnLogNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelReturnLogNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车关联折返逻辑区段ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			 UINT16 ablTrainRelReturnLogIdBuf[TRAIN_ABL_RETURNLOGSEC_SUM]	列车ABL列车关联折返逻辑区段ID
* 返回值  ： void
*/
void SetTrainAblRelReturnLogId(const UINT16 wTrainId, UINT16 ablTrainRelReturnLogIdBuf[TRAIN_ABL_RETURNLOGSEC_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.wABLRelReturnLogBuf,
			(UINT32)(sizeof(UINT16)*TRAIN_ABL_RETURNLOGSEC_SUM),
			0U, (UINT32)(sizeof(UINT16)*TRAIN_ABL_RETURNLOGSEC_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.wABLRelReturnLogBuf,		/*设置指定列车ABL列车关联折返逻辑区段ID*/
			(UINT32)(sizeof(UINT16)*TRAIN_ABL_RETURNLOGSEC_SUM),
			ablTrainRelReturnLogIdBuf, (UINT32)(sizeof(UINT16)*TRAIN_ABL_RETURNLOGSEC_SUM));
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车ABL列车关联折返逻辑区段ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车关联折返逻辑区段ID
*/
UINT16* GetTrainAblRelReturnLogId(const UINT16 wTrainId)
{
	UINT16* chTrainAblRelReturnLogBuf = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chTrainAblRelReturnLogBuf = gstTrainInfo[wBufIndex].strAblTrainNeedData.wABLRelReturnLogBuf;
	}
	else
	{
		chTrainAblRelReturnLogBuf = NULL;
	}

	return chTrainAblRelReturnLogBuf;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内PSD数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelPsdNum	ABL列车查询范围内PSD数量
* 返回值  ：无
*/
void SetTrainAblRelPsdNum(const UINT16 wTrainId, const UINT8 chAblRelPsdNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelPsdNum = chAblRelPsdNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内PSD数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内PSD数量
*/
UINT8 GetTrainAblRelPsdNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelPsdNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内PSD信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelPsdStru ablTrainRelPsdData[TRAIN_ABL_PSD_SUM]	列车ABL列车查询范围内PSD信息
* 返回值  ： void
*/
void SetTrainAblRelPsdData(const UINT16 wTrainId, ABLTrainRelPsdStru ablTrainRelPsdData[TRAIN_ABL_PSD_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelPsdData,
			(UINT32)(sizeof(ABLTrainRelPsdStru)*TRAIN_ABL_PSD_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelPsdStru)*TRAIN_ABL_PSD_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelPsdData,		/*设置指定列车ABL列车查询范围内PSD信息*/
			(UINT32)(sizeof(ABLTrainRelPsdStru)*TRAIN_ABL_PSD_SUM),
			ablTrainRelPsdData, (UINT32)(sizeof(ABLTrainRelPsdStru)*TRAIN_ABL_PSD_SUM));
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内PSD信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内PSD信息
*/
ABLTrainRelPsdStru* GetTrainAblRelPsdData(const UINT16 wTrainId)
{
	ABLTrainRelPsdStru* chRetValablTrainRelPsdData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelPsdData = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelPsdData;
	}
	else
	{
		chRetValablTrainRelPsdData = NULL;
	}

	return chRetValablTrainRelPsdData;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内ESB数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelEsbNum	ABL列车查询范围内ESB数量
* 返回值  ：无
*/
void SetTrainAblRelEsbNum(const UINT16 wTrainId, const UINT8 chAblRelEsbNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelEsbNum = chAblRelEsbNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内ESB数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内ESB数量
*/
UINT8 GetTrainAblRelEsbNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelEsbNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内ESBID
* 参数说明： const UINT16 wTrainId, 列车ID
*			 UINT16 ablTrainRelEsbIdBuf[TRAIN_ABL_ESB_SUM]	列车ABL列车查询范围内ESBID
* 返回值  ： void
*/
void SetTrainAblRelEsbId(const UINT16 wTrainId, ABLTrainRelEsbStru ablTrainRelEsbIdBuf[TRAIN_ABL_ESB_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelEsbData,
			(UINT32)(sizeof(ABLTrainRelEsbStru)*TRAIN_ABL_ESB_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelEsbStru)*TRAIN_ABL_ESB_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelEsbData,		/*设置指定列车ABL列车查询范围内ESBID(已激活)*/
			(UINT32)(sizeof(ABLTrainRelEsbStru)*TRAIN_ABL_ESB_SUM),
			ablTrainRelEsbIdBuf, (UINT32)(sizeof(ABLTrainRelEsbStru)*TRAIN_ABL_ESB_SUM));
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内ESBID(已激活)
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内ESBI数据(已激活)
*/
ABLTrainRelEsbStru* GetTrainAblRelEsbData(const UINT16 wTrainId)
{
	ABLTrainRelEsbStru* chTrainAblRelEsbIdBuf = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chTrainAblRelEsbIdBuf = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelEsbData;
	}
	else
	{
		chTrainAblRelEsbIdBuf = NULL;
	}

	return chTrainAblRelEsbIdBuf;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内道岔数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelSwitchNum	ABL列车查询范围内道岔数量
* 返回值  ：无
*/
void SetTrainAblRelSwitchNum(const UINT16 wTrainId, const UINT8 chAblRelSwitchNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelSwitchNum = chAblRelSwitchNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内道岔数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内道岔数量
*/
UINT8 GetTrainAblRelSwitchNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelSwitchNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内道岔信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelSwitchStru ablTrainRelSwitchData[TRAIN_ABL_SWITCH_SUM]	列车ABL列车查询范围内道岔信息
* 返回值  ： void
*/
void SetTrainAblRelSwitchData(const UINT16 wTrainId, ABLTrainRelSwitchStru ablTrainRelSwitchData[TRAIN_ABL_SWITCH_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelSwitchData,
			(UINT32)(sizeof(ABLTrainRelSwitchStru)*TRAIN_ABL_SWITCH_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelSwitchStru)*TRAIN_ABL_SWITCH_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelSwitchData,		/*设置指定列车ABL列车查询范围内道岔信息*/
			(UINT32)(sizeof(ABLTrainRelSwitchStru)*TRAIN_ABL_SWITCH_SUM),
			ablTrainRelSwitchData, (UINT32)(sizeof(ABLTrainRelSwitchStru)*TRAIN_ABL_SWITCH_SUM));
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内道岔信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内道岔信息
*/
ABLTrainRelSwitchStru* GetTrainAblRelSwitchData(const UINT16 wTrainId)
{
	ABLTrainRelSwitchStru* chRetValablTrainRelSwitchData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelSwitchData = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelSwitchData;
	}
	else
	{
		chRetValablTrainRelSwitchData = NULL;
	}

	return chRetValablTrainRelSwitchData;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内保护区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelProSecNum	ABL列车查询范围内保护区段数量
* 返回值  ：无
*/
void SetTrainAblRelProSecNum(const UINT16 wTrainId, const UINT8 chAblRelProSecNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelProSecNum = chAblRelProSecNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内保护区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内保护区段数量
*/
UINT8 GetTrainAblRelProSecNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelProSecNum;
	}
	else
	{
		chRetVal = 0U;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内保护区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelProSecStru ablTrainRelProSecData[TRAIN_ABL_PROSEC_SUM]	列车ABL列车查询范围内保护区段信息
* 返回值  ： void
*/
void SetTrainAblRelProSecData(const UINT16 wTrainId, ABLTrainRelProSecStru ablTrainRelProSecData[TRAIN_ABL_PROSEC_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelProSecData,
			(UINT32)(sizeof(ABLTrainRelProSecStru)*TRAIN_ABL_PROSEC_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelProSecStru)*TRAIN_ABL_PROSEC_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelProSecData,		/*设置指定列车ABL列车查询范围内保护区段信息*/
			(UINT32)(sizeof(ABLTrainRelProSecStru)*TRAIN_ABL_PROSEC_SUM),
			ablTrainRelProSecData, (UINT32)(sizeof(ABLTrainRelProSecStru)*TRAIN_ABL_PROSEC_SUM));
	}
	else
	{
		; /*不设置*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内保护区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内保护区段信息
*/
ABLTrainRelProSecStru* GetTrainAblRelProSecData(const UINT16 wTrainId)
{
	ABLTrainRelProSecStru* chRetValablTrainRelProSecData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelProSecData = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelProSecData;
	}
	else
	{
		chRetValablTrainRelProSecData = NULL;
	}

	return chRetValablTrainRelProSecData;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内限速物理区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblRelXianSuNum	ABL列车查询范围内限速物理区段数量
* 返回值  ：无
*/
void SetTrainAblRelXianSuNum(const UINT16 wTrainId, const UINT8 chAblRelXianSuNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelXianSuNum = chAblRelXianSuNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内限速物理区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内限速物理区段数量
*/
UINT8 GetTrainAblRelXianSuNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chABLRelXianSuNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车查询范围内限速物理区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelXianSuStru ablTrainRelXiansuData	列车ABL列车查询范围内限速物理区段信息
* 返回值  ： void
*/
void SetTrainAblRelXiansuData(const UINT16 wTrainId, ABLTrainRelXianSuStru ablTrainRelXiansuData)
{
	UINT16 bufIndex = 0U;  /*数组下标*/
	UINT8 chXiansuPhySecNum = 0U;/*限速物理区段数目*/

	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		chXiansuPhySecNum = GetTrainAblRelXianSuNum(wTrainId);
		if (TRAIN_ABL_XIANSUSEC_SUM > chXiansuPhySecNum)
		{
			gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelXiansuData[chXiansuPhySecNum] = ablTrainRelXiansuData;
			gstTrainInfo[bufIndex].strAblTrainNeedData.chABLRelXianSuNum = chXiansuPhySecNum + 1U;
		}
		else
		{
			; /*非法不存储*/
		}
	}
	else
	{

	}
}

/*
* 功能描述： 清空指定列车ABL列车查询范围内限速物理区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： void
*/
void ClearTrainAblRelXiansuData(const UINT16 wTrainId)
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelXiansuData,
			(UINT32)(sizeof(ABLTrainRelXianSuStru) * TRAIN_ABL_XIANSUSEC_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelXianSuStru) * TRAIN_ABL_XIANSUSEC_SUM));			/*清空*/

		gstTrainInfo[bufIndex].strAblTrainNeedData.chABLRelXianSuNum = 0U;
	}
	else
	{
		; /*不设置*/
	}
}

/*
* 功能描述： 设置指定列车ABL列车指定限速物理区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chIndex 指定索引
*			 ABLTrainRelXianSuStru ablTrainRelXiansuData	列车ABL列车查询范围内限速物理区段信息
* 返回值  ： void
*/
void SetTrainAblRelIndexXiansuData(const UINT16 wTrainId,const UINT8 chIndex,ABLTrainRelXianSuStru ablTrainRelXiansuData)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		if (TRAIN_ABL_XIANSUSEC_SUM > chIndex)
		{
			gstTrainInfo[bufIndex].strAblTrainNeedData.ablTrainRelXiansuData[chIndex] = ablTrainRelXiansuData;
		}
		else
		{
			; /*非法不存储*/
		}
	}
	else
	{

	}
}

/*
* 功能描述： 获取指定列车ABL列车查询范围内限速物理区段信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车查询范围内限速物理区段信息
*/
ABLTrainRelXianSuStru* GetTrainAblRelXiansuData(const UINT16 wTrainId)
{
	ABLTrainRelXianSuStru* chRetValablTrainRelXiansuData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelXiansuData = gstTrainInfo[wBufIndex].strAblTrainNeedData.ablTrainRelXiansuData;
	}
	else
	{
		chRetValablTrainRelXiansuData = NULL;
	}

	return chRetValablTrainRelXiansuData;
}

/*
* 功能描述： 设置指定列车ABL车脚下到前方所有进路数量
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chAblAllRouteNum	ABL车脚下到前方所有进路数量
* 返回值  ：无
*/
void SetTrainAblAllRouteNum(const UINT16 wTrainId, const UINT8 chAblAllRouteNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.chAblAllRouteNum = chAblAllRouteNum;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定列车ABL车脚下到前方所有进路数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL车脚下到前方所有进路数量
*/
UINT8 GetTrainAblAllRouteNum(const UINT16 wTrainId)
{
	UINT8 chRetVal = UINT8_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.chAblAllRouteNum;
	}
	else
	{
		chRetVal = UINT8_MAX;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车ABL列车脚下到前方所有进路信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 ABLTrainRelAllRouteStru ablTrainRelAllRouteData[TRAIN_ABL_ALLROUTE_SUM]	列车ABL列车脚下到前方所有进路信息
* 返回值  ： void
*/
void SetTrainAblRelAllRouteData(const UINT16 wTrainId, ABLTrainRelAllRouteStru ablTrainRelAllRouteData[TRAIN_ABL_ALLROUTE_SUM])
{
	UINT16 bufIndex = 0u;  /*数组下标*/
	bufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > bufIndex)
	{
		(void)CommonMemSet(gstTrainInfo[bufIndex].strAblTrainNeedData.wAblAllRouteData,
			(UINT32)(sizeof(ABLTrainRelAllRouteStru)*TRAIN_ABL_ALLROUTE_SUM),
			0U, (UINT32)(sizeof(ABLTrainRelAllRouteStru)*TRAIN_ABL_ALLROUTE_SUM));			/*先出清，防止脏数据*/

		(void)CommonMemCpy(gstTrainInfo[bufIndex].strAblTrainNeedData.wAblAllRouteData,		/*设置指定列车ABL列车脚下到前方所有进路信息*/
			(UINT32)(sizeof(ABLTrainRelAllRouteStru)*TRAIN_ABL_ALLROUTE_SUM),
			ablTrainRelAllRouteData, (UINT32)(sizeof(ABLTrainRelAllRouteStru)*TRAIN_ABL_ALLROUTE_SUM));
	}
	else
	{

	}
}

/*
* 功能描述： 获取指定列车ABL列车脚下到前方所有进路信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：指定列车ABL列车脚下到前方所有进路信息
*/
ABLTrainRelAllRouteStru* GetTrainAblRelAllRouteData(const UINT16 wTrainId)
{
	ABLTrainRelAllRouteStru* chRetValablTrainRelAllRouteData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetValablTrainRelAllRouteData = gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblAllRouteData;
	}
	else
	{
		chRetValablTrainRelAllRouteData = NULL;
	}

	return chRetValablTrainRelAllRouteData;
}

/*
* 功能描述： 设置指定列车NVRAM位置标识
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chState NVRAM位置标识
* 返回值  ： 无
* BY CGH 20240417
*/
void SetTrainNvramPosFlag(const UINT16 wTrainId, const UINT8 chState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wBufIndex) && ((TRAIN_NVRAM_POS_FLAG_YES == chState) || (TRAIN_NVRAM_POS_FLAG_NO == chState)))
	{
		gstTrainInfo[wBufIndex].chNvramPosFlag = chState;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车NVRAM位置标识
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车NVRAM位置标识
* BY CGH 20240417
*/
UINT8 GetTrainNvramPosFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_NVRAM_POS_FLAG_YES;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chNvramPosFlag;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车前车位置信息
* 参数说明： const UINT16 wTrainId, 列车ID
*			 HeadTrainLocStru strHeadTrainLocData  前车位置信息数据
* 返回值  ： void
* by cgh 20240606
*/
void SetTrainHeadTrainLocData(const UINT16 wTrainId,HeadTrainLocStru strHeadTrainLocData)
{
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetTrainBufIndex(wTrainId);

	if ((0U < bufIndex) && (TRAIN_SUM_MAX > bufIndex))
	{
		(void)CommonMemCpy((void*)&gstTrainInfo[bufIndex].strHeadTrainLocData, (UINT32)sizeof(HeadTrainLocStru), (void*)&strHeadTrainLocData, (UINT32)sizeof(HeadTrainLocStru));
	}
	else
	{
		; /*不设置*/
	}
}

/*
* 功能描述： 获取指定列车前车位置信息
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： NULL 获取失败
*            非NULL 前车位置信息数据
* by cgh 20240606
*/
HeadTrainLocStru GetTrainHeadTrainLocData(const UINT16 wTrainId)
{
	HeadTrainLocStru strRetVal = { 0U };
	UINT16 bufIndex = 0U;  /*数组下标*/

	bufIndex = GetTrainBufIndex(wTrainId);

	if ((0U < bufIndex) && (TRAIN_SUM_MAX > bufIndex))
	{
		(void)CommonMemCpy((void*)&strRetVal, (UINT32)sizeof(HeadTrainLocStru), (void*)&gstTrainInfo[bufIndex].strHeadTrainLocData, (UINT32)sizeof(HeadTrainLocStru));
	}
	else
	{
		; /*不设置*/
	}

	return strRetVal;
}

/*
* 功能描述： 获取列车ITE汇报的数据
* 参数说明： const UINT16 wTrainId, 列车ID
*			 HeadTrainLocStru strHeadTrainLocData  ITE汇报的数据
* 返回值  ： void
* by cgh 20240606
*/
TrainIteDataStruct* GetTrainIteData(const UINT16 wTrainId)
{
	TrainIteDataStruct* tempTrainIteData = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		tempTrainIteData = gstTrainInfo[wBufIndex].szTrainIteData;
	}
	else
	{
		tempTrainIteData = NULL;
	}

	return tempTrainIteData;
}

/*
* 功能描述：设置列车ITE数据——车头所处linkID
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT16 wHeadLinkId 列车车头所处linkID
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainHeadLinkId(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT16 wHeadLinkId)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].wTrainHeadLinkId = wHeadLinkId;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——车头所处link偏移量
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT32 dwHeadLinkOffset 列车车头所处link偏移量
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainHeadLinkOffset(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT32 dwHeadLinkOffset)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].dwTrainHeadLinkOffset = dwHeadLinkOffset;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——车尾所处linkID
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT16 wTailLinkId 列车车尾所处linkID
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainTailLinkId(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT16 wTailLinkId)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].wTrainTailLinkId = wTailLinkId;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——车尾所处link偏移量
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT32 dwTailLinkOffset 列车车尾所处link偏移量
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainTailLinkOffset(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT32 dwTailLinkOffset)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].dwTrainTailLinkOffset = dwTailLinkOffset;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——列车方向
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT8 cTrainDir 列车方向
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainDir(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT8 cTrainDir)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].cTrainDir = cTrainDir;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——位置向前方向误差
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT16 wForWardOffset 位置向前方向误差
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainForWardOffset(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT16 wForWardOffset)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].wForWardOffset = wForWardOffset;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述：设置列车ITE数据——位置向后方向误差
* 参数说明：const UINT16 wTrainId 列车ID
*			const UINT16 wIteLogId ITE逻辑ID
*           const UINT16 wBackOffset 位置向后方向误差
* 返 回 值：无
* Created By LQ 2024.06.06
*/
void SetIteTrainBackOffset(const UINT16 wTrainId, const UINT16 wIteLogId, const UINT16 wBackOffset)
{
	UINT16 wTrainIndex = 0U;  /*列车ID索引*/
	UINT16 wIteIndex = 0U;  /*ITEID索引*/

	wTrainIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wTrainIndex) && (0U < wIteLogId) && (TRAIN_INC_ITE_SUM_MAX >= wIteLogId))
	{
		wIteIndex = wIteLogId - 1U;
		gstTrainInfo[wTrainIndex].szTrainIteData[wIteIndex].wBackOffset = wBackOffset;
	}
	else
	{
		/*入参非法，不处理*/
	}
}

/*
* 功能描述： 设置指定列车前方信号机ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			const UINT16 wTrainSigId 前方信号机ID
* 返回值  ： 无
* BY CGH 20240710
*/
void SetTrainHeadSigId(const UINT16 wTrainId, const UINT16 wTrainSigId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wTrainHeadSigId = wTrainSigId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车前方信号机ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车前方信号机ID
* BY CGH 20240710
*/
UINT16 GetTrainHeadSigId(const UINT16 wTrainId)
{
	UINT16 wRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainHeadSigId;
	}
	else
	{
		;
	}

	return wRetVal;
}

/*
* 功能描述： 设置指定列车车身所处位置反向进路标志
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chFlag 列车车身所处位置反向进路标志
* 返回值  ： 无
* BY CGH 20240711
*/
void SetTrainLocReverseRouteFlag(const UINT16 wTrainId, const UINT8 chFlag)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wBufIndex) && ((TRAIN_LOC_REV_ROUTE_FLAG_NONE == chFlag)
		|| (TRAIN_LOC_REV_ROUTE_FLAG_NO == chFlag) || (TRAIN_LOC_REV_ROUTE_FLAG_YES == chFlag)))
	{
		gstTrainInfo[wBufIndex].chTrainLocReverseRouteFlag = chFlag;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车车身所处位置反向进路标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车车身所处位置反向进路标志
* BY CGH 20240711
*/
UINT8 GetTrainLocReverseRouteFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_LOC_REV_ROUTE_FLAG_YES;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chTrainLocReverseRouteFlag;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定Abl列车最小安全后端指向车头的运行方向
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chTrainDir 列车运行方向
* 返回值 : 无
* by cgh 20240711
*/
void SetAblTrainDir(const UINT16 wTrainId, const UINT8 chTrainDir)
{
	UINT16 wBufIndex = 0U;
	UINT8 chDir = 0u;
	UINT8 chLinkLogicDirUpAndDown = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_DIR_UP == chTrainDir) || (TRAIN_DIR_DOWN == chTrainDir))
		{
			chLinkLogicDirUpAndDown = GetLinkLogicDirUpAndDown();

			if (chLinkLogicDirUpAndDown == chTrainDir)
			{
				chDir = DIR_CONVERT;
			}
			else
			{
				chDir = DIR_SAME;
			}

			/*设置列车最小安全后端的运行方向*/
			gstTrainInfo[wBufIndex].chAblTrainDir = chDir;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定Abl列车最大安全前端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainHeadLinkId 列车最大安全前端Lk
* 返回值 : 无
* by cgh 20240711
*/
void SetAblTrainMaxHeadLink(const UINT16 wTrainId, const UINT16 wTrainHeadLinkId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainHeadLinkId)
		{
			gstTrainInfo[wBufIndex].wAblTrainMaxHeadLink = wTrainHeadLinkId;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定Abl列车最大安全前端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainHeadOff 列车安全前端Off
* 返回值 : 无
* by cgh 20240711
*/
void SetAblTrainMaxHeadOffset(const UINT16 wTrainId, const UINT32 dwTrainHeadOff)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwAblTrainMaxHeadOffset = dwTrainHeadOff;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定Abl列车最小安全后端所处LinkId
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 wTrainTailLinkId 列车安全后端所处Lk
* 返回值 : 无
* by cgh 20240711
*/
void SetAblTrainMinTailLink(const UINT16 wTrainId, const UINT16 wTrainTailLinkId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (UINT16_MAX != wTrainTailLinkId)
		{
			gstTrainInfo[wBufIndex].wAblTrainMinTailLink = wTrainTailLinkId;
		}
		else
		{
			;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定Abl列车最小安全后端所处LinkId Off
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 dwTrainTailOff 列车安全后端Off
* 返回值 : 无
* by cgh 20240711
*/
void SetAblTrainMinTailOffset(const UINT16 wTrainId, const UINT32 dwTrainTailOff)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].dwAblTrainMinTailOffset = dwTrainTailOff;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定Abl列车运行方向（最小安全后端）
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0x55: 与逻辑方向同向
*			 0xAA: 与逻辑方向反向
*			 0xFF: 无效方向
* by cgh 20240711
*/
UINT8 GetAblTrainDir(const UINT16 wTrainId)
{
	UINT8 chRetVal = DIR_INVALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chAblTrainDir;
	}
	else
	{
		chRetVal = DIR_INVALID;
	}

	return chRetVal;
}

/*
* 功能描述： 获取指定Abl列车最大安全前端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* by cgh 20240711
*/
UINT16 GetAblTrainMaxHeadLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wAblTrainMaxHeadLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定Abl列车最小安全后端linkId
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 linkID
* by cgh 20240711
*/
UINT16 GetAblTrainMinTailLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wAblTrainMinTailLink;
	}
	else
	{
		wRetVal = CI_ERROR;
	}

	return wRetVal;
}

/*
* 功能描述： 获取指定Abl列车最大安全前端偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* by cgh 20240711
*/
UINT32 GetAblTrainMaxHeadOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwAblTrainMaxHeadOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 获取指定Abl列车最小安全后偏移量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0: 获取数据失败
*			 link偏移量
* by cgh 20240711
*/
UINT32 GetAblTrainMinTailOffset(const UINT16 wTrainId)
{
	UINT32 dwRetVal = UINT32_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwAblTrainMinTailOffset;
	}
	else
	{
		dwRetVal = UINT32_MAX;
	}

	return dwRetVal;
}

/*
* 功能描述： 设置指定列车前车ID
* 参数说明： const UINT16 wTrainId, 列车ID
*			const UINT16 wHeadTrainId 前车ID
* 返回值  ： 无
* BY CGH 20240710
*/
void SetTrainHeadTrainId(const UINT16 wTrainId, const UINT16 wHeadTrainId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].wTrainHeadTrainId = wHeadTrainId;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车前车ID
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车前车ID
* BY CGH 20240710
*/
UINT16 GetTrainHeadTrainId(const UINT16 wTrainId)
{
	UINT16 wRetVal = TRAIN_ID_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainHeadTrainId;
	}
	else
	{
		;
	}

	return wRetVal;
}

/*
* 功能描述：检查列车是否存在CT包络
* 参数说明：const UINT16 wTrainId 列车ID（不带0x14）
* 返 回 值：CI_SUCCESS 1 存在CT包络
*           CI_ERROR 0 不存在CT包络
* Created By LQ 2024.07.25
*/
UINT8 CheckTrainRelCtEnvelope(const UINT16 wTrainId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 cEnvelopeNum = 0U;  /*列车关联的包络数量*/
	UINT16 szEnvelopeId[TRAIN_REL_ENVELOPE_SUM_MAX] = { 0U };  /*列车关联的包络ID*/
	const EnvelopeStruct* pstrEnvelop = NULL;  /*列车关联的包络结构体*/
	
	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		cEnvelopeNum = elm_GetTrainRelELM(wTrainId, szEnvelopeId);
		if (1U == cEnvelopeNum)
		{
			pstrEnvelop = elm_GetEnvelopeInfoByID(szEnvelopeId[0U]);
			if (NULL != pstrEnvelop)
			{
				if (TYPE_CT_ENVELOPE == pstrEnvelop->envelopeType)
				{
					cRetVal = CI_SUCCESS;  /*存在唯一CT包络，返回成功*/
				}
				else
				{
					/*无CT包络，返回失败*/
				}
			}
			else
			{
				/*获取包络失败，返回失败*/
			}
		}
		else
		{
			/*包络不唯一，返回失败*/
		}
	}
	else
	{
		/*列车ID非法，返回失败*/
	}

	return cRetVal;
}


/*
* 功能描述： 设置指定ABL列车车头所在逻辑区段
* 参数说明： const UINT16 wTrainId, 列车ID
*			const UINT16 logsecId  逻辑区段ID
* 返回值  ： void
*/
void SetTrainAblMaxHeadLogId(const UINT16 wTrainId, const UINT16 logsecId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && (0U != logsecId) && (LOGIC_SECTION_SUM_MAX > logsecId))
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblMaxHeadLogSecId = logsecId;
	}
	else
	{
		;		/*不处理*/
	}
}

/*
* 功能描述： 获取指定ABL列车车头所在逻辑区段
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0：获取失败
*           >0：逻辑区段ID
*/
UINT16 GetTrainAblMaxHeadLogId(const UINT16 wTrainId)
{
	UINT16 retVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex) 
	{
		retVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblMaxHeadLogSecId;
	}
	else
	{
		;		/*不处理*/
	}
	return retVal;

}



/*
* 功能描述： 设置指定列车ABL列车脚下逻辑区段数据
* 参数说明： const UINT16 wTrainId, 列车ID
*           const UINT8 chAblRelXianSuNum	ABL列车脚下逻辑区段数量
*			const UINT16* chAblOcculogIdbuff	ABL列车脚下逻辑区段数组
* 返回值  ：无
*/
void SetTrainAblOcculogData(const UINT16 wTrainId, const UINT8 chAblOcculogNum,const UINT16* chAblOcculogIdbuff)
{
	UINT16 wBufIndex = 0U;
	UINT8 i = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wBufIndex) && (NULL != chAblOcculogIdbuff) && (TRAIN_ABL_LOGSEC_SUM > chAblOcculogNum))
	{
		gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblOccuLogSeNum = chAblOcculogNum;
		for (i = 0U; i < chAblOcculogNum; i++)
		{
			gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblOccuLogSecIdBuff[i] = chAblOcculogIdbuff[i];
		}

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

/*
* 功能描述： 获取指定ABL列车脚下逻辑区段数量
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0：获取失败
*           >0：逻辑区段数量
*/
UINT8 GetTrainAblOcculogIdSum(const UINT16 wTrainId)
{
	UINT8 retVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		retVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblOccuLogSeNum;
	}
	else
	{
		;		/*不处理*/
	}
	return retVal;

}


/*
* 功能描述： 获取指定ABL列车脚下逻辑区段ID数组
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： NULL：获取失败
*           !=NULL：逻辑区段ID数组
*/
UINT16* GetTrainAblOcculogIdBuff(const UINT16 wTrainId)
{
	UINT16* retVal = NULL;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		retVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblOccuLogSecIdBuff;
	}
	else
	{
		;		/*不处理*/
	}
	return retVal;

}


/*
* 功能描述： 设置指定ABL列车最远端空闲所在逻辑区段
* 参数说明： const UINT16 wTrainId, 列车ID
*			const UINT16 logsecId  逻辑区段ID
* 返回值  ： void
*/
void SetTrainAblNoOccuFarLogId(const UINT16 wTrainId, const UINT16 logsecId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((0U != logsecId) && (LOGIC_SECTION_SUM_MAX > logsecId))
		{
			gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblNoOccuFarLogId = logsecId;
		}
		else if (UINT16_MAX == logsecId)
		{
			gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblNoOccuFarLogId = UINT16_MAX;
		}
		else
		{
			gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblNoOccuFarLogId = 0U;
		}

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

/*
* 功能描述： 获取指定ABL列车最远端空闲所在逻辑区段
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 0：获取失败
*           >0：逻辑区段ID
*/
UINT16 GetTrainAblNoOccuFarLogId(const UINT16 wTrainId)
{
	UINT16 retVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		retVal = gstTrainInfo[wBufIndex].strAblTrainNeedData.wAblNoOccuFarLogId;
	}
	else
	{
		;		/*不处理*/
	}
	return retVal;

}

/*
* 功能描述： 设置指定列车虚拟前筛通过标志
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chFlag 列车虚拟前筛通过标志
* 返回值  ： 无
* BY CGH 20240815
*/
void SetTrainVirHeadScreenPassFlag(const UINT16 wTrainId, const UINT8 chFlag)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wBufIndex) && ((TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chFlag) || (TRAIN_VIR_SCREEN_PASS_FLAG_INVALID == chFlag)))
	{
		gstTrainInfo[wBufIndex].chVirHeadScreenPassFlag = chFlag;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车虚拟前筛通过标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车虚拟前筛通过标志
* BY CGH 20240815
*/
UINT8 GetTrainVirHeadScreenPassFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chVirHeadScreenPassFlag;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车虚拟后筛通过标志
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT8 chFlag 列车虚拟后筛通过标志
* 返回值  ： 无
* BY CGH 20240815
*/
void SetTrainVirTailScreenPassFlag(const UINT16 wTrainId, const UINT8 chFlag)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if ((TRAIN_SUM_MAX > wBufIndex) && ((TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chFlag) || (TRAIN_VIR_SCREEN_PASS_FLAG_INVALID == chFlag)))
	{
		gstTrainInfo[wBufIndex].chVirTailScreenPassFlag = chFlag;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车虚拟后筛通过标志
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车虚拟后筛通过标志
* BY CGH 20240815
*/
UINT8 GetTrainVirTailScreenPassFlag(const UINT16 wTrainId)
{
	UINT8 chRetVal = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].chVirTailScreenPassFlag;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车驶入列检库所在LINK
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT16 列车驶入列检库所在LINK
* 返回值  ： 无
* BY CGH 20240815
*/
void SetTrainEnterLjkLinkId(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (0U != wLinkId)
		{
			if (0U == gstTrainInfo[wBufIndex].wEnterLjkLinkId)
			{
				gstTrainInfo[wBufIndex].wEnterLjkLinkId = wLinkId;
			}
			else
			{
				; /*已经有不再更新设置*/
			}
		}
		else
		{
			gstTrainInfo[wBufIndex].wEnterLjkLinkId = 0U;
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 获取指定列车驶入列检库所在LINK
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车驶入列检库所在LINK
* BY CGH 20240815
*/
UINT16 GetTrainEnterLjkLinkId(const UINT16 wTrainId)
{
	UINT16 chRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		chRetVal = gstTrainInfo[wBufIndex].wEnterLjkLinkId;
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 设置指定列车完全驶入列检库周期号
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwCycNum 列车完全驶入列检库周期号
* 返回值  ： 无
* BY CGH 20240815
*/
void SetTrainFullEnterLjkCycNum(const UINT16 wTrainId, const UINT32 dwCycNum)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (0U != dwCycNum)
		{
			if (0U == gstTrainInfo[wBufIndex].dwTrainFullEnterLjkCycNum)
			{
				gstTrainInfo[wBufIndex].dwTrainFullEnterLjkCycNum = dwCycNum;
			}
			else
			{
				; /*不等于0说明已经设置过*/
			}
		}
		else
		{
			gstTrainInfo[wBufIndex].dwTrainFullEnterLjkCycNum = 0U;
		}
	}
	else
	{
		; 
	}
}

/*
* 功能描述： 获取指定列车完全驶入列检库周期号
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： 列车完全驶入列检库周期号
* BY CGH 20240815
*/
UINT32 GetTrainFullEnterLjkCycNum(const UINT16 wTrainId)
{
	UINT32 dwRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwTrainFullEnterLjkCycNum;
	}
	else
	{
		;
	}

	return dwRetVal;
}

/*
* 功能描述：设置指定列车位置监督状态
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT8 cMonitorState 监督状态
* 返 回 值：无
* Created By LQ 2024.08.15
*/
void SetTrainPosMonitorState(const UINT16 wTrainId, const UINT8 cMonitorState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_POS_MONITOR_VALID == cMonitorState) || (TRAIN_POS_MONITOR_INVALID == cMonitorState) || (TRAIN_POS_MONITOR_DIFF == cMonitorState))
		{
			gstTrainInfo[wBufIndex].chTrainPosMonitorState = cMonitorState;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车位置监督状态
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0x55 位置监督无效
*           0xAA 位置监督有效
*           0xCC 位置监督不一致
* Created By LQ 2024.08.15
*/
UINT8 GetTrainPosMonitorState(const UINT16 wTrainId)
{
	UINT8 cRetVal = TRAIN_POS_MONITOR_INVALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		cRetVal = gstTrainInfo[wBufIndex].chTrainPosMonitorState;
	}
	else
	{
		/*返回默认值*/
	}

	return cRetVal;
}

/*
* 功能描述：设置指定列车位置监督所处link
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT16 wLinkId link ID
* 返 回 值：无
* Created By LQ 2024.08.15
*/
void SetTrainPosMonitorInLink(const UINT16 wTrainId, const UINT16 wLinkId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (LINK_SUM_MAX > wLinkId)
		{
			gstTrainInfo[wBufIndex].wTrainPosMonitorInLink = wLinkId;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车位置监督所处link
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：1300 获取失败
*           其它 位置监督所处link
* Created By LQ 2024.08.15
*/
UINT16 GetTrainPosMonitorInLink(const UINT16 wTrainId)
{
	UINT16 wRetVal = LINK_SUM_MAX;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		wRetVal = gstTrainInfo[wBufIndex].wTrainPosMonitorInLink;
	}
	else
	{
		/*返回默认值*/
	}

	return wRetVal;
}

/*
* 功能描述：列车位置监督处理
* 参数说明：无
* 返 回 值：无
* Created By LQ 2024.08.15
*/
void TrainPosMonitorProc(void)
{
	UINT8 cTrainIndex = 0U;
	UINT16 wTrainId = 0U;
	UINT8 cLocalCiType = 0U;
	UINT16 wTrainPosMonitorInLink = 0U;  /*列车位置监督状态有效时所处link*/
	UINT8 cFuncRet = CI_ERROR;
	UINT16 wLinkRelPhySecId = 0U;  /*link关联的物理区段*/
	UINT16* pPhySecIncAxleSecId = NULL;  /*物理区段包含的计轴区段*/
	UINT8 cPreMonitorState = TRAIN_POS_MONITOR_INVALID;  /*上一周期列车位置监督状态*/
	UINT8 cMonitorFailState = TRAIN_POS_MONITOR_INVALID;  /*检查失败后需要设置的监督状态*/
	UINT8 chAgTrainLeaveAgCheck = 0U;
	UINT8 chNvramFlag = 0U;

	for (cTrainIndex = 0U; cTrainIndex < TRAIN_SUM_MAX; cTrainIndex++)
	{
		wTrainId = GetTrainId(cTrainIndex);

		/*根据控区类型，进行列车位置监督*/
		cLocalCiType = GetLocalCiType();
		if ((CI_TYPE_ZX == cLocalCiType) || (CI_TYPE_SCX == cLocalCiType))
		{
			/****** 检查列车位置监督状态是否有效 *******/
			cFuncRet = ZXorSCXTrainPosMonitorCheck(wTrainId, &wTrainPosMonitorInLink, &cMonitorFailState);
		}
		else
		{
			/****** 检查列车位置监督状态是否有效 *******/
			cFuncRet = CLDTrainPosMonitorCheck(wTrainId, &wTrainPosMonitorInLink, &cMonitorFailState);
		}

		/****** 根据检查结果设置监督状态 *******/
		if (CI_SUCCESS == cFuncRet)
		{
			/*1.设置计轴关联的位置监督有效的列车ID*/
			wLinkRelPhySecId = GetLinkRelatedPhySec(wTrainPosMonitorInLink);
			pPhySecIncAxleSecId = GetPAxisSectionIdBuf(wLinkRelPhySecId);
			if (NULL != pPhySecIncAxleSecId)
			{
				SetAxisPosMonitorTrainId(pPhySecIncAxleSecId[0], wTrainId);  /*休眠唤醒轨为无岔区段，取首个计轴区段设置*/
			}
			else
			{
				/*获取失败，不处理*/
			}

			/*2.设置列车位置监督标志有效*/
			SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_VALID);
			SetTrainPosMonitorInLink(wTrainId, wTrainPosMonitorInLink);
		}
		else
		{
			cPreMonitorState = GetTrainPosMonitorState(wTrainId);  /*获取上一周期列车位置监督状态*/

			/*1.清除计轴关联的位置监督有效的列车ID（需在更新link前获取此时位置监督有效的link）*/
			wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/
			wLinkRelPhySecId = GetLinkRelatedPhySec(wTrainPosMonitorInLink);
			pPhySecIncAxleSecId = GetPAxisSectionIdBuf(wLinkRelPhySecId);
			if (NULL != pPhySecIncAxleSecId)
			{
				SetAxisPosMonitorTrainId(pPhySecIncAxleSecId[0], 0U);  /*休眠唤醒轨为无岔区段，取首个计轴区段设置*/
			}
			else
			{
				/*未设置列车ID，不处理*/
			}
			chNvramFlag = GetTrainNvramPosFlag(wTrainId);
			/*2.设置列车位置监督标志*/
			if (((TRAIN_POS_MONITOR_DIFF == cMonitorFailState) || (TRAIN_POS_MONITOR_DIFF == cPreMonitorState)) 
				&& (TRAIN_NVRAM_POS_FLAG_NO != chNvramFlag))
			{
				SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_DIFF);  /*列车完全不在监督link或上一周期监督状态是位置不一致，设置监督位置不一致*/
			}
			else
			{
				SetTrainPosMonitorState(wTrainId, TRAIN_POS_MONITOR_INVALID);  /*列车完全在监督link，设置监督无效*/
			}

			SetTrainPosMonitorInLink(wTrainId, 0U);  /*清除监督所处link*/

			/*3.清除列车前后端虚拟筛选标志*/
			if (TRAIN_POS_MONITOR_VALID == cPreMonitorState)
			{
				chAgTrainLeaveAgCheck = AgTrainLeaveAgCheck(wTrainPosMonitorInLink);
				if (CI_ERROR == chAgTrainLeaveAgCheck)
				{
					/*列车位置监督状态从有效到无效，清除列车前后端虚拟筛选标志*/
					SetTrainVirHeadScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
					SetTrainVirTailScreenPassFlag(wTrainId, TRAIN_VIR_SCREEN_PASS_FLAG_INVALID);
					SetTrainEnterLjkLinkId(wTrainId, 0U);
					SetTrainFullEnterLjkCycNum(wTrainId, 0U);
				}
				else
				{
					/*列车正常从AG驶出，只清除容忍周期号，不清除虚拟筛选标志*/
					SetTrainFullEnterLjkCycNum(wTrainId, 0U);
				}
			}
			else
			{
				/*不处理*/
			}
		}
	}
}

/*
* 功能描述：列车位置监督通用条件检查
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.18
*/
UINT8 TrainPosMonitorCommonCheck(const UINT16 wTrainId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	UINT16 wTrainPosMonitorInLink = 0U;  /*监督有效时列车所处link*/
	UINT16 wMinHeadLink = 0U;  /*列车小前link*/
	UINT16 wMaxTailLink = 0U;  /*列车大后link*/
	UINT8 cSleepWakeAttr = 0U;  /*休眠唤醒轨属性*/

	wTrainIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wTrainIndex)
	{
		wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/
		wMinHeadLink = GetTrainMinHeadLink(wTrainId);
		wMaxTailLink = GetTrainMaxTailLink(wTrainId);
		cSleepWakeAttr = IsLinkSwTrack(wMinHeadLink);  /*获取列车所处link的休眠唤醒属性*/
		
		if ((wTrainPosMonitorInLink == wMinHeadLink) && (wMinHeadLink == wMaxTailLink) && (CI_SUCCESS == cSleepWakeAttr))
		{
			cRetVal = CI_SUCCESS;  /*列车处于休眠唤醒轨且小前和大后未越出休眠唤醒轨，返回成功（函数调用时已保证列车通信正常，不再检查是否停准停稳）*/
		}
		else
		{
			/*列车不处于休眠唤醒轨或小前/大后越出休眠唤醒轨，返回失败*/
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车位置监督起始条件检查
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.21
*/
UINT8 TrainPosMonitorBeginCheck(const UINT16 wTrainId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	UINT16 wMaxHeadLink = 0U;  /*列车大前link*/
	UINT16 wMinTailLink = 0U;  /*列车小后link*/
	UINT16 wMaxHeadBelongCiId = 0U;  /*大前link所属CI*/
	UINT16 wMinTailBelongCiId = 0U;  /*小后link所属CI*/
	UINT8 cLocalCiId = 0U;
	UINT8 cSleepWakeAttr = 0U;  /*休眠唤醒轨属性*/
	UINT8 cStopSteadyState = TRAIN_SS_NO;  /*停准停稳状态*/
	UINT8 cUseNvramFlag = TRAIN_NVRAM_POS_FLAG_YES;  /*是否使用NVRAM标志*/
	UINT8 cVirHeadScreenState = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;  /*列车虚拟前筛标志*/
	UINT8 cVirTailScreenState = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;  /*列车虚拟后筛标志*/
	EnvelopeStruct* pTrainEnvelopeData = NULL;  /*列车包络*/

	wTrainIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wTrainIndex)
	{
		wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);  /*获取列车位置*/
		wMinTailLink = GetTrainMinTailLink(wTrainId);

		cLocalCiId = GetSystemParaLocalCiId();
		wMaxHeadBelongCiId = GetLinkManageTiocById(wMaxHeadLink);
		wMinTailBelongCiId = GetLinkManageTiocById(wMinTailLink);
		
		if ((0U != cLocalCiId) && (cLocalCiId == (UINT8)wMaxHeadBelongCiId) && (cLocalCiId == (UINT8)wMinTailBelongCiId))
		{
			cSleepWakeAttr = IsLinkSwTrack(wMaxHeadLink);  /*获取列车所处link的休眠唤醒属性*/

			if ((wMaxHeadLink == wMinTailLink) && (CI_SUCCESS == cSleepWakeAttr))
			{
				/*列车完全处于休眠唤醒轨，检查列车停准停稳且未使用NVRAM*/
				cStopSteadyState = GetTrainStopSteadyState(wTrainId);  /*获取列车停稳状态*/
				cUseNvramFlag = GetTrainNvramPosFlag(wTrainId);  /*使用NVRAM标志*/

				if ((TRAIN_SS_YES == cStopSteadyState) && (TRAIN_NVRAM_POS_FLAG_NO == cUseNvramFlag))
				{
					/*列车停准停准且未使用NVRAM，继续检查列车前筛和后筛状态*/
					pTrainEnvelopeData = elm_GetEnvelopeInfoByTrainID((wTrainId & 0xFFU));  /*获取列车所在包络*/
					if (NULL != pTrainEnvelopeData)
					{
						cVirHeadScreenState = GetTrainVirHeadScreenPassFlag(wTrainId);
						cVirTailScreenState = GetTrainVirTailScreenPassFlag(wTrainId);

						if (((0U == pTrainEnvelopeData->headTrainID) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == cVirHeadScreenState))
							&& ((0U == pTrainEnvelopeData->tailTrainID) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == cVirTailScreenState)))
						{
							cRetVal = CI_SUCCESS;  /*前筛和后筛有效，返回成功*/
						}
						else
						{
							/*虚拟前筛/后筛无效，返回失败*/
						}
					}
					else
					{
						/*获取包络失败，返回失败*/
					}
				}
				else
				{
					/*未停准停准或已使用NVRAM，返回失败*/
				}
			}
			else
			{
				/*列车未完全处于休眠唤醒轨，返回失败*/
			}
		}
		else
		{
			/*列车未完全在本控区，不监督，返回失败*/
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车位置监督状态检查（正线或试车线）
* 参数说明：const UINT16 wTrainId 列车ID
*           UINT16* pMonitorLinkId 监督有效时列车所处link（出参）
*           UINT8* pMonitorFailState 监督检查失败后需要设置的状态（出参）
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.21
*/
UINT8 ZXorSCXTrainPosMonitorCheck(const UINT16 wTrainId, UINT16* pMonitorLinkId, UINT8* pMonitorFailState)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	UINT8 cTransState = TRAIN_COMM_STATE_BAD;  /*列车通信状态*/
	UINT8 cFuncRet = CI_ERROR;
	UINT8 cMonitorState = TRAIN_POS_MONITOR_INVALID;  /*列车位置监督状态*/
	UINT16 wMaxHeadLink = 0U;  /*列车大前link*/
	UINT16 wMinHeadLink = 0U;  /*列车小前link*/
	UINT16 wMaxTailLink = 0U;  /*列车大后link*/
	UINT16 wMinTailLink = 0U;  /*列车小后link*/
	UINT16 wMinHeadBelongCiId = 0U;  /*小前link所属CI*/
	UINT16 wMaxTailBelongCiId = 0U;  /*大后link所属CI*/
	UINT8 cLocalCiId = 0U;
	UINT16 wTrainPosMonitorInLink = 0U;  /*列车位置监督状态有效时所处link*/
	UINT8 cOrgAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*起点相邻计轴区段采集占用状态*/
	UINT8 cTmlAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*终点相邻计轴区段采集占用状态*/
	UINT8 cStopSteadyState = TRAIN_SS_NO;  /*停准停稳状态*/
	UINT8 cMonitorFailState = TRAIN_POS_MONITOR_INVALID;  /*检查失败时的列车位置监督状态*/

	wTrainIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wTrainIndex) && (NULL != pMonitorLinkId) && (NULL != pMonitorFailState))
	{
		/****** 检查列车位置监督状态是否有效 *******/
		cMonitorState = GetTrainPosMonitorState(wTrainId);  /*获取列车位置监督状态*/
		cTransState = GetTrainTransitmitStat(wTrainId);  /*获取列车通信状态*/
		if (TRAIN_COMM_STATE_GOOD == cTransState)
		{
			wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);  /*获取列车位置信息*/
			wMinHeadLink = GetTrainMinHeadLink(wTrainId);
			wMaxTailLink = GetTrainMaxTailLink(wTrainId);
			wMinTailLink = GetTrainMinTailLink(wTrainId);
			wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/

			if (TRAIN_POS_MONITOR_VALID == cMonitorState)
			{
				cLocalCiId = GetSystemParaLocalCiId();
				wMinHeadBelongCiId = GetLinkManageTiocById(wMinHeadLink);
				wMaxTailBelongCiId = GetLinkManageTiocById(wMaxTailLink);

				if ((wMaxHeadLink != wTrainPosMonitorInLink) && (wMinHeadLink != wTrainPosMonitorInLink) && (wMaxTailLink != wTrainPosMonitorInLink) && (wMinTailLink != wTrainPosMonitorInLink))
				{
					cMonitorFailState = TRAIN_POS_MONITOR_DIFF;  /*列车完全不在原link，传出监督位置不一致*/
					cFuncRet = CI_ERROR;
				}
				else if ((0U != cLocalCiId) && (cLocalCiId == (UINT8)wMinHeadBelongCiId) && (cLocalCiId == (UINT8)wMaxTailBelongCiId))
				{
					cFuncRet = TrainPosMonitorCommonCheck(wTrainId);  /*列车在本控区，开始监督，进行列车位置监督通用条件检查*/
				}
				else
				{
					cMonitorFailState = TRAIN_POS_MONITOR_INVALID;  /*列车不在本控区，传出监督位置无效*/
					cFuncRet = CI_ERROR;
				}
			}
			else
			{
				cFuncRet = TrainPosMonitorBeginCheck(wTrainId);  /*列车还未开始监督，进行列车位置监督起始条件检查*/
			}

			if (CI_SUCCESS == cFuncRet)
			{
				/****** 前置条件检查通过，继续判断相邻区段采集占用状态 ******/
				wMinHeadLink = GetTrainMinHeadLink(wTrainId);
				cOrgAxleSecOccState = GetLinkOrgAxleSecOccSta(wMinHeadLink);  /*获取link起点关联的计轴区段采集占用状态*/
				cTmlAxleSecOccState = GetLinkTmlAxleSecOccSta(wMinHeadLink);  /*获取link终点关联的计轴区段采集占用状态*/

				if ((AXIS_SECTION_OCCUPY_NO == cOrgAxleSecOccState) && (AXIS_SECTION_OCCUPY_NO == cTmlAxleSecOccState))
				{
					*pMonitorLinkId = wMinHeadLink;  /*传出监督有效时的link*/
					cRetVal = CI_SUCCESS;  /*列车所处区段前后相邻区段均采集空闲，检查通过*/
				}
				else
				{
					cRetVal = CI_ERROR;  /*列车所处区段前后相邻区段存在采集占用，检查失败*/
				}
			}
			else
			{
				cRetVal = CI_ERROR;  /*列车位置监督前置条件检查失败*/
			}
		}
		else
		{
			cStopSteadyState = GetTrainStopSteadyState(wTrainId);  /*列车停稳状态*/
			if (TRAIN_SS_YES != cStopSteadyState)
			{
				cRetVal = CI_ERROR;  /*列车未停准停稳且通信中断，位置监督无效*/
			}
			else
			{
				if (TRAIN_POS_MONITOR_VALID == cMonitorState)
				{
					/****** 列车当前位置监督状态有效，则继续判断位置监督状态 ******/
					wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/
					cOrgAxleSecOccState = GetLinkOrgAxleSecOccSta(wTrainPosMonitorInLink);  /*获取link起点关联的计轴区段采集占用状态*/
					cTmlAxleSecOccState = GetLinkTmlAxleSecOccSta(wTrainPosMonitorInLink);  /*获取link终点关联的计轴区段采集占用状态*/

					if ((AXIS_SECTION_OCCUPY_NO == cOrgAxleSecOccState) && (AXIS_SECTION_OCCUPY_NO == cTmlAxleSecOccState))
					{
						*pMonitorLinkId = wTrainPosMonitorInLink;  /*传出监督有效时的link*/
						cRetVal = CI_SUCCESS;  /*列车所处区段前后相邻区段均采集空闲，检查通过*/
					}
					else
					{
						cRetVal = CI_ERROR;  /*列车所处区段前后相邻区段存在采集占用，检查失败*/
					}
				}
				else
				{
					cRetVal = CI_ERROR;  /*通信中断后列车位置监督无效，继续保持监督无效*/
				}
			}
		}

		*pMonitorFailState = cMonitorFailState;
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车位置监督状态占用检查（车辆段BG1）
* 参数说明：const UINT16 wBGLinkId  BG link ID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.18
*/
UINT8 BGTrainPosMonitorOccCheck(const UINT16 wBGLinkId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wLinkIndex = 0U;
	UINT16 wBGRelAGLinkId = 0U;  /*BGLink关联的AGlink*/
	UINT16 wBGRelOrgLinkId = 0U;  /*BG起点相连的link*/
	UINT16 wBGRelTmlLinkId = 0U;  /*BG终点相连的link*/
	UINT16 wBGRelOrgLinkAttr = LINK_REL_PHYSEC_DEFAULT;  /*BG起点相连link的AG/BG属性*/
	UINT16 wBGRelTmlLinkAttr = LINK_REL_PHYSEC_DEFAULT;  /*BG终点相连link的AG/BG属性*/
	UINT16 wAdjacentLinkId = 0U;  /*BG相邻的非BG2link*/
	UINT16 wAxleSecId = 0U;
	UINT8 cAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*相邻计轴区段采集占用状态*/
	UINT16 wMonitorTrainId = 0U;  /*计轴区段关联的监督有效的列车ID*/
	UINT16 wAGRelOrgLinkId = 0U;  /*AG起点相连的link*/
	UINT16 wAGRelTmlLinkId = 0U;  /*AG终点相连的link*/
	UINT16 wDGLinkId = 0U;  /*DG相邻link*/

	wLinkIndex = GetLinkIndexById(wBGLinkId);
	if ((0U < wLinkIndex) && (LINK_SUM_MAX > wLinkIndex))
	{
		wBGRelAGLinkId = GetBGLinkRelAGLinkId(wBGLinkId);  /*获取BG关联的AGlink*/

		wBGRelOrgLinkId = GetLinkOrgnJointMainLkIdById(wBGLinkId);
		wBGRelOrgLinkAttr = GetLinkRelPhySecAGorBGAttr(wBGRelOrgLinkId);
		if ((0U != wBGRelOrgLinkId) && (UINT16_MAX != wBGRelOrgLinkId) && (LINK_REL_PHYSEC_BG != wBGRelOrgLinkAttr))
		{
			wAdjacentLinkId = wBGRelOrgLinkId;  /*BG相邻的非BG2link为起点连接的link*/
		}
		else
		{
			/*尽头线或BG2，不处理*/
		}

		wBGRelTmlLinkId = GetLinkTmnlJointMainLkById(wBGLinkId);
		wBGRelTmlLinkAttr = GetLinkRelPhySecAGorBGAttr(wBGRelTmlLinkId);
		if ((0U != wBGRelTmlLinkId) && (UINT16_MAX != wBGRelTmlLinkId) && (LINK_REL_PHYSEC_BG != wBGRelTmlLinkAttr))
		{
			wAdjacentLinkId = wBGRelTmlLinkId;  /*BG相邻的非BG2link为起点连接的link*/
		}
		else
		{
			/*尽头线或BG2，不处理*/
		}

		if (wAdjacentLinkId == wBGRelAGLinkId)
		{
			/*无CG场景*/
			wAxleSecId = GetLinkBelongAcId(wAdjacentLinkId);  /*获取AG计轴区段ID*/
			wMonitorTrainId = GetAxisPosMonitorTrainId(wAxleSecId);  /*获取AG关联的监督有效的列车ID*/
			if (0U != wMonitorTrainId)
			{
				/*AG列车处于监督中，检查DG采集占用状态*/
				wAGRelOrgLinkId = GetLinkOrgnJointMainLkIdById(wBGRelAGLinkId);
				wAGRelTmlLinkId = GetLinkTmnlJointMainLkById(wBGRelAGLinkId);
				if (wAGRelOrgLinkId != wBGLinkId)
				{
					/*起点相邻link为DG*/
					wDGLinkId = wAGRelOrgLinkId;
				}
				else
				{
					/*终点相邻link为DG*/
					wDGLinkId = wAGRelTmlLinkId;
				}

				wAxleSecId = GetLinkBelongAcId(wDGLinkId);  /*获取DG计轴区段ID*/
				cAxleSecOccState = GetAxisOccupyState(wAxleSecId);  /*获取DG计轴区段采集占用状态*/

				if (AXIS_SECTION_OCCUPY_NO == cAxleSecOccState)
				{
					cRetVal = CI_SUCCESS;  /*DG无采集占用，返回成功*/
				}
				else
				{
					cRetVal = CI_ERROR;  /*DG采集占用，返回失败*/
				}
			}
			else
			{
				/*AG无列车处于监督中，检查AG列车的前/后端虚拟筛选标志*/
				cRetVal = CheckAGToBGTrainVirScreen(wAxleSecId, wBGRelAGLinkId, wBGLinkId);
			}
		}
		else
		{
			/*有CG场景*/
			wAxleSecId = GetLinkBelongAcId(wAdjacentLinkId);  /*获取CG计轴区段ID*/
			cAxleSecOccState = GetAxisOccupyState(wAxleSecId);  /*获取CG计轴区段采集占用状态*/

			if (AXIS_SECTION_OCCUPY_NO == cAxleSecOccState)
			{
				cRetVal = CI_SUCCESS;  /*DG无采集占用，返回成功*/
			}
			else
			{
				cRetVal = CI_ERROR;  /*DG采集占用，返回失败*/
			}
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：检查AG列车靠近BG端的虚拟筛选标志是否有效
* 参数说明：const UINT16 wAGAxleSecId AG计轴区段ID
*           const UINT16 wAGLinkId AG link ID
*           const UINT16 wBGLinkId  BG link ID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.18
*/
UINT8 CheckAGToBGTrainVirScreen(const UINT16 wAGAxleSecId, const UINT16 wAGLinkId, const UINT16 wBGLinkId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wACIndex = 0U;
	UINT16 wAGLinkIndex = 0U;
	UINT16 wBGLinkIndex = 0U;
	UINT16 ii = 0U;
	UINT16 wTrainId = 0U;
	UINT16 wEnterLjkLinkId = 0U;  /*列车驶入的列检库link*/
	UINT16 wAGRelOrgLinkId = 0U;  /*AG起点相连的link*/
	UINT16 wAGRelTmlLinkId = 0U;  /*AG终点相连的link*/
	UINT16 cVirScreenFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;  /*列车虚拟筛选标志*/
	UINT8 cTrianDir = DIR_INVALID;  /*列车方向*/
	UINT8 cBGFrontAxleSecNum = 0U;
	UINT16 szBGFrontAxleSecID[AC_MAXCNT_IN_SWITCH] = { 0U };
	UINT16 wBGAxleSecId = 0U;  /*BG计轴区段ID*/
	UINT8 cAGTrainNearFlag = AAM_BAD_NEAR;  /*AG列车接近标志*/

	wACIndex = GetAxisSecConfigBufIndex(wAGAxleSecId); 
	wAGLinkIndex = GetLinkIndexById(wAGLinkId);
	wBGLinkIndex = GetLinkIndexById(wBGLinkId);
	
	if ((AXIS_SECTION_SUM_MAX > wACIndex) && (0U < wAGLinkIndex) && (LINK_SUM_MAX > wAGLinkIndex) && (0U < wBGLinkIndex) && (LINK_SUM_MAX > wBGLinkIndex))
	{
		for (ii = 0U; ii < TRAIN_SUM_MAX; ii++)
		{
			wTrainId = GetTrainId(ii);
			wEnterLjkLinkId = GetTrainEnterLjkLinkId(wTrainId);

			if (wEnterLjkLinkId == wAGLinkId)
			{
				break;  /*找到AG列车，停止遍历*/
			}
			else
			{
				/*继续查找驶入AG的列车*/
			}
		}

		wAGRelOrgLinkId = GetLinkOrgnJointMainLkIdById(wAGLinkId);
		wAGRelTmlLinkId = GetLinkTmnlJointMainLkById(wAGLinkId);
		if (ii != TRAIN_SUM_MAX)
		{
			/*有列车驶入AG，判断列车靠近BG端的虚拟筛选标志*/
			cTrianDir = GetTrainDir(wTrainId);

			if (wAGRelOrgLinkId == wBGLinkId)
			{
				/*AGlink起点为BGlink*/
				if (DIR_SAME == cTrianDir)
				{
					cVirScreenFlag = GetTrainVirTailScreenPassFlag(wTrainId);
				}
				else
				{
					cVirScreenFlag = GetTrainVirHeadScreenPassFlag(wTrainId);
				}
			}
			else if (wAGRelTmlLinkId == wBGLinkId)
			{
				/*AGlink终点BGlink*/
				if (DIR_SAME == cTrianDir)
				{
					cVirScreenFlag = GetTrainVirHeadScreenPassFlag(wTrainId);
				}
				else
				{
					cVirScreenFlag = GetTrainVirTailScreenPassFlag(wTrainId);
				}
			}
			else
			{
				cVirScreenFlag = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;  /*异常场景，筛选无效*/
			}

			if (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == cVirScreenFlag)
			{
				cRetVal = CI_SUCCESS;  /*虚拟筛选标志有效，返回成功*/
			}
			else
			{
				cRetVal = CI_ERROR;  /*虚拟筛选标志无效，返回失败*/
			}
		}
		else
		{
			/*无列车驶入AG，判断AG计轴区段列车接近状态*/
			cBGFrontAxleSecNum = 1U;
			szBGFrontAxleSecID[0U] = wAGAxleSecId;
			wBGAxleSecId = GetLinkBelongAcId(wBGLinkId);  /*获取BG计轴区段ID*/

			if (wAGRelOrgLinkId == wBGLinkId)
			{
				cAGTrainNearFlag = aam_SearchNearbyTrainType(wBGAxleSecId, EMAP_SAME_DIR, cBGFrontAxleSecNum, szBGFrontAxleSecID);  /*起点相邻，按逻辑正方向查询*/
			}
			else if (wAGRelTmlLinkId == wBGLinkId)
			{
				cAGTrainNearFlag = aam_SearchNearbyTrainType(wBGAxleSecId, EMAP_CONVER_DIR, cBGFrontAxleSecNum, szBGFrontAxleSecID);  /*终点相邻，按逻辑反方向查询*/
			}
			else
			{
				cAGTrainNearFlag = AAM_BAD_NEAR;  /*异常场景，坏车接近*/
			}

			if ((AAM_BAD_NEAR != cAGTrainNearFlag) && (AAM_GOOD_OCC != cAGTrainNearFlag))
			{
				cRetVal = CI_SUCCESS;  /*非坏车接近，返回成功*/
			}
			else
			{
				cRetVal = CI_ERROR;  /*坏车接近，返回失败*/
				debug_infor_printf((const)"TrainScreen CheckAGToBGTrainVirScreen ERR.\n");
			}
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车位置监督状态占用检查（车辆段AG）
* 参数说明：const UINT16 wAGLinkId  AG link ID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.18
*/
UINT8 AGTrainPosMonitorOccCheck(const UINT16 wAGLinkId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wLinkIndex = 0U;
	UINT16 wAGRelBGLinkId = 0U;  /*AGLink关联的BGlink*/
	UINT16 wAGRelOrgLinkId = 0U;  /*AG起点相连的link*/
	UINT16 wAGRelTmlLinkId = 0U;  /*AG终点相连的link*/
	UINT8 cOrgLinkAttr = LINK_REL_PHYSEC_DEFAULT;
	UINT8 cTmlLinkAttr = LINK_REL_PHYSEC_DEFAULT;
	UINT16 wOrgAxleSecId = 0U;
	UINT8 cOrgAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*起点计轴区段采集占用状态*/
	UINT16 wTmlAxleSecId = 0U;
	UINT8 cTmlAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*终点计轴区段采集占用状态*/
	UINT16 wDGLinkId = 0U;  /*DGlink*/
	UINT16 wDGAxleSecId = 0U;
	UINT8 cDGAxleSecOccState = AXIS_SECTION_OCCUPY_YES;  /*DG计轴区段采集占用状态*/
	UINT16 wBGPhySecId = 0U;
	UINT8 cBGPreOccState = 0U;  /*BG之前采集占用状态*/
	UINT8 cBGCurOccState = 0U;  /*BG当前采集占用状态*/

	wLinkIndex = GetLinkIndexById(wAGLinkId);
	if ((0U < wLinkIndex) && (LINK_SUM_MAX > wLinkIndex))
	{
		wAGRelOrgLinkId = GetLinkOrgnJointMainLkIdById(wAGLinkId);
		wAGRelTmlLinkId = GetLinkTmnlJointMainLkById(wAGLinkId);

		cOrgLinkAttr = GetLinkRelPhySecAGorBGAttr(wAGRelOrgLinkId);
		cTmlLinkAttr = GetLinkRelPhySecAGorBGAttr(wAGRelTmlLinkId);

		if (LINK_REL_PHYSEC_BG == cOrgLinkAttr)
		{
			wAGRelBGLinkId = wAGRelOrgLinkId;
			wDGLinkId = wAGRelTmlLinkId;
		}
		else if (LINK_REL_PHYSEC_BG == cTmlLinkAttr)
		{
			wAGRelBGLinkId = wAGRelTmlLinkId;
			wDGLinkId = wAGRelOrgLinkId;
		}
		else
		{
			/*AG与BG未直接相连，即存在CG*/
		}

		if (0U == wAGRelBGLinkId)
		{
			/*存在CG，需检查CG+DG的采集占用状态*/
			wOrgAxleSecId = GetLinkBelongAcId(wAGRelOrgLinkId);
			cOrgAxleSecOccState = GetAxisOccupyState(wOrgAxleSecId);  /*获取起点计轴区段采集占用状态*/
			wTmlAxleSecId = GetLinkBelongAcId(wAGRelTmlLinkId);
			cTmlAxleSecOccState = GetAxisOccupyState(wTmlAxleSecId);  /*获取终点计轴区段采集占用状态*/

			if (((AXIS_SECTION_OCCUPY_NO == cOrgAxleSecOccState) || (0U == wAGRelOrgLinkId) || (UINT16_MAX == wAGRelOrgLinkId))
				&& ((AXIS_SECTION_OCCUPY_NO == cTmlAxleSecOccState) || (0U == wAGRelTmlLinkId) || (UINT16_MAX == wAGRelTmlLinkId)))
			{
				cRetVal = CI_SUCCESS;  /*CG+DG无采集占用（通过起始点link判断是否为单列位），返回成功*/
			}
			else
			{
				cRetVal = CI_ERROR;  /*存在采集占用，返回失败*/
			}
		}
		else
		{
			/*无CG，检查DG+BG的采集占用状态*/
			wDGAxleSecId = GetLinkBelongAcId(wDGLinkId);
			cDGAxleSecOccState = GetAxisOccupyState(wDGAxleSecId);  /*获取DG计轴区段采集占用状态*/
			if (AXIS_SECTION_OCCUPY_NO == cDGAxleSecOccState)
			{
				/*DG无占用，检查BG占用状态*/
				wBGPhySecId = GetLinkRelatedPhySec(wAGRelBGLinkId);
				cBGPreOccState = GetPhySecPreOccupyState(wBGPhySecId);
				cBGCurOccState = GetPhySecCurOccupyState(wBGPhySecId);
				if ((SECTION_OCCUPY_NO == cBGPreOccState) && (SECTION_OCCUPY_YES == cBGCurOccState))
				{
					cRetVal = CI_ERROR;  /*BG由空闲到占用，返回失败*/
				}
				else
				{
					cRetVal = CI_SUCCESS;  /*DG无采集占用，返回成功*/
				}
			}
			else
			{
				cRetVal = CI_ERROR;  /*DG存在采集占用，返回失败*/
			}
			
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}

/*
* 功能描述：列车位置监督状态检查（车辆段）
* 参数说明：const UINT16 wTrainId 列车ID
*           UINT16* pMonitorLinkId 监督有效时列车所处link（出参）
*           UINT8* pMonitorFailState 监督检查失败后需要设置的状态（出参）
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.21
*/
UINT8 CLDTrainPosMonitorCheck(const UINT16 wTrainId, UINT16* pMonitorLinkId, UINT8* pMonitorFailState)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wTrainIndex = 0U;
	UINT8 cTransState = TRAIN_COMM_STATE_BAD;  /*列车通信状态*/
	UINT8 cFuncRet = CI_ERROR;
	UINT8 cMonitorState = TRAIN_POS_MONITOR_INVALID;  /*列车位置监督状态*/
	UINT16 wMaxHeadLink = 0U;  /*列车大前link*/
	UINT16 wMinHeadLink = 0U;  /*列车小前link*/
	UINT16 wMaxTailLink = 0U;  /*列车大后link*/
	UINT16 wMinTailLink = 0U;  /*列车小后link*/
	UINT16 wMinHeadBelongCiId = 0U;  /*小前link所属CI*/
	UINT16 wMaxTailBelongCiId = 0U;  /*大后link所属CI*/
	UINT8 cLocalCiId = 0U;
	UINT16 wTrainPosMonitorInLink = 0U;  /*列车位置监督状态有效时所处link*/
	UINT8 cAGorBGAttr = LINK_REL_PHYSEC_DEFAULT;  /*AG/BG属性*/
	UINT8 cStopSteadyState = TRAIN_SS_NO;  /*停准停稳状态*/
	UINT8 cMonitorFailState = TRAIN_POS_MONITOR_INVALID;  /*检查失败时的列车位置监督状态*/

	wTrainIndex = GetTrainBufIndex(wTrainId);
	if ((TRAIN_SUM_MAX > wTrainIndex) && (NULL != pMonitorLinkId) && (NULL != pMonitorFailState))
	{
		/****** 检查列车位置监督状态是否有效 *******/
		cMonitorState = GetTrainPosMonitorState(wTrainId);  /*获取列车位置监督状态*/
		cTransState = GetTrainTransitmitStat(wTrainId);  /*获取列车通信状态*/
		if (TRAIN_COMM_STATE_GOOD == cTransState)
		{
			wMaxHeadLink = GetTrainMaxHeadLink(wTrainId);  /*获取列车位置信息*/
			wMinHeadLink = GetTrainMinHeadLink(wTrainId);
			wMaxTailLink = GetTrainMaxTailLink(wTrainId);
			wMinTailLink = GetTrainMinTailLink(wTrainId);
			wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/

			if (TRAIN_POS_MONITOR_VALID == cMonitorState)
			{
				cLocalCiId = GetSystemParaLocalCiId();
				wMinHeadBelongCiId = GetLinkManageTiocById(wMinHeadLink);
				wMaxTailBelongCiId = GetLinkManageTiocById(wMaxTailLink);

				if ((wMaxHeadLink != wTrainPosMonitorInLink) && (wMinHeadLink != wTrainPosMonitorInLink) && (wMaxTailLink != wTrainPosMonitorInLink) && (wMinTailLink != wTrainPosMonitorInLink))
				{
					cMonitorFailState = TRAIN_POS_MONITOR_DIFF;  /*列车完全不在原link，传出监督位置不一致*/
					cFuncRet = CI_ERROR;
				}
				else if ((0U != cLocalCiId) && (cLocalCiId == (UINT8)wMinHeadBelongCiId) && (cLocalCiId == (UINT8)wMaxTailBelongCiId))
				{
					cFuncRet = TrainPosMonitorCommonCheck(wTrainId);  /*列车在本控区，开始监督，进行列车位置监督通用条件检查*/
				}
				else
				{
					cMonitorFailState = TRAIN_POS_MONITOR_INVALID;  /*列车不在本控区，传出监督位置无效*/
					cFuncRet = CI_ERROR;
				}
			}
			else
			{
				cFuncRet = TrainPosMonitorBeginCheck(wTrainId);  /*列车还未开始监督，进行列车位置监督起始条件检查*/
			}

			if (CI_SUCCESS == cFuncRet)
			{
				/****** 前置条件检查通过，继续判断相邻区段采集占用状态 ******/
				wMinHeadLink = GetTrainMinHeadLink(wTrainId);
				wTrainPosMonitorInLink = wMinHeadLink;  /*记录下待设置的link*/
				cAGorBGAttr = GetLinkRelPhySecAGorBGAttr(wMinHeadLink);  /*获取AG/BG属性*/

				switch (cAGorBGAttr)
				{
				case LINK_REL_PHYSEC_AG:
					/*AG位置监督检查*/
					cRetVal = AGTrainPosMonitorOccCheck(wTrainPosMonitorInLink);
					break;
				case LINK_REL_PHYSEC_BG:
					/*BG位置监督检查*/
					cRetVal = BGTrainPosMonitorOccCheck(wTrainPosMonitorInLink);
					break;
				default:
					cRetVal = CI_ERROR;  /*非AG且非BG，失败*/
					break;
				}
			}
			else
			{
				cRetVal = CI_ERROR;  /*列车位置监督前置条件检查失败*/
			}
		}
		else
		{
			cStopSteadyState = GetTrainStopSteadyState(wTrainId);  /*列车停稳状态*/
			if (TRAIN_SS_YES != cStopSteadyState)
			{
				cRetVal = CI_ERROR;  /*列车未停准停稳且通信中断，位置监督无效*/
			}
			else
			{
				if (TRAIN_POS_MONITOR_VALID == cMonitorState)
				{
					/****** 列车当前位置监督状态有效，则继续判断位置监督状态 ******/
					wTrainPosMonitorInLink = GetTrainPosMonitorInLink(wTrainId);  /*获取列车位置监督状态有效时的link*/
					cAGorBGAttr = GetLinkRelPhySecAGorBGAttr(wTrainPosMonitorInLink);  /*获取AG/BG属性*/

					switch (cAGorBGAttr)
					{
					case LINK_REL_PHYSEC_AG:
						/*AG位置监督检查*/
						cRetVal = AGTrainPosMonitorOccCheck(wTrainPosMonitorInLink);
						break;
					case LINK_REL_PHYSEC_BG:
						/*BG位置监督检查*/
						cRetVal = BGTrainPosMonitorOccCheck(wTrainPosMonitorInLink);
						break;
					default:
						cRetVal = CI_ERROR;  /*非AG且非BG，失败*/
						break;
					}
				}
				else
				{
					cRetVal = CI_ERROR;  /*列车位置监督前置条件检查失败*/
				}
			}
		}

		if (CI_SUCCESS == cRetVal)
		{
			*pMonitorLinkId = wTrainPosMonitorInLink;  /*传出位置监督有效时的link*/
		}
		else
		{
			*pMonitorFailState = cMonitorFailState; /*传出检查失败时的列车位置监督状态*/
		}
	}
	else
	{
		/*入参检查失败，不处理*/
	}

	return cRetVal;
}

/*
* 功能描述：休眠唤醒轨相邻区段占用检查（车辆段）
* 参数说明：const UINT16 wSWLinkId  休眠唤醒轨linkID
* 返 回 值：0 失败
*           1 成功
* Created By LQ 2024.08.19
*/
UINT8 CLDSWAdjacentSecOccCheck(const UINT16 wSWLinkId)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 wLinkIndex = 0U;
	UINT8 cAGorBGAttr = LINK_REL_PHYSEC_DEFAULT;  /*AG/BG属性*/

	wLinkIndex = GetLinkIndexById(wSWLinkId);
	if ((0U < wLinkIndex) && (LINK_SUM_MAX > wLinkIndex))
	{
		cAGorBGAttr = GetLinkRelPhySecAGorBGAttr(wSWLinkId);  /*获取AG/BG属性*/

		if (LINK_REL_PHYSEC_AG == cAGorBGAttr)
		{
			cRetVal = AGTrainPosMonitorOccCheck(wSWLinkId);  /*AG相邻区段占用检查*/
		}
		else if (LINK_REL_PHYSEC_BG == cAGorBGAttr)
		{
			cRetVal = BGTrainPosMonitorOccCheck(wSWLinkId);  /*BG相邻区段占用检查*/
		}
		else
		{
			/*休眠唤醒轨不在AG且不在NG，异常场景，返回失败*/
		}
	}
	else
	{
		/*入参检查失败，返回失败*/
	}

	return cRetVal;
}
/*
* 功能描述：列车大前小后物理区段ABL标志更新
* 参数说明：无
* 返 回 值：无
* Created By fan 2024.08.20
*/
void TrainPhyAblTagUpdate(void)
{
	UINT8 cTrainIndex = 0U;
	UINT8 ii = 0U;
	UINT16 wTrainId = 0U;
	UINT8 chTrainLevel = 0U; /*列车运行级别*/
	UINT16 wTrainMaxSafeHeadLink = 0U; /*大前link*/
	UINT16 wTrainMinSafeTailLink=0U; /*小后ink*/
	UINT16 phySecCurSum = 0U; /*物理区段总数*/
	UINT16 wPhySecId = 0U;
	UINT8 belongCiId = 0u;
	UINT8 localCiId = GetSystemParaLocalCiId();
	UINT8 chAblTag = PHYSICAL_SECTION_ABLOCCUPY_DEFAULT;
	for (cTrainIndex = 0U; cTrainIndex < TRAIN_SUM_MAX; cTrainIndex++)
	{
		wTrainId = GetTrainId(cTrainIndex);
		chTrainLevel = GetTrainLevel(wTrainId);
		wTrainMaxSafeHeadLink = GetAblTrainMaxHeadLink(wTrainId);
		wTrainMinSafeTailLink = GetAblTrainMinTailLink(wTrainId);
		/*更新通信车ABL占压状态*/
		if (TRAIN_LEVEL_ABL == chTrainLevel)
		{
			chAblTag = PHYSICAL_SECTION_ABLOCCUPY_YES;
		}
		else
		{
			chAblTag = PHYSICAL_SECTION_ABLOCCUPY_NO;
		}
		/*大前所在物理区段设置ABL标志*/
		wPhySecId = GetLinkRelatedPhySec(wTrainMaxSafeHeadLink);
		if (0U != wPhySecId)
		{
			belongCiId = GetPhySecBelongCiId(wPhySecId);
			if (localCiId == belongCiId)
			{
				SetPhySecABLTrainFlag(wPhySecId, chAblTag);
			}
			else
			{
				; /*不处理*/
			}
		}

		/*小后所在物理区段设置ABL标志*/
		wPhySecId = GetLinkRelatedPhySec(wTrainMinSafeTailLink);
		if (0U != wPhySecId)
		{
			belongCiId = GetPhySecBelongCiId(wPhySecId);
			if (localCiId == belongCiId)
			{
				SetPhySecABLTrainFlag(wPhySecId, chAblTag);
			}
			else
			{
				; /*不处理*/
			}
		}
	}

	phySecCurSum = GetPhySecCurSum();
	/*  清除本周期未设置物理区段的标志 */
	for (ii = 0u; ii < phySecCurSum; ii++)
	{
		wPhySecId = GetPhySecId(ii);
		belongCiId = GetPhySecBelongCiId(wPhySecId);
		if (belongCiId == localCiId)
		{
			/*设置默认  对本周期未设置的区段更新周期*/
			SetPhySecABLTrainFlag(wPhySecId, PHYSICAL_SECTION_ABLOCCUPY_DEFAULT);
		}
	}
}

/*
* 功能描述：BG远程筛选AG UT占用检查
* 参数说明：const UINT16 wLinkId  BGlinkID
* 返 回 值：0 失败
*           1 成功
* by cgh 20240903
*/
UINT8 BGAtsScreenAgUtCheck(const UINT16 wLinkId)
{
	UINT8 chReval = CI_ERROR;
	UINT8 chLinkRelAbgFlag = 0U;/*LINK关联ABG属性*/
	UINT16 wBGLinkRelAGLinkId = 0U;/*BG关联AGLINK ID*/
	UINT16 wAGRelAxisSecId = 0U;/*AG关联计轴区段ID*/
	UINT8 chAgLinkExistRelCgFlag = 0U;/*AG是否存在CG标志*/

	if ((0U < wLinkId) && (LINK_SUM_MAX > wLinkId))
	{
		chLinkRelAbgFlag = GetLinkRelPhySecAGorBGAttr(wLinkId);
		if (LINK_REL_PHYSEC_BG == chLinkRelAbgFlag)
		{
			wBGLinkRelAGLinkId = GetBGLinkRelAGLinkId(wLinkId);
			chAgLinkExistRelCgFlag = GetAgLinkExistRelCgFlag(wBGLinkRelAGLinkId);
			if (AGLINK_EXIST_REL_CG_NO == chAgLinkExistRelCgFlag)
			{
				wAGRelAxisSecId = GetLinkBelongAcId(wBGLinkRelAGLinkId);
				chReval = CheckAGToBGTrainVirScreen(wAGRelAxisSecId, wBGLinkRelAGLinkId, wLinkId);
			}
			else
			{
				/*存在CG，通过相邻计轴区段是否空闲防护，这个条件通过*/
				chReval = CI_SUCCESS;
			}

		}
		else
		{
			/*非BG */
			chReval = CI_SUCCESS;
		}
	}
	else
	{
		; /*数据非法*/
	}

	return chReval;
}

/*
* 功能描述： 设置指定列车开始飞车起始周期
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwCycNum 列车开始飞车起始周期
* 返回值  ： 无
* BY fan 20241017
*/
void SetTrainStartFlyProtectCycNum(const UINT16 wTrainId, const UINT32 dwCycNum)
{
	UINT16 wBufIndex = 0U;
	UINT32 dwSysFlyOverCyc = GetFlyProtectOverCyc();
	UINT32 dwFlyStartCyc = 0U;
	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwFlyStartCyc = GetTrainStartFlyProtectCycNum(wTrainId);

		if (0U == dwFlyStartCyc)
		{
			gstTrainInfo[wBufIndex].dwStartFlyCycNum = dwCycNum; /*未设置*/
		}
		else if ((0U == dwSysFlyOverCyc) && (0U== dwCycNum))
		{
			gstTrainInfo[wBufIndex].dwStartFlyCycNum = dwCycNum; /*未设置系统宕机标志 可清零*/
		}
		else
		{
			; /*已进入宕机报警流程*/
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述： 设置指定列车开始飞车起始周期
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： UINT32 列车开始飞车起始周期
* BY fan 20241017
*/
UINT32 GetTrainStartFlyProtectCycNum(const UINT16 wTrainId)
{
	UINT32 dwRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].dwStartFlyCycNum;
	}
	else
	{
		;
	}

	return dwRetVal;
}


/**
* 功能描述： 添加飞车数据
* 参数说明：UINT16 wTrainID UINT16 envelopeId包络id
* 返回值  ： 无
* BY fan 20241018
*/
void elm_AddFlyingTrain(UINT16 wTrainID, UINT16 envelopeId)
{
	UINT8 ii = 0U;
	UINT8 jj = 0U;
	UINT8 chSecNum = 0;
	const EnvelopeStruct* pEnvelop = NULL;
	if (SHUT_DOWN_TRAIN_NUMMAX > gFlyTrainCnt)
	{
		for (ii = 0U; ii < gFlyTrainCnt; ii++)
		{
			if (gFlyTrainData[ii].wTrainId == wTrainID)
			{
				break; /*已有*/
			}
		}
		if (ii == gFlyTrainCnt)
		{
			gFlyTrainData[gFlyTrainCnt].wTrainId= wTrainID;
			/** 获取包络信息缓存地址 */
			pEnvelop = elm_GetEnvelopeInfoPtr(envelopeId);
			for (jj = 0U; jj < pEnvelop->ACCnt; jj++)
			{
				if (TRAIN_FLYALARM_SECNUM_MAX > chSecNum)
				{
					gFlyTrainData[gFlyTrainCnt].flyProtectSec[chSecNum] = pEnvelop->ACID[jj];
					chSecNum++;
				}
				else
				{
					break;
				}
			}
			gFlyTrainData[gFlyTrainCnt].flyProtectSecCnt = chSecNum;
			gFlyTrainCnt++;
		}
		else
		{
			; /*已添加*/
		}
	}
	else
	{
		; /*不添加*/
	}
}

/*
* 功能描述： 获取飞车数据
* 参数说明：UINT8 chIndex 索引
* 返回值  ： TrainFlyProtectStru*  gFlyTrainData
* BY fan 20241018
*/

TrainFlyProtectStru * GetFlyProtectData(UINT8 chIndex)
{
	return &gFlyTrainData[chIndex];
}

/*
* 功能描述： 获取飞车数量
* 参数说明：无
* 返回值  ： UINT8 flyProtectTrainNum
* BY fan 20241018
*/
UINT8  GetFlyProtectNum(void)
{
	return gFlyTrainCnt;
}

/**
* @brief 获取飞车宕机跟随数据
* @param UINT8 *pDataBuff 跟随数据存储缓冲区
* @param UINT32 curIndex 当前索引
* @return 计算后的索引
*/
UINT32 GeFlyProtectTransferData(OUT UINT8 *pDataBuff, IN UINT32 curIndex)
{
	UINT32 ret = 0U;
	UINT32 copyIndex = curIndex;
	UINT8 chIndex = 0u;
	UINT8 flyTrainCnt = 0u;
	flyTrainCnt = GetFlyProtectNum();
	if (NULL != pDataBuff)
	{
		pDataBuff[copyIndex] = flyTrainCnt;
		copyIndex++;
		for (chIndex = 0u; chIndex < flyTrainCnt; chIndex++)
		{
			(void)CommonMemCpy(&pDataBuff[copyIndex], (UINT32)sizeof(TrainFlyProtectStru), &gFlyTrainData[chIndex], (UINT32)sizeof(TrainFlyProtectStru));
			copyIndex += (UINT32)sizeof(TrainFlyProtectStru);
		}
		ret = copyIndex;
	}
	return ret;
}

/**
* @brief 获取飞车宕机跟随数据
* @param UINT8 *pDataBuff 跟随数据存储缓冲区
* @param UINT32 curIndex 当前索引
* @return 计算后的索引
*/
UINT32 SeFlyProtectTransferData(IN UINT8 *pDataBuff, IN UINT32 curIndex)
{
	UINT32 ret = curIndex;
	UINT32 copyIndex = curIndex;
	UINT8 chIndex = 0u;
	
	if (NULL != pDataBuff)
	{
		gFlyTrainCnt = pDataBuff[copyIndex++];
		for (chIndex = 0u; chIndex < SHUT_DOWN_TRAIN_NUMMAX; chIndex++)
		{
			(void)CommonMemSet(&gFlyTrainData[chIndex], (UINT32)sizeof(TrainFlyProtectStru), 0U, (UINT32)sizeof(TrainFlyProtectStru));
		}
		if (SHUT_DOWN_TRAIN_NUMMAX >= gFlyTrainCnt)
		{
			for (chIndex = 0u; chIndex < gFlyTrainCnt; chIndex++)
			{
				(void)CommonMemCpy(&gFlyTrainData[chIndex], (UINT32)sizeof(TrainFlyProtectStru), &pDataBuff[copyIndex], (UINT32)sizeof(TrainFlyProtectStru));
				copyIndex += (UINT32)sizeof(TrainFlyProtectStru);
			}
		}
		else
		{
			; /*数据溢出*/
		}
		ret = copyIndex;
	}
	return ret;
}

/*
* 功能描述： 设置指定列车飞车防护起始周期
* 参数说明： const UINT16 wTrainId, 列车ID
*			 const UINT32 dwCycNum 列车开始飞车起始周期
* 返回值  ： 无
* by cgh 20241028
*/
void SetTrainFlyProStartCycNum(const UINT16 wTrainId, const UINT32 dwCycNum)
{
	UINT16 wBufIndex = 0U;
	UINT32 dwFlyStartCyc = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if (0U == dwCycNum)
		{
			/*要设置的周期号为0，则直接设置*/
			gstTrainInfo[wBufIndex].dwStartFlyCycNum = 0U;
		}
		else
		{
			dwFlyStartCyc = GetTrainStartFlyProtectCycNum(wTrainId);
			if (0U == dwFlyStartCyc)
			{
				gstTrainInfo[wBufIndex].dwStartFlyCycNum = dwCycNum; 
			}
			else
			{
				; /*当前已有有效周期不重新设置*/
			}
		}
	}
	else
	{
		;
	}
}

/*
* 功能描述：设置指定列车区间疏散命令状态
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT8 chEaCmdState 区间疏散命令状态
* 返 回 值：无
* by cgh 20250310
*/
void SetTrainEaCmdState(const UINT16 wTrainId, const UINT8 chEaCmdState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_EA_CMD_STATE_VALID == chEaCmdState) || (TRAIN_EA_CMD_STATE_INVALID == chEaCmdState))
		{
			gstTrainInfo[wBufIndex].chEaCmdState = chEaCmdState;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车区间疏散命令状态
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0x55 区间疏散命令状态有效
*           0xAA 区间疏散命令状态有效
* by cgh 20250310
*/
UINT8 GetTrainEaCmdState(const UINT16 wTrainId)
{
	UINT8 cRetVal = TRAIN_EA_CMD_STATE_VALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		cRetVal = gstTrainInfo[wBufIndex].chEaCmdState;
	}
	else
	{
		/*返回默认值*/
	}

	return cRetVal;
}

/*
* 功能描述：试车线非试车期间清除飞车信息
* 参数说明：无
* 返 回 值：无
* Created By LQ 2025.04.02
*/
void ScxClearFlyProtectInfo(void)
{
	UINT8 ii = 0U;

	/*清除所有列车飞车起始周期*/
	for (ii = 1U; ii < TRAIN_SUM_MAX; ii++)
	{
		gstTrainInfo[ii].dwStartFlyCycNum = 0U;
	}

	/*清除飞车宕机报警列车信息*/
	gFlyTrainCnt = 0U;
	(void)CommonMemSet(&gFlyTrainData, (UINT32)(SHUT_DOWN_TRAIN_NUMMAX * sizeof(TrainFlyProtectStru)), 0U, (UINT32)(SHUT_DOWN_TRAIN_NUMMAX * sizeof(TrainFlyProtectStru)));

	/*清除飞车宕机报警起始周期*/
	gFlyProtectOverCyc = 0U;
}

/*
* 功能描述：AG列车驶出AG检查
* 参数说明：const UINT16 wLinkId  link ID
* 返 回 值：CI_ERROR  不是AG列车正常驶出AG
*           CI_SUCCESS 是AG列车正常驶出AG
* BY CGH 202050718
*/
UINT8 AgTrainLeaveAgCheck(const UINT16 wLinkId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 chAGorBGAttr = 0U;/*ABG属性*/
	UINT16 wAGRelBGLinkId = 0U;  /*AGLink关联的BGlink*/
	UINT16 wAGRelOrgLinkId = 0U;  /*AG起点相连的link*/
	UINT16 wAGRelTmlLinkId = 0U;  /*AG终点相连的link*/
	UINT8 chOrgLinkAttr = LINK_REL_PHYSEC_DEFAULT;
	UINT8 chTmlLinkAttr = LINK_REL_PHYSEC_DEFAULT;
	UINT16 wAGAxleSecId = 0U; /*AG计轴区段ID*/
	UINT16 wDGLinkId = 0U;  /*DGlink*/
	UINT16 wDGAxleSecId = 0U;/*DG计轴区段ID*/
	UINT16 wBGAxleSecId = 0U;/*BG计轴区段ID*/
	UINT8 chSecRelEnvelopeCnt = 0U; /*区段关联包络数目*/
	UINT16 szSecEnvelopeIds[SECTION_REL_ENVELOPE_SUM_MAX] = { 0U }; /*区段关联包络数据*/
	const EnvelopeStruct* pTempDgEnvelope = NULL; /*DG包络数据*/
	UINT8 chAgRelEnvelopeCnt = 0U; /*AG关联包络数目*/
	UINT16 szAgEnvelopeIds[SECTION_REL_ENVELOPE_SUM_MAX] = { 0U }; /*AG关联包络数据*/
	const EnvelopeStruct* pTempAgEnvelope = NULL; /*AG包络数据*/
	UINT8 chVirHeadScreenPassFlag = 0U; /*虚拟前筛标志*/
	UINT8 chVirTailScreenPassFlag = 0U; /*虚拟后筛标志*/
	UINT8 ii = 0U;
	UINT32 errorCode = 0U;

	chAGorBGAttr = GetLinkRelPhySecAGorBGAttr(wLinkId);  /*获取AG/BG属性*/

	if (LINK_REL_PHYSEC_AG == chAGorBGAttr)
	{
		wAGAxleSecId = GetLinkBelongAcId(wLinkId);
		wAGRelOrgLinkId = GetLinkOrgnJointMainLkIdById(wLinkId);
		wAGRelTmlLinkId = GetLinkTmnlJointMainLkById(wLinkId);
		chOrgLinkAttr = GetLinkRelPhySecAGorBGAttr(wAGRelOrgLinkId);
		chTmlLinkAttr = GetLinkRelPhySecAGorBGAttr(wAGRelTmlLinkId);

		if (LINK_REL_PHYSEC_BG == chOrgLinkAttr)
		{
			wAGRelBGLinkId = wAGRelOrgLinkId;
			wDGLinkId = wAGRelTmlLinkId;
		}
		else if (LINK_REL_PHYSEC_BG == chTmlLinkAttr)
		{
			wAGRelBGLinkId = wAGRelTmlLinkId;
			wDGLinkId = wAGRelOrgLinkId;
		}
		else
		{
			/*AG与BG未直接相连，即存在CG*/
		}

		if (0U != wAGRelBGLinkId)
		{
			/*无CG*/
			chAgRelEnvelopeCnt = elm_GetEnvelopeIDsInAC(wAGAxleSecId, szAgEnvelopeIds);
			if (1U == chAgRelEnvelopeCnt)
			{
				pTempDgEnvelope = elm_GetEnvelopeInfoByID(szAgEnvelopeIds[0]);

				if (NULL != pTempDgEnvelope)
				{
					wDGAxleSecId = GetLinkBelongAcId(wDGLinkId);
					wBGAxleSecId = GetLinkBelongAcId(wAGRelBGLinkId);

					for (ii = 0U; ii < pTempDgEnvelope->ACCnt; ii++)
					{
						if (wBGAxleSecId == pTempDgEnvelope->ACID[ii])
						{
							/*是包络延伸到BG*/
							break;
						}
						else
						{
							; /*继续检查*/
						}
					}

					if (ii == pTempDgEnvelope->ACCnt)
					{
						/* 获取DG计轴关联的包络数量 */
						chSecRelEnvelopeCnt = elm_GetEnvelopeIDsInAC(wDGAxleSecId, szSecEnvelopeIds);
					}
					else
					{
						/* 获取BG计轴关联的包络数量 */
						chSecRelEnvelopeCnt = elm_GetEnvelopeIDsInAC(wBGAxleSecId, szSecEnvelopeIds);
					}


					if ((1U == chSecRelEnvelopeCnt) && (szSecEnvelopeIds[0] == szAgEnvelopeIds[0]))
					{
						chVirHeadScreenPassFlag = GetTrainVirHeadScreenPassFlag(pTempDgEnvelope->trainID[0]);
						chVirTailScreenPassFlag = GetTrainVirTailScreenPassFlag(pTempDgEnvelope->trainID[0]);

						if (((0U == pTempDgEnvelope->headTrainID) || ((pTempDgEnvelope->endPos.Lnk == wLinkId) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chVirHeadScreenPassFlag))) &&
							((0U == pTempDgEnvelope->tailTrainID) || ((pTempDgEnvelope->startPos.Lnk == wLinkId) && (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chVirTailScreenPassFlag))))
						{
							/*无可疑，反馈正常驶出
							（排除场景；虚拟筛选标志清除在位置监督之后，当包络延伸至DG的同时出现占用，CT包络添加可疑但此时虚拟筛选标志是有效的，不能认为无可疑）*/
							chRetVal = CI_SUCCESS;
						}
						else
						{
							errorCode += 0x04000000U;
						}
					}
					else
					{
						/*返回非AG列车正常驶出*/
						errorCode += 0x08000000U;
					}
				}
				else
				{
					/*返回非AG列车正常驶出*/
					errorCode += 0x10000000U;
				}
			}
			else
			{
				/*返回非AG列车正常驶出*/
				errorCode += 0x20000000U;
			}		
		}
		else
		{
			errorCode += 0x40000000U;
		}
	}
	else
	{
		/*非AG不处理*/
		errorCode += 0x80000000U;
	}

	debug_infor_printf((const)"\nAgTrainLeaveAgCheck Error errorCode:0x%08x\n", errorCode);

	return chRetVal;
}

/*
* 功能描述：设置指定列车向后跳跃允许状态
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT8 chJumpBackReplyState 向后跳跃允许状态
* 返 回 值：无
* by fan 20250725
*/
void SetTrainJumpBackReplyState(const UINT16 wTrainId, const UINT8 chJumpBackReplyState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_JUMP_BACK_STATE_VALID == chJumpBackReplyState) || (TRAIN_JUMP_BACK_STATE_INVALID == chJumpBackReplyState)
			|| (TRAIN_JUMP_BACK_STATE_NONE == chJumpBackReplyState))
		{
			gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackReplyState = chJumpBackReplyState;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车向后跳跃允许状态
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0x55 允许 0xAA 不允许 0x00 无申请/默认值
* by fan 20250725
*/
UINT8 GetTrainJumpBackReplyState(const UINT16 wTrainId)
{
	UINT8 cRetVal = TRAIN_JUMP_BACK_STATE_NONE;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		cRetVal = gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackReplyState;
	}
	else
	{
		/*返回默认值*/
	}

	return cRetVal;
}
/*
* 功能描述：设置指定列车向后跳跃申请状态
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT8 chJumpBackApplyState 向后跳跃允许状态
* 返 回 值：无
* by fan 20250725
*/
void SetTrainJumpBackApplyState(const UINT16 wTrainId, const UINT8 chJumpBackApplyState)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((TRAIN_JUMP_BACK_STATE_VALID == chJumpBackApplyState) || (TRAIN_JUMP_BACK_STATE_INVALID == chJumpBackApplyState))
		{
			gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackApplyState = chJumpBackApplyState;
		}
		else
		{
			/*不处理*/
		}
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车向后跳跃申请状态
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：0x55 申请 0xAA 未申请
* by fan 20250725
*/
UINT8 GetTrainJumpBackApplyState(const UINT16 wTrainId)
{
	UINT8 cRetVal = TRAIN_JUMP_BACK_STATE_INVALID;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		cRetVal = gstTrainInfo[wBufIndex].strJumpBackData.chJumpBackApplyState;
	}
	else
	{
		/*返回默认值*/
	}

	return cRetVal;
}
/*
* 功能描述：设置指定列车向后跳跃申请序列号
* 参数说明：const UINT16 wTrainId 列车ID
*	 		const UINT32 dwJumpBackSN向后跳跃申请序列号
* 返 回 值：无
* by fan 20250725
*/
void SetTrainJumpBackApplySN(const UINT16 wTrainId, const UINT32 dwJumpBackSN)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strJumpBackData.dwJumpBackApplySn = dwJumpBackSN;
	}
	else
	{
		/*不处理*/
	}
}

/*
* 功能描述：获取指定列车向后跳跃申请序列号
* 参数说明：const UINT16 wTrainId 列车ID
* 返 回 值：UINT32 申请序列号
* by fan 20250725
*/
UINT32 GetTrainJumpBackApplySN(const UINT16 wTrainId)
{
	UINT32 dwRetVal = 0U;
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		dwRetVal = gstTrainInfo[wBufIndex].strJumpBackData.dwJumpBackApplySn;
	}
	else
	{
		/*返回默认值*/
	}

	return dwRetVal;
}

/*
* 功能描述： 清除列车安全车头方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：void
* by cgh 20250818
*/
void ClearTrainSafeHeadDir(const UINT16 wTrainId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.chHeadDir = 0U;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 清除列车安全车尾方向
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ：void
* by cgh 20250818
*/
void ClearTrainSafeTailDir(const UINT16 wTrainId)
{
	UINT16 wBufIndex = 0U;

	wBufIndex = GetTrainBufIndex(wTrainId);
	if (TRAIN_SUM_MAX > wBufIndex)
	{
		gstTrainInfo[wBufIndex].strSafeLoc.chTailDir = 0U;
	}
	else
	{
		;
	}
}

/*
* 功能描述： 检查列车是否完全在同一休眠唤醒轨
* 参数说明： const UINT16 wTrainId, 列车ID
* 返回值  ： CI_ERROR: 列车不完全在同一休眠唤醒轨
*		     CI_SUCCESS: 列车完全在同一休眠唤醒轨
* by cgh 20250915
*/
UINT8 CheckTrainIsSwTrack(const UINT16 wTrainId)
{
	UINT8 chRetVal = CI_ERROR;
	UINT16 wBufIndex = 0U;
	UINT8 chSleepFlag = 0U;  /*休眠轨判断标志*/

	wBufIndex = GetTrainBufIndex(wTrainId);

	if (TRAIN_SUM_MAX > wBufIndex)
	{
		if ((gstTrainInfo[wBufIndex].wTrainMinTailLink == gstTrainInfo[wBufIndex].wTrainMaxHeadLink)
			&& (0U < gstTrainInfo[wBufIndex].wTrainMaxHeadLink) && (LINK_SUM_MAX > gstTrainInfo[wBufIndex].wTrainMaxHeadLink))
		{
			chSleepFlag = IsLinkSwTrack(gstTrainInfo[wBufIndex].wTrainMaxHeadLink);

			if (CI_SUCCESS == chSleepFlag)
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				;
			}
		}
		else
		{
			; /*不完全在同一休眠唤醒轨*/
		}
	}
	else
	{
		;
	}

	return chRetVal;
}

/*
* 功能描述： 检查列车是否为可追踪UT场景
* 参数说明： const UINT16 wEnvelopeID, 包络ID
* 返回值  ： CI_ERROR: 否
*		     CI_SUCCESS: 是
* by cgh 20250915
*/
UINT8 CheckTrainIsFollowUt(const UINT16 wEnvelopeID)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 chNoCGFollowUtSwitch = 0U;
	const EnvelopeStruct* pEnvelop = NULL;
	UINT8 chTrainHeadRelAbgAttr = 0U; /*列车头关联ACG属性*/
	UINT8 chTrainTailRelAbgAttr = 0U; /*列车尾关联ACG属性*/

	chNoCGFollowUtSwitch = GetNoCGFollowUtSwitch();
	if (FUNC_SWITCH_ON == chNoCGFollowUtSwitch)
	{
		pEnvelop = elm_GetEnvelopeInfoPtr(wEnvelopeID);

		if (NULL != pEnvelop)
		{
			chTrainHeadRelAbgAttr = GetLinkRelPhySecAGorBGAttr(pEnvelop->endPos.Lnk);
			chTrainTailRelAbgAttr = GetLinkRelPhySecAGorBGAttr(pEnvelop->startPos.Lnk);

			if ((LINK_REL_PHYSEC_AG == chTrainHeadRelAbgAttr) || (LINK_REL_PHYSEC_BG == chTrainHeadRelAbgAttr)
				|| (LINK_REL_PHYSEC_AG == chTrainTailRelAbgAttr) || (LINK_REL_PHYSEC_BG == chTrainTailRelAbgAttr))
			{
				chRetVal = CI_SUCCESS;
			}
			else
			{
				; /*完全不在ABG*/
			}
		}
		else
		{

		}
	}
	else
	{
		; /*功能开关关闭*/
	}

	return chRetVal;
}

/*
* 功能描述：获取使用NVRAM且位置监督无效的飞车ID
* 参数说明：UINT8 chIndex 索引
* 返 回 值：UINT16* gNvramFlyTrainId 使用NVRAM且位置监督无效的飞车ID
* Created By LQ 2025.09.15
*/
UINT16* GetNvramFlyProtectId(void)
{
	return gNvramFlyTrainId;
}

/*
* 功能描述：获取使用NVRAM且位置监督无效的飞车数量
* 参数说明：无
* 返 回 值：UINT8 gNvramFlyTrainCnt 使用NVRAM且位置监督无效的飞车数量
* Created By LQ 2025.09.15
*/
UINT8 GetNvramFlyProtectNum(void)
{
	return gNvramFlyTrainCnt;
}

/**
* 功能描述：添加使用NVRAM且位置监督无效的飞车数据
* 参数说明：UINT16 wTrainID 列车ID
* 返 回 值：无
* Created By LQ 2025.09.15
*/
void AddNvramFlyingTrain(UINT16 wTrainID)
{
	UINT8 ii = 0U;

	if (SHUT_DOWN_TRAIN_NUMMAX > gNvramFlyTrainCnt)
	{
		for (ii = 0U; ii < gNvramFlyTrainCnt; ii++)
		{
			if (gNvramFlyTrainId[ii] == wTrainID)
			{
				break;  /*已存在，停止遍历*/
			}
			else
			{
				/*继续遍历比较*/
			}
		}

		if (ii == gNvramFlyTrainCnt)
		{
			gNvramFlyTrainId[gNvramFlyTrainCnt] = wTrainID;
			gNvramFlyTrainCnt++;
		}
		else
		{
			; /*已添加，不再重复添加*/
		}
	}
	else
	{
		; /*不添加*/
	}
}

/**
* 功能描述：清除使用NVRAM且位置监督无效的飞车数据
* 参数说明：无
* 返 回 值：无
* Created By LQ 2025.09.15
*/
void ClearNvramFlyingTrain(void)
{
	gNvramFlyTrainCnt = 0U;
	(void)CommonMemSet(gNvramFlyTrainId, (UINT32)(sizeof(UINT16) * SHUT_DOWN_TRAIN_NUMMAX), 0U, (UINT32)(sizeof(UINT16) * SHUT_DOWN_TRAIN_NUMMAX));
}