|
|
@ -11,6 +11,7 @@ import com.iflytop.handacid.app.core.state.DeviceState; |
|
|
|
import com.iflytop.handacid.app.model.dto.CommandDTO; |
|
|
|
import com.iflytop.handacid.app.service.ChannelCtrlService; |
|
|
|
import com.iflytop.handacid.app.service.DeviceCommandService; |
|
|
|
import com.iflytop.handacid.app.websocket.server.WebSocketSender; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -27,6 +28,7 @@ import java.util.concurrent.CompletableFuture; |
|
|
|
public class PumpRotateStartCommand extends BaseCommandHandler { |
|
|
|
private final DeviceCommandService deviceCommandService; |
|
|
|
private final ChannelCtrlService channelCtrlService; |
|
|
|
private final WebSocketSender webSocketSender; |
|
|
|
|
|
|
|
@Override |
|
|
|
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|
|
@ -39,11 +41,17 @@ public class PumpRotateStartCommand extends BaseCommandHandler { |
|
|
|
throw new IllegalArgumentException("参数 direction 不能为空"); |
|
|
|
} |
|
|
|
return runAsync(() -> { |
|
|
|
if(Direction.FORWARD.equals(direction)) { |
|
|
|
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); |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|
|
|
CommandUtil.wait(commandFuture); |
|
|
|
}else{ |
|
|
|
Integer newPosition = (Integer) commandFuture.getResponseResult().get("position"); |
|
|
|
webSocketSender.pushPumpPosition(newPosition - currentPosition); |
|
|
|
} else { |
|
|
|
DeviceCommand deviceCommand = channelCtrlService.getPumpBackwardRotateCommandByChannel(channelCode); |
|
|
|
CommandFuture commandFuture = deviceCommandService.sendCommand(deviceCommand); |
|
|
|
CommandUtil.wait(commandFuture); |
|
|
|