common.h 36 KB

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