Browse Source

fix: 硬件状态bug

master
guoapeng 5 months ago
parent
commit
31dc16e2c2
  1. 47
      src/main/java/com/qyft/ms/app/controller/CMDController.java
  2. 28
      src/main/java/com/qyft/ms/app/service/CMDService.java
  3. 2
      src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java
  4. 3
      src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java

47
src/main/java/com/qyft/ms/app/controller/CMDController.java

@ -49,6 +49,30 @@ public class CMDController {
} }
} }
@Operation(summary = "电机移动到原点")
@PostMapping("/motorMoveToHome")
public Result<String> motorMoveToHome(@RequestBody CMDForm cmdForm) {
try {
if (cmdForm.getCommandId() == null || cmdForm.getCommandId().isEmpty()) {
String commandId = UUID.randomUUID().toString();
cmdForm.setCommandId(commandId);
}
if (cmdForm.getCommandName() == null || cmdForm.getCommandName().isEmpty()) {
cmdForm.setCommandName("motorMoveToHome");
}
log.info("接收到指令: {}", JSONUtil.toJsonStr(cmdForm));
if (cmdService.motorMoveToHome(cmdForm)) {
return Result.success(cmdForm.getCommandId());
} else {
return Result.failed("参数错误");
}
} catch (Exception e) {
log.error("指令执行异常: {}", JSONUtil.toJsonStr(cmdForm), e);
return Result.failed("执行失败");
}
}
@Operation(summary = "三通阀切换") @Operation(summary = "三通阀切换")
@PostMapping("/switchThreeWayValve") @PostMapping("/switchThreeWayValve")
public Result<String> switchThreeWayValve(@RequestBody CMDForm cmdForm) { public Result<String> switchThreeWayValve(@RequestBody CMDForm cmdForm) {
@ -280,6 +304,29 @@ public class CMDController {
} }
} }
@Operation(summary = "设定指定轴的速度")
@PostMapping("/setMotorSpeed")
public Result<String> setMotorSpeed(@RequestBody CMDForm cmdForm) {
try {
if (cmdForm.getCommandId() == null || cmdForm.getCommandId().isEmpty()) {
String commandId = UUID.randomUUID().toString();
cmdForm.setCommandId(commandId);
}
if (cmdForm.getCommandName() == null || cmdForm.getCommandName().isEmpty()) {
cmdForm.setCommandName("setMotorSpeed");
}
log.info("接收到指令: {}", JSONUtil.toJsonStr(cmdForm));
if (cmdService.setMotorSpeed(cmdForm)) {
return Result.success(cmdForm.getCommandId());
} else {
return Result.failed("参数错误");
}
} catch (Exception e) {
log.error("指令执行异常: {}", JSONUtil.toJsonStr(cmdForm), e);
return Result.failed("执行失败");
}
}
@Operation(summary = "测试: 停止指定轴运动") @Operation(summary = "测试: 停止指定轴运动")
@PostMapping("/stopMotor") @PostMapping("/stopMotor")
public Result<String> stopMotor(@RequestBody CMDForm cmdForm) { public Result<String> stopMotor(@RequestBody CMDForm cmdForm) {

28
src/main/java/com/qyft/ms/app/service/CMDService.java

@ -235,7 +235,7 @@ public class CMDService {
// 移动到指定高度(位置) // 移动到指定高度(位置)
int height = (Integer) params.get("height"); int height = (Integer) params.get("height");
if(z - height < 6.2) {
if(z - height < 6.5) {
return "高度设置太低,有撞针的风险"; return "高度设置太低,有撞针的风险";
} }
cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z",z - height )); cmdList.add(() -> deviceTcpCMDService.moveMotorToPosition("Z",z - height ));
@ -430,6 +430,16 @@ public class CMDService {
return true; return true;
} }
// 电机回到原点
public boolean motorMoveToHome(CMDForm form) {
List<Supplier<Boolean>> cmdList = new ArrayList<>();
Map<String, Object> params = form.getParams();
String axis = (String) params.get("axis");
cmdList.add(() -> deviceTcpCMDService.motorMoveToHome(axis));
initExecutorThread(cmdList, form);
return true;
}
// 开始除湿 // 开始除湿
public boolean startDehumidify(CMDForm form) { public boolean startDehumidify(CMDForm form) {
List<Supplier<Boolean>> cmdList = new ArrayList<>(); List<Supplier<Boolean>> cmdList = new ArrayList<>();
@ -452,6 +462,21 @@ public class CMDService {
return true; return true;
} }
// 设置电机速度
public boolean setMotorSpeed(CMDForm form) {
List<Supplier<Boolean>> cmdList = new ArrayList<>();
Map<String, Object> params = form.getParams();
String axis = (String) params.get("axis");
double speed = Optional.ofNullable(params.get("speed"))
.filter(Number.class::isInstance)
.map(Number.class::cast)
.map(Number::doubleValue)
.orElse(0.0);
cmdList.add(() -> deviceTcpCMDService.setMotorSpeed(axis, speed));
initExecutorThread(cmdList, form);
return true;
}
public void run(List<Supplier<Boolean>> cmdList, CMDForm form) { public void run(List<Supplier<Boolean>> cmdList, CMDForm form) {
ExecutionResult executionResult = new ExecutionResult(); ExecutionResult executionResult = new ExecutionResult();
@ -476,4 +501,5 @@ public class CMDService {
} }
} }

2
src/main/java/com/qyft/ms/device/common/constant/DeviceCommands.java

@ -34,7 +34,7 @@ public class DeviceCommands {
public static final String SET_SYRINGE_PUMP_PARAMETERS = "setSyringePumpParameters"; public static final String SET_SYRINGE_PUMP_PARAMETERS = "setSyringePumpParameters";
// 推送指定容量的液体 // 推送指定容量的液体
public static final String PUSH_VOLUME = "pushVolume"; public static final String PUSH_VOLUME = "pushVolume";
public static final String ROTATE = "rotate";
public static final String ROTATE_MOTOR = "rotateMotor";
public static final String SYRINGE_PUMP_MOVE_AT_SPEED = "syringePumpMoveAtSpeed"; public static final String SYRINGE_PUMP_MOVE_AT_SPEED = "syringePumpMoveAtSpeed";
public static final String SYRINGE_PUMP_STOP = "syringePumpStop"; public static final String SYRINGE_PUMP_STOP = "syringePumpStop";
public static final String SYRINGE_PUMP_START = "syringePumpStart"; public static final String SYRINGE_PUMP_START = "syringePumpStart";

3
src/main/java/com/qyft/ms/device/service/DeviceTcpCMDService.java

@ -266,7 +266,7 @@ public class DeviceTcpCMDService {
params.put("axis", axis); params.put("axis", axis);
params.put("rotationSpeed", rotationSpeed); params.put("rotationSpeed", rotationSpeed);
params.put("time", time); params.put("time", time);
return this.putTask(DeviceCommands.ROTATE, params);
return this.putTask(DeviceCommands.ROTATE_MOTOR, params);
} }
// 停止指定轴的电机运动 // 停止指定轴的电机运动
@ -309,4 +309,5 @@ public class DeviceTcpCMDService {
params.put("humidity", humidity); params.put("humidity", humidity);
return this.putTask(DeviceCommands.START_DEHUMIDIFY, params); return this.putTask(DeviceCommands.START_DEHUMIDIFY, params);
} }
} }
Loading…
Cancel
Save