急停 发送ws 遥感控制 避免 raf循环闭包
This commit is contained in:
28
src/components/devices/emergencyStopControl.ts
Normal file
28
src/components/devices/emergencyStopControl.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
};
|
||||
Reference in New Issue
Block a user