json_handle.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. }_OverChnPwrRequest;
  138. /// @brief 总体电源返回信息
  139. typedef struct
  140. {
  141. char* product_name;
  142. char* product_number;
  143. int product_id;
  144. char* productChName;
  145. char productChId;
  146. int status;
  147. int NF_status;
  148. char* mac_addr;
  149. char* ip_addr;
  150. float voltage ;//电压
  151. float current ;//电流
  152. float power ;//功率
  153. float freq ;//频率
  154. float consumption ;//耗电量
  155. float factor ;
  156. unsigned short product_ch_start_delay ;//通道延时
  157. unsigned short product_ch_stop_delay ;//通道延时
  158. int product_type; //通道类型
  159. int product_phType; //三相类型
  160. float ph_voltage ;//电压
  161. float ph_current ;//电流
  162. float ph_power ;//功率
  163. float ph_consumption ;//耗电量
  164. int ph_outputType ;//输出类型
  165. int ph_outputStatus ;//输出状态-该通道是否输出
  166. struct list_head list;
  167. }_OverChnPwrAckInfo;
  168. /// @brief 总体电源返回信息
  169. typedef struct
  170. {
  171. char* product_name;
  172. char* product_number;
  173. int product_id;
  174. float voltage ;//电压
  175. float current ;//电流
  176. float power ;//功率
  177. float freq ;//频率
  178. float consumption ;//耗电量
  179. float factor ;//功率因素
  180. _Get_Total_Value _total_voltage ;//电压统计
  181. _Get_Total_Value _total_current ;//电流统计
  182. _Get_Total_Value _total_power ;//功率统计
  183. _Get_Total_Value _total_consumption ;//耗电量统计
  184. _Power_Trend_Info _Power_Trend_Info ;//有功、无功、视在功率统计
  185. }_OverAllPwrAckInfo;
  186. /// @brief 传感器总体请求信息
  187. typedef struct
  188. {
  189. float ydata[2][60] ;//0:温度,1:湿度;
  190. char xAxis[60][32] ;//时间点
  191. }_Sensor_Temp_Humi_Icon;
  192. typedef struct
  193. {
  194. float ydata[60] ;//气体值
  195. char xAxis[60][32] ;//时间点
  196. }_Sensor_Gas_Icon;
  197. typedef struct
  198. {
  199. float ydata[2][60] ;//0:气流,1:气压;
  200. char xAxis[60][32] ;//时间点
  201. }_Sensor_Air_Press_Icon;
  202. typedef struct
  203. {
  204. char* user_token;
  205. char* type;
  206. char* productName;
  207. char* productNumber;
  208. char* productChName;
  209. char* productChId;
  210. char* startTime;
  211. char* endTime;
  212. char* page_num;
  213. char* page_size;
  214. int sensorId;
  215. char* sensorType;
  216. char* sensorName;
  217. char* comSlogan;
  218. char* cgqtd;
  219. char* sensorAddr;
  220. char* sensorBaud;
  221. char* connectionStatus;
  222. }_OverSensorRequest;
  223. /// @brief 传感器应答状态
  224. typedef struct
  225. {
  226. int accessControlStatus;
  227. char sensorAddr;
  228. int nodeNumber;
  229. float airPressureValue;
  230. float airflowValue;
  231. int alarmStatus;
  232. int sensorBaud;
  233. char comSlogan[32];
  234. int connectionStatus;
  235. float gasConcentration;
  236. float humidityValue;
  237. float temperatureValue;
  238. char sensorName[64];
  239. char sensorId;
  240. char sensorType;
  241. int waterImmersionState;
  242. char sensorvaluech[32];
  243. float temperatureValue2;
  244. _Sensor_Temp_Humi_Icon temp_humi_sensor;
  245. _Sensor_Gas_Icon gas_sensor;
  246. _Sensor_Air_Press_Icon air_press_sensor;
  247. struct list_head list;
  248. }_OverSensorBackInfo;
  249. /// @brief 电源类阈值设置
  250. typedef struct
  251. {
  252. char* alarmContentUpperValue;
  253. char* currentUpperValue;
  254. char* powerUpperValue;
  255. char productChId;
  256. char* productChName;
  257. char* voltageDownValue;
  258. char* voltageUpperValue;
  259. bool bUpdatealarmContentUpperValue;
  260. bool bUpdatecurrentUpperValue;
  261. bool bUpdatepowerUpperValue;
  262. bool bUpdatevoltageDownValue;
  263. bool bUpdatevoltageUpperValue;
  264. char* currentUpperAction;
  265. char* voltageUpperAction;
  266. char*voltageDownAction;
  267. char* powerUpperAction;
  268. char* alarmContentUpperAction;
  269. }_Power_AlarmRequestInfo;
  270. /// @brief 传感器类阈值设置
  271. typedef struct
  272. {
  273. char* connectionStatus ;
  274. int sensorId;
  275. char* sensorName;
  276. char* sensorType;
  277. char* thresholdType;
  278. char* thresholdDownValue;
  279. char* thresholdUpperValue;
  280. char *thresholdDownAction;
  281. char *thresholdUpperAction;
  282. char *thresholdUpperChanel;
  283. char *thresholdDownChanel;
  284. }_Sensor_AlarmRequestInfo;
  285. /// @brief 告警信息查询
  286. typedef struct
  287. {
  288. char* user_token;
  289. char* type;
  290. int pagenum;
  291. int pagesize;
  292. _Power_AlarmRequestInfo _pwr_info;
  293. _Sensor_AlarmRequestInfo _sensor_info;
  294. }_AlarmRequestInfo;
  295. /// @brief 告警响应信息
  296. typedef struct
  297. {
  298. char alarmNumber[16];
  299. char alarmDate[32];
  300. char alarmType;
  301. char deviceNumber[16];
  302. char deviceName[32];
  303. char alarmContent[128];
  304. struct list_head list;
  305. }_AlarmAckInfo;
  306. /// @brief SMPT服务信息
  307. typedef struct
  308. {
  309. char* mode;
  310. char* account;
  311. char* password;
  312. char* server;
  313. char* port;
  314. char* auth;
  315. char* recvAccount[SMTP_RECV_MAX];
  316. }_SMTP_ServerRequestInfo;
  317. /// @brief SNMP信息
  318. typedef struct
  319. {
  320. char* mode;
  321. char* version;
  322. char* public;
  323. char* trapmode;
  324. }_SNMP_ServerRequestInfo;
  325. /// @brief SNMP TRAP信息
  326. typedef struct
  327. {
  328. char* mode;
  329. char* stType;
  330. }_SNMPTRAP_ServerRequestInfo;
  331. /// @brief NTP信息
  332. typedef struct
  333. {
  334. char* mode;
  335. char* ntpName;
  336. char* ntpaddress;
  337. char* port;
  338. char* time;
  339. char* weekday;
  340. char* tzone;
  341. }_NTP_ServiceRequestInfo;
  342. /// @brief 定时设置
  343. typedef struct
  344. {
  345. char* productChName;
  346. char* productChId;
  347. int productChIds[64];
  348. char* idx[64];
  349. char* channelDate;
  350. char* StartDate;
  351. char* Enddate;
  352. char* channelTime;
  353. char* setStatus;
  354. }_DS_ServiceRequestInfo;
  355. /// @brief 时序设置
  356. typedef struct
  357. {
  358. char* productId;
  359. char* productChName;
  360. char* productChId;
  361. char* firingInterval;
  362. char* closeInterval;
  363. // char* firingInterval;
  364. // char* closeInterval;
  365. }_POSIX_ServiceRequestInfo;
  366. /// @brief 分组设置
  367. typedef struct
  368. {
  369. char* mode;
  370. char* xlnumber;
  371. char* jgnumber;
  372. char* opergroupid;
  373. }_GROUP_ServiceRequestInfo;
  374. /// @brief 服务信息查询
  375. typedef struct
  376. {
  377. char* user_token;
  378. char* type;
  379. _SMTP_ServerRequestInfo _smtp_info ;
  380. _SNMP_ServerRequestInfo _snmp_info ;
  381. _SNMPTRAP_ServerRequestInfo _snmp_trap_info;
  382. _NTP_ServiceRequestInfo _ntp_info ;
  383. _DS_ServiceRequestInfo _ds_info;
  384. _POSIX_ServiceRequestInfo _posix_info;
  385. _GROUP_ServiceRequestInfo _group_info;
  386. }_ServiceManageRequestInfo;
  387. /// @brief 网络参数配置
  388. typedef struct
  389. {
  390. char* mode;
  391. char* ipaddr;
  392. char* maskaddr;
  393. char* gateway;
  394. char* dns1;
  395. char* dns2;
  396. }_NET_CommunicationRequestInfo;
  397. /// @brief RS参数配置
  398. typedef struct
  399. {
  400. char* mode;
  401. char* baud;
  402. char* addr;
  403. }_RS_CommunicationRequestInfo;
  404. /// @brief 通信信息查询
  405. typedef struct
  406. {
  407. char* user_token;
  408. char* type;
  409. _NET_CommunicationRequestInfo _net_info;
  410. _RS_CommunicationRequestInfo _rs_info;
  411. }_CommunicationManageRequestInfo;
  412. /// @brief日志信息查询
  413. typedef struct
  414. {
  415. char* user_token;
  416. char* type;
  417. char* alarmType;
  418. char* beginTime;
  419. char* endtime;
  420. int pagenum;
  421. int pagesize;
  422. char* openName;
  423. }_LogInformationRequestInfo;
  424. /// @brief 日志应答类容
  425. typedef struct
  426. {
  427. char* alarm_number;
  428. char* alarm_date;
  429. char alarm_type;
  430. int product_id;
  431. char product_name[32];
  432. char alarmContent[64];
  433. }_LogInformationAckInfo;
  434. /// @brief 设备维护
  435. typedef struct
  436. {
  437. char* user_token;
  438. char* type;
  439. char* product_name;
  440. char* product_id;
  441. char* product_number;
  442. /// @brief breaker infomation
  443. char *cjfs;
  444. char *comkh;
  445. char *cjdz;
  446. char *jdh;
  447. char *productChids;
  448. /////
  449. int switchId;
  450. char *switchName;
  451. }_Equipment_Mintenance;
  452. /// @brief 用户角色管理
  453. typedef struct
  454. {
  455. char* user_token;
  456. char* type;
  457. char* createTime;
  458. int userId;
  459. char* userName;
  460. char* nickName;//用途不明?
  461. bool delFlag;//用途不明?
  462. int roleId;
  463. char* roleName;
  464. char* password;
  465. int userIds;
  466. }_UserRoleManageInfo;
  467. char* ctrl_sts_ack_to_json(void);
  468. char* ctrl_breaker_err_ack_to_json(char *string);
  469. void get_rand_str(char* s,int num);
  470. char* json_to_Token_info(const char* strHead);
  471. int json_to_User_login_info(const char* str,_User_Log* _newUserLogin);
  472. int json_to_User_loginOut_info(const char* str,char** _UserLoginOutToken);
  473. char* log_info_to_json(const char* token);
  474. char* log_LoginFailedinfo_to_json();
  475. char* log_AthFailedinfo_to_json();
  476. char* user_info_to_json(void);
  477. char* user_routers_info_to_json(void);
  478. char* json_to_system_config_info(void);
  479. cJSON* json_to_overall_status_monitor(const char* str,_Over_All_Sts_Monitor* _over_all_sts_monitor);
  480. char* over_all_monitor_to_json(_OverBackStsInfo* _over_back_sts_info);
  481. char* overall_power_history_to_json(GlobalPowerInfo* _globalPowerInfo,GlobalDeviceInfo* _globalDeviceInfo);
  482. char* over_channel_power_history_to_json(GlobalPowerInfo* _globalPowerInfo,GlobalDeviceInfo* _globalDeviceInfo,char* chn_name,char chn);
  483. cJSON* json_to_overall_pwr_status_monitor(const char* str,_OverAllPwrRequest* _over_all_pwr_request);
  484. cJSON* json_to_over_equipment_mintenance(const char* str,_Equipment_Mintenance* _over_equipment_mintenance);
  485. char* over_product_list_info_to_json(GlobalDeviceManager *dm, _OverBackStsInfo* _over_back_sts_info,bool curFlag);
  486. char* vendor_info_to_json(GlobalDeviceInfo *dev);
  487. char* over_all_pwr_monitor_to_json(int phaseType,_OverAllPwrAckInfo* _over_all_pwr_back_info);
  488. 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);
  489. char* over_all_total_info_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info, int total_type);
  490. void over_all_total_info_t_ac_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info,cJSON* dataJson,cJSON* AxisJson, int total_type);
  491. int over_init_data_t_ac_to_json(cJSON* pAllJson,cJSON* dataJson[],cJSON* AxisJson,int total_type);
  492. 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);
  493. char* over_system_total_monitor_to_json(_OverBackStsInfo* _over_back_system_info);
  494. char* over_power_trend_to_json(_OverAllPwrAckInfo* _over_all_pwr_back_info);
  495. cJSON* json_to_chn_pwr_status_monitor(const char* str,_OverChnPwrRequest* _over_chn_pwr_request);
  496. char* over_chn_pwr_monitor_to_json(_OverChnPwrAckInfo* _over_chn_pwr_back_info);
  497. int json_to_overall_sensor_status(const char* str,_OverSensorRequest* _over_all_sensor_request);
  498. char* over_all_sensor_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_info,int nWSType);
  499. char* ws_sensor_status_ack_to_json(GlobalSensorManger* _globalSensorManger);
  500. char* over_sensor_history_info_to_json(_OverSensorBackInfo* _over_all_sensor_back_info, int sensor_type);
  501. char* alarm_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAllNumber);
  502. char* alarm_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAllNumber);
  503. char* alarm_ctrl_type_info_to_json(_AlarmAckInfo* _alarm_ack_info,int nAlarmNum);
  504. char* alarm_power_threshold_to_json(GlobalPowerManger* _globalPowerManger);
  505. char* alarm_sensor_threshold_to_json(GlobalSensorManger* _globalSensorManger);
  506. char* communication_net_ack_to_json(NetworkInfo_t* _networkInfo_t);
  507. char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t);
  508. char* service_ds_ack_to_json(char* chn_name,char* chn_id,_PowerDSManage_t* __powerDSManage_t);
  509. char* service_ds_all_ack_to_json(char* pDate,char* Name,char* nchID,GlobalPowerManger* __powerDSManage_t);
  510. char* service_sx_ack_to_json(int product_id, GlobalPowerManger * __PowerManage_t);
  511. char* service_ntp_ack_to_json(NTPManager* __NTPManager_t);
  512. char* service_snmp_ack_to_json(SNMPManager* __SNMPManager_t);
  513. char* service_smtp_ack_to_json(smtp_info_t* info);
  514. char* service_mqtt_ack_to_json(mqtt_info_t* info);
  515. char* service_group_ack_to_json(GroupInfo* _globalgroupInfo);
  516. ///请求管理
  517. cJSON* json_to_sensor_manage(const char* str,_OverSensorRequest* _overSensorRequest);
  518. cJSON* json_to_alarm_manage(const char* str,_AlarmRequestInfo* _alarm_request_info);
  519. cJSON* json_to_loginformation_manage(const char* str,_LogInformationRequestInfo* _logInformationRequestInfo);
  520. cJSON* json_to_communication_manage(const char* str,_CommunicationManageRequestInfo* _communicationRequestInfo);
  521. cJSON* json_to_service_manage(const char* str,_ServiceManageRequestInfo* _serviceManageRequestInfo);
  522. cJSON* json_to_user_manage(const char* str,_UserRoleManageInfo* _UserRoleManageRequestInfo);
  523. char* ws_over_status_ack_to_json(int type,_OverAllPwrAckInfo* _over_all_pwr_back_info);
  524. char* ws_chn_status_ack_to_json(int type,_OverChnPwrAckInfo* _over_chn_pwr_back_info,GlobalDeviceManager *gdm);
  525. int json_to_switch_language(const char* str);
  526. int InitHashTable(GlobalDeviceManager *gdm);
  527. int GetRoleIDByUserName(char* _userName,UserInfo* __UserInfo_t);
  528. int GetRoleLevelByID(int _RoleID,RoleInfo* __RoleInfo_t);
  529. char* GetRoleNameByID(int _RoleID,RoleInfo* __RoleInfo_t);
  530. int GetRoleIDByName(char* _RoleName,RoleInfo* __RoleInfo_t);
  531. char* service_userQuery_ack_to_json(char* _userName,UserInfo* __UserInfo_t,RoleInfo* __RoleInfo_t);
  532. char* service_userRole_ack_to_json(char* _userName,UserInfo* __UserInfo_t,RoleInfo* __RoleInfo_t);
  533. char* over_breaker_product_list_info_to_json(GlobalDeviceManager *dm,_OverBackBreakerInfo* _over_back_sts_info,bool curFlag);
  534. char* over_all_breaker_chn_info_to_json(_OverBreakerChnInfo* _over_all_breaker_back_info,int nWSType);
  535. char* over_all_breaker_switch_info_to_json(_OverBreakerSwitchInfo* _over_all_breaker_switch_info,int nWSType);
  536. char *breaker_status_ack_to_json(GlobalDeviceManager *gm,int slave);
  537. #endif