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

#include "ParsePackZcData.h"
#include "ParsePackCommon.h"
#include "../QueryFiles/dquCIInterFace.h"
#include "../HLHTMsgHead/HLHTHeadContexManage.h"
#include "../HLHTMsgHead/HLHTCommonDataPacketHead.h"




/*解析使用*/
static ZcToCiDataStruct ZcToCiDataStru={ 0u };/*ZC数据结构体*/

/*转发给ATS的列车位置信息*/
ComTrainPosDataStruct ComTrainPosDataStru[ZC_TO_CI_TRAIN_MAX];/*列车位置信息*/
UINT16 ComTrainSum = 0u;/*列车数量*/
UINT8 lineIdentity = 0u;	 /*线路标识*/


/*
* 功能描述： 解析ZC单帧数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
*            const UINT8 systemId, 源设备ID 暂时不用 预留
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功      
*/
UINT8 ParseZcToCiDataFrame(UINT8* dataBuf, UINT16 dataLength, UINT8 systemId)
{
	UINT8* sourceId = NULL;		/*源ID*/
	UINT16 ii = 0u;
	UINT16 jj = 0u;
	UINT8 kk = 0u;
	UINT8 retVal = CI_SUCCESS;
	UINT32 dwStep = 0U;
	UINT8 galHeadSaved = 0u;	/*通用头是否已保存标志，1保存；0未保存*/
	
	UINT32 curntCycleNo = 0u;				/*当前周期号*/
	UINT32 errCode = 0u;
	UINT16 zcName = 0u;						/*ZC设备名称：类型+ID*/
	UINT16 ciName = 0u;						/*联锁设备名称：类型+ID*/
	UINT8 localCiId = 0u;					/*联锁ID*/
	UINT8 headRet = HLHT_HEAD_ERROR;/*互联互通检查结果*/			
	HLHTGALInfoStruct hlhtGalHead = { 0u };
	INT32 zcInfoRemainValidity = 0;
	UINT8 ci_zcPrtclVersion = 0u;
	UINT16 wTmpDataLen = 0u; /*记录已经解析的数据长度*/
	UINT16 wMsgLen = 0u;  /*单个应用信息长度记录*/
	UINT16 wMsgType = 0u; /*单个应用信息报文类型*/
	UINT16 wMsgCheckLen = 0u;			/* 用于解析校验的数据长度 */
	UINT8 funRet = 0U;
	UINT32 dwCurCyc = 0U;
	UINT8 chDataType = 0U;

	lineIdentity = GetCiFunctionSwitchConfig(VOBC_INTERFACE_IDENTITY);/*获取线路标识*/

	ci_zcPrtclVersion = GetVersionOfZCToCI();
	localCiId = GetSystemParaLocalCiId();	/*获取联锁ID*/
	zcName = (CI_SYSTEM_TYPE_ZC)*256U + systemId;
	ciName = (CI_SYSTEM_TYPE_CI)*256U + localCiId;
	curntCycleNo = Get2oo2CurCycleNum();
	chDataType = GetLocalPublicDataType(); /*区分28.0.0.14与其他线路zc接口*/
	if ((NULL != dataBuf) && (dataLength > 0u))
	{
		sourceId = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/

		/*解析通用消息包头*/
		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;

		/*（通用消息包头校验通过 && 报文生存时间有效）才继续解析其他信息*/
		/*第一次收到ZC消息时校验不通过，只记录curntOwnMsg以及当前本方软件周期号*/

		if (LINE_HLHT == lineIdentity)/*互联互通线路*/
		{
	    	headRet = HLHTRecvCommonPacketHeadCheck(zcName, ciName, CI_ZC_INTERFACE_INFOTYPE, ci_zcPrtclVersion, &hlhtGalHead, &errCode, 0u, CI_SYSTEM_TYPE_ZC);
		}
		else
		{
			headRet = HLHTRecvCommonPacketHeadCheck(zcName, ciName, CI_ZC_INTERFACE_INFOTYPE, (UINT8)CI_ZC_PRTCL_VER, &hlhtGalHead, &errCode, 0u, CI_SYSTEM_TYPE_ZC);
		}

		debug_infor_printf((const)"\nZC_RECV GAL Check Result:%d,errCode:%d", headRet,errCode);	/*0x55正确，0xaa错误，0x33初始通信帧*/

		if (HLHT_HEAD_SUCCESS==headRet)
		{/*GAL消息包头校验通过*/
			/*计算消息的时效性*/
			zcInfoRemainValidity = HLHTCommonMsgRemainingValidity(GetCiAndZcTransmitBadEnsureTime(), curntCycleNo, GetSystemParaAppCycleTime(), hlhtGalHead.recvOppMsgSN, hlhtGalHead.crntOwnMsgSN, hlhtGalHead.preOwnMsgSN, hlhtGalHead.comPeriod);

			if (zcInfoRemainValidity > 0)
			{
				if (0u == hlhtGalHead.totalDataLen)
				{
					/* 仅有GAL头信息 */
					retVal = CI_ERROR;
				}
				else if (2u > hlhtGalHead.totalDataLen)
				{
					/* 数据长度错误,返回失败 */
					retVal = CI_ERROR;
				}
				else
				{
					/*报文有效，继续解析*/
					retVal = CI_SUCCESS;
					{
						if (DATA_TYPE_NEW == chDataType)
						{
							while (wTmpDataLen < hlhtGalHead.totalDataLen)
							{
								/* 一条应用数据长度 */
								wMsgLen = ShortFromChar(&dataBuf[ii]);

								ii += 2u;
								wTmpDataLen += 2U;
								wTmpDataLen += wMsgLen;

								if (0u == wMsgLen)
								{
									; /* 无处理，继续解析下一包 */
								}
								else if (5u > wMsgLen)
								{
									/* 单包长度不对 */
									retVal = CI_ERROR;
									debug_infor_printf((const)"ParseZcToCiDataFrame_Error wMsgLen\n");
								}
								else
								{
									/* 获取报文类型 */
									wMsgType = ShortFromChar(&dataBuf[ii]);
									ii += 2u;

									/* 跳过预留 */
									ii += 2u;

									wMsgCheckLen = wMsgLen - 4u;/*单个应用报文解析长度，删除预留2和类型2字节*/
									switch (wMsgType)
									{
									case ZC_TO_TIOC_MASK_MSG:
										/* 解析ZC-CI码位信息 */
										retVal = ParseMaskData(&dataBuf[ii], wMsgCheckLen);
										dwStep |= 0x10000U;
										break;
									case ZC_TO_TIOC_TSR_MSG:
										/* 解析临时限速信息 */
										retVal = ParseZcTsrData(&dataBuf[ii], wMsgCheckLen);
										dwStep |= 0x01000U;
										break;
									case ZC_TO_TIOC_WLB_MSG:
										/* 解析紧急制动信息 */
										retVal = ParseZcEbData(&dataBuf[ii], wMsgCheckLen);
										dwStep |= 0x00100U;
										break;
									case ZC_TO_TIOC_SNOW_MSG:
										/*解析ZC-CI雨雪模式信息*/
										retVal = ParseZcSnowData(&dataBuf[ii], wMsgCheckLen);
										dwStep |= 0x00010U;
										break;
									case ZC_TO_TIOC_ITELINECUT_MSG:
										/*解析ZC-CI的ITE切除信息*/
										retVal = ParseZcIteCutData(&dataBuf[ii], wMsgCheckLen);
										dwStep |= 0x00001U;
										break;
									default:
										retVal = CI_ERROR;
										break;
									}

									if (CI_SUCCESS == retVal)
									{
										/* 解析成功，跳过该数据包 */
										ii += wMsgCheckLen;
									}
									else
									{
										debug_infor_printf((const)"ParseZcToCiDataFrame_Error Step: 0x%5x\n", dwStep);
										ClearZcData(); /*任意步骤没解析通过则清空*/
									}
								}

								if (CI_ERROR == retVal) /*解析失败*/
								{
									break;
								}
								else
								{
									;  /*do nothing*/
								}
							}
							if (CI_SUCCESS == retVal)
							{
								/*校验数据长度*/
								if (ii > dataLength)
								{
									retVal = CI_ERROR;
								}
							}
						}
						else
						{
							/*杭德线无报文类型、类型长度和预留，仅具备码位0201*/
							wMsgCheckLen = hlhtGalHead.totalDataLen;
							retVal = ParseMaskData(&dataBuf[ii], wMsgCheckLen);
							if (CI_ERROR == retVal)
							{
								debug_infor_printf((const)"\nParseZcToCiDataFrame_Error MaskOnly\n");
								ClearZcData(); /*没解析通过则清空*/
							}
							else
							{
								; /*继续*/
							}
						}

						if (CI_SUCCESS == retVal)
						{
							/*更新通信周期*/
							dwCurCyc = Get2oo2CurCycleNum();
							funRet = SetCiTransmitRecvDataCycNum(localCiId, CI_SYSTEM_TYPE_ZC, sourceId[0], dwCurCyc);
							if (CI_ERROR == funRet)
							{/*更新周期失败*/

							}
							else
							{/*更新周期成功*/

							 /*更新与ZC通信状态：判断与ZC是否通信中断*/
								funRet = UpdateCiTransmitState(localCiId, CI_SYSTEM_TYPE_ZC, sourceId[0]);
								if (CI_ERROR == funRet)
								{
									/*更新通信状态失败*/
								}
								else
								{
									/*更新通信状态成功*/
								}
							}

							/*数据经过校验，需要存储通用报文上下文*/
							SetHLHTHeadCtxComPeriod(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.comPeriod);
							SetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.crntOwnMsgSN);
							SetHLHTHeadCtxSrcOppSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.recvOppMsgSN);
							SetHLHTHeadCtxSrcOwnSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.preOwnMsgSN);
							SetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_ZC, systemId, curntCycleNo);
							SetHLHTHeadCtxCiRcvLogId(CI_SYSTEM_TYPE_ZC, systemId, 0u);

							galHeadSaved = 1;
						}
					}
				}
			}
		}
		else if (HLHT_HEAD_INIT ==headRet)
		{
			if (curntCycleNo > 0u)/*判断序号大于0，因为把0当做无效序号*/
			{
				SetHLHTHeadCtxComPeriod(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.comPeriod);
				SetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.crntOwnMsgSN);
				SetHLHTHeadCtxSrcOppSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.recvOppMsgSN);
				SetHLHTHeadCtxSrcOwnSN(CI_SYSTEM_TYPE_ZC, systemId, hlhtGalHead.preOwnMsgSN);
				SetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_ZC, systemId, curntCycleNo);
				SetHLHTHeadCtxCiRcvLogId(CI_SYSTEM_TYPE_ZC, systemId, 0u);

				galHeadSaved = 1;
			}

			retVal = CI_ERROR;
		}
		else
		{	
#if 0
			/*给ATS或现地反馈CI-ZC数据版本校验失败信息*/
			if (GAL_COMPARE_EMAP_VER_COMP_ERR == errCode)
			{
				SetCiSendCmdBackInfoData(CI_BACK_DATA_VER_CHECK_FAIL, CI_SYSTEM_TYPE_ZC, systemId, 0, 0);
			}
#endif
			retVal = CI_ERROR;
			
		}

		/*给ATS或现地反馈ZC-CI数据接口信息类型错误*/
		if (GAL_COMPARE_INFO_TYPE_ERR == (errCode & GAL_COMPARE_INFO_TYPE_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_INFO_TYPE_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据发送方标识信息错误*/
		else if (GAL_COMPARE_SEND_FLAG_ERR == (errCode & GAL_COMPARE_SEND_FLAG_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_SEND_FLAG_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据接收方标志信息错误*/
		else if (GAL_COMPARE_RECV_FLAG_ERR == (errCode & GAL_COMPARE_RECV_FLAG_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_RECV_FLAG_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据版本校验失败信息*/
		else if (GAL_COMPARE_EMAP_VER_COMP_ERR == (errCode & GAL_COMPARE_EMAP_VER_COMP_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_VER_CHECK_FAIL,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据本方、对方及收到上一条消息时本方序列号错误*/
		else if (GAL_COMPARE_MSG_BDS_SN_ERR == (errCode & GAL_COMPARE_MSG_BDS_SN_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_MSG_BDS_SN_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据对方消息序列号及收到上一条消息时本方序列号错误*/
		else if (GAL_COMPARE_MSG_SN_ERR == (errCode & GAL_COMPARE_MSG_SN_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_MSG_SN_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据协议版本号错误*/
		else if (GAL_COMPARE_PROTOCOL_VER_ERR == (errCode & GAL_COMPARE_PROTOCOL_VER_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_PROTOCOL_VER_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据应用层数据长度无效*/
		else if (GAL_COMPARE_APP_LEN_ERR == (errCode & GAL_COMPARE_APP_LEN_ERR))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_APP_LEN_ERR,ESEND_LEVEL_ATS);
		}
		/*给ATS或现地反馈ZC-CI数据通信周期错误 */
		else if (GAL_COMPARE_COM_PERIOD == (errCode & GAL_COMPARE_COM_PERIOD))
		{/*记录通信故障码*/
			SetErrorData(EFUNC_PARSE_ZC2CI_DATA,CI_SYSTEM_TYPE_ZC,systemId,ETYPE_COMM_WITH_ZC,CI_BACK_DATA_COM_PERIOD,ESEND_LEVEL_ATS);
		}
		else
		{
			/*无记录通信故障码*/
		}
#if 0
		if ((HLHT_HEAD_SUCCESS==headRet) || (HLHT_HEAD_INIT ==headRet))
		{
			/*更新通信周期*/
			if (SetCiTransmitRecvDataCycNum(GetSystemParaLocalCiId(), CI_SYSTEM_TYPE_ZC, sourceId[0], Get2oo2CurCycleNum()) == CI_ERROR)
			{/*更新周期失败*/

			}
			else
			{/*更新周期成功*/

				/*更新与ZC通信状态：判断与ZC是否通信中断*/
				if (UpdateCiTransmitState(GetSystemParaLocalCiId(), CI_SYSTEM_TYPE_ZC, sourceId[0]) == CI_ERROR)
				{
					/*更新通信状态失败*/
				}
				else
				{
					/*更新通信状态成功*/
				}
			}
		}
#endif
	}
	else
	{
		retVal = CI_ERROR;
	}

	if ((CI_ERROR == retVal) || (0u == galHeadSaved))
	{
		/*清除通用报文头*/
		ClearHlhtHeadCtx(CI_SYSTEM_TYPE_ZC, systemId);
	}

	return retVal;
	
#if 0
	if ((dataBuf != NULL) && (dataLength > 0u))
	{

		sourceId = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/
        /*更新通信周期*/
        if (SetCiTransmitRecvDataCycNum(GetSystemParaLocalCiId(), CI_SYSTEM_TYPE_ZC, sourceId[0], Get2oo2CurCycleNum()) == CI_ERROR)
        {/*更新周期失败*/
            
        }
        else
        {/*更新周期成功*/
            
            /*更新与ZC通信状态*/
            if (UpdateCiTransmitState(GetSystemParaLocalCiId(), CI_SYSTEM_TYPE_ZC, sourceId[0]) == CI_ERROR)
            {
                /*更新通信状态失败*/
            }
            else
            {
                /*更新通信状态成功*/
            }
        }

        maskTotalLen = GetReceiveMaskSum(CI_SYSTEM_TYPE_ZC);		/*获取码位数据包总长度*/
        ZcToCiDataStru.ZcId = sourceId[0];                          /*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/
        ZcToCiDataStru.ZcMaskValueBufLen = maskTotalLen;
		if (maskTotalLen / 8u != 0)
		{
			maskTotalLen = maskTotalLen / 8u + 1;
		}
		else
		{
			maskTotalLen = maskTotalLen / 8u;
		}
        
		/*解析码位信息*/
		if (0u == ZcToCiDataStru.ZcMaskValueBufLen)
		{
			return CI_ERROR;
		}

		if (GetMaskValue(ZcToCiDataStru.ZcMaskValueBuf, ZcToCiDataStru.ZcMaskValueBufLen, &dataBuf[ii], maskTotalLen) == 0u)
		{
			return CI_ERROR;		
		}

		ii = (UINT16) (ii + maskTotalLen);
		
		/*包含通信车占用逻辑区段信息*/
		if ((dataLength > ii) && (dataBuf[ii] > 0u))
		{
            ComTrainSum = dataBuf[ii++];
            if (ComTrainSum > ZC_TO_CI_TRAIN_MAX)
            {
                ComTrainSum = 0u;
                return CI_ERROR;
            }
			for (jj = 0u; jj < ComTrainSum; jj++)
			{
				ComTrainPosDataStru[jj].TrainId = dataBuf[ii++];
				ComTrainPosDataStru[jj].OcuupySectionSum = dataBuf[ii++];
                if (ComTrainPosDataStru[jj].OcuupySectionSum > TRAIN_OCCUPY_SECTION_MAX)
                {
                    ComTrainSum = 0u;
                    return CI_ERROR;
                }
				for (kk = 0u; kk < ComTrainPosDataStru[jj].OcuupySectionSum; kk++)
				{
					ComTrainPosDataStru[jj].OcuupySectionIdBuf[kk] = ShortFromChar(&dataBuf[ii]);
					ii += 2u;
				}
			}

            if (dataLength < ii)
            {
                ComTrainSum = 0u;
                return CI_ERROR;
            }
		}
		else
		{
			/*无CT信息*/
		}

		return CI_SUCCESS;
	}
	else
	{
		/*数据无效*/

		return CI_ERROR;
	}
#endif
}

/*
* 功能描述： 解析ZC到CI码位数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功
*/
UINT8 ParseMaskData(UINT8* dataBuf, UINT16 dataLen)
{
	UINT8 retVal = CI_ERROR;
	UINT16 maskTotalLen = 0u;	/*码位数据包总长度*/
	UINT8* sourceId = NULL;		/*源ID*/
	UINT8 funcRet = 0u;	/*调用函数返回值*/
	UINT16 ii = 0u;
	/*入参校验*/
	if(NULL != dataBuf)
	{
		retVal = CI_SUCCESS;
		maskTotalLen = GetReceiveMaskSum(CI_SYSTEM_TYPE_ZC);		/*获取码位数据包总长度*/
		sourceId = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC);/*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/
		ZcToCiDataStru.ZcId = sourceId[0];                          /*获取与本联锁通信的ZC的ID，目前一个联锁最多只与一个ZC通信*/
		ZcToCiDataStru.ZcMaskValueBufLen = maskTotalLen;
		if (maskTotalLen % 8u != 0u)
		{
			maskTotalLen = maskTotalLen / 8u + 1U;
		}
		else
		{
			maskTotalLen = maskTotalLen / 8u;
		}

		/*解析码位信息*/
		if (0u == ZcToCiDataStru.ZcMaskValueBufLen)
		{
			retVal = CI_ERROR;
		}

		if (dataLen != maskTotalLen)
		{
			retVal = CI_ERROR; 
			debug_infor_printf((const)"ParseMaskData maskLen : %d__SystemMaskLen:%d\n", dataLen, maskTotalLen);
		}

		if (CI_SUCCESS == retVal)
		{
			funcRet = GetMaskValue(ZcToCiDataStru.ZcMaskValueBuf, ZcToCiDataStru.ZcMaskValueBufLen, &dataBuf[ii], maskTotalLen);
			if (0u == funcRet)
			{
				retVal = CI_ERROR;
				debug_infor_printf((const)"ParseZcToCiMask_MaskParse_Error \n");
			}
		}
#if 0
		if (CI_SUCCESS == retVal)
		{
			ii = (UINT16)(ii + maskTotalLen);

			/*包含通信车占用逻辑区段信息*/
			if ((dataLength > ii) && (dataBuf[ii] > 0u))
			{
				ComTrainSum = dataBuf[ii++];
				if (ComTrainSum > ZC_TO_CI_TRAIN_MAX)
				{
					ComTrainSum = 0u;
					retVal = CI_ERROR;
				}

				if (CI_SUCCESS == retVal)
				{
					for (jj = 0u; jj < ComTrainSum; jj++)
					{
						ComTrainPosDataStru[jj].TrainId = dataBuf[ii++];
						ComTrainPosDataStru[jj].OcuupySectionSum = dataBuf[ii++];
						if (ComTrainPosDataStru[jj].OcuupySectionSum > TRAIN_OCCUPY_SECTION_MAX)
						{
							ComTrainSum = 0u;
							retVal = CI_ERROR;
						}

						if (CI_SUCCESS == retVal)
						{
							for (kk = 0u; kk < ComTrainPosDataStru[jj].OcuupySectionSum; kk++)
							{
								ComTrainPosDataStru[jj].OcuupySectionIdBuf[kk] = ShortFromChar(&dataBuf[ii]);
								ii += 2u;
							}
						}

					}

					if (dataLength < ii)
					{
						ComTrainSum = 0u;
						retVal = CI_ERROR;
					}
				}

			}
			else
			{
				/*无CT信息*/
			}
		}
#endif
	}
	return retVal;
}

/*
* 功能描述： 解析ZC到CI临时限速数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功
*/
UINT8 ParseZcTsrData(UINT8* dataBuf, UINT16 dataLen)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 cFunRetVal = 0u; /* 返回结果 */
	UINT16 ii = 0u;
	UINT8 jj = 0u;
	UINT8 kk = 0u;
	TsrDataStruct* pTmpTsrInfo = NULL;
	UINT8 cTiocId = 0u;
	UINT8 cSpeed = 0U;
	UINT8 cDevTiocId = 0u;
	UINT16 wLogSecId = 0U;
	UINT8 wFlag = 0U;
	UINT8 localTsrSum = 0U; /*本控区的临时限速数量*/
	UINT8 wZcTsrSum = 0U; /*ZC发送的临时限速数量*/
	UINT8 chLogSecSum = 0U; /*单条临时限速属于本控区的临时限速区段数量*/
	UINT8 chTmpLogNum = 0U; /*ZC发送的限速区段数量*/
	UINT16 tsrMaxCmdSum = 0u; /*本控区临时限速最大数量*/
	UINT16 tsrMaxSecSum = 0u; /*单个临时限速最大区段数量*/

	if (NULL == dataBuf)
	{
		cRetVal = CI_ERROR;
	}
	else
	{
		tsrMaxCmdSum = GetTsrMaxCmdSum(); 
		tsrMaxSecSum = GetTsrMaxSecSum(); 
		cRetVal = CI_SUCCESS;
	}

	/* 临时限速有效标志位 */
	if (CI_SUCCESS == cRetVal)
	{
		ZcToCiDataStru.tsrInputInfoStru.cTsrValidFlag = ZC_TSR_VALID;
		/*记录临时限速有效*/
	}

	/* 全线临时限速信息 */
	if (CI_SUCCESS == cRetVal)
	{
		ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrState = dataBuf[ii];
		ii++;

		ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrSpeed = dataBuf[ii];
		ii++;

		/*0xAA 为有全线临时限速*/
		if (((0x55U == ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrState) && (0u == ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrSpeed))
			|| ((0xAAU == ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrState) && (0u < ZcToCiDataStru.tsrInputInfoStru.cAllLineTsrSpeed)))
		{
			cRetVal = CI_SUCCESS;
		}
		else
		{
			cRetVal = CI_ERROR; /*防护设置限速但限速为0或未设置但有限速*/
			debug_infor_printf((const)"ParseZcToCiTSR_Error  AllLineTsrSpeed\n");
		}
	}

	/* 解析临时限速数量 */
	if (CI_SUCCESS == cRetVal)
	{
		wZcTsrSum = dataBuf[ii];
		ii++;
		if (TSR_MAX_SUM <wZcTsrSum)
		{
 			cRetVal = CI_ERROR;
			debug_infor_printf((const)"ParseZcToCiTSR_Error  wZcTsrSum\n");
		}
		else
		{
			; /* do nothing */
		}
	}
	else
	{
		; /* do nothing */
	}

	/* 解析临时限速区段 */
	if (CI_SUCCESS == cRetVal)
	{
		cTiocId = GetSystemParaLocalCiId();	/*获取联锁ID*/

		for (jj = 0u; jj < wZcTsrSum; jj++)
		{
			wFlag = CI_ERROR;
			chLogSecSum = 0U;
			/* 限速值 */
			cSpeed = dataBuf[ii];
			ii++;
			if ((0u == cSpeed)|| (UINT8_MAX == cSpeed))
			{
				cRetVal = CI_ERROR;
				debug_infor_printf((const)"ParseZcToCiTSR_Error  cSpeed\n");
			}
			else
			{
				; /* do nothing */
			}

			/* 限速区段数量 */
			if (CI_SUCCESS == cRetVal)
			{
				chTmpLogNum = dataBuf[ii];
				ii++;
				if ((TSR_SEC_MAX_SUM < chTmpLogNum)
					|| (0u == chTmpLogNum)
					|| (tsrMaxSecSum <chTmpLogNum))
				{
					cRetVal = CI_ERROR;
					debug_infor_printf((const)"ParseZcToCiTSR_Error  chTmpLogNum\n");
				}
				else
				{
					; /* 继续解析 */
				}

			}

			/* 限速区段ID */
			if (CI_SUCCESS == cRetVal)
			{
				pTmpTsrInfo = &ZcToCiDataStru.tsrInputInfoStru.szTsrInfo[localTsrSum];/*本控区临时限速缓存*/
				for (kk = 0u; kk < chTmpLogNum; kk++)
				{
					wLogSecId = ShortFromChar(&dataBuf[ii]);

					ii += 2u;

					if ((0u == wLogSecId) || (UINT16_MAX == wLogSecId))
					{
						cRetVal = CI_ERROR;
					}
					else
					{
						cDevTiocId = GetLogSecBelongCiId(wLogSecId);

						if ((0u != cTiocId) && (cDevTiocId == cTiocId))
						{
							/* 是本TIOC的逻辑区段 */
							pTmpTsrInfo->szLogSecId[chLogSecSum] = wLogSecId;
							chLogSecSum++;
							wFlag = CI_SUCCESS;
						}
					}

					if (CI_ERROR == cRetVal)
					{
						break;
					}
				}

				if (CI_SUCCESS == wFlag)
				{
					/*发送区段与本RC相关*/
					pTmpTsrInfo->cSpeed = cSpeed;
					pTmpTsrInfo->cLogSecSum = chLogSecSum;
					localTsrSum++;
				}
			}

			if ((CI_ERROR == cRetVal) ||(tsrMaxCmdSum <localTsrSum)||(TSR_MAX_SUM<localTsrSum))
			{
				cRetVal = CI_ERROR;
				debug_infor_printf((const)"ParseZcToCiTSR_Error  localTsrSum\n");
				break;/*本控区最大临时限速数量上限 设置错误*/
			}
		}
		if (CI_ERROR != cRetVal)
		{
			ZcToCiDataStru.tsrInputInfoStru.cTsrSum = localTsrSum;
		}
		else
		{
			; /* do nothing */
		}
	}
	else
	{
		; /* do nothing */
	}

	if (dataLen != ii)
	{
		cRetVal = CI_ERROR;
		debug_infor_printf((const)"ParseZcToCiTSR_Error  dataLen\n");
	}

	return cRetVal;
}

/*
* 功能描述： 解析ZC到CI紧急制动限速数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功
*/
UINT8 ParseZcEbData(UINT8* dataBuf, UINT16 dataLen)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 ii = 0u;
	UINT8 jj = 0U;
	UINT16 cPhySecId = 0U;  /*物理区段ID*/
	UINT8 cEbSecNum = 0U;  /*紧急制动区段数量*/
	UINT8 cTmepNum = 0U;
	UINT8 cSecBelongCiId = 0U;  /*区段所属CI*/
	UINT8 cLocalCiId = 0U;

	if (NULL == dataBuf)
	{
		cRetVal = CI_ERROR;
	}
	else
	{
		cRetVal = CI_SUCCESS;
	}

	/*全线紧急制动命令有效标志位 */
	if (CI_SUCCESS == cRetVal)
	{
		ZcToCiDataStru.esbInputInfoStruct.cWlbValidFlag = dataBuf[ii]; 
		ii++;
		if ((0x55U == ZcToCiDataStru.esbInputInfoStruct.cWlbValidFlag)
			|| (0XAAU == ZcToCiDataStru.esbInputInfoStruct.cWlbValidFlag))
		{
			cRetVal = CI_SUCCESS;
		}
		else
		{
			cRetVal = CI_ERROR;
			debug_infor_printf((const)"ParseZcToCiESB_Error  cWlbValidFlag\n");
		}
	}

	/*解析区间紧急制动区段信息*/
	if (CI_SUCCESS == cRetVal)
	{
		cEbSecNum = dataBuf[ii];  /*解析区间紧急制动数量*/
		ii++;

		if (ZC_TO_CI_EB_MAX >= cEbSecNum)
		{
			cLocalCiId = GetSystemParaLocalCiId();
			for (jj = 0U; jj < cEbSecNum; jj++)
			{
				cPhySecId = ShortFromChar(&dataBuf[ii]);  /*解析物理区段ID*/
				ii += 2U;
				cSecBelongCiId = GetPhySecBelongCiId(cPhySecId);/*获取区段所属控区*/
				if ((0U < cPhySecId) && (cPhySecId<UINT16_MAX) && (0U != cSecBelongCiId))
				{
					if (cLocalCiId == cSecBelongCiId) 
					{
						ZcToCiDataStru.esbInputInfoStruct.wEbPhySecId[cTmepNum] = cPhySecId;
						cTmepNum++;
					}
					else
					{
						/*非本控区区段，不保存*/
					}
				}
				else
				{
					/*物理区段ID非法*/
					cRetVal = CI_ERROR;
					debug_infor_printf((const)"ParseZcToCiESB_Error  cPhySecId\n");
					break;
				}
			}
			if (ZC_TO_CI_EB_MAX >=  cTmepNum)
			{
				ZcToCiDataStru.esbInputInfoStruct.cSecEbSum = cTmepNum; /*本控区区间紧急制动数量*/
			}
			else
			{
				cRetVal = CI_ERROR;  /*数量超限*/
				debug_infor_printf((const)"ParseZcToCiESB_Error  cTmepNum\n");
			}
		}
		else
		{
			cRetVal = CI_ERROR;  /*数量超限，返回失败*/
		}
	}

	if (dataLen != ii)
	{
		cRetVal = CI_ERROR;
	}
	return cRetVal;
}

/*
* 功能描述： 解析ZC到CI雨雪数据
* 参数说明： const UINT8* dataBuf, 数据缓冲区
*            const UINT16 dataLength, 数据长度
* 返回值  ： 0: 数据解析失败
*			 1: 数据解析成功
* edit cgh 20241030
*/
UINT8 ParseZcSnowData(UINT8* dataBuf, UINT16 dataLen)
{
	UINT8 cRetVal = CI_ERROR;
	UINT16 ii = 0u;
	UINT8 jj = 0U;
	UINT16 wPlatFormId = 0U;  /*站台互联互通ID*/
	UINT8 cPlatFormNum = 0U;  /*ZC发送区间雨雪站台数量*/
	UINT8 cTmepNum = 0U;/*本控区区间雨雪站台数量*/
	UINT8 cPlatFormBelongCiId = 0U;  /*站台关联Link所属CI*/
	UINT8 cLocalCiId = 0U;
	UINT8 chLocalSnowValidFlag = 0U; /*本地雨雪命令有效标志*/
	UINT8 cAllLineSnowLevel = 0U;  /*全线湿轨级别*/

	if (NULL == dataBuf)
	{
		cRetVal = CI_ERROR;
	}
	else
	{
		cRetVal = CI_SUCCESS;
	}

	/*全线雨雪模式命令有效标志位 */
	if (CI_SUCCESS == cRetVal)
	{
		ZcToCiDataStru.cSnowValidFlag = dataBuf[ii];
		ii++;
		/*ZC发送AA有效 55无效*/
		if (0xAAU == ZcToCiDataStru.cSnowValidFlag)
		{
			ZcToCiDataStru.cSnowValidFlag = CI_ALL_SNOW_VALID;
		}
		else if (0X55U == ZcToCiDataStru.cSnowValidFlag)
		{
			ZcToCiDataStru.cSnowValidFlag = CI_ALL_SNOW_UNVALID;
		}
		else
		{
			cRetVal = CI_ERROR;
			debug_infor_printf((const)"ParseZcToCiSNOW_Error  cSnowValidFlag\n");
		}
	}
	else
	{
		; 
	}

	/*解析区间雨雪站台信息*/
	if (CI_SUCCESS == cRetVal)
	{
		cPlatFormNum = dataBuf[ii];  /*解析区间雨雪站台数量*/
		ii++;

		if (ALL_AREA_SNOW_SUM_MAX >= cPlatFormNum)
		{
			cLocalCiId = GetSystemParaLocalCiId();
			for (jj = 0U; jj < cPlatFormNum; jj++)
			{
				wPlatFormId = ShortFromChar(&dataBuf[ii]);  /*解析区间雨雪站台ID*/
				ii += 2U;
				cPlatFormBelongCiId = GetAreaSnowPlatFormBelongCiId(wPlatFormId);  /*获取区间雨雪站台所属控区*/
				if ((0U < wPlatFormId)&& (UINT16_MAX > wPlatFormId))
				{
					if (cLocalCiId == cPlatFormBelongCiId)
					{
						/*站台属于本控区*/
						if (LOCAL_AREA_SNOW_SUM_MAX > cTmepNum)
						{
							ZcToCiDataStru.szAreaSnowInfo[cTmepNum].wAreaId = wPlatFormId;
							ZcToCiDataStru.szAreaSnowInfo[cTmepNum].cAreaSnowLevel = CI_SNOW_LEVEL_DEFAULT;  /*CI模式，湿轨等级为默认值(适配TMC)*/
							cTmepNum++;
						}
						else
						{
							cRetVal = CI_ERROR;  /*本控区区间雨雪站台数量超限，停止遍历，返回失败*/
							debug_infor_printf((const)"ParseZcToCiSNOW_Error  cTmepNum\n");
							break;
						}
					}
					else
					{
						/*非本控区站台，不保存*/
					}
				}
				else
				{
					cRetVal = CI_ERROR;  /*区间雨雪站台Id非法，返回失败*/
					debug_infor_printf((const)"ParseZcToCiSNOW_Error  wPlatFormId\n");
				}
			}

			ZcToCiDataStru.cAreaSnowPlatFormNum = cTmepNum;
		}
		else
		{
			cRetVal = CI_ERROR;  /*区间雨雪站台数量超限，返回失败*/
			debug_infor_printf((const)"ParseZcToCiSNOW_Error  cPlatFormNum\n");
		}
	}
	else
	{
		;
	}

	/*本地雨雪模式命令有效标志位 */
	if (CI_SUCCESS == cRetVal)
	{
		chLocalSnowValidFlag = dataBuf[ii];
		ii++;
		/*ZC发送AA有效 55无效*/
		if ((CI_LOCAL_SNOW_UNVALID == chLocalSnowValidFlag) || (CI_LOCAL_SNOW_VALID == chLocalSnowValidFlag))
		{
			ZcToCiDataStru.chLocalSnowValidFlag = chLocalSnowValidFlag;
		}
		else
		{
			cRetVal = CI_ERROR;
			debug_infor_printf((const)"ParseZcToCiSNOW_Error  chLocalSnowValidFlag\n");
		}
	}
	else
	{
		;
	}

	if (dataLen != ii)
	{
		cRetVal = CI_ERROR;
	}
	else
	{
		;
	}
	return cRetVal;
}
/*
* 功能描述： 组ZC数据
* 参数说明： QueueStruct* CiToZcDataQueue, 组包发送队列地址     
* 返回值  ： 0:组数据失败
*			 1:组数据成功      
*/
UINT8 PackCiToZcData( UINT8 deviceId)
{
	UINT8 localCi = 0u; /*本地联锁ID*/
    UINT8 CiToZcDataBuffer[CI_TO_ZC_DATA_LEN_MAX] = {0u};/*CI到ZC组帧数组*/
    UINT16 SendMaskSum = 0u;
	UINT16 ii = 0u;
	UINT32 ciEtcsId = 0u;	/*CI互联互通编号*/
	UINT32 zcEtcsId = 0u;	/*ZC互联互通编号*/
	UINT32 emapCheckVer = 0u;	/*共用数据校验信息*/
	UINT8 retVal = CI_ERROR;
	UINT32 curCycleNum = Get2oo2CurCycleNum();	/*联锁应用周期号*/
	UINT32 appCycleTime = GetSystemParaAppCycleTime();	/*联锁应用周期*/
	UINT8 ci_zcPrtclVersion = 0u;
	UINT16 dstDevId = 0;
	UINT8 outnetSafeSendRtn = 0u;
	UINT8 CIName2HlhtId = 0U;
	UINT8 ZCName2HlhtId = 0U;
	UINT8 CiEmapCheckVer = 0U;
	UINT32 dwHlhtHSrcSN = 0u;
	UINT32 dwHlhtHRcvSN = 0u;
	UINT16 totallenIndex = 0U;
	UINT8 chDataType = 0U;

	localCi = GetSystemParaLocalCiId(); /*获取本地联锁ID*/
	ci_zcPrtclVersion = GetVersionOfZCToCI();
	/*首先获取组包时所需的信息，获取成功才有必要继续组包*/
	CIName2HlhtId = dquDevName2HlhtId((CI_SYSTEM_TYPE_CI * 256U) + localCi, 0U, &ciEtcsId);
	ZCName2HlhtId = dquDevName2HlhtId((CI_SYSTEM_TYPE_ZC * 256U) + deviceId, 0U, &zcEtcsId);
	dwHlhtHSrcSN = GetHLHTHeadCtxSrcCrntSN(CI_SYSTEM_TYPE_ZC, deviceId);
	dwHlhtHRcvSN = GetHLHTHeadCtxCiRcvSN(CI_SYSTEM_TYPE_ZC, deviceId);
	CiEmapCheckVer = GetCiEmapCheckVer(localCi, &emapCheckVer, CI_SYSTEM_TYPE_ZC);
	chDataType = GetLocalPublicDataType();
	if ((CI_SUCCESS == CIName2HlhtId) && (CI_SUCCESS == ZCName2HlhtId) && (CI_SUCCESS == CiEmapCheckVer))
	{
		retVal = CI_SUCCESS;
	}
	else
	{
		retVal = CI_ERROR;
	}

	if ((CI_SUCCESS == retVal))
	{	
		/*获取将要发送的码位字节数*/
		if ((GetSendMaskSum(CI_SYSTEM_TYPE_ZC) % 8u) == 0u)
		{
			SendMaskSum = (UINT16) (GetSendMaskSum(CI_SYSTEM_TYPE_ZC) / 8u);
		}
		else
		{
			SendMaskSum = (UINT16) (GetSendMaskSum(CI_SYSTEM_TYPE_ZC) / 8u + 1u);
		}

        if (0u == SendMaskSum)
        {
			retVal = CI_ERROR;
        }
		else
		{
		}

		/*判断设备名称对应的4字节互联互通编号是否获取成功*/
		if (CI_SUCCESS == retVal)
		{
			/*通用协议帧头*/

			/*RSSP帧头*/

			/*开始组应用数据帧*/
			/*组GAL包头*/
			ShortToChar(CI_ZC_INTERFACE_INFOTYPE, &CiToZcDataBuffer[ii]);/*接口信息类型*/
			ii += 2u;
			LongToChar(ciEtcsId, &CiToZcDataBuffer[ii]);/*发送方标识信息*/
			ii += 4u;
			LongToChar(zcEtcsId, &CiToZcDataBuffer[ii]);/*接收方标识信息*/
			ii += 4u;
			LongToChar(emapCheckVer, &CiToZcDataBuffer[ii]);/*电子地图版本校验信息*/
			ii += 4u;
			LongToChar(curCycleNum, &CiToZcDataBuffer[ii]);/*本方消息序列号*/
			ii += 4u;
			ShortToChar((UINT16)appCycleTime, &CiToZcDataBuffer[ii]);/*设备通讯周期*/
			ii += 2u;
			LongToChar(dwHlhtHSrcSN, &CiToZcDataBuffer[ii]);/*对方消息序列号：recvOppMsgSN记录收到对方上一条消息中的对方消息序列号*/
			ii += 4u;
			LongToChar(dwHlhtHRcvSN, &CiToZcDataBuffer[ii]);/*收到上一条消息时本方序列号*/
			ii += 4u;

			lineIdentity = GetCiFunctionSwitchConfig(VOBC_INTERFACE_IDENTITY);/*获取线路标识*/

			if (LINE_HLHT == lineIdentity)/*互联互通线路*/
			{
				CiToZcDataBuffer[ii++] = ci_zcPrtclVersion;  /*CI_ZC接口协议版本号*/
			}
			else
			{
				CiToZcDataBuffer[ii++] = (UINT8)CI_ZC_PRTCL_VER;/*CI_ZC接口协议版本号*/
			}

			totallenIndex = ii;
			ii += 2u;/*通用报文头中的应用层报文总长度*/
			if (DATA_TYPE_NEW == chDataType)
			{
				ii += 2u;/*通用报文头中的应用层报文长度(0x202报文长度)*/

				ShortToChar(TIOC_TO_ZC_MASK_MSG, &CiToZcDataBuffer[ii]);/*接口信息类型*/
				ii += 2u;

				ii += 2u; /*预留*/
			}
			else
			{
				;/*杭德线路无0x202报文长度、类型及预留*/
			}

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

			/*通用报文头中应用层报文总长度*/
			ShortToChar(ii - totallenIndex - 2U, &CiToZcDataBuffer[totallenIndex]);
			if (DATA_TYPE_NEW == chDataType)
			{
				/*通用应用层报文长度(0x202报文长度)*/
				totallenIndex += 2U;
				ShortToChar(ii - totallenIndex - 2U, &CiToZcDataBuffer[totallenIndex]);
			}
			/*清ZC数据*/
			ClearZcData();

			dstDevId = (UINT16)(CI_SYSTEM_TYPE_ZC << 8) | ((UINT16)deviceId);
			outnetSafeSendRtn = OutnetSafeSend(dstDevId, 0u, &CiToZcDataBuffer[0], ii);
			if (1u == outnetSafeSendRtn)
			{ /*写队列成功*/
#ifdef LOGPRINT/*日志打印宏*/			
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nZC_SEND:%d", ii);
				debug_out_array(0xAA, CiToZcDataBuffer, ii);
#endif/*平台打印结束*/

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

#if 0
		/*组码位信息*/
		MaskPack(CI_SYSTEM_TYPE_ZC,&CiToZcDataBuffer[ii]);	
		ii = (UINT16) (ii + SendMaskSum);

		/*数据长度 */
        CiToZcDataBuffer[0] = (UINT8) (((ii - 2u) >> 8u) & 0xff);
        CiToZcDataBuffer[1] = (UINT8) ((ii - 2u) & 0xff);

        /*清ZC数据*/
        ClearZcData();

		if (QueueWrite(ii, CiToZcDataBuffer, CiToZcDataQueue))
		{ /*写队列成功*/
#ifdef LOGPRINT/*日志打印宏*/			
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
            debug_infor_printf((const)"\nZC_SEND:%d", ii);
            debug_out_array(0xAA, CiToZcDataBuffer, ii);
#endif/*平台打印结束*/

#endif
            return CI_SUCCESS;
        }
        else
        {
            /*写队列失败*/
            return CI_ERROR;
		}
#endif
	}
	else
	{
        /*清ZC数据*/
        ClearZcData();

		retVal = CI_ERROR;
	}

	return retVal;
}


/*
* 功能描述： 获取ZC码位值Buf
* 参数说明： void    
* 返回值  ： NULL: 获取失败
*           !NULL: Buf指针      
*/
UINT8* GetZcMaskValueBuf(void)
{
	UINT8* pZcMaskValueBuf = NULL; /*ZC到CI码位值Buf*/
	if (0u == ZcToCiDataStru.ZcMaskValueBufLen)
	{		
	}
	else
	{
		pZcMaskValueBuf = ZcToCiDataStru.ZcMaskValueBuf;
	}
	return pZcMaskValueBuf;
}


/*
* 功能描述： 获取ZC码位值Buf长度
* 参数说明： void    
* 返回值  ： 0: 获取失败
*           >0: Buf长度   
*/
UINT16 GetZcMaskValueBufLen(void)
{
	return ZcToCiDataStru.ZcMaskValueBufLen;
}


/*
* 功能描述： 获取ZC码位中的ZCID
* 参数说明： void    
* 返回值  ： 0: 获取失败
*           >0: ZCID   
*/
UINT8 GetZcMaskZcId(void)
{
	return ZcToCiDataStru.ZcId;
}

/*
* 功能描述： 获取列车数量
* 参数说明： void    
* 返回值  ： 列车数量 
*/
UINT16 GetComTrainSum(void)
{
	return ComTrainSum;
}

/*
* 功能描述： 获取列车占用信息
* 参数说明： void    
* 返回值  ： 列车数量 
*/
ComTrainPosDataStruct* GetComTrainPosDataStru(void)
{
	return ComTrainPosDataStru;
}

/*
* 功能描述： 删除该逻辑区段的CT占用信息
* 参数说明： const UINT16 logSecId, 逻辑区段ID
* 返回值  ： void
*/
void DeleteLogSecCTInfo(const UINT16 logSecId)
{
    UINT16 ii = 0u;
    UINT8 jj = 0u;
    UINT8 kk = 0u;
    UINT8 secSum = 0u;/*列车占用逻辑区段数目*/

    for (ii = 0u; ii < ComTrainSum; ii++)
    {
        secSum = ComTrainPosDataStru[ii].OcuupySectionSum;
        for (jj = 0u; jj < secSum; jj++)
        {
            if (ComTrainPosDataStru[ii].OcuupySectionIdBuf[jj] == logSecId)
            {
                for (kk = jj + 1u; kk < secSum; kk++)
                {
                    ComTrainPosDataStru[ii].OcuupySectionIdBuf[kk - 1U] = ComTrainPosDataStru[ii].OcuupySectionIdBuf[kk];
                }
                ComTrainPosDataStru[ii].OcuupySectionSum--;
                return;
            }
        }     
    }
}

/*
* 功能描述： 清除ZC数据
* 参数说明： void
* 返回值  ： void
*/
void ClearZcData(void)
{
	(void)CommonMemSet(&ZcToCiDataStru, (UINT32)sizeof(ZcToCiDataStru), 0u, (UINT32)sizeof(ZcToCiDataStru));
}


/*
* 功能描述： 获取ZC信息缓存数据
* 参数说明： void
* 返回值  ： ZC信息结构体指针
*/
ZcToCiDataStruct* GetZcToCiDataStru(void)
{
	return & ZcToCiDataStru;
}

/*
* 功能描述：解析ZC到CI的ITE切除状态数据
* 参数说明：INT8* dataBuf 数据缓冲区
*           UINT16 dataLength 数据长度
* 返 回 值：CI_ERROR 0 数据解析失败
*			CI_SUCCESS 1 数据解析成功
* Edit By LQ 2025.04.15
*/
UINT8 ParseZcIteCutData(UINT8* dataBuf, UINT16 dataLen)
{
	UINT8 cRetVal = CI_ERROR;
	UINT8 cIteLineCutState = CI_ITE_LINE_CUT_INVALID;  /*ZC发送的ITE全线切除状态*/
	UINT16 ii = 0U;
	UINT8 jj = 0U;
	UINT16 wPlatFormId = 0U;  /*区间站台ID*/
	UINT8 cPlatFormNum = 0U;  /*ZC发送区间ITE切除数量*/

	if (NULL != dataBuf)
	{
		cRetVal = CI_SUCCESS;
		/*解析ZC发送的ITE全线切除状态*/
		cIteLineCutState = dataBuf[ii];
		ii++;

		if ((CI_ITE_LINE_CUT_INVALID == cIteLineCutState) || (CI_ITE_LINE_CUT_VALID == cIteLineCutState) || (CI_ITE_LINE_CUT_DEFAULT == cIteLineCutState))
		{
			ZcToCiDataStru.cIteLineCutState = cIteLineCutState;

			cPlatFormNum = dataBuf[ii];  /*解析区间ITE切除数量*/
			ii++;

			if (ALL_AREA_SNOW_SUM_MAX >= cPlatFormNum)
			{
				ZcToCiDataStru.cAreaIteCutNum = cPlatFormNum;

				for (jj = 0U; jj < cPlatFormNum; jj++)
				{
					wPlatFormId = ShortFromChar(&dataBuf[ii]);  /*解析区间ID*/
					ii += 2U;

					if ((0U < wPlatFormId) && (UINT16_MAX > wPlatFormId))
					{
						ZcToCiDataStru.szAreaIteCutId[jj] = wPlatFormId;
					}
					else
					{
						debug_infor_printf((const)"ParseZcIteCutData: PlatFormId Error\n");
						cRetVal = CI_ERROR;  /*区间ID非法，返回失败*/	
						break;
					}
				}

				if (CI_SUCCESS == cRetVal)
				{
					if (dataLen != ii)
					{
						debug_infor_printf((const)"ParseZcIteCutData: Msg Len Error\n");
						cRetVal = CI_ERROR;
					}
					else
					{
						/*不处理*/
					}
				}
				else
				{
					/*不处理*/
				}
			}
			else
			{
				debug_infor_printf((const)"ParseZcIteCutData: ZC AreaIteCutNum Error\n");
				cRetVal = CI_ERROR;  /*ZC区间ITE切除数量超限，返回失败*/
			}
		}
		else
		{
			debug_infor_printf((const)"ParseZcIteCutData Error: IteLineCutState Error\n");
			cRetVal = CI_ERROR;  /*状态非法，返回失败*/
		}
	}
	else
	{
		cRetVal = CI_ERROR;  /*入参非法，返回失败*/
	}

	return cRetVal;
}