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

#include "ParsePackManage.h"
#include "../DataManage/DeviceConfigDataManage.h"
#include "ParsePackOcData.h"
#include "ParsePackAxleData.h"
#include "FsfbProtcl.h"
#include "ParsePackTmcData.h"
#include "ParsePackGateWayData.h"
#include "../Deployment/DeploymentExtern.h"
#include "ParsePackCommon.h"
#define TMP_BUF_LEN 10000




/*
* 功能描述： 解析输入数据
* 参数说明： void
* 返回值  ： void
*/
void ParseInputData(void)
{
	UINT8 LocalCiPattern = 0u;
	UINT8 ParseIoToCiData_ret = 0u;
	UINT8 ParseOtherResult = CI_ERROR;
	UINT8 ParseInnetResult = CI_ERROR;
	UINT8 ParsePlatResult = CI_ERROR;
	LocalCiPattern = GetLocalCiPattern();

	if (CI_PATTERN_TRADITIONAL == LocalCiPattern)
	{/*传统联锁模式，才解析IO数据*/
		/*解析IO数据*/
		ParseIoToCiData_ret = ParseIoToCiData();
		if (0u == ParseIoToCiData_ret)
		{/*解析失败*/

			/*将解析后数据设为安全值*/
		}
		else
		{
			/*无操作*/
		}
	}
	else if (CI_PATTERN_FULL_ELECTRONIC == LocalCiPattern)/*临时用，不带协议解析OC数据*/
	{


	}
	else
	{
		/*无操作*/
	}

	/*解析SFP数据*/
	ParseOtherResult = ParseOtherSysToCiData();
	if (0u == ParseOtherResult)
	{/*解析失败*/

		/*内部已经设为安全值*/
	}
	else
	{
		/*解析成功*/
	}
	/*解析内网数据*/
	ParseInnetResult = ParseINNETToCiData();
	if (0u == ParseInnetResult)
	{/*解析失败*/

		/*内部已经设为安全值*/
	}
	else
	{
		/*解析成功*/
	}
	/*解析平台设备数据*/
	ParsePlatResult=ParasePlatToRCIData();
	if (0u == ParsePlatResult)
	{/*解析失败*/

		/*内部已经设为安全值*/
	}
	else
	{
		/*解析成功*/
	}
}

/*
* 功能描述： 插入oc id
* 参数说明：
*		UINT16 ocId
* 返回值  ： void
*/
void InsertOcId(UINT16 ocId)
{
	UINT16 i = 0U;
	UINT8 flagFind = 0u;
	for (i = 0U; i < OC_SUM_MAX; i++)
	{
		if (LocalOcIds[i] == ocId)
		{
			flagFind = 1u;
			break;
		}
	}
	if (0u == flagFind)
	{
		for (i = 0U; i < OC_SUM_MAX; i++)
		{
			if (0u == LocalOcIds[i])
			{
				LocalOcIds[i] = ocId;
				break;
			}
		}
	}
}

/*
* 功能描述： 组包输出数据
* 参数说明： void
* 返回值  ： void
*/
void PackOutputData(void)
{
	QueueStruct* dataSendQueue = NULL; /*获取输出队列*/
	UINT8 deviceSum = 0u;               /*设备总数*/
	UINT8* deviceIdBuf = NULL;         /*设备ID数组*/
	UINT32 flyTag = GetFlyProtectOverCyc();
	UINT8 ciPatten = GetLocalCiPattern();

	/*传统联锁 未宕机*/
	if ((0U == flyTag) && (CI_PATTERN_TRADITIONAL == ciPatten))
	{
		/*组IO数据*/
		(void)PackCiToIoData();
	}
	else
	{

	}

	/*组SFP数据*/
	if (CI_ERROR == PackCiToOtherSysData())
	{
		/*组包失败*/
	}

#ifdef LOGPRINT

	/*记录各设备状态*/
	(void)RecordDeviceDataLog(CI_SUCCESS);

#endif
}



/*
* 功能描述： 解析其他系统发来的数据
* 参数说明： void
* 返回值  ： 0:解析失败
*			 1:解析成功
*/
UINT8 ParseOtherSysToCiData(void)
{
	QueueStruct* otherSysToCiDataQueue = NULL; /*通用协议输入队列*/
	UINT32 dataQueueTotalLen = 0u;	           /*队列数据总长度*/
	UINT8 dataLenBuf[2] = { 0u };		           /*数据长度数组*/
	UINT16 appDataLen = 0u;			           /*一帧数据长度*/
	UINT8 tempBuf[7] = { 0u };			           /*临时数据数组*/

	UINT8 tempDataBuf[10000] = { 0u };		   /*数据临时数组*/
	UINT8 sameLineCi = SAME_LINE_ERR;/*标记发送方CI和接收方CI是否是同一条线路的CI*/
	UINT16 logId = 0u;/*逻辑ID，针对4IP VOBC修改,只在解析互联互通VOBC数据时可能有效*/
	UINT8 oc2ciParseResult = CI_ERROR;/*oc到ci解析结果*/
	UINT8 checkResult = 0u;
	UINT8 startLockFlag = 0u;

	UINT8 ocId = 0u;
	UINT8 chLocalCiId = 0u;
	UINT8 appRecvRtn = 0u;
	UINT16 srcDevTypeId = 0u;
	UINT16 srcDevLogicId = 0u;
	UINT8 data[TMP_BUF_LEN] = { 0u };

	UINT32 dataLen = 0u;
	UINT8 devType = 0u;
	UINT8 devId = 0u;
	UINT8 ocInCiId = 0u;
	UINT8 locCiId = 0u;
	UINT32 curSysCount = 0u; /*当前系统周期*/
	UINT8 srcDevTypeIdBuff[2] = { 0 }; /*源设备类型ID数组*/
	UINT8 srcLogicIdBuff[2] = { 0 }; /*源逻辑ID数组*/
	UINT8 isBreak = 0u; /*退出遍历*/
	UINT16 wTiocRcvAtsGtwyDevTypeId = 0U;
	UINT8 errorNO_Type = 0u;		/*CI间接口校验数据故障码*/

	curSysCount = MSCP_GetSysCount();
	wTiocRcvAtsGtwyDevTypeId = GetTiocTrnsmtGtwyDevTypeId();

	while (1)
	{ /*获取队列不为空*/
		/*获取队列数据总长度*/
		appRecvRtn = OutnetSafeRecv(&srcDevTypeId, &srcDevLogicId, data, &dataLen, (UINT32)sizeof(data));
		if ((1U == appRecvRtn) && (0U < dataLen)) //接收成功且有数据
		{
			devType = (UINT8)((srcDevTypeId >> 8u) & 0xFFu);/*获取设备类型*/
			devId = (UINT8)(srcDevTypeId & 0xFFu);
			switch (devType) /*按设备类型处理*/
			{
#if USE_PROTOCOL_RSSP


			case CI_SYSTEM_TYPE_OC:
			{
#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nOC_RECV:%d OcId:%d", dataLen, devId);
				debug_out_array(0xAA, data, (UINT16)dataLen);
				debug_out_array(0x11, data, (UINT16)dataLen);
#endif/*平台打印结束*/
#endif/*日志打印结束*/
				ocId = (UINT8)GetCiIdByOcId(devId);
				chLocalCiId = GetSystemParaLocalCiId();
				if (ocId == chLocalCiId)/*如果oc id所属的ci id为本机联锁id*/
				{
					oc2ciParseResult = ParseOcToCiDataFrame(data, (UINT16)dataLen, devId);
					if (CI_CHECK_LEN_ERROR == oc2ciParseResult)
					{
						/*长度校验错误处理，把此OC原始缓存所有设备状态导向安全*/
						/* 长度校验失败处理：
						*  1. 当周期，OC原始数据缓存设备状态、轨道板状态、DI板卡状态、DO板卡状态置安全态。
						*  2. 因为CI与此OC通信周期不更新，超过CI OC通信中断最大容忍周期数，也会置通信中断，所有设备状态导向安全。
						*/
						ResetOcOriginalState(devId);
						ConvertOcOriginDataToPtData();/*把解析的OC板卡数据转换为OC点位数据*/
						ConvertOcOriginDataToOcSigSwDev();/*把解析的OC设备数据转换为OC 信号机和 OC 道岔设备数据和OC轨道区段数据*/
						debug_infor_printf((const)"OC Id %d len check ERROR.", devId);
					}
					else if (CI_SUCCESS == oc2ciParseResult)
					{/*解析成功，转换OC板卡数据*/
						ConvertOcOriginDataToPtData();/*把解析的OC板卡数据转换为OC点位数据*/
						ConvertOcOriginDataToOcSigSwDev();/*把解析的OC设备数据转换为OC 信号机和 OC 道岔设备数据和OC轨道区段数据*/
						debug_infor_printf((const)"\nconvert succeed\n");
					}
					else
					{
						/*其它值，清除缓存数据*/
						ResetOcOriginalState(devId);
						ConvertOcOriginDataToPtData();/*把解析的OC板卡数据转换为OC点位数据*/
						ConvertOcOriginDataToOcSigSwDev();/*把解析的OC设备数据转换为OC 信号机和 OC 道岔设备数据和OC轨道区段数据*/
						debug_infor_printf((const)"OC Id %d parse ERROR.", devId);
					}
				}
				else
				{
				}

				break;
			}
#endif
			case CI_SYSTEM_TYPE_ATS:
				/*解析ATS数据*/
#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/

#endif/*平台打印结束*/

#endif              
				if (wTiocRcvAtsGtwyDevTypeId != srcDevTypeId)
				{

					debug_infor_printf((const)"\nATS_RECV:%d", dataLen);
					checkResult = ParseAtsOrXianDiToCiDataFrame(data, (UINT16)dataLen);
					(void)DarkInfoPack(CIM_INFO_ATS_TO_RCI_DATA, data, (UINT16)dataLen);
				}
				else
				{

					debug_infor_printf((const)"\nGATEWAY_RECV:%d", dataLen);
					checkResult = ParseGateWayToCiDataFrame(data, (UINT16)dataLen);
				}
				debug_out_array(0xAA, data, (UINT16)dataLen);
				if (CI_ERROR == checkResult)
				{/*解析失败*/

					debug_infor_printf((const)"parse ats id %d error.", devId);
				}
				else
				{
				}
				break;
			case CI_SYSTEM_TYPE_XIANDI:
				/*解析现地数据*/
#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nXIANDI_RECV:%d", dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);
				debug_out_array(0x11, data, (UINT16)dataLen);
#endif/*平台打印结束*/

#endif              
				checkResult = ParseAtsOrXianDiToCiDataFrame(data, (UINT16)dataLen);

				(void)DarkInfoPack(CIM_INFO_ATS_TO_RCI_DATA, data, (UINT16)dataLen);
				if (CI_ERROR == checkResult)
				{
					debug_infor_printf((const)"parse xiandi id %d error.", devId);
				}
				else
				{
				}
				break;
			case CI_SYSTEM_TYPE_CI:
				/*解析CI数据*/
#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nCI_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);
#endif/*平台打印结束*/

#endif
				/*判断是否是同一条线路的联锁，不同线路联锁使用互联互通联锁接口，同一条线路使用自家联锁接口*/
				sameLineCi = IsSameLineCI(devId, GetSystemParaLocalCiId());
				if (SAME_LINE_YES == sameLineCi) /*同线*/
				{
					startLockFlag = GetStartLockFlag();
					if (CI_START_LOCK_NO == startLockFlag)
					{
						checkResult = ParseCiToCiDataCheck(data, (UINT16)dataLen, &errorNO_Type);		/*相邻CI间数据传输的校验*/
						if (CI_SUCCESS != checkResult)
						{
							debug_infor_printf((const)"check parse ci step %d error", errorNO_Type);
						}
						else
						{
							checkResult = ParseCiToCiDataFrame(data, (UINT16)dataLen);
							if (CI_SUCCESS != checkResult) /*错误*/
							{
								debug_infor_printf((const)"parse ci id %d error", devId);
							}
							else
							{

							}
						}
					}
					else
					{
					}
				}
				else if (SAME_LINE_NO == sameLineCi) /*不同线*/
				{
					checkResult = ParseCiToCiDataFrameHLHT(data, (UINT16)dataLen, devId);
					if (CI_ERROR == checkResult) /*错误*/
					{
						debug_infor_printf((const)"parse hlht ci id %d error", devId);
					}
					else
					{
					}
				}
				else
				{
					debug_infor_printf((const)"ci id %d sameLineCi:%d error", devId, sameLineCi);
				}

				break;

			case CI_SYSTEM_TYPE_ZC:
				debug_infor_printf((const)"\nZC_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseZcToCiDataFrame(data, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					ClearZcData();/*清ZC数据*/
					debug_infor_printf((const)"parse zc id %d error", devId);
				}
				else
				{
				}

				break;

			case CI_SYSTEM_TYPE_TMC:/* 解析TMC数据 */
				debug_infor_printf((const)"\nTMC_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseTmcToTiocDataFrame(data, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse tmc id %d error", devId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_VOBC: /*解析VOBC数据*/
				debug_infor_printf((const)"\nVOBC_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseVobcToCiDataFrame(data, (UINT16)dataLen, devId, srcDevLogicId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse vobc id %d,logic id %d error", devId, srcDevLogicId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_VOBC_BACKUP: /*解析VOBC备用通道数据*/
				debug_infor_printf((const)"\nVOBC_BACKUP_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseVobcBackUpToCiDataFrame(data, (UINT16)dataLen, devId, srcDevLogicId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse vobc_backup id %d,logic id %d error", devId, srcDevLogicId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_ITE:
				debug_infor_printf((const)"\nITE_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseIteToCiData(data, (UINT16)dataLen, devId, srcDevLogicId);  /*解析ITE数据*/
				if (CI_ERROR == checkResult)
				{
					debug_infor_printf((const)"parse ite id %d,logic id %d error", devId, srcDevLogicId);   /*解析错误，记录日志*/
				}
				else
				{
					/*继续解析*/
				}
				break;
			case CI_SYSTEM_TYPE_PLATFORM: /*解析PSD数据*/
				debug_infor_printf((const)"\nPSD_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParsePlatformToCiDataFrame(data, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse psd id %d error", devId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_AXIS: /*解析计轴数据*/
				debug_infor_printf((const)"\nAXIS_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParseAxisToCiDataFrame(data, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse axis id %d error", devId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_PSC: /*解析PSC数据*/
				debug_infor_printf((const)"\nPSC_RECV:%d", (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);

				checkResult = ParsePscToCiDataFrame(data, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult) /*错误*/
				{
					debug_infor_printf((const)"parse psc id %d error", devId);
				}
				else
				{
				}

				break;
			case CI_SYSTEM_TYPE_LEU:
				/*解析LEU数据*/
				SaveLeuToCiData(data, (UINT16)dataLen);

#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nLEU%d_RECV:%d", devId, (UINT16)dataLen);
				debug_out_array(0xAA, data, (UINT16)dataLen);
#endif/*平台打印结束*/
#endif				
				checkResult = ParseLeuToCiDataFrame(data + 6, (UINT16)dataLen, devId);
				if (CI_ERROR == checkResult)
				{
					debug_infor_printf((const)"parse leu id %d error", devId);
				}
				else
				{
				}

				break;
			default: /*非法数据*/
				break;
			}

		}
		else
		{
			break;
		}
	}

	return CI_SUCCESS;
}


/*
* 功能描述： 解析内网发来的数据
* 参数说明： void
* 返回值  ： 0:解析失败
*			 1:解析成功
*/
UINT8 ParseINNETToCiData(void)
{
	UINT8 funcRet = 0u;
	UINT16 srcDevTypeId = 0u;
	UINT16 srcDevLogicId = 0u;
	UINT8 data[TMP_BUF_LEN] = { 0u };
	UINT32 dataLen = 0u;
	UINT8 devType = 0u;
	UINT8 devId = 0u;
	UINT8 parseResult = CI_ERROR; /*解析是否成功*/
	while (1)
	{
		/*获取队列不为空*/
		funcRet = InnetSafeRecv(&srcDevTypeId, &srcDevLogicId, data, &dataLen, (UINT32)sizeof(data));
		if ((1U == funcRet) && (0U < dataLen) && (0u != srcDevTypeId)) //接收成功且有数据
		{
			devType = (UINT8)((srcDevTypeId >> 8u) & 0xFFu);/*解析设备类型*/
			devId = (UINT8)(srcDevTypeId & 0xFFu);/*解析设备ID*/

			/*按设备类型处理*/
			switch (devType)
			{
#if USE_PROTOCOL_RSSP


			case DEVTYPE_AIM:
			{
#ifdef LOGPRINT/*日志打印宏*/
#ifdef PLATFORM_2OO2/*2oo2平台打印*/
				debug_infor_printf((const)"\nAIM_RECV:%d OcId:%d", dataLen, devId);
				debug_out_array(0xAA, data, (UINT16)dataLen);
#endif/*平台打印结束*/
#endif/*日志打印结束*/

				parseResult = Deploy_ParseAIMInputInfo(data, (UINT16)dataLen, devType, devId);
				if (CI_SUCCESS == parseResult)
				{
					/*解析成功*/
				}
				else
				{
					debug_infor_printf((const)"4.3 AID %04x Input Error!\n", srcDevTypeId);
				}
				break;
			}
#endif

			default: /*非法数据*/
				break;
			}
		}
		else
		{
			break;
		}
	}

	return CI_SUCCESS;
}




/*
* 功能描述： 组发送到其他系统的数据
* 参数说明： void
* 返回值  ： 0: 组包失败
*			 1: 组包成功
*/
UINT8 PackCiToOtherSysData(void)
{
	UINT8 deviceSum = 0u;               /*设备总数*/
	UINT8* deviceIdBuf = NULL;         /*设备ID数组*/
	UINT8 ii = 0u;
	UINT8 comCycNumForCiToOtherSys = 0u;
	UINT8 reVal = 0u;
	UINT8 IsSameLine = 0u;

	UINT32 fsfbDataLen = 0u; /*fsfb总数据长度*/
	UINT32 fsfbDataIdx = 0u; /*fsfb总数据当前位置*/
	UINT16 fsfbFramLen = 0u; /*fsfb帧长度*/
	UINT16 dstTypeId = 0u; /*目的类型ID*/
	UINT32 curSysCount = 0u; /*当前系统周期*/
	UINT32 fsfbOutQueLen = 0u; /*fsfb输出队列长度*/
	UINT8 fsfbOutQueData[2048] = { 0 }; /*fsfb输出队列数据*/
	UINT32 fsfbOutQueIdx = 0u; /*fsfb输出队列位置*/
	UINT16 fsfbOutQueFramLen = 0u; /*fsfb输出队列帧长度*/
	UINT8 fsfbBtmHead[5] = { 0 }; /*fsfb btm帧头*/

	UINT8 chTiocRcvAtsGtwyDevTypeId = 0U;
	unsigned long long cost[20] = { 0U };
	UINT32 dwFlyProtectOverCyc = GetFlyProtectOverCyc();

	chTiocRcvAtsGtwyDevTypeId = (UINT8)GetTiocTrnsmtGtwyDevTypeId();
	curSysCount = MSCP_GetSysCount();

	cost[0] = MSCP_GetTick();

	if(0U == dwFlyProtectOverCyc)
	{
		/*****组现地数据*****/
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_XIANDI);     /*获取通信现地设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_XIANDI); /*获取通信现地设备ID数组*/

		if ((0u < deviceSum) && (NULL != deviceIdBuf))
		{ /*通信设备正确*/

			/*检查通信周期是否满足通信要求,通信周期为0时可以进行通信*/
			comCycNumForCiToOtherSys = GetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_XIANDI);
			if (0u == comCycNumForCiToOtherSys)
			{
				for (ii = 0u; ii < deviceSum; ii++)
				{
					/*组现地站场帧数据*/
					reVal = PackCiToAtsOrXianDiData(deviceIdBuf[ii], CI_SYSTEM_TYPE_XIANDI, CI_ATS_STATION_FRAME);
					if (CI_ERROR == reVal)
					{
						/*组包错误*/
					}
					else
					{
						;
					}
				}

				SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_XIANDI, COM_CYCNUM_CI_TO_XIANDI);/*设置最大值通信周期*/
			}
			else
			{
				for (ii = 0u; ii < deviceSum; ii++)
				{
					/*组现地设备帧数据*/
					reVal = PackCiToAtsOrXianDiData(deviceIdBuf[ii], CI_SYSTEM_TYPE_XIANDI, CI_ATS_DEVICE_STATE_FRAME);
					if (CI_ERROR == reVal)
					{
						/*组包错误*/
					}
					else
					{
						;
					}
				}
				SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_XIANDI, (UINT8)(comCycNumForCiToOtherSys - 1U));/*设置最大值通信记录值减1*/
			}

		}

		/*****组ATS数据*****/
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_ATS); /*获取通信ATS设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ATS); /*获取通信ATS设备ID数组*/

		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{ /*通信设备正确*/

			/*检查通信周期是否满足通信要求,通信周期为0时可以进行通信*/
			comCycNumForCiToOtherSys = GetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS);
			for (ii = 0u; ii < deviceSum; ii++)
			{
				if (chTiocRcvAtsGtwyDevTypeId != deviceIdBuf[ii])
				{
					if (0u == comCycNumForCiToOtherSys)
					{

						/*组ATS站场帧数据*/
						reVal = PackCiToAtsOrXianDiData(deviceIdBuf[ii], CI_SYSTEM_TYPE_ATS, CI_ATS_STATION_FRAME);

						if (CI_ERROR == reVal)
						{
							/*组包错误*/
						}
						else
						{
							; /*DO NOTHING*/
						}
						SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS, COM_CYCNUM_CI_TO_ATS);/*设置最大值通信周期*/
					}
					else
					{
						/*组ATS设备帧数据*/
						reVal = PackCiToAtsOrXianDiData(deviceIdBuf[ii], CI_SYSTEM_TYPE_ATS, CI_ATS_DEVICE_STATE_FRAME);
						if (CI_ERROR == reVal)
						{
							/*组包错误*/
						}
						else
						{
							; /*DO NOTHING*/
						}
						SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS, (UINT8)(comCycNumForCiToOtherSys - 1U));/*设置最大值通信记录值减1*/
					}
				}
				else
				{
					; /*do nothing*/
				}
			}
			if (0u == comCycNumForCiToOtherSys)
			{
				ClearCiSendCmdData();/*组包完成后清CI给现地/ATS反馈命令数据*/
			}
			else
			{
				/* DO NOTHING*/
			}
		}
		else if (deviceSum == 0u)
		{
			comCycNumForCiToOtherSys = GetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS);
			if (0U == comCycNumForCiToOtherSys)
			{

				SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS, COM_CYCNUM_CI_TO_ATS);/*设置最大值通信周期*/

				ClearCiSendCmdData();/*组包完成后清CI给现地/ATS反馈命令数据*/
			}
			else
			{
				SetComCycNumForCiToOtherSys(CI_SYSTEM_TYPE_ATS, (UINT8)(comCycNumForCiToOtherSys - 1U));/*设置最大值通信记录值减1*/
			}
		}
		else
		{
			/*什么都不做*/
		}
	}

	/*******组ATS网关数据*********/
	deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_ATS); /*获取通信ATS设备总数*/
	deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ATS); /*获取通信ATS设备ID数组*/

	if ((deviceSum > 0u) && (deviceIdBuf != NULL))
	{ /*通信设备正确*/
		for (ii = 0u; ii < deviceSum; ii++)
		{
			if (chTiocRcvAtsGtwyDevTypeId == deviceIdBuf[ii])
			{
				/*组ATS站场帧数据*/
				reVal = PackTiocToGateWayData(deviceIdBuf[ii], CI_SYSTEM_TYPE_ATS);

				if (CI_ERROR == reVal)
				{
					/*组包错误*/
				}
				else
				{
					; /*DO NOTHING*/
				}
			}
			else
			{
				; /*do nothing*/
			}
		}

	}
	else
	{
		/*什么都不做*/
	}

	cost[1] = MSCP_GetTick();
	if(0U == dwFlyProtectOverCyc)
	{
		/*****组ZC数据*****/
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_ZC); /*获取通信ZC设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_ZC); /*获取通信ZC设备ID数组*/

		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组ZC数据*/
				reVal = PackCiToZcData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/
				}
				else
				{
					;
				}
			}
		}
		else
		{
			; /*do nothing*/
		}


		/*****组TMC数据*****/
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_TMC); /*获取通信TMC设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_TMC); /*获取通信TMC设备ID数组*/

		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组TMC数据*/
				reVal = PackTiocToTmcData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/
				}
				else
				{
					;
				}
			}
		}
		else
		{
			; /*do nothing*/
		}

		/*****组CI数据*****/
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(Get2oo2SheBeiType()); /*获取通信CI设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(Get2oo2SheBeiType()); /*获取通信CI设备ID数组*/

		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{

				IsSameLine = IsSameLineCI(GetSystemParaLocalCiId(), deviceIdBuf[ii]);

				if (SAME_LINE_YES == IsSameLine)
				{
					/*组CI数据*/
					reVal = PackCiToCiData(deviceIdBuf[ii]);
					if (CI_ERROR == reVal)
					{
						/*组包错误*/
					}
					else
					{
						;
					}
				}
				else if (SAME_LINE_NO == IsSameLine)
				{
					/*组CI数据*/
					reVal = PackHLHTCiToCiData(deviceIdBuf[ii]);
					if (CI_ERROR == reVal)
					{
						/*组包错误*/
					}
					else
					{
						;
					}
				}
				else
				{
					/*无操作*/
				}
			}
		}


		/*****组LEU数据*****/
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_LEU); /*获取通信CI设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_LEU); /*获取通信CI设备ID数组*/

		if ((deviceSum > 0u) && (deviceIdBuf != NULL))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组LEU数据*/
				reVal = PackCiToLeuData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/
					debug_infor_printf((const)"\nLEU_PACK_ERROR:%d");
				}
			}

		}
		else
		{
			; /*do nothing*/
		}
		cost[2] = MSCP_GetTick();
		/*****组VOBC数据*****/

		/*组VOBC数据*/
		reVal = PackCiToVobcData();
		if (CI_ERROR == reVal)
		{
			/*组包错误*/

		}
		cost[3] = MSCP_GetTick();
		/*组VOBC后备通道数据*/
		(void)PackCiToVobcBackUpData();
		if (CI_ERROR == reVal)
		{
			/*组包错误*/

		}

		/*组ITE数据*/
		reVal = PackCiToIteData();
		if (CI_ERROR == reVal)
		{
			/*组包错误*/

		}

		/*****组PSD数据******/
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_PLATFORM);     /*获取通信PSD设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_PLATFORM); /*获取通信PSD设备ID数组*/

		if ((0u < deviceSum) && (NULL != deviceIdBuf))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组PSD数据*/
				reVal = PackCiToPlatformData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/

				}
				else
				{
					; /*do nothing*/
				}
			}
		}
		else
		{
			; /*do nothing*/
		}

		/*****组Axis数据*****/

		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_AXIS); /*获取通信Axis设备ID数组*/

		if ((0u < deviceSum) && (NULL != deviceIdBuf))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组Axis数据*/
				reVal = PackCiToAxisData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/
				}
			}
		}
		else
		{
			; /*do nothing*/
		}
	}
	else
	{
		/*不处理*/
	}

	/*组飞车特控报文*/
	PackCiToVobcFlyProtectData();
	
#ifdef APPCI_MAINTAIN_DEBUG
#ifdef PLATFORM_2OO2
	/*cgh-合并CID-2349-1：*/
	/*发送给维护机设备通信状态*/
	PackCiToCimCommData();
	/*发送给维护机信号机断丝状态*/
	debug_infor_printf((const)"\nCIM_SEND_DS\n");
	PackCiToCimSignalDsData();
	/*发送维护机继电器驱动采集不一致报警*/
	debug_infor_printf((const)"\nCIM_Relay_DriAndCollDiff\n");
	PackCiToCimRelayDriAndCollDiff();
	/*发送维护机屏蔽门报警*/
	debug_infor_printf((const)"\nCIM_PSD_alarm\n");
	PackCiToCimPsdAlarmData();
	/*发送维护机驱动超时报警*/
	PackCiToCimSigDriOutTimeData(); 
	/*发送维护机版本号信息*/
	PackCiToCimVerData();
	/*发送维护机设备状态信息*/
	PackCiToCimDeviceData();
	/*发送维护机飞车报警*/
	PackCiToCimFlyProtectData();
	/*发送维护机IO双系采集不一致报警*/
	PackCiToCimCollDiffData();
	/*发送给AIM退出运营信息*/
	AIMOutput();
	/*发送给维护机执行单元报警信息*/
	PackCiToCimUnitAlarmData();
	
#endif		
#endif

#if USE_PROTOCOL_RSSP/*组OC数据*/
	/*组OC数据*/
	cost[4] = MSCP_GetTick();
	if (0U == dwFlyProtectOverCyc)
	{
		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_OC); /*获取通信OC设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_OC); /*获取通信OC设备ID数组*/

		if ((0u < deviceSum) && (NULL != deviceIdBuf))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组OC数据*/
				reVal = PackCiToOcData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/

				}
			}

		}
	}
#endif

	if (0U == dwFlyProtectOverCyc)
	{
		/*****组PSC数据******/

		deviceSum = 0u;
		deviceIdBuf = NULL;
		deviceSum = GetCiTransmitSpecifySysDevSum(CI_SYSTEM_TYPE_PSC);     /*获取通信PSC设备总数*/
		deviceIdBuf = GetCiTransmitSpecifySysDevBuf(CI_SYSTEM_TYPE_PSC); /*获取通信PSC设备ID数组*/

		if ((0u < deviceSum) && (NULL != deviceIdBuf))
		{ /*通信设备正确*/

			for (ii = 0u; ii < deviceSum; ii++)
			{
				/*组PSC数据*/
				reVal = PackCiToPscData(deviceIdBuf[ii]);
				if (CI_ERROR == reVal)
				{
					/*组包错误*/

				}
				else
				{
					; /*do nothing*/
				}
			}
		}
		else
		{
			; /*do nothing*/
		}
	}
	cost[5] = MSCP_GetTick();
#ifdef APPCI_MAINTAIN_DEBUG
#ifdef PLATFORM_2OO2
	/*转发LEU发送来的数据给维修机*/
#if 0
	tempDataBuf = GetLeuData();
	debug_out_array(0x10, GetLeuData(), GetLeuDataLen());
#endif
#endif
#endif

#ifdef APPCI_MAINTAIN_DEBUG
#ifdef PLATFORM_2OO2
#if 0
	debug_infor_printf((const)"\nCIM_SEND_COMM\n");
	/*发送给维修机设备通信状态*/
	PackCiToCimCommData();
#endif
	debug_infor_printf((const)"\nCIM_SEND_DS\n");
	/*发送给维修机信号机断丝状态*/
	PackCiToCimSignalDsData();
	/*发送给维修机继电器混线状态*/
	debug_infor_printf((const)"\nCIM_SEND_HUNXIAN\n");
	PackCiToCimRelayHunXianData();
#endif		
#endif

	/*清LEU数据*/
	ClearLeuToCiData();

	/*cgh-合并CID-2588-3：*/
	/*重置IO到联锁的采集继电器数据*/
	ResetRelayABCollState();
	/*重置继电器驱动状态*/
	ClearRelayDriveState();
	cost[6] = MSCP_GetTick();
	debug_infor_printf((const)"\n Pack Ats :%dms  Pack CI :%dms Pack Vobc:%dms Pack Axle:%dms Pack Oc:%dms Pack Maintain:%dms  \n", (cost[1] - cost[0]) / 1000, (cost[2] - cost[1]) / 1000, (cost[3] - cost[2]) / 1000, (cost[4] - cost[3]) / 1000, (cost[5] - cost[4]) / 1000, (cost[6] - cost[5]) / 1000);

	return CI_SUCCESS;
}

/*
* 功能描述： 解析内网发来的数据
* 参数说明： void
* 返回值  ： 0:解析失败
*			 1:解析成功
*/
UINT8 ParasePlatToRCIData(void)
{
	UINT8 retVal = CI_ERROR;

	/*解析心跳帧数据*/
	retVal = PlatHeartFrameProcess();
 
	/*解析平台通道IO数据*/
	PlatChannelIODataProcess();



	return retVal;
}


