221 lines
8.3 KiB
Java
221 lines
8.3 KiB
Java
package com.ruoyi.device.controller;
|
||
|
||
import com.ruoyi.common.core.domain.R;
|
||
import com.ruoyi.common.core.web.controller.BaseController;
|
||
import com.ruoyi.device.api.domain.DroneCurrentStatusVO;
|
||
import com.ruoyi.device.api.domain.DroneFlightControlRequest;
|
||
import com.ruoyi.device.api.domain.DroneRealtimeInfoVO;
|
||
import com.ruoyi.device.api.domain.DroneTakeoffResponseVO;
|
||
import com.ruoyi.device.api.domain.MachineStateVO;
|
||
import com.ruoyi.device.api.enums.DroneCurrentStatusEnum;
|
||
import com.ruoyi.device.api.enums.DroneMissionStatusEnum;
|
||
import com.ruoyi.device.domain.impl.machine.MachineCommandManager;
|
||
import com.ruoyi.device.domain.impl.machine.command.CommandResult;
|
||
import com.ruoyi.device.domain.impl.machine.command.CommandType;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.Parameter;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.concurrent.CompletableFuture;
|
||
|
||
/**
|
||
* 无人机飞控Controller
|
||
*
|
||
* @author ruoyi
|
||
* @date 2026-02-04
|
||
*/
|
||
@Slf4j
|
||
@Tag(name = "无人机飞控管理", description = "无人机飞控相关接口")
|
||
@RestController
|
||
@RequestMapping("/drone")
|
||
public class AircraftFlyController extends BaseController
|
||
{
|
||
@Autowired
|
||
private MachineCommandManager machineCommandManager;
|
||
|
||
@Autowired
|
||
private com.ruoyi.device.domain.impl.machine.statemachine.MachineStateManager machineStateManager;
|
||
/**
|
||
* 无人机飞控命令
|
||
*
|
||
* @param request 飞控命令请求
|
||
* @return 结果
|
||
*/
|
||
@Operation(summary = "无人机飞控命令", description = "发送飞控命令控制无人机的飞行动作,包括前进、后退、左移、右移、左旋、右旋、上升、下降、返航、急停等")
|
||
@PostMapping("/flight-control")
|
||
public R<Void> flightControl(@RequestBody DroneFlightControlRequest request)
|
||
{
|
||
// TODO: 实现飞控命令逻辑
|
||
return R.ok();
|
||
}
|
||
|
||
/**
|
||
* 无人机实时信息展示
|
||
*
|
||
* @param taskId 任务ID
|
||
* @return 实时信息
|
||
*/
|
||
@Operation(summary = "无人机实时信息展示", description = "根据任务ID获取无人机的实时飞行信息,包括速度、高度、姿态角等")
|
||
@GetMapping("/realtime-info/{taskId}")
|
||
public R<DroneRealtimeInfoVO> getRealtimeInfo(
|
||
@Parameter(description = "任务ID", required = true, example = "1")
|
||
@PathVariable("taskId") Long taskId)
|
||
{
|
||
// TODO: 实现获取实时信息逻辑
|
||
DroneRealtimeInfoVO vo = new DroneRealtimeInfoVO();
|
||
vo.setClimbSpeed(0);
|
||
vo.setCruiseSpeed(0);
|
||
vo.setDistanceToAirport(0);
|
||
vo.setAltitude(0);
|
||
vo.setPitch(0);
|
||
vo.setYaw(0);
|
||
vo.setGimbalPitch(0);
|
||
vo.setGimbalYaw(0);
|
||
vo.setMissionStatus(DroneMissionStatusEnum.IDLE);
|
||
return R.ok(vo);
|
||
}
|
||
|
||
/**
|
||
* 无人机当前状态查询
|
||
*
|
||
* @param dockId 机场ID
|
||
* @return 当前状态
|
||
*/
|
||
@Operation(summary = "无人机当前状态查询", description = "根据机场ID查询无人机的当前飞行状态")
|
||
@GetMapping("/current-status/{dockId}")
|
||
public R<DroneCurrentStatusVO> getCurrentStatus(
|
||
@Parameter(description = "机场ID", required = true, example = "1")
|
||
@PathVariable("dockId") Long dockId)
|
||
{
|
||
// TODO: 实现查询当前状态逻辑
|
||
DroneCurrentStatusVO vo = new DroneCurrentStatusVO();
|
||
vo.setDockId(dockId);
|
||
vo.setCurrentStatus(DroneCurrentStatusEnum.HOVERING);
|
||
return R.ok(vo);
|
||
}
|
||
|
||
/**
|
||
* 无人机起飞接口
|
||
*
|
||
* @param dockId 机场ID
|
||
* @return 起飞响应(任务ID和任务状态)
|
||
*/
|
||
@Operation(summary = "无人机起飞", description = "控制指定机场的无人机执行起飞操作,返回任务ID和当前任务状态")
|
||
@PostMapping("/takeoff/{dockId}")
|
||
public R<DroneTakeoffResponseVO> takeoff(
|
||
@Parameter(description = "机场ID", required = true, example = "1")
|
||
@PathVariable("dockId") Long dockId)
|
||
{
|
||
// TODO: 实现起飞逻辑
|
||
DroneTakeoffResponseVO vo = new DroneTakeoffResponseVO();
|
||
vo.setTaskId(1L);
|
||
vo.setMissionStatus(DroneMissionStatusEnum.TAKING_OFF);
|
||
return R.ok(vo);
|
||
}
|
||
|
||
/**
|
||
* 无人机开机接口
|
||
*
|
||
* @param sn 机场SN号
|
||
* @return 开机响应
|
||
*/
|
||
@Operation(summary = "无人机开机", description = "控制指定机场的无人机执行开机操作")
|
||
@PostMapping("/power-on/{sn}")
|
||
public R<String> powerOn(
|
||
@Parameter(description = "机场SN号", required = true, example = "THJSQ03B2309DN7VQN43")
|
||
@PathVariable("sn") String sn)
|
||
{
|
||
log.info("收到无人机开机请求: sn={}", sn);
|
||
|
||
try {
|
||
// 调用机器命令管理器执行开机命令
|
||
CompletableFuture<CommandResult> future = machineCommandManager.executeCommand(sn, CommandType.POWER_ON);
|
||
|
||
// 等待命令执行完成
|
||
CommandResult result = future.get();
|
||
|
||
if (result.isSuccess()) {
|
||
log.info("无人机开机成功: sn={}", sn);
|
||
return R.ok("开机命令执行成功");
|
||
} else {
|
||
log.error("无人机开机失败: sn={}, reason={}", sn, result.getErrorMessage());
|
||
return R.fail("开机命令执行失败: " + result.getErrorMessage());
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("无人机开机异常: sn={}", sn, e);
|
||
return R.fail("开机命令执行异常: " + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 无人机关机接口
|
||
*
|
||
* @param sn 机场SN号
|
||
* @return 关机响应
|
||
*/
|
||
@Operation(summary = "无人机关机", description = "控制指定机场的无人机执行关机操作")
|
||
@PostMapping("/power-off/{sn}")
|
||
public R<String> powerOff(
|
||
@Parameter(description = "机场SN号", required = true, example = "THJSQ03B2309DN7VQN43")
|
||
@PathVariable("sn") String sn)
|
||
{
|
||
log.info("收到无人机关机请求: sn={}", sn);
|
||
|
||
try {
|
||
// 调用机器命令管理器执行关机命令
|
||
CompletableFuture<CommandResult> future = machineCommandManager.executeCommand(sn, CommandType.POWER_OFF);
|
||
|
||
// 等待命令执行完成
|
||
CommandResult result = future.get();
|
||
|
||
if (result.isSuccess()) {
|
||
log.info("无人机关机成功: sn={}", sn);
|
||
return R.ok("关机命令执行成功");
|
||
} else {
|
||
log.error("无人机关机失败: sn={}, reason={}", sn, result.getErrorMessage());
|
||
return R.fail("关机命令执行失败: " + result.getErrorMessage());
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("无人机关机异常: sn={}", sn, e);
|
||
return R.fail("关机命令执行异常: " + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询无人机状态
|
||
*
|
||
* @param sn 设备SN号
|
||
* @return 状态信息
|
||
*/
|
||
@Operation(summary = "查询无人机状态", description = "根据设备SN号查询无人机的实时状态信息")
|
||
@GetMapping("/machine-state/{sn}")
|
||
public R<MachineStateVO> getMachineState(
|
||
@Parameter(description = "设备SN号", required = true, example = "TH001")
|
||
@PathVariable("sn") String sn)
|
||
{
|
||
log.info("查询无人机状态: sn={}", sn);
|
||
|
||
try {
|
||
// 从 MachineStateManager 获取状态
|
||
com.ruoyi.device.domain.impl.machine.state.MachineStates states = machineStateManager.getStates(sn);
|
||
|
||
// 转换为 VO 对象
|
||
MachineStateVO vo = new MachineStateVO();
|
||
vo.setSn(sn);
|
||
vo.setDroneState(states.getDroneState().name());
|
||
vo.setAirportState(states.getAirportState().name());
|
||
vo.setCoverState(states.getCoverState().name());
|
||
vo.setDrcState(states.getDrcState().name());
|
||
vo.setDebugModeState(states.getDebugModeState().name());
|
||
|
||
log.info("查询到状态: sn={}, vo={}", sn, vo);
|
||
return R.ok(vo);
|
||
} catch (Exception e) {
|
||
log.error("查询无人机状态异常: sn={}", sn, e);
|
||
return R.fail("查询状态失败: " + e.getMessage());
|
||
}
|
||
}
|
||
} |