From 3ae87923e183f2bed641b8c76639a0d4e2413520 Mon Sep 17 00:00:00 2001 From: zhangjiming Date: Wed, 26 Feb 2025 09:58:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=B0=83=E8=AF=95=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/socket.ts | 24 ++++---- src/stores/status.ts | 158 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 166 insertions(+), 16 deletions(-) diff --git a/src/services/socket.ts b/src/services/socket.ts index cfadabd..4b8a012 100644 --- a/src/services/socket.ts +++ b/src/services/socket.ts @@ -89,7 +89,8 @@ export type StatusDatagram = { // heatingStatus: boolean; // 加热区列表 heatArea: Array<{ - heaterId: string; + // heaterId: string; + hardwareId: string; trayStatus: 0 | 1 | 2; // 0为无托盘,1为有托盘,2为托盘抬起 isHeating: boolean; // 是否正在加热 capStatus: boolean; // 是否存在拍子 @@ -117,20 +118,20 @@ export type StatusDatagram = { }; export type CraftState = { - type: "crafts" + type: "crafts"; data: { - heatId: string | number - methodIndex: string| number - status: string| number - } -} + heatId: string | number; + methodIndex: string | number; + status: string | number; + }; +}; export type ContainerDatagram = { - type: "container", + type: "container"; data: { containerList: Container[]; - } -} + }; +}; export type Datagram = CmdDatagram | WarnDatagram | StatusDatagram | CraftDatagram | ContainerDatagram; export type DatagramType = Datagram["type"]; @@ -251,6 +252,7 @@ export const createWebSocket = (url: string): WebSocketClient => { } }; +// export const sharedWsUrl = `ws://${window.location.hostname}:8080/ws`; export const sharedWsUrl = `ws://${import.meta.env.VITE_API_HOST}:${import.meta.env.VITE_API_PORT}${ import.meta.env.VITE_WS_PATH -}`; +}`; \ No newline at end of file diff --git a/src/stores/status.ts b/src/stores/status.ts index 8061618..c1859c4 100644 --- a/src/stores/status.ts +++ b/src/stores/status.ts @@ -4,10 +4,158 @@ import * as R from "ramda"; import type { StatusDatagram } from "@/services/socket"; import { BehaviorSubject, Subject } from "rxjs"; +const defaultStatus: StatusDatagram["data"] = { + emergencyStop: false, // 硬件急停信号,true 为急停触发,false 为正常运行 + doorStatus: false, // 门的状态,false 表示关闭,true 表示开启 + railArm: { + x: 0, + y: 0, + z: 0, + joint1: 0, + joint2: 0, + distance: 0, // 当前机械臂(轴 3)上下移动的距离 + railDistance: 0, + clawDistance: 0, + clawStatus: false, // 夹爪状态,true 为张开,false 为闭合 + isZeroPos: true, // 导轨是否在原点 + isLimitPos: false, // 导轨是否在限位点 + }, + // 操作区(加液、摇匀、拍照)状态 + liquidArea: { + liquidArm: { + x: 0, + y: 0, + z: 0, + joint1: 0, + joint2: 0, + pump: [ + { + pumpId: 1, + isPumping: false, // 是否正在加液,true正在加液 + }, + { + pumpId: 2, + isPumping: false, // 是否正在加液,true正在加液 + }, + { + pumpId: 3, + isPumping: false, // 是否正在加液,true正在加液 + }, + { + pumpId: 4, + isPumping: false, // 是否正在加液,true正在加液 + }, + { + pumpId: 5, + isPumping: false, // 是否正在加液,true正在加液 + }, + { + pumpId: 6, + isPumping: false, // 是否正在加液,true正在加液 + }, + ], + }, + isShaking: false, // 是否正在摇匀 + liquidTray: false, // 是否存在托盘 + // 溶液容器状态 + solutionBucket: [ + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, + ], + }, + + // 加热区列表 + heatArea: [ + { + hardwareId: "hardware_1", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + { + hardwareId: "hardware_2", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + { + hardwareId: "hardware_3", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + { + hardwareId: "hardware_4", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + { + hardwareId: "hardware_5", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + { + hardwareId: "hardware_6", + trayStatus: 0, // 0为无托盘,1为有托盘,2为托盘抬起 + isHeating: false, // 是否正在加热 + capStatus: false, // 是否存在拍子 + isSealed: false, // 拍子密封状态,true为已密封,false为未密封 + temperature: 0, // 当前温度 + }, + ], + // 碱容器状态(废液桶) + alkaliBucket: { + isEmpty: false, // 容器是否为空 + isFull: false, // 容器是否已满 + }, +}; + export const useStatusStore = defineStore("status", () => { - const status = ref(); + const status = ref(defaultStatus); const setStatus = (data: StatusDatagram["data"]) => { - if (!R.equals(status.value, data)) { + if (!R.isEmpty(data) && !R.equals(status.value, data)) { console.log("status: ", data); status.value = data; } @@ -19,8 +167,8 @@ export const useStatusStore = defineStore("status", () => { // 进行中状态 export type OnGoingStatus = "idle" | "doorOpening" | "doorClosing" | "shaking" | "injecting" | "movingToAct" | "movingToHeat"; -const onGoingStatusSub = new BehaviorSubject('idle'); +const onGoingStatusSub = new BehaviorSubject("idle"); export const onGoingStatusOb = onGoingStatusSub.asObservable(); export function setOnGoingStatus(status: OnGoingStatus) { - onGoingStatusSub.next(status) -} \ No newline at end of file + onGoingStatusSub.next(status); +}