json_handle.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. #ifndef __JSON_HANDLE_H
  2. #define __JSON_HANDLE_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <stdbool.h>
  8. #include "list.h"
  9. #include "common.h"
  10. #include "cJSON.h"
  11. /// @brief 获取用户信息
  12. typedef struct
  13. {
  14. char* user_token;
  15. }_Get_Info_Request;
  16. /// @brief 电压、电流、功率、耗电量统计接口
  17. typedef struct
  18. {
  19. float ydata[60]; //value
  20. char xAxis[60][32];//时间点
  21. }_Get_Total_Value;
  22. /// @brief 系统总数信息
  23. typedef struct
  24. {
  25. int channel_total ;//通道总数
  26. int warn_total ;//告警总数
  27. int sensor_total ;//传感器总数
  28. int log_total ;//运行日志总数
  29. }_Get_System_Total;
  30. //功率趋势接口
  31. typedef struct
  32. {
  33. float ydata[3][60] ;//0:有功功率;1:无功功率;2:视在功率;
  34. char xAxis[60][32] ;//时间点
  35. }_Power_Trend_Info;
  36. /// @brief 总体设备信息
  37. typedef struct
  38. {
  39. char* user_token;
  40. char* type; //listInfoQuery listQuery open close listHisQuery
  41. char* product_name;
  42. int product_id;
  43. char* product_number;
  44. char* start_time;
  45. char* end_time;
  46. char* page_num;
  47. char* page_size;
  48. int product_pwr_type;
  49. char* product_phOrder;
  50. char* lType; //L1 L2 L3
  51. }_Over_All_Sts_Monitor;
  52. /// @brief 总设备信息返回
  53. typedef struct
  54. {
  55. char *product_name;
  56. int product_id;
  57. char *product_number;
  58. char *product_Code;
  59. char *product_type;
  60. int product_type_id;
  61. char *productVersion; // 固件版本
  62. char *product_status;
  63. char *product_sysTime;
  64. char *product_runTime;
  65. char *productPwrType;
  66. char *productAddr; // IP地址
  67. char *product_mac;
  68. int product_RS485Addr;
  69. int productMemory; // 内存
  70. char *occupancyRate; // 磁盘占用率
  71. char productCount; // 级联设备数
  72. _Get_System_Total system_total;
  73. }_OverBackStsInfo;
  74. /// @brief breaker device information
  75. typedef struct
  76. {
  77. char *product_name;
  78. int product_id;
  79. char *product_number;
  80. char product_type;
  81. }_OverBackBreakerInfo;
  82. /// @brief breaker channel list information
  83. typedef struct
  84. {
  85. char product_name[32];
  86. int product_id;
  87. char product_number[32];
  88. char product_ch_name[32];
  89. int product_ch_id;
  90. struct list_head list;
  91. }_OverBreakerChnInfo;
  92. /// @brief breaker channel switch information
  93. typedef struct
  94. {
  95. char productName[32];
  96. char product_number[32];
  97. int product_id;
  98. char product_ch_name[32];
  99. int product_ch_id;
  100. int status;
  101. int switch_id;
  102. char switch_name[64];
  103. char cjfs[20];
  104. char comkh[20];
  105. char cjdz[20];
  106. char jdh[20];
  107. char productChids[64];
  108. struct list_head list;
  109. }_OverBreakerSwitchInfo;
  110. /// @brief 电源总体监控请求信息
  111. typedef struct
  112. {
  113. char* user_token;
  114. char* type;
  115. char* product_name;
  116. char* product_number;
  117. }_OverAllPwrRequest;
  118. /// @brief 电源通道监控请求信息
  119. typedef struct
  120. {
  121. char* user_token;
  122. char* type;
  123. char* lType;
  124. char* product_name;
  125. int product_id;
  126. char* productChName;
  127. int productChId;
  128. char* start_time;
  129. char* end_time;
  130. char* pageNum;
  131. char* pageSize;
  132. char* ChannelLoadType;
  133. int productType;
  134. char* productPhOrder;
  135. int outputType;
  136. char* Zerotype;
  137. char* strProductChIds;
  138. }_OverChnPwrRequest;
  139. /// @brief 总体电源返回信息
  140. typedef struct
  141. {
  142. char* product_name;
  143. char* product_number;
  144. int product_id;
  145. char* productChName;
  146. char productChId;
  147. int status;
  148. int NF_status;
  149. char* mac_addr;
  150. char* ip_addr;
  151. float voltage ;//电压
  152. float current ;//电流
  153. float power ;//功率
  154. float freq ;//频率
  155. float consumption ;//耗电量
  156. float factor ;
  157. unsigned short product_ch_start_delay ;//通道延时
  158. unsigned short product_ch_stop_delay ;//通道延时
  159. int product_type; //通道类型
  160. int product_phType; //三相类型
  161. float ph_voltage ;//电压
  162. float ph_current ;//电流
  163. float ph_power ;//功率
  164. float ph_consumption ;//耗电量
  165. int ph_outputType ;//输出类型
  166. int ph_outputStatus ;//输出状态-该通道是否输出
  167. #if IS_IP
  168. float temperature;
  169. float humidity;
  170. #endif
  171. struct list_head list;
  172. }_OverChnPwrAckInfo;
  173. /// @brief 总体电源返回信息
  174. typedef struct
  175. {
  176. char* product_name;
  177. char* product_number;
  178. int product_id;
  179. float voltage ;//电压
  180. float current ;//电流
  181. float power ;//功率
  182. float freq ;//频率
  183. float consumption ;//耗电量
  184. float factor ;//功率因素
  185. _Get_Total_Value _total_voltage ;//电压统计
  186. _Get_Total_Value _total_current ;//电流统计
  187. _Get_Total_Value _total_power ;//功率统计
  188. _Get_Total_Value _total_consumption ;//耗电量统计
  189. _Power_Trend_Info _Power_Trend_Info ;//有功、无功、视在功率统计
  190. }_OverAllPwrAckInfo;
  191. /// @brief 传感器总体请求信息
  192. typedef struct
  193. {
  194. float ydata[2][60] ;//0:温度,1:湿度;
  195. char xAxis[60][32] ;//时间点
  196. }_Sensor_Temp_Humi_Icon;
  197. typedef struct
  198. {
  199. float ydata[60] ;//气体值
  200. char xAxis[60][32] ;//时间点
  201. }_Sensor_Gas_Icon;
  202. typedef struct
  203. {
  204. float ydata[2][60] ;//0:气流,1:气压;
  205. char xAxis[60][32] ;//时间点
  206. }_Sensor_Air_Press_Icon;
  207. typedef struct
  208. {
  209. char* user_token;
  210. char* type;
  211. char* productName;
  212. char* productNumber;
  213. char* productChName;
  214. char* productChId;
  215. char* startTime;
  216. char* endTime;
  217. char* page_num;
  218. char* page_size;
  219. int sensorId;
  220. char* sensorType;
  221. char* sensorName;
  222. char* comSlogan;
  223. char* cgqtd;
  224. char* sensorAddr;
  225. char* sensorBaud;
  226. char* connectionStatus;
  227. }_OverSensorRequest;
  228. /// @brief 传感器应答状态
  229. typedef struct
  230. {
  231. int accessControlStatus;
  232. char sensorAddr;
  233. int nodeNumber;
  234. float airPressureValue;
  235. float airflowValue;
  236. int alarmStatus;
  237. int sensorBaud;
  238. char comSlogan[32];
  239. int connectionStatus;
  240. float gasConcentration;
  241. float humidityValue;
  242. float temperatureValue;
  243. char sensorName[64];
  244. char sensorId;
  245. char sensorType;
  246. int waterImmersionState;
  247. char sensorvaluech[32];
  248. float temperatureValue2;
  249. _Sensor_Temp_Humi_Icon temp_humi_sensor;
  250. _Sensor_Gas_Icon gas_sensor;
  251. _Sensor_Air_Press_Icon air_press_sensor;
  252. struct list_head list;
  253. }_OverSensorBackInfo;
  254. /// @brief 电源类阈值设置
  255. typedef struct
  256. {
  257. char* alarmContentUpperValue;
  258. char* currentUpperValue;
  259. char* powerUpperValue;
  260. char productChId;
  261. char* productChName;
  262. char* voltageDownValue;
  263. char* voltageUpperValue;
  264. bool bUpdatealarmContentUpperValue;
  265. bool bUpdatecurrentUpperValue;
  266. bool bUpdatepowerUpperValue;
  267. bool bUpdatevoltageDownValue;
  268. bool bUpdatevoltageUpperValue;
  269. char* currentUpperAction;
  270. char* voltageUpperAction;
  271. char*voltageDownAction;
  272. char* powerUpperAction;
  273. char* alarmContentUpperAction;
  274. }_Power_AlarmRequestInfo;
  275. /// @brief 传感器类阈值设置
  276. typedef struct
  277. {
  278. char* connectionStatus ;
  279. int sensorId;
  280. char* sensorName;
  281. char* sensorType;
  282. char* thresholdType;
  283. char* thresholdDownValue;
  284. char* thresholdUpperValue;
  285. char *thresholdDownAction;
  286. char *thresholdUpperAction;
  287. char *thresholdUpperChanel;
  288. char *thresholdDownChanel;
  289. }_Sensor_AlarmRequestInfo;
  290. /// @brief 告警信息查询
  291. typedef struct
  292. {
  293. char* user_token;
  294. char* type;
  295. int pagenum;
  296. int pagesize;
  297. _Power_AlarmRequestInfo _pwr_info;
  298. _Sensor_AlarmRequestInfo _sensor_info;
  299. char* strProductChIds;
  300. }_AlarmRequestInfo;
  301. /// @brief 告警响应信息
  302. typedef struct
  303. {
  304. char alarmNumber[16];
  305. char alarmDate[32];
  306. char alarmType;
  307. char deviceNumber[16];
  308. char deviceName[32];
  309. char alarmContent[128];
  310. struct list_head list;
  311. }_AlarmAckInfo;
  312. /// @brief SMPT服务信息
  313. typedef struct
  314. {
  315. char* mode;
  316. char* account;
  317. char* password;
  318. char* server;
  319. char* port;
  320. char* auth;
  321. char* recvAccount[SMTP_RECV_MAX];
  322. }_SMTP_ServerRequestInfo;
  323. /// @brief SNMP信息
  324. typedef struct
  325. {
  326. char *mode;
  327. char *version;
  328. char *public;
  329. char *trapmode;
  330. char *user;
  331. char *auth_alg;
  332. char *auth_passwd;
  333. char *priv_alg;
  334. char *priv_passwd;
  335. char *nms_IP;
  336. }_SNMP_ServerRequestInfo;
  337. /// @brief SNMP TRAP信息
  338. typedef struct
  339. {
  340. char* mode;
  341. char* stType;
  342. }_SNMPTRAP_ServerRequestInfo;
  343. /// @brief NTP信息
  344. typedef struct
  345. {
  346. char* mode;
  347. char* ntpName;
  348. char* ntpaddress;
  349. char* port;
  350. char* time;
  351. char* weekday;
  352. char* tzone;
  353. }_NTP_ServiceRequestInfo;
  354. /// @brief 定时设置
  355. typedef struct
  356. {
  357. char* productChName;
  358. char* productChId;
  359. int productChIds[64];
  360. char* idx[64];
  361. char* channelDate;
  362. char* StartDate;
  363. char* Enddate;
  364. char* channelTime;
  365. char* setStatus;
  366. }_DS_ServiceRequestInfo;
  367. /// @brief 时序设置
  368. typedef struct
  369. {
  370. char* productId;
  371. char* productChName;
  372. char* productChId;
  373. char* firingInterval;
  374. char* closeInterval;
  375. // char* firingInterval;
  376. // char* closeInterval;
  377. }_POSIX_ServiceRequestInfo;
  378. /// @brief 分组设置
  379. typedef struct
  380. {
  381. char* mode;
  382. char* xlnumber;
  383. char* jgnumber;
  384. char* opergroupid;
  385. }_GROUP_ServiceRequestInfo;
  386. /// @brief 服务信息查询
  387. typedef struct
  388. {
  389. char* user_token;
  390. char* type;
  391. _SMTP_ServerRequestInfo _smtp_info ;
  392. _SNMP_ServerRequestInfo _snmp_info ;
  393. _SNMPTRAP_ServerRequestInfo _snmp_trap_info;
  394. _NTP_ServiceRequestInfo _ntp_info ;
  395. _DS_ServiceRequestInfo _ds_info;
  396. _POSIX_ServiceRequestInfo _posix_info;
  397. _GROUP_ServiceRequestInfo _group_info;
  398. }_ServiceManageRequestInfo;
  399. /// @brief 网络参数配置
  400. typedef struct
  401. {
  402. char* mode;
  403. char* ipaddr;
  404. char* maskaddr;
  405. char* gateway;
  406. char* dns1;
  407. char* dns2;
  408. }_NET_CommunicationRequestInfo;
  409. /// @brief RS参数配置
  410. typedef struct
  411. {
  412. char* mode;
  413. char* baud;
  414. char* addr;
  415. }_RS_CommunicationRequestInfo;
  416. /// @brief 通信信息查询
  417. typedef struct
  418. {
  419. char* user_token;
  420. char* type;
  421. _NET_CommunicationRequestInfo _net_info;
  422. _RS_CommunicationRequestInfo _rs_info;
  423. }_CommunicationManageRequestInfo;
  424. /// @brief日志信息查询
  425. typedef struct
  426. {
  427. char* user_token;
  428. char* type;
  429. char* alarmType;
  430. char* beginTime;
  431. char* endtime;
  432. int pagenum;
  433. int pagesize;
  434. char* openName;
  435. }_LogInformationRequestInfo;
  436. /// @brief 日志应答类容
  437. typedef struct
  438. {
  439. char* alarm_number;
  440. char* alarm_date;
  441. char alarm_type;
  442. int product_id;
  443. char product_name[32];
  444. char alarmContent[64];
  445. }_LogInformationAckInfo;
  446. /// @brief 设备维护
  447. typedef struct
  448. {
  449. char* user_token;
  450. char* type;
  451. char* product_name;
  452. char* product_id;
  453. char* product_number;
  454. /// @brief breaker infomation
  455. char* cjfs;
  456. char* comkh;
  457. char* cjdz;
  458. char* jdh;
  459. char* productChids;
  460. /////
  461. int switchId;
  462. char* switchName;
  463. char* cleanSelectItem;
  464. }_Equipment_Mintenance;
  465. /// @brief 用户角色管理
  466. typedef struct
  467. {
  468. char* user_token;
  469. char* type;
  470. char* createTime;
  471. int userId;
  472. char* userName;
  473. char* nickName;//用途不明?
  474. bool delFlag;//用途不明?
  475. int roleId;
  476. char* roleName;
  477. char* password;
  478. int userIds;
  479. int pagenum;
  480. int pagesize;
  481. }_UserRoleManageInfo;
  482. char* ctrl_sts_ack_to_json(void);
  483. char* ctrl_breaker_err_ack_to_json(char *string);
  484. void get_rand_str(char* s,int num);
  485. char* json_to_Token_info(const char* strHead);
  486. int json_to_User_login_info(const char* str,_User_Log* _newUserLogin);
  487. int json_to_User_loginOut_info(const char* str,char** _UserLoginOutToken);
  488. char* log_info_to_json(const char* token);
  489. char* log_LoginFailedinfo_to_json();
  490. char* log_AthFailedinfo_to_json();
  491. char* user_info_to_json(void);
  492. char* user_routers_info_to_json(void);
  493. char* json_to_system_config_info(void);
  494. cJSON* json_to_overall_status_monitor(const char* str,_Over_All_Sts_Monitor* _over_all_sts_monitor);
  495. char* over_all_monitor_to_json(_OverBackStsInfo* _over_back_sts_info);
  496. char* overall_power_history_to_json(GlobalPowerInfo* _globalPowerInfo,GlobalDeviceInfo* _globalDeviceInfo);
  497. char* over_channel_power_history_to_json(GlobalPowerInfo* _globalPowerInfo,GlobalDeviceInfo* _globalDeviceInfo,char* chn_name,char chn);
  498. cJSON* json_to_overall_pwr_status_monitor(const char* str,_OverAllPwrRequest* _over_all_pwr_request);
  499. cJSON* json_to_over_equipment_mintenance(const char* str,_Equipment_Mintenance* _over_equipment_mintenance);
  500. char* over_product_list_info_to_json(GlobalDeviceManager *dm, _OverBackStsInfo* _over_back_sts_info,bool curFlag);
  501. char* vendor_info_to_json(GlobalDeviceInfo *dev);
  502. char* over_all_pwr_monitor_to_json(int phaseType,_OverAllPwrAckInfo* _over_all_pwr_back_info);
  503. char* over_all_pwr_monitor_Tree_AC_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info_L1,_OverAllPwrAckInfo* _over_all_pwr_back_info_L2,_OverAllPwrAckInfo* _over_all_pwr_back_info_L3);
  504. char* over_all_total_info_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info, int total_type);
  505. void over_all_total_info_t_ac_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info,cJSON* dataJson,cJSON* AxisJson, int total_type);
  506. int over_init_data_t_ac_to_json(cJSON* pAllJson,cJSON* dataJson[],cJSON* AxisJson,int total_type);
  507. char* over_all_data_t_ac_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info, _Over_All_Sts_Monitor* _over_all_sts_monitor,int total_type);
  508. char* over_system_total_monitor_to_json(_OverBackStsInfo* _over_back_system_info);
  509. char* over_power_trend_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info);
  510. cJSON* json_to_chn_pwr_status_monitor(const char* str,_OverChnPwrRequest* _over_chn_pwr_request);
  511. char* over_chn_pwr_monitor_to_json(_OverChnPwrAckInfo* _over_chn_pwr_back_info);
  512. int json_to_overall_sensor_status(const char* str,_OverSensorRequest* _over_all_sensor_request);
  513. char* over_all_sensor_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_info,int nWSType);
  514. char* ws_sensor_status_ack_to_json(GlobalSensorManger* _globalSensorManger);
  515. char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_info, int sensor_type);
  516. char* alarm_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAllNumber);
  517. char* alarm_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAllNumber);
  518. char* alarm_ctrl_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAlarmNum);
  519. char* alarm_power_threshold_to_json(GlobalPowerManger* _globalPowerManger);
  520. char* alarm_sensor_threshold_to_json(GlobalSensorManger* _globalSensorManger);
  521. char* communication_net_ack_to_json(NetworkInfo_t* _networkInfo_t);
  522. char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t);
  523. char* service_ds_ack_to_json(char* chn_name,char* chn_id,_PowerDSManage_t* __powerDSManage_t);
  524. char* service_ds_all_ack_to_json(char* pDate,char* Name,char* nchID,GlobalPowerManger* __powerDSManage_t);
  525. char* service_sx_ack_to_json(int product_id, GlobalPowerManger * __PowerManage_t);
  526. char* service_ntp_ack_to_json(NTPManager* __NTPManager_t);
  527. char* service_snmp_ack_to_json(SNMPManager* sm);
  528. char* service_smtp_ack_to_json(smtp_info_t* info);
  529. char* service_mqtt_ack_to_json(mqtt_info_t* info);
  530. char* service_group_ack_to_json(GroupInfo* _globalgroupInfo);
  531. ///请求管理
  532. cJSON* json_to_sensor_manage(const char* str,_OverSensorRequest* _overSensorRequest);
  533. cJSON* json_to_alarm_manage(const char* str,_AlarmRequestInfo* _alarm_request_info);
  534. cJSON* json_to_loginformation_manage(const char* str,_LogInformationRequestInfo* _logInformationRequestInfo);
  535. cJSON* json_to_communication_manage(const char* str,_CommunicationManageRequestInfo* _communicationRequestInfo);
  536. cJSON* json_to_service_manage(const char* str,_ServiceManageRequestInfo* _serviceManageRequestInfo);
  537. cJSON* json_to_user_manage(const char* str,_UserRoleManageInfo* _UserRoleManageRequestInfo);
  538. char* ws_over_status_ack_to_json(int type,_OverAllPwrAckInfo* _over_all_pwr_back_info);
  539. char* ws_chn_status_ack_to_json(int type,_OverChnPwrAckInfo* _over_chn_pwr_back_info,GlobalDeviceManager *gdm);
  540. int json_to_switch_language(const char* str);
  541. int InitHashTable(GlobalDeviceManager *gdm);
  542. char* mem_info_to_json();
  543. int GetRoleIDByUserName(char* _userName,UserInfo* __UserInfo_t);
  544. int GetRoleLevelByID(int _RoleID,RoleInfo* __RoleInfo_t);
  545. char* GetRoleNameByID(int _RoleID,RoleInfo* __RoleInfo_t);
  546. int GetRoleIDByName(char* _RoleName,RoleInfo* __RoleInfo_t);
  547. char* service_userQuery_ack_to_json(char* _userName,UserInfo* __UserInfo_t,RoleInfo* __RoleInfo_t,char* _SelName,int pagenum,int pagesize);
  548. char* service_userRole_ack_to_json(char* _userName,UserInfo* __UserInfo_t,RoleInfo* __RoleInfo_t);
  549. char* over_breaker_product_list_info_to_json(GlobalDeviceManager *dm,_OverBackBreakerInfo* _over_back_sts_info,bool curFlag);
  550. char* over_all_breaker_chn_info_to_json(_OverBreakerChnInfo* _over_all_breaker_back_info,int nWSType);
  551. char* over_all_breaker_switch_info_to_json(_OverBreakerSwitchInfo* _over_all_breaker_switch_info,int nWSType);
  552. char *breaker_status_ack_to_json(GlobalDeviceManager *gm,int slave);
  553. int dev_get_all_profuct_chid_from_power_mgr(sqlite3 *db,uint8_t *cannnel);
  554. #endif