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); };