航线 设备状态 装备总览界面无人机和机场实时状态接入,并且地图上就可以实时显示无人机定位,根据航向角转角度
This commit is contained in:
@@ -50,6 +50,8 @@ import VideoPlayer from '../VideoPlayer.tsx';
|
||||
import DeviceController from './DeviceController';
|
||||
import { DatePicker } from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { useMqtt } from '@/hooks/useMqtt';
|
||||
import envConfig from '../../../env';
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const { Text } = Typography;
|
||||
@@ -58,39 +60,179 @@ export default function DeviceStatusPage({
|
||||
devicesAll,
|
||||
serialNumber,
|
||||
onDeviceChange,
|
||||
mqttDroneData,
|
||||
}) {
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
|
||||
const [persistentHostData, setPersistentHostData] = useState(null); // 持久化机场数据
|
||||
|
||||
// 获取当前选中的无人机设备
|
||||
const device = useMemo(() => {
|
||||
const sn =
|
||||
serialNumber ||
|
||||
devicesAll?.[0]?.device_sn ||
|
||||
devicesAll?.[0]?.serialNumber;
|
||||
|
||||
if (!sn) return null;
|
||||
|
||||
return devicesAll?.find(
|
||||
(d) => (d.device_sn || d.serialNumber) === sn,
|
||||
);
|
||||
}, [devicesAll, serialNumber]);
|
||||
|
||||
const isUAV = useMemo(() => {
|
||||
return !!device?.device_sn;
|
||||
}, [device]);
|
||||
|
||||
// 当MQTT数据更新时,更新持久化数据(只在有新数据时更新)
|
||||
useEffect(() => {
|
||||
if (mqttDroneData && mqttDroneData.host) {
|
||||
const { host } = mqttDroneData;
|
||||
setPersistentDroneData({
|
||||
// 无人机状态数据映射
|
||||
capacity_percent: host.drone_charge_state?.capacity_percent,
|
||||
environment_temperature: host.environment_temperature,
|
||||
height: host.height,
|
||||
wind_speed: host.wind_speed,
|
||||
rainfall: host.rainfall === 0 ? 'no_rain' : 'rain',
|
||||
position_state: host.position_state,
|
||||
longitude: host.longitude,
|
||||
latitude: host.latitude,
|
||||
heading: host.heading,
|
||||
humidity: host.humidity,
|
||||
drone_in_dock: host.drone_in_dock,
|
||||
cover_state: host.cover_state,
|
||||
temperature: host.temperature,
|
||||
home_distance: host.home_distance,
|
||||
air_conditioner_state: host.air_conditioner_state,
|
||||
});
|
||||
}
|
||||
}, [mqttDroneData]);
|
||||
const handleMqttMessage = (topic, message) => {
|
||||
console.log('DeviceStatusPage MQTT 消息到达 - Topic:', topic);
|
||||
console.log('DeviceStatusPage MQTT 消息内容:', message);
|
||||
try {
|
||||
const parsedMessage = JSON.parse(message);
|
||||
console.log('DeviceStatusPage 解析后的消息:', parsedMessage);
|
||||
|
||||
// 优先使用持久化数据,保持显示稳定
|
||||
if (parsedMessage.data && parsedMessage.data.host) {
|
||||
const { host } = parsedMessage.data;
|
||||
|
||||
// 判断是无人机数据还是机场数据:无人机数据有 battery 字段
|
||||
const isDroneData = host.battery !== undefined;
|
||||
|
||||
if (isDroneData) {
|
||||
// 处理无人机数据
|
||||
setPersistentDroneData(prevData => {
|
||||
const newData = { ...prevData };
|
||||
|
||||
// 无人机特有字段
|
||||
if (host.battery?.capacity_percent !== undefined) {
|
||||
newData.capacity_percent = host.battery.capacity_percent;
|
||||
}
|
||||
if (host.attitude_head !== undefined) {
|
||||
newData.heading = host.attitude_head;
|
||||
}
|
||||
if (host.horizontal_speed !== undefined) {
|
||||
newData.horizontal_speed = host.horizontal_speed;
|
||||
}
|
||||
if (host.vertical_speed !== undefined) {
|
||||
newData.vertical_speed = host.vertical_speed;
|
||||
}
|
||||
if (host.total_flight_time !== undefined) {
|
||||
newData.total_flight_time = host.total_flight_time;
|
||||
}
|
||||
if (host.total_flight_sorties !== undefined) {
|
||||
newData.total_flight_sorties = host.total_flight_sorties;
|
||||
}
|
||||
if (host.mode_code !== undefined) {
|
||||
newData.mode_code = host.mode_code;
|
||||
}
|
||||
|
||||
// 通用字段
|
||||
if (host.height !== undefined) {
|
||||
newData.height = host.height;
|
||||
}
|
||||
if (host.wind_speed !== undefined) {
|
||||
newData.wind_speed = host.wind_speed;
|
||||
}
|
||||
if (host.position_state !== undefined) {
|
||||
newData.position_state = host.position_state;
|
||||
}
|
||||
if (host.longitude !== undefined) {
|
||||
newData.longitude = host.longitude;
|
||||
}
|
||||
if (host.latitude !== undefined) {
|
||||
newData.latitude = host.latitude;
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
} else {
|
||||
// 处理机场数据
|
||||
setPersistentHostData(prevData => {
|
||||
const newData = { ...prevData };
|
||||
|
||||
// 机场特有字段
|
||||
if (host.drone_charge_state?.capacity_percent !== undefined) {
|
||||
newData.capacity_percent = host.drone_charge_state.capacity_percent;
|
||||
}
|
||||
if (host.air_conditioner?.air_conditioner_state !== undefined) {
|
||||
newData.air_conditioner_state = host.air_conditioner.air_conditioner_state;
|
||||
}
|
||||
if (host.air_conditioner_state !== undefined) {
|
||||
newData.air_conditioner_state = host.air_conditioner_state;
|
||||
}
|
||||
|
||||
// 通用字段
|
||||
if (host.environment_temperature !== undefined) {
|
||||
newData.environment_temperature = host.environment_temperature;
|
||||
}
|
||||
if (host.wind_speed !== undefined) {
|
||||
newData.wind_speed = host.wind_speed;
|
||||
}
|
||||
if (host.rainfall !== undefined) {
|
||||
newData.rainfall = host.rainfall === 0 ? 'no_rain' : 'rain';
|
||||
}
|
||||
if (host.humidity !== undefined) {
|
||||
newData.humidity = host.humidity;
|
||||
}
|
||||
if (host.drone_in_dock !== undefined) {
|
||||
newData.drone_in_dock = host.drone_in_dock;
|
||||
}
|
||||
if (host.cover_state !== undefined) {
|
||||
newData.cover_state = host.cover_state;
|
||||
}
|
||||
if (host.temperature !== undefined) {
|
||||
newData.temperature = host.temperature;
|
||||
}
|
||||
if (host.home_distance !== undefined) {
|
||||
newData.home_distance = host.home_distance;
|
||||
}
|
||||
|
||||
return newData;
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('DeviceStatusPage MQTT 消息解析失败:', err);
|
||||
}
|
||||
};
|
||||
|
||||
// 根据选中设备动态构建MQTT主题
|
||||
const mqttTopics = useMemo(() => {
|
||||
if (!isUAV || !device) {
|
||||
return [];
|
||||
}
|
||||
const topics = [];
|
||||
if (device.device_sn) {
|
||||
topics.push(`thing/product/${device.device_sn}/osd`);
|
||||
}
|
||||
if (device.gateway_sn && device.gateway_sn !== device.device_sn) {
|
||||
topics.push(`thing/product/${device.gateway_sn}/osd`);
|
||||
}
|
||||
console.log('DeviceStatusPage 订阅的MQTT主题:', topics);
|
||||
return topics;
|
||||
}, [isUAV, device]);
|
||||
|
||||
// 订阅MQTT消息
|
||||
useMqtt({
|
||||
url: envConfig.mqtt_url,
|
||||
topic: mqttTopics,
|
||||
onMessage: handleMqttMessage,
|
||||
});
|
||||
|
||||
// 合并无人机和机场数据
|
||||
const currentDroneData = React.useMemo(() => {
|
||||
return persistentDroneData;
|
||||
return { ...persistentHostData, ...persistentDroneData };
|
||||
}, [persistentDroneData, persistentHostData]);
|
||||
|
||||
// 实时位置数据(用于地图)
|
||||
const realtimePosition = React.useMemo(() => {
|
||||
if (persistentDroneData?.longitude && persistentDroneData?.latitude) {
|
||||
return {
|
||||
lon: persistentDroneData.longitude,
|
||||
lat: persistentDroneData.latitude,
|
||||
heading: persistentDroneData.heading
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}, [persistentDroneData]);
|
||||
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
@@ -121,23 +263,6 @@ export default function DeviceStatusPage({
|
||||
const [points, setPoints] = useState([]);
|
||||
const timerRef = useRef<any>(null);
|
||||
|
||||
const device = useMemo(() => {
|
||||
const sn =
|
||||
serialNumber ||
|
||||
devicesAll?.[0]?.device_sn ||
|
||||
devicesAll?.[0]?.serialNumber;
|
||||
|
||||
if (!sn) return null;
|
||||
|
||||
return devicesAll?.find(
|
||||
(d) => (d.device_sn || d.serialNumber) === sn,
|
||||
);
|
||||
}, [devicesAll, serialNumber]);
|
||||
|
||||
const isUAV = useMemo(() => {
|
||||
return !!device?.device_sn;
|
||||
}, [device]);
|
||||
|
||||
const runningStatus = useMemo(() => {
|
||||
const base = device?.lastRunningStatus || {};
|
||||
|
||||
@@ -525,7 +650,12 @@ export default function DeviceStatusPage({
|
||||
height: 400,
|
||||
}}
|
||||
>
|
||||
<CesiumMap devices={[mapDevices]} points={points} />
|
||||
<CesiumMap
|
||||
devices={[mapDevices]}
|
||||
points={points}
|
||||
realtimePosition={realtimePosition}
|
||||
realtimeType="plane"
|
||||
/>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
@@ -544,8 +674,18 @@ export default function DeviceStatusPage({
|
||||
<Descriptions.Item label={<><EnvironmentOutlined /> 飞行高度</>}>
|
||||
<Text strong style={{ fontSize: 16 }}>{fix2((currentDroneData || uavState || device).height)} m</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境风速"><Text>{fix2((currentDroneData || uavState || device).wind_speed)} m/s</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="环境温度"><Text>{fix2((currentDroneData || uavState || device).environment_temperature)} ℃</Text></Descriptions.Item>
|
||||
<Descriptions.Item label="水平速度">
|
||||
<Text>{fix2(currentDroneData?.horizontal_speed) || '-'} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="垂直速度">
|
||||
<Text>{fix2(currentDroneData?.vertical_speed) || '-'} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境风速">
|
||||
<Text>{fix2((currentDroneData || uavState || device).wind_speed)} m/s</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境温度">
|
||||
<Text>{fix2((currentDroneData || uavState || device).environment_temperature)} ℃</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="环境湿度">
|
||||
<Text>{(currentDroneData?.humidity) || '-'}{currentDroneData?.humidity ? '%' : ''}</Text>
|
||||
</Descriptions.Item>
|
||||
@@ -555,10 +695,16 @@ export default function DeviceStatusPage({
|
||||
<Descriptions.Item label="降雨状态">
|
||||
<Tag color={(currentDroneData || uavState || device).rainfall === 'no_rain' ? 'green' : 'red'}>{getVal((currentDroneData || uavState || device).rainfall)}</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="返航距离"><Text>{fix2((currentDroneData || uavState || device).home_distance)} m</Text></Descriptions.Item>
|
||||
|
||||
<Descriptions.Item label="航向角">
|
||||
<Text>{fix2(currentDroneData?.heading)}°</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="飞行模式">
|
||||
<Tag color="blue">
|
||||
{currentDroneData?.mode_code !== undefined ? `模式 ${currentDroneData.mode_code}` : '-'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
|
||||
<Descriptions.Item label="无人机位置">
|
||||
<Tag color="blue">
|
||||
{currentDroneData?.drone_in_dock === 1 ? '在库' : '外出'}
|
||||
@@ -580,11 +726,17 @@ export default function DeviceStatusPage({
|
||||
<Descriptions.Item label="RTK 卫星数">
|
||||
<Badge count={(currentDroneData || uavState || device).position_state?.rtk_number || 0} style={{ backgroundColor: '#52c41a' }} />
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="RTK 状态" span={2}>
|
||||
<Tag color={(currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
|
||||
{(currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
|
||||
<Descriptions.Item label="RTK 状态">
|
||||
<Tag color={(currentDroneData || uavState || device).position_state?.is_fixed === 2 || (currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'success' : 'warning'}>
|
||||
{(currentDroneData || uavState || device).position_state?.is_fixed === 2 || (currentDroneData || uavState || device).position_state?.is_fixed === 'fixing_successful' ? 'RTK 已固定' : '未固定'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="实时经纬度" span={2}>
|
||||
<Text style={{ fontSize: '12px' }}>
|
||||
{currentDroneData?.latitude && currentDroneData?.longitude ?
|
||||
`${currentDroneData.latitude.toFixed(6)}, ${currentDroneData.longitude.toFixed(6)}` : '-'}
|
||||
</Text>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
) : (
|
||||
<Descriptions column={2} size="small" layout="vertical">
|
||||
|
||||
Reference in New Issue
Block a user