Browse Source

feat:完善设备定义

tags/freeze
黄翔 3 months ago
parent
commit
cf934cc92c
  1. 6
      src/main/java/com/iflytop/gd/app/service/WebSocketService.java
  2. 14
      src/main/java/com/iflytop/gd/common/notification/Notification.java
  3. 10
      src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java
  4. 3
      src/main/java/com/iflytop/gd/debug/services/cmds/ColdTrapStartHeatingCommandHandler.java
  5. 1
      src/main/java/com/iflytop/gd/debug/services/cmds/DoorCloseCommandHandler.java
  6. 13
      src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java
  7. 43
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalColdTray.java
  8. 12
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalDoor.java
  9. 18
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalFan.java
  10. 33
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalHoldingJaw.java
  11. 14
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalLiquidFillingArm.java
  12. 9
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalPump.java
  13. 18
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalRelay.java
  14. 6
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalServoMotor.java
  15. 8
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalStepMotor.java
  16. 14
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalSwitchSensor.java
  17. 20
      src/main/java/com/iflytop/gd/infrastructure/devices/physical/PhysicalTransportationArm.java
  18. 43
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualColdTray.java
  19. 10
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualDoor.java
  20. 18
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualFan.java
  21. 2
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHeater.java
  22. 33
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualHoldingJaw.java
  23. 8
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualLiquidFillingArm.java
  24. 9
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualPump.java
  25. 15
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualRelay.java
  26. 4
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualServoMotor.java
  27. 2
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualStepMotor.java
  28. 13
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualSwitchSensor.java
  29. 5
      src/main/java/com/iflytop/gd/infrastructure/devices/virtual/VirtualTransportationArm.java
  30. 27
      src/main/java/com/iflytop/gd/infrastructure/repository/DeviceFactory.java
  31. 8
      src/main/java/com/iflytop/gd/system/constants/SystemMode.java
  32. 4
      src/main/java/com/iflytop/gd/system/devices/Sensor.java
  33. 5
      src/main/java/com/iflytop/gd/system/devices/SwitchSensor.java

6
src/main/java/com/iflytop/gd/app/service/WebSocketService.java

@ -1,6 +1,7 @@
package com.iflytop.gd.app.service; package com.iflytop.gd.app.service;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.iflytop.gd.common.notification.Notification;
import com.iflytop.gd.infrastructure.config.WebSocketServer; import com.iflytop.gd.infrastructure.config.WebSocketServer;
import com.iflytop.gd.app.model.dto.WebsocketResult; import com.iflytop.gd.app.model.dto.WebsocketResult;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,4 +16,9 @@ public class WebSocketService {
WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult)); WebSocketServer.sendMessageToClients(JSONUtil.toJsonStr(websocketResult));
} }
public void pushNotification(Notification notification) {
push("notification", notification);
}
} }

14
src/main/java/com/iflytop/gd/common/notification/Notification.java

@ -1,6 +1,7 @@
package com.iflytop.gd.common.notification; package com.iflytop.gd.common.notification;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import com.iflytop.gd.app.model.dto.CmdDTO;
import lombok.Getter; import lombok.Getter;
@ -41,6 +42,14 @@ public class Notification {
return new Notification(commandId, command, "info", title, content); 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级别通知 * 创建Warn级别通知
@ -60,6 +69,11 @@ public class Notification {
return new Notification(commandId, command, "error", title, content); 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级别通知 * 创建Fatal级别通知

10
src/main/java/com/iflytop/gd/debug/controller/CmdDebugController.java

@ -1,6 +1,7 @@
package com.iflytop.gd.debug.controller; package com.iflytop.gd.debug.controller;
import com.iflytop.gd.app.model.dto.CmdDTO; 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.app.service.exceptions.UnSupportCommandException;
import com.iflytop.gd.common.result.Result; import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.common.cmd.CommandHandler; 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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
@Tag(name = "前端调试指令") @Tag(name = "前端调试指令")
@RestController @RestController
@RequestMapping("/api/debug/cmd") @RequestMapping("/api/debug/cmd")
@ -28,10 +31,11 @@ public class CmdDebugController {
public Result<?> controlMethod(@Valid @RequestBody CmdDTO cmdDTO) { public Result<?> controlMethod(@Valid @RequestBody CmdDTO cmdDTO) {
String commandName = cmdDTO.getCommand(); String commandName = cmdDTO.getCommand();
try { try {
log.info("收到调试指令{}", commandName);
CommandHandler commandHandler = registry.getCommandHandler(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) { } catch (UnSupportCommandException exception) {
log.error("未找到对应的调试指令{}", commandName); log.error("未找到对应的调试指令{}", commandName);
String errorMsg = "未找到对应的调试指令, commandName=" + commandName; String errorMsg = "未找到对应的调试指令, commandName=" + commandName;

3
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.app.model.dto.CmdDTO;
import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.cmd.CommandHandler; import com.iflytop.gd.common.cmd.CommandHandler;
import com.iflytop.gd.system.devices.ColdTray;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -15,6 +16,8 @@ import org.springframework.stereotype.Component;
@RequiredArgsConstructor @RequiredArgsConstructor
@CommandMapping("debug_cold_trap_start_heating") @CommandMapping("debug_cold_trap_start_heating")
public class ColdTrapStartHeatingCommandHandler implements CommandHandler { public class ColdTrapStartHeatingCommandHandler implements CommandHandler {
private final ColdTray coldTray;
@Override @Override
public void handle(CmdDTO cmdDTO) { public void handle(CmdDTO cmdDTO) {

1
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.app.model.dto.CmdDTO;
import com.iflytop.gd.common.annotation.CommandMapping; import com.iflytop.gd.common.annotation.CommandMapping;
import com.iflytop.gd.common.cmd.CommandHandler; import com.iflytop.gd.common.cmd.CommandHandler;
import com.iflytop.gd.infrastructure.devices.MotorDrivenDoor;
import com.iflytop.gd.system.devices.Door; import com.iflytop.gd.system.devices.Door;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

13
src/main/java/com/iflytop/gd/debug/services/cmds/DoorOpenCommandHandler.java

@ -1,9 +1,10 @@
package com.iflytop.gd.debug.services.cmds; package com.iflytop.gd.debug.services.cmds;
import com.iflytop.gd.app.model.dto.CmdDTO; 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.annotation.CommandMapping;
import com.iflytop.gd.common.cmd.CommandHandler; 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 com.iflytop.gd.system.devices.Door;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -19,8 +20,16 @@ import org.springframework.stereotype.Component;
public class DoorOpenCommandHandler implements CommandHandler { public class DoorOpenCommandHandler implements CommandHandler {
private final Door door; private final Door door;
private final WebSocketService webSocketService;
@Override @Override
public void handle(CmdDTO cmdDTO) { 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(), "开门指令执行完成"));
} }
} }

43
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;
}
}

12
src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenDoor.java → 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.exception.AppException;
import com.iflytop.gd.common.result.ResultCode; 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.infrastructure.drivers.ModuleId;
import com.iflytop.gd.system.constants.DistanceUnit; import com.iflytop.gd.system.constants.DistanceUnit;
import com.iflytop.gd.system.devices.Door; import com.iflytop.gd.system.devices.Door;
@ -15,15 +16,14 @@ import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
/** /**
* 步进电机驱动的门实现
* 物理门
*/ */
@Profile("test")
@Component
public class MotorDrivenDoor implements Door {
public class PhysicalDoor implements Door {
private final StepMotor doorMotor; private final StepMotor doorMotor;
public MotorDrivenDoor(CommandBus commandBus) {
public PhysicalDoor(CommandBus commandBus) {
this.doorMotor = new VirtualStepMotor(ModuleId.DoorM); this.doorMotor = new VirtualStepMotor(ModuleId.DoorM);
} }

18
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;
}
}

33
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) {
}
}

14
src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenLiquidFillingArm.java → 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; import com.iflytop.gd.infrastructure.drivers.ModuleId;
@ -13,17 +13,15 @@ import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component; 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 largeArmMotor;
private final StepMotor smallArmMotor; 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 @Override

9
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 {
}

18
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;
}
}

6
src/main/java/com/iflytop/gd/infrastructure/devices/StandardServoMotor.java → 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.infrastructure.drivers.RegIndex;
import com.iflytop.gd.system.devices.ServoMotor; import com.iflytop.gd.system.devices.ServoMotor;
/** /**
* 标准物理伺服电机
* 物理伺服电机
*/ */
public class StandardServoMotor implements ServoMotor {
public class PhysicalServoMotor implements ServoMotor {
@Override @Override
public void enable() { public void enable() {

8
src/main/java/com/iflytop/gd/infrastructure/devices/StandardStepMotor.java → 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.CmdId;
import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.infrastructure.drivers.ModuleId;
@ -16,14 +16,14 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* 标准电机实现
* 物理步进电机实现
*/ */
public class StandardStepMotor implements StepMotor {
public class PhysicalStepMotor implements StepMotor {
protected final ModuleId moduleId; protected final ModuleId moduleId;
protected final CommandBus commandBus; protected final CommandBus commandBus;
protected final Integer DEFAULT_COMMAND_EXEC_TIMEOUT_SECONDS = 10; 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.moduleId = moduleId;
this.commandBus = commandBus; this.commandBus = commandBus;
} }

14
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;
}
}

20
src/main/java/com/iflytop/gd/infrastructure/devices/MotorDrivenTransportationArm.java → 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.infrastructure.drivers.ModuleId;
import com.iflytop.gd.system.constants.Dim; 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.StepMotor;
import com.iflytop.gd.system.devices.TransportationArm; import com.iflytop.gd.system.devices.TransportationArm;
import com.iflytop.gd.system.drivers.CommandBus; 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 xDimMotor;
private final StepMotor yDimMotor; private final StepMotor yDimMotor;
private final StepMotor zDimMotor; 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 @Override

43
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;
}
}

10
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java → 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 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 { public class VirtualDoor implements Door {
private boolean isOpen = false; private boolean isOpen = false;
@Override @Override

18
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;
}
}

2
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualHeater.java → 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.devices.Heater;
import com.iflytop.gd.system.models.HeaterStatus; import com.iflytop.gd.system.models.HeaterStatus;

33
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) {
}
}

8
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualLiquidFillingArm.java → 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.LiquidFillArmMotorIndex;
import com.iflytop.gd.system.constants.RotationDirection; import com.iflytop.gd.system.constants.RotationDirection;
import com.iflytop.gd.system.constants.SpeedUnit; import com.iflytop.gd.system.constants.SpeedUnit;
import com.iflytop.gd.system.devices.LiquidFillingArm; import com.iflytop.gd.system.devices.LiquidFillingArm;
import com.iflytop.gd.system.models.Point3D; 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 { public class VirtualLiquidFillingArm implements LiquidFillingArm {
@Override @Override
public void moveTo(Point3D point) { public void moveTo(Point3D point) {

9
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 {
}

15
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;
}
}

4
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualServoMotor.java → 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.infrastructure.drivers.RegIndex;
import com.iflytop.gd.system.devices.ServoMotor; import com.iflytop.gd.system.devices.ServoMotor;
@ -13,8 +13,6 @@ import java.util.Map;
/** /**
* 虚拟伺服电机 * 虚拟伺服电机
*/ */
@Component
@Profile("dev")
public class VirtualServoMotor implements ServoMotor { public class VirtualServoMotor implements ServoMotor {
private final ServoMotorStatus servoMotorStatus = new ServoMotorStatus(); private final ServoMotorStatus servoMotorStatus = new ServoMotorStatus();
private final Map<RegIndex, Integer> registers = new HashMap<RegIndex, Integer>(); private final Map<RegIndex, Integer> registers = new HashMap<RegIndex, Integer>();

2
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualStepMotor.java → 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 cn.hutool.json.JSONUtil;
import com.iflytop.gd.infrastructure.drivers.ModuleId; import com.iflytop.gd.infrastructure.drivers.ModuleId;

13
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;
}
}

5
src/main/java/com/iflytop/gd/infrastructure/devices/VirtualTransportationArm.java → 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.exception.AppException;
import com.iflytop.gd.common.result.ResultCode; 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.devices.TransportationArm;
import com.iflytop.gd.system.exceptions.CommandExecTimeoutException; import com.iflytop.gd.system.exceptions.CommandExecTimeoutException;
import com.iflytop.gd.system.exceptions.HardwareErrorException; import com.iflytop.gd.system.exceptions.HardwareErrorException;
import com.iflytop.gd.system.models.Point3D;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -21,8 +20,6 @@ import java.util.Map;
/** /**
* 虚拟转移机械臂 * 虚拟转移机械臂
*/ */
@Component
@Profile("dev")
public class VirtualTransportationArm implements TransportationArm { public class VirtualTransportationArm implements TransportationArm {
private final StepMotor xDimMotor; private final StepMotor xDimMotor;
private final StepMotor yDimMotor; private final StepMotor yDimMotor;

27
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);
}
}

8
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
}

4
src/main/java/com/iflytop/gd/system/devices/Sensor.java

@ -1,4 +0,0 @@
package com.iflytop.gd.system.devices;
public interface Sensor {
}

5
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();
}
Loading…
Cancel
Save