diff --git a/src/services/globalCmd/cmdTypes.ts b/src/services/globalCmd/cmdTypes.ts new file mode 100644 index 0000000..a307a09 --- /dev/null +++ b/src/services/globalCmd/cmdTypes.ts @@ -0,0 +1,142 @@ + +type UpTrayStepStruct = { + method: "upTray"; + // params: { + // heaterId: number; + // }; +}; +type DownTrayStepStruct = { + method: "downTray"; + // params: { + // heaterId: number; + // }; +}; +export type TubeSolStruct = { + tubeNum: number; + addLiquidList: Array<{ + solId: number; + volume: number; + }>; +}; +type AddLiquidStepStruct = { + method: "addLiquid"; + params: { + solId: number; + volume: number; + tubeSolList?: TubeSolStruct[]; + }; +}; +type MoveToSolStepStruct = { + method: "moveToSol"; + // params: { + // heaterId: number; + // }; +}; +type MoveToHeaterStepStruct = { + method: "moveToHeat"; + // params: { + // heaterId: number; + // }; +}; +type ShakingStepStruct = { + method: "shaking"; + params: { + second: number; + }; +}; + +type StartHeatingStepStruct = { + method: "startHeating"; + params: { + // heaterId: number; + temperature: number; + }; +}; +type StopHeatingStepStruct = { + method: "stopHeating"; + // params: { + // heaterId: number; + // }; +}; +type TakePhotoStepStruct = { + method: "takePhoto"; +}; +type DelayStepStruct = { + method: "delay"; + params: { + second: number; + }; +}; + +export type StepStruct = + | UpTrayStepStruct + | DownTrayStepStruct + | AddLiquidStepStruct + | MoveToSolStepStruct + | MoveToHeaterStepStruct + | ShakingStepStruct + | StartHeatingStepStruct + | StopHeatingStepStruct + | TakePhotoStepStruct + | DelayStepStruct; + +export type StepCmd = StepStruct["method"]; + +export const StepCmdDescMap: { [k in StepCmd]: string } = { + upTray: "抬起托盘", + downTray: "降下托盘", + addLiquid: "添加溶液", + moveToSol: "移至加液", + moveToHeat: "移至加热", + shaking: "摇匀", + startHeating: "开始加热", + stopHeating: "停止加热", + takePhoto: "拍照", + delay: "等待", +}; + +export const CmdDescMap: { [k in OperationCmd]: string } = { + upTray: "抬起托盘", + downTray: "降下托盘", + injectFluid: "注入溶液", + moveToActionArea: "移至操作区", + startShakeUp: "开始摇匀", + stopShakeUp: "结束摇匀", + startHeat: "开始加热", + stopHeat: "停止加热", + // keepHeat: "恒温", + takePhoto: "拍照", + // moveToUnusual: "移至异常区", + moveToHeatArea: "移至加热区", + takeOffCap: "取下拍子", + putBackCap: "装回拍子", + openClaw: "张开夹爪", + closeClaw: "收合夹爪", + moveMachineArm: "移动机械臂", + moveTube: "移动试管", + openDoor: "开门", + closeDoor: "关门", + +}; + +export type OperationCmd = + | "upTray" // 抬起托盘 + | "downTray" // 降下托盘 + | "injectFluid" // 注入溶液 + | "moveToActionArea" // 移至操作区 + | "startShakeUp" // 开始摇匀 + | "stopShakeUp" // 结束摇匀 + | "startHeat" // 开始加热 + | "stopHeat" // 停止加热 + // | "keepHeat" // 恒温 + | "takePhoto" // 拍照 + // | "moveToUnusual" // 移至异常区 + | "moveToHeatArea" // 移至加热区 + | "takeOffCap" // 取下拍子 + | "putBackCap" // 装回拍子 + | "openClaw" // 张开夹爪 + | "closeClaw" // 收合夹爪 + | "moveMachineArm" // 移动机械臂 + | "moveTube" // 移动试管 + | "openDoor" //开门 + | "closeDoor"; //关门 diff --git a/src/services/globalCmd/globalCmd.ts b/src/services/globalCmd/globalCmd.ts index c19985c..e9b76fc 100644 --- a/src/services/globalCmd/globalCmd.ts +++ b/src/services/globalCmd/globalCmd.ts @@ -1,147 +1,6 @@ import httpRequest, { type BaseResponse } from "../httpRequest"; import { addTxnRecord } from "../txn"; - -type UpTrayStepStruct = { - method: "upTray"; - // params: { - // heaterId: number; - // }; -}; -type DownTrayStepStruct = { - method: "downTray"; - // params: { - // heaterId: number; - // }; -}; -export type TubeSolStruct = { - tubeNum: number; - addLiquidList: Array<{ - solId: number; - volume: number; - }>; -}; -type AddLiquidStepStruct = { - method: "addLiquid"; - params: { - solId: number; - volume: number; - tubeSolList?: TubeSolStruct[]; - }; -}; -type MoveToSolStepStruct = { - method: "moveToSol"; - // params: { - // heaterId: number; - // }; -}; -type MoveToHeaterStepStruct = { - method: "moveToHeat"; - // params: { - // heaterId: number; - // }; -}; -type ShakingStepStruct = { - method: "shaking"; - params: { - second: number; - }; -}; - -type StartHeatingStepStruct = { - method: "startHeating"; - params: { - // heaterId: number; - temperature: number; - }; -}; -type StopHeatingStepStruct = { - method: "stopHeating"; - // params: { - // heaterId: number; - // }; -}; -type TakePhotoStepStruct = { - method: "takePhoto"; -}; -type DelayStepStruct = { - method: "delay"; - params: { - second: number; - }; -}; - -export type StepStruct = - | UpTrayStepStruct - | DownTrayStepStruct - | AddLiquidStepStruct - | MoveToSolStepStruct - | MoveToHeaterStepStruct - | ShakingStepStruct - | StartHeatingStepStruct - | StopHeatingStepStruct - | TakePhotoStepStruct - | DelayStepStruct; - -export type StepCmd = StepStruct["method"]; - -export const StepCmdDescMap: { [k in StepCmd]: string } = { - upTray: "抬起托盘", - downTray: "降下托盘", - addLiquid: "添加溶液", - moveToSol: "移至加液", - moveToHeat: "移至加热", - shaking: "摇匀", - startHeating: "开始加热", - stopHeating: "停止加热", - takePhoto: "拍照", - delay: "等待", -}; - -export const CmdDescMap: { [k in OperationCmd]: string } = { - upTray: "抬起托盘", - downTray: "降下托盘", - injectFluid: "注入溶液", - moveToActionArea: "移至操作区", - startShakeUp: "开始摇匀", - stopShakeUp: "结束摇匀", - startHeat: "开始加热", - stopHeat: "停止加热", - // keepHeat: "恒温", - takePhoto: "拍照", - // moveToUnusual: "移至异常区", - moveToHeatArea: "移至加热区", - takeOffCap: "取下拍子", - putBackCap: "装回拍子", - openClaw: "张开夹爪", - closeClaw: "收合夹爪", - moveMachineArm: "移动机械臂", - moveTube: "移动试管", - openDoor: "开门", - closeDoor: "关门", - -}; - -export type OperationCmd = - | "upTray" // 抬起托盘 - | "downTray" // 降下托盘 - | "injectFluid" // 注入溶液 - | "moveToActionArea" // 移至操作区 - | "startShakeUp" // 开始摇匀 - | "stopShakeUp" // 结束摇匀 - | "startHeat" // 开始加热 - | "stopHeat" // 停止加热 - // | "keepHeat" // 恒温 - | "takePhoto" // 拍照 - // | "moveToUnusual" // 移至异常区 - | "moveToHeatArea" // 移至加热区 - | "takeOffCap" // 取下拍子 - | "putBackCap" // 装回拍子 - | "openClaw" // 张开夹爪 - | "closeClaw" // 收合夹爪 - | "moveMachineArm" // 移动机械臂 - | "moveTube" // 移动试管 - | "openDoor" //开门 - | "closeDoor"; //关门 +import type { OperationCmd } from "./cmdTypes"; export function debugCmd(params: { command: OperationCmd; params: Record }) { const commandId = addTxnRecord({ ...params, category: "debug" }); diff --git a/src/services/socket.ts b/src/services/socket.ts index 4b8a012..647bda0 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -1,140 +1,5 @@ import { Subject } from "rxjs"; -import type { StepCmd } from "./globalCmd/globalCmd"; -import type { Container } from "./sysConfig/sysConfig"; - -export type CmdSuccess = "D0000"; -export type CmdFailure = "D1111"; -export type CmdDatagram = { - type: "cmd"; // 指令 - data: { - commandId: string; - // commandName: DebugCmd; - status: CmdSuccess | CmdFailure; - message: string; - success: boolean; - }; -}; - -export type CraftDatagram = { - type: "crafts"; - data: { - // 当前工艺执行状态,0 表示未执行,1 表示正在执行,2 表示暂停执行,3 表示停止执行 4:Error, 6: 完成。 - status: 0 | 1 | 2 | 3 | 4 | 6; - // 当前正在执行的具体工艺方法 - method: StepCmd; - // 当前正在执行的工艺步骤索引 - methodIndex: number; - // 加热区 ID - heatId: number; - }; -}; - -export type WarnDatagram = { - type: "warn"; // 报警 - data: { - code: string; - msg: string; - module: string; - }; -}; - -export type StatusDatagram = { - type: "status"; // 状态 - data: { - emergencyStop: boolean; // 硬件急停信号,true 为急停触发,false 为正常运行 - doorStatus: boolean; // 门的状态,false 表示关闭,true 表示开启 - railArm: { - x: number; - y: number; - z: number; - joint1: number; - joint2: number; - distance: number; // 当前机械臂(轴 3)上下移动的距离 - railDistance: number; - clawDistance: number; - clawStatus: boolean; // 夹爪状态,true 为张开,false 为闭合 - isZeroPos: boolean; // 导轨是否在原点 - isLimitPos: boolean; // 导轨是否在限位点 - }; - // 操作区(加液、摇匀、拍照)状态 - liquidArea: { - liquidArm: { - x: number; - y: number; - z: number; - joint1: number; - joint2: number; - pump: Array<{ - pumpId: number; - isPumping: boolean; // 是否正在加液,true正在加液 - }>; - }; - isShaking: boolean; // 是否正在摇匀 - liquidTray: boolean; // 是否存在托盘 - // 溶液容器状态 - solutionBucket: Array<{ - isEmpty: boolean; // 容器是否为空 - isFull: boolean; // 容器是否已满 - }>; - }; - - // 加液泵状态列表 - // motors: Array<{ - // pumpId: string; - // speed: number; - // position: number; // 电机实时位置 - // isZeroPos: 0 | 1; // 电机是否在原点,0 表示不在原点,非 0 表示在原点 - // isLimitPos: 0 | 1; // 电机是否在限位点,0 表示不在限位点,非 0 表示在限位点 - // }>; - // heatingStatus: boolean; - // 加热区列表 - heatArea: Array<{ - // heaterId: string; - hardwareId: string; - trayStatus: 0 | 1 | 2; // 0为无托盘,1为有托盘,2为托盘抬起 - isHeating: boolean; // 是否正在加热 - capStatus: boolean; // 是否存在拍子 - isSealed: boolean; // 拍子密封状态,true为已密封,false为未密封 - temperature: number; // 当前温度 - }>; - // 碱容器状态(废液桶) - alkaliBucket: { - isEmpty: boolean; // 容器是否为空 - isFull: boolean; // 容器是否已满 - }; - // trayStatus: boolean[]; // 加热位托盘状态列表,true 为存在托盘,false 为无托盘 - // capStatus: boolean[]; // 拍子状态列表,true 为存在拍子,false 为无拍子 - // 酸液桶状态 - // lyeTank: { - // isEmpty: boolean; - // isFull: boolean; - // }; - // 废液桶状态 - // wasteTank: { - // isEmpty: boolean; - // isFull: boolean; - // }; - }; -}; - -export type CraftState = { - type: "crafts"; - data: { - heatId: string | number; - methodIndex: string | number; - status: string | number; - }; -}; - -export type ContainerDatagram = { - type: "container"; - data: { - containerList: Container[]; - }; -}; - -export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram | CraftDatagram | ContainerDatagram; -export type DatagramType = Datagram["type"]; +import type { Datagram } from "./wsTypes"; export type SocketState = "open" | "close" | "error"; diff --git a/src/services/txn.ts b/src/services/txn.ts index 19c8ec2..4728dd4 100644 --- a/src/services/txn.ts +++ b/src/services/txn.ts @@ -1,4 +1,4 @@ -import type { OperationCmd } from "./globalCmd/globalCmd"; +import type { OperationCmd } from "./globalCmd/cmdTypes"; let _lastTimestamp = 0; export function generateTxnNo() { @@ -26,15 +26,15 @@ type TaskCmdRecord = { category: "task"; command: OperationCmd; params: Record; -} +}; type TaskCmdInjectFluidsRecord = { category: "task"; - command: OperationCmd, + command: OperationCmd; injectFluids: []; -} +}; -type TxnRecord = DebugCmdRecord | TaskCmdRecord | TaskCmdInjectFluidsRecord +type TxnRecord = DebugCmdRecord | TaskCmdRecord | TaskCmdInjectFluidsRecord; const txnCmdMap: Record = {}; @@ -44,7 +44,7 @@ export function addTxnRecord(val: TxnRecord) { return txn; } -export function injectFluidsRecord(val: TaskCmdInjectFluidsRecord){ +export function injectFluidsRecord(val: TaskCmdInjectFluidsRecord) { const txn = generateTxnNo().toString(); txnCmdMap[txn] = val; return txn; @@ -60,11 +60,11 @@ export function getTxnRecord(txn: string, category: TxnRecord["category"]) { return undefined; } -export function peekTxnRecord(txn: string, category: TxnRecord["category"]) { - const record = txnCmdMap[txn]; - // 只有属于指定category时,才返回,且返回后删除记录,节约内存 - if (record && record.category === category) { - return record; - } - return undefined; -} \ No newline at end of file +// export function peekTxnRecord(txn: string, category: TxnRecord["category"]) { +// const record = txnCmdMap[txn]; +// // 只有属于指定category时,才返回,且返回后删除记录,节约内存 +// if (record && record.category === category) { +// return record; +// } +// return undefined; +// } diff --git a/src/services/wsTypes.ts b/src/services/wsTypes.ts new file mode 100644 index 0000000..79a99e0 --- /dev/null +++ b/src/services/wsTypes.ts @@ -0,0 +1,118 @@ +import type { StepCmd } from "./globalCmd/cmdTypes"; + +export type CmdDatagram = { + type: "cmd"; // 指令 + data: { + commandId: string; + // commandName: DebugCmd; + status: "D0000" | "D1111"; + message: string; + success: boolean; + }; +}; + +export type CraftDatagram = { + type: "crafts"; + data: { + // 当前工艺执行状态,0 表示未执行,1 表示正在执行,2 表示暂停执行,3 表示停止执行 4:Error, 6: 完成。 + status: 0 | 1 | 2 | 3 | 4 | 6; + // 当前正在执行的具体工艺方法 + method: StepCmd; + // 当前正在执行的工艺步骤索引 + methodIndex: number; + // 加热区 ID + heatId: number; + }; +}; + +export type WarnDatagram = { + type: "warn"; // 报警 + data: { + code: string; + msg: string; + module: string; + }; +}; + +export type StatusDatagram = { + type: "status"; // 状态 + data: { + emergencyStop: boolean; // 硬件急停信号,true 为急停触发,false 为正常运行 + doorStatus: boolean; // 门的状态,false 表示关闭,true 表示开启 + railArm: { + x: number; + y: number; + z: number; + joint1: number; + joint2: number; + distance: number; // 当前机械臂(轴 3)上下移动的距离 + railDistance: number; + clawDistance: number; + clawStatus: boolean; // 夹爪状态,true 为张开,false 为闭合 + isZeroPos: boolean; // 导轨是否在原点 + isLimitPos: boolean; // 导轨是否在限位点 + }; + // 操作区(加液、摇匀、拍照)状态 + liquidArea: { + liquidArm: { + x: number; + y: number; + z: number; + joint1: number; + joint2: number; + pump: Array<{ + pumpId: number; + isPumping: boolean; // 是否正在加液,true正在加液 + }>; + }; + isShaking: boolean; // 是否正在摇匀 + liquidTray: boolean; // 是否存在托盘 + // 溶液容器状态 + solutionBucket: Array<{ + isEmpty: boolean; // 容器是否为空 + isFull: boolean; // 容器是否已满 + }>; + }; + + // 加热区列表 + heatArea: Array<{ + // heaterId: string; + hardwareId: string; + trayStatus: 0 | 1 | 2; // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: boolean; // 是否正在加热 + capStatus: boolean; // 是否存在拍子 + isSealed: boolean; // 拍子密封状态,true为已密封,false为未密封 + temperature: number; // 当前温度 + }>; + // 碱容器状态(废液桶) + alkaliBucket: { + isEmpty: boolean; // 容器是否为空 + isFull: boolean; // 容器是否已满 + }; + }; +}; + +export type CraftState = { + type: "crafts"; + data: { + heatId: string | number; + methodIndex: string | number; + status: string | number; + }; +}; + +export type ContainerDatagram = { + type: "container"; + data: { + containerList: Array<{ + id: number; + type: 0 | 1; // 0:酸液 1:废液 + solutionId: number; + pumpId: number; + capacityTotal: number; + capacityUsed: number; + }>; + }; +}; + +export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram | CraftDatagram | ContainerDatagram; diff --git a/src/stores/status.ts b/src/stores/status.ts index c1859c4..5628ee7 100644 --- a/src/stores/status.ts +++ b/src/stores/status.ts @@ -1,7 +1,7 @@ import { ref, computed } from "vue"; import { defineStore } from "pinia"; import * as R from "ramda"; -import type { StatusDatagram } from "@/services/socket"; +import type { StatusDatagram } from "@/services/wsTypes"; import { BehaviorSubject, Subject } from "rxjs"; const defaultStatus: StatusDatagram["data"] = { diff --git a/src/views/components/Footer.vue b/src/views/components/Footer.vue index 223f6e0..053b122 100644 --- a/src/views/components/Footer.vue +++ b/src/views/components/Footer.vue @@ -34,7 +34,6 @@ import { ref, onMounted, onUnmounted, computed } from "vue"; import Liquid from "./Liquid.vue"; import { onGoingStatusOb, setOnGoingStatus } from "@/stores/status"; import { createWebSocket, sharedWsUrl } from "@/services/socket"; -import { peekTxnRecord } from "@/services/txn"; import { useSettingStore } from "@/stores/setting"; const settingStore = useSettingStore(); diff --git a/src/views/components/index.ts b/src/views/components/index.ts deleted file mode 100644 index 81e6eea..0000000 --- a/src/views/components/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { default as Header } from './Header.vue' -import { default as Liquid } from './Liquid.vue' \ No newline at end of file diff --git a/src/views/debug/debug.vue b/src/views/debug/debug.vue index fd884c6..b3d81d7 100644 --- a/src/views/debug/debug.vue +++ b/src/views/debug/debug.vue @@ -191,7 +191,7 @@