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

/*********************************************
*函数功能：初始化继电器接口数据结构体
*参数说明：pDataAddr数据地址，  pRelayCfgDtStr继电器配置数据结构体指针，Name继电器名称
*返回值：0，失败；1，成功
*********************************************/
UINT8 RelayConfigDataStruFromChar(UINT8 * pDataAddr,RelayConfigDataStruct* pRelayCfgDtStr,CHAR* Name)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT16 i=0u;
	UINT16 OcIdBuff = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/

    if ((NULL == pDataAddr) || (NULL == pRelayCfgDtStr) || (NULL == Name))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }

	localCiPattern = GetLocalCiPattern();
	/*继电器ID (配置字段)*/
	pRelayCfgDtStr->RelayId = dquCiShortFromChar(pData);
	pData += 2u;

	for(i=0u;i<JDQ_NAME_LEN;i++)
	{
		Name[i] = (CHAR)*pData;
		pData++;
	}
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		/*所属联锁ID (配置字段)*/
		pRelayCfgDtStr->BelongCiId = (UINT8)(dquCiShortFromChar(pData));
		pRelayCfgDtStr->BelongOcId = 0u;
	}
	else
	{
		/*所属OC ID (配置字段)*/
		OcIdBuff = dquCiShortFromChar(pData);
		pRelayCfgDtStr->BelongCiId = (UINT8)(GetCiIdByOcId(OcIdBuff));
		pRelayCfgDtStr->BelongOcId = OcIdBuff;
		pRelayCfgDtStr->BelongDrvOcId = pRelayCfgDtStr->BelongOcId;
		pRelayCfgDtStr->BelongVirCIid = GetOCBelongVirCIid((UINT8)OcIdBuff);
	}
	pData += 2u;

    /*采集模式(前节点/后节点/双节点) (配置字段)*/
	pRelayCfgDtStr->CollMode = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系前节点采集地址 (配置字段)*/
	pRelayCfgDtStr->ForeNodeCollAddrA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系前节点采集位置 (配置字段)*/
	pRelayCfgDtStr->ForeNodeCollPosA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系后节点采集地址 (配置字段)*/
	pRelayCfgDtStr->BackNodeCollAddrA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系后节点采集位置 (配置字段)*/
	pRelayCfgDtStr->BackNodeCollPosA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*B系前节点采集地址 (配置字段)*/
	pRelayCfgDtStr->ForeNodeCollAddrB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*B系前节点采集位置 (配置字段)*/
	pRelayCfgDtStr->ForeNodeCollPosB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
	/*B系后节点采集地址 (配置字段)*/
	pRelayCfgDtStr->BackNodeCollAddrB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*B系后节点采集位置 (配置字段)*/
	pRelayCfgDtStr->BackNodeCollPosB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系驱动地址 (配置字段)*/
	pRelayCfgDtStr->DrvAddrA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*A系驱动位置 (配置字段)*/
	pRelayCfgDtStr->DrvPosA = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*B系驱动地址 (配置字段)*/
	pRelayCfgDtStr->DrvAddrB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;
    /*B系驱动位置 (配置字段)*/
	pRelayCfgDtStr->DrvPosB = (UINT8)(dquCiShortFromChar(pData));
	pData += 2u;

	rtnvalue = 1u;
	return rtnvalue;
}



/*********************************************
*函数功能：初始化紧急停车按钮继电器结构体
*参数说明：pDataAddr数据地址，  pEmgcyStpStr紧急停车按钮继电器配置数据结构体指针    realRowLen 每行字节的长度
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_EmegencyStopStructFromChar(UINT8 * pDataAddr,Relay_EmgcyStpStruct* pEmgcyStpStr, UINT16 realRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/
 
    if ((NULL == pDataAddr) || (NULL == pEmgcyStpStr))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }

	localCiPattern = GetLocalCiPattern();
	pEmgcyStpStr->wEmgcyStopBtnId = dquCiShortFromChar(pData);          /*紧急停车按钮ID */
    pData += 2u;
	if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
	{
		pEmgcyStpStr->wOcId = dquCiShortFromChar(pData);				 /*OC ID*/
		pData += 2u;
	}
	pEmgcyStpStr->wEmgcyStopBtnRelayId = dquCiShortFromChar(pData);          /*紧急停车按钮继电器ID */
	pData += 2u;
	if (CI_PATTERN_TRADITIONAL == localCiPattern)
	{
		pEmgcyStpStr->wRepEmgcyStopBtnRelayId = dquCiShortFromChar(pData);          /*复示紧急停车按钮继电器ID */
		pData += 2u;
  	}
	else
	{
		pEmgcyStpStr->wEmgcyStopBtnRelayId2 = dquCiShortFromChar(pData);          /*紧急停车按钮继电器ID 2*/
		pData += 2u;
		pEmgcyStpStr->wEmgcyStopBtnIndicateRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wEmgcyStopCutRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wEmgcyStopCutIndicateRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wEmgcyStopBuzzRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wESSRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wESSSteadyIndicatRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		pEmgcyStpStr->wESSFlashIndicatRelayId = dquCiShortFromChar(pData);
		pData += 2u;
	}
	if (22U < realRowLen)
	{
		/*取消紧急停车按钮继电器ID*/
		pEmgcyStpStr->wCancelEsbRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		/*紧急停车按钮站台指示灯继电器ID*/
		pEmgcyStpStr->wEsbPlatformDisRelayId = dquCiShortFromChar(pData);
		pData += 2u;
		/*切除蜂鸣器报警继电器ID*/
		pEmgcyStpStr->wCutoffEsbBuzzRelayId = dquCiShortFromChar(pData);
		pData += 2u;
	}
	else
	{
		/*取消紧急停车按钮继电器ID*/
		pEmgcyStpStr->wCancelEsbRelayId = 0U;
		/*紧急停车按钮站台指示灯继电器ID*/
		pEmgcyStpStr->wEsbPlatformDisRelayId = 0U;
		/*切除蜂鸣器报警继电器ID*/
		pEmgcyStpStr->wCutoffEsbBuzzRelayId = 0U;
	}
    rtnvalue = 1u;
	return rtnvalue;
}
/*********************************************
*函数功能：从数据到屏蔽门继电器结构体
*参数说明：pDataAddr数据地址，  pScrnStr屏蔽门继电器配置数据结构体指针,UINT16 rowLen 一行数据的长度
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_ScreenStructFromChar(UINT8 * pDataAddr,Relay_ScreenStruct* pScrnStr, UINT16 rowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/
 
    if ((NULL == pDataAddr) || (NULL == pScrnStr))
    {
        rtnvalue = 0u;
    }
	else
	{
		localCiPattern = GetLocalCiPattern();
		pScrnStr->wScreenId = dquCiShortFromChar(pData);                          /*屏蔽门ID (配置字段)*/
		pData += 2u;
		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pScrnStr->wOcId = dquCiShortFromChar(pData);                          /*OC ID*/
			pData += 2u;
		}
		pScrnStr->wRelayRelatedId = dquCiShortFromChar(pData);                    /*互锁解除继电器ID */
		pData += 2u;

		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pScrnStr->wRelayRelatedId2 = dquCiShortFromChar(pData);                    /*互锁解除继电器ID2 */
			pData += 2;
		}
		pScrnStr->wRelayDoorClosedId = dquCiShortFromChar(pData);                 /*门关继电器ID */
		pData += 2u;

		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pScrnStr->wRelayDoorClosedId2 = dquCiShortFromChar(pData);                    /*门关继电器ID2 */
			pData += 2;
		}
		pScrnStr->wRelayCloseDoorId = dquCiShortFromChar(pData);                  /*关门继电器ID */
		pData += 2u;
		pScrnStr->wRelayFourEditGroupOpenDoorId = dquCiShortFromChar(pData);       /*4编组开门继电器ID */
		pData += 2u;
		pScrnStr->wRelaySixEditGroupOpenDoorId = dquCiShortFromChar(pData);        /*6编组开门继电器ID */
		pData += 2u;
		pScrnStr->wRelayEightEditGroupOpenDoorId = dquCiShortFromChar(pData);      /*8编组开门继电器ID */
		pData += 2u;
		pScrnStr->wRelayDoorButtonId = dquCiShortFromChar(pData);                 /*PSD按钮继电器*/
		pData += 2u;
		pScrnStr->doorReopenRelayId = dquCiShortFromChar(pData);                 /*站台门再次开门继电器ID*/
		pData += 2u;
		pScrnStr->departureConfirmRelayId = dquCiShortFromChar(pData);             /*发车确认继电器ID*/
		pData += 2u;
		pScrnStr->detectStartRelayId = dquCiShortFromChar(pData);					/*启动探测继电器ID*/
		pData += 2u;
		pScrnStr->detectStopRelayId = dquCiShortFromChar(pData);					/*停止探测继电器ID*/
		pData += 2u;
		pScrnStr->obstacleRelayId = dquCiShortFromChar(pData);						/*障碍物继电器ID*/
		pData += 2u;
		pScrnStr->gapDetMuLockRelayId = dquCiShortFromChar(pData);                 /*间隙探测互锁解除继电器ID*/
		pData += 2u;
		pScrnStr->closeStateRelayId = dquCiShortFromChar(pData);                   /*关门状态继电器ID*/
		pData += 2u;

		if (36U < rowLen)
		{
			pScrnStr->wClearPasseSteadyLightRelayId = dquCiShortFromChar(pData);       /*清客确认按钮指示灯稳灯继电器ID*/
			pData += 2u;
			pScrnStr->wClearPasseFlashLightRelayId = dquCiShortFromChar(pData);       /*清客确认按钮指示灯闪灯继电器ID*/
			pData += 2u;
			pScrnStr->wClearPassengerButtonRelayId = dquCiShortFromChar(pData);       /*清客确认按钮继电器ID*/
			pData += 2u;
		}

		if (42U < rowLen)
		{
			pScrnStr->wCleFarePCBButtonRelayId = dquCiShortFromChar(pData);       /*清客确认箱PCB按钮继电器*/
			pData += 2u;
			pScrnStr->wCleFarePDBFlaLigRelayId = dquCiShortFromChar(pData);       /*清客确认箱PDB按钮指示灯闪灯继电器*/
			pData += 2u;
		}

		if (46U < rowLen)
		{
			pScrnStr->wPobBsdRelayId = dquCiShortFromChar(pData);  /*站台再开门按钮指示灯继电器*/
			pData += 2u;
			pScrnStr->wPcbBsdRelayId = dquCiShortFromChar(pData);  /*站台再关门按钮指示灯继电器*/
			pData += 2u;
		}

		if (50U < rowLen)
		{
			pScrnStr->wVideoQkLight1RelayId = dquCiShortFromChar(pData);  /*清客按钮箱视频清客指示灯1（绿）继电器*/
			pData += 2U;
			pScrnStr->wVideoQkLight2RelayId = dquCiShortFromChar(pData);  /*清客按钮箱视频清客指示灯2（红）继电器*/
			pData += 2U;
		}

		if (54U < rowLen)
		{
			pScrnStr->chControlType = *pData;	/*屏蔽门控制类型*/
			pData += 1U;
		}
		else
		{/*若没有这一列配置*/
			pScrnStr->chControlType = PSD_CONTROL_TYPE_RCI;	/*由RCI控制*/
		}

		rtnvalue = 1u;
	}

	return rtnvalue;
}
/*********************************************
*函数功能：从数据到物理区段继电器结构体
*参数说明：pDataAddr数据地址，pPhysclSgmtStr  物理区段继电器配置数据结构体指针 
*          UINT16 realRowLen 一行数据实际字节数
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_PhysicalSegmentStructFromChar(UINT8 * pDataAddr,Relay_PhysicalSegmentStruct* pPhysclSgmtStr,UINT16 realRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT16 index = 0u;

	if ((NULL == pDataAddr) || (NULL == pPhysclSgmtStr))
	{
		rtnvalue = 0u;
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		pPhysclSgmtStr->wPhysicalId = dquCiShortFromChar(pData);          /*物理区段ID*/
		pData += 2u;
		index += 2u;
		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pPhysclSgmtStr->wOcId = dquCiShortFromChar(pData);                          /*OC ID*/
			pData += 2u;
			index += 2u;
		}
		pPhysclSgmtStr->wRelayRailwayId = dquCiShortFromChar(pData);        /*轨道继电器ID */
		pData += 2u;
		index += 2u;
	if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
	{
		pPhysclSgmtStr->wRelayRailwayId2 = dquCiShortFromChar(pData);    /*轨道继电器ID2 */
		pData += 2;
	}
		pPhysclSgmtStr->wRelayAxleRetrunId = dquCiShortFromChar(pData);          /*计轴复位继电器ID */
		pData += 2u;
		index += 2u;
		pPhysclSgmtStr->wRelayAxleZongRetrunId = dquCiShortFromChar(pData);          /*计轴总复位继电器ID */
		pData += 2u;
		index += 2u;
		pPhysclSgmtStr->wRelayAxlePreResetId = dquCiShortFromChar(pData);          /*计轴预复位状态继电器ID */
		pData += 2u;
		index += 2u;
		if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			pPhysclSgmtStr->wRepRelayTrainId = dquCiShortFromChar(pData);          /*复示轨道继电器ID */
			pData += 2u;
			index += 2u;
		}
		/*比较字节数*/
		if(index + 2u <= realRowLen)
		{
			if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
			{
				pPhysclSgmtStr->wRepRelayZongResetShowId = dquCiShortFromChar(pData);          /*计轴总复位表示灯 */
				pData += 2u;
				index += 2u;
			}
		}

		rtnvalue = 1u;
	}
	return rtnvalue;
}

/*********************************************
*函数功能：从数据到道岔继电器结构体
*参数说明：pDataAddr数据地址，pPhysclSgmtStr  道岔继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_PointStructFromChar(UINT8 * pDataAddr,Relay_PointStruct* pSwitchStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 lineIdentity = GetCiFunctionSwitchConfig(LINE_RAILWAY_TYPE_CONF);/*获取线路标识:0x55:城轨交通；0xAA:单轨交通*/
    if ((NULL == pDataAddr) || (NULL == pSwitchStr))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }
	if (CI_TRADITION_RAILWAY == lineIdentity)
	{/*城轨线路*/
		pSwitchStr->wPointId = dquCiShortFromChar(pData);          /*道岔ID*/
		pData += 2u;   

		/*跳过OCID*/
		pData += 2u;
		pSwitchStr->wRelayDingBiaoId = dquCiShortFromChar(pData);        /*定表继电器ID */
		pData += 2u; 
		pSwitchStr->wRelayFanBiaoId = dquCiShortFromChar(pData);          /*反表继电器ID */
		pData += 2u;   

		pSwitchStr->wRelayYunCaoId = dquCiShortFromChar(pData);          /*允操继电器ID*/
		pData += 2u;   
		pSwitchStr->wRelayDingCaoId = dquCiShortFromChar(pData);        /*定操继电器ID */
		pData += 2u; 
		pSwitchStr->wRelayFanCaoId = dquCiShortFromChar(pData);          /*反操继电器ID */
		pData += 2u;   
		pSwitchStr->wRelayZongDingBiaoId = dquCiShortFromChar(pData);        /*总定表继电器ID */
		pData += 2u; 
		pSwitchStr->wRelayZongFanBiaoId = dquCiShortFromChar(pData);          /*总反表继电器ID */
		pData += 2u;
		pSwitchStr->wDFHId = dquCiShortFromChar(pData);						/*DFH继电器ID*/
		pData += 2u;

		pSwitchStr->wRelayShadowDingBiaoId = dquCiShortFromChar(pData);        /*定表继电器ID */
		pData += 2u;
		pSwitchStr->wRelayShadowFanBiaoId = dquCiShortFromChar(pData);          /*反表继电器ID */
		pData += 2u;
	}/* zt 删除单轨相关代码 2022-02-15 */
	else
	{
	
	}

    rtnvalue = 1u;
	return rtnvalue;
}
/*********************************************
*函数功能：从数据到信号机继电器结构体
*参数说明：pDataAddr数据地址，  pSgnlStr信号机继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_SignalStructFromChar(UINT8 * pDataAddr,Relay_SignalStruct* pSgnlStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;

    if ((NULL == pDataAddr) || (NULL == pSgnlStr))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }

    pSgnlStr->wSignalId = dquCiShortFromChar(pData);               /*信号机ID*/
	pData += 2u;

	/*跳过OC ID*/
	pData += 2U;
    pSgnlStr->wRelayDengSiId_1 = dquCiShortFromChar(pData);         /*1灯丝继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayDengSiId_2 = dquCiShortFromChar(pData);         /*1灯丝继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayTrainSignalId = dquCiShortFromChar(pData);        /*列车信号继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayZhengXianId = dquCiShortFromChar(pData);        /*正线信号继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayYinDaoId = dquCiShortFromChar(pData);        /*引导信号继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayDianDengId = dquCiShortFromChar(pData);          /*点灯继电器ID*/
	pData += 2u;
    pSgnlStr->wRelayDiaoCheSignalId = dquCiShortFromChar(pData);          /*调车信号继电器ID*/
	pData += 2u;
	pSgnlStr->wSignalDrvColType = dquCiShortFromChar(pData);          /*信号机驱动采集类型Modified on 20160330*/
	pData += 2u;

	pSgnlStr->DetainBtnCollRelayId = dquCiShortFromChar(pData);/*扣车按钮继电器*/
	pData+=2u;
	pSgnlStr->DetainBtnIndicatorRelayId = dquCiShortFromChar(pData);/*扣车按钮指示灯继电器*/
	pData+=2u;
	pSgnlStr->DetainCutBtnRelayId = dquCiShortFromChar(pData);/*扣车按钮旁路继电器*/
	pData+=2u;
	pSgnlStr->DetainCutBtnIndicatorRelayId = dquCiShortFromChar(pData);/*扣车旁路按钮指示灯继电器ID*/
	pData+=2u;

	 rtnvalue = 1u;
	return rtnvalue;

}

/*********************************************
*函数功能：从数据到洗车机继电器结构体
*参数说明：pDataAddr数据地址，  pWashMachineStr 洗车机继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_WashMachineStructFromChar(UINT8 * pDataAddr,Relay_WashMachineStruct * pWashMachineStr, UINT16 realRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 1U;
	UINT16 index = 0U;

    if ((NULL == pDataAddr) || (NULL == pWashMachineStr))
    {
        rtnvalue = 0U;
        
    }
    if(1U == rtnvalue)
    {
	    pWashMachineStr->wId = dquCiShortFromChar(pData);                              /*洗车机ID*/
		pData += 2U;
	    pWashMachineStr->WashMachineReadyRelayId = dquCiShortFromChar(pData);          /*洗车机就绪继电器ID*/
		pData += 2U;
		pWashMachineStr->WashMachineRequestVerifyRelayId = dquCiShortFromChar(pData);  /*洗车请求恢复确认继电器ID*/
		pData += 2U;
	    pWashMachineStr->TrainEmergencyStopRelayId = dquCiShortFromChar(pData);        /*列车急停继电器ID*/
		pData += 2U;
	    pWashMachineStr->HeadWashAllowRelayId = dquCiShortFromChar(pData);             /*出发1继电器ID*/
		pData += 2U;
	    pWashMachineStr->TailWashAllowRelayId = dquCiShortFromChar(pData);             /*出发2继电器ID*/
		pData += 2U;
	    pWashMachineStr->WashTrainRequestRelayId= dquCiShortFromChar(pData);           /*洗车请求继电器ID*/
		pData += 2U;
		
	    pWashMachineStr->TrainHeadStopSteadyRelayId = dquCiShortFromChar(pData);       /*列车停稳1继电器ID*/
		pData += 2U; 
	    pWashMachineStr->TrainTailStopSteadyRelayId = dquCiShortFromChar(pData);       /*列车停稳2继电器ID*/
		pData += 2U;		
	    pWashMachineStr->TrainOutWashPortAllowRelayId = dquCiShortFromChar(pData);/*允许出库继电器ID*/
		pData += 2U;
		pWashMachineStr->PauseTrainWashRequestRelayId = dquCiShortFromChar(pData);	   /*暂停洗车继电器ID*/
		pData += 2U;
		pWashMachineStr->TrainPassRequestRelayId = dquCiShortFromChar(pData);          /*通过请求继电器ID*/
		pData += 2U;
		
		index += 24U;
		if (index + 2U <= realRowLen)
		{
			pWashMachineStr->WashModeBackRelayId = dquCiShortFromChar(pData);   /*全自动洗车模式反馈继电器(配置字段:采集继电器)*/
			pData += 2U;

			pWashMachineStr->WashModeRelayId = dquCiShortFromChar(pData);/*全自动自动洗车模式继电器（配置字段:驱动继电器)*/
			pData += 2U;
			pWashMachineStr->wDownWashAllowRelayId = dquCiShortFromChar(pData);/*降级模式洗车同意按钮继电器ID(配置字段:采集继电器)*/
			pData += 2U;
			pWashMachineStr->wDownWashAllowLightRelayId = dquCiShortFromChar(pData);/*降级模式洗车同意指示灯继电器ID（配置字段:驱动继电器)*/
			pData += 2U;
			pWashMachineStr->wDownWashAllowPassRelayId = dquCiShortFromChar(pData);/*降级模式洗车同意通过按钮继电器ID(配置字段:采集继电器)*/
			pData += 2U;
			pWashMachineStr->wDownWashRelateRoute1Id = dquCiShortFromChar(pData);/*降级模式洗车线控制台表示灯1关联进路ID*/
			pData += 2U;
			pWashMachineStr->wDownWashRelateRoute1CheckType = *pData;/*降级模式洗车线控制台表示灯1关联进路状态检查类型*/
			pData += 1U;
			pWashMachineStr->wDownWashRelRoute1LightRelayId = dquCiShortFromChar(pData);/*降级模式洗车线控制台表示灯1继电器ID（配置字段:驱动继电器)*/
			pData += 2U;
			pWashMachineStr->wDownWashRelateRoute2Id = dquCiShortFromChar(pData);/*降级模式洗车线控制台表示灯2关联进路ID*/
			pData += 2U;
			pWashMachineStr->wDownWashRelateRoute2CheckType = *pData;/*降级模式洗车线控制台表示灯2关联进路状态检查类型*/
			pData += 1U;
			pWashMachineStr->wDownWashRelRoute2LightRelayId = dquCiShortFromChar(pData);/*降级模式洗车线控制台表示灯2继电器ID（配置字段:驱动继电器)*/
			pData += 2U;

			index += 20U;
		}

		rtnvalue = 1U;
    }
	 
	return rtnvalue;

}
/*********************************************
*函数功能：从数据到非进路数据继电器结构体
*参数说明：pDataAddr数据地址，  pNoRotStr非进路数据继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_NoRouteDcStruFromChar(UINT8 * pDataAddr,Relay_NoRouteDcStruct* pNoRotStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;

    if ((NULL == pDataAddr) || (NULL == pNoRotStr))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }

	pNoRotStr->wId = dquCiShortFromChar(pData);               /*非进路调车ID*/
	pData += 2u;
	pNoRotStr->wRelayShenQingScId = dquCiShortFromChar(pData);         /* 车辆段采集的申请试车继电器ID */
	pData += 2u;
	pNoRotStr->wRelayTongYiScId = dquCiShortFromChar(pData);         /* 车辆段驱动的同意试车继电器ID */
	pData += 2u;
   
	pNoRotStr->wRelayDrvShiCheShengQingId = dquCiShortFromChar(pData);         /* 试车线驱动的申请试车继电器ID */
	pData += 2u;

	pNoRotStr->wRelayColTongYiScId = dquCiShortFromChar(pData);	/* 试车线采集同意试车继电器ID */
	pData += 2u;

	 rtnvalue = 1u;
	return rtnvalue;

}
/*********************************************
*函数功能：从数据到照查继电器结构体
*参数说明：pDataAddr数据地址， pZCStr 照查继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_ZhaoChaStruFromChar(UINT8 * pDataAddr,Relay_ZhaoChaStruct* pZCStr,UINT16 realRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0U;
	UINT8 i = 0U;
	UINT16 index = 0U;
	UINT8 chLocalCiPattern = 0U;

	chLocalCiPattern = GetLocalCiPattern();
  
    if ((NULL == pDataAddr) || (NULL == pZCStr))
    {
        rtnvalue = 0U;
        return rtnvalue;
    }

	pZCStr->wRouteId = dquCiShortFromChar(pData);                  /*进路ID*/
	pData += 2U;
	index += 2U;
	pZCStr->wRelayBenDuanZcId = dquCiShortFromChar(pData);         /*本端继电器ID*/
	pData += 2U;
	index += 2U;
	pZCStr->wRelayDuiDuanZcId = dquCiShortFromChar(pData);         /*对端继电器ID*/
	pData += 2U;
	index += 2U;
	pZCStr->wCancelRelayId = dquCiShortFromChar(pData);            /*取消照查继电器ID*/
	pData += 2U;
	index += 2U;

    /*照查物理区段1-5的ID*/
    for(i=0u; i<ROUTE_THATZC_PHYSEC_SUM_MAX; i++)
    {
        pZCStr->wRelayZhaoChaPhySecId[i] = dquCiShortFromChar(pData);
        pData += 2U;
		index += 2U;
    }
   
	if (CI_PATTERN_TRADITIONAL == chLocalCiPattern)
	{
		pZCStr->wCancelRelayIdOnRelayInterface = dquCiShortFromChar(pData);            /*继电接口下取消照查继电器ID*/
		pData += 2u;
		index += 2u;

		if ((index + 4u) <= realRowLen)
		{
			pZCStr->wRelayBenDuanZcIdOnRelayInterface = dquCiShortFromChar(pData); /*继电接口本端照查继电器ID*/
			pData += 2u;
			index += 2u;
			pZCStr->wRelayDuiDuanZcIdOnRelayInterface = dquCiShortFromChar(pData);  /*继电接口对端照查继电器ID*/
			pData += 2u;
			index += 2u;
		}
	}
	else
	{
		; /*非法值*/
	}

	rtnvalue = 1U;
	return rtnvalue;

}
/*********************************************
*函数功能：从数据到报警灯继电器结构体
*参数说明：pDataAddr数据地址， pBjdStr 报警灯继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_BaoJingDengStruFromChar(UINT8 * pDataAddr,Relay_BaoJingDengStruct* pBjdStr,UINT32 dwRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT16 i=0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT8 includeVirFlag= GetCiFunctionSwitchConfig(FUNC_INCLUDEVIRCI_FLAG);
	UINT16 OCid = 0u;

    if ((NULL == pDataAddr) || (NULL == pBjdStr))
    {
        rtnvalue = 0u;
        return rtnvalue;
    }

	localCiPattern = GetLocalCiPattern();
	pBjdStr->wId = dquCiShortFromChar(pData);               /*ID*/
	pData += 2u;
	pBjdStr->wBelongCiId = dquCiShortFromChar(pData);               /*所属ID*/
	if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
	{
		OCid = pBjdStr->wBelongCiId;/*对应全电子联锁，读取到的是OCid*/
		pBjdStr->wBelongCiId = GetCiIdByOcId(pBjdStr->wBelongCiId);/*找到0Cid对应联锁id*/
		if(FUNC_SWITCH_ON == includeVirFlag)
		{
			pBjdStr->wBelongVirCIid = GetOCBelongVirCIid((UINT8)OCid);/*找到0Cid对应虚拟联锁id*/
		}
		else
		{
			pBjdStr->wBelongVirCIid  = 0u;
		}
	}
	pData += 2u;
	pBjdStr->wBjdID = dquCiShortFromChar(pData);               /*报警灯ID*/
	pData += 2u;
	pBjdStr->wBjdYouXiao = *pData;         /*是否有效*/
	pData += 1u;
	for(i=0u;i<BJD_MAX_NUM;i++)
	{
		pBjdStr->wBjdJdqId[i] = dquCiShortFromChar(pData);         /*对端继电器ID*/
		pData += 2u;
	}
	
	if (15U < dwRowLen)
	{
		pBjdStr->cBjdDevId = *pData;
		pData += 1;
	}
   
	 rtnvalue = 1u;
	return rtnvalue;

}

/*********************************************
*函数功能：从数据到无人折返继电器结构体
*参数说明：pDataAddr数据地址，  pWuRenRtnStr无人折返继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_NoReturnStruFromChar(UINT8 * pDataAddr,Relay_NoReturnStruct* pWuRenRtnStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/

    if ((NULL == pDataAddr) || (NULL == pWuRenRtnStr))
    {
        rtnvalue = 0u;
    }
	else
	{
		localCiPattern = GetLocalCiPattern();
		pWuRenRtnStr->wId = dquCiShortFromChar(pData);               /*ID*/
		pData += 2u;
		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pWuRenRtnStr->ocId = dquCiShortFromChar(pData); /*OC ID*/
			pData += 2u;
		}
		pWuRenRtnStr->wWuRenReturnRelayId = dquCiShortFromChar(pData);     /*继电器组ID*/
		pData += 2u;
		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pWuRenRtnStr->wWuRenReturnDisRelayId = dquCiShortFromChar(pData); /*无人折返指示灯继电器ID*/
			pData += 2u;
		}

		rtnvalue = 1u;
	}

	return rtnvalue;
}

/*********************************************
*函数功能：初始化车库门继电器结构体
*参数说明：pDataAddr数据地址，  pGaragedoorStr车库门继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_GaragedoorStructFromChar(UINT8 * pDataAddr,Relay_GaragedoorStruct* pGaragedoorStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
 
    if ((NULL == pDataAddr) || (NULL == pGaragedoorStr))
    {
        rtnvalue = 0u;
    }
	else
	{
		pGaragedoorStr->wGaragedoorId = dquCiShortFromChar(pData);          /* 车库门ID */
		pData += 2u;   
		pGaragedoorStr->wGardoorCloseRelayId = dquCiShortFromChar(pData);          /* 车库门关门继电器ID*/
		pData += 2u; 
		pGaragedoorStr->wGardoorOpenRelayId = dquCiShortFromChar(pData);          /* 车库门开门继电器ID*/
		pData += 2u; 
		pGaragedoorStr->wGardoorCloseOrderRelayId = dquCiShortFromChar(pData);          /* 车库门关门命令继电器ID*/
		pData += 2u; 
		pGaragedoorStr->wGardoorOpenOrderRelayId = dquCiShortFromChar(pData);          /* 车库门开门命令继电器ID*/
		pData += 2u; 
        pGaragedoorStr->wGardoorModeStateRelayId = dquCiShortFromChar(pData);          /* 车库门模式状态继电器ID*/
        pData += 2u; 
        pGaragedoorStr->wGardoorFaultStateRelayId = dquCiShortFromChar(pData);          /* 车库门故障继电器ID*/
        pData += 2u;
		pGaragedoorStr->wGardoorPangLuRelayId = dquCiShortFromChar(pData);              /* 车库门旁路继电器ID*/
		pData += 2u;
		pGaragedoorStr->wGardoorKGHRelayId = dquCiShortFromChar(pData);              /* 车库门开关后节点继电器ID*/
		pData += 2u;
		rtnvalue = 1u;
	}
	return rtnvalue;
}


/*********************************************
*函数功能：从数据到SPKS继电器结构体
*参数说明：pDataAddr数据地址，  pSpksStr SPKS数据结构体指针   realRowLen 每一行数据长度
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_SpksDataFromChar(UINT8 * pDataAddr,RelaySpksStruct* pSpksStr, UINT16 realRowLen)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/

	if ((NULL == pDataAddr) || (NULL == pSpksStr))
	{
		rtnvalue = 0u;		
	}
	else
	{
		localCiPattern = GetLocalCiPattern();
		
		if (CI_PATTERN_FULL_ELECTRONIC == localCiPattern)
		{
			pSpksStr->id = dquCiShortFromChar(pData);               /* ID */
			pData += 2u;

			pSpksStr->ocId = dquCiShortFromChar(pData);            /*OC ID*/
			pData += 2u;

			pSpksStr->colRelayId = dquCiShortFromChar(pData);     /* 采集继电器组ID */
			pData += 2u;

			pSpksStr->disRelayId = dquCiShortFromChar(pData);     /* 表示灯继电器组ID */
			pData += 2u;

			pSpksStr->cutRelayId = dquCiShortFromChar(pData);     /* 旁路继电器组ID */
			pData += 2u;

			pSpksStr->cutDisRelayId = dquCiShortFromChar(pData);     /*SPKS旁路按钮指示灯继电器ID*/
			pData += 2u;

			pSpksStr->outsideRelayId = dquCiShortFromChar(pData);     /*室外SPKS指示灯继电器*/
			pData += 2u;

			
		}
		else if (CI_PATTERN_TRADITIONAL == localCiPattern)
		{
			pSpksStr->id = dquCiShortFromChar(pData);               /* ID */
			pData += 2u;

			pSpksStr->colRelayId = dquCiShortFromChar(pData);     /* 采集继电器组ID */
			pData += 2u;

			pSpksStr->disRelayId = dquCiShortFromChar(pData);     /* 表示灯继电器组ID */
			pData += 2u;

			pSpksStr->cutRelayId = dquCiShortFromChar(pData);     /* 旁路继电器组ID */
			pData += 2u;

			pSpksStr->cutDisRelayId = dquCiShortFromChar(pData);     /*SPKS旁路按钮指示灯继电器ID*/
			pData += 2u;

			pSpksStr->outsideRelayId = dquCiShortFromChar(pData);     /*室外SPKS指示灯继电器*/
			pData += 2u;

			pSpksStr->repRelayId = dquCiShortFromChar(pData);     /* 复示继电器组ID */
			pData += 2u;
		}
		else
		{
			/*不处理*/
			;
		}
		rtnvalue = 1u;
	}
	
	return rtnvalue;
}

/*********************************************
*函数功能：从数据到门禁继电器结构体
*参数说明：pDataAddr数据地址，  pMjStr 门禁数据结构体指针   realRowLen 每一行数据长度
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_MJDataFromChar(UINT8* pDataAddr, Relay_MJStruct* pMjStr, UINT16 realRowLen)
{
	UINT8* pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT8 localCiPattern = 0u; /*本CI模式*/
	UINT8 realSPKSNum = 0u; /*真实填写的SPKS数量*/
	UINT8 ii = 0u;
	UINT16 wSpksId = 0U;

	if ((NULL == pDataAddr) || (NULL == pMjStr))
	{
		rtnvalue = 0u;
	}
	else
	{
		rtnvalue = 1U;
		localCiPattern = GetLocalCiPattern();
		realSPKSNum = (UINT8)((realRowLen - 6u) / 2u);               /*除去门禁ID OCID MJ继电器ID6字节*/

		if ((CI_PATTERN_FULL_ELECTRONIC == localCiPattern)|| (CI_PATTERN_TRADITIONAL == localCiPattern))
		{
			pMjStr->mjid = dquCiShortFromChar(pData);               /* ID */
			pData += 2u;

			pMjStr->ocId = dquCiShortFromChar(pData);            /*OC ID*/
			pData += 2u;

			pMjStr->mjjsRelayId = dquCiShortFromChar(pData);     /* 门禁解锁继电器组ID */
			pData += 2u;

			for ( ii = 0u; ii < realSPKSNum; ii++)
			{
				wSpksId = dquCiShortFromChar(pData);
				pData += 2u;

				if ((0U == ii) && ((0U == wSpksId) || (UINT16_MAX <= wSpksId)))
				{
					rtnvalue = 0U;  /*SPKS ID非法，停止读取，返回0*/
					break;
				}
				else
				{
					pMjStr->spksId[ii] = wSpksId;
				}
			}
		}
		else
		{
			/*不处理*/
			;
		}
	}

	return rtnvalue;
}


/*********************************************
*函数功能：从数据到防淹门继电器结构体
*参数说明：pDataAddr数据地址，  pFloodGateStr 防淹门数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_FloodGateStructFromChar(UINT8 * pDataAddr,Relay_FloodGateStruct* pFloodGateStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;

	if ((NULL == pDataAddr) || (NULL == pFloodGateStr))
	{
		rtnvalue = 0u;		
	}
	else
	{
		pFloodGateStr->wFloodGateId = dquCiShortFromChar(pData);               /* 防淹门ID */
		pData += 2u;
		pFloodGateStr->wCloseApplyRelayId = dquCiShortFromChar(pData);     /* 关门请求继电器ID */
		pData += 2u;
		pFloodGateStr->wOpenCloseRelayId = dquCiShortFromChar(pData);     /* 开门且锁闭继电器ID */
		pData += 2u;
		pFloodGateStr->wAllowRequestRelayId = dquCiShortFromChar(pData);     /* 允许请求继电器ID */
		pData += 2u;

		rtnvalue = 1u;
	}
	
	return rtnvalue;
}

/*********************************************
*函数功能：从数据到调车同意继电器结构体
*参数说明：pDataAddr数据地址，  pWashMachineStr 洗车机继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_DCAgreeStructFromChar(UINT8 * pDataAddr,Relay_DCAgreeStruct * pDCAgreeStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0U;
	UINT8 chLocalCiPattern = 0u; /*本CI模式*/

	if ((NULL == pDataAddr) || (NULL == pDCAgreeStr))
	{
		 ;

	}
	else
	{
		chLocalCiPattern = GetLocalCiPattern();

		pDCAgreeStr->wRouteId = dquCiShortFromChar(pData);			/*进路ID*/
		pData += 2U;
		pDCAgreeStr->DCRouteDCQJId = dquCiShortFromChar(pData);		/*调车同意-调车请求继电器ID*/
		pData += 2U;

		if (CI_PATTERN_FULL_ELECTRONIC == chLocalCiPattern)
		{
			pDCAgreeStr->DCRouteDCQJTwoId = dquCiShortFromChar(pData);		/*调车同意-调车请求继电器2ID*/
			pData += 2U;
		}
		else
		{
			pDCAgreeStr->DCRouteDCQJTwoId = 0U;
		}

		pDCAgreeStr->DCRouteTAJId = dquCiShortFromChar(pData);		/*调车同意-调车同意按钮继电器ID*/
		pData += 2U;

		rtnvalue = 1U;
	}

	return rtnvalue;

}

/*********************************************
*函数功能：初始化继电器关联故障锁闭区段结构体
*参数说明： pDataAddr数据地址，  pRelayCfgDtStr继电器配置数据结构体指针
			pRelayId继电器id地址	pSecBuf物理区段id行地址
*返回值：0，失败；1，成功
*********************************************/
UINT8 RelayCfgFaultLockPhySecFromChar(UINT8 * pDataAddr,RelayConfigDataStruct* pRelayCfgDtStr,
	UINT16 *pRelayId,UINT16 pSecBuf[][MAX_LOCK_EXCEPT_SECTION_NUM])
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;
	UINT16 i=0u;

	if ((NULL == pDataAddr) || (NULL == pRelayCfgDtStr) || (NULL == pRelayId) || (NULL == pSecBuf))
	{
		rtnvalue = 0u;
		
	}
	else
	{
		rtnvalue = 1u;

		/*继电器ID (配置字段)*/
		*pRelayId = dquCiShortFromChar(pData);
		pData += 2u;

		/*故障物理区段ID(配置字段)*/
		for (i=0u;i<MAX_LOCK_EXCEPT_SECTION_NUM;i++)
		{
			pSecBuf[0][i] = dquCiShortFromChar(pData);
			pData += 2u;
		}
				
	}
	
	return rtnvalue;
}

/*********************************************
*函数功能：从数据到倒切设备继电器结构体
*参数说明：pDataAddr数据地址，  pReverseCutDtStr 倒切设备继电器配置数据结构体指针
*返回值：0，失败；1，成功
*********************************************/
UINT8 R_ReverseCutStrFromChar(UINT8 * pDataAddr, Relay_ReverseCutStruct * pReverseCutDtStr)
{
	UINT8 * pData = pDataAddr;
	UINT8 rtnvalue = 0u;

	if ((NULL == pDataAddr) || (NULL == pReverseCutDtStr))
	{
		rtnvalue = 0u;

	}
	else
	{
		rtnvalue = 1U;
	}

	if (1u == rtnvalue)
	{
		pReverseCutDtStr->wReverseCutRelayId = dquCiShortFromChar(pData);			/*进路ID*/
		pData += 2u;
		

		rtnvalue = 1u;
	}

	return rtnvalue;

}
/*********************************************
*函数功能：从数据到OC站指示灯灯继电器结构体
*参数说明：pDataAddr数据地址， pBjdStr 报警灯继电器配置数据结构体指针
*返回值：0，失败；1，成功
* cgh-合并CID-3037-3：
*********************************************/
UINT8 R_OCIndicStruFromChar(UINT8* pDataAddr, OCStationIndicConfigDataStru* pIndicStru)
{
	UINT8* pData = pDataAddr;
	UINT16 i = 0u;
	UINT16 OCid = 0u;
	UINT8 reVal = CI_ERROR;
	UINT16 ocid = 0u;
	UINT8 localCiId = GetSystemParaLocalCiId();
	UINT8 belongCiId = 0u;
	UINT16 indicatorId = 0u;
	UINT8 avalibleFlag = 0u;
	UINT16 relayID = 0u;
	if ((NULL != pData) && (NULL != pIndicStru))
	{
		reVal = CI_SUCCESS;
	}

	if (CI_SUCCESS == reVal)
	{
		reVal = CI_ERROR;

		pData += 2; /*ID*/
		ocid = dquCiShortFromChar(pData);               /*所属ID*/
		pData += 2;
		belongCiId = (UINT8)GetCiIdByOcId(ocid);
		if (localCiId == belongCiId)
		{

			indicatorId = dquCiShortFromChar(pData);               /*报警灯ID*/
			pData += 2;
			avalibleFlag = *pData;     /*是否有效*/
			pData += 1;

			if (INDICATOR_DATA_RELAY == avalibleFlag)
			{
				reVal = CI_SUCCESS;

				pIndicStru->OcId = (UINT8)ocid;
				pIndicStru->IndicatorId = (UINT8)indicatorId;
				pIndicStru->IndicatorType = (UINT8)indicatorId;/*类型和ID相同*/

				for (i = 0; i < INDICATOR_RELAY_SUM_MAX; i++)
				{
					relayID = dquCiShortFromChar(pData);         /*继电器ID*/
					pData += 2;
					if ((0u == relayID) || (UINT16_MAX == relayID))
					{
					}
					else
					{
						pIndicStru->IdBuf[i] = relayID;/*继电器ID*/
						pIndicStru->IdSum++;/*继电器数目*/
					}
				}
			}

		}
	}

	return reVal;
}


