diff --git a/src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java b/src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java index b87bf71..446c97e 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/HeatStartCommand.java @@ -2,18 +2,14 @@ package com.iflytop.gd.app.command.control; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; -import com.iflytop.gd.app.service.api.DevicePositionService; import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.HeatModuleService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.enums.HeatModuleCode; -import com.iflytop.gd.common.enums.HeatingType; -import com.iflytop.gd.common.enums.data.DevicePositionCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; /** @@ -27,22 +23,16 @@ public class HeatStartCommand extends BaseCommandHandler { private final HeatModuleService heatModuleService; private final DeviceStateService deviceStateService; - @Override public CompletableFuture handle(CmdDTO cmdDTO) { String heatId = cmdDTO.getStringParam("heatId"); - Integer time = cmdDTO.getIntegerParam("time"); - Integer minutes = cmdDTO.getIntegerParam("minutes"); - Integer seconds = cmdDTO.getIntegerParam("seconds"); - Double temperature = cmdDTO.getDoubleParam("temperature"); HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); - return runAsync(() -> { + //从系统状态中获取指定加热区设定的温度数值 + double temperature = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature(); + //开启加热 heatModuleService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, temperature); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(time); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatTemperature(temperature); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTemperature(temperature); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.thermostatic); + deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(true); }); } } diff --git a/src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java b/src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java index 2214e82..8c8a69d 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/HeatStopCommand.java @@ -6,12 +6,10 @@ import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.HeatModuleService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.enums.HeatModuleCode; -import com.iflytop.gd.common.enums.HeatingType; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; /** @@ -32,12 +30,7 @@ public class HeatStopCommand extends BaseCommandHandler { return runAsync(() -> { //关闭加热 heatModuleService.heatRodClose(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(null); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(null); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setWarmUpTemperature(null); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatTemperature(null); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTemperature(null); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.stop); + deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeating(false); }); } } diff --git a/src/main/java/com/iflytop/gd/app/command/control/TrayUpCommand.java b/src/main/java/com/iflytop/gd/app/command/control/TrayUpCommand.java index e097e75..5c69bfb 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/TrayUpCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/TrayUpCommand.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.DevicePositionService; @@ -28,29 +27,24 @@ public class TrayUpCommand extends BaseCommandHandler { private final HeatModuleService heatModuleService; private final DevicePositionService devicePositionService; private final DeviceStateService deviceStateService; + @Override public CompletableFuture handle(CmdDTO cmdDTO) { if (deviceStateService.getCommandMutexState().get().isMoveToHeatAreaCommandExecuting() || deviceStateService.getCommandMutexState().get().isMoveToSolutionAreaCommandExecuting()) { throw new AppException(ResultCode.CMD_BUSY); } - JSONArray heatIdJsonArray = cmdDTO.getJSONArrayParam("heatId"); + String heatId = cmdDTO.getStringParam("heatId"); + HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); //获取加热位抬升托盘位置 double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); return runAsync(() -> { - for (int i = 0; i < heatIdJsonArray.size(); i++) { - String heatId = heatIdJsonArray.getStr(i); - HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); - - CompletableFuture.runAsync(() -> { - try { - //抬升加热位托盘 - heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift); - deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1); - } catch (Exception e) { - log.error("抬起托盘失败", e); - } - }); + try { + //抬升加热位托盘 + heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift); + deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1); + } catch (Exception e) { + log.error("抬起托盘失败", e); } }); } 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 26ccb3c..59d28bc 100644 --- a/src/main/java/com/iflytop/gd/app/controller/TestController.java +++ b/src/main/java/com/iflytop/gd/app/controller/TestController.java @@ -1,8 +1,10 @@ package com.iflytop.gd.app.controller; +import com.iflytop.gd.app.model.bo.status.CommandMutexState; import com.iflytop.gd.app.model.dto.AllSensorDTO; import com.iflytop.gd.app.service.api.HeatService; import com.iflytop.gd.app.service.api.TestService; +import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.CapModuleService; import com.iflytop.gd.common.result.Result; import com.iflytop.gd.hardware.exception.HardwareException; @@ -10,6 +12,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -27,9 +30,10 @@ import java.util.List; public class TestController { private final TestService testService; private final CapModuleService capModuleService; + private final DeviceStateService deviceStateService; @Operation(summary = "获取所有传感器读数") - @PostMapping("/all-sensor") + @GetMapping("/all-sensor") public Result> getAllSensor() throws HardwareException { return Result.success(testService.getAllSensor()); } @@ -49,4 +53,11 @@ public class TestController { return Result.success(); } + + @Operation(summary = "获取指令互斥状态") + @GetMapping("/mutex-state") + public Result getCommandMutexState() throws HardwareException { + return Result.success(deviceStateService.getCommandMutexState().get()); + } + }