diff --git a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java index cb53c73..8703ee3 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -48,20 +48,27 @@ public class ChannelCtrlService { while (!deviceState.isSolutionAddStop()) { List commandFutureList = new ArrayList<>(); for (ChannelState channelState : channelStateList) { + //打开阀门 + DeviceCommand valveOpenDeviceCommand = getValveOpenCommandByChannel(channelState.getChannelCode()); + CommandFuture valveOpenCommandFuture = deviceCommandService.sendCommand(valveOpenDeviceCommand); + CommandUtil.wait(valveOpenCommandFuture); + DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); CommandUtil.wait(currentPositionCommandFuture); Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); channelState.setPumpPositionCache(currentPosition); + Formulation formulation = formulationService.getOne(new LambdaQueryWrapper().eq(Formulation::getSolutionId, channelState.getSolutionId()) .eq(Formulation::getConcentration, channelState.getConcentration()).eq(Formulation::getVolume, channelState.getTargetVolume()).last("limit 1")); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), - channelState.getSolutionName(), formulation.getConcentration(), channelState.getChannelCode().name(), formulation.getVolume()); + channelState.getSolutionName(), formulation.getConcentration(), channelState.getChannelCode().name(), channelState.getTargetVolume()); auditRecordService.saveOrUpdate(auditRecord); } CommandUtil.wait(commandFutureList); + for (ChannelState channelState : channelStateList) {//与缓存的位置比较计算加液量 DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); @@ -80,7 +87,7 @@ public class ChannelCtrlService { DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), - channelState.getSolutionName(), formulation.getConcentration(), channelState.getChannelCode().name(), formulation.getVolume()); + channelState.getSolutionName(), formulation.getConcentration(), channelState.getChannelCode().name(), channelState.getTargetVolume()); auditRecordService.saveOrUpdate(auditRecord); } CommandUtil.wait(commandFutureList); @@ -90,6 +97,9 @@ public class ChannelCtrlService { } finally { for (ChannelState channelState : channelStateList) { channelState.setStateCode(ChannelStateCode.IDLE); + //关闭阀门 + DeviceCommand valveCloseDeviceCommand = getValveCloseCommandByChannel(channelState.getChannelCode()); + deviceCommandService.sendCommand(valveCloseDeviceCommand); } deviceState.setSolutionAddStop(false); } @@ -169,6 +179,30 @@ public class ChannelCtrlService { } /** + * 根据通道code获取阀打开指令 + */ + public DeviceCommand getValveOpenCommandByChannel(ChannelCode channelCode) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.valve1Open(); + case CHANNEL_2 -> DeviceCommandGenerator.valve2Open(); + case CHANNEL_3 -> DeviceCommandGenerator.valve3Open(); + case CHANNEL_4 -> DeviceCommandGenerator.valve4Open(); + }; + } + + /** + * 根据通道code获取阀关闭指令 + */ + public DeviceCommand getValveCloseCommandByChannel(ChannelCode channelCode) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.valve1Close(); + case CHANNEL_2 -> DeviceCommandGenerator.valve2Close(); + case CHANNEL_3 -> DeviceCommandGenerator.valve3Close(); + case CHANNEL_4 -> DeviceCommandGenerator.valve4Close(); + }; + } + + /** * 根据通道code获取泵相对移动指令 */ public DeviceCommand getPumpMoveByCommandByChannel(ChannelCode channelCode, Double position) {