Files
web-Iot/src/components/devices/emergencyStopControl.ts

29 lines
914 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { wsManager } from '../WebSocketManager';
// 急停对应手柄 button7(buttons 数组下标 7)
const EMERGENCY_STOP_BUTTON_INDEX = 7;
// 构建单帧遥控数据:仅急停位按下/松开,其余按键与摇杆轴保持空闲
const buildFrame = (pressed: boolean) => {
const buttons = new Array(17).fill(false);
buttons[EMERGENCY_STOP_BUTTON_INDEX] = pressed;
return { buttons, axes: [0, 0, 0, 0], connected: true, ts: Date.now() };
};
/**
* 单击急停:绕过控制权限校验,直接经 WebSocket 下发 button7;
* 约 300ms 后自动补发一帧复位数据,模拟按下再松开。
*/
export const sendEmergencyStop = (userInfo?: any) => {
const send = (pressed: boolean) =>
wsManager.send({
type: 'remoteControl',
remoteData: buildFrame(pressed),
token: userInfo?.token,
userName: userInfo?.username,
});
send(true);
setTimeout(() => send(false), 300);
};