修改 TuohengBufferDeviceImpl 中机场和无人机的状态判断
This commit is contained in:
parent
15fbad2334
commit
a0eb7202ff
|
|
@ -1,6 +1,10 @@
|
|||
package com.ruoyi.device.service.impl;
|
||||
|
||||
import com.ruoyi.device.domain.api.*;
|
||||
import com.ruoyi.device.domain.impl.machine.state.CoverState;
|
||||
import com.ruoyi.device.domain.impl.machine.state.DroneState;
|
||||
import com.ruoyi.device.domain.impl.machine.state.MachineStates;
|
||||
import com.ruoyi.device.domain.impl.machine.statemachine.MachineStateManager;
|
||||
import com.ruoyi.device.domain.model.*;
|
||||
import com.ruoyi.device.domain.model.thingsboard.AttributeMap;
|
||||
import com.ruoyi.device.domain.model.thingsboard.TelemetryMap;
|
||||
|
|
@ -51,6 +55,9 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
@Autowired
|
||||
private IThingsBoardDomain thingsBoardDomain;
|
||||
|
||||
@Autowired
|
||||
private MachineStateManager machineStateManager;
|
||||
|
||||
@Override
|
||||
public DockDetailDTO getDockDetailById(Long dockId) {
|
||||
log.info("获取拓恒机场详情: dockId={}", dockId);
|
||||
|
|
@ -145,8 +152,23 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
dto.setBindTime(device.getCreateTime().getTime());
|
||||
dto.setAircraftManufacturer(device.getDeviceManufacturer());
|
||||
|
||||
// 获取ThingsBoard数据并填充到DTO
|
||||
fillTuohengAircraftDetail(dto, device.getIotDeviceId());
|
||||
// 查询无人机关联的机场,获取机场SN(用于从MachineStateManager获取状态)
|
||||
// String dockSn = null;
|
||||
// List<DockAircraft> dockAircrafts = dockAircraftDomain.selectDockAircraftByAircraftId(aircraftId);
|
||||
// if (!CollectionUtils.isEmpty(dockAircrafts)) {
|
||||
// DockAircraft dockAircraft = dockAircrafts.get(0);
|
||||
// Dock dock = dockDomain.selectDockByDockId(dockAircraft.getDockId());
|
||||
// if (dock != null) {
|
||||
// Device dockDevice = deviceDomain.selectDeviceByDeviceId(dock.getDeviceId());
|
||||
// if (dockDevice != null) {
|
||||
// dockSn = dockDevice.getDeviceSn();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 获取ThingsBoard数据并填充到DTO(传入机场SN用于获取状态)
|
||||
// 这边的SN号是通用的
|
||||
fillTuohengAircraftDetail(dto, device.getIotDeviceId(), device.getDeviceSn());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
|
@ -307,23 +329,31 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
|
||||
log.info("无人机MODE值: {}", mode);
|
||||
|
||||
// 获取舱门状态(从机场遥测数据中获取)
|
||||
Integer doorStatus = telemetry.get(TuohengDeviceTelemetry.NEST_DOOR_STATUS)
|
||||
.map(TelemetryValue::getValue)
|
||||
.orElse(null);
|
||||
log.info("机场舱门状态: {}", doorStatus);
|
||||
// 通过 MachineStateManager 获取舱门状态;只通过舱门状态判断是否作业
|
||||
MachineStates machineStates =
|
||||
machineStateManager.getStates(dto.getSnNumber());
|
||||
CoverState coverState =
|
||||
machineStates.getCoverState();
|
||||
log.info("机场舱门状态(从MachineStateManager): {}", coverState);
|
||||
|
||||
// WORKING状态需要同时满足:mode=="auto" 且舱门打开(doorStatus==0)
|
||||
if ("auto".equalsIgnoreCase(mode) && doorStatus != null && doorStatus == 0) {
|
||||
dockStatus = "WORKING"; // auto模式且舱门打开表示正在执行任务
|
||||
if(coverState == CoverState.OPENED){
|
||||
dockStatus = "WORKING"; //只通过舱门状态判断是否作业
|
||||
log.info("无人机处于auto模式且舱门打开,设置机场状态为 WORKING");
|
||||
} else {
|
||||
if ("auto".equalsIgnoreCase(mode) && (doorStatus == null || doorStatus != 0)) {
|
||||
log.info("无人机处于auto模式但舱门未打开(doorStatus={}), 设置机场状态为 IDLE", doorStatus);
|
||||
} else {
|
||||
log.info("无人机处于{}模式,设置机场状态为 IDLE", mode);
|
||||
}
|
||||
}
|
||||
//
|
||||
// // WORKING状态需要同时满足:mode=="auto" 且舱门打开
|
||||
// if ("auto".equalsIgnoreCase(mode) &&
|
||||
// coverState == CoverState.OPENED) {
|
||||
// dockStatus = "WORKING"; // auto模式且舱门打开表示正在执行任务
|
||||
// log.info("无人机处于auto模式且舱门打开,设置机场状态为 WORKING");
|
||||
// } else {
|
||||
// if ("auto".equalsIgnoreCase(mode) &&
|
||||
// coverState != CoverState.OPENED) {
|
||||
// log.info("无人机处于auto模式但舱门未打开(coverState={}), 设置机场状态为 IDLE", coverState);
|
||||
// } else {
|
||||
// log.info("无人机处于{}模式,设置机场状态为 IDLE", mode);
|
||||
// }
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
log.warn("获取无人机mode或舱门状态失败,默认设置为IDLE: {}", e.getMessage());
|
||||
}
|
||||
|
|
@ -352,17 +382,34 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
dto.setCabinHumidity(value.getValue());
|
||||
});
|
||||
|
||||
/**
|
||||
* 通过 MachineStateManager 获取舱门状态
|
||||
*/
|
||||
|
||||
// 设置舱门状态
|
||||
log.info("---------- 解析舱门状态 ----------");
|
||||
telemetry.get(TuohengDeviceTelemetry.NEST_DOOR_STATUS)
|
||||
.ifPresent(value -> {
|
||||
Integer doorStatus = value.getValue();
|
||||
log.info("NEST_DOOR_STATUS 舱门状态原始值: {}", doorStatus);
|
||||
// 0=打开, 1=关闭
|
||||
String cabinDoorStatus = (doorStatus != null && doorStatus == 0) ? "OPEN" : "CLOSED";
|
||||
dto.setCabinDoorStatus(cabinDoorStatus);
|
||||
log.info("设置舱门状态: {}", cabinDoorStatus);
|
||||
});
|
||||
try {
|
||||
MachineStates machineStates =
|
||||
machineStateManager.getStates(dto.getSnNumber());
|
||||
CoverState coverState =
|
||||
machineStates.getCoverState();
|
||||
log.info("舱门状态(从MachineStateManager): {}", coverState);
|
||||
|
||||
String cabinDoorStatus;
|
||||
if (coverState == CoverState.OPENED) {
|
||||
cabinDoorStatus = "OPEN";
|
||||
} else if (coverState == CoverState.CLOSED) {
|
||||
cabinDoorStatus = "CLOSED";
|
||||
} else {
|
||||
cabinDoorStatus = "UNKNOWN";
|
||||
}
|
||||
dto.setCabinDoorStatus(cabinDoorStatus);
|
||||
log.info("设置舱门状态: {}", cabinDoorStatus);
|
||||
} catch (Exception e) {
|
||||
log.warn("从MachineStateManager获取舱门状态失败: {}", e.getMessage());
|
||||
dto.setCabinDoorStatus("UNKNOWN");
|
||||
}
|
||||
|
||||
|
||||
// 设置空调状态(从属性中获取 airConditionerStatus,取不到则默认为 IDLE)
|
||||
log.info("---------- 解析空调状态 ----------");
|
||||
|
|
@ -513,59 +560,54 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
.orElse("");
|
||||
log.info("无人机 MODE 值: {}", mode);
|
||||
|
||||
// 获取 tsingal(图传信号强度,用于判断开关机)
|
||||
Integer tsingal = aircraftTelemetry.get(TuohengDeviceTelemetry.TSINGAL)
|
||||
.map(TelemetryValue::getValue)
|
||||
.orElse(0);
|
||||
log.info("无人机 TSINGAL 值: {}", tsingal);
|
||||
|
||||
boolean isPowerOn = tsingal > 60; // tsingal > 60 表示开机
|
||||
log.info("无人机开关机状态: {}", isPowerOn ? "开机" : "关机");
|
||||
|
||||
// 获取 nest_door_status(舱门状态)
|
||||
Integer doorStatus = null;
|
||||
if (dockTelemetry != null) {
|
||||
doorStatus = dockTelemetry.get(TuohengDeviceTelemetry.NEST_DOOR_STATUS)
|
||||
.map(TelemetryValue::getValue)
|
||||
.orElse(null);
|
||||
log.info("机场舱门状态: {}", doorStatus);
|
||||
// 通过 MachineStateManager 获取舱门状态(使用机场SN)
|
||||
CoverState coverState = null;
|
||||
try {
|
||||
MachineStates machineStates =
|
||||
machineStateManager.getStates(dto.getSnNumber());
|
||||
coverState = machineStates.getCoverState();
|
||||
log.info("机场舱门状态(从MachineStateManager): {}", coverState);
|
||||
} catch (Exception e) {
|
||||
log.warn("从MachineStateManager获取舱门状态失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
// 判断逻辑:IN_MISSION 需要同时满足 mode=="auto" 且舱门打开
|
||||
// 从 MachineStateManager 获取无人机开关机状态
|
||||
DroneState droneState = null;
|
||||
try {
|
||||
MachineStates machineStates =
|
||||
machineStateManager.getStates(dto.getSnNumber());
|
||||
droneState = machineStates.getDroneState();
|
||||
log.info("无人机状态(从MachineStateManager): {}", droneState);
|
||||
} catch (Exception e) {
|
||||
log.warn("从MachineStateManager获取无人机状态失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
boolean isPowerOn = (droneState != null && droneState != DroneState.POWER_OFF && droneState != DroneState.UNKNOWN);
|
||||
log.info("无人机开关机状态: {}", isPowerOn ? "开机" : "关机");
|
||||
|
||||
// 判断逻辑:舱门打开就是任务中
|
||||
String aircraftStatus;
|
||||
if ("auto".equalsIgnoreCase(mode) && doorStatus != null && doorStatus == 0) {
|
||||
// mode == "auto" 且舱门打开,表示正在执行任务
|
||||
if (coverState == CoverState.OPENED) {
|
||||
// 舱门打开,表示正在执行任务
|
||||
aircraftStatus = "IN_MISSION";
|
||||
log.info("无人机处于 auto 模式且舱门打开,设置状态: IN_MISSION");
|
||||
} else {
|
||||
// 其他情况,根据 tsingal 和 nest_door_status 判断
|
||||
if (doorStatus != null && doorStatus == 1) {
|
||||
// 舱门关闭(舱内)
|
||||
if (isPowerOn) {
|
||||
aircraftStatus = "POWER_ON_IN_CABIN";
|
||||
log.info("舱门关闭 + 开机 → POWER_ON_IN_CABIN");
|
||||
} else {
|
||||
aircraftStatus = "POWER_OFF_IN_CABIN";
|
||||
log.info("舱门关闭 + 关机 → POWER_OFF_IN_CABIN");
|
||||
}
|
||||
} else if (doorStatus != null && doorStatus == 0) {
|
||||
// 舱门打开(舱外),但不是 auto 模式
|
||||
if (isPowerOn) {
|
||||
aircraftStatus = "POWER_ON_OUT_CABIN";
|
||||
log.info("舱门打开 + 开机(非auto模式) → POWER_ON_OUT_CABIN");
|
||||
} else {
|
||||
aircraftStatus = "POWER_OFF_OUT_CABIN";
|
||||
log.info("舱门打开 + 关机 → POWER_OFF_OUT_CABIN");
|
||||
}
|
||||
log.info("舱门打开,设置状态: IN_MISSION");
|
||||
} else if (coverState == CoverState.CLOSED) {
|
||||
// 舱门关闭(舱内),根据开关机状态判断
|
||||
if (isPowerOn) {
|
||||
aircraftStatus = "POWER_ON_IN_CABIN";
|
||||
log.info("舱门关闭 + 开机 → POWER_ON_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");
|
||||
}
|
||||
aircraftStatus = "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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -585,8 +627,9 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
*
|
||||
* @param dto 无人机详情DTO
|
||||
* @param iotDeviceId ThingsBoard设备ID
|
||||
* @param dockSn 机场SN号(用于从MachineStateManager获取状态)
|
||||
*/
|
||||
private void fillTuohengAircraftDetail(AircraftDetailDTO dto, String iotDeviceId) {
|
||||
private void fillTuohengAircraftDetail(AircraftDetailDTO dto, String iotDeviceId, String dockSn) {
|
||||
try {
|
||||
log.info("========== 开始填充拓恒无人机详情 ==========");
|
||||
log.info("iotDeviceId: {}", iotDeviceId);
|
||||
|
|
@ -614,7 +657,21 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
.orElse(0);
|
||||
log.info("无人机 TSINGAL 值: {}", tsingal);
|
||||
|
||||
boolean isPowerOn = tsingal > 60; // tsingal > 60 表示开机
|
||||
// 从 MachineStateManager 获取无人机开关机状态
|
||||
DroneState droneState = null;
|
||||
if (dockSn != null) {
|
||||
try {
|
||||
MachineStates machineStates = machineStateManager.getStates(dockSn);
|
||||
droneState = machineStates.getDroneState();
|
||||
log.info("无人机状态(从MachineStateManager): {}", droneState);
|
||||
} catch (Exception e) {
|
||||
log.warn("从MachineStateManager获取无人机状态失败: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.warn("机场SN为空,无法从MachineStateManager获取无人机状态");
|
||||
}
|
||||
|
||||
boolean isPowerOn = (droneState != null && droneState != DroneState.POWER_OFF && droneState != DroneState.UNKNOWN);
|
||||
log.info("无人机开关机状态: {}", isPowerOn ? "开机" : "关机");
|
||||
|
||||
// 判断逻辑
|
||||
|
|
|
|||
Loading…
Reference in New Issue