feat: 无人机视频播放
This commit is contained in:
+183
@@ -0,0 +1,183 @@
|
||||
package com.central.device.websocket.model;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 无人机实时数据
|
||||
* 专门存储无人机的实时遥测数据(msg_alarm)
|
||||
* 与机库数据完全分离
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-12-11
|
||||
*/
|
||||
@Data
|
||||
public class DroneRealtimeData {
|
||||
/**
|
||||
* 设备SN
|
||||
*/
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 是否在线
|
||||
*/
|
||||
private boolean online;
|
||||
|
||||
/**
|
||||
* 最后消息时间戳
|
||||
*/
|
||||
private long lastMessageTime;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private Double latitude;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private Double longitude;
|
||||
|
||||
/**
|
||||
* 高度(m)
|
||||
*/
|
||||
private Double height;
|
||||
|
||||
/**
|
||||
* 海拔(m)
|
||||
*/
|
||||
private Double elevation;
|
||||
|
||||
/**
|
||||
* 水平速度(m/s)
|
||||
*/
|
||||
private Double horizontalSpeed;
|
||||
|
||||
/**
|
||||
* 垂直速度(m/s)
|
||||
*/
|
||||
private Double verticalSpeed;
|
||||
|
||||
/**
|
||||
* 风速(m/s)
|
||||
*/
|
||||
private Double windSpeed;
|
||||
|
||||
/**
|
||||
* 姿态 - 俯仰角(度)
|
||||
*/
|
||||
private Double attitudePitch;
|
||||
|
||||
/**
|
||||
* 姿态 - 横滚角(度)
|
||||
*/
|
||||
private Double attitudeRoll;
|
||||
|
||||
/**
|
||||
* 姿态 - 偏航角(度)
|
||||
*/
|
||||
private Double attitudeYaw;
|
||||
|
||||
/**
|
||||
* 返航高度(m)
|
||||
*/
|
||||
private Integer rthAltitude;
|
||||
|
||||
/**
|
||||
* 国家代码
|
||||
*/
|
||||
private String country;
|
||||
|
||||
/**
|
||||
* 原始无人机数据
|
||||
*/
|
||||
private JSONObject rawData;
|
||||
|
||||
/**
|
||||
* 从原始无人机数据创建
|
||||
*/
|
||||
public static DroneRealtimeData fromRawData(String deviceSn, JSONObject rawDroneData) {
|
||||
if (rawDroneData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DroneRealtimeData droneData = new DroneRealtimeData();
|
||||
droneData.setDeviceSn(deviceSn);
|
||||
droneData.setOnline(true);
|
||||
droneData.setLastMessageTime(System.currentTimeMillis());
|
||||
droneData.setRawData(rawDroneData);
|
||||
|
||||
// 提取字段
|
||||
droneData.setLatitude(rawDroneData.getDouble("latitude"));
|
||||
droneData.setLongitude(rawDroneData.getDouble("longitude"));
|
||||
droneData.setHeight(rawDroneData.getDouble("height"));
|
||||
droneData.setElevation(rawDroneData.getDouble("elevation"));
|
||||
droneData.setHorizontalSpeed(rawDroneData.getDouble("horizontal_speed"));
|
||||
droneData.setVerticalSpeed(rawDroneData.getDouble("vertical_speed"));
|
||||
droneData.setWindSpeed(rawDroneData.getDouble("wind_speed"));
|
||||
droneData.setAttitudePitch(rawDroneData.getDouble("attitude_pitch"));
|
||||
droneData.setAttitudeRoll(rawDroneData.getDouble("attitude_roll"));
|
||||
droneData.setAttitudeYaw(rawDroneData.getDouble("attitude_yaw"));
|
||||
droneData.setRthAltitude(rawDroneData.getInteger("rth_altitude"));
|
||||
droneData.setCountry(rawDroneData.getString("country"));
|
||||
|
||||
return droneData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为前端兼容的JSON对象(使用下划线命名)
|
||||
*/
|
||||
public JSONObject toFrontendJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
// 基本字段
|
||||
json.put("deviceSn", deviceSn);
|
||||
|
||||
// 位置字段
|
||||
json.put("latitude", latitude);
|
||||
json.put("longitude", longitude);
|
||||
json.put("height", height);
|
||||
json.put("elevation", elevation);
|
||||
json.put("home_distance", 0); // 需要从原始数据获取
|
||||
|
||||
// 速度字段
|
||||
json.put("horizontal_speed", horizontalSpeed);
|
||||
json.put("vertical_speed", verticalSpeed);
|
||||
json.put("ground_speed", horizontalSpeed); // 使用水平速度作为地面速度
|
||||
|
||||
// 姿态字段
|
||||
json.put("attitude_pitch", attitudePitch);
|
||||
json.put("attitude_roll", attitudeRoll);
|
||||
json.put("attitude_head", attitudeYaw); // 注意:前端使用 attitude_head
|
||||
|
||||
// 电池字段
|
||||
if (rawData != null && rawData.containsKey("battery")) {
|
||||
json.put("battery", rawData.getJSONObject("battery"));
|
||||
}
|
||||
|
||||
// 飞行模式
|
||||
if (rawData != null) {
|
||||
json.put("mode_code", rawData.getInteger("mode_code"));
|
||||
json.put("gear", rawData.getInteger("gear"));
|
||||
}
|
||||
|
||||
// 位置状态
|
||||
if (rawData != null && rawData.containsKey("position_state")) {
|
||||
json.put("position_state", rawData.getJSONObject("position_state"));
|
||||
}
|
||||
|
||||
// 飞行状态
|
||||
if (rawData != null) {
|
||||
json.put("flight_status", rawData.getInteger("flight_status"));
|
||||
json.put("is_flying", rawData.getInteger("is_flying"));
|
||||
json.put("flight_time", rawData.getInteger("flight_time"));
|
||||
}
|
||||
|
||||
// 其他字段
|
||||
json.put("wind_speed", windSpeed);
|
||||
json.put("rth_altitude", rthAltitude);
|
||||
json.put("country", country);
|
||||
|
||||
return json;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user