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

#include "ParsePackAxleData.h"
#include "dquCIInit.h"
#include "HLHTCommonDataPacketHead.h"
#include "HLHTHeadContexManage.h"
#include "dsuRsspFunc.h"
#include "protclStruct.h"
#include "../QueryFiles/dquCIInterFace.h"

#define PHY_SEC_RESET_CMD (0x0DU) /*直接复位命令码*/
#define PHY_SEC_PRE_RESET_CMD (0x0EU) /*预复位命令码*/
#define GAL_INTERFACE ((UINT16)0x060A) /*GAL接口信息类型*/
#define GAL_PRTCL_VER ((UINT8)0x01) /*GAL协议版本号*/
#define GAL_DATA_VER ((UINT32)0x01000000) /*GAL数据版本校验信息*/
#define AXISDATASTR_IDX ((UINT8)0xFF) /*物理区段在axisDataStr中无效位置*/

AxisToCiDataStruct axisToCiDataStru[AXIS_TO_CI_SUM_MAX] = {0u};	/*Axis到CI数据帧结构体*/
static DSU_RSSP_INFO_STRU_WL dsuRsspInfo = { 0 }; /*RSSPI查询数据信息*/

static UINT8 GalHeadCheck(const UINT32 localEtcsId, const UINT32 remoteEtcsId, const UINT16 devInterfaceType, const UINT8 prtrlVer, const UINT32 dataVer, HLHTGALInfoStruct* pMICommonPackage, UINT32* pErrorCode);
static UINT8 GetRsspiAddr(const UINT16 locTypeId, const UINT16 oppTypeId, UINT16* locRsspiAddr, UINT16* oppRsspiAddr);
static UINT8 GetPhySecIdxInAxisDataStr(const UINT8 axleId, const UINT16 phySecId, UINT8* axisDataStrIdx);

extern ProtclConfigInfoStru gCbtcData; /*通用协议结构体*/
/*
* 功能描述： 解析处理计轴通信采集数据
* 参数说明： 
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功      
*/
#if 0


UINT8 ParseAxisToCiData()
{
	QueueStruct* AxisToCiDataQueue = Get2oo2AxisToCiDataQueue();

	if (AxisToCiDataQueue != NULL)
	{
		UINT32 dataQueueTotalLen = 0u;	/*队列数据总长度*/
		UINT8 dataLenBuf[2];			/*数据长度数组*/
		UINT8 tempDataBuf[5000];		/*数据临时数组*/
		UINT16 appDataLen = 0u;			/*一帧数据长度*/
		UINT8 tempBuf[2];				/*临时数据数组*/
		UINT8 axisId = 1u;     /*实验*/            /*Axis编号*/

		/*获取队列数据总长度*/
		dataQueueTotalLen = QueueStatus(AxisToCiDataQueue);

		while (dataQueueTotalLen > 0u)
		{
			QueueScan(2, dataLenBuf, AxisToCiDataQueue);

			appDataLen = (UINT16) (ShortFromChar(dataLenBuf) + 2u);	/*获取本帧数据长度*/

			if ((dataQueueTotalLen >= appDataLen) && (appDataLen > 2u))
			{
				/*读出前2个字节数据*/
				QueueRead(2, tempBuf, AxisToCiDataQueue);

				/*从队列中读出一帧数据*/
				QueueRead(appDataLen-2, tempDataBuf, AxisToCiDataQueue);

#ifdef LOGPRINT

				debug_infor_printf((const)"\nAXIS_RECV:%d", appDataLen - 2);
				debug_out_array(0xAA, tempDataBuf, appDataLen - 2);
				
#endif
				/*解析AXIS到CI数据帧*/
				if (CI_ERROR == ParseAxisToCiDataFrame(tempDataBuf, (UINT16)(appDataLen-2), axisId))
				{
					ClearAxisData();/*清Axis数据*/
				}
			}
			else
			{
				break;
			}

			/*获取队列数据总长度*/
			dataQueueTotalLen = QueueStatus(AxisToCiDataQueue);

		}

		if (dataQueueTotalLen > 0u)
		{
			QueueClear(AxisToCiDataQueue);	/*清队列*/

			return CI_ERROR;
		}
		else
		{
			return CI_SUCCESS;
		}

	}
	else
	{
		return CI_ERROR;
	}
}
#endif

/*
* 功能描述： 初始化计轴到CI数据结构体axisToCiDataStru
* 参数说明：
* 返回值  ： CI_ERROR: 初始化失败
*			 CI_SUCCESS: 初始化成功
*/
UINT8 InitAxleToCiDataStru(void)
{
	UINT8 rtn = CI_ERROR; /*返回值*/
	UINT8 deviceSum = 0u;               /*设备总数*/
	UINT8* deviceIdBuf = NULL;         /*设备ID数组*/
	UINT8 i = 0u; /*用于循环*/
	UINT8 j = 0u; /*用于循环*/
	UINT8 ciId = 0u; /*本CI ID*/
	UINT8 axleId = 0u; /*计轴ID*/
	UINT16 axleName = 0u; /*计轴设备名称：类型+ID*/
	UINT16 ciName = 0u; /*联锁设备名称：类型+ID*/
	UINT32 axieEtcsId = 0u; /*计轴互联互通ID*/
	UINT32 ciEtcsId = 0u; /*CI互联互通ID*/
	UINT16 phySecCurSum = 0u; /*物理区段总数目*/
	UINT16 phySecId = 0u; /*物理区段ID*/
	UINT8 belongCiId = 0u; /*物理区段所属联锁ID*/
	UINT8 belongAxleSysId = 0u; /*物理区段所属计轴ID*/
	UINT16 axlePhySecSum = 0u; /*计轴系统包含物理区段数目*/
	UINT8 pyhIsThisLine = 0u;

	ciId = GetSystemParaLocalCiId();
	ciName = (CI_SYSTEM_TYPE_CI) * 256U + ciId;
	rtn = DsuRsspInitWl((const)DataPath,0,NULL,ciName, 0, &dsuRsspInfo);
	if (CI_SUCCESS == rtn)
	{
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备ID数组*/
		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{
			phySecCurSum = GetPhySecCurSum();
			for (i = 0u; i < deviceSum; i++) /*遍历需通信的计轴系统*/
			{
				axleId = deviceIdBuf[i];
				axleName = (CI_SYSTEM_TYPE_AXIS) * 256u + axleId;

				rtn = dquDevName2HlhtId(axleName, 0U, &axieEtcsId);  /*获取计轴互联互通ID*/
				rtn &= dquDevName2HlhtId(ciName, 0U, &ciEtcsId);  /*获取CI互联互通ID*/

				if (CI_SUCCESS == rtn) /*GAL层互联互通ID获取成功*/
				{
					if (axleId >= AXIS_TO_CI_SUM_MAX)
					{
						break;/*防护代码，防止越界*/
					}
					axisToCiDataStru[axleId].deviceType = CI_SYSTEM_TYPE_AXIS;
					axisToCiDataStru[axleId].axisSystemId = deviceIdBuf[i];
					axisToCiDataStru[axleId].axisEtcsId = axieEtcsId;
					axisToCiDataStru[axleId].ciEtcsId = ciEtcsId;

					(void)memset(axisToCiDataStru[axleId].PhySecIdx, (INT)AXISDATASTR_IDX, PHYSICAL_SECTION_SUM_MAX); /*默认设置下标为无效位置*/
					for (j = 0u; j < phySecCurSum; j++) /*遍历物理区段*/
					{
						phySecId = GetPhySecId(j);
						belongCiId = GetPhySecBelongCiId(phySecId);
						belongAxleSysId = GetPhySecBelongAxisSysId(phySecId);
						pyhIsThisLine = GetPhyIsThisLineState(phySecId);        /*是否本线路*/
						if ((0U < phySecId) && (phySecId < PHYSICAL_SECTION_SUM_MAX) && (belongCiId == ciId)
							&& (belongAxleSysId == axleId) && (DEV_IS_THIS_LINE_YES == pyhIsThisLine))
						{
							axlePhySecSum = axisToCiDataStru[axleId].SectionSum;

							if (CI_INCLUDE_AXIS_MAX_SUM > axlePhySecSum)
							{
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].PhySecId = phySecId;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].gdRelayState = RELAY_STATE_DOWN;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].faultInfo = 0u;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].showAndReplyInfo = 0u;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].PreResetRst = RELAY_STATE_DOWN;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].chPreResetBack = RELAY_STATE_UP;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].chDirectResetRst = RELAY_STATE_DOWN;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].chDirectResetBack = RELAY_STATE_UP;
								axisToCiDataStru[axleId].axisDataStr[axlePhySecSum].State = RELAY_STATE_DOWN;

								axisToCiDataStru[axleId].PhySecIdx[phySecId] = (UINT8)(axlePhySecSum);

								axisToCiDataStru[axleId].SectionSum++;
							}
							else /*超出最大*/
							{
								rtn = CI_ERROR;
								break;
							}
						}
					}
				}
			}
		}
		else
		{
			rtn = CI_SUCCESS;
		}
	}
	if (CI_ERROR == rtn)
	{
		debug_infor_printf((const)"InitAxleToCiDataStru fail.\r\n");
	}

	return rtn;
}

/*
* 功能描述： 解析处理计轴通信采集数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
*            const UINT8 systemId, 源设备ID
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功      
*/
UINT8 ParseAxisToCiDataFrame(const UINT8* dataBuf, const UINT16 dataLength, const UINT8 systemId)
{
	UINT8 retVal = CI_ERROR;
	UINT8 deviceSum = 0u;               /*设备总数*/
	UINT8* deviceIdBuf = NULL;         /*设备ID数组*/
	UINT16 ii = 0u; /*用于循环*/
	UINT16 jj = 0u; /*用于循环*/
	UINT8 findFlag = 0u; /*找到标志*/
	UINT8 localCiId = 0u; /*本方CI ID*/
	UINT32 curCycleNo = 0u; /*当前周期号*/
	UINT8 acFty = 0u; /*计轴系统厂家*/
	HLHTGALInfoStruct hlhtGalHead = { 0u }; /*互联互通GAL包头*/
	UINT8 headRet = HLHT_HEAD_ERROR;/*互联互通检查结果*/
	UINT32 errCode = 0u; /*GAL包头错误码*/
	INT32 remainValidiy = 0; /*剩余时间是否有效*/
	UINT8 axisDataStrIdx = AXISDATASTR_IDX; /*物理区段在axisDataStr中位置*/
	UINT8 phySecNum = 0u; /*物理区段数量*/
	UINT16 curPhySecId = 0u; /*当前物理区段ID*/
	UINT8 galPrtclVer = 0u;  /*协议版本号*/
	UINT32 galAxisDataVer = 0u; /*计轴系统数据版本号*/
	UINT32 ciAndAxisTimeOutCout = 0u; /*联锁与计轴通信中断周期数*/
	UINT32 ciCurappCycleTime = 0u; /*联锁当前周期*/
	UINT16 axisDevName = 0U; /*计轴名称：类型+ID*/
	UINT16 wPhySecCurSum = 0U; /*本控区物理区段数目*/
	UINT16 wIndexInAxle = 0U; /*物理区段的索引号*/

	deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备总数*/
	deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备ID数组*/
	axisDevName = (CI_SYSTEM_TYPE_AXIS) * 256U + systemId;
	localCiId = GetSystemParaLocalCiId();
	if ((deviceSum > 0u) && (deviceIdBuf != NULL))
	{
		for (ii = 0u; ii < deviceSum; ii++) /*遍历需通信的计轴系统*/
		{
			if (deviceIdBuf[ii] == systemId) /*找到*/
			{
				for (jj = 0u; jj < axisToCiDataStru[systemId].SectionSum; jj++) /*导安全状态*/
				{
					axisToCiDataStru[systemId].axisDataStr[jj].gdRelayState = RELAY_STATE_DOWN;
					axisToCiDataStru[systemId].axisDataStr[jj].faultInfo = 0u;
					axisToCiDataStru[systemId].axisDataStr[jj].showAndReplyInfo = 0u;
					axisToCiDataStru[systemId].axisDataStr[jj].PreResetRst = RELAY_STATE_DOWN;
					axisToCiDataStru[systemId].axisDataStr[jj].chPreResetBack = RELAY_STATE_UP;
					axisToCiDataStru[systemId].axisDataStr[jj].chDirectResetRst = RELAY_STATE_DOWN;
					axisToCiDataStru[systemId].axisDataStr[jj].chDirectResetBack = RELAY_STATE_UP;
					axisToCiDataStru[systemId].axisDataStr[jj].State = RELAY_STATE_DOWN;
				}

				findFlag = 1u;/*设置找到标志*/
			}
		}
	}

	if (1u == findFlag)
	{
		retVal = CI_SUCCESS;
		curCycleNo = Get2oo2CurCycleNum();

		ii = 0u; /*用于下标清零*/

		/*解析通用消息包头*/
		hlhtGalHead.devInterInfoType = ShortFromChar(&dataBuf[ii]);
		ii += 2u;
		hlhtGalHead.sourceId = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.destId = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.emapVerCrc = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.crntOwnMsgSN = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.comPeriod = ShortFromChar(&dataBuf[ii]);
		ii += 2u;
		hlhtGalHead.recvOppMsgSN = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.preOwnMsgSN = LongFromChar(&dataBuf[ii]);
		ii += 4u;
		hlhtGalHead.prtclVer = dataBuf[ii++];
		hlhtGalHead.totalDataLen = ShortFromChar(&dataBuf[ii]);
		ii += 2u;
		galPrtclVer = GetCiAndAxisPrtclCheckVer();   /*获取联锁与计轴系统协议版本号*/
		galAxisDataVer = GetCiTranAxisDataCheckVer(localCiId, axisDevName); /*获取计轴系统数据版本号*/
		headRet = GalHeadCheck(axisToCiDataStru[systemId].axisEtcsId, axisToCiDataStru[systemId].ciEtcsId, GAL_INTERFACE, galPrtclVer, galAxisDataVer, &hlhtGalHead, &errCode);
		debug_infor_printf((const)"\nAXLE %d GAL Check Result:%d errCode:%d", systemId, headRet, errCode);	/*0x55正确，0xaa错误，0x33初始通信帧*/

		if (HLHT_HEAD_SUCCESS == headRet)
		{
			ciAndAxisTimeOutCout = GetCiAndAxleTransBadEnsureTime();
			ciCurappCycleTime = GetSystemParaAppCycleTime();
			/*计算消息的时效性*/
			remainValidiy = HLHTCommonMsgRemainingValidity(ciAndAxisTimeOutCout, curCycleNo, ciCurappCycleTime, hlhtGalHead.recvOppMsgSN, hlhtGalHead.crntOwnMsgSN, hlhtGalHead.preOwnMsgSN, hlhtGalHead.comPeriod);

			if (remainValidiy > 0) /*有效*/
			{
				acFty = GetCiFunctionSwitchConfig(FUNC_SWITCH_AC_FACTORY);
				if (AXIS_TYPE_YONGLIE == acFty)
				{
					if(systemId < AXIS_TO_CI_SUM_MAX)
					{
						if (axisToCiDataStru[systemId].deviceType != dataBuf[ii++])		/*设备类型判定*/
						{
							retVal = CI_ERROR;
						}
						if (axisToCiDataStru[systemId].axisSystemId != dataBuf[ii++])/*源计轴主机编号，默认01*/
						{
							retVal = CI_ERROR;
						}
					}
					else
					{
						retVal = CI_ERROR;
					}
					if (CI_SUCCESS == retVal)
					{
						phySecNum = dataBuf[ii++]; /*获取计轴区段数量*/
						for (jj = 0u; jj < phySecNum; jj++)
						{
							curPhySecId = ShortFromCharLE(&dataBuf[ii]); /*获取区段ID*/
							retVal = GetPhySecIdxInAxisDataStr(systemId, curPhySecId, &axisDataStrIdx);
							ii += 2u;
							if (CI_SUCCESS == retVal)
							{
								axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = dataBuf[ii++];		/*继电器状态*/
								axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].showAndReplyInfo = dataBuf[ii++];	/*表示信息和反馈信息*/
								axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].faultInfo = dataBuf[ii++];			/*故障信息*/
							}
							else /*偏移3字节*/
							{
								ii += 3u;
							}
							/*预留*/
							ii += 1u;
						}

						retVal = CI_SUCCESS;
					}

				}
				else if (AXIS_TYPE_KEANDA == acFty)
				{
					if (0x0BU == dataBuf[ii++])
					{
						phySecNum = dataBuf[ii++]; /*获取计轴区段数量*/
						if(AXIS_TO_CI_SECTION_SUM_MAX > phySecNum)  
						{
							for (jj = 0u; jj < phySecNum; jj++)
							{
								curPhySecId = ShortFromChar(&dataBuf[ii]);  /*获取区段ID*/
								ii += 2u;
								retVal = GetPhySecIdxInAxisDataStr(systemId, curPhySecId, &axisDataStrIdx);
								if (CI_SUCCESS == retVal)
								{
									if (0x03u == ((dataBuf[ii] >> 3u) & 0x03u)) /*预复位成功*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].PreResetRst = RELAY_STATE_UP;
									}
									else if (0x02u == ((dataBuf[ii] >> 3u) & 0x03u)) /*未正确接收到区段预复位命令*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].PreResetRst = RELAY_STATE_DOWN;
									}
									else /*否则*/
									{
										retVal = CI_ERROR;  /*预复位状态非法，返回失败*/
									}

									if (0x01u == ((dataBuf[ii] >> 2u) & 0x01u)) /*计轴受扰*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].State = RELAY_STATE_DOWN;
									}
									else /*默认状态*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].State = RELAY_STATE_UP;
									}

									if (0x02u == (dataBuf[ii] & 0x03u)) /*空闲*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = RELAY_STATE_UP;
									}
									else /*占用*/
									{
										axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = RELAY_STATE_DOWN;
									}
								}
								ii += 1u;

								if (CI_SUCCESS != retVal)
								{
									retVal = CI_ERROR;
									break;  /*解析失败，停止解析，返回失败*/
								}
								else
								{
									/*继续解析*/
								}
							}
						}
						else /*一个计轴子系统发送的物理区段数量最大值超限*/
						{
							/*将计轴区段安全侧处理*/
							for (jj = 0u; jj < phySecNum; jj++)
							{
								curPhySecId = ShortFromChar(&dataBuf[ii]);  /*获取区段ID*/
								ii += 2u;
								retVal = GetPhySecIdxInAxisDataStr(systemId, curPhySecId, &axisDataStrIdx);
								if (CI_SUCCESS == retVal)
								{
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].PreResetRst = RELAY_STATE_DOWN;

									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].State = RELAY_STATE_UP;

									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = RELAY_STATE_DOWN;
								}
								ii += 1u;

							}
						}
					}
					else
					{
						retVal = CI_ERROR;
					}
				}
				else if (AXIS_TYPE_FUHAOSHENG == acFty)
				{
					phySecNum = dataBuf[ii++]; /*获取计轴区段数量*/
					wPhySecCurSum = axisToCiDataStru[systemId].SectionSum;
	
					if ((AXIS_TO_CI_SECTION_SUM_MAX > phySecNum) && (wPhySecCurSum == phySecNum))
					{
						/*计轴设备工作健康状态只解析不处理*/
						ii++;
						for (jj = 0u; jj < phySecNum; jj++)
						{
							wIndexInAxle += 1U;
							retVal = GetInAxlePhySecIdx(systemId, wIndexInAxle, &axisDataStrIdx);

							if (CI_SUCCESS == retVal)
							{
								if (0x02U == (dataBuf[ii] & 0x03U))
								{
									/*10B:区段空闲*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = RELAY_STATE_UP;
								}
								else if((0x00U == (dataBuf[ii] & 0x03U)) || (0x01U == (dataBuf[ii] & 0x03U)))
								{	/*01B:区段占用*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].gdRelayState = RELAY_STATE_DOWN;
								}
								else
								{
									retVal = CI_ERROR;
									debug_infor_printf((const)"\nwIndexInAxle:%d OccState ERROR\n", wIndexInAxle);

								}
							}
							else
							{
								;
							}

							if (CI_SUCCESS == retVal)
							{
								if (0x01U == ((dataBuf[ii] >> 2U) & 0x01U))
								{
									/*计轴受扰*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].State = RELAY_STATE_DOWN;
								}
								else
								{
									/*默认状态*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].State = RELAY_STATE_UP;
								}
							}
							else
							{
								;
							}

							if (CI_SUCCESS == retVal)
							{
								if (0x01U == ((dataBuf[ii] >> 3U) & 0x01U))
								{
									/*未接受到计轴立即复位命令*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chDirectResetBack = RELAY_STATE_DOWN;
								}
								else
								{
									/*接受到计轴立即复位命令*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chDirectResetBack = RELAY_STATE_UP;
								}
							}
							else
							{
								;
							}

							if (CI_SUCCESS == retVal)
							{
								if (0x01U == ((dataBuf[ii] >> 4U) & 0x01U))
								{
									/*计轴立即复位成功*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chDirectResetRst = RELAY_STATE_UP;
								}
								else
								{
									/*计轴立即复位未执行或者执行未成功*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chDirectResetRst = RELAY_STATE_DOWN;
								}
							}
							else
							{
								;
							}

							if (CI_SUCCESS == retVal)
							{
								if (0x01U == ((dataBuf[ii] >> 5U) & 0x01U))
								{
									/*未接受到计轴预复位命令*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chPreResetBack = RELAY_STATE_DOWN;
								}
								else
								{
									/*接受到计轴预复位命令*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].chPreResetBack = RELAY_STATE_UP;
								}
							}
							else
							{
								;
							}

							if (CI_SUCCESS == retVal)
							{
								if (0x01U == ((dataBuf[ii] >> 6U) & 0x01U))
								{
									/*计轴预复位成功*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].PreResetRst = RELAY_STATE_UP;
								}
								else
								{
									/*计轴预复位未执行或者执行未成功*/
									axisToCiDataStru[systemId].axisDataStr[axisDataStrIdx].PreResetRst = RELAY_STATE_DOWN;
								}
							}
							else
							{
								;
							}

							/*计轴区段状态*/
							ii++;

							if (CI_SUCCESS != retVal)
							{
								retVal = CI_ERROR;
								break;  /*解析失败，停止解析，返回失败*/
							}
							else
							{
								/*继续解析*/
							}
						}

						if (CI_SUCCESS == retVal)
						{
							/*包含的计轴磁头数量*/
							ii++;
						}
						else
						{
							;
						}
					}
					else
					{
						retVal = CI_ERROR;
						debug_infor_printf((const)"\nAxis phySecNum:%d ERROR,RC wPhySecCurSum::%d\n", phySecNum, wPhySecCurSum);
					}				
				}
				else
				{
					retVal = CI_ERROR;
				}
			}
			else /*无效*/
			{
				retVal = CI_ERROR;
				debug_infor_printf((const)"\naxleSys gal check err.axleSysId=%d,remainValidiy=%d,curCycle=%d,RSN=%d,TSN=%d,LTSN=%d", systemId, remainValidiy, curCycleNo, hlhtGalHead.recvOppMsgSN, hlhtGalHead.crntOwnMsgSN, hlhtGalHead.preOwnMsgSN);
			}

			if (CI_SUCCESS == retVal)
			{
				/*数据经过校验，需要存储通用报文上下文*/
				SetHLHTHeadCtxComPeriod(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.comPeriod);
				SetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.crntOwnMsgSN);
				SetHLHTHeadCtxSrcOppSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.recvOppMsgSN);
				SetHLHTHeadCtxSrcOwnSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.preOwnMsgSN);
				SetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_AXIS, systemId, curCycleNo);
			}
		}
		else if (HLHT_HEAD_INIT == headRet)
		{
			if (curCycleNo > 0u)
			{
				SetHLHTHeadCtxComPeriod(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.comPeriod);
				SetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.crntOwnMsgSN);
				SetHLHTHeadCtxSrcOppSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.recvOppMsgSN);
				SetHLHTHeadCtxSrcOwnSN(CI_SYSTEM_TYPE_AXIS, systemId, hlhtGalHead.preOwnMsgSN);
				SetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_AXIS, systemId, curCycleNo);
			}
			retVal = CI_SUCCESS;
		}
		else
		{
			retVal = CI_ERROR;
		}

		if (CI_SUCCESS == retVal)
		{
			localCiId = GetSystemParaLocalCiId();
			/*更新通信周期*/
			if (CI_SUCCESS == SetCiTransmitRecvDataCycNum(localCiId, CI_SYSTEM_TYPE_AXIS, systemId, curCycleNo))
			{/*更新周期成功*/

				/*更新与axis通信状态：判断与axis是否通信中断*/
				if (CI_ERROR == UpdateCiTransmitState(localCiId, CI_SYSTEM_TYPE_AXIS, systemId))
				{
					/*更新通信状态失败*/
				}
				else
				{
					/*更新通信状态成功*/
				}
			}
		}
		else
		{
			/*解析出错，导向占用*/
			for (jj = 0u; jj < axisToCiDataStru[systemId].SectionSum; jj++) /*导安全状态*/
			{
				axisToCiDataStru[systemId].axisDataStr[jj].gdRelayState = RELAY_STATE_DOWN;
				axisToCiDataStru[systemId].axisDataStr[jj].faultInfo = 0u;
				axisToCiDataStru[systemId].axisDataStr[jj].showAndReplyInfo = 0u;
				axisToCiDataStru[systemId].axisDataStr[jj].PreResetRst = RELAY_STATE_DOWN;
				axisToCiDataStru[systemId].axisDataStr[jj].chPreResetBack = RELAY_STATE_UP;
				axisToCiDataStru[systemId].axisDataStr[jj].chDirectResetRst = RELAY_STATE_DOWN;
				axisToCiDataStru[systemId].axisDataStr[jj].chDirectResetBack = RELAY_STATE_UP;
				axisToCiDataStru[systemId].axisDataStr[jj].State = RELAY_STATE_DOWN;
			}

		}
	}
	else
	{
		retVal = CI_ERROR;
	}

	return retVal;
}

/*
* 功能描述： 获取计轴采集数据结构体数组
* 参数说明： void    
* 返回值  ： NULL: 获取失败
*           !NULL: 采集板结构体数组指针      
*/
AxisToCiDataStruct* GetCollAxisDataStruct(void)
{
	return axisToCiDataStru;
}

/*
* 功能描述： 清除Axis数据
* 参数说明： void
* 返回值  ： void
*/
void ClearAxisData(void)
{
	UINT16 ii = 0u;
	UINT16 kk = 0u;

	for (kk=0u;kk<AXIS_TO_CI_SUM_MAX;kk++)
	{

		for (ii = 0u; ii < CI_INCLUDE_AXIS_MAX_SUM; ii ++)
		{
			axisToCiDataStru[kk].axisDataStr[ii].PhySecId = 0u;
			axisToCiDataStru[kk].axisDataStr[ii].faultInfo = 0u;
			axisToCiDataStru[kk].axisDataStr[ii].showAndReplyInfo = 0u;
		}
		axisToCiDataStru[kk].deviceType = 0u;
		axisToCiDataStru[kk].SectionSum = 0u;
	}
}

/*
* 功能描述： 组Axis数据
* 参数说明： UINT8 axisSysId,计轴区段ID
* 返回值  ： 0:组数据失败
*			 1:组数据成功      
*/
UINT8 PackCiToAxisData(UINT8 axisSysId)
{
	UINT8 retVal = CI_ERROR; /*返回值*/
	UINT8 CiToAxisDataBuffer[CI_TO_AXIS_DATA_LEN_MAX] = { 0u }; /*CI到Axis组帧数组*/
	UINT16 phySecId = 0u; /*物理区段ID*/
	UINT8 relaySta = 0u; /*继电器状态*/
	UINT16 ii = 0u; /*用于循环*/
	UINT16 jj = 0u; /*用于循环*/
	UINT16 phySumIndex = 0u; /*物理区段数量位置*/
	UINT16 phyCount = 0u; /*物理区段数量*/
	UINT32 fwCycle = 0u; /*复位周期*/
	UINT8 acFty = 0u; /*计轴系统厂家*/
	UINT8 resetType = 0u; /*计轴复位类型*/
	UINT32 cmdIdx = 0u; /*命令码下标位置*/
	UINT8 isDiffCmd = 0u; /*物理区段中同时有复位预复位命令*/
	UINT32 curCycleNum = Get2oo2CurCycleNum();	/*联锁应用周期号*/
	UINT32 appCycleTime = GetSystemParaAppCycleTime();	/*联锁应用周期*/
	UINT8 localCiId = 0u;  /*协议版本号*/
	UINT8 galPrtclVer = 0u;  /*协议版本号*/
	UINT32 galAxisDataVer = 0u; /*计轴系统数据版本号*/
	UINT16 dstDevId = 0u;
	UINT8 outnetSafeSendRtn = 0u;
	UINT16 axisDevName = 0u; /*计轴名称：类型+ID*/
	UINT8* pDataByteIndex = NULL; /*数据比特位索引地址*/
	UINT8 chDataCurPos = 0U;/*数据当前位置*/
	UINT8 chOffset = 0U;/*偏移量*/
	UINT8 chSecResetBackState = 0U;/*区段复位状态*/
	UINT16 wIndexInAxle = 0U; /*物理区段的索引号*/

	axisDevName = (CI_SYSTEM_TYPE_AXIS) * 256U + axisSysId;
	if (AXIS_TO_CI_SUM_MAX > axisSysId)
	{
		retVal = CI_SUCCESS;
	}
	if (CI_SUCCESS == retVal)
	{
#if 0
#ifdef PLATFORM_2OO2
		/*通用协议帧头*/
		ii += 2u;
		CiToAxisDataBuffer[ii++] = CI_SYSTEM_TYPE_AXIS;/*接收端设备类型*/
		CiToAxisDataBuffer[ii++] = axisSysId;	   /*接收端设设备ID*/
		CiToAxisDataBuffer[ii++] = 0u;            /*预留2BYTE*/
		CiToAxisDataBuffer[ii++] = 0u;
#endif
#endif
		localCiId = GetSystemParaLocalCiId();
		galPrtclVer = GetCiAndAxisPrtclCheckVer();
		galAxisDataVer = GetCiTranAxisDataCheckVer(localCiId, axisDevName);
		ShortToChar(GAL_INTERFACE, &CiToAxisDataBuffer[ii]);/*接口信息类型*/
		ii += 2u;
		LongToChar(axisToCiDataStru[axisSysId].ciEtcsId, &CiToAxisDataBuffer[ii]);/*发送方标识信息*/
		ii += 4u;
		LongToChar(axisToCiDataStru[axisSysId].axisEtcsId, &CiToAxisDataBuffer[ii]);/*接收方标识信息*/
		ii += 4u;
		LongToChar(galAxisDataVer, &CiToAxisDataBuffer[ii]);/*电子地图版本校验信息*/
		ii += 4u;
		LongToChar(curCycleNum, &CiToAxisDataBuffer[ii]);/*本方消息序列号*/
		ii += 4u;
		ShortToChar((UINT16)appCycleTime, &CiToAxisDataBuffer[ii]);/*设备通讯周期*/
		ii += 2u;
		LongToChar(GetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_AXIS, axisSysId), &CiToAxisDataBuffer[ii]);/*对方消息序列号：recvOppMsgSN记录收到对方上一条消息中的对方消息序列号*/
		ii += 4u;
		LongToChar(GetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_AXIS, axisSysId), &CiToAxisDataBuffer[ii]);/*收到上一条消息时本方序列号*/
		ii += 4u;
		CiToAxisDataBuffer[ii++] = galPrtclVer; /*CI_VOBC接口协议版本号*/
		ii += 2u;/*通用报文头中的应用层报文总长度*/

		acFty = GetCiFunctionSwitchConfig(FUNC_SWITCH_AC_FACTORY);
		if (AXIS_TYPE_YONGLIE == acFty)
		{
			/*开始组应用数据帧*/
			CiToAxisDataBuffer[ii++] = Get2oo2SheBeiType();/*发送端设备类型*/
			CiToAxisDataBuffer[ii++] = axisSysId; /*计轴主机编号*/
			phyCount = axisToCiDataStru[axisSysId].SectionSum;
			CiToAxisDataBuffer[ii++] = (UINT8)(phyCount); /*区段数量*/
			for (jj = 0u; jj < phyCount; jj++)
			{
				phySecId = axisToCiDataStru[axisSysId].axisDataStr[jj].PhySecId;

				ShortToCharLE(phySecId, &CiToAxisDataBuffer[ii]);
				ii += 2u;

				fwCycle = GetPhySecResetStartCycNum(phySecId);
				if (0u < fwCycle)
				{
					relaySta = RELAY_STATE_UP;
					if (1U == (axisToCiDataStru[axisSysId].axisDataStr[jj].showAndReplyInfo & 0x01U))
					{
						relaySta = RELAY_STATE_DOWN;
					}
					else
					{
					}
				}
				else
				{
					relaySta = RELAY_STATE_DOWN;
				}
				CiToAxisDataBuffer[ii++] = relaySta;/*复零输入1*/
				CiToAxisDataBuffer[ii++] = 0u;/*复零输入2*/
				ii++;/*预留*/
				CiToAxisDataBuffer[ii++] = relaySta;/*正负1轴抗干扰输入*/
			}
		}
		else if (AXIS_TYPE_KEANDA == acFty)
		{
			cmdIdx = ii; /*记录命令码下标位置*/
			ii += 1u;
			phySumIndex = ii;
			phyCount = axisToCiDataStru[axisSysId].SectionSum;
			CiToAxisDataBuffer[ii] = (UINT8)(phyCount);
			ii += 1u;
			for (jj = 0u; jj < phyCount; jj++)
			{
				phySecId = axisToCiDataStru[axisSysId].axisDataStr[jj].PhySecId; /*区段ID*/
				ShortToChar(phySecId, &CiToAxisDataBuffer[ii]);	/*区段ID，大端*/
				ii += 2u;

				fwCycle = GetPhySecResetStartCycNum(phySecId);
				if (0u < fwCycle)
				{
					relaySta = RELAY_STATE_UP;
				}
				else
				{
					relaySta = RELAY_STATE_DOWN;
				}
				resetType = GetPhySecSectionResetType(phySecId);
				if ((PHYSICAL_SECTION_PRE_RESET_NO == resetType) && (RELAY_STATE_UP == relaySta)) /*直接复位*/
				{
					if (PHY_SEC_PRE_RESET_CMD == CiToAxisDataBuffer[cmdIdx]) /*其他物理区段已有预复位命令码*/
					{
						isDiffCmd = 1u;
					}
					else
					{
					}
					CiToAxisDataBuffer[cmdIdx] = PHY_SEC_RESET_CMD; /*命令码,直接复位*/
					CiToAxisDataBuffer[ii++] = 0x01u; /*下发立即复位命令*/
				}
				else if ((PHYSICAL_SECTION_PRE_RESET_YES == resetType) && (RELAY_STATE_UP == relaySta)) /*预复位*/
				{
					if (PHY_SEC_RESET_CMD == CiToAxisDataBuffer[cmdIdx]) /*其他物理区段已有直接复位命令码*/
					{
						isDiffCmd = 1u;
					}
					else
					{
					}
					CiToAxisDataBuffer[cmdIdx] = PHY_SEC_PRE_RESET_CMD; /*命令码,预复位*/
					CiToAxisDataBuffer[ii++] = 0x01u; /*下发预复位命令*/
				}
				else /*默认0x00指令*/
				{
					CiToAxisDataBuffer[ii++] = 0x00u;
				}

			}
			if (0u == CiToAxisDataBuffer[cmdIdx]) /*物理区段中无直接复位和预复位命令,默认预复位命令码,0x00指令*/
			{
				CiToAxisDataBuffer[cmdIdx] = PHY_SEC_PRE_RESET_CMD;
			}
			else
			{
			}

			if (1u == isDiffCmd) /*调整为默认预复位命令码,0x00指令*/
			{
				CiToAxisDataBuffer[cmdIdx] = PHY_SEC_PRE_RESET_CMD;
				for (jj = 1u; jj <= phyCount; jj++)
				{
					CiToAxisDataBuffer[phySumIndex + (2U + 1U) * jj] = 0x00u;
				}
			}
			else
			{
			}
		}
		else if (AXIS_TYPE_FUHAOSHENG == acFty)
		{
			phyCount = axisToCiDataStru[axisSysId].SectionSum;
			CiToAxisDataBuffer[ii] = (UINT8)(phyCount);
			ii++;

			for (jj = 0U; jj < phyCount; jj++)
			{
				/*先处理计轴直接复位*/
				/*每一个字节存储4个区段复位命令*/
				chDataCurPos = jj % SEC_NUM_PER_BYTE;

				if (0U == chDataCurPos)
				{
					pDataByteIndex = &CiToAxisDataBuffer[ii];
					ii++;
				}
				else
				{
					/*没有满一个字节，继续等待*/
					;
				}

				chOffset = chDataCurPos * BIT_NUM_PER_SEC;
				
				wIndexInAxle += 1U;
				phySecId = GetPhyIdByIndexInAxle(axisSysId, wIndexInAxle); /*区段ID*/
				fwCycle = GetPhySecResetStartCycNum(phySecId);

				if (0U < fwCycle)
				{
					resetType = GetPhySecSectionResetType(phySecId);
					if (PHYSICAL_SECTION_PRE_RESET_NO == resetType)
					{
						/*处理直接复位*/
						chSecResetBackState = GetPhySecDirectResetBack(phySecId);
						if (PHY_RESET_BACK_RECIVE_NO == chSecResetBackState)
						{
							/*发送*/
							*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X02U << chOffset));
						}
						else
						{
							/*不发送*/
							*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
						}
					}
					else if (PHYSICAL_SECTION_PRE_RESET_YES == resetType)
					{
						/*预复位等待不发送*/
						*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
					}
					else
					{
						retVal = CI_ERROR;
					}
				}
				else
				{
					/*不发送*/
					*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
				}

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

			if (CI_SUCCESS == retVal)
			{
				wIndexInAxle = 0U;
				for (jj = 0U; jj < phyCount; jj++)
				{
					/*处理计轴预复位*/
					/*每一个字节存储4个区段复位命令*/
					chDataCurPos = jj % SEC_NUM_PER_BYTE;

					if (0U == chDataCurPos)
					{
						pDataByteIndex = &CiToAxisDataBuffer[ii];
						ii++;
					}
					else
					{
						/*没有满一个字节，继续等待*/
						;
					}

					chOffset = chDataCurPos * BIT_NUM_PER_SEC;

					wIndexInAxle += 1U;
					phySecId = GetPhyIdByIndexInAxle(axisSysId, wIndexInAxle); /*区段ID*/
					fwCycle = GetPhySecResetStartCycNum(phySecId);

					if (0U < fwCycle)
					{
						resetType = GetPhySecSectionResetType(phySecId);
						if (PHYSICAL_SECTION_PRE_RESET_NO == resetType)
						{
							/*直接复位等待不发送*/
							/*不发送*/
							*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
						}
						else if (PHYSICAL_SECTION_PRE_RESET_YES == resetType)
						{
							chSecResetBackState = GetPhySecPreResetBack(phySecId);
							if (PHY_RESET_BACK_RECIVE_NO == chSecResetBackState)
							{
								/*发送*/
								*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X02U << chOffset));
							}
							else
							{
								/*不发送*/
								*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
							}
						}
						else
						{
							retVal = CI_ERROR;
						}
					}
					else
					{
						/*不发送*/
						*pDataByteIndex = *pDataByteIndex | ((UINT8)(0X00U << chOffset));
					}

					if (CI_ERROR == retVal)
					{
						break;
					}
					else
					{
						; /*继续*/
					}
				}
			}
			else
			{
				; /*不继续组包*/
			}
		}
		else
		{
			retVal = CI_ERROR;
		}

		/*通用报文头中应用层报文总长度*/
		CiToAxisDataBuffer[29] = (UINT8)(((ii - 31U) >> 8u) & 0xffu);
		CiToAxisDataBuffer[30] = (UINT8)((ii - 31U) & 0xffu);
#if 0
		/*所有数据包总长度 */
		CiToAxisDataBuffer[0] = (UINT8)(((ii - 2u) >> 8u) & 0xffu);
		CiToAxisDataBuffer[1] = (UINT8)((ii - 2u) & 0xffu);

		/*重置继电器驱动状态，注释掉，否则，CI给OC的继电器驱动会被清除*/
		ClearRelayDriveState();
#endif
		if (CI_TO_AXIS_DATA_LEN_MAX < ii )
		{
			retVal = CI_ERROR;
		}
		else
		{
		}

		if (CI_SUCCESS == retVal)/*如果之前的操作是成功的*/
		{
			dstDevId = (((UINT16)(CI_SYSTEM_TYPE_AXIS << 8u)) | ((UINT16)axisSysId));
			outnetSafeSendRtn = OutnetSafeSend(dstDevId, 1U, &CiToAxisDataBuffer[0], ii);
			if (1u == outnetSafeSendRtn)
			{ /*写队列成功*/
#ifdef LOGPRINT/*日志打印宏*/			
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nAXIS_SEND:%d", ii);
				debug_out_array(0xAA, CiToAxisDataBuffer, ii);
#endif/*平台打印结束*/
#endif
				retVal = CI_SUCCESS;
			}
			else
			{
				/*写队列失败*/
				retVal = CI_ERROR;
			}
		}
		else
		{
		}
	}
	else
	{
		/*清AXIS数据*/
		ClearAxisData();
		retVal = CI_ERROR;
	}
	return retVal;
}

/*
* 功能描述： GAL包头检查
* 参数说明： const UINT32 localEtcsId, 本方互联互通ID
*            const UINT32 remoteEtcsId, 对方互联互通ID
*            const UINT16 devInterfaceType, 接口信息类型
*			 const UINT8 prtrlVer,协议版本号
*			 const UINT32 dataVer,数据版本校验信息
*			 HLHTGALInfoStruct* pMICommonPackage, GAL包头
*			 UINT32* pErrorCode, 错误码
* 返回值  ： HLHT_HEAD_ERROR: 互联互通头检查错误
*			 HLHT_HEAD_INIT:表明头是互联互通初始通信帧
*			 HLHT_HEAD_SUCCESS:互联互通头检查正确
*/
static UINT8 GalHeadCheck(const UINT32 localEtcsId, const UINT32 remoteEtcsId, const UINT16 devInterfaceType, const UINT8 prtrlVer, const UINT32 dataVer, HLHTGALInfoStruct* pMICommonPackage, UINT32* pErrorCode)
{
	UINT8 retVal = CI_ERROR; /*返回值*/

	/*错误码每次都清零*/
	*pErrorCode = 0u;

	/*依次判断各信息是否在合法范围内,只要有错误则置相应错误码*/
	if (pMICommonPackage->devInterInfoType != devInterfaceType)
	{
		*pErrorCode |= GAL_COMPARE_INFO_TYPE_ERR;
	}

	/*发送方校验*/
	if (pMICommonPackage->sourceId != localEtcsId)
	{
		*pErrorCode |= GAL_COMPARE_SEND_FLAG_ERR;
	}

	/*接收方校验*/
	if (pMICommonPackage->destId != remoteEtcsId)
	{
		*pErrorCode |= GAL_COMPARE_RECV_FLAG_ERR;
	}

	/*数据版本校验*/
	if (dataVer != pMICommonPackage->emapVerCrc)
	{
		*pErrorCode |= GAL_COMPARE_EMAP_VER_COMP_ERR;
	}

	/* 序列号合法性检查, (2^31-1u)*/
	if ((1u > pMICommonPackage->crntOwnMsgSN) || (0x7FFFFFFFU < pMICommonPackage->crntOwnMsgSN)
		|| (1u > pMICommonPackage->recvOppMsgSN) || (0x7FFFFFFFU < pMICommonPackage->recvOppMsgSN)
		|| (1u > pMICommonPackage->preOwnMsgSN) || (0x7FFFFFFFU < pMICommonPackage->preOwnMsgSN))
	{
		*pErrorCode |= GAL_COMPARE_MSG_BDS_SN_ERR;
	}

	/* 检查协议版本 */
	if (prtrlVer != pMICommonPackage->prtclVer)
	{
		*pErrorCode |= GAL_COMPARE_PROTOCOL_VER_ERR;
	}

	/* 检查应用数据长度 */
	if (0u >= pMICommonPackage->totalDataLen)
	{
		*pErrorCode |= GAL_COMPARE_APP_LEN_ERR;
	}
	/*检查通用信息包中通信周期*/
	if (0u == pMICommonPackage->comPeriod)
	{
		*pErrorCode |= GAL_COMPARE_COM_PERIOD;
	}

	/*如果接口信息没有发生错误,则函数返回正确;否则返回错误*/
	if (0u == *pErrorCode)
	{
		/*接口全部正确,函数返回正确*/
		retVal = HLHT_HEAD_SUCCESS;
	}
	else if (GAL_COMPARE_MSG_BDS_SN_ERR == *pErrorCode)
	{
		if ((0u < pMICommonPackage->crntOwnMsgSN) && (UINT32_MAX == pMICommonPackage->recvOppMsgSN) && (UINT32_MAX == pMICommonPackage->preOwnMsgSN))
		{/*说明对方还没有收到本方的帧，当前帧是初始帧*/
			retVal = HLHT_HEAD_INIT;
		}
		else
		{
			retVal = HLHT_HEAD_ERROR;
		}
	}
	else
	{
		retVal = HLHT_HEAD_ERROR;
	}

	return retVal;
}

/*
* 功能描述： 获取RSSPI地址
* 参数说明： const UINT16 locTypeId, 本方类型ID
*            const UINT16 oppTypeId, 对方类型ID
*            UINT16* locRsspiAddr, 本方RSSPI地址
*			 UINT16* oppRsspiAddr, 对方RSSPI地址
* 返回值  ： CI_ERROR: 获取失败
*			 CI_SUCCESS: 获取成功
*/
static UINT8 GetRsspiAddr(const UINT16 locTypeId, const UINT16 oppTypeId, UINT16* locRsspiAddr, UINT16* oppRsspiAddr)
{

	UINT8 rtn = CI_ERROR; /*返回值*/
	UINT16 i = 0; /*用于循环*/
	UINT32 locHlhtId = 0; /*本方互联互通ID*/
	UINT32 oppHlhtId = 0; /*对方互联互通ID*/

	locHlhtId = DquTypeIdToHlhtId(locTypeId, 0, &dsuRsspInfo);
	oppHlhtId = DquTypeIdToHlhtId(oppTypeId, 0, &dsuRsspInfo);

	for (i = 0; i < dsuRsspInfo.RsspInfoStruLen; i++) /*遍历RSSPI配置信息*/
	{
		if ((dsuRsspInfo.pRsspLnkInfoStru[i].EmitterName == locHlhtId) && (dsuRsspInfo.pRsspLnkInfoStru[i].ReceptorName == oppHlhtId)) /*找到*/
		{
			*locRsspiAddr = dsuRsspInfo.pRsspLnkInfoStru[i].RsspAddr;
			*oppRsspiAddr = dsuRsspInfo.pRsspLnkInfoStru[i].SseAddr;
			rtn = CI_SUCCESS;
			break;
		}
	}

	return rtn;
}

/*
* 功能描述： 获取AxisDataStr里物理区段ID下标
* 参数说明： const UINT8 axleId, 计轴系统ID
*            const UINT16 phySecId, 物理区段ID
*            UINT8* axisDataStrIdx, AxisDataStr里物理区段ID下标
* 返回值  ： CI_ERROR: 获取失败
*			 CI_SUCCESS: 获取成功
*/
static UINT8 GetPhySecIdxInAxisDataStr(const UINT8 axleId, const UINT16 phySecId, UINT8* axisDataStrIdx)
{
	UINT8 rtn = CI_ERROR; /*返回值*/

	if ((0u < phySecId) && (PHYSICAL_SECTION_SUM_MAX > phySecId))
	{
		*axisDataStrIdx = axisToCiDataStru[axleId].PhySecIdx[phySecId];
		if (AXISDATASTR_IDX != (*axisDataStrIdx))
		{
			rtn = CI_SUCCESS;
		}
	}

	return rtn;
}

/*
* 功能描述： 计算物理区段在计轴系统中的下标
* 参数说明： const UINT8 chAxleId, 计轴系统ID
*            const UINT16 wIndexInAxle, 计轴系统中物理区段的序号
*            UINT8* pAxleDataStrIdx, 计轴系统里物理区段ID下标
* 返回值  ： CI_ERROR: 获取失败
*			 CI_SUCCESS: 获取成功
* by cgh 20250415
*/
UINT8 GetInAxlePhySecIdx(const UINT8 chAxleId, const UINT16 wIndexInAxle, UINT8* pAxleDataStrIdx)
{
	UINT8 ret = CI_ERROR; /*返回值*/
	UINT16 wTempPhyId = 0U; /*临时记录的物理区段ID*/

	if ((NULL != pAxleDataStrIdx) && (AXIS_TO_CI_SUM_MAX > chAxleId))
	{
		wTempPhyId = GetPhyIdByIndexInAxle(chAxleId, wIndexInAxle); /*获取计轴系统区段序号对应物理区段ID*/

		if ((0U < wTempPhyId) && (PHYSICAL_SECTION_SUM_MAX > wTempPhyId))
		{
			*pAxleDataStrIdx = axisToCiDataStru[chAxleId].PhySecIdx[wTempPhyId];/*AxisDataStr里物理区段ID下标*/
		}
		else
		{
			*pAxleDataStrIdx = AXISDATASTR_IDX;
		}
		if (AXISDATASTR_IDX != (*pAxleDataStrIdx))
		{
			ret = CI_SUCCESS;
		}
		else
		{
			/*返回error*/
		}
	}
	else
	{
		/*返回error*/
	}

	return ret;
}