From 83022a41ae23362b57dcb3ea132daeff178e56e5 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Tue, 18 Feb 2025 15:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E8=AF=B7=E6=B1=82=E6=B7=BB=E5=8A=A0=E5=91=BD?= =?UTF-8?q?=E4=BB=A4ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/debug/debugApi.ts | 14 ++-- src/services/socket.ts | 53 +++++++++++++- src/services/txn.ts | 42 +++++++++++ src/stores/status.ts | 12 ++++ src/views/debug/debug.vue | 154 +++++++++++++++++++++++++++-------------- 5 files changed, 216 insertions(+), 59 deletions(-) create mode 100644 src/services/txn.ts create mode 100644 src/stores/status.ts diff --git a/src/services/debug/debugApi.ts b/src/services/debug/debugApi.ts index 2da5c71..c4d4ee5 100644 --- a/src/services/debug/debugApi.ts +++ b/src/services/debug/debugApi.ts @@ -1,4 +1,5 @@ import httpRequest, { type BaseResponse } from "../httpRequest"; +import { addTxnRecord } from "../txn"; export const CmdDescMap: { [k in DebugCmd]: string } = { upTray: "抬起托盘", @@ -11,7 +12,7 @@ export const CmdDescMap: { [k in DebugCmd]: string } = { stopHeat: "停止加热", keepHeat: "恒温", takePhoto: "拍照", - moveToUnusual: "移至异常区", + // moveToUnusual: "移至异常区", moveToHeatArea: "移至加热区", takeOffCap: "取下拍子", putBackCap: "装回拍子", @@ -27,20 +28,21 @@ export type DebugCmd = | "injectFluid" // 注入溶液 | "moveToActionArea" // 移至操作区 | "startShakeUp" // 开始摇匀 - | "stopShakeUp" // 结束摇匀 + | "stopShakeUp" // 结束摇匀 | "startHeat" // 开始加热 | "stopHeat" // 停止加热 | "keepHeat" // 恒温 | "takePhoto" // 拍照 - | "moveToUnusual" // 移至异常区 + // | "moveToUnusual" // 移至异常区 | "moveToHeatArea" // 移至加热区 | "takeOffCap" // 取下拍子 | "putBackCap" // 装回拍子 - | "openClaw" // 张开夹爪 - | "closeClaw" // 收合夹爪 + | "openClaw" // 张开夹爪 + | "closeClaw" // 收合夹爪 | "moveMachineArm" // 移动机械臂 | "moveTube"; // 移动试管 export function debugCmd(params: { command: DebugCmd; params: Record }) { - return httpRequest>({ url: "/api/cmd/", params, method: "POST" }); + const commandId = addTxnRecord({ ...params, category: "debug" }); + return httpRequest>({ url: "/api/cmd/", params: { ...params, commandId }, method: "POST" }); } diff --git a/src/services/socket.ts b/src/services/socket.ts index 9991d6a..a069553 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -7,7 +7,7 @@ export type CmdDatagram = { type: "cmd"; // 指令 data: { commandId: string; - commandName: DebugCmd; + // commandName: DebugCmd; status: CmdSuccess | CmdFailure; message: string; }; @@ -19,10 +19,59 @@ export type WarnDatagram = { message: string; }; }; + export type StatusDatagram = { type: "status"; // 状态 data: { - message: string; + emergencyStop: boolean; // 硬件急停信号,true 为急停触发,false 为正常运行 + railArm: { + x: number; + y: number; + z: number; + joint1: number; + joint2: number; + joint3: number; + railDistance: number; + clawDistance: number; + speed: number; + isZeroPos: 0 | 1; // 导轨是否在原点,0 表示不在原点,非 0 表示在原点 + isLimitPos: 0 | 1; // 导轨是否在限位点,0 表示不在限位点,非 0 表示在限位点 + }; + liquidArm: { + x: number; + y: number; + z: number; + joint1: number; + joint2: number; + speed: number; + }; + // 加液泵状态列表 + motors: Array<{ + pumpId: string; + speed: number; + position: number; // 电机实时位置 + isZeroPos: 0 | 1; // 电机是否在原点,0 表示不在原点,非 0 表示在原点 + isLimitPos: 0 | 1; // 电机是否在限位点,0 表示不在限位点,非 0 表示在限位点 + }>; + heatingStatus: boolean; + // 加热器状态列表 + heater: Array<{ + heaterId: string; + temperature: number; + current: number; + }>; + trayStatus: boolean[]; // 加热位托盘状态列表,true 为存在托盘,false 为无托盘 + capStatus: boolean[]; // 拍子状态列表,true 为存在拍子,false 为无拍子 + // 酸液桶状态 + lyeTank: { + isEmpty: boolean; + isFull: boolean; + }; + // 废液桶状态 + wasteTank: { + isEmpty: boolean; + isFull: boolean; + }; }; }; diff --git a/src/services/txn.ts b/src/services/txn.ts new file mode 100644 index 0000000..7b1e0d6 --- /dev/null +++ b/src/services/txn.ts @@ -0,0 +1,42 @@ +import type { DebugCmd } from "./debug/debugApi"; + +let _lastTimestamp = 0; +export function generateTxnNo() { + const txnNo = Date.now(); + // 确保前后两条指定的txn 不一样 + if (txnNo !== _lastTimestamp) { + if (txnNo < _lastTimestamp) { + _lastTimestamp++; + } else { + _lastTimestamp = txnNo; + } + } else { + _lastTimestamp = txnNo + 1; + } + return _lastTimestamp; +} + +type DebugCmdRecord = { + category: 'debug'; + command: DebugCmd; + params: Record +} + +type TxnRecord = DebugCmdRecord // | xxxRecord + +const txnCmdMap: Record = {}; + +export function addTxnRecord(val: TxnRecord) { + const txn = generateTxnNo().toString(); + txnCmdMap[txn] = val; + return txn +} + +export function getTxnRecord(txn: string, del: boolean = true) { + const record = txnCmdMap[txn]; + console.log(txn,':', record) + if (del) { + delete txnCmdMap[txn]; + } + return record; +} diff --git a/src/stores/status.ts b/src/stores/status.ts new file mode 100644 index 0000000..5e12eed --- /dev/null +++ b/src/stores/status.ts @@ -0,0 +1,12 @@ +import { ref, computed } from 'vue' +import { defineStore } from 'pinia' +import type { StatusDatagram } from '@/services/socket' + +export const useStatusStore = defineStore('status', () => { + const status = ref() + const setStatus = (data: StatusDatagram['data']) => { + status.value = data + } + + return { status, setStatus } +}) diff --git a/src/views/debug/debug.vue b/src/views/debug/debug.vue index f93b0a6..fc63acd 100644 --- a/src/views/debug/debug.vue +++ b/src/views/debug/debug.vue @@ -1,52 +1,16 @@