5 Commits

  1. 11
      src/main/java/com/iflytop/handacid/app/controller/FormulationController.java
  2. 56
      src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java
  3. 8
      src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java
  4. 46
      src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java

11
src/main/java/com/iflytop/handacid/app/controller/FormulationController.java

@ -1,5 +1,6 @@
package com.iflytop.handacid.app.controller; package com.iflytop.handacid.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.iflytop.handacid.app.model.dto.FormulationListDTO; import com.iflytop.handacid.app.model.dto.FormulationListDTO;
import com.iflytop.handacid.app.model.vo.FormulationListVO; import com.iflytop.handacid.app.model.vo.FormulationListVO;
import com.iflytop.handacid.common.base.BasePageQuery; import com.iflytop.handacid.common.base.BasePageQuery;
@ -51,8 +52,14 @@ public class FormulationController {
@PostMapping @PostMapping
@Operation(summary = "创建配方") @Operation(summary = "创建配方")
public Result<String> create(@RequestBody Formulation formulation) { public Result<String> create(@RequestBody Formulation formulation) {
boolean flag = formulationService.save(formulation);
return flag ? Result.success() : Result.failed();
Formulation existFormulation = formulationService.getOne(new LambdaQueryWrapper<Formulation>().eq(Formulation::getSolutionId, formulation.getSolutionId())
.eq(Formulation::getConcentration, formulation.getConcentration()).eq(Formulation::getVolume, formulation.getVolume()).last("limit 1"));
if (existFormulation != null) {
existFormulation.setRevolutions(formulation.getRevolutions());
return formulationService.updateById(existFormulation) ? Result.success() : Result.failed();
} else {
return formulationService.save(formulation) ? Result.success() : Result.failed();
}
} }
@PutMapping @PutMapping

56
src/main/java/com/iflytop/handacid/app/core/command/DeviceCommandGenerator.java

@ -11,6 +11,62 @@ import com.iflytop.handacid.common.enums.MotorDirection;
public class DeviceCommandGenerator { public class DeviceCommandGenerator {
//=========================================== ================================================================= //=========================================== =================================================================
/**
* 阀1 打开
*/
public static DeviceCommand valve1Open() {
return controlCmd(Device.VALVE_1, Action.OPEN, null);
}
/**
* 阀2 打开
*/
public static DeviceCommand valve2Open() {
return controlCmd(Device.VALVE_2, Action.OPEN, null);
}
/**
* 阀3 打开
*/
public static DeviceCommand valve3Open() {
return controlCmd(Device.VALVE_3, Action.OPEN, null);
}
/**
* 阀4 打开
*/
public static DeviceCommand valve4Open() {
return controlCmd(Device.VALVE_4, Action.OPEN, null);
}
/**
* 阀1 关闭
*/
public static DeviceCommand valve1Close() {
return controlCmd(Device.VALVE_1, Action.CLOSE, null);
}
/**
* 阀2 关闭
*/
public static DeviceCommand valve2Close() {
return controlCmd(Device.VALVE_2, Action.CLOSE, null);
}
/**
* 阀3 关闭
*/
public static DeviceCommand valve3Close() {
return controlCmd(Device.VALVE_3, Action.CLOSE, null);
}
/**
* 阀4 关闭
*/
public static DeviceCommand valve4Close() {
return controlCmd(Device.VALVE_4, Action.CLOSE, null);
}
//=========================================== ================================================================= //=========================================== =================================================================
/** /**

8
src/main/java/com/iflytop/handacid/app/core/listener/BleGamepadEventListener.java

@ -42,6 +42,10 @@ public class BleGamepadEventListener {
if (CmdId.event_ble_gamepad_liquid_acid.equals(cmdId)) { if (CmdId.event_ble_gamepad_liquid_acid.equals(cmdId)) {
//判断当前的设备状态 //判断当前的设备状态
log.info("蓝牙手柄 加酸按钮 按下"); log.info("蓝牙手柄 加酸按钮 按下");
if (deviceState.isSolutionPreFillStart()) {//正在预充 忽略加液按钮事件
log.info("正在与预充中...");
return;
}
if (deviceState.isSolutionAdding()) { if (deviceState.isSolutionAdding()) {
channelCtrlService.solutionAddStop(); channelCtrlService.solutionAddStop();
} else { } else {
@ -49,6 +53,10 @@ public class BleGamepadEventListener {
} }
} else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) { } else if (CmdId.event_ble_gamepad_liquid_acid_prefilling.equals(cmdId)) {
log.info("蓝牙手柄 预充按钮 按下"); log.info("蓝牙手柄 预充按钮 按下");
if (deviceState.isSolutionAdding()) {//正在加液 忽略预充按钮事件
log.info("正在加液中...");
return;
}
if (deviceState.isSolutionPreFillStart()) { if (deviceState.isSolutionPreFillStart()) {
channelCtrlService.solutionPreFillStop(); channelCtrlService.solutionPreFillStop();
} else { } else {

46
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);
} }
@ -130,6 +140,11 @@ public class ChannelCtrlService {
} }
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 deviceCommand = getPumpForwardRotateCommandByChannel(channelState.getChannelCode()); DeviceCommand deviceCommand = getPumpForwardRotateCommandByChannel(channelState.getChannelCode());
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(),
@ -163,12 +178,39 @@ public class ChannelCtrlService {
for (ChannelState channelCode : channelCodeList) { for (ChannelState channelCode : channelCodeList) {
channelCode.setPre(true); channelCode.setPre(true);
channelCode.setStateCode(ChannelStateCode.IDLE); channelCode.setStateCode(ChannelStateCode.IDLE);
//关闭阀门
DeviceCommand valveCloseDeviceCommand = getValveCloseCommandByChannel(channelCode.getChannelCode());
deviceCommandService.sendCommand(valveCloseDeviceCommand);
} }
} }
}); });
} }
/** /**
* 根据通道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