Browse Source

fix:喷涂时每个操作指令增加互斥逻辑判断

tags/1.0
白凤吉 4 months ago
parent
commit
124696c7bb
  1. 1
      src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java
  2. 4
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  3. 7
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
  4. 2
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
  5. 34
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  6. 67
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java
  7. 2
      src/main/java/com/qyft/ms/system/core/client/DeviceTcpClient.java
  8. 1
      src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java

1
src/main/java/com/qyft/ms/app/device/status/DeviceStatus.java

@ -1,7 +1,6 @@
package com.qyft.ms.app.device.status; package com.qyft.ms.app.device.status;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; import lombok.Data;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

4
src/main/java/com/qyft/ms/app/device/status/SprayTask.java

@ -38,6 +38,10 @@ public class SprayTask {
*/ */
private volatile boolean suspendable = false; private volatile boolean suspendable = false;
/** /**
* 是否正在结束
*/
private volatile boolean closing = false;
/**
* 设备是否正在进行的喷涂任务 * 设备是否正在进行的喷涂任务
*/ */
private volatile boolean spraying = false; private volatile boolean spraying = false;

7
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java

@ -36,10 +36,11 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) { public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance(); SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSpraying()) {//判断设备是否正在喷涂
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "未开始喷涂无法修改"));
throw new RuntimeException("未开始喷涂无法修改");
if (!sprayTask.isSpraying() || sprayTask.isClosing()) {//判断设备是否正在喷涂
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "目前无法修改喷涂参数"));
throw new RuntimeException("目前无法修改喷涂参数");
} }
Double motorZHeight = form.getDoubleParam("motorZHeight"); Double motorZHeight = form.getDoubleParam("motorZHeight");
Double gasPressure = form.getDoubleParam("gasPressure"); Double gasPressure = form.getDoubleParam("gasPressure");
Double volume = form.getDoubleParam("volume"); Double volume = form.getDoubleParam("volume");

2
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java

@ -34,7 +34,7 @@ public class MatrixSprayPause extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) { public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance(); SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSuspendable()) {
if (!sprayTask.isSuspendable() || sprayTask.isClosing()) {
throw new RuntimeException("当前喷涂任务不可暂停"); throw new RuntimeException("当前喷涂任务不可暂停");
} }
sprayTask.setPaused(true);//已暂停 sprayTask.setPaused(true);//已暂停

34
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java

@ -314,14 +314,32 @@ public class MatrixSprayStart extends BaseCommandHandler {
} }
} }
return runAsync(() -> { return runAsync(() -> {
//XYZ回原点
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();
DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet();
CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), overallDeviceStatusGetCommand);
commandWait(overallDeviceStatusGetCommandFuture);
CommandFuture motorXOriginCommandFuture;
CommandFuture motorYOriginCommandFuture;
CommandFuture motorZOriginCommandFuture;
List<CommandFuture> 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);
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路 DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand); CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), threeWayValveOpenSyringePipelineCommand);

67
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStop.java

@ -17,6 +17,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
@ -40,38 +42,49 @@ public class MatrixSprayStop extends BaseCommandHandler {
if (!sprayTask.isSpraying()) { if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂"); throw new RuntimeException("设备没有正在喷涂");
} }
if(sprayTask.isClosing()){
throw new RuntimeException("正在结束喷涂,请稍后");
}
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
return runAsync(() -> { return runAsync(() -> {
sprayTaskExecutor.stopTask();//终止喷涂任务线程
sprayTask.setClosing(true);
try{
sprayTaskExecutor.stopTask();//终止喷涂任务线程
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand);
DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀
CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand);
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose(); //关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(syringePumpStopCommandFuture, nozzleValveCloseCommandFuture, highVoltageCloseCommandFuture);
DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动
DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动
DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动
CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand);
CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand);
CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand);
commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture);
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop(); //停止推动注射泵
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStopCommand);
DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose(); //关闭喷嘴阀
CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), nozzleValveCloseCommand);
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose(); //关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(syringePumpStopCommandFuture, nozzleValveCloseCommandFuture, highVoltageCloseCommandFuture);
//XYZ回原点
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();
DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
DeviceCommand motorXStopCommand = DeviceCommandGenerator.motorXStop(); //x轴停止移动
DeviceCommand motorYStopCommand = DeviceCommandGenerator.motorYStop(); //y轴停止移动
DeviceCommand motorZStopCommand = DeviceCommandGenerator.motorZStop(); //z轴停止移动
CommandFuture motorXStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXStopCommand);
CommandFuture motorYStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYStopCommand);
CommandFuture motorZStopCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZStopCommand);
commandWait(motorXStopCommandFuture, motorYStopCommandFuture, motorZStopCommandFuture);
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
}finally {
sprayTask.setClosing(false);
}
//XYZ回原点
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorYOrigin();
DeviceCommand motorZOriginCommand = DeviceCommandGenerator.motorZOrigin();
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
CommandFuture motorZOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture, motorZOriginCommandFuture);
}); });
} }
} }

2
src/main/java/com/qyft/ms/system/core/client/DeviceTcpClient.java

@ -111,7 +111,7 @@ public class DeviceTcpClient {
*/ */
public boolean send(String request) { public boolean send(String request) {
if (channel != null && channel.isActive()) { if (channel != null && channel.isActive()) {
// log.info("向设备发送TCP指令:{}", request);
log.info("向设备发送TCP指令:{}", request);
channel.writeAndFlush(Unpooled.copiedBuffer(request, CharsetUtil.UTF_8)); channel.writeAndFlush(Unpooled.copiedBuffer(request, CharsetUtil.UTF_8));
return true; return true;
} else { } else {

1
src/main/java/com/qyft/ms/system/core/listener/DeviceTcpMessageEventListener.java

@ -24,6 +24,7 @@ public class DeviceTcpMessageEventListener {
@EventListener @EventListener
public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) { public void handleDeviceTcpMessageEvent(DeviceTcpMessageEvent event) {
JSONObject deviceResult = event.getDeviceResult(); JSONObject deviceResult = event.getDeviceResult();
log.info("设备反馈信息{}", JSONUtil.toJsonStr(deviceResult));
String tag = deviceResult.getStr("tag"); String tag = deviceResult.getStr("tag");
if ("ACK".equals(tag)) { if ("ACK".equals(tag)) {
log.info("ACK {}", JSONUtil.toJsonStr(deviceResult)); log.info("ACK {}", JSONUtil.toJsonStr(deviceResult));

Loading…
Cancel
Save