Browse Source

修改调试指令

master
王梦远 2 weeks ago
parent
commit
74e86febdf
  1. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/HeatRodGetCommand.java
  2. 6
      src/main/java/com/iflytop/colortitration/app/command/debug/LightOpenCommand.java
  3. 7
      src/main/java/com/iflytop/colortitration/app/command/debug/RoboticArmBigMotorMoveByCommand.java
  4. 7
      src/main/java/com/iflytop/colortitration/app/command/debug/RoboticArmSmallMotorMoveByCommand.java
  5. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpCloseCommand.java
  6. 12
      src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpMoveCommand.java
  7. 18
      src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpOpenCommand.java
  8. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/StirMotorMoveByCommand.java
  9. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/StirMotorOriginCommand.java
  10. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorDisableCommand.java
  11. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorEnableCommand.java
  12. 12
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorMoveByCommand.java
  13. 8
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorMoveToCommand.java
  14. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorOriginCommand.java
  15. 4
      src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorStopCommand.java
  16. 7
      src/main/java/com/iflytop/colortitration/app/command/debug/ZMotorMoveByCommand.java
  17. 28
      src/main/java/com/iflytop/colortitration/app/core/command/DeviceCommandGenerator.java

4
src/main/java/com/iflytop/colortitration/app/command/debug/HeatRodGetCommand.java

@ -31,8 +31,8 @@ public class HeatRodGetCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (heatModuleCodeStr) { DeviceCommand deviceCommand = switch (heatModuleCodeStr) {
case "heat_module_01" -> DeviceCommandGenerator.heatRod1Get();
case "heat_module_02" -> DeviceCommandGenerator.heatRod2Get();
case "heat_module_1" -> DeviceCommandGenerator.heatRod1Get();
case "heat_module_2" -> DeviceCommandGenerator.heatRod2Get();
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

6
src/main/java/com/iflytop/colortitration/app/command/debug/LightOpenCommand.java

@ -6,7 +6,6 @@ import com.iflytop.colortitration.app.core.command.DeviceCommand;
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator;
import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.model.dto.CommandDTO;
import com.iflytop.colortitration.app.service.DeviceCommandService; import com.iflytop.colortitration.app.service.DeviceCommandService;
import com.iflytop.colortitration.common.base.IBaseEnum;
import com.iflytop.colortitration.common.enums.TricolorLightColor; import com.iflytop.colortitration.common.enums.TricolorLightColor;
import com.iflytop.colortitration.common.exception.AppException; import com.iflytop.colortitration.common.exception.AppException;
import com.iflytop.colortitration.common.result.ResultCode; import com.iflytop.colortitration.common.result.ResultCode;
@ -33,9 +32,10 @@ public class LightOpenCommand extends BaseCommandHandler {
if (StringUtils.isEmpty(colorStr)) { if (StringUtils.isEmpty(colorStr)) {
throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失
} }
if (!IBaseEnum.contains(TricolorLightColor.class, colorStr)) {
// todo 颜色 需要确认下
/*if (!IBaseEnum.contains(TricolorLightColor.class, colorStr)) {
throw new AppException(ResultCode.PARAMETER_TYPE_MISMATCH);//参数类型不匹配 throw new AppException(ResultCode.PARAMETER_TYPE_MISMATCH);//参数类型不匹配
}
}*/
TricolorLightColor color = TricolorLightColor.valueOf(colorStr); TricolorLightColor color = TricolorLightColor.valueOf(colorStr);
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.tricolorLightOpen(color); DeviceCommand deviceCommand = DeviceCommandGenerator.tricolorLightOpen(color);

7
src/main/java/com/iflytop/colortitration/app/command/debug/RoboticArmBigMotorMoveByCommand.java

@ -8,11 +8,8 @@ import com.iflytop.colortitration.app.core.command.DeviceCommand;
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator;
import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.model.dto.CommandDTO;
import com.iflytop.colortitration.app.service.DeviceCommandService; import com.iflytop.colortitration.app.service.DeviceCommandService;
import com.iflytop.colortitration.common.exception.AppException;
import com.iflytop.colortitration.common.result.ResultCode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -30,13 +27,9 @@ public class RoboticArmBigMotorMoveByCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
String motorCode = commandDTO.getStringParam("motorCode");
Double speed = commandDTO.getDoubleParam("speed"); Double speed = commandDTO.getDoubleParam("speed");
Integer times = commandDTO.getIntegerParam("times"); Integer times = commandDTO.getIntegerParam("times");
Double angle = commandDTO.getDoubleParam("angle"); Double angle = commandDTO.getDoubleParam("angle");
if (StringUtils.isEmpty(motorCode) || angle == null) {
throw new AppException(ResultCode.INVALID_PARAMETER);
}
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
DeviceCommand deviceCommand = DeviceCommandGenerator.roboticArmBigMotorSetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.roboticArmBigMotorSetSpeed(speed);

7
src/main/java/com/iflytop/colortitration/app/command/debug/RoboticArmSmallMotorMoveByCommand.java

@ -8,11 +8,8 @@ import com.iflytop.colortitration.app.core.command.DeviceCommand;
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator;
import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.model.dto.CommandDTO;
import com.iflytop.colortitration.app.service.DeviceCommandService; import com.iflytop.colortitration.app.service.DeviceCommandService;
import com.iflytop.colortitration.common.exception.AppException;
import com.iflytop.colortitration.common.result.ResultCode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -30,13 +27,9 @@ public class RoboticArmSmallMotorMoveByCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
String motorCode = commandDTO.getStringParam("motorCode");
Double speed = commandDTO.getDoubleParam("speed"); Double speed = commandDTO.getDoubleParam("speed");
Integer times = commandDTO.getIntegerParam("times"); Integer times = commandDTO.getIntegerParam("times");
Double angle = commandDTO.getDoubleParam("angle"); Double angle = commandDTO.getDoubleParam("angle");
if (StringUtils.isEmpty(motorCode) || angle == null) {
throw new AppException(ResultCode.INVALID_PARAMETER);
}
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
DeviceCommand deviceCommand = DeviceCommandGenerator.roboticArmSmallMotorSetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.roboticArmSmallMotorSetSpeed(speed);

4
src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpCloseCommand.java

@ -30,8 +30,8 @@ public class StepPumpCloseCommand extends BaseCommandHandler {
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (pumpCode) { DeviceCommand deviceCommand = switch (pumpCode) {
case "set_pump_1" -> DeviceCommandGenerator.stepPump1Stop(); case "set_pump_1" -> DeviceCommandGenerator.stepPump1Stop();
case "set_pump_02" -> DeviceCommandGenerator.stepPump2Stop();
case "set_pump_03" -> DeviceCommandGenerator.stepPump3Stop();
case "set_pump_2" -> DeviceCommandGenerator.stepPump2Stop();
case "set_pump_3" -> DeviceCommandGenerator.stepPump3Stop();
default -> throw new IllegalStateException("Unexpected value: " + pumpCode); default -> throw new IllegalStateException("Unexpected value: " + pumpCode);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

12
src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpMoveCommand.java

@ -34,9 +34,9 @@ public class StepPumpMoveCommand extends BaseCommandHandler {
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
DeviceCommand deviceSetCommand = switch (pumpCode) { DeviceCommand deviceSetCommand = switch (pumpCode) {
case "set_pump_01" -> DeviceCommandGenerator.stepPump1SetSpeed(speed);
case "set_pump_02" -> DeviceCommandGenerator.stepPump2SetSpeed(speed);
case "set_pump_03" -> DeviceCommandGenerator.stepPump3SetSpeed(speed);
case "set_pump_1" -> DeviceCommandGenerator.stepPump1SetSpeed(speed);
case "set_pump_2" -> DeviceCommandGenerator.stepPump2SetSpeed(speed);
case "set_pump_3" -> DeviceCommandGenerator.stepPump3SetSpeed(speed);
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
CommandFuture sentCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceSetCommand); CommandFuture sentCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceSetCommand);
@ -44,9 +44,9 @@ public class StepPumpMoveCommand extends BaseCommandHandler {
} }
DeviceCommand deviceMoveCommand = switch (pumpCode) { DeviceCommand deviceMoveCommand = switch (pumpCode) {
case "set_pump_01" -> DeviceCommandGenerator.stepPump1MoveBy(distance);
case "set_pump_02" -> DeviceCommandGenerator.stepPump2MoveBy(distance);
case "set_pump_03" -> DeviceCommandGenerator.stepPump3MoveBy(distance);
case "set_pump_1" -> DeviceCommandGenerator.stepPump1MoveBy(distance);
case "set_pump_2" -> DeviceCommandGenerator.stepPump2MoveBy(distance);
case "set_pump_3" -> DeviceCommandGenerator.stepPump3MoveBy(distance);
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
CommandFuture moveCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand); CommandFuture moveCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand);

18
src/main/java/com/iflytop/colortitration/app/command/debug/StepPumpOpenCommand.java

@ -34,9 +34,9 @@ public class StepPumpOpenCommand extends BaseCommandHandler {
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
DeviceCommand deviceSetCommand = switch (pumpCode) { DeviceCommand deviceSetCommand = switch (pumpCode) {
case "set_pump_1" -> DeviceCommandGenerator.stepPump1SetSpeed(speed);
case "set_pump_2" -> DeviceCommandGenerator.stepPump2SetSpeed(speed);
case "set_pump_3" -> DeviceCommandGenerator.stepPump3SetSpeed(speed);
case "set_motor_1" -> DeviceCommandGenerator.stepPump1SetSpeed(speed);
case "set_motor_2" -> DeviceCommandGenerator.stepPump2SetSpeed(speed);
case "set_motor_3" -> DeviceCommandGenerator.stepPump3SetSpeed(speed);
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
CommandFuture sentCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceSetCommand); CommandFuture sentCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceSetCommand);
@ -45,15 +45,15 @@ public class StepPumpOpenCommand extends BaseCommandHandler {
DeviceCommand deviceRoteCommand = switch (direction) { DeviceCommand deviceRoteCommand = switch (direction) {
case "forward" -> switch (pumpCode) { case "forward" -> switch (pumpCode) {
case "set_pump_1" -> DeviceCommandGenerator.stepPump1ForwardRotate();
case "set_pump_2" -> DeviceCommandGenerator.stepPump2ForwardRotate();
case "set_pump_3" -> DeviceCommandGenerator.stepPump3ForwardRotate();
case "set_motor_1" -> DeviceCommandGenerator.stepPump1ForwardRotate();
case "set_motor_2" -> DeviceCommandGenerator.stepPump2ForwardRotate();
case "set_motor_3" -> DeviceCommandGenerator.stepPump3ForwardRotate();
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
case "backward" -> switch (pumpCode) { case "backward" -> switch (pumpCode) {
case "set_pump_1" -> DeviceCommandGenerator.stepPump1BackwardRotate();
case "set_pump_2" -> DeviceCommandGenerator.stepPump2BackwardRotate();
case "set_pump_3" -> DeviceCommandGenerator.stepPump3BackwardRotate();
case "set_motor_1" -> DeviceCommandGenerator.stepPump1BackwardRotate();
case "set_motor_2" -> DeviceCommandGenerator.stepPump2BackwardRotate();
case "set_motor_3" -> DeviceCommandGenerator.stepPump3BackwardRotate();
default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效 default -> throw new AppException(ResultCode.INVALID_PARAMETER);//参数无效
}; };
default -> throw new IllegalStateException("Unexpected value: " + direction); default -> throw new IllegalStateException("Unexpected value: " + direction);

4
src/main/java/com/iflytop/colortitration/app/command/debug/StirMotorMoveByCommand.java

@ -78,8 +78,8 @@ public class StirMotorMoveByCommand extends BaseCommandHandler {
} else { } else {
DeviceCommand deviceMoveCommand = switch (motorCode) { DeviceCommand deviceMoveCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.stirMotor1MoveBy(distance);
case "titration_motor_02" -> DeviceCommandGenerator.stirMotor2MoveBy(distance);
case "titration_motor_1" -> DeviceCommandGenerator.stirMotor1MoveBy(distance);
case "titration_motor_2" -> DeviceCommandGenerator.stirMotor2MoveBy(distance);
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand);

4
src/main/java/com/iflytop/colortitration/app/command/debug/StirMotorOriginCommand.java

@ -35,8 +35,8 @@ public class StirMotorOriginCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (motorCode) { DeviceCommand deviceCommand = switch (motorCode) {
case "magnet_stir_motor_01" -> DeviceCommandGenerator.stirMotor1Origin();
case "magnet_stir_motor_02" -> DeviceCommandGenerator.stirMotor2Origin();
case "stir_motor_1" -> DeviceCommandGenerator.stirMotor1Origin();
case "stir_motor_2" -> DeviceCommandGenerator.stirMotor2Origin();
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

4
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorDisableCommand.java

@ -35,8 +35,8 @@ public class TitrationMotorDisableCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (motorCode) { DeviceCommand deviceCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1Disable();
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2Disable();
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1Disable();
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2Disable();
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

4
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorEnableCommand.java

@ -35,8 +35,8 @@ public class TitrationMotorEnableCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (motorCode) { DeviceCommand deviceCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1Enable();
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2Enable();
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1Enable();
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2Enable();
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

12
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorMoveByCommand.java

@ -40,12 +40,12 @@ public class TitrationMotorMoveByCommand extends BaseCommandHandler {
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
switch (motorCode) { switch (motorCode) {
case "titration_motor_01" -> {
case "titration_motor_1" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1SetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1SetSpeed(speed);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
} }
case "titration_motor_02" -> {
case "titration_motor_2" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2SetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2SetSpeed(speed);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
@ -55,7 +55,7 @@ public class TitrationMotorMoveByCommand extends BaseCommandHandler {
if (times != null) { if (times != null) {
for (int i = 0; i < times; i++) { for (int i = 0; i < times; i++) {
switch (motorCode) { switch (motorCode) {
case "titration_motor_01" -> {
case "titration_motor_1" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1MoveBy(distance); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1MoveBy(distance);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
@ -64,7 +64,7 @@ public class TitrationMotorMoveByCommand extends BaseCommandHandler {
CommandFuture backCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceBackCommand); CommandFuture backCommandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceBackCommand);
CommandUtil.wait(backCommandFuture); CommandUtil.wait(backCommandFuture);
} }
case "titration_motor_02" -> {
case "titration_motor_2" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2MoveBy(distance); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2MoveBy(distance);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
@ -78,8 +78,8 @@ public class TitrationMotorMoveByCommand extends BaseCommandHandler {
} else { } else {
DeviceCommand deviceMoveCommand = switch (motorCode) { DeviceCommand deviceMoveCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1MoveBy(distance);
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2MoveBy(distance);
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1MoveBy(distance);
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2MoveBy(distance);
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand);

8
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorMoveToCommand.java

@ -38,12 +38,12 @@ public class TitrationMotorMoveToCommand extends BaseCommandHandler {
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
switch (motorCode) { switch (motorCode) {
case "titration_motor_01" -> {
case "titration_motor_1" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1SetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor1SetSpeed(speed);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
} }
case "titration_motor_02" -> {
case "titration_motor_2" -> {
DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2SetSpeed(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.titrationMotor2SetSpeed(speed);
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);
CommandUtil.wait(commandFuture); CommandUtil.wait(commandFuture);
@ -52,8 +52,8 @@ public class TitrationMotorMoveToCommand extends BaseCommandHandler {
} }
DeviceCommand deviceMoveCommand = switch (motorCode) { DeviceCommand deviceMoveCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1MoveTo(position);
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2MoveTo(position);
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1MoveTo(position);
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2MoveTo(position);
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceMoveCommand);

4
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorOriginCommand.java

@ -35,8 +35,8 @@ public class TitrationMotorOriginCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (motorCode) { DeviceCommand deviceCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1Origin();
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2Origin();
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1Origin();
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2Origin();
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

4
src/main/java/com/iflytop/colortitration/app/command/debug/TitrationMotorStopCommand.java

@ -35,8 +35,8 @@ public class TitrationMotorStopCommand extends BaseCommandHandler {
} }
return runAsync(() -> { return runAsync(() -> {
DeviceCommand deviceCommand = switch (motorCode) { DeviceCommand deviceCommand = switch (motorCode) {
case "titration_motor_01" -> DeviceCommandGenerator.titrationMotor1Stop();
case "titration_motor_02" -> DeviceCommandGenerator.titrationMotor2Stop();
case "titration_motor_1" -> DeviceCommandGenerator.titrationMotor1Stop();
case "titration_motor_2" -> DeviceCommandGenerator.titrationMotor2Stop();
default -> throw new AppException(ResultCode.INVALID_PARAMETER); default -> throw new AppException(ResultCode.INVALID_PARAMETER);
}; };
CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); CommandFuture commandFuture = deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand);

7
src/main/java/com/iflytop/colortitration/app/command/debug/ZMotorMoveByCommand.java

@ -8,11 +8,8 @@ import com.iflytop.colortitration.app.core.command.DeviceCommand;
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator;
import com.iflytop.colortitration.app.model.dto.CommandDTO; import com.iflytop.colortitration.app.model.dto.CommandDTO;
import com.iflytop.colortitration.app.service.DeviceCommandService; import com.iflytop.colortitration.app.service.DeviceCommandService;
import com.iflytop.colortitration.common.exception.AppException;
import com.iflytop.colortitration.common.result.ResultCode;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -30,13 +27,9 @@ public class ZMotorMoveByCommand extends BaseCommandHandler {
@Override @Override
public CompletableFuture<Void> handle(CommandDTO commandDTO) { public CompletableFuture<Void> handle(CommandDTO commandDTO) {
String motorCode = commandDTO.getStringParam("motorCode");
Double speed = commandDTO.getDoubleParam("speed"); Double speed = commandDTO.getDoubleParam("speed");
Integer times = commandDTO.getIntegerParam("times"); Integer times = commandDTO.getIntegerParam("times");
Double distance = commandDTO.getDoubleParam("distance"); Double distance = commandDTO.getDoubleParam("distance");
if (StringUtils.isEmpty(motorCode) || distance == null) {
throw new AppException(ResultCode.INVALID_PARAMETER);
}
return runAsync(() -> { return runAsync(() -> {
if (speed != null) { if (speed != null) {
DeviceCommand deviceCommand = DeviceCommandGenerator.zSet(speed); DeviceCommand deviceCommand = DeviceCommandGenerator.zSet(speed);

28
src/main/java/com/iflytop/colortitration/app/core/command/DeviceCommandGenerator.java

@ -786,7 +786,7 @@ public class DeviceCommandGenerator {
// =========================================== 滴定移动电机 ==================================================== // =========================================== 滴定移动电机 ====================================================
/** /**
* titration_motor_01 回原点
* titration_motor_1 回原点
*/ */
public static DeviceCommand titrationMotor1Origin() { public static DeviceCommand titrationMotor1Origin() {
@ -794,7 +794,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 停止
* titration_motor_1 停止
*/ */
public static DeviceCommand titrationMotor1Stop() { public static DeviceCommand titrationMotor1Stop() {
@ -802,7 +802,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 使能
* titration_motor_1 使能
*/ */
public static DeviceCommand titrationMotor1Enable() { public static DeviceCommand titrationMotor1Enable() {
@ -810,7 +810,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 失能
* titration_motor_1 失能
*/ */
public static DeviceCommand titrationMotor1Disable() { public static DeviceCommand titrationMotor1Disable() {
@ -818,7 +818,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 设置速度
* titration_motor_1 设置速度
*/ */
public static DeviceCommand titrationMotor1SetSpeed(double speed) { public static DeviceCommand titrationMotor1SetSpeed(double speed) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();
@ -827,7 +827,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 绝对移动
* titration_motor_1 绝对移动
*/ */
public static DeviceCommand titrationMotor1MoveTo(double position) { public static DeviceCommand titrationMotor1MoveTo(double position) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();
@ -836,7 +836,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_01 相对移动
* titration_motor_1 相对移动
*/ */
public static DeviceCommand titrationMotor1MoveBy(double distance) { public static DeviceCommand titrationMotor1MoveBy(double distance) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();
@ -845,7 +845,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 回原点
* titration_motor_2 回原点
*/ */
public static DeviceCommand titrationMotor2Origin() { public static DeviceCommand titrationMotor2Origin() {
@ -853,7 +853,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 停止
* titration_motor_2 停止
*/ */
public static DeviceCommand titrationMotor2Stop() { public static DeviceCommand titrationMotor2Stop() {
@ -861,7 +861,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 使能
* titration_motor_2 使能
*/ */
public static DeviceCommand titrationMotor2Enable() { public static DeviceCommand titrationMotor2Enable() {
@ -869,7 +869,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 失能
* titration_motor_2 失能
*/ */
public static DeviceCommand titrationMotor2Disable() { public static DeviceCommand titrationMotor2Disable() {
@ -877,7 +877,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 设置速度
* titration_motor_2 设置速度
*/ */
public static DeviceCommand titrationMotor2SetSpeed(double speed) { public static DeviceCommand titrationMotor2SetSpeed(double speed) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();
@ -887,7 +887,7 @@ public class DeviceCommandGenerator {
/** /**
* titration_motor_02 绝对移动
* titration_motor_2 绝对移动
*/ */
public static DeviceCommand titrationMotor2MoveTo(double position) { public static DeviceCommand titrationMotor2MoveTo(double position) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();
@ -896,7 +896,7 @@ public class DeviceCommandGenerator {
} }
/** /**
* titration_motor_02 相对移动
* titration_motor_2 相对移动
*/ */
public static DeviceCommand titrationMotor2MoveBy(double distance) { public static DeviceCommand titrationMotor2MoveBy(double distance) {
DeviceCommandParams params = new DeviceCommandParams(); DeviceCommandParams params = new DeviceCommandParams();

Loading…
Cancel
Save