Browse Source

我也不知道改了什么

tags/1.0
白凤吉 5 months ago
parent
commit
959670bc49
  1. 12
      src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java
  2. 2
      src/main/java/com/qyft/ms/app/controller/SprayTaskController.java
  3. 12
      src/main/java/com/qyft/ms/app/device/spray/SensorCollector.java
  4. 53
      src/main/java/com/qyft/ms/app/device/spray/SprayTaskExecutor.java
  5. 5
      src/main/java/com/qyft/ms/app/device/status/SprayTask.java
  6. 3
      src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java
  7. 9
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java
  8. 6
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayContinue.java
  9. 51
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayPause.java
  10. 63
      src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java
  11. 6
      src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java
  12. 20
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java
  13. 7
      src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java
  14. 3
      src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java
  15. 4
      src/main/java/com/qyft/ms/system/common/constant/CommandStatus.java
  16. 2
      src/main/java/com/qyft/ms/system/core/client/DeviceTcpClient.java
  17. 2
      src/main/java/com/qyft/ms/system/core/handler/DeviceMessageHandler.java
  18. 14
      src/main/java/com/qyft/ms/system/core/server/WebSocketServer.java
  19. 8
      src/main/java/com/qyft/ms/system/service/WebSocketService.java

12
src/main/java/com/qyft/ms/app/common/generator/PathGenerator.java

@ -48,18 +48,18 @@ public class PathGenerator {
double effBottom = bottom - spacing;
// 若收缩后无空间则返回空集合
if (effLeft > effRight || effTop > effBottom) {
System.out.println("内缩后无有效空间,返回空路径");
return new ArrayList<>();
}
// if (effLeft > effRight || effTop > effBottom) {
// System.out.println("内缩后无有效空间,返回空路径");
// return new ArrayList<>();
// }
// 2) 根据mode选择不同的之字形算法
return switch (mode) {
case HORIZONTAL_ZIGZAG_TOP_DOWN -> generateHorizontalZigzagTopDown(
effLeft, effRight, effTop, effBottom, spacing
left, right, top, bottom, spacing
);
case VERTICAL_ZIGZAG_LEFT_RIGHT -> generateVerticalZigzagLeftRight(
effLeft, effRight, effTop, effBottom, spacing
left, right, top, bottom, spacing
);
default ->
// 预留给更多模式扩展

2
src/main/java/com/qyft/ms/app/controller/SprayTaskController.java

@ -24,7 +24,7 @@ public class SprayTaskController {
SprayTask sprayTask = SprayTask.getInstance();
SprayTaskStatusVO sprayTaskStatusVO = new SprayTaskStatusVO();
sprayTaskStatusVO.setSprayTaskSprayedList(sprayTask.getSprayTaskSprayedList());
sprayTaskStatusVO.setSprayParams(sprayTask.getSprayParams());
sprayTaskStatusVO.setSprayParams(sprayTask.getCacheParams());
return Result.success(sprayTaskStatusVO);
}

12
src/main/java/com/qyft/ms/app/device/spray/SensorCollector.java

@ -36,14 +36,10 @@ public class SensorCollector {
Double deviceHumidity = humidityGetCmdFutureResult.getDouble("humidity");
Map<String, Object> map = new HashMap<>();
map.put("humidity", deviceHumidity);
webSocketService.pushMsg(WebSocketMessageType.SENSOR, map);
} catch (Exception e) {
if (!executorService.isShutdown()) {
executorService.shutdown(); // 关闭 ScheduledExecutorService
}
log.error("定时推送传感器状态错误", e);
webSocketService.pushMsgNoLog(WebSocketMessageType.SENSOR, map);
} catch (Exception ignored) {
}
}, 10, 3000, TimeUnit.MILLISECONDS);
}, 10, 3, TimeUnit.SECONDS);
}
private void commandWait(CommandFuture... futures) throws ExecutionException, InterruptedException {
@ -51,7 +47,7 @@ public class SensorCollector {
.map(CommandFuture::getResponseFuture)
.toArray(CompletableFuture[]::new);
CompletableFuture.allOf(responseFutures)
.orTimeout(120, TimeUnit.SECONDS)
.orTimeout(1, TimeUnit.SECONDS)
.get();
}
}

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

@ -12,13 +12,16 @@ import com.qyft.ms.app.model.entity.Position;
import com.qyft.ms.app.model.entity.SysSettings;
import com.qyft.ms.app.service.PositionService;
import com.qyft.ms.app.service.SysSettingsService;
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.model.bo.DeviceCommand;
import com.qyft.ms.system.service.WebSocketService;
import com.qyft.ms.system.service.device.DeviceCommandService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
@ -28,6 +31,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
@RequiredArgsConstructor
public class SprayTaskExecutor {
@ -60,14 +64,14 @@ public class SprayTaskExecutor {
* 启动任务线程如果线程已存在且正在运行则不重复启动
*/
public synchronized void startTask() {
SprayTask sprayTask = SprayTask.getInstance();
if (taskThread != null && taskThread.isAlive()) {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "设备正在喷涂,请先停止喷涂");
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.ERROR, "设备正在喷涂,请先停止喷涂"));
return;
}
taskThread = new Thread(() -> {
try {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "喷涂任务线程启动");
SprayTask sprayTask = SprayTask.getInstance();
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.START, "喷涂任务开始执行"));
if (!sprayTask.isSprayPreStepsCompleted()) {
//XYZ回原点
DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(0.0);
@ -98,6 +102,7 @@ public class SprayTaskExecutor {
int reCurrentStep = sprayTask.getCurrentStep();
int currentStep = 0; //当前喷涂步骤
int sprayNum = 1;
for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen();//开启喷嘴阀
@ -111,7 +116,7 @@ public class SprayTaskExecutor {
deviceStatus.setSuspendable(true);
for (int i = 0; i < sprayTaskStep.getSpraySteps().size(); i++) {//单次喷涂
if (currentStep < reCurrentStep) {
break;
continue;
}
List<DeviceCommand> sprayStepCommands = sprayTaskStep.getSpraySteps().get(i);
List<CommandFuture> commandFutureList = new ArrayList<>();
@ -132,7 +137,7 @@ public class SprayTaskExecutor {
double nextXPoint = (Double) sprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0];
double nextYPoint = 75.5 - (Double) sprayStepCommands.get(1).getParam().get("position");
nextPoint = new Point2D(nextXPoint, nextYPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTaskStep.getIndex(), currentPoint, nextPoint);
SprayTaskPointCollectorPushBO sprayTaskPointCollectorPushBO = new SprayTaskPointCollectorPushBO(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayTaskStep.getIndex(), sprayNum, currentPoint, nextPoint);
webSocketService.pushMsg(WebSocketMessageType.SPRAY_POINT, sprayTaskPointCollectorPushBO);
}
commandWait(commandFutureArray);
@ -141,22 +146,23 @@ public class SprayTaskExecutor {
sprayTask.setCurrentStep(currentStep);//将当前的喷涂进度缓存
if (nextPoint != null) {
//将当前点位缓存
sprayStepList.add(new Point2D(nextPoint.getX(), nextPoint.getY()));
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
sprayTaskSprayed.setNumber(sprayNum);
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex());
sprayTaskSprayed.setSprayedPoints(new Point2D(nextPoint.getX(), nextPoint.getY()));
sprayTask.getSprayTaskSprayedList().add(sprayTaskSprayed);
}
}
sprayTask.setSuspendable(false);//不可暂停
deviceStatus.setSuspendable(false);
SprayTaskSprayed sprayTaskSprayed = new SprayTaskSprayed();
sprayTaskSprayed.setIndex(sprayTaskStep.getIndex());
sprayTaskSprayed.setSprayedPoints(sprayStepList);
DeviceCommand nozzleValveCloseCommand = DeviceCommandGenerator.nozzleValveClose();//关闭喷嘴阀
DeviceCommand syringePumpStopCommand = DeviceCommandGenerator.syringePumpStop();//停止推动注射泵
CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand);
CommandFuture syringePumpStopCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpStopCommand);
commandWait(nozzleValveCloseCommandFuture, syringePumpStopCommandFuture);
sprayNum++;
}
DeviceCommand highVoltageCloseCommand = DeviceCommandGenerator.highVoltageClose();//关闭高压
CommandFuture highVoltageCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), highVoltageCloseCommand);
commandWait(highVoltageCloseCommandFuture);
@ -169,21 +175,31 @@ public class SprayTaskExecutor {
CommandFuture motorYPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYPositionSetCommand);
CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetCommand);
commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetCommandFuture);
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "喷涂任务执行完毕");
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setSuspendable(false);
deviceStatus.setSuspendable(false);
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功"));
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
} catch (InterruptedException e) {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "喷涂任务线程停止");
deviceStatus.setSuspendable(false);
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程停止"));
Thread.currentThread().interrupt();
} catch (Exception e) {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "喷涂任务线程异常:" + e.getMessage());
log.info("喷涂任务失败", e);
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setSuspendable(false);
deviceStatus.setSuspendable(false);
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.FAIL, "喷涂任务执行失败"));
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束"));
} finally {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "喷涂任务线程退出");
webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SEND, "喷涂任务线程退出"));
// 在线程结束后将 taskThread 设置为 null保证状态一致和资源释放
synchronized (this) {
taskThread = null;
SprayTask.getInstance().clear();
deviceStatus.setSpraying(false);
deviceStatus.setPaused(false);
deviceStatus.setSuspendable(false);
}
}
});
@ -198,7 +214,6 @@ public class SprayTaskExecutor {
*/
public synchronized void stopTask() {
if (taskThread != null && taskThread.isAlive()) {
webSocketService.pushMsg(WebSocketMessageType.CMD_DEBUG, "停止喷涂任务线程");
// 中断线程使得 future.get() 能够抛出 InterruptedException从而退出等待
taskThread.interrupt();
}

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

@ -48,6 +48,10 @@ public class SprayTask {
* 当前正在执行的步骤序号
*/
private volatile int currentStep = 0;
/**
* 缓存前端的参数
*/
private Map<String, Object> cacheParams = null;
/**
* 已喷涂点位
@ -107,6 +111,7 @@ public class SprayTask {
sprayTaskStepList.clear();
currentStep = 0;
sprayTaskSprayedList.clear();
cacheParams = null;
}
private static class Holder {

3
src/main/java/com/qyft/ms/app/front/cmd/business/DehumidifierStart.java

@ -33,6 +33,9 @@ public class DehumidifierStart extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
if (deviceStatus.isDehumidifierRunning()) {
throw new RuntimeException("正在除湿中,无法再次开启除湿");
}
Double humidity = form.getDoubleParam("humidity");
// 参数校验humidity 必填
if (humidity == null) {

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

@ -5,11 +5,14 @@ import com.qyft.ms.app.device.status.SprayTask;
import com.qyft.ms.app.model.entity.SysSettings;
import com.qyft.ms.app.service.SysSettingsService;
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;
@ -28,6 +31,7 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SysSettingsService sysSettingsService;
private final WebSocketService webSocketService;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
@ -39,7 +43,10 @@ public class MatrixSprayChangeParam extends BaseCommandHandler {
Double highVoltageValue = form.getDoubleParam("highVoltageValue");
Double movingSpeed = form.getDoubleParam("movingSpeed");
sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed);
if (highVoltageValue > 6000) {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.ERROR, "电压不能大于6000V"));
throw new RuntimeException("电压不能大于6000V");
}
return runAsync(() -> {
//1.速度
DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置

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

@ -8,6 +8,7 @@ import com.qyft.ms.system.common.device.command.DeviceCommandGenerator;
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,8 +30,11 @@ public class MatrixSprayContinue extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSpraying()) {
throw new RuntimeException("设备没有正在喷涂");
}
return runAsync(() -> {
SprayTask sprayTask = SprayTask.getInstance();
DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume()); //推动注射泵
CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpForwardCommand);
DeviceCommand nozzleValveOpenCommand = DeviceCommandGenerator.nozzleValveOpen(); //打开喷嘴阀

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

@ -5,10 +5,8 @@ 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;
@ -32,36 +30,33 @@ public class MatrixSprayPause extends BaseCommandHandler {
private final DeviceCommandService deviceCommandService;
private final SprayTaskExecutor sprayTaskExecutor;
private final DeviceStatus deviceStatus;
private final WebSocketService webSocketService;
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
SprayTask sprayTask = SprayTask.getInstance();
if (!sprayTask.isSuspendable()) {
throw new RuntimeException("当前喷涂任务不可暂停");
}
sprayTask.setPaused(true);
deviceStatus.setPaused(true);
return runAsync(() -> {
SprayTask sprayTask = SprayTask.getInstance();
if (sprayTask.isSuspendable()) {
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);
sprayTask.setPaused(true);
deviceStatus.setPaused(true);
} else {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.ERROR, "当前喷涂任务不可暂停"));
}
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);
});
}
}

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

@ -27,6 +27,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.LinkedHashMap;
import java.util.List;
@ -143,9 +144,10 @@ public class MatrixSprayStart extends BaseCommandHandler {
return runAsync(() -> {
// 3. 设定喷涂参数
sprayTask.setSprayParam(matrixPathType, motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, spacing, movingSpeed, times, positionList);
sprayTask.setCacheParams(form.getParams());
OperationLog operationLog = new OperationLog();
operationLog.setMatrixInfo(JSONUtil.toJsonStr(sprayTask.getSprayParams()));
operationLog.setMatrixInfo(JSONUtil.toJsonStr(sprayTask.getCacheParams()));
operationLogService.add(operationLog);
//1.速度
@ -177,24 +179,27 @@ public class MatrixSprayStart extends BaseCommandHandler {
Double[] upperLeft = {((Number) position.get("x1")).doubleValue(), ((Number) position.get("y1")).doubleValue()}; //范围左上角 x1y1
Double[] lowerRight = {((Number) position.get("x2")).doubleValue(), ((Number) position.get("y2")).doubleValue()}; //范围右下角 x2y2
Double[] slide = slideArr[index];//获取玻片的坐标
Double slideCompleteUCSX = slide[0] + upperLeft[0]; //玻片范围的实际位置x坐标
Double slideCompleteUCSY = slide[1] + upperLeft[1]; //玻片范围的实际位置y坐标
//规划路线坐标
double left = slideCompleteUCSX + upperLeft[0];
double right = slideCompleteUCSX + lowerRight[0];
double top = slideCompleteUCSY + upperLeft[1];
double bottom = slideCompleteUCSY + lowerRight[1];
DecimalFormat df = new DecimalFormat("#.##");
double left = Double.parseDouble(df.format( slide[0] + upperLeft[0]));
double right = Double.parseDouble(df.format( slide[0] + lowerRight[0]));
double top = Double.parseDouble(df.format(slide[1] + upperLeft[1]));
double bottom = Double.parseDouble(df.format(slide[1] + lowerRight[1]));
if ("horizontal".equals(matrixPathType)) {//喷涂路径类型 horizontal 横向 | vertical 纵向 | grid 网格先横向后纵向
for (int i = 0; i < times; i++) {
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
if (i != 0 && i % 2 == 0) {//双数喷涂插空移动边界
double leftReal = left;
double rightReal = right;
if (i % 2 == 0) {//双数喷涂插空移动边界
double halfSpacing = spacing / 2;
topReal = top - halfSpacing;
bottomReal = bottom + halfSpacing;
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
left, right, topReal, bottomReal,
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
@ -211,16 +216,20 @@ public class MatrixSprayStart extends BaseCommandHandler {
sprayTask.getSprayTaskStepList().add(sprayTaskStep);
}
} else if ("vertical".equals(matrixPathType)) {
for (int i = 0; i < times; i++) {
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
double leftReal = left;
double rightReal = right;
if (i != 0 && i % 2 == 0) {//双数喷涂插空移动边界
if (i % 2 == 0) {//双数喷涂插空移动边界
double halfSpacing = spacing / 2;
leftReal = top - halfSpacing;
rightReal = bottom + halfSpacing;
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, top, bottom,
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
);
@ -237,22 +246,22 @@ public class MatrixSprayStart extends BaseCommandHandler {
sprayTask.getSprayTaskStepList().add(sprayTaskStep);
}
} else if ("grid".equals(matrixPathType)) {
for (int i = 0; i < times; i++) {
double leftReal = left;
double rightReal = right;
for (int i = 1; i <= times; i++) {
double topReal = top;
double bottomReal = bottom;
if (i != 0 && i % 2 == 0) {//双数喷涂插空移动边界
double halfSpacing = spacing / 2;
leftReal = top - halfSpacing;
rightReal = bottom + halfSpacing;
topReal = top - halfSpacing;
bottomReal = bottom + halfSpacing;
double leftReal = left;
double rightReal = right;
double halfSpacing = spacing / 2;
if (i % 2 == 0) {//双数喷涂插空移动边界
topReal = top + halfSpacing;
bottomReal = bottomReal - halfSpacing;
leftReal = left + halfSpacing;
rightReal = right - halfSpacing;
}
List<PathGenerator.Points> pathList = PathGenerator.generatePathPoints(
leftReal, rightReal, topReal, bottomReal,
spacing,
PathGenerator.MoveMode.VERTICAL_ZIGZAG_LEFT_RIGHT
PathGenerator.MoveMode.HORIZONTAL_ZIGZAG_TOP_DOWN
);
List<List<DeviceCommand>> deviceCommandList = new ArrayList<>();
for (PathGenerator.Points p : pathList) {//喷针移动目标位置

6
src/main/java/com/qyft/ms/app/front/cmd/business/NozzlePipelinePreFill.java

@ -40,11 +40,15 @@ public class NozzlePipelinePreFill extends BaseCommandHandler {
@Override
public CompletableFuture<Void> handle(FrontCmdControlForm form) {
if (deviceStatus.isPrefilling()) {
throw new RuntimeException("正在预充中,无法再次开启预充");
}
Double speed = form.getDoubleParam("speed");
if (speed == null) {
webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(form.getCmdId(), form.getCmdCode(), CommandStatus.ERROR, "参数 speed 必填"));
throw new RuntimeException("参数 speed 必填");
}
deviceStatus.setPrefilling(true);
return runAsync(() -> {
//2.判断z轴是否在安全距离如果不在安全距离可以不抬升z轴
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet();
@ -83,8 +87,6 @@ public class NozzlePipelinePreFill extends BaseCommandHandler {
DeviceCommand syringePumpStartCommand = DeviceCommandGenerator.syringePumpForward(speed); // 生成移动注射泵指令
CommandFuture syringePumpStartCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpStartCommand);
commandWait(syringePumpStartCommandFuture);
deviceStatus.setPrefilling(true);
});
}

20
src/main/java/com/qyft/ms/app/model/bo/SprayTaskPointCollectorPushBO.java

@ -1,15 +1,26 @@
package com.qyft.ms.app.model.bo;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
@Data
public class SprayTaskPointCollectorPushBO {
/**
* 当前是第几次喷涂
* 指令id
*/
String cmdId;
/**
* 指令code
*/
String cmdCode;
/**
* 当前是第几个玻片 从0开始
*/
Integer index;
/**
* 当前玻片是第几次喷涂
*/
Integer number;
/**
* 当前点位坐标
*/
Point2D currentPoint;
@ -18,8 +29,11 @@ public class SprayTaskPointCollectorPushBO {
*/
Point2D nextPoint;
public SprayTaskPointCollectorPushBO(Integer index, Point2D currentPoint, Point2D nextPoint) {
public SprayTaskPointCollectorPushBO(String cmdId, String cmdCode, Integer index, Integer number, Point2D currentPoint, Point2D nextPoint) {
this.cmdId = cmdId;
this.cmdCode = cmdCode;
this.index = index;
this.number = number;
this.currentPoint = currentPoint;
this.nextPoint = nextPoint;
}

7
src/main/java/com/qyft/ms/app/model/bo/SprayTaskSprayed.java

@ -13,10 +13,13 @@ public class SprayTaskSprayed {
*/
@Schema(description = "玻片序号")
private Integer index;
/**
* 当前玻片是第几次喷涂
*/
Integer number;
/**
* 已喷涂点位
*/
private volatile List<Point2D> sprayedPoints;
private volatile Point2D sprayedPoints;
}

3
src/main/java/com/qyft/ms/app/model/vo/SprayTaskStatusVO.java

@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* 喷涂状态VO
@ -23,7 +24,7 @@ public class SprayTaskStatusVO {
* 喷涂参数
*/
@Schema(description = "喷涂参数")
private SprayParams sprayParams;
private Map<String,Object> sprayParams;
}

4
src/main/java/com/qyft/ms/system/common/constant/CommandStatus.java

@ -30,6 +30,10 @@ public class CommandStatus {
*/
public static final String FAIL = "fail";
/**
* 指令执行失败
*/
public static final String SPRAY_TASK_FINISH = "spray_task_finish";
/**
* 业务指令处理完毕反馈
*/
public static final String FINISH = "finish";

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

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

2
src/main/java/com/qyft/ms/system/core/handler/DeviceMessageHandler.java

@ -29,7 +29,7 @@ public class DeviceMessageHandler extends ChannelInboundHandlerAdapter {
}
try {
String serverMsg = buf.toString(CharsetUtil.UTF_8);
log.info("serverMsg: {}", serverMsg);
// log.info("serverMsg: {}", serverMsg);
JSONObject deviceResult = JSONUtil.parseObj(serverMsg);
publisher.publishEvent(new DeviceTcpMessageEvent(this, deviceResult));
} catch (Exception e) {

14
src/main/java/com/qyft/ms/system/core/server/WebSocketServer.java

@ -18,6 +18,20 @@ public class WebSocketServer {
// 消息按顺序发送加锁
private static final Object sendLock = new Object();
public static void sendMessageToClientsNoLog(String message) {
synchronized (sendLock) {
for (Session session : sessions) {
if (session.isOpen()) {
try {
session.getBasicRemote().sendText(message);
} catch (IOException ignored) {
}
}
}
}
}
/**
* 群发消息给所有客户端
*/

8
src/main/java/com/qyft/ms/system/service/WebSocketService.java

@ -11,11 +11,17 @@ import org.springframework.stereotype.Service;
@Service
public class WebSocketService {
public void pushMsgNoLog(String type, Object data) {
WebSocketMessage websocketResult = new WebSocketMessage();
websocketResult.setType(type);
websocketResult.setData(data);
WebSocketServer.sendMessageToClientsNoLog(JSONUtil.toJsonStr(websocketResult));
}
public void pushMsg(String type, Object data) {
WebSocketMessage websocketResult = new WebSocketMessage();
websocketResult.setType(type);
websocketResult.setData(data);
// 发送消息给客户端
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult));
}

Loading…
Cancel
Save