json_handle.h 18 KB

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