-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mavlink: Add MAVLink inspection tool
This tool can help users on debugging of MAVLink related problems. It allows the user to see the messages that are being received by Cockpit, as well as the ones being sent. This was already useful before being merged on a situation where we needed to know if the proper `MANUAL_CONTROL` messages were being sent.
- Loading branch information
1 parent
8075768
commit 259a1b6
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<template> | ||
<div class="flex flex-col gap-4"> | ||
<div class="flex flex-row gap-4 mb-4 flex-wrap"> | ||
<div> | ||
<div class="text-lg mb-2">Available Message Types</div> | ||
<div class="mb-2 flex items-center"> | ||
<input | ||
v-model="searchQuery" | ||
type="text" | ||
placeholder="Search messages..." | ||
class="w-full px-3 py-2 bg-[#FFFFFF22] rounded-md text-white placeholder-gray-400 outline-none focus:ring-2 focus:ring-blue-500" | ||
/> | ||
<v-btn variant="outlined" class="rounded-md ml-2" @click="resetTrackedMessageTypes">Reset</v-btn> | ||
</div> | ||
<div class="bg-[#FFFFFF11] rounded-md p-2 max-h-[320px] overflow-y-auto"> | ||
<div | ||
v-for="type in filteredMessageTypes" | ||
:key="type" | ||
class="cursor-pointer hover:bg-[#FFFFFF22] p-1 rounded" | ||
:class="{ 'bg-[#FFFFFF33]': trackedMessageTypes.has(type) }" | ||
@click="toggleMessageTracking(type)" | ||
> | ||
{{ type }} | ||
</div> | ||
<div v-if="filteredMessageTypes.length === 0" class="text-gray-400 text-center p-2">No messages found</div> | ||
</div> | ||
</div> | ||
<div v-if="trackedMessageTypes.size > 0" class="w-auto mr-2"> | ||
<div class="text-lg mb-2">Message Values</div> | ||
<div class="bg-[#FFFFFF11] rounded-md p-2 w-[24rem] overflow-y-auto"> | ||
<div v-for="type in trackedMessageTypes" :key="type" class="mb-4"> | ||
<div class="font-bold mb-2">{{ type }}</div> | ||
<div class="ml-1 text-xs text-gray-400 mb-1">Incoming Messages:</div> | ||
<div v-if="messageValues.has(`in:${type}`)" class="ml-2 text-sm whitespace-pre-wrap"> | ||
<pre>{{ JSON.stringify(messageValues.get(`in:${type}`), null, 2) }}</pre> | ||
</div> | ||
<div v-else class="ml-2 text-sm text-gray-400">No incoming messages</div> | ||
<div class="ml-1 text-xs text-gray-400 mt-2 mb-1">Outgoing Messages:</div> | ||
<div v-if="messageValues.has(`out:${type}`)" class="ml-2 text-sm whitespace-pre-wrap"> | ||
<pre>{{ JSON.stringify(messageValues.get(`out:${type}`), null, 2) }}</pre> | ||
</div> | ||
<div v-else class="ml-2 text-sm text-gray-400">No outgoing messages</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, onMounted, onUnmounted, ref } from 'vue' | ||
import type { Package } from '@/libs/connection/m2r/messages/mavlink2rest' | ||
import { MAVLinkType } from '@/libs/connection/m2r/messages/mavlink2rest-enum' | ||
import { useMainVehicleStore } from '@/stores/mainVehicle' | ||
const mainVehicleStore = useMainVehicleStore() | ||
const searchQuery = ref('') | ||
const availableMessageTypes = computed(() => { | ||
return Object.values(MAVLinkType).filter((type) => typeof type === 'string') | ||
}) | ||
const filteredMessageTypes = computed(() => { | ||
const query = searchQuery.value.toLowerCase() | ||
if (!query) return availableMessageTypes.value | ||
return availableMessageTypes.value.filter((type) => type.toLowerCase().includes(query)) | ||
}) | ||
const trackedMessageTypes = ref<Set<MAVLinkType>>(new Set()) | ||
const messageValues = ref<Map<string, unknown>>(new Map()) | ||
const toggleMessageTracking = (type: MAVLinkType): void => { | ||
if (trackedMessageTypes.value.has(type)) { | ||
trackedMessageTypes.value.delete(type) | ||
messageValues.value.delete(`in:${type}`) | ||
messageValues.value.delete(`out:${type}`) | ||
} else { | ||
trackedMessageTypes.value.add(type) | ||
setupMessageListeners(type) | ||
} | ||
} | ||
const setupMessageListeners = (type: MAVLinkType): void => { | ||
try { | ||
mainVehicleStore.listenToIncomingMessages(type, (pack: Package) => { | ||
messageValues.value.set(`in:${type}`, pack.message) | ||
}) | ||
mainVehicleStore.listenToOutgoingMessages(type, (pack: Package) => { | ||
messageValues.value.set(`out:${type}`, pack.message) | ||
}) | ||
} catch (error) { | ||
console.error(`Failed to setup message listeners for type ${type}:`, error) | ||
} | ||
} | ||
const resetTrackedMessageTypes = (): void => { | ||
trackedMessageTypes.value.clear() | ||
messageValues.value.clear() | ||
} | ||
// Set up listeners for any already tracked message types | ||
onMounted(() => { | ||
trackedMessageTypes.value.forEach(setupMessageListeners) | ||
}) | ||
// Clean up when component is unmounted | ||
onUnmounted(() => { | ||
trackedMessageTypes.value.clear() | ||
messageValues.value.clear() | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<BaseConfigurationView> | ||
<template #title>MAVLink</template> | ||
<template #content> | ||
<div | ||
class="max-h-[85vh] overflow-y-auto -mr-4" | ||
:class="interfaceStore.isOnSmallScreen ? 'max-w-[85vw]' : 'max-w-[60vw]'" | ||
> | ||
<ExpansiblePanel :is-expanded="!interfaceStore.isOnPhoneScreen" no-top-divider no-bottom-divider> | ||
<template #title>Message Inspector</template> | ||
<template #content> | ||
<MAVLinkInspector /> | ||
</template> | ||
</ExpansiblePanel> | ||
</div> | ||
</template> | ||
</BaseConfigurationView> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import MAVLinkInspector from '@/components/development/MAVLinkInspector.vue' | ||
import ExpansiblePanel from '@/components/ExpansiblePanel.vue' | ||
import { useAppInterfaceStore } from '@/stores/appInterface' | ||
import BaseConfigurationView from './BaseConfigurationView.vue' | ||
const interfaceStore = useAppInterfaceStore() | ||
</script> | ||
<style scoped> | ||
.custom-header { | ||
background-color: #333 !important; | ||
color: #fff; | ||
} | ||
</style> |