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 d33aae4..efd1925 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 @@ -77,15 +77,15 @@ public class SprayTaskExecutor { int sprayNum = 1; 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); + 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); + DeviceCommand motorZPositionSetAboveSlideCommand = DeviceCommandGenerator.motorZPositionSet(height, 15.0); CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); @@ -104,17 +104,21 @@ public class SprayTaskExecutor { continue; } List sprayStepCommands = sprayTaskStep.getSpraySteps().get(i); + DeviceCommand xSprayStepCommands = sprayStepCommands.get(0); + xSprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed());//防止修改了移动速度这里重新设置移动速度 + DeviceCommand ySprayStepCommands = sprayStepCommands.get(1); + ySprayStepCommands.getParam().put("speed", sprayTask.getSprayParams().getMovingSpeed()); List commandFutureList = new ArrayList<>(); - double aXPoint = (double) sprayStepCommands.get(0).getParam().get("position"); - double aYPoint = (double) sprayStepCommands.get(1).getParam().get("position"); + double aXPoint = (double) xSprayStepCommands.getParam().get("position"); + double aYPoint = (double) ySprayStepCommands.getParam().get("position"); - if(cacheXPoint != aXPoint){ - CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStepCommands.get(0)); + if (cacheXPoint != aXPoint) { + CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), xSprayStepCommands); commandFutureList.add(commandFuture); cacheXPoint = aXPoint; } - if(cacheYPoint != aYPoint){ - CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStepCommands.get(1)); + if (cacheYPoint != aYPoint) { + CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), ySprayStepCommands); commandFutureList.add(commandFuture); cacheYPoint = aYPoint; } @@ -126,8 +130,8 @@ public class SprayTaskExecutor { 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) sprayStepCommands.get(0).getParam().get("position") - slideArr[sprayTaskStep.getIndex()][0]; - double nextYPoint = 75.5 - (Double) sprayStepCommands.get(1).getParam().get("position"); + 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); 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 59b9ae9..8a5c13d 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 @@ -1,6 +1,7 @@ package com.qyft.ms.system.service.device; import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; 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; @@ -78,7 +79,7 @@ public class DeviceCommandService { // Boolean success = result.getBool("success"); // if (success == null || !success) { //ack失败 // String message = deviceCommand.getCmdName() + "指令,设备ack错误"; -// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); +// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, message, result)); // throw new RuntimeException(message); // } // webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result)); @@ -89,7 +90,7 @@ public class DeviceCommandService { Boolean success = result.getBool("success"); if (success == null || !success) { //response失败 String message = deviceCommand.getCmdName() + "指令,设备response错误"; - webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); + webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_ERROR, message, result)); throw new RuntimeException(message); } webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.DEVICE_RESULT, deviceCommand.getCmdName() + "指令,设备response正常,耗时:" + (commandFuture.getEndSendTime() - commandFuture.getStartSendTime()), result)); @@ -103,8 +104,10 @@ public class DeviceCommandService { public void handleDeviceResult(JSONObject deviceResult) { String tag = deviceResult.getStr("tag"); if ("ACK".equals(tag)) { + log.info("ACK {}", JSONUtil.toJsonStr(deviceResult)); completeCommandAck(deviceResult); } else if ("RESPONSE".equals(tag)) { + log.info("RESPONSE {}", JSONUtil.toJsonStr(deviceResult)); completeCommandResponse(deviceResult); } else if ("EVENT".equals(tag)) { String eventType = deviceResult.getStr("event_type");