| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #ifndef __HL8810_HANELD_H
- #define __HL8810_HANELD_H
- #include "termios.h"
- #include "ctype.h"
- //8112/8110 reg define
- #define REG_SYSCON_ADDR 0x00
- #define REG_EMUCON_ADDR 0x01
- #define REG_HFCONST_ADDR 0x02
- #define REG_EMUCON2_ADDR 0x13
- #define REG_ANGLE_ADDR 0x22
- #define REG_UFREQ_ADDR 0x23
- #define REG_RMSIA_ADDR 0x24
- #define REG_RMSIB_ADDR 0x25
- #define REG_RMSU_ADDR 0x26
- #define REG_PF_ADDR 0x27
- #define REG_ENERGY_PA_ADDR 0x28
- #define REG_ENERGY_PB_ADDR 0x29
- #define REG_POWER_PA_ADDR 0x2C
- #define REG_POWER_PB_ADDR 0x2D
- #define REG_OVLVL_ADDR 0x19
- #define REG_INT_ADDR 0x1D
- #define REG_IE_ADDR 0x40
- #define REG_IF_ADDR 0x41
- #define REG_RIF_ADDR 0x42
- #define REG_RDATA_ADDR 0x44
- #define REG_CHECKSUM_ADDR 0x6f
- #define REG_RMS_IAC_ADDR 0x70
- #define REG_RMS_IBC_ADDR 0x71
- #define REG_RMS_UC_ADDR 0x72
- #define REG_POWER_PAC_ADDR 0x73
- #define REG_POWER_PBC_ADDR 0x74
- #define REG_POWER_SC_ADDR 0x75
- #define REG_ENERGY_AC_ADDR 0x76
- #define REG_ENERGY_BC_ADDR 0x77
- #define CHANEL_A 0
- #define CHANEL_B 1
- #define D_TIME_50MS 50000
- #define D_TIME_10MS 10000
- #define D_TIME_20MS 20000
- #define D_TIME_100MS 100000
- #define D_CAL_U 1000/1000
- #define D_CAL_A_I 1000/1000
- #define D_CAL_A_P 1000/1000
- #define D_CAL_A_E 1000/1000
- #define D_CAL_B_P 1000/1000
- #define D_CAL_B_I 1000/1000
- #define D_CAL_B_E 1000/1000
- //GPIO
- #define GPIO_DIR_PATH "/sys/class/gpio/"
- #define GPIO_EXPORT_PATH GPIO_DIR_PATH "export"
- #define GPIO_UNEXPORT_PATH GPIO_DIR_PATH "unexport"
- #define GPIO_VALUE_PATH GPIO_DIR_PATH "gpio%d/value"
- #define GPIO_DIRECTION_PATH GPIO_DIR_PATH "gpio%d/direction"
- #define GPIO_PE3 131
- #define GPIO_PD11 107
- //#define DEBUG
- #ifdef DEBUG
- #define _DEBUG(dircetion,buff,size) \
- do{\
- printf("%-40s:%4d -- <%4s>",__func__,__LINE__,(dircetion ? "GET":"SET"));\
- for(int i = 0; i < size; i++)\
- {\
- if((unsigned int)(buff[i]) > 15)\
- printf("%X ",(unsigned int)(buff[i]));\
- else\
- printf("0%X ",(unsigned int)(buff[i]));\
- }\
- printf("\n");\
- }while(0);
- #else
- #define _DEBUG(dircetion,buff,size)
- #endif
- #define SET 0
- #define GET 1
- typedef unsigned char uint8_t;
- typedef unsigned short uint16_t;
- typedef unsigned int uint32_t;
- typedef struct LowConf_8110 LowConf;
- typedef struct LowConf_8110{
- //日志等级
- int log_level;
- //串口文件描述符
- int h_hlw8110_fd;
- uint8_t opreation;
- //串口基本配置
- struct termios bak_opt;
- struct termios new_opt;
- // hlw8110 参数
- uint16_t U16_RMSIAC_RegData; //A通道电流转换系数
- uint16_t U16_RMSIBC_RegData; //B通道电流转换系数
- uint16_t U16_RMSUC_RegData; //电压通道转换系数
- uint16_t U16_PowerPAC_RegData; //A通道功率转化系数
- uint16_t U16_PowerPBC_RegData; //B通道功率转化系数
- uint16_t U16_PowerSC_RegData; //视在功率转化系数,if A通道,则是A通道视在转换系数,AB二选其一
- uint16_t U16_EnergyAC_RegData; //A通道有功电能转换系数
- uint16_t U16_EnergyBC_RegData; //B通道有功电能转换系数
- uint16_t U16_CheckSUM_RegData; //转换系数checksum
- uint16_t U16_CheckSUM_Data; //转换系数计算出的Checksum
- uint16_t U16_HFConst_RegData;
- uint16_t U16_Check_SysconReg_Data;
- uint16_t U16_Check_EmuconReg_Data;
- uint16_t U16_Check_Emucon2Reg_Data;
- uint32_t U32_RMSU_RegData; //电压有效值寄存器
-
- uint32_t U32_RMSIA_RegData; //A通道电流有效值寄存器
- uint32_t U32_POWERPA_RegData; //A通道功率有效值寄存器
- uint32_t U32_ENERGY_PA_RegData; //A通道有功电能有效值寄存器
- uint32_t U32_RMSIB_RegData; //B通道电流有效值寄存器
- uint32_t U32_POWERPB_RegData; //B通道功率有效值寄存器
- uint32_t U32_ENERGY_PB_RegData; //B通道有功电能有效值寄存器
- float F_AC_BACKUP_E; //A通道电量备份
- float F_BC_BACKUP_E; //B通道电量备份
- uint8_t current_channel;
- uint8_t serial_tx_buf[10]; //串口数据发送
- uint8_t serial_rx_buf[10];
- int tx_lenth;
- int rx_lenth;
- //pthread_mutex_t mutex_lwx8110;
- float F_AC_V;
- float F_AC_I;
- float F_AC_P;
- float F_AC_E;
- float F_AC_PF;
- float F_Angle;
- float F_AC_I_B;
- float F_AC_P_B;
- float F_AC_E_B;
- float F_AC_BACKUP_E_B;
- float F_AC_LINE_Freq;
- int F_AC_status;
-
- }LowConf;
- float hlw8110_read_Angle(LowConf *conf);
- float hwl8110_read_PF(LowConf *conf);
- float hwl8110_read_LineFreq(LowConf *conf);
- float hwl8110_read_EA(LowConf *conf);
- float hwl8110_read_PA(LowConf *conf);
- float hlw8110_read_IA(LowConf *conf);
- float hlw8110_read_UV(LowConf *conf);
- int hlw8110_read_Status(LowConf* conf,int* nStatus);
- LowConf * hlw8110_init(void);
- void hlw8110_deinit(LowConf *conf);
- LowConf* hlw8110_Reset(LowConf *conf);
- #endif
|