Browse Source

feat:计算指令通信、执行时间

master
白凤吉 2 months ago
parent
commit
73f72e95d2
  1. 7
      src/main/java/com/iflytop/gd/app/controller/TestController.java
  2. 30
      src/main/java/com/iflytop/gd/app/service/api/TestService.java

7
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<List<AllSensorDTO>> countPackage() throws Exception {
testService.countPackage();
return Result.success();
}
}

30
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<AllSensorDTO> getAllSensor() throws HardwareException {
List<AllSensorDTO> 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);
}
}
Loading…
Cancel
Save