From cb2a53cfaa349ce68d0de99a9af395059afb7afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Sat, 26 Jul 2025 17:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=99=9A=E6=8B=9F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/DeviceCommandService.java | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java b/src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java index 1cf94c8..9cef242 100644 --- a/src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java +++ b/src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java @@ -99,12 +99,31 @@ public class DeviceCommandService { commandFuture.getDeviceCommand().setCmdId(cmdId); sendCommandFutureMap.put(cmdId, commandFuture); commandFuture.setStartSendTime(System.currentTimeMillis()); - if (!hardwareService.sendCommand(commandFuture.getDeviceCommand())) { - sendCommandFutureMap.remove(commandFuture.getDeviceCommand().getCmdId()); - throw new RuntimeException("向设备发送指令失败"); - } - if (commandFuture.getCmdId() != null) { - webSocketService.pushDebug(DebugGenerator.generateJson(commandFuture.getCmdId(), commandFuture.getCmdCode(), CommandStatus.DEVICE_SEND, commandFuture.getDeviceCommand().getDevice() + "_" + commandFuture.getDeviceCommand().getAction() + "指令,已发给设备", commandFuture.getDeviceCommand())); + if (!deviceState.isVirtual()) { + if (!hardwareService.sendCommand(commandFuture.getDeviceCommand())) { + sendCommandFutureMap.remove(commandFuture.getDeviceCommand().getCmdId()); + throw new RuntimeException("向设备发送指令失败"); + } + if (commandFuture.getCmdId() != null) { + webSocketService.pushDebug(DebugGenerator.generateJson(commandFuture.getCmdId(), commandFuture.getCmdCode(), CommandStatus.DEVICE_SEND, commandFuture.getDeviceCommand().getDevice() + "_" + commandFuture.getDeviceCommand().getAction() + "指令,已发给设备", commandFuture.getDeviceCommand())); + } + } else { + //虚拟模式 + new Thread(() -> { + try { + String actionName = commandFuture.getDeviceCommand().getAction().name(); + if (actionName.contains("move") || actionName.contains("origin")) { + Thread.sleep(300); + } + JSONObject jsonObject = new JSONObject(); + jsonObject.putOnce("cmdId", cmdId); + jsonObject.putOnce("success", true); + completeCommandResponse(jsonObject); + } catch (InterruptedException e) { + // 处理中断异常 + Thread.currentThread().interrupt(); + } + }).start(); } }