From 17d23b882d0338836a6e1a32573a45e8df611d7d Mon Sep 17 00:00:00 2001 From: HSZ_HeSongZhen <210202959@qq.com> Date: Wed, 7 May 2025 20:24:58 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=AD=89=E7=BA=A7=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/iflytop/gd/hardware/HardwareService.java | 10 ++++++++-- .../iflytop/gd/hardware/constants/ActionOvertimeConstant.java | 2 +- .../gd/hardware/drivers/StepMotorDriver/DoorDriver.java | 6 +++--- src/main/resources/logback.xml | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/iflytop/gd/hardware/HardwareService.java b/src/main/java/com/iflytop/gd/hardware/HardwareService.java index 7a14e98..edac94a 100644 --- a/src/main/java/com/iflytop/gd/hardware/HardwareService.java +++ b/src/main/java/com/iflytop/gd/hardware/HardwareService.java @@ -11,6 +11,7 @@ import com.iflytop.gd.common.enums.cmd.CmdDevice; import com.iflytop.gd.hardware.command.CommandHandler; import com.iflytop.gd.hardware.command.DeviceResponse; import com.iflytop.gd.hardware.command.checker.SupportMethod; +import com.iflytop.gd.hardware.exception.HardwareException; import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -47,7 +48,6 @@ public class HardwareService { for (CmdDevice device : devices) { cmdHandlers.put(device, handler); } - } public boolean sendCommand(DeviceCommand cmd) { @@ -71,12 +71,18 @@ public class HardwareService { cmdHandlers.get(cmd.getDevice()).sendCommand(cmd); response.setSuccess(Boolean.TRUE); } else { + log.error("不支持的设备类型: {}", cmd.getDevice()); throw new InvalidParameterException(StrUtil.format("[Device]: {}", cmd.getDevice())); } + } catch (HardwareException e) { + log.error("HardwareException 指令执行失败: {}", e.getMessage(), e); + response.setSuccess(Boolean.FALSE); } catch (Exception e) { + log.error("指令执行失败: {}", e.getMessage(), e); response.setSuccess(Boolean.FALSE); - } finally { + } + finally { JSONObject jsonResponse = JSONUtil.parseObj(response); eventPublisher.publishEvent(new CommandFeedbackEvent(this, jsonResponse)); } diff --git a/src/main/java/com/iflytop/gd/hardware/constants/ActionOvertimeConstant.java b/src/main/java/com/iflytop/gd/hardware/constants/ActionOvertimeConstant.java index 5eab7b8..6b2a005 100644 --- a/src/main/java/com/iflytop/gd/hardware/constants/ActionOvertimeConstant.java +++ b/src/main/java/com/iflytop/gd/hardware/constants/ActionOvertimeConstant.java @@ -12,7 +12,7 @@ import java.util.List; @Component public class ActionOvertimeConstant { - final Integer defaultOvertime = 10 * 1000; + final Integer defaultOvertime = 60 * 1000; static class OvertimeConfigItem { public MId mid; diff --git a/src/main/java/com/iflytop/gd/hardware/drivers/StepMotorDriver/DoorDriver.java b/src/main/java/com/iflytop/gd/hardware/drivers/StepMotorDriver/DoorDriver.java index 1f0829f..2f99f0d 100644 --- a/src/main/java/com/iflytop/gd/hardware/drivers/StepMotorDriver/DoorDriver.java +++ b/src/main/java/com/iflytop/gd/hardware/drivers/StepMotorDriver/DoorDriver.java @@ -35,7 +35,7 @@ public class DoorDriver{ // ==== ==== ==== ==== ==== ==== Ctrl ==== ==== ==== ==== ==== ==== public void moveToHome(StepMotorMId stepMotorMId) throws Exception { - stepMotorCtrlDriver_.stepMotorEasyMoveToZero(stepMotorMId); + stepMotorCtrlDriver_.stepMotorEasyMoveToZeroBlock(stepMotorMId); } public void moveTo(StepMotorMId stepMotorMId, double position) throws Exception @@ -46,7 +46,7 @@ public class DoorDriver{ } int motorPosition = StepMotorHelper.toMotorPosition(position); - stepMotorCtrlDriver_.stepMotorEasyMoveTo(stepMotorMId, motorPosition); + stepMotorCtrlDriver_.stepMotorEasyMoveToBlock(stepMotorMId, motorPosition); } public void moveBy(StepMotorMId stepMotorMId, double distance) throws Exception @@ -57,7 +57,7 @@ public class DoorDriver{ } int motorPosition = StepMotorHelper.toMotorPosition(distance); - stepMotorCtrlDriver_.stepMotorEasyMoveBy(stepMotorMId, motorPosition); + stepMotorCtrlDriver_.stepMotorEasyMoveByBlock(stepMotorMId, motorPosition); } public void stop(StepMotorMId stepMotorMId) throws Exception { diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f18b14b..0e6c853 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -46,7 +46,7 @@ - +