common.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  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 <sys/wait.h>
  26. #include "cfg.h"
  27. #include <iconv.h>
  28. #define MAX_RELAY_CHN 100
  29. //是否在OS环境下运行
  30. #define OS_HANDWARE 1
  31. #define WEB_ROOT "../web"
  32. #define PARAS_FILE "pduParas"
  33. #define DATABASE_NAME "pdu_dat.db"
  34. #define DATABASE_BAK_NAME "pdu_dat_bak.db"
  35. #define SNMP_MIB_NAME "pduMIB"
  36. #define INI_FILE_NAME "smartPDU.ini"
  37. #define INI_FILE_BAK_NAME "smartPDU_bak.ini"
  38. #define PH_INI_FILE_NAME "smartPDU_PhList.ini"
  39. #define CHANGES_NAME "changes.txt"
  40. #define SERV_CFG_NAME "service.ini"
  41. #define SENSOR_CFG_NAME "sensor.ini"
  42. #define ALARM_CFG_NAME "alarm.ini"
  43. #define INFO_FILE_PATH "/usr/share/PDUInfo.txt"
  44. #if (CHIP_TYPE == CHIP_T113s)
  45. //控制板通信串口
  46. #define INTERL_MODBUS_PORT "/dev/ttyS4"
  47. #define INTERL_MODBUS_BAUD 115200
  48. //表头级联通讯串口
  49. #define CASCADE_MODBUS_PORT "/dev/ttyS5"
  50. #define CASCADE_MODBUS_BAUD 115200
  51. //传感器通信串口
  52. #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyS1"
  53. #define INTERL_SENSOR_MODBUS_BAUD 9600
  54. #else
  55. //高配表头串口定义-----------------------------------------------
  56. //控制板通信串口
  57. #define INTERL_MODBUS_PORT "/dev/ttyAS5"
  58. #define INTERL_MODBUS_BAUD 115200
  59. //表头级联通讯串口
  60. #define CASCADE_MODBUS_PORT "/dev/ttyAS4"
  61. #ifdef NORTH_USER_SPECILS
  62. #define CASCADE_MODBUS_BAUD 9600
  63. #else
  64. #define CASCADE_MODBUS_BAUD 115200
  65. #endif
  66. //传感器通信串口
  67. #define INTERL_SENSOR_MODBUS_PORT "/dev/ttyAS2"
  68. #define INTERL_SENSOR_MODBUS_BAUD 9600
  69. #endif
  70. #define IMAGE_FOLDER "image"
  71. #define LOGO_FILE "logo.png"
  72. #define QRCODE_FILE "qrcode.png"
  73. #define CERT_FILE "ca.cert"
  74. #define SHM_NAME_5_inch_screen "/smartPDU_shm_5_inch_screen"
  75. #define USE_SHM_5_inch_screen
  76. #define AC_SINGLE_S_CUR_CHN_NUM 8
  77. #define AC_SINGLE_B_CUR_CHN_NUM 4
  78. #define AC_SINGLE_S_MAX_CHN_NUM 10 //单个控制板最大数量
  79. #define AC_SINGLE_S_MAX_ADDRESS_NUM 16 //控制板最大数量
  80. #define AC_MAX_VOLTAGE_VAL 500
  81. #define AC_MAX_CURRENT_VAL 100
  82. #define AC_MAX_POWER_VAL 100
  83. #define NOARTH_MAX_SENSOR 4
  84. #define NOARTH_MAX_DRY 4
  85. #define MAIL_RECV_MAX 10
  86. #define MQTT_SER_MAX 5
  87. enum{
  88. BREAKER_DIO = 0,
  89. BREAKER_RS485
  90. };
  91. enum
  92. {
  93. TOTAL_VOLTAGE_TYPE = 0,//统计电压类型
  94. TOTAL_CURRENT_TYPE = 1,//统计电流类型
  95. TOTAL_POWER_TYPE = 2,//统计功率类型
  96. TOTAL_POWER_CONS_TYPE = 3 //统计耗电量类型
  97. };
  98. enum
  99. {
  100. POWER_MERITORIOUS_TYPE = 0,//有功功率类型
  101. POWER_REACTIVE_TYPE = 1,//无功功率类型
  102. POWER_APPARENT_TYPE = 2 //视在功率类型
  103. };
  104. enum
  105. {
  106. SENSOR_TYPE_TEMP_HUMI = 0 , //温湿度传感器
  107. SENSOR_TYPE_SMOKE = 1 , //烟雾传感器
  108. SENSOR_TYPE_WATER = 2 , //水浸传感器
  109. SENSOR_TYPE_ACCESS = 3 , //门禁传感器
  110. SENSOR_TYPE_GAS = 4 , //气体传感器
  111. SENSOR_TYPE_AIR_PRESS = 5 , //气压传感器
  112. SENSOR_TYPE_AIR_COND = 6, //空条传感器
  113. SENSOR_TYPE_LEAK = 7, //泄漏传感器
  114. SENSOR_TYPE_TEMP = 8, //温度传感器
  115. SENSOR_TYPE_TEMP_DOUBLE = 9, //双温度传感器
  116. SENSOR_TYPE_PRESS = 10, //压力传感器
  117. SENSOR_TYPE_MAX,
  118. };
  119. enum {
  120. SENSOR_TYPE_TEMP_HUMI_RSWSN01PVC=0,
  121. SENSOR_TYPE_TEMP_HUMI_HKSHT301T1H536VRS485,
  122. SENSOR_TYPE_TEMP_HUMI_MAX
  123. };
  124. enum {
  125. SENSOR_TYPE_TEMP_DOUBLE_DL10BM485V24D2=0,
  126. SENSOR_TYPE_TEMP_DOUBLE_MAX
  127. };
  128. enum {
  129. SENSOR_TYPE_TEMP_BTG50H8EL3200=0,
  130. SENSOR_TYPE_TEMP_MAX
  131. };
  132. enum {
  133. SENSOR_TYPE_LEAK_XWDC01A=0,
  134. SENSOR_TYPE_LEAK_MAX
  135. };
  136. enum
  137. {
  138. SENSOR_VAL1_UPPER = 0,
  139. SENSOR_VAL1_LOWER,
  140. SENSOR_VAL2_UPPER,
  141. SENSOR_VAL2_LOWER,
  142. };
  143. enum
  144. {
  145. SENSOR_TYPE_VALUE = 0 , //传感器类型0、4、5
  146. SENSOR_TYPE_LIST //传感器类型1、2、3
  147. };
  148. static char* g_product_type_str[] = {
  149. "SmartPDU(AC)",
  150. "SmartPDU(DC)",
  151. "SmartPDU",
  152. "SmartPDU(AC_3P-IN & 3P-OUT)",
  153. "SmartPDU(AC_3P-IN & 1P-OUT)",
  154. "SmartPDU(AC_3P-IN & 1P-OUT)",
  155. "SmartPDU(AC_3P-IN & 2P-OUT)",
  156. };
  157. /// @brief 板子类型
  158. enum MODBUS_BOARD_TYPE
  159. {
  160. AC_SINGLE_S_TYPE=1,
  161. AC_SINGLE_B_TYPE,
  162. AC_MULTI_S_TYPE,
  163. AC_MULTI_B_TYPE,
  164. DC_OUT_TYPE,
  165. DC_IN_TYPE,
  166. DCPDU_TYPE,
  167. TREE_AC_TYPE, // 三相进三相出,单板最大3通道9相
  168. DOUBLE_AC_TYPE, // 两相进两相出,单板最大4通道8相
  169. };
  170. enum AppProductType
  171. {
  172. SmartPDU_AC=0,
  173. SmartPDU_DC=1,
  174. SmartPDU_Tree_AC_Tree=3,
  175. SmartPDU_Tree_AC_One=4,
  176. SmartPDU_Tree_AC_One_B=5,
  177. SmartPDU_Tree_AC_Two=6,
  178. };
  179. /// @brief 三相网页数据
  180. static char* g_product_t_ac_type_str[3] = {
  181. "L1",
  182. "L2",
  183. "L3",
  184. };
  185. /// @brief 按位标记
  186. enum BIT_CTRL
  187. {
  188. BIT_00 = 1 ,
  189. BIT_01 = 2 ,
  190. BIT_02 = 4 ,
  191. BIT_03 = 8 ,
  192. BIT_04 = 16,
  193. BIT_05 = 32,
  194. BIT_06 = 64,
  195. BIT_07 = 128,
  196. BIT_08 = 256,
  197. BIT_09 = 512,
  198. BIT_10 = 1024,
  199. BIT_11 = 2048,
  200. BIT_12 = 4096,
  201. BIT_13 = 8192,
  202. BIT_14 = 16384,
  203. BIT_15 = 32768,
  204. };
  205. /// @brief 使能位
  206. enum ENABLE_BIT_CTRL
  207. {
  208. ENABLE_V_UP = 2 ,
  209. ENABLE_V_DOWN = 8 ,
  210. ENABLE_A_UP = 32,
  211. ENABLE_W_UP = 128,
  212. ENABLE_P_UP = 512,
  213. ENABLE_ALL_UP = BIT_11,
  214. ENABLE_ALL_DOWN = BIT_12,
  215. };
  216. /// @brief 使能位三项
  217. enum ENABLE_TreeAC_CTRL
  218. {
  219. ENABLE_TAC_V_UP = BIT_01,
  220. ENABLE_TAC_V_DOWN = BIT_02,
  221. ENABLE_TAC_A_UP = BIT_03,
  222. ENABLE_TAC_W_UP = BIT_04,
  223. ENABLE_TAC_P_UP = BIT_05,
  224. ENABLE_TAC_STIME = BIT_06,
  225. ENABLE_TAC_ETIME = BIT_07,
  226. };
  227. /// @brief 报警位
  228. enum WARNING_BIT_CTRL
  229. {
  230. WARNING_V_UP = 4 ,
  231. WARNING_V_DOWN = 16 ,
  232. WARNING_A_UP = 64,
  233. WARNING_W_UP = 256,
  234. WARNING_P_UP = 1024,
  235. };
  236. enum {
  237. ALARM_TYPE_POWER=0,
  238. ALARM_TYPE_SENSOR,
  239. ALARM_TYPE_NETWORK,
  240. ALARM_TYPE_OPRATION,
  241. ALARM_TYPE_RUNNING,
  242. };
  243. enum {
  244. NETWORK_MAC_CHANGED=0,
  245. NETWORK_IP_CHANGED,
  246. };
  247. /// @brief 报警动作
  248. enum ALARM_CTRL
  249. {
  250. ALARM_CTRL_CLOSE_CH = 1 ,
  251. ALARM_CTRL_ALARM_ONLY = 2 ,
  252. ALARM_CTRL_CLOSE_ALLCH = 3 ,
  253. };
  254. enum {
  255. MODBUS_MASTER=0,
  256. MODBUS_SLAVE,
  257. };
  258. enum {
  259. LANG_ID_CHINESE=0,
  260. LANG_ID_ENGLISH,
  261. LANG_ID_RUSSIAN,
  262. LANG_ID_SPANISH,
  263. LANG_ID_PORTYGYESE,
  264. LANG_ID_GERMAN,
  265. LANG_ID_FRENCH,
  266. LANG_ID_ITALIAN,
  267. LANG_ID_JAPANESE,
  268. LANG_ID_MAX
  269. };
  270. ///////////////////////////////////////////////////////////////////////////////////
  271. typedef struct {
  272. int id;
  273. int up;
  274. char ip[48];
  275. char mac[24];
  276. char desc[64];
  277. }port_info_t;
  278. typedef struct {
  279. #define SW_PORT_MAX 28
  280. port_info_t port[SW_PORT_MAX];
  281. }netswitch_info_t;
  282. ///////////////////////////////////////////////////////////////////////////////////
  283. //modbus信息管理
  284. typedef struct
  285. {
  286. bool mode ; //0: master 1slave
  287. unsigned char addr;
  288. unsigned int baudrate ; //波特率
  289. char path[32] ; //device path
  290. }ModbusInfo_t;
  291. typedef struct
  292. {
  293. int mode; //0:dhcp 1:static
  294. char ip_address[64] ; //ip地址
  295. char mask[64]; //子网掩码
  296. char gateway[64]; //网关
  297. char dns1[64]; //dns1
  298. char dns2[64]; //dns2
  299. }NetworkInfo_t;
  300. /// @brief 用户登录
  301. typedef struct
  302. {
  303. char user_name[64];
  304. char user_password[64];
  305. char user_uuid[64];
  306. char user_token[64];
  307. struct list_head list;
  308. }_User_Log;
  309. typedef struct {
  310. uint32_t id; //产品ID
  311. char pname[32]; //产品名称
  312. char pnumber[32]; //产品编号
  313. char status[32]; //产品状态
  314. char name[32]; //设备名称
  315. char number[32]; //设备编号
  316. char date[32]; //设备生产日期
  317. char batch[32]; //设备生产批次
  318. uint8_t type; //产品类型
  319. uint8_t pwr_type; //电源类型
  320. char version[8]; //软件版本
  321. uint8_t language; //多国语言
  322. uint8_t count; //级联设备数
  323. uint32_t samp_time; //采集周期 单位ms
  324. uint32_t save_time; //采集周期 单位ms
  325. uint16_t ph_group; //三组相数
  326. uint16_t ch_delay; //通道延时
  327. }ProductInfo_t;
  328. typedef struct {
  329. int monway; //1:总检测 2:分监分控 3:分监不控
  330. int netsw;
  331. int nwire;
  332. int ipv4;
  333. int ipv6;
  334. int brdupg;
  335. }WebcfgInfo_t;
  336. typedef struct {
  337. int watchdog;
  338. int flip_time;
  339. int led;
  340. int beep;
  341. uint32_t interval; //led beep 时间间隔
  342. uint32_t duption; //led beep 持续时间
  343. int rotate;
  344. int radius;
  345. }MiscInfo_t;
  346. // 4G网络及GPS信息
  347. typedef struct
  348. {
  349. int id;
  350. int use;
  351. char account[64];
  352. }sms_recv_t;
  353. typedef struct {
  354. uint8_t broad_enable;
  355. uint16_t broadcast_port;
  356. uint16_t mulcast_port;
  357. char boardcast_ip[64];
  358. char mulcast_ip [64];
  359. // char cmd[128];
  360. }mulcast_t;
  361. typedef struct
  362. {
  363. bool Cellular_enable; // 4G模块启用状态
  364. int mode; // 4G模块默认模式
  365. bool Link_status; // 4G网络连接状态
  366. int Signal_strength; // 信号强度
  367. char Cellular_name[32];// 4G网络运营商名称
  368. char apn[32];// APN接入点名称
  369. char username[32];
  370. char password[32];
  371. char Cellular_Num[32]; // 电话号码
  372. char ipv4[16];
  373. char ipv6[64];
  374. bool GPS_status; // GPS功能启用
  375. char GPS_utc[64];// UTC时间
  376. float GPS_latitude;// 纬度,范围-89.99999~89.99999
  377. float GPS_longitude;// 精度,范围-179.99999~179.99999
  378. float GPS_altitude;// 海拔高度,单位m
  379. float GPS_speed;//地面速率,单位km/h
  380. int GPS_nsat;//卫星数量
  381. bool SMS_status; // 短信功能启用
  382. sms_recv_t sms_recv[MAIL_RECV_MAX];// 短信接收信息
  383. } CellInfo_t;
  384. // WIFI信息
  385. typedef struct
  386. {
  387. bool WIFI_enable; // WIFI模块启用状态
  388. int mode; // WIFI模块启用状态
  389. bool Link_status; // wifi网络连接状态
  390. char WIFI_ip[64]; // wifi ip address
  391. char WIFI_name[64];// WIFI网络SSID名称
  392. char WIFI_code[64];// WIFI密码
  393. } WIFIInfo_t;
  394. typedef struct {
  395. char name[256];
  396. char site[256];
  397. char mail[256];
  398. char addr[256];
  399. char tele[32];
  400. }ServiceInfo_t;
  401. typedef struct
  402. {
  403. int voltage;
  404. int current;
  405. int power;
  406. int brdMax;
  407. }PowerTotal_t;
  408. typedef struct
  409. {
  410. ModbusInfo_t relay; //继电器控制端口
  411. NetworkInfo_t network; //网络信息
  412. ModbusInfo_t cascade; //级联端口
  413. ProductInfo_t product; //产品信息
  414. PowerTotal_t ptotal;
  415. WebcfgInfo_t webcfg;
  416. ServiceInfo_t service; //服务信息
  417. MiscInfo_t misc;
  418. CellInfo_t cell;
  419. WIFIInfo_t wifi;
  420. mulcast_t broadcast; //udp 广播
  421. }GlobalDeviceInfo;
  422. ///////////////////////////////////////////////////////////////////////////////////
  423. //自定义共享内存类
  424. typedef struct
  425. {
  426. //电源数据
  427. int bPDUSet;
  428. int nSelectPowerCH;
  429. int nMaxCh;
  430. float fV;
  431. float fA;
  432. float fW;
  433. float fF;
  434. float fS;
  435. int nStatus;
  436. //传感器数据
  437. int nSelectSensor;
  438. float fT;//温度
  439. float fH;//湿度
  440. float fCO2;//co2
  441. char strVer[20];//版本号
  442. //三项数据
  443. int bT_ACType;//三相类型
  444. int nSelectPh;//当前通道的三相ph参数:0:A相 1:B相 2:C相 -1通道总计
  445. //报警列表 0表示空,1表示写入,2表示已确认可清空。
  446. int nTypeCtrlType[10];
  447. char strMSG[10][64];
  448. } smartPDU_shm_data;
  449. //消息队列头结构体定义
  450. enum MsgCtrlType
  451. {
  452. Msg_Ch_Ctrl=1, //通道控制
  453. Msg_All_Ctrl=2, //整体控制
  454. Msg_Threshold_Set=3, //阈值设置
  455. Msg_Threshold_Update=4, //阈值更新
  456. };
  457. typedef struct {
  458. long MsgType; //消息方向1:Qt->PDU 2:pdu->Qt
  459. int CtrlType; //控制类型
  460. int nValue[2];
  461. // double fValue[10];
  462. }MsgData;
  463. // 消息队列线程参数结构
  464. typedef struct {
  465. int msgid; // 消息队列ID
  466. int running; // 线程运行标志
  467. bool needInit;
  468. pthread_mutex_t lock;
  469. } Msg_thread_args;
  470. ///////////////////////////////////////////////////////////////////////////////////
  471. ///////////////////////////////////////////////////////////////////////////////////
  472. //超限管理表
  473. typedef struct
  474. {
  475. int product_vol_upper_enable ;//电压上限使能
  476. float product_vol_upper_threshold ;//电压上限值
  477. int product_vol_over_upper_threshold_ctrl ;//电压超限动作
  478. int product_vol_over_upper_threshold_ctrl_para ;//电压超限关联参数
  479. int product_vol_lower_enable ;//电压下限使能
  480. float product_vol_lower_threshold ;//电压下限值
  481. int product_vol_over_lower_threshold_ctrl ;//电压超限动作
  482. int product_vol_over_lower_threshold_ctrl_para ;//电压超限动作
  483. int product_cur_upper_enable ;//电流下限使能
  484. float product_cur_upper_threshold ;//电流下限值
  485. float product_cur_lower_threshold; //
  486. int product_cur_over_upper_threshold_ctrl ;//电流超限动作
  487. int product_cur_over_upper_threshold_ctrl_para ;//电流超限动作
  488. int product_pwr_upper_enable ;//功率上限使能
  489. float product_pwr_upper_threshold ;//功率上限值
  490. int product_pwr_over_upper_threshold_ctrl ;//功率超限动作
  491. int product_pwr_over_upper_threshold_ctrl_para ;//功率超限动作
  492. int product_pwrcon_upper_enable ;//耗电量上限使能
  493. float product_pwrcon_upper_threshold ;//耗电量上限值
  494. int product_pwrcon_over_upper_threshold_ctrl ;//耗电量超限动作
  495. int product_pwrcon_over_upper_threshold_ctrl_para ;//耗电量超限动作
  496. }GlobalOverManager;
  497. /// @brief 定时管理
  498. typedef struct
  499. {
  500. char set_date[16]; //设置日期
  501. char ds_date[16]; //设置时间
  502. char ds_time[16]; //设置时间
  503. int set_stats; //状态
  504. int ds_is_triggered; //是否已触发
  505. struct list_head list;
  506. }_PowerDSManage_t;
  507. typedef struct
  508. {
  509. int firingSortno; //启动序号
  510. int closeSortno; //关闭序号
  511. }_PowerSXManage_t;
  512. typedef struct
  513. {
  514. int product_id;
  515. int mode;
  516. char ntpName[64];
  517. char ntpaddress[64];
  518. int port;
  519. char time[64];
  520. int weekday;
  521. int tzone;
  522. }NTPManager;
  523. enum {
  524. SNMP_AUTH_NONE=0,
  525. SNMP_AUTH_MD5,
  526. SNMP_AUTH_SHA,
  527. SNMP_AUTH_MAX
  528. };
  529. enum {
  530. SNMP_ENCYPT_NONE=0,
  531. SNMP_ENCYPT_DES,
  532. SNMP_ENCYPT_AES,
  533. SNMP_ENCYPT_MAX
  534. };
  535. typedef struct {
  536. char alg[12];
  537. char passwd[64];
  538. }crypt_data_t;
  539. typedef struct {
  540. char user[32];
  541. crypt_data_t auth;
  542. crypt_data_t priv;
  543. }crypt_t;
  544. typedef struct
  545. {
  546. int product_id;
  547. int mode;
  548. int version;
  549. char public[64];
  550. int trapmode;
  551. crypt_t crypt;
  552. char nmsIP[64];
  553. }SNMPManager;
  554. //分组管理
  555. typedef struct
  556. {
  557. int product_id;
  558. int GroupID;
  559. char GroupName[64];
  560. char GroupChList[512];
  561. struct list_head list;
  562. }GroupInfo;
  563. //电源部分
  564. typedef struct
  565. {
  566. float voltage ;//电压
  567. float current ;//电流
  568. float power ;//有功功率
  569. float n_power ;//无功功率
  570. float app_power ;//视在功率
  571. float freq ;//频率
  572. float consumption ;//耗电量
  573. float factor ;//功率因素
  574. unsigned short status ;//开关状态
  575. unsigned short NF_status ;//零线状态
  576. int OperAllowFlag; //操作允许标志
  577. port_info_t port; //
  578. }PowerInfo;
  579. //电源部分报警信息
  580. typedef struct
  581. {
  582. bool w_voltage_up ;//电压上限报警
  583. bool w_voltage_down ;//电压下限报警
  584. bool w_current ;//电流上限报警
  585. bool w_power ;//功率
  586. bool w_consumption ;//耗电量
  587. bool w_phase_lossA; // 缺相报警
  588. bool w_phase_lossB; // 缺相报警
  589. bool w_phase_lossC; // 缺相报警
  590. }PowerWarningInfo;
  591. typedef struct
  592. {
  593. int nBoardID;
  594. int nLeftTac;
  595. int nRightTac;
  596. /* data */
  597. }TAC_Double_Item;
  598. //三项数据
  599. typedef struct
  600. {
  601. int product_id;
  602. int product_ch_id;
  603. int product_ph_id;
  604. int product_ph_type;//0:A相 1:B相 2:C相
  605. int product_saddr;
  606. int product_ch_addr;
  607. int product_ph_outputType;//三相控制方式1,三项2单项
  608. int product_ph_outputStatus;//该相是否输出,1输出2不输出
  609. char samp_time[64]; //采集时间
  610. PowerInfo _PowerInfo; //存储最新的数据(兼容三项输入)
  611. GlobalOverManager global_over_manager; //超限管理
  612. PowerWarningInfo _PowerWarninginfo; //存储报警数据(兼容三项输入)
  613. time_t product_log_time; //存储最新时间
  614. struct list_head list_Tree_AC; //存储三项数据指针
  615. }GlobalTreeACManager;
  616. //电源通道管理总表(输出)
  617. typedef struct
  618. {
  619. int product_id ;//产品ID
  620. //20240225 add
  621. int product_saddr ;//modbus地址记录
  622. int product_ch_id ;//通道号
  623. int product_ch_addr ;//通道号实际地址
  624. char product_ch_name[32] ;//通道名称
  625. int product_ch_type ;//通道类型
  626. int product_ch_status ;//通道状态
  627. int product_ch_NF_status ;//通道零线状态(三相)
  628. int product_ch_start_delay ;//通道延时
  629. int product_ch_stop_delay ;//通道延时
  630. GlobalOverManager global_over_manager ;//超限管理
  631. struct list_head list_DS; //定时设置
  632. _PowerSXManage_t* _PowerSXManage; //时序管理
  633. PowerInfo _PowerInfo; //存储最新的数据
  634. PowerWarningInfo _PowerWarninginfo ; //存储报警数据
  635. time_t product_log_time; //存储最新时间
  636. struct list_head list_Tree_AC; //存储三项数据指针
  637. struct list_head list;
  638. } GlobalPowerManger;
  639. //电源通道管理总表(输入)
  640. typedef struct
  641. {
  642. int product_id ;//产品ID
  643. //20240225 add
  644. char product_saddr ;//modbus地址记录
  645. char product_saddr_name[32] ;//输入名称
  646. char product_saddr_type ;//输入类型
  647. GlobalOverManager global_over_manager ;//超限管理
  648. PowerInfo _PowerInfo[3]; //存储最新的数据(兼容三项输入)
  649. PowerWarningInfo _PowerWarninginfo[3]; //存储报警数据(兼容三项输入)
  650. time_t product_log_time; //存储最新时间
  651. int product_MissingPH[3]; //缺相报警
  652. }GlobalPowerInManger;
  653. //电源控制板计数
  654. typedef struct
  655. {
  656. char product_saddr ;//modbus地址记录
  657. int product_number; //数量
  658. int product_type; //类型
  659. PowerInfo _PowerInfo[AC_SINGLE_S_MAX_CHN_NUM]; //存储最新的数据
  660. PowerWarningInfo _PowerWarninginfo[AC_SINGLE_S_MAX_CHN_NUM] ;//存储报警数据
  661. struct list_head list; //存储具有的通道指针
  662. GlobalPowerInManger _globalPowerInManger; //总输入数据
  663. int nLeft_phType; //左半边相类型
  664. int nRight_phType; //右半边相类型
  665. }GlobalPowerCtrlBoard;
  666. ///////////////////////////////////////////////////////////////////////////////////
  667. ///////////////////////////////////////////////////////////////////////////////////
  668. //自定义共享内存类
  669. typedef struct
  670. {
  671. //电源数据
  672. pid_t nIPD;
  673. size_t array_size;
  674. GlobalPowerCtrlBoard m_pData[];
  675. } smartPDU_shm_5_inch_data;
  676. //电源信息统计
  677. typedef struct
  678. {
  679. float ydata[60]; //value
  680. char xAxis[60][32];//时间点
  681. }GetTotalInfo;
  682. //系统总数信息
  683. typedef struct
  684. {
  685. int channel_total ;//通道总数
  686. int warn_total ;//告警总数
  687. int sensor_total ;//传感器总数
  688. int log_total ;//运行日志总数
  689. }SystemTotalInfo;
  690. //功率趋势接口
  691. typedef struct
  692. {
  693. float ydata[3][60] ;//0:有功功率;1:无功功率;2:视在功率;
  694. char xAxis[60][32] ;//时间点
  695. }PowerTrendInfo;
  696. ///////////////////////////////////////////////////////////////////////////////////
  697. ///////////////////////////////////////////////////////////////////////////////////
  698. //电源监控
  699. typedef struct
  700. {
  701. int product_id ;//产品ID
  702. char product_ch_id ;//电源通道
  703. unsigned short product_status ;//当前状态
  704. PowerInfo _power_info ;//采集值
  705. char samp_time[64] ;//采集时间
  706. GetTotalInfo _total_voltage ;//统计电压
  707. GetTotalInfo _total_current ;//统计电流
  708. GetTotalInfo _total_power ;//统计功率
  709. GetTotalInfo _total_consumption ;//统计耗电量
  710. SystemTotalInfo _system_total_info ;//系统总数信息
  711. PowerTrendInfo _power_trend_info ;//功率趋势图
  712. struct list_head list;
  713. }GlobalPowerInfo;
  714. ///////////////////////////////////////////////////////////////////////////////////
  715. ///////////////////////////////////////////////////////////////////////////////////
  716. ///////////////////////////////////////////////////////////////////////////////////
  717. ///////////////////////////////////////////////////////////////////////////////////
  718. //传感器值
  719. typedef struct
  720. {
  721. char samp_time[64] ;//采集时间
  722. int product_id ;//产品ID
  723. char sensor_id ;//传感器ID
  724. float val1 ;//值1
  725. float val2 ;//值2
  726. time_t product_log_time; //存储最新时间
  727. struct list_head list;
  728. }GlobalSensorInfo;
  729. typedef struct
  730. {
  731. char samp_time[64];
  732. int product_id;
  733. char sensor_id;
  734. char sensor_name[64];
  735. float val1;
  736. float val2;
  737. }download_sensor_Info_t;
  738. typedef struct
  739. {
  740. int sensor_val1_upper_enabled ;//
  741. float sensor_val1_upper_threshold;
  742. int sensor_val1_upper_threshold_ctrl;
  743. char sensor_val1_upper_threshold_ctrl_para[512];
  744. int sensor_val1_lower_enabled ;//
  745. float sensor_val1_lower_threshold;
  746. int sensor_val1_lower_threshold_ctrl;
  747. char sensor_val1_lower_threshold_ctrl_para[512];
  748. int sensor_val2_upper_enabled ;//
  749. float sensor_val2_upper_threshold;
  750. int sensor_val2_upper_threshold_ctrl;
  751. char sensor_val2_upper_threshold_ctrl_para[512];
  752. int sensor_val2_lower_enabled ;//
  753. float sensor_val2_lower_threshold;
  754. int sensor_val2_lower_threshold_ctrl;
  755. char sensor_val2_lower_threshold_ctrl_para[512];
  756. }GlobalSensorOverManage;
  757. //传感器报警状态表
  758. typedef struct
  759. {
  760. int sensor_val1_upper;
  761. int sensor_val1_lower;
  762. int sensor_val2_upper;
  763. int sensor_val2_lower;
  764. }GlobalSensorOverInfo;
  765. //传感器管理总表
  766. typedef struct
  767. {
  768. int product_id ;//产品ID
  769. int sensor_id ;//传感器ID
  770. int sensor_type ;//传感器类型
  771. int sensor_interface_type; //接口类型
  772. char sensor_name[64] ;//传感器名称
  773. char sensor_port_name[32] ;//传感器端口号
  774. int sensor_baud ;//波特率
  775. int sensor_addr ;//modbus地址
  776. int sensor_status ;//传感器状态
  777. int sensor_val_count ;//传感器值个数
  778. int sensor_node_number ;//节点号
  779. int sensor_check_count; //值状态计数
  780. GlobalSensorInfo Cur_sensor_info ;
  781. GlobalSensorOverManage over_manager ;//超限管理
  782. GlobalSensorOverInfo warning_status;//报警状态
  783. struct list_head list;
  784. }GlobalSensorManger;
  785. ///////////////////////////////////////////////////////////////////////////////////
  786. ///////////////////////////////////////////////////////////////////////////////////
  787. ///////////////////////////////////////////////////////////////////////////////////
  788. ///////////////////////////////////////////////////////////////////////////////////
  789. ///温湿度数据信息管理
  790. typedef struct
  791. {
  792. float temperature;
  793. float humidity;
  794. }SenorTempVal;
  795. //采集KB值
  796. typedef struct
  797. {
  798. float voltage_k;//电压K
  799. float voltage_b;//电压B
  800. float current_k;//电流K
  801. float current_b;//电流B
  802. }SwitchKbVal;
  803. ///////////////////////////////////////////////////////////////////////////////////
  804. ///////////////////////////////////////////////////////////////////////////////////
  805. //MAIL管理
  806. typedef struct
  807. {
  808. int id;
  809. int use;
  810. char account[64];
  811. }mail_recv_t;
  812. typedef struct
  813. {
  814. int id;
  815. int mode; //0: open 1: close
  816. char account[64]; //用户账号
  817. char password[24]; //用户密码
  818. char server[64]; //服务器
  819. char port[10]; //端口
  820. char auth[16]; //认证方式
  821. char ca[8196]; //ca cert
  822. }mail_send_t;
  823. typedef struct
  824. {
  825. mail_send_t send;
  826. mail_recv_t recv[MAIL_RECV_MAX]; //接收账号列表
  827. }mail_info_t;
  828. enum {
  829. MQTT_PLAT_EMQX=0,
  830. MQTT_PLAT_ALIYUN,
  831. MQTT_PLAT_MAX
  832. };
  833. typedef struct {
  834. int id; //id
  835. int plat; //0: emqx 1: aliyun
  836. int mode; //0: open 1: close
  837. char proto[16]; //mqtt, mqtts, ws, wss
  838. char name[32]; //server name
  839. char server[512]; //server ip
  840. char port[10]; //server port
  841. char cid[64]; //client ID
  842. char user[64]; //
  843. char password[64];
  844. char cert[8200];
  845. int status;
  846. }mqtt_server_t;
  847. typedef struct {
  848. mqtt_server_t ser[MQTT_SER_MAX];
  849. }mqtt_info_t;
  850. typedef struct
  851. {
  852. int product_id;
  853. int userID; //用户ID
  854. char userName[32]; //用户名-登录
  855. char userPW[32]; //用户密码
  856. char nickName[32]; //用户名称
  857. int roleID; //角色ID
  858. char createTime[32]; //用户创建时间
  859. struct list_head list;
  860. }UserInfo;
  861. typedef struct
  862. {
  863. int product_id;
  864. int roleID; //角色ID
  865. char roleName[32]; //角色名称
  866. int roleLevel; //角色等级
  867. char roleAuthority[32]; //角色权限
  868. int roleSort; //显示顺序
  869. char createTime[32]; //创建时间
  870. struct list_head list;
  871. }RoleInfo;
  872. typedef struct MenuAuthority{
  873. bool PowerEnabled;
  874. bool SensorEnabled;
  875. bool AlarmEnabled;
  876. bool LogEnabled;
  877. bool UserInfoEnabled;
  878. bool CommEnabled;
  879. bool ServiceEnabled;
  880. bool MaintenanceEnabled;
  881. //1、电源监控菜单
  882. bool MonitorallEnabled;
  883. bool ChannelstatusEnabled;
  884. bool SwitchtatusEnabled;
  885. bool MonitorhistoryEnabled;
  886. //2、传感器管理菜单
  887. bool SensorStatusEnabled;
  888. bool SensorHistorylEnabled;
  889. //3、告警管理菜单
  890. bool XtjgEnabled;
  891. bool YzszEnabled;
  892. //4、日志信息菜单
  893. bool CzrzEnabled;
  894. bool YxrzEnabled;
  895. //5、用户管理菜单
  896. bool UserEnabled;
  897. bool RoleEnabled;
  898. bool MenuEnabled;
  899. //6、通信管理菜单
  900. bool WkszEnabled;
  901. bool RsszEnabled;
  902. bool CellularEnabled;
  903. bool WifiEnabled;
  904. bool BroadcastEnable;
  905. //7、服务管理菜单
  906. bool SmtpszEnabled;
  907. bool SnmpszEnabled;
  908. bool MqszEnabled;
  909. bool NtpszEnabled;
  910. bool DsszEnabled;
  911. bool SxszEnabled;
  912. bool FzszEnabled;
  913. bool RadiusEnabled;
  914. //8、设备维护菜单
  915. bool SbcqEnabled;
  916. bool GjsjEnabled;
  917. bool KzbsjEnabled;
  918. bool HhccszEnabled;
  919. bool PzdrdcEnabled;
  920. bool ShfwEnabled;
  921. bool GysbEnabled;
  922. }MenuAuthority;
  923. typedef struct CascadeDevices{
  924. int product_id; //级联设备ID modbus地址
  925. int type; //
  926. char device_name[20]; //接连设备名;
  927. float valtage; //485
  928. float current;
  929. float power;
  930. float factor;
  931. float freq;
  932. float consumption;
  933. }CascadeDevices;
  934. struct modbus_slave_read_reg{
  935. uint16_t deveice_type; //设备类型
  936. uint16_t slave_addr; //设备地址
  937. uint32_t voltage; //当前电压
  938. uint32_t current; //当前电流
  939. uint32_t power; //当前功率
  940. uint32_t consumption_cur; //耗电量
  941. uint32_t freq; //频率
  942. uint32_t factor; //功率因素
  943. uint32_t temprature; //温度值
  944. uint32_t humidity; //湿度值
  945. uint32_t warning; //告警
  946. uint16_t power_supplay_status; //供电状态
  947. uint16_t sencor_status; //传感器状态
  948. uint32_t temprature2; //温度值2
  949. uint32_t fCO2; //CO2
  950. // uint32_t Warinfo;
  951. // uint16_t sercor_type;
  952. };
  953. typedef struct cascade_pw_info{
  954. uint32_t voltage ;//电压
  955. uint32_t current ;//电流
  956. uint32_t power ;//功率
  957. uint32_t freq ;//频率
  958. uint32_t consumption ;//耗电量
  959. uint32_t factor ;//功率因素
  960. }cascade_single_chn_info; //siggle hell
  961. typedef struct temp_hum{
  962. uint16_t temperature;
  963. uint16_t humidity;
  964. }temp_hum_t;
  965. typedef uint32_t sensor_t;
  966. typedef uint16_t dry_node_t;
  967. typedef struct cascade_sensor{
  968. sensor_t s_1;
  969. sensor_t s_2;
  970. }cascade_sensor_t;
  971. #pragma pack (1)
  972. typedef struct cascade_single_mmap{
  973. uint16_t dev_chn;
  974. cascade_single_chn_info all_ch[128];
  975. uint32_t total_valtage;
  976. uint32_t total_current;
  977. uint32_t total_power;
  978. uint32_t total_consumer;
  979. temp_hum_t total_temp;
  980. uint16_t chn_status[64];
  981. uint16_t open_delay[64];
  982. uint16_t close_delay[64];
  983. //uint16_t reservers[29];
  984. cascade_sensor_t cas_sensor[4];
  985. dry_node_t d_node[4];
  986. uint16_t breaker_value;
  987. uint16_t reservers[8];
  988. uint16_t set_chn_open_delay[64];
  989. uint16_t set_chn_close_delay[64];
  990. uint16_t set_chn_switch_status[64];
  991. uint16_t set_chn_all_switch_status;
  992. }cascade_single_mmap_t;
  993. #ifdef NORTH_USER_SPECILS
  994. typedef struct cascade_north_user{
  995. uint32_t total_elec_energy;
  996. uint16_t frequency;
  997. uint16_t wire_voltage[3];
  998. uint16_t wire_current[3];
  999. uint16_t total_power;
  1000. uint16_t status_1_16;
  1001. uint16_t status_17_32;
  1002. uint16_t status_33_48;
  1003. uint16_t status_49_64;
  1004. uint16_t total_wanning;
  1005. uint16_t current_wanning;
  1006. uint16_t fault_1_16;
  1007. uint16_t fault_17_32;
  1008. uint16_t fault_33_48;
  1009. uint16_t fault_49_64;
  1010. uint16_t set_1_16;
  1011. uint16_t set_17_32;
  1012. uint16_t set_33_48;
  1013. uint16_t set_49_64;
  1014. }cascade_north_user_t;
  1015. #endif
  1016. #pragma pack ()
  1017. #pragma pack (1)
  1018. #define MAX_CHN 64
  1019. typedef struct cascade_triphasic_pw_out{
  1020. uint32_t o_voltage;
  1021. uint32_t o_current;
  1022. uint32_t o_power;
  1023. uint32_t o_consumption;
  1024. uint32_t o_status;
  1025. }cascade_triphasic_pw_out_t;
  1026. typedef struct cascade_triphasic_pw_o_chn{
  1027. cascade_triphasic_pw_out_t chn[3]; // A B C
  1028. }cascade_triphasic_pw_o_chn_t;
  1029. typedef struct cascade_triphasic_pw_in{
  1030. uint32_t i_total_voltage;
  1031. uint32_t i_total_current;
  1032. uint32_t i_total_power;
  1033. uint32_t i_total_consumption;
  1034. }cascade_triphasic_pw_in_t;
  1035. typedef struct cascade_triphasic_pw_i_total{
  1036. cascade_triphasic_pw_in_t pw_i_total[3]; // A B C
  1037. }cascade_triphasic_pw_i_total_t;
  1038. typedef struct cascade_triphasic_chn_info{
  1039. uint32_t chn_power;
  1040. uint32_t chn_freq;
  1041. uint32_t chn_consumption;
  1042. uint32_t chn_factor;
  1043. uint32_t chn_type;
  1044. }cascade_triphasic_chn_info_t;
  1045. typedef struct cascade_triphasic_mmap{
  1046. uint16_t dev_chn;
  1047. cascade_triphasic_pw_i_total_t i_total;
  1048. cascade_triphasic_chn_info_t chn_info[MAX_CHN];
  1049. cascade_triphasic_pw_o_chn_t pw_o_chn[MAX_CHN];
  1050. uint16_t temperature;
  1051. uint16_t humidity;
  1052. uint16_t chn_status[MAX_CHN];
  1053. uint16_t open_delay[MAX_CHN];
  1054. uint16_t close_delay[MAX_CHN];
  1055. cascade_sensor_t cas_sensor[4];
  1056. dry_node_t d_node[4];
  1057. uint16_t breaker_value;
  1058. uint16_t set_chn_open_delay[MAX_CHN];
  1059. uint16_t set_chn_close_delay[MAX_CHN];
  1060. uint16_t set_chn_switch_status[MAX_CHN];
  1061. uint16_t set_chn_all_switch_status;
  1062. }cascade_triphasic_mmap_t;
  1063. typedef struct
  1064. {
  1065. modbus_t *ctx;
  1066. char ip[64];
  1067. uint16_t port;
  1068. uint8_t slave_id;
  1069. uint8_t power_type;
  1070. modbus_mapping_t *map;
  1071. int connection;
  1072. //pthread_mutex_t mutex;
  1073. }Modbus_Manger_Tcp;
  1074. #pragma pack ()
  1075. struct modbus_slave_write_reg{
  1076. uint16_t voltage_high_enable:1; //电压高阈值检测使能
  1077. uint16_t voltage_low_enable:1; //电压低阈值检测使能
  1078. uint16_t current_enable:1; //电流阈值使能
  1079. uint16_t power_enable:1; //功率阈值使能
  1080. uint16_t consumption_cur_enable:1; //功耗阈值使能
  1081. uint32_t voltage_upper_threshold; //
  1082. uint32_t voltage_lower_threshold;
  1083. uint32_t current_upper_threshold;
  1084. uint32_t power_upper_threshold;
  1085. uint32_t consumption_threshold;
  1086. };
  1087. enum
  1088. {
  1089. DI,
  1090. RS485
  1091. };
  1092. enum{
  1093. SWITCH_CONNETCTED,
  1094. SWITCH_DISCONNETCTED,
  1095. SWITCH_OFFLINE
  1096. };
  1097. #define SWITCH_CHN_1_SET (1<<0)
  1098. #define SWITCH_CHN_2_SET (1<<1)
  1099. #define SWITCH_CHN_3_SET (1<<2)
  1100. #define SWITCH_CHN_4_SET (1<<3)
  1101. #define SWITCH_CHN_5_SET (1<<4)
  1102. #define SWITCH_CHN_6_SET (1<<5)
  1103. #define SWITCH_CHN_DI_1_SET (1<<6)
  1104. #define SWITCH_CHN_DI_2_SET (1<<7)
  1105. typedef struct {
  1106. int id;
  1107. int type;
  1108. char date[32];
  1109. char content[128];
  1110. }alarm_data_t;
  1111. typedef struct {
  1112. int ch;
  1113. char date[16];
  1114. char time[16];
  1115. int status;
  1116. int triggered;
  1117. }timer_data_t;
  1118. typedef struct {
  1119. int addr;
  1120. char name[32];
  1121. char ver[32];
  1122. char date[32];
  1123. int dev_id;
  1124. int brd_id;
  1125. int channels;
  1126. int status;
  1127. }board_info_t;
  1128. typedef struct breaker_switch_sta{
  1129. uint16_t status;
  1130. uint16_t gather;
  1131. char com[30];
  1132. uint8_t product_name[256];
  1133. }breaker_switch_sta_t;
  1134. typedef struct GlobalBreakerManger{
  1135. uint32_t all_count;
  1136. uint32_t online_count;
  1137. uint32_t mask;
  1138. uint8_t saddr;
  1139. void *manager;
  1140. breaker_switch_sta_t sta[8]; // 6 + 2
  1141. pthread_mutex_t b_mutex;
  1142. }GlobalBreakerManger;
  1143. typedef struct GlobalBreakerManager{
  1144. uint32_t product_id;
  1145. uint32_t breaker_id;
  1146. uint32_t breaker_chn;
  1147. uint32_t breaker_status;
  1148. uint32_t breaker_gather_addr;
  1149. char breaker_switch_name[128];
  1150. char breaker_com[64];
  1151. char breaker_gather_type[64];
  1152. char breaker_chns_name[128];
  1153. struct list_head list;
  1154. }GlobalBreakerManager;
  1155. //设备总体管理
  1156. typedef struct
  1157. {
  1158. sqlite3* db; //数据库接口
  1159. pthread_mutex_t dbThreadlock; //写入线程锁
  1160. pthread_t appweb_thread; //appweb线程
  1161. pthread_t dev_samp_thread;//电源采集与控制线程
  1162. pthread_t dev_update_thread;//电源采集与控制线程
  1163. pthread_t io_thread; //IO采集线程
  1164. pthread_t sensor_thread; //传感器采集现成
  1165. bool dev_samp_flag ; //电源采集线程标志
  1166. GlobalDeviceInfo _globalDevInfo; //设备管理信息
  1167. GlobalPowerManger _globalPowerManger; //电源管理表
  1168. GlobalSensorManger _globalSensorManger; //传感器管理表
  1169. Modbus_Manger sensor_modbus_manager; //通信接口管理
  1170. unsigned int useSlaveCount ; //有效地址
  1171. Modbus_Manger _globalRelaySampManger; //内部继电器使用
  1172. unsigned char uart_init_flag[6] ; //
  1173. bool ws_isok; //ws准备好
  1174. struct mg_connection *ws_client; //websocket管理信息
  1175. HashTable* alarmTab; //全局的报警映射
  1176. int nTreeACLshow; //三项总数据显示L1=0,L2=1,L3=2
  1177. pthread_t snmp_agent_thread;//SNMP代理线程
  1178. bool _ReloadChm_flag; //重新加载端口数据
  1179. int brdMax;
  1180. GlobalPowerCtrlBoard *pCtrlBoard; //所有控制板
  1181. LowConf* _RS485LowConfData;//485Data
  1182. //传感器
  1183. struct modbus_slave_read_reg g_modebus_read;
  1184. struct modbus_slave_write_reg g_modebus_write;
  1185. smartPDU_shm_data* g_shm_Data;
  1186. int g_lastAlarmIndex; //最后一次报警索引位置
  1187. pthread_mutex_t _power_ds; //定时器锁
  1188. pthread_mutex_t _power_update; //数据刷新锁
  1189. pthread_mutex_t _sensor_update; //传感器刷新锁
  1190. pthread_mutex_t _breaker_mutex; // breaker info
  1191. cascade_single_mmap_t *single_mmap;
  1192. cascade_triphasic_mmap_t *triphasic_mmap;
  1193. GlobalBreakerManager g_new_global_breaker;
  1194. mail_info_t mailInfo;
  1195. mqtt_info_t mqttInfo;
  1196. Modbus_Manger_Tcp *md_tcp;
  1197. Msg_thread_args _MSG_args;
  1198. uint8_t upgread_flag;
  1199. #ifdef NORTH_USER_SPECILS
  1200. cascade_north_user_t north_user;
  1201. #endif
  1202. }GlobalDeviceManager;
  1203. extern GlobalDeviceManager __globalDeviceManage;
  1204. extern GlobalDeviceManager __globalDeviceManage2;
  1205. extern int ntp_sync_flag;
  1206. extern unsigned long __globalSxIdx;
  1207. extern _User_Log _GlobalUserLoginInfo;//全局用户登录信息
  1208. extern UserInfo _GlobalUserInfoNew;////最近登录的信息
  1209. extern char _GlobalUserToken[64];////最近登录的信息
  1210. extern MenuAuthority _GlobalMenuAuthority;////角色菜单权限
  1211. extern NTPManager _globalNTPManager;
  1212. extern SNMPManager _globalSNMPManager;
  1213. extern int SMS_SEND_COUNT;
  1214. extern char DS_QueryDate[32];
  1215. void initLogger(void);
  1216. //打印设备信息结构
  1217. void printf_global_device_info(GlobalDeviceInfo* _globalDeviceInfo);
  1218. //打印设备超限电源管理
  1219. void printf_global_power_manage_info(GlobalPowerManger* _globalPowerManger);
  1220. //打印设备超限电源通道管理
  1221. //void printf_global_power_chn_manage_info(GlobalPowerChnManger* _globalPowerChnManger);
  1222. void printf_power_info(GlobalPowerInfo* _globalPowerInfo);
  1223. int getTotalMemorySize(unsigned int* totalSize);
  1224. char* getLocalIpAddress(char* dev);
  1225. char *getLocalMask(char *dev);
  1226. char *getLocalGateway(char *dev);
  1227. char* get_mac_address(const char *iface_name) ;
  1228. void get_disk_occupy(char ** reused);
  1229. int get_tzone(void);
  1230. int set_tzone(int tzone);
  1231. int set_time(struct tm *t, int tzone);
  1232. int set_utctime(time_t t);
  1233. int set_time_zone(struct tm *t, int tzone);
  1234. int set_utctime_zone(time_t t, int tzone);
  1235. time_t mktime0(void);
  1236. time_t mktime2(struct tm *t, int tzone);
  1237. int get_time_str(char *s, int len, time_t t);
  1238. int get_time_str2(char *s, int len, time_t t);
  1239. int get_curtime_str(char *s, int len);
  1240. int get_curtime_str2(char *s, int len);
  1241. int get_bldtime(char *buf, int len);
  1242. int get_bldtime2(char *dst, char *ori);
  1243. void print_time(char *s, struct tm *tm);
  1244. void print_utc(char *s, time_t t);
  1245. int is_process_running(const char *process_name);
  1246. // 辅助函数:判断是否是闰年
  1247. int is_leap_year(int year);
  1248. // 辅助函数:获取某月的天数
  1249. int days_in_month(int year, int month);
  1250. // 函数:增加一天到日期
  1251. void add_day_to_date(char *date_str, int *year, int *month, int *day);
  1252. char* utf8_to_unicode_string(const char* utf8_str) ;
  1253. int chinese_to_ucs2(const char* utf8_str, char* ucs2_hex, size_t ucs2_hex_size);
  1254. void SetMenuAuthority(int RoleID);
  1255. void InitCellularManager();
  1256. #endif