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