Browse Source

虚拟功能

master
王梦远 1 week ago
parent
commit
cb2a53cfaa
  1. 31
      src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java

31
src/main/java/com/iflytop/colortitration/app/service/DeviceCommandService.java

@ -99,12 +99,31 @@ public class DeviceCommandService {
commandFuture.getDeviceCommand().setCmdId(cmdId); commandFuture.getDeviceCommand().setCmdId(cmdId);
sendCommandFutureMap.put(cmdId, commandFuture); sendCommandFutureMap.put(cmdId, commandFuture);
commandFuture.setStartSendTime(System.currentTimeMillis()); 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();
} }
} }

Loading…
Cancel
Save