抢夺控制权优化

main
刘妍 2025-07-10 17:20:04 +08:00
parent 5820971d5c
commit 5a7ec0e1f0
2 changed files with 46 additions and 25 deletions

View File

@ -30,12 +30,14 @@
<a-button @click="emits('clickFlyTo')"></a-button> <a-button @click="emits('clickFlyTo')"></a-button>
<!-- <a-button>智能环绕</a-button> --> <!-- <a-button>智能环绕</a-button> -->
<a-button @click="returnVoyage"></a-button> <a-button @click="returnVoyage"></a-button>
<a-button @click="obtain" style="background-color: #1b71e8; border: none" <a-button @click="obtain" style="background-color: #1b71e8; border: none">
>获取飞行器控制权</a-button <template #icon v-if="flightGrab"><CheckOutlined /></template>
> 获取飞行器控制权
<a-button @click="enterDRC" style="background-color: #24d365; border: none" </a-button>
>进入飞行控制</a-button <a-button @click="enterDRC" style="background-color: #24d365; border: none">
> <template #icon v-if="modeEnter"><CheckOutlined /></template>
进入飞行控制
</a-button>
<a-button @click="exitDRC" style="background-color: #e3150e; border: none" <a-button @click="exitDRC" style="background-color: #e3150e; border: none"
>退出飞行控制</a-button >退出飞行控制</a-button
> >
@ -84,7 +86,7 @@
destroySeizeConnection, destroySeizeConnection,
connection, connection,
} from '@/utils/mqtt'; } from '@/utils/mqtt';
import { CloseOutlined } from '@ant-design/icons-vue'; import { CloseOutlined, CheckOutlined } from '@ant-design/icons-vue';
import { vDrag } from '@/utils/drag'; import { vDrag } from '@/utils/drag';
import { drcDownTopicReize, eventsTopicSubscribeReize } from '@/utils/debugging/events'; import { drcDownTopicReize, eventsTopicSubscribeReize } from '@/utils/debugging/events';
import { import {
@ -127,7 +129,7 @@
const airportVal: any = ref({ const airportVal: any = ref({
mode_code: 0, mode_code: 0,
}); });
const bid = buildGUID();
//redis //redis
const changeRedisUser = (val: boolean) => { const changeRedisUser = (val: boolean) => {
const querys = redisUser.value; const querys = redisUser.value;
@ -158,7 +160,6 @@
emits('clickTakeOff'); emits('clickTakeOff');
changeRedisUser(true); changeRedisUser(true);
}; };
// //
const obtain = () => { const obtain = () => {
// if (!getClient()) { // if (!getClient()) {
@ -168,11 +169,15 @@
createMessage.success('当前有用户正在操作,请稍后再试'); createMessage.success('当前有用户正在操作,请稍后再试');
return; return;
} }
if (flightGrab.value) {
createMessage.warning('已经获取了飞行器控制权');
return;
}
createMessage.info('正在获取飞行器控制权,请稍候'); createMessage.info('正在获取飞行器控制权,请稍候');
changeRedisUser(true); changeRedisUser(true);
// //
servicesTopic({ servicesTopic({
bid: buildGUID(), bid: bid,
method: 'flight_authority_grab', method: 'flight_authority_grab',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
@ -180,7 +185,7 @@
}); });
// //
servicesTopic({ servicesTopic({
bid: buildGUID(), bid: bid,
method: 'payload_authority_grab', method: 'payload_authority_grab',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
@ -191,8 +196,13 @@
services_replyTopic(); services_replyTopic();
}; };
// //
const returnBtn = ref(false);
const returnVoyage = () => { const returnVoyage = () => {
// if (returnBtn.value) {
createMessage.warning('正在返航或已返航,请勿重复操作');
return;
}
returnBtn.value = true;
servicesTopic({ servicesTopic({
bid: buildGUID(), bid: buildGUID(),
method: 'return_home', method: 'return_home',
@ -200,7 +210,6 @@
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
data: {}, data: {},
}); });
// servicesTopicReize
}; };
const seq = ref(1); const seq = ref(1);
const changeDRC = (type, value) => { const changeDRC = (type, value) => {
@ -243,7 +252,7 @@
const { protocol, host, port, endpoint } = connection; const { protocol, host, port, endpoint } = connection;
const connectUrl = `${protocol}://${host}:${port}${endpoint}`; const connectUrl = `${protocol}://${host}:${port}${endpoint}`;
const querys = { const querys = {
bid: buildGUID(), bid: bid,
data: { data: {
hsi_frequency: 10, hsi_frequency: 10,
mqtt_broker: { mqtt_broker: {
@ -289,7 +298,7 @@
const exitDRC = () => { const exitDRC = () => {
createMessage.info('正在退出飞行控制,请稍后'); createMessage.info('正在退出飞行控制,请稍后');
const querys = { const querys = {
bid: buildGUID(), bid: bid,
data: {}, data: {},
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
@ -311,7 +320,7 @@
if (rs.data.mode_code || rs.data.mode_code == 0) { if (rs.data.mode_code || rs.data.mode_code == 0) {
airportVal.value.mode_code = rs.data.mode_code; airportVal.value.mode_code = rs.data.mode_code;
} }
if (rs.method == 'flight_authority_grab') { if (rs.method == 'flight_authority_grab' && rs.bid == bid) {
if (rs.data.result == 0) { if (rs.data.result == 0) {
flightGrab.value = true; flightGrab.value = true;
createMessage.success('飞行控制权抢夺成功'); createMessage.success('飞行控制权抢夺成功');
@ -320,7 +329,7 @@
createMessage.error('飞行控制权抢夺失败,' + errorName(rs.data.result)); createMessage.error('飞行控制权抢夺失败,' + errorName(rs.data.result));
} }
} }
if (rs.method == 'drc_mode_enter') { if (rs.method == 'drc_mode_enter' && rs.bid == bid) {
if (rs.data.result == 0) { if (rs.data.result == 0) {
modeEnter.value = true; modeEnter.value = true;
createMessage.success('进入指令飞行控制模式成功'); createMessage.success('进入指令飞行控制模式成功');
@ -329,10 +338,11 @@
createMessage.error('进入指令飞行控制模式失败,' + errorName(rs.data.result)); createMessage.error('进入指令飞行控制模式失败,' + errorName(rs.data.result));
} }
} }
if (rs.method == 'drc_mode_exit') { if (rs.method == 'drc_mode_exit' && rs.bid == bid) {
if (rs.data.result == 0) { if (rs.data.result == 0) {
modeEnter.value = false; modeEnter.value = false;
createMessage.success('退出指令飞行控制模式成功'); createMessage.success('退出指令飞行控制模式成功');
changeRedisUser(false);
} else { } else {
createMessage.error('退出指令飞行控制模式失败,' + errorName(rs.data.result)); createMessage.error('退出指令飞行控制模式失败,' + errorName(rs.data.result));
} }
@ -342,8 +352,10 @@
if (rs.data.result == 0) { if (rs.data.result == 0) {
createMessage.success('一键返航成功'); createMessage.success('一键返航成功');
monitorDRC.value = false; monitorDRC.value = false;
returnBtn.value = true;
} else { } else {
createMessage.error('一键返航失败,' + errorName(rs.data.result)); createMessage.error('一键返航失败,' + errorName(rs.data.result));
returnBtn.value = false;
} }
} }
if (rs.method === 'takeoff_to_point') { if (rs.method === 'takeoff_to_point') {
@ -354,7 +366,6 @@
} }
} }
if (rs.method === 'drc_status_notify' && monitorDRC.value) { if (rs.method === 'drc_status_notify' && monitorDRC.value) {
console.log('drc_status_notify', rs.data);
if (rs.data.result == 0) { if (rs.data.result == 0) {
if (rs.data.drc_state == 0) { if (rs.data.drc_state == 0) {
drc_eart_beat(); drc_eart_beat();

View File

@ -17,7 +17,10 @@
</div> </div>
<div class="content"> <div class="content">
<div class="content-button"> <div class="content-button">
<a-button @click="obtain"></a-button> <a-button @click="obtain">
<template #icon v-if="grabBtn"><CheckOutlined /></template>
获取相机控制权
</a-button>
<a-button @click="singleShot"></a-button> <a-button @click="singleShot"></a-button>
</div> </div>
<div class="direction-controller"> <div class="direction-controller">
@ -64,7 +67,7 @@
destroySeizeConnection, destroySeizeConnection,
connection, connection,
} from '@/utils/mqtt'; } from '@/utils/mqtt';
import { CloseOutlined } from '@ant-design/icons-vue'; import { CloseOutlined, CheckOutlined } from '@ant-design/icons-vue';
import { vDrag } from '@/utils/drag'; import { vDrag } from '@/utils/drag';
import { buildGUID } from '@/utils/uuid'; import { buildGUID } from '@/utils/uuid';
import { servicesTopic, services_replyTopic, errorName } from '@/utils/debugging/remote'; import { servicesTopic, services_replyTopic, errorName } from '@/utils/debugging/remote';
@ -187,7 +190,7 @@
cameraZoom(); cameraZoom();
}, },
); );
const bid = buildGUID();
// //
const cameraZoom = () => { const cameraZoom = () => {
if (!flightGrab.value) { if (!flightGrab.value) {
@ -234,6 +237,7 @@
} }
}); });
}; };
const grabBtn = ref(false);
const obtain = () => { const obtain = () => {
// if (!getClient()) { // if (!getClient()) {
// createConnection(); // createConnection();
@ -242,10 +246,14 @@
createMessage.success('当前有用户正在操作,请稍后再试'); createMessage.success('当前有用户正在操作,请稍后再试');
return; return;
} }
if (grabBtn.value) {
createMessage.warning('已经获取了飞行器控制权');
return;
}
changeRedisUser(true); changeRedisUser(true);
// //
servicesTopic({ servicesTopic({
bid: buildGUID(), bid: bid,
method: 'flight_authority_grab', method: 'flight_authority_grab',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
@ -253,7 +261,7 @@
}); });
// //
servicesTopic({ servicesTopic({
bid: buildGUID(), bid: bid,
method: 'payload_authority_grab', method: 'payload_authority_grab',
tid: buildGUID(), tid: buildGUID(),
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
@ -329,12 +337,14 @@
createMessage.error('拍照失败,' + errorName(rs.data.result)); createMessage.error('拍照失败,' + errorName(rs.data.result));
} }
} }
if (rs.method == 'flight_authority_grab') { if (rs.method == 'flight_authority_grab' && rs.bid == bid) {
if (rs.data.result == 0) { if (rs.data.result == 0) {
flightGrab.value = true; flightGrab.value = true;
grabBtn.value = true;
createMessage.success('相机控制权获取成功'); createMessage.success('相机控制权获取成功');
} else { } else {
flightGrab.value = false; flightGrab.value = false;
grabBtn.value = false;
createMessage.error('相机控制权获取失败,' + errorName(rs.data.result)); createMessage.error('相机控制权获取失败,' + errorName(rs.data.result));
} }
} }