common.h 31 KB

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