ws.js 3.2 KB

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