

#ifndef __CAN_METERING_APP_H__
#define __CAN_METERING_APP_H__



enum XS_YX_ID
{
	ID_PA_INV=0,
	ID_PB_INV,
	ID_PC_INV,
	ID_TD_DIR,	//潮流方向
	ID_YX_NUM
};

enum XS_YC_ID
{
	ID_FREQ=0,
	ID_IA,
	ID_IB,
	ID_IC,

	ID_UAB,
	ID_UBC,
	ID_UCA,	
	ID_UA,
	ID_UB,
	ID_UC,
	ID_PA,
	ID_PB,
	ID_PC,
	ID_P,
	ID_QA,
	ID_QB,
	ID_QC,
	ID_Q,
	ID_SA,
	ID_SB,
	ID_SC,
	ID_S,
	ID_COSA,
	ID_COSB,
	ID_COSC,
	ID_COS,
	ID_YC_NUM
};

enum ID_DD
{
	ID_EP_P=0,
	ID_EQ_P,
	ID_EQ_1,
	ID_EQ_4,
	ID_EP_N,
	ID_EQ_N,
	ID_EQ_2,
	ID_EQ_3,

	ID_EPA_P,
	ID_EPB_P,
	ID_EPC_P,
	ID_EPA_N,
	ID_EPB_N,
	ID_EPC_N,
	ID_EPA,
	ID_EPB,
	ID_EPC,

	ID_EP,
	ID_EQ,

	ID_DD_NUM
};

enum
{
	ID_SET_FRZ_DAY=0,			//考核日冻结日
	ID_SET_FRZ_HOUR,
	ID_SET_REVLIMPW,
	ID_SET_TREVLIMPW,
	ID_SET_REVLIMITD,
	ID_SET_TREVLIMTD,
	ID_SET_NUM,
};

enum ID_YK
{
	ID_YK_JL_CLR=0,
	ID_YK_SOE_CLR,
	ID_YK_AD_JZ,
	
	ID_YK_NUM,
};

enum ID_FREEZE_DD
{
	FREEZE_15MIN_POS_EP = 0,	//15分钟冻结，正向有功电能
	FREEZE_15MIN_POS_EQ,		//15分钟冻结，正向无功电能
	FREEZE_15MIN_I_EQ,			//15分钟冻结，一象限无功电能
	FREEZE_15MIN_IV_EQ,   		//15分钟冻结，四象限无功电能

	FREEZE_15MIN_INV_EP,		//15分钟冻结，反向有功电能
	FREEZE_15MIN_INV_EQ,		//15分钟冻结，反向无功电能
	FREEZE_15MIN_II_EQ,			//15分钟冻结，二象限无功电能
	FREEZE_15MIN_III_EQ, 		//15分钟冻结，三象限无功电能

	FREEZE_DAY_POS_EP,			//日冻结，正向有功电能
	FREEZE_DAY_POS_EQ,			//日冻结，正向无功电能
	FREEZE_DAY_I_EQ,			//日冻结，一象限无功电能
	FREEZE_DAY_IV_EQ,   		//日冻结，四象限无功电能

	FREEZE_DAY_INV_EP,			//日冻结，反向有功电能
	FREEZE_DAY_INV_EQ,			//日冻结，反向无功电能
	FREEZE_DAY_II_EQ,			//日冻结，二象限无功电能
	FREEZE_DAY_III_EQ, 			//日冻结，三象限无功电能

	FREEZE_DIR_POS_EP,			//潮流变化冻结，正向有功电能
	FREEZE_DIR_POS_EQ,			//潮流变化冻结，正向无功电能
	FREEZE_DIR_I_EQ,			//潮流变化冻结，一象限无功电能
	FREEZE_DIR_IV_EQ,   		//潮流变化冻结，四象限无功电能

	FREEZE_DIR_INV_EP,			//潮流变化冻结，反向有功电能
	FREEZE_DIR_INV_EQ,			//潮流变化冻结，反向无功电能
	FREEZE_DIR_II_EQ,			//潮流变化冻结，二象限无功电能
	FREEZE_DIR_III_EQ, 			//潮流变化冻结，三象限无功电能
	
	FREEZE_NUM,
};



typedef struct  XS_CAN_ST
{
	int ti;
	int len;
	int data_type;
	char *name;
	void *p_set;
}XS_CAN_ST;

typedef struct  
{
	int ti;
	u8 value;
}METER_YX_ST,METER_YK_ST;

typedef struct  
{
	int ti;
	float value;
}METER_YC_ST,METER_DD_ST;



typedef struct  XS_CAN_SET_ST
{
	int ti;
	int len;
	int data_type;
	char *name;
	void *p_set;
}XS_CAN_SET_ST;


typedef struct  
{
	u8	  byAddr;       //线路地址
	WORD  byMaddr;
	WORD  wZDJG;  		// 整点间隔
	float dRevLimtPW;	//功率反向事件有功功率触发下限
	DWORD dTRevLimtPW;	//功率反向事件判定延时间
	float dRevLimtTD;	//潮流方向改变事件有功功率触发下限
	DWORD dTRevLimtTD;	//潮流方向改变事件判定延时
	
	u8    frz_day;		//考核日冻结日
	u8    frz_hour;		//考核日冻结小时
}METER_RUN_PARA;

typedef struct METER_DATA
{
	u8 xs_yx[ID_YX_NUM];
	float xs_yc[ID_YC_NUM];
	float xs_dd[ID_DD_NUM];
	u32 xs_yk[ID_YK_NUM];
}METER_DATA;

/****************************冻结电能量记录文件****************************/
typedef struct 
{
	u16 cp;
	float elem_val;				//信息元素值(浮点)
}METER_ELEM;

/*
struct frz_rcd_t
{
	struct  rtc_time_t 	time_bk;	//定点时刻
	u8 info_num;
	struct frz_rcd_data data[ID_DD_NUM];
};
*/

extern struct frz_rcd_t 	rcd_fixd;
extern struct frz_rcd_t 	rcd_rand;
extern struct frz_rcd_t 	rcd_frzd;
extern struct frz_rcd_t 	rcd_sharpd;
extern struct frz_rcd_t 	rcd_monthd;

extern METER_DD_ST meter_dd[];
extern METER_YC_ST meter_yc[];




extern RUN_PARA tRunPara;
extern METER_DATA tMeterData;
extern u8 calib_step;
extern void soft_dd_val_clr(void);

void metering_freeze_copy(int owner,int index);
void metering_freeze_refresh(u8 data_type,struct rtc_time_t *p_time);
void metering_yc_refresh(void);
u8 metering_dir_change(u8 id);

#ifdef CAN_DISABLE
	u8 metering_calib(char* buf);
#else
	u8 can_metering_calib(char* buf);
#endif

void can_clear_send_timer(void);

int can_metering_send(u8 cmd, u8 *src, u8 data_len);
extern int can_metering_recv_app(u8 *buf);
void can_metering_send_app(void);
void can_metering_calib_step1(u8 no, u8 slot);
void can_metering_calib_step2(u8 no, u8 slot);
int can_app_energy_clear(u8 no, u8 slot);
void can_app_busy(void);



#endif


