
/*******************************************************************************
* 版权所有：	
* 文件版本： V1.00
* 文件名称： vol.c 
* 生成日期： 2007年9月10日
* 作   者：电力开发部部
* 功   能： 电压逻辑处理
* 修改日志：  
* 日志1：           
* 修改者： 
* 修改日期：2013.6.18
* 修改内容：
* 修改原因：
****************************************************************************/
#include "head.h"

/**********************************************************************
定义全局变量
***********************************************************************/
#ifdef	CUSTOMIZE_BZT //备自投
TVOL_T	g_tVolLost;
#endif
TVOL_T	g_tVol[VOL_NUMBER];
#define SOFE_AUTO_EN(sw) (BH_ALL_EN(sw)||FA_ALL_EN(sw))//安全自动化功能压板  保护和FA模式下都需要投入安自功能

void vol_over(DWORD  dStep,int vno,int index,int soeno)
{
	bool  bQDD=false; 	
	TVOL_T *pvol = &g_tVol[vno];
	VOL_SET *pSet = &pRunSet->tVolSet[vno];

	if((vno!=VOL_DDY_DC1)&&(vno!=VOL_DDY_DC2)&&(vno!=VOL_WY_POW1)&&(vno!=VOL_WY_POW2))
	{
           if(vno==VOL_YY_POW1)
	       {
		       bQDD = OverRelay(g_sw_pub.m2_max[2], pSet->dUVol,pSet->dUVol_fh,pvol->sta.bFlag.bQD);
           }
		   else if(vno==VOL_YY_POW2)
		   {
		       bQDD = OverRelay(g_sw_pub.m2_max[3], pSet->dUVol,pSet->dUVol_fh,pvol->sta.bFlag.bQD);
           }
		   else 
		   {
			   bQDD = OverRelay(g_ui[index].m2[0],  pSet->dUVol,pSet->dUVol_fh,pvol->sta.bFlag.bQD); 
	   	   }
	}
	

	pvol->sta.bFlag.bQD = (pSet->bTT && bQDD);

	/***********动作*********************************/
	RunTR(&pvol->tQDTime, pvol->sta.bFlag.bQD, dStep);		
	pvol->sta.bFlag.bGj = pvol->tQDTime.boolTrip;

	/************事件记录及出口****************************/
	if(pvol->sta.bFlag.bGj) 
	{
		if(soe_check(soeno)==false)	
		{
			DWORD Uab;
            if (vno == VOL_YY_POW1)
            {
                Uab = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, g_ui[index].m2_factor_k);
            }
            else if (vno == VOL_YY_POW2)
            {
                Uab = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, g_ui[index].m2_factor_k);
            }
            else
            {
                Uab = _Mul_Div_U(sqrt_32fix(g_ui[index].m2[0]), 256, g_ui[index].m2_factor_k);
            }
            soe_record_ev(soeno,1, Uab,0,0);                                          
		}
	}
	else
	{
		if(soe_check(soeno)==true)			
		{
			soe_record_ev(soeno,0, 0,0,0 );                                          
		}			
	} 
}

void vol_low(DWORD  dStep,int vno,int index,int soeno)
{
	bool  bQDD_H,bQDD; 	
	TVOL_T *pvol = &g_tVol[vno];
	VOL_SET *pSet = &pRunSet->tVolSet[vno];
	static bool bCYY_bk[VOL_NUMBER]={false},bQD_bk[VOL_NUMBER]={false},bGj_bk[VOL_NUMBER]={false},bQDD_H_bk[VOL_NUMBER]={false};
	
	if((vno!=VOL_DDY_DC1)&&(vno!=VOL_DDY_DC2))
	{
        if (vno == VOL_WY_POW1)
        {
            bQDD_H = OverRelay(g_sw_pub.m2_max[2], pSet->dUVol, pSet->dUVol, false);
        }
        else if (vno == VOL_WY_POW2)
        {
            bQDD_H = OverRelay(g_sw_pub.m2_max[3], pSet->dUVol, pSet->dUVol, false);
        }
        else
        {
            bQDD_H = OverRelay(g_ui[index].m2[0], pSet->dUVol, pSet->dUVol, false);
        }
    }
	else if((vno==VOL_DDY_DC1)||(vno==VOL_DDY_DC2))
	{
		bQDD_H = OverRelay(_AbsL(g_sw_pub.ac_in[index]), pSet->dUVol,pSet->dUVol,false); 
	}

	//有压充电
	RunTR(&pvol->tCYYTime, (bQDD_H|pvol->sta.bFlag.bCYY), dStep);		
	pvol->sta.bFlag.bCYY = pvol->tCYYTime.boolTrip&&pSet->bTT;
	
	RunTR(&pvol->tWaveYYTime, bQDD_H, dStep);	
	if(pvol->tWaveYYTime.boolTrip)
	{
		pvol->sta.bFlag.bQDWave=false;
	}	

	if((vno!=VOL_DDY_DC1)&&(vno!=VOL_DDY_DC2))
	{
        if (vno == VOL_WY_POW1)
        {
            bQDD = LowRelay(g_sw_pub.m2_max[2], pSet->dUVol, pSet->dUVol_fh, pvol->sta.bFlag.bQD);
        }
        else if (vno == VOL_WY_POW2)
        {
            bQDD = LowRelay(g_sw_pub.m2_max[3], pSet->dUVol, pSet->dUVol_fh, pvol->sta.bFlag.bQD);
        }
        else
        {
            bQDD = LowRelay(g_ui[index].m2[0], pSet->dUVol, pSet->dUVol_fh, pvol->sta.bFlag.bQD);
        }
    }
	else if((vno==VOL_DDY_DC1)||(vno==VOL_DDY_DC2))
	{
		bQDD = LowRelay(_AbsL(g_sw_pub.ac_in[index]), pSet->dUVol,pSet->dUVol_fh,pvol->sta.bFlag.bQD); 
	}

	pvol->sta.bFlag.bQD = (pSet->bTT&&bQDD&&pvol->sta.bFlag.bCYY);
	if(pvol->sta.bFlag.bQD)
	{
		if(!pvol->sta.bFlag.bQDWave)
		{
			int sw;
			if(vno==VOL_DDY_Uab1||vno==VOL_DDY_Ubc1||vno==VOL_DDY_Uca1)
			{

				bool bY1;
				bY1=g_tVol[VOL_DDY_Uab1].sta.bFlag.bQDWave||g_tVol[VOL_DDY_Ubc1].sta.bFlag.bQDWave||g_tVol[VOL_DDY_Uca1].sta.bFlag.bQDWave;  // 判断是否启动过低电压
				for(sw=0;sw<g_sw_num;sw++)
				{
					if(!pRunSet->tSwSet[sw].bTT_Power_v2&&!bY1)
					{
						rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	// 线路低电压，启动开关录波
					}
				}
			}
			if(vno==VOL_DDY_Uab2||vno==VOL_DDY_Ubc2||vno==VOL_DDY_Uca2)
			{
				bool bY1;
				bY1=g_tVol[VOL_DDY_Uab2].sta.bFlag.bQDWave||g_tVol[VOL_DDY_Ubc2].sta.bFlag.bQDWave||g_tVol[VOL_DDY_Uca2].sta.bFlag.bQDWave;  // 判断是否启动过低电压
				for(sw=0;sw<g_sw_num;sw++)
				{
					if(pRunSet->tSwSet[sw].bTT_Power_v2&&!bY1)
					{
						rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	// 线路低电压，启动开关录波
					}
				}
			}		
			pvol->sta.bFlag.bQDWave=true;
		}
	}

	/***********动作*********************************/
	RunTR(&pvol->tQDTime, pvol->sta.bFlag.bQD, dStep);		
	pvol->sta.bFlag.bGj = pvol->tQDTime.boolTrip;

	if(vno==VOL_DDY_DC1)
	{
		if((bCYY_bk[VOL_DDY_DC1]!=pvol->sta.bFlag.bCYY)
			||(bQD_bk[VOL_DDY_DC1]!=pvol->sta.bFlag.bQD)
			||(bGj_bk[VOL_DDY_DC1]!=pvol->sta.bFlag.bGj)
			||(bQDD_H_bk[VOL_DDY_DC1]!=bQDD_H))
		{
			/*rt_printf("DC1:bQDD_H=%d,bCYY=%d,bQD=%d,bGj=%d,dUVol=%d,ac_in[%d]=%d\r\n",
				bQDD_H,
				pvol->sta.bFlag.bCYY,
				pvol->sta.bFlag.bQD,
				pvol->sta.bFlag.bGj,
				pSet->dUVol,
				index,
				g_sw_pub.ac_in[index]
				);*/
			bCYY_bk[VOL_DDY_DC1]=pvol->sta.bFlag.bCYY;
			bQD_bk[VOL_DDY_DC1]=pvol->sta.bFlag.bQD;
			bGj_bk[VOL_DDY_DC1]=pvol->sta.bFlag.bGj;
			bQDD_H_bk[VOL_DDY_DC1]=bQDD_H;
		}
			
	}

	if(vno==VOL_DDY_DC2)
	{
		if((bCYY_bk[VOL_DDY_DC2]!=pvol->sta.bFlag.bCYY)
			||(bQD_bk[VOL_DDY_DC2]!=pvol->sta.bFlag.bQD)
			||(bGj_bk[VOL_DDY_DC2]!=pvol->sta.bFlag.bGj)
			||(bQDD_H_bk[VOL_DDY_DC2]!=bQDD_H))
		{
			/*rt_printf("DC2:bQDD_H=%d,bCYY=%d,bQD=%d,bGj=%d,dUVol=%d,ac_in[%d]=%d\r\n",
				bQDD_H,
				pvol->sta.bFlag.bCYY,
				pvol->sta.bFlag.bQD,
				pvol->sta.bFlag.bGj,
				pSet->dUVol,
				index,
				g_sw_pub.ac_in[index]);*/
				
			bCYY_bk[VOL_DDY_DC2]=pvol->sta.bFlag.bCYY;
			bQD_bk[VOL_DDY_DC2]=pvol->sta.bFlag.bQD;
			bGj_bk[VOL_DDY_DC2]=pvol->sta.bFlag.bGj;
			bQDD_H_bk[VOL_DDY_DC2]=bQDD_H;
		}		
	}

	
	/************事件记录及出口****************************/
	if(pvol->sta.bFlag.bGj) 
	{
		int sw;
		
		if(soe_check(soeno)==false)	
		{
			DWORD Uab;

			if((vno!=VOL_DDY_DC1)&&(vno!=VOL_DDY_DC2))
            {
                if (vno == VOL_WY_POW1)
                {
                    Uab = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, g_ui[index].m2_factor_k);
                }
                else if (vno == VOL_WY_POW2)
                {
                    Uab = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, g_ui[index].m2_factor_k);
                }
                else
                {
                    Uab = _Mul_Div_U(sqrt_32fix(g_ui[index].m2[0]), 256, g_ui[index].m2_factor_k);
                }
            }
            else if((vno==VOL_DDY_DC1)||(vno==VOL_DDY_DC2))
			{
				Uab = g_sw_pub.ac_in[index];
			}
			

			if(vno==VOL_DDY_Uab1||vno==VOL_DDY_Ubc1||vno==VOL_DDY_Uca1)
			{
				bool bY1;
				bY1=soe_check(EV_UAB1DDY)||soe_check(EV_UBC1DDY)	||soe_check(EV_UCA1DDY);  // 判断是否启动过低电压
				for(sw=0;sw<g_sw_num;sw++)
			
				{
					if(!pRunSet->tSwSet[sw].bTT_Power_v2)
					{
						if(!bY1&&BH_WAVETIME_EN(pSet->dTVol))rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	// 线路低电压，启动开关录波
					}
				}
			}
			if(vno==VOL_DDY_Uab2||vno==VOL_DDY_Ubc2||vno==VOL_DDY_Uca2)
			{
				bool bY1;
				bY1=soe_check(EV_UAB2DDY)||soe_check(EV_UBC2DDY)	||soe_check(EV_UCA2DDY);  // 判断是否启动过低电压
				for(sw=0;sw<g_sw_num;sw++)
			
				{
					if(pRunSet->tSwSet[sw].bTT_Power_v2)
					{
						if(!bY1&&BH_WAVETIME_EN(pSet->dTVol))rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	// 线路低电压，启动开关录波
					}
				}
			}	

			soe_record_ev(soeno,1, Uab,0,0); 
			
		}
	}
	else
	{
		if(soe_check(soeno)==true)			
		{
			//if(pvol->sta.bFlag.bGj)
			{
				pvol->sta.bFlag.bCYY=false;
			}

			soe_record_ev(soeno,0, 0,0,0 );                                          
			pvol->sta.bFlag.bQDWave=false;
		}			
	}
}


void Pro_vol(DWORD  dStep)
{
	vol_over(dStep,VOL_GDY_Uab1,	PUB_AC_UAB1,	EV_UAB1GDY);
	vol_over(dStep,VOL_GDY_Ubc1,	PUB_AC_UBC1,	EV_UBC1GDY);
	vol_over(dStep,VOL_GDY_Uca1,	PUB_AC_UCA1,	EV_UCA1GDY);
	vol_over(dStep,VOL_GDY_Uab2,	PUB_AC_UAB2,	EV_UAB2GDY);
	vol_over(dStep,VOL_GDY_Ubc2,	PUB_AC_UBC2,	EV_UBC2GDY);
	vol_over(dStep,VOL_GDY_Uca2,	PUB_AC_UCA2,	EV_UCA2GDY);
	vol_over(dStep,VOL_YY_POW1,		PUB_AC_US1,	    EV_POW1YY);
	vol_over(dStep,VOL_YY_POW2,		PUB_AC_US2,  	EV_POW2YY);
	vol_low(dStep,VOL_DDY_Uab1,		PUB_AC_UAB1,	EV_UAB1DDY);
	vol_low(dStep,VOL_DDY_Ubc1,		PUB_AC_UBC1,	EV_UBC1DDY);
	vol_low(dStep,VOL_DDY_Uca1,		PUB_AC_UCA1,	EV_UCA1DDY);
	vol_low(dStep,VOL_DDY_Uab2,		PUB_AC_UAB2,	EV_UAB2DDY);
	vol_low(dStep,VOL_DDY_Ubc2,		PUB_AC_UBC2,	EV_UBC2DDY);
	vol_low(dStep,VOL_DDY_Uca2,		PUB_AC_UCA2,	EV_UCA2DDY);
	vol_low(dStep,VOL_WY_POW1,		PUB_AC_US1,	    EV_POW1WY);
	vol_low(dStep,VOL_WY_POW2,		PUB_AC_US2,	    EV_POW2WY);
	vol_low(dStep,VOL_DDY_DC1,		PUB_AC_IN_UZ1,	EV_DC1DDY);
#ifndef DC_TEST_ONE
	vol_low(dStep,VOL_DDY_DC2,		PUB_AC_IN_UZ2,	EV_DC2DDY);
#endif
}

/**************************************************************************
函数名称：Pro_TQHz

函数版本：1.00 
作者：    电力产品开发部
创建日期：2012.3.16   
函数功能说明：合环
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
void Pro_TQHz(int sw,DWORD  dStep)
{
	bool bQD,bTQ=false;
	TRELAY_T *pR=&g_tRelay[sw];
	TTQHZ_T *pSW = &pR->tTQHz;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	static int printf_Pro_TQHz=1;
	

	if(pR->uRmtSW.bTQHz)
	{
		pR->uRmtSW.bTQHz = false;
		bTQ = true;
	}	
	RunTR(&pSW->tTQQDTime, bTQ, dStep);
	if(pSW->tTQQDTime.boolTrip && pR->tSWST.uSWST.bFlag.bHZWZ)
	{
		ResetTR(&pSW->tTQQDTime);
	}
	// 合环合闸
	if(!TYTQ_ALL_EN(sw))      
	{		
		#if 1
		long deltaA;
		bool bMxYY,bMxWY,bUxYY,bUxWY,bDa,bDu,bDf;
		qs16 ang1=0,ang2=0;

		if(pRunSet->pt2vol==PUB_AC_UAB1)ang2=0;
		else if(pRunSet->pt2vol==PUB_AC_UBC1)ang2=-120*65536;
		else if(pRunSet->pt2vol==PUB_AC_UCA1)ang2=120*65536;
		else if(pRunSet->pt2vol==PUB_AC_UAB2)ang2=0;
		else if(pRunSet->pt2vol==PUB_AC_UBC2)ang2=-120*65536;
		else if(pRunSet->pt2vol==PUB_AC_UCA2)ang2=120*65536;
		
		
		//deltaA = _AbsL((g_ui[PUB_AC_UAB1].p -ang1)- (g_ui[pRunSet->pt2vol].p-ang2));	
		//bdeltaA = LowRelay(da, pSet->dTQ_ANG, pSet->dTQ_ANG_fh, pSW->uTQHz.bFlag.bQD); 
		//bDa = LowRelay(deltaA, pSet->dA_tq_delatA, pSet->dA_tq_delatA, false); 

	    bMxYY = OverRelay(g_sw_pub.m2_max[2], pSet->dU_chz_yy,pSet->dU_chz_yy,false); 
	    bMxWY = LowRelay(g_sw_pub.m2_max[2], pSet->dU_chz_wy,pSet->dU_chz_wy,false); 
	    bUxYY = OverRelay(g_ui[pRunSet->pt2vol].m2[0], pSet->dU_chz_yy,pSet->dU_chz_yy,false); 
	    bUxWY = LowRelay(g_ui[pRunSet->pt2vol].m2[0], pSet->dU_chz_wy,pSet->dU_chz_wy,false); 
	   // deltaA=CalcAngSub(g_ui[PUB_AC_UAB1].ri.r,g_ui[PUB_AC_UAB1].ri.i,g_ui[pRunSet->pt2vol].ri.r,g_ui[pRunSet->pt2vol].ri.i);
		deltaA = _AbsL((g_ui[PUB_AC_UAB1].p -ang1)- (g_ui[pRunSet->pt2vol].p-ang2));
		bDa=(((_AbsL(deltaA) < pSet->dA_tq_delatA)?true:false)||(pSet->dA_tq_delatA==0)); //角差满足要求，角差为零，不判角差
		bDu=((_AbsL(g_ui[PUB_AC_UAB1].fz -g_ui[pRunSet->pt2vol].fz)<pSet->dU_tq_deltaU)?true:false)||(pSet->dU_tq_deltaU==0); //压差满足要求
		bDf= ((_AbsL(g_sw_pub.ac_in[PUB_AC_IN_F1] - g_sw_pub.ac_in[PUB_AC_IN_F2])<pSet->dF_tq_deltaF)?true:false)||(pSet->dF_tq_deltaF==0);//频差

#ifdef FUNC_PRINT_PT_ERR
		if(bTQ && (tPT.uPT1DX.bFlag.bPTYC || tPT.uPT2DX.bFlag.bPTYC))
		{
			rt_printf("有同期合闸需求但PT断线,不允许合闸!\r\n");
		}
#endif

		bQD=(bDa&&bDu&&bDf&&bMxYY&&bUxYY&&(!tPT.uPT1DX.bFlag.bPTYC)&&(!tPT.uPT2DX.bFlag.bPTYC))
		#ifndef FUNC_TQ_YY
			||(bMxWY&&(!tPT.uPT1DX.bFlag.bPTYC))
			||(bUxWY&&(!tPT.uPT2DX.bFlag.bPTYC))
		#endif
			;  //压差，角差，频差满足要求，或有一侧无压

		pSW->uTQHz.bFlag.bQD = (FUN_ALL_EN(sw) &&
			                    (!TYTQ_ALL_EN(sw)) &&
								bQD && 						
								pSW->tTQQDTime.boolTrip && !pR->tSWST.uSWST.bFlag.bHZWZ);		// 有外部同期需求

		pSW->uTQHz.bFlag.bHz = pSW->uTQHz.bFlag.bQD;
		if(pSW->uTQHz.bFlag.bHz && printf_Pro_TQHz)
		{
			if(!FUN_ALL_EN(sw))
				rt_printf("保护硬件压板条件不满足\r\n");
			if(!bQD)
			{
				if(!bDa)	
					rt_printf("角差不满足要求\r\n");
				else if(!bDu)	
					rt_printf("压差不满足要求\r\n");
				else if(!bDf)	
					rt_printf("频差 不满足要求\r\n");
				else 
					rt_printf("PT异常！ 不满足要求\r\n");
			}
				
			//rt_printf("QD=%d %d\r\n",FUN_ALL_EN(sw),pSW->tTQQDTime.boolTrip);
			//rt_printf("pt1=%d pt2=%d ang2=%d  pt断线=%d:%d\r\n",g_ui[PUB_AC_UAB1].p/65536,g_ui[pRunSet->pt2vol].p/65536,ang2/65536,tPT.uPT1DX.bFlag.bPTYC,tPT.uPT2DX.bFlag.bPTYC);
			//rt_printf("pSetA=%d deltaA=%d bQD=%d bMxYY=%d bMxWY=%d bUxYY=%d bUxWY=%d  \r\n",pSet->dA_tq_delatA/65536,_AbsL(deltaA)/65536,bQD,bMxYY,bMxWY,bUxYY,bUxWY);
			//rt_printf("角差=%d, 压差=%d bDf=%d pSW->uTQHz.bFlag.bQD=%d\r\n\r\n",bDa,bDu,bDf,pSW->uTQHz.bFlag.bQD);		
			printf_Pro_TQHz=0;
		}
		if(!pSW->tTQQDTime.boolTrip)
			printf_Pro_TQHz=1;
		#endif

		if(pSW->uTQHz.bFlag.bHz)
		{
			if (!pSW->uTQHz.bFlag.bEvent)
			{
				if(!pR->uRmtSW.bHandHz)
				{
			       	pR->uRmtSW.bHandHz_fa = true;
			    }
			    	sw_do(sw,SW_DO_YKH,SW_DO_TYPE_ON);  //合环合闸开出遥控出口
			    	sw_do(sw,SW_DO_HZ,SW_DO_TYPE_ON);  //合环合闸开出遥控出口
				soe_record_ev(EV_TQHZ+sw*EV_SW_NUM, 1, 0,0,0 );
				pSW->uTQHz.bFlag.bEvent = true;
			}
		}
		else
		{
			if (pSW->uTQHz.bFlag.bEvent)
			{
				soe_record_ev(EV_TQHZ+sw*EV_SW_NUM, 0, 0,0,0 );
				pSW->uTQHz.bFlag.bEvent = false;
				ResetTR(&pSW->tTQTime);
			}
		}
	}
}
//手动操作同期合闸检测
void Pro_TQBS(int sw,DWORD  dStep)
{
	bool bQD,bTQ=false;
	TRELAY_T *pR=&g_tRelay[sw];
	//TTQHZ_T *pSW = &pR->tTQHz;
	TSETSW *pSet = &pRunSet->tSwSet[sw];

    // 合环合闸
    long deltaA;
    bool bMxYY,bMxWY,bUxYY,bUxWY,bDa,bDu,bDf;
    qs16 ang1=0,ang2=0;

    if(pRunSet->pt2vol==PUB_AC_UAB1)ang2=0;
    else if(pRunSet->pt2vol==PUB_AC_UBC1)ang2=-120*65536;
    else if(pRunSet->pt2vol==PUB_AC_UCA1)ang2=120*65536;
    else if(pRunSet->pt2vol==PUB_AC_UAB2)ang2=0;
    else if(pRunSet->pt2vol==PUB_AC_UBC2)ang2=-120*65536;
    else if(pRunSet->pt2vol==PUB_AC_UCA2)ang2=120*65536;
    

    bMxYY = OverRelay(g_sw_pub.m2_max[2], pSet->dU_chz_yy,pSet->dU_chz_yy,false); 
    bMxWY = LowRelay(g_sw_pub.m2_max[2], pSet->dU_chz_wy,pSet->dU_chz_wy,false); 
    bUxYY = OverRelay(g_ui[pRunSet->pt2vol].m2[0], pSet->dU_chz_yy,pSet->dU_chz_yy,false); 
    bUxWY = LowRelay(g_ui[pRunSet->pt2vol].m2[0], pSet->dU_chz_wy,pSet->dU_chz_wy,false); 
    deltaA = _AbsL((g_ui[PUB_AC_UAB1].p -ang1)- (g_ui[pRunSet->pt2vol].p-ang2));
    bDa=(((_AbsL(deltaA) < pSet->dA_tq_delatA)?true:false)||(pSet->dA_tq_delatA==0)); //角差满足要求，角差为零，不判角差
    bDu=((_AbsL(g_ui[PUB_AC_UAB1].fz -g_ui[pRunSet->pt2vol].fz)<pSet->dU_tq_deltaU)?true:false)||(pSet->dU_tq_deltaU==0); //压差满足要求
    bDf= ((_AbsL(g_sw_pub.ac_in[PUB_AC_IN_F1] - g_sw_pub.ac_in[PUB_AC_IN_F2])<pSet->dF_tq_deltaF)?true:false)||(pSet->dF_tq_deltaF==0);//频差


    bQD=((bDa&&bDu&&bDf&&bMxYY&&bUxYY&&(!tPT.uPT1DX.bFlag.bPTYC)&&(!tPT.uPT2DX.bFlag.bPTYC))
        ||(bMxWY&&(!tPT.uPT1DX.bFlag.bPTYC))
        ||(bUxWY&&(!tPT.uPT2DX.bFlag.bPTYC)));  //压差，角差，频差满足要求，或有一侧无压

    bTQ =  (!TYTQ_ALL_EN(sw)) && !bQD;	// 合环合闸投入
	
	if(bTQ)
		sw_do(sw,SW_DO_TQBS,SW_DO_TYPE_ON);//不同期
	else
		sw_do(sw,SW_DO_TQBS,SW_DO_TYPE_OFF);//同期
#ifdef GD_AREA_CHAOZHOU_CHAOAN_FUYANG
	//同期合闸开出-常闭"
	if(!bTQ)
		sw_do(sw,SW_DI_TQBS_CLOSE,SW_DO_TYPE_ON);//不同期
	else
		sw_do(sw,SW_DI_TQBS_CLOSE,SW_DO_TYPE_OFF);//同期
#endif	
}

enum
{
	HC_UAB1=0,
	HC_UBC1,
	HC_UCA1,
	HC_UAB2,
	HC_UBC2,
	HC_UCA2,
	HC_FREQ,
	HC_VT,
	HC_FT,
	HC_NUMS,
};

DWORD     dhcbsBuf[32][HC_NUMS];        // 滑差闭锁缓冲区，含频率和两组电压
WORD      whcCnt;                //滑差缓冲区指针
DWORD dTcounterrem;

void hcbs_init(void)
{
	int i;
	whcCnt=0;				  //滑差电压缓冲区指针
	for(i=0;i<32;i++)
	{
		int j;
		DWORD v=(DWORD)(100.0*pRunSet->dKU[PUB_AC_UAB1]/256);
		for(j=HC_UAB1;j<=HC_UCA2;j++)
		{
			dhcbsBuf[i][j]=v;
		}	
		dhcbsBuf[i][HC_FREQ]	=50<<16;  //频率缓冲区:  频率,频率刷新时刻
		dhcbsBuf[i][HC_VT]	=0;
		dhcbsBuf[i][HC_FT]	=0;
	}
}
void hcbs_dataset(void)
{
	whcCnt = ( whcCnt + 1 ) & 0x1f;
	dhcbsBuf[whcCnt][HC_UAB1] = g_ui[PUB_AC_UAB1].fz;		
	dhcbsBuf[whcCnt][HC_UBC1] = g_ui[PUB_AC_UBC1].fz;		
	dhcbsBuf[whcCnt][HC_UCA1] = g_ui[PUB_AC_UCA1].fz;		
	dhcbsBuf[whcCnt][HC_UAB2] = g_ui[PUB_AC_UAB2].fz;		
	dhcbsBuf[whcCnt][HC_UBC2] = g_ui[PUB_AC_UBC2].fz;		
	dhcbsBuf[whcCnt][HC_UCA2] = g_ui[PUB_AC_UCA2].fz;		
	dhcbsBuf[whcCnt][HC_FREQ] = freq_get(0)*65536;			
	dhcbsBuf[whcCnt][HC_VT] =dTcounterrem;			 		
	dhcbsBuf[whcCnt][HC_FT] =dTcounterrem;		 		
}

bool hcbs_vol(int sw,int type)  //电压滑差判断
{
	long   lTsubV;
	long   lDeltaVol;
	TSETSW *pSet = &pRunSet->tSwSet[sw];

	lTsubV = dhcbsBuf[ whcCnt ][ HC_VT ]                          //获取当前时刻
			- dhcbsBuf[ ( whcCnt - 15 ) & 0x1f ][ HC_VT ];      //获取15次软件中断前采样时刻

	if(lTsubV <= 0 ) 
	{    
		return( false );
	}

	lDeltaVol =   dhcbsBuf[ ( whcCnt - 15 ) & 0x1f ][type]    //获取当前采样
			- dhcbsBuf[ whcCnt ][type];                     //获取15*5MS前电压

	if( lDeltaVol < 0 ) 
	{
		return false;
	}
#if 0  //调试信息
	if(type==HC_UAB1)
	{
		float fku=pRunSet->dKU[PUB_AC_UAB1]/256.0;
		if(g_ui[PUB_AC_UAB1].fz<60*fku&&g_ui[PUB_AC_UAB1].fz>50*fku&&(lTsubV > 20) )
		{
			rt_printf("\r\n hc=%.2f %d %d %d %d \r\n",lDeltaVol*1600/lTsubV/fku,lDeltaVol,lTsubV,dhcbsBuf[ ( whcCnt - 15 ) & 0x1f ][type],dhcbsBuf[ whcCnt ][type]);
			g_print_101=0;
		}
	}
#endif	
	if( ((lDeltaVol * 1600) > ((long)pSet->dhcbs_u * lTsubV)) && (lTsubV > 20) ) 
	{
		return true;
	}

	
	return false;

}

bool hcbs_freq(int sw) //频率滑差判断
{
	long	lTsub;
	long	lDeltaF;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	
	 lTsub = dhcbsBuf[ ( whcCnt ) & 0x1f ][HC_FT] 		 //获取当前频率采样时刻
			 - dhcbsBuf[ ( whcCnt - 4 ) & 0x1f ][HC_FT];	 //获取5周前频率采样时刻

	 if( lTsub < 0 )
	 {
		  return( false );
	 }

	 lDeltaF = dhcbsBuf[ ( whcCnt - 4 ) & 0x1f ][HC_FREQ]	  //获取5周频率采样
			  - dhcbsBuf[ whcCnt	& 0x1f ][HC_FREQ];		  //获取当前频率采样	  ΔF = |f - fm|;

	 if( lDeltaF < 0 )
	 {
		return false;
	 }
	 
	 //if( lDeltaF * 1600 > pRunSet->dDP_DELTAF * lTsub )
	 if( lDeltaF * 400 > (( (long)(pSet->dhcbs_hz) * lTsub )/4 ))
	 {
		return true ;						 //滑差闭锁确认
	 }
	 return false;

}




//获取电压通道信息
static int get_vol_index(int ac_index)
{
	if(PUB_AC_UAB1==ac_index || PUB_AC_UBC1==ac_index || PUB_AC_UCA1==ac_index)
		if(g_equ_config_ac[0].type-1 == PUB_AC_UAB2)
			return (PUB_AC_UAB2+(ac_index-PUB_AC_UAB1));

	if(PUB_AC_UA1==ac_index || PUB_AC_UB1==ac_index || PUB_AC_UC1==ac_index)
			if(g_equ_config_ac[0].type-1 == PUB_AC_UA2)
				return (PUB_AC_UA2+(ac_index-PUB_AC_UA1));
	return ac_index;
}
#define IS_VOL_CHANNEL_TYPE (g_equ_config_ac[0].type-1==PUB_AC_UAB2 || g_equ_config_ac[0].type-1==PUB_AC_UA2)
void vol_DYJL(int sw,DWORD  dStep)   // 电压解列
{
	bool  bQDD1,bQDD2;  			
	TRELAY_T *pR=&g_tRelay[sw];
	TJL_T*pJL=&pR->tDYJL;
	TSWST *pSWST =&pR->tSWST;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bool bhcbs;
	
	
	/***********启动	**********************************/	
	if(IS_VOL_CHANNEL_TYPE)
		bQDD1 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_jl_ggdy,pSet->dU_jl_ggdy_fh,pJL->sta.bFlag.bQD_H); 
	else	
		bQDD1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_jl_ggdy,pSet->dU_jl_ggdy_fh,pJL->sta.bFlag.bQD_H); 

	pJL->sta.bFlag.bQD_H = SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_dy//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&bQDD1;


	/***********过高压分闸*********************************/
	RunTR(&pJL->tHighTime, pJL->sta.bFlag.bQD_H, dStep);
	pJL->sta.bFlag.bTz_H = pJL->tHighTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_H) 
	{
		if(soe_check(EV_GGDY_TZ+sw*EV_SW_NUM)==false)   // 
		{
			DWORD Uab,Ubc,Uca;		
			Uab = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UAB1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UAB1)]);
			Ubc = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UBC1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UBC1)]);
			Uca = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UCA1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UCA1)]);
			soe_record_ev( EV_GGDY_TZ+sw*EV_SW_NUM, 1, Uab,Ubc,Uca );  			
			pJL->bLed= true;
		}
	}
	else
	{
		if(soe_check(EV_GGDY_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_GGDY_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 

	if(IS_VOL_CHANNEL_TYPE)
		bQDD2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_jl_gdy,pSet->dU_jl_gdy_fh,pJL->sta.bFlag.bQD_G); 
	else
		bQDD2 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_jl_gdy,pSet->dU_jl_gdy_fh,pJL->sta.bFlag.bQD_G); 

	pJL->sta.bFlag.bQD_G = SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_dy//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&(!bQDD1&&bQDD2);

	/***********过压分闸*********************************/
	RunTR(&pJL->tGdyTime, pJL->sta.bFlag.bQD_G, dStep);
	pJL->sta.bFlag.bTz_G = pJL->tGdyTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_G) 
	{
		if(soe_check(EV_GDY_TZ+sw*EV_SW_NUM)==false)   // 
		{
			DWORD Uab,Ubc,Uca;		
			Uab = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UAB1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UAB1)]);
			Ubc = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UBC1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UBC1)]);
			Uca = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UCA1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UCA1)]);
			soe_record_ev( EV_GDY_TZ+sw*EV_SW_NUM, 1, Uab,Ubc,Uca );  			
			pJL->bLed= true;
		}
	}
	else
	{
		if(soe_check(EV_GDY_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_GDY_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 

	if(IS_VOL_CHANNEL_TYPE)
	{
		bQDD1 = LowRelay(g_sw_pub.m2_max[3], pSet->dU_jl_gddy,pSet->dU_jl_gddy_fh,pJL->sta.bFlag.bQD_L); 
	}
	else
	{
		bQDD1 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_jl_gddy,pSet->dU_jl_gddy_fh,pJL->sta.bFlag.bQD_L); 
	}

	if(IS_VOL_CHANNEL_TYPE)
	{		
		bhcbs=pSet ->bTT_hcbs_dy
				&&(hcbs_vol(sw,HC_UAB2)||hcbs_vol(sw,HC_UBC2)||hcbs_vol(sw,HC_UCA2));
	}
	else
	{
		bhcbs=pSet ->bTT_hcbs_dy
				&&(hcbs_vol(sw,HC_UAB1)||hcbs_vol(sw,HC_UBC1)||hcbs_vol(sw,HC_UCA1));
	}

	pJL->sta.bFlag.bQD_L = SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_dy//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&pR->tSWST.uSWST.bFlag.bCYY		//曾有压
							&&(!tPT.uPT1DX.bFlag.bPTYC)      //无 PT异常
							&&bQDD1;

	RunTR(&pJL->thcbs1_0ms_100ms, pJL->sta.bFlag.bQD_L, dStep);
	pJL->sta.bFlag.bhcbs1=(pJL->thcbs1_0ms_100ms.boolTrip&&pJL->sta.bFlag.bhcbs1)
						||bhcbs;
	/***********过低压分闸*********************************/
	RunTR(&pJL->tLowTime, pJL->sta.bFlag.bQD_L&&(!pJL->sta.bFlag.bhcbs1), dStep);
	pJL->sta.bFlag.bTz_L = pJL->tLowTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_L) 
	{
		if(soe_check(EV_GDDY_TZ+sw*EV_SW_NUM)==false)   // 
		{
			DWORD Uab,Ubc,Uca;		
			Uab = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UAB1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UAB1)]);
			Ubc = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UBC1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UBC1)]);
			Uca = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UCA1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UCA1)]);
			soe_record_ev( EV_GDDY_TZ+sw*EV_SW_NUM, 1, Uab,Ubc,Uca );  			
			pJL->bLed= true;
			pR->tSWST.uSWST.bFlag.bCYY=false;
		}
	}
	else
	{
		if(soe_check(EV_GDDY_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_GDDY_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 
		
	if(IS_VOL_CHANNEL_TYPE)
		bQDD2 = LowRelay(g_sw_pub.m2_max[3], pSet->dU_jl_ddy,pSet->dU_jl_ddy_fh,pJL->sta.bFlag.bQD_D); 
	else
		bQDD2 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_jl_ddy,pSet->dU_jl_ddy_fh,pJL->sta.bFlag.bQD_D); 
	
	pJL->sta.bFlag.bQD_D = SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_dy//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&pR->tSWST.uSWST.bFlag.bCYY		//曾有压
							&&(!tPT.uPT1DX.bFlag.bPTYC)      //无 PT异常
							&&(!bQDD1&&bQDD2);

	RunTR(&pJL->thcbs2_0ms_100ms, pJL->sta.bFlag.bQD_D, dStep);
	pJL->sta.bFlag.bhcbs2=(pJL->thcbs2_0ms_100ms.boolTrip&&pJL->sta.bFlag.bhcbs2)
						||bhcbs;
	/***********低压分闸*********************************/
	RunTR(&pJL->tDdyTime, pJL->sta.bFlag.bQD_D&&(!pJL->sta.bFlag.bhcbs2), dStep);
	pJL->sta.bFlag.bTz_D = pJL->tDdyTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_D) 
	{
		if(soe_check(EV_DDY_TZ+sw*EV_SW_NUM)==false)   // 
		{
			DWORD Uab,Ubc,Uca;		
			Uab = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UAB1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UAB1)]);
			Ubc = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UBC1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UBC1)]);
			Uca = _Mul_Div_U(sqrt_32fix(g_ui[get_vol_index(PUB_AC_UCA1)].m2[0]), 256, pRunSet->dKU[get_vol_index(PUB_AC_UCA1)]);
			soe_record_ev( EV_DDY_TZ+sw*EV_SW_NUM, 1, Uab,Ubc,Uca );  			
			pJL->bLed= true;
			pR->tSWST.uSWST.bFlag.bCYY=false;
		}
	}
	else
	{
		if(soe_check(EV_DDY_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_DDY_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 

	pJL->sta.bFlag.bTz =pJL->sta.bFlag.bTz_H||pJL->sta.bFlag.bTz_L||pJL->sta.bFlag.bTz_G||pJL->sta.bFlag.bTz_D;
	pJL->sta.bFlag.bQD=pJL->sta.bFlag.bQD_H||pJL->sta.bFlag.bQD_L||pJL->sta.bFlag.bQD_G||pJL->sta.bFlag.bQD_D;
	
}


void vol_PLJL(int sw,DWORD  dStep)   // 频率解列
{
	bool  bQDD1,bQDD2;  			
	TRELAY_T *pR=&g_tRelay[sw];
	TJL_T*pJL=&pR->tPLJL;
	TSWST *pSWST =&pR->tSWST;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	DWORD freq=freq_get(0)*65536;
	bool bhcbs;
	bhcbs=pSet ->bTT_hcbs_hz&&hcbs_freq(sw);	
	
	
	/***********频率过低启动	**********************************/	
	bQDD1 = LowRelay(freq, pSet->dU_jl_lowhz,pSet->dU_jl_lowhz_fh,pJL->sta.bFlag.bQD_L); 
	pJL->sta.bFlag.bQD_L = SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_hz//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&(freq>44*65536)  //频率大于44hz，不然认为无频率
							&&(bQDD1);
	RunTR(&pJL->thcbs1_0ms_100ms, pJL->sta.bFlag.bQD_L, dStep);
	pJL->sta.bFlag.bhcbs1=(pJL->thcbs1_0ms_100ms.boolTrip&&pJL->sta.bFlag.bhcbs1)
						||bhcbs;							

	/***********过低频解列*********************************/
	//RunTR(&pJL->tLowTime, pJL->sta.bFlag.bQD_L, dStep);
	RunTR2(&pJL->tLowTime, pJL->sta.bFlag.bQD_L&&(!pJL->sta.bFlag.bhcbs1), dStep);
	pJL->sta.bFlag.bTz_L = pJL->tLowTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_L) 
	{
		if(soe_check(EV_LOWPL_TZ+sw*EV_SW_NUM)==false)   // 
		{
			soe_record_ev( EV_LOWPL_TZ+sw*EV_SW_NUM, 1, freq,0,0 );  			
			pJL->bLed= true;
		}
	}
	else
	{
		if(soe_check(EV_LOWPL_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_LOWPL_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 
	/***********低频解列*********************************/

	bQDD2 = LowRelay(freq, pSet->dU_jl_dhz,pSet->dU_jl_dhz_fh,pJL->sta.bFlag.bQD_D); 
	pJL->sta.bFlag.bQD_D= SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_hz//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&(!bQDD1&&bQDD2);

	RunTR(&pJL->thcbs2_0ms_100ms, pJL->sta.bFlag.bQD_D, dStep);
	pJL->sta.bFlag.bhcbs2=(pJL->thcbs2_0ms_100ms.boolTrip&&pJL->sta.bFlag.bhcbs2)
						||bhcbs;

	RunTR(&pJL->tDhzTime, pJL->sta.bFlag.bQD_D&&(!pJL->sta.bFlag.bhcbs2), dStep);
	pJL->sta.bFlag.bTz_D = pJL->tDhzTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_D) 
	{
		if(soe_check(EV_DPL_TZ+sw*EV_SW_NUM)==false)   // 
		{
			soe_record_ev( EV_DPL_TZ+sw*EV_SW_NUM, 1, freq,0,0 );  			
			pJL->bLed= true;
		}
	}
	else
	{
		if(soe_check(EV_DPL_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_DPL_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 

	/***********高频解列*********************************/

	bQDD1 = OverRelay(freq, pSet->dU_jl_ghz,pSet->dU_jl_ghz_fh,pJL->sta.bFlag.bQD_H); 
	pJL->sta.bFlag.bQD_H= SOFE_AUTO_EN(sw)
							&& pSet->bTT_jl_hz//投退字
							&& pRunSet->bTT_JL_YB
							&&pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&&bQDD1;

	RunTR(&pJL->tHighTime, pJL->sta.bFlag.bQD_H, dStep);
	pJL->sta.bFlag.bTz_H = pJL->tHighTime.boolTrip;		
					
	/************事件记录及出口****************************/
	if(pJL->sta.bFlag.bTz_H) 
	{
		if(soe_check(EV_GPL_TZ+sw*EV_SW_NUM)==false)   // 
		{
			soe_record_ev( EV_GPL_TZ+sw*EV_SW_NUM, 1, freq,0,0);  			
			pJL->bLed= true;
		}
	}
	else
	{
		if(soe_check(EV_GPL_TZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev( EV_GPL_TZ+sw*EV_SW_NUM, 0, 0,0,0 );  			
		}
	} 

	pJL->sta.bFlag.bTz=pJL->sta.bFlag.bTz_H||pJL->sta.bFlag.bTz_L||pJL->sta.bFlag.bTz_D;
	pJL->sta.bFlag.bQD=pJL->sta.bFlag.bQD_H||pJL->sta.bFlag.bQD_L||pJL->sta.bFlag.bQD_D;

}



 TPTCHECK_T	tPT;
#define ANG_PHASEYC  (15*65536)
void PT_Check(DWORD  dStep)
{
	bool bsxyl=false;
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
	DWORD Umin_tmp=0;
	DWORD U_WY=0;
#endif
/***********PT 异常判断**********************************/
	{
		int sw;
		DWORD Umax,Umin;
		bool bCheck=false;
		bool bpt1check=false;
		bool bpt2check=false;
		for(sw=0;sw<SWITCH_NUM_MAX;sw++)
		{
			bool bptdx;
			bsxyl|=(g_sw[sw].m2_max>pRunSet->dIWL_SQR[sw]);  //三相无流
			bptdx=((BH_ALL_EN(sw)&&pRunSet->tSwSet[sw].bTT_bh_ptdx)
					||(FA_ALL_EN(sw)&&pRunSet->tSwSet[sw].bTT_fa_ptdx));
			bpt1check|=bptdx;
			bpt2check|=(bptdx&&(pRunSet->a_side_pt_type));// pt2 vv接线
#ifdef GD_AREA_MAIN_2020
            bpt1check&=pRunSet->tSwSet[sw].bTT_PT1_ll_check;
            bpt2check&=pRunSet->tSwSet[sw].bTT_PT2_ll_check;
#endif
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			if(Umin_tmp < pRunSet->tSwSet[sw].dU_fa_YY)
			{
				Umin_tmp = pRunSet->tSwSet[sw].dU_fa_YY;
			}
			if(U_WY < pRunSet->tSwSet[sw].dU_fa_WY)
			{
				U_WY = pRunSet->tSwSet[sw].dU_fa_WY;
			}
#endif
		}

		/*********PT1断线判断***************************/

		//判断电压配置，只有在配置了Ua Ub Uc 或Uab Ubc Uca后，才进行断线检查
		bCheck=(((short)g_sw_pub.ac_cfg_index[PUB_AC_UA1] != INDEX_INVALLID)
				&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UB1] != INDEX_INVALLID)
				&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UC1] != INDEX_INVALLID))||
				(((short)g_sw_pub.ac_cfg_index[PUB_AC_UAB1] != INDEX_INVALLID)
				&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UBC1] != INDEX_INVALLID));
		Umax=g_sw_pub.m2_max[2];
		Umin=g_sw_pub.m2_min[2];
	#ifdef GD_AREA_SHANTOU
		tPT.uPT1DX.bFlag.bQD=(((Umax<pRunSet->dVOL16V_SQR)&&((((FA_ALL_EN(0) && !g_tRelay[0].run_stu.fa_ls) || BH_ALL_EN(0)) && bsxyl )//三相断线:无压有流(非Fa联络)
		                                                      ||(FA_ALL_EN(0) && g_tRelay[0].run_stu.fa_ls))) //三相断线:三相断线(Fa联络)
									||((Umax>pRunSet->dVOL50V_SQR)&&(Umin<pRunSet->dVOL16V_SQR))// 两相断线最小值小于16V，最大值大于50V
									||((Umax>pRunSet->dVOL90V_SQR)&&(Umin<pRunSet->dVOL70V_SQR)))// 最小值小于71V，最大值大于90V
									&&bCheck
									&&bpt1check;
	#else
		tPT.uPT1DX.bFlag.bQD=(((Umax<pRunSet->dVOL16V_SQR)&&(bsxyl)) //三相断线，无压有流
							||((Umax>pRunSet->dVOL50V_SQR)&&(Umin<pRunSet->dVOL16V_SQR))// 两相断线最小值小于16V，最大值大于50V
							||((Umax>pRunSet->dVOL90V_SQR)&&(Umin<pRunSet->dVOL70V_SQR)))// 最小值小于71V，最大值大于90V
							&&bCheck
							&&bpt1check;
    #endif
		RunTR(&tPT.tTPT1DXTime, tPT.uPT1DX.bFlag.bQD, dStep);

		if(tPT.tTPT1DXTime.boolTrip) 
		{
			if(!tPT.uPT1DX.bFlag.bEvent) 			
			{
				DWORD Uab,Ubc,Uca;
				Uab = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UAB1].m2[0]), 256, g_ui[PUB_AC_UAB1].m2_factor_k);
				Ubc = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UBC1].m2[0]), 256, g_ui[PUB_AC_UBC1].m2_factor_k);
				Uca = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UCA1].m2[0]), 256, g_ui[PUB_AC_UCA1 ].m2_factor_k);				

				soe_record_ev(EV_PT1ERR,1, Uab,Ubc,Uca);                                          
				tPT.uPT1DX.bFlag.bEvent=true;
				tPT.uPT1DX.bFlag.bPTYC=true;
			}
		}
		else
		{
		#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			if(Umin >= Umin_tmp)
		#endif
			{
				if(tPT.uPT1DX.bFlag.bEvent) 						
				{
					soe_record_ev(EV_PT1ERR,0, 0,0,0 ); 										 
					tPT.uPT1DX.bFlag.bEvent=false;
					tPT.uPT1DX.bFlag.bPTYC=false;
		
				}
			}
		}
		//PT1相序检查
		{
			bool bok;
			u32 da,db,dc;
			if(((short)g_sw_pub.ac_cfg_index[PUB_AC_UA1] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UB1] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UC1] != INDEX_INVALLID))  // 相电压接线
			{
					da = _AbsL(g_ui[PUB_AC_UA1].p - g_ui[PUB_AC_UB1].p-120*65536);
					db = _AbsL(g_ui[PUB_AC_UB1].p - g_ui[PUB_AC_UC1].p+240*65536);
					dc = _AbsL(g_ui[PUB_AC_UA1].p - g_ui[PUB_AC_UC1].p+120*65536);
					Umin=g_sw_pub.m2_min[0];

			}
			else  //线电压接线
			{                               
					da = _AbsL(g_ui[PUB_AC_UAB1].p - g_ui[PUB_AC_UBC1].p-120*65536);
					db = _AbsL(g_ui[PUB_AC_UBC1].p - g_ui[PUB_AC_UCA1].p+240*65536);
					dc = _AbsL(g_ui[PUB_AC_UAB1].p - g_ui[PUB_AC_UCA1].p+120*65536);
					Umin=g_sw_pub.m2_min[2];
			}
			bok=pRunSet->bTT_CheckPhase
				&&(Umin>pRunSet->dVOL16V_SQR)  //最小电压大于16V
				&&bCheck
				&&((da>ANG_PHASEYC)||(db>ANG_PHASEYC)||(dc>ANG_PHASEYC));  //三相电压角度差15度

			RunTR(&tPT.tTPT1XXYC, bok, dStep);

			if(tPT.tTPT1XXYC.boolTrip) 
			{
				if(soe_check(EV_PT1XXYC)==false)   // 
				{
					soe_record_ev(EV_PT1XXYC, 1, 0,0,0 );
				}

			}
			else
			{
				if(soe_check(EV_PT1XXYC)==true)   // 
				{
					soe_record_ev(EV_PT1XXYC, 0, 0,0,0 );
				}
			}
		}

		/*********PT2断线判断***************************/
		Umax=g_sw_pub.m2_max[3];
		Umin=g_sw_pub.m2_min[3];

		//判断电压配置，只有在配置了Ua Ub Uc 或Uab Ubc Uca后，才进行断线检查
		bCheck=(((short)g_sw_pub.ac_cfg_index[PUB_AC_UA2] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UB2] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UC2] != INDEX_INVALLID))
			#ifdef FUNC_PT_ERR_SINGLE
				||(((short)g_sw_pub.ac_cfg_index[PUB_AC_UAB2] != INDEX_INVALLID)
					|| ((short)g_sw_pub.ac_cfg_index[PUB_AC_UBC2] != INDEX_INVALLID)
					|| ((short)g_sw_pub.ac_cfg_index[PUB_AC_UCA2] != INDEX_INVALLID))
			#else
				||(((short)g_sw_pub.ac_cfg_index[PUB_AC_UAB2] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UBC2] != INDEX_INVALLID))
			#endif
					;

	#ifdef GD_AREA_SHANTOU
		tPT.uPT2DX.bFlag.bQD=(((Umax<pRunSet->dVOL16V_SQR)&&((((FA_ALL_EN(0) && !g_tRelay[0].run_stu.fa_ls) || BH_ALL_EN(0)) && bsxyl )//三相断线:无压有流(非Fa联络)
		                                                      ||(FA_ALL_EN(0) && g_tRelay[0].run_stu.fa_ls))) //三相断线:三相断线(Fa联络)
									||((Umax>pRunSet->dVOL50V_SQR)&&(Umin<pRunSet->dVOL16V_SQR))// 两相断线最小值小于16V，最大值大于50V
									||((Umax>pRunSet->dVOL90V_SQR)&&(Umin<pRunSet->dVOL70V_SQR)))// 最小值小于71V，最大值大于90V
									&&bCheck
									&&bpt2check;
	#else
		tPT.uPT2DX.bFlag.bQD=(((Umax<pRunSet->dVOL16V_SQR)&&(bsxyl)) //三相断线，无压有流
							|((Umax>pRunSet->dVOL50V_SQR)&&(Umin<pRunSet->dVOL16V_SQR))// 两相断线最小值小于16V，最大值大于50V
							|((Umax>pRunSet->dVOL90V_SQR)&&(Umin<pRunSet->dVOL70V_SQR)))// 最小值小于71V，最大值大于90V
							&&bCheck
							&&bpt2check;
    #endif  
		RunTR(&tPT.tTPT2DXTime, tPT.uPT2DX.bFlag.bQD, dStep);

		if(tPT.tTPT2DXTime.boolTrip) 
		{
			if(!tPT.uPT2DX.bFlag.bEvent) 			
			{
				DWORD Uab,Ubc,Uca;
				Uab = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UAB2].m2[0]), 256, g_ui[PUB_AC_UAB2].m2_factor_k);
				Ubc = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UBC2].m2[0]), 256, g_ui[PUB_AC_UBC2].m2_factor_k);
				Uca = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_UCA2].m2[0]), 256, g_ui[PUB_AC_UCA2].m2_factor_k);
				soe_record_ev(EV_PT2ERR,1, Uab,Ubc,Uca );                                          
				tPT.uPT2DX.bFlag.bEvent=true;
				tPT.uPT2DX.bFlag.bPTYC=true;
			}
		}
		else
		{
		#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			if(Umin >= Umin_tmp)
		#endif
			{
				if(tPT.uPT2DX.bFlag.bEvent) 						
				{
					soe_record_ev(EV_PT2ERR,0, 0,0,0 ); 										 
					tPT.uPT2DX.bFlag.bEvent=false;
					tPT.uPT2DX.bFlag.bPTYC=false;
				}
			}
		}
		//PT2相序检查
		{
			bool bok;
			u32 da,db,dc;
			if(((short)g_sw_pub.ac_cfg_index[PUB_AC_UA2] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UB2] != INDEX_INVALLID)
					&&((short)g_sw_pub.ac_cfg_index[PUB_AC_UC2] != INDEX_INVALLID))  // 相电压接线
			{
					da = _AbsL(g_ui[PUB_AC_UA2].p - g_ui[PUB_AC_UB2].p-120*65536);
					db = _AbsL(g_ui[PUB_AC_UB2].p - g_ui[PUB_AC_UC2].p+240*65536);
					dc = _AbsL(g_ui[PUB_AC_UA2].p - g_ui[PUB_AC_UC2].p+120*65536);
					Umin=g_sw_pub.m2_min[1];

			}
			else  //线电压接线
			{
					da = _AbsL(g_ui[PUB_AC_UAB2].p - g_ui[PUB_AC_UBC2].p-120*65536);
					db = _AbsL(g_ui[PUB_AC_UBC2].p - g_ui[PUB_AC_UCA2].p+240*65536);
					dc = _AbsL(g_ui[PUB_AC_UAB2].p - g_ui[PUB_AC_UCA2].p+120*65536);
					Umin=g_sw_pub.m2_min[3];
			}
			bok=pRunSet->bTT_CheckPhase
				&&(Umin>pRunSet->dVOL16V_SQR)  //最小电压大于16V
				&&bCheck
				&&((da>ANG_PHASEYC)||(db>ANG_PHASEYC)||(dc>ANG_PHASEYC));  //三相电压角度差15度

			RunTR(&tPT.tTPT2XXYC, bok, dStep);

			if(tPT.tTPT2XXYC.boolTrip) 
			{
				if(soe_check(EV_PT2XXYC)==false)   // 
				{
					soe_record_ev(EV_PT2XXYC, 1, 0,0,0 );
				}

			}			
			else
			{
				if(soe_check(EV_PT2XXYC)==true)   // 
				{
					soe_record_ev(EV_PT2XXYC, 0, 0,0,0 );
				}
			}
		}		
	}
	
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
	if((g_sw_pub.m2_min[2]<U_WY) && !bsxyl && tPT.uPT1DX.bFlag.bEvent)
	{
		ResetTR(&tPT.tTPT1DXTime);	//清PT断线计时器避免返回时间内一直刷屏PT断线SOE
		if(soe_check(EV_PT1ERR))
		{
			soe_record_ev(EV_PT1ERR,0, 0,0,0 );
		}
		tPT.uPT1DX.bFlag.bEvent=false;
		tPT.uPT1DX.bFlag.bPTYC=false;
	}
	if((g_sw_pub.m2_min[3]<U_WY) && !bsxyl && tPT.uPT2DX.bFlag.bEvent)
	{
		ResetTR(&tPT.tTPT2DXTime);	//清PT断线计时器避免返回时间内一直刷屏PT断线SOE
		if(soe_check(EV_PT2ERR))
		{
			soe_record_ev(EV_PT2ERR,0, 0,0,0 );
		}
		tPT.uPT2DX.bFlag.bEvent=false;
		tPT.uPT2DX.bFlag.bPTYC=false;
	}
#endif
}



void FDL_Check(DWORD    dStep)
{
	int i;
	struct equ_config_di *ecd;	
	
	int sw=0;
	for(i=0;i<8;i++)  //非电量跳闸
	{
		bool byx=false;
		TFDL_T*pFDL=&g_tRelay[sw].tFdl[i];
		if ((short)g_sw_pub.di_cfg_index[PUB_DI_FDL1+i] != INDEX_INVALLID)	
		{
			ecd = &g_equ_config_di[g_sw_pub.di_cfg_index[PUB_DI_FDL1+i]];
			byx = dido_di_is_on(ecd->slot,ecd->index);
		}
		pFDL->sta.bFlag.bQD=byx&&(pRunSet->bTT_FDLGj[i]||pRunSet->bTT_FDLTz[i]);
		
		RunTR(&pFDL->tFdlTime, pFDL->sta.bFlag.bQD, dStep);

		pFDL->sta.bFlag.bTz=pFDL->tFdlTime.boolTrip&&pRunSet->bTT_FDLTz[i];
		pFDL->sta.bFlag.bGj=pFDL->tFdlTime.boolTrip&&pRunSet->bTT_FDLGj[i];
		if(pFDL->sta.bFlag.bTz)
		{
			if(soe_check(EV_FDL1_TZ+i)==false)
			{
				soe_record_ev( EV_FDL1_TZ+i, 1, 0,0,0 ); 
			}
		}
		else
		{
			if(soe_check(EV_FDL1_TZ+i)==true)
			{
				soe_record_ev( EV_FDL1_TZ+i, 0, 0,0,0 ); 
			}

		}
		if(pFDL->sta.bFlag.bGj)
		{
			if(soe_check(EV_FDL1_GJ+i)==false)
			{
				soe_record_ev( EV_FDL1_GJ+i, 1, 0,0,0 ); 
			}
		}
		else
		{
			if(soe_check(EV_FDL1_GJ+i)==true)
			{
				soe_record_ev( EV_FDL1_GJ+i, 0, 0,0,0 ); 
			}
		}
	}

}

void Pro_3U0(int sw,DWORD  dStep)
{
	bool  bQDD; 			
	TRELAY_T *pR=&g_tRelay[sw];
	TU0_T *pSW=&pR->tOVER_U0TZ;
	TSWST *pSWST =&pR->tSWST;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	DWORD U01 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k); 	
	DWORD U02 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U02].m2[0]), 256, g_ui[PUB_AC_U02].m2_factor_k); 	
	
	/***********启动	**********************************/ 
	bQDD = OverRelay(g_ui[PUB_AC_U01].m2[0] >g_ui[PUB_AC_U02].m2[0] ?g_ui[PUB_AC_U01].m2[0]:g_ui[PUB_AC_U02].m2[0],pSet->dBHOverU0,pSet->dBHOverU0_fh,pSW->uZOV.bFlag.bQD);	
	pSW->uZOV.bFlag.bQD = BH_ALL_EN(sw)
							&& (pSet->bTT_3U0Tz||pSet->bTT_3U0Gj)//投退字
							//&& pSWST->uSWST.bFlag.bHZWZ		//在合闸位置
							&& bQDD
							&& (!tPT.uPT1DX.bFlag.bPTYC);
#ifdef EV_GL_STATR
	lx_start_soe_set( pSW->uZOV.bFlag.bQD,sw,EV_U0_STATR);
#endif						
											
	/***********零序过压分闸*********************************/
	RunTR(&pSW->tZOVTime, pSW->uZOV.bFlag.bQD, dStep);
	pSW->uZOV.bFlag.bTz = pSW->tZOVTime.boolTrip && pSet->bTT_3U0Tz && pSWST->uSWST.bFlag.bHZWZ;	
	pSW->uZOV.bFlag.bGJ = pSW->tZOVTime.boolTrip&&pSet->bTT_3U0Gj;	
			
					
	/************事件记录及出口****************************/
	if(pSW->uZOV.bFlag.bTz) 
	{
		if(!pSW->uZOV.bFlag.bEvent) 			
		{
			soe_record_ev( EV_U0TZ+sw*EV_SW_NUM, 1,   U01>U02?U01:U02,0,0 );	
	
			rcd_start(sw,RECORD_TYPE_LXDY, RECORD_LEN_TZQD);	
			pSW->uZOV.bFlag.bEvent = true;	
			pSW->bU0Led = true;
		}
	}
	else
	{
		if(pSW->uZOV.bFlag.bEvent)						
		{
			soe_record_ev(EV_U0TZ+sw*EV_SW_NUM, 0, 0,0,0 );    
			pSW->uZOV.bFlag.bEvent = false;
			pSW->uZOV.bFlag.bU0Ov = false;
		}
	} 

	/************告警记录****************************/
	if(pSW->uZOV.bFlag.bGJ) 
	{
		if(!pSW->uZOV.bFlag.bGJEvent) 			
		{
			soe_record_ev( EV_U0GJ+sw*EV_SW_NUM, 1,   U01>U02?U01:U02,0,0 );	
	
			rcd_start(sw,RECORD_TYPE_LXDY, RECORD_LEN_TZQD);	
			pSW->uZOV.bFlag.bGJEvent = true;	
			if(pSW->bU0Led == false)
			{
				pSW->bU0GjLed = true;
			}
		}
	}
	else
	{
		if(pSW->uZOV.bFlag.bGJEvent)						
		{
			soe_record_ev(EV_U0GJ+sw*EV_SW_NUM, 0, 0,0,0 );    
			pSW->uZOV.bFlag.bGJEvent = false;
			pSW->uZOV.bFlag.bU0Ov = false;
		}
	} 

}


#ifdef	CUSTOMIZE_BZT //备自投
void vol_lost_tz(int sw, DWORD      dStep)  // 失压跳闸
{
	bool  bQDD1, bQDD2,pt1cyy,pt2cyy;  		
	VOL_SET *pSet = &pRunSet->tVolLostSet;
	TVOL_T *pvol = &g_tVolLost;
	DWORD pt1_value,pt2_value;	
	TRELAY_T *pR = &g_tRelay[sw];
	UBZT *uBZT   = &pR->tBzt.uBZT; 

	pt1_value = g_sw_pub.m2_max[2];
	pt2_value = g_sw_pub.m2_max[3];
	pt1cyy = OverRelay(pt1_value, pSet->dUVol, pSet->dUVol,false); 
	pt2cyy = OverRelay(pt2_value, pSet->dUVol, pSet->dUVol,false); 
	//曾有压
	RunTR(&pvol->tCYYTime, pt1cyy || pt2cyy, dStep);
	pvol->sta.bFlag.bCYY = pvol->tCYYTime.boolTrip || pvol->sta.bFlag.bCYY;
	/***********启动	**********************************/		
	bQDD1 = LowRelay(pt1_value, pSet->dUVol, pSet->dUVol_fh, pvol->sta.bFlag.bQD); 
	bQDD2 = LowRelay(pt2_value, pSet->dUVol, pSet->dUVol_fh, pvol->sta.bFlag.bQD); 	
	pvol->sta.bFlag.bQD = bQDD1 && bQDD2 && pvol->sta.bFlag.bCYY && pSet->bTT && pR->tSWST.uSWST.bFlag.b1DLHW;
	if(!pR->tSWST.uSWST.bFlag.b1DLHW)
		pvol->sta.bFlag.bCYY = 0;
	/***********失压分闸*********************************/
	RunTR(&pvol->tQDTime, pvol->sta.bFlag.bQD, dStep);
	pvol->sta.bFlag.bTz = pvol->tQDTime.boolTrip;
	//pvol->sta.bFlag.bGJ = pvol->tQDTime.boolTrip;		
	/************事件记录及出口****************************/
	if(pvol->sta.bFlag.bTz) 
	{
		pvol->sta.bFlag.bCYY = false;
		if(!pvol->sta.bFlag.bEvent) 			
		{
			DWORD Us1,Us2;	
			
			Us1 = _Mul_Div_U(sqrt_32fix(pt1_value), 256, pRunSet->dKU[PUB_AC_UAB1]);
			Us2 = _Mul_Div_U(sqrt_32fix(pt2_value), 256, pRunSet->dKU[pRunSet->pt2vol]);
			if(soe_check(EV_SYTZ)==false)
			{
				soe_record_ev(EV_SYTZ, 1, Us1,Us2,0 );			 
			}

			rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	//录波类型：跳闸类
			pvol->sta.bFlag.bEvent = true;
			//pSW->uLostVot.bFlag.bTz=true;  //执行跳闸标志
			sw_do(sw,SW_DO_HZ,SW_DO_TYPE_OFF);
			sw_do(sw,SW_DO_BHH,SW_DO_TYPE_OFF);

			sw_do(sw,SW_DO_BHDZ,SW_DO_TYPE_ON);
			sw_do(sw,SW_DO_FZ,SW_DO_TYPE_ON);
			sw_do(sw,SW_DO_BHT,SW_DO_TYPE_ON);
	
			if(uBZT->bBZT.bZF && pRunSet->tSwSet[sw].bBZT_TT)
			{
				if((g_sw[sw].do_cfg_index[SW_DO_JX1_SY] < g_equ_config->do_num) && (g_sw[sw].do_cfg_index[SW_DO_JX2_SY] == 0xffff))
				{
					sw_do(sw,SW_DO_DL1_FZ,SW_DO_TYPE_ON);
				}
				else if((g_sw[sw].do_cfg_index[SW_DO_JX2_SY] < g_equ_config->do_num) && (g_sw[sw].do_cfg_index[SW_DO_JX1_SY] == 0xffff))
				{
					sw_do(sw,SW_DO_DL2_FZ,SW_DO_TYPE_ON);
				}
				uBZT->bBZT.bSYFZ = 1;
			}
		}
	}
	else
	{
		if(pvol->sta.bFlag.bEvent) 						
		{
			soe_record_ev(EV_SYTZ, 0, 0,0,0 ); 
			pvol->sta.bFlag.bEvent = false;
		}
		pvol->sta.bFlag.bTz=false;		
	} 
}
#endif

#if (0)
/**************************************************************************
函数名称：Pro_U0Tz
函数版本：1.00 
作者：    赵海洋
创建日期：2022.2.25   
函数功能说明：零压跳闸默认检测零压1
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
void Pro_U0Tz(int sw,DWORD  dStep)
{
	bool  bQDD; 
	TRELAY_T *pR=&g_tRelay[sw];
	TVOL_T *pvol = &pR->tU0GZ;
	VOL_SET *pSet = &pRunSet->tSwSet[sw].tU0Set;
	
	bQDD = OverRelay(g_ui[PUB_AC_U01].m2[0], pSet->dUVol,pSet->dUVol_fh,pvol->sta.bFlag.bQD); 
	pvol->sta.bFlag.bQD = ((pSet->bTT || pSet->bTz)&& bQDD);

	if(pvol->sta.bFlag.bQD)
	{
		if(!pvol->sta.bFlag.bQDWave)
		{
			rcd_start(sw,RECORD_TYPE_LXDY, RECORD_LEN_TZQD); 	//录波类型：跳闸类
			pvol->sta.bFlag.bQDWave = true;
		}
	}
	/***********动作*********************************/
	RunTR(&pvol->tQDTime, pvol->sta.bFlag.bQD, dStep);		
	if (pSet->bTT)pvol->sta.bFlag.bGj = pvol->tQDTime.boolTrip;
	if (pSet->bTz)pvol->sta.bFlag.bTz = pvol->tQDTime.boolTrip;
	
	/************事件记录及出口****************************/
	if(pvol->sta.bFlag.bGj) 
	{
		if(soe_check(EV_LYGJ+sw*EV_SW_NUM)==false)	
		{
			DWORD U0;
			U0 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k);
			soe_record_ev(EV_LYGJ+sw*EV_SW_NUM,1, U0,0,0);                                          
		}
	}
	else
	{
		if(soe_check(EV_LYGJ+sw*EV_SW_NUM)==true)			
		{
			pvol->sta.bFlag.bQDWave = false;
			soe_record_ev(EV_LYGJ+sw*EV_SW_NUM,0, 0,0,0 );                                          
		}			
	} 

	if(pvol->sta.bFlag.bTz) 
	{
		if(soe_check(EV_LYTZ+sw*EV_SW_NUM)==false)	
		{
			DWORD U0;
			U0 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k);
			soe_record_ev(EV_LYTZ+sw*EV_SW_NUM,1, U0,0,0);                                          
		}
	}
	else
	{
		if(soe_check(EV_LYTZ+sw*EV_SW_NUM)==true)			
		{
			pvol->sta.bFlag.bQDWave = false;
			soe_record_ev(EV_LYTZ+sw*EV_SW_NUM,0, 0,0,0 );                                          
		}			
	} 
}
#endif

// = ========================= 本文件结束 =============================


