|
|
@ -1,8 +1,13 @@ |
|
|
|
package com.qyft.ms.app.controller; |
|
|
|
|
|
|
|
import com.qyft.ms.app.device.status.DeviceStatus; |
|
|
|
import com.qyft.ms.app.model.vo.SelfTestVO; |
|
|
|
import com.qyft.ms.app.service.SelfTestService; |
|
|
|
import com.qyft.ms.system.common.device.command.CommandFuture; |
|
|
|
import com.qyft.ms.system.common.device.command.DeviceCommandGenerator; |
|
|
|
import com.qyft.ms.system.common.result.Result; |
|
|
|
import com.qyft.ms.system.model.bo.DeviceCommand; |
|
|
|
import com.qyft.ms.system.service.device.DeviceCommandService; |
|
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
@ -11,6 +16,10 @@ import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutionException; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
import java.util.concurrent.TimeoutException; |
|
|
|
|
|
|
|
@Tag(name = "自检") |
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/self-test") |
|
|
@ -18,10 +27,26 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
@Slf4j |
|
|
|
public class SelfTestController { |
|
|
|
private final SelfTestService selfTestService; |
|
|
|
private final DeviceCommandService deviceCommandService; |
|
|
|
private final DeviceStatus deviceStatus; |
|
|
|
|
|
|
|
@Operation(summary = "获取自检状态") |
|
|
|
@GetMapping("/") |
|
|
|
public Result<SelfTestVO> getSelfTestStatus() { |
|
|
|
public Result<SelfTestVO> getSelfTestStatus() throws ExecutionException, InterruptedException, TimeoutException { |
|
|
|
DeviceCommand overallDeviceStatusGetCommand = DeviceCommandGenerator.overallDeviceStatusGet(); |
|
|
|
CommandFuture overallDeviceStatusGetCommandFuture = deviceCommandService.sendCommandNoFront(overallDeviceStatusGetCommand); |
|
|
|
overallDeviceStatusGetCommandFuture.getResponseFuture().get(5, TimeUnit.SECONDS); |
|
|
|
boolean xAxisAtOrigin = overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("xAxisAtOrigin"); |
|
|
|
boolean yAxisAtOrigin = overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("yAxisAtOrigin"); |
|
|
|
boolean zAxisAtOrigin = overallDeviceStatusGetCommandFuture.getResponseResult().getJSONObject("data").getBool("zAxisAtOrigin"); |
|
|
|
|
|
|
|
selfTestService.getSelfTestStatus().setXAxisAtOrigin(xAxisAtOrigin); |
|
|
|
selfTestService.getSelfTestStatus().setYAxisAtOrigin(yAxisAtOrigin); |
|
|
|
selfTestService.getSelfTestStatus().setZAxisAtOrigin(zAxisAtOrigin); |
|
|
|
|
|
|
|
if (xAxisAtOrigin && yAxisAtOrigin && zAxisAtOrigin) { |
|
|
|
deviceStatus.setSelfTestCompleted(true); |
|
|
|
} |
|
|
|
return Result.success(selfTestService.getSelfTestStatus()); |
|
|
|
} |
|
|
|
|
|
|
|