diff --git a/src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java b/src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java index 9b32888..d302ce7 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/FilledSolutionStopCommand.java @@ -1,6 +1,5 @@ package com.iflytop.gd.app.command.control; -import cn.hutool.json.JSONArray; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.app.service.api.ContainerService; @@ -27,17 +26,24 @@ public class FilledSolutionStopCommand extends BaseCommandHandler { @Override public CompletableFuture handle(CmdDTO cmdDTO) { return runAsync(() -> { - JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list"); - for (int i = 0; i < idJsonArray.size(); i++) { - String idStr = idJsonArray.getStr(i); - CompletableFuture.runAsync(() -> { - try { - AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr)); - solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice); - } catch (Exception e) { - log.error("停止预充失败", e); - } - }); +// JSONArray idJsonArray = cmdDTO.getJSONArrayParam("list"); +// for (int i = 0; i < idJsonArray.size(); i++) { +// String idStr = idJsonArray.getStr(i); +// CompletableFuture.runAsync(() -> { +// try { +// AcidPumpDeviceCode acidPumpDevice = containerService.getPumpByContainerId(Long.parseLong(idStr)); +// solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice); +// } catch (Exception e) { +// log.error("停止预充失败", e); +// } +// }); +// } + for (AcidPumpDeviceCode acidPumpDeviceCode : AcidPumpDeviceCode.values()) { + try { + solutionModuleService.acidPumpStop(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDeviceCode); + } catch (Exception e) { + log.error("停止预充错误", e); + } } Thread.sleep(1000); solutionModuleService.dualRobotOrigin(); diff --git a/src/main/java/com/iflytop/gd/app/controller/SystemController.java b/src/main/java/com/iflytop/gd/app/controller/SystemController.java index 6c15f08..263eaf0 100644 --- a/src/main/java/com/iflytop/gd/app/controller/SystemController.java +++ b/src/main/java/com/iflytop/gd/app/controller/SystemController.java @@ -12,9 +12,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import java.time.Instant; -import java.time.LocalDateTime; - @Tag(name = "系统") @RestController @RequestMapping("/api/sys") @@ -24,6 +21,19 @@ public class SystemController { private final SystemConfigService systemConfigService; private final DeviceStateService deviceStateService; + @Operation(summary = "是否启动虚拟模式") + @PostMapping("/virtual") + public Result changeVirtualMode(Boolean mode) { + deviceStateService.getDeviceState().setVirtual(mode); + return Result.success(); + } + + @Operation(summary = "模拟向硬件写入完毕") + @PostMapping("/initComplete") + public Result setInitComplete(Boolean initComplete) { + deviceStateService.getDeviceState().setInitComplete(initComplete); + return Result.success(); + } @Operation(summary = "系统状态") @GetMapping("/device-status") @@ -38,10 +48,10 @@ public class SystemController { return Result.success(); } - @Operation(summary = "获取系统时间") + @Operation(summary = "获取系统时间 yyyy-MM-dd HH:mm:ss") @GetMapping("/datetime") public Result getDatetime() { - return Result.success(Instant.now().toEpochMilli()); + return Result.success(deviceStateService.getDeviceState()); } } diff --git a/src/main/java/com/iflytop/gd/app/controller/TestController.java b/src/main/java/com/iflytop/gd/app/controller/TestController.java index a96e957..cfce7fb 100644 --- a/src/main/java/com/iflytop/gd/app/controller/TestController.java +++ b/src/main/java/com/iflytop/gd/app/controller/TestController.java @@ -7,7 +7,7 @@ import com.iflytop.gd.app.service.device.DeviceEmergencyStopService; import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.CapModuleService; import com.iflytop.gd.app.service.device.module.OtherModuleService; -import com.iflytop.gd.app.service.device.module.SolutionModuleService; +import com.iflytop.gd.common.enums.HeatModuleCode; import com.iflytop.gd.common.result.Result; import com.iflytop.gd.hardware.exception.HardwareException; import io.swagger.v3.oas.annotations.Operation; @@ -92,4 +92,11 @@ public class TestController { otherModuleService.craftsFinishBeepRemind(); return Result.success(); } + + @Operation(summary = "设置当前温度") + @PostMapping("/set-temperature") + public Result setTemperature(HeatModuleCode code, Double temperature) throws Exception { + testService.setTemperature(code, temperature); + return Result.success(); + } } diff --git a/src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java b/src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java index 5ffd29c..318278b 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/SystemConfigService.java @@ -83,4 +83,10 @@ public class SystemConfigService extends ServiceImpl heatModuleState.getHeatTemperature()) {//当前温度达到目标温度,允许有1度以内的误差 + heatModuleState.setStartHeatTime(now); heatModuleState.setHeatingType(HeatingType.constant);//修改状态为恒温中 - if (heatModuleState.getStartHeatTime() == null) { - //设定开始加热时间 - heatModuleState.setStartHeatTime(now); - } else { - LocalDateTime endTime = heatModuleState.getStartHeatTime().minusSeconds(heatModuleState.getTargetTime()); - //判断是否达到目标加热时间 - if (endTime.isBefore(now)) {//加热完毕 - double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); - //抬起托盘 - heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift); - heatModuleState.setTrayUp(1); - //关闭加棒 - heatModuleService.heatRodClose(heatModuleState.getModuleCode()); - heatModuleState.setHeatingType(HeatingType.stop); - //还原状态 - heatModuleState.setStartHeatTime(null); - heatModuleState.setTargetTime(null); - heatModuleState.setWarmUpTemperature(null); - heatModuleState.setHeatTemperature(null); - heatModuleState.setTargetTemperature(null); - heatModuleState.setHeatingType(HeatingType.stop); - } else {//加热中 - long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间 - HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); - heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); - heatCountdownVO.setCountdown((int) diffSeconds); - heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds)); - heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); - heatCountdownVO.setEndTime(endTime); - heatCountdownVOList.add(heatCountdownVO); - } - } + } + } else if (heatModuleState.getHeatingType() == HeatingType.constant) { + LocalDateTime endTime = heatModuleState.getStartHeatTime().plusSeconds(heatModuleState.getTargetTime()); + //判断是否达到目标加热时间 + long diffSeconds = Duration.between(now, endTime).getSeconds();//计算剩余时间 + if (diffSeconds <= 0) {//加热完毕 + double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); + //抬起托盘 + heatModuleService.heaterMotorMove(heatModuleState.getModuleCode(), trayLift); + heatModuleState.setTrayUp(1); + //关闭加棒 + heatModuleService.heatRodClose(heatModuleState.getModuleCode()); + //还原状态 +// heatModuleState.setStartHeatTime(null); +// heatModuleState.setTargetTime(null); +// heatModuleState.setWarmUpTemperature(null); +// heatModuleState.setHeatTemperature(null); +// heatModuleState.setTargetTemperature(null); + heatModuleState.setHeatingType(HeatingType.finish); + +// HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); +// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); +// heatCountdownVO.setCountdown((int) diffSeconds); +// heatCountdownVO.setCountdownStr("加热完毕"); +// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); +// heatCountdownVO.setEndTime(endTime); +// heatCountdownVOList.add(heatCountdownVO); + } else {//加热中 推送倒计时 +// HeatCountdownVO heatCountdownVO = new HeatCountdownVO(); +// heatCountdownVO.setHeatModuleCode(heatModuleState.getModuleCode()); +// heatCountdownVO.setCountdown((int) diffSeconds); +// heatCountdownVO.setCountdownStr(LocalDateTimeUtil.formatSecondsToHMS(diffSeconds)); +// heatCountdownVO.setStartTime(heatModuleState.getStartHeatTime()); +// heatCountdownVO.setEndTime(endTime); +// heatCountdownVOList.add(heatCountdownVO); } } } diff --git a/src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java b/src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java index 7123e2c..9eba5f6 100644 --- a/src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java +++ b/src/main/java/com/iflytop/gd/app/ws/client/DeviceEmergencyStopConfig.java @@ -1,10 +1,6 @@ package com.iflytop.gd.app.ws.client; -import com.iflytop.gd.app.core.CommandPoolManager; -import com.iflytop.gd.app.service.api.CraftsService; import com.iflytop.gd.app.service.device.DeviceEmergencyStopService; -import com.iflytop.gd.app.service.device.DeviceStateService; -import com.iflytop.gd.app.service.device.DeviceStepCommandService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/iflytop/gd/common/enums/HeatingType.java b/src/main/java/com/iflytop/gd/common/enums/HeatingType.java index 99e6f66..e4b88bc 100644 --- a/src/main/java/com/iflytop/gd/common/enums/HeatingType.java +++ b/src/main/java/com/iflytop/gd/common/enums/HeatingType.java @@ -20,4 +20,8 @@ public enum HeatingType { * 恒温中 */ constant, + /** + * 加热完成 + */ + finish, } diff --git a/src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java b/src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java index 5c8a751..c9e1c9a 100644 --- a/src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java +++ b/src/main/java/com/iflytop/gd/common/utils/LocalDateTimeUtil.java @@ -3,16 +3,13 @@ package com.iflytop.gd.common.utils; public class LocalDateTimeUtil { /** - * 秒数格式化为 “HH:mm:ss” 格式。 - * @param diffSeconds 两个时间点相差的秒数(可以为正或负) - * @return 格式化后的 “HH:mm:ss” 字符串 + * 秒数格式化为 “mm:ss” 格式。 */ public static String formatSecondsToHMS(long diffSeconds) { long absSeconds = Math.abs(diffSeconds); - long hours = absSeconds / 3600; - long minutes = (absSeconds % 3600) / 60; + long minutes = absSeconds / 60; long seconds = absSeconds % 60; - return String.format("%02d:%02d:%02d", hours, minutes, seconds); + return String.format("%02d:%02d", minutes, seconds); } } \ No newline at end of file