common.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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 <sys/shm.h>
  24. //#define RS485_TYPE
  25. #define MAX_CHN_COUNT 16
  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 INTERL_MODBUS_PORT "/dev/ttyAS5"
  35. #define INTERL_MODBUS_BAUD 115200
  36. //485温湿度传感器 选择串口1
  37. #define INTERL_485_SENSOR_MODBUS_PORT "/dev/ttyS1"
  38. #define INTERL_485_SENSOR_MODBUS_BAUD 9600
  39. //继电器接口级联
  40. #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyAS2"
  41. #define INTERL_SENSOR_MODBUS_BAUD 9600
  42. //表头级联接口
  43. #define CASCADE_MODBUS_PORT "/dev/ttyAS4"
  44. #define CASCADE_MODBUS_BAUD 115200
  45. //485级联选择串口
  46. #define INTERL_485_CASCADE_PORT "/dev/ttyAS4"
  47. #define INTERL_485_CASCADE_BAUD 115200
  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_TYPE_VALUE = 0 , //传感器类型0、4、5
  80. SENSOR_TYPE_LIST =1 //传感器类型1、2、3
  81. };
  82. /// @brief 板子类型
  83. enum MODBUS_BOARD_TYPE
  84. {
  85. AC_SINGLE_S_TYPE=1,
  86. AC_SINGLE_B_TYPE,
  87. AC_MULTI_S_TYPE,
  88. AC_MULTI_B_TYPE,
  89. DC_OUT_TYPE,
  90. DC_IN_TYPE,
  91. DCPDU_TYPE,
  92. TREE_AC_TYPE, //三相进三项出
  93. RS485_Type,
  94. };
  95. enum AppProductType
  96. {
  97. SmartPDU_AC=0,
  98. SmartPDU_DC=1,
  99. SmartPDU_Tree_AC_Tree=3,
  100. SmartPDU_Tree_AC_One=4
  101. };
  102. /// @brief 三相网页数据
  103. static char* g_product_t_ac_type_str[3] = {
  104. "L1",
  105. "L2",
  106. "L3",
  107. };
  108. /// @brief 按位标记
  109. enum BIT_CTRL
  110. {
  111. BIT_00 = 1 ,
  112. BIT_01 = 2 ,
  113. BIT_02 = 4 ,
  114. BIT_03 = 8 ,
  115. BIT_04 = 16,
  116. BIT_05 = 32,
  117. BIT_06 = 64,
  118. BIT_07 = 128,
  119. BIT_08 = 256,
  120. BIT_09 = 512,
  121. BIT_10 = 1024,
  122. BIT_11 = 2048,
  123. BIT_12 = 4096,
  124. BIT_13 = 8192,
  125. BIT_14 = 16384,
  126. BIT_15 = 32768,
  127. };
  128. /// @brief 使能位
  129. enum ENABLE_BIT_CTRL
  130. {
  131. ENABLE_V_UP = 2 ,
  132. ENABLE_V_DOWN = 8 ,
  133. ENABLE_A_UP = 32,
  134. ENABLE_W_UP = 128,
  135. ENABLE_P_UP = 512,
  136. };
  137. /// @brief 使能位三项
  138. enum ENABLE_TreeAC_CTRL
  139. {
  140. ENABLE_TAC_V_UP = BIT_01,
  141. ENABLE_TAC_V_DOWN = BIT_02,
  142. ENABLE_TAC_A_UP = BIT_03,
  143. ENABLE_TAC_W_UP = BIT_04,
  144. ENABLE_TAC_P_UP = BIT_05,
  145. ENABLE_TAC_STIME = BIT_06,
  146. ENABLE_TAC_ETIME = BIT_07,
  147. };
  148. /// @brief 报警位
  149. enum WARNING_BIT_CTRL
  150. {
  151. WARNING_V_UP = 4 ,
  152. WARNING_V_DOWN = 16 ,
  153. WARNING_A_UP = 64,
  154. WARNING_W_UP = 256,
  155. WARNING_P_UP = 1024,
  156. };
  157. ///////////////////////////////////////////////////////////////////////////////////
  158. ///////////////////////////////////////////////////////////////////////////////////
  159. //modbus信息管理
  160. typedef struct
  161. {
  162. bool product_modbus_type ; //modbus模式
  163. unsigned int product_modbus_baud ; //波特率
  164. unsigned char product_modbus_addr ;//从Modbus地址信息
  165. char product_relay_ctrl_port[32] ;//继电器modbus控制端口
  166. }ModbusInfo_t;
  167. typedef struct
  168. {
  169. int mode; //1: static 0: dhcp
  170. char ip_address[64] ; //ip地址
  171. char mask[64]; //子网掩码
  172. char gateway[64]; //网关
  173. char dns1[64]; //dns1
  174. char dns2[64]; //dns2
  175. }NetworkInfo_t;
  176. /// @brief 用户登录
  177. typedef struct
  178. {
  179. char user_name[64];
  180. char user_password[64];
  181. char user_uuid[64];
  182. char user_token[64];
  183. struct list_head list;
  184. }_User_Log;
  185. //设备总体管理表
  186. typedef struct
  187. {
  188. int product_id ;//产品ID
  189. char product_number[16] ;//产品编号
  190. char product_name[32] ;//产品名称
  191. char product_status[32] ;//产品状态
  192. unsigned char product_type ;//产品类型
  193. unsigned char product_pwr_type ;//电源类型
  194. unsigned char product_version[8] ;//软件版本
  195. unsigned char product_language ; //多国语言
  196. unsigned char product_count ;//级联设备数
  197. unsigned short product_samp_time ;//采集周期 单位ms
  198. unsigned short product_save_time ;//采集周期 单位ms
  199. ModbusInfo_t _modbus_info ;//继电器控制端口
  200. NetworkInfo_t _network_info ; ;//网络信息
  201. ModbusInfo_t _gmodbus_info ;//级联端口
  202. }GlobalDeviceInfo;
  203. ///////////////////////////////////////////////////////////////////////////////////
  204. ///////////////////////////////////////////////////////////////////////////////////
  205. //自定义共享内存类
  206. typedef struct
  207. {
  208. //电源数据
  209. int bPDUSet;
  210. int nSelectPowerCH;
  211. int nMaxCh;
  212. float fV;
  213. float fA;
  214. float fW;
  215. float fF;
  216. float fS;
  217. int nStatus;
  218. //传感器数据
  219. int nSelectSensor;
  220. float fT;//温度
  221. float fH;//湿度
  222. } smartPDU_shm_data;
  223. ///////////////////////////////////////////////////////////////////////////////////
  224. ///////////////////////////////////////////////////////////////////////////////////
  225. //超限管理表
  226. typedef struct
  227. {
  228. char product_vol_upper_enable ;//电压上限使能
  229. float product_vol_upper_threshold ;//电压上限值
  230. char product_vol_over_upper_threshold_ctrl ;//电压超限动作
  231. char product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数
  232. char product_vol_lower_enable ;//电压下限使能
  233. float product_vol_lower_threshold ;//电压下限值
  234. char product_vol_over_lower_threshold_ctrl ;//电压超限动作
  235. char product_vol_over_lower_threshold_ctrl_para ;//电压超限动作
  236. char product_cur_upper_enable ;//电流下限使能
  237. float product_cur_upper_threshold ;//电流下限值
  238. float product_cur_lower_threshold; //
  239. char product_cur_over_upper_threshold_ctrl ;//电流超限动作
  240. char product_cur_over_upper_threshold_ctrl_para ;//电流超限动作
  241. char product_pwr_upper_enable ;//功率上限使能
  242. float product_pwr_upper_threshold ;//功率上限值
  243. char product_pwr_over_upper_threshold_ctrl ;//功率超限动作
  244. char product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作
  245. char product_pwrcon_upper_enable ;//耗电量上限使能
  246. float product_pwrcon_upper_threshold ;//耗电量上限值
  247. char product_pwrcon_over_upper_threshold_ctrl ;//耗电量超限动作
  248. char product_pwrcon_over_upper_threshold_ctrl_para ;//耗电量超限动作
  249. }GlobalOverManager;
  250. /// @brief 定时管理
  251. typedef struct
  252. {
  253. char set_date[16]; //设置日期
  254. char ds_date[16]; //设置时间
  255. char ds_time[16]; //设置时间
  256. char set_stats; //状态
  257. struct list_head list;
  258. }_PowerDSManage_t;
  259. typedef struct
  260. {
  261. int firingSortno; //启动序号
  262. int closeSortno; //关闭序号
  263. }_PowerSXManage_t;
  264. typedef struct
  265. {
  266. int product_id;
  267. int mode;
  268. char* ntpName;
  269. char* ntpaddress;
  270. int port;
  271. char* time;
  272. int weekday;
  273. int tzone;
  274. }NTPManager;
  275. NTPManager _globalNTPManager;
  276. typedef struct
  277. {
  278. int product_id;
  279. int mode;
  280. int version;
  281. char* public;
  282. int trapmode;
  283. }SNMPManager;
  284. SNMPManager _globalSNMPManager;
  285. //分组管理
  286. typedef struct
  287. {
  288. int product_id;
  289. int GroupID;
  290. char GroupName[64];
  291. char GroupChList[512];
  292. struct list_head list;
  293. }GroupInfo;
  294. //电源部分
  295. typedef struct
  296. {
  297. float voltage ;//电压
  298. float current ;//电流
  299. float power ;//功率
  300. float freq ;//频率
  301. float consumption ;//耗电量
  302. float factor ;//功率因素
  303. unsigned short status ;//开关状态
  304. }PowerInfo;
  305. //电源部分报警信息
  306. typedef struct
  307. {
  308. bool w_voltage_up ;//电压上限报警
  309. bool w_voltage_down ;//电压下限报警
  310. bool w_current ;//电流上限报警
  311. bool w_power ;//功率
  312. bool w_consumption ;//耗电量
  313. bool w_phase_loss ;//缺相报警
  314. }PowerWarningInfo;
  315. //三项数据
  316. typedef struct
  317. {
  318. int product_id;
  319. int product_ch_id;
  320. int product_ph_id;
  321. int product_ph_type;//0:A相 1:B相 2:C相
  322. int product_saddr;
  323. int product_ch_addr;
  324. int product_ph_outputType;//三相控制方式1,三项2单项
  325. int product_ph_outputStatus;//该相是否输出,1输出2不输出
  326. PowerInfo _PowerInfo; //存储最新的数据(兼容三项输入)
  327. GlobalOverManager* global_over_manager ;//超限管理
  328. PowerWarningInfo _PowerWarninginfo; //存储报警数据(兼容三项输入)
  329. time_t product_log_time; //存储最新时间
  330. struct list_head list_Tree_AC; //存储三项数据指针
  331. }GlobalTreeACManager;
  332. //电源通道管理总表(输出)
  333. typedef struct
  334. {
  335. int product_id ;//产品ID
  336. //20240225 add
  337. char product_saddr ;//modbus地址记录
  338. char product_ch_id ;//通道号
  339. char product_ch_addr ;//通道号实际地址
  340. char product_ch_name[32] ;//通道名称
  341. char product_ch_type ;//通道类型
  342. char product_ch_status ;//通道状态
  343. unsigned short product_ch_start_delay ;//通道延时
  344. unsigned short product_ch_stop_delay ;//通道延时
  345. GlobalOverManager* global_over_manager ;//超限管理
  346. _PowerDSManage_t* _powerDsManage ;//定时设置
  347. _PowerSXManage_t* _PowerSXManage; //时序管理
  348. PowerInfo _PowerInfo; //存储最新的数据
  349. PowerWarningInfo _PowerWarninginfo ; //存储报警数据
  350. time_t product_log_time; //存储最新时间
  351. struct list_head list_Tree_AC; //存储三项数据指针
  352. struct list_head list;
  353. } GlobalPowerManger;
  354. //电源通道管理总表(输入)
  355. typedef struct
  356. {
  357. int product_id ;//产品ID
  358. //20240225 add
  359. char product_saddr ;//modbus地址记录
  360. char product_saddr_name[32] ;//输入名称
  361. char product_saddr_type ;//输入类型
  362. GlobalOverManager* global_over_manager ;//超限管理
  363. PowerInfo _PowerInfo[3]; //存储最新的数据(兼容三项输入)
  364. PowerWarningInfo _PowerWarninginfo[3]; //存储报警数据(兼容三项输入)
  365. time_t product_log_time; //存储最新时间
  366. }GlobalPowerInManger;
  367. //电源控制板计数
  368. typedef struct
  369. {
  370. char product_saddr ;//modbus地址记录
  371. int product_number; //数量
  372. int product_type; //类型
  373. PowerInfo _PowerInfo[AC_SINGLE_S_MAX_CHN_NUM]; //存储最新的数据
  374. PowerWarningInfo _PowerWarninginfo[AC_SINGLE_S_MAX_CHN_NUM] ;//存储报警数据
  375. struct list_head list; //存储具有的通道指针
  376. GlobalPowerInManger _globalPowerInManger; //总输入数据
  377. }GlobalPowerCtrlBoard;
  378. ///////////////////////////////////////////////////////////////////////////////////
  379. ///////////////////////////////////////////////////////////////////////////////////
  380. //电源信息统计
  381. typedef struct
  382. {
  383. float ydata[60]; //value
  384. char xAxis[60][32];//时间点
  385. }GetTotalInfo;
  386. //系统总数信息
  387. typedef struct
  388. {
  389. int channel_total ;//通道总数
  390. int warn_total ;//告警总数
  391. int sensor_total ;//传感器总数
  392. int log_total ;//运行日志总数
  393. }SystemTotalInfo;
  394. //功率趋势接口
  395. typedef struct
  396. {
  397. float ydata[3][60] ;//0:有功功率;1:无功功率;2:视在功率;
  398. char xAxis[60][32] ;//时间点
  399. }PowerTrendInfo;
  400. ///////////////////////////////////////////////////////////////////////////////////
  401. ///////////////////////////////////////////////////////////////////////////////////
  402. //电源监控
  403. typedef struct
  404. {
  405. int product_id ;//产品ID
  406. char product_ch_id ;//电源通道
  407. unsigned short product_status ;//当前状态
  408. PowerInfo _power_info ;//采集值
  409. char samp_time[32] ;//采集时间
  410. GetTotalInfo _total_voltage ;//统计电压
  411. GetTotalInfo _total_current ;//统计电流
  412. GetTotalInfo _total_power ;//统计功率
  413. GetTotalInfo _total_consumption ;//统计耗电量
  414. SystemTotalInfo _system_total_info ;//系统总数信息
  415. PowerTrendInfo _power_trend_info ;//功率趋势图
  416. struct list_head list;
  417. }GlobalPowerInfo;
  418. ///////////////////////////////////////////////////////////////////////////////////
  419. ///////////////////////////////////////////////////////////////////////////////////
  420. ///////////////////////////////////////////////////////////////////////////////////
  421. ///////////////////////////////////////////////////////////////////////////////////
  422. //传感器值
  423. typedef struct
  424. {
  425. char samp_time[32] ;//采集时间
  426. int product_id ;//产品ID
  427. char sensor_id ;//传感器ID
  428. float val1 ;//值1
  429. float val2 ;//值2
  430. time_t product_log_time; //存储最新时间
  431. struct list_head list;
  432. }GlobalSensorInfo;
  433. typedef struct
  434. {
  435. bool sensor_val1_upper_enabled ;//
  436. float sensor_val1_upper_threshold;
  437. char sensor_val1_upper_threshold_ctrl;
  438. char sensor_val1_upper_threshold_ctrl_para;
  439. bool sensor_val1_lower_enabled ;//
  440. float sensor_val1_lower_threshold;
  441. char sensor_val1_lower_threshold_ctrl;
  442. char sensor_val1_lower_threshold_ctrl_para;
  443. bool sensor_val2_upper_enabled ;//
  444. float sensor_val2_upper_threshold;
  445. char sensor_val2_upper_threshold_ctrl;
  446. char sensor_val2_upper_threshold_ctrl_para;
  447. bool sensor_val2_lower_enabled ;//
  448. float sensor_val2_lower_threshold;
  449. char sensor_val2_lower_threshold_ctrl;
  450. char sensor_val2_lower_threshold_ctrl_para;
  451. }GlobalSensorOverManage;
  452. //传感器管理总表
  453. typedef struct
  454. {
  455. int product_id ;//产品ID
  456. char sensor_id ;//传感器ID
  457. char sensor_type ;//传感器类型
  458. char sensor_interface_type; //接口类型
  459. char sensor_name[64] ;//传感器名称
  460. char sensor_port_name[32] ;//传感器端口号
  461. int sensor_baud ;//波特率
  462. char sensor_addr ;//modbus地址
  463. int sensor_status ;//传感器状态
  464. char sensor_val_count ;//传感器值个数
  465. int sensor_node_number ;//节点号
  466. GlobalSensorOverManage* over_manager ;//超限管理
  467. struct list_head list;
  468. }GlobalSensorManger;
  469. ///////////////////////////////////////////////////////////////////////////////////
  470. ///////////////////////////////////////////////////////////////////////////////////
  471. ///////////////////////////////////////////////////////////////////////////////////
  472. ///////////////////////////////////////////////////////////////////////////////////
  473. ///温湿度数据信息管理
  474. typedef struct
  475. {
  476. float temperature;
  477. float humidity;
  478. }SenorTempVal;
  479. //采集KB值
  480. typedef struct
  481. {
  482. float voltage_k;//电压K
  483. float voltage_b;//电压B
  484. float current_k;//电流K
  485. float current_b;//电流B
  486. }SwitchKbVal;
  487. ///////////////////////////////////////////////////////////////////////////////////
  488. ///////////////////////////////////////////////////////////////////////////////////
  489. //SMTP管理
  490. typedef struct
  491. {
  492. int idx;
  493. char* receive_account;
  494. char* receive_account_info;
  495. struct list_head list;
  496. }SMTPreceiveAccount;
  497. typedef struct
  498. {
  499. int product_id;
  500. int mode; //状态
  501. char* account; //用户账号
  502. char* password; //用户密码
  503. char* server; //服务器
  504. int port; //端口
  505. char auth[16]; //认证方式
  506. SMTPreceiveAccount* receive_account; //接收账号列表
  507. }SMTPManager;
  508. SMTPManager globalSMTPManager;
  509. typedef struct
  510. {
  511. int product_id;
  512. int userID; //用户ID
  513. char* userName; //用户名-登录
  514. char* userPW; //用户密码
  515. char* nickName; //用户名称
  516. int roleID; //角色ID
  517. char* createTime; //用户创建时间
  518. struct list_head list;
  519. }UserInfo;
  520. typedef struct
  521. {
  522. int product_id;
  523. int roleID; //角色ID
  524. char* roleName; //角色名称
  525. int roleLevel; //角色等级
  526. int roleAuthority; //角色权限
  527. int roleSort; //显示顺序
  528. char* createTime; //创建时间
  529. struct list_head list;
  530. }RoleInfo;
  531. typedef struct CascadeDevices{
  532. int product_id; //级联设备ID modbus地址
  533. int type; //
  534. char device_name[20]; //接连设备名;
  535. float valtage; //485
  536. float current;
  537. float power;
  538. float factor;
  539. float freq;
  540. float consumption;
  541. }CascadeDevices;
  542. struct modbus_slave_read_reg{
  543. uint16_t deveice_type; //设备类型
  544. uint16_t slave_addr; //设备地址
  545. uint32_t voltage; //当前电压
  546. uint32_t current; //当前电流
  547. uint32_t power; //当前功率
  548. uint32_t consumption_cur; //耗电量
  549. uint32_t freq; //频率
  550. uint32_t factor; //功率因素
  551. uint32_t temprature; //温度值
  552. uint32_t humidity; //湿度值
  553. uint32_t warning; //告警
  554. uint16_t power_supplay_status; //供电状态
  555. uint16_t sencor_status; //传感器状态
  556. // uint32_t Warinfo;
  557. // uint16_t sercor_type;
  558. };
  559. struct modbus_slave_write_reg{
  560. uint16_t voltage_high_enable:1; //电压高阈值检测使能
  561. uint16_t voltage_low_enable:1; //电压低阈值检测使能
  562. uint16_t current_enable:1; //电流阈值使能
  563. uint16_t power_enable:1; //功率阈值使能
  564. uint16_t consumption_cur_enable:1; //功耗阈值使能
  565. uint32_t voltage_upper_threshold; //
  566. uint32_t voltage_lower_threshold;
  567. uint32_t current_upper_threshold;
  568. uint32_t power_upper_threshold;
  569. uint32_t consumption_threshold;
  570. };
  571. //设备总体管理
  572. typedef struct
  573. {
  574. sqlite3* db; //数据库接口
  575. pthread_mutex_t dbThreadlock; //写入线程锁
  576. pthread_t appweb_thread; //appweb线程
  577. pthread_t dev_samp_thread;//电源采集与控制线程
  578. unsigned char view_page ; //前端切换页面 1->总体信息 2->通道信息
  579. pthread_t dev_update_thread;//电源采集与控制线程
  580. pthread_t io_thread; //IO采集线程
  581. pthread_t sensor_thread; //传感器采集现成
  582. bool dev_samp_flag ; //电源采集线程标志
  583. GlobalDeviceInfo* _global_device_info; //设备管理信息
  584. GlobalPowerManger _globalPowerManger; //电源管理表
  585. GlobalSensorManger _globalSensorManger; //传感器管理表
  586. Modbus_Manger sensor_modbus_manager; //通信接口管理
  587. unsigned int useSlaveCount ; //有效地址
  588. Modbus_Manger _globalRelaySampManger; //内部继电器使用
  589. unsigned char uart_init_flag[6] ; //
  590. bool ws_isok; //ws准备好
  591. struct mg_connection *ws_client; //websocket管理信息
  592. HashTable* _global_alarmLanguage; //全局的报警映射
  593. int nTreeACLshow; //三项总数据显示L1=0,L2=1,L3=2
  594. pthread_t snmp_agent_thread;//SNMP代理线程
  595. bool _ReloadChm_flag; //重新加载端口数据
  596. GlobalPowerCtrlBoard _all_ctrl_board[16]; //所有控制板
  597. LowConf* _RS485LowConfData;//485Data
  598. //传感器
  599. struct modbus_slave_read_reg g_modebus_read;
  600. struct modbus_slave_write_reg g_modebus_write;
  601. smartPDU_shm_data* g_shm_Data;
  602. }GlobalDeviceManager;
  603. GlobalDeviceManager __globalDeviceManage;
  604. GlobalDeviceManager __globalDeviceManage2;
  605. NTPClient* globalNTPclient;
  606. bool bStopNTPthread;
  607. pthread_t NTPthread;
  608. unsigned long __globalSxIdx;
  609. _User_Log _GlobalUserLoginInfo;//全局用户登录信息
  610. UserInfo _GlobalUserInfoNew;////最近登录的信息
  611. char _GlobalUserToken[64];////最近登录的信息
  612. void initLogger(void);
  613. //打印设备信息结构
  614. void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo);
  615. //打印设备超限电源管理
  616. void printf_global_power_manage_info(GlobalPowerManger* _globalPowerManger);
  617. //打印设备超限电源通道管理
  618. //void printf_global_power_chn_manage_info(GlobalPowerChnManger* _globalPowerChnManger);
  619. void printf_power_info(GlobalPowerInfo* _globalPowerInfo);
  620. int getTotalMemorySize(unsigned int* totalSize);
  621. char* getLocalIpAddress(char* dev);
  622. char* get_mac_address(const char *iface_name) ;
  623. void get_disk_occupy(char ** reused);
  624. int set_local_timeandzone(struct tm* t, int zone);
  625. char* getUserNamebyToken(char* Token);
  626. int is_process_running(const char *process_name);
  627. #endif