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 b97b6a3..841a1b8 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 @@ -108,14 +108,6 @@ public class SprayTaskExecutor { int currentStep = 0; //当前喷涂步骤 int sprayNum = 1; for (SprayTaskStep sprayTaskStep : sprayTask.getSprayTaskStepList()) {//循环进行多次喷涂 - //加快速度 -// DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(20.0);//x轴电机速度设置 -// DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(20.0);//y轴电机速度设置 -// DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(20.0);//z轴电机速度设置 -// CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); -// CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); -// CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); -// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); //先移动到玻片位置 DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(slideArr[sprayTaskStep.getIndex()][0],20.0); DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(75.5 - slideArr[sprayTaskStep.getIndex()][1],20.0); @@ -129,15 +121,6 @@ public class SprayTaskExecutor { CommandFuture motorZPositionSetAboveSlideCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetAboveSlideCommand); commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetAboveSlideCommandFuture); - //还原速度 -// motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//x轴电机速度设置 -// motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 -// motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 -// motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); -// motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); -// motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); -// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); - DeviceCommand syringePumpForwardCommand = DeviceCommandGenerator.syringePumpForward(sprayTask.getSprayParams().getVolume());//推动移动注射泵 CommandFuture syringePumpForwardCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpForwardCommand); commandWait(syringePumpForwardCommandFuture); @@ -156,6 +139,7 @@ public class SprayTaskExecutor { List commandFutureList = new ArrayList<>(); double aXPoint = (double) sprayStepCommands.get(0).getParam().get("position"); double aYPoint = (double) sprayStepCommands.get(1).getParam().get("position"); + if(cacheXPoint != aXPoint){ CommandFuture commandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), sprayStepCommands.get(0)); commandFutureList.add(commandFuture); @@ -209,15 +193,6 @@ public class SprayTaskExecutor { CommandFuture nozzleValveCloseCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), nozzleValveCloseCommand); commandWait(nozzleValveCloseCommandFuture); - //加快速度 -// DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(20.0);//x轴电机速度设置 -// DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(20.0);//y轴电机速度设置 -// DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(20.0);//y轴电机速度设置 -// CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); -// CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); -// CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); -// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); - //XYZ回原点 DeviceCommand motorXPositionSetCommand = DeviceCommandGenerator.motorXPositionSet(0.0,20.0); DeviceCommand motorYPositionSetCommand = DeviceCommandGenerator.motorYPositionSet(0.0,20.0); @@ -227,14 +202,6 @@ public class SprayTaskExecutor { CommandFuture motorZPositionSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZPositionSetCommand); commandWait(motorXPositionSetCommandFuture, motorYPositionSetCommandFuture, motorZPositionSetCommandFuture); - //还原速度 -// motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//x轴电机速度设置 -// motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 -// motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 -// motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); -// motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); -// motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); -// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SUCCESS, "喷涂任务执行成功")); webSocketService.pushCMDResponseMsg(FrontResponseGenerator.generateJson(sprayTask.getCmdId(), sprayTask.getCmdCode(), CommandStatus.SPRAY_TASK_FINISH, "喷涂任务结束")); 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 50c5e74..65ff5a6 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 @@ -71,12 +71,25 @@ public class SprayTask { Boolean highVoltage, Double highVoltageValue, Double movingSpeed) { - sprayParams.setMotorZHeight(motorZHeight); - sprayParams.setGasPressure(gasPressure); - sprayParams.setVolume(volume); - sprayParams.setHighVoltage(highVoltage); - sprayParams.setHighVoltageValue(highVoltageValue); - sprayParams.setMovingSpeed(movingSpeed); + if (motorZHeight != null) { + sprayParams.setMotorZHeight(motorZHeight); + } + if (gasPressure != null) { + sprayParams.setGasPressure(gasPressure); + } + if (volume != null) { + sprayParams.setVolume(volume); + } + if (highVoltage != null) { + sprayParams.setHighVoltage(highVoltage); + } + if (highVoltageValue != null) { + sprayParams.setHighVoltageValue(highVoltageValue); + } + if (movingSpeed != null) { + sprayParams.setMovingSpeed(movingSpeed); + } + } public void setSprayParam(String matrixPathType, diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java index 8f74425..a23b9fc 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayChangeParam.java @@ -42,20 +42,23 @@ public class MatrixSprayChangeParam extends BaseCommandHandler { Boolean highVoltage = form.getBooleanParam("highVoltage"); 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"); } + + sprayTask.setChangeSprayParam(motorZHeight, gasPressure, volume, highVoltage, highVoltageValue, movingSpeed); + return runAsync(() -> { //1.速度 - DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置 - DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置 - DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(movingSpeed);//z轴电机速度设置 - CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); - CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); - CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); - commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); +// DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(movingSpeed);//x轴电机速度设置 +// DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(movingSpeed);//y轴电机速度设置 +// DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(movingSpeed);//z轴电机速度设置 +// CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); +// CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); +// CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); +// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); //2.流速 // DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(volume);//注射泵流速设置 // CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), syringePumpVolumeSetCommand); @@ -64,7 +67,7 @@ public class MatrixSprayChangeParam extends BaseCommandHandler { SysSettings slideHeightSysSettings = sysSettingsService.getOne(new LambdaQueryWrapper().eq(SysSettings::getCode, "slide_height")); Double slideHeight = Double.parseDouble(slideHeightSysSettings.getValue()); Double height = slideHeight - motorZHeight; - DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height);//移动z轴到指定位置 + DeviceCommand smotorZPositionSetCommand = DeviceCommandGenerator.motorZPositionSet(height, sprayTask.getSprayParams().getMovingSpeed());//移动z轴到指定位置 CommandFuture smotorZPositionSetCommandFuture = deviceCommandService.sendCommand(form.getCmdId(), form.getCmdCode(), smotorZPositionSetCommand); commandWait(smotorZPositionSetCommandFuture); if (!sprayTask.isPaused()) { diff --git a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java index 9a6073d..a3046fb 100644 --- a/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java +++ b/src/main/java/com/qyft/ms/app/front/cmd/business/MatrixSprayStart.java @@ -151,13 +151,13 @@ public class MatrixSprayStart extends BaseCommandHandler { operationLogService.add(operationLog); //1.速度 - DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//x轴电机速度设置 - DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 - DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//z轴电机速度设置 - CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); - CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); - CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); - commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); +// DeviceCommand motorXSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorXSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//x轴电机速度设置 +// DeviceCommand motorYSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorYSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//y轴电机速度设置 +// DeviceCommand motorZSpeedSetCmdToDeviceCommand = DeviceCommandGenerator.motorZSpeedSet(sprayTask.getSprayParams().getMovingSpeed());//z轴电机速度设置 +// CommandFuture motorXSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorXSpeedSetCmdToDeviceCommand); +// CommandFuture motorYSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorYSpeedSetCmdToDeviceCommand); +// CommandFuture motorZSpeedSetCmdToDeviceCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), motorZSpeedSetCmdToDeviceCommand); +// commandWait(motorXSpeedSetCmdToDeviceCommandFuture, motorYSpeedSetCmdToDeviceCommandFuture, motorZSpeedSetCmdToDeviceCommandFuture); //2.流速 // DeviceCommand syringePumpVolumeSetCommand = DeviceCommandGenerator.syringePumpVolumeSet(sprayTask.getSprayParams().getVolume());//注射泵流速设置 // CommandFuture syringePumpVolumeSetCommandFuture = deviceCommandService.sendCommand(sprayTask.getCmdId(), sprayTask.getCmdCode(), syringePumpVolumeSetCommand); 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 e2fb119..c5b5a12 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 @@ -2,6 +2,7 @@ package com.qyft.ms.system.common.device.command; import cn.hutool.json.JSONObject; import lombok.Getter; +import lombok.Setter; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -11,17 +12,22 @@ public class CommandFuture { /** * 用于保存ack反馈 */ - private final CompletableFuture ackFuture = new CompletableFuture<>(); +// private final CompletableFuture ackFuture = new CompletableFuture<>(); /** * 用于保存response反馈 */ private final CompletableFuture responseFuture = new CompletableFuture<>(); + @Setter + private long startSendTime; + @Setter + private long endSendTime; + /** * 完成ack反馈 */ public void completeAck(JSONObject result) { - ackFuture.complete(result); +// ackFuture.complete(result); } /** @@ -35,9 +41,9 @@ public class CommandFuture { /** * 获取ack反馈的json */ - public JSONObject getAckResult() throws ExecutionException, InterruptedException { - return ackFuture.get(); - } +// public JSONObject getAckResult() throws ExecutionException, InterruptedException { +// return ackFuture.get(); +// } /** * 获取response反馈的json diff --git a/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java b/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java index 0dc3137..4b22ec4 100644 --- a/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java +++ b/src/main/java/com/qyft/ms/system/common/device/command/DeviceCommandGenerator.java @@ -500,9 +500,9 @@ public class DeviceCommandGenerator { * 设备指令包装 */ private static DeviceCommand deviceCmd(String code, String device, String action, Map params, String commandName) { - int cmdId = CyclicNumberGenerator.getInstance().generateNumber(); +// int cmdId = CyclicNumberGenerator.getInstance().generateNumber(); DeviceCommand cmdToDevice = new DeviceCommand(); - cmdToDevice.setCmdId(cmdId); +// cmdToDevice.setCmdId(cmdId); cmdToDevice.setCmdCode(code); cmdToDevice.setDevice(device); cmdToDevice.setAction(action); 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 8ceb1a0..cfb9df0 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 @@ -4,6 +4,7 @@ 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.device.command.CommandFuture; +import com.qyft.ms.system.common.device.command.CyclicNumberGenerator; import com.qyft.ms.system.common.device.command.FrontResponseGenerator; import com.qyft.ms.system.core.client.DeviceTcpClient; import com.qyft.ms.system.model.bo.DeviceCommand; @@ -29,29 +30,35 @@ public class DeviceCommandService { public CommandFuture executeCommand(DeviceCommand cmdToDevice) { + int cmdId = CyclicNumberGenerator.getInstance().generateNumber(); + cmdToDevice.setCmdId(cmdId); CommandFuture cmdFuture = new CommandFuture(); commandFutureMap.put(cmdToDevice.getCmdId(), cmdFuture); + cmdFuture.setStartSendTime(System.currentTimeMillis()); if (!deviceTcpClient.sendToJSON(cmdToDevice)) { commandFutureMap.remove(cmdToDevice.getCmdId()); throw new RuntimeException("向设备发送指令失败"); } - cmdFuture.getResponseFuture().whenComplete((result, ex) -> - commandFutureMap.remove(cmdToDevice.getCmdId())); + cmdFuture.getResponseFuture().whenComplete((result, ex) -> { + log.info("commandFutureMap 移除id:{} 剩余:{}", cmdToDevice.getCmdId(),commandFutureMap.size()); + commandFutureMap.remove(cmdToDevice.getCmdId()); + }); + return cmdFuture; } public CommandFuture sendCommandNoFront(DeviceCommand deviceCommand) { CommandFuture commandFuture = executeCommand(deviceCommand); - commandFuture.getAckFuture().thenApply(result -> { - Boolean status = result.getBool("status"); - if (!status) { //ack失败 - String message = deviceCommand.getCmdName() + "指令,设备ack错误"; - throw new RuntimeException(message); - } - return result; - }); +// commandFuture.getAckFuture().thenApply(result -> { +// Boolean status = result.getBool("status"); +// if (!status) { //ack失败 +// String message = deviceCommand.getCmdName() + "指令,设备ack错误"; +// throw new RuntimeException(message); +// } +// return result; +// }); commandFuture.getResponseFuture().thenApply(result -> { Boolean status = result.getBool("status"); @@ -67,17 +74,17 @@ public class DeviceCommandService { public CommandFuture sendCommand(String cmdId, String cmdCode, DeviceCommand deviceCommand) throws IOException { CommandFuture commandFuture = executeCommand(deviceCommand); - webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getCmdName() + "指令", deviceCommand)); - commandFuture.getAckFuture().thenApply(result -> { - Boolean status = result.getBool("status"); - if (!status) { //ack失败 - String message = deviceCommand.getCmdName() + "指令,设备ack错误"; - webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); - throw new RuntimeException(message); - } - webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result)); - return result; - }); +// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, "已向设备发送了" + deviceCommand.getCmdName() + "指令", deviceCommand)); +// commandFuture.getAckFuture().thenApply(result -> { +// Boolean status = result.getBool("status"); +// if (!status) { //ack失败 +// String message = deviceCommand.getCmdName() + "指令,设备ack错误"; +// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); +// throw new RuntimeException(message); +// } +// webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备ack正常", result)); +// return result; +// }); commandFuture.getResponseFuture().thenApply(result -> { Boolean status = result.getBool("status"); @@ -86,7 +93,7 @@ public class DeviceCommandService { webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.SEND, message, result)); throw new RuntimeException(message); } - webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备response正常", result)); + webSocketService.pushDebugMsg(FrontResponseGenerator.generateJson(cmdId, cmdCode, CommandStatus.RESULT, deviceCommand.getCmdName() + "指令,设备response正常,耗时:" + (commandFuture.getEndSendTime() - commandFuture.getStartSendTime()), result)); return result.get("data"); }); @@ -113,13 +120,13 @@ public class DeviceCommandService { } public void completeCommandAck(JSONObject deviceResult) { - Integer cmdId = deviceResult.getInt("cmdId"); - if (cmdId != null) { - CommandFuture future = commandFutureMap.get(cmdId); - if (future != null) { - future.completeAck(deviceResult); - } - } +// Integer cmdId = deviceResult.getInt("cmdId"); +// if (cmdId != null) { +// CommandFuture future = commandFutureMap.get(cmdId); +// if (future != null) { +// future.completeAck(deviceResult); +// } +// } } public void completeCommandResponse(JSONObject deviceResult) { @@ -127,6 +134,7 @@ public class DeviceCommandService { if (cmdId != null) { CommandFuture future = commandFutureMap.get(cmdId); if (future != null) { + future.setEndSendTime(System.currentTimeMillis()); future.completeResponse(deviceResult); } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index db30da3..eabc930 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -38,9 +38,8 @@ jwt: tcp: enable: true # 是否开启 TCP 连接 server-enable: true # 是否开启 TCP 连接 -# host: 127.0.0.1 - # host: 192.168.1.168 - host: 192.168.1.168 + host: 127.0.0.1 +# host: 192.168.100.168 port: 9080 reconnect: 5000 # 断线重连间隔(单位:毫秒) timeout: 10000 # 连接超时时间(单位:毫秒)