This commit is contained in:
parent
ed1489092b
commit
f733eff2ea
|
|
@ -7,6 +7,7 @@ import com.ruoyi.device.domain.api.*;
|
|||
import com.ruoyi.device.domain.model.*;
|
||||
import com.ruoyi.device.domain.model.thingsboard.AttributeMap;
|
||||
import com.ruoyi.device.domain.model.thingsboard.TelemetryMap;
|
||||
import com.ruoyi.device.domain.model.thingsboard.TelemetryValue;
|
||||
import com.ruoyi.device.domain.model.thingsboard.constants.DeviceAttributes;
|
||||
import com.ruoyi.device.domain.model.thingsboard.constants.DeviceTelemetry;
|
||||
import com.ruoyi.device.service.api.IBufferDeviceService;
|
||||
|
|
@ -26,6 +27,7 @@ import org.springframework.util.CollectionUtils;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -493,7 +495,7 @@ public class BufferDeviceImpl implements IBufferDeviceService
|
|||
TelemetryMap telemetryMap = thingsBoardDomain.getPredefinedDeviceTelemetry(aircraftDeviceIotId);
|
||||
|
||||
|
||||
AttributeMap attributeDockMap = thingsBoardDomain.getPredefinedDeviceAttributes(dockDeviceIotId);
|
||||
// AttributeMap attributeDockMap = thingsBoardDomain.getPredefinedDeviceAttributes(dockDeviceIotId);
|
||||
TelemetryMap telemetryDockMap = thingsBoardDomain.getPredefinedDeviceTelemetry(dockDeviceIotId);
|
||||
|
||||
//设置aircraftStatus
|
||||
|
|
@ -503,7 +505,7 @@ public class BufferDeviceImpl implements IBufferDeviceService
|
|||
// 任务中 和 调试, 这两个状态用机场的, 暂时不要用离线状态
|
||||
//
|
||||
|
||||
String aircraftStatus = determineAircraftStatus(attributeMap, telemetryDockMap);
|
||||
String aircraftStatus = determineAircraftStatus(attributeMap, telemetryMap,telemetryDockMap);
|
||||
dto.setAircraftStatus(aircraftStatus);
|
||||
|
||||
// 从 TelemetryMap 中获取 total_flight_sorties 赋予 missionCount
|
||||
|
|
@ -545,7 +547,7 @@ public class BufferDeviceImpl implements IBufferDeviceService
|
|||
* @param telemetryMap 机场 遥测数据映射
|
||||
* @return 无人机状态字符串
|
||||
*/
|
||||
private String determineAircraftStatus(AttributeMap attributeMap, TelemetryMap telemetryMap) {
|
||||
private String determineAircraftStatus(AttributeMap attributeMap,TelemetryMap telemetryAirportMap,TelemetryMap telemetryMap) {
|
||||
// 先检查 MODE_CODE,判断是否处于任务中或调试状态
|
||||
// MODE_CODE 定义: {"0":"待机","1":"起飞准备","2":"起飞准备完毕","3":"手动飞行","4":"自动起飞",
|
||||
// "5":"航线飞行","6":"全景拍照","7":"智能跟随","8":"ADS-B 躲避","9":"自动返航",
|
||||
|
|
@ -571,14 +573,20 @@ public class BufferDeviceImpl implements IBufferDeviceService
|
|||
.map(telemetryValue -> telemetryValue.getValue())
|
||||
.orElse(null);
|
||||
|
||||
// 获取无人机是否开机: {"0":"关机","1":"开机"}
|
||||
Integer deviceOnlineStatus = telemetryMap.get(DeviceTelemetry.Sub_Device_Online_Status)
|
||||
.map(telemetryValue -> telemetryValue.getValue())
|
||||
.orElse(null);
|
||||
// 从机场遥测数据中获取 total_flight_time,根据更新时间判断无人机是否开机
|
||||
// 如果 total_flight_time 在1分钟以内更新,则认为无人机开机,否则关机
|
||||
boolean isPowerOn = false;
|
||||
Optional<TelemetryValue<Integer>> totalFlightTimeOpt = telemetryMap.get(DeviceTelemetry.Total_Flight_Time);
|
||||
if (totalFlightTimeOpt.isPresent()) {
|
||||
long updateTimestamp = totalFlightTimeOpt.get().getTimestamp();
|
||||
long currentTimestamp = System.currentTimeMillis();
|
||||
long timeDiff = currentTimestamp - updateTimestamp;
|
||||
// 1分钟 = 60000 毫秒
|
||||
isPowerOn = timeDiff <= 60000;
|
||||
}
|
||||
|
||||
// 根据舱内/舱外和开机/关机状态确定无人机状态
|
||||
boolean isInCabin = droneInDock != null && droneInDock == 1;
|
||||
boolean isPowerOn = deviceOnlineStatus != null && deviceOnlineStatus == 1;
|
||||
|
||||
if (isInCabin) {
|
||||
// 舱内
|
||||
|
|
|
|||
Loading…
Reference in New Issue