|
@ -1,8 +1,14 @@ |
|
|
package com.qyft.ms.app.controller; |
|
|
package com.qyft.ms.app.controller; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
import com.qyft.ms.app.device.status.DeviceStatus; |
|
|
import com.qyft.ms.app.device.status.DeviceStatus; |
|
|
|
|
|
import com.qyft.ms.app.model.bo.Point3D; |
|
|
import com.qyft.ms.app.model.vo.SelfTestVO; |
|
|
import com.qyft.ms.app.model.vo.SelfTestVO; |
|
|
|
|
|
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.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.Operation; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
@ -11,6 +17,10 @@ import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 测试用 |
|
|
* 测试用 |
|
|
*/ |
|
|
*/ |
|
@ -21,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class TestController { |
|
|
public class TestController { |
|
|
private final DeviceStatus deviceStatus; |
|
|
private final DeviceStatus deviceStatus; |
|
|
|
|
|
private final DeviceCommandService deviceCommandService; |
|
|
|
|
|
|
|
|
@Operation(summary = "启动虚拟模式") |
|
|
@Operation(summary = "启动虚拟模式") |
|
|
@PostMapping("/virtual") |
|
|
@PostMapping("/virtual") |
|
@ -36,4 +47,27 @@ public class TestController { |
|
|
deviceStatus.setSelfTestCompleted(true); |
|
|
deviceStatus.setSelfTestCompleted(true); |
|
|
return Result.success(); |
|
|
return Result.success(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "获取当前xyz位置") |
|
|
|
|
|
@PostMapping("/get-xyz") |
|
|
|
|
|
public Result<Point3D> getXyz() throws Exception { |
|
|
|
|
|
DeviceCommand motorXyzPositionGetCommand = DeviceCommandGenerator.motorXyzPositionGet(); // 生成获得电机XYZ相对原点坐标指令 |
|
|
|
|
|
CommandFuture motorXyzPositionGetCommandFuture = deviceCommandService.sendCommandNoFront(motorXyzPositionGetCommand); |
|
|
|
|
|
commandWait(motorXyzPositionGetCommandFuture); |
|
|
|
|
|
JSONObject motorXyzPositionGetCommandDeviceResult = motorXyzPositionGetCommandFuture.getResponseResult(); |
|
|
|
|
|
Double xAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("xAxisPosition"); |
|
|
|
|
|
Double yAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("yAxisPosition"); |
|
|
|
|
|
Double zAxisPosition = motorXyzPositionGetCommandDeviceResult.getJSONObject("data").getDouble("zAxisPosition"); |
|
|
|
|
|
Point3D point3D = new Point3D(xAxisPosition, yAxisPosition, zAxisPosition); |
|
|
|
|
|
|
|
|
|
|
|
return Result.success(point3D); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void commandWait(CommandFuture... futures) throws Exception { |
|
|
|
|
|
CompletableFuture<?>[] responseFutures = Arrays.stream(futures) |
|
|
|
|
|
.map(CommandFuture::getResponseFuture) |
|
|
|
|
|
.toArray(CompletableFuture[]::new); |
|
|
|
|
|
CompletableFuture.allOf(responseFutures) |
|
|
|
|
|
.get(120, TimeUnit.SECONDS); |
|
|
|
|
|
} |
|
|
} |
|
|
} |