You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
5.3 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. import { control, debugControl } from 'apis/system'
  2. import { FtMessage } from 'libs/message'
  3. import { socket } from 'libs/socket'
  4. import { useSystemStore } from 'stores/useSystemStore'
  5. export const sendControl = async (params: any, type?: string) => {
  6. if (!params.cmdId) {
  7. params.cmdId = Date.now()
  8. }
  9. const systemStore = useSystemStore()
  10. const systemStatus = systemStore.systemStatus
  11. const sprayingDisableCmd = [
  12. 'slide_tray_in',
  13. 'slide_tray_out',
  14. 'matrix_prefill',
  15. 'nozzle_pipeline_wash',
  16. 'syringe_pipeline_wash',
  17. 'matrix_spray_start',
  18. 'syringe_pipeline_wash_stop',
  19. 'matrix_prefill_stop',
  20. ]
  21. if (systemStatus.spraying && (type === 'debug' || sprayingDisableCmd.includes(params.cmdCode))) {
  22. FtMessage.error('设备正在喷涂中,请等待喷涂完成')
  23. return
  24. }
  25. if (systemStatus.spraying && (type === 'debug' || sprayingDisableCmd.includes(params.cmdCode))) {
  26. FtMessage.error('设备正在喷涂中,请等待喷涂完成')
  27. return
  28. }
  29. systemStore.systemList = []
  30. const cmdName = cmdNameMap[params.cmdCode as keyof typeof cmdNameMap] || params.cmdCode
  31. socket.init((data: any) => {
  32. systemStore.pushSystemList(data)
  33. }, 'cmd_debug')
  34. socket.init((data: any) => {
  35. systemStore.pushSystemList(data)
  36. }, 'cmd_response')
  37. await (type ? control(params) : debugControl(params))
  38. systemStore.updateStreamVisible(true)
  39. FtMessage.success(`[${cmdName}]已发送`)
  40. // if (!res.ok) {
  41. // FtMessage.error(`[${cmdName}]发送失败`)
  42. // return
  43. // }
  44. // FtMessage.success(`[${cmdName}]已发送`)
  45. // const reader = res.body!.getReader()
  46. // const decoder = new TextDecoder()
  47. // systemStore.updateStreamVisible(true)
  48. // let buffer = ''
  49. // FtMessage.success(`[${cmdName}]已开始执行`)
  50. // while (true) {
  51. // const { done, value } = await reader.read()
  52. // if (done) {
  53. // console.log('done')
  54. // FtMessage.success(`[${cmdName}]执行完毕`)
  55. // break
  56. // }
  57. // const chunk = decoder.decode(value, { stream: true })
  58. // // console.log(chunk)
  59. // buffer += chunk
  60. // const { objects, remaining } = extractJSONObjects(buffer)
  61. // buffer = remaining
  62. // objects.forEach((jsonStr) => {
  63. // try {
  64. // const json = JSON.parse(jsonStr)
  65. // systemStore.pushSystemList(json)
  66. // }
  67. // catch (e) {
  68. // console.log(e)
  69. // }
  70. // })
  71. // }
  72. }
  73. export const cmdNameMap = {
  74. slide_tray_in: '推入托盘',
  75. slide_tray_out: '推出托盘',
  76. device_status_get: '获取系统状态',
  77. dehumidifier_start: '除湿',
  78. dehumidifier_stop: '停止除湿',
  79. matrix_prefill: '基质预充',
  80. matrix_prefill_stop: '停止预充',
  81. nozzle_pipeline_wash: '清洗喷嘴管路',
  82. syringe_pipeline_wash: '清洗注射器管路',
  83. syringe_pipeline_wash_stop: '结束清洗',
  84. matrix_spray_start: '开始喷涂',
  85. matrix_spray_stop: '结束喷涂',
  86. matrix_spray_pause: '暂停喷涂',
  87. matrix_spray_continue: '继续喷涂',
  88. motor_x_to_home: 'X轴回原点',
  89. motor_y_to_home: 'Y轴回原点',
  90. motor_z_to_home: 'z轴回原点',
  91. motor_x_stop: 'x轴停止',
  92. motor_y_stop: 'y轴停止',
  93. motor_z_stop: 'z轴停止',
  94. motor_x_to_position: 'X轴移动',
  95. motor_y_to_position: 'Y轴移动',
  96. motor_z_to_position: 'Z轴移动',
  97. syringe_pump_start: '注射泵移动',
  98. syringe_pump_stop: '注射泵停止移动',
  99. high_voltage_open: '打开高压',
  100. high_voltage_close: '关闭高压',
  101. nozzle_valve_open: '喷嘴阀开启',
  102. nozzle_valve_close: '喷嘴阀关闭',
  103. dehumidifier_valve_open: '除湿阀开启',
  104. dehumidifier_valve_close: '除湿阀关闭',
  105. wash_valve_open: '清洗阀开启',
  106. wash_valve_close: '清洗阀关闭',
  107. three_way_valve_close_all: '三通阀管路关闭',
  108. three_way_valve_open_syringe_pipeline: '打开喷嘴管路',
  109. three_way_valve_open_spray_pipeline: '打开注射器管路',
  110. lighting_panel_open: '打开照明灯',
  111. lighting_panel_close: '关闭照明灯',
  112. motor_xyz_origin: '三轴回原点',
  113. }
  114. // const extractJSONObjects = (data: string) => {
  115. // const objects = []
  116. // let startIndex = -1
  117. // let bracketCount = 0
  118. // let inString = false
  119. // let escape = false
  120. //
  121. // for (let i = 0; i < data.length; i++) {
  122. // const char = data[i]
  123. //
  124. // if (inString) {
  125. // if (escape) {
  126. // escape = false
  127. // }
  128. // else if (char === '\\') {
  129. // escape = true
  130. // }
  131. // else if (char === '"') {
  132. // inString = false
  133. // }
  134. // }
  135. // else {
  136. // if (char === '"') {
  137. // inString = true
  138. // }
  139. // else if (char === '{') {
  140. // // 当 bracketCount 为0时,标记一个新的 JSON 对象开始
  141. // if (bracketCount === 0) {
  142. // startIndex = i
  143. // }
  144. // bracketCount++
  145. // }
  146. // else if (char === '}') {
  147. // bracketCount--
  148. // // 当 bracketCount 归零时,说明一个 JSON 对象完整
  149. // if (bracketCount === 0 && startIndex !== -1) {
  150. // const jsonStr = data.slice(startIndex, i + 1)
  151. // objects.push(jsonStr)
  152. // startIndex = -1 // 重置起始位置
  153. // }
  154. // }
  155. // }
  156. // }
  157. // // 如果最后 bracketCount 不为0,说明还有未完成的部分
  158. // const remaining = (bracketCount > 0 && startIndex !== -1) ? data.slice(startIndex) : ''
  159. // return { objects, remaining }
  160. // }