#ifndef __COMMON_H_ #define __COMMON_H_ #include #include #include #include #include #include "sqlite3.h" #include "pthread.h" #include "list.h" #include "modbus_handle.h" #include "elog.h" #include "mongoose.h" #include "ntpclient.h" #include #include #include #include "pduMIB_form.h" #include "pduMIB_scalar.h" #include "pduMIB_trap.h" #include "language_hashmap.h" #include "hlw8110_habdle.h" #include "language_common.h" #include #include #include "cfg.h" #include #define MAX_RELAY_CHN 100 //是否在OS环境下运行 #define OS_HANDWARE 1 #define WEB_ROOT "../web" #define PARAS_FILE "pduParas" #define DATABASE_NAME "pdu_dat.db" #define DATABASE_BAK_NAME "pdu_dat_bak.db" #define SNMP_MIB_NAME "pduMIB" #define INI_FILE_NAME "smartPDU.ini" #define INI_FILE_BAK_NAME "smartPDU_bak.ini" #define PH_INI_FILE_NAME "smartPDU_PhList.ini" #define PH_3_1_INI_FILE_NAME "smartPDU_3_1_PhList.ini" #define CHANGES_NAME "changes.txt" #define SERV_CFG_NAME "service.ini" #define SENSOR_CFG_NAME "sensor.ini" #define ALARM_CFG_NAME "alarm.ini" #define INFO_FILE_PATH "/usr/share/PDUInfo.txt" #if (CHIP_TYPE == CHIP_T113s) #define TOTAL_COUNT (60) #else #define TOTAL_COUNT (1440) #endif #if (CHIP_TYPE == CHIP_T113s) //控制板通信串口 #define INTERL_MODBUS_PORT "/dev/ttyS4" #define INTERL_MODBUS_BAUD 115200 //表头级联通讯串口 #define CASCADE_MODBUS_PORT "/dev/ttyS5" #define CASCADE_MODBUS_BAUD 115200 //传感器通信串口 #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyS1" #define INTERL_SENSOR_MODBUS_BAUD 9600 #else //高配表头串口定义----------------------------------------------- //控制板通信串口 #define INTERL_MODBUS_PORT "/dev/ttyAS5" #ifdef SURRPORT_20KHZ_PWM #define INTERL_MODBUS_BAUD 38400 #else #define INTERL_MODBUS_BAUD 115200 #endif //表头级联通讯串口 #define CASCADE_MODBUS_PORT "/dev/ttyAS4" #ifdef NORTH_USER_SPECILS #define CASCADE_MODBUS_BAUD 9600 #else #define CASCADE_MODBUS_BAUD 115200 #endif //传感器通信串口 #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyAS2" #define INTERL_SENSOR_MODBUS_BAUD 9600 #endif #define IMAGE_FOLDER "image" #define LOGO_FILE "logo.png" #define QRCODE_FILE "qrcode.png" #define CERT_FILE "ca.cert" #define SHM_NAME_5_inch_screen "/smartPDU_shm_5_inch_screen" #define USE_SHM_5_inch_screen #define AC_SINGLE_S_CUR_CHN_NUM 8 #define AC_SINGLE_B_CUR_CHN_NUM 4 #define AC_SINGLE_S_MAX_CHN_NUM 10 //单个控制板最大数量 #define AC_SINGLE_S_MAX_ADDRESS_NUM 16 //控制板最大数量 #define AC_MAX_VOLTAGE_VAL 500 #define AC_MAX_CURRENT_VAL 100 #define AC_MAX_POWER_VAL 100 #define NOARTH_MAX_SENSOR 4 #define NOARTH_MAX_DRY 4 #define MAIL_RECV_MAX 10 #define MQTT_SER_MAX 5 #define TECNCENT_CLOUD_PHONE_MAX 20 enum{ BREAKER_DIO = 0, BREAKER_RS485 }; enum { TOTAL_VOLTAGE_TYPE = 0,//统计电压类型 TOTAL_CURRENT_TYPE = 1,//统计电流类型 TOTAL_POWER_TYPE = 2,//统计功率类型 TOTAL_POWER_CONS_TYPE = 3 //统计耗电量类型 }; enum { POWER_MERITORIOUS_TYPE = 0,//有功功率类型 POWER_REACTIVE_TYPE = 1,//无功功率类型 POWER_APPARENT_TYPE = 2 //视在功率类型 }; enum { SENSOR_TYPE_TEMP_HUMI = 0 , //温湿度传感器 SENSOR_TYPE_SMOKE = 1 , //烟雾传感器 SENSOR_TYPE_WATER = 2 , //水浸传感器 SENSOR_TYPE_ACCESS = 3 , //门禁传感器 SENSOR_TYPE_GAS = 4 , //气体传感器 SENSOR_TYPE_AIR_PRESS = 5 , //气压传感器 SENSOR_TYPE_AIR_COND = 6, //空条传感器 SENSOR_TYPE_LEAK = 7, //泄漏传感器 SENSOR_TYPE_TEMP = 8, //温度传感器 SENSOR_TYPE_TEMP_DOUBLE = 9, //双温度传感器 SENSOR_TYPE_PRESS = 10, //压力传感器 SENSOR_TYPE_TEMP_PRESS = 11, //压传感器 SENSOR_TYPE_MAX, }; enum { SENSOR_TYPE_TEMP_HUMI_RSWSN01PVC=0, SENSOR_TYPE_TEMP_HUMI_HKSHT301T1H536VRS485, SENSOR_TYPE_TEMP_HUMI_MAX }; enum { SENSOR_TYPE_TEMP_DOUBLE_DL10BM485V24D2=0, SENSOR_TYPE_TEMP_DOUBLE_MAX }; enum { SENSOR_TYPE_TEMP_BTG50H8EL3200=0, SENSOR_TYPE_TEMP_MAX }; enum { SENSOR_TYPE_LEAK_XWDC01A=0, SENSOR_TYPE_LEAK_MAX }; enum { SENSOR_VAL1_UPPER = 0, SENSOR_VAL1_LOWER, SENSOR_VAL2_UPPER, SENSOR_VAL2_LOWER, }; enum { SENSOR_TYPE_VALUE = 0 , //传感器类型0、4、5 SENSOR_TYPE_LIST //传感器类型1、2、3 }; static char* g_product_type_str[] = { "SmartPDU(AC)", "SmartPDU(DC)", "SmartPDU", "SmartPDU(AC_3P-IN & 3P-OUT)", "SmartPDU(AC_3P-IN & 1P-OUT)", "SmartPDU(AC_3P-IN & 1P-OUT)", "SmartPDU(AC_3P-IN & 2P-OUT)", }; /// @brief 板子类型 enum MODBUS_BOARD_TYPE { AC_SINGLE_S_TYPE=1, AC_SINGLE_B_TYPE, AC_MULTI_S_TYPE, AC_MULTI_B_TYPE, DC_OUT_TYPE, DC_IN_TYPE, DCPDU_TYPE, TREE_AC_TYPE, // 三相进三相出,单板最大3通道9相 DOUBLE_AC_TYPE, // 两相进两相出,单板最大4通道8相 }; enum AppProductType { SmartPDU_AC=0, SmartPDU_DC=1, SmartPDU_Tree_AC_Tree=3, SmartPDU_Tree_AC_One=4, SmartPDU_Tree_AC_One_B=5, SmartPDU_Tree_AC_Two=6, }; /// @brief 三相网页数据 static char* g_product_t_ac_type_str[3] = { "L1", "L2", "L3", }; /// @brief 按位标记 enum BIT_CTRL { BIT_00 = 1 , BIT_01 = 2 , BIT_02 = 4 , BIT_03 = 8 , BIT_04 = 16, BIT_05 = 32, BIT_06 = 64, BIT_07 = 128, BIT_08 = 256, BIT_09 = 512, BIT_10 = 1024, BIT_11 = 2048, BIT_12 = 4096, BIT_13 = 8192, BIT_14 = 16384, BIT_15 = 32768, }; /// @brief 使能位 enum ENABLE_BIT_CTRL { ENABLE_V_UP = 2 , ENABLE_V_DOWN = 8 , ENABLE_A_UP = 32, ENABLE_W_UP = 128, ENABLE_P_UP = 512, ENABLE_ALL_UP = BIT_11, ENABLE_ALL_DOWN = BIT_12, }; /// @brief 使能位三项 enum ENABLE_TreeAC_CTRL { ENABLE_TAC_V_UP = BIT_01, ENABLE_TAC_V_DOWN = BIT_02, ENABLE_TAC_A_UP = BIT_03, ENABLE_TAC_W_UP = BIT_04, ENABLE_TAC_P_UP = BIT_05, ENABLE_TAC_STIME = BIT_06, ENABLE_TAC_ETIME = BIT_07, }; /// @brief 报警位 enum WARNING_BIT_CTRL { WARNING_V_UP = 4 , WARNING_V_DOWN = 16 , WARNING_A_UP = 64, WARNING_W_UP = 256, WARNING_P_UP = 1024, }; enum { ALARM_TYPE_POWER=0, ALARM_TYPE_SENSOR, ALARM_TYPE_NETWORK, ALARM_TYPE_OPRATION, ALARM_TYPE_RUNNING, }; enum { NETWORK_MAC_CHANGED=0, NETWORK_IP_CHANGED, }; /// @brief 报警动作 enum ALARM_CTRL { ALARM_CTRL_CLOSE_CH = 1 , ALARM_CTRL_ALARM_ONLY = 2 , ALARM_CTRL_CLOSE_ALLCH = 3 , }; enum CTRL_PERMISSION{ PERMISSION_SUPER_ADMIN = 1, PERMISSION_ADMIN , PERMISSION_USER , }; enum { MODBUS_MASTER=0, MODBUS_SLAVE, }; enum { LANG_ID_CHINESE=0, LANG_ID_ENGLISH, LANG_ID_RUSSIAN, LANG_ID_SPANISH, LANG_ID_PORTYGYESE, LANG_ID_GERMAN, LANG_ID_FRENCH, LANG_ID_ITALIAN, LANG_ID_JAPANESE, LANG_ID_MAX }; /////////////////////////////////////////////////////////////////////////////////// typedef struct { int id; int up; char ip[48]; char mac[24]; char desc[64]; }port_info_t; typedef struct { #define SW_PORT_MAX 28 port_info_t port[SW_PORT_MAX]; }netswitch_info_t; /////////////////////////////////////////////////////////////////////////////////// //modbus信息管理 typedef struct { bool mode ; //0: master 1slave unsigned char addr; unsigned int baudrate ; //波特率 char path[32] ; //device path }ModbusInfo_t; typedef struct { int mode; //0:dhcp 1:static char ip_address[64] ; //ip地址 char ip_v6_address[64]; char mask_v6[64]; char mask[64]; //子网掩码 char gateway[64]; //网关 char dns1[64]; //dns1 char dns2[64]; //dns2 }NetworkInfo_t; /// @brief 用户登录 typedef struct { char user_name[64]; char user_password[64]; char user_uuid[64]; char user_token[64]; struct list_head list; }_User_Log; typedef struct { uint32_t id; //产品ID char pname[32]; //产品名称 char pnumber[32]; //产品编号 char status[32]; //产品状态 char name[32]; //设备名称 char number[32]; //设备编号 char date[32]; //设备生产日期 char batch[32]; //设备生产批次 uint8_t type; //产品类型 uint8_t pwr_type; //电源类型 char version[8]; //软件版本 uint8_t language; //多国语言 uint8_t count; //级联设备数 uint32_t samp_time; //采集周期 单位ms uint32_t save_time; //采集周期 单位ms uint16_t ph_group; //三组相数 uint16_t ch_delay; //通道延时 }ProductInfo_t; typedef struct { int monway; //1:总检测 2:分监分控 3:分监不控 int netsw; int nwire; int ipv4; int ipv6; int brdupg; }WebcfgInfo_t; typedef struct { int watchdog; int flip_time; int led; int beep; uint32_t interval; //led beep 时间间隔 uint32_t duption; //led beep 持续时间 int rotate; int radius; }MiscInfo_t; typedef struct{ int ldap; char ldip_server[64]; }ldap_t; // 4G网络及GPS信息 typedef struct { int id; int use; char account[64]; }sms_recv_t; typedef struct { uint8_t broad_enable; uint16_t broadcast_port; uint16_t mulcast_port; char boardcast_ip[64]; char mulcast_ip [64]; // char cmd[128]; }mulcast_t; typedef struct { bool Cellular_enable; // 4G模块启用状态 int mode; // 4G模块默认模式 bool Link_status; // 4G网络连接状态 int Signal_strength; // 信号强度 char Cellular_name[32];// 4G网络运营商名称 char apn[32];// APN接入点名称 char username[32]; char password[32]; char Cellular_Num[32]; // 电话号码 char ipv4[16]; char ipv6[64]; bool GPS_status; // GPS功能启用 char GPS_utc[64];// UTC时间 float GPS_latitude;// 纬度,范围-89.99999~89.99999 float GPS_longitude;// 精度,范围-179.99999~179.99999 float GPS_altitude;// 海拔高度,单位m float GPS_speed;//地面速率,单位km/h int GPS_nsat;//卫星数量 bool SMS_status; // 短信功能启用 sms_recv_t sms_recv[MAIL_RECV_MAX];// 短信接收信息 } CellInfo_t; // WIFI信息 typedef struct { bool WIFI_enable; // WIFI模块启用状态 int mode; // WIFI模块启用状态 bool Link_status; // wifi网络连接状态 char WIFI_ip[64]; // wifi ip address char WIFI_name[64];// WIFI网络SSID名称 char WIFI_code[64];// WIFI密码 } WIFIInfo_t; typedef struct { char name[256]; char site[256]; char mail[256]; char addr[256]; char tele[32]; }ServiceInfo_t; typedef struct { int voltage; int current; int power; int brdMax; }PowerTotal_t; typedef struct { ModbusInfo_t relay; //继电器控制端口 NetworkInfo_t network; //网络信息 ModbusInfo_t cascade; //级联端口 ProductInfo_t product; //产品信息 PowerTotal_t ptotal; WebcfgInfo_t webcfg; ServiceInfo_t service; //服务信息 MiscInfo_t misc; CellInfo_t cell; WIFIInfo_t wifi; mulcast_t broadcast; //udp 广播 ldap_t ldap; //ldap server and enable config }GlobalDeviceInfo; /////////////////////////////////////////////////////////////////////////////////// //自定义共享内存类 enum{ SMS_PDU_NETWORK, SMS_PDU_AIR_PRESSURE, SMS_PDU_AIR_FLOW, SMS_PDU_ACCESS, SMS_PDU_WATER, SMS_PDU_SMOKE, SMS_PDU_HUMI, SMS_PDU_TEMP, SMS_PDU_3_LEAK, SMS_PDU_CONSUMER, SMS_PDU_POWER, SMS_PDU_CURRENT, SMS_PDU_VOLTAGE_UP, SMS_PDU_VOLTAGE_LOW, }; typedef struct { char wanning[64]; }sms_network_t; typedef struct{ char name[64]; float over; float current; float limit; }sms_air_t; typedef struct{ char name[64]; }sms_dry_t; typedef struct{ char name[64]; }sms_leak_t; typedef struct{ char name[64]; float over; float current; float limit; }sms_humi_temp_t; typedef struct { char name[64]; float ele_val1; float ele_val2; }sms_ele_t; typedef union { sms_network_t network; sms_air_t air; sms_dry_t dry; sms_humi_temp_t humi_temp; sms_ele_t elec; sms_leak_t leak; }sms_info_t; typedef struct { char pdu_name[64]; uint8_t sms_type; sms_info_t info; }cloud_sms_info_t; typedef struct { uint8_t status[10]; //char cloudMSG[10][64]; cloud_sms_info_t cloud_msg[10]; }cloud_mesage_t; typedef struct{ uint8_t status; uint8_t phone_cnt; char secret_id[64]; char secret_key[64]; char url[64]; char app_id[64]; char signature[64]; char template[64]; char country[64]; char region[64]; char phone[20][64]; cloud_mesage_t c_msg; }tencentcloud_sms_t; typedef struct { //电源数据 int bPDUSet; int nSelectPowerCH; int nMaxCh; float fV; float fA; float fW; float fF; float fS; int nStatus; //传感器数据 int nSelectSensor; float fT;//温度 float fH;//湿度 float fCO2;//co2 char strVer[20];//版本号 //三项数据 int bT_ACType;//三相类型 int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计 //报警列表 0表示空,1表示写入,2表示已确认可清空。 int nTypeCtrlType[10]; char strMSG[10][64]; #if (1) tencentcloud_sms_t cloud_sms; #endif } smartPDU_shm_data; //消息队列头结构体定义 enum MsgCtrlType { Msg_Ch_Ctrl=1, //通道控制 Msg_All_Ctrl=2, //整体控制 Msg_Threshold_Set=3, //阈值设置 Msg_Threshold_Update=4, //阈值更新 }; typedef struct { long MsgType; //消息方向1:Qt->PDU 2:pdu->Qt int CtrlType; //控制类型 int nValue[2]; // double fValue[10]; }MsgData; // 消息队列线程参数结构 typedef struct { int msgid; // 消息队列ID int running; // 线程运行标志 bool needInit; pthread_mutex_t lock; } Msg_thread_args; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //超限管理表 typedef struct { int product_vol_upper_enable ;//电压上限使能 float product_vol_upper_threshold ;//电压上限值 int product_vol_over_upper_threshold_ctrl ;//电压超限动作 int product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数 int product_vol_lower_enable ;//电压下限使能 float product_vol_lower_threshold ;//电压下限值 int product_vol_over_lower_threshold_ctrl ;//电压超限动作 int product_vol_over_lower_threshold_ctrl_para ;//电压超限动作 int product_cur_upper_enable ;//电流下限使能 float product_cur_upper_threshold ;//电流下限值 float product_cur_lower_threshold; // int product_cur_over_upper_threshold_ctrl ;//电流超限动作 int product_cur_over_upper_threshold_ctrl_para ;//电流超限动作 int product_pwr_upper_enable ;//功率上限使能 float product_pwr_upper_threshold ;//功率上限值 int product_pwr_over_upper_threshold_ctrl ;//功率超限动作 int product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作 int product_pwrcon_upper_enable ;//耗电量上限使能 float product_pwrcon_upper_threshold ;//耗电量上限值 int product_pwrcon_over_upper_threshold_ctrl ;//耗电量超限动作 int product_pwrcon_over_upper_threshold_ctrl_para ;//耗电量超限动作 }GlobalOverManager; /// @brief 定时管理 typedef struct { char set_date[16]; //设置日期 char ds_date[16]; //设置时间 char ds_time[16]; //设置时间 int set_stats; //状态 int ds_is_triggered; //是否已触发 struct list_head list; }_PowerDSManage_t; enum { SCHE_TYPE_YEAR = 0, SCHE_TYPE_MONTH, SCHE_TYPE_DAY, SCHE_TYPE_WEEK, SCHE_TYPE_TIMEPERIOD, SCHE_TYPE_MAX, }; typedef struct { int type; int product_ch_id; int rule_id; int year; int month; int day; char time[32]; int status; int is_triger; }_powerScheRunInfo_t; typedef struct { int flag; int shce_type[5]; }day_t; typedef struct { int manager_id; int channel_id; int sche_type; int day; char time[32]; int status; int is_triger; struct list_head list; }day_info_t; typedef struct { int year; int month; int curent_day; int all_count; int triger; int not_triger; day_t day[32]; struct list_head list; //day_info_t }_PowerMonthShce_t; typedef struct { uint8_t id; // uint8_t channel_id; //channel id uint8_t sche_type; //sche type time_t start_time; time_t next_time; //target time time_t end_time; uint8_t set_status; //status struct tm timestart; struct tm timenext; struct tm timeend; sqlite3 *db; void (*set_next_time)(void *,int flag); struct list_head list; }_PowerShceManage_t; typedef struct { int firingSortno; //启动序号 int closeSortno; //关闭序号 }_PowerSXManage_t; typedef struct { int product_id; int mode; char ntpName[64]; char ntpaddress[64]; int port; char time[64]; int weekday; int tzone; }NTPManager; enum { SNMP_AUTH_NONE=0, SNMP_AUTH_MD5, SNMP_AUTH_SHA, SNMP_AUTH_MAX }; enum { SNMP_ENCYPT_NONE=0, SNMP_ENCYPT_DES, SNMP_ENCYPT_AES, SNMP_ENCYPT_MAX }; typedef struct { char alg[12]; char passwd[64]; }crypt_data_t; typedef struct { char user[32]; crypt_data_t auth; crypt_data_t priv; }crypt_t; typedef struct { int product_id; int mode; int version; char public[64]; int trapmode; crypt_t crypt; char nmsIP[64]; }SNMPManager; //分组管理 typedef struct { int product_id; int GroupID; char GroupName[64]; char GroupChList[512]; struct list_head list; }GroupInfo; //电源部分 typedef struct { float voltage ;//电压 float current ;//电流 float power ;//有功功率 float n_power ;//无功功率 float app_power ;//视在功率 float freq ;//频率 float consumption ;//耗电量 float factor ;//功率因素 unsigned short status ;//开关状态 unsigned short NF_status ;//零线状态 int OperAllowFlag; //操作允许标志 port_info_t port; // }PowerInfo; //电源部分报警信息 typedef struct { bool w_voltage_up ;//电压上限报警 bool w_voltage_down ;//电压下限报警 bool w_current ;//电流上限报警 bool w_power ;//功率 bool w_consumption ;//耗电量 bool w_phase_lossA; // 缺相报警 bool w_phase_lossB; // 缺相报警 bool w_phase_lossC; // 缺相报警 }PowerWarningInfo; typedef struct { int nBoardID; int nLeftTac; int nRightTac; /* data */ }TAC_Double_Item; //三项数据 typedef struct { int product_id; int product_ch_id; int product_ph_id; int product_ph_type;//0:A相 1:B相 2:C相 int product_saddr; int product_ch_addr; int product_ph_outputType;//三相控制方式1,三项2单项 int product_ph_outputStatus;//该相是否输出,1输出2不输出 char samp_time[64]; //采集时间 PowerInfo _PowerInfo; //存储最新的数据(兼容三项输入) GlobalOverManager global_over_manager; //超限管理 PowerWarningInfo _PowerWarninginfo; //存储报警数据(兼容三项输入) time_t product_log_time; //存储最新时间 struct list_head list_Tree_AC; //存储三项数据指针 }GlobalTreeACManager; //电源通道管理总表(输出) typedef struct { int product_id ;//产品ID //20240225 add int product_saddr ;//modbus地址记录 int product_ch_id ;//通道号 int product_ch_addr ;//通道号实际地址 char product_ch_name[32] ;//通道名称 int product_ch_type ;//通道类型 int product_ch_status ;//通道状态 int product_ch_NF_status ;//通道零线状态(三相) int product_ch_start_delay ;//通道延时 int product_ch_stop_delay ;//通道延时 int product_ch_permission ;// permison char product_ch_load_type[64] ;//load type GlobalOverManager global_over_manager ;//超限管理 struct list_head list_DS; //定时设置 _PowerSXManage_t* _PowerSXManage; //时序管理 PowerInfo _PowerInfo; //存储最新的数据 PowerWarningInfo _PowerWarninginfo ; //存储报警数据 time_t product_log_time; //存储最新时间 struct list_head list_Tree_AC; //存储三项数据指针 struct list_head list; struct list_head list_sche; } GlobalPowerManger; //电源通道管理总表(输入) typedef struct { int product_id ;//产品ID //20240225 add char product_saddr ;//modbus地址记录 char product_saddr_name[32] ;//输入名称 char product_saddr_type ;//输入类型 GlobalOverManager global_over_manager ;//超限管理 PowerInfo _PowerInfo[3]; //存储最新的数据(兼容三项输入) PowerWarningInfo _PowerWarninginfo[3]; //存储报警数据(兼容三项输入) time_t product_log_time; //存储最新时间 int product_MissingPH[3]; //缺相报警 }GlobalPowerInManger; //电源控制板计数 typedef struct { char product_saddr ;//modbus地址记录 int product_number; //数量 int product_type; //类型 PowerInfo _PowerInfo[AC_SINGLE_S_MAX_CHN_NUM]; //存储最新的数据 PowerWarningInfo _PowerWarninginfo[AC_SINGLE_S_MAX_CHN_NUM] ;//存储报警数据 struct list_head list; //存储具有的通道指针 GlobalPowerInManger _globalPowerInManger; //总输入数据 int nLeft_phType; //左半边相类型 int nRight_phType; //右半边相类型 }GlobalPowerCtrlBoard; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //自定义共享内存类 typedef struct { //电源数据 pid_t nIPD; size_t array_size; GlobalPowerCtrlBoard m_pData[]; } smartPDU_shm_5_inch_data; //电源信息统计 typedef struct { float ydata[TOTAL_COUNT]; //value char xAxis[TOTAL_COUNT][32];//时间点 }GetTotalInfo; //系统总数信息 typedef struct { int channel_total ;//通道总数 int warn_total ;//告警总数 int sensor_total ;//传感器总数 int log_total ;//运行日志总数 }SystemTotalInfo; //功率趋势接口 typedef struct { float ydata[3][TOTAL_COUNT] ;//0:有功功率;1:无功功率;2:视在功率; char xAxis[TOTAL_COUNT][32] ;//时间点 }PowerTrendInfo; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //电源监控 typedef struct { int product_id ;//产品ID char product_ch_id ;//电源通道 unsigned short product_status ;//当前状态 PowerInfo _power_info ;//采集值 char samp_time[64] ;//采集时间 GetTotalInfo _total_voltage ;//统计电压 GetTotalInfo _total_current ;//统计电流 GetTotalInfo _total_power ;//统计功率 GetTotalInfo _total_consumption ;//统计耗电量 SystemTotalInfo _system_total_info ;//系统总数信息 PowerTrendInfo _power_trend_info ;//功率趋势图 struct list_head list; }GlobalPowerInfo; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //传感器值 typedef struct { char samp_time[64] ;//采集时间 int product_id ;//产品ID char sensor_id ;//传感器ID float val1 ;//值1 float val2 ;//值2 time_t product_log_time; //存储最新时间 struct list_head list; }GlobalSensorInfo; typedef struct { char samp_time[64]; int product_id; char sensor_id; char sensor_name[64]; float val1; float val2; }download_sensor_Info_t; typedef struct { int sensor_val1_upper_enabled ;// float sensor_val1_upper_threshold; int sensor_val1_upper_threshold_ctrl; char sensor_val1_upper_threshold_ctrl_para[512]; int sensor_val1_lower_enabled ;// float sensor_val1_lower_threshold; int sensor_val1_lower_threshold_ctrl; char sensor_val1_lower_threshold_ctrl_para[512]; int sensor_val2_upper_enabled ;// float sensor_val2_upper_threshold; int sensor_val2_upper_threshold_ctrl; char sensor_val2_upper_threshold_ctrl_para[512]; int sensor_val2_lower_enabled ;// float sensor_val2_lower_threshold; int sensor_val2_lower_threshold_ctrl; char sensor_val2_lower_threshold_ctrl_para[512]; }GlobalSensorOverManage; //传感器报警状态表 typedef struct { int sensor_val1_upper; int sensor_val1_lower; int sensor_val2_upper; int sensor_val2_lower; }GlobalSensorOverInfo; //传感器管理总表 typedef struct { int product_id ;//产品ID int sensor_id ;//传感器ID int sensor_type ;//传感器类型 int sensor_interface_type; //接口类型 char sensor_name[64] ;//传感器名称 char sensor_port_name[32] ;//传感器端口号 int sensor_baud ;//波特率 int sensor_addr ;//modbus地址 int sensor_status ;//传感器状态 int sensor_val_count ;//传感器值个数 int sensor_node_number ;//节点号 int sensor_check_count; //值状态计数 GlobalSensorInfo Cur_sensor_info ; GlobalSensorOverManage over_manager ;//超限管理 GlobalSensorOverInfo warning_status;//报警状态 struct list_head list; }GlobalSensorManger; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// ///温湿度数据信息管理 typedef struct { float temperature; float humidity; }SenorTempVal; //采集KB值 typedef struct { float voltage_k;//电压K float voltage_b;//电压B float current_k;//电流K float current_b;//电流B }SwitchKbVal; /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// //MAIL管理 typedef struct { int id; int use; char account[64]; }mail_recv_t; typedef struct { int id; int mode; //0: open 1: close char account[64]; //用户账号 char password[24]; //用户密码 char server[64]; //服务器 char port[10]; //端口 char auth[16]; //认证方式 char ca[8196]; //ca cert }mail_send_t; typedef struct { mail_send_t send; mail_recv_t recv[MAIL_RECV_MAX]; //接收账号列表 }mail_info_t; typedef struct { uint8_t id; uint8_t status; char secret_id[64]; char secret_key[64]; char url[64]; char app_id[64]; char signature[64]; char template[64]; char country_code[64]; char region[64]; }tencent_cloud_info_t; typedef struct { uint8_t id; char phone[64]; }phone_id_t; typedef struct{ phone_id_t phone[TECNCENT_CLOUD_PHONE_MAX]; }tencent_cloud_phone_t; typedef struct { tencent_cloud_info_t info; tencent_cloud_phone_t phone; }cloud_info_t; enum { MQTT_PLAT_EMQX=0, MQTT_PLAT_ALIYUN, MQTT_PLAT_MAX }; typedef struct { int id; //id int plat; //0: emqx 1: aliyun int mode; //0: open 1: close char proto[16]; //mqtt, mqtts, ws, wss char name[32]; //server name char server[512]; //server ip char port[10]; //server port char cid[64]; //client ID char user[64]; // char password[64]; char cert[8200]; int status; int device_timer; int network_timer; int power_timer; int sensor_timer; int alarm_timer; }mqtt_server_t; typedef struct { mqtt_server_t ser[MQTT_SER_MAX]; }mqtt_info_t; typedef struct { int product_id; int userID; //用户ID char userName[32]; //用户名-登录 char userPW[32]; //用户密码 char nickName[32]; //用户名称 int roleID; //角色ID char createTime[32]; //用户创建时间 struct list_head list; }UserInfo; typedef struct { int product_id; int roleID; //角色ID char roleName[32]; //角色名称 int roleLevel; //角色等级 char roleAuthority[32]; //角色权限 int roleSort; //显示顺序 char createTime[32]; //创建时间 struct list_head list; }RoleInfo; typedef struct MenuAuthority{ bool PowerEnabled; bool SensorEnabled; bool AlarmEnabled; bool LogEnabled; bool UserInfoEnabled; bool CommEnabled; bool ServiceEnabled; bool MaintenanceEnabled; //1、电源监控菜单 bool MonitorallEnabled; bool ChannelstatusEnabled; bool SwitchtatusEnabled; bool MonitorhistoryEnabled; //2、传感器管理菜单 bool SensorStatusEnabled; bool SensorHistorylEnabled; //3、告警管理菜单 bool XtjgEnabled; bool YzszEnabled; //4、日志信息菜单 bool CzrzEnabled; bool YxrzEnabled; //5、用户管理菜单 bool UserEnabled; bool RoleEnabled; bool MenuEnabled; //6、通信管理菜单 bool WkszEnabled; bool RsszEnabled; bool CellularEnabled; bool WifiEnabled; bool BroadcastEnable; //7、服务管理菜单 bool SmtpszEnabled; bool SnmpszEnabled; bool MqszEnabled; bool NtpszEnabled; bool DsszEnabled; bool SxszEnabled; bool FzszEnabled; bool RadiusEnabled; bool LdapEnabled; bool CloudSmsEnable; //8、设备维护菜单 bool SbcqEnabled; bool GjsjEnabled; bool KzbsjEnabled; bool HhccszEnabled; bool PzdrdcEnabled; bool ShfwEnabled; bool GysbEnabled; }MenuAuthority; typedef struct CascadeDevices{ int product_id; //级联设备ID modbus地址 int type; // char device_name[20]; //接连设备名; float valtage; //485 float current; float power; float factor; float freq; float consumption; }CascadeDevices; struct modbus_slave_read_reg{ uint16_t deveice_type; //设备类型 uint16_t slave_addr; //设备地址 uint32_t voltage; //当前电压 uint32_t current; //当前电流 uint32_t power; //当前功率 uint32_t consumption_cur; //耗电量 uint32_t freq; //频率 uint32_t factor; //功率因素 int32_t temprature; //温度值 uint32_t humidity; //湿度值 uint32_t warning; //告警 uint16_t power_supplay_status; //供电状态 uint16_t sencor_status; //传感器状态 int32_t temprature2; //温度值2 uint32_t fCO2; //CO2 // uint32_t Warinfo; // uint16_t sercor_type; }; typedef struct cascade_pw_info{ uint32_t voltage ;//电压 uint32_t current ;//电流 uint32_t power ;//功率 uint32_t freq ;//频率 uint32_t consumption ;//耗电量 uint32_t factor ;//功率因素 }cascade_single_chn_info; //siggle hell typedef struct temp_hum{ uint16_t temperature; uint16_t humidity; }temp_hum_t; typedef uint32_t sensor_t; typedef uint16_t dry_node_t; typedef struct cascade_sensor{ sensor_t s_1; sensor_t s_2; }cascade_sensor_t; #pragma pack (1) typedef struct{ uint16_t waning_voltage_max : 1; uint16_t waning_voltage_min : 1; uint16_t waning_current_max : 1; uint16_t waning_power_max : 1; uint16_t waning_consumer_max : 1; uint16_t : 11; }north_wanning_t; typedef struct{ uint16_t wanning_all_voltage_max : 1; uint16_t wanning_all_voltage_min : 1; uint16_t wanning_all_power_max : 1; uint16_t wanning_all_consumer_max : 1; uint16_t wanning_all_l1_lost : 1; uint16_t wanning_all_l2_lost : 1; uint16_t wanning_all_l3_lost : 1; uint16_t : 9; }north_3_all_wanning_t; typedef struct{ uint16_t wanning_ph_voltage_max : 1; uint16_t wanning_ph_voltage_min : 1; uint16_t wanning_ph_current_max : 1; uint16_t wanning_ph_power_max : 1; uint16_t wanning_ph_consumer_max : 1; uint16_t wanning_ph_lost : 1; uint16_t : 10; }north_3_ph_wanning_t; typedef struct{ uint16_t waning_l1_voltage_max : 1; uint16_t waning_l1_voltage_min : 1; uint16_t waning_l1_current_max : 1; uint16_t waning_l1_power_max : 1; uint16_t waning_l1_consumer_max : 1; uint16_t waning_l2_voltage_max : 1; uint16_t waning_l2_voltage_min : 1; uint16_t waning_l2_current_max : 1; uint16_t waning_l2_power_max : 1; uint16_t waning_l2_consumer_max : 1; uint16_t waning_l3_voltage_max : 1; uint16_t waning_l3_voltage_min : 1; uint16_t waning_l3_current_max : 1; uint16_t waning_l3_power_max : 1; uint16_t waning_l3_consumer_max : 1; uint16_t : 1; }north_3_chn_wanning_t; typedef struct { uint16_t sensor_val1_wanning_max : 1; uint16_t sensor_val1_wanning_min : 1; uint16_t sensor_val2_wanning_max : 1; uint16_t sensor_val2_wanning_min : 1; uint16_t : 12; }sensor_485_wanning; typedef struct cascade_single_mmap{ uint16_t dev_chn; cascade_single_chn_info all_ch[128]; uint32_t total_valtage; uint32_t total_current; uint32_t total_power; uint32_t total_consumer; temp_hum_t total_temp; uint16_t chn_status[64]; uint16_t open_delay[64]; uint16_t close_delay[64]; //uint16_t reservers[29]; cascade_sensor_t cas_sensor[4]; dry_node_t d_node[4]; uint16_t breaker_value; uint16_t reservers[8]; uint16_t set_chn_open_delay[64]; uint16_t set_chn_close_delay[64]; uint16_t set_chn_switch_status[64]; uint16_t set_chn_all_switch_status; north_wanning_t all_ele_wanning; north_wanning_t channel_ele_wanning[64]; sensor_485_wanning sensor_wanning[4]; uint16_t dry_wanning[4]; }cascade_single_mmap_t; #ifdef NORTH_USER_SPECILS typedef struct cascade_north_user{ uint32_t total_elec_energy; uint16_t frequency; uint16_t wire_voltage[3]; uint16_t wire_current[3]; uint16_t total_power; uint16_t status_1_16; uint16_t status_17_32; uint16_t status_33_48; uint16_t status_49_64; uint16_t total_wanning; uint16_t current_wanning; uint16_t fault_1_16; uint16_t fault_17_32; uint16_t fault_33_48; uint16_t fault_49_64; uint16_t set_1_16; uint16_t set_17_32; uint16_t set_33_48; uint16_t set_49_64; }cascade_north_user_t; #endif #pragma pack () #pragma pack (1) #define MAX_CHN 64 typedef struct cascade_triphasic_pw_out{ uint32_t o_voltage; uint32_t o_current; uint32_t o_power; uint32_t o_consumption; uint32_t o_status; }cascade_triphasic_pw_out_t; typedef struct cascade_triphasic_pw_o_chn{ cascade_triphasic_pw_out_t chn[3]; // A B C }cascade_triphasic_pw_o_chn_t; typedef struct cascade_triphasic_pw_in{ uint32_t i_total_voltage; uint32_t i_total_current; uint32_t i_total_power; uint32_t i_total_consumption; }cascade_triphasic_pw_in_t; typedef struct cascade_triphasic_pw_i_total{ cascade_triphasic_pw_in_t pw_i_total[3]; // A B C }cascade_triphasic_pw_i_total_t; typedef struct cascade_triphasic_chn_info{ uint32_t chn_power; uint32_t chn_freq; uint32_t chn_consumption; uint32_t chn_factor; uint32_t chn_type; }cascade_triphasic_chn_info_t; typedef struct cascade_triphasic_mmap{ uint16_t dev_chn; cascade_triphasic_pw_i_total_t i_total; cascade_triphasic_chn_info_t chn_info[MAX_CHN]; cascade_triphasic_pw_o_chn_t pw_o_chn[MAX_CHN]; uint16_t temperature; uint16_t humidity; uint16_t chn_status[MAX_CHN]; uint16_t open_delay[MAX_CHN]; uint16_t close_delay[MAX_CHN]; cascade_sensor_t cas_sensor[4]; dry_node_t d_node[4]; uint16_t breaker_value; uint16_t set_chn_open_delay[MAX_CHN]; uint16_t set_chn_close_delay[MAX_CHN]; uint16_t set_chn_switch_status[MAX_CHN]; uint16_t set_chn_all_switch_status; north_3_all_wanning_t all_wanning; north_3_ph_wanning_t all_ph_wanning[3]; north_3_chn_wanning_t channel_wanning[MAX_CHN]; sensor_485_wanning sensor_wanning[4]; uint16_t dry_wanning[4]; }cascade_triphasic_mmap_t; typedef struct { modbus_t *ctx; char ip[64]; uint16_t port; uint8_t slave_id; uint8_t power_type; modbus_mapping_t *map; int connection; //pthread_mutex_t mutex; }Modbus_Manger_Tcp; #pragma pack () struct modbus_slave_write_reg{ uint16_t voltage_high_enable:1; //电压高阈值检测使能 uint16_t voltage_low_enable:1; //电压低阈值检测使能 uint16_t current_enable:1; //电流阈值使能 uint16_t power_enable:1; //功率阈值使能 uint16_t consumption_cur_enable:1; //功耗阈值使能 uint32_t voltage_upper_threshold; // uint32_t voltage_lower_threshold; uint32_t current_upper_threshold; uint32_t power_upper_threshold; uint32_t consumption_threshold; }; enum { DI, RS485 }; enum{ SWITCH_CONNETCTED, SWITCH_DISCONNETCTED, SWITCH_OFFLINE }; #define SWITCH_CHN_1_SET (1<<0) #define SWITCH_CHN_2_SET (1<<1) #define SWITCH_CHN_3_SET (1<<2) #define SWITCH_CHN_4_SET (1<<3) #define SWITCH_CHN_5_SET (1<<4) #define SWITCH_CHN_6_SET (1<<5) #define SWITCH_CHN_DI_1_SET (1<<6) #define SWITCH_CHN_DI_2_SET (1<<7) typedef struct { int id; int type; char date[32]; char content[128]; }alarm_data_t; typedef struct { int ch; char date[16]; char time[16]; int status; int triggered; }timer_data_t; typedef struct { int addr; char name[32]; char ver[32]; char date[32]; int dev_id; int brd_id; int channels; int status; }board_info_t; typedef struct breaker_switch_sta{ uint16_t status; uint16_t gather; char com[30]; uint8_t product_name[256]; }breaker_switch_sta_t; typedef struct GlobalBreakerManger{ uint32_t all_count; uint32_t online_count; uint32_t mask; uint8_t saddr; void *manager; breaker_switch_sta_t sta[8]; // 6 + 2 pthread_mutex_t b_mutex; }GlobalBreakerManger; typedef struct GlobalBreakerManager{ uint32_t product_id; uint32_t breaker_id; uint32_t breaker_chn; uint32_t breaker_status; uint32_t breaker_gather_addr; char breaker_switch_name[128]; char breaker_com[64]; char breaker_gather_type[64]; char breaker_chns_name[128]; struct list_head list; }GlobalBreakerManager; //设备总体管理 typedef struct { sqlite3* db; //数据库接口 pthread_mutex_t dbThreadlock; //写入线程锁 pthread_t appweb_thread; //appweb线程 pthread_t dev_samp_thread;//电源采集与控制线程 pthread_t dev_update_thread;//电源采集与控制线程 pthread_t io_thread; //IO采集线程 pthread_t sensor_thread; //传感器采集现成 bool dev_samp_flag ; //电源采集线程标志 GlobalDeviceInfo _globalDevInfo; //设备管理信息 GlobalPowerManger _globalPowerManger; //电源管理表 GlobalSensorManger _globalSensorManger; //传感器管理表 Modbus_Manger sensor_modbus_manager; //通信接口管理 unsigned int useSlaveCount ; //有效地址 Modbus_Manger _globalRelaySampManger; //内部继电器使用 unsigned char uart_init_flag[6] ; // bool ws_isok; //ws准备好 struct mg_connection *ws_client; //websocket管理信息 HashTable* alarmTab; //全局的报警映射 int nTreeACLshow; //三项总数据显示L1=0,L2=1,L3=2 pthread_t snmp_agent_thread;//SNMP代理线程 bool _ReloadChm_flag; //重新加载端口数据 int brdMax; GlobalPowerCtrlBoard *pCtrlBoard; //所有控制板 LowConf* _RS485LowConfData;//485Data //传感器 struct modbus_slave_read_reg g_modebus_read; struct modbus_slave_write_reg g_modebus_write; smartPDU_shm_data* g_shm_Data; int g_lastAlarmIndex; //最后一次报警索引位置 pthread_mutex_t _power_ds; //定时器锁 pthread_mutex_t _power_update; //数据刷新锁 pthread_mutex_t _sensor_update; //传感器刷新锁 pthread_mutex_t _breaker_mutex; // breaker info cascade_single_mmap_t *single_mmap; cascade_triphasic_mmap_t *triphasic_mmap; GlobalBreakerManager g_new_global_breaker; mail_info_t mailInfo; mqtt_info_t mqttInfo; Modbus_Manger_Tcp *md_tcp; Msg_thread_args _MSG_args; uint8_t upgread_flag; #ifdef NORTH_USER_SPECILS cascade_north_user_t north_user; #endif cloud_info_t tencent_sms; int g_cloud_sms_lastIndex; //最后一次报警索引位置 _PowerMonthShce_t month_sche; }GlobalDeviceManager; extern GlobalDeviceManager __globalDeviceManage; extern GlobalDeviceManager __globalDeviceManage2; extern int ntp_sync_flag; extern unsigned long __globalSxIdx; extern _User_Log _GlobalUserLoginInfo;//全局用户登录信息 extern UserInfo _GlobalUserInfoNew;////最近登录的信息 extern char _GlobalUserToken[64];////最近登录的信息 extern MenuAuthority _GlobalMenuAuthority;////角色菜单权限 extern NTPManager _globalNTPManager; extern SNMPManager _globalSNMPManager; extern int SMS_SEND_COUNT; extern char DS_QueryDate[32]; extern char alarm_power_start_time[32]; extern char alarm_power_end_time[32]; extern int alarm_power_page_size; extern int alarm_power_page_num; extern int alarm_power_push_type; extern char alarm_sensor_start_time[32]; extern char alarm_sensor_end_time[32]; extern int alarm_sensor_page_size; extern int alarm_sensor_page_num; extern char alarm_network_start_time[32]; extern char alarm_network_end_time[32]; extern int alarm_network_page_size; extern int alarm_network_page_num; extern char alarm_running_start_time[32]; extern char alarm_running_end_time[32]; extern int alarm_running_page_size; extern int alarm_running_page_num; extern char alarm_operation_start_time[32]; extern char alarm_operation_end_time[32]; extern int alarm_operation_page_size; extern int alarm_operation_page_num; void initLogger(void); //打印设备信息结构 void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo); //打印设备超限电源管理 void printf_global_power_manage_info(GlobalPowerManger* _globalPowerManger); //打印设备超限电源通道管理 //void printf_global_power_chn_manage_info(GlobalPowerChnManger* _globalPowerChnManger); void printf_power_info(GlobalPowerInfo* _globalPowerInfo); int getTotalMemorySize(unsigned int* totalSize); char* getLocalIpAddress(char* dev); char *getLocalMask(char *dev); char *getLocalGateway(char *dev); char* get_mac_address(const char *iface_name) ; void get_disk_occupy(char ** reused); int get_tzone(void); int set_tzone(int tzone); int set_time(struct tm *t, int tzone); int set_utctime(time_t t); int set_time_zone(struct tm *t, int tzone); int set_utctime_zone(time_t t, int tzone); time_t mktime0(void); time_t mktime2(struct tm *t, int tzone); int get_time_str(char *s, int len, time_t t); int get_time_str2(char *s, int len, time_t t); int get_curtime_str(char *s, int len); int get_curtime_str2(char *s, int len); int get_bldtime(char *buf, int len); int get_bldtime2(char *dst, char *ori); void print_time(char *s, struct tm *tm); void print_utc(char *s, time_t t); int is_process_running(const char *process_name); // 辅助函数:判断是否是闰年 int is_leap_year(int year); // 辅助函数:获取某月的天数 int days_in_month(int year, int month); // 函数:增加一天到日期 void add_day_to_date(char *date_str, int *year, int *month, int *day); char* utf8_to_unicode_string(const char* utf8_str) ; int chinese_to_ucs2(const char* utf8_str, char* ucs2_hex, size_t ucs2_hex_size); void SetMenuAuthority(int RoleID); void InitCellularManager(); #endif