diff --git a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java b/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java index 7c6b761..a8de039 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java +++ b/src/main/java/com/iflytop/gd/infrastructure/devices/VirtualDoor.java @@ -7,14 +7,15 @@ import org.springframework.stereotype.Component; @Component @Profile("dev") public class VirtualDoor implements Door { + private boolean isOpen = false; @Override public void open() { - + this.isOpen = true; } @Override public void close() { - + this.isOpen = false; } @Override diff --git a/src/main/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImpl.java b/src/main/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImpl.java index b75d096..c9a4ea6 100644 --- a/src/main/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImpl.java +++ b/src/main/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImpl.java @@ -33,6 +33,7 @@ public class WebSocketCommandBusImpl implements CommandBus { private Integer packetIndex = 0; private final String COMMAND_BUS_WEBSOCKET_URL; + private final Boolean commandBusEnable; public static final int PACKET_TYPE_CMD = 0xA0; public static final int PACKET_TYPE_ACK = 0xA1; @@ -40,14 +41,15 @@ public class WebSocketCommandBusImpl implements CommandBus { public static final int PACKET_TYPE_EVENT = 0xA3; //TODO 配置硬件服务段ws链接 - public WebSocketCommandBusImpl(@Value("${command_bus.websocket_server_url}") String websocketServerUrl) throws DeploymentException, IOException { + public WebSocketCommandBusImpl(@Value("${command_bus.websocket_server_url}") String websocketServerUrl, @Value("${command_bus.enable}") Boolean commandBusEnable) throws DeploymentException, IOException { this.COMMAND_BUS_WEBSOCKET_URL = websocketServerUrl; + this.commandBusEnable = commandBusEnable; } @Scheduled(fixedRate = 5000) @PostConstruct public void connectToCommandBusWebSocketServer() throws DeploymentException, IOException { - if (this.session == null || !this.session.isOpen()) { + if (commandBusEnable && (this.session == null || !this.session.isOpen())) { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); URI endpointURI = URI.create(COMMAND_BUS_WEBSOCKET_URL); try { diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 8781a47..2515f8f 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -33,3 +33,4 @@ springdoc: command_bus: websocket_server_url: ws://127.0.0.1 + enable: false diff --git a/src/test/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImplTest.java b/src/test/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImplTest.java index bfd9220..36c2f3c 100644 --- a/src/test/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImplTest.java +++ b/src/test/java/com/iflytop/gd/infrastructure/drivers/WebSocketCommandBusImplTest.java @@ -19,7 +19,7 @@ class WebSocketCommandBusImplTest { @Test void waitForCommandExec() throws DeploymentException, IOException, HardwareErrorException, CommandExecTimeoutException, InterruptedException { String webSocketUrl = "ws://localhost:8888"; - WebSocketCommandBusImpl webSocketCommandBus = new WebSocketCommandBusImpl(webSocketUrl); + WebSocketCommandBusImpl webSocketCommandBus = new WebSocketCommandBusImpl(webSocketUrl, true); webSocketCommandBus.connectToCommandBusWebSocketServer(); DataPacket dataPacket = DataPacket.createCommandDataPacket(ModuleId.HBotXM.index, CmdId.step_motor_easy_move_to.index, 100);