common.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. #ifndef __COMMON_H_
  2. #define __COMMON_H_
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <stdbool.h>
  8. #include "sqlite3.h"
  9. #include "pthread.h"
  10. #include "list.h"
  11. #include "modbus_handle.h"
  12. #include "elog.h"
  13. #include "mongoose.h"
  14. #include "ntpclient.h"
  15. #include <net-snmp/net-snmp-config.h>
  16. #include <net-snmp/net-snmp-includes.h>
  17. #include <net-snmp/agent/net-snmp-agent-includes.h>
  18. #include "pduMIB_form.h"
  19. #include "pduMIB_scalar.h"
  20. #include "pduMIB_trap.h"
  21. #include "language_hashmap.h"
  22. #include "hlw8110_habdle.h"
  23. #include "language_common.h"
  24. #include <sys/shm.h>
  25. #include "cfg.h"
  26. #define MAX_RELAY_CHN 100
  27. //是否在OS环境下运行
  28. #define OS_HANDWARE 1
  29. #define WEB_ROOT "../web"
  30. #define PARAS_FILE "pduParas"
  31. #define DATABASE_NAME "pdu_dat.db"
  32. #define DATABASE_BAK_NAME "pdu_dat_bak.db"
  33. #define SNMP_MIB_NAME "pduMIB"
  34. #define INI_FILE_NAME "smartPDU.ini"
  35. //高配表头串口定义-----------------------------------------------
  36. //控制板通信串口
  37. #define INTERL_MODBUS_PORT "/dev/ttyAS5"
  38. #define INTERL_MODBUS_BAUD 115200
  39. //表头级联通讯串口
  40. #define CASCADE_MODBUS_PORT "/dev/ttyAS4"
  41. #define CASCADE_MODBUS_BAUD 115200
  42. //传感器通信串口
  43. #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyAS2"
  44. #define INTERL_SENSOR_MODBUS_BAUD 9600
  45. #define IMAGE_PATH "image"
  46. #define LOGO_FILE "logo.png"
  47. #define QRCODE_FILE "qrcode.png"
  48. #define AC_SINGLE_S_CUR_CHN_NUM 8
  49. #define AC_SINGLE_B_CUR_CHN_NUM 4
  50. #define AC_SINGLE_S_MAX_CHN_NUM 10 //单个控制板最大数量
  51. #define AC_SINGLE_S_MAX_ADDRESS_NUM 16 //控制板最大数量
  52. #define AC_MAX_VOLTAGE_VAL 400
  53. #define AC_MAX_CURRENT_VAL 100
  54. #define AC_MAX_POWER_VAL 100
  55. enum
  56. {
  57. TOTAL_VOLTAGE_TYPE = 0,//统计电压类型
  58. TOTAL_CURRENT_TYPE = 1,//统计电流类型
  59. TOTAL_POWER_TYPE = 2,//统计功率类型
  60. TOTAL_POWER_CONS_TYPE = 3 //统计耗电量类型
  61. };
  62. enum
  63. {
  64. POWER_MERITORIOUS_TYPE = 0,//有功功率类型
  65. POWER_REACTIVE_TYPE = 1,//无功功率类型
  66. POWER_APPARENT_TYPE = 2 //视在功率类型
  67. };
  68. enum
  69. {
  70. SENSOR_TYPE_TEMPERATURE = 0 , //温度传感器
  71. SENSOR_TYPE_SMOKE = 1 , //烟雾传感器
  72. SENSOR_TYPE_WATER = 2 , //水浸传感器
  73. SENSOR_TYPE_DOOR = 3 , //门禁传感器
  74. SENSOR_TYPE_GAS = 4 , //气体传感器
  75. SENSOR_TYPE_AIR_PRESS = 5 , //气体、气压传感器
  76. SENSOR_TYPE_AIR_Conditioner = 6, //空调传感器
  77. SENSOR_TYPE_DoubleT = 7 //双头温度
  78. };
  79. enum
  80. {
  81. SENSOR_VAL1_UPPER = 0,
  82. SENSOR_VAL1_LOWER = 1,
  83. SENSOR_VAL2_UPPER = 2,
  84. SENSOR_VAL2_LOWER = 3,
  85. };
  86. enum
  87. {
  88. SENSOR_TYPE_VALUE = 0 , //传感器类型0、4、5
  89. SENSOR_TYPE_LIST =1 //传感器类型1、2、3
  90. };
  91. /// @brief 板子类型
  92. enum MODBUS_BOARD_TYPE
  93. {
  94. AC_SINGLE_S_TYPE=1,
  95. AC_SINGLE_B_TYPE,
  96. AC_MULTI_S_TYPE,
  97. AC_MULTI_B_TYPE,
  98. DC_OUT_TYPE,
  99. DC_IN_TYPE,
  100. DCPDU_TYPE,
  101. TREE_AC_TYPE, //三相进三项出
  102. };
  103. enum AppProductType
  104. {
  105. SmartPDU_AC=0,
  106. SmartPDU_DC=1,
  107. SmartPDU_Tree_AC_Tree=3,
  108. SmartPDU_Tree_AC_One=4,
  109. SmartPDU_Tree_AC_One_B=5,
  110. };
  111. /// @brief 三相网页数据
  112. static char* g_product_t_ac_type_str[3] = {
  113. "L1",
  114. "L2",
  115. "L3",
  116. };
  117. /// @brief 按位标记
  118. enum BIT_CTRL
  119. {
  120. BIT_00 = 1 ,
  121. BIT_01 = 2 ,
  122. BIT_02 = 4 ,
  123. BIT_03 = 8 ,
  124. BIT_04 = 16,
  125. BIT_05 = 32,
  126. BIT_06 = 64,
  127. BIT_07 = 128,
  128. BIT_08 = 256,
  129. BIT_09 = 512,
  130. BIT_10 = 1024,
  131. BIT_11 = 2048,
  132. BIT_12 = 4096,
  133. BIT_13 = 8192,
  134. BIT_14 = 16384,
  135. BIT_15 = 32768,
  136. };
  137. /// @brief 使能位
  138. enum ENABLE_BIT_CTRL
  139. {
  140. ENABLE_V_UP = 2 ,
  141. ENABLE_V_DOWN = 8 ,
  142. ENABLE_A_UP = 32,
  143. ENABLE_W_UP = 128,
  144. ENABLE_P_UP = 512,
  145. ENABLE_ALL_UP = BIT_11,
  146. ENABLE_ALL_DOWN = BIT_12,
  147. };
  148. /// @brief 使能位三项
  149. enum ENABLE_TreeAC_CTRL
  150. {
  151. ENABLE_TAC_V_UP = BIT_01,
  152. ENABLE_TAC_V_DOWN = BIT_02,
  153. ENABLE_TAC_A_UP = BIT_03,
  154. ENABLE_TAC_W_UP = BIT_04,
  155. ENABLE_TAC_P_UP = BIT_05,
  156. ENABLE_TAC_STIME = BIT_06,
  157. ENABLE_TAC_ETIME = BIT_07,
  158. };
  159. /// @brief 报警位
  160. enum WARNING_BIT_CTRL
  161. {
  162. WARNING_V_UP = 4 ,
  163. WARNING_V_DOWN = 16 ,
  164. WARNING_A_UP = 64,
  165. WARNING_W_UP = 256,
  166. WARNING_P_UP = 1024,
  167. };
  168. enum {
  169. ALARM_TYPE_POWER=0,
  170. ALARM_TYPE_SENSOR,
  171. ALARM_TYPE_NETWORK,
  172. ALARM_TYPE_OPRATION,
  173. ALARM_TYPE_RUNNING,
  174. };
  175. enum {
  176. NETWORK_MAC_CHANGED=0,
  177. NETWORK_IP_CHANGED,
  178. };
  179. /// @brief 报警动作
  180. enum ALARM_CTRL
  181. {
  182. ALARM_CTRL_CLOSE_CH = 1 ,
  183. ALARM_CTRL_ALARM_ONLY = 2 ,
  184. ALARM_CTRL_CLOSE_ALLCH = 3 ,
  185. };
  186. ///////////////////////////////////////////////////////////////////////////////////
  187. typedef struct {
  188. int id;
  189. int up;
  190. char ip[48];
  191. char mac[24];
  192. char desc[64];
  193. }port_info_t;
  194. typedef struct {
  195. #define SW_PORT_MAX 28
  196. port_info_t port[SW_PORT_MAX];
  197. }netswitch_info_t;
  198. ///////////////////////////////////////////////////////////////////////////////////
  199. //modbus信息管理
  200. typedef struct
  201. {
  202. bool product_modbus_type ; //modbus模式
  203. unsigned int product_modbus_baud ; //波特率
  204. unsigned char product_modbus_addr ;//从Modbus地址信息
  205. char product_relay_ctrl_port[32] ;//继电器modbus控制端口
  206. }ModbusInfo_t;
  207. typedef struct
  208. {
  209. int mode; //1: static 0: dhcp
  210. char ip_address[64] ; //ip地址
  211. char mask[64]; //子网掩码
  212. char gateway[64]; //网关
  213. char dns1[64]; //dns1
  214. char dns2[64]; //dns2
  215. }NetworkInfo_t;
  216. /// @brief 用户登录
  217. typedef struct
  218. {
  219. char user_name[64];
  220. char user_password[64];
  221. char user_uuid[64];
  222. char user_token[64];
  223. struct list_head list;
  224. }_User_Log;
  225. //设备总体管理表
  226. typedef struct
  227. {
  228. int product_id ;//产品ID
  229. char product_number[16] ;//产品编号
  230. char product_name[32] ;//产品名称
  231. char product_status[32] ;//产品状态
  232. unsigned char product_type ;//产品类型
  233. unsigned char product_pwr_type ;//电源类型
  234. char product_version[8] ;//软件版本
  235. unsigned char product_language ;//多国语言
  236. unsigned char product_count ;//级联设备数
  237. unsigned short product_samp_time ;//采集周期 单位ms
  238. unsigned short product_save_time ;//采集周期 单位ms
  239. ModbusInfo_t _modbus_info ;//继电器控制端口
  240. NetworkInfo_t _network_info ; ;//网络信息
  241. ModbusInfo_t _gmodbus_info ;//级联端口
  242. }GlobalDeviceInfo;
  243. ///////////////////////////////////////////////////////////////////////////////////
  244. ///////////////////////////////////////////////////////////////////////////////////
  245. //自定义共享内存类
  246. typedef struct
  247. {
  248. //电源数据
  249. int bPDUSet;
  250. int nSelectPowerCH;
  251. int nMaxCh;
  252. float fV;
  253. float fA;
  254. float fW;
  255. float fF;
  256. float fS;
  257. int nStatus;
  258. //传感器数据
  259. int nSelectSensor;
  260. float fT;//温度
  261. float fH;//湿度
  262. } smartPDU_shm_data;
  263. ///////////////////////////////////////////////////////////////////////////////////
  264. ///////////////////////////////////////////////////////////////////////////////////
  265. //超限管理表
  266. typedef struct
  267. {
  268. char product_vol_upper_enable ;//电压上限使能
  269. float product_vol_upper_threshold ;//电压上限值
  270. char product_vol_over_upper_threshold_ctrl ;//电压超限动作
  271. char product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数
  272. char product_vol_lower_enable ;//电压下限使能
  273. float product_vol_lower_threshold ;//电压下限值
  274. char product_vol_over_lower_threshold_ctrl ;//电压超限动作
  275. char product_vol_over_lower_threshold_ctrl_para ;//电压超限动作
  276. char product_cur_upper_enable ;//电流下限使能
  277. float product_cur_upper_threshold ;//电流下限值
  278. float product_cur_lower_threshold; //
  279. char product_cur_over_upper_threshold_ctrl ;//电流超限动作
  280. char product_cur_over_upper_threshold_ctrl_para ;//电流超限动作
  281. char product_pwr_upper_enable ;//功率上限使能
  282. float product_pwr_upper_threshold ;//功率上限值
  283. char product_pwr_over_upper_threshold_ctrl ;//功率超限动作
  284. char product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作
  285. char product_pwrcon_upper_enable ;//耗电量上限使能
  286. float product_pwrcon_upper_threshold ;//耗电量上限值
  287. char product_pwrcon_over_upper_threshold_ctrl ;//耗电量超限动作
  288. char product_pwrcon_over_upper_threshold_ctrl_para ;//耗电量超限动作
  289. }GlobalOverManager;
  290. /// @brief 定时管理
  291. typedef struct
  292. {
  293. char set_date[16]; //设置日期
  294. char ds_date[16]; //设置时间
  295. char ds_time[16]; //设置时间
  296. int set_stats; //状态
  297. int ds_is_triggered; //是否已触发
  298. struct list_head list;
  299. }_PowerDSManage_t;
  300. typedef struct
  301. {
  302. int firingSortno; //启动序号
  303. int closeSortno; //关闭序号
  304. }_PowerSXManage_t;
  305. typedef struct
  306. {
  307. int product_id;
  308. int mode;
  309. char* ntpName;
  310. char* ntpaddress;
  311. int port;
  312. char* time;
  313. int weekday;
  314. int tzone;
  315. }NTPManager;
  316. NTPManager _globalNTPManager;
  317. typedef struct
  318. {
  319. int product_id;
  320. int mode;
  321. int version;
  322. char* public;
  323. int trapmode;
  324. }SNMPManager;
  325. SNMPManager _globalSNMPManager;
  326. //分组管理
  327. typedef struct
  328. {
  329. int product_id;
  330. int GroupID;
  331. char GroupName[64];
  332. char GroupChList[512];
  333. struct list_head list;
  334. }GroupInfo;
  335. //电源部分
  336. typedef struct
  337. {
  338. float voltage ;//电压
  339. float current ;//电流
  340. float power ;//功率
  341. float freq ;//频率
  342. float consumption ;//耗电量
  343. float factor ;//功率因素
  344. unsigned short status ;//开关状态
  345. unsigned short NF_status ;//零线状态
  346. port_info_t port; //
  347. }PowerInfo;
  348. //电源部分报警信息
  349. typedef struct
  350. {
  351. bool w_voltage_up ;//电压上限报警
  352. bool w_voltage_down ;//电压下限报警
  353. bool w_current ;//电流上限报警
  354. bool w_power ;//功率
  355. bool w_consumption ;//耗电量
  356. bool w_phase_lossA; // 缺相报警
  357. bool w_phase_lossB; // 缺相报警
  358. bool w_phase_lossC; // 缺相报警
  359. }PowerWarningInfo;
  360. //三项数据
  361. typedef struct
  362. {
  363. int product_id;
  364. int product_ch_id;
  365. int product_ph_id;
  366. int product_ph_type;//0:A相 1:B相 2:C相
  367. int product_saddr;
  368. int product_ch_addr;
  369. int product_ph_outputType;//三相控制方式1,三项2单项
  370. int product_ph_outputStatus;//该相是否输出,1输出2不输出
  371. PowerInfo _PowerInfo; //存储最新的数据(兼容三项输入)
  372. GlobalOverManager* global_over_manager ;//超限管理
  373. PowerWarningInfo _PowerWarninginfo; //存储报警数据(兼容三项输入)
  374. time_t product_log_time; //存储最新时间
  375. struct list_head list_Tree_AC; //存储三项数据指针
  376. }GlobalTreeACManager;
  377. //电源通道管理总表(输出)
  378. typedef struct
  379. {
  380. int product_id ;//产品ID
  381. //20240225 add
  382. char product_saddr ;//modbus地址记录
  383. char product_ch_id ;//通道号
  384. char product_ch_addr ;//通道号实际地址
  385. char product_ch_name[32] ;//通道名称
  386. char product_ch_type ;//通道类型
  387. char product_ch_status ;//通道状态
  388. char product_ch_NF_status ;//通道零线状态(三相)
  389. unsigned short product_ch_start_delay ;//通道延时
  390. unsigned short product_ch_stop_delay ;//通道延时
  391. GlobalOverManager* global_over_manager ;//超限管理
  392. struct list_head list_DS; //定时设置
  393. _PowerSXManage_t* _PowerSXManage; //时序管理
  394. PowerInfo _PowerInfo; //存储最新的数据
  395. PowerWarningInfo _PowerWarninginfo ; //存储报警数据
  396. time_t product_log_time; //存储最新时间
  397. struct list_head list_Tree_AC; //存储三项数据指针
  398. struct list_head list;
  399. } GlobalPowerManger;
  400. //电源通道管理总表(输入)
  401. typedef struct
  402. {
  403. int product_id ;//产品ID
  404. //20240225 add
  405. char product_saddr ;//modbus地址记录
  406. char product_saddr_name[32] ;//输入名称
  407. char product_saddr_type ;//输入类型
  408. GlobalOverManager* global_over_manager ;//超限管理
  409. PowerInfo _PowerInfo[3]; //存储最新的数据(兼容三项输入)
  410. PowerWarningInfo _PowerWarninginfo[3]; //存储报警数据(兼容三项输入)
  411. time_t product_log_time; //存储最新时间
  412. int product_MissingPH[3]; //缺相报警
  413. }GlobalPowerInManger;
  414. //电源控制板计数
  415. typedef struct
  416. {
  417. char product_saddr ;//modbus地址记录
  418. int product_number; //数量
  419. int product_type; //类型
  420. PowerInfo _PowerInfo[AC_SINGLE_S_MAX_CHN_NUM]; //存储最新的数据
  421. PowerWarningInfo _PowerWarninginfo[AC_SINGLE_S_MAX_CHN_NUM] ;//存储报警数据
  422. struct list_head list; //存储具有的通道指针
  423. GlobalPowerInManger _globalPowerInManger; //总输入数据
  424. }GlobalPowerCtrlBoard;
  425. ///////////////////////////////////////////////////////////////////////////////////
  426. ///////////////////////////////////////////////////////////////////////////////////
  427. //电源信息统计
  428. typedef struct
  429. {
  430. float ydata[60]; //value
  431. char xAxis[60][32];//时间点
  432. }GetTotalInfo;
  433. //系统总数信息
  434. typedef struct
  435. {
  436. int channel_total ;//通道总数
  437. int warn_total ;//告警总数
  438. int sensor_total ;//传感器总数
  439. int log_total ;//运行日志总数
  440. }SystemTotalInfo;
  441. //功率趋势接口
  442. typedef struct
  443. {
  444. float ydata[3][60] ;//0:有功功率;1:无功功率;2:视在功率;
  445. char xAxis[60][32] ;//时间点
  446. }PowerTrendInfo;
  447. ///////////////////////////////////////////////////////////////////////////////////
  448. ///////////////////////////////////////////////////////////////////////////////////
  449. //电源监控
  450. typedef struct
  451. {
  452. int product_id ;//产品ID
  453. char product_ch_id ;//电源通道
  454. unsigned short product_status ;//当前状态
  455. PowerInfo _power_info ;//采集值
  456. char samp_time[64] ;//采集时间
  457. GetTotalInfo _total_voltage ;//统计电压
  458. GetTotalInfo _total_current ;//统计电流
  459. GetTotalInfo _total_power ;//统计功率
  460. GetTotalInfo _total_consumption ;//统计耗电量
  461. SystemTotalInfo _system_total_info ;//系统总数信息
  462. PowerTrendInfo _power_trend_info ;//功率趋势图
  463. struct list_head list;
  464. }GlobalPowerInfo;
  465. ///////////////////////////////////////////////////////////////////////////////////
  466. ///////////////////////////////////////////////////////////////////////////////////
  467. ///////////////////////////////////////////////////////////////////////////////////
  468. ///////////////////////////////////////////////////////////////////////////////////
  469. //传感器值
  470. typedef struct
  471. {
  472. char samp_time[64] ;//采集时间
  473. int product_id ;//产品ID
  474. char sensor_id ;//传感器ID
  475. float val1 ;//值1
  476. float val2 ;//值2
  477. time_t product_log_time; //存储最新时间
  478. struct list_head list;
  479. }GlobalSensorInfo;
  480. typedef struct
  481. {
  482. bool sensor_val1_upper_enabled ;//
  483. float sensor_val1_upper_threshold;
  484. char sensor_val1_upper_threshold_ctrl;
  485. char sensor_val1_upper_threshold_ctrl_para[512];
  486. bool sensor_val1_lower_enabled ;//
  487. float sensor_val1_lower_threshold;
  488. char sensor_val1_lower_threshold_ctrl;
  489. char sensor_val1_lower_threshold_ctrl_para[512];
  490. bool sensor_val2_upper_enabled ;//
  491. float sensor_val2_upper_threshold;
  492. char sensor_val2_upper_threshold_ctrl;
  493. char sensor_val2_upper_threshold_ctrl_para[512];
  494. bool sensor_val2_lower_enabled ;//
  495. float sensor_val2_lower_threshold;
  496. char sensor_val2_lower_threshold_ctrl;
  497. char sensor_val2_lower_threshold_ctrl_para[512];
  498. }GlobalSensorOverManage;
  499. //传感器报警状态表
  500. typedef struct
  501. {
  502. bool sensor_val1_upper;
  503. bool sensor_val1_lower;
  504. bool sensor_val2_upper;
  505. bool sensor_val2_lower;
  506. }GlobalSensorOverInfo;
  507. //传感器管理总表
  508. typedef struct
  509. {
  510. int product_id ;//产品ID
  511. char sensor_id ;//传感器ID
  512. char sensor_type ;//传感器类型
  513. char sensor_interface_type; //接口类型
  514. char sensor_name[64] ;//传感器名称
  515. char sensor_port_name[32] ;//传感器端口号
  516. int sensor_baud ;//波特率
  517. char sensor_addr ;//modbus地址
  518. int sensor_status ;//传感器状态
  519. char sensor_val_count ;//传感器值个数
  520. int sensor_node_number ;//节点号
  521. GlobalSensorInfo Cur_sensor_info ;
  522. GlobalSensorOverManage* over_manager ;//超限管理
  523. GlobalSensorOverInfo warning_status;//报警状态
  524. struct list_head list;
  525. }GlobalSensorManger;
  526. ///////////////////////////////////////////////////////////////////////////////////
  527. ///////////////////////////////////////////////////////////////////////////////////
  528. ///////////////////////////////////////////////////////////////////////////////////
  529. ///////////////////////////////////////////////////////////////////////////////////
  530. ///温湿度数据信息管理
  531. typedef struct
  532. {
  533. float temperature;
  534. float humidity;
  535. }SenorTempVal;
  536. //采集KB值
  537. typedef struct
  538. {
  539. float voltage_k;//电压K
  540. float voltage_b;//电压B
  541. float current_k;//电流K
  542. float current_b;//电流B
  543. }SwitchKbVal;
  544. ///////////////////////////////////////////////////////////////////////////////////
  545. ///////////////////////////////////////////////////////////////////////////////////
  546. //SMTP管理
  547. typedef struct
  548. {
  549. int idx;
  550. int use;
  551. char account[64];
  552. }smtp_recv_t;
  553. typedef struct
  554. {
  555. int id;
  556. int mode; //0: open 1: close
  557. char account[64]; //用户账号
  558. char password[24]; //用户密码
  559. char server[64]; //服务器
  560. char port[10]; //端口
  561. char auth[16]; //认证方式
  562. }smtp_send_t;
  563. typedef struct
  564. {
  565. smtp_send_t send;
  566. #define SMTP_RECV_MAX 10
  567. smtp_recv_t recv[SMTP_RECV_MAX]; //接收账号列表
  568. }smtp_info_t;
  569. typedef struct {
  570. int id; //id
  571. int mode; //0: open 1: close
  572. char proto[10]; //mqtt, mqtts, ws, wss
  573. char server[512]; //server
  574. char ip[48]; //server ip
  575. char port[10]; //server port
  576. char cid[32]; //client ID
  577. char user[32]; //认证方式
  578. char password[32];
  579. char *cert;
  580. }mqtt_server_t;
  581. typedef struct {
  582. #define MQTT_SER_MAX 10
  583. mqtt_server_t ser[MQTT_SER_MAX];
  584. }mqtt_info_t;
  585. typedef struct
  586. {
  587. int product_id;
  588. int userID; //用户ID
  589. char* userName; //用户名-登录
  590. char* userPW; //用户密码
  591. char* nickName; //用户名称
  592. int roleID; //角色ID
  593. char* createTime; //用户创建时间
  594. struct list_head list;
  595. }UserInfo;
  596. typedef struct
  597. {
  598. int product_id;
  599. int roleID; //角色ID
  600. char* roleName; //角色名称
  601. int roleLevel; //角色等级
  602. char* roleAuthority; //角色权限
  603. int roleSort; //显示顺序
  604. char* createTime; //创建时间
  605. struct list_head list;
  606. }RoleInfo;
  607. typedef struct MenuAuthority{
  608. bool PowerEnabled;
  609. bool SensorEnabled;
  610. bool AlarmEnabled;
  611. bool LogEnabled;
  612. bool UserInfoEnabled;
  613. bool CommEnabled;
  614. bool ServiceEnabled;
  615. bool MaintenanceEnabled;
  616. //1、电源监控菜单
  617. bool MonitorallEnabled;
  618. bool ChannelstatusEnabled;
  619. bool SwitchtatusEnabled;
  620. bool MonitorhistoryEnabled;
  621. //2、传感器管理菜单
  622. bool SensorStatusEnabled;
  623. bool SensorHistorylEnabled;
  624. //3、告警管理菜单
  625. bool XtjgEnabled;
  626. bool YzszEnabled;
  627. //4、日志信息菜单
  628. bool CzrzEnabled;
  629. bool YxrzEnabled;
  630. //5、用户管理菜单
  631. bool UserEnabled;
  632. bool RoleEnabled;
  633. bool MenuEnabled;
  634. //6、通信管理菜单
  635. bool WkszEnabled;
  636. bool RsszEnabled;
  637. //7、服务管理菜单
  638. bool SmtpszEnabled;
  639. bool SnmpszEnabled;
  640. bool MqszEnabled;
  641. bool NtpszEnabled;
  642. bool DsszEnabled;
  643. bool SxszEnabled;
  644. bool FzszEnabled;
  645. //8、设备维护菜单
  646. bool SbcqEnabled;
  647. bool GjsjEnabled;
  648. bool HhccszEnabled;
  649. bool PzdrdcEnabled;
  650. bool ShfwEnabled;
  651. bool GysbEnabled;
  652. }MenuAuthority;
  653. typedef struct CascadeDevices{
  654. int product_id; //级联设备ID modbus地址
  655. int type; //
  656. char device_name[20]; //接连设备名;
  657. float valtage; //485
  658. float current;
  659. float power;
  660. float factor;
  661. float freq;
  662. float consumption;
  663. }CascadeDevices;
  664. struct modbus_slave_read_reg{
  665. uint16_t deveice_type; //设备类型
  666. uint16_t slave_addr; //设备地址
  667. uint32_t voltage; //当前电压
  668. uint32_t current; //当前电流
  669. uint32_t power; //当前功率
  670. uint32_t consumption_cur; //耗电量
  671. uint32_t freq; //频率
  672. uint32_t factor; //功率因素
  673. uint32_t temprature; //温度值
  674. uint32_t humidity; //湿度值
  675. uint32_t warning; //告警
  676. uint16_t power_supplay_status; //供电状态
  677. uint16_t sencor_status; //传感器状态
  678. uint32_t temprature2; //温度值2
  679. // uint32_t Warinfo;
  680. // uint16_t sercor_type;
  681. };
  682. typedef struct cascade_pw_info{
  683. uint32_t voltage ;//电压
  684. uint32_t current ;//电流
  685. uint32_t power ;//功率
  686. uint32_t freq ;//频率
  687. uint32_t consumption ;//耗电量
  688. uint32_t factor ;//功率因素
  689. }cascade_single_chn_info; //siggle hell
  690. typedef struct temp_hum{
  691. uint16_t temperature;
  692. uint16_t humidity;
  693. }temp_hum_t;
  694. #pragma pack (1)
  695. typedef struct cascade_single_mmap{
  696. uint16_t dev_chn;
  697. cascade_single_chn_info all_ch[128];
  698. uint32_t total_valtage;
  699. uint32_t total_current;
  700. uint32_t total_power;
  701. uint32_t total_consumer;
  702. temp_hum_t total_temp;
  703. uint16_t chn_status[64];
  704. uint16_t open_delay[64];
  705. uint16_t close_delay[64];
  706. uint16_t reservers[29];
  707. uint16_t set_chn_open_delay[64];
  708. uint16_t set_chn_close_delay[64];
  709. uint16_t set_chn_switch_status[64];
  710. uint16_t set_chn_all_switch_status;
  711. }cascade_single_mmap_t;
  712. #pragma pack ()
  713. #pragma pack (1)
  714. #define MAX_CHN 64
  715. typedef struct cascade_triphasic_pw_out{
  716. uint32_t o_voltage;
  717. uint32_t o_current;
  718. uint32_t o_power;
  719. uint32_t o_consumption;
  720. uint32_t o_status;
  721. }cascade_triphasic_pw_out_t;
  722. typedef struct cascade_triphasic_pw_o_chn{
  723. cascade_triphasic_pw_out_t chn[3]; // A B C
  724. }cascade_triphasic_pw_o_chn_t;
  725. typedef struct cascade_triphasic_pw_in{
  726. uint32_t i_total_voltage;
  727. uint32_t i_total_current;
  728. uint32_t i_total_power;
  729. uint32_t i_total_consumption;
  730. }cascade_triphasic_pw_in_t;
  731. typedef struct cascade_triphasic_pw_i_total{
  732. cascade_triphasic_pw_in_t pw_i_total[3]; // A B C
  733. }cascade_triphasic_pw_i_total_t;
  734. typedef struct cascade_triphasic_chn_info{
  735. uint32_t chn_power;
  736. uint32_t chn_freq;
  737. uint32_t chn_consumption;
  738. uint32_t chn_factor;
  739. uint32_t chn_type;
  740. }cascade_triphasic_chn_info_t;
  741. typedef struct cascade_triphasic_mmap{
  742. uint16_t dev_chn;
  743. cascade_triphasic_pw_i_total_t i_total;
  744. cascade_triphasic_chn_info_t chn_info[MAX_CHN];
  745. cascade_triphasic_pw_o_chn_t pw_o_chn[MAX_CHN];
  746. uint16_t temperature;
  747. uint16_t humidity;
  748. uint16_t chn_status[MAX_CHN];
  749. uint16_t open_delay[MAX_CHN];
  750. uint16_t close_delay[MAX_CHN];
  751. uint16_t set_chn_open_delay[MAX_CHN];
  752. uint16_t set_chn_close_delay[MAX_CHN];
  753. uint16_t set_chn_switch_status[MAX_CHN];
  754. uint16_t set_chn_all_switch_status;
  755. }cascade_triphasic_mmap_t;
  756. #pragma pack ()
  757. struct modbus_slave_write_reg{
  758. uint16_t voltage_high_enable:1; //电压高阈值检测使能
  759. uint16_t voltage_low_enable:1; //电压低阈值检测使能
  760. uint16_t current_enable:1; //电流阈值使能
  761. uint16_t power_enable:1; //功率阈值使能
  762. uint16_t consumption_cur_enable:1; //功耗阈值使能
  763. uint32_t voltage_upper_threshold; //
  764. uint32_t voltage_lower_threshold;
  765. uint32_t current_upper_threshold;
  766. uint32_t power_upper_threshold;
  767. uint32_t consumption_threshold;
  768. };
  769. enum
  770. {
  771. DI,
  772. RS485
  773. };
  774. enum{
  775. SWITCH_CONNETCTED,
  776. SWITCH_DISCONNETCTED,
  777. SWITCH_OFFLINE
  778. };
  779. #define SWITCH_CHN_1_SET (1<<0)
  780. #define SWITCH_CHN_2_SET (1<<1)
  781. #define SWITCH_CHN_3_SET (1<<2)
  782. #define SWITCH_CHN_4_SET (1<<3)
  783. #define SWITCH_CHN_5_SET (1<<4)
  784. #define SWITCH_CHN_6_SET (1<<5)
  785. #define SWITCH_CHN_DI_1_SET (1<<6)
  786. #define SWITCH_CHN_DI_2_SET (1<<7)
  787. typedef struct breaker_switch_sta{
  788. uint16_t status;
  789. uint16_t gather;
  790. char com[30];
  791. uint8_t product_name[256];
  792. }breaker_switch_sta_t;
  793. typedef struct GlobalBreakerManger{
  794. uint32_t all_count;
  795. uint32_t online_count;
  796. uint32_t mask;
  797. uint8_t saddr;
  798. void *manager;
  799. breaker_switch_sta_t sta[8]; // 6 + 2
  800. pthread_mutex_t b_mutex;
  801. }GlobalBreakerManger;
  802. typedef struct GlobalBreakerManager{
  803. uint32_t product_id;
  804. uint32_t breaker_id;
  805. uint32_t breaker_chn;
  806. uint32_t breaker_status;
  807. uint32_t breaker_gather_addr;
  808. char breaker_switch_name[128];
  809. char breaker_com[64];
  810. char breaker_gather_type[64];
  811. char breaker_chns_name[128];
  812. struct list_head list;
  813. }GlobalBreakerManager;
  814. //设备总体管理
  815. typedef struct
  816. {
  817. sqlite3* db; //数据库接口
  818. pthread_mutex_t dbThreadlock; //写入线程锁
  819. pthread_t appweb_thread; //appweb线程
  820. pthread_t dev_samp_thread;//电源采集与控制线程
  821. pthread_t dev_update_thread;//电源采集与控制线程
  822. pthread_t io_thread; //IO采集线程
  823. pthread_t sensor_thread; //传感器采集现成
  824. bool dev_samp_flag ; //电源采集线程标志
  825. GlobalDeviceInfo _globalDevInfo; //设备管理信息
  826. GlobalPowerManger _globalPowerManger; //电源管理表
  827. GlobalSensorManger _globalSensorManger; //传感器管理表
  828. Modbus_Manger sensor_modbus_manager; //通信接口管理
  829. unsigned int useSlaveCount ; //有效地址
  830. Modbus_Manger _globalRelaySampManger; //内部继电器使用
  831. unsigned char uart_init_flag[6] ; //
  832. bool ws_isok; //ws准备好
  833. struct mg_connection *ws_client; //websocket管理信息
  834. HashTable* alarmTab; //全局的报警映射
  835. int nTreeACLshow; //三项总数据显示L1=0,L2=1,L3=2
  836. pthread_t snmp_agent_thread;//SNMP代理线程
  837. bool _ReloadChm_flag; //重新加载端口数据
  838. GlobalPowerCtrlBoard _all_ctrl_board[MAX_CHN_COUNT]; //所有控制板
  839. LowConf* _RS485LowConfData;//485Data
  840. //传感器
  841. struct modbus_slave_read_reg g_modebus_read;
  842. struct modbus_slave_write_reg g_modebus_write;
  843. smartPDU_shm_data* g_shm_Data;
  844. pthread_mutex_t _power_ds; //定时器锁
  845. pthread_mutex_t _power_update; //数据刷新锁
  846. pthread_mutex_t _sensor_update; //传感器刷新锁
  847. pthread_mutex_t _breaker_mutex; // breaker info
  848. cascade_single_mmap_t *single_mmap;
  849. cascade_triphasic_mmap_t *triphasic_mmap;
  850. GlobalBreakerManager g_new_global_breaker;
  851. smtp_info_t smtpInfo;
  852. mqtt_info_t mqttInfo;
  853. }GlobalDeviceManager;
  854. extern GlobalDeviceManager __globalDeviceManage;
  855. extern GlobalDeviceManager __globalDeviceManage2;
  856. extern NTPClient* globalNTPclient;
  857. extern unsigned long __globalSxIdx;
  858. extern _User_Log _GlobalUserLoginInfo;//全局用户登录信息
  859. extern UserInfo _GlobalUserInfoNew;////最近登录的信息
  860. extern char _GlobalUserToken[64];////最近登录的信息
  861. extern MenuAuthority _GlobalMenuAuthority;////角色菜单权限
  862. void initLogger(void);
  863. //打印设备信息结构
  864. void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo);
  865. //打印设备超限电源管理
  866. void printf_global_power_manage_info(GlobalPowerManger* _globalPowerManger);
  867. //打印设备超限电源通道管理
  868. //void printf_global_power_chn_manage_info(GlobalPowerChnManger* _globalPowerChnManger);
  869. void printf_power_info(GlobalPowerInfo* _globalPowerInfo);
  870. int getTotalMemorySize(unsigned int* totalSize);
  871. char* getLocalIpAddress(char* dev);
  872. char* get_mac_address(const char *iface_name) ;
  873. void get_disk_occupy(char ** reused);
  874. int set_local_timeandzone(struct tm* t, int zone);
  875. char* getUserNamebyToken(char* Token);
  876. int is_process_running(const char *process_name);
  877. bool CheckLoginStatus(char* Token);
  878. // 辅助函数:判断是否是闰年
  879. int is_leap_year(int year);
  880. // 辅助函数:获取某月的天数
  881. int days_in_month(int year, int month);
  882. // 函数:增加一天到日期
  883. void add_day_to_date(char *date_str, int *year, int *month, int *day);
  884. void SetMenuAuthority(int RoleID);
  885. #endif