ws.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. let productTypeData = {
  2. };
  3. let data_alarm = [];
  4. let sensorc_list = [];
  5. let network_data = {}
  6. // 485配置
  7. let cas_data = {}
  8. // snmp
  9. let snmp_data = {}
  10. // 设备信息
  11. let lang_data = {}
  12. let sensor_data = {}
  13. let his_alarm = []
  14. function on_ws_msg(js) {
  15. console.log("执行")
  16. // debugger
  17. //总电源数据显示
  18. if (js.powert != undefined) {
  19. total_data = js.powert.total
  20. type = js.powert.type
  21. productTypeData.productType = type;
  22. total_Infor(js, total_data, type)
  23. }
  24. //通道电源数据显示
  25. if (js.powerc != undefined) {
  26. channel_power_infro = js.powerc
  27. channel_infro = channel_power_infro.power
  28. alarm = js.powerc.alarm
  29. channel_number = js.powerc.info // 通道基础信息
  30. channel_power = js.powerc.power
  31. j_data = js
  32. // 通道号
  33. Channel_Info(j_data, channel_power_infro)
  34. // 阈值设置
  35. threshold_mannage(js, channel_power_infro)
  36. // systemAlarm(alarm)
  37. //populateTable(j_data,channel_power)
  38. }
  39. // 警告
  40. if (js.alarmd != undefined) {
  41. alarmd_data = js.alarmd
  42. data_alarm = [];
  43. data_alarm = alarm_process(alarmd_data)
  44. }
  45. // 配置信息(网络配置,485配置,snmp,设备信息)
  46. if (js.cas != undefined) {
  47. cas_data = js.cas;
  48. }
  49. if (js.network != undefined) {
  50. network_data = js.network
  51. }
  52. if (js.snmp != undefined) {
  53. snmp_data = js.snmp
  54. console.log("snmp数据--》")
  55. console.log(snmp_data)
  56. }
  57. if (js.sensorc != undefined) {
  58. sensor_data = js.sensorc;
  59. }
  60. // if (js.paras != undefined) {
  61. // // 设备信息
  62. // lang_data = js.paras.lang
  63. // }
  64. if (js.sensorc != undefined) {
  65. sensorc_list = [];
  66. // 传感器
  67. sensorc_list = js.sensorc
  68. // console.log(sensorc_list)
  69. }
  70. if (js.sys != undefined) {
  71. lang_data = js.sys
  72. // console.log(lang_data)
  73. }
  74. if (js.his_alarmd != undefined) {
  75. his_alarm = js.his_alarmd;
  76. console.log(his_alarm)
  77. }
  78. }
  79. function alarm_process(alarmd_data) {
  80. const result = [];
  81. const alarmProperties = alarmd_data.alarm;
  82. const baseProperties = {
  83. "ch": alarmd_data.ch,
  84. "time": alarmd_data.time
  85. };
  86. let idCounter = 1;
  87. for (const key in alarmProperties) {
  88. if (alarmProperties.hasOwnProperty(key) && alarmProperties[key] == 1) {
  89. const newObj = {...baseProperties, [key]: alarmProperties[key], "id": idCounter++ };
  90. result.push(newObj);
  91. }
  92. }
  93. return result;
  94. }
  95. function ws_hdr() {
  96. var proto = window.location.protocol,
  97. ws;
  98. if (proto == 'https:') {
  99. ws = 'wss://';
  100. } else {
  101. ws = 'ws://';
  102. }
  103. return ws;
  104. }
  105. function setActivePage(pageFunction, intervalTime) {
  106. // 停止之前活动的页面定时函数
  107. if (activePageIntervalId != null) {
  108. clearInterval(activePageIntervalId);
  109. }
  110. activePageIntervalId = setInterval(pageFunction, intervalTime);
  111. }
  112. ws = new WS('ws://'+window.location.host+'/ws',on_ws_msg);
  113. // ws = new WS('ws://192.168.1.134/ws', on_ws_msg);
  114. //ws = new WS('ws://192.168.1.134/websocket/TMS-WebSocket', on_ws_msg);