修改无人机的状态判断

This commit is contained in:
孙小云 2026-02-11 16:28:03 +08:00
parent a0eb7202ff
commit 5e9111e879
1 changed files with 37 additions and 17 deletions

View File

@ -651,11 +651,11 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
.orElse(""); .orElse("");
log.info("无人机 MODE 值: {}", mode); log.info("无人机 MODE 值: {}", mode);
// 获取 tsingal图传信号强度用于判断开关机 // // 获取 tsingal图传信号强度用于判断开关机
Integer tsingal = telemetry.get(TuohengDeviceTelemetry.TSINGAL) // Integer tsingal = telemetry.get(TuohengDeviceTelemetry.TSINGAL)
.map(TelemetryValue::getValue) // .map(TelemetryValue::getValue)
.orElse(0); // .orElse(0);
log.info("无人机 TSINGAL 值: {}", tsingal); // log.info("无人机 TSINGAL 值: {}", tsingal);
// MachineStateManager 获取无人机开关机状态 // MachineStateManager 获取无人机开关机状态
DroneState droneState = null; DroneState droneState = null;
@ -674,23 +674,43 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
boolean isPowerOn = (droneState != null && droneState != DroneState.POWER_OFF && droneState != DroneState.UNKNOWN); boolean isPowerOn = (droneState != null && droneState != DroneState.POWER_OFF && droneState != DroneState.UNKNOWN);
log.info("无人机开关机状态: {}", isPowerOn ? "开机" : "关机"); log.info("无人机开关机状态: {}", isPowerOn ? "开机" : "关机");
// 判断逻辑 // MachineStateManager 获取舱门状态
// 注意无人机详情接口无法获取机场舱门状态 CoverState coverState = null;
// 如果 mode == "auto" 且开机推测为 IN_MISSION if (dockSn != null) {
// 否则根据开关机状态判断 try {
String aircraftStatus; MachineStates machineStates = machineStateManager.getStates(dockSn);
if ("auto".equalsIgnoreCase(mode) && isPowerOn) { coverState = machineStates.getCoverState();
// mode == "auto" 且开机推测正在执行任务 log.info("机场舱门状态(从MachineStateManager): {}", coverState);
aircraftStatus = "IN_MISSION"; } catch (Exception e) {
log.info("无人机处于 auto 模式且开机,推测状态: IN_MISSION"); log.warn("从MachineStateManager获取舱门状态失败: {}", e.getMessage());
}
} else { } else {
// 其他情况根据开关机状态判断默认舱内 log.warn("机场SN为空无法从MachineStateManager获取舱门状态");
}
// 判断逻辑舱门打开就是任务中
String aircraftStatus;
if (coverState == CoverState.OPENED) {
// 舱门打开表示正在执行任务
aircraftStatus = "IN_MISSION";
log.info("舱门打开,设置状态: IN_MISSION");
} else if (coverState == CoverState.CLOSED) {
// 舱门关闭舱内根据开关机状态判断
if (isPowerOn) { if (isPowerOn) {
aircraftStatus = "POWER_ON_IN_CABIN"; aircraftStatus = "POWER_ON_IN_CABIN";
log.info("开机状态,默认设置: POWER_ON_IN_CABIN"); log.info("舱门关闭 + 开机 → POWER_ON_IN_CABIN");
} else { } else {
aircraftStatus = "POWER_OFF_IN_CABIN"; aircraftStatus = "POWER_OFF_IN_CABIN";
log.info("关机状态,默认设置: POWER_OFF_IN_CABIN"); log.info("舱门关闭 + 关机 → POWER_OFF_IN_CABIN");
}
} else {
// 无法获取舱门状态默认根据开关机状态判断
if (isPowerOn) {
aircraftStatus = "POWER_ON_IN_CABIN";
log.warn("无法获取舱门状态,默认设置: POWER_ON_IN_CABIN");
} else {
aircraftStatus = "POWER_OFF_IN_CABIN";
log.warn("无法获取舱门状态,默认设置: POWER_OFF_IN_CABIN");
} }
} }