feat: 3d控制指令
This commit is contained in:
@@ -56,7 +56,9 @@
|
|||||||
"Bash(cmd /c \"dir /s /b \"\"D:\\模型\\新建模型重建-2025-09-29 20_24_08 (UTC+08)\\model\\download\"\"\")",
|
"Bash(cmd /c \"dir /s /b \"\"D:\\模型\\新建模型重建-2025-09-29 20_24_08 (UTC+08)\\model\\download\"\"\")",
|
||||||
"Bash(cmd /c \"dir \"\"D:\\模型\\新建模型重建-2025-09-29 20_24_08 (UTC+08)\\model\\download\"\"\")",
|
"Bash(cmd /c \"dir \"\"D:\\模型\\新建模型重建-2025-09-29 20_24_08 (UTC+08)\\model\\download\"\"\")",
|
||||||
"Bash(del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\websocket\\config\\DeviceControlWebSocketConfig.java\")",
|
"Bash(del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\websocket\\config\\DeviceControlWebSocketConfig.java\")",
|
||||||
"Bash(del \"F:\\project\\go-fly-platform-services\\zlt-web\\react-web-next\\src\\services\\deviceControlWs.ts\")"
|
"Bash(del \"F:\\project\\go-fly-platform-services\\zlt-web\\react-web-next\\src\\services\\deviceControlWs.ts\")",
|
||||||
|
"Bash(del:*)",
|
||||||
|
"Bash(cmd /c del \"F:\\project\\go-fly-platform-services\\zlt-business\\device-center\\src\\main\\java\\com\\central\\device\\controller\\CdnProxyController.java\")"
|
||||||
],
|
],
|
||||||
"deny": [],
|
"deny": [],
|
||||||
"ask": []
|
"ask": []
|
||||||
|
|||||||
@@ -123,3 +123,6 @@ AFTER `terrain_type`;
|
|||||||
ALTER TABLE `3d_model_file`
|
ALTER TABLE `3d_model_file`
|
||||||
ADD COLUMN `arcgis_height` DECIMAL(10,2) DEFAULT NULL COMMENT 'ArcGIS地形对应的高度偏移(米)'
|
ADD COLUMN `arcgis_height` DECIMAL(10,2) DEFAULT NULL COMMENT 'ArcGIS地形对应的高度偏移(米)'
|
||||||
AFTER `cesium_height`;
|
AFTER `cesium_height`;
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE manage_device ADD COLUMN video_stream_url VARCHAR(500) COMMENT '视频流地 址(WHEP URL)';
|
||||||
|
|||||||
@@ -46,4 +46,8 @@ public class AgeDevice extends SuperEntity {
|
|||||||
private String urlNormal;
|
private String urlNormal;
|
||||||
private String urlSelect;
|
private String urlSelect;
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
/**
|
||||||
|
* 视频流地址(完整WHEP URL,如:http://220.205.16.27:8024/rtc/v1/whep/?app=live&stream=49214ac552fa)
|
||||||
|
*/
|
||||||
|
private String videoStreamUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
+73
@@ -150,4 +150,77 @@ public class DeviceStatusSseController {
|
|||||||
return org.springframework.http.ResponseEntity.badRequest().body("取消订阅失败: " + e.getMessage());
|
return org.springframework.http.ResponseEntity.badRequest().body("取消订阅失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订阅无人机遥测数据SSE连接(独立连接)
|
||||||
|
* 前端建立独立的SSE连接,专门接收无人机遥测数据(msg_alarm)
|
||||||
|
* 与机库状态数据(fire_alarm)完全分离,互不干扰
|
||||||
|
*
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param clientSessionId 客户端会话ID(可选,从请求头获取,用于连接复用和清理)
|
||||||
|
* @return SSE连接
|
||||||
|
*/
|
||||||
|
@Operation(summary = "订阅无人机遥测数据SSE连接(独立连接)")
|
||||||
|
@GetMapping(value = "/drone-telemetry/{deviceSn}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
|
public org.springframework.http.ResponseEntity<SseEmitter> subscribeDroneTelemetrySse(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@PathVariable String deviceSn,
|
||||||
|
@Parameter(description = "客户端会话ID(可选)")
|
||||||
|
@RequestHeader(value = "X-Client-Session-Id", required = false) String clientSessionId) {
|
||||||
|
|
||||||
|
String tenantId = LoginUserContextHolder.getCurrentTenantId() != null ? LoginUserContextHolder.getCurrentTenantId() : "1";
|
||||||
|
String username = LoginUserContextHolder.getUser() != null ? LoginUserContextHolder.getUser().getUsername() : "anonymous";
|
||||||
|
|
||||||
|
// 生成sessionId:如果前端提供了clientSessionId,则使用它;否则生成UUID
|
||||||
|
String sessionId;
|
||||||
|
if (clientSessionId != null && !clientSessionId.trim().isEmpty()) {
|
||||||
|
sessionId = "drone_" + clientSessionId + "_" + deviceSn;
|
||||||
|
log.info("客户端订阅无人机遥测数据SSE(复用会话): session={}, deviceSn={}, tenant={}, user={}",
|
||||||
|
sessionId, deviceSn, tenantId, username);
|
||||||
|
} else {
|
||||||
|
sessionId = "drone_" + java.util.UUID.randomUUID().toString() + "_" + deviceSn;
|
||||||
|
log.info("客户端订阅无人机遥测数据SSE(新会话): session={}, deviceSn={}, tenant={}, user={}",
|
||||||
|
sessionId, deviceSn, tenantId, username);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加SSE连接(内部会触发WebSocket懒加载和设备订阅)
|
||||||
|
// 如果同sessionId已存在连接,会自动断开旧连接
|
||||||
|
SseEmitter emitter = sseEmitterManager.addDroneTelemetryEmitter(sessionId, deviceSn, tenantId);
|
||||||
|
|
||||||
|
// 设置响应头,禁用缓冲
|
||||||
|
return org.springframework.http.ResponseEntity.ok()
|
||||||
|
.header("Cache-Control", "no-cache, no-transform")
|
||||||
|
.header("Connection", "keep-alive")
|
||||||
|
.header("X-Accel-Buffering", "no")
|
||||||
|
.contentType(org.springframework.http.MediaType.TEXT_EVENT_STREAM)
|
||||||
|
.body(emitter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主动断开无人机遥测数据SSE连接
|
||||||
|
* 前端页面卸载时调用,确保后端资源及时释放
|
||||||
|
*
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param clientSessionId 客户端会话ID(必需)
|
||||||
|
* @return 断开结果
|
||||||
|
*/
|
||||||
|
@Operation(summary = "主动断开无人机遥测数据SSE连接")
|
||||||
|
@DeleteMapping("/drone-telemetry/{deviceSn}")
|
||||||
|
public org.springframework.http.ResponseEntity<String> disconnectDroneTelemetrySse(
|
||||||
|
@Parameter(description = "设备SN", required = true)
|
||||||
|
@PathVariable String deviceSn,
|
||||||
|
@Parameter(description = "客户端会话ID", required = true)
|
||||||
|
@RequestHeader(value = "X-Client-Session-Id") String clientSessionId) {
|
||||||
|
|
||||||
|
String sessionId = "drone_" + clientSessionId + "_" + deviceSn;
|
||||||
|
log.info("客户端主动断开无人机遥测数据SSE连接: session={}, deviceSn={}", sessionId, deviceSn);
|
||||||
|
|
||||||
|
boolean success = sseEmitterManager.removeEmitterBySessionId(sessionId, deviceSn);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
return org.springframework.http.ResponseEntity.ok("无人机遥测数据连接已断开");
|
||||||
|
} else {
|
||||||
|
return org.springframework.http.ResponseEntity.ok("连接不存在或已断开");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+203
-22
@@ -5,6 +5,7 @@ import com.central.device.sse.model.EmitterWrapper;
|
|||||||
import com.central.device.websocket.handler.DeviceMessageHandler;
|
import com.central.device.websocket.handler.DeviceMessageHandler;
|
||||||
import com.central.device.websocket.manager.DeviceSubscriptionManager;
|
import com.central.device.websocket.manager.DeviceSubscriptionManager;
|
||||||
import com.central.device.websocket.model.DeviceRealtimeData;
|
import com.central.device.websocket.model.DeviceRealtimeData;
|
||||||
|
import com.central.device.websocket.model.DroneRealtimeData;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -27,7 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* 2. WebSocket懒加载:只有前端调用时才连接
|
* 2. WebSocket懒加载:只有前端调用时才连接
|
||||||
* 3. 引用计数:支持多个客户端订阅同一设备
|
* 3. 引用计数:支持多个客户端订阅同一设备
|
||||||
*
|
*
|
||||||
* @author lishilin
|
* @author dzc
|
||||||
* @date 2025-01-19
|
* @date 2025-01-19
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -105,8 +106,8 @@ public class SseEmitterManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 保存连接(使用deviceSn作为scenicId字段,保持兼容性)
|
// 保存连接(使用deviceSn作为scenicId字段,保持兼容性)
|
||||||
EmitterWrapper wrapper = new EmitterWrapper(emitter, 0L, tenantId, sessionId,deviceSn);
|
EmitterWrapper wrapper = new EmitterWrapper(emitter, 0L, tenantId, sessionId, deviceSn);
|
||||||
wrapper.setDeviceSn(deviceSn); // 扩展字段
|
wrapper.setIsDroneTelemetry(false); // 标记为机库状态数据连接
|
||||||
emitters.put(sessionId, wrapper);
|
emitters.put(sessionId, wrapper);
|
||||||
|
|
||||||
log.info("新增SSE连接: session={}, deviceSn={}, tenant={}, 当前连接数: {}",
|
log.info("新增SSE连接: session={}, deviceSn={}, tenant={}, 当前连接数: {}",
|
||||||
@@ -155,6 +156,9 @@ public class SseEmitterManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 记录连接类型(无人机还是机库)
|
||||||
|
boolean isDroneTelemetry = wrapper.getIsDroneTelemetry() != null && wrapper.getIsDroneTelemetry();
|
||||||
|
|
||||||
// 尝试完成emitter(优雅关闭)
|
// 尝试完成emitter(优雅关闭)
|
||||||
try {
|
try {
|
||||||
wrapper.getEmitter().complete();
|
wrapper.getEmitter().complete();
|
||||||
@@ -162,8 +166,15 @@ public class SseEmitterManager {
|
|||||||
log.debug("完成SSE连接失败(可能已关闭): session={}, error={}", sessionId, e.getMessage());
|
log.debug("完成SSE连接失败(可能已关闭): session={}, error={}", sessionId, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("移除SSE连接: session={}, deviceSn={}, 剩余连接数: {}",
|
log.info("移除SSE连接: session={}, deviceSn={}, isDroneTelemetry={}, 剩余连接数: {}",
|
||||||
sessionId, deviceSn, emitters.size());
|
sessionId, deviceSn, isDroneTelemetry, emitters.size());
|
||||||
|
|
||||||
|
// 【关键】如果是无人机SSE连接,需要先取消 msg_alarm 订阅
|
||||||
|
// 无论引用计数是否归零,都要取消无人机遥测数据订阅
|
||||||
|
if (isDroneTelemetry) {
|
||||||
|
log.info("无人机SSE连接断开,取消 msg_alarm 订阅: deviceSn={}", deviceSn);
|
||||||
|
deviceSubscriptionManager.unsubscribeDroneTelemetry(deviceSn);
|
||||||
|
}
|
||||||
|
|
||||||
// 减少设备引用计数
|
// 减少设备引用计数
|
||||||
Integer refCount = deviceRefCount.compute(deviceSn, (k, v) -> {
|
Integer refCount = deviceRefCount.compute(deviceSn, (k, v) -> {
|
||||||
@@ -173,9 +184,9 @@ public class SseEmitterManager {
|
|||||||
return v - 1;
|
return v - 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 关键:如果引用计数归零,取消设备订阅
|
// 关键:如果引用计数归零,取消所有设备订阅(机库订阅)
|
||||||
if (refCount == null) {
|
if (refCount == null) {
|
||||||
log.info("设备 {} 引用计数归零,取消订阅", deviceSn);
|
log.info("设备 {} 引用计数归零,取消所有订阅", deviceSn);
|
||||||
deviceSubscriptionManager.unsubscribeDevice(deviceSn);
|
deviceSubscriptionManager.unsubscribeDevice(deviceSn);
|
||||||
} else {
|
} else {
|
||||||
log.info("设备 {} 仍有 {} 个订阅,保持连接", deviceSn, refCount);
|
log.info("设备 {} 仍有 {} 个订阅,保持连接", deviceSn, refCount);
|
||||||
@@ -201,9 +212,10 @@ public class SseEmitterManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送设备数据更新(只推送给订阅该设备的连接)
|
* 推送设备数据更新(只推送给订阅该设备的连接)
|
||||||
|
* 注意:这个方法推送机库数据
|
||||||
*
|
*
|
||||||
* @param deviceSn 设备SN
|
* @param deviceSn 设备SN
|
||||||
* @param data 设备实时数据
|
* @param data 设备实时数据(机库数据)
|
||||||
*/
|
*/
|
||||||
public void sendDeviceDataUpdate(String deviceSn, DeviceRealtimeData data) {
|
public void sendDeviceDataUpdate(String deviceSn, DeviceRealtimeData data) {
|
||||||
DeviceRealtimeDataDTO dto = convertToDTO(data);
|
DeviceRealtimeDataDTO dto = convertToDTO(data);
|
||||||
@@ -213,35 +225,29 @@ public class SseEmitterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送给指定设备的所有连接
|
* 发送给指定设备的机库SSE连接(不包括无人机SSE连接)
|
||||||
|
* 只推送给 isDroneTelemetry = false 的连接
|
||||||
*/
|
*/
|
||||||
private void sendToDevice(String deviceSn, String eventName, Object data) {
|
private void sendToDevice(String deviceSn, String eventName, Object data) {
|
||||||
List<String> deadEmitters = new ArrayList<>();
|
List<String> deadEmitters = new ArrayList<>();
|
||||||
|
|
||||||
// log.info("准备推送到设备: deviceSn={}, 当前所有连接数: {}", deviceSn, emitters.size());
|
// 找到匹配的机库连接(排除无人机连接)
|
||||||
|
|
||||||
// 打印所有连接的 deviceSn,用于调试
|
|
||||||
emitters.values().forEach(wrapper -> {
|
|
||||||
log.info(" 连接详情: session={}, deviceSn={}", wrapper.getSessionId(), wrapper.getDeviceSn());
|
|
||||||
});
|
|
||||||
|
|
||||||
// 找到匹配的连接
|
|
||||||
List<EmitterWrapper> matchingEmitters = emitters.values().stream()
|
List<EmitterWrapper> matchingEmitters = emitters.values().stream()
|
||||||
.filter(wrapper -> {
|
.filter(wrapper -> {
|
||||||
boolean match = deviceSn.equals(wrapper.getDeviceSn());
|
boolean matchDevice = deviceSn.equals(wrapper.getDeviceSn());
|
||||||
return match;
|
// 【关键】只推送给机库连接,排除无人机连接
|
||||||
|
boolean isDeviceConnection = wrapper.getIsDroneTelemetry() == null || !wrapper.getIsDroneTelemetry();
|
||||||
|
return matchDevice && isDeviceConnection;
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
log.info("找到 {} 个匹配设备 {} 的SSE连接", matchingEmitters.size(), deviceSn);
|
log.debug("推送机库数据到设备 {} 的 {} 个SSE连接", deviceSn, matchingEmitters.size());
|
||||||
|
|
||||||
matchingEmitters.forEach(wrapper -> {
|
matchingEmitters.forEach(wrapper -> {
|
||||||
try {
|
try {
|
||||||
wrapper.getEmitter().send(SseEmitter.event()
|
wrapper.getEmitter().send(SseEmitter.event()
|
||||||
.name(eventName)
|
.name(eventName)
|
||||||
.data(data));
|
.data(data));
|
||||||
log.info("✅ SSE推送成功: session={}, event={}, deviceSn={} , data={}",
|
|
||||||
wrapper.getSessionId(), eventName, deviceSn, data);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("❌ SSE推送失败: session={}, event={}, error={}",
|
log.error("❌ SSE推送失败: session={}, event={}, error={}",
|
||||||
wrapper.getSessionId(), eventName, e.getMessage());
|
wrapper.getSessionId(), eventName, e.getMessage());
|
||||||
@@ -349,4 +355,179 @@ public class SseEmitterManager {
|
|||||||
log.info("取消订阅无人机遥测数据: deviceSn={}", deviceSn);
|
log.info("取消订阅无人机遥测数据: deviceSn={}", deviceSn);
|
||||||
deviceSubscriptionManager.unsubscribeDroneTelemetry(deviceSn);
|
deviceSubscriptionManager.unsubscribeDroneTelemetry(deviceSn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加无人机遥测数据SSE连接(独立连接)
|
||||||
|
* 专门用于接收无人机遥测数据(msg_alarm),与机库状态数据完全分离
|
||||||
|
*
|
||||||
|
* @param sessionId 会话ID(含设备SN)
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param tenantId 租户ID
|
||||||
|
* @return SSE Emitter
|
||||||
|
*/
|
||||||
|
public SseEmitter addDroneTelemetryEmitter(String sessionId, String deviceSn, String tenantId) {
|
||||||
|
// 检查是否已存在相同sessionId的连接,如果存在则先移除(避免重复连接)
|
||||||
|
if (emitters.containsKey(sessionId)) {
|
||||||
|
log.warn("检测到重复的无人机SSE连接,sessionId={},先移除旧连接", sessionId);
|
||||||
|
removeEmitter(sessionId, deviceSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建SseEmitter(超时时间5分钟,避免僵尸连接)
|
||||||
|
long timeoutMs = 5 * 60 * 1000L; // 5分钟
|
||||||
|
SseEmitter emitter = new SseEmitter(timeoutMs);
|
||||||
|
|
||||||
|
// 设置回调
|
||||||
|
emitter.onCompletion(() -> {
|
||||||
|
log.info("无人机SSE连接完成: session={}, deviceSn={}", sessionId, deviceSn);
|
||||||
|
removeEmitter(sessionId, deviceSn);
|
||||||
|
});
|
||||||
|
|
||||||
|
emitter.onTimeout(() -> {
|
||||||
|
log.warn("无人机SSE连接超时: session={}, deviceSn={}", sessionId, deviceSn);
|
||||||
|
removeEmitter(sessionId, deviceSn);
|
||||||
|
});
|
||||||
|
|
||||||
|
emitter.onError((ex) -> {
|
||||||
|
log.error("无人机SSE连接错误: session={}, deviceSn={}, error={}",
|
||||||
|
sessionId, deviceSn, ex.getMessage());
|
||||||
|
removeEmitter(sessionId, deviceSn);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 保存连接
|
||||||
|
EmitterWrapper wrapper = new EmitterWrapper(emitter, 0L, tenantId, sessionId, deviceSn);
|
||||||
|
wrapper.setDeviceSn(deviceSn);
|
||||||
|
wrapper.setIsDroneTelemetry(true); // 标记为无人机遥测数据连接
|
||||||
|
emitters.put(sessionId, wrapper);
|
||||||
|
|
||||||
|
log.info("新增无人机SSE连接: session={}, deviceSn={}, isDroneTelemetry={}, tenant={}, 当前连接数: {}",
|
||||||
|
sessionId, deviceSn, wrapper.getIsDroneTelemetry(), tenantId, emitters.size());
|
||||||
|
|
||||||
|
// 立即发送连接确认消息,激活SSE流
|
||||||
|
try {
|
||||||
|
emitter.send(SseEmitter.event()
|
||||||
|
.name("connected")
|
||||||
|
.data("无人机SSE连接已建立"));
|
||||||
|
log.info("发送无人机连接确认消息成功: session={}", sessionId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送无人机连接确认消息失败: session={}, error={}", sessionId, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加设备引用计数(无人机专用)
|
||||||
|
int refCount = deviceRefCount.compute(deviceSn, (k, v) -> v == null ? 1 : v + 1);
|
||||||
|
|
||||||
|
// 【关键修复】无论引用计数是多少,都需要订阅无人机遥测数据(msg_alarm)
|
||||||
|
// 因为机库订阅(addEmitter)只订阅了 fire_alarm,不包括 msg_alarm
|
||||||
|
// 所以这里需要额外订阅 msg_alarm 主题
|
||||||
|
log.info("设备 {} 订阅无人机遥测数据,当前引用计数: {}", deviceSn, refCount);
|
||||||
|
|
||||||
|
// 如果是首次订阅该设备(refCount == 1),需要先订阅基础主题
|
||||||
|
if (refCount == 1) {
|
||||||
|
log.info("设备 {} 首次订阅,触发WebSocket懒加载并订阅基础主题", deviceSn);
|
||||||
|
deviceSubscriptionManager.subscribeDevice(deviceSn, tenantId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 无论如何都要订阅无人机遥测数据主题(msg_alarm)
|
||||||
|
// 这是独立于机库订阅的,需要单独调用
|
||||||
|
log.info("设备 {} 订阅无人机遥测主题 msg_alarm", deviceSn);
|
||||||
|
deviceSubscriptionManager.subscribeDroneTelemetry(deviceSn);
|
||||||
|
|
||||||
|
// 立即推送一次当前无人机数据(如果存在)
|
||||||
|
com.central.device.websocket.model.DeviceRealtimeData currentData = messageHandler.getDeviceData(deviceSn);
|
||||||
|
if (currentData != null && currentData.getRawData() != null && currentData.getRawData().get("droneData") != null) {
|
||||||
|
log.info("推送设备 {} 的当前无人机数据到新连接", deviceSn);
|
||||||
|
// 注意:这里应该推送无人机数据,而不是机库数据
|
||||||
|
// 但由于我们刚刚修改了 handleMsgAlarmEvent 不再更新 DeviceRealtimeData
|
||||||
|
// 所以这里可能不会有 droneData 了
|
||||||
|
// 等待新的无人机消息到来
|
||||||
|
} else {
|
||||||
|
log.info("设备 {} 暂无无人机缓存数据,等待WebSocket消息", deviceSn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return emitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送无人机数据更新到所有订阅该设备的无人机SSE连接(新版本,使用 DroneRealtimeData)
|
||||||
|
* 只发送给标记为无人机遥测数据的连接
|
||||||
|
*
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param data 无人机实时数据
|
||||||
|
*/
|
||||||
|
public void sendDroneDataUpdate(String deviceSn, DroneRealtimeData data) {
|
||||||
|
if (data == null || data.getRawData() == null) {
|
||||||
|
log.warn("无人机数据为空,跳过推送: deviceSn={}", deviceSn);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 统计无人机SSE连接数
|
||||||
|
long droneConnectionCount = emitters.values().stream()
|
||||||
|
.filter(w -> deviceSn.equals(w.getDeviceSn()) && Boolean.TRUE.equals(w.getIsDroneTelemetry()))
|
||||||
|
.count();
|
||||||
|
|
||||||
|
log.info("【无人机数据推送】deviceSn={}, 无人机SSE连接数={}, 总连接数={}",
|
||||||
|
deviceSn, droneConnectionCount, emitters.size());
|
||||||
|
|
||||||
|
if (droneConnectionCount == 0) {
|
||||||
|
log.warn("【无人机数据推送】没有找到无人机SSE连接: deviceSn={}", deviceSn);
|
||||||
|
// 打印所有连接的详情
|
||||||
|
emitters.forEach((sid, w) -> {
|
||||||
|
log.info(" 连接详情: session={}, deviceSn={}, isDroneTelemetry={}",
|
||||||
|
sid, w.getDeviceSn(), w.getIsDroneTelemetry());
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只查找标记为无人机遥测数据的连接
|
||||||
|
emitters.forEach((sessionId, wrapper) -> {
|
||||||
|
if (deviceSn.equals(wrapper.getDeviceSn()) && Boolean.TRUE.equals(wrapper.getIsDroneTelemetry())) {
|
||||||
|
try {
|
||||||
|
// 创建专门用于无人机数据的事件
|
||||||
|
SseEmitter.SseEventBuilder event = SseEmitter.event()
|
||||||
|
.name("drone-data-update")
|
||||||
|
.data(data.toFrontendJson()) // 推送前端兼容的JSON
|
||||||
|
.id("drone-" + System.currentTimeMillis());
|
||||||
|
|
||||||
|
wrapper.getEmitter().send(event);
|
||||||
|
log.info("✅ 发送无人机数据更新成功: session={}, deviceSn={}", sessionId, deviceSn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("发送无人机数据更新失败,连接可能已关闭: session={}, deviceSn={}, error={}",
|
||||||
|
sessionId, deviceSn, e.getMessage());
|
||||||
|
// 不立即移除,等待心跳检测或回调处理
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送无人机数据更新到所有订阅该设备的无人机SSE连接(旧版本,保持兼容)
|
||||||
|
* 只发送给标记为无人机遥测数据的连接
|
||||||
|
*
|
||||||
|
* @param deviceSn 设备SN
|
||||||
|
* @param data 设备实时数据
|
||||||
|
*/
|
||||||
|
public void sendDroneDataUpdate(String deviceSn, com.central.device.websocket.model.DeviceRealtimeData data) {
|
||||||
|
if (data == null || data.getRawData() == null || data.getRawData().get("droneData") == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 只查找标记为无人机遥测数据的连接
|
||||||
|
emitters.forEach((sessionId, wrapper) -> {
|
||||||
|
if (deviceSn.equals(wrapper.getDeviceSn()) && wrapper.getIsDroneTelemetry()) {
|
||||||
|
try {
|
||||||
|
// 创建专门用于无人机数据的事件
|
||||||
|
SseEmitter.SseEventBuilder event = SseEmitter.event()
|
||||||
|
.name("drone-data-update")
|
||||||
|
.data(data.getRawData().get("droneData"))
|
||||||
|
.id("drone-" + System.currentTimeMillis());
|
||||||
|
|
||||||
|
wrapper.getEmitter().send(event);
|
||||||
|
log.debug("发送无人机数据更新到连接: session={}, deviceSn={}", sessionId, deviceSn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("发送无人机数据更新失败,连接可能已关闭: session={}, deviceSn={}, error={}",
|
||||||
|
sessionId, deviceSn, e.getMessage());
|
||||||
|
// 不立即移除,等待心跳检测或回调处理
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
@@ -37,4 +37,29 @@ public class EmitterWrapper {
|
|||||||
* 设备SN(新增字段,v3.0)
|
* 设备SN(新增字段,v3.0)
|
||||||
*/
|
*/
|
||||||
private String deviceSn;
|
private String deviceSn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为无人机遥测数据连接(新增字段)
|
||||||
|
* true: 无人机遥测数据(msg_alarm)
|
||||||
|
* false: 机库状态数据(fire_alarm)
|
||||||
|
*/
|
||||||
|
private Boolean isDroneTelemetry = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参构造函数(Lombok兼容)
|
||||||
|
*/
|
||||||
|
public EmitterWrapper() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数(兼容旧代码)
|
||||||
|
*/
|
||||||
|
public EmitterWrapper(SseEmitter emitter, Long scenicId, String tenantId, String sessionId, String deviceSn) {
|
||||||
|
this.emitter = emitter;
|
||||||
|
this.scenicId = scenicId;
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
this.deviceSn = deviceSn;
|
||||||
|
this.isDroneTelemetry = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+80
-19
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.central.device.websocket.config.WebSocketProperties;
|
import com.central.device.websocket.config.WebSocketProperties;
|
||||||
import com.central.device.websocket.handler.DeviceMessageHandler;
|
import com.central.device.websocket.handler.DeviceMessageHandler;
|
||||||
|
import com.central.device.websocket.manager.DeviceCommandManager;
|
||||||
import com.central.device.websocket.manager.TokenManager;
|
import com.central.device.websocket.manager.TokenManager;
|
||||||
import com.central.device.websocket.model.SubscriptionMessage;
|
import com.central.device.websocket.model.SubscriptionMessage;
|
||||||
import com.central.device.websocket.model.SubscriptionTopic;
|
import com.central.device.websocket.model.SubscriptionTopic;
|
||||||
@@ -20,9 +21,11 @@ import javax.annotation.PreDestroy;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JetLinks平台WebSocket客户端(全局单例)
|
* JetLinks平台WebSocket客户端(全局单例)
|
||||||
@@ -44,13 +47,19 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
/**
|
/**
|
||||||
* 命令管理器(延迟注入,避免循环依赖)
|
* 命令管理器(延迟注入,避免循环依赖)
|
||||||
*/
|
*/
|
||||||
private Object commandManager;
|
private DeviceCommandManager commandManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前订阅的主题列表
|
* 当前订阅的主题列表
|
||||||
*/
|
*/
|
||||||
private final Set<String> subscribedTopics = new HashSet<>();
|
private final Set<String> subscribedTopics = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备订阅计数:deviceSn -> 订阅次数
|
||||||
|
* 用于管理同一设备多个主题的订阅,避免过早断开连接
|
||||||
|
*/
|
||||||
|
private final ConcurrentHashMap<String, AtomicInteger> deviceSubscriptionCounts = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket会话
|
* WebSocket会话
|
||||||
*/
|
*/
|
||||||
@@ -147,9 +156,7 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
// 处理命令队列
|
// 处理命令队列
|
||||||
if (commandManager != null) {
|
if (commandManager != null) {
|
||||||
try {
|
try {
|
||||||
commandManager.getClass()
|
commandManager.onWebSocketReconnected();
|
||||||
.getMethod("onWebSocketReconnected")
|
|
||||||
.invoke(commandManager);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("调用命令管理器失败: {}", e.getMessage());
|
log.warn("调用命令管理器失败: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -207,7 +214,7 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
String requestId = json.getString("id");
|
String requestId = json.getString("id");
|
||||||
String deviceSn = extractDeviceSn(topic);
|
String deviceSn = extractDeviceSn(topic);
|
||||||
|
|
||||||
log.info("收到命令响应: topic={}, requestId={}, deviceSn={}", topic, requestId, deviceSn);
|
log.info("收到命令响应: topic={}, requestId={}, deviceSn={}, json={}", topic, requestId, deviceSn, json.toJSONString());
|
||||||
|
|
||||||
// 通知命令管理器处理响应
|
// 通知命令管理器处理响应
|
||||||
if (commandManager != null && requestId != null) {
|
if (commandManager != null && requestId != null) {
|
||||||
@@ -231,6 +238,7 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
} else {
|
} else {
|
||||||
// 如果有 payload 但没有 success 字段,可能是成功的
|
// 如果有 payload 但没有 success 字段,可能是成功的
|
||||||
success = true;
|
success = true;
|
||||||
|
log.debug("命令响应没有success字段,默认视为成功: requestId={}", requestId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 没有 payload,检查顶层是否有 success
|
// 没有 payload,检查顶层是否有 success
|
||||||
@@ -238,14 +246,14 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
message = json.getString("message");
|
message = json.getString("message");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("命令响应解析: requestId={}, success={}, message={}", requestId, success, message);
|
log.info("命令响应解析结果: requestId={}, success={}, message={}", requestId, success, message);
|
||||||
|
|
||||||
commandManager.getClass()
|
commandManager.handleCommandResponse(requestId, success, message);
|
||||||
.getMethod("handleCommandResponse", String.class, boolean.class, String.class)
|
|
||||||
.invoke(commandManager, requestId, success, message);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("调用命令管理器处理响应失败: {}", e.getMessage());
|
log.error("调用命令管理器处理响应失败: requestId={}, error={}", requestId, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("命令管理器未设置或requestId为空: commandManager={}, requestId={}", commandManager != null, requestId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +344,7 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
messageHandler.handlePropertyReport(deviceSn, json.toJSONString());
|
messageHandler.handlePropertyReport(deviceSn, json.toJSONString());
|
||||||
} else if (topic.contains("/message/event/fire_alarm")) {
|
} else if (topic.contains("/message/event/fire_alarm")) {
|
||||||
// 设备状态事件上报 - 使用专用处理方法
|
// 设备状态事件上报 - 使用专用处理方法
|
||||||
log.info("处理fire_alarm事件: deviceSn={}", deviceSn);
|
// log.info("处理fire_alarm事件: deviceSn={}", deviceSn);
|
||||||
messageHandler.handleDeviceStateEvent(deviceSn, json.toJSONString());
|
messageHandler.handleDeviceStateEvent(deviceSn, json.toJSONString());
|
||||||
} else if (topic.contains("/message/event/msg_alarm")) {
|
} else if (topic.contains("/message/event/msg_alarm")) {
|
||||||
// 无人机遥测数据事件 - 使用专用处理方法
|
// 无人机遥测数据事件 - 使用专用处理方法
|
||||||
@@ -442,10 +450,15 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
unsubscribeTopic(topic, deviceSn);
|
unsubscribeTopic(topic, deviceSn);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否所有订阅都已取消,如果是则断开WebSocket连接以节省资源
|
// 检查是否所有设备的订阅都已取消,如果是则断开WebSocket连接以节省资源
|
||||||
if (subscribedTopics.isEmpty()) {
|
// 注意:这里检查deviceSubscriptionCounts而不是subscribedTopics
|
||||||
log.info("所有设备订阅已取消,自动断开WebSocket连接以节省资源");
|
// 因为一个设备可能有多个主题订阅(fire_alarm + msg_alarm)
|
||||||
|
if (deviceSubscriptionCounts.isEmpty()) {
|
||||||
|
log.info("所有设备的所有订阅已取消,自动断开WebSocket连接以节省资源");
|
||||||
closeConnection();
|
closeConnection();
|
||||||
|
} else {
|
||||||
|
log.info("仍有{}个设备有活跃订阅,保持WebSocket连接: {}",
|
||||||
|
deviceSubscriptionCounts.size(), deviceSubscriptionCounts.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +478,12 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
send(JSON.toJSONString(message));
|
send(JSON.toJSONString(message));
|
||||||
subscribedTopics.add(topic);
|
subscribedTopics.add(topic);
|
||||||
|
|
||||||
log.info("发送订阅消息: topic={}, id={}, message={}", topic, message.getId(), JSON.toJSONString(message));
|
// 更新设备订阅计数
|
||||||
|
deviceSubscriptionCounts.computeIfAbsent(deviceSn, k -> new AtomicInteger(0)).incrementAndGet();
|
||||||
|
|
||||||
|
log.info("发送订阅消息: topic={}, id={}, message={}, 设备{}订阅计数: {}",
|
||||||
|
topic, message.getId(), JSON.toJSONString(message),
|
||||||
|
deviceSn, deviceSubscriptionCounts.get(deviceSn).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -490,8 +508,19 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
send(JSON.toJSONString(message));
|
send(JSON.toJSONString(message));
|
||||||
subscribedTopics.remove(topic);
|
subscribedTopics.remove(topic);
|
||||||
|
|
||||||
log.info("取消订阅主题: topic={}, id={}, 剩余订阅数: {}, 剩余主题: {}",
|
// 更新设备订阅计数
|
||||||
topic, message.getId(), subscribedTopics.size(), subscribedTopics);
|
AtomicInteger count = deviceSubscriptionCounts.get(deviceSn);
|
||||||
|
if (count != null) {
|
||||||
|
int newCount = count.decrementAndGet();
|
||||||
|
if (newCount <= 0) {
|
||||||
|
deviceSubscriptionCounts.remove(deviceSn);
|
||||||
|
log.info("设备{}所有订阅已取消,从订阅计数中移除", deviceSn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("取消订阅主题: topic={}, id={}, 剩余订阅数: {}, 剩余主题: {}, 设备{}剩余订阅计数: {}",
|
||||||
|
topic, message.getId(), subscribedTopics.size(), subscribedTopics,
|
||||||
|
deviceSn, count != null ? count.get() : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -503,10 +532,12 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("重新订阅 {} 个主题", subscribedTopics.size());
|
log.info("重新订阅 {} 个主题,涉及 {} 个设备", subscribedTopics.size(), deviceSubscriptionCounts.size());
|
||||||
|
|
||||||
Set<String> topics = new HashSet<>(subscribedTopics);
|
Set<String> topics = new HashSet<>(subscribedTopics);
|
||||||
subscribedTopics.clear();
|
subscribedTopics.clear();
|
||||||
|
// 清空设备订阅计数,重新订阅时会重新计算
|
||||||
|
deviceSubscriptionCounts.clear();
|
||||||
|
|
||||||
// 按设备分组重新订阅(订阅所有标准主题)
|
// 按设备分组重新订阅(订阅所有标准主题)
|
||||||
Set<String> deviceSns = new HashSet<>();
|
Set<String> deviceSns = new HashSet<>();
|
||||||
@@ -675,10 +706,40 @@ public class JetLinksWebSocketClient extends TextWebSocketHandler {
|
|||||||
return subscribedTopics.size();
|
return subscribedTopics.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备订阅计数
|
||||||
|
*/
|
||||||
|
public int getDeviceSubscriptionCount(String deviceSn) {
|
||||||
|
AtomicInteger count = deviceSubscriptionCounts.get(deviceSn);
|
||||||
|
return count != null ? count.get() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有有活跃订阅的设备
|
||||||
|
*/
|
||||||
|
public Set<String> getActiveDevices() {
|
||||||
|
return new HashSet<>(deviceSubscriptionCounts.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印当前订阅状态(用于调试)
|
||||||
|
*/
|
||||||
|
public void printSubscriptionStatus() {
|
||||||
|
log.info("=== WebSocket订阅状态 ===");
|
||||||
|
log.info("连接状态: {}", isConnected() ? "已连接" : "未连接");
|
||||||
|
log.info("主题订阅数: {}", subscribedTopics.size());
|
||||||
|
log.info("设备订阅数: {}", deviceSubscriptionCounts.size());
|
||||||
|
log.info("活跃设备: {}", deviceSubscriptionCounts.keySet());
|
||||||
|
deviceSubscriptionCounts.forEach((deviceSn, count) -> {
|
||||||
|
log.info(" 设备 {}: {} 个主题订阅", deviceSn, count.get());
|
||||||
|
});
|
||||||
|
log.info("=== 结束 ===");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置命令管理器(延迟注入,避免循环依赖)
|
* 设置命令管理器(延迟注入,避免循环依赖)
|
||||||
*/
|
*/
|
||||||
public void setCommandManager(Object commandManager) {
|
public void setCommandManager(DeviceCommandManager commandManager) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-21
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.central.device.service.DeviceAlarmDataService;
|
import com.central.device.service.DeviceAlarmDataService;
|
||||||
import com.central.device.websocket.model.DeviceRealtimeData;
|
import com.central.device.websocket.model.DeviceRealtimeData;
|
||||||
|
import com.central.device.websocket.model.DroneRealtimeData;
|
||||||
import com.central.device.websocket.model.GpsData;
|
import com.central.device.websocket.model.GpsData;
|
||||||
import com.central.device.websocket.model.message.DeviceStateEventMessage;
|
import com.central.device.websocket.model.message.DeviceStateEventMessage;
|
||||||
import com.central.device.websocket.model.message.PropertyReportMessage;
|
import com.central.device.websocket.model.message.PropertyReportMessage;
|
||||||
@@ -322,7 +323,7 @@ public class DeviceMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 三种数据都齐全了,合并并推送
|
// 三种数据都齐全了,合并并推送
|
||||||
log.info("设备 {} 三种数据已齐全,开始合并推送", deviceSn);
|
// log.info("设备 {} 三种数据已齐全,开始合并推送", deviceSn);
|
||||||
|
|
||||||
// 合并三种缓存数据
|
// 合并三种缓存数据
|
||||||
JSONObject mergedDockData = mergeAllCaches(cache);
|
JSONObject mergedDockData = mergeAllCaches(cache);
|
||||||
@@ -423,29 +424,23 @@ public class DeviceMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果设备已在 deviceDataMap 中注册,更新其数据并推送SSE
|
// 创建无人机数据对象(与机库数据完全分离)
|
||||||
DeviceRealtimeData data = deviceDataMap.get(deviceSn);
|
DroneRealtimeData droneRealtimeData = DroneRealtimeData.fromRawData(deviceSn, droneData);
|
||||||
if (data != null) {
|
|
||||||
data.setOnline(true);
|
|
||||||
data.setLastMessageTime(timestamp != null ? timestamp : System.currentTimeMillis());
|
|
||||||
|
|
||||||
// 从 droneData 提取关键字段更新到 DeviceRealtimeData
|
// 推送到无人机专用的SSE连接
|
||||||
extractDroneKeyFields(data, droneData);
|
if (sseEmitterManager != null) {
|
||||||
|
try {
|
||||||
// 将 msg_alarm 数据合并到 rawData 中
|
log.info("【handleMsgAlarmEvent】准备推送无人机数据到SSE: deviceSn={}", deviceSn);
|
||||||
JSONObject rawData = data.getRawData();
|
sseEmitterManager.getClass()
|
||||||
if (rawData == null) {
|
.getMethod("sendDroneDataUpdate", String.class, DroneRealtimeData.class)
|
||||||
rawData = new JSONObject();
|
.invoke(sseEmitterManager, deviceSn, droneRealtimeData);
|
||||||
|
log.info("【handleMsgAlarmEvent】已推送无人机数据到专用SSE连接: deviceSn={}", deviceSn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("【handleMsgAlarmEvent】调用无人机SSE推送失败: deviceSn={}, error={}", deviceSn, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
// 只保留 droneData,不再重复存储 msgAlarmData
|
} else {
|
||||||
// 前端直接从 rawData.droneData 读取无人机遥测数据
|
log.warn("【handleMsgAlarmEvent】sseEmitterManager 为 null,无法推送无人机数据");
|
||||||
rawData.put("droneData", droneData);
|
|
||||||
data.setRawData(rawData);
|
|
||||||
|
|
||||||
// 推送到前端(通过SSE)
|
|
||||||
pushDeviceDataUpdate(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("解析 msg_alarm 消息失败: deviceSn={}, error={}", deviceSn, e.getMessage(), e);
|
log.error("解析 msg_alarm 消息失败: deviceSn={}, error={}", deviceSn, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -400,13 +400,13 @@ public class DeviceCommandManager {
|
|||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
command.setStatus(CommandStatus.SUCCESS);
|
command.setStatus(CommandStatus.SUCCESS);
|
||||||
log.info("命令执行成功: commandId={}, device={}",
|
log.info("命令执行成功: commandId={}, device={}, type={}",
|
||||||
commandId, command.getDeviceSn());
|
commandId, command.getDeviceSn(), command.getCommandType());
|
||||||
} else {
|
} else {
|
||||||
command.setStatus(CommandStatus.FAILED);
|
command.setStatus(CommandStatus.FAILED);
|
||||||
command.setErrorMsg(message);
|
command.setErrorMsg(message);
|
||||||
log.error("命令执行失败: commandId={}, device={}, error={}",
|
log.error("命令执行失败: commandId={}, device={}, type={}, error={}",
|
||||||
commandId, command.getDeviceSn(), message);
|
commandId, command.getDeviceSn(), command.getCommandType(), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
-6
@@ -317,19 +317,31 @@ public class DeviceSubscriptionManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("订阅无人机遥测数据: deviceSn={}", deviceSn);
|
log.info("【调试】开始订阅无人机遥测数据: deviceSn={}", deviceSn);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 打印当前WebSocket连接状态
|
||||||
|
boolean isConnected = jetLinksWebSocketClient.isConnected();
|
||||||
|
log.info("【调试】WebSocket连接状态: {}", isConnected ? "已连接" : "未连接");
|
||||||
|
|
||||||
|
// 打印当前设备订阅计数
|
||||||
|
int deviceCount = jetLinksWebSocketClient.getDeviceSubscriptionCount(deviceSn);
|
||||||
|
log.info("【调试】设备{}当前订阅计数: {}", deviceSn, deviceCount);
|
||||||
|
|
||||||
// 只订阅 msg_alarm 主题
|
// 只订阅 msg_alarm 主题
|
||||||
jetLinksWebSocketClient.subscribeDevice(
|
jetLinksWebSocketClient.subscribeDevice(
|
||||||
deviceSn,
|
deviceSn,
|
||||||
SubscriptionTopic.EVENT_MSG_ALARM // 无人机遥测数据
|
SubscriptionTopic.EVENT_MSG_ALARM // 无人机遥测数据
|
||||||
);
|
);
|
||||||
|
|
||||||
log.info("无人机遥测数据 {} 订阅成功", deviceSn);
|
log.info("【调试】无人机遥测数据 {} 订阅成功", deviceSn);
|
||||||
|
|
||||||
|
// 打印订阅后的状态
|
||||||
|
int newDeviceCount = jetLinksWebSocketClient.getDeviceSubscriptionCount(deviceSn);
|
||||||
|
log.info("【调试】设备{}订阅后计数: {}", deviceSn, newDeviceCount);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("订阅无人机遥测数据 {} 失败: {}", deviceSn, e.getMessage(), e);
|
log.error("【调试】订阅无人机遥测数据 {} 失败: {}", deviceSn, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,19 +357,31 @@ public class DeviceSubscriptionManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("取消订阅无人机遥测数据: deviceSn={}", deviceSn);
|
log.info("【调试】开始取消订阅无人机遥测数据: deviceSn={}", deviceSn);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 打印取消订阅前的状态
|
||||||
|
int deviceCount = jetLinksWebSocketClient.getDeviceSubscriptionCount(deviceSn);
|
||||||
|
log.info("【调试】设备{}取消订阅前计数: {}", deviceSn, deviceCount);
|
||||||
|
|
||||||
// 只取消 msg_alarm 主题
|
// 只取消 msg_alarm 主题
|
||||||
jetLinksWebSocketClient.unsubscribeDevice(
|
jetLinksWebSocketClient.unsubscribeDevice(
|
||||||
deviceSn,
|
deviceSn,
|
||||||
SubscriptionTopic.EVENT_MSG_ALARM // 无人机遥测数据
|
SubscriptionTopic.EVENT_MSG_ALARM // 无人机遥测数据
|
||||||
);
|
);
|
||||||
|
|
||||||
log.info("无人机遥测数据 {} 订阅已取消", deviceSn);
|
log.info("【调试】无人机遥测数据 {} 订阅已取消", deviceSn);
|
||||||
|
|
||||||
|
// 打印取消订阅后的状态
|
||||||
|
int newDeviceCount = jetLinksWebSocketClient.getDeviceSubscriptionCount(deviceSn);
|
||||||
|
log.info("【调试】设备{}取消订阅后计数: {}", deviceSn, newDeviceCount);
|
||||||
|
|
||||||
|
// 打印当前所有活跃设备
|
||||||
|
java.util.Set<String> activeDevices = jetLinksWebSocketClient.getActiveDevices();
|
||||||
|
log.info("【调试】当前活跃设备: {}", activeDevices);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("取消订阅无人机遥测数据 {} 失败: {}", deviceSn, e.getMessage(), e);
|
log.error("【调试】取消订阅无人机遥测数据 {} 失败: {}", deviceSn, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,48 @@
|
|||||||
* - 统一网关转发:仅代理 /api- 前缀到网关(/api-user、/api-uaa 等)
|
* - 统一网关转发:仅代理 /api- 前缀到网关(/api-user、/api-uaa 等)
|
||||||
* - 生产环境由网关/容器转发,此文件不生效
|
* - 生产环境由网关/容器转发,此文件不生效
|
||||||
*/
|
*/
|
||||||
const GATEWAY = process.env.GATEWAY_ORIGIN || 'http://127.0.0.1:9900';
|
const GATEWAY = process.env.GATEWAY_ORIGIN || 'http://192.168.2.214:9900';
|
||||||
|
// SRS流媒体服务器地址
|
||||||
|
const SRS_SERVER = process.env.SRS_SERVER || 'http://220.205.16.27:8024';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
dev: {
|
dev: {
|
||||||
// 单一规则覆盖所有微服务前缀:/api-*
|
// 单一规则覆盖所有微服务前缀:/api-*
|
||||||
'/api-': { target: GATEWAY, changeOrigin: true },
|
'/api-': { target: GATEWAY, changeOrigin: true },
|
||||||
|
// 3D模型CDN代理 - 解决跨域问题
|
||||||
|
'/goflymodel': {
|
||||||
|
target: 'https://minicdn.goflytec.com',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
|
// SRS WebRTC WHEP 视频流代理
|
||||||
|
'/rtc': {
|
||||||
|
target: SRS_SERVER,
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
|
// SRS 登录认证接口代理
|
||||||
|
'/terraform': {
|
||||||
|
target: SRS_SERVER,
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
'/api-': { target: GATEWAY, changeOrigin: true },
|
'/api-': { target: GATEWAY, changeOrigin: true },
|
||||||
|
'/goflymodel': {
|
||||||
|
target: 'https://minicdn.goflytec.com',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
pre: {
|
pre: {
|
||||||
'/api-': { target: GATEWAY, changeOrigin: true },
|
'/api-': { target: GATEWAY, changeOrigin: true },
|
||||||
|
'/goflymodel': {
|
||||||
|
target: 'https://minicdn.goflytec.com',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
"prebuild:test:mgnt": "npm run copy:cesium",
|
"prebuild:test:mgnt": "npm run copy:cesium",
|
||||||
"prebuild:pre:mgnt": "npm run copy:cesium",
|
"prebuild:pre:mgnt": "npm run copy:cesium",
|
||||||
"prebuild:prod:mgnt": "npm run copy:cesium",
|
"prebuild:prod:mgnt": "npm run copy:cesium",
|
||||||
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://127.0.0.1:9900 umi dev",
|
"start": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://192.168.2.124:9900 umi dev",
|
||||||
"start:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://127.0.0.1:9900 umi dev",
|
"start:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=dev GATEWAY_ORIGIN=http://192.168.2.124:9900 umi dev",
|
||||||
"start:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test GATEWAY_ORIGIN=https://test.goflytec.com umi dev",
|
"start:test": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=test GATEWAY_ORIGIN=https://test.goflytec.com umi dev",
|
||||||
"start:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre GATEWAY_ORIGIN=http://119.45.169.13:9900 umi dev",
|
"start:pre": "cross-env NODE_OPTIONS=--openssl-legacy-provider REACT_APP_ENV=pre GATEWAY_ORIGIN=http://119.45.169.13:9900 umi dev",
|
||||||
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider umi build",
|
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider umi build",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export type DeviceFormValues = {
|
|||||||
deviceType?: number;
|
deviceType?: number;
|
||||||
firmwareVersion?: string;
|
firmwareVersion?: string;
|
||||||
remark?: string;
|
remark?: string;
|
||||||
|
videoStreamUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface DeviceFormProps {
|
interface DeviceFormProps {
|
||||||
@@ -53,6 +54,13 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
|
|||||||
<ProFormText name="nickname" label="昵称" width="md" />
|
<ProFormText name="nickname" label="昵称" width="md" />
|
||||||
<ProFormSelect name="deviceType" label="设备类型" options={DEVICE_TYPE_OPTIONS} width="md" />
|
<ProFormSelect name="deviceType" label="设备类型" options={DEVICE_TYPE_OPTIONS} width="md" />
|
||||||
<ProFormText name="firmwareVersion" label="固件版本" width="md" />
|
<ProFormText name="firmwareVersion" label="固件版本" width="md" />
|
||||||
|
<ProFormText
|
||||||
|
name="videoStreamUrl"
|
||||||
|
label="视频流地址"
|
||||||
|
width="lg"
|
||||||
|
placeholder="如:http://220.205.16.27:8024/rtc/v1/whep/?app=live&stream=xxx"
|
||||||
|
tooltip="WHEP视频流完整地址,用于无人机图传播放"
|
||||||
|
/>
|
||||||
<ProFormTextArea name="deviceDesc" label="备注" width="lg" />
|
<ProFormTextArea name="deviceDesc" label="备注" width="lg" />
|
||||||
</ProForm.Group>
|
</ProForm.Group>
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
|
|||||||
+9
-1
@@ -346,7 +346,15 @@ const ModelPreviewModal: React.FC<ModelPreviewModalProps> = ({
|
|||||||
viewer.imageryLayers.addImageryProvider(arcgisImagery);
|
viewer.imageryLayers.addImageryProvider(arcgisImagery);
|
||||||
|
|
||||||
// 加载3D Tiles模型 - 预览时使用高质量设置
|
// 加载3D Tiles模型 - 预览时使用高质量设置
|
||||||
const tileset = await Cesium.Cesium3DTileset.fromUrl(model.tilesetUrl, {
|
// 处理跨域问题:非 localhost 访问时将 CDN URL 转换为代理路径
|
||||||
|
let tilesetUrl = model.tilesetUrl;
|
||||||
|
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||||
|
if (!isLocalhost && tilesetUrl.includes('minicdn.goflytec.com')) {
|
||||||
|
tilesetUrl = tilesetUrl.replace('https://minicdn.goflytec.com', '');
|
||||||
|
console.log('[ModelPreview] 使用代理路径:', tilesetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tileset = await Cesium.Cesium3DTileset.fromUrl(tilesetUrl, {
|
||||||
maximumScreenSpaceError: 1,
|
maximumScreenSpaceError: 1,
|
||||||
maximumMemoryUsage: 2048,
|
maximumMemoryUsage: 2048,
|
||||||
skipLevelOfDetail: false,
|
skipLevelOfDetail: false,
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
|||||||
// 提取每个查询结果的第一个设备
|
// 提取每个查询结果的第一个设备
|
||||||
const devices = results
|
const devices = results
|
||||||
.map((res) => (res.data && res.data.length > 0 ? res.data[0] : null))
|
.map((res) => (res.data && res.data.length > 0 ? res.data[0] : null))
|
||||||
.filter((device) => device !== null);
|
.filter((device): device is any => device !== null);
|
||||||
|
|
||||||
setDeviceList(devices);
|
setDeviceList(devices);
|
||||||
|
|
||||||
@@ -467,6 +467,16 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
|||||||
|
|
||||||
setTakeoffLoading(true);
|
setTakeoffLoading(true);
|
||||||
try {
|
try {
|
||||||
|
console.log('发送起飞命令:', {
|
||||||
|
deviceSn: selectedDeviceSn,
|
||||||
|
targetLatitude: takeoffForm.targetLatitude,
|
||||||
|
targetLongitude: takeoffForm.targetLongitude,
|
||||||
|
targetHeight: takeoffForm.targetHeight,
|
||||||
|
securityTakeoffHeight: takeoffForm.securityTakeoffHeight,
|
||||||
|
rthAltitude: takeoffForm.rthAltitude,
|
||||||
|
maxSpeed: takeoffForm.maxSpeed,
|
||||||
|
});
|
||||||
|
|
||||||
const res = await deviceApi.takeoff({
|
const res = await deviceApi.takeoff({
|
||||||
deviceSn: selectedDeviceSn,
|
deviceSn: selectedDeviceSn,
|
||||||
targetLatitude: takeoffForm.targetLatitude,
|
targetLatitude: takeoffForm.targetLatitude,
|
||||||
@@ -477,14 +487,36 @@ const TourismDeviceDetail: React.FC<TourismDeviceDetailProps> = (props) => {
|
|||||||
maxSpeed: takeoffForm.maxSpeed,
|
maxSpeed: takeoffForm.maxSpeed,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.code === 0) {
|
console.log('起飞命令响应:', res);
|
||||||
|
|
||||||
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
||||||
setTakeoffModalVisible(false);
|
setTakeoffModalVisible(false);
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '起飞命令发送失败');
|
console.error('起飞命令失败:', res);
|
||||||
|
message.error(msg || '起飞命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '起飞命令发送失败');
|
console.error('起飞命令发送失败:', error);
|
||||||
|
// 更详细的错误信息
|
||||||
|
let errorMsg = '起飞命令发送失败';
|
||||||
|
if (error.response) {
|
||||||
|
// HTTP错误响应
|
||||||
|
const data = error.response.data;
|
||||||
|
// 兼容两种响应格式
|
||||||
|
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||||
|
} else if (error.message) {
|
||||||
|
errorMsg = error.message;
|
||||||
|
} else if (error.msg) {
|
||||||
|
errorMsg = error.msg;
|
||||||
|
} else if (error.resp_msg) {
|
||||||
|
errorMsg = error.resp_msg;
|
||||||
|
}
|
||||||
|
message.error(errorMsg);
|
||||||
} finally {
|
} finally {
|
||||||
setTakeoffLoading(false);
|
setTakeoffLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
+227
-58
@@ -24,6 +24,28 @@
|
|||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 全屏模式
|
||||||
|
&.fullscreen {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: 9999;
|
||||||
|
transform: none;
|
||||||
|
|
||||||
|
.videoContainer {
|
||||||
|
flex: 1;
|
||||||
|
aspect-ratio: unset;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header, .flightDashboard, .controlsContent {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&::after {
|
&::after {
|
||||||
content: '';
|
content: '';
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -36,7 +58,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
padding: 16px 20px;
|
padding: 12px 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -44,7 +66,7 @@
|
|||||||
background: rgba(0, 240, 255, 0.05);
|
background: rgba(0, 240, 255, 0.05);
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 16px;
|
font-size: 14px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -98,6 +120,126 @@
|
|||||||
.icon { font-size: 48px; margin-bottom: 12px; filter: drop-shadow(0 0 10px @cyan); }
|
.icon { font-size: 48px; margin-bottom: 12px; filter: drop-shadow(0 0 10px @cyan); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 简化的HUD样式
|
||||||
|
.hudTopLeft {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
left: 8px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-family: 'Consolas', monospace;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
.statusLine {
|
||||||
|
color: rgba(255, 255, 255, 0.9);
|
||||||
|
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||||
|
margin-bottom: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusOk { color: #00ff88; }
|
||||||
|
.statusErr { color: #ff4444; }
|
||||||
|
|
||||||
|
.hudTopRight {
|
||||||
|
position: absolute;
|
||||||
|
top: 8px;
|
||||||
|
right: 8px;
|
||||||
|
text-align: right;
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: 'Consolas', monospace;
|
||||||
|
font-weight: bold;
|
||||||
|
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
span {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.hudBottom {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 8px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
display: flex;
|
||||||
|
gap: 16px;
|
||||||
|
font-size: 11px;
|
||||||
|
font-family: 'Consolas', monospace;
|
||||||
|
color: rgba(255, 255, 255, 0.85);
|
||||||
|
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||||
|
background: rgba(0, 0, 0, 0.4);
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hudBottomLeft {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 8px;
|
||||||
|
left: 8px;
|
||||||
|
font-size: 10px;
|
||||||
|
font-family: 'Consolas', monospace;
|
||||||
|
color: rgba(0, 255, 255, 0.7);
|
||||||
|
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 浮动控制按钮
|
||||||
|
.floatingControls {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
right: 8px;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.floatBtn {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: rgba(0, 0, 0, 0.6);
|
||||||
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
||||||
|
color: #fff;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(0, 240, 255, 0.3);
|
||||||
|
border-color: @cyan;
|
||||||
|
color: @cyan;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.recording {
|
||||||
|
background: rgba(255, 0, 0, 0.6);
|
||||||
|
border-color: #ff4444;
|
||||||
|
animation: recordPulse 1s infinite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接状态指示
|
||||||
|
.connectionStatus {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 8px;
|
||||||
|
right: 8px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-size: 12px;
|
||||||
|
background: rgba(0, 0, 0, 0.5);
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.hudOverlay {
|
.hudOverlay {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px; left: 10px; right: 10px; bottom: 10px;
|
top: 10px; left: 10px; right: 10px; bottom: 10px;
|
||||||
@@ -115,38 +257,38 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 飞行仪表盘
|
// 飞行仪表盘 - 更紧凑
|
||||||
.flightDashboard {
|
.flightDashboard {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(3, 1fr);
|
grid-template-columns: repeat(6, 1fr);
|
||||||
gap: 8px;
|
gap: 4px;
|
||||||
padding: 16px 20px;
|
padding: 8px 12px;
|
||||||
background: rgba(0,0,0,0.2);
|
background: rgba(0,0,0,0.2);
|
||||||
border-bottom: 1px solid rgba(255,255,255,0.05);
|
border-bottom: 1px solid rgba(255,255,255,0.05);
|
||||||
|
|
||||||
.dashItem {
|
.dashItem {
|
||||||
background: rgba(255,255,255,0.05);
|
background: rgba(255,255,255,0.05);
|
||||||
padding: 8px;
|
padding: 6px 4px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
.dashLabel { font-size: 10px; color: rgba(255,255,255,0.4); margin-bottom: 2px; }
|
.dashLabel { font-size: 9px; color: rgba(255,255,255,0.4); margin-bottom: 2px; }
|
||||||
.dashValue { font-size: 14px; font-weight: bold; color: #fff; font-family: 'Consolas', monospace; }
|
.dashValue { font-size: 12px; font-weight: bold; color: #fff; font-family: 'Consolas', monospace; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.controlsContent {
|
.controlsContent {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 20px;
|
padding: 12px 16px;
|
||||||
|
|
||||||
.controlGroup {
|
.controlGroup {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 16px;
|
||||||
|
|
||||||
.groupTitle {
|
.groupTitle {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgba(255, 255, 255, 0.4);
|
color: rgba(255, 255, 255, 0.5);
|
||||||
margin-bottom: 12px;
|
margin-bottom: 10px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
&::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.1); margin-left: 8px; }
|
&::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.1); margin-left: 8px; }
|
||||||
@@ -154,67 +296,84 @@
|
|||||||
|
|
||||||
.flightActions {
|
.flightActions {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||||
gap: 8px;
|
gap: 6px;
|
||||||
margin-bottom: 16px;
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
height: 36px;
|
height: 32px;
|
||||||
|
font-size: 12px;
|
||||||
background: rgba(0, 240, 255, 0.1);
|
background: rgba(0, 240, 255, 0.1);
|
||||||
border: 1px solid rgba(0, 240, 255, 0.3);
|
border: 1px solid rgba(0, 240, 255, 0.3);
|
||||||
color: @cyan;
|
color: @cyan;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
border-radius: 4px;
|
||||||
|
transition: all 0.2s;
|
||||||
&:hover { background: rgba(0, 240, 255, 0.2); }
|
&:hover { background: rgba(0, 240, 255, 0.2); }
|
||||||
|
&.danger {
|
||||||
|
background: rgba(255, 77, 79, 0.1);
|
||||||
|
border-color: rgba(255, 77, 79, 0.3);
|
||||||
|
color: #ff4d4f;
|
||||||
|
&:hover { background: rgba(255, 77, 79, 0.2); }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.joystickArea {
|
// 键盘控制说明样式
|
||||||
display: flex;
|
.keyboardHint {
|
||||||
justify-content: space-between;
|
background: rgba(0, 0, 0, 0.3);
|
||||||
gap: 12px;
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 12px;
|
||||||
|
|
||||||
.joystickGroup {
|
.keyGroup {
|
||||||
flex: 1;
|
display: flex;
|
||||||
display: flex;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
gap: 4px;
|
||||||
background: rgba(0,0,0,0.3);
|
margin-bottom: 8px;
|
||||||
padding: 12px 8px;
|
font-size: 11px;
|
||||||
border-radius: 8px;
|
color: rgba(255, 255, 255, 0.6);
|
||||||
border: 1px solid rgba(255,255,255,0.05);
|
|
||||||
|
|
||||||
.joystickLabel {
|
&:last-child {
|
||||||
font-size: 10px;
|
margin-bottom: 0;
|
||||||
color: rgba(255,255,255,0.4);
|
}
|
||||||
margin-bottom: 8px;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.dpad {
|
.keyLabel {
|
||||||
display: grid;
|
color: rgba(255, 255, 255, 0.4);
|
||||||
grid-template-columns: repeat(3, 32px);
|
margin-right: 4px;
|
||||||
grid-template-rows: repeat(3, 32px);
|
min-width: 36px;
|
||||||
gap: 4px;
|
}
|
||||||
|
|
||||||
button {
|
kbd {
|
||||||
background: rgba(255, 255, 255, 0.1);
|
display: inline-block;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
padding: 2px 6px;
|
||||||
color: #fff;
|
font-size: 11px;
|
||||||
border-radius: 4px;
|
font-family: 'Consolas', monospace;
|
||||||
cursor: pointer;
|
background: rgba(255, 255, 255, 0.1);
|
||||||
display: flex;
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||||
align-items: center;
|
border-radius: 3px;
|
||||||
justify-content: center;
|
color: #fff;
|
||||||
font-size: 12px;
|
min-width: 20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover { background: @cyan; color: #000; box-shadow: 0 0 10px @cyan; }
|
.activeKeyDisplay {
|
||||||
&:active { transform: scale(0.95); }
|
margin-top: 8px;
|
||||||
|
padding-top: 8px;
|
||||||
|
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
||||||
|
display: flex;
|
||||||
|
gap: 4px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
&.up { grid-column: 2; grid-row: 1; }
|
.activeKey {
|
||||||
&.left { grid-column: 1; grid-row: 2; }
|
background: @cyan;
|
||||||
&.right { grid-column: 3; grid-row: 2; }
|
border-color: @cyan;
|
||||||
&.down { grid-column: 2; grid-row: 3; }
|
color: #000;
|
||||||
}
|
font-weight: bold;
|
||||||
}
|
box-shadow: 0 0 8px @cyan;
|
||||||
|
animation: keyGlow 0.3s ease;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,3 +384,13 @@
|
|||||||
0%, 100% { opacity: 1; }
|
0%, 100% { opacity: 1; }
|
||||||
50% { opacity: 0.4; }
|
50% { opacity: 0.4; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes recordPulse {
|
||||||
|
0%, 100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.5); }
|
||||||
|
50% { box-shadow: 0 0 10px 4px rgba(255, 0, 0, 0.3); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes keyGlow {
|
||||||
|
from { transform: scale(1.2); }
|
||||||
|
to { transform: scale(1); }
|
||||||
|
}
|
||||||
|
|||||||
+403
-241
@@ -2,17 +2,9 @@ import React, { useMemo, useState, useCallback, useEffect, useRef } from 'react'
|
|||||||
import {
|
import {
|
||||||
CloseOutlined,
|
CloseOutlined,
|
||||||
VideoCameraOutlined,
|
VideoCameraOutlined,
|
||||||
ArrowUpOutlined,
|
|
||||||
ArrowDownOutlined,
|
|
||||||
ArrowLeftOutlined,
|
|
||||||
ArrowRightOutlined,
|
|
||||||
StopOutlined,
|
StopOutlined,
|
||||||
HomeOutlined,
|
HomeOutlined,
|
||||||
CameraOutlined,
|
CameraOutlined,
|
||||||
RotateLeftOutlined,
|
|
||||||
RotateRightOutlined,
|
|
||||||
VerticalAlignTopOutlined,
|
|
||||||
VerticalAlignBottomOutlined,
|
|
||||||
CompassOutlined,
|
CompassOutlined,
|
||||||
WifiOutlined,
|
WifiOutlined,
|
||||||
LoadingOutlined,
|
LoadingOutlined,
|
||||||
@@ -21,12 +13,16 @@ import {
|
|||||||
LinkOutlined,
|
LinkOutlined,
|
||||||
DisconnectOutlined,
|
DisconnectOutlined,
|
||||||
CaretRightOutlined,
|
CaretRightOutlined,
|
||||||
SwapOutlined,
|
FullscreenOutlined,
|
||||||
AimOutlined
|
FullscreenExitOutlined,
|
||||||
|
AimOutlined,
|
||||||
|
ThunderboltOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { message, Tooltip, Modal, Switch, Tag } from 'antd';
|
import { message, Tooltip, Modal, Tag } from 'antd';
|
||||||
import { deviceApi } from '@/services/device';
|
import { deviceApi } from '@/services/device';
|
||||||
import { deviceControlWs } from '@/services/deviceControlWs';
|
import { deviceControlWs } from '@/services/deviceControlWs';
|
||||||
|
import { useDroneSSE } from '../hooks/useDroneSSE';
|
||||||
|
import WhepPlayer from './WhepPlayer';
|
||||||
import styles from './LeftControlPanel.less';
|
import styles from './LeftControlPanel.less';
|
||||||
|
|
||||||
interface LeftControlPanelProps {
|
interface LeftControlPanelProps {
|
||||||
@@ -34,6 +30,8 @@ interface LeftControlPanelProps {
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
device: any;
|
device: any;
|
||||||
realtimeData: any;
|
realtimeData: any;
|
||||||
|
/** 视频流完整地址(WHEP URL) */
|
||||||
|
videoStreamUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 飞行模式映射
|
// 飞行模式映射
|
||||||
@@ -52,81 +50,93 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
visible,
|
visible,
|
||||||
onClose,
|
onClose,
|
||||||
device,
|
device,
|
||||||
realtimeData
|
realtimeData,
|
||||||
|
videoStreamUrl,
|
||||||
}) => {
|
}) => {
|
||||||
const dockData = realtimeData?.rawData?.dockData;
|
const dockData = realtimeData?.rawData?.dockData;
|
||||||
const droneData = realtimeData?.rawData?.droneData;
|
const rawDroneData = realtimeData?.rawData?.droneData;
|
||||||
|
|
||||||
// 从 droneData (msg_alarm) 获取无人机实时飞行数据
|
// 获取设备SN
|
||||||
// droneData 结构: 根级别有 latitude, longitude, height, attitude_pitch 等
|
const deviceSn = device?.deviceSn;
|
||||||
// 云台数据在 payload 索引下,如 droneData["98-0-0"]
|
|
||||||
|
// 【重要】使用独立的无人机SSE连接 - 必须在 flightData useMemo 之前定义
|
||||||
|
const {
|
||||||
|
droneData,
|
||||||
|
sseConnected: droneSseConnected,
|
||||||
|
loading: droneSseLoading,
|
||||||
|
hasData: droneHasData,
|
||||||
|
connectDroneSSE,
|
||||||
|
disconnectDroneSSE,
|
||||||
|
resetDroneData,
|
||||||
|
} = useDroneSSE();
|
||||||
|
|
||||||
|
// 从 droneData (独立SSE连接) 或 rawDroneData (props) 获取无人机实时飞行数据
|
||||||
|
// 优先使用独立SSE连接的 droneData,因为它专门接收无人机遥测数据
|
||||||
const flightData = useMemo(() => {
|
const flightData = useMemo(() => {
|
||||||
// 调试日志 - 查看 droneData 的实际结构
|
// 优先使用独立SSE的droneData,其次使用rawDroneData
|
||||||
if (droneData) {
|
const effectiveDroneData = droneData || rawDroneData;
|
||||||
console.log('[FlightData] droneData keys:', Object.keys(droneData));
|
|
||||||
console.log('[FlightData] droneData.latitude:', droneData?.latitude);
|
|
||||||
console.log('[FlightData] droneData.longitude:', droneData?.longitude);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取云台payload数据 - 遍历查找带有 gimbal_pitch 的子对象
|
// 获取云台payload数据 - 遍历查找带有 gimbal_pitch 的子对象
|
||||||
let gimbalPayload: any = {};
|
let gimbalPayload: any = {};
|
||||||
if (droneData) {
|
if (effectiveDroneData) {
|
||||||
// 常见的 payload 索引
|
// 常见的 payload 索引
|
||||||
const payloadKeys = ['98-0-0', '39-0-0', '42-0-0', '43-0-0', '52-0-0', '53-0-0', '165-0-0'];
|
const payloadKeys = ['98-0-0', '39-0-0', '42-0-0', '43-0-0', '52-0-0', '53-0-0', '165-0-0'];
|
||||||
for (const key of payloadKeys) {
|
for (const key of payloadKeys) {
|
||||||
if (droneData[key] && (droneData[key].gimbal_pitch !== undefined || droneData[key].gimbal_yaw !== undefined)) {
|
if (effectiveDroneData[key] && (effectiveDroneData[key].gimbal_pitch !== undefined || effectiveDroneData[key].gimbal_yaw !== undefined)) {
|
||||||
gimbalPayload = droneData[key];
|
gimbalPayload = effectiveDroneData[key];
|
||||||
console.log('[FlightData] 找到云台数据在 key:', key, gimbalPayload);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果常见索引没找到,遍历所有数字格式的key
|
// 如果常见索引没找到,遍历所有数字格式的key
|
||||||
if (!gimbalPayload.gimbal_pitch && !gimbalPayload.gimbal_yaw) {
|
if (!gimbalPayload.gimbal_pitch && !gimbalPayload.gimbal_yaw) {
|
||||||
for (const key of Object.keys(droneData)) {
|
for (const key of Object.keys(effectiveDroneData)) {
|
||||||
if (/^\d+-\d+-\d+$/.test(key) && droneData[key]?.gimbal_pitch !== undefined) {
|
if (/^\d+-\d+-\d+$/.test(key) && effectiveDroneData[key]?.gimbal_pitch !== undefined) {
|
||||||
gimbalPayload = droneData[key];
|
gimbalPayload = effectiveDroneData[key];
|
||||||
console.log('[FlightData] 遍历找到云台数据在 key:', key);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pitch = droneData?.attitude_pitch ?? 0;
|
// 使用 effectiveDroneData 获取所有飞行数据
|
||||||
const roll = droneData?.attitude_roll ?? 0;
|
const pitch = effectiveDroneData?.attitude_pitch ?? 0;
|
||||||
const yaw = droneData?.attitude_head ?? 0;
|
const roll = effectiveDroneData?.attitude_roll ?? 0;
|
||||||
const hSpeed = droneData?.horizontal_speed ?? droneData?.ground_speed ?? 0;
|
const yaw = effectiveDroneData?.attitude_head ?? 0;
|
||||||
const vSpeed = droneData?.vertical_speed ?? 0;
|
const hSpeed = effectiveDroneData?.horizontal_speed ?? effectiveDroneData?.ground_speed ?? 0;
|
||||||
const altitude = droneData?.height ?? droneData?.elevation ?? realtimeData?.gps?.altitude ?? 0;
|
const vSpeed = effectiveDroneData?.vertical_speed ?? 0;
|
||||||
const distance = droneData?.home_distance ?? 0;
|
const altitude = effectiveDroneData?.height ?? effectiveDroneData?.elevation ?? realtimeData?.gps?.altitude ?? 0;
|
||||||
|
const distance = effectiveDroneData?.home_distance ?? 0;
|
||||||
|
|
||||||
// GPS/RTK卫星数据
|
// GPS/RTK卫星数据
|
||||||
const satellites = droneData?.position_state?.gps_number ?? dockData?.position_state?.gps_number ?? 0;
|
const satellites = effectiveDroneData?.position_state?.gps_number ?? dockData?.position_state?.gps_number ?? 0;
|
||||||
const rtkSatellites = droneData?.position_state?.rtk_number ?? dockData?.position_state?.rtk_number ?? 0;
|
const rtkSatellites = effectiveDroneData?.position_state?.rtk_number ?? dockData?.position_state?.rtk_number ?? 0;
|
||||||
const isFixed = droneData?.position_state?.is_fixed ?? dockData?.position_state?.is_fixed ?? 0;
|
const isFixed = effectiveDroneData?.position_state?.is_fixed ?? dockData?.position_state?.is_fixed ?? 0;
|
||||||
const rtkStatus = isFixed === 2 ? 'FIX' : (isFixed === 1 ? 'FLOAT' : (rtkSatellites > 0 ? 'FLOAT' : 'NONE'));
|
const rtkStatus = isFixed === 2 ? 'FIX' : (isFixed === 1 ? 'FLOAT' : (rtkSatellites > 0 ? 'FLOAT' : 'NONE'));
|
||||||
|
|
||||||
// 电池数据
|
// 电池数据 - 支持两种结构:直接的battery对象 或 嵌套的batteries数组
|
||||||
const batteryPercent = droneData?.battery?.capacity_percent ?? realtimeData?.battery ?? 0;
|
const batteryData = effectiveDroneData?.battery;
|
||||||
const batteryVoltage = droneData?.battery?.voltage ?? 0;
|
const batteryPercent = batteryData?.capacity_percent ?? realtimeData?.battery ?? 0;
|
||||||
const batteryTemp = droneData?.battery?.temperature ?? 0;
|
// 电压可能在 battery.voltage 或 battery.batteries[0].voltage
|
||||||
const remainFlightTime = droneData?.battery?.remain_flight_time ?? 0;
|
const batteryVoltage = batteryData?.voltage ?? batteryData?.batteries?.[0]?.voltage ?? 0;
|
||||||
|
// 温度可能在 battery.temperature 或 battery.batteries[0].temperature
|
||||||
|
const batteryTemp = batteryData?.temperature ?? batteryData?.batteries?.[0]?.temperature ?? 0;
|
||||||
|
const remainFlightTime = batteryData?.remain_flight_time ?? 0;
|
||||||
|
|
||||||
// 信号强度
|
// 信号强度
|
||||||
const signal = dockData?.wireless_link?.dongle_number ?? dockData?.sdr?.upward_quality ?? 0;
|
const signal = dockData?.wireless_link?.dongle_number ?? dockData?.sdr?.upward_quality ?? 0;
|
||||||
|
|
||||||
// 飞行模式
|
// 飞行模式
|
||||||
const modeCode = droneData?.mode_code ?? 0;
|
const modeCode = effectiveDroneData?.mode_code ?? 0;
|
||||||
const flightMode = FLIGHT_MODE_MAP[modeCode] || `模式${modeCode}`;
|
const flightMode = FLIGHT_MODE_MAP[modeCode] || `模式${modeCode}`;
|
||||||
|
|
||||||
// 云台角度 - 优先从 payload 中获取,否则从根级别获取
|
// 云台角度 - 优先从 payload 中获取,否则从根级别获取
|
||||||
const gimbalPitch = gimbalPayload?.gimbal_pitch ?? droneData?.gimbal_pitch ?? 0;
|
const gimbalPitch = gimbalPayload?.gimbal_pitch ?? effectiveDroneData?.gimbal_pitch ?? 0;
|
||||||
const gimbalYaw = gimbalPayload?.gimbal_yaw ?? droneData?.gimbal_yaw ?? 0;
|
const gimbalYaw = gimbalPayload?.gimbal_yaw ?? effectiveDroneData?.gimbal_yaw ?? 0;
|
||||||
const windSpeed = droneData?.wind_speed ?? 0;
|
const windSpeed = effectiveDroneData?.wind_speed ?? 0;
|
||||||
|
|
||||||
// 无人机实时经纬度 - 直接从 droneData 根级别获取
|
// 无人机实时经纬度 - 从 effectiveDroneData 获取
|
||||||
const droneLat = droneData?.latitude ?? 0;
|
const droneLat = effectiveDroneData?.latitude ?? 0;
|
||||||
const droneLng = droneData?.longitude ?? 0;
|
const droneLng = effectiveDroneData?.longitude ?? 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pitch: Number(pitch).toFixed(1),
|
pitch: Number(pitch).toFixed(1),
|
||||||
@@ -153,7 +163,7 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
latitude: Number(droneLat).toFixed(6),
|
latitude: Number(droneLat).toFixed(6),
|
||||||
longitude: Number(droneLng).toFixed(6),
|
longitude: Number(droneLng).toFixed(6),
|
||||||
};
|
};
|
||||||
}, [droneData, dockData, realtimeData]);
|
}, [droneData, rawDroneData, dockData, realtimeData]);
|
||||||
|
|
||||||
// 指令发送状态
|
// 指令发送状态
|
||||||
const [loading, setLoading] = useState<string | null>(null);
|
const [loading, setLoading] = useState<string | null>(null);
|
||||||
@@ -163,36 +173,33 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
// WebSocket连接状态
|
// WebSocket连接状态
|
||||||
const [wsConnected, setWsConnected] = useState(false);
|
const [wsConnected, setWsConnected] = useState(false);
|
||||||
|
|
||||||
|
// 视频流连接状态
|
||||||
|
const [videoConnected, setVideoConnected] = useState(false);
|
||||||
|
|
||||||
|
// 视频全屏状态
|
||||||
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
||||||
|
const videoContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// 键盘控制状态
|
||||||
|
const [activeKeys, setActiveKeys] = useState<Set<string>>(new Set());
|
||||||
|
const keyIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
// DRC模式状态 - 只需进入一次即可持续控制
|
// DRC模式状态 - 只需进入一次即可持续控制
|
||||||
const [drcMode, setDrcMode] = useState(false);
|
const [drcMode, setDrcMode] = useState(false);
|
||||||
const drcModeRef = useRef(false); // 用于在回调中访问最新状态
|
const drcModeRef = useRef(false); // 用于在回调中访问最新状态
|
||||||
|
|
||||||
// 获取设备SN
|
// WebSocket连接管理 + 无人机SSE连接管理
|
||||||
const deviceSn = device?.deviceSn;
|
|
||||||
|
|
||||||
// WebSocket连接管理 + 无人机遥测数据订阅
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible && deviceSn) {
|
if (visible && deviceSn) {
|
||||||
// 1. 连接实时控制WebSocket
|
// 1. 连接实时控制WebSocket
|
||||||
deviceControlWs.connect(deviceSn);
|
deviceControlWs.connect(deviceSn);
|
||||||
|
|
||||||
// 2. 订阅无人机遥测数据(msg_alarm)
|
// 2. 建立独立的无人机SSE连接(专门接收无人机遥测数据)
|
||||||
// 只有进入操控台时才订阅,因为大部分时间无人机不在线
|
connectDroneSSE(deviceSn);
|
||||||
console.log('[LeftControlPanel] 订阅无人机遥测数据:', deviceSn);
|
|
||||||
deviceApi.subscribeDroneTelemetry(deviceSn).then((res) => {
|
|
||||||
if (res.success) {
|
|
||||||
console.log('[LeftControlPanel] 无人机遥测数据订阅成功');
|
|
||||||
} else {
|
|
||||||
console.warn('[LeftControlPanel] 无人机遥测数据订阅失败:', res.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const unsubscribe = deviceControlWs.onStatusChange((connected) => {
|
const unsubscribe = deviceControlWs.onStatusChange((connected) => {
|
||||||
setWsConnected(connected);
|
setWsConnected(connected);
|
||||||
if (connected) {
|
if (!connected) {
|
||||||
console.log('[LeftControlPanel] 实时控制WebSocket已连接');
|
|
||||||
} else {
|
|
||||||
console.log('[LeftControlPanel] 实时控制WebSocket已断开');
|
|
||||||
// 断开时重置DRC模式状态
|
// 断开时重置DRC模式状态
|
||||||
setDrcMode(false);
|
setDrcMode(false);
|
||||||
drcModeRef.current = false;
|
drcModeRef.current = false;
|
||||||
@@ -202,20 +209,23 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
return () => {
|
return () => {
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
deviceControlWs.disconnect();
|
deviceControlWs.disconnect();
|
||||||
|
|
||||||
// 清理DRC模式状态
|
// 清理DRC模式状态
|
||||||
setDrcMode(false);
|
setDrcMode(false);
|
||||||
drcModeRef.current = false;
|
drcModeRef.current = false;
|
||||||
|
|
||||||
// 3. 取消订阅无人机遥测数据
|
// 断开无人机SSE连接
|
||||||
console.log('[LeftControlPanel] 取消订阅无人机遥测数据:', deviceSn);
|
disconnectDroneSSE(deviceSn);
|
||||||
deviceApi.unsubscribeDroneTelemetry(deviceSn).then((res) => {
|
resetDroneData();
|
||||||
if (res.success) {
|
|
||||||
console.log('[LeftControlPanel] 无人机遥测数据已取消订阅');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [visible, deviceSn]);
|
}, [visible, deviceSn, connectDroneSSE, disconnectDroneSSE, resetDroneData]);
|
||||||
|
|
||||||
|
// 监控无人机SSE连接状态(静默)
|
||||||
|
useEffect(() => {
|
||||||
|
// 清理函数
|
||||||
|
return () => {};
|
||||||
|
}, [visible, deviceSn, droneSseConnected, droneSseLoading, droneHasData, droneData]);
|
||||||
|
|
||||||
// 进入DRC模式(只需调用一次)
|
// 进入DRC模式(只需调用一次)
|
||||||
const enterDrcMode = useCallback(async () => {
|
const enterDrcMode = useCallback(async () => {
|
||||||
@@ -231,17 +241,32 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('drc');
|
setLoading('drc');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.enterDrcMode(deviceSn);
|
const res = await deviceApi.enterDrcMode(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
setDrcMode(true);
|
setDrcMode(true);
|
||||||
drcModeRef.current = true;
|
drcModeRef.current = true;
|
||||||
message.success('已进入指令飞行模式');
|
message.success('已进入指令飞行模式');
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '进入指令飞行模式失败');
|
message.error(msg || '进入指令飞行模式失败');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '进入指令飞行模式失败');
|
let errorMsg = '进入指令飞行模式失败';
|
||||||
|
if (error.response) {
|
||||||
|
const data = error.response.data;
|
||||||
|
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||||
|
} else if (error.message) {
|
||||||
|
errorMsg = error.message;
|
||||||
|
} else if (error.msg) {
|
||||||
|
errorMsg = error.msg;
|
||||||
|
} else if (error.resp_msg) {
|
||||||
|
errorMsg = error.resp_msg;
|
||||||
|
}
|
||||||
|
message.error(errorMsg);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(null);
|
setLoading(null);
|
||||||
@@ -262,10 +287,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('return');
|
setLoading('return');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.returnHome(deviceSn);
|
const res = await deviceApi.returnHome(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('返航命令已发送');
|
message.success('返航命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '返航命令发送失败');
|
message.error(msg || '返航命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '返航命令发送失败');
|
message.error(error.message || '返航命令发送失败');
|
||||||
@@ -286,10 +315,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('cancelReturn');
|
setLoading('cancelReturn');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.cancelReturnHome(deviceSn);
|
const res = await deviceApi.cancelReturnHome(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('取消返航命令已发送');
|
message.success('取消返航命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '取消返航命令发送失败');
|
message.error(msg || '取消返航命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '取消返航命令发送失败');
|
message.error(error.message || '取消返航命令发送失败');
|
||||||
@@ -308,10 +341,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('pause');
|
setLoading('pause');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.pause(deviceSn);
|
const res = await deviceApi.pause(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('航线暂停/悬停命令已发送');
|
message.success('航线暂停/悬停命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '暂停命令发送失败');
|
message.error(msg || '暂停命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '暂停命令发送失败');
|
message.error(error.message || '暂停命令发送失败');
|
||||||
@@ -330,10 +367,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('resume');
|
setLoading('resume');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.resume(deviceSn);
|
const res = await deviceApi.resume(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('航线恢复命令已发送');
|
message.success('航线恢复命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '恢复命令发送失败');
|
message.error(msg || '恢复命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '恢复命令发送失败');
|
message.error(error.message || '恢复命令发送失败');
|
||||||
@@ -354,11 +395,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
// camera_mode: 0=拍照模式, 1=录像模式
|
// camera_mode: 0=拍照模式, 1=录像模式
|
||||||
const cameraModeValue = mode === 'photo' ? 0 : 1;
|
const cameraModeValue = mode === 'photo' ? 0 : 1;
|
||||||
const res = await deviceApi.switchCameraMode(deviceSn, cameraModeValue);
|
const res = await deviceApi.switchCameraMode(deviceSn, cameraModeValue);
|
||||||
if (res?.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res?.resp_code !== undefined ? res.resp_code : res?.code;
|
||||||
|
const msg = res?.resp_msg !== undefined ? res.resp_msg : res?.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
setCameraMode(mode);
|
setCameraMode(mode);
|
||||||
message.success(`已切换到${mode === 'photo' ? '拍照' : '录像'}模式`);
|
message.success(`已切换到${mode === 'photo' ? '拍照' : '录像'}模式`);
|
||||||
} else {
|
} else {
|
||||||
message.error(res?.msg || '切换相机模式失败');
|
message.error(msg || '切换相机模式失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '切换相机模式失败');
|
message.error(error.message || '切换相机模式失败');
|
||||||
@@ -382,10 +427,14 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('photo');
|
setLoading('photo');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.takePhoto(deviceSn);
|
const res = await deviceApi.takePhoto(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('拍照命令已发送');
|
message.success('拍照命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '拍照命令发送失败');
|
message.error(msg || '拍照命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '拍照命令发送失败');
|
message.error(error.message || '拍照命令发送失败');
|
||||||
@@ -409,11 +458,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('recording');
|
setLoading('recording');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.startRecording(deviceSn);
|
const res = await deviceApi.startRecording(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
setIsRecording(true);
|
setIsRecording(true);
|
||||||
message.success('开始录像命令已发送');
|
message.success('开始录像命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '开始录像命令发送失败');
|
message.error(msg || '开始录像命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '开始录像命令发送失败');
|
message.error(error.message || '开始录像命令发送失败');
|
||||||
@@ -432,11 +485,15 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
setLoading('recording');
|
setLoading('recording');
|
||||||
try {
|
try {
|
||||||
const res = await deviceApi.stopRecording(deviceSn);
|
const res = await deviceApi.stopRecording(deviceSn);
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
setIsRecording(false);
|
setIsRecording(false);
|
||||||
message.success('停止录像命令已发送');
|
message.success('停止录像命令已发送');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '停止录像命令发送失败');
|
message.error(msg || '停止录像命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '停止录像命令发送失败');
|
message.error(error.message || '停止录像命令发送失败');
|
||||||
@@ -521,8 +578,123 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
}
|
}
|
||||||
}, [deviceSn, wsConnected, enterDrcMode]);
|
}, [deviceSn, wsConnected, enterDrcMode]);
|
||||||
|
|
||||||
|
// 键盘按键映射
|
||||||
|
const keyMappings: Record<string, { type: 'stick' | 'gimbal'; direction: string }> = {
|
||||||
|
'w': { type: 'stick', direction: 'forward' }, // 前进
|
||||||
|
's': { type: 'stick', direction: 'backward' }, // 后退
|
||||||
|
'a': { type: 'stick', direction: 'left' }, // 左转
|
||||||
|
'd': { type: 'stick', direction: 'right' }, // 右转
|
||||||
|
'q': { type: 'stick', direction: 'moveLeft' }, // 向左平移
|
||||||
|
'e': { type: 'stick', direction: 'moveRight' }, // 向右平移
|
||||||
|
'r': { type: 'stick', direction: 'up' }, // 上升
|
||||||
|
'f': { type: 'stick', direction: 'down' }, // 下降
|
||||||
|
'arrowup': { type: 'gimbal', direction: 'up' }, // 云台上仰
|
||||||
|
'arrowdown': { type: 'gimbal', direction: 'down' },// 云台下俯
|
||||||
|
'arrowleft': { type: 'gimbal', direction: 'left' },// 云台左转
|
||||||
|
'arrowright': { type: 'gimbal', direction: 'right' },// 云台右转
|
||||||
|
};
|
||||||
|
|
||||||
|
// 处理键盘控制
|
||||||
|
const handleKeyboardControl = useCallback(() => {
|
||||||
|
if (activeKeys.size === 0) return;
|
||||||
|
|
||||||
|
activeKeys.forEach(key => {
|
||||||
|
const mapping = keyMappings[key];
|
||||||
|
if (mapping) {
|
||||||
|
if (mapping.type === 'stick') {
|
||||||
|
handleStickControl(mapping.direction);
|
||||||
|
} else {
|
||||||
|
handleGimbalControl(mapping.direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [activeKeys, handleStickControl, handleGimbalControl]);
|
||||||
|
|
||||||
|
// 键盘事件监听
|
||||||
|
useEffect(() => {
|
||||||
|
if (!visible || !wsConnected) return;
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
|
if (keyMappings[key] && !activeKeys.has(key)) {
|
||||||
|
e.preventDefault();
|
||||||
|
setActiveKeys(prev => new Set(prev).add(key));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyUp = (e: KeyboardEvent) => {
|
||||||
|
const key = e.key.toLowerCase();
|
||||||
|
if (keyMappings[key]) {
|
||||||
|
e.preventDefault();
|
||||||
|
setActiveKeys(prev => {
|
||||||
|
const newSet = new Set(prev);
|
||||||
|
newSet.delete(key);
|
||||||
|
return newSet;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
window.addEventListener('keyup', handleKeyUp);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('keydown', handleKeyDown);
|
||||||
|
window.removeEventListener('keyup', handleKeyUp);
|
||||||
|
setActiveKeys(new Set());
|
||||||
|
};
|
||||||
|
}, [visible, wsConnected]);
|
||||||
|
|
||||||
|
// 持续发送控制指令
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeKeys.size > 0 && wsConnected) {
|
||||||
|
// 立即执行一次
|
||||||
|
handleKeyboardControl();
|
||||||
|
// 然后每100ms执行一次
|
||||||
|
keyIntervalRef.current = setInterval(handleKeyboardControl, 100);
|
||||||
|
} else {
|
||||||
|
if (keyIntervalRef.current) {
|
||||||
|
clearInterval(keyIntervalRef.current);
|
||||||
|
keyIntervalRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (keyIntervalRef.current) {
|
||||||
|
clearInterval(keyIntervalRef.current);
|
||||||
|
keyIntervalRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [activeKeys, wsConnected, handleKeyboardControl]);
|
||||||
|
|
||||||
|
// 全屏切换
|
||||||
|
const toggleFullscreen = useCallback(() => {
|
||||||
|
if (!videoContainerRef.current) return;
|
||||||
|
|
||||||
|
if (!isFullscreen) {
|
||||||
|
if (videoContainerRef.current.requestFullscreen) {
|
||||||
|
videoContainerRef.current.requestFullscreen();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (document.exitFullscreen) {
|
||||||
|
document.exitFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isFullscreen]);
|
||||||
|
|
||||||
|
// 监听全屏变化
|
||||||
|
useEffect(() => {
|
||||||
|
const handleFullscreenChange = () => {
|
||||||
|
setIsFullscreen(!!document.fullscreenElement);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('fullscreenchange', handleFullscreenChange);
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('fullscreenchange', handleFullscreenChange);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${styles.leftPanel} ${visible ? styles.visible : ''}`}>
|
<div className={`${styles.leftPanel} ${visible ? styles.visible : ''} ${isFullscreen ? styles.fullscreen : ''}`}>
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
<div className={styles.title}>
|
<div className={styles.title}>
|
||||||
<VideoCameraOutlined />
|
<VideoCameraOutlined />
|
||||||
@@ -534,73 +706,122 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.videoContainer}>
|
|
||||||
<div className={styles.videoPlaceholder}>
|
<div className={styles.videoContainer} ref={videoContainerRef}>
|
||||||
<VideoCameraOutlined className={styles.icon} />
|
{/* 使用 WHEP WebRTC 播放器 */}
|
||||||
<span>等待图传信号...</span>
|
{videoStreamUrl ? (
|
||||||
<span style={{fontSize: 12, marginTop: 8}}>{device?.deviceSn || '未选择设备'}</span>
|
<WhepPlayer
|
||||||
|
url={videoStreamUrl}
|
||||||
|
autoPlay={visible}
|
||||||
|
muted={true}
|
||||||
|
videoOnly={true}
|
||||||
|
onConnectionChange={setVideoConnected}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className={styles.videoPlaceholder}>
|
||||||
|
<VideoCameraOutlined className={styles.icon} />
|
||||||
|
<span>未配置视频流地址</span>
|
||||||
|
<span style={{fontSize: 12, marginTop: 8}}>{device?.deviceSn || '未选择设备'}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 简化的HUD - 左上角状态指示 */}
|
||||||
|
<div className={styles.hudTopLeft}>
|
||||||
|
<div className={styles.statusLine}>
|
||||||
|
<span className={droneData ? styles.statusOk : styles.statusErr}>●</span>
|
||||||
|
{flightData.flightMode}
|
||||||
|
</div>
|
||||||
|
<div className={styles.statusLine}>
|
||||||
|
<span className={videoConnected ? styles.statusOk : styles.statusErr}>●</span>
|
||||||
|
图传
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.hudOverlay}>
|
|
||||||
<div className={styles.crosshair} />
|
{/* 简化的HUD - 右上角电池 */}
|
||||||
{/* HUD左上角 - 飞行模式和状态 */}
|
<div className={styles.hudTopRight}>
|
||||||
<div style={{position: 'absolute', top: 10, left: 10, color: '#0f0', fontSize: 12, fontFamily: 'monospace'}}>
|
<span style={{color: Number(flightData.batteryPercent) > 30 ? '#0f0' : '#f00'}}>
|
||||||
MODE: {flightData.flightMode}<br/>
|
{flightData.batteryPercent}%
|
||||||
<span style={{color: droneData ? '#0f0' : '#f00'}}>
|
</span>
|
||||||
{droneData ? '● 遥测正常' : '○ 等待遥测'}
|
<span style={{color: '#888', fontSize: 10}}>{flightData.batteryVoltage}V</span>
|
||||||
</span><br/>
|
</div>
|
||||||
GIMBAL: P{flightData.gimbalPitch}° Y{flightData.gimbalYaw}°
|
|
||||||
</div>
|
{/* 简化的HUD - 底部数据条 */}
|
||||||
{/* HUD左下角 - 无人机GPS坐标和高度 */}
|
<div className={styles.hudBottom}>
|
||||||
<div style={{position: 'absolute', bottom: 30, left: 10, color: '#0ff', fontSize: 11, fontFamily: 'monospace'}}>
|
<span>H:{flightData.altitude}m</span>
|
||||||
<AimOutlined style={{marginRight: 4}} />
|
<span>D:{flightData.distance}m</span>
|
||||||
LAT: {flightData.latitude}°<br/>
|
<span>HS:{flightData.hSpeed}</span>
|
||||||
<span style={{marginLeft: 16}}>LNG: {flightData.longitude}°</span><br/>
|
<span>VS:{flightData.vSpeed}</span>
|
||||||
<span style={{marginLeft: 16}}>ALT: {flightData.altitude}m</span>
|
</div>
|
||||||
</div>
|
|
||||||
{/* HUD右上角 - 电池信息 */}
|
{/* 云台角度指示 - 左下角小字 */}
|
||||||
<div style={{position: 'absolute', top: 10, right: 10, color: '#fff', fontSize: 12, fontFamily: 'monospace', textAlign: 'right'}}>
|
<div className={styles.hudBottomLeft}>
|
||||||
<span style={{color: Number(flightData.batteryPercent) > 30 ? '#0f0' : '#f00'}}>
|
<AimOutlined /> P{flightData.gimbalPitch}° Y{flightData.gimbalYaw}°
|
||||||
BAT: {flightData.batteryPercent}%
|
</div>
|
||||||
</span><br/>
|
|
||||||
{flightData.batteryVoltage}V / {flightData.batteryTemp}°C<br/>
|
{/* 浮动控制按钮组 - 右侧 */}
|
||||||
<span style={{color: '#0ff'}}>剩余: {flightData.remainFlightTime}min</span>
|
<div className={styles.floatingControls}>
|
||||||
</div>
|
{/* 全屏按钮 */}
|
||||||
{/* HUD底部状态条 */}
|
<Tooltip title={isFullscreen ? '退出全屏' : '全屏'} placement="left">
|
||||||
<div style={{
|
<button className={styles.floatBtn} onClick={toggleFullscreen}>
|
||||||
position: 'absolute', bottom: 10, left: 10, right: 10,
|
{isFullscreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
|
||||||
display: 'flex', justifyContent: 'space-between',
|
</button>
|
||||||
color: '#fff', fontSize: 12, textShadow: '0 0 2px #000'
|
</Tooltip>
|
||||||
}}>
|
|
||||||
<span>H: {flightData.altitude}m</span>
|
{/* 拍照按钮 */}
|
||||||
<span>D: {flightData.distance}m</span>
|
<Tooltip title="拍照 (Space)" placement="left">
|
||||||
<span>H.S: {flightData.hSpeed}m/s</span>
|
<button
|
||||||
<span>V.S: {flightData.vSpeed}m/s</span>
|
className={styles.floatBtn}
|
||||||
<span>WIND: {flightData.windSpeed}m/s</span>
|
onClick={handleTakePhoto}
|
||||||
</div>
|
disabled={loading === 'photo'}
|
||||||
|
>
|
||||||
|
{loading === 'photo' ? <LoadingOutlined /> : <CameraOutlined />}
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
{/* 录像按钮 */}
|
||||||
|
<Tooltip title={isRecording ? '停止录像' : '开始录像'} placement="left">
|
||||||
|
<button
|
||||||
|
className={`${styles.floatBtn} ${isRecording ? styles.recording : ''}`}
|
||||||
|
onClick={isRecording ? handleStopRecording : handleStartRecording}
|
||||||
|
disabled={loading === 'recording'}
|
||||||
|
>
|
||||||
|
{loading === 'recording' ? <LoadingOutlined /> : (isRecording ? <StopOutlined /> : <PlayCircleOutlined />)}
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* DRC模式和连接状态指示 - 左下 */}
|
||||||
|
<div className={styles.connectionStatus}>
|
||||||
|
{wsConnected ? (
|
||||||
|
<LinkOutlined style={{ color: '#00ff88' }} />
|
||||||
|
) : (
|
||||||
|
<DisconnectOutlined style={{ color: '#ff4444' }} />
|
||||||
|
)}
|
||||||
|
{drcMode && <Tag color="green" style={{ marginLeft: 4, fontSize: 10 }}>DRC</Tag>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 飞行仪表盘区域 */}
|
{/* 飞行仪表盘区域 - 更紧凑 */}
|
||||||
<div className={styles.flightDashboard}>
|
<div className={styles.flightDashboard}>
|
||||||
<Tooltip title="俯仰角 - 无人机前后倾斜角度">
|
<Tooltip title="俯仰角">
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}><CompassOutlined /> PITCH</div>
|
<div className={styles.dashLabel}>PITCH</div>
|
||||||
<div className={styles.dashValue}>{flightData.pitch}°</div>
|
<div className={styles.dashValue}>{flightData.pitch}°</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="横滚角 - 无人机左右倾斜角度">
|
<Tooltip title="横滚角">
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}><CompassOutlined /> ROLL</div>
|
<div className={styles.dashLabel}>ROLL</div>
|
||||||
<div className={styles.dashValue}>{flightData.roll}°</div>
|
<div className={styles.dashValue}>{flightData.roll}°</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="偏航角 - 无人机航向角度">
|
<Tooltip title="偏航角">
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}><CompassOutlined /> YAW</div>
|
<div className={styles.dashLabel}>YAW</div>
|
||||||
<div className={styles.dashValue}>{flightData.yaw}°</div>
|
<div className={styles.dashValue}>{flightData.yaw}°</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title={`RTK定位状态 (RTK卫星数: ${flightData.rtkSatellites})`}>
|
<Tooltip title={`RTK (${flightData.rtkSatellites}星)`}>
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}>RTK</div>
|
<div className={styles.dashLabel}>RTK</div>
|
||||||
<div className={styles.dashValue} style={{
|
<div className={styles.dashValue} style={{
|
||||||
@@ -611,7 +832,7 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="GPS卫星数量">
|
<Tooltip title="GPS卫星数">
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}>SAT</div>
|
<div className={styles.dashLabel}>SAT</div>
|
||||||
<div className={styles.dashValue} style={{
|
<div className={styles.dashValue} style={{
|
||||||
@@ -622,9 +843,9 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title="图传信号质量">
|
<Tooltip title="信号质量">
|
||||||
<div className={styles.dashItem}>
|
<div className={styles.dashItem}>
|
||||||
<div className={styles.dashLabel}><WifiOutlined /> LINK</div>
|
<div className={styles.dashLabel}>LINK</div>
|
||||||
<div className={styles.dashValue} style={{
|
<div className={styles.dashValue} style={{
|
||||||
color: flightData.signal >= 70 ? '#00ff88' :
|
color: flightData.signal >= 70 ? '#00ff88' :
|
||||||
flightData.signal >= 40 ? '#ffaa00' : '#ff4444'
|
flightData.signal >= 40 ? '#ffaa00' : '#ff4444'
|
||||||
@@ -638,113 +859,54 @@ const LeftControlPanel: React.FC<LeftControlPanelProps> = ({
|
|||||||
<div className={styles.controlsContent}>
|
<div className={styles.controlsContent}>
|
||||||
{/* 飞行控制指令 */}
|
{/* 飞行控制指令 */}
|
||||||
<div className={styles.controlGroup}>
|
<div className={styles.controlGroup}>
|
||||||
<div className={styles.groupTitle}>飞行控制 / FLIGHT CONTROL</div>
|
<div className={styles.groupTitle}>飞行控制</div>
|
||||||
<div className={styles.flightActions}>
|
<div className={styles.flightActions}>
|
||||||
<button onClick={handleReturnHome} disabled={loading === 'return'}>
|
<button onClick={handleReturnHome} disabled={loading === 'return'}>
|
||||||
{loading === 'return' ? <LoadingOutlined /> : <HomeOutlined />} 一键返航
|
{loading === 'return' ? <LoadingOutlined /> : <HomeOutlined />} 返航
|
||||||
</button>
|
</button>
|
||||||
<button onClick={handleCancelReturn} disabled={loading === 'cancelReturn'}>
|
<button onClick={handleCancelReturn} disabled={loading === 'cancelReturn'}>
|
||||||
{loading === 'cancelReturn' ? <LoadingOutlined /> : <StopOutlined />} 取消返航
|
{loading === 'cancelReturn' ? <LoadingOutlined /> : <StopOutlined />} 取消
|
||||||
</button>
|
</button>
|
||||||
<button className={styles.danger} onClick={handlePause} disabled={loading === 'pause'}>
|
<button className={styles.danger} onClick={handlePause} disabled={loading === 'pause'}>
|
||||||
{loading === 'pause' ? <LoadingOutlined /> : <PauseCircleOutlined />} 航线暂停
|
{loading === 'pause' ? <LoadingOutlined /> : <PauseCircleOutlined />} 暂停
|
||||||
</button>
|
</button>
|
||||||
<button onClick={handleResume} disabled={loading === 'resume'}>
|
<button onClick={handleResume} disabled={loading === 'resume'}>
|
||||||
{loading === 'resume' ? <LoadingOutlined /> : <CaretRightOutlined />} 航线恢复
|
{loading === 'resume' ? <LoadingOutlined /> : <CaretRightOutlined />} 恢复
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 相机控制 */}
|
{/* 键盘控制说明 */}
|
||||||
<div className={styles.controlGroup}>
|
<div className={styles.controlGroup}>
|
||||||
<div className={styles.groupTitle}>
|
<div className={styles.groupTitle}>
|
||||||
相机控制 / CAMERA
|
<ThunderboltOutlined /> 键盘控制
|
||||||
<Tag color={cameraMode === 'photo' ? 'blue' : 'red'} style={{ marginLeft: 8 }}>
|
<span style={{ marginLeft: 8, fontSize: 11, color: wsConnected ? '#00ff88' : '#ff4444' }}>
|
||||||
{cameraMode === 'photo' ? '拍照模式' : '录像模式'}
|
{wsConnected ? '已连接' : '未连接'}
|
||||||
</Tag>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.flightActions}>
|
<div className={styles.keyboardHint}>
|
||||||
<button onClick={handleTakePhoto} disabled={loading === 'photo'}>
|
<div className={styles.keyGroup}>
|
||||||
{loading === 'photo' ? <LoadingOutlined /> : <CameraOutlined />} 拍照
|
<span className={styles.keyLabel}>飞行:</span>
|
||||||
</button>
|
<kbd>W</kbd><kbd>A</kbd><kbd>S</kbd><kbd>D</kbd>
|
||||||
{!isRecording ? (
|
<span style={{margin: '0 4px'}}>|</span>
|
||||||
<button onClick={handleStartRecording} disabled={loading === 'recording'}>
|
<kbd>Q</kbd><kbd>E</kbd> 平移
|
||||||
{loading === 'recording' ? <LoadingOutlined /> : <PlayCircleOutlined />} 开始录像
|
<span style={{margin: '0 4px'}}>|</span>
|
||||||
</button>
|
<kbd>R</kbd><kbd>F</kbd> 升降
|
||||||
) : (
|
</div>
|
||||||
<button className={styles.danger} onClick={handleStopRecording} disabled={loading === 'recording'}>
|
<div className={styles.keyGroup}>
|
||||||
{loading === 'recording' ? <LoadingOutlined /> : <StopOutlined />} 停止录像
|
<span className={styles.keyLabel}>云台:</span>
|
||||||
</button>
|
<kbd>↑</kbd><kbd>↓</kbd><kbd>←</kbd><kbd>→</kbd>
|
||||||
)}
|
</div>
|
||||||
<button onClick={() => handleSwitchCameraMode(cameraMode === 'photo' ? 'video' : 'photo')} disabled={loading === 'switchMode'}>
|
{/* 当前按下的键 */}
|
||||||
{loading === 'switchMode' ? <LoadingOutlined /> : <SwapOutlined />} 切换模式
|
{activeKeys.size > 0 && (
|
||||||
</button>
|
<div className={styles.activeKeyDisplay}>
|
||||||
</div>
|
{Array.from(activeKeys).map(key => (
|
||||||
</div>
|
<kbd key={key} className={styles.activeKey}>{key.toUpperCase()}</kbd>
|
||||||
|
))}
|
||||||
{/* 飞行姿态控制 (模拟双摇杆) */}
|
</div>
|
||||||
<div className={styles.controlGroup}>
|
|
||||||
<div className={styles.groupTitle}>
|
|
||||||
姿态控制 / ATTITUDE CONTROL
|
|
||||||
<Tooltip title={wsConnected ? '实时控制通道已连接' : '实时控制通道未连接'}>
|
|
||||||
<span style={{ marginLeft: 8, fontSize: 12 }}>
|
|
||||||
{wsConnected ? (
|
|
||||||
<LinkOutlined style={{ color: '#00ff88' }} />
|
|
||||||
) : (
|
|
||||||
<DisconnectOutlined style={{ color: '#ff4444' }} />
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
</Tooltip>
|
|
||||||
{drcMode && (
|
|
||||||
<Tag color="green" style={{ marginLeft: 8 }}>DRC模式</Tag>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.joystickArea}>
|
|
||||||
{/* 左手:升降 + 转向 */}
|
|
||||||
<div className={styles.joystickGroup}>
|
|
||||||
<div className={styles.joystickLabel}>升降 & 偏航 (Left)</div>
|
|
||||||
<div className={styles.dpad}>
|
|
||||||
<button className={styles.up} onClick={() => handleStickControl('up')} title="上升"><VerticalAlignTopOutlined /></button>
|
|
||||||
<button className={styles.left} onClick={() => handleStickControl('left')} title="左转"><RotateLeftOutlined /></button>
|
|
||||||
<button className={styles.right} onClick={() => handleStickControl('right')} title="右转"><RotateRightOutlined /></button>
|
|
||||||
<button className={styles.down} onClick={() => handleStickControl('down')} title="下降"><VerticalAlignBottomOutlined /></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 右手:前后 + 左右 */}
|
|
||||||
<div className={styles.joystickGroup}>
|
|
||||||
<div className={styles.joystickLabel}>水平移动 (Right)</div>
|
|
||||||
<div className={styles.dpad}>
|
|
||||||
<button className={styles.up} onClick={() => handleStickControl('forward')} title="前进"><ArrowUpOutlined /></button>
|
|
||||||
<button className={styles.left} onClick={() => handleStickControl('moveLeft')} title="向左"><ArrowLeftOutlined /></button>
|
|
||||||
<button className={styles.right} onClick={() => handleStickControl('moveRight')} title="向右"><ArrowRightOutlined /></button>
|
|
||||||
<button className={styles.down} onClick={() => handleStickControl('backward')} title="后退"><ArrowDownOutlined /></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 云台控制 */}
|
|
||||||
<div className={styles.controlGroup}>
|
|
||||||
<div className={styles.groupTitle}>
|
|
||||||
云台控制 / GIMBAL
|
|
||||||
{drcMode && (
|
|
||||||
<Tag color="green" style={{ marginLeft: 8 }}>DRC模式</Tag>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className={styles.joystickArea}>
|
|
||||||
<div className={styles.joystickGroup} style={{flex: 1}}>
|
|
||||||
<div className={styles.joystickLabel}>云台方向</div>
|
|
||||||
<div className={styles.dpad}>
|
|
||||||
<button className={styles.up} onClick={() => handleGimbalControl('up')} title="云台上仰"><ArrowUpOutlined /></button>
|
|
||||||
<button className={styles.left} onClick={() => handleGimbalControl('left')} title="云台左转"><ArrowLeftOutlined /></button>
|
|
||||||
<button className={styles.right} onClick={() => handleGimbalControl('right')} title="云台右转"><ArrowRightOutlined /></button>
|
|
||||||
<button className={styles.down} onClick={() => handleGimbalControl('down')} title="云台下俯"><ArrowDownOutlined /></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+20
-3
@@ -140,13 +140,30 @@ const RightPanel: React.FC<RightPanelProps> = ({
|
|||||||
maxSpeed: 5,
|
maxSpeed: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.code === 0) {
|
// 兼容两种响应格式:resp_code/resp_msg 或 code/msg
|
||||||
|
const code = res.resp_code !== undefined ? res.resp_code : res.code;
|
||||||
|
const msg = res.resp_msg !== undefined ? res.resp_msg : res.msg;
|
||||||
|
|
||||||
|
if (code === 0) {
|
||||||
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
message.success('起飞命令已发送,无人机将自动开机并起飞');
|
||||||
} else {
|
} else {
|
||||||
message.error(res.msg || '起飞命令发送失败');
|
message.error(msg || '起飞命令发送失败');
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
message.error(error.message || '起飞命令发送失败');
|
console.error('起飞命令发送失败:', error);
|
||||||
|
// 更详细的错误信息
|
||||||
|
let errorMsg = '起飞命令发送失败';
|
||||||
|
if (error.response) {
|
||||||
|
const data = error.response.data;
|
||||||
|
errorMsg = data?.resp_msg || data?.msg || error.response.statusText || errorMsg;
|
||||||
|
} else if (error.message) {
|
||||||
|
errorMsg = error.message;
|
||||||
|
} else if (error.msg) {
|
||||||
|
errorMsg = error.msg;
|
||||||
|
} else if (error.resp_msg) {
|
||||||
|
errorMsg = error.resp_msg;
|
||||||
|
}
|
||||||
|
message.error(errorMsg);
|
||||||
} finally {
|
} finally {
|
||||||
setTakeoffLoading(false);
|
setTakeoffLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -93,8 +93,16 @@ export const useTilesetLoader = (): UseTilesetLoaderResult => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 处理跨域问题:非 localhost 访问时将 CDN URL 转换为代理路径
|
||||||
|
let tilesetUrl = config.url;
|
||||||
|
const isLocalhost = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
|
||||||
|
if (!isLocalhost && tilesetUrl.includes('minicdn.goflytec.com')) {
|
||||||
|
tilesetUrl = tilesetUrl.replace('https://minicdn.goflytec.com', '');
|
||||||
|
console.log('[Tileset] 使用代理路径:', tilesetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建3DTileset - 高清晰度渲染配置
|
// 创建3DTileset - 高清晰度渲染配置
|
||||||
const tileset = await Cesium.Cesium3DTileset.fromUrl(config.url, {
|
const tileset = await Cesium.Cesium3DTileset.fromUrl(tilesetUrl, {
|
||||||
// 核心清晰度控制 - 值越小越清晰(大疆司空使用约1-2)
|
// 核心清晰度控制 - 值越小越清晰(大疆司空使用约1-2)
|
||||||
maximumScreenSpaceError: config.style?.maximumScreenSpaceError ?? 1,
|
maximumScreenSpaceError: config.style?.maximumScreenSpaceError ?? 1,
|
||||||
maximumMemoryUsage: config.style?.maximumMemoryUsage ?? 2048, // 增加内存以加载更多高精度瓦片
|
maximumMemoryUsage: config.style?.maximumMemoryUsage ?? 2048, // 增加内存以加载更多高精度瓦片
|
||||||
|
|||||||
+29
-3
@@ -13,10 +13,11 @@ let Cesium: any = null;
|
|||||||
interface CesiumContainerProps {
|
interface CesiumContainerProps {
|
||||||
tourismList: any[];
|
tourismList: any[];
|
||||||
externalSelectedTourism?: any; // 接收外部选择的景区
|
externalSelectedTourism?: any; // 接收外部选择的景区
|
||||||
|
onClearSelection?: () => void; // 清空选择的回调
|
||||||
}
|
}
|
||||||
|
|
||||||
const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
||||||
const { tourismList, externalSelectedTourism } = props;
|
const { tourismList, externalSelectedTourism, onClearSelection } = props;
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const viewerRef = useRef<any>(null);
|
const viewerRef = useRef<any>(null);
|
||||||
const entitiesRef = useRef<Map<string, any>>(new Map());
|
const entitiesRef = useRef<Map<string, any>>(new Map());
|
||||||
@@ -294,20 +295,44 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
|||||||
}
|
}
|
||||||
}, [externalSelectedTourism, loading, handleTourismSelect]);
|
}, [externalSelectedTourism, loading, handleTourismSelect]);
|
||||||
|
|
||||||
// 处理从右侧面板点击“操控”
|
// 处理从右侧面板点击"操控"
|
||||||
const handleOpenControl = useCallback((device: any, realtimeData: any) => {
|
const handleOpenControl = useCallback((device: any, realtimeData: any) => {
|
||||||
setControlDevice(device);
|
setControlDevice(device);
|
||||||
setControlRealtimeData(realtimeData);
|
setControlRealtimeData(realtimeData);
|
||||||
setLeftPanelVisible(true);
|
setLeftPanelVisible(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// 获取设备的视频流地址(从设备数据中获取)
|
||||||
|
const getVideoStreamUrl = useCallback((device: any): string | undefined => {
|
||||||
|
// 从设备配置获取视频流地址
|
||||||
|
return device?.videoStreamUrl || undefined;
|
||||||
|
}, []);
|
||||||
|
|
||||||
// 关闭右侧面板
|
// 关闭右侧面板
|
||||||
const handleRightPanelClose = useCallback(() => {
|
const handleRightPanelClose = useCallback(() => {
|
||||||
setRightPanelVisible(false);
|
setRightPanelVisible(false);
|
||||||
setSelectedTourism(null);
|
setSelectedTourism(null);
|
||||||
setLeftPanelVisible(false); // 同时也关闭左侧
|
setLeftPanelVisible(false); // 同时也关闭左侧
|
||||||
|
|
||||||
|
// 【修复】卸载所有3D模型,避免返回地球时出现渲染问题(黑洞)
|
||||||
|
if (viewerRef.current) {
|
||||||
|
unloadAllTilesets(viewerRef.current);
|
||||||
|
}
|
||||||
|
setCurrentTourismModels([]);
|
||||||
|
setTilesetPanelVisible(false);
|
||||||
|
|
||||||
|
// 【修复】重置地形为椭球地形(快速响应,避免地形问题)
|
||||||
|
if (viewerRef.current && Cesium) {
|
||||||
|
viewerRef.current.terrainProvider = new Cesium.EllipsoidTerrainProvider();
|
||||||
|
viewerRef.current.scene.globe.depthTestAgainstTerrain = false;
|
||||||
|
terrainLoadedRef.current = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 【修复】通知父组件清空景区选择框
|
||||||
|
onClearSelection?.();
|
||||||
|
|
||||||
flyToGlobal();
|
flyToGlobal();
|
||||||
}, [flyToGlobal]);
|
}, [flyToGlobal, unloadAllTilesets, onClearSelection]);
|
||||||
|
|
||||||
// ========== 3D Tiles 模型管理方法 ==========
|
// ========== 3D Tiles 模型管理方法 ==========
|
||||||
|
|
||||||
@@ -638,6 +663,7 @@ const CesiumContainer: React.FC<CesiumContainerProps> = (props) => {
|
|||||||
onClose={() => setLeftPanelVisible(false)}
|
onClose={() => setLeftPanelVisible(false)}
|
||||||
device={controlDevice}
|
device={controlDevice}
|
||||||
realtimeData={controlRealtimeData}
|
realtimeData={controlRealtimeData}
|
||||||
|
videoStreamUrl={getVideoStreamUrl(controlDevice)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 右侧数据面板 */}
|
{/* 右侧数据面板 */}
|
||||||
|
|||||||
+3
-1
@@ -8,10 +8,11 @@ interface MapContainerProps {
|
|||||||
tourismList: any[];
|
tourismList: any[];
|
||||||
onTourismClick: (tourism: any) => void;
|
onTourismClick: (tourism: any) => void;
|
||||||
selectedTourism?: any;
|
selectedTourism?: any;
|
||||||
|
onClearSelection?: () => void; // 清空选择的回调
|
||||||
}
|
}
|
||||||
|
|
||||||
const MapContainer: React.FC<MapContainerProps> = (props) => {
|
const MapContainer: React.FC<MapContainerProps> = (props) => {
|
||||||
const { mode, tourismList, onTourismClick, selectedTourism } = props;
|
const { mode, tourismList, onTourismClick, selectedTourism, onClearSelection } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.mapContainer}>
|
<div className={styles.mapContainer}>
|
||||||
@@ -25,6 +26,7 @@ const MapContainer: React.FC<MapContainerProps> = (props) => {
|
|||||||
<CesiumContainer
|
<CesiumContainer
|
||||||
tourismList={tourismList}
|
tourismList={tourismList}
|
||||||
externalSelectedTourism={selectedTourism}
|
externalSelectedTourism={selectedTourism}
|
||||||
|
onClearSelection={onClearSelection}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -94,6 +94,11 @@ const MapDashboard: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 清空景区选择(关闭设备详情页面时调用)
|
||||||
|
const handleClearSelection = () => {
|
||||||
|
setSelectedTourism(null);
|
||||||
|
};
|
||||||
|
|
||||||
// 地图模式切换
|
// 地图模式切换
|
||||||
const handleMapModeChange = (mode: MapMode) => {
|
const handleMapModeChange = (mode: MapMode) => {
|
||||||
setMapMode(mode);
|
setMapMode(mode);
|
||||||
@@ -143,7 +148,10 @@ const MapDashboard: React.FC = () => {
|
|||||||
showSearch
|
showSearch
|
||||||
placeholder="请选择景区进入..."
|
placeholder="请选择景区进入..."
|
||||||
optionFilterProp="children"
|
optionFilterProp="children"
|
||||||
|
value={selectedTourism?.id}
|
||||||
onChange={handleDropdownSelect}
|
onChange={handleDropdownSelect}
|
||||||
|
allowClear
|
||||||
|
onClear={handleClearSelection}
|
||||||
filterOption={(input, option) =>
|
filterOption={(input, option) =>
|
||||||
(option?.children as unknown as string).toLowerCase().indexOf(input.toLowerCase()) >= 0
|
(option?.children as unknown as string).toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||||
}
|
}
|
||||||
@@ -196,6 +204,7 @@ const MapDashboard: React.FC = () => {
|
|||||||
tourismList={tourismList}
|
tourismList={tourismList}
|
||||||
onTourismClick={handleTourismClick}
|
onTourismClick={handleTourismClick}
|
||||||
selectedTourism={selectedTourism} // 传递选中的景区
|
selectedTourism={selectedTourism} // 传递选中的景区
|
||||||
|
onClearSelection={handleClearSelection} // 传递清空选择的回调
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -75,8 +75,10 @@ export interface GimbalControlParams {
|
|||||||
|
|
||||||
/** 命令响应结果 */
|
/** 命令响应结果 */
|
||||||
export interface CommandResult {
|
export interface CommandResult {
|
||||||
code: number;
|
code?: number;
|
||||||
msg: string;
|
msg?: string;
|
||||||
|
resp_code?: number;
|
||||||
|
resp_msg?: string;
|
||||||
data?: string; // commandId
|
data?: string; // commandId
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +95,22 @@ export interface CommandStatus {
|
|||||||
errorMsg?: string;
|
errorMsg?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化响应格式,兼容 resp_code/resp_msg 和 code/msg 两种格式
|
||||||
|
*/
|
||||||
|
function normalizeResponse(response: any): { code: number; msg: string; data?: any } {
|
||||||
|
// 优先使用 resp_code/resp_msg,如果没有则使用 code/msg
|
||||||
|
const code = response.resp_code !== undefined ? response.resp_code : response.code;
|
||||||
|
const msg = response.resp_msg !== undefined ? response.resp_msg : response.msg;
|
||||||
|
const data = response.data;
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: code !== undefined ? code : 1, // 默认为错误
|
||||||
|
msg: msg || '',
|
||||||
|
data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const deviceApi = {
|
export const deviceApi = {
|
||||||
wayline: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
wayline: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||||
const { current, pageSize, ...rest } = params || {};
|
const { current, pageSize, ...rest } = params || {};
|
||||||
@@ -159,7 +177,7 @@ export const deviceApi = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params,
|
data: params,
|
||||||
});
|
});
|
||||||
return res as CommandResult;
|
return normalizeResponse(res);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,7 +190,7 @@ export const deviceApi = {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
params: { deviceSn },
|
params: { deviceSn },
|
||||||
});
|
});
|
||||||
return res as CommandResult;
|
return normalizeResponse(res);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user