From 0594e7a47c93ac556f0c41c391d28b1c6d578d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Sun, 23 Mar 2025 04:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E8=AE=B0=E5=BE=97=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E4=BB=80=E4=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms/app/device/spray/SprayTaskExecutor.java | 78 ++++++++++++---------- .../com/qyft/ms/app/device/status/SprayTask.java | 10 ++- .../ms/app/front/cmd/business/DeviceSelfTest.java | 57 +++++++++++++--- .../front/cmd/business/MatrixSprayContinue.java | 3 + .../ms/app/front/cmd/business/MatrixSprayStop.java | 5 ++ .../model/bo/SprayTaskPointCollectorPushBO.java | 13 ++-- .../com/qyft/ms/app/model/bo/SprayTaskSprayed.java | 4 ++ .../common/device/command/CommandFuture.java | 5 +- .../ms/system/controller/FrontCmdController.java | 4 ++ .../ms/system/core/handler/BaseCommandHandler.java | 3 +- .../listener/DeviceTcpMessageEventListener.java | 21 +++++- .../service/device/DeviceCommandService.java | 9 +-- 12 files changed, 146 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java index efd1925..34d7f39 100644 --- a/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java +++ b/src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java @@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -74,31 +75,42 @@ public class SprayTaskExecutor { webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行")); int reCurrentStep = sprayTask.getCurrentStep(); int currentStep = 0; //当前喷涂步骤 + int sprayCount = 0; int sprayNum = 1; + int currentIndex = 0; for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂 - //先移动到玻片位置 - DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); - DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); - CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); - CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); - - SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "slide_height")); - Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); - Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度 - DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); - CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); - commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); + if(!sprayTask.isFirstImmobility()){ + //先移动到玻片位置 + DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); + DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); + CommandFuture motorXPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXPositionSetCommand); + CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand); + + SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "slide_height")); + Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); + Double height = slideHeight - sprayTask.getSprayParams().getMotorZHeight();//下降z轴高度 + DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); + CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); + commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); + }else{ + sprayTask.setFirstImmobility(false); + } DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵 CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); commandWait(syringePumpForwardCommandFuture); Thread.sleep(100); - sprayTask.setSuspendable(true);//可以暂停,单次喷涂范围内可以进行暂停 deviceStatus.setSuspendable(true); double cacheXPoint = -1; double cacheYPoint = -1; + DecimalFormat df = new DecimalFormat("#.##"); + for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂 + if(currentIndex != sprayTaskStep.getIndex()) { + sprayNum = 0; + currentIndex = sprayTaskStep.getIndex(); + } if (currentStep < reCurrentStep) { currentStep++; continue; @@ -112,6 +124,9 @@ public class SprayTaskExecutor { double aXPoint = (double) xSprayStepCommands.getParam().get("position"); double aYPoint = (double) ySprayStepCommands.getParam().get("position"); + xSprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aXPoint))); + ySprayStepCommands.getParam().put("position", Double.parseDouble(df.format(aYPoint))); + if (cacheXPoint != aXPoint) { CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands); commandFutureList.add(commandFuture); @@ -123,38 +138,31 @@ public class SprayTaskExecutor { cacheYPoint = aYPoint; } CommandFuture[] commandFutureArray = commandFutureList.toArray(new CommandFuture[0]); - Point2D currentPoint; - Point2D nextPoint = null; - if (i != 0) { - List currentSprayStepCommands = sprayTaskStep.getSpraySteps().get(i - 1); - double currentXPoint = (Double) currentSprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; - double currentYPoint = 75.5 - (Double) currentSprayStepCommands.get(1).getParam().get("position"); - currentPoint = new Point2D(currentXPoint, currentYPoint); - double nextXPoint = (Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; - double nextYPoint = 75.5 - (Double) ySprayStepCommands.getParam().get("position"); - nextPoint = new Point2D(nextXPoint, nextYPoint); - SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint); - webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); - } + + double currentXPoint = Double.parseDouble(df.format((Double) xSprayStepCommands.getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0])); + double currentYPoint = Double.parseDouble(df.format(75.5 - (Double) ySprayStepCommands.getParam().get("position"))); + Point2D currentPoint = new Point2D(currentXPoint, currentYPoint); + SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, sprayCount, currentPoint); + webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO); + commandWait(commandFutureArray); currentStep++; sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存 - if (nextPoint != null) { - //将当前点位缓存 - SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed(); - sprayTaskSprayed.setNumber(sprayNum); - sprayTaskSprayed.setIndex(sprayTaskStep.getIndex()); - sprayTaskSprayed.setSprayedPoints(new Point2D(nextPoint.getX(), nextPoint.getY())); - sprayTask.addSprayTaskSprayed(sprayTaskSprayed); - } + //将当前点位缓存 + SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed(); + sprayTaskSprayed.setNumber(sprayNum); + sprayTaskSprayed.setIndex(sprayTaskStep.getIndex()); + sprayTaskSprayed.setSprayCount(sprayCount); + sprayTaskSprayed.setSprayedPoints(new Point2D(Double.parseDouble(df.format(aXPoint - slideArr[sprayTaskStep.getIndex()][0])), Double.parseDouble(df.format(75.5 - aYPoint)))); + sprayTask.addSprayTaskSprayed(sprayTaskSprayed); } sprayTask.setSuspendable(false);//不可暂停 deviceStatus.setSuspendable(false); - DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵 CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand); commandWait(syringePumpStopCommandFuture); + sprayCount++; sprayNum++; } diff --git a/src/main/java/com/qyft/ms/app/device/status/SprayTask.java b/src/main/java/com/qyft/ms/app/device/status/SprayTask.java index e6a0d99..42ae245 100644 --- a/src/main/java/com/qyft/ms/app/device/status/SprayTask.java +++ b/src/main/java/com/qyft/ms/app/device/status/SprayTask.java @@ -45,6 +45,9 @@ public class SprayTask { * 当前正在执行的步骤序号 */ private volatile int currentStep = 0; + + private volatile boolean firstImmobility = false; + /** * 缓存前端的参数 */ @@ -114,11 +117,11 @@ public class SprayTask { public synchronized void addSprayTaskSprayed(SprayTaskSprayed task) { LinkedHashSet distinctNumbers = new LinkedHashSet<>(); for (SprayTaskSprayed item : sprayTaskSprayedList) { - distinctNumbers.add(item.getNumber()); + distinctNumbers.add(item.getSprayCount()); } - if (!distinctNumbers.contains(task.getNumber()) && distinctNumbers.size() >= 4) { + if (!distinctNumbers.contains(task.getSprayCount()) && distinctNumbers.size() >= 120) { Integer oldestNumber = distinctNumbers.iterator().next(); - sprayTaskSprayedList.removeIf(item -> item.getNumber().equals(oldestNumber)); + sprayTaskSprayedList.removeIf(item -> item.getSprayCount().equals(oldestNumber)); } sprayTaskSprayedList.add(task); } @@ -131,6 +134,7 @@ public class SprayTask { spraying = false; sprayTaskStepList.clear(); currentStep = 0; + firstImmobility = false; sprayTaskSprayedList.clear(); cacheParams = null; } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java b/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java index d969eb2..2a14c02 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/DeviceSelfTest.java @@ -1,5 +1,6 @@ package com.qyft.ms.app.front.cmd.business; +import cn.hutool.json.JSONObject; import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.service.SelfTestService; import com.qyft.ms.system.common.annotation.CommandMapping; @@ -13,7 +14,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; /** * 设备自检指令 @@ -30,27 +35,61 @@ public class DeviceSelfTest extends BaseCommandHandler { @Override public CompletableFuture handle(FrontCmdControlForm form) { return runAsync(() -> { - DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点 - CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand); + DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet(); + CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand); + commandWait(overallDeviceStatusGetCommandFuture); - DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点 - CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand); + CommandFuture motorXOriginCommandFuture = null; + CommandFuture motorYOriginCommandFuture = null; + CommandFuture motorZOriginCommandFuture = null; - DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();//z轴回原点 - CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand); - commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture); - try { + List futureList = new ArrayList<>(); + if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("xAxisAtOrigin")) { + DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin(); // x轴回原点 + motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand); + futureList.add(motorXOriginCommandFuture); + } + if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("yAxisAtOrigin")) { + DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();//y轴回原点 + motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand); + futureList.add(motorYOriginCommandFuture); + } + if (!overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("zAxisAtOrigin")) { + DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();//z轴回原点 + motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand); + futureList.add(motorZOriginCommandFuture); + } + CommandFuture[] commandFutureArray = futureList.toArray(new CommandFuture[0]); + commandWait(commandFutureArray); + boolean selfTestCompleted = true; + if (motorXOriginCommandFuture != null) { if (motorXOriginCommandFuture.getResponseResult().getBool("success")) { selfTestService.getSelfTestStatus().setXAxisAtOrigin(true); + } else { + selfTestCompleted = false; } + } + + if (motorYOriginCommandFuture != null) { if (motorYOriginCommandFuture.getResponseResult().getBool("success")) { selfTestService.getSelfTestStatus().setYAxisAtOrigin(true); + } else { + selfTestCompleted = false; } + } + + if (motorZOriginCommandFuture != null) { if (motorZOriginCommandFuture.getResponseResult().getBool("success")) { selfTestService.getSelfTestStatus().setZAxisAtOrigin(true); + } else { + selfTestCompleted = false; } + } + + if (selfTestCompleted) { deviceStatus.setSelfTestCompleted(true); - } catch (Exception ignored) { + } else { + throw new RuntimeException("自检未完成"); } }); } diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java index d62039d..e8a2440 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java @@ -37,7 +37,9 @@ public class MatrixSprayContinue extends BaseCommandHandler { throw new RuntimeException("设备没有正在喷涂"); } sprayTask.setSpraying(true); + sprayTask.setPaused(false); deviceStatus.setSpraying(true); + deviceStatus.setPaused(false); return runAsync(() -> { DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路 @@ -57,6 +59,7 @@ public class MatrixSprayContinue extends BaseCommandHandler { CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand); commandWait(highVoltageOpenCommandFuture); } + sprayTask.setFirstImmobility(true); sprayTaskExecutor.startTask(); }); diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java index 9781f7b..1a745ae 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java @@ -4,11 +4,14 @@ import com.qyft.ms.app.device.spray.SprayTaskExecutor; import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.system.common.annotation.CommandMapping; +import com.qyft.ms.system.common.constant.CommandStatus; 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.FrontResponseGenerator; import com.qyft.ms.system.core.handler.BaseCommandHandler; import com.qyft.ms.system.model.bo.DeviceCommand; import com.qyft.ms.system.model.form.FrontCmdControlForm; +import com.qyft.ms.system.service.WebSocketService; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,6 +32,7 @@ public class MatrixSprayStop extends BaseCommandHandler { private final DeviceCommandService deviceCommandService; private final SprayTaskExecutor sprayTaskExecutor; private final DeviceStatus deviceStatus; + private final WebSocketService webSocketService; @Override public CompletableFuture handle(FrontCmdControlForm form) { @@ -36,6 +40,7 @@ public class MatrixSprayStop extends BaseCommandHandler { if (!sprayTask.isSpraying()) { throw new RuntimeException("设备没有正在喷涂"); } + webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); SprayTask.getInstance().clear(); deviceStatus.setSpraying(false); deviceStatus.setPaused(false); diff --git a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java index 84d669e..6021115 100644 --- a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java +++ b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java @@ -21,20 +21,21 @@ public class SprayTaskPointCollectorPushBO { */ Integer number; /** - * 当前点位坐标 + * 总喷涂计数 */ - Point2D currentPoint; + Integer sprayCount; /** - * 下一个点位坐标 + * 当前点位坐标 */ - Point2D nextPoint; + Point2D currentPoint; + - public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Point2D currentPoint, Point2D nextPoint) { + public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Integer sprayCount, Point2D currentPoint) { this.cmdId = cmdId; this.cmdCode = cmdCode; this.index = index; this.number = number; + this.sprayCount = sprayCount; this.currentPoint = currentPoint; - this.nextPoint = nextPoint; } } diff --git a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java index 5668ff9..3f9fb1c 100644 --- a/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java +++ b/src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java @@ -16,6 +16,10 @@ public class SprayTaskSprayed { */ Integer number; /** + * 总喷涂计数 + */ + Integer sprayCount; + /** * 已喷涂点位 */ private volatile Point2D sprayedPoints; 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 c5b5a12..e13c775 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 @@ -7,6 +7,7 @@ import lombok.Setter; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +@Setter @Getter public class CommandFuture { /** @@ -16,11 +17,9 @@ public class CommandFuture { /** * 用于保存response反馈 */ - private final CompletableFuture responseFuture = new CompletableFuture<>(); + private CompletableFuture responseFuture = new CompletableFuture<>(); - @Setter private long startSendTime; - @Setter private long endSendTime; /** diff --git a/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java b/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java index 6d848e2..69d769a 100644 --- a/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java +++ b/src/main/java/com/qyft/ms/system/controller/FrontCmdController.java @@ -42,6 +42,10 @@ public class FrontCmdController { return Result.failed("未进行自检,无法执行业务指令"); } } + if(deviceStatus.isStopPressed()){ + log.error("设备急停中"); + return Result.failed("设备急停中"); + } webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RECEIVE, "已收到业务指令请求,开始处理")); CommandHandler commandHandler = registry.getHandler(cmdCode); if (commandHandler == null) { 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 682dc33..19b18e9 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 @@ -8,7 +8,6 @@ import com.qyft.ms.system.functions.CommandHandler; import java.util.Arrays; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; public abstract class BaseCommandHandler implements CommandHandler { @@ -18,7 +17,7 @@ public abstract class BaseCommandHandler implements CommandHandler { } - protected void commandWait(CommandFuture... futures) throws ExecutionException, InterruptedException { + protected void commandWait(CommandFuture... futures) throws Exception { CompletableFuture[] responseFutures = Arrays.stream(futures) .map(CommandFuture::getResponseFuture) .toArray(CompletableFuture[]::new); diff --git a/src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java b/src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java index 594b4a7..f455404 100644 --- a/src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java +++ b/src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java @@ -1,6 +1,9 @@ package com.qyft.ms.system.core.listener; import cn.hutool.json.JSONObject; +import com.qyft.ms.app.device.spray.SprayTaskExecutor; +import com.qyft.ms.app.device.status.DeviceStatus; +import com.qyft.ms.app.device.status.SprayTask; import com.qyft.ms.system.core.event.DeviceTcpMessageEvent; import com.qyft.ms.system.service.device.DeviceCommandService; import lombok.extern.slf4j.Slf4j; @@ -12,14 +15,30 @@ import org.springframework.stereotype.Component; public class DeviceTcpMessageEventListener { private final DeviceCommandService deviceCommandService; + private final DeviceStatus deviceStatus; + private final SprayTaskExecutor sprayTaskExecutor; - public DeviceTcpMessageEventListener(DeviceCommandService deviceCommandService) { + public DeviceTcpMessageEventListener(DeviceCommandService deviceCommandService, DeviceStatus deviceStatus, SprayTaskExecutor sprayTaskExecutor) { this.deviceCommandService = deviceCommandService; + this.deviceStatus = deviceStatus; + this.sprayTaskExecutor = sprayTaskExecutor; } @EventListener public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) { JSONObject deviceResult = event.getDeviceResult(); + String tag = deviceResult.getStr("tag"); + String eventType = deviceResult.getStr("event_type"); + if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下 + sprayTaskExecutor.stopTask();//终止喷涂任务线程 + SprayTask.getInstance().clear(); + deviceStatus.setSpraying(false); + deviceStatus.setPaused(false); + deviceStatus.setSuspendable(false); + deviceStatus.setStopPressed(true); + } else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放 + deviceStatus.setStopPressed(false); + } deviceCommandService.handleDeviceResult(deviceResult); } } 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 8a5c13d..05e8597 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 @@ -2,6 +2,7 @@ package com.qyft.ms.system.service.device; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.qyft.ms.app.device.spray.SprayTaskExecutor; import com.qyft.ms.app.device.status.DeviceStatus; import com.qyft.ms.system.common.constant.CommandStatus; import com.qyft.ms.system.common.device.command.CommandFuture; @@ -26,7 +27,6 @@ public class DeviceCommandService { private final ConcurrentMap commandFutureMap = new ConcurrentHashMap<>(); private final DeviceTcpClient deviceTcpClient; - private final DeviceStatus deviceStatus; private final WebSocketService webSocketService; @@ -110,12 +110,7 @@ public class DeviceCommandService { log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult)); completeCommandResponse(deviceResult); } else if ("EVENT".equals(tag)) { - String eventType = deviceResult.getStr("event_type"); - if ("system_e_stop_pressed".equals(eventType)) {//系统急停按钮被按下 - deviceStatus.setStopPressed(true); - } else if ("system_e_stop_released".equals(eventType)) {//系统急停按钮被释放 - deviceStatus.setStopPressed(false); - } + } else if ("STATUS".equals(tag)) { }