/************************************************************************
*
* 文件名   ：  dquCIJDQStruInit.c
* 版权说明 ：  北京交控科技有限公司 
* 版本号   ：  1.0
* 创建时间 ：  2011.12.27
* 作者     ：  研发中心软件部
* 功能描述 ：  继电器数据结构体初始化处理过程 
* 使用注意 ： 
* 修改记录 ：  
*
************************************************************************/
#include "dquCIJDQStruInit.h"



/*********定义全局的继电器信息数据变量*******/
RelayDataStruct_Config RelayData;
	RelayDataStruct_ConfigLen RelayDataLen;

/***************************/


/*********************************************
*函数功能：填充信号机继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_SignalStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_SignalStruct* pSgnlStr;   /*临时信号机继电器变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT8 localCiPattern;
	UINT32 excelId = 0U;
	UINT32 sheetId = 0U;
	UINT32 rowLen = 0U;
	/*已经初始化了，不用老是调用执行过程*/
	if(NULL != RelayData.pRelaySignalStr)
	{
		rtnValue = 1u;
		return rtnValue;
	}
	else
	{
		rtnValue = 1u;
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_SIGNAL;
			rowLen = LEN_RELAY_SIGNAL;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_SIGNAL_RELAY_ID;
			rowLen = LEN_OC_SIGNAL_RELAY;
		}
	}
	/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName, excelId, sheetId,&pDataAddr,&DataSize);
	   if(0u == funcRtn)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
			return rtnValue;
	   } 	
	   else
	   {
	   }
		/*求得个数*/
	   if(0u != DataSize%LEN_OC_SIGNAL_RELAY)
	   {   
			rtnValue = 0u;
			debug_infor_printf((const)"\nCI_RELAY_DATA,SIGNAL_RELAY,len %d not equal to fs",LEN_RELAY_SIGNAL);
			DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,((UINT32)CI_DATA_TYPE<<8u)+RELAY_SIGNAL,PRINT_ONCE);
			return rtnValue;
	   }
	   				
	   RelayDataLen.RelaySignalStrLen = (UINT16)(DataSize/ LEN_OC_SIGNAL_RELAY);

		if(LEN_OC_SIGNAL_RELAY > DataSize)
	   {
		   RelayData.pRelaySignalStr = (Relay_SignalStruct *) MyNew ((UINT32)sizeof(Relay_SignalStruct) );
		   rtnValue = 1u;
		   return rtnValue;
	   }
	   else
	   {
		   /*继续执行*/
	   }


		/*动态申请空间*/
		RelayData.pRelaySignalStr = (Relay_SignalStruct *) MyNew ((UINT32)(sizeof(Relay_SignalStruct) * RelayDataLen.RelaySignalStrLen));
		/*动态申请空间失败*/
		if(NULL == RelayData.pRelaySignalStr)
		{
            RelayDataLen.RelaySignalStrLen = 0u;
			rtnValue = 0u;
			return rtnValue;
		}
		else
		{
			/*内存先设为无效*/
			(void)memset(RelayData.pRelaySignalStr, 0x00,sizeof(Relay_SignalStruct) * RelayDataLen.RelaySignalStrLen);
		}
		
		/*解析数据到 默认行车序列 结构体数组 */  
		for(j=0u;j<RelayDataLen.RelaySignalStrLen;j++)
		{
			pSgnlStr = RelayData.pRelaySignalStr + j;
			
			/*填充数据结构体*/
			(void) R_SignalStructFromChar(pDataAddr,pSgnlStr);
			pDataAddr += LEN_OC_SIGNAL_RELAY;

		}

	rtnValue = 1u;
	return rtnValue;
}
/*********************************************
*函数功能：填充洗车机继电器结构体数组---内部用
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_WashMachineStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0u;
	Relay_WashMachineStruct* pWashMachineStr = NULL;   /*临时洗车机继电器变量*/
	UINT8* pDataAddr;                                  /*数据地址*/
	UINT32 DataSize;                                   /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT16 rowLen = 0u; /*行长度*/
	UINT16 realRowLen = 0U;/*实际表一行的长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayWashMachineStr != NULL)
	{
		rtnValue = 1u;
	}
    else
    {
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_WASH_MACHINE_ID;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_WASH_MACHINE_ID;
		}
	   /*读取洗车机继电器数据表*/
	   funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId,&pDataAddr,&DataSize, &rowLen);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
	   }
	   else
	   {
			
		   if((0U != DataSize) && (0U != rowLen))
		   { 
			   if (0U != DataSize % rowLen)
			   {
				   /*求得个数不为整数，数据错误*/
				   debug_infor_printf((const)"\nCI_RELAY_DATA,WASHMACHINE_RELAY len %d not equal to fs", rowLen);
				   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, (excelId << 8u) + sheetId, PRINT_ONCE);
				   rtnValue = 0u;
			   }
			   else
			   {
				   realRowLen = (UINT16)(DataSize / rowLen);
				   RelayDataLen.RelayWashMachineStrLen = rowLen;/*计算结构体个数*/

				   if (DataSize < realRowLen)
				   {/*不足一个*/
					   rtnValue = 0U;
				   }
				   else
				   {

					   /*动态申请空间*/
					   RelayData.pRelayWashMachineStr = (Relay_WashMachineStruct*)MyNew((UINT32)(sizeof(Relay_WashMachineStruct) * RelayDataLen.RelayWashMachineStrLen));

					   if (NULL == RelayData.pRelayWashMachineStr)
					   {/*动态申请空间失败*/
						   RelayDataLen.RelayWashMachineStrLen = 0u;
						   rtnValue = 0u;
					   }
					   else
					   {
						   /*内存先设为无效*/
						   (void)memset(RelayData.pRelayWashMachineStr, 0x00, sizeof(Relay_WashMachineStruct) * RelayDataLen.RelayWashMachineStrLen);
						   /*解析数据到 默认行车序列 结构体数组 */
						   rtnValue = 1u;
						   for (j = 0u; j < RelayDataLen.RelayWashMachineStrLen; j++)
						   {
							   pWashMachineStr = RelayData.pRelayWashMachineStr + j;

							   /*填充数据结构体*/
							   rtnValue &= R_WashMachineStructFromChar(pDataAddr, pWashMachineStr, realRowLen);
							   pDataAddr += realRowLen;

						   }
					   }/*end:if(NULL == RelayData.pRelayWashMachineStr)*/
				   }/*end:if(DataSize < LEN_RELAY_WASH_MACHINE)*/
			   }/*end:if(DataSize%LEN_RELAY_WASH_MACHINE != 0)*/

		   }
		   else
		   {
			   rtnValue = 1u;
		   }

	   	}/*end:	if(funcRtn == 0)*/
    }/*end:if(RelayData.pRelayWashMachineStr != NULL)*/
	return rtnValue;

}

/*********************************************
*函数功能：填充紧急停车按钮继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_EmgcyStpStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_EmgcyStpStruct* pEmgcyStpStr;   /*临时信号机继电器变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*读到的行数*/
	UINT16 realRowLen = 0U;/*实际表一行的长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if (RelayData.pRelayEmgcyStpStr != NULL)
	{
		rtnValue = 1u;
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_EMERG_STOP_ID;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_EMERG_STOP_ID;
		}
		/*读取 默认行车序列  数据*/
		funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId, &pDataAddr, &DataSize, &rowLen);
		if (0u == funcRtn)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		}
		else
		{
			/*求得个数*/
			if ((0U != DataSize) && (0U != rowLen))
			{
				if (0U != DataSize % rowLen)
				{
					/*求得个数不为整数，数据错误*/
					debug_infor_printf((const)"\nCI_CI_DATA,EMERG_STOP len %d not equal to fs", rowLen);
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, ((UINT32)CI_DATA_TYPE << 8u) + RELAY_EMERG_STOP_ID, PRINT_ONCE);
					rtnValue = 0u;
				}
				else
				{
					realRowLen = (UINT16)(DataSize / rowLen);
					RelayDataLen.RelayEmgcyStpStrLen = (UINT16)rowLen;


					if (DataSize < realRowLen)
					{
						rtnValue = 0U;
					}
					else
					{
						/*动态申请空间*/
						RelayData.pRelayEmgcyStpStr = (Relay_EmgcyStpStruct*)MyNew((UINT32)((sizeof(Relay_EmgcyStpStruct)) * (RelayDataLen.RelayEmgcyStpStrLen)));
						/*动态申请空间失败*/
						if (NULL == RelayData.pRelayEmgcyStpStr)
						{
							RelayDataLen.RelayEmgcyStpStrLen = 0u;
							rtnValue = 0u;
						}
						else
						{
							/*内存先设为无效*/
							(void)memset(RelayData.pRelayEmgcyStpStr, 0x00, sizeof(Relay_EmgcyStpStruct) * RelayDataLen.RelayEmgcyStpStrLen);
							/*解析数据到 默认行车序列 结构体数组 */
							rtnValue = 1u;
							for (j = 0u; j < RelayDataLen.RelayEmgcyStpStrLen; j++)
							{
								pEmgcyStpStr = RelayData.pRelayEmgcyStpStr + j;

								/*填充数据结构体*/
								rtnValue &= R_EmegencyStopStructFromChar(pDataAddr, pEmgcyStpStr, realRowLen);
								pDataAddr += realRowLen;

							}
						}
					}
				}
			}
			else
			{
				rtnValue = 1u;
			}
		}
	}
	return rtnValue;
}

/*********************************************
*函数功能：填充屏蔽门继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_ScreenStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0U;
	Relay_ScreenStruct* pScreenStr = NULL;   /*临时信号机继电器变量*/
	UINT8* pDataAddr = NULL;         /*数据地址*/
	UINT32 DataSize = 0U;          /*数据大小（字节数）*/
	UINT16 j = 0U;
	UINT16 wRealRowCount = 0U;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

							   /*已经初始化了，不用老是调用执行过程*/
	if (RelayData.pRelayScreenStr != NULL)
	{
		rtnValue = 1u;
		return rtnValue;
	}
	localCiPattern = GetLocalCiPattern();
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		excelId = CI_DATA_TYPE;
		sheetId = RELAY_SCREEN_ID;
	}
	else
	{
		excelId = OC_DATA_TYPE;
		sheetId = OC_RELAY_SCREEN_ID;
	}
	/*读取 默认行车序列  数据*/
	funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId, &pDataAddr, &DataSize, &wRealRowCount);
	if (funcRtn == 0u)
	{
		/*函数调用失败*/
		rtnValue = 0u;
	}
	else
	{
		rtnValue = 1u;
	}

	if (1U == rtnValue)
	{/*求得个数*/
		if (DataSize%wRealRowCount != 0u)
		{
			debug_infor_printf((const)"\nCI_RELAY_DATA,SCREEN_RELAY len %d not equal to fs", rowLen);
			DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, (excelId << 8) + sheetId, PRINT_ONCE);
			rtnValue = 0u;
		}
		else
		{
			;  /*不处理*/
		}
	}

	if (1U == rtnValue)
	{
		RelayDataLen.RelayScreenStrLen = wRealRowCount;
		rowLen = DataSize / wRealRowCount;
		if (DataSize < rowLen)
		{
			rtnValue = 0U;
			
		}
		else
		{
			/*动态申请空间*/
			RelayData.pRelayScreenStr = (Relay_ScreenStruct *)MyNew((UINT32)(sizeof(Relay_ScreenStruct) * RelayDataLen.RelayScreenStrLen));
			/*动态申请空间失败*/
			if (NULL == RelayData.pRelayScreenStr)
			{
				RelayDataLen.RelayScreenStrLen = 0u;
				rtnValue = 0u;
			}
			else
			{
				/*内存先设为无效*/
				(void)memset(RelayData.pRelayScreenStr, 0x00, sizeof(Relay_ScreenStruct) * RelayDataLen.RelayScreenStrLen);
				/*解析数据到 默认行车序列 结构体数组 */
				for (j = 0u; j<RelayDataLen.RelayScreenStrLen; j++)
				{
					pScreenStr = RelayData.pRelayScreenStr + j;

					/*填充数据结构体*/
					rtnValue &= R_ScreenStructFromChar(pDataAddr, pScreenStr, (UINT16)rowLen);
					pDataAddr += rowLen;

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

	return rtnValue;
}

/* zt 删除单轨相关代码 2022-02-15 */

/*********************************************
*函数功能：填充道岔继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_PointStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_PointStruct* pPointRelayStr;   /*临时道岔继电器变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT8 localCiPattern = 0U;
	UINT32 excelId = 0U;
	UINT32 sheetId = 0U;
	UINT32 rowLen = 0U;
	/*已经初始化了，不用老是调用执行过程*/
	if (NULL != RelayData.pRelayPointStr)
	{
		rtnValue = 1u;
		return rtnValue;
	}
	else
	{
		rtnValue = 1u;
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_SIGNAL;
			rowLen = LEN_RELAY_SIGNAL;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_SWITCH_RELAY_ID;
			rowLen = LEN_OC_SWITCH_RELAY;
		}
	}
	
	/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName, excelId, sheetId,&pDataAddr,&DataSize);
	   if( 0u == funcRtn)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
			return rtnValue;
	   } 
	   else
	   {
	   }	
		/*求得个数*/
	   if( 0u != DataSize%rowLen)
	   {   
		   rtnValue = 0u;
		   debug_infor_printf((const)"\nCI_RELAY_DATA,SWITCH_RELAY len %d not equal to fs", rowLen);
		   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,((UINT32)CI_DATA_TYPE<<8u)+RELAY_POINT,PRINT_ONCE);
			return rtnValue;
	   }	
	   else
	   {
	   }			
	   RelayDataLen.RelayPointStrLen = (UINT16)(DataSize/ rowLen);

		if(DataSize<rowLen)
	   {
		   RelayData.pRelayPointStr = (Relay_PointStruct *) MyNew ((UINT32)sizeof(Relay_PointStruct) );
		   rtnValue = 1u;
		   return rtnValue;
	   }
	   else
	   {
		   /*继续执行*/
	   }

		/*动态申请空间*/
		RelayData.pRelayPointStr = (Relay_PointStruct *) MyNew ((UINT32)(sizeof(Relay_PointStruct) * (RelayDataLen.RelayPointStrLen)));
		/*动态申请空间失败*/
		if(NULL == RelayData.pRelayPointStr)
		{
            RelayDataLen.RelayPointStrLen = 0u;
			rtnValue = 0u;
			return rtnValue;
		}
		else
		{
			/*内存先设为无效*/
			(void)memset(RelayData.pRelayPointStr, 0x00,sizeof(Relay_PointStruct) * RelayDataLen.RelayPointStrLen);
		}
		
		/*解析数据到 默认行车序列 结构体数组 */  
		for(j=0u;j<RelayDataLen.RelayPointStrLen;j++)
		{
			 pPointRelayStr = RelayData.pRelayPointStr + j;
			
			/*填充数据结构体*/
			 (void)R_PointStructFromChar(pDataAddr,pPointRelayStr);
			pDataAddr += rowLen;

		}

	rtnValue = 1u;
	return rtnValue;
}


/*********************************************
*函数功能：填充物理区段继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_PhysicalSgmtStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0u;
	Relay_PhysicalSegmentStruct* pPhysicalSegmentStr = NULL;   /*临时物理区段继电器变量*/
	UINT8* pDataAddr = NULL;         /*数据地址*/
	UINT32 DataSize = 0u;          /*数据大小（字节数）*/
	UINT16 j = 0u;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT16 realRowCount = 0u; /*实际表数据的行数*/
	UINT16 realRowLen = 0u; /*实际表数据的一行的长度*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayPhysicalSgmtStr != NULL)
	{
		rtnValue = 1u;
	}
	else
	{
		rtnValue = 1u;
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_PHYSICAL_SGMT;
			rowLen = LEN_RELAY_PHYSICAL_SGMT;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_PHYSICAL_SGMT;
			rowLen = OC_LEN_RELAY_PHYSICAL_SGMT;
		}
		/*读取 默认行车序列  数据*/
		funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId,&pDataAddr,&DataSize,&realRowCount);
		if(funcRtn == 0u)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		} 	
		else
		{
			if((0u != DataSize) && (0u != realRowCount))
			{
				if(0u != (DataSize% realRowCount))
				{
					debug_infor_printf((const)"\nCI_RELAY_DATA,PHY_RELAY len %d %d not equal to fs", DataSize,realRowCount);
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId <<8)+ sheetId,PRINT_ONCE);
					rtnValue = 0u;
				}
				else
				{
					/*数据实际一行的数据字节长度*/
					realRowLen = (UINT16)(DataSize / realRowCount);
					RelayDataLen.RelayPhysicalSgmtStrLen = realRowCount;	
					/*动态申请空间*/
					RelayData.pRelayPhysicalSgmtStr = (Relay_PhysicalSegmentStruct *) MyNew ((UINT32)(sizeof(Relay_PhysicalSegmentStruct) * RelayDataLen.RelayPhysicalSgmtStrLen));
					/*动态申请空间失败*/
					if(NULL == RelayData.pRelayPhysicalSgmtStr)
					{
						RelayDataLen.RelayPhysicalSgmtStrLen = 0u;
						rtnValue = 0u;
					}
					else
					{
						/*内存先设为无效*/
						(void)memset(RelayData.pRelayPhysicalSgmtStr, 0x00,sizeof(Relay_PhysicalSegmentStruct) * RelayDataLen.RelayPhysicalSgmtStrLen);
						/*解析数据到 默认行车序列 结构体数组 */  
						for(j=0;j<RelayDataLen.RelayPhysicalSgmtStrLen;j++)
						{
							pPhysicalSegmentStr = RelayData.pRelayPhysicalSgmtStr + j;

							/*填充数据结构体*/
							rtnValue &= R_PhysicalSegmentStructFromChar(pDataAddr,pPhysicalSegmentStr,realRowLen);
							pDataAddr += realRowLen;

						}
					}
				}
			}
			else
			{
				/*不做处理*/
			}
		}
	}
	return rtnValue;
}

/*********************************************
*函数功能：填充非进路调车继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_NoRouteDcStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_NoRouteDcStruct* pNoRouteStr;   /*临时变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayNoRouteDcStr != NULL)
	{
		rtnValue = 1u;
		return rtnValue;
	}

	localCiPattern = GetLocalCiPattern();
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		excelId = CI_DATA_TYPE;
		sheetId = RELAY_NO_ROUTE_ID;
		rowLen = LEN_RELAY_NO_ROUTE;
	}
	else
	{
		excelId = OC_DATA_TYPE;
		sheetId = OC_RELAY_NO_ROUTE_ID;
		rowLen = OC_LEN_RELAY_NO_ROUTE;
	}
	/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName, excelId, sheetId,&pDataAddr,&DataSize);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
			return rtnValue;
	   } 	
		/*求得个数*/
	   if(DataSize% rowLen != 0u)
	   {   
		   debug_infor_printf((const)"\nCI_RELAY_DATA,NO_ROUTE_RELAY len %d not equal to fs", rowLen);
		   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId <<8)+ sheetId,PRINT_ONCE);
		   rtnValue = 0u;
			return rtnValue;
	   }				
	   RelayDataLen.RelayNoRouteDcStrLen = (UINT16)(DataSize/ rowLen);

		if(DataSize< rowLen)
	   {
		   RelayData.pRelayNoRouteDcStr = (Relay_NoRouteDcStruct *) MyNew ((UINT32)(sizeof(Relay_NoRouteDcStruct)));
		   rtnValue = 1u;
		   return rtnValue;
	   }
	   else
	   {
		   /*继续执行*/
	   }


		/*动态申请空间*/
		RelayData.pRelayNoRouteDcStr = (Relay_NoRouteDcStruct *) MyNew ((UINT32)(sizeof(Relay_NoRouteDcStruct) * RelayDataLen.RelayNoRouteDcStrLen));
		/*动态申请空间失败*/
		if(NULL == RelayData.pRelayNoRouteDcStr)
		{
            RelayDataLen.RelayNoRouteDcStrLen = 0u;
			rtnValue = 0u;
			return rtnValue;
		}
		else
		{
			/*内存先设为无效*/
			(void)memset(RelayData.pRelayNoRouteDcStr, 0x00,sizeof(Relay_NoRouteDcStruct) * RelayDataLen.RelayNoRouteDcStrLen);
		}
		
		/*解析数据到 默认行车序列 结构体数组 */  
		for(j=0u;j<RelayDataLen.RelayNoRouteDcStrLen;j++)
		{
			pNoRouteStr = RelayData.pRelayNoRouteDcStr + j;
			
			/*填充数据结构体*/
			 (void)R_NoRouteDcStruFromChar(pDataAddr,pNoRouteStr);
			pDataAddr += rowLen;

		}

	rtnValue = 1u;
	return rtnValue;
}


/*********************************************
*函数功能：填充照查继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_ZhaoChaStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0u;
	Relay_ZhaoChaStruct* pZcStr = NULL;   /*临时变量*/
	UINT8* pDataAddr = NULL;         /*数据地址*/
	UINT32 DataSize = 0u;          /*数据大小（字节数）*/
	UINT16 j = 0u;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT16 realRowCount = 0u; /*实际表数据的行数*/
	UINT16 realRowLen = 0u; /*实际表数据的一行的长度*/

	/*已经初始化了，不用老是调用执行过程*/
	if(NULL != RelayData.pRelayZhaoChaStr)
	{
		rtnValue = 1u;
	}
	else
	{
		/*先设返回成功*/
		rtnValue = 1u;
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_ZHAO_CHA_ID;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_ZHAO_CHA_ID;
		}
		/*读取 默认行车序列  数据*/
		funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId,&pDataAddr,&DataSize,&realRowCount);
		if(0u == funcRtn)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		}
		else
		{		
			if((0u != DataSize) && (0u != realRowCount))
			{
				if(0u != (DataSize% realRowCount))
				{   
					debug_infor_printf((const)"\nCI_RELAY_DATA,ZHAOCHA_RELAY len %d %d not equal to fs", DataSize,realRowCount);
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId <<8)+ sheetId,PRINT_ONCE);
					rtnValue = 0u;
				}	
				else
				{					
					/*数据实际一行的数据字节长度*/
					realRowLen = (UINT16)(DataSize / realRowCount);
					RelayDataLen.RelayZhaoChaStrLen = realRowCount;					
					/*动态申请空间*/
					RelayData.pRelayZhaoChaStr = (Relay_ZhaoChaStruct *) MyNew ((UINT32)(sizeof(Relay_ZhaoChaStruct) * RelayDataLen.RelayZhaoChaStrLen));
					/*动态申请空间失败*/
					if(NULL == RelayData.pRelayZhaoChaStr)
					{
						RelayDataLen.RelayZhaoChaStrLen = 0u;
						rtnValue = 0u;
					}
					else
					{
						/*内存先设为无效*/
						(void)memset(RelayData.pRelayZhaoChaStr, 0x00,sizeof(Relay_ZhaoChaStruct) * RelayDataLen.RelayZhaoChaStrLen);

						/*解析数据到 默认行车序列 结构体数组 */  
						for(j=0u;j<RelayDataLen.RelayZhaoChaStrLen;j++)
						{
							pZcStr = RelayData.pRelayZhaoChaStr + j;

							/*填充数据结构体*/
							rtnValue &= R_ZhaoChaStruFromChar(pDataAddr,pZcStr,realRowLen);
							pDataAddr += realRowLen;
						}
					}
				}
					
			}
			else
			{
				debug_infor_printf((const)"\nZHAOCHA_RELAY_DATA_ERR  DataSize %d  realRowCount %d\n ",DataSize,realRowCount);
			}
			
		}
	}
	return rtnValue;
}


/*********************************************
*函数功能：填充报警灯结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_BaoJingDengStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0U;
	Relay_BaoJingDengStruct* pBjdStr = NULL;   /*临时变量*/
	UINT8* pDataAddr = NULL;         /*数据地址*/
	UINT32 DataSize = 0U;          /*数据大小（字节数）*/
	UINT16 j =0U;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT16 wRowCount = 0U;
	/*已经初始化了，不用老是调用执行过程*/
	if(NULL != RelayData.pRelayBjdStr)
	{
		rtnValue = 1u;
		return rtnValue;
	}
	else
	{
	}
	localCiPattern = GetLocalCiPattern();
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		excelId = CI_DATA_TYPE;
		sheetId = RELAY_BJD_ID;
	}
	else
	{
		excelId = OC_DATA_TYPE;
		sheetId = OC_RELAY_BJD_ID;
	}
	/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId,&pDataAddr,&DataSize,&wRowCount);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
			return rtnValue;
	   } 
	   else
	   {
	   }	
		/*求得个数*/
	   if(0u != DataSize%wRowCount)
	   {   
		   rtnValue = 0u;
		   debug_infor_printf((const)"\nCI_RELAY_DATA,INDICATOR_RELAY len %d not equal to fs",rowLen);
		   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,((UINT32)CI_DATA_TYPE<<8u)+RELAY_BJD_ID,PRINT_ONCE);
			return rtnValue;
	   }
	   else
	   {
	   }
	   rowLen = DataSize / wRowCount;
	   RelayDataLen.RelayBjdStrLen = wRowCount;

		if(DataSize<rowLen)
	   {
		   RelayData.pRelayBjdStr = (Relay_BaoJingDengStruct *) MyNew ((UINT32)(sizeof(Relay_BaoJingDengStruct)));
		   rtnValue = 1u;
		   return rtnValue;
	   }
	   else
	   {
		   /*继续执行*/
	   }


		/*动态申请空间*/
		RelayData.pRelayBjdStr = (Relay_BaoJingDengStruct *) MyNew ((UINT32)(sizeof(Relay_BaoJingDengStruct) * RelayDataLen.RelayBjdStrLen));
		/*动态申请空间失败*/
		if(NULL == RelayData.pRelayBjdStr)
		{
            RelayDataLen.RelayBjdStrLen = 0u;
			rtnValue = 0u;
			return rtnValue;
		}
		else
		{
			/*内存先设为无效*/
			(void)memset(RelayData.pRelayBjdStr, 0x00,sizeof(Relay_BaoJingDengStruct) * RelayDataLen.RelayBjdStrLen);
		}
		
		/*解析数据到 默认行车序列 结构体数组 */  
		for(j=0u;j<RelayDataLen.RelayBjdStrLen;j++)
		{
			pBjdStr = RelayData.pRelayBjdStr + j;
			
			/*填充数据结构体*/
			 (void)R_BaoJingDengStruFromChar(pDataAddr,pBjdStr, rowLen);
			pDataAddr += rowLen;

		}

	rtnValue = 1u;
	return rtnValue;
}


/*********************************************
*函数功能：填充无人折返结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_NoReturnStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_NoReturnStruct* pNoRtnStr;   /*临时变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayNoRtnStru != NULL)
	{
		rtnValue = 1u;
		return rtnValue;
	}
	localCiPattern = GetLocalCiPattern();
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		excelId = CI_DATA_TYPE;
		sheetId = RELAY_NO_RETURN_ID;
		rowLen = LEN_RELAY_NO_RETURN;
	}
	else
	{
		excelId = OC_DATA_TYPE;
		sheetId = OC_RELAY_NO_RETURN_ID;
		rowLen = OC_LEN_RELAY_NO_RETURN;
	}
	/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName,excelId, sheetId,&pDataAddr,&DataSize);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
			return rtnValue;
	   } 	
		/*求得个数*/
	   if(DataSize% rowLen != 0u)
	   {   
			rtnValue = 0u;
			debug_infor_printf((const)"\nCI_RELAY_DATA,NO_RETURN_RELAY len %d not equal to fs", rowLen);
			DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId<<8)+ sheetId,PRINT_ONCE);
			return rtnValue;
	   }				
	   RelayDataLen.RelayNoRtnStruLen = (UINT16)(DataSize/ rowLen);

		if(DataSize< rowLen)
	   {
		   RelayData.pRelayNoRtnStru = (Relay_NoReturnStruct *) MyNew ((UINT32)(sizeof(Relay_NoReturnStruct)));
		   rtnValue = 1u;
		   return rtnValue;
	   }
	   else
	   {
		   /*继续执行*/
	   }


		/*动态申请空间*/
		RelayData.pRelayNoRtnStru = (Relay_NoReturnStruct *) MyNew ((UINT32)(sizeof(Relay_NoReturnStruct) * RelayDataLen.RelayNoRtnStruLen));
		/*动态申请空间失败*/
		if(NULL == RelayData.pRelayNoRtnStru)
		{
            RelayDataLen.RelayNoRtnStruLen = 0u;
			rtnValue = 0u;
			return rtnValue;
		}
		else
		{
			/*内存先设为无效*/
			(void)memset(RelayData.pRelayNoRtnStru, 0x00,sizeof(Relay_NoReturnStruct) * RelayDataLen.RelayNoRtnStruLen);
		}
		
		/*解析数据到 默认行车序列 结构体数组 */  
		rtnValue = 1u;
		for(j=0u;j<RelayDataLen.RelayNoRtnStruLen;j++)
		{
			pNoRtnStr = RelayData.pRelayNoRtnStru + j;
			
			/*填充数据结构体*/
			rtnValue &= R_NoReturnStruFromChar(pDataAddr,pNoRtnStr);
			pDataAddr += rowLen;

		}

	return rtnValue;
}


/*********************************************
*函数功能：填充车库门继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_GaragedoorStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_GaragedoorStruct* pGaragedoorStr;   /*临时信号机继电器变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayGaragedoorStr != NULL)
	{
		rtnValue = 1u;
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_GARAGE_DOOR_ID;
			rowLen = LEN_GARAGE_DOOR;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_GARAGE_DOOR_ID;
			rowLen = OC_LEN_GARAGE_DOOR;
		}
	   /*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName, excelId, sheetId,&pDataAddr,&DataSize);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
	   } 
	   else
	   {
			/*求得个数*/
		   if(DataSize% rowLen != 0u)
		   {   
			   debug_infor_printf((const)"\nCI_RELAY_DATA,GARAGE_DOOR_RELAY len %d not equal to fs", rowLen);
			   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId <<8)+ sheetId,PRINT_ONCE);
			   rtnValue = 0u;
		   }
		   else
		   {
			   RelayDataLen.RelayGaragedoorStrLen = (UINT16)(DataSize/ rowLen);

				if(DataSize < rowLen)
			   {
				   RelayData.pRelayGaragedoorStr = (Relay_GaragedoorStruct *) MyNew ((UINT32)(sizeof(Relay_GaragedoorStruct)) );
				   rtnValue = 1u;
			   }
			   else
			   {				
				   /*动态申请空间*/
					RelayData.pRelayGaragedoorStr = (Relay_GaragedoorStruct *) MyNew ((UINT32)((sizeof(Relay_GaragedoorStruct)) * (RelayDataLen.RelayGaragedoorStrLen)));
					/*动态申请空间失败*/
					if(NULL == RelayData.pRelayGaragedoorStr)
					{
						RelayDataLen.RelayGaragedoorStrLen = 0u;
						rtnValue = 0u;
					}
					else
					{
						/*内存先设为无效*/
						(void)memset(RelayData.pRelayGaragedoorStr, 0x00,sizeof(Relay_GaragedoorStruct) * RelayDataLen.RelayGaragedoorStrLen);
				    	/*解析数据到 默认行车序列 结构体数组 */  
						rtnValue = 1u;
						for(j=0u;j<RelayDataLen.RelayGaragedoorStrLen;j++)
						{
							pGaragedoorStr = RelayData.pRelayGaragedoorStr + j;
							
							/*填充数据结构体*/
							rtnValue &= R_GaragedoorStructFromChar(pDataAddr,pGaragedoorStr);
							pDataAddr += rowLen;

						}
					}
			   }
		   }
		}
	}

	return rtnValue;
}


/*********************************************
*函数功能：初始化SPKS继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelaySpksStru(CHAR* CIDataName)
{
	UINT8 tmpRtn = 0u;
	RelaySpksStruct* pRelaySpksStr;   /*临时变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 dataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 1u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*读到的行数*/
	UINT16 realRowLen = 0U;/*实际表一行的长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelaySpksStr != NULL)
	{
		rtnValue = 1u;		
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_SPKS_ID;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_SPKS_ID;
		}
		/*读取 默认行车序列  数据*/
		tmpRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId,&pDataAddr,&dataSize, &rowLen);
		if(tmpRtn == 0u)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		} 
		else
		{
			/*求得个数*/
			if ((0U != dataSize) && (0U != rowLen))
			{
				if (0U != dataSize % rowLen)
				{
					debug_infor_printf((const)"\nCI_RELAY_DATA,SPKS_RELAY len %d not equal to fs", rowLen);
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, (excelId << 8) + sheetId, PRINT_ONCE);
					rtnValue = 0u;
				}
				else
				{
					realRowLen = (UINT16)(dataSize / rowLen);
					RelayDataLen.RelaySpksStrLen = (UINT16)rowLen;

					if (dataSize < realRowLen)
					{
						rtnValue = 0U;
					}
					else
					{
						/* 动态申请空间 */
						RelayData.pRelaySpksStr = (RelaySpksStruct*)MyNew((UINT32)(sizeof(RelaySpksStruct) * RelayDataLen.RelaySpksStrLen));
						/* 动态申请空间失败 */
						if (NULL == RelayData.pRelaySpksStr)
						{
							RelayDataLen.RelaySpksStrLen = 0u;
							rtnValue = 0u;
						}
						else
						{
							/* 清零 */
							(void)memset(RelayData.pRelaySpksStr, 0x00, sizeof(RelaySpksStruct) * RelayDataLen.RelaySpksStrLen);
							/*解析数据到 默认行车序列 结构体数组 */
							rtnValue = 1u;
							for (j = 0u; j < RelayDataLen.RelaySpksStrLen; j++)
							{
								pRelaySpksStr = RelayData.pRelaySpksStr + j;

								/*填充数据结构体*/
								rtnValue &= R_SpksDataFromChar(pDataAddr, pRelaySpksStr, realRowLen);
								pDataAddr += realRowLen;

							}
						}
					}
				}
			}
			else
			{
				rtnValue = 1u;
			}
		}
	}
	return rtnValue;
}

/*********************************************
*函数功能：初始化门禁解锁继电器结构体数组
*参数说明：CIDataName件指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_MJStru(CHAR* CIDataName)
{
	UINT8 tmpRtn = 0u;
	Relay_MJStruct* pRelayMJStr;   /*临时变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 dataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 1u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*读到的行数*/
	UINT16 realRowLen = 0U;/*实际表一行的长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if (RelayData.pMjStr != NULL)
	{
		rtnValue = 1u;
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_MJ_ID;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_MJ_ID;
		}
		/*读取 默认行车序列  数据*/
		tmpRtn = dquGetConfigDataNew(CIDataName, excelId, sheetId, &pDataAddr, &dataSize, &rowLen);
		if (tmpRtn == 0u)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		}
		else
		{
			/*求得个数*/
			if ((0U != dataSize) && (0U != rowLen))
			{
				if (0U != dataSize % rowLen)
				{
					debug_infor_printf((const)"\nCI_RELAY_DATA,MJ_RELAY len %d not equal to fs", rowLen);
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, (excelId << 8) + sheetId, PRINT_ONCE);
					rtnValue = 0u;
				}
				else
				{
					realRowLen = (UINT16)(dataSize / rowLen);
					RelayDataLen.RelayMJStrLen = (UINT16)rowLen;

					if ((dataSize < realRowLen)||(MJ_MAX_SPKSNUM < (realRowLen - 6U) / 2U) || (6U == realRowLen))
					{
						rtnValue = 0U;
						debug_infor_printf((const)"\nCI_RELAY_DATA,MJ_RELAY relaySPKS，MjRelSpksNum Is [0] Or exceeded the maximum number of [%d]\n", MJ_MAX_SPKSNUM);
					}
					else
					{
						/* 动态申请空间 */
						RelayData.pMjStr = (Relay_MJStruct*)MyNew((UINT32)(sizeof(Relay_MJStruct) * RelayDataLen.RelayMJStrLen));
						/* 动态申请空间失败 */
						if (NULL == RelayData.pMjStr)
						{
							RelayDataLen.RelayMJStrLen = 0u;
							rtnValue = 0u;
						}
						else
						{
							/* 清零 */
							(void)memset(RelayData.pMjStr, 0x00, sizeof(Relay_MJStruct) * RelayDataLen.RelayMJStrLen);
							/*解析数据到 默认行车序列 结构体数组 */

							rtnValue = 1U;
							for (j = 0u; j < RelayDataLen.RelayMJStrLen; j++)
							{
								pRelayMJStr = RelayData.pMjStr + j;

								/*填充数据结构体*/
								tmpRtn = R_MJDataFromChar(pDataAddr, pRelayMJStr, realRowLen);
								pDataAddr += realRowLen;

								if (1U != tmpRtn)
								{
									rtnValue = 0U;  /*填充数据结构体失败，停止遍历，返回0*/
									break;
								}
							}							
						}
					}
				}
			}
			else
			{
				rtnValue = 1u;
			}
		}
	}
	return rtnValue;
}

/*********************************************
*函数功能：填充防淹门继电器结构体数组
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_FloodGateStru(CHAR* CIDataName)
{
	UINT8 funcRtn;
	Relay_FloodGateStruct* pFloodGateStr;   /*临时防淹门继电器变量*/
	UINT8* pDataAddr;         /*数据地址*/
	UINT32 DataSize;          /*数据大小（字节数）*/
	UINT16 j;
	UINT8 rtnValue = 0u;
	UINT32 excelId = 0u; /*excel id*/
	UINT32 sheetId = 0u; /*sheet id*/
	UINT32 rowLen = 0u; /*行长度*/
	UINT8 localCiPattern = 0u; /*本CI模式*/

	/*已经初始化了，不用老是调用执行过程*/
	if(RelayData.pRelayFloodGateStr != NULL)
	{
		rtnValue = 1u;
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			excelId = CI_DATA_TYPE;
			sheetId = RELAY_FLOOD_GATE_ID;
			rowLen = LEN_FLOOD_GATE;
		}
		else
		{
			excelId = OC_DATA_TYPE;
			sheetId = OC_RELAY_FLOOD_GATE_ID;
			rowLen = OC_LEN_FLOOD_GATE;
		}
		/*读取 默认行车序列  数据*/
	   funcRtn = dquGetConfigData(CIDataName, excelId, sheetId,&pDataAddr,&DataSize);
	   if(funcRtn == 0u)
	   {
		   /*函数调用失败*/
		   rtnValue = 0u;
	   } 
	   else
	   {
			/*求得个数*/
		   if(DataSize% rowLen != 0u)
		   {   
			   debug_infor_printf((const)"\nCI_RELAY_DATA,FLOOD_GATE_RELAY len %d not equal to fs", rowLen);
			   DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software,CI_DEVICE_TYPE_FS_TABLE,(excelId <<8)+ sheetId,PRINT_ONCE);
			   rtnValue = 0u;
		   }
		   else
		   {
			   RelayDataLen.RelayFloodGateStrLen = (UINT16)(DataSize/ rowLen);

				if(DataSize< rowLen)
			   {
				   RelayData.pRelayFloodGateStr = (Relay_FloodGateStruct *) MyNew ((UINT32)sizeof(Relay_FloodGateStruct) );
				   rtnValue = 1u;
			   }
			   else
			   {
					   /*动态申请空间*/
					RelayData.pRelayFloodGateStr = (Relay_FloodGateStruct *) MyNew ((UINT32)((sizeof(Relay_FloodGateStruct)) * (RelayDataLen.RelayFloodGateStrLen)));
					/*动态申请空间失败*/
					if(NULL == RelayData.pRelayFloodGateStr)
					{
						RelayDataLen.RelayFloodGateStrLen = 0u;
						rtnValue = 0u;
					}
					else
					{
						/*内存先设为无效*/
						(void)memset(RelayData.pRelayFloodGateStr, 0x00,sizeof(Relay_FloodGateStruct) * RelayDataLen.RelayFloodGateStrLen);
						/*解析数据到 默认行车序列 结构体数组 */ 
						rtnValue = 1u;
						for(j=0u;j<RelayDataLen.RelayFloodGateStrLen;j++)
						{
							pFloodGateStr = RelayData.pRelayFloodGateStr + j;
							
							/*填充数据结构体*/
							rtnValue &= R_FloodGateStructFromChar(pDataAddr,pFloodGateStr);
							pDataAddr += rowLen;

						}
					}					
			   }
		   }
	   }

	}

	return rtnValue;
}


/*********************************************
*函数功能：填充调车同意继电器结构体数组---内部用
*参数说明：CIDataName件指针          
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_DCAgreeStru(CHAR* CIDataName)
{
	UINT8 funcRtn = 0U;
	Relay_DCAgreeStruct* pDCAgreeStr = NULL;   /*调车同意继电器变量*/
	UINT8* pDataAddr = NULL;                                  /*数据地址*/
	UINT32 DataSize = 0U;                                   /*数据大小（字节数）*/
	UINT16 j = 0U;
	UINT8 rtnValue = 0U;
	UINT8 localCiPattern = 0U;
	UINT32 dwExcelId = 0u; /*excel id*/
	UINT32 dwSheetId = 0u; /*sheet id*/
	UINT32 dwRowLen = 0u; /*行长度*/
	UINT16 wRealRowCount = 0U; /*行数*/

	localCiPattern = GetLocalCiPattern();
	
	/*已经初始化了，不用老是调用执行过程*/
	if(NULL != RelayData.pRelayDCAgreeStr)
	{
		rtnValue = 1U;
	}
	else
	{
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			dwExcelId = CI_DATA_TYPE;
			dwSheetId = RELAY_DCAGREE_ID;
		}
		else
		{
			dwExcelId = OC_DATA_TYPE;
			dwSheetId = OC_RELAY_DCAGREE_ID;
		}

		/*读取进路调车同意继电器数据表*/
		funcRtn = dquGetConfigDataNew(CIDataName, dwExcelId, dwSheetId,&pDataAddr,&DataSize, &wRealRowCount);
		if(0U == funcRtn)
		{
			/*没有表初始化成功*/
			rtnValue = 1U;
			debug_infor_printf((const)"\nOC_DCAgree_RELAY_ID NO IN FS\n");
		}
		else
		{
			rtnValue = 1U;

			if ((0U != DataSize) && (0U != wRealRowCount))
			{
				if (0U != (DataSize % wRealRowCount))
				{
					/*求得个数不为整数，数据错误*/
					debug_infor_printf((const)"\nCI_RELAY_DATA,RELAY_DCAGREE len %d not equal to fs", (DataSize % wRealRowCount));
					DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, ((UINT32)(dwExcelId << 8U)) + dwSheetId, PRINT_ONCE);
					rtnValue = 0U;
				}
				else
				{
					RelayDataLen.RelayDCAgreeStrLen = wRealRowCount;/*计算结构体个数*/
					dwRowLen = DataSize / wRealRowCount;

					/*动态申请空间*/
					RelayData.pRelayDCAgreeStr = (Relay_DCAgreeStruct*)MyNew((UINT32)(sizeof(Relay_DCAgreeStruct) * RelayDataLen.RelayDCAgreeStrLen));

					if (NULL == RelayData.pRelayDCAgreeStr)
					{/*动态申请空间失败*/
						RelayDataLen.RelayDCAgreeStrLen = 0U;
						rtnValue = 0U;
					}
					else
					{
						/*内存先设为无效*/
						(void)memset(RelayData.pRelayDCAgreeStr, 0x00, sizeof(Relay_DCAgreeStruct) * RelayDataLen.RelayDCAgreeStrLen);
						/*解析数据到 默认行车序列 结构体数组 */

						for (j = 0u; j < RelayDataLen.RelayDCAgreeStrLen; j++)
						{
							if (1U == rtnValue)
							{
								pDCAgreeStr = RelayData.pRelayDCAgreeStr + j;

								/*填充数据结构体*/
								rtnValue &= R_DCAgreeStructFromChar(pDataAddr, pDCAgreeStr);
								pDataAddr += dwRowLen;
							}
							else
							{
								break;
							}
						}
					}
				}
			}
			else
			{
				;
			}
		}
	}
	return rtnValue;

}

/*********************************************
*函数功能：填充倒切设备继电器结构体数组---内部用
*参数说明：CIDataName件指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 InitRelay_ReverseCutStru(CHAR* CIDataName) 
{
	UINT8 funcRtn = 0u;
	Relay_ReverseCutStruct* pReverseCutStr = NULL;   /*倒切设备继电器变量*/
	UINT8* pDataAddr =NULL;                                  /*数据地址*/
	UINT32 DataSize=0U;                                   /*数据大小（字节数）*/
	UINT16 j=0U;
	UINT8 rtnValue = 0u;
	UINT8 localCiPattern = 0U;
	localCiPattern = GetLocalCiPattern();

	/*已经初始化了，不用老是调用执行过程 全电子不用初始化这张表*/
	if (NULL != RelayData.pRelayReverseCutStr )
	{
		rtnValue = 1u;
	}
	else
	{
		/*读取倒切设备继电器数据表*/
		funcRtn = dquGetConfigData(CIDataName, OC_DATA_TYPE, OC_RELAY_REVERSE_CUT_ID, &pDataAddr, &DataSize);
		if (0u == funcRtn)
		{
			/*函数调用失败*/
			rtnValue = 0u;
		}
		else
		{

			if ((0u != DataSize%OC_LEN_REVERSE_CUT))
			{ /*求得个数不为整数，数据错误*/
				debug_infor_printf((const)"\nCI_RELAY_DATA,REVERSE_CUT len %d not equal to fs", OC_LEN_REVERSE_CUT);
				DebugPrintAppError(ERROR_fs_columns_len_not_equal_to_ci_software, CI_DEVICE_TYPE_FS_TABLE, ((UINT32)OC_DATA_TYPE << 8u) + OC_RELAY_REVERSE_CUT_ID, PRINT_ONCE);
				rtnValue = 0u;
			}
			else
			{
				RelayDataLen.RelayReverseCutStrLen = (UINT16)(DataSize / OC_LEN_REVERSE_CUT);/*计算结构体个数*/

				if (OC_LEN_REVERSE_CUT > DataSize)
				{/*不足一个*/
					RelayData.pRelayReverseCutStr = (Relay_ReverseCutStruct *)MyNew((UINT32)sizeof(Relay_ReverseCutStruct));
					rtnValue = 1u;
				}
				else
				{

					/*动态申请空间*/
					RelayData.pRelayReverseCutStr = (Relay_ReverseCutStruct *)MyNew((UINT32)(sizeof(Relay_ReverseCutStruct) * RelayDataLen.RelayReverseCutStrLen));

					if (NULL == RelayData.pRelayReverseCutStr)
					{/*动态申请空间失败*/
						RelayDataLen.RelayReverseCutStrLen = 0u;
						rtnValue = 0u;
					}
					else
					{
						/*内存先设为无效*/
						(void)CommonMemSet(RelayData.pRelayReverseCutStr, (UINT32)(sizeof(Relay_ReverseCutStruct) * RelayDataLen.RelayReverseCutStrLen),
							0x00, (UINT32)(sizeof(Relay_ReverseCutStruct) * RelayDataLen.RelayReverseCutStrLen));
						/*解析数据到 默认行车序列 结构体数组 */
						rtnValue = 1u;
						for (j = 0u; j < RelayDataLen.RelayReverseCutStrLen; j++)
						{
							pReverseCutStr = RelayData.pRelayReverseCutStr + j;

							/*填充数据结构体*/
							rtnValue &= R_ReverseCutStrFromChar(pDataAddr, pReverseCutStr);
							pDataAddr += OC_LEN_REVERSE_CUT;

						}
					}
				}
			}
		}
	}
	return rtnValue;
}

