Browse Source

fix:动态支持喷涂参数设置

tags/1.0
白凤吉 4 months ago
parent
commit
48c604b3d4
  1. 15
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  2. 39
      src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java
  3. 32
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
  4. 11
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
  5. 1
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
  6. 30
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  7. 16
      src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java
  8. 42
      src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

15
src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java

@ -79,7 +79,7 @@ public class SprayTaskExecutor {
int sprayNum = 1; int sprayNum = 1;
int currentIndex = 0; int currentIndex = 0;
for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂 for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂
if(!sprayTask.isFirstImmobility()){
if (!sprayTask.isFirstImmobility()) {
//先移动到玻片位置 //先移动到玻片位置
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0); DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0], 20.0);
DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0); DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1], 20.0);
@ -92,13 +92,11 @@ public class SprayTaskExecutor {
DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0);
CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand);
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); 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);
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture);
}
Thread.sleep(100); Thread.sleep(100);
sprayTask.setSuspendable(true);//可以暂停单次喷涂范围内可以进行暂停 sprayTask.setSuspendable(true);//可以暂停单次喷涂范围内可以进行暂停
deviceStatus.setSuspendable(true); deviceStatus.setSuspendable(true);
@ -107,7 +105,7 @@ public class SprayTaskExecutor {
DecimalFormat df = new DecimalFormat("#.##"); DecimalFormat df = new DecimalFormat("#.##");
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂 for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂
if(currentIndex != sprayTaskStep.getIndex()) {
if (currentIndex != sprayTaskStep.getIndex()) {
sprayNum = 0; sprayNum = 0;
currentIndex = sprayTaskStep.getIndex(); currentIndex = sprayTaskStep.getIndex();
} }
@ -115,6 +113,7 @@ public class SprayTaskExecutor {
currentStep++; currentStep++;
continue; continue;
} }
sprayTask.setFirstImmobility(false);
List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i); List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i);
DeviceCommand xSprayStepCommands = sprayStepCommands.get(0); DeviceCommand xSprayStepCommands = sprayStepCommands.get(0);
xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度 xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度

39
src/main/java/com/qyft/ms/app/front/cmd/DemoCommand.java

@ -30,24 +30,29 @@ public class DemoCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) { public CompletableFuture<Void> handle(FrontCmdControlForm form) {
return runAsync(() -> { return runAsync(() -> {
DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();//x轴回原点
DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorXOrigin();//y轴回原点
// DeviceCommand motorXOriginCommand = DeviceCommandGenerator.motorXOrigin();//x轴回原点
// DeviceCommand motorYOriginCommand = DeviceCommandGenerator.motorXOrigin();//y轴回原点
//
// CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
// CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
//
// commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture);
//
//
// DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet();//获得电机XYZ相对原点坐标
//
// CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand);
//
// commandWait(motorXyzPositionGetCommandFuture);
//
// JSONObject responseResultJson = motorXyzPositionGetCommandFuture.getResponseResult();
//
// webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "参数XXX必填"));
Double volume = form.getDoubleParam("volume");
DeviceCommand syringePumpStartCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume); // 生成移动注射泵指令
CommandFuture syringePumpStartCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStartCommand);
commandWait(syringePumpStartCommandFuture);
CommandFuture motorXOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXOriginCommand);
CommandFuture motorYOriginCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYOriginCommand);
commandWait(motorXOriginCommandFuture, motorYOriginCommandFuture);
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet();//获得电机XYZ相对原点坐标
CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXyzPositionGetCommand);
commandWait(motorXyzPositionGetCommandFuture);
JSONObject responseResultJson = motorXyzPositionGetCommandFuture.getResponseResult();
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.DEVICE_ERROR, "参数XXX必填"));
}); });
} }

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

@ -36,6 +36,10 @@ 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("未开始喷涂无法修改");
}
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");
@ -51,6 +55,19 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed); sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed);
return runAsync(() -> { return runAsync(() -> {
if (!sprayTask.isPaused()) {
//4.是否打开高压
if (highVoltage) {//打开高压
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
} else {//关闭高压
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(highVoltageCloseCommandFuture);
}
}
//1.速度 //1.速度
DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置 DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置
DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置 DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置
@ -64,25 +81,14 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand); CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand);
commandWait(syringePumpVolumeSetCommandFuture); commandWait(syringePumpVolumeSetCommandFuture);
//3.z轴高度
//3.z轴高度
SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height")); SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper<SysSettings>().eq(SysSettings::getCode, "slide_height"));
Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue());
Double height = slideHeight - motorZHeight; Double height = slideHeight - motorZHeight;
DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置 DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置
CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand); CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand);
commandWait(smotorZPositionSetCommandFuture); commandWait(smotorZPositionSetCommandFuture);
if (!sprayTask.isPaused()) {
//4.是否打开高压
if (highVoltage) {//打开高压
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(highVoltageValue);//开启高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
} else {//关闭高压
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageCloseCommand);
commandWait(highVoltageCloseCommandFuture);
}
}
}); });
} }

11
src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java

@ -42,6 +42,12 @@ public class MatrixSprayContinue extends BaseCommandHandler {
deviceStatus.setPaused(false); deviceStatus.setPaused(false);
return runAsync(() -> { return runAsync(() -> {
if (sprayTask.getSprayParams().getHighVoltage()) {
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTask.getSprayParams().getHighVoltageValue()); //打开高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路 DeviceCommand threeWayValveOpenSyringePipelineCommand = DeviceCommandGenerator.threeWayValveOpenSyringePipeline();//打开三通阀喷嘴管路
CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand); CommandFuture threeWayValveOpenSyringePipelineCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), threeWayValveOpenSyringePipelineCommand);
commandWait(threeWayValveOpenSyringePipelineCommandFuture); commandWait(threeWayValveOpenSyringePipelineCommandFuture);
@ -54,11 +60,6 @@ public class MatrixSprayContinue extends BaseCommandHandler {
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand); CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand);
commandWait(syringePumpForwardCommandFuture); commandWait(syringePumpForwardCommandFuture);
if (sprayTask.getSprayParams().getHighVoltage()) {
DeviceCommand highVoltageOpenCommand = DeviceCommandGenerator.highVoltageOpen(sprayTask.getSprayParams().getHighVoltageValue()); //打开高压
CommandFuture highVoltageOpenCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), highVoltageOpenCommand);
commandWait(highVoltageOpenCommandFuture);
}
sprayTask.setFirstImmobility(true); sprayTask.setFirstImmobility(true);
sprayTaskExecutor.startTask(); sprayTaskExecutor.startTask();
}); });

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

@ -41,6 +41,7 @@ public class MatrixSprayPause extends BaseCommandHandler {
deviceStatus.setPaused(true); deviceStatus.setPaused(true);
sprayTask.setSuspendable(false);//不可暂停 sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false); deviceStatus.setSuspendable(false);
sprayTask.setFirstImmobility(true);
return runAsync(() -> { return runAsync(() -> {
sprayTaskExecutor.stopTask();//终止喷涂任务线程 sprayTaskExecutor.stopTask();//终止喷涂任务线程

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

@ -199,11 +199,11 @@ public class MatrixSprayStart extends BaseCommandHandler {
PathGenerator.Points p = pathList.get(j); PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>(); List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) { if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else { } else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴 deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} }
deviceCommandList.add(deviceCommands); deviceCommandList.add(deviceCommands);
} }
@ -236,11 +236,11 @@ public class MatrixSprayStart extends BaseCommandHandler {
PathGenerator.Points p = pathList.get(j); PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>(); List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) { if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else { } else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} }
deviceCommandList.add(deviceCommands); deviceCommandList.add(deviceCommands);
} }
@ -272,11 +272,11 @@ public class MatrixSprayStart extends BaseCommandHandler {
PathGenerator.Points p = pathList.get(j); PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>(); List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) { if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else { } else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} }
deviceCommandList.add(deviceCommands); deviceCommandList.add(deviceCommands);
} }
@ -295,11 +295,11 @@ public class MatrixSprayStart extends BaseCommandHandler {
PathGenerator.Points p = pathList.get(j); PathGenerator.Points p = pathList.get(j);
List<DeviceCommand> deviceCommands = new ArrayList<>(); List<DeviceCommand> deviceCommands = new ArrayList<>();
if (j == pathList.size() - 1) { if (j == pathList.size() - 1) {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} else { } else {
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX(), movingSpeed));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY(), movingSpeed));//移动y轴
deviceCommands.add(DeviceCommandGenerator.motorXPositionSet(p.getX()));//移动x轴
deviceCommands.add(DeviceCommandGenerator.motorYPositionSet(75.5 - p.getY()));//移动y轴
} }
deviceCommandList.add(deviceCommands); deviceCommandList.add(deviceCommands);
} }

16
src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java

@ -206,23 +206,11 @@ public class DeviceCommandGenerator {
} }
/** /**
* 推动移动注射泵
*
* @param speed 是指注射泵每分钟注射多少微升(volume 最低0.1)
*/
public static DeviceCommand syringePumpBackward(Double speed) {
Map<String, Object> params = new HashMap<>();
params.put("direction", "backward");
params.put("speed", speed);
return controlCmd("syringe_pump", "move", params, "推动移动注射泵");
}
/**
* 注射泵流速设置 * 注射泵流速设置
*/ */
public static DeviceCommand syringePumpVolumeSet(Double volume) {
public static DeviceCommand syringePumpVolumeSet(Double speed) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("volume", volume);
params.put("speed", speed);
return controlCmd("syringe_pump", "set", params, "注射泵流速设置"); return controlCmd("syringe_pump", "set", params, "注射泵流速设置");
} }

42
src/main/java/com/qyft/ms/system/service/device/DeviceCommandService.java

@ -1,6 +1,7 @@
package com.qyft.ms.system.service.device; package com.qyft.ms.system.service.device;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import com.qyft.ms.app.device.status.DeviceStatus;
import com.qyft.ms.system.common.constant.CommandStatus; 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.CommandFuture;
import com.qyft.ms.system.common.device.command.CyclicNumberGenerator; import com.qyft.ms.system.common.device.command.CyclicNumberGenerator;
@ -12,7 +13,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -25,6 +25,7 @@ public class DeviceCommandService {
private final DeviceTcpClient deviceTcpClient; private final DeviceTcpClient deviceTcpClient;
private final WebSocketService webSocketService; private final WebSocketService webSocketService;
private final DeviceStatus deviceStatus;
public CommandFuture executeCommand(DeviceCommand cmdToDevice) { public CommandFuture executeCommand(DeviceCommand cmdToDevice) {
@ -47,31 +48,18 @@ public class DeviceCommandService {
public CommandFuture sendCommandNoFront(DeviceCommand deviceCommand) { public CommandFuture sendCommandNoFront(DeviceCommand deviceCommand) {
CommandFuture commandFuture = executeCommand(deviceCommand);
commandFuture.getResponseFuture().thenApply(result -> {
Boolean success = result.getBool("success");
if (!success) { //response失败
String message = deviceCommand.getCmdName() + "指令,设备response错误";
}
return result;
});
return commandFuture;
return executeCommand(deviceCommand);
} }
public CommandFuture sendCommand(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws IOException {
public CommandFuture sendCommand(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws Exception {
if (deviceStatus.isStopPressed()) {
throw new RuntimeException("设备急停中");
}
CommandFuture commandFuture = executeCommand(deviceCommand); CommandFuture commandFuture = executeCommand(deviceCommand);
commandFuture.setCmdId(cmdId);
commandFuture.setCmdCode(cmdCode);
commandFuture.setDeviceCommand(deviceCommand);
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_SEND, deviceCommand.getCmdName() + "指令,已发给设备", deviceCommand)); webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_SEND, deviceCommand.getCmdName() + "指令,已发给设备", deviceCommand));
commandFuture.getResponseFuture().thenApply(result -> {
Boolean success = result.getBool("success");
if (success == null || !success) { //response失败
String message = deviceCommand.getCmdName() + "指令,设备response错误";
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, message, result));
}
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_RESULT, deviceCommand.getCmdName() + "指令,设备response正常,耗时:" + (commandFuture.getEndSendTime() - commandFuture.getStartSendTime()), result));
return result;
});
return commandFuture; return commandFuture;
} }
@ -83,8 +71,16 @@ public class DeviceCommandService {
future.setEndSendTime(System.currentTimeMillis()); future.setEndSendTime(System.currentTimeMillis());
Boolean success = deviceResult.getBool("success"); //数据验证 Boolean success = deviceResult.getBool("success"); //数据验证
if (success == null || !success) { //response失败 if (success == null || !success) { //response失败
future.completeResponseExceptionally(new RuntimeException("response失败"));
if(future.getCmdId() != null) {
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(future.getCmdId(), future.getCmdCode(), CommandStatus.DEVICE_ERROR,
future.getDeviceCommand().getCmdName() + "指令,设备response错误,耗时:" + (future.getEndSendTime() - future.getStartSendTime()), deviceResult));
}
future.completeResponseExceptionally(new RuntimeException("response失败:" + deviceResult));
} else { } else {
if(future.getCmdId() != null) {
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(future.getCmdId(), future.getCmdCode(), CommandStatus.DEVICE_RESULT,
future.getDeviceCommand().getCmdName() + "指令,设备response正常,耗时:" + (future.getEndSendTime() - future.getStartSendTime()), deviceResult));
}
future.completeResponse(deviceResult); future.completeResponse(deviceResult);
} }
} }

Loading…
Cancel
Save