diff --git a/src/main/java/com/iflytop/gd/app/service/WebSocketService.java b/src/main/java/com/iflytop/gd/app/service/WebSocketService.java index 5a13e4c..9516794 100644 --- a/src/main/java/com/iflytop/gd/app/service/WebSocketService.java +++ b/src/main/java/com/iflytop/gd/app/service/WebSocketService.java @@ -1,6 +1,7 @@ package com.iflytop.gd.app.service; import cn.hutool.json.JSONUtil; +import com.iflytop.gd.common.notification.Notification; import com.iflytop.gd.infrastructure.config.WebSocketServer; import com.iflytop.gd.app.model.dto.WebsocketResult; import org.springframework.stereotype.Service; @@ -15,4 +16,9 @@ public class WebSocketService { WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); } + + public void pushNotification(Notification notification) { + push("notification", notification); + } + } 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 724b0ee..32d7865 100644 --- a/src/main/java/com/iflytop/gd/common/notification/Notification.java +++ b/src/main/java/com/iflytop/gd/common/notification/Notification.java @@ -1,6 +1,7 @@ package com.iflytop.gd.common.notification; import cn.hutool.core.date.DateTime; +import com.iflytop.gd.app.model.dto.CmdDTO; import lombok.Getter; @@ -41,6 +42,14 @@ public class Notification { return new Notification(commandId, command, "info", title, content); } + public static Notification infoNotification(String commandId, String command, String title) { + return new Notification(commandId, command, "info", title, ""); + } + + public static Notification infoNotification(CmdDTO cmdDTO, String title) { + return new Notification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "info", title, ""); + } + /** * 创建Warn级别通知 @@ -60,6 +69,11 @@ public class Notification { return new Notification(commandId, command, "error", title, content); } + public static Notification errorNotification(CmdDTO cmdDTO, Exception e) { + String title = String.format("执行{}出错", cmdDTO.getCommand()); + return new Notification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "error", title, e.getMessage()); + } + /** * 创建Fatal级别通知 diff --git a/src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java b/src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java index 708d71b..7dc7b95 100644 --- a/src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java +++ b/src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java @@ -1,6 +1,7 @@ package com.iflytop.gd.debug.controller; import com.iflytop.gd.app.model.dto.CmdDTO; +import com.iflytop.gd.app.service.WebSocketService; import com.iflytop.gd.app.service.exceptions.UnSupportCommandException; import com.iflytop.gd.common.result.Result; import com.iflytop.gd.common.cmd.CommandHandler; @@ -15,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.concurrent.CompletableFuture; + @Tag(name = "前端调试指令") @RestController @RequestMapping("/api/debug/cmd") @@ -28,10 +31,11 @@ public class CmdDebugController { public Result controlMethod(@Valid @RequestBody CmdDTO cmdDTO) { String commandName = cmdDTO.getCommand(); try { + log.info("收到调试指令{}", commandName); CommandHandler commandHandler = registry.getCommandHandler(commandName); - log.info("调试指令{}开始执行", commandName); - commandHandler.handle(cmdDTO); - log.info("调试指令{}执行结束", commandName); + log.info("找到指令处理器{}", commandHandler.getClass().getName()); + CompletableFuture.runAsync(() -> commandHandler.handle(cmdDTO)); + log.info("指令处理器提交异步执行"); } catch (UnSupportCommandException exception) { log.error("未找到对应的调试指令{}", commandName); String errorMsg = "未找到对应的调试指令, commandName=" + commandName; 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 aaa350d..b547e2c 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 @@ -3,6 +3,7 @@ package com.iflytop.gd.debug.services.cmds; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.cmd.CommandHandler; +import com.iflytop.gd.system.devices.ColdTray; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -15,6 +16,8 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor @CommandMapping("debug_cold_trap_start_heating") public class ColdTrapStartHeatingCommandHandler implements CommandHandler { + private final ColdTray coldTray; + @Override public void handle(CmdDTO cmdDTO) { diff --git a/src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java b/src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java index 01d571a..e94aebf 100644 --- a/src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java +++ b/src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java @@ -3,7 +3,6 @@ package com.iflytop.gd.debug.services.cmds; import com.iflytop.gd.app.model.dto.CmdDTO; import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.cmd.CommandHandler; -import com.iflytop.gd.infrastructure.devices.MotorDrivenDoor; import com.iflytop.gd.system.devices.Door; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java b/src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java index 6b47902..f309740 100644 --- a/src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java +++ b/src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java @@ -1,9 +1,10 @@ package com.iflytop.gd.debug.services.cmds; 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.infrastructure.devices.MotorDrivenDoor; +import com.iflytop.gd.common.notification.Notification; import com.iflytop.gd.system.devices.Door; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,8 +20,16 @@ import org.springframework.stereotype.Component; public class DoorOpenCommandHandler implements CommandHandler { private final Door door; + private final WebSocketService webSocketService; + @Override public void handle(CmdDTO cmdDTO) { - door.open(); + webSocketService.pushNotification(Notification.infoNotification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "开始执行开门指令")); + try { + door.open(); + } catch (Exception e) { + webSocketService.pushNotification(Notification.errorNotification(cmdDTO, e)); + } + webSocketService.pushNotification( Notification.infoNotification(cmdDTO.getCommandId(), cmdDTO.getCommand(), "开门指令执行完成")); } } 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 new file mode 100644 index 0000000..6b986f9 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java @@ -0,0 +1,43 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.ColdTray; + +/** + * 物理冷阱 + */ +public class PhysicalColdTray implements ColdTray { + @Override + public boolean setTemperature(Double temperature) { + return false; + } + + @Override + public boolean openRecycle() { + return false; + } + + @Override + public boolean closeRecycle() { + return false; + } + + @Override + public boolean openHeating() { + return false; + } + + @Override + public boolean closeHeating() { + return false; + } + + @Override + public boolean openRefrigeration() { + return false; + } + + @Override + public boolean closeRefrigeration() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenDoor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalDoor.java similarity index 90% rename from src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenDoor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalDoor.java index 257f13d..a63d026 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenDoor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalDoor.java @@ -1,7 +1,8 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.common.exception.AppException; import com.iflytop.gd.common.result.ResultCode; +import com.iflytop.gd.infrastructure.devices.virtual.VirtualStepMotor; import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.system.constants.DistanceUnit; import com.iflytop.gd.system.devices.Door; @@ -15,15 +16,14 @@ import org.springframework.stereotype.Component; import java.io.IOException; /** - * 步进电机驱动的门实现 + * 物理门 */ -@Profile("test") -@Component -public class MotorDrivenDoor implements Door { + +public class PhysicalDoor implements Door { private final StepMotor doorMotor; - public MotorDrivenDoor(CommandBus commandBus) { + public PhysicalDoor(CommandBus commandBus) { this.doorMotor = new VirtualStepMotor(ModuleId.DoorM); } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalFan.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalFan.java new file mode 100644 index 0000000..611727b --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalFan.java @@ -0,0 +1,18 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.Fan; + +/** + * 物理风扇 + */ +public class PhysicalFan implements Fan { + @Override + public boolean open() { + return false; + } + + @Override + public boolean close() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalHoldingJaw.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalHoldingJaw.java new file mode 100644 index 0000000..34a3a46 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalHoldingJaw.java @@ -0,0 +1,33 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.HoldingJaw; + +/** + * 物理夹爪 + */ +public class PhysicalHoldingJaw implements HoldingJaw { + @Override + public void open() { + + } + + @Override + public void close() { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void setSpeed(int speed) { + + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenLiquidFillingArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java similarity index 73% rename from src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenLiquidFillingArm.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java index dbb961c..560c42f 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenLiquidFillingArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.ModuleId; @@ -13,17 +13,15 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; /** - * 液体加注机械臂 + * 物理液体加注机械臂 */ -@Profile("test") -@Component -public class MotorDrivenLiquidFillingArm implements LiquidFillingArm { +public class PhysicalLiquidFillingArm implements LiquidFillingArm { private final StepMotor largeArmMotor; private final StepMotor smallArmMotor; - public MotorDrivenLiquidFillingArm(CommandBus commandBus) { - this.largeArmMotor = new StandardStepMotor(ModuleId.DualRobotAxis1M, commandBus); - this.smallArmMotor = new StandardStepMotor(ModuleId.DualRobotAxis2M, commandBus); + public PhysicalLiquidFillingArm(CommandBus commandBus) { + this.largeArmMotor = new PhysicalStepMotor(ModuleId.DualRobotAxis1M, commandBus); + this.smallArmMotor = new PhysicalStepMotor(ModuleId.DualRobotAxis2M, commandBus); } @Override diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalPump.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalPump.java new file mode 100644 index 0000000..7b065e5 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalPump.java @@ -0,0 +1,9 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.Pump; + +/** + * 物理泵 + */ +public class PhysicalPump implements Pump { +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalRelay.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalRelay.java new file mode 100644 index 0000000..658a310 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalRelay.java @@ -0,0 +1,18 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.Relay; + +/** + * 物理继电器 + */ +public class PhysicalRelay implements Relay { + @Override + public boolean open() { + return false; + } + + @Override + public boolean close() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/StandardServoMotor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalServoMotor.java similarity index 86% rename from src/main/java/com/iflytop/gd/infrastructure/devices/StandardServoMotor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalServoMotor.java index a8c723e..e3d564f 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/StandardServoMotor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalServoMotor.java @@ -1,13 +1,13 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.RegIndex; import com.iflytop.gd.system.devices.ServoMotor; /** - * 标准物理伺服电机 + * 物理伺服电机 */ -public class StandardServoMotor implements ServoMotor { +public class PhysicalServoMotor implements ServoMotor { @Override public void enable() { diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/StandardStepMotor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalStepMotor.java similarity index 96% rename from src/main/java/com/iflytop/gd/infrastructure/devices/StandardStepMotor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalStepMotor.java index 02f682e..b457c35 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/StandardStepMotor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalStepMotor.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.CmdId; import com.iflytop.gd.infrastructure.drivers.ModuleId; @@ -16,14 +16,14 @@ import java.util.Map; import java.util.concurrent.TimeUnit; /** - * 标准电机实现 + * 物理步进电机实现 */ -public class StandardStepMotor implements StepMotor { +public class PhysicalStepMotor implements StepMotor { protected final ModuleId moduleId; protected final CommandBus commandBus; protected final Integer DEFAULT_COMMAND_EXEC_TIMEOUT_SECONDS = 10; - protected StandardStepMotor(ModuleId moduleId, CommandBus commandBus) { + public PhysicalStepMotor(ModuleId moduleId, CommandBus commandBus) { this.moduleId = moduleId; this.commandBus = commandBus; } diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalSwitchSensor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalSwitchSensor.java new file mode 100644 index 0000000..5e67827 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalSwitchSensor.java @@ -0,0 +1,14 @@ +package com.iflytop.gd.infrastructure.devices.physical; + +import com.iflytop.gd.system.devices.SwitchSensor; + +/** + * 物理传感器 + */ + +public class PhysicalSwitchSensor implements SwitchSensor { + @Override + public boolean isOpen() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenTransportationArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java similarity index 59% rename from src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenTransportationArm.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java index f86e6c9..bc25e05 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenTransportationArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.physical; import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.system.constants.Dim; @@ -7,25 +7,21 @@ import com.iflytop.gd.system.constants.SpeedUnit; import com.iflytop.gd.system.devices.StepMotor; import com.iflytop.gd.system.devices.TransportationArm; 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; /** - * 电机驱动转移机械臂 + * 物理转移机械臂 */ -@Profile("test") -@Component -public class MotorDrivenTransportationArm implements TransportationArm { + +public class PhysicalTransportationArm implements TransportationArm { private final StepMotor xDimMotor; private final StepMotor yDimMotor; private final StepMotor zDimMotor; - public MotorDrivenTransportationArm(CommandBus commandBus) { - this.xDimMotor = new StandardStepMotor(ModuleId.HBotXM, commandBus); - this.yDimMotor = new StandardStepMotor(ModuleId.HBotYM, commandBus); - this.zDimMotor = new StandardStepMotor(ModuleId.HBotZM, commandBus); + public PhysicalTransportationArm(CommandBus commandBus) { + this.xDimMotor = new PhysicalStepMotor(ModuleId.HBotXM, commandBus); + this.yDimMotor = new PhysicalStepMotor(ModuleId.HBotYM, commandBus); + this.zDimMotor = new PhysicalStepMotor(ModuleId.HBotZM, commandBus); } @Override 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 new file mode 100644 index 0000000..0e48680 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java @@ -0,0 +1,43 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.ColdTray; + +/** + * 虚拟冷阱 + */ +public class VirtualColdTray implements ColdTray { + @Override + public boolean setTemperature(Double temperature) { + return false; + } + + @Override + public boolean openRecycle() { + return false; + } + + @Override + public boolean closeRecycle() { + return false; + } + + @Override + public boolean openHeating() { + return false; + } + + @Override + public boolean closeHeating() { + return false; + } + + @Override + public boolean openRefrigeration() { + return false; + } + + @Override + public boolean closeRefrigeration() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualDoor.java similarity index 64% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualDoor.java index a8de039..d80acfd 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualDoor.java @@ -1,11 +1,11 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.virtual; import com.iflytop.gd.system.devices.Door; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; -@Component -@Profile("dev") +/** + * 虚拟门 + */ + public class VirtualDoor implements Door { private boolean isOpen = false; @Override diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualFan.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualFan.java new file mode 100644 index 0000000..fd8036e --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualFan.java @@ -0,0 +1,18 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.Fan; + +/** + * 虚拟风扇 + */ +public class VirtualFan implements Fan { + @Override + public boolean open() { + return false; + } + + @Override + public boolean close() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualHeater.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHeater.java similarity index 92% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualHeater.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHeater.java index d40030f..e0c8ff8 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualHeater.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHeater.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.virtual; import com.iflytop.gd.system.devices.Heater; import com.iflytop.gd.system.models.HeaterStatus; diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHoldingJaw.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHoldingJaw.java new file mode 100644 index 0000000..a329a67 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHoldingJaw.java @@ -0,0 +1,33 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.HoldingJaw; + +/** + * 虚拟夹爪 + */ +public class VirtualHoldingJaw implements HoldingJaw { + @Override + public void open() { + + } + + @Override + public void close() { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void setSpeed(int speed) { + + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualLiquidFillingArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java similarity index 78% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualLiquidFillingArm.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java index 9ac2c04..47b1c3e 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualLiquidFillingArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java @@ -1,18 +1,16 @@ -package com.iflytop.gd.infrastructure.devices; +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.devices.LiquidFillingArm; import com.iflytop.gd.system.models.Point3D; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; + /** * 虚拟加液机械臂 */ -@Profile("dev") -@Component + public class VirtualLiquidFillingArm implements LiquidFillingArm { @Override public void moveTo(Point3D point) { diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualPump.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualPump.java new file mode 100644 index 0000000..d1bbb0c --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualPump.java @@ -0,0 +1,9 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.Pump; + +/** + * 虚拟泵 + */ +public class VirtualPump implements Pump { +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualRelay.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualRelay.java new file mode 100644 index 0000000..e1b3820 --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualRelay.java @@ -0,0 +1,15 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.Relay; + +public class VirtualRelay implements Relay { + @Override + public boolean open() { + return false; + } + + @Override + public boolean close() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualServoMotor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualServoMotor.java similarity index 96% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualServoMotor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualServoMotor.java index 67715fe..d5e7f0c 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualServoMotor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualServoMotor.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.virtual; import com.iflytop.gd.infrastructure.drivers.RegIndex; import com.iflytop.gd.system.devices.ServoMotor; @@ -13,8 +13,6 @@ import java.util.Map; /** * 虚拟伺服电机 */ -@Component -@Profile("dev") public class VirtualServoMotor implements ServoMotor { private final ServoMotorStatus servoMotorStatus = new ServoMotorStatus(); private final Map registers = new HashMap(); diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualStepMotor.java similarity index 99% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualStepMotor.java index add4875..b5a43b0 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualStepMotor.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.virtual; import cn.hutool.json.JSONUtil; import com.iflytop.gd.infrastructure.drivers.ModuleId; diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualSwitchSensor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualSwitchSensor.java new file mode 100644 index 0000000..bf0886b --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualSwitchSensor.java @@ -0,0 +1,13 @@ +package com.iflytop.gd.infrastructure.devices.virtual; + +import com.iflytop.gd.system.devices.SwitchSensor; + +/** + * 虚拟传感器 + */ +public class VirtualSwitchSensor implements SwitchSensor { + @Override + public boolean isOpen() { + return false; + } +} diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualTransportationArm.java b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java similarity index 96% rename from src/main/java/com/iflytop/gd/infrastructure/devices/VirtualTransportationArm.java rename to src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java index bcd5b3b..8013f63 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualTransportationArm.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java @@ -1,4 +1,4 @@ -package com.iflytop.gd.infrastructure.devices; +package com.iflytop.gd.infrastructure.devices.virtual; import com.iflytop.gd.common.exception.AppException; import com.iflytop.gd.common.result.ResultCode; @@ -10,7 +10,6 @@ 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 com.iflytop.gd.system.models.Point3D; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @@ -21,8 +20,6 @@ import java.util.Map; /** * 虚拟转移机械臂 */ -@Component -@Profile("dev") public class VirtualTransportationArm implements TransportationArm { private final StepMotor xDimMotor; private final StepMotor yDimMotor; diff --git a/src/main/java/com/iflytop/gd/infrastructure/repository/DeviceFactory.java b/src/main/java/com/iflytop/gd/infrastructure/repository/DeviceFactory.java new file mode 100644 index 0000000..fed68bd --- /dev/null +++ b/src/main/java/com/iflytop/gd/infrastructure/repository/DeviceFactory.java @@ -0,0 +1,27 @@ +package com.iflytop.gd.infrastructure.repository; + +import com.iflytop.gd.infrastructure.devices.physical.PhysicalStepMotor; +import com.iflytop.gd.infrastructure.devices.virtual.VirtualStepMotor; +import com.iflytop.gd.infrastructure.drivers.ModuleId; +import com.iflytop.gd.system.devices.StepMotor; +import com.iflytop.gd.system.drivers.CommandBus; +import com.iflytop.gd.system.constants.SystemMode; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class DeviceFactory { + private final CommandBus commandBus; + public StepMotor createStepMotor(SystemMode systemMode, ModuleId moduleId) { + if (SystemMode.VIRTUAL.equals(systemMode)) { + return new VirtualStepMotor(moduleId); + } + + if (SystemMode.PHYSICAL.equals(systemMode)) { + return new PhysicalStepMotor(moduleId, commandBus); + } + + throw new IllegalArgumentException("Unsupported system mode: " + systemMode); + } +} diff --git a/src/main/java/com/iflytop/gd/system/constants/SystemMode.java b/src/main/java/com/iflytop/gd/system/constants/SystemMode.java new file mode 100644 index 0000000..c660d67 --- /dev/null +++ b/src/main/java/com/iflytop/gd/system/constants/SystemMode.java @@ -0,0 +1,8 @@ +package com.iflytop.gd.system.constants; + +/** + * 系统运行模式 + */ +public enum SystemMode { + VIRTUAL, PHYSICAL +} diff --git a/src/main/java/com/iflytop/gd/system/devices/Sensor.java b/src/main/java/com/iflytop/gd/system/devices/Sensor.java deleted file mode 100644 index a84cbfd..0000000 --- a/src/main/java/com/iflytop/gd/system/devices/Sensor.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.iflytop.gd.system.devices; - -public interface Sensor { -} diff --git a/src/main/java/com/iflytop/gd/system/devices/SwitchSensor.java b/src/main/java/com/iflytop/gd/system/devices/SwitchSensor.java new file mode 100644 index 0000000..702ee25 --- /dev/null +++ b/src/main/java/com/iflytop/gd/system/devices/SwitchSensor.java @@ -0,0 +1,5 @@ +package com.iflytop.gd.system.devices; + +public interface SwitchSensor { + boolean isOpen(); +}