From e410ec50f988b0c2badcf634bfd6c98f0019f20d Mon Sep 17 00:00:00 2001 From: huangxiang <155373492@qq.com> Date: Tue, 29 Apr 2025 21:26:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=9E=E7=8E=B0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Conflicts: # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartRecycleCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartRefrigerationCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStopHeatingCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStopRecycleCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStopRefrigerationCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftDownCommandHandler.java # src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java --- .../gd/common/notification/Notification.java | 10 ++++++++ .../cmds/ColdTrapStartHeatingCommandHandler.java | 2 ++ .../cmds/CoverElevatorLiftDownCommandHandler.java | 26 +++++++++++++++++--- .../cmds/CoverElevatorLiftUpCommandHandler.java | 6 +++++ .../devices/physical/PhysicalColdTray.java | 12 +++++----- .../devices/physical/PhysicalLiquidFillingArm.java | 6 ++--- .../physical/PhysicalTransportationArm.java | 4 ++-- .../devices/virtual/VirtualColdTray.java | 12 +++++----- .../devices/virtual/VirtualLiquidFillingArm.java | 4 ++-- .../devices/virtual/VirtualTransportationArm.java | 6 ++--- .../iflytop/gd/system/constants/DistanceUnit.java | 13 ++++++++++ .../com/iflytop/gd/system/constants/SpeedUnit.java | 15 ------------ .../iflytop/gd/system/constants/VelocityUnit.java | 28 ++++++++++++++++++++++ .../com/iflytop/gd/system/devices/ColdTray.java | 12 +++++----- .../gd/system/devices/LiquidFillingArm.java | 4 ++-- .../gd/system/devices/TransportationArm.java | 4 ++-- 16 files changed, 112 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/com/iflytop/gd/system/constants/SpeedUnit.java create mode 100644 src/main/java/com/iflytop/gd/system/constants/VelocityUnit.java diff --git a/src/main/java/com/iflytop/gd/common/notification/Notification.java b/src/main/java/com/iflytop/gd/common/notification/Notification.java index 32d7865..82f3b0d 100644 --- a/src/main/java/com/iflytop/gd/common/notification/Notification.java +++ b/src/main/java/com/iflytop/gd/common/notification/Notification.java @@ -50,6 +50,16 @@ public class Notification { return new Notification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "info", title, ""); } + public static Notification infoHandleStartNotification(CmdDTO cmdDTO) { + String title = String.format("开始执行{}指令", cmdDTO.getCommand()); + return new Notification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "info", title, ""); + } + + public static Notification infoHandleEndNotification(CmdDTO cmdDTO) { + String title = String.format("{}指令执行完成", cmdDTO.getCommand()); + return new Notification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "info", title, ""); + } + /** * 创建Warn级别通知 diff --git a/src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java b/src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java index 278808e..7460410 100644 --- a/src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java +++ b/src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java @@ -2,8 +2,10 @@ package com.iflytop.gd.debug.services.cmds; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.WebSocketService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.cmd.CommandHandler; +import com.iflytop.gd.common.notification.Notification; import com.iflytop.gd.system.devices.ColdTray; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftDownCommandHandler.java b/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftDownCommandHandler.java index 64856d7..c19a3cf 100644 --- a/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftDownCommandHandler.java +++ b/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftDownCommandHandler.java @@ -2,17 +2,37 @@ package com.iflytop.gd.debug.services.cmds; import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.WebSocketService; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.cmd.CommandHandler; +import com.iflytop.gd.common.notification.Notification; +import com.iflytop.gd.system.constants.VelocityUnit; +import com.iflytop.gd.system.devices.StepMotor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; /** * 处理拍子电机下降指令 */ +@Slf4j +@Component +@RequiredArgsConstructor @CommandMapping("debug_cover_elevator_lift_down") -public class CoverElevatorLiftDownCommandHandler extends BaseCommandHandler { - +public class CoverElevatorLiftDownCommandHandler implements CommandHandler { + private final WebSocketService webSocketService; + private final StepMotor stepMotor; @Override public void handle(CmdDTO cmdDTO) { - + webSocketService.pushNotification(Notification.infoHandleStartNotification(cmdDTO)); + try { + Integer velocity = cmdDTO.getIntegerParam("velocity"); + String velocityUnitStr = cmdDTO.getStringParam("velocityUnit"); + VelocityUnit velocityUnit = VelocityUnit.toVelocityUnit(velocityUnitStr); + stepMotor.setDefaultVelocity(velocityUnit.toMM_PER_SEC(velocity)); + } catch (Exception e) { + webSocketService.pushNotification(Notification.errorNotification(cmdDTO, e)); + } + webSocketService.pushNotification(Notification.infoHandleEndNotification(cmdDTO)); } } diff --git a/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftUpCommandHandler.java b/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftUpCommandHandler.java index 4f13fdf..41a62cf 100644 --- a/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftUpCommandHandler.java +++ b/src/main/java/com/iflytop/gd/debug/services/cmds/CoverElevatorLiftUpCommandHandler.java @@ -4,11 +4,17 @@ import com.iflytop.gd.app.core.BaseCommandHandler; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.cmd.CommandHandler; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; /** * 处理拍子电机抬升指令 */ +@Slf4j +@Component +@RequiredArgsConstructor @CommandMapping("debug_cover_elevator_lift_up") public class CoverElevatorLiftUpCommandHandler extends BaseCommandHandler { @Override diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java index 6b986f9..f53c01f 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java @@ -12,32 +12,32 @@ public class PhysicalColdTray implements ColdTray { } @Override - public boolean openRecycle() { + public boolean startRecycle() { return false; } @Override - public boolean closeRecycle() { + public boolean stopRecycle() { return false; } @Override - public boolean openHeating() { + public boolean startHeating() { return false; } @Override - public boolean closeHeating() { + public boolean stopHeating() { return false; } @Override - public boolean openRefrigeration() { + public boolean startRefrigeration() { return false; } @Override - public boolean closeRefrigeration() { + public boolean stopRefrigeration() { return false; } } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java index 560c42f..15ef345 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java @@ -4,13 +4,11 @@ package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.system.constants.LiquidFillArmMotorIndex; import com.iflytop.gd.system.constants.RotationDirection; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; import com.iflytop.gd.system.devices.LiquidFillingArm; import com.iflytop.gd.system.devices.StepMotor; import com.iflytop.gd.system.drivers.CommandBus; import com.iflytop.gd.system.models.Point3D; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; /** * 物理液体加注机械臂 @@ -35,7 +33,7 @@ public class PhysicalLiquidFillingArm implements LiquidFillingArm { } @Override - public void setRotationSpeed(Integer speed, SpeedUnit speedUnit) { + public void setRotationSpeed(Integer speed, VelocityUnit speedUnit) { } } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java index bc25e05..51dc2c5 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java @@ -3,7 +3,7 @@ package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.system.constants.Dim; import com.iflytop.gd.system.constants.DistanceUnit; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; import com.iflytop.gd.system.devices.StepMotor; import com.iflytop.gd.system.devices.TransportationArm; import com.iflytop.gd.system.drivers.CommandBus; @@ -41,7 +41,7 @@ public class PhysicalTransportationArm implements TransportationArm { } @Override - public void setSpeed(Dim dim, Integer speed, SpeedUnit unit) { + public void setSpeed(Dim dim, Integer speed, VelocityUnit unit) { } } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java index 0e48680..f80e756 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java @@ -12,32 +12,32 @@ public class VirtualColdTray implements ColdTray { } @Override - public boolean openRecycle() { + public boolean startRecycle() { return false; } @Override - public boolean closeRecycle() { + public boolean stopRecycle() { return false; } @Override - public boolean openHeating() { + public boolean startHeating() { return false; } @Override - public boolean closeHeating() { + public boolean stopHeating() { return false; } @Override - public boolean openRefrigeration() { + public boolean startRefrigeration() { return false; } @Override - public boolean closeRefrigeration() { + public boolean stopRefrigeration() { return false; } } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java index 47b1c3e..4480ab7 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java @@ -2,7 +2,7 @@ package com.iflytop.gd.infrastructure.devices.virtual; import com.iflytop.gd.system.constants.LiquidFillArmMotorIndex; import com.iflytop.gd.system.constants.RotationDirection; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; import com.iflytop.gd.system.devices.LiquidFillingArm; import com.iflytop.gd.system.models.Point3D; @@ -21,6 +21,6 @@ public class VirtualLiquidFillingArm implements LiquidFillingArm { } @Override - public void setRotationSpeed(Integer speed, SpeedUnit speedUnit) { + public void setRotationSpeed(Integer speed, VelocityUnit speedUnit) { } } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java index 8013f63..3e7ac18 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java @@ -5,13 +5,11 @@ import com.iflytop.gd.common.result.ResultCode; import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.system.constants.Dim; import com.iflytop.gd.system.constants.DistanceUnit; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; import com.iflytop.gd.system.devices.StepMotor; import com.iflytop.gd.system.devices.TransportationArm; import com.iflytop.gd.system.exceptions.CommandExecTimeoutException; import com.iflytop.gd.system.exceptions.HardwareErrorException; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; import java.io.IOException; import java.util.HashMap; @@ -75,7 +73,7 @@ public class VirtualTransportationArm implements TransportationArm { } @Override - public void setSpeed(Dim dim, Integer speed, SpeedUnit unit) { + public void setSpeed(Dim dim, Integer speed, VelocityUnit unit) { try { stepMotors.get(dim).setDefaultVelocity(unit.toMM_PER_SEC(speed)); } catch (HardwareErrorException e) { diff --git a/src/main/java/com/iflytop/gd/system/constants/DistanceUnit.java b/src/main/java/com/iflytop/gd/system/constants/DistanceUnit.java index e9528a6..f119210 100644 --- a/src/main/java/com/iflytop/gd/system/constants/DistanceUnit.java +++ b/src/main/java/com/iflytop/gd/system/constants/DistanceUnit.java @@ -14,4 +14,17 @@ public enum DistanceUnit { return value; } + + + public static DistanceUnit toDistanceUnit(String unitString) { + if ("mm".equals(unitString)) { + return MM; + } + + if ("cm".equals(unitString)) { + return CM; + } + + throw new IllegalArgumentException("Unknown distance unit " + unitString); + } } diff --git a/src/main/java/com/iflytop/gd/system/constants/SpeedUnit.java b/src/main/java/com/iflytop/gd/system/constants/SpeedUnit.java deleted file mode 100644 index f87d879..0000000 --- a/src/main/java/com/iflytop/gd/system/constants/SpeedUnit.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.iflytop.gd.system.constants; - -/** - * 移动速度单位 - */ -public enum SpeedUnit { - MM_PER_SEC, CM_PER_SEC; - - public Integer toMM_PER_SEC(Integer value) { - if (this == SpeedUnit.CM_PER_SEC) { - return value * 10; - } - return value; - } -} diff --git a/src/main/java/com/iflytop/gd/system/constants/VelocityUnit.java b/src/main/java/com/iflytop/gd/system/constants/VelocityUnit.java new file mode 100644 index 0000000..f7919a9 --- /dev/null +++ b/src/main/java/com/iflytop/gd/system/constants/VelocityUnit.java @@ -0,0 +1,28 @@ +package com.iflytop.gd.system.constants; + +/** + * 移动速度单位 + */ +public enum VelocityUnit { + MM_PER_SEC, CM_PER_SEC; + + public Integer toMM_PER_SEC(Integer value) { + if (this == VelocityUnit.CM_PER_SEC) { + return value * 10; + } + return value; + } + + + public static VelocityUnit toVelocityUnit(String unitString) { + if ("mm/s".equals(unitString)) { + return VelocityUnit.MM_PER_SEC; + } + + if ("cm/s".equals(unitString)) { + return VelocityUnit.CM_PER_SEC; + } + + throw new IllegalArgumentException("Unrecognized SpeedUnit: " + unitString); + } +} diff --git a/src/main/java/com/iflytop/gd/system/devices/ColdTray.java b/src/main/java/com/iflytop/gd/system/devices/ColdTray.java index 80db602..f3f6540 100644 --- a/src/main/java/com/iflytop/gd/system/devices/ColdTray.java +++ b/src/main/java/com/iflytop/gd/system/devices/ColdTray.java @@ -16,39 +16,39 @@ public interface ColdTray { * 开启循环 * @return */ - boolean openRecycle(); + boolean startRecycle(); /** * 关闭循环 * @return */ - boolean closeRecycle(); + boolean stopRecycle(); /** * 开启加热 * @return */ - boolean openHeating(); + boolean startHeating(); /** * 关闭加热 * @return */ - boolean closeHeating(); + boolean stopHeating(); /** * 开启制冷 * @return */ - boolean openRefrigeration(); + boolean startRefrigeration(); /** * 关闭制冷 * @return */ - boolean closeRefrigeration(); + boolean stopRefrigeration(); } diff --git a/src/main/java/com/iflytop/gd/system/devices/LiquidFillingArm.java b/src/main/java/com/iflytop/gd/system/devices/LiquidFillingArm.java index 9cae460..60dd622 100644 --- a/src/main/java/com/iflytop/gd/system/devices/LiquidFillingArm.java +++ b/src/main/java/com/iflytop/gd/system/devices/LiquidFillingArm.java @@ -2,7 +2,7 @@ package com.iflytop.gd.system.devices; import com.iflytop.gd.system.constants.LiquidFillArmMotorIndex; import com.iflytop.gd.system.constants.RotationDirection; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; import com.iflytop.gd.system.models.Point3D; @@ -34,5 +34,5 @@ public interface LiquidFillingArm { * @param speedUnit 速率单位 * @return 是否设置成功 */ - void setRotationSpeed(Integer speed, SpeedUnit speedUnit); + void setRotationSpeed(Integer speed, VelocityUnit speedUnit); } diff --git a/src/main/java/com/iflytop/gd/system/devices/TransportationArm.java b/src/main/java/com/iflytop/gd/system/devices/TransportationArm.java index 2e4c613..45c0c45 100644 --- a/src/main/java/com/iflytop/gd/system/devices/TransportationArm.java +++ b/src/main/java/com/iflytop/gd/system/devices/TransportationArm.java @@ -2,7 +2,7 @@ package com.iflytop.gd.system.devices; import com.iflytop.gd.system.constants.Dim; import com.iflytop.gd.system.constants.DistanceUnit; -import com.iflytop.gd.system.constants.SpeedUnit; +import com.iflytop.gd.system.constants.VelocityUnit; public interface TransportationArm { @@ -36,5 +36,5 @@ public interface TransportationArm { * @param unit 速率单位 * @return 是否设置完成 */ - void setSpeed(Dim dim, Integer speed, SpeedUnit unit); + void setSpeed(Dim dim, Integer speed, VelocityUnit unit); }