diff --git a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java index ea896fb..0de86cd 100644 --- a/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java +++ b/src/main/java/com/iflytop/handacid/app/command/control/PumpRotateStartCommand.java @@ -40,13 +40,17 @@ public class PumpRotateStartCommand extends BaseCommandHandler { if (direction == null) { throw new IllegalArgumentException("参数 direction 不能为空"); } + Double position = commandDTO.getDoubleParam("position"); + if (position == null) { + throw new IllegalArgumentException("参数 position 不能为空"); + } return runAsync(() -> { if (Direction.FORWARD.equals(direction)) { DeviceCommand getPositionDeviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); CommandFuture positionCommandFuture = deviceCommandService.sendCommand(getPositionDeviceCommand); CommandUtil.wait(positionCommandFuture); Integer currentPosition = (Integer) positionCommandFuture.getResponseResult().get("position"); - DeviceCommand deviceCommand = channelCtrlService.getPumpForwardRotateCommandByChannel(channelCode); + DeviceCommand deviceCommand = channelCtrlService.getPumpMoveCommandByChannel(channelCode, position); CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); CommandUtil.wait(commandFuture); Integer newPosition = (Integer) commandFuture.getResponseResult().get("position"); 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 fc9adf6..ecfe275 100644 --- a/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java +++ b/src/main/java/com/iflytop/handacid/app/service/ChannelCtrlService.java @@ -165,6 +165,18 @@ public class ChannelCtrlService { }; } + /** + * 根据通道code获取泵移动指令 + */ + public DeviceCommand getPumpMoveCommandByChannel(ChannelCode channelCode, Double position) { + return switch (channelCode) { + case CHANNEL_1 -> DeviceCommandGenerator.pump1MoveBy(position); + case CHANNEL_2 -> DeviceCommandGenerator.pump2MoveBy(position); + case CHANNEL_3 -> DeviceCommandGenerator.pump3MoveBy(position); + case CHANNEL_4 -> DeviceCommandGenerator.pump4MoveBy(position); + }; + } + /** * 根据通道code获取泵转数指令