diff --git a/src/main/java/com/iflytop/gd/app/controller/TestController.java b/src/main/java/com/iflytop/gd/app/controller/TestController.java index ec201ee..dd79e3e 100644 --- a/src/main/java/com/iflytop/gd/app/controller/TestController.java +++ b/src/main/java/com/iflytop/gd/app/controller/TestController.java @@ -120,4 +120,11 @@ public class TestController { testService.setHeatModuleState(code, trayStatus); return Result.success(); } + + @Operation(summary = "计算包装指令的时间") + @GetMapping("/count-package") + public Result> countPackage() throws Exception { + testService.countPackage(); + return Result.success(); + } } diff --git a/src/main/java/com/iflytop/gd/app/service/api/TestService.java b/src/main/java/com/iflytop/gd/app/service/api/TestService.java index 477f41b..34192cf 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/TestService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/TestService.java @@ -1,13 +1,19 @@ package com.iflytop.gd.app.service.api; import com.iflytop.gd.app.model.dto.AllSensorDTO; +import com.iflytop.gd.app.service.device.DeviceCommandService; import com.iflytop.gd.app.service.device.DeviceStateService; +import com.iflytop.gd.common.command.CommandFuture; +import com.iflytop.gd.common.command.DeviceCommandBundle; +import com.iflytop.gd.common.command.DeviceCommandGenerator; import com.iflytop.gd.common.enums.HeatModuleCode; import com.iflytop.gd.common.enums.HeatingType; +import com.iflytop.gd.common.utils.CommandUtil; import com.iflytop.gd.hardware.exception.HardwareException; import com.iflytop.gd.hardware.service.GDDeviceStatusService; import com.iflytop.gd.hardware.type.IO.InputIOMId; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -16,11 +22,13 @@ import java.util.List; /** * 测试用 */ +@Slf4j @Service @RequiredArgsConstructor public class TestService { private final GDDeviceStatusService gdDeviceStatusService; private final DeviceStateService deviceStateService; + private final DeviceCommandService deviceCommandService; public List getAllSensor() throws HardwareException { List allSensorDTOList = new ArrayList<>(); @@ -56,4 +64,26 @@ public class TestService { deviceStateService.getDeviceState().getHeatModuleByCode(code).setTrayStatus(trayStatus); } + public void countPackage() throws Exception { + long startTime = System.nanoTime(); + DeviceCommandBundle deviceCommand = DeviceCommandGenerator.fan1Open(); + long endTime = System.nanoTime(); + long duration = endTime - startTime; + double milliseconds = duration / 1_000_000.0; + log.info("指令包装时间:{}",milliseconds); + startTime = System.nanoTime(); + CommandFuture deviceCommandFuture = deviceCommandService.sendCommand(deviceCommand); + endTime = System.nanoTime(); + duration = endTime - startTime; + milliseconds = duration / 1_000_000.0; + log.info("指令发送时间:{}",milliseconds); + CommandUtil.wait(deviceCommandFuture); + endTime = System.nanoTime(); + duration = endTime - startTime; + milliseconds = duration / 1_000_000.0; + log.info("指令反馈时间:{}",milliseconds); + deviceCommand = DeviceCommandGenerator.fan1Close(); + deviceCommandService.sendCommand(deviceCommand); + } + }