common.h 52 KB

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