#ifndef _MEA_H_
#define _MEA_H_

#define ANGEL_INVALID 0xfffffff
#define ANGEL_180  (180*65536L)
#define ANGEL_F180  (-180*65536L)

#define ANGEL_360  (360*65536L)
#define ANGEL_F360  (-360*65536L)  

//#define ZERO_OFFSET  1843  // 零漂偏移
#define ZERO_OFFSET  0  // 零漂偏移

typedef struct RMTYCTEST
{
	u8	owner;	//归属：开关1~开关12、公共0
	u8	indexno;	//在归属中的索引号
	long val;
	bool bRmt;
}RMTYCTEST;


extern RMTYCTEST g_rmt_set_yc;
extern RMTYCTEST g_rmt_set_dd;

extern DWORD dTRstTime;

extern long lMeaVal[]; //测量值保存
extern long lMeaAng[]; //测量值角度
extern bool lMeaCal[]; //测量值是否自产

void FreshMeaPub(long *pVal,long *pAng,bool *pCal);
void FreshMeaSw(long *pVal,long* pAng,bool *pCal,int sw);
long GetRmtMeaVal(int owner,int index,u8 *link_qds);  //取遥测值
int GetRmtDdTmVal(int owner,int index,struct rtc_time_t  *p_ct,float *f_v);  //取带时标电度遥测值

float GetRmtDdVal(int owner,int index);
BYTE GetRmtYxVal(int sw,int index);//取遥信值
void iec_mea_filter(void);

#ifdef METERING_ENERGY
enum
{
	METERING_EVT_ADIR=0,
	METERING_EVT_BDIR,
	METERING_EVT_CDIR,
	METERING_EVT_DIR,
	METERING_EVT_DD_CLEAR,
	METERING_EVT_CLEAR,
	METERING_EVT_ADJ_TIME,
	METERING_EVT_NUM,
};

#define ENERGY_DAY_DATA		0	//日冻结数据
#define ENERGY_SET_DATA		1	//设定间隔冻结数据
#define ENERGY_RT_DATA		2	//实时冻结数据

//每100ms累加的积分电度值
typedef struct T_DLVAL
{
	DWORD  dPEz;	  //正向有功，比例系数1000
	DWORD  dPEzChip; //正向有功累加的碎片，比例系数1000*3600
	DWORD  dPWz;	  //正向无功，比例系数1000
	DWORD  dPWzChip; //正向无功累加的碎片，比例系数1000*3600
	DWORD  dNEz;	  //反向有功，比例系数1000
	DWORD  dNEzChip; //反向有功累加的碎片，比例系数1000*3600
	DWORD  dNWz;	  //反向无功，比例系数1000
	DWORD  dNWzChip;//反向无功累加的碎片，比例系数1000*3600

    DWORD  dPEzSave;//正向有功，比例系数1000
    DWORD  dPWzSave;//正向无功，比例系数1000
    DWORD  dNEzSave;//反向有功，比例系数1000
    DWORD  dNWzSave;//反向无功，比例系数1000
    DWORD  dWz[4];    // 4 象限无功
    DWORD  dWzChip[4];// 4象限无功片比例系数1000
    DWORD  dWzSave[4];// 4象限无功
    DWORD    dirus0;        //方向翻转持续时间
    DWORD    dirus[3];
    short     sDir;
    short     sDir_Num;
    short     sADir;
    short     sBDir;
    short     sCDir;
    bool      bClr;

} TDLVAL;

struct EventNum_
{
    DWORD     sDir_Num;
    DWORD     sADir_Num;
    DWORD     sBDir_Num;
    DWORD     sCDir_Num;
    DWORD     sClr_Num;
	DWORD     sSOEClr_Num;
    DWORD     sAdjustTime_Num;
    short     CheckValue;
};
typedef  struct EventNum_ EventNumType;
extern EventNumType   EventNumData;

void DLInit(void);
void DLCal(void);
void HW_DLCal(void);
void DD_Calc(void);
void DL_clear(void);
void soft_dd_val_clr(void);
void get_eep_dd_data(void);
extern int line_loss_event_start(u8 evt_id,short sum);
extern int line_loss_event_end(u8 evt_id,short sum);
extern void save_event_num_data(void);
#endif

#endif 

/******************end file******************************/


