From 17193498c45c338f072a205dc23f32e3a7fbe851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Mon, 2 Jun 2025 17:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=8E=B0=E5=9C=BA=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gd/app/command/control/HeatStartCommand.java | 11 ++++++++--- .../gd/app/command/control/HeatStopCommand.java | 2 ++ .../gd/app/command/control/SolutionAddCommand.java | 20 ++++++++++++++------ .../gd/app/command/control/TrayDownCommand.java | 11 ----------- .../iflytop/gd/app/controller/TestController.java | 10 +++++++++- .../java/com/iflytop/gd/app/core/CraftsContext.java | 2 +- .../app/model/bo/status/device/HeatModuleState.java | 5 +++++ .../com/iflytop/gd/app/model/entity/Container.java | 4 ++++ .../gd/app/service/api/ContainerService.java | 7 +++++++ .../gd/app/service/crafts/CraftsStepService.java | 15 +++++++++++---- .../gd/app/service/device/DeviceInitService.java | 4 ++-- .../iflytop/gd/app/ws/server/WebSocketSender.java | 6 ++++++ .../gd/common/constant/WebSocketMessageType.java | 5 +++++ .../com/iflytop/gd/common/enums/HeatingType.java | 10 ++++++++++ src/main/resources/sql/init.sql | 21 +++++++++++---------- 15 files changed, 95 insertions(+), 38 deletions(-) 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 25897f7..b87bf71 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,15 +2,18 @@ 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; /** @@ -24,14 +27,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"); + 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(() -> { heatModuleService.heatRodOpen(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, temperature); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(time); 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 e4c8841..2214e82 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 @@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; /** @@ -31,6 +32,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); diff --git a/src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java b/src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java index b01ce7e..b8e94cb 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/SolutionAddCommand.java @@ -5,6 +5,7 @@ import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.model.entity.Container; import com.iflytop.gd.app.service.api.ContainerService; import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.SolutionModuleService; @@ -21,6 +22,7 @@ import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; /** @@ -46,13 +48,13 @@ public class SolutionAddCommand extends BaseCommandHandler { || deviceStateService.getCommandMutexState().get().isShakeStartCommandExecuting()) { throw new AppException(ResultCode.CMD_BUSY); } - if(deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1){ + if (deviceStateService.getDeviceState().getSolutionModule().getTrayStatus() != 1) { throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY); } deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(true); deviceStateService.getDeviceState().getSolutionModule().setPumping(true); return runAsync(() -> { - try{ + try { JSONArray dataList = JSONUtil.parseArray(cmdDTO.getParams().get("dataList")); for (int i = 0; i < dataList.size(); i++) {//遍历前端传入的加液配置 JSONObject tubeSol = dataList.getJSONObject(i); @@ -68,11 +70,17 @@ public class SolutionAddCommand extends BaseCommandHandler { JSONObject addSolution = solutionList.getJSONObject(k); Long solId = addSolution.getLong("solutionId"); Double volume = addSolution.getDouble("volume"); - AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵 - if (acidPumpDevice == null) { + //AcidPumpDeviceCode acidPumpDevice = containerService.getPumpBySolutionId(solId);//获取溶液对应的泵 + Container container = containerService.getContainerBySolutionId(solId); + if (container == null) { throw new AppException(ResultCode.CRAFT_CONTAINER_NOT_FOUND);//未找到对应溶液容器 } - CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume);//添加溶液 + AcidPumpDeviceCode acidPumpDevice = AcidPumpDeviceCode.valueOf(container.getPumpId());//泵 + int scale = container.getScale() == null ? 120 : container.getScale();//系数 +// Integer scale = Optional.ofNullable(container) +// .map(Container::getScale) +// .orElse(500); + CommandFuture deviceCommandFuture = solutionModuleService.acidPumpMoveBy(cmdDTO.getCommandId(), cmdDTO.getCommand(), acidPumpDevice, volume * ((double) scale /100));//添加溶液 futuresList.add(deviceCommandFuture); } CommandUtil.wait(futuresList.toArray(new CommandFuture[0])); @@ -81,7 +89,7 @@ public class SolutionAddCommand extends BaseCommandHandler { solutionModuleService.dualRobotOrigin(); deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false); deviceStateService.getDeviceState().getSolutionModule().setPumping(false); - }finally { + } finally { deviceStateService.getCommandMutexState().get().setSolutionAddCommandExecuting(false); } diff --git a/src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java b/src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java index 55971bb..39f864c 100644 --- a/src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java +++ b/src/main/java/com/iflytop/gd/app/command/control/TrayDownCommand.java @@ -40,22 +40,11 @@ public class TrayDownCommand extends BaseCommandHandler { HeatModuleCode heatModuleCode = HeatModuleCode.valueOf(heatId); //从数据库获取加热位下降托盘位置 double trayLower = devicePositionService.getPosition(DevicePositionCode.trayLower).getDistance(); - double trayLift = devicePositionService.getPosition(DevicePositionCode.trayLift).getDistance(); return runAsync(() -> { try { //下降加热位托盘 heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLower); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(0); -// if (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getHeatingType() == HeatingType.thermostatic) { -// schedulerManager.scheduleOnce(heatModuleCode,() -> { -// try { -// heatModuleService.heaterMotorMove(cmdDTO.getCommandId(), cmdDTO.getCommand(), heatModuleCode, trayLift); -// deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTrayUp(1); -// } catch (Exception e) { -// log.error("加热完毕抬起托盘错误{}", heatModuleCode, e); -// } -// }, deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTargetTime(), TimeUnit.SECONDS); -// } } 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 cb20f7c..a96e957 100644 --- a/src/main/java/com/iflytop/gd/app/controller/TestController.java +++ b/src/main/java/com/iflytop/gd/app/controller/TestController.java @@ -6,6 +6,7 @@ import com.iflytop.gd.app.service.api.TestService; 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.result.Result; import com.iflytop.gd.hardware.exception.HardwareException; @@ -32,7 +33,7 @@ public class TestController { private final TestService testService; private final CapModuleService capModuleService; private final DeviceStateService deviceStateService; - private final SolutionModuleService solutionModuleService; + private final OtherModuleService otherModuleService; private final DeviceEmergencyStopService deviceEmergencyStopService; @Operation(summary = "获取所有传感器读数") @@ -84,4 +85,11 @@ public class TestController { deviceEmergencyStopService.release(); return Result.success(); } + + @Operation(summary = "工艺执行完毕蜂鸣器提醒") + @PostMapping("/crafts-finish-beep-remind") + public Result craftsFinishBeepRemind() throws Exception { + otherModuleService.craftsFinishBeepRemind(); + return Result.success(); + } } diff --git a/src/main/java/com/iflytop/gd/app/core/CraftsContext.java b/src/main/java/com/iflytop/gd/app/core/CraftsContext.java index 536d286..a98743f 100644 --- a/src/main/java/com/iflytop/gd/app/core/CraftsContext.java +++ b/src/main/java/com/iflytop/gd/app/core/CraftsContext.java @@ -94,7 +94,7 @@ public class CraftsContext implements Runnable { } } if (sm.getState().getId() == CraftStates.RUNNING) { - craftsStepService.finish(heatModuleCode); + craftsStepService.finish(heatModuleCode);//工艺执行完毕将托盘移动至加液模块 Message finishMsg = MessageBuilder.withPayload(CraftEvents.FINISH).build(); Mono.from(sm.sendEvent(Mono.just(finishMsg))).block(); } diff --git a/src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java b/src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java index 2d40dfa..b4e37bc 100644 --- a/src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java +++ b/src/main/java/com/iflytop/gd/app/model/bo/status/device/HeatModuleState.java @@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; + @Schema(description = "加热模块") @Data @Component @@ -46,6 +48,9 @@ public class HeatModuleState { @Schema(description = "加热器目标加热时间,单位秒") private Integer targetTime = null; + @Schema(description = "开始加热时间") + private LocalDateTime startHeatTime = null; + @Schema(description = "加热器当前温度") private Double temperature = null; diff --git a/src/main/java/com/iflytop/gd/app/model/entity/Container.java b/src/main/java/com/iflytop/gd/app/model/entity/Container.java index ed5e7b4..32a489a 100644 --- a/src/main/java/com/iflytop/gd/app/model/entity/Container.java +++ b/src/main/java/com/iflytop/gd/app/model/entity/Container.java @@ -34,6 +34,10 @@ public class Container extends BaseEntity { @Schema(description = "泵id") private String pumpId; + + @Schema(description = "加液系数") + private Integer scale=120; + @Positive(message = "总容量 必须是正数") @NotNull @Schema(description = "总容量") diff --git a/src/main/java/com/iflytop/gd/app/service/api/ContainerService.java b/src/main/java/com/iflytop/gd/app/service/api/ContainerService.java index 9d947d9..760047c 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/ContainerService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/ContainerService.java @@ -33,6 +33,13 @@ public class ContainerService extends ServiceImpl { } return null; } + /** + * 根据溶液id获取容器 + */ + public Container getContainerBySolutionId(Long solutionId) { + Container container = this.getOne(new LambdaQueryWrapper().eq(Container::getSolutionId, solutionId)); + return container; + } /** * 根据容器id获取泵id diff --git a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java index 2836a6c..d92a769 100644 --- a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java +++ b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java @@ -9,20 +9,24 @@ import com.iflytop.gd.app.service.api.ContainerService; import com.iflytop.gd.app.service.api.DevicePositionService; import com.iflytop.gd.app.service.device.DeviceCommandTempUtilService; 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.GantryModuleService; -import com.iflytop.gd.app.service.device.module.HeatModuleService; -import com.iflytop.gd.app.service.device.module.SolutionModuleService; +import com.iflytop.gd.app.service.device.module.*; import com.iflytop.gd.app.ws.server.WebSocketSender; import com.iflytop.gd.common.enums.AcidPumpDeviceCode; import com.iflytop.gd.common.enums.HeatModuleCode; import com.iflytop.gd.common.enums.data.DevicePositionCode; import com.iflytop.gd.common.exception.AppException; import com.iflytop.gd.common.result.ResultCode; +import com.iflytop.gd.hardware.drivers.DODriver.OutputIOCtrlDriver; +import com.iflytop.gd.hardware.drivers.TricolorLightDriver; +import com.iflytop.gd.hardware.exception.HardwareException; +import com.iflytop.gd.hardware.type.IO.OutputIOMId; +import com.iflytop.gd.hardware.type.MId; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.concurrent.CompletableFuture; + /** * 工艺步骤执行服务 */ @@ -40,6 +44,7 @@ public class CraftsStepService { private final DevicePositionService devicePositionService; private final DeviceStateService deviceStateService; private final DeviceCommandTempUtilService deviceCommandTempUtilService; + private final OtherModuleService otherModuleService; /** * 执行单个工艺步骤 @@ -160,6 +165,8 @@ public class CraftsStepService { */ public void finish(HeatModuleCode heatModuleCode) throws Exception { moveToSolutionModule(heatModuleCode); + //蜂鸣器提示 + otherModuleService.craftsFinishBeepRemind(); } /** diff --git a/src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java b/src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java index 246b874..c038586 100644 --- a/src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java +++ b/src/main/java/com/iflytop/gd/app/service/device/DeviceInitService.java @@ -65,7 +65,7 @@ public class DeviceInitService { try { tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.BLUE); } catch (HardwareException e) { - log.error("设备初始化灯光失败,Color.BLUE"); + log.error("设备初始化灯光失败,Color.BLUE", e); } }); initDeviceState(); @@ -75,7 +75,7 @@ public class DeviceInitService { try { tricolorLightDriver.open(MId.TriColorLight, TricolorLightDriver.Color.GREEN); } catch (HardwareException e) { - log.error("设备初始化灯光失败,Color.GREEN"); + log.error("设备初始化灯光失败,Color.GREEN", e); } deviceStateService.getDeviceState().setInitComplete(true); log.info("初始化完毕"); diff --git a/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java b/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java index bc9fffc..8746903 100644 --- a/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java +++ b/src/main/java/com/iflytop/gd/app/ws/server/WebSocketSender.java @@ -4,8 +4,10 @@ import cn.hutool.json.JSONUtil; import com.iflytop.gd.app.model.bo.Notification; import com.iflytop.gd.app.model.dto.WebsocketResult; import com.iflytop.gd.common.constant.WebSocketMessageType; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +@Slf4j @Component public class WebSocketSender { @@ -14,6 +16,7 @@ public class WebSocketSender { websocketResult.setType(type); websocketResult.setData(data); WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); + log.info("WS::{}", JSONUtil.toJsonStr(websocketResult)); } public void pushCraftsDebug(Object data) { @@ -32,6 +35,9 @@ public class WebSocketSender { push(WebSocketMessageType.SELF_MOVE_TEST, data); } + public void pushHeatCountdown(Object data) { + push(WebSocketMessageType.HEAT_COUNTDOWN, data); + } public void pushNotification(Notification notification) { push("notification", notification); diff --git a/src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java b/src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java index 67258dc..da28757 100644 --- a/src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java +++ b/src/main/java/com/iflytop/gd/common/constant/WebSocketMessageType.java @@ -43,4 +43,9 @@ public class WebSocketMessageType { */ public static final String CMD_DEBUG = "cmd_debug"; + /** + * 加热倒计时 + */ + public static final String HEAT_COUNTDOWN = "heat_countdown"; + } 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 dd0c4b2..99e6f66 100644 --- a/src/main/java/com/iflytop/gd/common/enums/HeatingType.java +++ b/src/main/java/com/iflytop/gd/common/enums/HeatingType.java @@ -8,6 +8,16 @@ import lombok.Getter; @Getter public enum HeatingType { stop, + /** + * 预热中 + */ warm_up, + /** + * 加热中 + */ thermostatic, + /** + * 恒温中 + */ + constant, } diff --git a/src/main/resources/sql/init.sql b/src/main/resources/sql/init.sql index 1b168a7..c789160 100644 --- a/src/main/resources/sql/init.sql +++ b/src/main/resources/sql/init.sql @@ -50,20 +50,21 @@ CREATE TABLE IF NOT EXISTS container capacity_total INTEGER, capacity_used INTEGER, filled REAL, + scale INTEGER, create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -INSERT OR IGNORE INTO container (id, type, code, solution_id, pump_id, capacity_total, capacity_used) -VALUES (1, 0, 'container_01', 1, 'acid_pump_01', 5000, 0), - (2, 0, 'container_02', 2, 'acid_pump_02', 5000, 2500), - (3, 0, 'container_03', 3, 'acid_pump_03', 5000, 2600), - (4, 0, 'container_04', 4, 'acid_pump_04', 5000, 4000), - (5, 0, 'container_05', 5, 'acid_pump_05', 5000, 2400), - (6, 0, 'container_06', 6, 'acid_pump_06', 5000, 4500), - (7, 0, 'container_07', 7, 'acid_pump_07', 5000, 4900), - (8, 0, 'container_08', 3, 'acid_pump_08', 5000, 100), - (9, 1, 'container_09', NULL, null, 5000, 0); +INSERT OR IGNORE INTO container (id, type, code, solution_id, pump_id, scale,capacity_total, capacity_used) +VALUES (1, 0, 'container_01', 1, 'acid_pump_01', 120,5000, 0), + (2, 0, 'container_02', 2, 'acid_pump_02', 100,5000, 2500), + (3, 0, 'container_03', 3, 'acid_pump_03', 111,5000, 2600), + (4, 0, 'container_04', 4, 'acid_pump_04', 107,5000, 4000), + (5, 0, 'container_05', 5, 'acid_pump_05', 117,5000, 2400), + (6, 0, 'container_06', 6, 'acid_pump_06', 105,5000, 4500), + (7, 0, 'container_07', 7, 'acid_pump_07', 187,5000, 4900), + (8, 0, 'container_08', 3, 'acid_pump_08', 120,5000, 100), + (9, 1, 'container_09', NULL, null, 120,5000, 0); -- solutions 溶液 表