diff --git a/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java b/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java index 7125294..b637e12 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java @@ -1,5 +1,6 @@ package com.qyft.ms.app.front.cmd; +import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -32,7 +33,17 @@ public class DemoCommand extends BaseCommandHandler { CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(motorXOriginCommand, form, emitter); CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(motorYOriginCommand, form, emitter); - commandWaitAll(motorXOriginCommandFuture, motorYOriginCommandFuture); + commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture); + + + DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet();//获得电机XYZ相对原点坐标 + + CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); + + commandWait(motorXyzPositionGetCommandFuture); + + JSONObject ackResultJson = motorXyzPositionGetCommandFuture.getAckResult(); + JSONObject responseResultJson = motorXyzPositionGetCommandFuture.getResponseResult(); }); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java b/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java index 053021c..5195bef 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java @@ -43,10 +43,10 @@ public class DehumidifierStart extends BaseCommandHandler { // 获取设备当前湿度 DeviceCommand humidityGetCmd = DeviceCommandGenerator.humidityGet(); // 生成获取湿度指令 CommandFuture humidityGetCmdFuture = deviceCommandService.sendCommand(humidityGetCmd, form, emitter); - waitAll(humidityGetCmdFuture.getAckFuture()); + commandWait(humidityGetCmdFuture); - JSONObject humidityGetCmdFutureResult = humidityGetCmdFuture.getEventFuture().get(); - Double deviceHumidity = humidityGetCmdFutureResult.getJSONObject("result").getDouble("humidity"); + JSONObject humidityGetCmdFutureResult = humidityGetCmdFuture.getResponseResult(); + Double deviceHumidity = humidityGetCmdFutureResult.getDouble("humidity"); // 判断是否需要除湿:若前端设定湿度大于当前湿度,则无需开启除湿阀 if (humidity > deviceHumidity) { @@ -57,7 +57,7 @@ public class DehumidifierStart extends BaseCommandHandler { // 开启除湿阀门 DeviceCommand dehumidifierValveOpenCmd = DeviceCommandGenerator.dehumidifierValveOpen(); // 生成开启除湿阀指令 CommandFuture dehumidifierValveOpenCmdFuture = deviceCommandService.sendCommand(dehumidifierValveOpenCmd, form, emitter); - waitAll(dehumidifierValveOpenCmdFuture.getAckFuture()); + commandWait(dehumidifierValveOpenCmdFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStop.java b/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStop.java index 32a8131..3367715 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStop.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.business; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -32,7 +30,7 @@ public class DehumidifierStop extends BaseCommandHandler { return runAsync(() -> { DeviceCommand dehumidifierStopCommand = DeviceCommandGenerator.dehumidifierValveClose(); // 生成关闭除湿阀指令 CommandFuture dehumidifierStopCommandFuture = deviceCommandService.sendCommand(dehumidifierStopCommand, form, emitter); - waitAll(dehumidifierStopCommandFuture.getAckFuture()); + commandWait(dehumidifierStopCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java index bcb4ac0..787acb3 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java @@ -83,12 +83,7 @@ public class MatrixSprayStart extends BaseCommandHandler { CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(motorXPositionSetCommand, form, emitter); CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(motorYPositionSetCommand, form, emitter); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_X_MOVE_FINISHED, motorZPositionSetCommandFuture); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_Y_MOVE_FINISHED, motorXPositionSetCommandFuture); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_Z_MOVE_FINISHED, motorYPositionSetCommandFuture); - - waitAll(motorZPositionSetCommandFuture.getAckFuture(), motorXPositionSetCommandFuture.getAckFuture(),motorYPositionSetCommandFuture.getAckFuture()); - waitAllEvent(motorZPositionSetCommandFuture.getEventFuture(), motorXPositionSetCommandFuture.getEventFuture(),motorYPositionSetCommandFuture.getEventFuture()); + commandWait(motorZPositionSetCommandFuture, motorXPositionSetCommandFuture,motorYPositionSetCommandFuture); }); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java b/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java index 564efd3..ebdaca3 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java @@ -3,7 +3,6 @@ package com.qyft.ms.app.front.cmd.business; import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.constant.CommandStatus; -import com.qyft.ms.system.common.constant.DeviceEventConstants; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; import com.qyft.ms.system.common.device.command.FrontCommand; @@ -43,7 +42,7 @@ public class NozzlePipelinePreFill extends BaseCommandHandler { // 判断z轴是否在安全距离,如果不在安全距离则抬升z轴 DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获取xyz当前位置指令 CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); - waitAll(motorXyzPositionGetCommandFuture.getAckFuture()); + commandWait(motorXyzPositionGetCommandFuture); JSONObject motorXyzPositionGetCommandFutureResult = motorXyzPositionGetCommandFuture.getAckFuture().get(); JSONObject resultObj = motorXyzPositionGetCommandFutureResult.getJSONObject("result"); @@ -58,9 +57,7 @@ public class NozzlePipelinePreFill extends BaseCommandHandler { emitter.send(FrontCommand.backstage(form.getCmdId(), form.getCmdCode(), CommandStatus.SEND, "z轴超出安全距离,抬升z轴至安全距离"), MediaType.APPLICATION_JSON); DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(80.0); CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(motorZPositionSetCommand, form, emitter); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_Z_MOVE_FINISHED,motorZPositionSetCommandFuture); - waitAll(motorZPositionSetCommandFuture.getAckFuture()); - waitAllEvent(motorZPositionSetCommandFuture.getEventFuture()); + commandWait(motorZPositionSetCommandFuture); } // x轴移动到废液位置,下降z轴高度防止飞溅 @@ -72,26 +69,21 @@ public class NozzlePipelinePreFill extends BaseCommandHandler { DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(70.0); CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(motorZPositionSetCommand, form, emitter); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_X_MOVE_FINISHED,motorXPositionSetCommandFuture); - deviceCommandService.waitForEvent(DeviceEventConstants.MOTOR_Z_MOVE_FINISHED,motorZPositionSetCommandFuture); - - waitAll(motorXPositionSetCommandFuture.getAckFuture(),motorZPositionSetCommandFuture.getAckFuture()); - waitAllEvent(motorXPositionSetCommandFuture.getEventFuture(),motorZPositionSetCommandFuture.getEventFuture()); + commandWait(motorXPositionSetCommandFuture, motorZPositionSetCommandFuture); // 打开三通阀注射器管路 DeviceCommand threeWayValveOpenNozzlePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline(); CommandFuture threeWayValveOpenNozzlePipelineCommandFuture = deviceCommandService.sendCommand(threeWayValveOpenNozzlePipelineCommand, form, emitter); - waitAll(threeWayValveOpenNozzlePipelineCommandFuture.getAckFuture()); // 打开喷嘴阀 DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(nozzleValveOpenCommand, form, emitter); - waitAll(nozzleValveOpenCommandFuture.getAckFuture()); // 设置注射泵速度,推注射泵 DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(speed); CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(syringePumpForwardCommand, form, emitter); - waitAll(syringePumpForwardCommandFuture.getAckFuture()); + + commandWait(threeWayValveOpenNozzlePipelineCommandFuture, nozzleValveOpenCommandFuture, syringePumpForwardCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveClose.java index 6a24936..06a31e2 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class DehumidifierValveClose extends BaseCommandHandler { return runAsync(() -> { DeviceCommand dehumidifierValveCloseCommand = DeviceCommandGenerator.dehumidifierValveClose();//生成关闭除湿阀指令 CommandFuture dehumidifierValveCloseCommandFuture = deviceCommandService.sendCommand(dehumidifierValveCloseCommand, form, emitter); - waitAll(dehumidifierValveCloseCommandFuture.getAckFuture()); + commandWait(dehumidifierValveCloseCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveOpen.java index 3122843..cc536fd 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/DehumidifierValveOpen.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class DehumidifierValveOpen extends BaseCommandHandler { return runAsync(() -> { DeviceCommand dehumidifierValveOpenCommand = DeviceCommandGenerator.dehumidifierValveOpen(); // 生成开启除湿阀指令 CommandFuture dehumidifierValveOpenCommandFuture = deviceCommandService.sendCommand(dehumidifierValveOpenCommand, form, emitter); - waitAll(dehumidifierValveOpenCommandFuture.getAckFuture()); + commandWait(dehumidifierValveOpenCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageClose.java index 61f7ec0..78d2fec 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class HighVoltageClose extends BaseCommandHandler { return runAsync(() -> { DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose(); // 生成关闭高压指令 CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(highVoltageCloseCommand, form, emitter); - waitAll(highVoltageCloseCommandFuture.getAckFuture()); + commandWait(highVoltageCloseCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageOpen.java index 4e70e96..25a3164 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/HighVoltageOpen.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -32,7 +30,7 @@ public class HighVoltageOpen extends BaseCommandHandler { Double voltage = form.getDoubleParam("voltage"); DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(voltage); // 生成打开高压指令 CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(highVoltageOpenCommand, form, emitter); - waitAll(highVoltageOpenCommandFuture.getAckFuture()); + commandWait(highVoltageOpenCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlClose.java index f6fab7d..028c3aa 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class LaserControlClose extends BaseCommandHandler { return runAsync(() -> { DeviceCommand laserControlCloseCommand = DeviceCommandGenerator.laserControlClose(); // 生成关闭激光指令 CommandFuture laserControlCloseCommandFuture = deviceCommandService.sendCommand(laserControlCloseCommand, form, emitter); - waitAll(laserControlCloseCommandFuture.getAckFuture()); + commandWait(laserControlCloseCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlOpen.java index 8db936d..e3ea59b 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/LaserControlOpen.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -32,7 +30,7 @@ public class LaserControlOpen extends BaseCommandHandler { Double power = form.getDoubleParam("power"); DeviceCommand laserControlOpenCommand = DeviceCommandGenerator.laserControlOpen(power); // 生成打开激光指令 CommandFuture laserControlOpenCommandFuture = deviceCommandService.sendCommand(laserControlOpenCommand, form, emitter); - waitAll(laserControlOpenCommandFuture.getAckFuture()); + commandWait(laserControlOpenCommandFuture); }); } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelClose.java index 4717984..a83dd9d 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class LightingPanelClose extends BaseCommandHandler { return runAsync(() -> { DeviceCommand lightingPanelCloseCommand = DeviceCommandGenerator.lightingPanelClose(); // 生成关闭照明灯指令 CommandFuture lightingPanelCloseCommandFuture = deviceCommandService.sendCommand(lightingPanelCloseCommand, form, emitter); - waitAll(lightingPanelCloseCommandFuture.getAckFuture()); + commandWait(lightingPanelCloseCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelOpen.java index 985369a..b1865b4 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/LightingPanelOpen.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class LightingPanelOpen extends BaseCommandHandler { return runAsync(() -> { DeviceCommand lightingPanelOpenCommand = DeviceCommandGenerator.lightingPanelOpen(); // 生成打开照明灯板指令 CommandFuture lightingPanelOpenCommandFuture = deviceCommandService.sendCommand(lightingPanelOpenCommand, form, emitter); - waitAll(lightingPanelOpenCommandFuture.getAckFuture()); + commandWait(lightingPanelOpenCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXMove.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXMove.java index e339380..fdc7b61 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXMove.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXMove.java @@ -36,12 +36,10 @@ public class MotorXMove extends BaseCommandHandler { // 获取当前x轴位置 DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成电机XYZ相对原点坐标指令 CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); - waitAll(motorXyzPositionGetCommandFuture.getAckFuture()); + commandWait(motorXyzPositionGetCommandFuture); - JSONObject motorXyzPositionGetCommandResult = motorXyzPositionGetCommandFuture.getAckFuture().get(); - - JSONObject motorXyzPositionGetCommandResultObj = motorXyzPositionGetCommandResult.getJSONObject("result"); - Double xAxisPosition = motorXyzPositionGetCommandResultObj.getDouble("xAxisPosition"); + JSONObject motorXyzPositionGetCommandResult = motorXyzPositionGetCommandFuture.getResponseResult(); + Double xAxisPosition = motorXyzPositionGetCommandResult.getDouble("xAxisPosition"); // 计算目标位置 double finalPosition = 0.0; @@ -57,7 +55,7 @@ public class MotorXMove extends BaseCommandHandler { // 生成移动x轴到指定位置指令并发送 DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(finalPosition, speed); CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(motorXPositionSetCommand, form, emitter); - waitAll(motorXPositionSetCommandFuture.getAckFuture()); + commandWait(motorXPositionSetCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXOrigin.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXOrigin.java index c54d2a2..c66483e 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXOrigin.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXOrigin.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class MotorXOrigin extends BaseCommandHandler { return runAsync(() -> { DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点 CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(motorXOriginCommand, form, emitter); - waitAll(motorXOriginCommandFuture.getAckFuture()); + commandWait(motorXOriginCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXStop.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXStop.java index f9d1d89..236c82b 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXStop.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -31,7 +29,7 @@ public class MotorXStop extends BaseCommandHandler { return runAsync(() -> { DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); // 生成x轴停止移动指令 CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(motorXStopCommand, form, emitter); - waitAll(motorXStopCommandFuture.getAckFuture()); + commandWait(motorXStopCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXYZPositionGet.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXYZPositionGet.java index 78c7a41..e0ce10c 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXYZPositionGet.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorXYZPositionGet.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class MotorXYZPositionGet extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获得电机XYZ相对原点坐标指令 - CommandFuture future = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); + commandWait(motorXyzPositionGetCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYMove.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYMove.java index 57d6f90..c5939fd 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYMove.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYMove.java @@ -10,7 +10,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -36,10 +35,9 @@ public class MotorYMove extends BaseCommandHandler { // 获取当前Y轴位置 DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获得电机XYZ相对原点坐标指令 CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); - waitAll(motorXyzPositionGetCommandFuture.getAckFuture()); - JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getAckFuture().get(); - JSONObject motorXyzPositionGetCommandResultObj = motorXyzPositionGetCommandDeviceResult.getJSONObject("result"); - Double yAxisPosition = motorXyzPositionGetCommandResultObj.getDouble("yAxisPosition"); + commandWait(motorXyzPositionGetCommandFuture); + JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); + Double yAxisPosition = motorXyzPositionGetCommandDeviceResult.getDouble("yAxisPosition"); // 计算目标位置 double finalPosition = 0.0; @@ -55,7 +53,7 @@ public class MotorYMove extends BaseCommandHandler { // 生成移动Y轴到指定位置指令并发送 DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(finalPosition, speed); CommandFuture moveFuture = deviceCommandService.sendCommand(motorYPositionSetCommand, form, emitter); - waitAll(moveFuture.getAckFuture()); + commandWait(moveFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYOrigin.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYOrigin.java index bccb8fd..865c301 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYOrigin.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYOrigin.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class MotorYOrigin extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin(); // 生成Y回原点指令 - CommandFuture future = deviceCommandService.sendCommand(motorYOriginCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(motorYOriginCommand, form, emitter); + commandWait(motorYOriginCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYStop.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYStop.java index 15b36c7..e3e3f4e 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorYStop.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class MotorYStop extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); // 生成Y停止指令 - CommandFuture future = deviceCommandService.sendCommand(motorYStopCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(motorYStopCommand, form, emitter); + commandWait(motorYStopCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZMove.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZMove.java index 56d2654..69c1143 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZMove.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZMove.java @@ -10,7 +10,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -37,10 +36,9 @@ public class MotorZMove extends BaseCommandHandler { // 生成获得电机XYZ相对原点坐标指令 DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(motorXyzPositionGetCommand, form, emitter); - waitAll(motorXyzPositionGetCommandFuture.getAckFuture()); - JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getAckFuture().get(); - JSONObject motorXyzPositionGetCommandResultObj = motorXyzPositionGetCommandDeviceResult.getJSONObject("result"); - Double zAxisPosition = motorXyzPositionGetCommandResultObj.getDouble("zAxisPosition"); + commandWait(motorXyzPositionGetCommandFuture); + JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); + Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getDouble("zAxisPosition"); // 根据方向计算最终位置 double finalPosition = 0.0; @@ -55,8 +53,8 @@ public class MotorZMove extends BaseCommandHandler { // 生成移动Z轴到指定位置指令 DeviceCommand motorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(finalPosition, speed); - CommandFuture moveFuture = deviceCommandService.sendCommand(motorZPositionSetCommand, form, emitter); - waitAll(moveFuture.getAckFuture()); + CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(motorZPositionSetCommand, form, emitter); + commandWait(motorZPositionSetCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZOrigin.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZOrigin.java index 15c6af8..d9e129f 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZOrigin.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZOrigin.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class MotorZOrigin extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin(); // 生成Z回原点指令 - CommandFuture future = deviceCommandService.sendCommand(motorZOriginCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(motorZOriginCommand, form, emitter); + commandWait(motorZOriginCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZStop.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZStop.java index a9ed51e..7c09477 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/MotorZStop.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class MotorZStop extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); // 生成Z停止指令 - CommandFuture future = deviceCommandService.sendCommand(motorZStopCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(motorZStopCommand, form, emitter); + commandWait(motorZStopCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveClose.java index bc059a7..f6f0345 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class NozzleValveClose extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); // 生成关闭喷嘴阀指令 - CommandFuture future = deviceCommandService.sendCommand(nozzleValveCloseCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture nozzleValveCloseCommandfuture = deviceCommandService.sendCommand(nozzleValveCloseCommand, form, emitter); + commandWait(nozzleValveCloseCommandfuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveOpen.java index d3dd4c1..7b74f91 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/NozzleValveOpen.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -30,8 +28,8 @@ public class NozzleValveOpen extends BaseCommandHandler { public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); // 生成开启喷嘴阀指令 - CommandFuture future = deviceCommandService.sendCommand(nozzleValveOpenCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture nozzleValveOpenCommandFuture = deviceCommandService.sendCommand(nozzleValveOpenCommand, form, emitter); + commandWait(nozzleValveOpenCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/SyringePumpStart.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/SyringePumpStart.java index bdc8baf..50c82b1 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/SyringePumpStart.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/SyringePumpStart.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -32,8 +30,8 @@ public class SyringePumpStart extends BaseCommandHandler { Double speed = form.getDoubleParam("speed"); String direction = form.getStringParam("direction"); DeviceCommand syringePumpStartCommand = DeviceCommandGenerator.syringePumpStart(direction, speed); // 生成移动注射泵指令 - CommandFuture future = deviceCommandService.sendCommand(syringePumpStartCommand, form, emitter); - waitAll(future.getAckFuture()); + CommandFuture syringePumpStartCommandFuture = deviceCommandService.sendCommand(syringePumpStartCommand, form, emitter); + commandWait(syringePumpStartCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveCloseAll.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveCloseAll.java index 529bcd9..10401f7 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveCloseAll.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveCloseAll.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -29,9 +27,9 @@ public class ThreeWayValveCloseAll extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { - DeviceCommand command = DeviceCommandGenerator.threeWayValveCloseAll(); // 生成全部关闭三通阀指令 - CommandFuture future = deviceCommandService.sendCommand(command, form, emitter); - waitAll(future.getAckFuture()); + DeviceCommand threeWayValveCloseAllCommand = DeviceCommandGenerator.threeWayValveCloseAll(); // 生成全部关闭三通阀指令 + CommandFuture threeWayValveCloseAllCommandFuture = deviceCommandService.sendCommand(threeWayValveCloseAllCommand, form, emitter); + commandWait(threeWayValveCloseAllCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenNuzzlePipeline.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenNuzzlePipeline.java index 57812d9..8fb0048 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenNuzzlePipeline.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenNuzzlePipeline.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -29,9 +27,9 @@ public class ThreeWayValveOpenNuzzlePipeline extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { - DeviceCommand command = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline(); // 生成打开喷嘴管路指令 - CommandFuture future = deviceCommandService.sendCommand(command, form, emitter); - waitAll(future.getAckFuture()); + DeviceCommand threeWayValveOpenNozzlePipelineCommand = DeviceCommandGenerator.threeWayValveOpenNozzlePipeline(); // 生成打开喷嘴管路指令 + CommandFuture threeWayValveOpenNozzlePipelineCommandFuture = deviceCommandService.sendCommand(threeWayValveOpenNozzlePipelineCommand, form, emitter); + commandWait(threeWayValveOpenNozzlePipelineCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenSyringePipeline.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenSyringePipeline.java index 9c5ce54..b0a877d 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenSyringePipeline.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/ThreeWayValveOpenSyringePipeline.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -29,9 +27,9 @@ public class ThreeWayValveOpenSyringePipeline extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { - DeviceCommand command = DeviceCommandGenerator.threeWayValveOpenSyringePipeline(); // 生成打开注射器管路指令 - CommandFuture future = deviceCommandService.sendCommand(command, form, emitter); - waitAll(future.getAckFuture()); + DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline(); // 生成打开注射器管路指令 + CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(threeWayValveOpenSyringePipelineCommand, form, emitter); + commandWait(threeWayValveOpenSyringePipelineCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveClose.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveClose.java index 48a73a4..2e08a1f 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveClose.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveClose.java @@ -1,6 +1,5 @@ package com.qyft.ms.app.front.cmd.debug; -import cn.hutool.json.JSONObject; import com.qyft.ms.system.common.annotation.CommandMapping; import com.qyft.ms.system.common.device.command.CommandFuture; import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; @@ -10,7 +9,6 @@ import com.qyft.ms.system.model.form.FrontCmdControlForm; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; @@ -29,9 +27,9 @@ public class WashValveClose extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { - DeviceCommand command = DeviceCommandGenerator.washValveClose(); // 生成关闭清洗阀指令 - CommandFuture future = deviceCommandService.sendCommand(command, form, emitter); - waitAll(future.getAckFuture()); + DeviceCommand washValveCloseCommand = DeviceCommandGenerator.washValveClose(); // 生成关闭清洗阀指令 + CommandFuture washValveCloseCommandFuture = deviceCommandService.sendCommand(washValveCloseCommand, form, emitter); + commandWait(washValveCloseCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveOpen.java b/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveOpen.java index c60c35e..ec102bc 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveOpen.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/debug/WashValveOpen.java @@ -29,9 +29,9 @@ public class WashValveOpen extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form, ResponseBodyEmitter emitter) { return runAsync(() -> { - DeviceCommand command = DeviceCommandGenerator.washValveOpen(); // 生成打开清洗阀指令 - CommandFuture future = deviceCommandService.sendCommand(command, form, emitter); - waitAll(future.getAckFuture()); + DeviceCommand washValveOpenCommand = DeviceCommandGenerator.washValveOpen(); // 生成打开清洗阀指令 + CommandFuture washValveOpenCommandFuture = deviceCommandService.sendCommand(washValveOpenCommand, form, emitter); + commandWait(washValveOpenCommandFuture); }); } } diff --git a/src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java b/src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java index 99c43ae..a5c6cc5 100644 --- a/src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java +++ b/src/main/java/com/qyft/ms/system/common/device/command/CommandFuture.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; import lombok.Getter; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @Getter @@ -25,17 +26,26 @@ public class CommandFuture { } /** - * 完成event反馈 + * 完成response反馈 */ public void completeResponse(JSONObject result) { responseFuture.complete(result); } + + + /** + * 获取ack反馈的json + */ + public JSONObject getAckResult() throws ExecutionException, InterruptedException { + return ackFuture.get(); + } + /** - * 等待指令反馈 + * 获取response反馈的json */ - public void commandWait() { - responseFuture.orTimeout(5, TimeUnit.SECONDS).join(); + public JSONObject getResponseResult() throws ExecutionException, InterruptedException { + return responseFuture.get(); } } \ No newline at end of file diff --git a/src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java b/src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java index a770c0a..03fb0d1 100644 --- a/src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java +++ b/src/main/java/com/qyft/ms/system/core/handler/BaseCommandHandler.java @@ -16,12 +16,13 @@ public abstract class BaseCommandHandler implements CommandHandler { return CompletableFuture.runAsync(LambdaUtil.unchecked(task)); } - protected void commandWaitAll(CommandFuture... futures) { + + protected void commandWait(CommandFuture... futures) { CompletableFuture[] responseFutures = Arrays.stream(futures) .map(CommandFuture::getResponseFuture) .toArray(CompletableFuture[]::new); CompletableFuture.allOf(responseFutures) - .orTimeout(5, TimeUnit.SECONDS) + .orTimeout(120, TimeUnit.SECONDS) .join(); } diff --git a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java index 04cf87a..a777ea2 100644 --- a/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java +++ b/src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java @@ -66,7 +66,7 @@ public class DeviceCommandService { throw new RuntimeException(message); } frontCommandService.sendToFront(emitter, form, CommandStatus.RESULT, deviceCommand.getCommandName() + "指令,设备response正常", result); - return result; + return result.get("data"); } catch (IOException e) { throw new RuntimeException(e); }