|
@ -5,7 +5,7 @@ import { useSystemStore } from 'stores/useSystemStore' |
|
|
|
|
|
|
|
|
export const sendControl = async (params: any, type?: string) => { |
|
|
export const sendControl = async (params: any, type?: string) => { |
|
|
if (!params.cmdId) { |
|
|
if (!params.cmdId) { |
|
|
params.cmdId = Date.now() |
|
|
|
|
|
|
|
|
params.cmdId = Date.now().toString() |
|
|
} |
|
|
} |
|
|
const systemStore = useSystemStore() |
|
|
const systemStore = useSystemStore() |
|
|
const systemStatus = systemStore.systemStatus |
|
|
const systemStatus = systemStore.systemStatus |
|
@ -61,47 +61,18 @@ export const sendControl = async (params: any, type?: string) => { |
|
|
const cmdName = cmdNameMap[params.cmdCode as keyof typeof cmdNameMap] || params.cmdCode |
|
|
const cmdName = cmdNameMap[params.cmdCode as keyof typeof cmdNameMap] || params.cmdCode |
|
|
|
|
|
|
|
|
socket.init((data: any) => { |
|
|
socket.init((data: any) => { |
|
|
systemStore.pushSystemList(data) |
|
|
|
|
|
|
|
|
if (data.cmdId === params.cmdId) { |
|
|
|
|
|
systemStore.pushSystemList(data) |
|
|
|
|
|
} |
|
|
}, 'cmd_debug') |
|
|
}, 'cmd_debug') |
|
|
socket.init((data: any) => { |
|
|
socket.init((data: any) => { |
|
|
console.log('system', data) |
|
|
|
|
|
systemStore.pushSystemList(data) |
|
|
|
|
|
|
|
|
if (data.cmdId === params.cmdId) { |
|
|
|
|
|
systemStore.pushSystemList(data) |
|
|
|
|
|
} |
|
|
}, 'cmd_response') |
|
|
}, 'cmd_response') |
|
|
await (type === 'debug' ? debugControl(params) : control(params)) |
|
|
await (type === 'debug' ? debugControl(params) : control(params)) |
|
|
systemStore.updateStreamVisible(true) |
|
|
systemStore.updateStreamVisible(true) |
|
|
FtMessage.success(`[${cmdName}]已发送`) |
|
|
FtMessage.success(`[${cmdName}]已发送`) |
|
|
// if (!res.ok) {
|
|
|
|
|
|
// FtMessage.error(`[${cmdName}]发送失败`)
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// FtMessage.success(`[${cmdName}]已发送`)
|
|
|
|
|
|
// const reader = res.body!.getReader()
|
|
|
|
|
|
// const decoder = new TextDecoder()
|
|
|
|
|
|
// systemStore.updateStreamVisible(true)
|
|
|
|
|
|
// let buffer = ''
|
|
|
|
|
|
// FtMessage.success(`[${cmdName}]已开始执行`)
|
|
|
|
|
|
// while (true) {
|
|
|
|
|
|
// const { done, value } = await reader.read()
|
|
|
|
|
|
// if (done) {
|
|
|
|
|
|
// console.log('done')
|
|
|
|
|
|
// FtMessage.success(`[${cmdName}]执行完毕`)
|
|
|
|
|
|
// break
|
|
|
|
|
|
// }
|
|
|
|
|
|
// const chunk = decoder.decode(value, { stream: true })
|
|
|
|
|
|
// // console.log(chunk)
|
|
|
|
|
|
// buffer += chunk
|
|
|
|
|
|
// const { objects, remaining } = extractJSONObjects(buffer)
|
|
|
|
|
|
// buffer = remaining
|
|
|
|
|
|
// objects.forEach((jsonStr) => {
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// const json = JSON.parse(jsonStr)
|
|
|
|
|
|
// systemStore.pushSystemList(json)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// catch (e) {
|
|
|
|
|
|
// console.log(e)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// })
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export const cmdNameMap = { |
|
|
export const cmdNameMap = { |
|
@ -146,51 +117,3 @@ export const cmdNameMap = { |
|
|
motor_xyz_origin: '三轴回原点', |
|
|
motor_xyz_origin: '三轴回原点', |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// const extractJSONObjects = (data: string) => {
|
|
|
|
|
|
// const objects = []
|
|
|
|
|
|
// let startIndex = -1
|
|
|
|
|
|
// let bracketCount = 0
|
|
|
|
|
|
// let inString = false
|
|
|
|
|
|
// let escape = false
|
|
|
|
|
|
//
|
|
|
|
|
|
// for (let i = 0; i < data.length; i++) {
|
|
|
|
|
|
// const char = data[i]
|
|
|
|
|
|
//
|
|
|
|
|
|
// if (inString) {
|
|
|
|
|
|
// if (escape) {
|
|
|
|
|
|
// escape = false
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (char === '\\') {
|
|
|
|
|
|
// escape = true
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (char === '"') {
|
|
|
|
|
|
// inString = false
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else {
|
|
|
|
|
|
// if (char === '"') {
|
|
|
|
|
|
// inString = true
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (char === '{') {
|
|
|
|
|
|
// // 当 bracketCount 为0时,标记一个新的 JSON 对象开始
|
|
|
|
|
|
// if (bracketCount === 0) {
|
|
|
|
|
|
// startIndex = i
|
|
|
|
|
|
// }
|
|
|
|
|
|
// bracketCount++
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else if (char === '}') {
|
|
|
|
|
|
// bracketCount--
|
|
|
|
|
|
// // 当 bracketCount 归零时,说明一个 JSON 对象完整
|
|
|
|
|
|
// if (bracketCount === 0 && startIndex !== -1) {
|
|
|
|
|
|
// const jsonStr = data.slice(startIndex, i + 1)
|
|
|
|
|
|
// objects.push(jsonStr)
|
|
|
|
|
|
// startIndex = -1 // 重置起始位置
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 如果最后 bracketCount 不为0,说明还有未完成的部分
|
|
|
|
|
|
// const remaining = (bracketCount > 0 && startIndex !== -1) ? data.slice(startIndex) : ''
|
|
|
|
|
|
// return { objects, remaining }
|
|
|
|
|
|
// }
|
|
|
|