#ifndef _BLV_485_DEV_ENERGYMONITOR_H_
#define _BLV_485_DEV_ENERGYMONITOR_H_

#include "stdint.h"
#include "BLV_485_Protocol.h"
#include "BLV_All_Dev_Init.h"

#define BLV_Energy_Bus_Type					0xF4

#define BLV_Energy_RecvData_LenMax			45
#define BLV_Energy_RecvData_LenMin			8

#define BLV_Energy_DataHeard				0x8A
#define BLV_Energy_DataEnd					0xA8

#define BLV_Energy_PeriodicReport_CMD		0x01		//定期上报命令
#define BLV_Energy_Inquire_CMD				0x02		//查询命令				
#define BLV_Energy_SetInfo_CMD				0x03		//设置参数信息
#define BLV_Energy_ReadVer_CMD				0x04		//设置参数信息
#define BLV_Energy_ClearStat_CMD			0x13		//清除定期能耗统计

#define BLV_Energy_Send_Flag_Max			4
#define BLV_Energy_SetInfo_Flag				0x0001
#define BLV_Energy_ClearStat_Flag			0x0002
#define BLV_Energy_ReadVer_Flag				0x0004
#define BLV_Energy_Inquire_Flag				0x0008



typedef struct
{
	BLV_COMM_RECORD_G comm_record;	//通讯记录
	
	uint8_t 	DevSendCnt;     	//设备发送计数   计数达到重发次数都没有回复，判为离线
	uint8_t 	DevOffline;       	//设备离线标志 1，设备离线   0，设备在线
	uint8_t 	DevOfflineLast;    	//设备离线标志 1，设备离线   0，设备在线
	
	uint8_t 	DevSendSN;			//设备通讯 SN
	uint8_t 	periodic_enable;	//定期上报使能状态
			
	uint16_t 	voltage;			//电压,通道A，B相同			
	uint16_t 	current;			//电流,通道A
	uint32_t 	active_power;		//有功功率,通道A	
	uint32_t	phase_energy;		//阶段能耗,通道A
	uint32_t	total_energy;		//总能耗,通道A

    uint16_t 	voltage_B;			//电压,通道A，B相同		
	uint16_t 	current_B;			//电流,通道B		
	uint32_t 	active_power_B;		//有功功率,通道B
	uint32_t	phase_energy_B;		//阶段能耗,通道B
	uint32_t	total_energy_B;		//总能耗,通道B
    
	uint32_t 	send_flag;			//发生标志位
	uint32_t 	periodic_time;		//定期上报时间间隔，单位：mS
	
	uint32_t 	inquire_tick;		//询问时间戳

}__attribute__ ((__packed__))RS485_ENERGYMONITOR_INFO;						//485开关的数据与函数

void BLV_RS485_EnrgyMonitor_Data_For_Logic_Init(LOGICFILE_DEVICE_INFO *dev_info,uint8_t *data,uint16_t data_len);
uint8_t BLV_RS485_Energy_Cycle_Dis(uint32_t dev_addr);
uint8_t BLV_RS485_Energy_Data_Processing(uint32_t dev_addr,uint32_t data_addr,uint16_t len);
void Dev_Energy_Output_Ctrl(uint32_t CfgDevAddIn, uint16_t DevInputAddr, uint32_t DevAddr, uint16_t DevOutputLoop, uint16_t DevOutputType);

#endif
