|
|
@ -8,6 +8,7 @@ import com.iflytop.handacid.app.common.utils.CommandUtil; |
|
|
|
import com.iflytop.handacid.app.core.command.BaseCommandHandler; |
|
|
|
import com.iflytop.handacid.app.core.command.CommandFuture; |
|
|
|
import com.iflytop.handacid.app.core.command.DeviceCommand; |
|
|
|
import com.iflytop.handacid.app.core.state.ChannelState; |
|
|
|
import com.iflytop.handacid.app.core.state.DeviceState; |
|
|
|
import com.iflytop.handacid.app.model.dto.CommandDTO; |
|
|
|
import com.iflytop.handacid.app.service.ChannelCtrlService; |
|
|
@ -30,12 +31,21 @@ public class PumpRotateStartCommand extends BaseCommandHandler { |
|
|
|
private final DeviceCommandService deviceCommandService; |
|
|
|
private final ChannelCtrlService channelCtrlService; |
|
|
|
private final WebSocketSender webSocketSender; |
|
|
|
private final DeviceState deviceState; |
|
|
|
|
|
|
|
@Override |
|
|
|
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|
|
|
ChannelCode channelCode = commandDTO.getEnumParam("channelCode", ChannelCode.class); |
|
|
|
if (channelCode == null) { |
|
|
|
throw new IllegalArgumentException("参数 channelCode 不能为空"); |
|
|
|
Long solutionId = commandDTO.getLongParam("solutionId"); |
|
|
|
if (solutionId == null) { |
|
|
|
throw new IllegalArgumentException("参数 solutionId 不能为空"); |
|
|
|
} |
|
|
|
Double concentration = commandDTO.getDoubleParam("concentration"); |
|
|
|
if (concentration == null) { |
|
|
|
throw new IllegalArgumentException("参数 concentration 不能为空"); |
|
|
|
} |
|
|
|
ChannelState channelState = deviceState.getChannelStateBySolution(solutionId, concentration); |
|
|
|
if (channelState == null) { |
|
|
|
throw new IllegalArgumentException("该溶液与浓度未找到对应通道"); |
|
|
|
} |
|
|
|
Direction direction = commandDTO.getEnumParam("direction", Direction.class); |
|
|
|
if (direction == null) { |
|
|
@ -47,25 +57,25 @@ public class PumpRotateStartCommand extends BaseCommandHandler { |
|
|
|
} |
|
|
|
return runAsync(() -> { |
|
|
|
if (Direction.FORWARD.equals(direction)) { |
|
|
|
DeviceCommand currentPositionDeviceCommand = channelCtrlService.getPumpPositionCommandByChannel(channelCode); |
|
|
|
DeviceCommand currentPositionDeviceCommand = channelCtrlService.getPumpPositionCommandByChannel(channelState.getChannelCode()); |
|
|
|
CommandFuture currentPositionCommandFuture = deviceCommandService.sendCommand(currentPositionDeviceCommand); |
|
|
|
CommandUtil.wait(currentPositionCommandFuture); |
|
|
|
Double currentPosition = currentPositionCommandFuture.getResponseResult().getJSONObject("data").getDouble("position"); |
|
|
|
|
|
|
|
|
|
|
|
DeviceCommand deviceCommand = channelCtrlService.getPumpMoveCommandByChannel(channelCode, position); |
|
|
|
DeviceCommand deviceCommand = channelCtrlService.getPumpMoveCommandByChannel(channelState.getChannelCode(), position); |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|
|
|
CommandUtil.wait(commandFuture); |
|
|
|
|
|
|
|
|
|
|
|
DeviceCommand newPositionDeviceCommand = channelCtrlService.getPumpPositionCommandByChannel(channelCode); |
|
|
|
DeviceCommand newPositionDeviceCommand = channelCtrlService.getPumpPositionCommandByChannel(channelState.getChannelCode()); |
|
|
|
CommandFuture newPositionCommandFuture = deviceCommandService.sendCommand(newPositionDeviceCommand); |
|
|
|
CommandUtil.wait(newPositionCommandFuture); |
|
|
|
Double newPosition = (Double) newPositionCommandFuture.getResponseResult().getJSONObject("data").get("position"); |
|
|
|
log.info("currentPosition: {}, newPosition: {}", currentPosition, newPosition); |
|
|
|
webSocketSender.pushPumpPosition((newPosition - currentPosition) / 100); |
|
|
|
} else { |
|
|
|
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); |
|
|
|
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelState.getChannelCode()); |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|
|
|
CommandUtil.wait(commandFuture); |
|
|
|
} |
|
|
|