/********************************************************
*                                                                                                            
* 文 件 名： ParseAtsData.c   
* 版权说明： 北京交控科技有限公司 
* 创建时间： 2012-03-28
* 作    者： 联锁组
* 功能描述： ATS数据解析
* 修改记录：   
*
********************************************************/ 

#include "ParsePackAtsData.h"
#include "../DataManage/DeviceConfigDataManage.h"
#include "ParsePackPSCData.h"
#include "ParsePackOcData.h"
#include "dsuRssp2Func.h"
#include "dquCIInterFace.h"
#include "../IO/OutputDataProcess.h"
#include "EnvelopeManageAPI.h"
#include "../DataManage/PlatDataManage.h"
#include "../IO/InputDataProcess.h"

/*解包使用*/
CommandDataStruct CiRevCmdDataStru[ATSORXIANDI_TO_CI_CMD_DATA_STRU_SUM_MAX] = {0u}; /*CI操作命令结构体数组*/
UINT16 CiRevCmdStruCurSum = 0u;	    /*CI操作命令结构体数组长度*/
/*解包使用*/
CommandDataStruct ATSorXDToCiCmdRtnToTRDataStru[ATSORXIANDI_TO_CI_CMD_DATA_STRU_SUM_MAX] = {0u}; /*ATS或现地到CI信号特开操作命令结构体数组*/
UINT16 ATSorXDToCiCmdReturnToTRCurSum = 0u;	    /*ATS或现地到CI信号特开操作命令结构体数组长度*/

/*组包使用*/
CommandDataStruct CiSendCmdDataStru[CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX] = {0u}; /*CI操作命令反馈结构体数组*/
UINT16 CiSendCmdStruCurSum = 0u;	    /*CI操作命令反馈结构体数组长度*/
/*暂存反馈*/
CommandDataStruct CiSendBackDataTempStru[CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX] = {0u}; /*CI操作命令反馈临时数组*/
UINT16 CiSendBackDataTempStruSum = 0u;	    /*CI操作命令反馈结构体临时数组长度*/

/*最近一次操作命令来源系统类型*/
UINT8 LastCmdSourceSysType = 0u;

/*首次操作确认的命令ID*/
UINT32 FirstCmdId;      /*首次操作确认的命令ID号*/

PSCToCiDataStruct* pscCiSendToAtsDataStru = NULL;

/*
* 功能描述： 组包Ci到Ats逻辑区段已征用信息
* 参数说明： const UINT8* pDataBuf, 数据缓冲区
*            const UINT16 *wDataLength, 数据长度 输出参数
* 返回值  ： CI_ERROR 失败
*			 CI_SUCCESS 成功
*/
static UINT8 PackCiToAtsLgcSgmtInfo(UINT8* pDataBuf, UINT16* wDataLength);


/*
* 功能描述： 转换Ci到ATS中OCbyte双系电源状态信息
* 参数说明：入参
*            UINT8 PowerState, 电源状态
*			出参
*			无
* 返回值  ： 转换后的电源状态
*/
static UINT8 TransCiToAtsPowerState(UINT8 PowerState);

/*
* 功能描述： 转换Ci到ATS中OCbyte风扇状态信息
* 参数说明：入参
*            UINT8 fanState, 风扇状态
*			出参
*			无
* 返回值  ： 转换后的风扇状态
*/
static UINT8 TransCiToAtsFanState(UINT8 fanState);

/*
* 功能描述： 转换Ci到ATS中OCbyte设备故障状态信息
* 参数说明：入参
*            UINT8 ocDevFaultState, OC设备故障状态
*			出参
*			无
* 返回值  ： 转换后的设备故障状态
*/
static UINT8 TransCiToAtsOcDevFaultState(UINT8 ocDevFaultState);

/*
* 功能描述： 转换Ci到ATS中PSC 工作状态表示灯状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscState  psc工作状态表示灯状态
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscState);

/*
* 功能描述： 转换Ci到ATS中PSC 各状态表示灯信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscState  psc工作状态表示灯状态
*			UINT8 BitValY  if成立要左移的宏值数据
*			UINT8 BitValN  if不成立要左移的宏值数据
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscState, UINT8 BitValY, UINT8 BitValN);

/*
* 功能描述： 转换Ci到ATS中PSC 各类型状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscStatetype	psC状态对应类型
*			UINT8 PscState  psc对应类型状态
*			UINT8 BitValY  if成立要左移的宏值数据
*			UINT8 BitValN  if不成立要左移的宏值数据
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCtypeState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscStatetype, UINT8 PscState, UINT8 BitValY, UINT8 BitValN);

/*
* 功能描述： 转换Ci到ATS中PSD 驱动电源状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd驱动电源状态信息
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsDrvWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState);

/*
* 功能描述： 转换Ci到ATS中PSD 控制电源状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd控制电源状态信息
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsCtlWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState);

/*
* 功能描述： 转换Ci到ATS中PSD 边缘控制器状态
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd边缘控制器状态
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSDEdgeState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState);

/*
* 功能描述： 解析操作命令数据帧
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功 
* 修复bug YF0083-210
*/
UINT8 ParseAtsOrXianDiToCiDataFrame(const UINT8* dataBuf, const UINT16 dataLength)
{
	UINT8 sourceId = 0u;		/*源ID*/
	UINT8 sourceType = 0u;   /*源系统类型*/
	UINT8 targetId = 0u;		/*目标ID*/
	UINT8 targetType = 0u;   /*目标系统类型*/
	UINT32 systemTimeH = 0u;		/*系统时间高4字节*/
	UINT32 systemTimeL = 0u;		/*系统时间低4字节*/
	UINT16 commandTotalLen = 0u; /*命令总长度*/
	UINT16 commandTotalSum = 0u; /*命令总数量*/
	UINT8 commandLenth = 0u;	/*本条命令长度*/
	UINT16 ii = 0u;
	UINT16 jj = 0u;
	UINT16 dwIndex = 0u;
	UINT32 dataCheckInfo = 0u;	/*数据版本校验信息*/
	UINT32 interfacePrtclVer = 0u;	/*接口协议版本，暂时预留*/
	UINT32 emapCrcInfo = 0u;
	UINT8 localCiId = 0u;
	UINT8 ciEmapCheck = 0u;
	UINT8 systemtype = 0u;
	UINT8 chRetVal = CI_ERROR;
	UINT8 chKeepWork = CI_ERROR;
	UINT16 preAtsRouteSteCmdNum = 0u; /*检查ATS进路办理命令数*/
	UINT16 wCmdStartByteNum = 0u;/*单条命令长度校验用*/
	UINT16 wParseCmdLength = 0u;
	UINT8 chSecIndex = 0u;
	UINT32 dwHlhtTrainId = 0u;/*互联互通列车编号*/
	UINT16 wTrainId = 0;/*列车ID 高字节类型，低字节编号*/
	UINT16 logId = 0;/*vobc时是使用端编号 1-TC1 2-TC2 0-2IP车（首尾冗余车）*/
	UINT8 chCmdType = 0u;
	UINT32 dwCmdParam = 0u;
	UINT32 dwCmdId = 0u;
	UINT16 wTerminalId = 0u;
	UINT8 chVirCi = 0u;
	UINT8 chSectionNum = 0u;
	UINT8 chToaCmdNum = 0u;
	UINT32 dwCmdParam_DevID = 0u;
	UINT16 dwCmdParam_Type = 0u;
	UINT8 dwCmdParam_Param = 0u;
	UINT16 oVerlap_RouteId = 0U;

	if ((NULL!= dataBuf) && (0u < dataLength))
	{
		sourceType = dataBuf[ii++];                     /*获取数据包来源设备类型*/
		sourceId = dataBuf[ii++];			            /*获取数据包来源设备ID*/
		targetType= dataBuf[ii++];                      /*获取数据包目标设备类型*/
		targetId = dataBuf[ii++];			            /*获取数据包目标设备ID*/
		dataCheckInfo = LongFromChar(&dataBuf[ii]);		/*获取数据版本校验信息4字节*/
		ii += 4u;
		/*数据校验信息比较*/
		ciEmapCheck = GetCiEmapCheckVer(targetId,&emapCrcInfo,sourceType);
		if (CI_SUCCESS == ciEmapCheck)
		{
			chRetVal = CI_SUCCESS;
			chKeepWork = CI_SUCCESS;

			if (dataCheckInfo != emapCrcInfo)
			{
#if 0
				/*给ATS或现地反馈数据版本校验失败信息*/
				if ((CI_SYSTEM_TYPE_XIANDI == sourceType) || ((CI_SYSTEM_TYPE_ATS == sourceType)))
				{
					SetCiSendCmdBackInfoData(CI_BACK_DATA_VER_CHECK_FAIL, sourceType, sourceId, 0, 0);
				}
#endif
				chRetVal = CI_ERROR;
			}
		}
		else
		{
			chRetVal = CI_ERROR;
		}
		if (CI_ERROR != chRetVal)
		{
			interfacePrtclVer = LongFromChar(&dataBuf[ii]);		/*获取接口协议版本信息4字节*/
			ii += 4u;
			systemTimeH = LongFromChar(&dataBuf[ii]);		/*获取系统时间高4字节*/
			ii += 4u;
			systemTimeL = LongFromChar(&dataBuf[ii]);		/*获取系统时间低4字节*/
			ii += 4u;
			commandTotalLen = ShortFromChar(&dataBuf[ii]);	/*获取数据包总长度*/
			ii += 2u;

			localCiId = GetSystemParaLocalCiId();
			systemtype = Get2oo2SheBeiType();
			if ((targetType != systemtype) || (targetId != localCiId)
				|| ((CI_SYSTEM_TYPE_XIANDI != sourceType) && (CI_SYSTEM_TYPE_ATS != sourceType)))
			{/*数据不合法*/

				chKeepWork = CI_ERROR;
			}

			if (0u == commandTotalLen)
			{/*无命令数据*/

				chKeepWork = CI_ERROR;
			}

			if (CI_ERROR != chKeepWork)
			{
				commandTotalSum = ShortFromChar(&dataBuf[ii]);	/*获取数据包命令帧总数量*/
				ii += 2u;
				if ((0u == commandTotalSum) || (ATSORXIANDI_TO_CI_CMD_DATA_STRU_SUM_MAX < commandTotalSum))
				{/*命令数量为0*/

					chRetVal = CI_ERROR;
				}
				else
				{
					/** 检查命令数据总长度的有效性*/
					chRetVal = CheckATSorXiandTotalDataLenVal(&dataBuf[ii], commandTotalSum, commandTotalLen);
					
				}
				
				if (CI_ERROR != chRetVal)
				{
					/*先获取上一周期是存储进路办理命令数*/
					preAtsRouteSteCmdNum = GetCiRevCmdStruCurSum();
					/*解析命令*/
					for (jj = preAtsRouteSteCmdNum; jj < (commandTotalSum + preAtsRouteSteCmdNum); jj++)
					{
						/*安全防护*/
						if (ATSORXIANDI_TO_CI_CMD_DATA_STRU_SUM_MAX > jj)
						{
							commandLenth = dataBuf[ii++];/*获取本条命令长度*/
							wCmdStartByteNum = ii;  /*本条命令长度不包含命令长度本身*/
							chCmdType = dataBuf[ii++];			/*获取命令类型*/
							dwCmdId = LongFromChar(&dataBuf[ii]);	/*获取命令编号*/
							ii += 4u;
							dwCmdParam = LongFromChar(&dataBuf[ii]);/*获取命令参数*/
							ii += 4u;
							wTerminalId = ShortFromChar(&dataBuf[ii]);/*获取终端ID*/
							ii += 2u;

							oVerlap_RouteId = ShortFromChar(&dataBuf[ii]);/*获取保护区段关联进路ID*/
							ii += 2U;

							/*以下预留*/
							ii += 2U;
							chVirCi = dataBuf[ii++];/*虚拟联锁ID*/
																		 /*预留*/
							ii++;

							/*车车新加*/
							dwHlhtTrainId = LongFromChar(&dataBuf[ii]);
							ii += 4u;
							(void)dquHlhtId2VobcName(dwHlhtTrainId, &wTrainId, &logId);/*4字节互联互通编号转2字节*/

							chSectionNum = dataBuf[ii++];/*区段数量,命令类型为0x93,0x94代表逻辑区段数量，0x0b,0x0c代表物理区段数量*/
							/*对命令编号、命令设备ID进行防护*/
							dwCmdParam_DevID = dwCmdParam & 0xffff0000u;
							dwCmdParam_Type = (UINT16)(dwCmdParam & 0x0000ff00u);
							dwCmdParam_Param = (UINT8)(dwCmdParam & 0x000000ffu);			/*增加防护，YF0083-227缺陷修复*/
							if ((0xffffffffu == dwCmdId) || (0xffff0000u == dwCmdParam_DevID)||
								(0x0000ff00u == dwCmdParam_Type)||(0x000000ffu == dwCmdParam_Param))
							{
								chRetVal = CI_ERROR;
							}
							else
							{
								if ((ATS_CMD_SET_PHYSEC_ERR == chCmdType)
									|| (ATS_CMD_CANCEL_PHYSEC_FIRST == chCmdType)
									|| (ATS_CMD_CANCEL_PHYSEC_SECOND == chCmdType)
									|| (ATS_CMD_TOA_RESET_FIRST == chCmdType)
									|| (ATS_CMD_TOA_RESET_SECOND == chCmdType))
								{
									chToaCmdNum++;
									chRetVal = ToaAddCmd(chCmdType, wTrainId, dwCmdId, wTerminalId, chVirCi, dwCmdParam);
									if ((CI_SUCCESS == chRetVal) && (0u != chSectionNum))
									{
										chRetVal = CI_ERROR;
									}
									else
									{
										;
									}
								}
								else
								{
									CiRevCmdDataStru[jj].CommandType = chCmdType;			/*获取命令类型*/
									CiRevCmdDataStru[jj].CommandId = dwCmdId;	/*获取命令编号*/
									CiRevCmdDataStru[jj].CommandParam = dwCmdParam;/*获取命令参数*/
									CiRevCmdDataStru[jj].termial_id = wTerminalId;/*获取终端ID*/
									CiRevCmdDataStru[jj].VirCIid = chVirCi;/*虚拟联锁ID*/
									CiRevCmdDataStru[jj].wTrainIdParam = wTrainId;  /* 列车ID*/
									CiRevCmdDataStru[jj].OverLapRouteID = oVerlap_RouteId;  /* 保护区段关联进路ID*/

									CiRevCmdDataStru[jj].chSectionSum = chSectionNum;/*区段数量*/
									if (MAX_ROUTE_IN_LT_NUM > CiRevCmdDataStru[jj].chSectionSum)
									{
										for (chSecIndex = 0u; chSecIndex < CiRevCmdDataStru[jj].chSectionSum; chSecIndex++)
										{
											CiRevCmdDataStru[jj].wSectionData[chSecIndex] = ShortFromChar(&dataBuf[ii]);/*区段ID序列，命令类型为0x93,0x94代表逻辑区段序列，0x0b,0x0c代表物理区段序列*/
											ii += 2u;
										}
									}
									else
									{
										/*数量错误，数组越界风险*/
										chRetVal = CI_ERROR;
									}
								}
							}
							if (CI_SUCCESS == chRetVal)
							{
								/*单条命令长度校验*/
								wParseCmdLength = (UINT16)(ii - wCmdStartByteNum);
								if (commandLenth != wParseCmdLength)
								{/*命令长度出错*/
									chRetVal = CI_ERROR;
									
								}
								else
								{
									chRetVal = CI_SUCCESS;
								}
							}
							else
							{
								;
							}
							
							if (CI_ERROR == chRetVal)
							{/*包内有数据错误，丢包处理*/
								/*清除这本包数据*/
								ToaClearCmd();
								commandTotalSum = 0u;
								for (dwIndex = preAtsRouteSteCmdNum; dwIndex <= jj; dwIndex++)
								{
									(void)CommonMemSet(&CiRevCmdDataStru[dwIndex], (UINT32)sizeof(CommandDataStruct), 0u, (UINT32)sizeof(CommandDataStruct));
								}
								break;
							}
							else
							{
								/*无操作*/
							}

						}
					}

					/*命令数量更新*/
					if (CI_SUCCESS == chRetVal)
					{
						CiRevCmdStruCurSum = commandTotalSum - chToaCmdNum + preAtsRouteSteCmdNum;/*命令总数*/
					}
					else
					{
						CiRevCmdStruCurSum = preAtsRouteSteCmdNum;/*只记录上周期存储的命令*/
					}
					

					if (dataLength < ii)
					{
						CiRevCmdStruCurSum = 0u;
						chRetVal = CI_ERROR;
					}
					else
					{
						/*无操作*/
					}

					LastCmdSourceSysType = sourceType;/*设置最近一次操作命令来源系统类型*/
				}
				
			}
			
		}
		
	}
	else
	{
		/*数据无效*/
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 组ATS或现地数据
* 参数说明： QueueStruct* ciToAtsDataQueue, 组包发送队列地址   
*            const UINT8 deviceId, 目标系统ID
*            const UINT8 targetDevType, 目标系统类型
*            const UINT8 frame,帧类型
* 返回值  ： 0: 组包失败
*			 1: 组包成功      
*/
UINT8 PackCiToAtsOrXianDiData(const UINT8 deviceId, const UINT8 targetDevType, const UINT8 frame)
{
	UINT8 localCi = 0u;	                                                                           /*本地联锁ID*/
	UINT8 ciToXianDiDataBuffer[CI_TO_ATS_DATA_LEN_MAX] = { 0u };                                  /*CI到现地组帧数组*/
	UINT16 SendMaskSum = 0u;	                                                                   /*码位总字节数*/
	UINT16 indicatorId = 0u;                                                                     /*表示灯报警灯ID*/
	UINT16 ii = 0u;                                                                             /*游标*/
	UINT16 jj = 0u;                                                                             /*游标*/
	UINT8 kk = 0u;                                                                              /*游标*/
	UINT16 m = 0u;
	UINT8 n = 0u;
	UINT8 mm = 0U;																				/*执行电插箱游标*/
	UINT16 curIndex = 0u;                                                                       /*游标*/
	UINT8 pscId = 0u;

	UINT8 transmitState = 0u;
	UINT8 pscConfirmFlag = 0u;

	UINT32 emapCrcInfo = 0u;	/*数据版本校验CRC信息*/
	UINT32 interfacePrtclVer = 0u;	/*接口协议版本，暂时预留*/
	UINT16 deviceSum = 0u;               /*设备总数*/
	UINT8* pDeviceIdBuf = NULL;         /*设备ID数组*/

	UINT16 ocDeviceSum = 0u;/*OC设备总数*/
	UINT8* pOcDeviceIdBuf = NULL;         /*OC设备ID数组*/
	UINT16 ocId = 0u;
	UINT8 powerAState = 0u;/*A系电源状态，新增。0x55-双路空开正常，0xaa-单路空开异常，0xFF-双路空开异常*/
	UINT8 powerBState = 0u;/*B系电源状态，新增。0x55-双路空开正常，0xaa-单路空开异常，0xFF-双路空开异常*/
	UINT8 ocDevFaultState = 0u;/*OC设备故障状态，新增。0x55-板卡正常，0xFF-板卡故障*/
	UINT8 fanState = 0u;
	UINT8 ciAndOcCommState = 0u;/*ci与OC通信状态*/
	UINT32 curCycleNum = 0u;/*当前周期数*/
	UINT8 psdSum = 0u;
	UINT8 psdMutualLockState = 0u;
	UINT8 psdCiId = 0u;
	UINT8 emapCheckState = 0u;
	PSCToCiDataStruct* pscToCiDataStru = GetPscToCiDataStru();
	UINT8 virtualCiNum = 0u;
	UINT8 virtualCIid = 0u;
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT8 indicatorState = 0u;
	UINT16 indicatorNum = 0u;
	UINT8 i = 0u;
	UINT16 dstDevId = 0u;
	UINT8 outnetSafeSendRtn = 0u;
	UINT8 cTiocMode = REVERSE_MODE_SHADOW;
	UINT8 cTiocCutReason = 0u;
	UINT8 cTiocCutState = REVERSE_CUT_STATE_DEFAULT;
	UINT32 dwTrainId = 0u;
	UINT8 cFunRetVal = CI_ERROR;
	UINT8 ocstionPowerIndic = 0U;

	UINT8 indicatorDevId = 0U;
	UINT16 szEnvelopeIdBuf[ENVELOPE_SUM_MAX] = { 0u };
	UINT16 wEnvelopeSum = 0u;
	UINT16 wcomTrainSumIndex = 0u;			/*通信车数量索引*/
	UINT16 comTrainSum = 0U;				/*通信车数量，初始化为0*/
	UINT16 wEnvelopeIndex = 0u;				/*包络索引*/
	InfEnvelopeStruct strEnvelope = { 0u };		/*包络信息相关结构体*/
	UINT16 wEnvelopeId = 0u;
	UINT8 chFunRtn = CI_ERROR;
	UINT32 dwHLHTTrainID = 0u;		/*列车互联互通ID*/
	UINT8 chHeadScreStat = 0u;			/*列车前筛标志*/
	UINT8 chTailScreStat = 0u;			/*列车后筛标志*/
	UINT8 chVirHeadScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;	    /*列车虚拟前筛标志*/
	UINT8 chVirTailScreStat = TRAIN_VIR_SCREEN_PASS_FLAG_INVALID;		/*列车虚拟后筛标志*/
	UINT16 wTrainId = 0u;				/*列车ID*/
	UINT8 cPhySecIndex = 0U;
	UINT8 chRetVal = CI_ERROR;
	UINT8 indicatorType = 0u; /*设备类型*/

	UINT8 wPbNum = 0u;			/*执行电插箱数量*/
	UINT8 hlhtIdFlag = 0U;      /*互联互通ID是否有效*/
	OcToATSPlusBox szSendATSPlusBox[MAX_OC_PLUS_BOX_NUM] = { 0U };	/*输出给ATS的执行电插箱结构体相关信息*/
	UINT16 wDjqySwitchNum = 0U;			/*多机牵引道岔数量*/
	OcToATSSwitchZzjData szSendAtsSwitchZzjData[SWITCH_SUM_MAX] = { 0U };	/*输出给ATS的道岔对应转辙机相关信息*/
	UINT16 wDjqySwitchIndex = 0U;/*多机牵引道岔索引*/
	UINT8 chSwitchZzjStateIndex = 0U;/*多机牵引道岔对应转辙机状态的索引*/

	UINT8 powerANodeState = 0U;/*A系电源状态*/
	UINT8 powerBNodeState = 0U;/*B系电源状态*/
	UINT8 ModeAState = 0U;/*A系电源模块状态*/
	UINT8 ModeBState = 0U;/*B系电源模块状态*/


	localCi = GetSystemParaLocalCiId();	/*获取本地联锁ID*/
	pscCiSendToAtsDataStru = GetPscToCiDataStru(); /*获取Psc-CI的结构体数据*/

	curCycleNum = Get2oo2CurCycleNum();/*获取当前周期号*/

	if (CI_ATS_STATION_FRAME == frame)
	{
		/*开始组应用数据帧*/
		ciToXianDiDataBuffer[ii++] = CI_ATS_STATION_FRAME;       /*站场状态帧*/
		ciToXianDiDataBuffer[ii++] = Get2oo2SheBeiType();/*发送端设备ID和设备类型*/
		ciToXianDiDataBuffer[ii++] = localCi;

		ciToXianDiDataBuffer[ii++] = targetDevType;      /*接收端设备ID和设备类型*/
		ciToXianDiDataBuffer[ii++] = deviceId;

		emapCheckState = GetCiEmapCheckVer(localCi, &emapCrcInfo, targetDevType);
		if (CI_SUCCESS == emapCheckState)
		{
			LongToChar(emapCrcInfo, &ciToXianDiDataBuffer[ii]);	/*数据版本校验CRC信息*/
			ii += 4u;
		}
		else
		{
			ii += 4u;
		}
		LongToChar(interfacePrtclVer, &ciToXianDiDataBuffer[ii]);	/*接口协议版本信息*/
		ii += 4u;

		ShortToChar((UINT16)255, &ciToXianDiDataBuffer[ii]);
		ii += 4u;                                                 /*时间前四个字节为默认发送*/

		LongToChar(curCycleNum, &ciToXianDiDataBuffer[ii]);
		ii += 4u;                                                 /*时间后四个字节为CI周期号*/


		/*开始组应用数据*/

		if (0u == GetSendMaskSum(targetDevType) % 8u)
		{
			SendMaskSum = (UINT16)(GetSendMaskSum(targetDevType) / 8u);
		}
		else
		{
			SendMaskSum = (UINT16)(GetSendMaskSum(targetDevType) / 8u + 1u);
		}

		curIndex = ii;

		ShortToChar(SendMaskSum, &ciToXianDiDataBuffer[ii]); /*站场信息总长度*/
		ii += 2u;

		/*组码位信息*/
		(void)MaskPack(targetDevType, &ciToXianDiDataBuffer[ii]);
		ii = (UINT16)(ii + SendMaskSum);

		/*通信列车信息*/
		chRetVal = CI_SUCCESS;
		wEnvelopeSum = elm_GetAllEnvelope(szEnvelopeIdBuf);		/*获取所有的包络信息*/
		wcomTrainSumIndex = ii;
		ii += 2U;
		if (ENVELOPE_SUM_MAX > wEnvelopeSum)
		{
			for (wEnvelopeIndex = 0U; wEnvelopeIndex < wEnvelopeSum; wEnvelopeIndex++)
			{
				wEnvelopeId = szEnvelopeIdBuf[wEnvelopeIndex];		/*获取包络ID*/
				chFunRtn = elm_ConvertEnvelopeInfo(wEnvelopeId, &strEnvelope);
				if (CI_SUCCESS == chFunRtn)
				{/*包络信息获取成功*/
					/*通信车包络*/
					if (TYPE_CT_ENVELOPE == strEnvelope.envelopeType)
					{
						comTrainSum++;
						wTrainId = 0x1400u + (strEnvelope.trainID[0] & 0x00FFu);
						hlhtIdFlag = dquDevName2HlhtId(wTrainId, 0u, &dwHLHTTrainID);			/*两字节列车ID转换为4字节互联互通ID*/
						if (hlhtIdFlag == CI_SUCCESS)
						{/*互联互通ID查询成功*/
							LongToChar(dwHLHTTrainID, &ciToXianDiDataBuffer[ii]);		/* 列车ID */
							ii += 4u;
						}
						else
						{   /*组包失败*/
							chRetVal = CI_ERROR;
						}

						/*前筛*/						
						chHeadScreStat = strEnvelope.suspicHead;
						chVirHeadScreStat = GetTrainVirHeadScreenPassFlag(wTrainId);
						if ((CI_IVOC_HEAD_SCREEN_PASS == chHeadScreStat) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chVirHeadScreStat))
						{
							/*前筛状态有效*/
							ciToXianDiDataBuffer[ii] = CI_IVOC_HEAD_SCREEN_PASS;
							ii += 1U;
						}
						else if ((CI_IVOC_HEAD_SCREEN_UNKNOW == chHeadScreStat) && (TRAIN_VIR_SCREEN_PASS_FLAG_INVALID == chVirHeadScreStat))
						{
							/*前筛状态无效*/
							ciToXianDiDataBuffer[ii] = CI_IVOC_HEAD_SCREEN_UNKNOW;
							ii += 1U;
						}
						else
						{
							chRetVal = CI_ERROR;
						}

						/*后筛*/						
						chTailScreStat = strEnvelope.suspicTail;
						chVirTailScreStat = GetTrainVirTailScreenPassFlag(wTrainId);
						if ((CI_IVOC_TAIL_SCREEN_PASS == chTailScreStat) || (TRAIN_VIR_SCREEN_PASS_FLAG_VALID == chVirTailScreStat))
						{
							/*后筛状态有效*/
							ciToXianDiDataBuffer[ii] = CI_IVOC_TAIL_SCREEN_PASS;
							ii += 1U;
						}
						else if ((CI_IVOC_TAIL_SCREEN_UNKNOW == chTailScreStat) && (TRAIN_VIR_SCREEN_PASS_FLAG_INVALID == chVirTailScreStat))
						{
							/*后筛状态无效*/
							ciToXianDiDataBuffer[ii] = CI_IVOC_TAIL_SCREEN_UNKNOW;
							ii += 1U;
						}
						else
						{
							chRetVal = CI_ERROR;
						}
					}
					else
					{
						/*跳过 继续执行*/
					}
				}
				else
				{
					/*物理区段ID错误*/
					chRetVal = CI_ERROR;
				}
				if (CI_SUCCESS != chRetVal)
				{
					break;
				}
				else
				{
					/*继续执行*/
				}
			}
		}
		else
		{
			/*无列车信息，继续执行*/
		}
		ShortToChar(comTrainSum, &ciToXianDiDataBuffer[wcomTrainSumIndex]);

		/*指示灯状态*/
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			virtualCiNum = GetVirtualCINum();
			ciToXianDiDataBuffer[ii++] = virtualCiNum;/*本联锁包含的虚拟联锁数量*/
			for (kk = 0u; kk < virtualCiNum; kk++)
			{
				virtualCIid = GetVirtualCIid(kk);
				ciToXianDiDataBuffer[ii++] = virtualCIid;/*虚拟联锁ID*/
				/*表示灯报警灯信息*/
				indicatorNum = (UINT8)GetVirCIIndicatorConfigDataNum(virtualCIid);
				ShortToChar(indicatorNum, &ciToXianDiDataBuffer[ii]);/*表示灯报警灯总数*/
				ii += 2u;
				for (i = 0u; i < indicatorNum; i++)
				{
					indicatorId = GetVirCIlocalCiIndicatorId(virtualCIid, i);            /*表示灯报警灯分类号*/
					indicatorType = GetVirCIIndicatorType(virtualCIid, (UINT8)indicatorId); /*获取设备类型*/					/*原来直接用的类型做的索引，现在改为用ID做索引，需要转换为类型即报警灯类型*/
					indicatorState = GetVirCIIndicatorState(virtualCIid, (UINT8)indicatorId);   /*表示灯报警灯状态*/
					indicatorDevId = GetVirCIIndicatorDevId(virtualCIid, (UINT8)indicatorId);  /*表示灯报警灯ID*/
					ciToXianDiDataBuffer[ii++] = indicatorType;
					ciToXianDiDataBuffer[ii++] = indicatorDevId;
					ciToXianDiDataBuffer[ii++] = indicatorState;
				}
			}
		}
		else
		{
			/*表示灯报警灯信息*/
			ciToXianDiDataBuffer[ii++] = 1u;/*适配接口*/
			ciToXianDiDataBuffer[ii++] = localCi;
			indicatorNum = GetIndicatorCurSum();
			ShortToChar(indicatorNum, &ciToXianDiDataBuffer[ii]);/*表示灯报警灯总数*/
			ii += 2u;
			for (jj = 0u; jj < indicatorNum; jj++)
			{
				indicatorId = GetIndicatorId(jj);
				indicatorType = GetIndicatorType(indicatorId); /*获取设备类型*/				/*原来直接用的类型做的索引，现在改为用ID做索引，需要转换为类型即报警灯类型*/
				ciToXianDiDataBuffer[ii++] = indicatorType;    /*表示灯报警灯分类号*/
				indicatorDevId = GetIndicatorDevId(indicatorId);
				ciToXianDiDataBuffer[ii++] = indicatorDevId;/*报警灯设备ID*/
				ciToXianDiDataBuffer[ii++] = GetIndicatorState(indicatorId);/*表示灯报警灯状态*/
			}
		}

		UpdataCiSendCmdBack_OrderBack();/*发送数据命令更新*/
		if (1u > CiSendCmdStruCurSum)
		{ /*命令长度错误*/

			ShortToChar(0, &ciToXianDiDataBuffer[ii]);  /*命令帧总长度*/
			ii += 2u;
		}
		else
		{
			curIndex = ii;/*跳过命令帧总长度*/
			ii += 2u;

			ShortToChar(CiSendCmdStruCurSum, &ciToXianDiDataBuffer[ii]);        /*命令帧总数量*/
			ii += 2u;

			for (jj = 0u; jj < CiSendCmdStruCurSum; jj++)
			{
				ciToXianDiDataBuffer[ii++] = 22u;											/*反馈命令长度*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].CommandType;				/*命令类型*/
				LongToChar(CiSendCmdDataStru[jj].CommandId, &ciToXianDiDataBuffer[ii]);		/*命令编号*/
				ii += 4u;
				LongToChar(CiSendCmdDataStru[jj].CommandParam, &ciToXianDiDataBuffer[ii]);		/*命令参数*/
				ii += 4u;
				ShortToChar(CiSendCmdDataStru[jj].termial_id, &ciToXianDiDataBuffer[ii]);		/*命令参数*/
				ii += 2u;
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].order_type;   /*命令类型*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].response_type;   /*应答类型*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].affirm_result;   /*确认结果*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].firstCmd_time;   /*一次倒计时*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].VirCIid;   /*虚拟联锁ID*/
				ciToXianDiDataBuffer[ii++] = CiSendCmdDataStru[jj].OCid;   /*OC ID*/

				if (0u != CiSendCmdDataStru[jj].wTrainIdParam)
				{
					cFunRetVal = dquDevName2HlhtId(CiSendCmdDataStru[jj].wTrainIdParam, 0U, &dwTrainId);
					if (CI_ERROR == cFunRetVal)
					{
						dwTrainId = 0u;
					}
					else
					{
						;
					}
				}
				else
				{
					dwTrainId = 0u;
				}
				LongToChar(dwTrainId, &ciToXianDiDataBuffer[ii]);
				ii += 4u;

				ciToXianDiDataBuffer[ii++] = 0u;/*区段数量*/							
			}

			ShortToChar((UINT16)(ii - curIndex - 2U), &ciToXianDiDataBuffer[curIndex]);  /*命令帧总长度*/

#if 0
				/*清组命令反馈数据*/
			ClearCiSendCmdData();
#endif
		}

		/* 逻辑区段的已征用信息*/
		(void)PackCiToAtsLgcSgmtInfo(ciToXianDiDataBuffer, &ii);

		/* 组模式信息 */
		cTiocMode = GetTiocSystemMode();
		if (REVERSE_MODE_MAIN == cTiocMode)
		{
			/* 主控模式 */
			ciToXianDiDataBuffer[ii] = 0x55;
		}
		else
		{
			/* 影子模式 */
			ciToXianDiDataBuffer[ii] = 0xAA;
		}
		ii++;

		ciToXianDiDataBuffer[ii] = GetTiocSystemCutState();
		ii++;

		/* 不可导切原因 */
		cTiocCutReason = GetTiocCanntCutReason();
		ciToXianDiDataBuffer[ii] = cTiocCutReason;
		ii++;

		ii += 40u;
	}
	else
	{
	}

	/*设备状态帧*/
	if (CI_ATS_DEVICE_STATE_FRAME == frame)
	{
		/*组设备帧数据*/
		ciToXianDiDataBuffer[ii++] = CI_ATS_DEVICE_STATE_FRAME;  /*设备状态帧*/
		ciToXianDiDataBuffer[ii++] = Get2oo2SheBeiType();/*发送端设备ID和设备类型*/
		ciToXianDiDataBuffer[ii++] = localCi;

		ciToXianDiDataBuffer[ii++] = targetDevType;      /*接收端设备ID和设备类型*/
		ciToXianDiDataBuffer[ii++] = deviceId;

		emapCheckState = GetCiEmapCheckVer(localCi, &emapCrcInfo, targetDevType);
		if (CI_SUCCESS == emapCheckState)
		{
			LongToChar(emapCrcInfo, &ciToXianDiDataBuffer[ii]);	/*数据版本校验CRC信息*/
			ii += 4u;
		}
		else
		{
			ii += 4u;
		}
		LongToChar(interfacePrtclVer, &ciToXianDiDataBuffer[ii]);	/*接口协议版本信息*/
		ii += 4u;

		ShortToChar((UINT16)255, &ciToXianDiDataBuffer[ii]);
		ii += 4u;                                                 /*时间前四个字节为默认发送*/

		LongToChar(curCycleNum, &ciToXianDiDataBuffer[ii]);
		ii += 4u;                                                 /*时间后四个字节为CI周期号*/


		deviceSum = (UINT16)GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_PSC);     /*获取通信PSC设备总数*/
		pDeviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_PSC); /*获取通信PSC设备ID数组*/
		if (1u > deviceSum)
		{ /*PSC数量错误*/

			ShortToChar(0u, &ciToXianDiDataBuffer[ii]);  /*PSC数量总长度*/
			ii += 2u;
		}
		else
		{
			ShortToChar(deviceSum, &ciToXianDiDataBuffer[ii]);        /*PSC总数量总数量*/
			ii += 2u;

			if (NULL != pDeviceIdBuf)
			{ /*通信设备正确*/
				for (jj = 0u; jj < deviceSum; jj++)
				{
					pscId = pDeviceIdBuf[jj];					/*获取PSCID*/
					if (0u != pscId)
					{
						ciToXianDiDataBuffer[ii++] = 0u; /*PSC的ID*/
						ciToXianDiDataBuffer[ii++] = pscId;

						/*处理PSC A系工作状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCWorkState(ciToXianDiDataBuffer[ii], 6u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_A_WORK_STATE);

						/*处理PSC B系工作状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCWorkState(ciToXianDiDataBuffer[ii], 4u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_B_WORK_STATE);

						/*处理PSC 单个通信板故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 2u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_SINGLE_COMM_STATE, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC FSIO故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 0u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_FSIO_FAULT_STATE, BIT_VAL_00000011B, BIT_VAL_00000000B);

						ii++;

						/*处理PSC 驱动电源状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 6u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_DRIVE_POWER_STATE, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC 控制电源状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 4u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_CONTROL_POWER_STATE, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC与接口模块1的状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 2u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_Q_IM_1_STATE, BIT_VAL_00000001B, BIT_VAL_00000000B);

						/*处理PSC与接口模块2的状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 0u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_Q_IM_2_STATE, BIT_VAL_00000001B, BIT_VAL_00000000B);

						ii++;
						/*处理PSC 上行开门故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 6u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_OPEN_FAULT_STATE_UP, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC 上行关门故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 4u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_CLOSE_FAULT_STATE_UP, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC 下行开门故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 2u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_OPEN_FAULT_STATE_DOWN, BIT_VAL_00000011B, BIT_VAL_00000000B);

						/*处理PSC 下行关门故障状态表示灯*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCState(ciToXianDiDataBuffer[ii], 0u,
							pscCiSendToAtsDataStru[pscId].devType_PSC_CLOSE_FAULT_STATE_DOWN, BIT_VAL_00000011B, BIT_VAL_00000000B);

						ii++;

						transmitState = GetCiTransmitState(CI_SYSTEM_TYPE_PSC, pscId);/*获取CI与PSC通信状态*/
						pscConfirmFlag = GetPscConfirmFlag(pscId);    /*获取PSC旁路状态*/
						/*旁路状态*/

						/*旁路状态转换*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCtypeState(ciToXianDiDataBuffer[ii], 2u, pscConfirmFlag,
							CI_PSC_PL_CONFIRM_YES, BIT_VAL_00000000B, BIT_VAL_00000001B);

						/*CI与PSC通信状态转换*/
						ciToXianDiDataBuffer[ii] = TransCiToAtsPSCtypeState(ciToXianDiDataBuffer[ii], 0u, transmitState,
							TRANSMIT_STATE_GOOD, BIT_VAL_00000001B, BIT_VAL_00000000B);

						ii++;
					}
					else
					{
					}
				}
			}
			else
			{
			}
		}

		/*组OC-PSC一体化数据*/
		PackOcPscDataToAts(ciToXianDiDataBuffer, &ii);

		/*组PSD数据*/
		PackPsdDataToAts(ciToXianDiDataBuffer, &ii);
		
		
		ocDeviceSum = (UINT16)GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_OC);     /*获取通信OC设备总数*/
		pOcDeviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_OC); /*获取通信OC设备ID数组*/

		ShortToChar(ocDeviceSum, &ciToXianDiDataBuffer[ii]);  /*OC数量总长度*/
		ii += 2u;

		if (NULL != pOcDeviceIdBuf)
		{
			for (jj = 0u; jj < ocDeviceSum; jj++)/*遍历所有通信的oc*/
			{
				ocId = pOcDeviceIdBuf[jj];					/*获取OC ID*/

				powerAState = DUAL_WAY_AIR_SWITCH_ABNORMAL;/*故障*/
				powerBState = DUAL_WAY_AIR_SWITCH_ABNORMAL;/*故障*/
				ocDevFaultState = OC_CARD_ABNORMAL;/*故障*/
				fanState = DUAL_WAY_AIR_SWITCH_ABNORMAL;/*风扇故障*/
				wPbNum = 0U;								/*在组OC前先清除电插箱数量，防止将同一集中区另一个OC数据组入*/

				if (0U != ocId)
				{
					ShortToChar(ocId, &ciToXianDiDataBuffer[ii]);  /*OC的ID*/
					ii += 2u;

					for (kk = 0u; kk < m_OcToCiOrginDataNum; kk++)
					{
						if (NULL != m_OcToCiOrginDataArr)
						{
							if (m_OcToCiOrginDataArr[kk].OcId == ocId)/*有通信，能找到，就赋值*/
							{
								powerAState = m_OcToCiOrginDataArr[kk].PowerAState;
								powerBState = m_OcToCiOrginDataArr[kk].PowerBState;
								ocDevFaultState = m_OcToCiOrginDataArr[kk].OCDevFaultState;
								fanState = m_OcToCiOrginDataArr[kk].FanState;

								/*OCbyte执行电插箱接口转换*/
								wPbNum = TransCiToAtsOCPlusBoxInfo(szSendATSPlusBox, &kk);

								/*by cgh 20230918 多机牵引道岔转辙机数目数据转换*/
								wDjqySwitchNum = TransCiToAtsSwitchZzjInfo(szSendAtsSwitchZzjData, &kk);
							}
							else
							{

							}
						}
						else
						{
						}
					}
					/*转换A系电源状态*/
					powerAState = TransCiToAtsPowerState(powerAState);

					/*转换B系电源状态*/
					powerBState = TransCiToAtsPowerState(powerBState);

					/*转换风扇状态*/
					fanState = TransCiToAtsFanState(fanState);

					/*转换OC设备故障状态*/
					ocDevFaultState = TransCiToAtsOcDevFaultState(ocDevFaultState);

					ciAndOcCommState = Get2oo2CiAndOtherSysCommState(CI_SYSTEM_TYPE_OC, (UINT8)jj);

					ciToXianDiDataBuffer[ii++] = powerAState;
					ciToXianDiDataBuffer[ii++] = powerBState;
					ciToXianDiDataBuffer[ii++] = ciAndOcCommState;/*OC与联锁通信状态*/
					ciToXianDiDataBuffer[ii++] = ocDevFaultState;
					ciToXianDiDataBuffer[ii++] = fanState;

					ciToXianDiDataBuffer[ii++] = wPbNum;		/*组执行电插箱数量,若数据无效只组数量，若数量为0，也只组数量*/
					if (MAX_OC_PLUS_BOX_NUM >= wPbNum)
					{
						for (mm = 0u; mm < wPbNum; mm++)
						{
							ciToXianDiDataBuffer[ii++] = szSendATSPlusBox[mm].chPbId;		/*组执行电插箱编号*/
							ciToXianDiDataBuffer[ii++] = szSendATSPlusBox[mm].SendAtsAsState;		/*组报警类型*/
						}
					}
					else
					{
						; /*do nothing*/
					}

					ShortToChar(wDjqySwitchNum, &ciToXianDiDataBuffer[ii]);  /*双机牵引道岔的数目*/
					ii += 2U;
					if (SWITCH_SUM_MAX > wDjqySwitchNum)
					{
						for (wDjqySwitchIndex = 0U; wDjqySwitchIndex < wDjqySwitchNum; wDjqySwitchIndex++)
						{
							ShortToChar(szSendAtsSwitchZzjData[wDjqySwitchIndex].wSwitchId, &ciToXianDiDataBuffer[ii]);  /*双机牵引道岔的ID*/
							ii += 2U;
							ciToXianDiDataBuffer[ii++] = szSendAtsSwitchZzjData[wDjqySwitchIndex].chSwIncludeZzjSum;		/*道岔对应转辙机数目*/
							for (chSwitchZzjStateIndex = 0U; chSwitchZzjStateIndex < szSendAtsSwitchZzjData[wDjqySwitchIndex].chSwIncludeZzjSum; chSwitchZzjStateIndex++)
							{
								ciToXianDiDataBuffer[ii++] = szSendAtsSwitchZzjData[wDjqySwitchIndex].szSwitchIncldeZzjState[chSwitchZzjStateIndex];
							}
						}
					}
					else
					{
						; /*do nothing*/
					}
				}
				else
				{
				}
			}
		}
		else
		{
		}

#if 0
		/*存在PSC设备，才发送PSD隔离信息给ATS*/
		if (NULL == pDeviceIdBuf)
		{
			ciToXianDiDataBuffer[ii++] = 0u;
		}
		else
		{
			/*PSD数量先填0*/
			ciToXianDiDataBuffer[ii++] = 0u;

			for (m = 0u; m < deviceSum; m++)
			{
				for (n = 0u; n < pscToCiDataStru[pDeviceIdBuf[m]].psdSum; n++)
				{
					/*获取PSD所属联锁*/
					psdCiId = GetPsdBelongCiId(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdId);
					if (localCi == psdCiId)
					{
						psdSum++;
						/*psd ID*/
						ShortToChar(0u, &ciToXianDiDataBuffer[ii]);
						ii += 2u;
						ShortToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdId, &ciToXianDiDataBuffer[ii]);
						ii += 2u;
						/*获取互锁解除信息*/
						psdMutualLockState = GetPsdMutualLockRemoveState(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdId);
						/*ATS确认旁路*/
						if ((PSD_ATS_MUTUALLOCK_REMOVE_YES == psdMutualLockState) ||
							(PSD_ATS_AND_JD_MUTUALLOCK_REMOVE_YES == psdMutualLockState))
						{
							/*故障隔离信息(主动隔离)*/
							pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdFaultQStataOne = 0u;
							pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdFaultQStataTwo = 0u;
							/*屏蔽门开关信息*/
							pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorsStateOne = 0u;
							pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorsStateTwo = 0u;
						}
						else
						{
							/*不做处理*/
						}
						/*故障隔离信息(主动隔离)*/
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdFaultQStataOne, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdFaultQStataTwo, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
						/*屏蔽门被隔离信息*/
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorIStateOne, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorIStateTwo, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
						/*每扇门开关信息*/
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorsStateOne, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
						LongToChar(pscToCiDataStru[pDeviceIdBuf[m]].psdDataStr[n].psdDoorsStateTwo, &ciToXianDiDataBuffer[ii]);
						ii += 4u;
					}
					else
					{
						/*不做处理*/
					}
				}
			}
			/*重新填写PSD数量*/
			ciToXianDiDataBuffer[ii - (psdSum * 28U) - 1U] = psdSum;
		}
#endif


		/*组RCOCI设备状态 （电源/电源模块状态）2字节*/
		powerANodeState = CheckRCIAPowerFaultState();
		powerBNodeState = CheckRCIBPowerFaultState();
		ModeAState = CheckRCIAPowerModeFaultState();
		ModeBState = CheckRCIBPowerModeFaultState();

		/*处理A系电源状态表示灯*/
		ciToXianDiDataBuffer[ii] = TransCiToAtsPowerModeState(ciToXianDiDataBuffer[ii], 6u, powerANodeState, BIT_VAL_00000011B, BIT_VAL_00000000B);

		/*处理B系电源状态表示灯*/
		ciToXianDiDataBuffer[ii] = TransCiToAtsPowerModeState(ciToXianDiDataBuffer[ii], 4u, powerBNodeState, BIT_VAL_00000011B, BIT_VAL_00000000B);

		/*处理A系电源模块状态表示灯*/
		ciToXianDiDataBuffer[ii] = TransCiToAtsPowerModeState(ciToXianDiDataBuffer[ii], 2u, ModeAState, BIT_VAL_00000011B, BIT_VAL_00000000B);

		/*处理B系电源模块状态表示灯*/
		ciToXianDiDataBuffer[ii] = TransCiToAtsPowerModeState(ciToXianDiDataBuffer[ii], 0u, ModeBState, BIT_VAL_00000011B, BIT_VAL_00000000B);
		debug_infor_printf((const)"\nPOWER BYTE IS %d", ciToXianDiDataBuffer[ii]);
		ii++;


		/*预留一字节*/
		ii++;

		/*组中央联锁数据*/
		/*获取虚拟联锁数量*/
		virtualCiNum = GetVirtualCINum();
		ciToXianDiDataBuffer[ii++] = virtualCiNum;
		if (0u < virtualCiNum)
		{
			for (m = 0u; m < virtualCiNum; m++)
			{
				ciToXianDiDataBuffer[ii++] = ctrlpowerFlag[m].virCiId;
				ciToXianDiDataBuffer[ii++] = ctrlpowerFlag[m].ctrlPowerState;
				ciToXianDiDataBuffer[ii++] = ctrlpowerFlag[m].ctrlDeviceType;
				ShortToChar(ctrlpowerFlag[m].ctrlDeviceId, &ciToXianDiDataBuffer[ii]);
				ii += 2u;
			}
		}
		else
		{
			/*不处理*/
		}

		/*组通信联锁信息*/
		PackCiDataToAts(ciToXianDiDataBuffer, &ii);

		/*预留40字节*/
		ii += 40u;
	}
	else
	{
	}

	/*所有数据包总长度 */
	/*ciToXianDiDataBuffer[0] = (UINT8) (((ii - 2) >> 8u) & 0xffu);
	ciToXianDiDataBuffer[1] = (UINT8) ((ii - 2) & 0xffu);*/

	if (ii > CI_TO_ATS_DATA_LEN_MAX)
	{
		return CI_ERROR;
	}
	else
	{
	}

#ifdef APPCI_MAINTAIN_DEBUG
#ifdef PLATFORM_2OO2
	/*发送给维修机*/
	(void)DarkInfoPack(CIM_INFO_RCI_TO_ATS_DATA, ciToXianDiDataBuffer, ii);
#endif

#endif/*APPCI_MAINTAIN_DEBUG结束*/


	/*if (QueueWrite(ii, ciToXianDiDataBuffer, ciToXianDiDataQueue))*/
	dstDevId = ((UINT16)((UINT16)targetDevType << 8u) | ((UINT16)deviceId));
	outnetSafeSendRtn = OutnetSafeSend(dstDevId, 0u, &ciToXianDiDataBuffer[0], ii);
	if (1u == outnetSafeSendRtn)
	{ /*写队列成功*/
#ifdef LOGPRINT/*日志打印宏*/	
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
		if (targetDevType == CI_SYSTEM_TYPE_XIANDI)
		{/*发送给现地*/
			debug_infor_printf((const)"\nXIANDI_SEND:%d", ii);
			debug_out_array(0xAA, ciToXianDiDataBuffer, ii);
		}
		else
		{/*发送给ATS*/
			debug_infor_printf((const)"\nATS_SEND:%d", ii);
			debug_out_array(0xAA, ciToXianDiDataBuffer, ii);
		}
#endif/*平台打印结束*/

#endif
		return CI_SUCCESS;
	}
	else
	{
		/*写队列失败*/
		return CI_ERROR;
	}
}

/*
* 功能描述： 获取CI接收的操作命令结构体数组长度
* 参数说明： void    
* 返回值  ： 0: 获取失败
*           >0: CI接收操作命令结构体数组长度      
*/
UINT16 GetCiRevCmdStruCurSum(void)
{
	return CiRevCmdStruCurSum;
}


/*
* 功能描述： 获取CI接收的操作命令结构体数组
* 参数说明： void    
* 返回值  ： NULL: 获取失败
*           !NULL: CI接收操作命令结构体数组指针      
*/
CommandDataStruct* GetCiRevCmdDataStruct(void)
{
	if (CiRevCmdStruCurSum == 0u)
	{
		return NULL;
	}
	else
	{
		return CiRevCmdDataStru;
	}
}


/*
* 功能描述： 添加CI命令反馈数据
* 参数说明： const UINT32 CommandId, 命令ID
*            const UINT8 CommandType, 命令类型
*            const UINT16 DeviceId, 设备ID
*			 const UINT8 commandParam, 反馈参数
*            const UINT32 commandId, 命令ID
* 返回值  ： void     
*/
void SetCiSendCmdBackInfoData(const UINT8 CommandType, const UINT8 deviceType, const UINT16 deviceId, const UINT8 commandParam, const UINT32 commandId)
{
	UINT32 deviceInfo = 0u;  /*设备信息*/
	UINT16 tempDeviceId = 0U;
	UINT8 swapSysBoardBelongOC = 0U;

	/*当反馈命令为OC板卡切系类型时，deviceId传递进来的参数是高字节OC ID+低字节板卡ID
	ATS报警时需要的设备ID这个参数实际值为板卡ID，因此需要在这里将deviceId转换成OC ID和板卡ID*/
	if (CI_BACK_OC_BOARD_SWAPSYS == CommandType)
	{
		swapSysBoardBelongOC = (UINT8)(deviceId >> 8U); /*获取高字节的OC ID*/
		tempDeviceId = (deviceId & (UINT16)0xFF);       /*获取低字节的板卡ID*/
	}
	else
	{
		/*其他反馈命令类型传递的deviceId参数为实际的设备ID因此不需要进行转换，且OC ID填充为零*/
		swapSysBoardBelongOC = 0U;
		tempDeviceId = deviceId;
	}
	
	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)tempDeviceId) << 16U) | ((deviceInfo | (UINT32)deviceType) << 8U) | (UINT32)commandParam);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CommandType;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = commandId;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid = 0U;
		/*反馈命令类型为OC板卡切系则填充切系板卡所属的OC ID*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].OCid = swapSysBoardBelongOC;

		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:SetCiSendCmdBackInfoData,%d exceed max %d\n",CiSendCmdStruCurSum,CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}
	
}

/*
* 功能描述： 添加CI命令反馈数据带列车ID
* 参数说明： const UINT32 CommandId, 命令ID
*            const UINT8 CommandType, 命令类型
*            const UINT16 DeviceId, 设备ID
*			 const UINT8 commandParam, 反馈参数
*            const UINT32 commandId, 命令ID
*			 const UINT16 TrainId,列车ID
* 返回值  ： 0: 设置失败
*			 1: 设置成功
*/
void SetCiSendCmdBackInfoWithTrainId(const UINT8 CommandType, const UINT8 deviceType, const UINT16 deviceId, const UINT8 commandParam, const UINT32 commandId,const UINT16 trainId)
{
	UINT32 deviceInfo = 0u;  /*设备信息*/

	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)deviceId) << 16u) | ((deviceInfo | (UINT32)deviceType) << 8u) | (UINT32)commandParam);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CommandType;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = commandId;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].wTrainIdParam = trainId;
		CiSendCmdDataStru[CiSendCmdStruCurSum].OCid = 0U;
		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:SetCiSendCmdBackInfoData,%d exceed max %d\n", CiSendCmdStruCurSum, CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}

}

/*
* 功能描述： 针对一次二次命令的反馈
* 参数说明： const UINT32 CommandId, 命令ID
*            const UINT8 CommandType, 命令类型
*            const UINT16 DeviceId, 设备ID
*			 const UINT8 commandParam, 反馈参数
*            const UINT32 commandId, 命令ID
* 返回值  ： 无  
*/
void SetCiSendCmdBackData_OrderBack( const UINT32 commandId,const UINT16 deviceId, const UINT8 deviceType,const UINT16 termial_id, const UINT8 order_type, const UINT8 response_type,const UINT8 affirm_result,const UINT8 virCIid)
{
	UINT32 curCycleNum = 0u;
	UINT32 appCycTime = 0u;/*联锁周期数*/
	UINT8 ii = 0u;
	UINT16 cmdDeviceId = 0u;
	UINT8 cmdDevType = 0u;
    UINT32 deviceInfo = 0u;  /*设备信息*/
	UINT32 firstOrderTimeCount = 0u;
	curCycleNum =Get2oo2CurCycleNum();
	appCycTime = GetSystemParaAppCycleTime();/*获取联锁周期号*/
	firstOrderTimeCount = GetFirstOrderTimeCount();
	/*要发送二次命令时，清除暂存的一次命令*/
	for (ii = 0u; ii < CiSendBackDataTempStruSum; ii ++)
	{
		if(RESPONSE_SECOND == response_type)
		{
			cmdDeviceId = (UINT16)(CiSendBackDataTempStru[ii].CommandParam>>16u);
			cmdDevType = (UINT8)(CiSendBackDataTempStru[ii].CommandParam >> 8u);
			if((termial_id == CiSendBackDataTempStru[ii].termial_id) &&(commandId == CiSendBackDataTempStru[ii].CommandId)
				&&(deviceType == cmdDevType)&&(deviceId == cmdDeviceId)&&(virCIid == CiSendBackDataTempStru[ii].VirCIid))
			{
				(void)CommonMemSet(&CiSendBackDataTempStru[ii], (UINT32)sizeof(CommandDataStruct),0u, (UINT32)sizeof(CommandDataStruct));
			}
		}
	}
	/*清除暂存一次命令后，将无效命令清除，并将数量置为有效命令的数量 YF0083-Bug-148*/
	ClearCiSendBackDataTempStruData();

	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)deviceId) << 16u) | ((deviceInfo | (UINT32)deviceType) << 8u) | (UINT32)0u);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CI_BACK_ORDER_REPEAT;/*分类号0x70*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = commandId;/*命令ID  */  
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;/*设备ID+设备类型+参数(时间值)*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = termial_id; /*终端ID*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = order_type;/*命令类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = response_type;/*回复类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = affirm_result; /*确认结果*/		
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0u; /*一次命令设置周期*/	
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time  = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid = virCIid;
		CiSendCmdDataStru[CiSendCmdStruCurSum].OCid = 0U;
		if((RESPONSE_FIRST == CiSendCmdDataStru[CiSendCmdStruCurSum].response_type)&&(AFFIRM_SUCCESS==CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result))
		{/*针对一次命令设置命令周期*/
			CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = curCycleNum; /*一次命令设置周期*/
			CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time  = (UINT8)((firstOrderTimeCount*appCycTime)/1000U);
			/*暂存1次命令*/
			if (CiSendBackDataTempStruSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
			{
				(void)CommonMemCpy(&CiSendBackDataTempStru[CiSendBackDataTempStruSum], (UINT32)sizeof(CommandDataStruct),&CiSendCmdDataStru[CiSendCmdStruCurSum], (UINT32)sizeof(CommandDataStruct));
				CiSendBackDataTempStruSum++;
			}
			else
			{
				debug_infor_printf((const)"Error:CiSendBackDataTempStru,%d exceed max %d\n",CiSendBackDataTempStruSum,CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
			}
		}
		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:SetCiSendCmdBackData_OrderBack,%d exceed max %d\n",CiSendCmdStruCurSum,CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}
	
}
/*
* 功能描述：对一次命令倒计时更新
* 参数说明： 无
* 返回值  ： 无     
*/
void UpdataCiSendCmdBack_OrderBack(void)
{/*组包之前调用*/
	UINT16 ii = 0u;
	UINT8 timeData = 0u;
	UINT32 curCycleNum = 0u;
	UINT32 appCycTime = 0u;/*联锁周期数*/
	UINT32 firstOrderTimeCount = 0u;
	UINT16 deviceID = 0u;
	UINT8  deviceType = 0u;
	UINT8 virCIid = 0u;
	curCycleNum =Get2oo2CurCycleNum();
	appCycTime = GetSystemParaAppCycleTime();/*获取联锁周期号*/
	firstOrderTimeCount = GetFirstOrderTimeCount();
	for (ii = 0u; ii < CiSendBackDataTempStruSum; ii ++)
	{		
		/*一次命令倒计时管理*/
		if(0u != CiSendBackDataTempStru[ii].setCurNum)
		{			
			if(curCycleNum >= (firstOrderTimeCount + CiSendBackDataTempStru[ii].setCurNum))
			{/*计时时间到*/
				/*发送一次命令超时报警*/
				deviceID = (UINT16)(CiSendBackDataTempStru[ii].CommandParam>>16u);
				deviceType = (UINT8)(CiSendBackDataTempStru[ii].CommandParam>>8u);
				virCIid = CiSendBackDataTempStru[ii].VirCIid;
				SetCiSendCmdBack_FstOrdOutTime(CiSendBackDataTempStru[ii].CommandId,deviceID,deviceType,CiSendBackDataTempStru[ii].order_type,CiSendBackDataTempStru[ii].termial_id,virCIid);
				/*清除缓存*/
				(void)CommonMemSet(&CiSendBackDataTempStru[ii], (UINT32)sizeof(CommandDataStruct), 0U , (UINT32)sizeof(CommandDataStruct));
			}
			else
			{	
				timeData = (UINT8)(((firstOrderTimeCount + CiSendBackDataTempStru[ii].setCurNum - curCycleNum)* appCycTime)/1000U);
				CiSendBackDataTempStru[ii].firstCmd_time = timeData; /*一次命令倒计时*/
			}			
		}
		
	}	
}
/*
* 功能描述：一次命令超时报警
* 参数说明： 无
* 返回值  ： 无     
*/
void SetCiSendCmdBack_FstOrdOutTime(const UINT32 commandId,const UINT16 deviceId, const UINT8 deviceType,const UINT8 order_type,const UINT16 termial_id,UINT8 virCIid)
{
	UINT32 deviceInfo = 0u;  /*设备信息*/
	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)deviceId) << 16u) | ((deviceInfo | (UINT32)deviceType) << 8u) | (UINT32)0u);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CI_BACK_FIRSTORDER_OUTTIME;/*分类号0x7d*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = commandId;/*命令ID    */
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;/*设备ID+设备类型+参数(时间值)*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = termial_id; /*终端ID*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = order_type;/*命令类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = 0u;/*回复类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = 0u; /*确认结果*/		
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0u; /*一次命令设置周期*/	
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time  = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid  =virCIid;
		CiSendCmdDataStru[CiSendCmdStruCurSum].OCid = 0U;
		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:SetCiSendCmdBack_FstOrdOutTime,%d exceed max %d\n",CiSendCmdStruCurSum,CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}

}
/*
* 功能描述： 清空CI暂存的不需要的命令数据
* 参数说明： void    
* 返回值  ：无     
*/
void ClearCiSendBackDataTempStruData(void)
{
	UINT16 ii = 0u;
	UINT16 ciSendCmdStruTempNum = 0u;	    /*CI操作命令反馈结构体数组长度*/
	UINT16 jj = 0u;
	for (ii = 0u; ii < CiSendBackDataTempStruSum; ii ++)
	{
		if(ii < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
		{
			/*不是全0数据保存，全零数据移出数组*/
			if(0u !=CiSendBackDataTempStru[ii].response_type)
			{	
				(void)CommonMemCpy(&CiSendBackDataTempStru[ciSendCmdStruTempNum], (UINT32)sizeof(CommandDataStruct), &CiSendBackDataTempStru[ii], (UINT32)sizeof(CommandDataStruct));
				ciSendCmdStruTempNum++;
			}
		}
	}
	/*清除脏数据*/
	for (jj = ciSendCmdStruTempNum; jj < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX; jj ++)
	{
		(void)CommonMemSet(&CiSendBackDataTempStru[jj], (UINT32)sizeof(CommandDataStruct), 0 , (UINT32)sizeof(CommandDataStruct));
	}
	CiSendBackDataTempStruSum = ciSendCmdStruTempNum;
}
/*
* 功能描述： 清空CI接收命令数据队列
* 参数说明： void    
* 返回值  ： 0: 解析失败
*			 1: 解析成功      
*/
void ClearCiRevCmdData(void)
{
	UINT16 ii = 0u;

	for (ii = 0u; ii < CiRevCmdStruCurSum; ii ++)
	{
		(void)CommonMemSet(&CiRevCmdDataStru[ii], (UINT32)sizeof(CommandDataStruct), 0u , (UINT32)sizeof(CommandDataStruct));
	}

	CiRevCmdStruCurSum = 0u;
}


/*
* 功能描述： 清空CI发送命令反馈数据队列
* 参数说明： void    
* 返回值  ： 0: 解析失败
*			 1: 解析成功      
*/
void ClearCiSendCmdData(void)
{
	UINT16 ii = 0u;

	for (ii = 0u; ii < CiSendCmdStruCurSum; ii ++)
	{
		(void)CommonMemSet(&CiSendCmdDataStru[ii], (UINT32)sizeof(CommandDataStruct), 0u , (UINT32)sizeof(CommandDataStruct));
	}

	CiSendCmdStruCurSum = 0u;
	ClearCiSendBackDataTempStruData();
}
/*
* 功能描述： 二次命令有效性检查
* 参数说明： 设备ID,设备类型，终端ID,终端类型    
* 返回值  ：CI_ERROR : 失败
*			CI_SUCCESS: 成功      
*/
UINT8 CheckSecondOrderValid(const UINT32 commandId,const UINT16 deviceId, const UINT8 deviceType,const UINT16 termial_id, const UINT8 order_type,const UINT8 virCiID)
{
	UINT16 ii = 0u;
	UINT16 ciSendCmdStruNum = 0u;	    /*CI操作命令反馈结构体数组长度*/
	UINT8 reVal = CI_ERROR;
	UINT8 firstOrder = 0u;
	UINT16 cmdDeviceId =0u;
	UINT8 cmdDevType =0u;
	firstOrder = FindFirstOrder(order_type);
	for (ii = 0u; ii < CiSendBackDataTempStruSum; ii ++)
	{				
		cmdDeviceId = (UINT16)(CiSendBackDataTempStru[ii].CommandParam>>16u);
		cmdDevType = (UINT8)(CiSendBackDataTempStru[ii].CommandParam >> 8u);
		if((deviceId == cmdDeviceId)&&(deviceType == cmdDevType)&&(commandId == CiSendBackDataTempStru[ii].CommandId)
			&&(termial_id == CiSendBackDataTempStru[ii].termial_id)&&(firstOrder == CiSendBackDataTempStru[ii].order_type)
			&&(0u !=firstOrder)&&(virCiID == CiSendBackDataTempStru[ii].VirCIid))
		{
			reVal = CI_SUCCESS;
			break;
		}
	}
	return reVal;
}

/*
* 功能描述： 获取首次操作确认的命令ID
* 参数说明： void    
* 返回值  ： 首次操作确认的命令ID     
*/
UINT32 GetFirstCmdId(void)
{
	return FirstCmdId;
}

/*
* 功能描述： 设置首次操作确认的命令ID
* 参数说明： const UINT32 cmdId, 命令ID    
* 返回值  ： void     
*/
void SetFirstCmdId(const UINT32 cmdId)
{
	FirstCmdId = cmdId;
}

/*
* 功能描述： 获取CI接收的ATS或现地信号特开操作命令结构体数组长度
* 参数说明： void    
* 返回值  ： 0: 获取失败
*           >0: CI接收ATS或现地信号特开操作命令结构体数组长度      
*/
UINT16 GetATSToCiCmdRtnToTRCurSum(void)
{
	return ATSorXDToCiCmdReturnToTRCurSum;
}


/*
* 功能描述： 获取CI接收的ATS或现地信号特开操作命令结构体数组
* 参数说明： void    
* 返回值  ： NULL: 获取失败
*           !NULL: CI接收ATS或现地信号特开操作命令结构体数组指针      
*/
CommandDataStruct* GetATSorXDToCiCmdRtnToTRData(void)
{
	CommandDataStruct* pTemp = NULL;
	if (0u == ATSorXDToCiCmdReturnToTRCurSum)
	{
		pTemp = NULL;
	}
	else
	{
		pTemp = ATSorXDToCiCmdRtnToTRDataStru;
	}

	return pTemp;
}


/*
* 功能描述： 从信号特开命令结构体数组中，删除指定位置的数据
* 参数说明： const UINT16 idx:信号特开命令结构体数组的位置索引
* 返回值  ： 0:失败
*			 1:成功     
*/
UINT8 RemoveReturnToTRCmdAt(const UINT16 idx)
{
	UINT8 retVal = CI_ERROR;
	UINT16 afIdx = 0u;
	if(idx >= ATSorXDToCiCmdReturnToTRCurSum)
	{
		retVal = CI_ERROR;
	}
	else
	{
		for(afIdx = idx+1U;afIdx < ATSorXDToCiCmdReturnToTRCurSum;afIdx++)
		{
			CopyReturnToTRCmd(&(ATSorXDToCiCmdRtnToTRDataStru[afIdx]),&(ATSorXDToCiCmdRtnToTRDataStru[afIdx-1U]));
		}
		
		/*总数减少一个*/
		ATSorXDToCiCmdReturnToTRCurSum--;
		retVal = CI_SUCCESS;
	}

	return retVal;
}
/*
* 功能描述： 拷贝发送给相邻CI的信号特开申请命令信息结构体
* 参数说明： const CommandDataStruct* src:被复制的信号特开申请命令结构体指针
			 CommandDataStruct* dst:目标信号特开申请命令结构体指针
* 返回值  ： 无     
*/
void CopyReturnToTRCmd(const CommandDataStruct* src,CommandDataStruct* dst)
{
	if ((NULL != src) && (NULL != dst))
	{
		(void)CommonMemCpy(dst, (UINT32)sizeof(CommandDataStruct), src , (UINT32)sizeof(CommandDataStruct));
	}

}

/*
* 功能描述： 获取确认PSC互锁解除标志
* 参数说明： UINT8 pscId, PSC系统ID
*            
* 返回值  ： 0: 未设置互锁解除
*			 >0: 设置互锁解除      
*/
UINT8 GetPscConfirmFlag(UINT8 pscId)
{
	/*变量初始化*/
	UINT8 i = 0u;
	UINT8 pscPsdFlag = 0u;
	UINT8 retVal = 0u;
	UINT8 localCiId = 0u;
	UINT8 psdCiId = 0u;
	PSCToCiDataStruct* pscToCiDataStru = GetPscToCiDataStru();/*不会返回NULL*/

	localCiId = GetSystemParaLocalCiId();/*获取CI ID*/

	/*防空*/
	if  (PSC_TO_CI_SUM_MAX > pscId)
	{
		for(i = 0u; i < pscToCiDataStru[pscId].psdSum; i++)
		{
			
			psdCiId = GetPsdBelongCiId(pscToCiDataStru[pscId].psdDataStr[i].psdId);
			/*本联锁*/
			if(psdCiId == localCiId)
			{
				/*获取PSC对应PSD的互锁解除确认标志*/
				pscPsdFlag = GetPsdPlFlag(pscToCiDataStru[pscId].psdDataStr[i].psdId);
				if(CI_PSC_PL_CONFIRM_YES == pscPsdFlag)
				{
					retVal = CI_PSC_PL_CONFIRM_YES;
					break;
				}
				else
				{
					/*不做处理*/
				}
			}
		}
	}
	return(retVal);
}
/*
* 功能描述： psd超时报警处理
* 参数说明： 无
*
* 返回值  ：无
* cgh-合并CID-3037-2：
*/
void PsdDriveOutTimeToAts(void)
{
	UINT16 wPsdSum = 0u;
	UINT16 i = 0u;
	UINT16 wpsdId = 0u;
	UINT8 chPsdBelongCiId = 0u;
	UINT8 chlocalCiId = 0u;
	UINT8 chPsdDriveOutTimeState = 0u;

	chlocalCiId = GetSystemParaLocalCiId();
	/*获取psd总数*/
	wPsdSum = GetTotalPsdCurNum();
	for (i = 0u; i < wPsdSum; i++)
	{
		wpsdId = GetPsdId(i);
		chPsdBelongCiId = GetPsdBelongCiId(wpsdId);
		if (chlocalCiId == chPsdBelongCiId)
		{
			/*驱动未响应报警信息*/
			chPsdDriveOutTimeState = CheckPsdDriveOutTimeState(wpsdId);

			if (PSD_OPEN_OUT_TIME == chPsdDriveOutTimeState)
			{
				SetCiSendCmdBackInfoData(CI_BACK_PSD_OPEN_OUT_TIME, CI_DEVICE_TYPE_PSD, wpsdId, 0u, 0u);

			}
			else if (PSD_CLOSE_OUT_TIME == chPsdDriveOutTimeState)
			{
				SetCiSendCmdBackInfoData(CI_BACK_PSD_CLOSE_OUT_TIME, CI_DEVICE_TYPE_PSD, wpsdId, 0u, 0u);

			}
			else
			{
				; /*不是超时状态，不进行报警操作*/
			}


		}
		else
		{
			; /*不是本联锁管辖PSD，不进行处理*/
		}

	}
}
/*
* 功能描述： 输入二次命令，获取对应一次命令
* 参数说明： 二次命令
*            
* 返回值  ： 一次命令    
*/
UINT8 FindFirstOrder(UINT8 SecondOrder)
{
   UINT8 i = 0u;
   UINT8 reVal = 0u;
   switch(SecondOrder)
   {
      case ATS_CMD_STARTFLOCK_UNLOCK_TWO:
		   reVal = ATS_CMD_STARTFLOCK_UNLOCK_ONE; /*全站解封一次*/
		   break;
	  case ATS_CMD_ALL_SIG_BRIGHT_SET_TWO:
		  reVal =ATS_CMD_ALL_SIG_BRIGHT_SET_ONE;/*全站点灯一次*/
		  break;
	  case ATS_CMD_ALLSIGBRIGHT_CANCEL_TWO:
		  reVal =ATS_CMD_ALLSIGBRIGHT_CANCEL_ONE;/*取消全站点灯一次*/
		  break;
	  case ATS_CMD_SWITCH_ZONGSUO_SET_TWO:
		  reVal =ATS_CMD_SWITCH_ZONGSUO_SET_ONE;/*引导总锁一次*/
		  break;
	  case ATS_CMD_SWIT_ZONGSUO_CANCEL_TWO:
		  reVal =ATS_CMD_SWIT_ZONGSUO_CANCEL_ONE;/*取消引导总锁一次*/
		  break;
	  case ATS_CMD_PHYSEC_RESET_TWO:
		  reVal = ATS_CMD_PHYSEC_RESET_ONE;/*计轴复位一次*/
		  break;
	  case ATS_CMD_SWIT_QIANG_DINGWEI_TWO:
		  reVal = ATS_CMD_SWIT_QIANG_DINGWEI_ONE; /*道岔强扳定位一次*/
		  break;
	  case ATS_CMD_SWIT_QIANG_FANWEI_TWO:
		  reVal = ATS_CMD_SWIT_QIANG_FANWEI_ONE;  /*道岔强扳反位一次*/
		  break;
	  case ATS_CMD_PHYSEC_PRE_RESET_TWO:
		  reVal = ATS_CMD_PHYSEC_PRE_RESET_ONE; /*计轴预复位一次*/
		  break;
	  case ATS_CMD_CICI_NET_TO_RELAY_TWO:
		  reVal = ATS_CMD_CICI_NET_TO_RELAY_ONE; /*联锁与联锁网络接口转继电接口一次命令*/
		  break;
	  case ATS_CMD_PSC_PL_TWO:
		  reVal = ATS_CMD_PSC_PL_ONE;/*设置PSC旁路一次命令*/
		  break;
	  case ATS_CMD_QUXIAO_PSC_PL_TWO:
		  reVal = ATS_CMD_QUXIAO_PSC_PL_ONE;/*取消PSC旁路一次命令*/
		  break;
	  case ATS_CMD_SIGNALMAINTAINSTATE_TWO:
		  reVal = ATS_CMD_SIGNALMAINTAINSTATE_ONE;/*返回信号机维修点灯一次命令*/
		  break;
	  case ATS_CMD_CANCEL_SIG_MAINTAIN_TWO:
		  reVal = ATS_CMD_CANCEL_SIG_MAINTAIN_ONE;/*返回取消信号机维修点灯一次命令*/
		  break;
	 case ATS_CMD_CANCEL_SW_ALARM_TWO:
		  reVal = ATS_CMD_CANCEL_SW_ALARM_ONE; /*取消转辙机封连报警一次命令*/
		  break;
	 case ATS_CMD_RECOVER_SW_ALARM_TWO:
		 reVal = ATS_CMD_RECOVER_SW_ALARM_ONE; /*恢复转辙机封连报警一次命令*/
		 break;
	 case LABOR_CMD_CANCEL_OVERLAP_TWO:
		 reVal = LABOR_CMD_CANCEL_OVERLAP_ONE; /*人工解锁保护区段一次命令*/
		 break;
	 case ATS_CMD_CANCEL_PHYSEC_SECOND:
		 reVal = ATS_CMD_CANCEL_PHYSEC_FIRST;/* 解锁降级车一次命令 */
		 break;
	 case ATS_CMD_TOA_RESET_SECOND:
		 reVal = ATS_CMD_TOA_RESET_FIRST;/*集中区故障占压复位一次命令*/
		 break;
	 case ATS_CMD_OPEN_XIANSU_SIGNAL_SECOND:
		 reVal = ATS_CMD_OPEN_XIANSU_SIGNAL_FIRST;/*开放限速信号一次命令*/
		 break;
	 case ATS_CMD_SWITCH_DINGWEI_TEST_TWO:
		 reVal = ATS_CMD_SWITCH_DINGWEI_TEST_ONE; /*道岔定位测试一次命令*/
		 break;
	 case ATS_CMD_SWITCH_FANWEI_TEST_TWO:
		 reVal = ATS_CMD_SWITCH_FANWEI_TEST_ONE; /*道岔反位测试一次命令*/
		 break;
	 case ATS_CMD_OC_P_PL_TWO:
		 reVal = ATS_CMD_OC_P_PL_ONE; /*OC-P旁路一次命令*/
		 break;
	 case ATS_CMD_QUXIAO_OC_P_PL_TWO:
		 reVal = ATS_CMD_QUXIAO_OC_P_PL_ONE; /*取消OC-P旁路一次命令*/
		 break;
	  default:
		  reVal = 0u;
		  break;
   }
   return reVal;
}
/*
* 功能描述： 给发送现地或ATS的反馈数据添加虚拟联锁ID或者本地联锁ID
* 参数说明： void    
* 返回值  ：无     
*/
void AddCiSendBackDataCIid(void)
{
	UINT16 ii = 0u;
	UINT16 cmdDeviceId = 0u;
	UINT8 cmdDevType = 0u;
	UINT8 belongVirCIid = 0u;
	UINT8 backType = 0u;
	UINT8 virCINum = 0u;
	UINT8 boardBelongOcId = 0U;
	UINT16 phySecPlockBelongRouteId = 0U;  /*物理区段防护锁闭所属进路ID*/
	UINT8 includeVirFlag = GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG); /*获取是否支持虚拟联锁功能开关*/

	for (ii = 0u; ii < CiSendCmdStruCurSum; ii ++)
	{
		belongVirCIid = 0u;
		cmdDeviceId = (UINT16)(CiSendCmdDataStru[ii].CommandParam >> 16u);
		cmdDevType = (UINT8)(CiSendCmdDataStru[ii].CommandParam >> 8u);
		backType = CiSendCmdDataStru[ii].CommandType;
		if (FUNC_SWITCH_ON == includeVirFlag)
		{
			if ((CI_BACK_ORDER_REPEAT != backType) && (CI_BACK_FIRSTORDER_OUTTIME != backType)
				&& (CI_BACK_COUNT_OVERLAP_UNLOCK != backType) && (CI_BACK_COUNT_OVERLAP_UNLOCK_HIGH != backType))
				/*0x70，0x7d类型不处理,两种反馈VirCIid前面已经赋值过，在此处不再赋值。0x55,0x5d此分支不赋值，避免保护区段在相邻虚拟联锁时，在本虚拟联锁现地上不显示倒计时*/
			{
				switch (cmdDevType)
				{
				case CI_DEVICE_TYPE_SWITCH:
					belongVirCIid = GetSwitchBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_SIGNAL:
					belongVirCIid = GetSignalBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_PHYSEC:
					belongVirCIid = GetPhySecBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_LOGICSEC:
					belongVirCIid = GetLogSecBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_ROUTE:
					belongVirCIid = GetRouteBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_OVERLAP:
					belongVirCIid = GetOverlapBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_AXISSEC:
					belongVirCIid = GetAxisSectionBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_PSD:
					belongVirCIid = GetPsdbelongVirCIid(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_RELAY:
					belongVirCIid = GetRelayBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_SPKS:
					belongVirCIid = GetSpksBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_GARAGEDOOR:
					belongVirCIid = GetGaragedoorBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_WASHMACHINE:
					belongVirCIid = GetWashMachineBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_FLOODGATE:
					belongVirCIid = GetFloodGateBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_GROUP_AUTO_ROUTE:
					belongVirCIid = GetGroupAutoRouteBelongVirCIid(cmdDeviceId);/*计算组合自动进路所属虚拟联锁*/
					break;
					/*此命令专用于试车线*/
				case CI_DEVICE_TYPE_CMD:
					virCINum = GetVirtualCINum();
					if (1u <= virCINum)
					{
						belongVirCIid = GetVirtualCIid(0u);/*由于试车线一个联锁，仅存在一个虚拟联锁，故直接取读取到的第一个虚拟联锁ID*/
					}
					break;
				case CI_DEVICE_TYPE_ESB:
					belongVirCIid = GetEsbBelongVirCiId(cmdDeviceId);
					break;
				case CI_DEVICE_TYPE_NONROUTE:
					belongVirCIid = GetnonRouteIdbelongVirCIid((UINT8)cmdDeviceId);/*非进路所属虚拟联锁由非进路包含信号机的所属虚拟联锁计算出*/
					break;
				case CI_DEVICE_TYPE_WASH_LINE:/*洗车线*/
					belongVirCIid = GetWashMachineBelongVirCiId(cmdDeviceId);/*XTJ对应洗车机所属虚拟联锁*/
					break;
				case CI_DEVICE_TYPE_OC_BOARD:
					boardBelongOcId = CiSendCmdDataStru[ii].OCid;
					belongVirCIid = GetOCBelongVirCIid(boardBelongOcId);                   /*获取切系板卡所属虚拟联锁ID*/
					break;
				case CI_DEVICE_TYPE_WASH_ALLOW_PASS:/*洗车反向通过*/
					belongVirCIid = GetWashMachineBelongVirCiId(cmdDeviceId);/*洗车机所属虚拟联锁*/
					break;
				default:
					belongVirCIid = 0u;
					break;
				}
			}
			else if ((CI_BACK_COUNT_OVERLAP_UNLOCK == backType) || (CI_BACK_COUNT_OVERLAP_UNLOCK_HIGH == backType))
			{
				if (CI_DEVICE_TYPE_PHYSEC == cmdDevType)
				{
					phySecPlockBelongRouteId = GetPhySecPLockBelongRouteId(cmdDeviceId);      /*获取物理区段防护锁闭所属进路ID*/
					belongVirCIid = GetRouteBelongVirCiId(phySecPlockBelongRouteId);  /*获取进路所属虚拟联锁ID*/
				}
			}
			else
			{
				; /*不做处理*/
			}
		}
		else
		{
			/*不具备虚拟联锁，给ATS组包本地联锁ID*/
			belongVirCIid = GetSystemParaLocalCiId();
		}

		if (0U == CiSendCmdDataStru[ii].VirCIid)
		{
			CiSendCmdDataStru[ii].VirCIid = belongVirCIid;
		}
	}
}

/*
* 功能描述： 组包Ci到Ats逻辑区段已征用信息
* 参数说明： const UINT8* pDataBuf, 数据缓冲区
*            const UINT16 *wDataLength, 数据长度 输出参数
* 返回值  ： CI_ERROR 失败
*			 CI_SUCCESS 成功
*/
static UINT8 PackCiToAtsLgcSgmtInfo(UINT8* pDataBuf, UINT16* wDataLength)
{
	UINT16 wLogicSecSum = 0u;	/*逻辑区段总数*/
	UINT16 wLogicSecIndex = 0U;
	UINT16 wLogicSecId = 0U; /*逻辑区段ID*/
	UINT16 deviceSumIndex = 0u;	/*设备总数游标位置*/
	UINT16 deviceSum = 0u;
	UINT8 chLogicTrainSum = 0U;	/*征用逻辑区段的列车数量*/
	LogicTrainResStruct * pstLogicResTrainInfo = NULL;	/*征用逻辑区段的列车信息指针*/
	UINT16 wTrainId = 0U;/*征用逻辑区段的列车ID*/
	UINT8 chTrainIndex = 0U;
	UINT8 chRetVal = CI_ERROR;
	UINT16 ii = 0U;
	UINT8 belongCiId = 0u;
	UINT8 localCiId = 0u;
	UINT32 dwHlhtTrainId = 0u;/*互联互通列车ID*/
	UINT8 chLogUseState = 0u;
	UINT8 chLogLockState = 0u;
	UINT8 chLogRouteLogLockState = 0U;
	UINT8 chUseState = 0u;
	UINT8 chLockState = 0u;
	UINT8 chUseLockState = 0u;

	/*入参防护*/
	if ((NULL == pDataBuf) || (NULL == wDataLength))
	{
		chRetVal = CI_ERROR;
	}
	else
	{
		chRetVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == chRetVal)
	{
		ii = *wDataLength;
		localCiId = GetSystemParaLocalCiId();/*本机联锁ID*/
		wLogicSecSum = GetTotalLogSecCurNum();
		if (LOGIC_SECTION_SUM_MAX > wLogicSecSum)
		{
			
			/*组逻辑区段总数*/
			/*填写逻辑区段总数*/
			ShortToChar(wLogicSecSum, &pDataBuf[ii]);
			ii += 2u;
			for (wLogicSecIndex = 0u; wLogicSecIndex < wLogicSecSum; wLogicSecIndex++)
			{
				/*逻辑区段ID*/
				wLogicSecId = GetLogicSecId(wLogicSecIndex);
				
				/*只发送本联锁逻辑区段信息*/
				if ((0U < wLogicSecId) && (LOGIC_SECTION_SUM_MAX> wLogicSecId))
				{
					/*组征用逻辑区段的列车数量*/
					chLogicTrainSum = GetLogSecTrainInfoSum(wLogicSecId);
					pstLogicResTrainInfo = GetLogSecTrainInfo(wLogicSecId);

					/*组逻辑区段ID*/
					ShortToChar(wLogicSecId, &pDataBuf[ii]);
					ii += 2u;

					pDataBuf[ii++] = chLogicTrainSum;
					if((0U < chLogicTrainSum))
					{
						if((LOGIC_SECTION_RES_SUM_MAX >chLogicTrainSum)
							&& (NULL != pstLogicResTrainInfo))
						{
							
							for (chTrainIndex = 0u; chTrainIndex < chLogicTrainSum; chTrainIndex++)
							{
								/*逻辑区段正常锁闭、延时解锁、异常锁闭、逻辑正常锁闭、逻辑异常锁闭时，向ATS组逻辑区段资源信息*/
								chLogLockState = GetLogSecLockState(wLogicSecId);
								chLogRouteLogLockState = GetLogSecLogLockState(wLogicSecId);
								if ((LOG_SECTION_LOCK_NORMAL == chLogLockState) || (LOG_SECTION_LOCK_DELAY == chLogLockState) || (LOG_SECTION_LOCK_EXCEPT == chLogLockState)
									|| (LOG_SECTION_LOGLOCK_NORMAL == chLogRouteLogLockState) || (LOG_SECTION_LOGLOCK_EXCEPT == chLogRouteLogLockState))
								{
									/*组车组号-2字节内部转4字节互联互通(默认发一端)*/
									(void)dquDevName2HlhtId(pstLogicResTrainInfo[chTrainIndex].wTrainId, 1u, &dwHlhtTrainId);
									LongToChar(dwHlhtTrainId, &pDataBuf[ii]);
									ii += 4u;
									if (LOGIC_SECTION_RES_USABLE == pstLogicResTrainInfo[chTrainIndex].chLogicResUsable)
									{
										chUseLockState = 0x55u;/*锁闭且可用*/
									}
									else
									{
										chUseLockState = 0x5Au;/*锁闭不可用*/
									}
									pDataBuf[ii++] = chUseLockState;
								}
								else
								{
								}
								
							}
						}
						else
						{
							chRetVal = CI_ERROR;
						}
						
					}
					else
					{
						; /*没车征用 继续执行*/
					}
				}
				else
				{
					chRetVal = CI_ERROR;
				}

				if (CI_SUCCESS != chRetVal)
				{
					break;
				}
				else
				{
				}
				
			}
			
		}
		else
		{
			/*错误，停止组包*/
			chRetVal = CI_ERROR;
		}
	}
	else
	{
	}
	if (CI_SUCCESS == chRetVal)
	{
		*wDataLength = ii;
	}
	else
	{
		chRetVal = CI_ERROR;
	}

	return chRetVal;
}

/*
* 功能描述： 检查ATS/现地的命令数据总长度有效性
* 参数说明： const UINT8* pdataBuf, 数据缓冲区
*            const UINT16 comSum, 命令帧总数量
*            const UINT16 comTotalLen, 命令数据总长度
* 返回值  ： CI_ERROR 无效
*			 CI_SUCCESS 有效
*/
UINT8 CheckATSorXiandTotalDataLenVal(const UINT8* pdataBuf, const UINT16 comSum, const UINT16 comTotalLen)
{
	UINT8 retValue = CI_ERROR;
	UINT16 i = 0u;
	UINT8 oneCmdDataLen = 0u;
	UINT16 jj = 0u;
	
	/** 入参检查*/
	if ((NULL != pdataBuf) && (0u != comSum) && (ATSORXIANDI_TO_CI_CMD_DATA_STRU_SUM_MAX >= comSum) && (0u != comTotalLen))
	{
		/** 遍历命令帧总数量，计算命令数据总长度*/
		for (jj = 0u; jj < comSum; jj++)
		{
			/** 获取单条命令的数据长度*/
			oneCmdDataLen = pdataBuf[i];
			i = i + 1u + ((UINT16)oneCmdDataLen);  /** 单条命令的数据长度不包含命令长度本身，需要加上本身的1个字节*/
		}

		/** 计算命令数据总长度,需加上命令帧总数量的2个字节*/
		i += 2u;

		/** 计算的命令数据总长度与入参发送的命令数据总长度字段相等*/
		if (comTotalLen == i)
		{
			/** 总长度有效，返回成功*/
			retValue = CI_SUCCESS;
		}
		else
		{
			/** 总长度无效，返回失败*/
			retValue = CI_ERROR;
		}
	}
	else
	{
		/** 入参不合法，返回失败*/
		retValue = CI_ERROR;
	}

	return retValue;
}
/*
* 功能描述： 故障码信息转命令反馈
* 参数说明： const UINT32 CommandId, 命令ID
*            const UINT8 CommandType, 命令类型
*            const UINT16 DeviceId, 设备ID
*			 const UINT8 virCIid, 虚拟联锁ID
* 返回值  ： 0: 设置失败
*			 1: 设置成功
* cgh-合并CID-2349-5：
*/
void errorCodeDataTransCmdBack(const UINT8 CommandType, const UINT8 deviceType, const UINT16 deviceId, const UINT8 virCIid)
{
	UINT32 deviceInfo = 0u;  /*设备信息*/

	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)deviceId) << 16) | ((deviceInfo | (UINT32)deviceType) << 8) | (UINT32)0);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CommandType;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0u;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid = virCIid;
		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:errorCodeDataTransCmdBack,%d exceed max %d\n", CiSendCmdStruCurSum, CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}

}

/*
* 功能描述： 转换Ci到ATS中OCbyte执行电插箱状态信息
* 参数说明：入参 
*            UINT8 *dataLength, 输入数据地址
*			出参
*			OcToATSPlusBox *ciSendATSPlusBox, 状态输出缓冲区	
* 返回值  ： 执行电插箱数量
*/
UINT8 TransCiToAtsOCPlusBoxInfo(OcToATSPlusBox *ciSendATSPlusBox, UINT8 *wDataLength)
{
	UINT8 chRetVal = CI_ERROR;
	UINT8 kk = 0U;
	UINT8 mm = 0U;
	UINT8 wPbNum = 0u;			/*执行电插箱数量*/
	UINT8 wPbType = 0u;			/*执行电插箱类型*/
	UINT8 wAsState = 0u;		/*执行电插箱报警类型*/

	if ((NULL == ciSendATSPlusBox)
		|| (NULL == wDataLength))
	{
		chRetVal = CI_ERROR;
	}
	else
	{
		kk = *wDataLength;
		chRetVal = CI_SUCCESS;

		wPbNum = m_OcToCiOrginDataArr[kk].chPbNum;			/*获取执行电插箱数量*/

		if (MAX_OC_PLUS_BOX_NUM >= wPbNum)
		{
			for (mm = 0U; mm < wPbNum; mm++)
			{
				ciSendATSPlusBox[mm].chPbId = m_OcToCiOrginDataArr[kk].szPlusBox[mm].chPbId;		/*获取对应电插箱编号并存下来*/
				wPbType = m_OcToCiOrginDataArr[kk].szPlusBox[mm].chPbType;
				wAsState = m_OcToCiOrginDataArr[kk].szPlusBox[mm].chAsState;
				switch (wPbType)
				{
				case TYPE_SIGNAL:								/*电插箱为信号机插箱*/
					if (HIGH_NORMAL == (wAsState & 0xf0U))			/*只需查高四位，执行电熔丝是否正常*/
					{
						ciSendATSPlusBox[mm].SendAtsAsState = FUSE_NORMAL;
					}
					else
					{
						ciSendATSPlusBox[mm].SendAtsAsState = SIGNAL_FUSE_ALARM;
					}
					break;
				case TYPE_POINT_SWITCH:							/*电插箱为转辙机插箱*/
					if (HIGH_NORMAL == (wAsState & 0xf0U))			/*高四位，执行电熔丝是否正常*/
					{
						if (LOW_NORMAL == (wAsState & 0x0fU))		/*低四位，表示电熔丝是否正常*/
						{
							ciSendATSPlusBox[mm].SendAtsAsState = FUSE_NORMAL;
						}
						else
						{
							ciSendATSPlusBox[mm].SendAtsAsState = POINT_SWITCH_EXPRESSED_FUSE_ALARM;
						}
					}
					else
					{
						if (LOW_NORMAL == (wAsState & 0x0fU))		/*低四位，表示电熔丝是否正常*/
						{
							ciSendATSPlusBox[mm].SendAtsAsState = POINT_SWITCH_EXECUTIVE_FUSE_ALARM;
						}
						else
						{
							ciSendATSPlusBox[mm].SendAtsAsState = POINT_SWITCH_FUSE_ALARM;
						}
					}
					break;
				default:
					/*不可达分支*/
					break;
				}
			}
		}
		else
		{
			;	/*OC获取的执行电插箱数据错误*/
		}
	}
	return wPbNum;
}
/*
* 功能描述： 转换Ci到ATS中OCbyte双系电源状态信息
* 参数说明：入参
*            UINT8 PowerState, 电源状态
*			出参
*			无
* 返回值  ： 转换后的电源状态
*/
static UINT8 TransCiToAtsPowerState(UINT8 PowerState)
{
	UINT8 Power_state = DUAL_WAY_AIR_SWITCH_ABNORMAL_ATS;

	if (DUAL_WAY_AIR_SWITCH_NORMAL == PowerState)
	{
		Power_state = DUAL_WAY_AIR_SWITCH_NORMAL_ATS;
	}
	else if (SINGLE_WAY_AIR_SWITCH_ABNORMAL == PowerState)
	{
		Power_state = SINGLE_WAY_AIR_SWITCH_ABNORMAL_ATS;
	}
	else
	{
		Power_state = DUAL_WAY_AIR_SWITCH_ABNORMAL_ATS;
	}

	return Power_state;
}

/*
* 功能描述： 转换Ci到ATS中OCbyte风扇状态信息
* 参数说明：入参
*            UINT8 fanState, 风扇状态
*			出参
*			无
* 返回值  ： 转换后的风扇状态
*/
static UINT8 TransCiToAtsFanState(UINT8 fanState)
{
	UINT8 Fan_state = AirFan_ABNORMAL_ATS;

	if (AirFan_NORMAL == fanState)
	{
		Fan_state = AirFan_NORMAL_ATS;
	}
	else if (AirFan_Fault == fanState)
	{
		Fan_state = AirFan_Fault_ATS;
	}
	else
	{
		Fan_state = AirFan_ABNORMAL_ATS;
	}

	return Fan_state;
}

/*
* 功能描述： 转换Ci到ATS中OCbyte风扇状态信息
* 参数说明：入参
*            UINT8 ocDevFaultState, OC设备故障状态
*			出参
*			无
* 返回值  ： 转换后的设备故障状态
*/
static UINT8 TransCiToAtsOcDevFaultState(UINT8 ocDevFaultState)
{
	UINT8 ocDevFault_state = OC_CARD_ABNORMAL_ATS;

	if (OC_CARD_NORMAL == ocDevFaultState)
	{
		ocDevFault_state = OC_CARD_NORMAL_ATS;
	}
	else
	{
		ocDevFault_state = OC_CARD_ABNORMAL_ATS;
	}

	return ocDevFault_state;
}

/*
* 功能描述： 转换Ci到ATS中PSC 工作状态表示灯状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscState  psc工作状态表示灯状态
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscState)
{
	UINT8 TransCiSendData = 0u;

	if (ALARM_MAIN_WORK_STATE == PscState)
	{/*PSC 工作状态表示灯*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000001B << MoveNum));
	}
	else if (ALARM_BACKUP_WORK_STATE == PscState)
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000010B << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}

	return TransCiSendData;
}

/*
* 功能描述： 转换Ci到ATS中PSC 各状态表示灯信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscState  psc工作状态表示灯状态
*			UINT8 BitValY  if成立要左移的宏值数据
*			UINT8 BitValN  if不成立要左移的宏值数据
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscState, UINT8 BitValY,UINT8 BitValN)
{
	UINT8 TransCiSendData = 0u;

	if (ALARM_STATE_NO == PscState)
	{/*PSC 各状态表示灯*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValY << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValN << MoveNum));
	}

	return TransCiSendData;
}

/*
* 功能描述： 转换Ci到ATS中PSC 各类型状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PscStatetype	psC状态对应类型
*			UINT8 PscState  psc对应类型状态
*			UINT8 BitValY  if成立要左移的宏值数据
*			UINT8 BitValN  if不成立要左移的宏值数据
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSCtypeState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PscStatetype, UINT8 PscState, UINT8 BitValY, UINT8 BitValN)
{
	UINT8 TransCiSendData = 0u;

	if (PscState == PscStatetype)
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValY << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValN << MoveNum));
	}

	return TransCiSendData;
}
#if 0
/*
* 功能描述： 根据OCid发送OC站电源指示灯状态
* 参数说明： void
* 返回值  ：无
* cgh-合并CID-3037-3\cgh-合并CID-3037-5：：
*/
UINT8 packOcStationPowerIndic(UINT8 ocid)
{
	UINT16 devCurSum = GetOCStationIndicCurSum(); /*获取OC站表示灯当前总数*/
	UINT16 i = 0u;
	UINT8 belongOcid = 0u;
	UINT8 indicId = 0u;
	UINT8 indicType = 0u;
	UINT8 reval = 0u;
	UINT8 indicState = 0u;
	for (i = 0u; i < devCurSum; i++)
	{
		belongOcid = GetOCStationIndicOcIdByIndex(i);
		if (ocid == belongOcid)
		{
			indicId = GetOCStationIndicIdByIndex(i);
			indicType = GetOCStationIndicType(ocid, indicId);
			indicState = GetOCStationIndicState(ocid, indicId);
			if (INDICATOR_SHOW_YES == indicState)
			{
				indicState = CLOASE_STATE;
			}
			else
			{
				indicState = BREAK_STATE;
			}

			switch (indicType)
			{
			case INDIC_POWER_I_1:
				reval = reval | indicState;
				break;
			case INDIC_POWER_I_2:
				reval = reval | (indicState << 2);
				break;
			case INDIC_POWER_II_1:
				reval = reval | (indicState << 4);
				break;
			case INDIC_POWER_II_2:
				reval = reval | (indicState << 6);
				break;
			default:
				break;
			}
		}
	}
	return reval;
}
#endif

/*
* 功能描述： 转换Ci到ATS中多机牵引道岔转辙机数目状态信息
* 参数说明：入参
*            UINT8 *wDataLength, 输入数据地址
*			出参
*			OcToATSSwitchZzjData *ciSendAtsSwitchZzjData, 状态输出缓冲区
* 返回值  ： 多机牵引道岔数量
* by cgh 20230918 成都三线道岔转辙机故障显示方案
*/
UINT16 TransCiToAtsSwitchZzjInfo(OcToATSSwitchZzjData* ciSendAtsSwitchZzjData, UINT8* wDataLength)
{
	UINT16 wSwitchNum = 0U;	/*多机牵引道岔数量*/
	UINT8 kk = 0U;/*OC ID的索引*/
	UINT16 ii = 0U;/*遍历设备的索引*/
	UINT8 jj = 0U;/*道岔对应转辙机的索引*/
	UINT8 mm = 0U;/*道岔状态四开时，判断是否有异常情况循环体*/
	UINT8 chSwitchDriveFlag = 0U;/*道岔驱动过标志*/
	UINT8 chSingleSwitchCurPosition = 0u;/*道岔当前单独位置*/

	if ((NULL != ciSendAtsSwitchZzjData)
		&& (NULL != wDataLength))
	{
		kk = *wDataLength;
		for (ii = 0U; ii < m_OcToCiOrginDataArr[kk].OcDeviceNum; ii++)
		{
			if (OC_DEVICE_TYPE_SWITCH == m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceType)
			{
				/*设备类型是道岔才存在以下判断逻辑*/
				if (1U < m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum)
				{
					/*道岔对应转辙机数目大于1说明是多机牵引道岔,满足条件，将状态输出*/
					ciSendAtsSwitchZzjData[wSwitchNum].wSwitchId = m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceId;
					ciSendAtsSwitchZzjData[wSwitchNum].chSwIncludeZzjSum = m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum;
					if ((OC_SWITCH_POSITION_DINGWEI == m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceState)
						|| (OC_SWITCH_POSITION_FANWEI == m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceState)
						|| (OC_SWITCH_POSITION_MOVE == m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceState))
					{
						/*（1）OC给CI的道岔当前状态为定位或反位时，说明对应的转辙机状态也是定位或者反位，此时均无故障
						  （2）OC给CI的道岔当前状态为移动中，此时转辙机状态为四开，但此时不判断为故障，此时均无故障*/
						for (jj = 0U; jj < m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum; jj++)
						{
							ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_NORMAL;
						}
						
					}
					else if(OC_SWITCH_POSITION_UNKNOW == m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceState)
					{
						/*OC给CI的道岔当前状态为未知，设置对应的转辙机状态为故障,未知状态不会单独一块转辙机出现*/
						for (jj = 0U; jj < m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum; jj++)
						{
							ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_ALARM;
						}
					}
					else
					{
						/*OC给CI的道岔当前状态为四开*/
						for (jj = 0U; jj < m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum; jj++)
						{
							if ((OC_SWITCH_POSITION_FANWEI == m_OcToCiOrginDataArr[kk].OcDevices[ii].szSwitchIncldeZzjState[jj])
								|| ((OC_SWITCH_POSITION_DINGWEI == m_OcToCiOrginDataArr[kk].OcDevices[ii].szSwitchIncldeZzjState[jj])))
							{
#if 0
								/*遍历一下其他的转辙机状态，防止一个转辙机状态为定表 同时存在其他转辙机反表（电路设计道岔驱动定位只采集定表相关，不会采集到反位，此情况不存在，但需要判断为故障）或者未知（异常情况，安全通信板应用逻辑，未知状态不会单独一块转辙机出现）*/
								for (mm = 0U; mm < m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum; mm++)
								{
									if (((UINT8)(~m_OcToCiOrginDataArr[kk].OcDevices[ii].szSwitchIncldeZzjState[jj]) == m_OcToCiOrginDataArr[kk].OcDevices[ii].szSwitchIncldeZzjState[mm])
										|| (OC_SWITCH_POSITION_UNKNOW == m_OcToCiOrginDataArr[kk].OcDevices[ii].szSwitchIncldeZzjState[mm]))
									{
										break;
									}
								}
								if (m_OcToCiOrginDataArr[kk].OcDevices[ii].chSwitchIncldeZzjNum == mm)
								{
									/*没有其他转辙机与本转辙机状态相反,此转辙机状态设置为正常*/
									ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_NORMAL;
								}
								else
								{
									/*有其他转辙机与本转辙机状态相反,此转辙机状态设置为故障*/
									ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_ALARM;
								}
#endif							
								 /*18.0牵引修改 定反位认为正常*/
								ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_NORMAL;
							}
							else
							{
								chSingleSwitchCurPosition = GetSingleSwitchCurPosition(m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceId);
								if (SWITCH_POSITION_JICHA == chSingleSwitchCurPosition)
								{
									/*道岔当前挤岔，转辙机判断为故障*/
									ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_ALARM;
								}
								else
								{
									chSwitchDriveFlag = GetSwitchDrivedFlag(m_OcToCiOrginDataArr[kk].OcDevices[ii].DeviceId);
									if (SWITCH_DRIVED_FLAG_YES == chSwitchDriveFlag)
									{
										/*道岔被驱动过取消驱动，此转辙机状态设置为正常*/
										ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_NORMAL;
									}
									else
									{
										/*道岔没被驱动四开，此转辙机状态设置为正常*/
										ciSendAtsSwitchZzjData[wSwitchNum].szSwitchIncldeZzjState[jj] = OC_TO_ATS_SWITCH_ZZJ_ALARM;
									}
								}
							}
						}
					}
					wSwitchNum++;
				}
				else
				{
					; /*道岔对应转辙机数目不为0.则不是多机牵引道岔*/
				}

			}
			else
			{
				; /*信号机无此接口，跳过*/
			}
		}
	}
	return wSwitchNum;
}


/*
* 功能描述： 转换Ci到ATS中主机柜电源/电源模块状态表示灯信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 powerState  电源/电源模块状态
*			UINT8 BitValY  if成立要左移的宏值数据
*			UINT8 BitValN  if不成立要左移的宏值数据
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPowerModeState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 powerState, UINT8 BitValY, UINT8 BitValN)
{
	UINT8 TransCiSendData = 0u;

	if (CI_SUCCESS == powerState)
	{/*电源/电源模块 状态表示灯*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValY << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BitValN << MoveNum));
	}

	return TransCiSendData;
}

/*
* 功能描述： 转换Ci到ATS中PSD 驱动电源状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd驱动电源状态信息
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsDrvWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState)
{
	UINT8 TransCiSendData = 0u;

	if (PSD_DRIVE_POWER_NORMAL == PsdState)
	{/*PSD 驱动电源状态正常*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000011B << MoveNum));
	}
	else if (PSD_DRIVE_POWER_ERROR == PsdState)
	{/*故障*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}

	return TransCiSendData;
}

/*
* 功能描述： 转换Ci到ATS中PSD 控制电源状态信息
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd控制电源状态信息
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsCtlWorkState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState)
{
	UINT8 TransCiSendData = 0u;

	if (PSD_CONTROL_POWER_NORMAL == PsdState)
	{/*PSD 控制电源状态正常*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000011B << MoveNum));
	}
	else if (PSD_CONTROL_POWER_ERROR == PsdState)
	{/*故障*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}

	return TransCiSendData;
}

/*
* 功能描述： 转换Ci到ATS中PSD 边缘控制器状态
* 参数说明：入参
*            UINT8 ciToXianDiData, CI到现地数据信息
*			UINT8 MoveNum	左移位数
*			UINT8 PsdState  psd边缘控制器状态
*			出参
*			无
* 返回值  ： 转换后输出数据
*/
static UINT8 TransCiToAtsPSDEdgeState(UINT8 ciToXianDiData, UINT8 MoveNum, UINT8 PsdState)
{
	UINT8 TransCiSendData = 0u;

	if (PSD_EDGE_CONTROLLER_NORMAL == PsdState)
	{/*PSD 边缘控制器正常*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000001B << MoveNum));
	}
	else if (PSD_EDGE_CONTROLLER_ERROR == PsdState)
	{/*边缘控制器故障*/
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}
	else
	{
		TransCiSendData = ciToXianDiData | ((UINT8)(BIT_VAL_00000000B << MoveNum));
	}

	return TransCiSendData;
}


/*
* 功能描述： 组OC-P信息到ATS
* 参数说明：入参
*			UINT8* ciToXianDiDataBuffer 存放信息的buffer
*			UINT16* ii 偏移量
*			出参
*			无
* 返回值  ： 无
*/
void PackOcPscDataToAts(UINT8* ciToXianDiDataBuffer, UINT16* ii)
{
	UINT16 ocPscNum = 0u;
	UINT16 ocId = 0u;				/*psd id*/
	UINT8 ocPscConfirmFlag = 0u;
	UINT16 jj = 0u;					/*游标*/
	UINT16 index = 0u;
	UINT16 temp_index = 0u;

	if ((NULL != ciToXianDiDataBuffer) && (NULL != ii))
	{
		index = *ii;

		/*OC一体机总数量,先不组，有psdNum才组*/
		temp_index = index;
		index += 2u;

		for (jj = 0u; jj < m_OcToCiOrginDataNum; jj++)
		{
			if (0u < m_OcToCiOrginDataArr[jj].OCPsdNum)
			{/*有PSD数量*/
				ocPscNum++;

				ShortToChar(m_OcToCiOrginDataArr[jj].OcId, &ciToXianDiDataBuffer[index]);
				index += 2u;

				/*OC-P驱动电源状态*/
				ciToXianDiDataBuffer[index] = TransCiToAtsDrvWorkState(ciToXianDiDataBuffer[index], 6u, m_OcToCiOrginDataArr[jj].DrvPowerState);
				/*OC-P控制电源状态*/
				ciToXianDiDataBuffer[index] = TransCiToAtsCtlWorkState(ciToXianDiDataBuffer[index], 4u, m_OcToCiOrginDataArr[jj].CtlPowerState);
				/*边缘控制器1状态*/
				ciToXianDiDataBuffer[index] = TransCiToAtsPSDEdgeState(ciToXianDiDataBuffer[index], 2u, m_OcToCiOrginDataArr[jj].EdgeCtllerState1);
				/*边缘控制器2状态*/
				ciToXianDiDataBuffer[index] = TransCiToAtsPSDEdgeState(ciToXianDiDataBuffer[index], 0u, m_OcToCiOrginDataArr[jj].EdgeCtllerState2);
				index++;

				ocPscConfirmFlag = GetOcPscConfirmFlag(jj);

				/*旁路状态转换*/
				ciToXianDiDataBuffer[index] = TransCiToAtsPSCtypeState(ciToXianDiDataBuffer[index], 0u, ocPscConfirmFlag,
					OC_PSC_PL_CONFIRM_YES, BIT_VAL_00000000B, BIT_VAL_00000001B);

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

		/*组OC-P数量*/
		ShortToChar(ocPscNum, &ciToXianDiDataBuffer[temp_index]);
		*ii = index;
	}
	else
	{/*不处理*/
	}

}


/*
* 功能描述： 组PSD信息到ATS
* 参数说明：入参
*			UINT8* ciToXianDiDataBuffer 存放信息的buffer
*			UINT16* ii 偏移量
*			出参
*			无
* 返回值  ： 无
*/
void PackPsdDataToAts(UINT8* ciToXianDiDataBuffer, UINT16* ii)
{
	UINT8 psdDeviceSum = 0u;/*PSD设备总数*/
	UINT16 jj = 0u;	/*游标*/
	UINT16 psdId = 0u;/*psd id*/
	UINT16 index = 0u;
	UINT16 index_psd = 0u;/*用于记录组PSD数量的偏移量*/
	UINT32 tempPack = 0u;
	UINT8 psdConType = PSD_CONTROL_TYPE_RCI;
	UINT8 OcPsdSum = 0u;	/*属于OC-P的PSD数量*/


	if ((NULL != ciToXianDiDataBuffer) && (NULL != ii))
	{
		index = *ii;

		psdDeviceSum = GetPsdSum();/*PSD总数*/

		index_psd = index;
		ciToXianDiDataBuffer[index] = 0u;	/*PSD数量先组0*/
		index += 1u;

		for (jj = 0u; jj < psdDeviceSum; jj++)	/*遍历所有的PSD*/
		{
			psdId = GetPsdId(jj);/*PSD id*/
			psdConType = GetPsdControlType(psdId);

			if ((0u != psdId) && (PSD_CONTROL_TYPE_OC_P == psdConType))
			{
				OcPsdSum++;

				ShortToChar(0u, &ciToXianDiDataBuffer[index]);	/*psd id*/
				index += 2u;
				ShortToChar(psdId, &ciToXianDiDataBuffer[index]);
				index += 2u;

				tempPack = GetPsdFaultQState(psdId, HIGH_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*故障主动隔离信息*/
				index += 4u;
				tempPack = GetPsdFaultQState(psdId, LOW_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*故障主动隔离信息*/
				index += 4u;

				tempPack = GetPsdDoorIState(psdId, HIGH_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*被隔离信息*/
				index += 4u;
				tempPack = GetPsdDoorIState(psdId, LOW_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*被隔离信息*/
				index += 4u;

				tempPack = GetPsdDoorState(psdId, HIGH_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*每扇屏蔽门的开关状态*/
				index += 4u;
				tempPack = GetPsdDoorState(psdId, LOW_FOUR_CHAR);
				LongToChar(tempPack, &ciToXianDiDataBuffer[index]);/*每扇屏蔽门的开关状态*/
				index += 4u;

				tempPack = GetOpenErrState(psdId);
				ciToXianDiDataBuffer[index++] = tempPack;			/*开门故障状态*/

				tempPack = GetCloseErrState(psdId);
				ciToXianDiDataBuffer[index++] = tempPack;			/*关门故障状态*/
			}
			else
			{
				/*不处理*/
			}
		}
		debug_infor_printf("psd control type:%x\n", psdConType);
		ciToXianDiDataBuffer[index_psd] = OcPsdSum;			/*填入PSD数量*/
		
		*ii = index;
	}
	else
	{/*不处理*/
	}
}

/*
* 功能描述： 获取确认OC-P旁路状态
* 参数说明： UINT8 index, OC-P系统对应的数组下标
*
* 返回值  ： 0x55 旁路状态已确认
*			 0xaa 旁路状态未确认
*/
UINT8 GetOcPscConfirmFlag(UINT8 index)
{
	UINT8 retVal = OC_PSC_PL_CONFIRM_NO;
	UINT8 i = 0u;
	UINT8 ocPscPsdFlag = 0u;

	/*防空*/
	if (OC_SUM_MAX > index)
	{
		for (i = 0u; i < m_OcToCiOrginDataArr[index].OCPsdNum; i++)
		{
			/*获取OC-P对应PSD的旁路状态*/
			ocPscPsdFlag = GetPsdPlFlag(m_OcToCiOrginDataArr[index].PsdInfo[i].wPsdId);
			if (OC_PSC_PL_CONFIRM_YES == ocPscPsdFlag)
			{
				retVal = OC_PSC_PL_CONFIRM_YES;
				break;
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	else
	{
		/*不处理*/
	}

	return retVal;
}

/*
* 功能描述： 组通信联锁信息到ATS
* 参数说明：入参
*			UINT8* ciToXianDiDataBuffer 存放信息的buffer
*			UINT16* ii 偏移量
*			出参
*			无
* 返回值  ： 无
*/
void PackCiDataToAts(UINT8* ciToXianDiDataBuffer, UINT16* ii)
{
	UINT16 index = 0u;
	UINT8 transCiSum = 0u;
	UINT8* pCiDeviceIdBuf = NULL;         /*OC设备ID数组*/
	UINT8 jj = 0u;
	UINT8 ciAndCiCommState = 0u;/*ci与ci通信状态*/
	UINT8 ciToAtsTransState = 0u;
	UINT8 ciId = 0u;

	if ((NULL != ciToXianDiDataBuffer) && (NULL != ii))
	{
		index = *ii;

		transCiSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_CI);
		pCiDeviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_CI);

		ciToXianDiDataBuffer[index++] = transCiSum;/*通信的联锁数量*/
		if (NULL != pCiDeviceIdBuf)
		{
			for (jj = 0u; jj < transCiSum; jj++)
			{
				ciId = pCiDeviceIdBuf[jj];/*CI ID*/
				ciAndCiCommState = Get2oo2CiAndOtherSysCommState(CI_SYSTEM_TYPE_CI, (UINT8)jj);/*与联锁通信状态*/

				ciToXianDiDataBuffer[index++] = 0x00u;
				ciToXianDiDataBuffer[index++] = ciId;	/*组ID*/

				if (TRANSMIT_2OO2_STATE_GOOD == ciAndCiCommState)
				{/*双网通信良好*/
					ciToAtsTransState = TRANSMIT_CI_STATE_GOOD;
				}
				else if (TRANSMIT_2OO2_STATE_LINK == ciAndCiCommState)
				{/*单网通信故障*/
					ciToAtsTransState = TRANSMIT_CI_STATE_LINK;
				}
				else if (TRANSMIT_2OO2_STATE_BAD == ciAndCiCommState)
				{/*双网通信故障*/
					ciToAtsTransState = TRANSMIT_CI_STATE_BAD;
				}
				else
				{
					ciToAtsTransState = TRANSMIT_CI_STATE_BAD;
				}

				ciToXianDiDataBuffer[index++] = ciToAtsTransState;

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

		*ii = index;
	}
	else
	{
		/*入参检查失败，不处理*/
	}
}

/*
* 功能描述：检查批量计轴复位命令
* 参数说明：UINT8 virCIid 输入虚拟联锁ID
*		UINT8 orderType  命令类型
*       const UINT8 cPhySecSum  物理区段数量
*		const UINT16 pPhySecIdBuff[]  物理区段ID数组
* 返 回 值：无
* Created By yx 2026.04.14
*/
UINT8 CheckAxisResetCmd(UINT8 virCIid, UINT8 cmdType, const UINT8 cPhySecSum, const UINT16 pPhySecIdBuff[])
{
	UINT8 ii = 0U;
	UINT8 checkRetVal = CI_FALSE;
	UINT8 belongVirCIid = 0U;
	UINT8 OrderCheckReVal = 0U;
	UINT8 retVal = CI_ERROR;
	UINT16 wPhySecId = 0U;  /*物理区段ID*/
	if ((NULL != pPhySecIdBuff) && (0U != cPhySecSum))
	{
		for (ii = 0U; ii < cPhySecSum; ii++)
		{
			wPhySecId = pPhySecIdBuff[ii];
			checkRetVal = CheckTheDevIsNotOfDiffLine(CI_DEVICE_TYPE_PHYSEC, wPhySecId);
			belongVirCIid = GetPhySecBelongVirCiId(wPhySecId);
			OrderCheckReVal = CheckOrderWhetherDoing(virCIid, belongVirCIid, cmdType, wPhySecId);	/*检查命令能否被执行*/
			if ((CI_TRUE == checkRetVal) && (CI_SUCCESS == OrderCheckReVal))
			{
				/*继续检查*/
			}
			else
			{/*检查失败*/
				retVal = CI_ERROR;
				break;
			}			
		}
		/*所有区段都检查完成且全部通过*/
		if (ii == cPhySecSum)
		{
			retVal = CI_SUCCESS;
		}
	}
	else
	{
		/*数据错误，返回失败*/
	}	
	return retVal;
}

/*
* 功能描述： 针对批量计轴复位一次二次命令的反馈
* 参数说明： const UINT32 commandId, 命令ID
*			 const UINT16 deviceId, 设备ID
*            const UINT8 deviceType, 设备类型
*            const UINT16 termial_id,终端ID
*			 const UINT8 order_type，命令类型
*			 const UINT8 response_type, 回复类型
*            const UINT8 affirm_result, 确认结果
*			 const UINT8 virCIid, 虚拟联锁ID
*			 const UINT8 cPhySecSum  物理区段数量
*			 const UINT16 pPhySecIdBuff[]  物理区段ID数组
* 返回值  ： 无
*/
void SetAixsResetCiSendCmdBackData(const UINT32 commandId, const UINT16 deviceId, const UINT8 deviceType, const UINT16 termial_id, const UINT8 order_type, const UINT8 response_type, const UINT8 affirm_result, const UINT8 virCIid, const UINT8 cPhySecSum, const UINT16 pPhySecIdBuff[])
{
	UINT32 curCycleNum = 0U;
	UINT32 appCycTime = 0U;/*联锁周期数*/
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 cmdDeviceId = 0U;
	UINT8 cmdDevType = 0U;	
	UINT32 deviceInfo = 0U;  /*设备信息*/
	UINT32 firstOrderTimeCount = 0U;
	UINT8 checkVaild = CI_SUCCESS;
	curCycleNum = Get2oo2CurCycleNum();
	appCycTime = GetSystemParaAppCycleTime();/*获取联锁周期号*/
	firstOrderTimeCount = GetFirstOrderTimeCount();
	/*要发送二次命令时，清除暂存的一次命令*/
	if (RESPONSE_SECOND == response_type)
	{
		for (ii = 0U; ii < CiSendBackDataTempStruSum; ii++)
		{
			cmdDeviceId = (UINT16)(CiSendBackDataTempStru[ii].CommandParam >> 16U);
			cmdDevType = (UINT8)(CiSendBackDataTempStru[ii].CommandParam >> 8U);
			if ((termial_id == CiSendBackDataTempStru[ii].termial_id) && (commandId == CiSendBackDataTempStru[ii].CommandId)
				&& (deviceType == cmdDevType) && (deviceId == cmdDeviceId) && (virCIid == CiSendBackDataTempStru[ii].VirCIid)
				&& (cPhySecSum == CiSendBackDataTempStru[ii].chSectionSum))
			{
				for (jj = 0U; jj < cPhySecSum; jj++)
				{
					if (pPhySecIdBuff[jj] != CiSendBackDataTempStru[ii].wSectionData[jj])
					{
						checkVaild = CI_ERROR;
						break;
					}
					else
					{
						/*继续对比*/
					}
				}
				if (CI_SUCCESS == checkVaild)
				{
					(void)CommonMemSet((void*)&CiSendBackDataTempStru[ii], (UINT32)sizeof(CommandDataStruct), 0U, (UINT32)sizeof(CommandDataStruct));
				}
				else
				{
					/*不是同一个一次二次命令*/
				}
				
			}
		}
	}	
	/*清除暂存一次命令后，将无效命令清除，并将数量置为有效命令的数量*/
	ClearCiSendBackDataTempStruData();

	if (CiSendCmdStruCurSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
	{
		deviceInfo = (((deviceInfo | (UINT32)deviceId) << 16U) | ((deviceInfo | (UINT32)deviceType) << 8U) | (UINT32)0U);

		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandType = CI_BACK_ORDER_REPEAT;/*分类号0x70*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandId = commandId;/*命令ID  */
		CiSendCmdDataStru[CiSendCmdStruCurSum].CommandParam = deviceInfo;/*设备ID+设备类型+参数(时间值)*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].termial_id = termial_id; /*终端ID*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].order_type = order_type;/*命令类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].response_type = response_type;/*回复类型*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result = affirm_result; /*确认结果*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = 0U; /*一次命令设置周期*/
		CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].VirCIid = virCIid;
		CiSendCmdDataStru[CiSendCmdStruCurSum].OCid = 0U;
		CiSendCmdDataStru[CiSendCmdStruCurSum].chSectionSum = cPhySecSum;	/*物理区段数量*/
		if ((pPhySecIdBuff != NULL) && (cPhySecSum > 0U))
		{
			(void)CommonMemCpy((void*)CiSendCmdDataStru[CiSendCmdStruCurSum].wSectionData, (UINT32)cPhySecSum * sizeof(UINT16), (const void*)pPhySecIdBuff, (UINT32)cPhySecSum * sizeof(UINT16));	/*物理区段序列*/
		}
		if ((RESPONSE_FIRST == CiSendCmdDataStru[CiSendCmdStruCurSum].response_type) && (AFFIRM_SUCCESS == CiSendCmdDataStru[CiSendCmdStruCurSum].affirm_result))
		{/*针对一次命令设置命令周期*/
			CiSendCmdDataStru[CiSendCmdStruCurSum].setCurNum = curCycleNum; /*一次命令设置周期*/
			CiSendCmdDataStru[CiSendCmdStruCurSum].firstCmd_time = (UINT8)((firstOrderTimeCount * appCycTime) / 1000U);
			/*暂存1次命令*/
			if (CiSendBackDataTempStruSum < CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX)
			{
				(void)CommonMemCpy(&CiSendBackDataTempStru[CiSendBackDataTempStruSum], (UINT32)sizeof(CommandDataStruct), &CiSendCmdDataStru[CiSendCmdStruCurSum], (UINT32)sizeof(CommandDataStruct));
				CiSendBackDataTempStruSum++;
			}
			else
			{
				debug_infor_printf((const)"Error:CiSendBackDataTempStru,%d exceed max %d\n", CiSendBackDataTempStruSum, CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
			}
		}
		CiSendCmdStruCurSum++;
	}
	else
	{
		debug_infor_printf((const)"Error:SetAixsResetCiSendCmdBackData,%d exceed max %d\n", CiSendCmdStruCurSum, CI_TO_ATSORXIANDI_CMD_DATA_STRU_SUM_MAX);
	}
}

/*
* 功能描述： 批量计轴复位二次命令有效性检查
* 参数说明： const UINT32 commandId, 命令ID
*			 const UINT16 deviceId, 设备ID
*            const UINT8 deviceType, 设备类型
*            const UINT16 termial_id,终端ID
*			 const UINT8 order_type，命令类型
*			 const UINT8 virCIid, 虚拟联锁ID
*			 const UINT8 cPhySecSum  物理区段数量
*			 const UINT16 pPhySecIdBuff[]  物理区段ID数组
* 返回值  ：CI_ERROR : 失败
*			CI_SUCCESS: 成功
*/
UINT8 CheckAxisResetSndOrderValid(const UINT32 commandId, const UINT16 deviceId, const UINT8 deviceType, const UINT16 termial_id, const UINT8 order_type, const UINT8 virCiID, const UINT8 cPhySecSum, const UINT16 pPhySecIdBuff[])
{
	UINT16 ii = 0U;
	UINT16 jj = 0U;
	UINT8 reVal = CI_ERROR;
	UINT8 firstOrder = 0U;
	UINT16 cmdDeviceId = 0U;
	UINT8 cmdDevType = 0U;
	UINT8 checkVaild = CI_SUCCESS;
	firstOrder = FindFirstOrder(order_type);
	for (ii = 0U; ii < CiSendBackDataTempStruSum; ii++)
	{
		cmdDeviceId = (UINT16)(CiSendBackDataTempStru[ii].CommandParam >> 16U);
		cmdDevType = (UINT8)(CiSendBackDataTempStru[ii].CommandParam >> 8U);
		if ((deviceId == cmdDeviceId) && (deviceType == cmdDevType) && (commandId == CiSendBackDataTempStru[ii].CommandId)
			&& (termial_id == CiSendBackDataTempStru[ii].termial_id) && (firstOrder == CiSendBackDataTempStru[ii].order_type)
			&& (0U != firstOrder) && (virCiID == CiSendBackDataTempStru[ii].VirCIid) && (cPhySecSum == CiSendBackDataTempStru[ii].chSectionSum))
		{
			for (jj = 0U; jj < cPhySecSum; jj++)
			{
				if (pPhySecIdBuff[jj] != CiSendBackDataTempStru[ii].wSectionData[jj])
				{
					checkVaild = CI_ERROR;
					break;
				}
				else
				{
					/*继续对比*/
				}
			}
			if (CI_SUCCESS == checkVaild)
			{
				reVal = CI_SUCCESS;
			}
			else
			{
				reVal = CI_ERROR;
			}
			break;
		}
	}
	return reVal;
}