/******************************************************************************
版权所有：	
文件名称：	vol_ls.c
文件版本：	01.01
创建作者：	xxxxxx
创建日期：	2013-04-15
功能说明：	上电合闸、失压分闸、合环配网功能
其它说明：
修改记录：
*/
/*------------------------------- 头文件 --------------------------------------
*/


#include  "head.h"

const char *fa_s_status[]={"S_0",
						"S_INIT",
						"S_TEMP",
						"S_BSFLASH",
						"S_XTIME",
						"S_X_ZTIME",
						"S_BSXTIME",
						"S_YTIME",
						"S_Y_ZTIME",
						"S_BSYTIME",
						"S_USUAL",
						"S_BSDOUBLE",
						"S_BSHHGZ", 		//合后故障闭锁状态
						"S_BSFZ",			//合后闭锁分闸状态
						"S_BSDL",			//大电流闭锁分闸状态
						"S_BS_SW",
						"S_ERROR",
						};


const char *fa_l_status[13]={"L_0",
						"L_INIT",		//初始状态
						"L_BS_STATE",		//联络闭锁，待双侧YL有压解锁
						"L_Y_ZTIME",		//Y时限计数状态中发生的Z时限计数状态
						"L_USUAL",		//正常运行状态
						"L_XLTIME",		//X时限计数状态
						"L_XL_ZTIME",		//X时限计数中发生的Z时限计数状态
						"L_RELAYON",	//开关合运行状态	
						"L_YL_TIME",};	//合闸成功Y计时
//FA.h USDHZ_U						
const char *fa_run_falg_str[]={
						"UAB有压标志",
						"UBC有压标志",
						"UAB残压标志",
						"UBC残压标志",
						
						"上电记录标志 Uab1侧，电源侧",
						"有压标志",
						"两侧有压标志",
						"一侧失压标志",

						"对侧有压标志",
						"对侧有瞬时电压标志",
						"电源侧有压标志",
						"X时间闭锁",

						"Y时间闭锁",
						"瞬时加压闭锁",
						"双侧电源闭锁",
						"开关合命令标志",

						"告警动作",
						"合闸事件",
						"X闭锁事件",
						"Y闭锁事件"

						"瞬时电压闭锁事件		",
						"双电源闭锁事件",
						"故障记忆",
						"接地记忆",

						"零序过压标志",

						"X 时间有U0"
,
						"失电过程中的Uab瞬压标志"
,
						"失电过程中的Ubc瞬压标志",

						"合闸事件",
						"状态保护标志",
						"上电记录标志",
						"暂态判断小电流接地",
						
						0,
	};

//FA.h UVOT_U
const char *sw_u_str[]={
						"失压启动",	
						"失压启动",
						"分闸",
						"合闸",
						
						"合后故障闭锁失压分闸标志",
						"合后故障闭锁失压分闸标志",
						"合后接地故障闭锁失压分闸标志",
						"过流启动",
						"闭锁",

						"保护退出 ",
						"保护退出",
						"bEvent"
						"计数完成",
						
						#if 1
						"跳闸2",
						"15",
						"16",
						"17",
						"18",
						"19",
						"20",
						"21",
						"22",
						"23",
						"24",
						"25",
						"26",
						"27",
						"28",
						"29",
						"30",
						"31",
						"32",
						#endif

	};
//run_status.h USWST
const char *sw_status_str[]={
						"重合闸分位信号",	
						"重合闸合位信号",
						"外部开入合位",
						"外部开入分位",
						
						"未储能告警",
						"控制回路",
						"跳位有流告警",
						"三相无流",
						"手合加速",

						"上电加速 ",
						"智能分布式联络合闸，加速",
						"闭锁跳闸"
						"曾有压",
						
						#if 1
						"14",
						"15",
						"16",
						"17",
						"18",
						"19",
						"20",
						"21",
						"22",
						"23",
						"24",
						"25",
						"26",
						"27",
						"28",
						"29",
						"30",
						"31",
						"32",
						#endif

						0,
};

#if defined FUNC_MODE_JS || defined FUNC_ONLY_MMD_JS
	bool gb_js_mode=false;
#endif

static void _volstu_update(void);
static void _volstatus_init(void);
#define FA_BSYTIME_JS		//中山局正向闭锁后，不解锁直接来电合闸，合闸3S内两侧有压无故障则解除正向闭锁。如果两侧都闭锁则不执行来电合

#define VOLSTATUS_FILE_VERSION	0X01010101	//文件版本

//上电合闸状态存储数据文件头
struct vol_file_head
{
	struct cfg_file_head cfh;		//配置文件头
	
	u32	addr;		//起始地址
	u32	num;		//存储总量
	u8 reserved[8];
};

u8 g_volfile_open=0;
static u8 vol_filelen;
char *g_volbuf;
struct vol_stu g_vol_stu[SWITCH_NUM_MAX];
struct file * gf_volstu;

#if 0 // 板上瞬压板处理
unsigned short  fa_getUFDI(void)
{
	unsigned int di=0;
	unsigned short ret=0;

	if( pRunSet->bTT_SY_Board)
	{
	    di = gpio_get_di();
	}
	ret = (unsigned short)((di >> 15) & 0x0003); // YX16 Yx17为瞬压信号
	return ret;

}


TIMERELAY tUfdiTime;

void   fa_RstUFDI(DWORD  dStep)
{
	static bool brst=false;
	static DWORD rstUFDICounter=0;	
	int ufdi=fa_getUFDI();	
	RunTR(&tUfdiTime, (ufdi>0), dStep);	//延迟 1秒 复归瞬压继电器，防止抖动 	
	if(tUfdiTime.boolTrip)	brst=true;	
	

	if(brst&&pRunSet->bTT_SY_Board)
	{
		gpio_pwm_do(1, 2); // PWM2 为复归瞬压信号的开出
		if(dTCounter-rstUFDICounter>=T_20ms) //开出20ms开出
		{	
			gpio_pwm_do(0, 2); // PWM2 为复归瞬压信号的开出
			brst=false;
			rstUFDICounter=dTCounter;
		}
	}
	else
	{
		rstUFDICounter=dTCounter;
	}
}
#endif










/**************************************************************************
函数名称：FA_Init
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：状态初始化
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
void FA_Init(void)
{
	u8 sw;
	//unsigned short ufdi;
	//bool bUab,bUbc;
	//ufdi=fa_getUFDI()&0x03;

	//bUab=(ufdi&0x01)?true:false;
	//bUbc=(ufdi&0x02)?true:false;	
	for (sw=0; sw< SWITCH_NUM_MAX; sw++)
	{
		g_tRelay[sw].tSDHZ.S_Status = S_INIT;
		g_tRelay[sw].tSDHZ.L_Status = L_INIT;
		//g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUabflashDI=bUab&&pRunSet->tSwSet[sw].bTT_FA;
		//g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUbcflashDI=bUbc&&pRunSet->tSwSet[sw].bTT_FA;
	}
	
	//InitTR(&tUfdiTime, T_1s,0 ); 

	_volstatus_init();
	
}

static void dl_ope_event(int sw,int code,long v1,long v2,long v3)
{
	int i;
	for(i=EV_FA_HZ;i<=EV_YK_FZ;i++)
	{
		if(i==code)
		{
		 	if(soe_check(i+sw*EV_SW_NUM)==false)   // 
		 	{
				soe_record_ev(i+sw*EV_SW_NUM, 1, v1,v2,v3 );
			}
		}
		else
		{
		 	if(soe_check(i+sw*EV_SW_NUM)==true)   // 
		 	{
				soe_record_ev(i+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		}
	}
}


static bool  fa_check_all_s_bs(int sw)
{
	bool bY=false;
	bool bY1=false;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bY=0
		||soe_check(EV_BS_X_L+sw*EV_SW_NUM)
		||soe_check(EV_BS_Y_L+sw*EV_SW_NUM)
		||soe_check(EV_BS_X_P+sw*EV_SW_NUM)
		||soe_check(EV_BS_Y_P+sw*EV_SW_NUM)
		||(soe_check(EV_BS_U0+sw*EV_SW_NUM)&&pSet->bTT_fa_gzbshz)
		||soe_check(EV_BS_HA+sw*EV_SW_NUM)
		||soe_check(EV_BS_UF_P+sw*EV_SW_NUM)
		||soe_check(EV_BSBE_U0+sw*EV_SW_NUM)
		||(soe_check(EV_HHGZ+sw*EV_SW_NUM)&&pSet->bTT_fa_gzbshz)		
		||soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)
		||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)
		||soe_check(EV_GOOSE_GZBS_FA)// goose故障闭锁
		||soe_check(EV_GOOSE_TZBS_FA)// goose故障闭锁
	#ifdef FA_OC_COUNT
		||soe_check(EV_BS_OC_COUNT+sw*EV_SW_NUM)// 过流脉冲计数闭锁
	#endif
	#ifdef YK_FA_ENBLE
		||soe_check(EV_YK_BS_FA+sw*EV_SW_NUM)   // 遥控闭锁FA
	#endif
	#ifndef GD_AREA_ECZD_MEIZHOU_2021
		|| g_tRelay[sw].tPLJL.bLed			//解裂动作后需闭锁合闸
	#endif
		|| g_tRelay[sw].tDYJL.bLed;			//解裂动作后需闭锁合闸
		//||soe_check(EV_BS_DB+sw*EV_SW_NUM);  //广西双电源不点闭锁灯
		bY1=soe_check(EV_BS_DB+sw*EV_SW_NUM);

	if(bY||bY1)
	{
		if(soe_check(EV_BS_ALL+sw*EV_SW_NUM)==false)
		{
			soe_record_ev(EV_BS_ALL+sw*EV_SW_NUM, 1, 0,0,0 );
		}
	}
	else
	{
		if(soe_check(EV_BS_ALL+sw*EV_SW_NUM)==true)
		{
			soe_record_ev(EV_BS_ALL+sw*EV_SW_NUM, 0, 0,0,0 );
		}
	}
	
	//return(bY; // 广西FA 双电源闭锁，不点闭锁灯
	return (bY||bY1);
}


/**************************************************************************
函数名称：Pro_LS_LED
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：VSP5开关LED灯处理
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void  fa_ls_led(int sw, bool bFA_L)
{
	TSDHZ_T *pSW = &g_tRelay[sw].tSDHZ;
	if(!bFA_L)
	{
		if (pSW->S_Status == S_XTIME)
			led_set_sw(sw,SW_LED_XT, LED_ON);
		else
			led_set_sw(sw,SW_LED_XT, LED_OFF);
		
		if (pSW->S_Status == S_YTIME)
			led_set_sw(sw,SW_LED_YT, LED_ON);
		else
			led_set_sw(sw,SW_LED_YT, LED_OFF);

		if(pSW->S_Status == S_XTIME)
			led_set_sw(sw,SW_LED_X_YT, LED_ON);
		else if(pSW->S_Status == S_YTIME)
			led_set_sw(sw,SW_LED_X_YT, LED_QUICK);
		else
			led_set_sw(sw,SW_LED_X_YT, LED_OFF);
	
		//if(fa_check_all_s_bs(sw))
		//	led_set_sw(sw,SW_LED_LOCK, LED_ON);
		//else
		//	led_set_sw(sw,SW_LED_LOCK, LED_OFF);
	}
	else
	{
		if (pSW->L_Status == L_XLTIME)
			led_set_sw(sw,SW_LED_XT, LED_ON);
		else
			led_set_sw(sw,SW_LED_XT, LED_OFF);
		
		if (((pSW->L_Status == L_BS_STATE) || (pSW->L_Status == L_Y_ZTIME)||(pSW->L_Status == L_YL_TIME) ) && (!pSW->uSdhz_L.bFlag.bLockUFlash))
			led_set_sw(sw,SW_LED_YT, LED_ON);
		else
			led_set_sw(sw,SW_LED_YT, LED_OFF);
		
		if(pSW->L_Status == L_XLTIME)
			led_set_sw(sw,SW_LED_X_YT, LED_ON);
		else if (((pSW->L_Status == L_BS_STATE) ||(pSW->L_Status == L_Y_ZTIME)||(pSW->L_Status == L_YL_TIME) ) && (!pSW->uSdhz_L.bFlag.bLockUFlash))
			led_set_sw(sw,SW_LED_X_YT, LED_QUICK);
		else
			led_set_sw(sw,SW_LED_X_YT, LED_OFF);
		
		if(pSW->L_Status == L_USUAL)
		{
			led_set_sw(sw,SW_LED_XT, LED_OFF);
			led_set_sw(sw,SW_LED_YT, LED_OFF);
			led_set_sw(sw,SW_LED_X_YT, LED_OFF);
		}
		
		//if (pSW->uSdhz_L.bFlag.bLockY)
		//	led_set_sw(sw,SW_LED_LOCK, LED_ON);
		//else
		//	led_set_sw(sw,SW_LED_LOCK, LED_OFF);
	}
}


/**************************************************************************
函数名称：Pro_UF_Clear
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：瞬时电压标志处理
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_uf_set(int sw, bool bSW_LL, DWORD  dStep)
{
	bool bY1,bY2;
	TRELAY_T *pR=&g_tRelay[sw];
	TSWST *pSWST =&pR->tSWST;
	TSDHZ_T *pSW=&pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];	
#ifdef FA_PL_PJ
	bool bFreq0,bFreq1;
	float freq0,freq1;
#endif

		//频率在要求范围内
	#ifdef FA_PL_PJ
		if(pRunSet->bTT_judgeFreq)
		{
			freq0=freq_get(0);
			freq1=freq_get(1);
			//电源1频率判断
			if((freq0>=48.9) && (freq0<=50.9))
			{
				bFreq0 = true;
			}
			else
			{
				bFreq0 = false;
			}
			//电源2频率判断
			if((freq1>=48.9) && (freq1<=50.9))
			{
				bFreq1 = true;
			}
			else
			{
				bFreq1 = false;
			}

			if(bSW_LL)
			{
				RunTR(&pSW->tFREQAB25ms_LCY, bFreq0, dStep);
				RunTR(&pSW->tFREQBC25ms_LCY, bFreq1, dStep);
			}
			else
			{
				RunTR(&pSW->tFREQAB25ms_SCY, bFreq0, dStep);
				RunTR(&pSW->tFREQBC25ms_SCY, bFreq1, dStep);
			}
		}
	#endif
	
	#ifdef FA_PL_PJ
		if(pRunSet->bTT_judgeFreq)
		{
			if(bSW_LL)
			{
			#ifdef GD_AREA_LIAONING_2021
				bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pSW->tFREQAB25ms_LCY.boolTrip&&pR->run_stu.fa_start_hz;// 电源1瞬压
				bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pSW->tFREQBC25ms_LCY.boolTrip;// 电源2瞬压
			#else
				bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pSW->tFREQAB25ms_LCY.boolTrip;// 电源1瞬压
				bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pR->run_stu.fa_start_hz&&pSW->tFREQBC25ms_LCY.boolTrip;// 电源2瞬压
			#endif
			}
			else
			{
			#ifdef GD_AREA_LIAONING_2021
				bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pSW->tFREQAB25ms_SCY.boolTrip&&pR->run_stu.fa_start_hz;// 电源1瞬压
				bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pSW->tFREQBC25ms_SCY.boolTrip;// 电源2瞬压
			#else
				bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pSW->tFREQAB25ms_SCY.boolTrip;// 电源1瞬压
				bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pR->run_stu.fa_start_hz&&pSW->tFREQBC25ms_SCY.boolTrip;// 电源2瞬压
			#endif
			}
		}
		else
		{
		#ifdef GD_AREA_LIAONING_2021
			bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pR->run_stu.fa_start_hz;// 电源1瞬压
			bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0);// 电源2瞬压
		#else
			bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0);// 电源1瞬压
			bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pR->run_stu.fa_start_hz;// 电源2瞬压
		#endif
		}
	#elif defined GD_AREA_JIEYANG
		bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0)&&pR->run_stu.fa_start_hz;
		bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0);
	#else //GD_AREA_ZHUHAI_V2
		bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_UF, pSet->dU_UF, 0);// 电源1瞬压
		bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_UF2, pSet->dU_UF2, 0)&&pR->run_stu.fa_start_hz;// 电源2瞬压
	#endif

	if(bSW_LL)
	{
			RunTR(&pSW->tUFABL25ms, !bY1, dStep);		//确认从无压到有压
			RunTR(&pSW->tUFBCL25ms, !bY2, dStep);		


			RunTR(&pSW->tUFABL80ms, (bY1 && pSW->tUFABL25ms.boolTrip), dStep);					
			RunTR(&pSW->tUFBCL80ms, (bY2 && pSW->tUFBCL25ms.boolTrip), dStep);	
		#ifdef GD_AREA_CHAOZHOUFENGXI //潮州	 联络残压不需要对侧有压条件 2020-8-12			
			pSW->uSdhz_L.bFlag.bUABFlash = ((pSW->tUFABL80ms.boolTrip&&(!bY1))
											||pSW->uSdhz_L.bFlag.bUABFlash)&&pSet->bTT_fa_cybs;
			
			pSW->uSdhz_L.bFlag.bUBCFlash = ((pSW->tUFBCL80ms.boolTrip&&(!bY2))
											||pSW->uSdhz_L.bFlag.bUBCFlash)&&pSet->bTT_fa_cybs;//&&pR->run_stu.fa_start_hz;			
		#else
			pSW->uSdhz_L.bFlag.bUABFlash = ((pSW->tUFABL80ms.boolTrip&&(!bY1)&&pSW->uSdhz_L.bFlag.bUBCYY)
											||pSW->uSdhz_L.bFlag.bUABFlash)&&pSet->bTT_fa_cybs;
				
			pSW->uSdhz_L.bFlag.bUBCFlash = ((pSW->tUFBCL80ms.boolTrip&&(!bY2)&&pSW->uSdhz_L.bFlag.bUABYY)
											||pSW->uSdhz_L.bFlag.bUBCFlash)&&pSet->bTT_fa_cybs;
		#endif
	}
	else
	{
			RunTR(&pSW->tUFABS25ms, !bY1, dStep);					
			RunTR(&pSW->tUFBCS25ms, !bY2, dStep);
			
			RunTR(&pSW->tUFABS80ms, (bY1 && pSW->tUFABS25ms.boolTrip&&pSWST->uSWST.bFlag.bDITW), dStep);					
			RunTR(&pSW->tUFBCS80ms, (bY2 && pSW->tUFBCS25ms.boolTrip&&pSWST->uSWST.bFlag.bDITW), dStep);	
					
			pSW->uSdhz_S.bFlag.bUABFlash = ((pSW->tUFABS80ms.boolTrip&&(!bY1)&& pSWST->uSWST.bFlag.bDITW)
											|| pSW->uSdhz_S.bFlag.bUABFlash)&&pSet->bTT_fa_cybs;
			
			pSW->uSdhz_S.bFlag.bUBCFlash = ((pSW->tUFBCS80ms.boolTrip&&(!bY2)&&pSWST->uSWST.bFlag.bDITW)
											|| pSW->uSdhz_S.bFlag.bUBCFlash)&&pSet->bTT_fa_cybs;//&&pR->run_stu.fa_start_hz;										
	}
}

static void fa_uf_clear(int sw, bool bSW_LL)
{
	TSDHZ_T *pSW=&g_tRelay[sw].tSDHZ;
	if(bSW_LL)
	{
		ResetTR(&pSW->tUFABL25ms);					//清零
		ResetTR(&pSW->tUFBCL25ms);					//清零
		ResetTR(&pSW->tUFABL80ms);					//清零
		ResetTR(&pSW->tUFBCL80ms);					//清零

	#ifdef FA_PL_PJ
		ResetTR(&pSW->tFREQAB25ms_LCY);
		ResetTR(&pSW->tFREQBC25ms_LCY);
	#endif
	
		pSW->uSdhz_L.bFlag.bUABFlash = false;
		pSW->uSdhz_L.bFlag.bUBCFlash = false;	
	}
	else
	{
		ResetTR(&pSW->tUFABS25ms);
		ResetTR(&pSW->tUFBCS25ms);
		ResetTR(&pSW->tUFABS80ms);					
		ResetTR(&pSW->tUFBCS80ms);				

	#ifdef FA_PL_PJ
		ResetTR(&pSW->tFREQAB25ms_SCY);
		ResetTR(&pSW->tFREQBC25ms_SCY);
	#endif
	
		pSW->uSdhz_S.bFlag.bUABFlash = false;
		pSW->uSdhz_S.bFlag.bUBCFlash = false;
		pSW->uSdhz_S.bFlag.bUabflashDI=false;
		pSW->uSdhz_S.bFlag.bUbcflashDI=false;
	}
}


/**************************************************************************
函数名称：Pro_CLOSE_LED
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：VSP5关LED灯
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_close_led(int sw)
{
	led_set_sw(sw,SW_LED_XT, LED_OFF);
	led_set_sw(sw,SW_LED_YT, LED_OFF);
	led_set_sw(sw,SW_LED_LOCK, LED_OFF);
	led_set_sw(sw,SW_LED_JD, LED_OFF);
	led_set_sw(sw,SW_LED_GL, LED_OFF);
	led_set_sw(sw,SW_LED_DZ, LED_OFF);
	led_set_sw(sw,SW_LED_TZ, LED_OFF);

	g_tRelay[sw].run_stu.dz=0;

	g_tRelay[sw].tU0TZ.bU0Led=false;
	g_tRelay[sw].tOC[FA_GL].sta.bFlag.bDzLed = false;
	g_tRelay[sw].tOC[FA_GL].sta.bFlag.bGj = false;

	g_tRelay[sw].tOC[FA_GL_II].sta.bFlag.bDzLed = false;
	g_tRelay[sw].tOC[FA_GL_II].sta.bFlag.bGj = false;

	g_tRelay[sw].tOC[FA_GL2].sta.bFlag.bDzLed = false;
	g_tRelay[sw].tOC[FA_GL2].sta.bFlag.bGj = false;

	g_tRelay[sw].tOC[FA_LX].sta.bFlag.bDzLed = false;
	g_tRelay[sw].tOC[FA_LX].sta.bFlag.bGj = false;

	g_tRelay[sw].tOC[FA_LX2].sta.bFlag.bDzLed = false;
	g_tRelay[sw].tOC[FA_LX2].sta.bFlag.bGj = false;
}

void fa_s_set_savestatus(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW =&pR->tSDHZ;
	pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
}
//谐波含量
bool fa_XBCalc(int sw,DWORD Iset)
{
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	TRELAY_T *pR=&g_tRelay[sw];
	int index=0;
	if(FA_ALL_EN(sw)&&pSet->bTT_fa_xbbs)
	{
		for(index=0;index<3;index++)
		{
			if(( g_ui[UI_SW_INDEX(sw,SW_AC_IA+index)].m2[0] > Iset) && ( g_ui[UI_SW_INDEX(sw,SW_AC_IA+index)].m2[1] > pR->tSWST.uSWST.bFlag.bFAWL))           // I 与 Ixb2 均应大于无流定值
			{
				if( g_ui[UI_SW_INDEX(sw,SW_AC_IA+index)].m2[1] > _MulFac_U(g_ui[UI_SW_INDEX(sw,SW_AC_IA+index)].m2[0], pSet->d_fa_xbcoe ))                         
					return(true);
			}
		}
	}
	return(false);
}

void run_vol_refersh(int sw, DWORD  dStep)
{
	bool  bY2, bY3,bQDD1,bQDD2;	
#ifdef FUNC_NYY_NWY
	bool bY2_n=0,bY3_n=0;
#endif
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW =&pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];	
	DWORD Us1,Us2;
	int ui_begin;

#ifdef GD_AREA_ECZD_CHAOZHOU_2022
	bool  bY4, bY5;
#endif
	//用于保存故障断面	
	ui_begin = UI_SW_INDEX_BEGIN(sw);

	if(pRunSet->bTT_UYYmin)
	{
		Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_min[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
		Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_min[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
	}
	else
	{
		Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
		Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
	}

	//有压检测
	// 电源1上电合闸
	if(pRunSet->bTT_UYYmin)
	{
		bY2 = OverRelay(g_sw_pub.m2_min[2], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_S.bFlag.bUABYY);
#ifdef FUNC_NYY_NWY
		bY2_n = (((g_sw_pub.m2_min[2] > pSet->dU_fa_WY) && (g_sw_pub.m2_min[2] < pSet->dU_fa_YY))?true:false)
				|| (tPT.uPT1DX.bFlag.bQD && pSW->uSdhz_S.bFlag.bUBCYY)
				;
#endif
	#ifdef GD_AREA_ECZD_CHAOZHOU_2022
		pSW->uSdhz_S.bFlag.bHzEnable_P = true;
		
		if(pSW->uSdhz_S.bFlag.bBsXtime_P)
			pSW->uSdhz_S.bFlag.bHzEnable_P = false;
		bY4 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_S.bFlag.bUABYY);
		if(bY4 && pSW->uSdhz_S.bFlag.bBsXtime_P)
		{
			pSW->uSdhz_S.bFlag.bHzEnable_P = true;
			pSW->uSdhz_S.bFlag.bBsXtime_P = false;
		}
	#endif
	}
	else
	{
		bY2 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_S.bFlag.bUABYY);
	#ifdef GD_AREA_ECZD_CHAOZHOU_2022
		pSW->uSdhz_S.bFlag.bHzEnable_P = true;
		pSW->uSdhz_S.bFlag.bHzEnable_L = true;
	#endif
	}
	RunTR(&pSW->tUABS25ms, bY2, dStep);	
	
#ifdef FUNC_NYY_NWY
	RunTR(&pSW->tUABS_NYY_NWY_50ms, bY2_n, dStep); 
	pSW->uSdhz_S.bFlag.bUAB_NYY_NWY = pSW->tUABS_NYY_NWY_50ms.boolTrip;
#endif

	#if defined GD_AREA_JIEYANG || defined GD_AREA_LIAONING_2021
		pSW->uSdhz_S.bFlag.bUABYY = pSW->tUABS25ms.boolTrip && pR->run_stu.fa_start_hz;
	#else
		pSW->uSdhz_S.bFlag.bUABYY = pSW->tUABS25ms.boolTrip;
	#endif
		
	if(soe_check(EV_YY_P+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bUABYY)//记录SOE
		soe_record_ev(EV_YY_P+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bUABYY, Us1,Us2,0 ); 
	
	// 电源2上电合闸
	if(pRunSet->bTT_UYYmin)
	{
		bY3 = OverRelay(g_sw_pub.m2_min[3], pSet->dU_fa_YY2, pSet->dU_fa_YY2_fh, pSW->uSdhz_S.bFlag.bUBCYY) ;
#ifdef FUNC_NYY_NWY
		bY3_n = (((g_sw_pub.m2_min[3] > pSet->dU_fa_WY2) && (g_sw_pub.m2_min[3] < pSet->dU_fa_YY2))?true:false)
				|| (tPT.uPT2DX.bFlag.bQD && pSW->uSdhz_S.bFlag.bUABYY)
				;
#endif
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
		pSW->uSdhz_S.bFlag.bHzEnable_L = true;
		
		if(pSW->uSdhz_S.bFlag.bBsXtime_L)
			pSW->uSdhz_S.bFlag.bHzEnable_L = false;
		bY5 = LowRelay(g_sw_pub.m2_max[3], pSet->dU_fa_YY2, pSet->dU_fa_YY2_fh, pSW->uSdhz_S.bFlag.bUBCYY);
		if(bY5 && pSW->uSdhz_S.bFlag.bBsXtime_L)
		{
			pSW->uSdhz_S.bFlag.bHzEnable_L = true;
			pSW->uSdhz_S.bFlag.bBsXtime_L = false;
		}
#endif
	}
	else
	{
		bY3 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_fa_YY2, pSet->dU_fa_YY2_fh, pSW->uSdhz_S.bFlag.bUBCYY) ;
	}
	RunTR(&pSW->tUBCS25ms, bY3, dStep);	
#ifdef FUNC_NYY_NWY
	RunTR(&pSW->tUBCS_NYY_NWY_50ms, bY3_n, dStep); 
	pSW->uSdhz_S.bFlag.bUBC_NYY_NWY = pSW->tUBCS_NYY_NWY_50ms.boolTrip;
#endif
	#if defined GD_AREA_JIEYANG || defined GD_AREA_LIAONING_2021
		pSW->uSdhz_S.bFlag.bUBCYY = pSW->tUBCS25ms.boolTrip;
	#else
		pSW->uSdhz_S.bFlag.bUBCYY = pSW->tUBCS25ms.boolTrip && pR->run_stu.fa_start_hz;
	#endif
	if(soe_check(EV_YY_L+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bUBCYY)//记录SOE
		soe_record_ev(EV_YY_L+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bUBCYY, Us1,Us2,0 ); 

	//曾有压标志
	if( pSW->uSdhz_S.bFlag.bUABYY || pSW->uSdhz_S.bFlag.bUBCYY)
		pSW->uSdhz_S.bFlag.bCYY = TRUE;
	
	//两侧有压
	pSW->uSdhz_S.bFlag.bDBYY = pSW->uSdhz_S.bFlag.bUABYY && pSW->uSdhz_S.bFlag.bUBCYY;//双侧有压直接赋值，不需等待稳定时间

	//停电时间Z
	pR->tSWST.uSWST.bFlag.bFAWL = LowRelay(g_sw[sw].m2_max, pSet->dT_wldz,pSet->dT_wldz,false);

	#if defined GD_AREA_JIEYANG || defined GD_AREA_LIAONING_2021
		bQDD1 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_fa_WY, pSet->dU_fa_WY_fh, false) || !pR->run_stu.fa_start_hz;
		bQDD2 = LowRelay(g_sw_pub.m2_max[3], pSet->dU_fa_WY2, pSet->dU_fa_WY2_fh, false);	
	#else
		bQDD1 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_fa_WY, pSet->dU_fa_WY_fh, false);
		bQDD2 = LowRelay(g_sw_pub.m2_max[3], pSet->dU_fa_WY2, pSet->dU_fa_WY2_fh, false) || !pR->run_stu.fa_start_hz;
	#endif
	RunTR(&pR->tLostVot.tLostVotTime,  bQDD1 && bQDD2&&pSet->bTT_fa_Lostfz && pR->tSWST.uSWST.bFlag.bFAWL, dStep);	
	pSW->uSdhz_S.bFlag.bPowerZ=pSW->uSdhz_L.bFlag.bPowerZ =   pR->tLostVot.tLostVotTime.boolTrip
								&& !pSW->uSdhz_S.bFlag.bUABYY && !pSW->uSdhz_S.bFlag.bUBCYY			//两侧无压
								//&& pR->tSWST.uSWST.bFlag.bHZWZ		//在合闸位置
								//&& pR->tSWST.uSWST.bFlag.bSXWL;		//三相无流
								&& pSW->uSdhz_S.bFlag.bCYY;
	if(soe_check(EV_Z_TIME+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bPowerZ)//记录SOE
		soe_record_ev(EV_Z_TIME+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bPowerZ, Us1,Us2,0 ); 
		
}
void fa_s_Dataset(int sw, DWORD  dStep)
{
	bool bY1;//, bY2, bY3,bQDD1,bQDD2;	
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW =&pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];	
	bool bgl,bjd=false;

	DWORD Us1,Us2;
	DWORD Ia,Ib,Ic; 
	DWORD I0,U0;
	int ui_begin;
	bool xbQD1=false;
	DWORD U01,U02;
	//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理	
	#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
	bool xbQD2=false;
	#endif
	bool xbAll=false;

	//用于保存故障断面	
	ui_begin = UI_SW_INDEX_BEGIN(sw);
	Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
	Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
	Ia = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IA].m2[0]), 256, g_ui[ui_begin + SW_AC_IA].m2_factor_k);
	Ib = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IB].m2[0]), 256, g_ui[ui_begin + SW_AC_IB].m2_factor_k);
	Ic = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IC].m2[0]), 256, g_ui[ui_begin + SW_AC_IC].m2_factor_k);	
	I0 = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_I0].m2[0]), 256, g_ui[ui_begin + SW_AC_I0].m2_factor_k);
	U0 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k); 			

	U01 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k);	
	U02 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U02].m2[0]), 256, g_ui[PUB_AC_U02].m2_factor_k);	

	//遮断电流								
	bgl = OverRelay(g_sw[sw].m2_max, pSet->toc[FA_DLBS].dI, pSet->toc[FA_DLBS].dI_fh, 0);//
	RunTR(&g_tRelay[sw].tOC[FA_DLBS].tQDTime,bgl && !pR->tSWST.uSWST.bFlag.bFAWL, dStep);
	pR->bBSTZ =  g_tRelay[sw].tOC[FA_DLBS].tQDTime.boolTrip&&pSet->toc[FA_DLBS].bTz;
	pR->tOC[FA_DLBS].sta.bFlag.bGj =  pR->tOC[FA_DLBS].sta.bFlag.bTz =pR->tOC[FA_DLBS].sta.bFlag.bDzLed = pR->bBSTZ;
	if(soe_check(EV_BSTZ+sw*EV_SW_NUM)!=pR->bBSTZ)//记录SOE
		soe_record_ev(EV_BSTZ+sw*EV_SW_NUM, pR->bBSTZ, Ia,Ib,Ic ); 

	//相间故障谐波
	xbQD1 = fa_XBCalc(sw,pSet->toc[FA_GL].dI);
	RunTR(&g_tRelay[sw].tOC[FA_GL].tXBTime, xbQD1, dStep);//谐波含量
	//xbQD1 = g_tRelay[sw].tOC[FA_GL].tXBTime.boolTrip;	
//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理
#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
	xbQD2 = fa_XBCalc(sw,pSet->toc[FA_GL_II].dI);	
	RunTR(&g_tRelay[sw].tOC[FA_GL_II].tXBTime, xbQD2, dStep);//谐波含量
	//xbQD2 = g_tRelay[sw].tOC[FA_GL_II].tXBTime.boolTrip;
#else
	g_tRelay[sw].tOC[FA_GL_II].tXBTime.boolTrip=false;
#endif
	xbAll = (g_tRelay[sw].tOC[FA_GL].tXBTime.boolTrip||g_tRelay[sw].tOC[FA_GL_II].tXBTime.boolTrip);	
	if(FA_ALL_EN(sw))
	{
		if(soe_check(EV_XBBS+sw*EV_SW_NUM)!=xbAll) //记录谐波SOE
		{
			if(pSW->S_Status==S_YTIME || pSW->L_Status==L_YL_TIME)//非Y时限内，不产生谐波闭锁SOE
				soe_record_ev(EV_XBBS+sw*EV_SW_NUM, xbAll, 0,0,0 ); 
			else if(soe_check(EV_XBBS+sw*EV_SW_NUM))			
				soe_record_ev(EV_XBBS+sw*EV_SW_NUM, 0, 0,0,0 ); 
		}
	}
	//相间故障
	bgl = OverRelay(g_sw[sw].m2_max, pSet->toc[FA_GL].dI, pSet->toc[FA_GL].dI_fh, pSW->uSdhz_S.bFlag.bGL) && (pSet->bTT_fa_Icheck||pSet->toc[FA_GL].bTz);//
	pR->tOC[FA_GL].sta.bFlag.bQD = bgl;	// add xxxxxx 20220705 需要置上启动标志，否则会启动后马上进入整组复归
#ifdef EV_GL_STATR
		gl_start_soe_set( bgl,sw,EV_FA_GL_START);
#endif
	RunTR(&pSW->tGZJYRstGLTime, bgl&&!xbQD1 ,dStep);  //跳闸位置、超过故障记忆过流复归时间，清跳闸次数
	pSW->uSdhz_S.bFlag.bGL=pSW->uSdhz_L.bFlag.bGL = pSW->tGZJYRstGLTime.boolTrip && !xbQD1;//时间&&谐波含量

//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理
#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
	//相间II段故障
	bgl = OverRelay(g_sw[sw].m2_max, pSet->toc[FA_GL_II].dI, pSet->toc[FA_GL_II].dI_fh, pSW->uSdhz_S.bFlag.bGL_II) && (pSet->bTT_fa_Icheck||pSet->toc[FA_GL_II].bTz);//
	RunTR(&pSW->tGZJYRstGL_II_Time, bgl&&!xbQD2,dStep);  //跳闸位置、超过故障记忆过流复归时间，清跳闸次数
	pSW->uSdhz_S.bFlag.bGL_II=pSW->uSdhz_L.bFlag.bGL_II = pSW->tGZJYRstGL_II_Time.boolTrip && !xbQD2;//时间&&谐波含量
	pR->tOC[FA_GL_II].sta.bFlag.bQD = bgl;	// add xxxxxx 20220705 需要置上启动标志，否则会启动后马上进入整组复归
#ifdef GD_AREA_ECZD_2020
		gl_start_soe_set( bgl,sw,EV_FA_GL2_START);
#endif
#else
	pSW->uSdhz_S.bFlag.bGL_II=pSW->uSdhz_L.bFlag.bGL_II=0;
#endif
	
	//相间告警
#ifdef GD_AREA_ECZD_2020
	bgl =   OverRelay(g_sw[sw].m2_max, pSet->toc[FA_GL2].dI, pSet->toc[FA_GL2].dI_fh, pSW->uSdhz_S.bFlag.bGL2)
	      &&(LowRelay(g_sw_pub.m2_min[2], pSet->toc[FA_GL2].dU,  pSet->toc[FA_GL2].dU_fh, pSW->uSdhz_S.bFlag.bGL2)||OverRelay(Us1_120.vect2, pSet->toc[FA_GL2].dU2,  pSet->toc[FA_GL2].dU2_fh, pSW->uSdhz_S.bFlag.bGL2))
	      &&(pSet->bTT_fa_gl2);
#else
	bgl =   OverRelay(g_sw[sw].m2_max, pSet->toc[FA_GL2].dI, pSet->toc[FA_GL2].dI_fh, pSW->uSdhz_S.bFlag.bGL2)&&(pSet->bTT_fa_gl2);
#endif
	pR->tOC[FA_GL2].sta.bFlag.bQD = bgl;	// add xxxxxx 20220705 需要置上启动标志，否则会启动后马上进入整组复归

#ifdef FUN_JDXX
		bjd |= ((soe_check(EV_JDXX_TZ+sw*EV_SW_NUM) || soe_check(EV_JDXX_GJ+sw*EV_SW_NUM)) ? true : false);
#endif	

	RunTR(&pSW->tGZJYRstGL2Time, bgl,dStep);  //跳闸位置、超过故障记忆过流复归时间，清跳闸次数
	pSW->uSdhz_S.bFlag.bGL2 = pSW->tGZJYRstGL2Time.boolTrip;	
	pR->tOC[FA_GL2].sta.bFlag.bGj = pR->tOC[FA_GL2].sta.bFlag.bGjLed = pSW->uSdhz_S.bFlag.bGL2;
	if(soe_check(EV_FA_GL_GJ+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bGL2)//记录SOE
		soe_record_ev(EV_FA_GL_GJ+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bGL2, Ia,Ib,Ic );  

	if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)&& !soe_check(EV_FA_GL_GJ+sw*EV_SW_NUM))
	{
		soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );
	}

	//接地故障	 
	bjd = OverRelay(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].m2[0], pSet->toc[FA_LX].dI, pSet->toc[FA_LX].dI_fh,pSW->uSdhz_S.bFlag.bJD) && (pSet->bTT_fa_Icheck||pSet->toc[FA_LX].bTz);
	pR->tOC[FA_LX].sta.bFlag.bQD = bjd;	// add xxxxxx 20220705 需要置上启动标志，否则会启动后马上进入整组复归
#ifdef EV_GL_STATR
	lx_start_soe_set( bjd,sw,EV_FA_LX_START);
#endif
	RunTR(&pSW->tGZJYRstJDTime, bjd,dStep);  //跳闸位置、超过故障记忆过流复归时间，清跳闸次数
	pSW->uSdhz_S.bFlag.bJD=pSW->uSdhz_L.bFlag.bJD=pSW->tGZJYRstJDTime.boolTrip;

	//接地告警
	bjd = OverRelay(g_ui[UI_SW_INDEX(sw,SW_AC_I0)].m2[0], pSet->toc[FA_LX2].dI, pSet->toc[FA_LX2].dI_fh, pSW->uSdhz_S.bFlag.bJD2) && (pSet->bTT_fa_lx2); 
	pR->tOC[FA_LX2].sta.bFlag.bQD = bjd;	// add xxxxxx 20220705 需要置上启动标志，否则会启动后马上进入整组复归
	RunTR(&pSW->tGZJYRstJD2Time, bjd,dStep);  //跳闸位置、超过故障记忆过流复归时间，清跳闸次数
	pSW->uSdhz_S.bFlag.bJD2=pSW->tGZJYRstJD2Time.boolTrip;	
	pR->tOC[FA_LX2].sta.bFlag.bGj =  pSW->uSdhz_S.bFlag.bJD2;
	if(soe_check(EV_FA_LX_GJ+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bJD2)//记录SOE
		soe_record_ev(EV_FA_LX_GJ+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bJD2, I0,  U01>U02?U01:U02,0 );	

#ifdef GD_AREA_ZHONGSHAN_2020//中山2020要求Y时间内失压，且FA二段或者零序一段满足条件后报Y闭锁 2020-10-24
		RunTR(&pSW->tOnOCingTime, soe_check(EV_FA_GL2_START+sw*EV_SW_NUM),dStep);
		RunTR(&pSW->tOnLXingTime, soe_check(EV_FA_LX_START+sw*EV_SW_NUM),dStep);

		pSW->uSdhz_S.bFlag.bOCing = (pSW->tOnOCingTime.boolTrip||pSW->tOnLXingTime.boolTrip);
#endif	

	//零序电压判断
#ifdef GD_AREA_CHAOZHOUFENGXI
	bjd = 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->dU_OverU0, pSet->dU_OverU0_fh, pSW->uSdhz_S.bFlag.bOverU0);
#else
	bjd = OverRelay(g_ui[PUB_AC_U01].m2[0], pSet->dU_OverU0, pSet->dU_OverU0_fh, pSW->uSdhz_S.bFlag.bOverU0);
#endif
#ifdef EV_GL_STATR
	lx_start_soe_set( bjd,sw,EV_FA_U0_STATR);
#endif
	RunTR(&pR->tU0TZ.tZOVTime, bjd,dStep);
	pSW->uSdhz_S.bFlag.bOverU0 = pR->tU0TZ.tZOVTime.boolTrip;
	pSW->uSdhz_L.bFlag.bOverU0 = pSW->uSdhz_S.bFlag.bOverU0;
	pR->tU0TZ.bU0GjLed = 0;
	if(pSet->bTT_fa_U0Gj)
		pR->tU0TZ.bU0GjLed = pSW->uSdhz_S.bFlag.bOverU0;
	if((soe_check(EV_FA_U0GJ+sw*EV_SW_NUM)!=pSW->uSdhz_S.bFlag.bOverU0) && pSet->bTT_fa_U0Gj &&(pSW->S_Status==S_YTIME || pSW->L_Status==L_YL_TIME
	#ifdef GD_AREA_HEYUAN_2021
		|| ((pSW->S_Status==S_USUAL) && pSW->uSdhz_S.bFlag.bYtOn) || ((pSW->L_Status==L_RELAYON) && pSW->uSdhz_L.bFlag.bYtOn)
	#endif
	) )
	{
		soe_record_ev(EV_FA_U0GJ+sw*EV_SW_NUM, pSW->uSdhz_S.bFlag.bOverU0 ,  U01>U02?U01:U02,I0,0 );	
	}
	if(soe_check(EV_BE_UO+sw*EV_SW_NUM) && !pSW->uSdhz_S.bFlag.bOverU0)   // 合前零压返回
		soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 0, 0,0,0 );
#ifdef GD_AREA_HEYUAN_2021
	if(pR->tSWST.uSWST.bFlag.bDITW)
	{
		pSW->uSdhz_L.bFlag.bYtOn = false;
		pSW->uSdhz_S.bFlag.bYtOn = false;
	}
#endif
	
	//残压检测
	fa_uf_set(sw, pR->run_stu.fa_ls>0, dStep);

	//有压标志
	pSW->uSdhz_S.bFlag.bYY = pSW->uSdhz_S.bFlag.bUABYY || pSW->uSdhz_S.bFlag.bUBCYY;													//有压
		
	//初始化完成
	if((pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_S.bFlag.bYY)  //合位时,无压变有压才能动作
	    ||(pR->tSWST.uSWST.bFlag.bDITW && !pSW->uSdhz_S.bFlag.bYY))//分位时,有压变无压才能动作
	{
		pSW->bSDHZinit=1; 
	}

	/*对侧有残压压标志
	pSW->uSdhz_S.bFlag.bOppositeUF = (pSW->uSdhz_S.bFlag.bUABFlash && (!pSW->uSdhz_S.bFlag.bPower)) 
									|| (pSW->uSdhz_S.bFlag.bUBCFlash && pSW->uSdhz_S.bFlag.bPower);		
	*/
	
	//对侧来电
	bY1 = ((pSW->uSdhz_S.bFlag.bUABYY 	&& (!pSW->uSdhz_S.bFlag.bUBCYY) && (!pSW->uSdhz_S.bFlag.bPower)) 
		||((!pSW->uSdhz_S.bFlag.bUABYY) && pSW->uSdhz_S.bFlag.bUBCYY 	&& pSW->uSdhz_S.bFlag.bPower));	
	RunTR(&pSW->tOpsiteYY100ms, bY1, dStep);
	pSW->uSdhz_S.bFlag.bOppositeYY = pSW->tOpsiteYY100ms.boolTrip  && pSet->bTT_fa_poweron && pSet->bTT_fa_lineon;	

	//上电侧来电
	bY1 = ((pSW->uSdhz_S.bFlag.bUABYY && (!pSW->uSdhz_S.bFlag.bUBCYY)	&& (pSW->uSdhz_S.bFlag.bPower)) 
		|| ((!pSW->uSdhz_S.bFlag.bUABYY) && pSW->uSdhz_S.bFlag.bUBCYY	&& (!pSW->uSdhz_S.bFlag.bPower)));
	RunTR(&pSW->tPowerYY100ms, bY1, dStep);
	pSW->uSdhz_S.bFlag.bPowerYY = pSW->tPowerYY100ms.boolTrip;	

}

static void fa_unlock_s_bs(int sw)
{
	if(soe_check(EV_BS_X_L+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_X_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_X_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BSBE_U0+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BSBE_U0+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	
	if(soe_check(EV_BS_DB+sw*EV_SW_NUM)==true)	// 
	{
		soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
	}

#ifdef GD_AREA_ZHONGSHAN_FTU
	if(!g_tRelay[sw].run_stu.bs_bhz)
#endif	
	{
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
		}
	}
	if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
	{
		soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)==true)
	{
		soe_record_ev(EV_BS_FZMORE+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	//if(soe_check(EV_GOOSE_GZBS_FA)==true)	// goose故障闭锁
	//	soe_record_ev(EV_GOOSE_GZBS_FA, 0, 0,0,0 );
	//if(soe_check(EV_GOOSE_TZBS_FA)==true)	// goose故障闭锁
	//	soe_record_ev(EV_GOOSE_TZBS_FA, 0, 0,0,0 );
#ifdef FA_OC_COUNT	
	if(soe_check(EV_BS_OC_COUNT+sw*EV_SW_NUM)==true)
	{
		soe_record_ev(EV_BS_OC_COUNT+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	g_tRelay[sw].tSDHZ.fa_oc_count=0;
#endif
#ifdef GD_AREA_CHAOZHOUFENGXI//潮州合前零压不允许直接解锁 2021-4-27
	if(soe_check(EV_BE_UO+sw*EV_SW_NUM)==true)	 // 
	{
		soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 0, 0,0,0 );
	}
#endif

	fa_s_set_savestatus(sw);
}

static bool fa_check_s_bs_hz(int sw)
{
	#if 0
	if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
	if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
	#endif
	if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
#ifdef FA_OC_COUNT	
	if(soe_check(EV_BS_OC_COUNT+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
#endif
	if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
#ifdef YK_FA_ENBLE
	if(soe_check(EV_YK_BS_FA+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}	
#endif
#ifdef GD_AREA_CHAOZHOUFENGXI
	if(soe_check(EV_BSBE_U0+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}	
#endif

	if(g_tRelay[sw].tDYJL.bLed==true)
	{
		return true;
	}
	
#ifndef GD_AREA_ECZD_MEIZHOU_2021
	if(g_tRelay[sw].tPLJL.bLed==true)
	{
		return true;
	}
#endif

	if(soe_check(EV_GOOSE_GZBS_FA)==true)	// goose故障闭锁
		return true;
	if(soe_check(EV_GOOSE_TZBS_FA)==true)	// goose故障闭锁
		return true;
	return false;
}


static void fa_unlock_l_bs(int sw)
{
	if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	
	if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
	{
		soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)==true)
	{
		soe_record_ev(EV_BS_FZMORE+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	/*if(soe_check(EV_GOOSE_GZBS_FA)==true)	// goose故障闭锁
		soe_record_ev(EV_GOOSE_GZBS_FA, 0, 0,0,0 );
	if(soe_check(EV_GOOSE_TZBS_FA)==true)	// goose故障闭锁
		soe_record_ev(EV_GOOSE_TZBS_FA, 0, 0,0,0 );
	*/
}
#if 0
static bool fa_check_l_bs_hz(int sw)
{
	
	if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)   // 
	{
		return true;
	}
	
	return false;
}
#endif
static bool  fa_check_all_l_bs(int sw)
{
	bool bY=false;
	bY=0
		||soe_check(EV_BS_UF_P+sw*EV_SW_NUM)
		||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)
		||soe_check(EV_HHGZ+sw*EV_SW_NUM)
		||soe_check(EV_BS_U0+sw*EV_SW_NUM)
		||soe_check(EV_BS_HA+sw*EV_SW_NUM)
	#ifdef YK_FA_ENBLE
		||soe_check(EV_YK_BS_FA+sw*EV_SW_NUM)	
	#endif
		||soe_check(EV_GOOSE_GZBS_FA)// goose故障闭锁
		||soe_check(EV_GOOSE_TZBS_FA);// goose故障闭锁
			
	if(bY)
	{
		if(soe_check(EV_BS_ALL+sw*EV_SW_NUM)==false)
		{
			soe_record_ev(EV_BS_ALL+sw*EV_SW_NUM, 1, 0,0,0 );
		}
	}
	else
	{
		if(soe_check(EV_BS_ALL+sw*EV_SW_NUM)==true)
		{
			soe_record_ev(EV_BS_ALL+sw*EV_SW_NUM, 0, 0,0,0 );
		}
	}
	return bY;
}

bool  fa_check_auto_l_bs(int sw)
{
	bool bY=false;
	bY=0
		//||soe_check(EV_BS_U0+sw*EV_SW_NUM)
		||soe_check(EV_BS_HA+sw*EV_SW_NUM);

	return bY;
}



void fa_rstbs_soe(int sw)
{

	if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_X_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_X_L+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_X_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	#ifndef FA_BSYTIME_JS	//不允许直接解锁
	if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	#endif
	if(soe_check(EV_BS_DB+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)  
	{
		soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
	}
	if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==true)   // 
	{
		soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
	}
#ifndef GD_AREA_CHAOZHOUFENGXI//潮州合前零压不允许直接解锁 2021-4-27
	if(soe_check(EV_BE_UO+sw*EV_SW_NUM)==true)	 // 
	{
		soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 0, 0,0,0 );
	}
#endif
	if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==true)
		soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理
#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
	if(soe_check(EV_FA_GL_TZ2+sw*EV_SW_NUM)==true)
		soe_record_ev(EV_FA_GL_TZ2+sw*EV_SW_NUM, 0, 0,0 ,0 );	
#endif
	if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==true)
		soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
	
	if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
		soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0 ,0 );
	
	if(soe_check(EV_FA_FZ+sw*EV_SW_NUM)==true)	 // 
		soe_record_ev(EV_FA_FZ+sw*EV_SW_NUM, 0, 0,0,0 );  

	if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)==true)	 // 
		soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 0, 0,0,0 );  
	
	if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==true)   // 
		soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 0, 0,0,0 );
	
}
void fa_change_status_print(WORD oldStatus,WORD newStatus,const char **str)
{
	if(oldStatus==newStatus)
		return;
	rt_printf_time("status: %s -> %s  \r\n",str[oldStatus],str[newStatus]);
}
//S 状态转换
void fa_s_state_change(int sw,int state)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;

	#ifdef FA_BSYTIME_JS
	if(pSW->uSdhz_S.bFlag.bTempJS && S_YTIME==pSW->S_Status && S_BSYTIME==state)//之前已正向闭锁未解锁，再次进入Y闭锁
		pSW->uSdhz_S.bFlag.bTempJS = false;//产生Y闭锁SOE后，再次=TURE
	#endif
	
	ResetTR(&pSW->tOnXSTime);//X
	if(state!=S_BSHHGZ && state!=S_BSDL)//合后故障/大电流闭锁可以继续报Y闭锁SOE,所以不清Y计时器
		ResetTR(&pSW->tOnYSTime);//Y	
	//ResetTR(&pSW->tOnZSTime);//Z
	ResetTR(&pR->tSDHZ.tOnBSTZTime);  
	if(pSW->S_Status == state)
		return;
	fa_change_status_print(pSW->S_Status,state,fa_s_status);
	pSW->S_Status = state;
	pSW->s_flag_save=pSW->uSdhz_S.wfFlag;
	pSW->S_Status_save=pSW->S_Status;
	
//	pSW->uSdhz_S.bFlag.bSNChange = pSW->uSdhz_S.bFlag.bUABYY;
//	pSW->uSdhz_S.bFlag.bPower = pSW->uSdhz_S.bFlag.bUABYY;
	pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
}
static void fa_l_state_change(int sw,int state)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	if(pSW->L_Status == state)
		return;
	fa_change_status_print(pSW->L_Status,state,fa_l_status);
	pSW->L_Status = state;
	pSW->l_flag_save=pSW->uSdhz_L.wfFlag;
	pSW->L_Status_save=pSW->L_Status;
	pSW->L_Status = state;	
	pSW->uSdhz_L.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
}
static bool soe_check_pt_ok(u32 sw)
{
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	if(!pSet->bTT_fa_ptdx)//PT告警
		return true;//未投入，直接返回OK
	return ((soe_check(EV_PT1ERR)==false) && (soe_check(EV_PT2ERR)==false));
}
static bool cheak_pt_ok_ing(u32 sw)//检查PT实时状态
{
	if(!soe_check_pt_ok(sw))
		return FALSE;//返回异常
	if(tPT.tTPT1DXTime.dTimer>T_100ms || tPT.tTPT2DXTime.dTimer>T_100ms)
		return FALSE;//返回异常
	return TRUE;//返回OK
}
#ifdef	FA_OC_COUNT
static bool isBs_fa_oc_count(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bool bVIok;
	static bool oc_flag;
	bVIok = pSW->uSdhz_S.bFlag.bGL2;
	if(!pSet->bTT_fa_oc_count)//压板退出
		return FALSE;
	if(pSW->fa_oc_count >= pSet->fa_oc_count_m)//次数已满足闭锁条件
		return TRUE;
	if(bVIok)
	{
		if(oc_flag==false)
		{
			//rt_printf("count=%d m=%d\r\n",pSW->fa_oc_count,pSet->fa_oc_count_m);
			pSW->fa_oc_count++ ;
		}
		oc_flag=TRUE;
	}
	else
	{
		oc_flag=FALSE;
	}
	return FALSE;
	
}
#endif
static void fa_sw_opt(int sw,u16 soeCode)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW =&pR->tSDHZ;
	TU0_T *pU0=&pR->tU0TZ;
	TOC_T *poc ;
	DWORD Us1,Us2;
	DWORD Ia,Ib,Ic;	
	DWORD I0,U01,U02;
	int ui_begin;	
				
	ui_begin = UI_SW_INDEX_BEGIN(sw);
	
	Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
	Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
	Ia = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IA].m2[0]), 256, g_ui[ui_begin + SW_AC_IA].m2_factor_k);
	Ib = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IB].m2[0]), 256, g_ui[ui_begin + SW_AC_IB].m2_factor_k);
	Ic = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_IC].m2[0]), 256, g_ui[ui_begin + SW_AC_IC].m2_factor_k);

	I0 = _Mul_Div_U(sqrt_32fix(g_ui[ui_begin + SW_AC_I0].m2[0]), 256, g_ui[ui_begin + SW_AC_I0].m2_factor_k);
	U01 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U01].m2[0]), 256, g_ui[PUB_AC_U01].m2_factor_k);	
	U02 = _Mul_Div_U(sqrt_32fix(g_ui[PUB_AC_U02].m2[0]), 256, g_ui[PUB_AC_U02].m2_factor_k);	

	//复归合闸原因SOE				
	if(soe_check(EV_YK_HZ+sw*EV_SW_NUM)==true)	 // 遥控合闸
		soe_record_ev(EV_YK_HZ+sw*EV_SW_NUM,0, 0,0,0 ); 		
	if(soe_check(EV_DL_HZ+sw*EV_SW_NUM)==true)	 //
		soe_record_ev(EV_DL_HZ+sw*EV_SW_NUM,0, 0,0,0 ); 
	if(soe_check(EV_HA_HZ+sw*EV_SW_NUM)==true)	 //
		soe_record_ev(EV_HA_HZ+sw*EV_SW_NUM,0, 0,0,0 ); 

	switch(soeCode)
	{
		case EV_FA_FZ:
			if(soe_check(EV_FA_FZ+sw*EV_SW_NUM)==false)	 // EV_FA_FZ
				soe_record_ev(EV_FA_FZ+sw*EV_SW_NUM, 1, Us1,Us2,0 ); 
			
			rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	//录波类型：跳闸类

			pR->tLostVot.bLostVotLed = true;	
			pR->tLostVot.uLostVot.bFlag.bEvent = true;
			pR->tSWST.uSWST.bFlag.bCYY = false;	//清曾有压标志		
			//ResetTR(&pR->tLostVot.tCYY25ms0ms);
			pR->tLostVot.uLostVot.bFlag.bTz=true;
			//InitTR_Time(&pR->tLostVot.tLostVotTime, pSet->dT_Z, T_20ms);    	 //
			pR->tLostVot.uLostVot.bFlag.bQD=true;
			
			break;
		case EV_HHGZ://合后故障分：相间、接地、零序电压
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==false)
				soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 ); 
#if defined GD_AREA_ECZD_2020 && !defined GD_AREA_ZHONGSHAN_2020
			pSW->uSdhz_S.bFlag.bHhgz = true;
#endif
			if(pSW->uSdhz_S.bFlag.bGL)
			{	
				poc = &g_tRelay[sw].tOC[FA_GL];
				//poc->sta.bFlag.bIaQD=true;
				poc->sta.bFlag.bQD = true;
				poc->sta.bFlag.bTz = true;
				poc->sta.bFlag.bTripBak = true;
				poc->sta.bFlag.bDzLed = true;
				poc->sta.bFlag.bGj = true;  // 告警
				poc->sta.bFlag.bGjEvent = true;
				poc->tQDTime.boolTrip = true; 
				poc->tQD25ms.boolTrip =true;
				if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==false)	 //
					soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 1, Ia,Ib,Ic );     

				if(g_ui[ui_begin + SW_AC_IA].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL].dI)
				{
					pR->bYcRefresh.bAGl = true;
				}

				if(g_ui[ui_begin + SW_AC_IB].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL].dI)
				{
					pR->bYcRefresh.bBGl = true;
				}

				if(g_ui[ui_begin + SW_AC_IC].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL].dI)
				{
					pR->bYcRefresh.bCGl = true;
				}

				rcd_start(sw,RECORD_TYPE_GLGZ, RECORD_LEN_TZQD); 	//录波类型：跳闸类
				poc->sta.bFlag.bQDWave=true;
			}
			else if(pSW->uSdhz_S.bFlag.bGL_II)
			{	
				poc = &g_tRelay[sw].tOC[FA_GL_II];
				//poc->sta.bFlag.bIaQD=true;
				poc->sta.bFlag.bQD = true;
				poc->sta.bFlag.bTz = true;
				poc->sta.bFlag.bTripBak = true;
				poc->sta.bFlag.bDzLed = true;
				poc->sta.bFlag.bGj = true;  // 告警
				poc->sta.bFlag.bGjEvent = true;
				poc->tQDTime.boolTrip = true; 
				poc->tQD25ms.boolTrip =true;
			//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理		
            #if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
				if(soe_check(EV_FA_GL_TZ2+sw*EV_SW_NUM)==false)	 //
					soe_record_ev(EV_FA_GL_TZ2+sw*EV_SW_NUM, 1, Ia,Ib,Ic );     
			#endif
				rcd_start(sw,RECORD_TYPE_GLGZ, RECORD_LEN_TZQD); 	//录波类型：跳闸类
				poc->sta.bFlag.bQDWave=true;
				
				if(g_ui[ui_begin + SW_AC_IA].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL_II].dI)
				{
					pR->bYcRefresh.bAGl = true;
				}

				if(g_ui[ui_begin + SW_AC_IB].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL_II].dI)
				{
					pR->bYcRefresh.bBGl = true;
				}

				if(g_ui[ui_begin + SW_AC_IC].m2[0] > pRunSet->tSwSet[sw].toc[FA_GL_II].dI)
				{
					pR->bYcRefresh.bCGl = true;
				}
			}
	
			else if (pSW->uSdhz_S.bFlag.bJD) 
			{
				poc = &g_tRelay[sw].tOC[FA_LX];
				poc->sta.bFlag.bQD = true;
				poc->sta.bFlag.bTz = true;
				poc->sta.bFlag.bTripBak = true;
				poc->sta.bFlag.bDzLed = true;
				poc->sta.bFlag.bGj = true;	// 告警
				poc->sta.bFlag.bGjEvent = true;
				
				if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==false)	 //
					soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 1, I0,  U01>U02?U01:U02,0 );  
				
				rcd_start(sw,RECORD_TYPE_LXGL, RECORD_LEN_TZQD); 	//录波类型：跳闸类
				poc->sta.bFlag.bQDWave=true;

				if(g_ui[ui_begin + SW_AC_I0].m2[0] > pRunSet->tSwSet[sw].toc[FA_LX].dI)
				{
					pR->bYcRefresh.bLx = true;
				}
				
			}
			else if (pSW->uSdhz_S.bFlag.bOverU0)
			{
				pU0->uZOV.bFlag.bQD = true;
				pU0->uZOV.bFlag.bTz = true;
				if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==false)
					soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 1,   U01>U02?U01:U02,I0 ,0 );  
	
				rcd_start(sw,RECORD_TYPE_LXDY, RECORD_LEN_TZQD); 	
				pU0->uZOV.bFlag.bEvent = true;	
				pU0->bU0Led = true;
			}
			else
			{
				rt_printf_time("error HHGZ\r\n");
				if(soe_check(EV_FA_FZ+sw*EV_SW_NUM)==false)	 // EV_FA_FZ
					soe_record_ev(EV_FA_FZ+sw*EV_SW_NUM, 1, Us1,Us2,0 ); 
				
				rcd_start(sw,RECORD_TYPE_XLSY, RECORD_LEN_TZQD); 	//录波类型：跳闸类

				pR->tLostVot.bLostVotLed = true;	
				pR->tLostVot.uLostVot.bFlag.bEvent = true;
				pR->tSWST.uSWST.bFlag.bCYY = false;	//清曾有压标志		
				pR->tLostVot.uLostVot.bFlag.bTz=true;
				pR->tLostVot.uLostVot.bFlag.bQD=true;
				//fa_s_state_change(sw,S_INIT);
			}
			break;		
	}
}
#ifdef FA_BSYTIME_JS
static void rst_ybs_soe(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
		soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
	if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
		soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
	if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
		soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );		
	if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
		soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );	
	if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)  
		soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
	pR->tU0TZ.bU0Led=false;
	pSW->uSdhz_S.bFlag.bTempJS = false;
	fa_close_led(sw);
}

void fa_s_bsYtime_js(int sw, DWORD  dStep)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	//TSETSW *pSet = &pRunSet->tSwSet[sw];
	{
	
		//fa_rstbs_soe(sw);
		fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//返回初始状态
		//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
		pSW->uSdhz_S.bFlag.bUABFlash = false;
		pSW->uSdhz_S.bFlag.bUBCFlash = false;

	}
	pSW->uSdhz_S.bFlag.bTempJS = TRUE;
	ResetTR(&pSW->tOnY_JSTime);				//js时间计数

}
#endif
/**************************************************************************
函数名称：Pro_S_Status_Run
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：分段开关状态流程
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_s_status_run(int sw, DWORD  dStep)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bool bVTok,bVIok,bUoOk;
	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); 	

#ifdef FA_PL_PJ
	bool bFreq0,bFreq1;
	float freq0,freq1;
#endif

#ifdef GD_AREA_ECZD_MEIZHOU_2021
	static bool bLockHZ=false;
#endif

	if(!pSW->bSDHZinit) return;//#ifdef GD_AREA_ZHONGSHAN_2020

	#ifdef FA_PL_PJ
		if(pRunSet->bTT_judgeFreq)
		{
			//频率在要求范围内
			freq0=freq_get(0);
			freq1=freq_get(1);

			//电源1频率判断
			if((freq0>=48.9) && (freq0<=50.9))
			{
				bFreq0 = true;
			}
			else
			{
				bFreq0 = false;
			}
			//电源2频率判断
			if((freq1>=48.9) && (freq1<=50.9))
			{
				bFreq1 = true;
			}
			else
			{
				bFreq1 = false;
			}
		}
		else
		{
			bFreq0 = true;
			bFreq1 = true;
		}
	#endif

#if defined GD_AREA_JIEYANG_2021 || defined GD_AREA_ECZD_2020
	if(!pSW->uSdhz_S.bFlag.bYY)
	{
		pSW->uSdhz_S.bFlag.bJS=false;
	}
#endif	

	switch(pSW->S_Status)
	{	
		case S_INIT:

		#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			pSW->uSdhz_S.bFlag.bBsXtime_P = false;
			pSW->uSdhz_S.bFlag.bBsXtime_L = false;
		#endif
	
		#ifdef	FA_OC_COUNT
			if(pSet->bTT_fa_oc_count && pR->tSWST.uSWST.bFlag.bDIHW)
			{
				fa_s_state_change(sw,S_USUAL);
				return;  //开关在合闸位置且双侧有压，进入正常运行态
			}
		#endif
			
			if((!pSet->bTT_fa_poweron)&&(!pSet->bTT_fa_lineon))
			{
				fa_uf_clear(sw,false);//两侧上电合闸压板退出，清残压标志 
				return;	
			}			
			if(pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_S.bFlag.bUABYY && pSW->uSdhz_S.bFlag.bUBCYY)
			{
				//rt_printf("双侧有压，开关合位 %d %d \r\n",pSW->uSdhz_S.bFlag.bUABYY,pSW->uSdhz_S.bFlag.bUBCYY);
				fa_s_state_change(sw,S_USUAL);
				pSW->bSDHZinit=1;			
				return;  //开关在合闸位置且双侧有压，进入正常运行态
			}
			ResetTR(&pSW->tOnXSTime);
			ResetTR(&pSW->tOnYSTime);
			ResetTR(&pSW->tOnZSTime);
			
		#ifdef FA_PL_PJ
			ResetTR(&pSW->tFREQSAB25ms);
			ResetTR(&pSW->tFREQSBC25ms);
		#endif

		#ifdef GD_AREA_ECZD_MEIZHOU_2021
			if(pR->tPLJL.sta.bFlag.bTz || bLockHZ)
			{//中山局要求频率解列后需判掉电再上电的过程才允许得电合闸
				fa_uf_clear(sw,false);
				if(pSW->uSdhz_S.bFlag.bYY)
				{
					bLockHZ = true;
					return;
				}
				else
				{
					bLockHZ = false;
				}
			}
		#endif
		
			if (pSW->uSdhz_S.bFlag.bUABFlash||pSW->uSdhz_S.bFlag.bUBCFlash)				//如果对侧有瞬时电压
			{
				//pSW->S_Status = S_BSFLASH;					//进入瞬时电压闭锁状态
				pSW->uSdhz_S.bFlag.bPower = pSW->uSdhz_S.bFlag.bUABFlash;//电压方向保存残压方向
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				fa_s_state_change(sw,S_BSFLASH);
				return;
			}
			else if (pSW->uSdhz_S.bFlag.bYY) //有压&&PT正常&&soe_check_pt_ok(sw)
			{
				if(pSW->bSDHZinit==0)//先无压再有压
				{
					return;
				}
				if((pSW->uSdhz_S.bFlag.bUabflashDI && !pSW->uSdhz_S.bFlag.bUABYY)
					||(pSW->uSdhz_S.bFlag.bUbcflashDI && !pSW->uSdhz_S.bFlag.bUBCYY))
				{
					pSW->uSdhz_S.bFlag.bPower = pSW->uSdhz_S.bFlag.bUABYY;//电压方向保存残压方向
					pSW->uSdhz_S.bFlag.bSNChange = !pSW->uSdhz_S.bFlag.bPower;
					fa_s_state_change(sw,S_BSFLASH);					//进入瞬时电压闭锁状态
					return;
				}	
				pSW->uSdhz_S.bFlag.bPower = pSW->uSdhz_S.bFlag.bUABYY;
				if(pR->tSWST.uSWST.bFlag.bHZWZ)
				{
					fa_s_state_change(sw,S_YTIME);//有压且合位直接进入Y时限
					#ifdef FUNC_DRIVE_JY
						ResetTR(&gb_drive.tDriveFaBSTime);
					#endif
				}	
			#ifdef FA_PL_PJ
				else if((pSW->uSdhz_S.bFlag.bUABYY&&pSet->bTT_fa_poweron&&bFreq0) || (pSW->uSdhz_S.bFlag.bUBCYY && pSet->bTT_fa_lineon&&bFreq1))
			#else
				else if((pSW->uSdhz_S.bFlag.bUABYY&&pSet->bTT_fa_poweron) || (pSW->uSdhz_S.bFlag.bUBCYY && pSet->bTT_fa_lineon))
			#endif
				{
					#if defined GD_AREA_JIEYANG_2021
						if(pSW->uSdhz_S.bFlag.bJS)
							return;
					#endif
					#ifdef FUNC_NYY_NWY
						if((pSW->uSdhz_S.bFlag.bUABYY && pSW->uSdhz_S.bFlag.bUBC_NYY_NWY)
							||(pSW->uSdhz_S.bFlag.bUBCYY && pSW->uSdhz_S.bFlag.bUAB_NYY_NWY))
							return;
					#endif
					fa_s_state_change(sw,S_XTIME);//;//pSW->S_Status = S_TEMP;						//进入临时状态	
				}	
			}
			else if(!pSW->uSdhz_S.bFlag.bYY && pSW->uSdhz_S.bFlag.bUabflashDI!=pSW->uSdhz_S.bFlag.bUbcflashDI)//无压且单侧有残压
			{
				pSW->uSdhz_S.bFlag.bPower = pSW->uSdhz_S.bFlag.bUabflashDI;//电压方向保存残压方向
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				fa_s_state_change(sw,S_BSFLASH);				//进入瞬时电压闭锁状态
				return;
			}
			else if(!pSW->uSdhz_S.bFlag.bYY && pSW->uSdhz_S.bFlag.bUabflashDI&&pSW->uSdhz_S.bFlag.bUbcflashDI)//开机的时候两侧都残压闭锁，等待有压信号	
			{
				return;
			}
		#if defined GD_AREA_JIEYANG_2021
			else if(!pSW->uSdhz_S.bFlag.bYY)
			{
				pSW->uSdhz_S.bFlag.bJS=false;
			}
		#endif
			if (pR->tSWST.uSWST.bFlag.bDIHW && !pSW->uSdhz_S.bFlag.bYY)	//开关合位且两侧失压  
				pR->tSWST.uSWST.bFlag.bCYY=true;
			fa_rstbs_soe(sw);
			
		break;

		case S_BSFLASH:
			
			if((pSW->uSdhz_S.bFlag.bUABFlash||pSW->uSdhz_S.bFlag.bUabflashDI)&&!pSW->uSdhz_S.bFlag.bUABYY)
			{
				if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==false)   // 瞬压闭锁
				{
					soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 1, 0,0,0 );
				}
				pSW->uSdhz_S.bFlag.bUBCFlash=false;
				pSW->uSdhz_S.bFlag.bUbcflashDI=false;
			}
			else if((pSW->uSdhz_S.bFlag.bUBCFlash||pSW->uSdhz_S.bFlag.bUbcflashDI)&&!pSW->uSdhz_S.bFlag.bUBCYY)
			{
				if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==false)   // 瞬压闭锁
				{
					soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 1, 0,0,0 );
				}
				pSW->uSdhz_S.bFlag.bUABFlash=false;
				pSW->uSdhz_S.bFlag.bUabflashDI=false;
			}
			
			if(pSW->bSDHZinit==0)
			{
				return;
			}
			if ((pSW->uSdhz_S.bFlag.bUABYY&&((pSW->uSdhz_S.bFlag.bUABFlash||pSW->uSdhz_S.bFlag.bUabflashDI)&&soe_check(EV_BS_UF_P+sw*EV_SW_NUM)))				// 本侧检出有压
			 ||(pSW->uSdhz_S.bFlag.bUBCYY&&((pSW->uSdhz_S.bFlag.bUBCFlash||pSW->uSdhz_S.bFlag.bUbcflashDI)&&soe_check(EV_BS_UF_L+sw*EV_SW_NUM)))
				)
			{
			#if defined GD_AREA_ZHONGSHAN || defined GD_AREA_ZHONGSHAN_2020 || defined GD_AREA_CHAOZHOU_2021 || defined GD_AREA_ECZD_2020 || defined GD_AREA_ECZD_MEIZHOU_2021//中山局、广东二次指导意见要求残压经过解锁时间才能解锁
				RunTR(&pSW->tOnJSTime, TRUE , dStep);				//js时间计数
				if(!pSW->tOnJSTime.boolTrip)
					break;
			#endif
				if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 单侧来电解锁
				{
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
					#ifdef GD_AREA_ECZD_2020
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
					#endif
				}	
				fa_uf_clear(sw,false);
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//进入临时状态
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
				pSW->uSdhz_S.wfFlag = 0;
				pSW->uSdhz_S.wfFlag = 0;
				pSW->bS_BSLed = 0;
			}
			else 

			{
				ResetTR(&pSW->tOnJSTime);
			}
		break;

		case S_XTIME:
		{
		#ifdef GD_AREA_ECZD_MEIZHOU_2021
			if(pR->tPLJL.sta.bFlag.bTz)
			{	//X计时过程中频率解列跳闸后回到INIT状态
				fa_s_state_change(sw,S_INIT);
				ResetTR(&pSW->tOnXSTime);
				fa_uf_clear(sw,false);
				return;
			}
		#endif

		#ifdef GD_AREA_ZHONGSHAN
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM))
			{
				if(!(soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && soe_check(EV_HHGZ_L+sw*EV_SW_NUM)))
				{
					if((soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && pSW->uSdhz_S.bFlag.bUBCYY)
						|| (soe_check(EV_HHGZ_L+sw*EV_SW_NUM) && pSW->uSdhz_S.bFlag.bUABYY))
					{
						RunTR(&pSW->tOnXSTime, true, dStep);				//X时间计数
					}
					else
					{
						ResetTR(&pSW->tOnXSTime);
					}
				
					if(pSW->tOnXSTime.boolTrip)
					{
						pSW->uSdhz_S.bFlag.bRLONFLAG = TRUE;
						fa_s_state_change(sw,S_YTIME);						//进入Y计时状态
					}
				}
				break;
			}
		#endif
		
		#ifdef FA_PL_PJ
			if(pRunSet->bTT_judgeFreq)
			{
				RunTR(&pSW->tFREQSAB25ms, bFreq0, dStep);
				RunTR(&pSW->tFREQSBC25ms, bFreq1, dStep);
			}
			else
			{
				pSW->tFREQSAB25ms.boolTrip = true;
				pSW->tFREQSBC25ms.boolTrip = true;
			}
		#endif

		#ifdef FA_PL_PJ
			if(pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ && (pSW->tFREQSAB25ms.boolTrip || pSW->tFREQSBC25ms.boolTrip))
		#else
			if(pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ)//无压暂停计时&& soe_check_pt_ok(sw)
		#endif
			{	
				if ( pSW->uSdhz_S.bFlag.bPower != pSW->uSdhz_S.bFlag.bUABYY && pSW->uSdhz_S.bFlag.bUABYY != pSW->uSdhz_S.bFlag.bUBCYY)	//无压暂停过程中，对侧有压
				{
				#if defined GD_AREA_ZHAOQING_FENGKAI 
					if(!pSW->tOnYSTime.boolTrip)//肇庆封开县要求X上电的Y时间内失压为残压
					{	
						fa_s_state_change(sw,S_BSFLASH);//
						pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
						break;
					}
				#endif
				#if defined GD_AREA_ZHONGSHAN_2020	
					if(!pSW->tOnYSTime.boolTrip)
					{	
						fa_s_state_change(sw,S_BSFLASH);//
						pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
						break;
					}
					else
					{
						fa_uf_clear(sw,false);
						ResetTR(&pSW->tOnYSTime);
						//fa_s_state_change(sw,S_BSFLASH);//
						//pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
						break;
					}
				#endif
					fa_s_state_change(sw,S_BSXTIME);//
					pSW->uSdhz_S.bFlag.bUABFlash = false;
					pSW->uSdhz_S.bFlag.bUBCFlash = false;
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				}
				else
				{
					RunTR(&pSW->tOnXSTime, TRUE, dStep);				//X时间计数
				#if defined GD_AREA_ZHAOQING_FENGKAI || defined GD_AREA_ZHONGSHAN_2020 || defined FA_PL_PJ
					RunTR(&pSW->tOnYSTime,TRUE, dStep);
				#endif
				}

			}
			
			//合前零压
			if(pSW->uSdhz_S.bFlag.bOverU0 && (pSet->bTT_fa_U0Tz||pSet->bTT_fa_U0Gj))
			{
				if(soe_check(EV_BE_UO+sw*EV_SW_NUM)==false)   // 
					soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 1, U01>U02?U01:U02,0,0 );
			#ifdef  GD_AREA_CHAOZHOUFENGXI
				if(soe_check(EV_BSBE_U0+sw*EV_SW_NUM)==false)   // 
					soe_record_ev(EV_BSBE_U0+sw*EV_SW_NUM, 1, U01>U02?U01:U02,0,0 );
				ResetTR(&pSW->tOnXSTime);
				break;//合前零压不走上电合闸，重新X计时 2021-4-15
			#endif
			}
			
			if (pSW->uSdhz_S.bFlag.bPowerZ&&pR->tSWST.uSWST.bFlag.bFAWL)					//如果两侧失压且无流,停电Z
			{
			#if defined  GD_AREA_ZHAOQING_FENGKAI || defined GD_AREA_ECZD_MEIZHOU_2021
				if(!pSW->tOnYSTime.boolTrip)//肇庆封开县要求X上电计时的Y时间内失压为残压
				{
					fa_s_state_change(sw,S_BSFLASH);//
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
					break;
				}
			#endif
			#if  defined GD_AREA_ZHONGSHAN_2020	//X上电计时的Y时间内失压为残压,否则返回初始状态 2020-12-3
				if(!pSW->tOnYSTime.boolTrip)
				{
					fa_s_state_change(sw,S_BSFLASH);//
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
					break;
				}
				else
				{
					fa_uf_clear(sw,false);
					fa_s_state_change(sw,S_INIT);//
					break;
				}	
			#endif
				fa_s_state_change(sw,S_BSXTIME);//pSW->S_Status = S_BSXTIME;					//进入X-Z状态，即X计时中的Z计时状态,置X计时暂停标志
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
			}
			else if((pSW->uSdhz_S.bFlag.bPower&&pSW->uSdhz_S.bFlag.bUBCFlash)||(!pSW->uSdhz_S.bFlag.bPower&&pSW->uSdhz_S.bFlag.bUABFlash))  //对侧有残压
			{
				pSW->uSdhz_S.bFlag.bPower=!pSW->uSdhz_S.bFlag.bPower;
				fa_s_state_change(sw,S_BSFLASH);
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;						//存储状态标志、来电切换状态	
			}
		#ifdef  GD_AREA_ZHAOQING_FENGKAI
			else if(pSW->tOnYSTime.boolTrip&&pSW->uSdhz_S.bFlag.bDBYY)
			{
				//过了Y计时且如果双侧有压
				{
					fa_s_state_change(sw,S_BSDOUBLE);//pSW->S_Status = S_BSDOUBLE;					//进入双侧电源闭锁状态
					fa_uf_clear(sw,false);
					break;
				}
			}
		#endif	
#ifdef FUNC_NYY_NWY
			else if(pSW->tOnXSTime.boolTrip  && ((pSW->uSdhz_S.bFlag.bUABYY && pSW->uSdhz_S.bFlag.bUBC_NYY_NWY)
				||(pSW->uSdhz_S.bFlag.bUBCYY && pSW->uSdhz_S.bFlag.bUAB_NYY_NWY)))
			{
				ResetTR(&pSW->tOnXSTime);
				fa_uf_clear(sw,false);
				fa_s_state_change(sw,S_INIT);
				break;
			}
#endif
			else if (pSW->tOnXSTime.boolTrip||pR->tSWST.uSWST.bFlag.bDIHW				//如果X计时完毕
				#ifdef FUNC_DRIVE_JY
					|| gb_drive.b_fa_reclose
				#endif
					)
			{	
			#if 1 //在X计时结束后，仍然双侧有压才判为双电源闭锁
				if(!pR->tSWST.uSWST.bFlag.bDIHW)
				{
				#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					if (pSW->uSdhz_S.bFlag.bDBYY||(pSW->uSdhz_S.bFlag.bUABYY&&pSW->uSdhz_S.bFlag.bUBCYY)
						|| (pSW->uSdhz_S.bFlag.bUABYY && soe_check(EV_PT2ERR))
						|| (pSW->uSdhz_S.bFlag.bUBCYY && soe_check(EV_PT1ERR))
						)				//如果双侧有压，潮州要求就地FA分段PT断线不闭锁得电合
				#else
					if (pSW->uSdhz_S.bFlag.bDBYY||(pSW->uSdhz_S.bFlag.bUABYY&&pSW->uSdhz_S.bFlag.bUBCYY)|| !cheak_pt_ok_ing(sw))				//如果双侧有压
				#endif
					{
					#ifdef FUNC_PRINT_PT_ERR
						if(!cheak_pt_ok_ing(sw))
						{
							rt_printf("分段模式有上电合闸需求但PT断线,不允许合闸!\r\n");
						}
					#endif

						fa_s_state_change(sw,S_BSDOUBLE);//pSW->S_Status = S_BSDOUBLE;					//进入双侧电源闭锁状态
						fa_uf_clear(sw,false);
						break;
					}
				}
			#endif
			
				pSW->uSdhz_S.bFlag.bRLONFLAG = TRUE;
				pSW->uSdhz_S.bFlag.bGL = false;
				pSW->uSdhz_S.bFlag.bGL_II = false;
				pSW->uSdhz_S.bFlag.bJD = false;
				pSW->uSdhz_S.bFlag.bXOverUo=pSW->uSdhz_S.bFlag.bOverU0;
				pR->tU0TZ.uZOV.bFlag.bU0Ov=false;
				pR->tLostVot.uLostVot.bFlag.bStartLock = false;			
				pR->tLostVot.uLostVot.bFlag.bGL = false;		
				pR->tLostVot.uLostVot.bFlag.bJD = false;	
				pR->tLostVot.uLostVot.bFlag.bFault=false;
				pR->tLostVot.uLostVot.bFlag.bSHWY = false;
				ResetTR(&pSW->tGZJYRstGLTime);
				ResetTR(&pSW->tGZJYRstGL_II_Time);
				ResetTR(&pSW->tGZJYRstJDTime);
				ResetTR(&pSW->tGZJYRstGL2Time);
				ResetTR(&pSW->tGZJYRstJD2Time);
				ResetTR(&pSW->tOnYSTime);
				
			#ifdef FA_PL_PJ
				ResetTR(&pSW->tFREQSAB25ms);
				ResetTR(&pSW->tFREQSBC25ms);
			#endif

			#ifdef FUNC_DRIVE_JY
				ResetTR(&gb_drive.tDriveFaBSTime);
				gb_drive.b_fa_reclose = false;
				gb_drive.b_clear_bs = true;
			#endif
			
				//ResetTR(&pSW->tOnJSTime);				//js时间计数
				pR->tLostVot.uLostVot.bFlag.bSHWY=false;//清手合无压标志
				fa_s_state_change(sw,S_YTIME);//pSW->S_Status = S_YTIME;						//进入Y计时状态
			}
			
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			if(!pSW->uSdhz_S.bFlag.bUABYY && !pSW->uSdhz_S.bFlag.bUBCYY && !pSW->uSdhz_S.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL)
			{	//双侧有压返回但电压未低于无压值时
				ResetTR(&pSW->tOnXSTime);
				fa_s_state_change(sw,S_BSXTIME);
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
			}
#endif
		}
		break;

		case S_BSXTIME:
			if(pSW->uSdhz_S.bFlag.bPower) 
			{

				if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==false)   // x闭锁
				{
					soe_record_ev(EV_BS_X_P+sw*EV_SW_NUM, 1, 0,0,0 );
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					pSW->uSdhz_S.bFlag.bBsXtime_P = true;
					pSW->uSdhz_S.bFlag.bHzEnable_P = false;
#endif
				}
			}
			else
			{
				if(soe_check(EV_BS_X_L+sw*EV_SW_NUM)==false)   // x闭锁
				{
					soe_record_ev(EV_BS_X_L+sw*EV_SW_NUM, 1, 0,0,0 );
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					pSW->uSdhz_S.bFlag.bBsXtime_L = true;
					pSW->uSdhz_S.bFlag.bHzEnable_L = false;
#endif
				}
			}
		#if	defined GD_AREA_ZHUHAI_V2
			if (pSW->uSdhz_S.bFlag.bPowerYY && (pSW->uSdhz_S.bFlag.bUABYY||(pSW->uSdhz_S.bFlag.bUBCYY&&pR->run_stu.fa_start_hz)))					//上电侧来电
        #elif defined GD_AREA_JIEYANG
			if (pSW->uSdhz_S.bFlag.bPowerYY && (pSW->uSdhz_S.bFlag.bUBCYY||(pSW->uSdhz_S.bFlag.bUABYY&&pR->run_stu.fa_start_hz)))	
		#elif defined GD_AREA_ECZD_CHAOZHOU_2022
			if (pSW->uSdhz_S.bFlag.bPowerYY && ((pSW->uSdhz_S.bFlag.bPowerYY == pSW->uSdhz_S.bFlag.bUABYY)?(pSW->uSdhz_S.bFlag.bHzEnable_P):(pSW->uSdhz_S.bFlag.bHzEnable_L)))					//上电侧掉电再来电
		#else
			if (pSW->uSdhz_S.bFlag.bPowerYY)					//上电侧来电
	#endif
			{
	#if defined GD_AREA_ZHONGSHAN || defined GD_AREA_ZHONGSHAN_2020 || defined GD_AREA_ECZD_2020	//中山、广东二次指导意见要求X闭锁需经过解锁时间才能解
				RunTR(&pSW->tOnJSTime, TRUE, dStep);				//js时间计时器
				if(!pSW->tOnJSTime.boolTrip)
					break;
	#endif
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//返回初始状态
				if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 对侧来电解锁
				{
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
					#ifdef GD_AREA_ECZD_2020
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
					#endif
				}	
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
			}
	    #ifdef GD_AREA_ZHONGSHAN_2020
			else if(pSW->uSdhz_S.bFlag.bDBYY)
			{
				RunTR(&pSW->tOnJSTime, TRUE, dStep);				//js时间计时器
				if(!pSW->tOnJSTime.boolTrip)
					break;
				fa_s_state_change(sw,S_BSDOUBLE);
			}
		#endif
			else
			{
				ResetTR(&pSW->tOnJSTime);				//js时间计时器
			}
			fa_uf_clear(sw,false);
		break;
		
		case S_BSDOUBLE:
		#ifdef GD_AREA_ZHONGSHAN_2020
			#if 0
			if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)	 // 对侧来电解锁
			{
				soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
			}
			#endif
								
			pSW->uSdhz_S.bFlag.bUABFlash = false;
			pSW->uSdhz_S.bFlag.bUBCFlash = false;
			if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_X_P+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_BS_X_L+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_X_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			
			if(soe_check(EV_BE_UO+sw*EV_SW_NUM)==true)	 // 
			{
				soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 0, 0,0,0 );
			}			
			if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );
			}
			if(soe_check(EV_FA_GL_TZ2+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_GL_TZ2+sw*EV_SW_NUM, 0, 0,0 ,0 );
			}
			if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
			}
			if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0 ,0 );
			}
			if(soe_check(EV_FA_FZ+sw*EV_SW_NUM)==true)	 // 
			{
				soe_record_ev(EV_FA_FZ+sw*EV_SW_NUM, 0, 0,0,0 );  
			}
			if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)==true)	 //
			{
				soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 0, 0,0,0 );  
			}
			if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==true)   // 
			{
				soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
			{
				soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		#endif
		#ifndef GD_AREA_ZHONGSHAN_2020 //中山2020要求双电源不报双电源闭锁SOE
			if(soe_check(EV_BS_DB+sw*EV_SW_NUM)==false && pSW->uSdhz_S.bFlag.bDBYY)			//双电源闭锁
			{
				soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 1, 0,0,0 );
			}
		#endif
			if (!pSW->uSdhz_S.bFlag.bDBYY&&pSW->uSdhz_S.bFlag.bPowerZ)						//如果失压
			{
				fa_uf_clear(sw,false);
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_D_ZTIME;					//进入D-Z状态
			}				
		break;

		case S_YTIME:	
		{
		#ifdef GD_AREA_ECZD_MEIZHOU_2021
			if(pR->tPLJL.sta.bFlag.bTz)
			{	//Y计时过程中频率解列跳闸后回到INIT状态
				fa_s_state_change(sw,S_INIT);
				ResetTR(&pSW->tOnYSTime);
				fa_uf_clear(sw,false);
				return;
			}
		#endif
		#ifdef GD_AREA_ZHONGSHAN_2020	//中山2020要求手合无压进入Y时间，如果Y时间合后故障则闭锁双侧 2020-12-23
			if((pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ)||pR->tLostVot.uLostVot.bFlag.bSHWY )//无压暂停计时
				RunTR(&pSW->tOnYSTime, TRUE, dStep);				//启动Y时间计数
		#else
			if(pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ)//无压暂停计时
				RunTR(&pSW->tOnYSTime, TRUE, dStep);				//启动Y时间计数
		#endif

		#ifdef GD_AREA_ZHONGSHAN
			if((soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && !soe_check(EV_HHGZ_L+sw*EV_SW_NUM))
				|| (!soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && soe_check(EV_HHGZ_L+sw*EV_SW_NUM)))
			{
				if(!pSW->uSdhz_S.bFlag.bYY)
				{
					ResetTR(&pSW->tOnJSTime);
					fa_s_state_change(sw,S_XTIME);
					fa_sw_opt(sw, EV_FA_FZ);//失压分闸
				}
				
				RunTR(&pSW->tOnJSTime, (pSW->uSdhz_S.bFlag.bDBYY || pSW->uSdhz_S.bFlag.bOppositeYY) && (soe_check(EV_HHGZ+sw*EV_SW_NUM)==true), dStep);
				
				if(pSW->tOnJSTime.boolTrip)
				{
					fa_close_led(sw);
					
					if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					
					if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					
					if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					
					if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				}

				bVTok=!pSet->bTT_fa_Icheck ; //电压时间型，不判故障电流
				bVIok=(pSW->uSdhz_S.bFlag.bGL||pSW->uSdhz_S.bFlag.bGL_II||pSW->uSdhz_S.bFlag.bJD);//合后故障跳闸			
				bUoOk = pSW->uSdhz_S.bFlag.bOverU0 && pSet->bTT_fa_U0Tz && soe_check(EV_BE_UO+sw*EV_SW_NUM)==false;
				if(((bVIok&&pSet->bTT_fa_gzTz)||bUoOk)&& !pR->bBSTZ)	//合后有故障	 	且未遮断闭锁					
				{
					fa_sw_opt(sw, EV_HHGZ);//合后故障分闸
					if((soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && pSW->uSdhz_S.bFlag.bUBCYY)
						|| (soe_check(EV_HHGZ_L+sw*EV_SW_NUM) && pSW->uSdhz_S.bFlag.bUABYY))
					{
						pSW->uSdhz_S.bFlag.bPower = !pSW->uSdhz_S.bFlag.bPower;
					}
					if(pSet->bTT_fa_gzbshz||bUoOk)//合后故障闭锁合闸
						fa_s_state_change(sw,S_BSHHGZ);	
					ResetTR(&pSW->tOnJSTime);
				}
				
				break;
			}
		#endif
			//X上电合闸失败	
		#ifdef FUNC_DRIVE_JY
			//为避免传动合闸时直接进入YTIME而合闸拒动SOE未返回而导致进入错误态；
			//正常逻辑进入YTIME时合闸拒动已返回，无需此延时；
			if(gb_drive.b_clear_bs)
			{
				RunTR(&gb_drive.tDriveFaBSTime,true,dStep);
				if(gb_drive.tDriveFaBSTime.boolTrip)
				{
					gb_drive.b_clear_bs = false;
					if(soe_check(EV_HZFAIL+sw*EV_SW_NUM))
					{
						pSW->uSdhz_S.bFlag.bSNChange = pSW->uSdhz_S.bFlag.bPower;
						if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)==false)
							soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 1, 0,0,0 ); 
						fa_s_state_change(sw,S_BS_SW);//						pSW->uSdhz_S.bFlag.bUABFlash = false;
						pSW->uSdhz_S.bFlag.bUBCFlash = false;
					
						break;
					}
				}
			}
			else
		#endif
			{
				if(soe_check(EV_HZFAIL+sw*EV_SW_NUM))
				{
					pSW->uSdhz_S.bFlag.bSNChange = pSW->uSdhz_S.bFlag.bPower;
					if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)==false)
						soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 1, 0,0,0 ); 
					fa_s_state_change(sw,S_BS_SW);//						pSW->uSdhz_S.bFlag.bUABFlash = false;
					pSW->uSdhz_S.bFlag.bUBCFlash = false;
					
					break;
				}
			}
			
			#ifdef FA_BSYTIME_JS 
			   #ifdef GD_AREA_ZHONGSHAN 			
			   RunTR(&pSW->tOnY_JSTime, pSW->uSdhz_S.bFlag.bTempJS && !pR->bBSTZ , dStep);			   //js时间计数
			   #else
			   RunTR(&pSW->tOnY_JSTime, pSW->uSdhz_S.bFlag.bDBYY&&pSW->uSdhz_S.bFlag.bTempJS && !pR->bBSTZ , dStep);				//js时间计数
			   #endif
			   if(pSW->tOnY_JSTime.boolTrip)
					rst_ybs_soe(sw);
			#endif
			pR->tSWST.uSWST.bFlag.bCYY = true;		//防止开关位置遥信未来得及检测到，CYY标志未及时置一，CYY判断开关位置为合状态
			if(pSW->uSdhz_S.bFlag.bGL||pSW->uSdhz_S.bFlag.bGL_II)	//合后故障时间内发生故障在判故障时已与控制字关联
			{
				pR->tLostVot.uLostVot.bFlag.bGL = true;
			}
			if(pSW->uSdhz_S.bFlag.bJD)	//合后故障时间内发生故障
			{
				pR->tLostVot.uLostVot.bFlag.bJD = true;
			}			
			if(pSW->uSdhz_S.bFlag.bOverU0)	//合后有接地故障启动零序过压
			{
				pR->tU0TZ.uZOV.bFlag.bU0Ov = true&&(!pSW->uSdhz_S.bFlag.bXOverUo);
			}
			pR->tLostVot.uLostVot.bFlag.bStartLock = pSW->tOnYSTime.boolTrip&&(!pR->tLostVot.uLostVot.bFlag.bGL)&&(!pR->tLostVot.uLostVot.bFlag.bJD); //Y时间内无失压且无故障，启动失压闭锁

			if (pR->tLostVot.uLostVot.bFlag.bGL||pSW->uSdhz_S.bFlag.bGL_II||pR->tLostVot.uLostVot.bFlag.bJD||pR->tU0TZ.uZOV.bFlag.bU0Ov)
			{
				//if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==false)
				//{
					//soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );
				//}
				pR->tLostVot.uLostVot.bFlag.bFault=true;
			}
			bVTok=!pSet->bTT_fa_Icheck ; //电压时间型，不判故障电流
			bVIok=(pSW->uSdhz_S.bFlag.bGL||pSW->uSdhz_S.bFlag.bGL_II||pSW->uSdhz_S.bFlag.bJD);//合后故障跳闸			
			bUoOk = pSW->uSdhz_S.bFlag.bOverU0 && pSet->bTT_fa_U0Tz && soe_check(EV_BE_UO+sw*EV_SW_NUM)==false;
			if(((bVIok&&pSet->bTT_fa_gzTz)||bUoOk)&& !pR->bBSTZ)	//合后有故障	 	且未遮断闭锁					
			{
				fa_sw_opt(sw, EV_HHGZ);//合后故障分闸
				pSW->uSdhz_S.bFlag.bSNChange = pSW->uSdhz_S.bFlag.bPower;
				//pSW->uSdhz_S.bFlag.bPower=pSW->uSdhz_S.bFlag.bUABYY;
				if(pSet->bTT_fa_gzbshz||bUoOk)//合后故障闭锁合闸
					fa_s_state_change(sw,S_BSHHGZ);	
				else if(!pSet->bTT_fa_gzbshz&&bVTok)//电压时间型，主动跳闸后没投“合到故障闭锁合闸”，进入Y闭锁
					fa_s_state_change(sw,S_BSYTIME);//
				else
				{
					if(pSW->uSdhz_S.bFlag.bTempJS)//!!!正向闭锁临时解锁，电压方向需取反
						pSW->uSdhz_S.bFlag.bPower=!pSW->uSdhz_S.bFlag.bPower;
					fa_s_state_change(sw,S_USUAL);//直接切换至正常运行态	
				}

			#ifdef FUNC_DRIVE_JY
				gb_drive.b_clear_bs = false;
			#endif
			
				ResetTR(&pSW->tOnJSTime);
				break;
			}
		#ifdef GD_AREA_ZHONGSHAN_2020//中山2020最新要求失压的时候有故障延时到报Y闭锁
			else if(pSW->uSdhz_S.bFlag.bPowerZ && !pR->tLostVot.uLostVot.bFlag.bSHWY && !pR->bBSTZ && pR->tSWST.uSWST.bFlag.bFAWL)//Z停电&&未遮断闭锁，被动跳闸
		#else
			else if(pSW->uSdhz_S.bFlag.bPowerZ && !pR->bBSTZ && pR->tSWST.uSWST.bFlag.bFAWL)//Z停电&&未遮断闭锁，被动跳闸
		#endif
			{
				pSW->uSdhz_S.bFlag.bSNChange = pSW->uSdhz_S.bFlag.bPower;			
				if(bVTok||(bVIok&&(pSet->bTT_fa_gzTz||pSet->bTT_fa_Icheck)))//电压时间型失压 或 电压电流型过流且失压
					fa_s_state_change(sw,S_BSYTIME);//pSW->S_Status = S_BSYTIME;					//进入Y闭锁状态
				else if(pSW->uSdhz_S.bFlag.bTempJS)//!!!正向闭锁临时解锁，电压方向需取反
				{	//
					pSW->uSdhz_S.bFlag.bPower=!pSW->uSdhz_S.bFlag.bPower;
					fa_s_state_change(sw,S_BSYTIME);
				}
			#ifdef GD_AREA_ZHONGSHAN_2020//中山2020最新要求失压的时候有故障延时到报Y闭锁
				else if(pSW->uSdhz_S.bFlag.bOCing)
				{
					fa_s_state_change(sw,S_BSYTIME);
				}
			#endif
				else
				{
					fa_uf_clear(sw,false);
					fa_s_state_change(sw,S_INIT);
				}

			#ifdef FUNC_DRIVE_JY
				gb_drive.b_clear_bs = false;
			#endif
			
				fa_sw_opt(sw, EV_FA_FZ);
			}
			else if ( pSW->tOnYSTime.boolTrip)//如果Y计时完毕
			{	
			#ifdef GD_AREA_HEYUAN_2021
				pSW->uSdhz_S.bFlag.bYtOn = true;
			#endif
				if(pR->bBSTZ	//闭锁
				||(!pR->tSWST.uSWST.bFlag.bFAWL&&pSW->uSdhz_S.bFlag.bPowerZ)//有流且失压
					)
				{
					fa_s_state_change(sw,S_BSDL);	//为满足分闸条件，等待至满足分闸条件为止
				}
				else if(pSet->bTT_fa_bsTz)
				{
					if(soe_check(EV_BSTZ_FA+sw*EV_SW_NUM)==false) 
						soe_record_ev(EV_BSTZ_FA+sw*EV_SW_NUM, 1, 0,0,0 );
					fa_s_state_change(sw,S_BSFZ);	//合闸成功进入闭锁分闸状态
				}
				else
				{
					if(pSW->uSdhz_S.bFlag.bTempJS)//!!!正向闭锁临时解锁，电压方向需取反
						pSW->uSdhz_S.bFlag.bPower=!pSW->uSdhz_S.bFlag.bPower;
					fa_s_state_change(sw,S_USUAL);	//进入正常运行状态
					pR->tLostVot.uLostVot.bFlag.bFault=false;
				}
				if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)==false && pR->tSWST.uSWST.bFlag.bDITW)//X上电合闸失败
				{
					soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 1, 0,0,0 );	
				}

				#ifdef FUNC_DRIVE_JY
					gb_drive.b_clear_bs = false;
				#endif
			}				
		break;
		}
		case S_BS_SW:
			if((soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)||soe_check(EV_HZFAIL+sw*EV_SW_NUM)) && !pSW->uSdhz_S.bFlag.bPowerZ)//X上电合闸失败且未失压
			{
			#ifdef FUNC_DRIVE_JY
				if(gb_drive.b_fa_reclose)
				{
					fa_s_state_change(sw,S_XTIME);
				}
			#endif
			
				break;
			}
			else if((soe_check(EV_X_SWFAIL+sw*EV_SW_NUM)||soe_check(EV_HZFAIL+sw*EV_SW_NUM)) && pSW->uSdhz_S.bFlag.bPowerZ)////X上电合闸失败且失压
			{
				if(soe_check(EV_X_SWFAIL+sw*EV_SW_NUM))
					soe_record_ev(EV_X_SWFAIL+sw*EV_SW_NUM, 0, 0,0,0 );	
				if(soe_check(EV_HZFAIL+sw*EV_SW_NUM))
					soe_record_ev(EV_HZFAIL+sw*EV_SW_NUM, 0, 0,0,0 );	
				fa_s_state_change(sw,S_INIT);
				break;
			}
			break;
		case S_BSYTIME:			
			if(pR->tSWST.uSWST.bFlag.bDIHW )
			{
				if( soe_check(EV_TZFAIL+sw*EV_SW_NUM))//
				{
					fa_s_state_change(sw,S_BS_SW);					
				}
				break;
			}
			if(!pSW->uSdhz_S.bFlag.bTempJS)//未临时解锁，则报Y闭锁SOE
			{
				if(pSW->uSdhz_S.bFlag.bPower) 
				{
					if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==false)   // Y闭锁
						soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 1, 0,0,0 );
				}
				else
				{
					if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==false)   // Y闭锁
						soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 1, 0,0,0 );			
				}
			}
		#ifdef GD_AREA_ZHONGSHAN 	//中山局Y闭锁，需合闸且双侧有压才能解锁
			pSW->uSdhz_S.bFlag.bTempJS = true;
			ResetTR(&pSW->tOnY_JSTime);				//js时间计数
			if (pSW->uSdhz_S.bFlag.bOppositeYY && 
				(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)!=soe_check(EV_BS_Y_L+sw*EV_SW_NUM)||soe_check(EV_HHGZ_P+sw*EV_SW_NUM)!=soe_check(EV_HHGZ_L+sw*EV_SW_NUM))   )//对侧来电且双侧未闭锁
			{
				fa_s_bsYtime_js(sw,dStep);
			}		
		#else//非中山局Y闭锁，反向来压直接解锁	
		  #ifdef GD_AREA_ZHONGSHAN_2020		  
			if(pSW->uSdhz_S.bFlag.bPowerZ)//(!pSW->uSdhz_S.bFlag.bDBYY && !pSW->uSdhz_S.bFlag.bOppositeYY)
			{
				ResetTR(&pSW->tOnJSTime);
			}
			RunTR(&pSW->tOnJSTime, (pSW->uSdhz_S.bFlag.bDBYY || pSW->uSdhz_S.bFlag.bOppositeYY)&&((soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)||(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)), dStep);				
			if(pSW->tOnJSTime.boolTrip) //如果双侧有压,js时间计时器
			{
				if(pSW->uSdhz_S.bFlag.bDBYY)
				{
					fa_s_state_change(sw,S_BSDOUBLE);
				}
				else if(pSW->uSdhz_S.bFlag.bOppositeYY)
				{
					if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 对侧来电解锁
					{
						soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
						#ifdef GD_AREA_ECZD_2020
						soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
						#endif
					}	
					fa_rstbs_soe(sw);
					fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//返回初始状态
					//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
					pSW->uSdhz_S.bFlag.bUABFlash = false;
					pSW->uSdhz_S.bFlag.bUBCFlash = false;
					if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				}
			}			
		  #else
			//对侧来电,且非双侧有压			
			if (pSW->uSdhz_S.bFlag.bOppositeYY)				//对侧来电
			{
				if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 对侧来电解锁
				{
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
					#ifdef GD_AREA_ECZD_2020
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
					#endif
				}	
				fa_rstbs_soe(sw);
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//返回初始状态
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
				if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
				{
					soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
				{
					soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
				{
					soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
				{
					soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			}
		  #endif
		#endif
		break;
		case S_BSHHGZ://合后故障
			if(pR->tSWST.uSWST.bFlag.bDIHW)
			{	
			    if(soe_check(EV_TZFAIL+sw*EV_SW_NUM))//
			   	{
					fa_s_state_change(sw,S_BS_SW);
			   	}
				break;
			}	
			#ifdef GD_AREA_ZHONGSHAN_2020
				if(pR->tLostVot.uLostVot.bFlag.bSHWY)
				{	//手合无压进入Y时间闭锁后禁止解锁 2020-12-23
					if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==false)   // EV_HHGZ闭锁
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );
					}
					break;
				}
			#endif
			
			//if(pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ)//无压暂停计时
				RunTR(&pSW->tOnYSTime, TRUE, dStep);				//启动Y时间计数
			if (!pSW->tOnYSTime.boolTrip)//Y计时未完毕失压
			{
				if(pSW->uSdhz_S.bFlag.bPowerZ)//当前失压且在合位
				{
					//合后故障后，Y时间内失压，加记录Y闭锁SOE
					if(pSW->uSdhz_S.bFlag.bPower) 
					{
						if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==false)   // Y闭锁
							soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 1, 0,0,0 );
					}
					else
					{	
						if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==false)   // Y闭锁
							soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
			}
			if(pSW->uSdhz_S.bFlag.bPower) 
			{
				if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==false)   // Y闭锁
				{
					soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			}
			else
			{
				if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==false)   // Y闭锁
				{
					soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			}
			
			//if(pSW->uSdhz_S.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bHZWZ)//当前失压且在合位
			//	fa_sw_opt(sw, EV_HHGZ);
			
			//if(pSW->uSdhz_S.bFlag.bPower) 
			{
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==false)   // EV_HHGZ闭锁
				{
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			}
		#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHUHAI_FTU//珠海局2019供货要求合后故障只能在有压且开关合位的时候才能解锁
				break;
		#endif
		#ifdef FA_BSYTIME_JS
		  #ifdef GD_AREA_ZHONGSHAN_2020	
		    if(!pSW->uSdhz_S.bFlag.bDBYY && !pSW->uSdhz_S.bFlag.bOppositeYY)
			{
				ResetTR(&pSW->tOnJSTime);
			}
			RunTR(&pSW->tOnJSTime, (pSW->uSdhz_S.bFlag.bDBYY || pSW->uSdhz_S.bFlag.bOppositeYY) && (soe_check(EV_HHGZ+sw*EV_SW_NUM)==true), dStep);				
			if(pSW->tOnJSTime.boolTrip) 
			{
				if(pSW->uSdhz_S.bFlag.bDBYY)//如果双侧有压,js时间计时器
				{
					fa_s_state_change(sw,S_BSDOUBLE);
				}
				else if(pSW->uSdhz_S.bFlag.bOppositeYY)//对侧来电,且非双侧有压
				{
					if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)	 // 对侧来电解锁
					{
						soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
						#ifdef GD_AREA_ECZD_2020
						soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
						#endif
					}						
				
					fa_rstbs_soe(sw);	
					fa_close_led(sw);
					fa_s_state_change(sw,S_INIT);
					pSW->uSdhz_S.bFlag.bUABFlash = false;
					pSW->uSdhz_S.bFlag.bUBCFlash = false;
					if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ_P+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_HHGZ_L+sw*EV_SW_NUM)==true)  
					{
						soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				}
			}			
		  #elif defined GD_AREA_ZHONGSHAN
			if(pSW->uSdhz_S.bFlag.bDBYY || pSW->uSdhz_S.bFlag.bOppositeYY)
			{
				fa_s_state_change(sw,S_XTIME);
				
				if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );
					
				if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );
			}
		  #else
			if (pSW->uSdhz_S.bFlag.bOppositeYY && !pSW->uSdhz_S.bFlag.bDBYY &&soe_check(EV_HHGZ_P+sw*EV_SW_NUM)!=soe_check(EV_HHGZ_L+sw*EV_SW_NUM))				//对侧来电,且非双侧有压
			{
				fa_s_bsYtime_js(sw,dStep);
			}
		  #endif
		#else
			if (pSW->uSdhz_S.bFlag.bOppositeYY && !pSW->uSdhz_S.bFlag.bDBYY)				//对侧来电,且非双侧有压
			{
				if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 对侧来电解锁
				{
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
					#ifdef GD_AREA_ECZD_2020
					soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
					#endif
				}	
				fa_rstbs_soe(sw);
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;						//返回初始状态
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
				pSW->uSdhz_S.bFlag.bUABFlash = false;
				pSW->uSdhz_S.bFlag.bUBCFlash = false;
				
				if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
				if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
				if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		#endif
			break;
		
		case S_BSDL://遮断电流
			if(pSW->uSdhz_S.bFlag.bYY && !pSW->uSdhz_S.bFlag.bPowerZ)//无压暂停计时
				RunTR(&pSW->tOnYSTime, TRUE, dStep);				//启动Y时间计数
			if (!pSW->tOnYSTime.boolTrip)//Y计时未完毕失压
			{
				if(pSW->uSdhz_S.bFlag.bPowerZ)
				{
					//合后故障后，Y时间内失压，加记录Y闭锁SOE
					if(pSW->uSdhz_S.bFlag.bPower) 
					{
						if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==false)   // Y闭锁
							soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 1, 0,0,0 );
					}
					else
					{	
						if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==false)   // Y闭锁
							soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
			}
			bVTok=!pSet->bTT_fa_Icheck ; //电压时间型，不判故障电流
			bVIok=(pSW->uSdhz_S.bFlag.bGL||pSW->uSdhz_S.bFlag.bGL_II||pSW->uSdhz_S.bFlag.bJD)&&pSet->bTT_fa_gzbshz;			
			bUoOk = pSW->uSdhz_S.bFlag.bOverU0 && pSet->bTT_fa_U0Tz;
			if((bVIok||bUoOk)			//合后有故障
				&&pSet->bTT_fa_gzTz 	//合后故障跳闸
				&& !pR->bBSTZ)			//未遮断闭锁          -> //合后故障，主动跳闸
			{
				fa_sw_opt(sw, EV_HHGZ);
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				fa_s_state_change(sw,S_BSHHGZ);//主动跳闸过了Y时限，不报Y闭锁	
			}
			else if(pSW->uSdhz_S.bFlag.bPowerZ&& !pR->bBSTZ&&pR->tSWST.uSWST.bFlag.bFAWL)//Z停电，被动跳闸,电压时间型
			{
				fa_sw_opt(sw, EV_FA_FZ);
				pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;
				
				//if(bVTok)//电压时间型失压 
					fa_s_state_change(sw,S_BSYTIME);//pSW->S_Status = S_BSYTIME;					//进入Y闭锁状态
				//else
				//	fa_s_state_change(sw,S_INIT);		
			}
			break;
		case S_BSFZ://合闸成功闭锁失压分
			RunTR(&pSW->tOnBSTZTime, TRUE, dStep);				//启动Y时间计数
			if(pSW->uSdhz_S.bFlag.bYY)
			{
				pR->tLostVot.uLostVot.bFlag.bSHWY=false;//清手分闭锁标志
			}
			if(pSW->tOnBSTZTime.boolTrip||!KZ_OUT_ALL_EN(sw))
			{
				//if (pSW->uSdhz_S.bFlag.bPowerZ || !pR->tSWST.uSWST.bFlag.bHZWZ)//失压或者当前分位
				if(soe_check(EV_BSTZ_FA+sw*EV_SW_NUM)==true) 
					soe_record_ev(EV_BSTZ_FA+sw*EV_SW_NUM, 0, 0,0,0 );
				fa_s_state_change(sw,S_USUAL);
			}
			else if(!pR->tSWST.uSWST.bFlag.bHZWZ)//手分？
			{
				if(soe_check(EV_BSTZ_FA+sw*EV_SW_NUM)==true) 
					soe_record_ev(EV_BSTZ_FA+sw*EV_SW_NUM, 0, 0,0,0 );
				fa_uf_clear(sw,false);
				fa_s_state_change(sw,S_INIT);
			}
			
			break;
		case S_USUAL:	

		#ifdef	FA_OC_COUNT
			if(isBs_fa_oc_count(sw))//过流脉冲计数闭锁
			{
				if(!pSW->uSdhz_S.bFlag.bYY && pR->tSWST.uSWST.bFlag.bFAWL)
				{
					fa_sw_opt(sw, EV_FA_FZ);
					fa_uf_clear(sw,false);
					if(soe_check(EV_BS_OC_COUNT+sw*EV_SW_NUM)==false)	 // 脉冲计数闭锁
						soe_record_ev(EV_BS_OC_COUNT+sw*EV_SW_NUM,1, 0,0,0 ); 
				}
				break;
			}
		#endif
			if(!pR->tSWST.uSWST.bFlag.bHZWZ || !pR->tSWST.uSWST.bFlag.bDIHW)//开关拉杆分闸，手分
			{
				fa_uf_clear(sw,false);
				#ifdef FA_BSYTIME_JS
				if(pSW->uSdhz_S.bFlag.bTempJS)
				{	//当前正向闭锁未解锁，需切换至Y闭锁状态
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;			
					fa_s_state_change(sw,S_BSYTIME);
				}
				else
				#endif	
				{
					fa_s_state_change(sw,S_INIT);
				}
				break;
			}
			if(pR->tLostVot.uLostVot.bFlag.bSHWY && !pSet->bTT_fa_shbs)//手合无压，闭锁合闸
			{
				if(pSW->uSdhz_S.bFlag.bYY)		//有压
					pR->tLostVot.uLostVot.bFlag.bSHWY = FALSE;		//清手合无压标志
				else
					break;
			}
			#ifdef FA_BSYTIME_JS
				//正向闭锁需等待解锁处理
				#ifdef GD_AREA_ZHONGSHAN				
			    RunTR(&pSW->tOnY_JSTime, pSW->uSdhz_S.bFlag.bTempJS && !pR->bBSTZ , dStep);			   //js时间计数
				#elif defined GD_AREA_ECZD_2020
				RunTR(&pSW->tOnY_JSTime,((pR->tSWST.uSWST.bFlag.bDITW && pSW->uSdhz_S.bFlag.bDBYY)// 双侧有压 && 分位
									|| (pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_S.bFlag.bYY))// 有压 && 合位
									&& pSW->uSdhz_S.bFlag.bTempJS,dStep);
				#else
			    RunTR(&pSW->tOnY_JSTime, pSW->uSdhz_S.bFlag.bDBYY&&pSW->uSdhz_S.bFlag.bTempJS && !pR->bBSTZ , dStep);				//js时间计数
			    #endif
				if(pSW->tOnY_JSTime.boolTrip)
					rst_ybs_soe(sw);
				else if(!pSW->tOnY_JSTime.boolTrip && pSW->uSdhz_S.bFlag.bPowerZ&&pSW->uSdhz_S.bFlag.bTempJS)//正向闭锁后未解锁，且失压 再次Y闭锁
				{
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;			
					fa_s_state_change(sw,S_BSYTIME);
				}
			#endif
			if (!pSW->uSdhz_S.bFlag.bPowerZ)//等待无压
				break;	
			
			if (pSW->uSdhz_S.bFlag.bPowerZ&&pR->tSWST.uSWST.bFlag.bHZWZ && pR->tSWST.uSWST.bFlag.bFAWL)						//失压 
			{				
				if(pSet->bTT_hzbs)//正常运行，连续闭锁分闸投入
				{
					pR->thzbs.fztimes++;
					rt_printf("连续闭锁分闸次数 = %d次 \r\n",pR->thzbs.fztimes);	
				}
				fa_sw_opt(sw, EV_FA_FZ);
				fa_uf_clear(sw,false);
				#ifdef FA_BSYTIME_JS
				if(pSW->uSdhz_S.bFlag.bTempJS)
				{	//当前正向闭锁未解锁，需切换至Y闭锁状态
					pSW->uSdhz_S.bFlag.bSNChange=pSW->uSdhz_S.bFlag.bPower;	
					fa_s_state_change(sw,S_BSYTIME);
				}
				else
				#endif
				{
					fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;					//进入U-Z状态，即正常运行中的失电状态
				}
				if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==true)   // 
			 	{
					soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			}
		break;
		
		default:
		break;
	}
}

/**************************************************************************
函数名称：Pro_L_Status_RUN
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：联络点状态流程
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_l_status_run(int sw, DWORD  dStep)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bool bVTok,bVIok,bUoOk;
	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); 	
	static bool TempBSTZ;//保存Y时间内产生的遮断信息

#ifdef FA_PL_PJ
	bool bFreq0,bFreq1;
	float freq0,freq1;

	//频率在要求范围内
	freq0=freq_get(0);
	freq1=freq_get(1);

	//电源1频率判断
	if((freq0>=48.9) && (freq0<=50.9))
	{
		bFreq0 = true;
	}
	else
	{
		bFreq0 = false;
	}
	//电源2频率判断
	if((freq1>=48.9) && (freq1<=50.9))
	{
		bFreq1 = true;
	}
	else
	{
		bFreq1 = false;
	}
#endif


	if(pSW->uSdhz_L.bFlag.bYY) 
		pSW->bSDHZinit=true; 
	if(!pSW->bSDHZinit)//未曾有压
		return;
	switch(pSW->L_Status)
	{		
		case L_INIT:			
			ResetTR(&pSW->tOnXLTime);
		#ifdef GD_AREA_ZHONGSHAN_2020//中山2020需要独立设置联络充电时间
			ResetTR(&pSW->tOnLLCDYLTime);
		#endif
			ResetTR(&pSW->tOnYLTime);
			ResetTR(&pSW->tOnZLTime);

		#ifdef FA_PL_PJ
			ResetTR(&pSW->tFREQLAB25ms);
			ResetTR(&pSW->tFREQLBC25ms);
		#endif
		
			ResetTR(&pSW->tL_RELAYONL3s);
			pR->uRmtSW.bYH_fajs_flag=false;
			pR->run_stu.fa_ll_cd=0;
			//if(fa_check_auto_l_bs(sw))return;			
			if (pSW->uSdhz_L.bFlag.bYY)						
				pSW->uSdhz_L.bFlag.bPower = pSW->uSdhz_L.bFlag.bUABYY;	//记录上电侧
		#ifdef GD_AREA_ZHONGSHAN_2020
			if(pSW->uSdhz_L.bFlag.bYY)		//有压
			{
				pR->tLostVot.uLostVot.bFlag.bSHWY = FALSE;		//清手合无压标志
			}
			if(!pR->tLostVot.uLostVot.bFlag.bSHWY )//手合无压，闭锁合闸
			{
				if(pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_L.bFlag.bPowerZ)//防止开关在合位不分闸 2020-11-13
				{
					pR->tLostVot.uLostVot.bFlag.bSHWY= true;//防止分闸过程中未检测到合位，多次进入失压分闸操作函数 2020-11-16
					fa_sw_opt(sw, EV_FA_FZ);
				}
			}
			//中山2020要求闭锁后需经双侧有压、分位且持续6s解锁 2020-10-24
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM)
				||soe_check(EV_BS_Y_P+sw*EV_SW_NUM)
				||soe_check(EV_BS_Y_L+sw*EV_SW_NUM)
				||soe_check(EV_BS_UF_P+sw*EV_SW_NUM)
				||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)
				||soe_check(EV_BS_HA+sw*EV_SW_NUM)
			)
			{
				RunTR(&pSW->tOnJSTime, pSW->uSdhz_L.bFlag.bDBYY && !pR->tSWST.uSWST.bFlag.bDIHW, dStep);				//js时间计数
				if(!pSW->tOnJSTime.boolTrip)
					break;
				if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)   // 手动分闸，闭锁合闸
		 		{
					soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			}			
		#endif

			
			if(soe_check(EV_L_LST_T+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_L_LST_T+sw*EV_SW_NUM, 0, 0,0,0 );  //联络单侧失压时间到		
			}
			if(soe_check(EV_FA_FZ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_FZ+sw*EV_SW_NUM, 0, 0,0,0 );  //失电分闸
			}
			if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==true)
				soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
		//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理		
        #if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
			if(soe_check(EV_FA_GL_TZ2+sw*EV_SW_NUM)==true)
				soe_record_ev(EV_FA_GL_TZ2+sw*EV_SW_NUM, 0, 0,0 ,0 );	
		#endif
			if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==true)
				soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
			if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==true)   // 
				soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 0, 0,0,0 );
			if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
				soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0 ,0 );
			//2020-03-17 	
			#if defined GD_AREA_ZHONGSHAN || defined GD_AREA_ZHONGSHAN_2020	
				if(soe_check(EV_FA_LL_EN+sw*EV_SW_NUM)==true)//自转电功能投入SOE返回
				{
					soe_record_ev(EV_FA_LL_EN+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				#ifdef GD_AREA_ZHONGSHAN_2020 
					if(soe_check(EV_FA_HZ_OK+sw*EV_SW_NUM)==true)//联络合闸成功返回
					{
						soe_record_ev(EV_FA_HZ_OK+sw*EV_SW_NUM, 0, 0,0,0 );
					}
					if(soe_check(EV_FA_HZ_FAIL+sw*EV_SW_NUM)==true)//自转电失败SOE返回
					{
						soe_record_ev(EV_FA_HZ_FAIL+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				#endif
			#endif

			#ifdef GD_AREA_ZHUHAI_V2 
				if(soe_check(EV_FA_HZ_OK+sw*EV_SW_NUM)==true)//联络合闸成功返回
				{
					soe_record_ev(EV_FA_HZ_OK+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#elif defined GD_AREA_ZHONGSHAN 
				if(soe_check(EV_GOOSE_HZ_OK+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_GOOSE_HZ_OK+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#endif
				if(soe_check(EV_FA_LL_CD+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_FA_LL_CD+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#ifdef GD_AREA_CHAOZHOUFENGXI //潮州
				if(pSW->uSdhz_L.bFlag.bUABFlash)
				{
					if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
				if(pSW->uSdhz_L.bFlag.bUBCFlash)
				{
					if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
			#endif
			if (pSW->uSdhz_L.bFlag.bDBYY)	//两侧有压
			{
				fa_uf_clear(sw,true);
				if(pR->tSWST.uSWST.bFlag.bDIHW)
					fa_l_state_change(sw,L_YL_TIME);
				else
				{
				#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					if((!soe_check(EV_PT2ERR) && pSW->uSdhz_L.bFlag.bHzEnable_P) || (!soe_check(EV_PT1ERR) && pSW->uSdhz_L.bFlag.bHzEnable_L))
				#endif
					{
						fa_l_state_change(sw,L_BS_STATE);
					}
				}
			}
			else if(pSW->uSdhz_L.bFlag.bYY && pR->tSWST.uSWST.bFlag.bDIHW)
			{
				fa_uf_clear(sw,true);
				fa_l_state_change(sw,L_YL_TIME);
			}	

		#ifdef GD_TEST_2021
			if(soe_check(EV_L_A_LST_ALA+sw*EV_SW_NUM))
				soe_record_ev(EV_L_A_LST_ALA+sw*EV_SW_NUM, 0, 0,0,0 );

			if(soe_check(EV_L_A_LST_HZ+sw*EV_SW_NUM))
				soe_record_ev(EV_L_A_LST_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
		
			if(soe_check(EV_L_B_LST_ALA+sw*EV_SW_NUM))
				soe_record_ev(EV_L_B_LST_ALA+sw*EV_SW_NUM, 0, 0,0,0 );

			if(soe_check(EV_L_B_LST_HZ+sw*EV_SW_NUM))
				soe_record_ev(EV_L_B_LST_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
		#endif		
		break;

		case L_BS_STATE:
		#ifdef GD_AREA_ZHONGSHAN_2020//中山2020需要独立设置联络充电时间
			//if(pSW->uSdhz_L.bFlag.bYY && soe_check_pt_ok(sw))//无压暂停计时
				RunTR(&pSW->tOnLLCDYLTime, TRUE, dStep);				//启动Y时间计数 
		#else
			//if(pSW->uSdhz_L.bFlag.bYY && soe_check_pt_ok(sw))//无压暂停计时
				RunTR(&pSW->tOnYLTime, TRUE, dStep);				//启动Y时间计数 
		#endif
		
		//零序电压不允许解锁 2021-4-27
		if((pSW->uSdhz_L.bFlag.bOverU0 && (pSet->bTT_fa_U0Tz||pSet->bTT_fa_U0Gj))
		#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			|| (!soe_check_pt_ok(sw))
		#endif
			)
			ResetTR(&pSW->tOnYLTime);
	#if defined GD_AREA_MAIN_2020 || defined GD_AREA_ECZD_2020
		if(soe_check(EV_BS_DB+sw*EV_SW_NUM)==false)
		{
			soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 1, 0,0,0 );
		}
	#endif
		#ifdef GD_AREA_ZHONGSHAN_2020	
			if ((!pSW->tOnLLCDYLTime.boolTrip) && pSW->uSdhz_L.bFlag.bOneLostV)//如果Y计时未完成且一侧失压
		#else
			if ((!pSW->tOnYLTime.boolTrip) && pSW->uSdhz_L.bFlag.bOneLostV)//如果Y计时未完成且一侧失压
		#endif
			{
				ResetTR(&pSW->tOnZLTime);
				fa_l_state_change(sw,L_Y_ZTIME);
			#if defined GD_AREA_MAIN_2020  || defined GD_AREA_ECZD_2020
				if(soe_check(EV_BS_DB+sw*EV_SW_NUM))
				{
					soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#endif
			}
		#ifdef GD_AREA_ZHONGSHAN_2020//中山2020需要独立设置联络充电时间
			else if (pSW->tOnLLCDYLTime.boolTrip && soe_check_pt_ok(sw))					//如果Y计时完毕
		#else
			else if (pSW->tOnYLTime.boolTrip && soe_check_pt_ok(sw))					//如果Y计时完毕
		#endif
			{	
				pR->run_stu.fa_ll_cd=1;
				fa_uf_clear(sw,true);
				fa_close_led(sw);
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0 ,0 );

				fa_l_state_change(sw,L_USUAL);
				if((soe_check(EV_JS_L+sw*EV_SW_NUM)==false)&&(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)))
				{
					soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 1, 0,0,0 );
				}	
				if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				
				if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_U0+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_HHGZ+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				//2020-03-17
				#ifdef GD_AREA_ZHUHAI_V2
					if(soe_check(EV_FA_HZ_FAIL+sw*EV_SW_NUM)==true)//自转电失败SOE返回
					{
						soe_record_ev(EV_FA_HZ_FAIL+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				
				#elif defined GD_AREA_ZHONGSHAN
					if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==true)//自转电失败SOE返回
					{
						soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 0, 0,0,0 );
					}
				#endif	
                if(soe_check(EV_FA_LL_CD+sw*EV_SW_NUM)==false)
                {
                    soe_record_ev(EV_FA_LL_CD+sw*EV_SW_NUM, 1, 0,0,0 );
                }
				#if defined GD_AREA_ZHONGSHAN || defined GD_AREA_ZHONGSHAN_2020
					if(soe_check(EV_FA_LL_EN+sw*EV_SW_NUM)==false)//自转电功能SOE置位
					{
						soe_record_ev(EV_FA_LL_EN+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				#endif
				pSW->uSdhz_L.bFlag.bLockUFlash = FALSE;
			}
				
		break;

		case L_Y_ZTIME:
			RunTR(&pSW->tOnZLTime, TRUE, dStep);				//启动Z时间计数
			if ((!pSW->tOnZLTime.boolTrip) && pSW->uSdhz_L.bFlag.bDBYY)	//如果Z计时未完时失压侧恢复供电
			{	
				ResetTR(&pSW->tOnZLTime);
				//pSW->L_Status = L_BS_STATE;						//返回Y计时状态
				fa_l_state_change(sw,L_BS_STATE);
			}		
			else if (pSW->tOnZLTime.boolTrip)				//如果Z计时完成
			{
				ResetTR(&pSW->tOnYLTime);					//清零Y计时		
				pSW->uSdhz_L.wfFlag = 0;				//返回初始状态
				fa_l_state_change(sw,L_INIT);
			}
		break;

		case L_USUAL:
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
			if(!cheak_pt_ok_ing(sw))
			{
				if(soe_check(EV_PT1ERR))
				{
					pSW->uSdhz_L.bFlag.bPtErr_P = true;
				}

				if(soe_check(EV_PT2ERR))
				{
					pSW->uSdhz_L.bFlag.bPtErr_L = true;
				}
			}
#endif
#ifdef FUNC_YL_FZ_SOE
			if(soe_check(EV_YL_FZ+sw*EV_SW_NUM))
			{
				soe_record_ev(EV_YL_FZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
#endif
			if (pSW->uSdhz_L.bFlag.bOneLostV)					//如果一侧失压
			{
				pSW->uSdhz_L.bFlag.bPower = pSW->uSdhz_L.bFlag.bUABYY;
				//pSW->L_Status = L_XLTIME;					//进入X延时投入状态，
				ResetTR(&pSW->tOnYLTime);					//清零Y计时		
				ResetTR(&pSW->tUFDBTime);					//清零
				fa_uf_clear(sw,true);

				if((pSW->uSdhz_L.bFlag.bPower&&(!pSet->bTT_fa_lineoff)) //负荷侧失压，负荷侧失压合闸退出
					|| ((!pSW->uSdhz_L.bFlag.bPower)&&(!pSet->bTT_fa_poweroff)) // 电源侧失压，电源侧侧失压合闸退出
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					|| (pSW->uSdhz_L.bFlag.bPtErr_P || pSW->uSdhz_L.bFlag.bPtErr_L)
#endif
					)
				{
					//pSW->L_Status = L_INIT;					//进入初始状态，重新充电
					fa_l_state_change(sw,L_INIT);
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
					if(!pSW->uSdhz_L.bFlag.bPower && pSW->uSdhz_L.bFlag.bPtErr_P)
					{
						pSW->uSdhz_L.bFlag.bBsXtime_P = true;
						pSW->uSdhz_L.bFlag.bPtErr_P = false;
					}
					
					if(pSW->uSdhz_L.bFlag.bPower && pSW->uSdhz_L.bFlag.bPtErr_L)
					{
						pSW->uSdhz_L.bFlag.bBsXtime_L = true;
						pSW->uSdhz_L.bFlag.bPtErr_L = false;
					}
#endif
				}
				else
				{
					fa_l_state_change(sw,L_XLTIME);
				}

			#if defined GD_AREA_MAIN_2020 || defined GD_AREA_ECZD_2020
				if(soe_check(EV_BS_DB+sw*EV_SW_NUM))
				{
					soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#endif
			}
			else if(!pSW->uSdhz_L.bFlag.bYY)
			{
				//pSW->L_Status = L_INIT;					//两侧失压进入初始状态
				fa_l_state_change(sw,L_INIT);		
			#if defined GD_AREA_MAIN_2020 || defined GD_AREA_ECZD_2020
				if(soe_check(EV_BS_DB+sw*EV_SW_NUM))
				{
					soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#endif
			}
			
		break;

		case L_XLTIME:
			#if defined GD_AREA_MAIN_2020 || defined GD_AREA_ECZD_2020
				if(soe_check(EV_BS_DB+sw*EV_SW_NUM))
				{
					soe_record_ev(EV_BS_DB+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			#endif

		#ifdef FA_PL_PJ
			if(pRunSet->bTT_judgeFreq)
			{
				RunTR(&pSW->tFREQLAB25ms,bFreq0,dStep);
				RunTR(&pSW->tFREQLBC25ms,bFreq1,dStep);
			}
			else
			{
				pSW->tFREQLAB25ms.boolTrip = true;
				pSW->tFREQLBC25ms.boolTrip = true;
			}
		#endif

		#ifdef FA_PL_PJ
			if(((pSW->uSdhz_L.bFlag.bUABYY && pSW->tFREQLAB25ms.boolTrip) || (pSW->uSdhz_L.bFlag.bUBCYY && pSW->tFREQLBC25ms.boolTrip))
				&& !pSW->uSdhz_L.bFlag.bOppositeYY)
		#else
			#ifdef GD_AREA_ECZD_2020
			if(pSW->uSdhz_L.bFlag.bYY && !pSW->uSdhz_L.bFlag.bOppositeYY)
			#endif
		#endif
			{
				RunTR(&pSW->tOnXLTime, soe_check_pt_ok(sw), dStep);				//启动X时间计数
			}
			RunTR(&pSW->tOnZLTime, TRUE, dStep);				//启动Z时间计数
			//if (pSW->uSdhz_L.bFlag.bPower != pSW->uSdhz_L.bFlag.bUABYY)	//电压方向有变化
			//{
			//	fa_l_state_change(sw,L_INIT);	
			//	break;
			//}
		
			//合前零压
			if(pSW->uSdhz_L.bFlag.bOverU0 && (pSet->bTT_fa_U0Tz||pSet->bTT_fa_U0Gj))
			{
				if(soe_check(EV_BE_UO+sw*EV_SW_NUM)==false)   // 
					soe_record_ev(EV_BE_UO+sw*EV_SW_NUM, 1,  U01>U02?U01:U02,0,0 );
			#ifdef  GD_AREA_CHAOZHOUFENGXI
				ResetTR(&pSW->tOnXLTime);
				fa_l_state_change(sw,L_INIT);
				break;//合前零压不合闸，重新Xl计时 2021-4-19
			#endif
			}

			if (pSW->uSdhz_L.bFlag.bUABFlash||pSW->uSdhz_L.bFlag.bUBCFlash||pSW->uSdhz_L.bFlag.bDBYY)//如果X计数过程中有瞬时电压
			{				
				if(pSW->uSdhz_L.bFlag.bDBYY)//在YL时间内双侧有压认为是残压，过了YL时间则进入初始状态
				{
					pSW->uSdhz_L.bFlag.bUABFlash = !pSW->uSdhz_L.bFlag.bPower;
					pSW->uSdhz_L.bFlag.bUBCFlash = pSW->uSdhz_L.bFlag.bPower;
				}
				ResetTR(&pSW->tOnYLTime);
				pSW->uSdhz_L.bFlag.bSNChange = pSW->uSdhz_L.bFlag.bUABFlash;//残压方向
				fa_l_state_change(sw,L_XL_ZTIME);
			}
			else if (pSW->tOnXLTime.boolTrip && pSW->uSdhz_L.bFlag.bOneLostV )				//如果X计数完毕
			{
			#ifdef FUNC_NYY_NWY
				if((pSW->uSdhz_L.bFlag.bUABYY && pSW->uSdhz_L.bFlag.bUBC_NYY_NWY)
					|| (pSW->uSdhz_L.bFlag.bUBCYY && pSW->uSdhz_L.bFlag.bUAB_NYY_NWY))
				{
					pSW->uSdhz_L.wfFlag = 0;
					fa_l_state_change(sw,L_INIT);
				}
				else
			#endif
				{
				#ifdef GD_TEST_2021
					if(pSW->uSdhz_L.bFlag.bUABYY){
						if(pSet->bTT_fa_lineoff == 1){
							if(!soe_check(EV_L_B_LST_ALA+sw*EV_SW_NUM))
								soe_record_ev(EV_L_B_LST_ALA+sw*EV_SW_NUM, 1, 0,0,0 );
						}else{
							pSW->uSdhz_L.bFlag.bRLONFLAG = TRUE;
							if(!soe_check(EV_L_B_LST_HZ+sw*EV_SW_NUM))
								soe_record_ev(EV_L_B_LST_HZ+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					}else{
						if(pSet->bTT_fa_poweroff == 1){
							if(!soe_check(EV_L_A_LST_ALA+sw*EV_SW_NUM))
								soe_record_ev(EV_L_A_LST_ALA+sw*EV_SW_NUM, 1, 0,0,0 );
						}else{
							pSW->uSdhz_L.bFlag.bRLONFLAG = TRUE;
							if(!soe_check(EV_L_A_LST_HZ+sw*EV_SW_NUM))
								soe_record_ev(EV_L_A_LST_HZ+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					}
				#else
					pSW->uSdhz_L.bFlag.bRLONFLAG = TRUE;
					soe_record_ev(EV_L_LST_T+sw*EV_SW_NUM, 1, 0,0,0 );  //联络单侧失压时间到	
				#endif		
					//pSW->L_Status = L_RELAYON;					//进入合闸状态			
					ResetTR(&pSW->tOnYLTime);

				#ifdef FA_PL_PJ
					ResetTR(&pSW->tFREQLAB25ms);
					ResetTR(&pSW->tFREQLBC25ms);
				#endif
				
					TempBSTZ=false;
					fa_l_state_change(sw,L_YL_TIME);//fa_l_state_change(sw,L_RELAYON);
			
					pSW->uSdhz_L.bFlag.bXOverUo=	pSW->uSdhz_L.bFlag.bOverU0;
				}
			}
			else if (pSW->tOnXLTime.boolTrip||pSW->uSdhz_L.bFlag.bPowerZ
			#ifdef GD_AREA_ECZD_CHAOZHOU_2022
				|| !soe_check_pt_ok(sw)
			#endif
				)
			{
				pSW->uSdhz_L.wfFlag = 0;
				//pSW->L_Status = L_INIT; 				//返回初始状态		
				fa_l_state_change(sw,L_INIT);
			}
			
		break;

		case L_XL_ZTIME:  // 有瞬压产生
			RunTR(&pSW->tOnYLTime, TRUE, dStep);				//启动Y时间计数 
			if(pSW->tOnYLTime.boolTrip && !soe_check(EV_BS_UF_P+sw*EV_SW_NUM) && !soe_check(EV_BS_UF_L+sw*EV_SW_NUM))//有压持续时间超过YL延时，不认为残压，进入初始状态
			{
				pSW->uSdhz_L.wfFlag = 0;
				fa_l_state_change(sw,L_INIT);
				break;
			}
			if (pSW->uSdhz_L.bFlag.bOneLostV||pSW->uSdhz_L.bFlag.bPowerZ)	
			{
				if(pSW->uSdhz_L.bFlag.bUABFlash)
				{
					if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
				if(pSW->uSdhz_L.bFlag.bUBCFlash)
				{
					if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				}
				//ResetTR(&pSW->tOnJSTime);				//js时间计数
			}
		#ifdef GD_AREA_ZHONGSHAN_2020	//中山2020要求双侧有压经过解锁时间6s才能解锁 2020-10-24
			if( (pSW->uSdhz_L.bFlag.bUABYY && pSW->uSdhz_L.bFlag.bUBCYY)
				&&(soe_check(EV_BS_UF_P+sw*EV_SW_NUM) || soe_check(EV_BS_UF_L+sw*EV_SW_NUM))  ) 
		#else
			//感受到残压一侧得电，延时6s解除残压闭锁 （中山局交底文件需求 2019-10）
			if( (pSW->uSdhz_L.bFlag.bUABYY&&soe_check(EV_BS_UF_P+sw*EV_SW_NUM))
		 	  ||(pSW->uSdhz_L.bFlag.bUBCYY&&soe_check(EV_BS_UF_L+sw*EV_SW_NUM)) )
		 #endif
			{
				RunTR(&pSW->tOnJSTime, TRUE, dStep);				//js时间计数
				if(!pSW->tOnJSTime.boolTrip)
					break;				
				if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				if(soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true)
				{
					soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 0, 0,0,0 );
				}
				pSW->uSdhz_L.wfFlag = 0;
				fa_l_state_change(sw,L_INIT);
				ResetTR(&pSW->tUABL25ms);
				ResetTR(&pSW->tUBCL25ms);		
			}
			else
			{
				ResetTR(&pSW->tOnJSTime);				//js时间计数
			}
			
		break;
		case L_YL_TIME:
			if(!pR->bBSTZ)//遮断暂停计时
				RunTR(&pSW->tOnYLTime, pSW->uSdhz_L.bFlag.bYY , dStep);
			else
				TempBSTZ = true;//保存之前遮断闭锁信号
			#ifdef GD_AREA_ZHONGSHAN_2020//中山2020最新要求失压的时候有故障延时到报Y闭锁
				if(pSW->uSdhz_L.bFlag.bYY)		//有压
				{
					pR->tLostVot.uLostVot.bFlag.bSHWY = FALSE;		//清手合无压标志
				}
				bVTok=(!pSet->bTT_fa_Icheck && pSW->uSdhz_L.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL && !pR->tLostVot.uLostVot.bFlag.bSHWY); //电压时间型，不判故障电流
			#else
				bVTok=(!pSet->bTT_fa_Icheck && pSW->uSdhz_L.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL); //电压时间型，不判故障电流
			#endif	
			
			bVIok=(pSW->uSdhz_L.bFlag.bGL||pSW->uSdhz_L.bFlag.bGL_II||pSW->uSdhz_L.bFlag.bJD)&&pSet->bTT_fa_gzTz; 		
			bUoOk = pSW->uSdhz_L.bFlag.bOverU0 && pSet->bTT_fa_U0Tz && soe_check(EV_BE_UO+sw*EV_SW_NUM)==false;
			if(!pR->bBSTZ)
			{
				if(bVTok||bVIok||bUoOk||TempBSTZ)
				{
					if(bVTok)
						fa_sw_opt(sw, EV_FA_FZ);
					else
						fa_sw_opt(sw, EV_HHGZ);
					TempBSTZ=false;
					ResetTR(&pSW->tUABL25ms);//跳闸后，将电压计时器清零，防止INIT 状态后，合位未及时检测到又返回 L_YL_TIME
					ResetTR(&pSW->tUBCL25ms);
					pSW->uSdhz_L.bFlag.bDBYY=0;
					fa_l_state_change(sw,L_INIT);
#ifdef FUNC_YL_FZ_SOE
					if(soe_check(EV_YL_FZ+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_YL_FZ+sw*EV_SW_NUM, 1, 0,0,0 );
					}
#endif
				#ifdef GD_AREA_ECZD_2020
					fa_uf_clear(sw,true);
				#endif
				
					//2020-03-17 EV_GOOSE_HZ_FAIL
					#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHONGSHAN_2020
						if(soe_check(EV_FA_HZ_FAIL+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_FA_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					#elif defined GD_AREA_ZHONGSHAN 
						if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					#endif
					
					break;
				}
			}
			//开关拒动
			if(soe_check(EV_HZFAIL+sw*EV_SW_NUM)==true)
			{
				#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHONGSHAN_2020
					if(soe_check(EV_FA_HZ_FAIL+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_FA_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				#elif defined GD_AREA_ZHONGSHAN
					if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==false)
					{
						soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
					}
				#endif
				fa_l_state_change(sw,L_INIT);	
			}
			
			if(pSW->tOnYLTime.boolTrip)
			{
				TempBSTZ=false;
				fa_l_state_change(sw,L_RELAYON);
			#ifdef GD_AREA_HEYUAN_2021
				pSW->uSdhz_L.bFlag.bYtOn = true;
			#endif

				//2020-03-17 EV_GOOSE_HZ_OK				
				if(pR->tSWST.uSWST.bFlag.bHZWZ)//开关合位,SOE转供电成功
				{
					#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHONGSHAN_2020
						if(soe_check(EV_FA_HZ_OK+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_FA_HZ_OK+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					#elif defined GD_AREA_ZHONGSHAN
						if(soe_check(EV_GOOSE_HZ_OK+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_GOOSE_HZ_OK+sw*EV_SW_NUM, 1, 0,0,0 );
						}	
					#endif
				}
				else
				{					
					#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHONGSHAN_2020
						if(soe_check(EV_FA_HZ_FAIL+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_FA_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					#elif defined GD_AREA_ZHONGSHAN
						if(soe_check(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM)==false)
						{
							soe_record_ev(EV_GOOSE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
						}
					#endif
					fa_l_state_change(sw,L_INIT);	
				}				 
			}
			else if(pSW->uSdhz_L.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL && !pR->bBSTZ)
			{
				#if defined GD_AREA_ZHONGSHAN_2020
					if(pR->tLostVot.uLostVot.bFlag.bSHWY)
						break;
				#endif
				fa_sw_opt(sw, EV_FA_FZ);
				TempBSTZ=false;
				ResetTR(&pSW->tUABL25ms);//跳闸后，将电压计时器清零，防止INIT 状态后，合位未及时检测到又返回 L_YL_TIME
				ResetTR(&pSW->tUBCL25ms);
				pSW->uSdhz_L.bFlag.bDBYY=0;
			#ifdef FUNC_YL_FZ_SOE
				if(soe_check(EV_YL_FZ+sw*EV_SW_NUM)==false)
				{
					soe_record_ev(EV_YL_FZ+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			#endif
				fa_l_state_change(sw,L_INIT);
				break;
			}
			break;	
		case L_RELAYON:
			if(pR->tLostVot.uLostVot.bFlag.bSHWY && !pSet->bTT_fa_shbs)//手合无压，闭锁合闸
			{
				if(pSW->uSdhz_L.bFlag.bYY)		//有压
					pR->tLostVot.uLostVot.bFlag.bSHWY = FALSE;		//清手合无压标志
				else
					break;
				if(pSW->uSdhz_L.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bHZWZ && pR->tSWST.uSWST.bFlag.bFAWL)//双侧失压&&在合位
				{
					fa_sw_opt(sw, EV_FA_FZ);
					pSW->uSdhz_L.wfFlag = 0;
					fa_l_state_change(sw,L_INIT);
					break;
				}
			}
			pR->uRmtSW.bYH_fajs_flag=false;
			RunTR(&pSW->tL_RELAYONL3s, TRUE, dStep);				//启动合闸确认时间计数
			if(!pSW->tL_RELAYONL3s.boolTrip)
			{
				pR->tU0TZ.uZOV.bFlag.bU0Ov=pSW->uSdhz_L.bFlag.bOverU0&&!pSW->uSdhz_L.bFlag.bXOverUo;
			}
			if ((pR->tSWST.uSWST.bFlag.bTZWZ) && pSW->tL_RELAYONL3s.boolTrip)
			{
				pSW->uSdhz_L.wfFlag = 0;
				//fa_sw_opt(sw, EV_FA_FZ);
				//pSW->L_Status = L_INIT;						//返回初始状态
				fa_l_state_change(sw,L_INIT);
				break;
			}
			if(pSW->uSdhz_L.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL)//双侧失压
			{
				if(pR->tSWST.uSWST.bFlag.bHZWZ)
					fa_sw_opt(sw, EV_FA_FZ);
				pSW->uSdhz_L.wfFlag = 0;
				//pSW->L_Status = L_INIT;						//返回初始状态
				fa_l_state_change(sw,L_INIT);
				break;
			}
		break;
		
		default:
		break;
	}
}

bool get_s_bs(WORD s_status)
{
	switch(s_status)
	{
		case S_BSFLASH:
		case S_BSXTIME:
	#ifndef GD_AREA_ZHONGSHAN
		case S_BSYTIME:
		case S_BSHHGZ:
	#endif
			return true;
		default:
			return false;			
	}
	return false;
}

/**************************************************************************
函数名称：fa_s_run
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：顺送/逆送运行
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_s_run(int sw, DWORD  dStep)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	int bJS=0,bFWJS=0;
#if defined GD_AREA_ECZD_2020  && !defined GD_AREA_ZHONGSHAN_2020
	static int i=0;
	bool b_SyFinish=false;
#endif

#ifdef	FA_OC_COUNT
	RunTR(&pSW->tFaOcCountTime,pSet->bTT_fa_oc_count&&pSW->fa_oc_count,dStep);
	if(pSW->tFaOcCountTime.boolTrip)
	{
		pSW->fa_oc_count=0;//过流脉冲计数清零，复归
	}
#endif
	if ((pR->uRmtSW.bYTExecute || pR->uRmtSW.bHandTz||pSW->bDL_Tz) && pSet->bTT_fa_sfbs)
	{
 		if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==false)   // 手动分闸，闭锁合闸
 		{
			soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 1, 0,0,0 );
			fa_s_set_savestatus(sw);
		}	
		if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==true)   // 
		{
			soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 0, 0,0,0 );
		}
		if(soe_check(EV_BSTZ_FA+sw*EV_SW_NUM)==true) 
		{
			soe_record_ev(EV_BSTZ_FA+sw*EV_SW_NUM, 0, 0,0,0 );
		}
		ResetTR(&pSW->tOnJSTime);				//js时间计数
		pSW->bDL_Tz=false;
		pR->uRmtSW.bYHExecute_fa=false;	//遥控合
		pR->uRmtSW.bHandHz_fa=false;	//遥信合
		g_run_stu.js=false;				//遥信解锁
		//pSW->bDL_Hz=false;				//拉杆合
		g_run_stu.rmtjs=false;			//按钮解锁
		pR->uRmtSW.bYH_fajs_flag=false;	//状态保持合
		pR->uBHDZ.bFlag.bTZSB=false;
	}
//#if defined GD_AREA_MEIZHOU_FTU || defined GD_AREA_ZHONGSHAN 
#if defined GD_AREA_MEIZHOU_FTU
	// 合位 && 闭锁 && 未跳闸失败 ，则可以直接合位解锁
	RunTR(&pSW->tOnHW_FA_JSTime,
								pR->tSWST.uSWST.bFlag.bHZWZ 
							&& (soe_check(EV_BS_ALL+sw*EV_SW_NUM) || get_s_bs(pSW->S_Status) )
							&& !soe_check(EV_TZFAIL+sw*EV_SW_NUM)
							&& pSW->S_Status != S_BS_SW ,dStep);				//js时间计数
	if(pSW->tOnHW_FA_JSTime.boolTrip)	//合位直接解锁,防止闭锁且合位无法解锁 2020-7-28	
		pSW->bDL_Hz = true;
		
#elif defined GD_AREA_ECZD_2020 && !defined GD_AREA_ZHONGSHAN_2020
	//合后故障后需等双侧完全失压才允许判解锁逻辑，
	//因解锁时间判50ms，合后故障后50ms内有压来不及变为无压导致判定分位、双侧有压进入解锁会执行逻辑出错
	if(pSW->uSdhz_S.bFlag.bHhgz && pSW->uSdhz_S.bFlag.bDBYY)
	{
		b_SyFinish = false;
	}
	else
	{
		b_SyFinish = true;
		pSW->uSdhz_S.bFlag.bHhgz = false;
	}
	
	RunTR(&pSW->tOnHW_FA_JSTime,
								((pR->tSWST.uSWST.bFlag.bDITW && pSW->uSdhz_S.bFlag.bDBYY && (soe_check(EV_BS_DB+sw*EV_SW_NUM)==false))// 双侧有压 && 分位 && 非双电源闭锁
							|| (pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_S.bFlag.bYY))	// 有压 && 合位
						#ifdef GD_AREA_ECZD_MAOMING
                            && ((soe_check(EV_BS_ALL+sw*EV_SW_NUM) && soe_check(EV_BS_HA+sw*EV_SW_NUM)) || get_s_bs(pSW->S_Status) )
                        #else
							&& ((soe_check(EV_BS_ALL+sw*EV_SW_NUM) && !soe_check(EV_BS_HA+sw*EV_SW_NUM)) || get_s_bs(pSW->S_Status) )
						#endif
							&& !soe_check(EV_TZFAIL+sw*EV_SW_NUM)
							&& b_SyFinish
							,dStep);
						//&& pSW->S_Status != S_BS_SW ,dStep);
	if(pSW->tOnHW_FA_JSTime.boolTrip)
	{
		if(pR->tSWST.uSWST.bFlag.bDIHW && pSW->uSdhz_S.bFlag.bYY)
		{
			bJS=1;
		}
		else
		{//双侧有压且分位满足解锁条件后进入init状态，报对侧来电解锁SOE
			bFWJS=1;
		}	
	}
	if(pR->tSWST.uSWST.bFlag.bDIHW && soe_check(EV_BS_ALL+sw*EV_SW_NUM))
	{//有闭锁合闸事件且开关在合位，如果失压应能报失电分闸
		if(((i==0)||(i==2)) && pSW->uSdhz_S.bFlag.bYY)
		{//如果开关合后有压
			i=1;
		}
		else if(((i==0)||(i==2)) && !pSW->uSdhz_S.bFlag.bYY)
		{
			i=2;
		}
		
		if(i==1)
		{
			if(pSW->uSdhz_S.bFlag.bPowerZ && pR->tSWST.uSWST.bFlag.bFAWL)	//停电或无流则报失电分闸
			{
				i=0;
				fa_sw_opt(sw, EV_FA_FZ);
			}
		}	
	}
	else
	{
		i=0;
	}
	
	if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_X_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_HHGZ+sw*EV_SW_NUM)==false 
	)
	{//合位解锁手分闭锁合闸
	#ifndef GD_AREA_ECZD_MAOMING
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM)&&(pSW->bDL_Hz||pR->uRmtSW.bHandHz_fa||pR->uRmtSW.bYHExecute_fa||soe_check(EV_DL_HZ+sw*EV_SW_NUM)))//手分/遥分闭锁后，再次手合/遥控合立即解锁
		{
			bJS = 1; 
		}
    #endif
	}

#elif defined GD_AREA_ZHONGSHAN
	RunTR(&pSW->tOnHW_FA_JSTime,
							pR->tSWST.uSWST.bFlag.bDIHW
							&& (pSW->uSdhz_S.bFlag.bUABYY || pSW->uSdhz_S.bFlag.bUBCYY)
							&& (get_s_bs(pSW->S_Status)
								|| (soe_check(EV_HHGZ+sw*EV_SW_NUM) && !(soe_check(EV_HHGZ_P+sw*EV_SW_NUM) && soe_check(EV_HHGZ_L+sw*EV_SW_NUM)))	//非双侧合后故障
								|| (soe_check(EV_BS_Y_P+sw*EV_SW_NUM) != soe_check(EV_BS_Y_L+sw*EV_SW_NUM)))	//非双侧Y闭锁
							&& !soe_check(EV_TZFAIL+sw*EV_SW_NUM)
							&& pSW->S_Status != S_BS_SW ,dStep);				//js时间计数
	if(pSW->tOnHW_FA_JSTime.boolTrip)
	{
		pR->uRmtSW.bYH_fajs_flag= true;	
	}

	if(pSW->S_Status == S_XTIME)
	{
		if(pR->run_stu.sw==2)
		{	//X计时过程有合信号时，先记录上电侧，因本体合闸有100ms延时，往下代码在本体合后才判上电侧会导致逻辑出错
			pSW->uSdhz_S.bFlag.bPower=pSW->uSdhz_S.bFlag.bUABYY;
		}
	}

#elif defined GD_AREA_ZHONGSHAN_2020
	RunTR(&pSW->tOnHW_FA_JSTime,
							pR->tSWST.uSWST.bFlag.bDIHW
							&& (pSW->uSdhz_S.bFlag.bUABYY || pSW->uSdhz_S.bFlag.bUBCYY)
							&& (soe_check(EV_BS_ALL+sw*EV_SW_NUM) || get_s_bs(pSW->S_Status) )
							&& !soe_check(EV_TZFAIL+sw*EV_SW_NUM)
							&& pSW->S_Status != S_BS_SW ,dStep);				//js时间计数
	if(pSW->tOnHW_FA_JSTime.boolTrip)//合位直接解锁,防止闭锁且合位无法解锁 2020-7-28	 	
	{
		pR->uRmtSW.bYH_fajs_flag= true;	
	}
#if 1
	if(soe_check(EV_BS_X_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_X_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_Y_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_Y_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==false 
	&& soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==false 
	&& soe_check(EV_HHGZ+sw*EV_SW_NUM)==false 
	)
	{
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM)&&(pSW->bDL_Hz||pR->uRmtSW.bHandHz_fa||soe_check(EV_DL_HZ+sw*EV_SW_NUM)))//手分闭锁后，再次手合立即解锁
		{
			pR->uRmtSW.bYH_fajs_flag= true; 
		}
	}
#endif
	//拉杆合、遥信合、遥控合进入Y计时 2020-12-23
	if((pSW->bDL_Hz||pR->uRmtSW.bHandHz_fa||pR->uRmtSW.bYHExecute_fa)&&pR->tSWST.uSWST.bFlag.bHZWZ && pSW->S_Status != S_YTIME)
	{
		//pR->uRmtSW.bYH_fajs_flag= true;
		pR->tLostVot.uLostVot.bFlag.bSHWY=!(pSW->uSdhz_S.bFlag.bUABYY||pSW->uSdhz_S.bFlag.bUBCYY);//将手合状态电压保存
		fa_s_state_change(sw,S_YTIME);//
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM))//手分闭锁清
			soe_record_ev(EV_BS_HA, 0, 0,0,0 );
		pSW->bDL_Hz = false;
		pR->uRmtSW.bHandHz_fa=false;
		pR->uRmtSW.bYHExecute_fa=false;

	//#if defined GD_AREA_ZHONGSHAN_2020	//中山2020允许无压进入Y实现即时，需将故障定时器清零
		ResetTR(&pSW->tGZJYRstGLTime);
		ResetTR(&pSW->tGZJYRstGL_II_Time);
		ResetTR(&pSW->tGZJYRstJDTime);	
		ResetTR(&pSW->tGZJYRstGL2Time);
		ResetTR(&pSW->tGZJYRstJD2Time); 
		ResetTR(&pR->tU0TZ.tZOVTime);	

	#ifdef FUNC_DRIVE_JY
		ResetTR(&gb_drive.tDriveFaBSTime);
	#endif
	//#endif
	}
	else
	{
		pSW->bDL_Hz = false;
		//pR->uRmtSW.bHandHz_fa=false;
		//pR->uRmtSW.bYHExecute_fa=false;
	}
#endif

#ifdef FUNC_REBOOT_BS_HA_JS_3S
	RunTR(&pSW->tHW_JS_HA_3STime, (g_tRelay[sw].uRmtSW.b_bsha && pR->tSWST.uSWST.bFlag.bDIHW), dStep);
	if(pSW->tHW_JS_HA_3STime.boolTrip)
	{
		g_tRelay[sw].uRmtSW.b_bsha = false;
		g_run_stu.js = true;
	}
#endif
	//手合、遥合解锁
	if ((pR->uRmtSW.bYHExecute_fa&&pR->tSWST.uSWST.bFlag.bHZWZ) 	//遥控合
		||(pR->uRmtSW.bHandHz_fa&&pR->tSWST.uSWST.bFlag.bHZWZ)		//遥信合
		||g_run_stu.js		//遥信解锁
		||pSW->bDL_Hz		//拉杆合
		||g_run_stu.rmtjs	//按钮解锁
		||(pR->uRmtSW.bYH_fajs_flag&&pR->tSWST.uSWST.bFlag.bHZWZ)	//状态保持合
		|| bFWJS || bJS
		)	// 解锁
	{
		bool bUAB,bUBC;
		bool bU0;
	#ifdef GD_AREA_ZHONGSHAN
		bool b_temp;	//记录清所有标志前的上电侧标志
	#endif
		bUAB = pSW->uSdhz_S.bFlag.bUABYY;
		bUBC = pSW->uSdhz_S.bFlag.bUBCYY;
		bU0=pSW->uSdhz_S.bFlag.bOverU0;
		
		//遥控合&遥信合
	#ifndef GD_AREA_ZHONGSHAN
		if(pR->uRmtSW.bYHExecute_fa||pR->uRmtSW.bHandHz_fa)
			pR->uRmtSW.bYH_fajs_flag=true;
	#endif
	#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHUHAI_FTU || (defined GD_AREA_ECZD_2020  && !defined GD_AREA_ZHONGSHAN_2020) || defined GD_AREA_ZHONGSHAN//有压且合位的时候才能解锁
		#ifdef GD_AREA_ZHONGSHAN
		if(soe_check(EV_HHGZ+sw*EV_SW_NUM) || soe_check(EV_BS_UF_L+sw*EV_SW_NUM) || soe_check(EV_BS_UF_P+sw*EV_SW_NUM)
			|| soe_check(EV_BS_X_P+sw*EV_SW_NUM) || soe_check(EV_BS_X_L+sw*EV_SW_NUM)
			|| soe_check(EV_BS_Y_P+sw*EV_SW_NUM) || soe_check(EV_BS_Y_L+sw*EV_SW_NUM))
		#else
		if(soe_check(EV_HHGZ+sw*EV_SW_NUM))
		#endif
		{
		#if defined GD_AREA_ECZD_2020 && !defined GD_AREA_ZHONGSHAN_2020
			if(bFWJS || bJS || g_run_stu.rmtjs || g_run_stu.js)	//满足解锁条件解锁/按钮解锁/遥信解锁
			{
				;
			}
		#elif defined GD_AREA_ZHONGSHAN
			if(g_run_stu.rmtjs || g_run_stu.js || ((bUAB||bUBC) && pR->uRmtSW.bYH_fajs_flag && pR->tSWST.uSWST.bFlag.bHZWZ ))// 有压 && 合位
			{
				;//解锁
			}
		#else
			if((bUAB||bUBC) && pR->tSWST.uSWST.bFlag.bHZWZ )// 有压 && 合位
				;//解锁
		#endif
			else
			{
				g_run_stu.js=0;
				g_run_stu.rmtjs=0;
				return ;//不允许解锁;
			}
			
		}
		#ifdef GD_AREA_ZHUHAI_FTU//珠海之前提出Y闭锁后有压不允许解锁，合后故障有压且合位才能解锁
			if(soe_check(EV_BS_Y_P+sw*EV_SW_NUM)||soe_check(EV_BS_Y_L+sw*EV_SW_NUM))
			{
				if(bUAB||bUBC)// 有压 
				{
					g_run_stu.js=0;
					g_run_stu.rmtjs=0;
					return ;//不允许解锁;
				}
					
			}

		#endif
	#endif
	#if defined GD_AREA_ECZD_2020  && !defined GD_AREA_ZHONGSHAN_2020
		if(soe_check(EV_BS_ALL+sw*EV_SW_NUM))
		{
			if(bFWJS || bJS || g_run_stu.rmtjs || g_run_stu.js)	//满足解锁条件解锁/按钮解锁/遥信解锁
			{
				;
			}
			else
			{
				g_run_stu.js=0;
				g_run_stu.rmtjs=0;
				return ;//不允许解锁;
			}
			
		}
	#endif
		
	#if defined GD_AREA_ZHONGSHAN || defined GD_AREA_DONGGUAN || defined GD_AREA_YUNFU || defined GD_AREA_ZHONGSHAN_2020 //中山&东莞 有压不允许直接解锁 

		#if 0//def GD_AREA_ZHONGSHAN//中山局要求手合闸后，双侧有压且合位6S后才能解锁(正向解锁方式)
			if( (pSW->bDL_Hz||pR->uRmtSW.bHandHz_fa||pR->uRmtSW.bYHExecute_fa||pR->uRmtSW.bYH_fajs_flag) &&soe_check(EV_BS_ALL+sw*EV_SW_NUM))
			{
			
				RunTR(&pSW->tOnJSTime,pSW->uSdhz_S.bFlag.bDBYY,dStep);				//js时间计数
				if(!pSW->tOnJSTime.boolTrip )
				{
					return;
				}	
			}
		#endif
		if (g_run_stu.js||g_run_stu.rmtjs)
		{
			if(soe_check(EV_BS_ALL+sw*EV_SW_NUM))//闭锁合闸
			{
				if(bUAB||bUBC)//有压
				{
					//pR->uRmtSW.bYHExecute_fa=0;
					//pR->uRmtSW.bHandHz_fa=0;
					g_run_stu.js=0;
					g_run_stu.rmtjs=0;
					return ;//有压不允许直接解锁
				}
			}
		}
	#endif
		#if 0
		else if(pSW->bDL_Hz || pR->uRmtSW.bYH_fajs_flag || pR->uRmtSW.bHandHz_fa)//分段(?) -> 手合或遥控合闸，开关两侧至少有一侧电压正常，延时6s解除残压闭锁。（中山局新增）
		{
			if(pSW->S_Status == S_BSFLASH||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true||soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)
			{
				//手合或遥控合闸，开关两侧至少有一侧电压正常，延时6s解除残压闭锁。
				RunTR(&pSW->tOnJSTime, (bUAB||bUBC), dStep);				//js时间计数
				
				if(!pSW->tOnJSTime.boolTrip)//残压闭锁后 开关合位且双侧有压才能解锁 
					return;
			}
			ResetTR(&pSW->tOnJSTime);				//js时间计数
			SignalReset(0,false);
		}
		#endif
	#if defined GD_AREA_ECZD_2020
		if((pSW->bDL_Hz||pR->uRmtSW.bYHExecute_fa||pR->uRmtSW.bHandHz_fa||bJS)&&pSW->uSdhz_S.bFlag.bYY&&pR->tSWST.uSWST.bFlag.bHZWZ)	
		{
			pR->tLostVot.uLostVot.bFlag.bSHWY=!(pSW->uSdhz_S.bFlag.bUABYY||pSW->uSdhz_S.bFlag.bUBCYY);
			fa_s_state_change(sw,S_YTIME);
			bJS = false;
			pSW->bDL_Hz = false;
			pR->uRmtSW.bHandHz_fa=false;
			pR->uRmtSW.bYHExecute_fa=false;
			ResetTR(&pSW->tGZJYRstGLTime);
			ResetTR(&pSW->tGZJYRstGL_II_Time);
			ResetTR(&pSW->tGZJYRstJDTime);	
			ResetTR(&pSW->tGZJYRstGL2Time);
			ResetTR(&pSW->tGZJYRstJD2Time); 
			ResetTR(&pR->tU0TZ.tZOVTime);	
		#ifdef FUNC_DRIVE_JY
			ResetTR(&gb_drive.tDriveFaBSTime);
		#endif
		}
	#endif	
	#if defined GD_AREA_CHAOZHOU_2021
	   #if defined GD_AREA_CHAOZHOUFENGXI
		if (g_run_stu.js||g_run_stu.rmtjs)
		{	//潮州要求人工干预直接解锁 2020-8-4
			if(bUAB||bUBC)//有压
			{
				pR->uRmtSW.bYHExecute_fa=0;
				pR->uRmtSW.bHandHz_fa=0;
				g_run_stu.js=0;
				g_run_stu.rmtjs=0;
				return ;//当前有压不允许直接解锁
			}
		}else
	   #endif
		if(pSW->S_Status == S_BSFLASH||soe_check(EV_BS_UF_L+sw*EV_SW_NUM)==true||soe_check(EV_BS_UF_P+sw*EV_SW_NUM)==true)
		{
			RunTR(&pSW->tOnJSTime, (bUAB||bUBC), dStep);				//js时间计数
			if(!pSW->tOnJSTime.boolTrip)//残压闭锁后
				return;
			ResetTR(&pSW->tOnJSTime);				//js时间计数
			//SignalReset(0,false);
		}
	#endif	
		SignalReset(0,false);
		g_tRelay[sw].tDYJL.bLed=false;
		g_tRelay[sw].tPLJL.bLed=false;
	#ifdef GD_AREA_ZHONGSHAN
		b_temp = pSW->uSdhz_S.bFlag.bPower;
	#endif
		pSW->uSdhz_S.wfFlag = 0;
		pSW->bS_BSLed = 0;
		pSW->uSdhz_S.bFlag.bUABYY = bUAB;
		pSW->uSdhz_S.bFlag.bUBCYY = bUBC;		
	#ifdef GD_AREA_ZHONGSHAN
		if(pSW->S_Status == S_YTIME)
		{	//X计时过程中本体合进入YTIME，本体合瞬间UAB已有压，但本体合信号需延时100ms，所以应以100ms前的上电侧为准
			pSW->uSdhz_S.bFlag.bPower = b_temp;
		}
		else
	#endif
		{
			pSW->uSdhz_S.bFlag.bPower=pSW->uSdhz_S.bFlag.bUABYY;
		}
		//pSW->uSdhz_S.bFlag.bTempJS = false;
		#ifdef FA_BSYTIME_JS
		rst_ybs_soe( sw);
		#endif
		pR->bBSHZ=false;  // 解锁合闸闭锁
		fa_close_led(sw);
		pR->tU0TZ.bU0Led=false;
		if(g_run_stu.js||g_run_stu.rmtjs||bFWJS||bJS)  // 解锁后，进入初始状态
		{//解锁条件后期需更改？无闭锁直接退出？
			if(pR->tSWST.uSWST.bFlag.bHZWZ)//当前在合位且正常运行态，直接切换至正常运行???
			{
			//#ifdef GD_AREA_ZHUHAI_V2//珠海要求B侧需判断对侧开关位置
			#if	defined GD_AREA_ZHUHAI_V2 //|| defined GD_AREA_JIEYANG
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||(bUBC&&pR->run_stu.fa_start_hz));//将手合状态电压保存
			#elif defined GD_AREA_JIEYANG
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUBC||(bUAB&&pR->run_stu.fa_start_hz));//将手合状态电压保存
			#else
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||bUBC);//将手合状态电压保存
			#endif
				pSW->uSdhz_S.bFlag.bPowerZ=0;
				ResetTR(&pR->tLostVot.tLostVotTime);//重新开始Z计时
				fa_s_state_change(sw,S_USUAL);//
				pR->thzbs.fztimes=0;	//连续分闸计数清零
				pSW->uSdhz_S.bFlag.bOppositeYY =false;
				pR->tSWST.uSWST.bFlag.bSDJS =true;
				ResetTR(&pSW->tOpsiteYY100ms);
				ResetTR(&pSW->tGZJYRstGLTime);
				ResetTR(&pSW->tGZJYRstGL_II_Time);
				ResetTR(&pSW->tGZJYRstJDTime);	
				ResetTR(&pSW->tGZJYRstGL2Time);
				ResetTR(&pSW->tGZJYRstJD2Time);	
			}
			else	
			{	
				fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_INIT;
				//pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
			}			
			SignalReset(0,true);
		}
		else if(pSW->S_Status != S_YTIME)//手合启动Y时限// if(bUAB||bUBC)  //手合遥控合，开关合，单侧有电压
		{
			ResetTR(&pSW->tOnYSTime);					//清零Y计时			
			pR->tU0TZ.uZOV.bFlag.bU0Ov=false;
			pR->tLostVot.uLostVot.bFlag.bStartLock = false;			
			pR->tLostVot.uLostVot.bFlag.bGL = false;						
			pSW->uSdhz_S.bFlag.bGL = false;
			pSW->uSdhz_S.bFlag.bGL_II=false;
			pSW->uSdhz_S.bFlag.bJD = false;
			pSW->uSdhz_S.bFlag.bXOverUo=bU0;
			
		//#ifdef GD_AREA_ZHUHAI_V2//珠海要求B侧需判断对侧开关位置
		#if	defined GD_AREA_ZHUHAI_V2 //|| defined GD_AREA_JIEYANG
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||(bUBC&&pR->run_stu.fa_start_hz));//将手合状态电压保存
		#elif defined GD_AREA_JIEYANG
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUBC||(bUAB&&pR->run_stu.fa_start_hz));//将手合状态电压保存
		#else
				pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||bUBC);//将手合状态电压保存
		#endif	

		#ifndef GD_AREA_ZHONGSHAN_2020	//中山2020要求手合无压进入Y时间，如果Y时间合后故障则闭锁双侧 2020-12-23
			if(pR->tLostVot.uLostVot.bFlag.bSHWY || pSW->S_Status == S_USUAL)
			{
				pSW->uSdhz_S.bFlag.bPowerZ=0;
				ResetTR(&pR->tLostVot.tLostVotTime);//重新开始Z计时
				fa_s_state_change(sw,S_USUAL);//pSW->S_Status = S_USUAL;//手合于无压，闭锁合闸
			#ifndef GD_AREA_YUNFU //云浮要求不报 手合/遥合闭锁失压分 SOE
				if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==false && !pSet->bTT_fa_shbs)   // 
		 		{
					soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			#endif
				pR->thzbs.fztimes=0;	//连续分闸计数清零
			}
			else
		#endif		
			{
			#ifdef GD_AREA_ZHONGSHAN
				if(pSW->S_Status != S_BSFZ)
			#endif
				fa_s_state_change(sw,S_YTIME);//pSW->S_Status = S_YTIME;//手合启动Y时限
				if(soe_check(EV_FA_GL_TZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_FA_GL_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
			//#if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020   //潮州局要求合后电流两段处理		
           #if defined GD_AREA_CHAOZHOU || defined GD_AREA_SHANTOU  || defined GD_AREA_ECZD_2020 || defined GD_AREA_MAIN_2020 
				if(soe_check(EV_FA_GL_TZ2+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_FA_GL_TZ2+sw*EV_SW_NUM, 0, 0,0 ,0 );	
			#endif
				if(soe_check(EV_FA_LX_TZ+sw*EV_SW_NUM)==true)
					soe_record_ev(EV_FA_LX_TZ+sw*EV_SW_NUM, 0, 0,0 ,0 );	
			}
			pSW->uSdhz_S.bFlag.bOppositeYY =false;
			pR->tSWST.uSWST.bFlag.bSDJS =true;
			ResetTR(&pSW->tOpsiteYY100ms);
			ResetTR(&pSW->tGZJYRstGLTime);
			ResetTR(&pSW->tGZJYRstGL_II_Time);
			ResetTR(&pSW->tGZJYRstJDTime);	
			ResetTR(&pSW->tGZJYRstGL2Time);
			ResetTR(&pSW->tGZJYRstJD2Time);	
		#ifdef FUNC_DRIVE_JY
			ResetTR(&gb_drive.tDriveFaBSTime);
		#endif
		}
		/*else
		{
			pSW->S_Status = S_INIT;
			pSW->uSdhz_S.bFlag.bSaveStatus = TRUE;			//存储状态标志、来电切换状态	
		}*/
		if(soe_check(EV_GOOSE_GZBS_FA)==true)	// goose故障闭锁
			soe_record_ev(EV_GOOSE_GZBS_FA, 0, 0,0,0 );
		if(soe_check(EV_GOOSE_TZBS_FA)==true)	// goose故障闭锁
			soe_record_ev(EV_GOOSE_TZBS_FA, 0, 0,0,0 );
		if(g_run_stu.js||g_run_stu.rmtjs)
		{
	 		if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==false)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 1, 0,0,0 );
			}			
	 		if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_L+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}	
	 		if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
			}	
			if(soe_check(EV_BSTZ_FA+sw*EV_SW_NUM)==true) 
			{
				soe_record_ev(EV_BSTZ_FA+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_FA_U0GJ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_U0GJ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		}
	#ifdef GD_AREA_ECZD_2020
		else if(bFWJS)
		{
			if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==false)   // 
	 		{
				soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 1, 0,0,0 );
			}	
			if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
			}	
			if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==true)   //
	 		{
				soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_L+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}	
	 		if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		}
	#endif
		else 
		{
	 		if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==false&&soe_check(EV_BS_ALL+sw*EV_SW_NUM)==true)   //
	 		{
				soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 1, 0,0,0 );
			}
	 		if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_L+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}	
	 		if(soe_check(EV_JS_POWER+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_POWER+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			
		}
		{
			TLOSTVOT_T *pSW = &pR->tLostVot;
			pSW->losttimes=0;
		}
		g_run_stu.rmtjs=false;
	#if defined FUNC_MODE_JS || defined FUNC_ONLY_MMD_JS
		if(!gb_js_mode)
	#endif    
        {
            g_run_stu.js=false;
        }   		
		pSW->bDL_Hz=false;	
		pR->uRmtSW.bYHExecute_fa=false;
		pR->uRmtSW.bHandHz_fa=false;	
		pR->uRmtSW.bYH_fajs_flag=false;
		pSW->uSdhz_S.bFlag.bJS=true;
		fa_unlock_s_bs(sw);		
		fa_uf_clear(sw,false);
		pSW->bS_BSLed=fa_check_all_s_bs(sw);
		return;
	}
	
	//运行状态流程处理
	if(!fa_check_s_bs_hz(sw))
	{
		fa_s_status_run(sw, dStep);		
	}
	else
	{
		fa_s_state_change(sw,S_INIT);//pSW->S_Status = S_USUAL;
	}
	pSW->bS_BSLed=fa_check_all_s_bs(sw);	
	//闭锁标志处理
	pSW->uSdhz_S.bFlag.bLockUFlash 	= (pSW->S_Status == S_BSFLASH) 	&& pSW->uSdhz_S.bFlag.bPowerYY;							
//	pSW->uSdhz_S.bFlag.bLockX 		= (pSW->S_Status == S_BSXTIME) 	&& pSW->uSdhz_S.bFlag.bOppositeYY;
	pSW->uSdhz_S.bFlag.bLockY 		= (pSW->S_Status == S_BSYTIME) 	&& pSW->uSdhz_S.bFlag.bPowerYY;
//	pSW->uSdhz_S.bFlag.bLockUDouble = (pSW->S_Status == S_BSDOUBLE)	&& pSW->uSdhz_S.bFlag.bYY;
	
	//pSW->bS_BSLed = pSW->uSdhz_S.bFlag.bLockUFlash
	//			|| pSW->uSdhz_S.bFlag.bLockX
	//			|| pSW->uSdhz_S.bFlag.bLockY
	//			|| pSW->uSdhz_S.bFlag.bLockUDouble;
//
	//LED灯处理
	fa_ls_led(sw, false);				

	/*********************合闸判断***********************/	
	RunTR(&pSW->tHzS100ms, pSW->uSdhz_S.bFlag.bRLONFLAG, dStep);	// 合闸信号，限制在合闸脉冲时间以内
	pSW->uSdhz_S.bFlag.bHz = pSW->tHzS100ms.boolTrip;

	//上电加速
	RunTR(&pSW->tTSDHzHJS, (pSW->uSdhz_S.bFlag.bHz && pR->tSWST.uSWST.bFlag.bTZWZ), dStep);
	pR->tSWST.uSWST.bFlag.bSDJS = pSW->tTSDHzHJS.boolTrip && (!pR->tSWST.uSWST.bFlag.bTZWZ);                     		
	
	/************事件记录及出口****************************/
	if(pSW->uSdhz_S.bFlag.bHz) 
	{
		if(!pSW->uSdhz_S.bFlag.bHZEvent) 			
		{
			DWORD Us1,Us2;
			if(pRunSet->bTT_UYYmin)
			{
				Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_min[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
				Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_min[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
			}
			else
			{
				Us1 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
				Us2 = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
			}
			//rcd_start(sw,RECORD_WAVE_TYPE_TZ, RECORD_LEN_TZQD); 	//录波类型：跳闸类
			soe_record_ev(EV_FA_HZ+sw*EV_SW_NUM, 1, Us1,Us2,0 );    

		#if defined GD_AREA_MEIZHOU_FTU	|| defined GD_AREA_ZHUHAI_V2 || defined  GD_AREA_JIEYANG_FTU || defined  GD_AREA_ECZD_MEIZHOU_2021
			if(pSW->uSdhz_S.bFlag.bPower)
				soe_record_ev(EV_FA_HZ_L+sw*EV_SW_NUM, 1, Us1,Us2,0 ); 
			else
				soe_record_ev(EV_FA_HZ_P+sw*EV_SW_NUM, 1, Us1,Us2,0 ); 
		#endif			
			pSW->uSdhz_S.bFlag.bHZEvent = true;	
			pSW->uSdhz_S.bFlag.bRLONFLAG = false;
		}
	}
	else
	{
		if(pSW->uSdhz_S.bFlag.bHZEvent) 			
		{
			soe_record_ev(EV_FA_HZ+sw*EV_SW_NUM, 0, 0,0,0 );   
		#if defined GD_AREA_MEIZHOU_FTU	|| defined GD_AREA_ZHUHAI_V2 || defined  GD_AREA_JIEYANG_FTU || defined  GD_AREA_ECZD_MEIZHOU_2021
			if(pSW->uSdhz_S.bFlag.bPower)
				soe_record_ev(EV_FA_HZ_L+sw*EV_SW_NUM,0, 0,0,0 ); 
			else
				soe_record_ev(EV_FA_HZ_P+sw*EV_SW_NUM, 0, 0,0,0 );
		#endif
			pSW->uSdhz_S.bFlag.bHZEvent = false;	
		}

	}
}



/**************************************************************************
函数名称：Pro_L_RUN
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：环网点运行
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static void fa_l_run(int sw, DWORD  dStep)
{
	bool bY1=FALSE;
	bool bY2=FALSE;
#ifdef FUNC_NYY_NWY
	bool bY1_n=0,bY2_n=0;
#endif

	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];	
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
	bool bY3=false,bY4=false;
#endif

	//有压检测
	// 电源1上电合闸
	if(pRunSet->bTT_UYYmin)
	{
		bY1 = OverRelay(g_sw_pub.m2_min[2], pSet->dU_fa_YY, pSet->dU_fa_WY, pSW->uSdhz_L.bFlag.bUABYY);
		bY2 = OverRelay(g_sw_pub.m2_min[3], pSet->dU_fa_YY2, pSet->dU_fa_WY2, pSW->uSdhz_L.bFlag.bUBCYY);
#ifdef GD_AREA_ECZD_CHAOZHOU_2022
		//电源侧
		{
			pSW->uSdhz_L.bFlag.bHzEnable_P = true;
			
			if(pSW->uSdhz_L.bFlag.bBsXtime_P)
				pSW->uSdhz_L.bFlag.bHzEnable_P = false;
			bY3 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_L.bFlag.bUABYY);
			if(bY3 && pSW->uSdhz_L.bFlag.bBsXtime_P && cheak_pt_ok_ing(sw))
			{
				pSW->uSdhz_L.bFlag.bHzEnable_P = true;
				pSW->uSdhz_L.bFlag.bBsXtime_P = false;
			}
		}
		//负荷侧
		{
			pSW->uSdhz_L.bFlag.bHzEnable_L = true;
			
			if(pSW->uSdhz_L.bFlag.bBsXtime_L)
				pSW->uSdhz_L.bFlag.bHzEnable_L = false;
			bY4 = LowRelay(g_sw_pub.m2_max[2], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_L.bFlag.bUABYY);
			if(bY4 && pSW->uSdhz_L.bFlag.bBsXtime_L && cheak_pt_ok_ing(sw))
			{
				pSW->uSdhz_L.bFlag.bHzEnable_L = true;
				pSW->uSdhz_L.bFlag.bBsXtime_L = false;
			}
		}
#endif
#ifdef FUNC_NYY_NWY
		bY1_n = (((g_sw_pub.m2_min[2] > pSet->dU_fa_WY) && (g_sw_pub.m2_min[2] < pSet->dU_fa_YY))?true:false)
				|| (tPT.uPT1DX.bFlag.bQD && pSW->uSdhz_L.bFlag.bUBCYY)
				;
		bY2_n = (((g_sw_pub.m2_min[3] > pSet->dU_fa_WY2) && (g_sw_pub.m2_min[3] < pSet->dU_fa_YY2))?true:false)
				|| (tPT.uPT2DX.bFlag.bQD && pSW->uSdhz_L.bFlag.bUABYY)
				;
#endif
	}
	else
	{
		bY1 = OverRelay(g_sw_pub.m2_max[2], pSet->dU_fa_YY, pSet->dU_fa_WY, pSW->uSdhz_L.bFlag.bUABYY);
		bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_fa_YY2, pSet->dU_fa_WY2, pSW->uSdhz_L.bFlag.bUBCYY);
	#ifdef GD_AREA_ECZD_CHAOZHOU_2022
		pSW->uSdhz_L.bFlag.bHzEnable_P = true;
		pSW->uSdhz_L.bFlag.bHzEnable_L = true;
	#endif
	}
	
	RunTR(&pSW->tUABL25ms, bY1, dStep);	

#ifdef GD_AREA_LIAONING_2021
	pSW->uSdhz_L.bFlag.bUABYY = pSW->tUABL25ms.boolTrip && pR->run_stu.fa_start_hz;
#else
	pSW->uSdhz_L.bFlag.bUABYY = pSW->tUABL25ms.boolTrip;
#endif

	// 电源2上电合闸
	//bY2 = OverRelay(g_sw_pub.m2_max[3], pSet->dU_fa_YY, pSet->dU_fa_YY_fh, pSW->uSdhz_L.bFlag.bUBCYY);
	
	RunTR(&pSW->tUBCL25ms, bY2, dStep);	
	pSW->uSdhz_L.bFlag.bUBCYY = pSW->tUBCL25ms.boolTrip;

#ifdef FUNC_NYY_NWY
	RunTR(&pSW->tUABL_NYY_NWY_50ms, bY1_n, dStep); 
	pSW->uSdhz_L.bFlag.bUAB_NYY_NWY = pSW->tUABL_NYY_NWY_50ms.boolTrip;
	RunTR(&pSW->tUBCL_NYY_NWY_50ms, bY2_n, dStep); 
	pSW->uSdhz_L.bFlag.bUBC_NYY_NWY = pSW->tUBCL_NYY_NWY_50ms.boolTrip;
#endif

	//两侧有压
	pSW->uSdhz_L.bFlag.bDBYY = pSW->uSdhz_L.bFlag.bUABYY && pSW->uSdhz_L.bFlag.bUBCYY;		

	/*对侧有瞬时电压
	pSW->uSdhz_L.bFlag.bOppositeUF = (pSW->uSdhz_L.bFlag.bUABFlash && (!pSW->uSdhz_L.bFlag.bPower)) 
								  || (pSW->uSdhz_L.bFlag.bUBCFlash && pSW->uSdhz_L.bFlag.bPower);	
	*/

	//一侧失压
	pSW->uSdhz_L.bFlag.bOneLostV = pSW->uSdhz_L.bFlag.bUABYY ^ pSW->uSdhz_L.bFlag.bUBCYY;		

	//有压
	pSW->uSdhz_L.bFlag.bYY = pSW->uSdhz_L.bFlag.bUABYY || pSW->uSdhz_L.bFlag.bUBCYY;		

	bY1 = ((pSW->uSdhz_L.bFlag.bUABYY && (!pSW->uSdhz_L.bFlag.bUBCYY) && (!pSW->uSdhz_L.bFlag.bPower)) 
			||((!pSW->uSdhz_L.bFlag.bUABYY) && pSW->uSdhz_L.bFlag.bUBCYY && pSW->uSdhz_L.bFlag.bPower)); 
		RunTR(&pSW->tOpsiteYY100ms, bY1, dStep);
	pSW->uSdhz_L.bFlag.bOppositeYY = pSW->tOpsiteYY100ms.boolTrip  && pSet->bTT_fa_poweron && pSet->bTT_fa_lineon;

	if (pR->uRmtSW.bYTExecute || pR->uRmtSW.bHandTz||pSW->bDL_Tz)	
	{
 	#ifndef GD_AREA_ZHONGSHAN_2020//中山2020联络模式不报手分闭锁SOE 2020-11-3
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM)==false)   // 手动分闸，闭锁合闸
 		{
			soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 1, 0,0,0 );
		}
	#endif
		pSW->bDL_Tz=false;
		
		//pSW->L_Status = L_INIT;
		fa_l_state_change(sw,L_INIT);
		pSW->uSdhz_L.wfFlag = 0;
		//pSW->bL_BSLed = 0;
	}		
	
#ifdef FUNC_REBOOT_BS_HA_JS_3S
	RunTR(&pSW->tHW_JS_HA_3STime, (g_tRelay[sw].uRmtSW.b_bsha && pR->tSWST.uSWST.bFlag.bDIHW), dStep);
	if(pSW->tHW_JS_HA_3STime.boolTrip)
	{
		g_tRelay[sw].uRmtSW.b_bsha = false;
		g_run_stu.js = true;
	}
#endif

	if (pR->uRmtSW.bYHExecute_fa || pR->uRmtSW.bHandHz_fa||g_run_stu.js||pSW->bDL_Hz||g_run_stu.rmtjs||pR->uRmtSW.bYH_fajs_flag)	//如果有手合、遥合事件，
	{
		bool bUAB,bUBC;
		bUAB = pSW->uSdhz_L.bFlag.bUABYY;
		bUBC = pSW->uSdhz_L.bFlag.bUBCYY;

		pSW->uSdhz_L.bFlag.bUABYY = bUAB;
		pSW->uSdhz_L.bFlag.bUBCYY = bUBC;
		
	#ifdef GD_AREA_ZHONGSHAN_2020
		//if(pSW->uSdhz_L.bFlag.bYY && (pSW->bDL_Hz || pR->uRmtSW.bHandHz_fa))
		{
			fa_l_state_change(sw,L_YL_TIME);
		}	
		g_run_stu.rmtjs=false;
		g_run_stu.js=false;
		pSW->bDL_Hz=false;
		pR->uRmtSW.bYHExecute_fa=false;
		pR->uRmtSW.bHandHz_fa=false;
		pR->uRmtSW.bYH_fajs_flag=false;
		//if(pSW->L_Status == L_INIT)
		{
			pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||bUBC);//将手合状态电压保存
		}
	//#if defined GD_AREA_ZHONGSHAN_2020	//中山2020允许无压进入Y实现即时，需将故障定时器清零
		ResetTR(&pSW->tGZJYRstGLTime);
		ResetTR(&pSW->tGZJYRstGL_II_Time);
		ResetTR(&pSW->tGZJYRstJDTime);	
		ResetTR(&pSW->tGZJYRstGL2Time);
		ResetTR(&pSW->tGZJYRstJD2Time); 
		ResetTR(&pR->tU0TZ.tZOVTime);	
		ResetTR(&pSW->tOnYLTime);
	//#endif
		return;//中山2020要求不允许任何人为情况干预解锁
	#endif

		if(pR->uRmtSW.bYHExecute_fa||pR->uRmtSW.bHandHz_fa)
			pR->uRmtSW.bYH_fajs_flag=true;
		
		//rt_printf_time("遥控合闸解锁 bYHExecute_fa=%d bHandHz_fa=%d       js=%d bDL_Hz=%d rmtjs=%d\r\n",pR->uRmtSW.bYHExecute_fa , pR->uRmtSW.bHandHz_fa,g_run_stu.js,pSW->bDL_Hz,g_run_stu.rmtjs);
		//if (g_run_stu.js||g_run_stu.rmtjs)
		//	;//除了合位解锁条件
		//else if(pSW->bDL_Hz || pR->uRmtSW.bYH_fajs_flag || pR->uRmtSW.bHandHz_fa)//联络 -> 手合或遥控合闸，开关两侧至少有一侧电压正常，延时6s解除残压闭锁。（中山局新增）	
		{	
		#ifndef GD_AREA_CHAOZHOUFENGXI//潮州要求直接解锁 2020-8-12
            if(soe_check(EV_BS_UF_P+sw*EV_SW_NUM)||soe_check(EV_BS_UF_L+sw*EV_SW_NUM))
            { 
                if(!bUAB&&!bUBC)
                    return;
                RunTR(&pSW->tOnJSTime, TRUE, dStep);				//js时间计数
                if(!pSW->tOnJSTime.boolTrip)
                    return;
            }
		#endif
			pR->tLostVot.uLostVot.bFlag.bSHWY=!(bUAB||bUBC);//将手合状态电压保存

			if(pR->tSWST.uSWST.bFlag.bDIHW || pR->uRmtSW.bYH_fajs_flag)//合位或者手合遥控合
			{
				ResetTR(&pSW->tOnYLTime);
			#ifndef GD_AREA_YUNFU //云浮要求不报 手合/遥合闭锁失压分 SOE
				if(soe_check(EV_SH_BSFZ+sw*EV_SW_NUM)==false && !pSet->bTT_fa_shbs)   // 
		 		{
					soe_record_ev(EV_SH_BSFZ+sw*EV_SW_NUM, 1, 0,0,0 );
				}
			#endif
				if((pR->tLostVot.uLostVot.bFlag.bSHWY && pR->uRmtSW.bYH_fajs_flag) ||pR->tLostVot.uLostVot.bFlag.bSHWY)
				{
					pSW->uSdhz_L.bFlag.bPowerZ=0;
					ResetTR(&pR->tLostVot.tLostVotTime);//重新开始Z计时
					fa_l_state_change(sw,L_RELAYON);
				}
				else
				{
					fa_l_state_change(sw,L_YL_TIME);
				}
			}
			else 
			{
				ResetTR(&pSW->tOnYLTime);
				if(pR->tSWST.uSWST.bFlag.bDIHW)
					fa_l_state_change(sw,L_BS_STATE);
				else
					fa_l_state_change(sw,L_INIT);
			}
		}
		ResetTR(&pSW->tOnJSTime);				//js时间计数		
		
		pSW->uSdhz_L.wfFlag = 0;
		pSW->bL_BSLed = 0;

		SignalReset(0,true);
		fa_close_led(sw);
		
		if(g_run_stu.js||g_run_stu.rmtjs)
		{
			SignalReset(0,false);
	 		if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==false)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 1, 0,0,0 );
			}
	 		if(soe_check(EV_JS_L+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
			if(soe_check(EV_FA_U0GJ+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_FA_U0GJ+sw*EV_SW_NUM, 0, 0,0,0 );
			}
		}
		else 
		{
	 		if(soe_check(EV_JS_HZ+sw*EV_SW_NUM)==false&&soe_check(EV_BS_ALL+sw*EV_SW_NUM)==true)   //
	 		{
				soe_record_ev(EV_JS_HZ+sw*EV_SW_NUM, 1, 0,0,0 );
			}
	 		if(soe_check(EV_JS_L+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_L+sw*EV_SW_NUM, 0, 0,0,0 );
			}
	 		if(soe_check(EV_JS_HA+sw*EV_SW_NUM)==true)   // 
	 		{
				soe_record_ev(EV_JS_HA+sw*EV_SW_NUM, 0, 0,0,0 );
			}			
		}
		g_run_stu.rmtjs=false;
	#if defined FUNC_MODE_JS || defined FUNC_ONLY_MMD_JS
		if(!gb_js_mode)
	#endif
        {
            g_run_stu.js=false;
        }   
		pSW->bDL_Hz=false;
		pR->uRmtSW.bYHExecute_fa=false;
		pR->uRmtSW.bHandHz_fa=false;
		pR->uRmtSW.bYH_fajs_flag=false;
		fa_unlock_l_bs(sw);	

		return;
	}

	//if (!pSW->uSdhz_L.bFlag.bYY)			//如果两侧失压
	//{
	//	pSW->L_Status = L_INIT;
	//	pSW->uSdhz_L.wfFlag = 0;
	//	pSW->bL_BSLed = 0;
	//	_pro_close_led();
	//	return;
	//}

	//运行状态流程处理
	//if(!check_l_bs_hz(sw))
	{
		fa_l_status_run(sw, dStep);
	}
	//pSW->bL_BSLed=check_all_l_bs(sw);	
	//闭锁标志处理
	#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHONGSHAN_2020
	pSW->uSdhz_L.bFlag.bLockY = pSW->uSdhz_L.bFlag.bLockUFlash;//(	((pSW->L_Status == L_BS_STATE) && (!pSW->tOnYLTime.boolTrip))
								//||	(pSW->uSdhz_L.bFlag.bLockUFlash));	//L_Status == L_Y_ZTIME));
	#else
	pSW->uSdhz_L.bFlag.bLockY = (((pSW->L_Status == L_INIT) && pSW->uSdhz_L.bFlag.bYY)
							||	((pSW->L_Status == L_BS_STATE) && (!pSW->tOnYLTime.boolTrip))
							||  (pSW->uSdhz_L.bFlag.bLockUFlash));	//L_Status == L_Y_ZTIME));
	#endif
	pSW->bL_BSLed = pSW->uSdhz_L.bFlag.bLockY||fa_check_all_l_bs(sw);	
	
	//LED灯处理
	fa_ls_led(sw, true);	
	
	//合闸判断
	RunTR(&pSW->tHzS100ms, pSW->uSdhz_L.bFlag.bRLONFLAG, dStep);	// 合闸信号，限制在合闸脉冲时间以内
	pSW->uSdhz_L.bFlag.bHz = pSW->tHzS100ms.boolTrip;

	//上电加速
	RunTR(&pSW->tTSDHzHJS, (pSW->uSdhz_L.bFlag.bHz && pR->tSWST.uSWST.bFlag.bTZWZ), dStep);               
	pR->tSWST.uSWST.bFlag.bSDJS = pSW->tTSDHzHJS.boolTrip && (!pR->tSWST.uSWST.bFlag.bTZWZ);                 					//上电后加速标志
	
	/************事件记录及出口****************************/	
	if(pSW->uSdhz_L.bFlag.bHz) 
	{
		if(!pSW->uSdhz_L.bFlag.bHZEvent) 			
		{
			DWORD Uab,Ubc;
			Uab = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[2]), 256, pRunSet->dKU[PUB_AC_UAB1]);
			Ubc = _Mul_Div_U(sqrt_32fix(g_sw_pub.m2_max[3]), 256, pRunSet->dKU[pRunSet->pt2vol]);
			//rcd_start(sw,RECORD_WAVE_TYPE_TZ, RECORD_LEN_TZQD); 	//录波类型：跳闸类
			soe_record_ev(EV_FA_LL_HZ+sw*EV_SW_NUM, 1, Uab,Ubc,0 );   
			pSW->uSdhz_L.bFlag.bHZEvent = true;	
			pSW->uSdhz_L.bFlag.bRLONFLAG = false;
			pSW->uSdhz_L.bFlag.bX_HZEvent = true;
		}
	}
	else
	{
		if(pSW->uSdhz_L.bFlag.bHZEvent) 						
		{
			soe_record_ev(EV_FA_LL_HZ+sw*EV_SW_NUM, 0, 0,0,0 );    
			pSW->uSdhz_L.bFlag.bHZEvent = false;	
		}
	}
	
}

void fa_status_print(int sw)
{
	
	{
		TRELAY_T *pR=&g_tRelay[sw];
		TSDHZ_T *pSW =&pR->tSDHZ;

		if(pSW->uSdhz_L.wfFlag!=pSW->l_flag_save||pSW->L_Status!=pSW->L_Status_save)
		{
			//if(pSW->uSdhz_L.wfFlag!=pSW->l_flag_save)
			//	fa_change_flag_print(sw,pSW->l_flag_save,pSW->uSdhz_L.wfFlag,fa_run_falg_str);
			//fa_change_status_print(pSW->L_Status_save,pSW->L_Status,fa_l_status);
			pSW->l_flag_save=pSW->uSdhz_L.wfFlag;
			pSW->L_Status_save=pSW->L_Status;
		}
		if(pSW->uSdhz_S.wfFlag!=pSW->s_flag_save||pSW->S_Status!=pSW->S_Status_save)
		{
			//if(pSW->uSdhz_S.wfFlag!=pSW->s_flag_save)
			//	fa_change_flag_print(sw,pSW->s_flag_save,pSW->uSdhz_S.wfFlag,fa_run_falg_str);
			//fa_change_status_print(pSW->S_Status_save,pSW->S_Status,fa_s_status);
			pSW->s_flag_save=pSW->uSdhz_S.wfFlag;
			pSW->S_Status_save=pSW->S_Status;
		}
		#if 0
		if(pR->tLostVot.uLostVot.wfFlag!=pR->tLostVot.wfFlagsave)
		{
			//fa_change_flag_print(sw,pR->tLostVot.wfFlagsave,pR->tLostVot.uLostVot.wfFlag,sw_u_str);
			rt_printf("sw=%d tLostFlag=%08x losttimes=%d\r\n",sw,pR->tLostVot.uLostVot.wfFlag,pR->tLostVot.losttimes);
			pR->tLostVot.wfFlagsave=pR->tLostVot.uLostVot.wfFlag;
		}
		if(pR->tSWST.uSWST.wfFlag!=pR->tSWST.wfFlagsave)
		{
			//fa_change_flag_print(sw,pR->tSWST.wfFlagsave,pR->tSWST.uSWST.wfFlag,sw_status_str);
			rt_printf("\r\n sw=%d tSWST Flag=%08x\r\n",sw,pR->tSWST.uSWST.wfFlag);
			pR->tSWST.wfFlagsave=pR->tSWST.uSWST.wfFlag;
		}
		#endif
	}
}

int  fa_UFDI_Init(void)
{
	int sw, i;
	if(!pRunSet->bTT_SY_Board)return 1; //无瞬压模块

#if (1) /* TODO lch */
	for (sw=0; sw< SWITCH_NUM_MAX; sw++)
	{
		g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUabflashDI=g_tRelay[sw].run_stu.pt1uf&&pRunSet->tSwSet[sw].bTT_FA;
		g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUbcflashDI=g_tRelay[sw].run_stu.pt2uf&&pRunSet->tSwSet[sw].bTT_FA;
	}
#else  // DTU需采集初始遥信才能返回

	for(i=0; i<g_equ_config->equ_slot_num; i++)
	{
		int di_num = equ_get_di_num(i);	
		if(di_num>0)
		{
			if(g_board_info[i].type != BOARD_TYPE_DI)continue;
			if(g_di[i].bInited==false) return 0;
		}
	}
#endif

	for (sw=0; sw< SWITCH_NUM_MAX; sw++)
	{
		g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUabflashDI=g_tRelay[sw].run_stu.pt1uf&&pRunSet->tSwSet[sw].bTT_FA;
		g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bUbcflashDI=g_tRelay[sw].run_stu.pt2uf&&pRunSet->tSwSet[sw].bTT_FA;
	}	
	return 1;
}

void   fa_RstUFDI(int sw)
{
	if(!pRunSet->bTT_SY_Board)return;
	sw_do(sw,SW_FBT_SY,SW_DO_TYPE_ON); 
	if(g_tRelay[sw].run_stu.pt1uf||g_tRelay[sw].run_stu.pt2uf)
	{
		sw_do(sw,SW_RST_SY,SW_DO_TYPE_ON);
		sw_do(sw,SW_RST_SY1,SW_DO_TYPE_OFF); 
	}
	else
	{
		sw_do(sw,SW_RST_SY1,SW_DO_TYPE_ON); 
		sw_do(sw,SW_RST_SY,SW_DO_TYPE_OFF); 
	}
}


//清启动跳闸启动条件
static void fa_cls_qd(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	//TSDHZ_T *pSW =&pR->tSDHZ;
	//TSETSW *pSet = &pRunSet->tSwSet[sw];

	TU0_T *pU0=&pR->tU0TZ;
	TOC_T *poc ;
	if(pR->bBSTZ)//遮断电流的时候防止提前清掉启动标志
		return;
//	if(!pR->tSWST.uSWST.bFlag.bDIHW)	
	{	
		pR->tLostVot.uLostVot.bFlag.bQD = false;//失压启动返回
		pR->tLostVot.uLostVot.bFlag.bTz = false;
	}

	//if(pSW->uSdhz_S.bFlag.bGL)
	{
		poc = &g_tRelay[sw].tOC[FA_GL];
		poc->sta.bFlag.bQD = false;
		poc->sta.bFlag.bTz = false;
	}
	//else if(pSW->uSdhz_S.bFlag.bGL_II)
	{
		poc = &g_tRelay[sw].tOC[FA_GL_II];
		poc->sta.bFlag.bQD = false;
		poc->sta.bFlag.bTz = false;
	}
	//else if (pSW->uSdhz_S.bFlag.bJD) 
	{
		poc = &g_tRelay[sw].tOC[FA_LX];
		
		poc->sta.bFlag.bQD = false;
		poc->sta.bFlag.bTz = false;
	}
	//else if (pSW->uSdhz_S.bFlag.bOverU0)
	{
		pU0->uZOV.bFlag.bQD = false;
		pU0->uZOV.bFlag.bTz = false;
	}

}
//fa闭锁分合闸
bool fa_bs_fz(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	//TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	if (!(FA_ALL_EN(sw)) || !pSet->bTT_FA) // FA功能未投入
		return false;

	if(pR->bBSTZ)	//
	{
		rt_printf("遮断电流，禁止分闸\r\n");
		return true;
	}

	return false;
}
bool fa_bs_hz(int sw)
{
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW = &pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	RUN_STU_SW *prun=&g_tRelay[sw].run_stu;
	if (!(FA_ALL_EN(sw)) || !pSet->bTT_FA ) // FA功能未投入
		return false;
	
	if((soe_check(EV_BS_DB+(sw)*EV_SW_NUM)||pSW->uSdhz_S.bFlag.bDBYY) && pSet->bTT_fa_scyy_bs)
	{
		rt_printf("FA双侧有压，禁止合\r\n");
		return true;//
	}
	if (prun->fa_ls)	// 联络
	{
		if(pSW->bL_BSLed && pRunSet->bTT_bs_ykon)
		{
			rt_printf("联络双侧有压，禁止合闸\r\n");	
			return true;
		}
	}
	else
	{
		if(soe_check(EV_BS_ALL+(sw)*EV_SW_NUM) && pRunSet->bTT_bs_ykon)
		{
			rt_printf("FA闭锁合闸，禁止合\r\n");
			return true;//
		}
	}
	return false;
}
#ifdef FUNC_MODE_JS
//清重合闸闭锁
void Reset_chz_bs(int sw)
{
	if(soe_check(EV_ARBS+sw*EV_SW_NUM)==true)
	{
		g_tRelay[sw].tCHZ.sta.bFlag.bCHBS=false;
		soe_record_ev(EV_ARBS+sw*EV_SW_NUM, 0, 0,0,0);	// 重合闸闭锁
		led_set_sw(sw,SW_LED_CHZBS, LED_OFF);
		led_set_sw(sw,SW_LED_CHZBS_LOCK, LED_OFF);	
		ResetTR(&g_tRelay[sw].tCHZ.tTCHJBSTime);	
	}
}
#endif

/**************************************************************************
函数名称：Pro_LS_RUN
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：环网点运行
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
void FA_Run(DWORD  dStep)
{
	int sw=g_protect.sw;	
	bool bSW_LL,bY1;
	TRELAY_T *pR=&g_tRelay[sw];
	TSDHZ_T *pSW =&pR->tSDHZ;
	TSETSW *pSet = &pRunSet->tSwSet[sw];

#ifdef FUNC_MODE_JS
    static bool sb_first=true,sb_first_ll = true,sb_first_fd = true;
#endif
#ifdef FUNC_DRIVE
	gb_drive.b_fa_drive = true;
#endif

	if(!pSW->bInitUF)
	{
		int ret;
		ret=fa_UFDI_Init();
		if(ret==0)return;
		pSW->bInitUF=true;
	}
	run_vol_refersh(sw, dStep);
	if (!(FA_ALL_EN(sw)) || !pSet->bTT_FA) // FA功能未投入
	{
		pR->tU0TZ.bU0Led=false;
		pR->tU0TZ.bU0GjLed = false;
		pR->tOC[FA_GL].sta.bFlag.bDzLed = false;
		pR->tOC[FA_GL].sta.bFlag.bGj = false;
		pR->tOC[FA_GL_II].sta.bFlag.bDzLed = false;
		pR->tOC[FA_GL_II].sta.bFlag.bGj = false;
		pR->tOC[FA_GL2].sta.bFlag.bDzLed = false;
		pR->tOC[FA_GL2].sta.bFlag.bGj = false;
		pR->tOC[FA_LX].sta.bFlag.bDzLed = false;
		pR->tOC[FA_LX].sta.bFlag.bGj = false;
		pR->tOC[FA_LX2].sta.bFlag.bDzLed = false;
		pR->tOC[FA_LX2].sta.bFlag.bGj = false;
		if(soe_check(EV_BS_HA+sw*EV_SW_NUM))//手分闭锁后，切换至其他模式应保持该信号 2020-11-3
		{
			pSW->bDL_Tz=true;
		}
		if(pR->tSWST.uSWST.bFlag.bDIHW)
		{
			pSW->bDL_Tz=false;//合位清手分闭锁标志 2020-11-3
		}
		pSW->bS_BSLed = 0;
		pSW->bL_BSLed = 0;
	#ifndef GD_AREA_ECZD_2020
		fa_unlock_s_bs(sw);
	#endif

		//非FA逻辑下实时清以下状态
		pR->uRmtSW.bYHExecute_fa =0;
		pR->uRmtSW.bHandHz_fa=0;
	#if !defined FUNC_MODE_JS && !defined FUNC_ONLY_MMD_JS
		g_run_stu.js=0;
    #endif
		pSW->bDL_Hz=0;
		g_run_stu.rmtjs=0;
		pR->tLostVot.uLostVot.bFlag.bSHWY = FALSE;		//清手合无压标志

		pR->uRmtSW.bYTExecute=0 ; 
		pR->uRmtSW.bHandTz=0;
		//pSW->bDL_Tz=0;
		pSW->bSDHZinit=0;
		//开关状态监测计时器
		ResetTR(&pSW->tHw100ms100ms);
		ResetTR(&pSW->tTw100ms100ms);
		ResetTR(&pSW->tTz0ms1s);
		ResetTR(&pSW->tHz0ms1s);
		ResetTR(&pSW->tOnYLTime);
		ResetTR(&pSW->tUABL25ms);
		ResetTR(&pSW->tUBCL25ms);
		ResetTR(&pSW->tOnHW_FA_JSTime);

		if(pSW->S_Status==S_XTIME)
		{
			ResetTR(&pSW->tOnXSTime);
		}	
		if(pSW->S_Status==S_YTIME)
		{
			ResetTR(&pSW->tOnYSTime);
		}

		//fa_s_state_change(sw,S_INIT);
		//fa_l_state_change(sw,L_INIT);
	//#ifdef FA_BSYTIME_JS
		//rst_ybs_soe( sw);
	//#endif
		//fa_close_led(sw);	
	#if defined FUNC_MODE_JS || defined FUNC_ONLY_MMD_JS
	{
		bool b_js_mode=false,b_js_mmd=false;
	#ifdef FUNC_MODE_JS
		b_js_mode = (!sb_first_ll || !sb_first_fd);
	#endif
	#ifdef FUNC_ONLY_MMD_JS
		b_js_mmd = g_run_stu.b_mmdjs;
	#endif
		if(b_js_mode || b_js_mmd)
		{
		#ifdef FUNC_MODE_JS
			if(b_js_mode)
			{
				sb_first_ll = true;
				sb_first_fd = true;
				sb_first = false;
			}
		#endif
		#ifdef FUNC_ONLY_MMD_JS
			if(b_js_mmd)
			{
				pSW->bDL_Tz=false;
			}
		#endif
			gb_js_mode = true;
		
			if(gb_js_mode)
			{
				g_run_stu.js = true;
				fa_s_run(sw, dStep);
				fa_l_run(sw, dStep);
				fa_rstbs_soe(sw);
				pSW->bL_BSLed=fa_check_all_l_bs(sw);
				pSW->bS_BSLed=fa_check_all_s_bs(sw);
				fa_uf_clear(sw,false);
				fa_uf_clear(sw,true);
			}
			
			gb_js_mode = false;
		#ifdef FUNC_ONLY_MMD_JS
			g_run_stu.b_mmdjs = false;
		#endif
		}
		
		//解锁标志在宏定义FUNC_MODE_JS开启时有用到，需在用完后再清，所以调整到此位置
		g_run_stu.js=0;
	}
    #endif	
		return;
	}
#if defined FUNC_MODE_JS || defined FUNC_ONLY_MMD_JS
	gb_js_mode = false;
#endif
#ifdef FUNC_ONLY_MMD_JS
	//FA模式下要将此标志一直置0，否则可能出现FA下有解锁需求将此标志置位后，切模式后会因为此标志一直未清零而自动解锁一次
	g_run_stu.b_mmdjs = false;
#endif

	fa_cls_qd(sw);
	fa_RstUFDI(sw);	//复归瞬压继电器	
	fa_s_Dataset(sw, dStep);
	bSW_LL=(pR->run_stu.fa_ls>0)?true:false;
	#if 1
	if (pR->uRmtSW.bYTExecute )	
	{
		dl_ope_event(sw,EV_YK_FZ, 0,0,0 );
	}	
	
	if (pR->uRmtSW.bYHExecute )	
	{
		dl_ope_event(sw,EV_YK_HZ, 0,0,0 );
	}	
	

	if (pR->uRmtSW.bHandTz )	
	{
		dl_ope_event(sw,EV_HA_FZ, 0,0,0 );
	}	
	
	if (pR->uRmtSW.bHandHz )	
	{
		dl_ope_event(sw,EV_HA_HZ, 0,0,0 );
	}

	RunTR(&pSW->tHw100ms100ms,( (pR->run_stu.sw==2)?true:false), dStep);   
	RunTR(&pSW->tTz0ms1s,(pR->uBHDZ.bFlag.bBHT||pR->uRmtSW.bYTExecute || pR->uRmtSW.bHandTz || pR->tgoc.bTzout), dStep);  // 
	bY1=pSW->tHw100ms100ms.boolTrip&&((pR->run_stu.sw==1)?true:false);
	if(bY1)  // 开关由合到分
	{
		//ResetTR(&pSW->tHz0ms2s);
		if(!pSW->tTz0ms1s.boolTrip)
		{
			if(pR->run_stu.kgyf)
			{
				dl_ope_event(sw,EV_HA_FZ, 0,0,0 );
			}
			else
			{
				dl_ope_event(sw,EV_DL_FZ, 0,0,0 );
				pSW->bDL_Tz=true;
			}
		}
	}
	RunTR(&pSW->tTw100ms100ms,( (pR->run_stu.sw==1)?true:false), dStep);   
	RunTR(&pSW->tHz0ms1s,(pR->uBHDZ.bFlag.bBHH||pR->uRmtSW.bYHExecute || pR->uRmtSW.bHandHz||pR->tTQHz.uTQHz.bFlag.bHz||pR->tgoc.sta.bFlag.bllhz), dStep);   
	bY1=pSW->tTw100ms100ms.boolTrip&&((pR->run_stu.sw==2)?true:false);
	if(bY1)  // 开关由分到合
	{
		//ResetTR(&pSW->tTz0ms2s);
		if(!pSW->tHz0ms1s.boolTrip)
		{
			if(pR->run_stu.kgyf)
			{
				dl_ope_event(sw,EV_HA_HZ, 0,0,0 );
			}
			else
			{		
				dl_ope_event(sw,EV_DL_HZ, 0,0,0 );
				pSW->bDL_Hz=true;
			}
			if(pSW->uSdhz_L.bFlag.bX_HZEvent)
			{
				//if(soe_check(EV_GOOSE_HZ_OK+sw*EV_SW_NUM)==false)
				//	soe_record_ev(EV_GOOSE_HZ_OK+sw*EV_SW_NUM, 1, 0,0,0 );				
			}
			pSW->uSdhz_L.bFlag.bX_HZEvent = false;
		}
	}

#endif
	if (!(FA_ALL_EN(sw)) ||!pSet->bTT_FA) // FA功能未投入
	{
		if(!BH_GOOSE_EN(sw))fa_close_led(sw);
		if (pSW->S_Status != S_USUAL)
		{
			fa_s_state_change(sw,S_USUAL);//pSW->S_Status = S_USUAL;
			pSW->uSdhz_S.wfFlag = 0;	
			pSW->bS_BSLed = 0;
		}
		if (pSW->L_Status != L_INIT)
		{
			//pSW->L_Status = L_INIT;
			fa_l_state_change(sw,L_INIT);
			pSW->uSdhz_L.wfFlag = 0;
			pSW->bL_BSLed = 0;
		}
		return;
	}

	fa_status_print(sw);

	if (!bSW_LL)  // 分段功能
	{
	#ifdef FUNC_MODE_JS
		if(sb_first_fd && !sb_first)
		{
			sb_first_fd = false;
			sb_first_ll = true;
			g_run_stu.js=true;
			fa_l_run(sw, dStep);
			fa_rstbs_soe(sw);
			Reset_chz_bs(sw);
			pSW->bL_BSLed=fa_check_all_l_bs(sw);
			fa_uf_clear(sw,false);
			fa_uf_clear(sw,true);
		}
	
		if(sb_first_fd)
		{
			sb_first_fd = false;
			sb_first_ll = true;
			sb_first = false;
		}
	#endif
		fa_s_run(sw, dStep);
		//pSW->L_Status = L_INIT;
		if(pSW->L_Status==L_XL_ZTIME)
			fa_rstbs_soe( sw);
		fa_l_state_change(sw,L_INIT);
		pSW->bL_BSLed = 0;
#ifdef FUNC_DRIVE_JY
		if(gb_drive.b_drive_success_again || gb_drive.b_drive_success)
		{
			if(fa_check_all_s_bs(sw))
			{
				gb_drive.b_drive_success_again = false;
				gb_drive.b_drive_success = false;
				
				if(soe_check(EV_DRIVE_HZ_FAIL+sw*EV_SW_NUM) == false)
				{
					soe_record_ev(EV_DRIVE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
				}
	
				if(soe_check(EV_DRIVE_END+sw*EV_SW_NUM)==false) //传动结束
				{
					soe_record_ev(EV_DRIVE_END+sw*EV_SW_NUM, 1, 0,0,0 );
				}
				if(soe_check(EV_DRIVE_END+sw*EV_SW_NUM)==true)	//传动结束返回
				{
					soe_record_ev(EV_DRIVE_END+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			}
		}
#endif
	}
	else  // 联络功能
	{
	#ifdef FUNC_MODE_JS
		if(sb_first_ll && !sb_first)
		{
			sb_first_fd = true;
			sb_first_ll = false;
			g_run_stu.js=true;
			fa_s_run(sw, dStep);
			fa_rstbs_soe(sw);
			Reset_chz_bs(sw);
			pSW->bS_BSLed=fa_check_all_s_bs(sw);
			fa_uf_clear(sw,false);
			fa_uf_clear(sw,true);
		}
	
		if(sb_first_ll)
		{
			sb_first_ll = false;
			sb_first_fd = true;
			sb_first = false;
		}
	#endif
		if (pSW->S_Status != S_USUAL)
		{
			fa_s_state_change(sw,S_USUAL);//pSW->S_Status = S_USUAL;
			pSW->uSdhz_S.wfFlag = 0;
			pSW->bS_BSLed = 0;
		}
		fa_l_run(sw, dStep);
#ifdef FUNC_DRIVE_JY
		if(gb_drive.b_drive_success_again || gb_drive.b_drive_success)
		{
			if(fa_check_all_l_bs(sw))
			{
				gb_drive.b_drive_success_again = false;
				gb_drive.b_drive_success = false;
				
				if(soe_check(EV_DRIVE_HZ_FAIL+sw*EV_SW_NUM) == false)
				{
					soe_record_ev(EV_DRIVE_HZ_FAIL+sw*EV_SW_NUM, 1, 0,0,0 );
				}
	
				if(soe_check(EV_DRIVE_END+sw*EV_SW_NUM)==false) //传动结束
				{
					soe_record_ev(EV_DRIVE_END+sw*EV_SW_NUM, 1, 0,0,0 );
				}
				if(soe_check(EV_DRIVE_END+sw*EV_SW_NUM)==true)	//传动结束返回
				{
					soe_record_ev(EV_DRIVE_END+sw*EV_SW_NUM, 0, 0,0,0 );
				}
			}
		}
#endif
	}
}


static int _volstatus_createfile(void)
{
	unsigned int addr,file_length;
	u16 crc;
	loff_t pos;
	struct vol_file_head	volstatus_file;
		
	// 写文件头
	memset(&volstatus_file,0,sizeof(volstatus_file));
	volstatus_file.cfh.signature = SIG_VOL_STATUS_FILE;
	volstatus_file.cfh.version = VOLSTATUS_FILE_VERSION;
		
	volstatus_file.addr = FILE_ADDR_ALGIN(sizeof(volstatus_file));
	volstatus_file.num = SWITCH_NUM_MAX;

	// 得到文件长度
	addr = volstatus_file.addr + volstatus_file.num * sizeof(struct vol_stu);
	file_length = FILE_ADDR_ALGIN(addr);
	vol_filelen = file_length+2;
	
	// 分配并初始化空间
	g_volbuf = rt_malloc(file_length + 2); 
	if(!g_volbuf)
	{
		g_volbuf = 0;
		return -1;
	}
	memset(g_volbuf, 0, file_length + 2);
	
	// 写入文件头
	memcpy(g_volbuf, (char *)&volstatus_file, sizeof(volstatus_file));
	
	// 写上电合闸状态	
	memcpy(g_volbuf+volstatus_file.addr, (char *)&g_vol_stu, volstatus_file.num * sizeof(struct vol_stu));

	// 计算CRC
	crc = CrcStr(g_volbuf, file_length);
	memcpy(g_volbuf+file_length, &crc, 2);

	// 创建数据文件
	gf_volstu = rt_file_open("/app/data/vol_status.bin",O_CREAT|O_RDWR|O_TRUNC,0);
	if(IS_ERR(gf_volstu))
	{
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -2;
	}
	
	pos = 0;
	rt_file_write(gf_volstu, g_volbuf, file_length+2, &pos);

	return 0;
}

/**************************************************************************
函数名称：StatusRead
函数版本：1.00 
作者：    电力产品开发部
创建日期：2011.10.28   
函数功能说明：上电后对相关状态进行读取
输入参数：
其他输入:
输出参数：
返回值： 
***************************************************************************/
static int _volstatus_readfile(void)
{	
	u32 len;
	u16 crc, crc1;
	loff_t pos;
	struct vol_file_head *brh;
	
	// 创建并打开文件
	gf_volstu = rt_file_open("/app/data/vol_status.bin",O_RDWR,0);
	if(IS_ERR(gf_volstu))
	{
		gf_volstu = 0;
		return -1;
	}

	// 得到文件长度
	len = rt_file_getfile_size(gf_volstu);
	if(len <= 0)
	{
		rt_file_close(gf_volstu,0);
		return -11;
	}

	// 分配内存
	g_volbuf = rt_malloc(len);
	if((g_volbuf) == NULL)
	{
		rt_file_close(gf_volstu,0);
		g_volbuf = 0;
		return -2; 	
	}

	// 读出内容
	pos = 0;
	if(rt_file_read(gf_volstu,g_volbuf,len,&pos) != len)
	{
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -3;
	}

	// 检查CRC
	crc = CrcStr(g_volbuf,len-2);
	crc1 = *(u16*)(g_volbuf+len-2);
	if(crc != crc1)
	{
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -4;
	}

	// 检查文件签名
	brh = (struct vol_file_head*)g_volbuf;
	if(brh->cfh.signature != SIG_VOL_STATUS_FILE)
	{
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -5;
	}

	// 检查开关个数是否对应
	if(brh->num != SWITCH_NUM_MAX)
	{
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -6;
	}

	//检查数据长度
	if((len-2) != FILE_ADDR_ALGIN((SWITCH_NUM_MAX * sizeof(struct vol_stu) + sizeof(struct vol_file_head))))
	{
		rt_printf("当前volstatus文件长度为%d,正确文件长度为%d\r\n",len-2,FILE_ADDR_ALGIN((SWITCH_NUM_MAX * sizeof(struct vol_stu) + sizeof(struct vol_file_head))));
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);
		gf_volstu = 0;
		g_volbuf = 0;
		return -7;
	}
	#if 0
	// 检测文件长度是否合法
	if(len-sizeof(struct vol_file_head ) != sizeof(struct vol_stu)*brh->num+2)
	{
		rt_printf("vol_status.bin is err len=%d %d addr=%d %d\r\n",len,sizeof(struct vol_stu)*brh->num,brh->addr ,sizeof(struct vol_file_head ));
		return -7;
		
	}
	#endif
	//取出文件中存储内容
	memcpy (&g_vol_stu, g_volbuf+brh->addr, sizeof(struct vol_stu)*brh->num);
	vol_filelen = len;
		
	return 0;

}
bool gb_wake_soe=false;
static void _volstu_update(void)
{
	int sw;
	gb_wake_soe = true;
	for (sw=0; sw<SWITCH_NUM_MAX; sw++)
	{
		TSDHZ_T *pSW = &g_tRelay[sw].tSDHZ;	
		if (!(FA_ALL_EN(sw)) || !pRunSet->tSwSet[sw].bTT_FA) // FA功能未投入
			continue;
		if (pRunSet->tSwSet[sw].bTT_FA&&!g_tRelay[sw].run_stu.fa_ls)
		{
			pSW->S_Status = g_vol_stu[sw].status;//初始化FA状态
			pSW->uSdhz_S.bFlag.bPower= g_vol_stu[sw].shangdiance;
			rt_printf_time("\r\n当前分段模式 FA S_Status >>>>>>>>>上电方向=%d 上电状态=%s\r\n",pSW->uSdhz_S.bFlag.bPower,fa_s_status[pSW->S_Status]);
			if(pSW->S_Status==S_BSXTIME)
			{
				pSW->S_Status=S_BSXTIME;
				if(pSW->uSdhz_S.bFlag.bPower) 
					soe_record_ev(EV_BS_X_P+sw*EV_SW_NUM, 1, 0,0,0 );	
				else
					soe_record_ev(EV_BS_X_L+sw*EV_SW_NUM, 1, 0,0,0 );	

			}
			else if(pSW->S_Status==S_BSFLASH)

			{
				pSW->S_Status=S_BSFLASH;
				pSW->uSdhz_S.bFlag.bUABFlash = pSW->uSdhz_S.bFlag.bPower;
				pSW->uSdhz_S.bFlag.bUBCFlash = !pSW->uSdhz_S.bFlag.bUABFlash;
				if(pSW->uSdhz_S.bFlag.bPower) 
					soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 1, 0,0,0 );	
				else
					soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 1, 0,0,0 );	
			}
			else if(g_vol_stu[sw].S_lockstatus&(1<<0))//零序电压合后故障

			{
				pSW->S_Status = S_BSHHGZ ;
				soe_record_ev(EV_BS_U0+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_BS_U0+sw*EV_SW_NUM,1);
				soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ+sw*EV_SW_NUM,1);
				pSW->tOnYSTime.boolTrip=true;//强制将Y计时器置一，防止开机后再次产生Y闭锁
				if(pSW->uSdhz_S.bFlag.bPower) 	
					soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ_P+sw*EV_SW_NUM,1);
				else	
					soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ_L+sw*EV_SW_NUM,1);
			}
			else if(pSW->S_Status==S_BSYTIME|| pSW->S_Status==S_BSHHGZ ||pSW->S_Status==S_BSDL)

			{
				if(pSW->uSdhz_S.bFlag.bPower) 
				{
					if(pSW->S_Status==S_BSYTIME)
						soe_record_ev(EV_BS_Y_P+sw*EV_SW_NUM, 1, 0,0,0 );	//soe_ev_set(EV_BS_Y_P+sw*EV_SW_NUM,1);
					else if(pSW->S_Status==S_BSHHGZ||pSW->S_Status==S_BSDL)
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ+sw*EV_SW_NUM,1);
						soe_record_ev(EV_HHGZ_P+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ_P+sw*EV_SW_NUM,1);
						pSW->tOnYSTime.boolTrip=true;//强制将Y计时器置一，防止开机后再次产生Y闭锁
					}
				}
				else
				{
					if(pSW->S_Status==S_BSYTIME)
						soe_record_ev(EV_BS_Y_L+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_BS_Y_L+sw*EV_SW_NUM,1);
					else if(pSW->S_Status==S_BSHHGZ||pSW->S_Status==S_BSDL)
					{
						soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ+sw*EV_SW_NUM,1);
						soe_record_ev(EV_HHGZ_L+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_HHGZ_L+sw*EV_SW_NUM,1);
						pSW->tOnYSTime.boolTrip=true;//强制将Y计时器置一，防止开机后再次产生Y闭锁
					}
				}			
			}
			else if(pSW->S_Status!=S_INIT)
			{
				fa_s_state_change(sw,S_INIT);//pSW->S_Status=S_INIT;
				pSW->uSdhz_S.bFlag.bPower=0;
			}

			
			if(g_vol_stu[sw].S_lockstatus&(1<<1))
			{
				soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_BS_HA+sw*EV_SW_NUM,1);
			#ifdef FUNC_REBOOT_BS_HA_JS_3S
				g_tRelay[sw].uRmtSW.b_bsha = true;
			#endif
			}
			if(g_vol_stu[sw].S_lockstatus&(1<<2))
			{
				soe_record_ev(EV_BS_FZMORE+sw*EV_SW_NUM, 1, 0,0,0 );//soe_ev_set(EV_BS_FZMORE+sw*EV_SW_NUM,1);
			}
		#ifdef GD_AREA_CHAOZHOUFENGXI
			if(g_vol_stu[sw].S_lockstatus&(1<<3))
			{
				soe_record_ev(EV_BSBE_U0+sw*EV_SW_NUM, 1, 0,0,0 );
			}	
		#endif
		#if defined GD_AREA_ZHUHAI_V2 || defined GD_AREA_ZHUHAI_FTU //珠海局要求合后故障，有压且合位的时候才能解锁
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM))
			{
				g_tRelay[sw].uRmtSW.bYH_fajs_flag=true;
				pSW->bS_BSLed=fa_check_all_s_bs(sw);//点灯
			}
		#endif
			g_vol_stu[sw].L_status = L_INIT;//重置联络模式保存信息
		}
		else if (pRunSet->tSwSet[sw].bTT_FA && g_tRelay[sw].run_stu.fa_ls)
		{
			rt_printf_time("\r\n当前联络模式 FA L_Status >>>>>>>>>上电方向=%d 上电状态=%s\r\n",g_vol_stu[sw].shangdiance,fa_l_status[g_vol_stu[sw].L_status]);
			if(g_vol_stu[sw].L_status == L_XL_ZTIME)
			{
				pSW->uSdhz_L.bFlag.bUABFlash = g_vol_stu[sw].shangdiance;//残压方向
				pSW->uSdhz_L.bFlag.bUBCFlash = !pSW->uSdhz_L.bFlag.bUABFlash;
				ResetTR(&pSW->tOnYLTime);
				fa_l_state_change(sw,L_XL_ZTIME);
			#ifdef GD_AREA_ZHONGSHAN_2020
				if(pSW->uSdhz_L.bFlag.bUABFlash)
					soe_record_ev(EV_BS_UF_P+sw*EV_SW_NUM, 1, 0,0,0 );
				if(pSW->uSdhz_L.bFlag.bUBCFlash)
					soe_record_ev(EV_BS_UF_L+sw*EV_SW_NUM, 1, 0,0,0 );
			#endif
			}
			else
			{
				g_vol_stu[sw].L_status = L_INIT;//重置联络模式保存信息
			}
			if(g_vol_stu[sw].L_lockstatus&(1<<0))//合后故障
				soe_record_ev(EV_HHGZ+sw*EV_SW_NUM, 1, 0,0,0 );
				
		#ifdef FUNC_REBOOT_BS_HA_JS_3S
			if(g_vol_stu[sw].L_lockstatus&(1<<1))
			{
				soe_record_ev(EV_BS_HA+sw*EV_SW_NUM, 1, 0,0,0 );
				g_tRelay[sw].uRmtSW.b_bsha = true;
			}
		#endif
			
			g_vol_stu[sw].status = S_INIT;//重置分段模式保存信息
		}


	}

	gb_wake_soe = false;
}
#if 0
static void _volstu_update(void)
{
	int sw;
	for (sw=0; sw<SWITCH_NUM_MAX; sw++)
	{
		TSDHZ_T *pSW = &g_tRelay[sw].tSDHZ;		
		if (pRunSet->tSwSet[sw].bTT_FA&&!g_tRelay[sw].run_stu.fa_ls)
		{
			pSW->S_Status = g_vol_stu[sw].status;//初始化FA状态
			pSW->uSdhz_S.bFlag.bPower= g_vol_stu[sw].shangdiance;
			if(pSW->S_Status==S_BSXTIME||pSW->S_Status==S_BSFLASH)
			{
				pSW->S_Status=S_BSXTIME;
				if(pSW->uSdhz_S.bFlag.bPower) 
				{
					soe_ev_set(EV_BS_X_P+sw*EV_SW_NUM,1);
				}
				else
				{
					soe_ev_set(EV_BS_X_L+sw*EV_SW_NUM,1);
				}			
			}
			else if(pSW->S_Status==S_BSYTIME||pSW->S_Status==S_BSHHGZ||pSW->S_Status==S_BSDL)
			{
				if(pSW->uSdhz_S.bFlag.bPower) 
				{
					soe_ev_set(EV_BS_Y_P+sw*EV_SW_NUM,1);
				}
				else
				{
					soe_ev_set(EV_BS_Y_L+sw*EV_SW_NUM,1);
				}			
			}
			else if(pSW->S_Status!=S_INIT)
			{
				fa_s_state_change(sw,S_INIT);//pSW->S_Status=S_INIT;
				pSW->uSdhz_S.bFlag.bPower=0;
			}

			if(g_vol_stu[sw].lockstatus&(1<<0))
			{
				soe_ev_set(EV_BS_U0+sw*EV_SW_NUM,1);
			}

			if(g_vol_stu[sw].lockstatus&(1<<1))
			{
				soe_ev_set(EV_BS_HA+sw*EV_SW_NUM,1);
			}
			if(g_vol_stu[sw].lockstatus&(1<<2))
			{
				soe_ev_set(EV_BS_FZMORE+sw*EV_SW_NUM,1);
			}
		}
	}
}
#endif
static void _volstatus_init(void)
{
	int i;
	int sw;
	for(sw=0; sw<SWITCH_NUM_MAX; sw++)
	{	
		// 仅保护投入时，才初始化上电合闸标志
		if (pRunSet->tSwSet[sw].bTT_FA)
		{
			i = _volstatus_readfile();
			if (i != 0)
			{
				rt_printf("上电合闸标志文件错误:  %d\r\n", i);
				
				// 上电合闸状态	
				memset (g_vol_stu, 0, sizeof(g_vol_stu));
				g_vol_stu[sw].status = 1;
				_volstatus_createfile();
			}
			g_volfile_open = 1;
			break;
		}
	}
	
	_volstu_update();
	
}

static void _volstatus_reinit(void)
{
	int i;
	int sw;
	for(sw=0; sw<SWITCH_NUM_MAX; sw++)
	{	
		// 仅保护投入时，才初始化上电合闸标志
		if (pRunSet->tSwSet[sw].bTT_FA&& FA_ALL_EN(sw))
		{
			i = _volstatus_readfile();
			if (i != 0)
			{
				rt_printf("上电合闸标志文件错误:  %d\r\n", i);
				
				// 上电合闸状态	
				memset (g_vol_stu, 0, sizeof(g_vol_stu));
				g_vol_stu[sw].status = 0;
				_volstatus_createfile();
			}
			g_volfile_open = 1;
			break;
		}
	}	
}



int vol_stu_printf(void)
{
	int sw;
	
	rt_printf("\r\nsw\tS_Status\tshangdiance\r\n");
	for (sw=0; sw<SWITCH_NUM_MAX; sw++)
	{
		rt_printf("%d\t%02d\t%02d\r\n",
					sw,
					g_vol_stu[sw].status,
					g_vol_stu[sw].shangdiance);
	}
 	return 0;
}


int FA_status_write(void)
{
	int sw, writeflag=0, bhTT=0;
	loff_t pos;
	int ret;
	u16 crc;

	//确保文件曾经打开
	if (!g_volfile_open)
	{
		_volstatus_reinit();
		return -1;
	}

	//文件句柄被清0，释放缓存
	if(gf_volstu == 0)
	{
		if(g_volbuf)
		{
			rt_free(g_volbuf);		
			g_volbuf = 0;
			g_volfile_open = 0;
		}
		return -2;
	}
	
	//判断保护是否投入，判断是否有存储标志
	for (sw=0; sw<SWITCH_NUM_MAX; sw++)
	{
		if (pRunSet->tSwSet[sw].bTT_FA&& FA_ALL_EN(sw))
		{
			bhTT = 1;
		}

		if(g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bSaveStatus)
		{
			g_vol_stu[sw].status = g_tRelay[sw].tSDHZ.S_Status;
			g_vol_stu[sw].shangdiance = g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bSNChange;
			g_vol_stu[sw].S_lockstatus=0;
			if(soe_check(EV_BS_U0+sw*EV_SW_NUM)) // 合后零压
			{
				g_vol_stu[sw].S_lockstatus|=(1<<0);
			}

			if(soe_check(EV_BS_HA+sw*EV_SW_NUM))  //手分闭锁
			{
				g_vol_stu[sw].S_lockstatus|=(1<<1);
			}
			if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM))//多次分闸闭锁
			{
				g_vol_stu[sw].S_lockstatus|=(1<<2);
			}	
		#ifdef GD_AREA_CHAOZHOUFENGXI
			if(soe_check(EV_BSBE_U0+sw*EV_SW_NUM)==true)   // 
			{
				g_vol_stu[sw].S_lockstatus|=(1<<3);
			}	
		#endif
			writeflag = 1;
			g_tRelay[sw].tSDHZ.uSdhz_S.bFlag.bSaveStatus=false;			
		}
		else if(g_tRelay[sw].tSDHZ.uSdhz_L.bFlag.bSaveStatus)
		{
			g_vol_stu[sw].status = 0;
			g_vol_stu[sw].shangdiance = g_tRelay[sw].tSDHZ.uSdhz_L.bFlag.bSNChange;
			g_vol_stu[sw].L_lockstatus=0;
			if(soe_check(EV_HHGZ+sw*EV_SW_NUM)) // 合后故障
			{
				g_vol_stu[sw].L_lockstatus|=(1<<0);
			}
		#ifdef FUNC_REBOOT_BS_HA_JS_3S
			if(soe_check(EV_BS_HA+sw*EV_SW_NUM)) // 手分闭锁
			{
				g_vol_stu[sw].L_lockstatus|=(1<<1);
			}
		#endif
			
			g_vol_stu[sw].L_status = g_tRelay[sw].tSDHZ.L_Status;
			writeflag = 1;
			g_tRelay[sw].tSDHZ.uSdhz_L.bFlag.bSaveStatus=false;
		}		
	}

	//所有上电合闸保护全部退出时，关闭文件，释放缓存
	if (!bhTT)
	{
		if(gf_volstu != 0)
		{
			rt_file_close(gf_volstu,0);	
		}
		if(g_volbuf)
		{
			rt_free(g_volbuf);	
			gf_volstu = 0;
			g_volbuf = 0;
			g_volfile_open = 0;
		}		
		return -3;
	}

	//巡检上电合闸的存储标志
	if (!writeflag)
	{
		return -4;
	}	
	
	//存储标志
	memcpy(g_volbuf+sizeof(struct vol_file_head), g_vol_stu, sizeof(g_vol_stu));
	
	// 计算CRC
	crc = CrcStr(g_volbuf, vol_filelen-2);

	//CRC的位置需考虑16对齐
	memcpy(g_volbuf+vol_filelen-2, &crc, 2);

	pos = 0;
	ret = rt_file_write(gf_volstu, g_volbuf, vol_filelen, &pos);
	if(ret != vol_filelen)
	{
		rt_file_close(gf_volstu,0);
		rt_free(g_volbuf);		
		gf_volstu = 0;
		g_volbuf = 0;
		g_volfile_open = 0;
		rt_printf("\r\n write error");
		return -5;
	}
	return 0;

}

int FA_exit(void)
{
	if(gf_volstu != 0)
	{
		rt_file_close(gf_volstu,0);	
	}
	if(g_volbuf)
	{
		rt_free(g_volbuf);	
		gf_volstu = 0;
		g_volbuf = 0;
		g_volfile_open = 0;
	}		
	return 0;
}

void Pro_hzbs(int sw,DWORD  dStep)
{
	TRELAY_T *pR=&g_tRelay[sw];
	THZBS_T *pSW = &pR->thzbs;
	TSETSW *pSet = &pRunSet->tSwSet[sw];
	bool bY1;
	
	RunTR(&pSW->tTw100ms100ms,( (pR->run_stu.sw==2)?true:false), dStep);   
	bY1=pSW->tTw100ms100ms.boolTrip&&((pR->run_stu.sw==1)?true:false);
#if 1
	if(pR->run_stu.sw==1 && soe_check(EV_BS_FZMORE+sw*EV_SW_NUM))
	{
		pSW->fztimes = 0;
	}
#endif

	RunTR(&pSW->tBSHZTime,((pSW->fztimes>0)?true:false), dStep);   
	bY1=FA_ALL_EN(sw)
		&&pSet->bTT_hzbs				//连续分闸闭锁投退
		&&!pSW->tBSHZTime.boolTrip;         //时间未到, 设定时间内连续失压分闸
	if(bY1)
	{
		if(pSW->fztimes>=pSet->hzbstimes)  //分闸次数大于整定值，
		{
			pR->bBSHZ=true;
			if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)==false)
			{
				soe_record_ev(EV_BS_FZMORE+sw*EV_SW_NUM, 1, 0,0,0 );
				fa_s_set_savestatus(sw);
			}
			pSW->fztimes=0;			
			ResetTR(&pSW->tBSHZTime);	
		}
	}
	else //超时清零
	{
		pSW->fztimes = 0;
		ResetTR(&pSW->tBSHZTime);	
	}

	if(pSet->bTT_hzbs)  //
	{
		if(g_run_stu.js||g_run_stu.rmtjs)
		{
			if(pSW->fztimes)
				rt_printf("js:连续分闸闭锁\r\n");
			pR->bBSHZ=false;
			pSW->fztimes=0;
			ResetTR(&pSW->tBSHZTime);	
			if(soe_check(EV_BS_FZMORE+sw*EV_SW_NUM)==true)
			{
				soe_record_ev(EV_BS_FZMORE+sw*EV_SW_NUM, 0, 0,0,0 );
				fa_s_set_savestatus(sw);
			}
		}
	}
}

#ifdef FUN_JDXX
/**************************************************************************
函数名称：get_power_on_dir
函数版本：1.00 
作者：
创建日期：
函数功能说明：获取上电方向(目前暂未使用，仅用作返回参数，后续小电流接地需判方向时再做完整功能)
输入参数：
其他输入:
输出参数：
返回值：true----负荷侧送电       false电源侧送电
***************************************************************************/

bool get_power_on_dir(int sw)
{
	return false;	
}
#endif

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

