Browse Source

增加根据通道打开 关闭阀门指令

加液增加阀门打开和关闭指令
master
王梦远 2 days ago
parent
commit
188b89f676
  1. 38
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

38
src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

@ -48,20 +48,27 @@ public class ChannelCtrlService {
while (!deviceState.isSolutionAddStop()) { while (!deviceState.isSolutionAddStop()) {
List<CommandFuture> commandFutureList = new ArrayList<>(); List<CommandFuture> commandFutureList = new ArrayList<>();
for (ChannelState channelState : channelStateList) { for (ChannelState channelState : channelStateList) {
//打开阀门
DeviceCommand valveOpenDeviceCommand = getValveOpenCommandByChannel(channelState.getChannelCode());
CommandFuture valveOpenCommandFuture = deviceCommandService.sendCommand(valveOpenDeviceCommand);
CommandUtil.wait(valveOpenCommandFuture);
DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode());
CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand);
CommandUtil.wait(currentPositionCommandFuture); CommandUtil.wait(currentPositionCommandFuture);
Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position");
channelState.setPumpPositionCache(currentPosition); channelState.setPumpPositionCache(currentPosition);
Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId()) Formulation formulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, channelState.getSolutionId())
.eq(Formulation::getConcentration, channelState.getConcentration()).eq(Formulation::getVolume, channelState.getTargetVolume()).last("limit 1")); .eq(Formulation::getConcentration, channelState.getConcentration()).eq(Formulation::getVolume, channelState.getTargetVolume()).last("limit 1"));
DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), 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); auditRecordService.saveOrUpdate(auditRecord);
} }
CommandUtil.wait(commandFutureList); CommandUtil.wait(commandFutureList);
for (ChannelState channelState : channelStateList) {//与缓存的位置比较计算加液量 for (ChannelState channelState : channelStateList) {//与缓存的位置比较计算加液量
DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode()); DeviceCommand currentPositionDeviceCommand = getPumpPositionCommandByChannel(channelState.getChannelCode());
CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand);
@ -80,7 +87,7 @@ public class ChannelCtrlService {
DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions()); DeviceCommand deviceCommand = getPumpMoveByCommandByChannel(channelState.getChannelCode(), formulation.getRevolutions());
commandFutureList.add(deviceCommandService.sendCommand(deviceCommand)); commandFutureList.add(deviceCommandService.sendCommand(deviceCommand));
AuditRecord auditRecord = new AuditRecord(deviceState.getCurrentUser().getId(), deviceState.getCurrentUser().getNickname(), channelState.getSolutionId(), 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); auditRecordService.saveOrUpdate(auditRecord);
} }
CommandUtil.wait(commandFutureList); CommandUtil.wait(commandFutureList);
@ -90,6 +97,9 @@ public class ChannelCtrlService {
} finally { } finally {
for (ChannelState channelState : channelStateList) { for (ChannelState channelState : channelStateList) {
channelState.setStateCode(ChannelStateCode.IDLE); channelState.setStateCode(ChannelStateCode.IDLE);
//关闭阀门
DeviceCommand valveCloseDeviceCommand = getValveCloseCommandByChannel(channelState.getChannelCode());
deviceCommandService.sendCommand(valveCloseDeviceCommand);
} }
deviceState.setSolutionAddStop(false); 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获取泵相对移动指令 * 根据通道code获取泵相对移动指令
*/ */
public DeviceCommand getPumpMoveByCommandByChannel(ChannelCode channelCode, Double position) { public DeviceCommand getPumpMoveByCommandByChannel(ChannelCode channelCode, Double position) {

Loading…
Cancel
Save