Skip to content

Commit

Permalink
mavlink: Add MAVLink inspection tool
Browse files Browse the repository at this point in the history
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
rafaellehmkuhl committed Jan 14, 2025
1 parent 8075768 commit 259a1b6
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ import ConfigurationDevelopmentView from './views/ConfigurationDevelopmentView.v
import ConfigurationGeneralView from './views/ConfigurationGeneralView.vue'
import ConfigurationJoystickView from './views/ConfigurationJoystickView.vue'
import ConfigurationTelemetryView from './views/ConfigurationLogsView.vue'
import ConfigurationMAVLinkView from './views/ConfigurationMAVLinkView.vue'
import ConfigurationMissionView from './views/ConfigurationMissionView.vue'
import ConfigurationUIView from './views/ConfigurationUIView.vue'
import ConfigurationVideoView from './views/ConfigurationVideoView.vue'
Expand Down Expand Up @@ -411,6 +412,11 @@ const configMenu = [
title: 'Dev',
component: markRaw(ConfigurationDevelopmentView) as ConfigComponent,
},
{
icon: 'mdi-protocol',
title: 'MAVLink',
component: markRaw(ConfigurationMAVLinkView) as ConfigComponent,
},
{
icon: 'mdi-map-marker-path',
title: 'Mission',
Expand Down
6 changes: 6 additions & 0 deletions src/components/ConfigurationMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import ConfigurationDevelopmentView from '../views/ConfigurationDevelopmentView.
import ConfigurationGeneralView from '../views/ConfigurationGeneralView.vue'
import ConfigurationJoystickView from '../views/ConfigurationJoystickView.vue'
import ConfigurationLogsView from '../views/ConfigurationLogsView.vue'
import ConfigurationMAVLinkView from '../views/ConfigurationMAVLinkView.vue'
import ConfigurationMissionView from '../views/ConfigurationMissionView.vue'
import ConfigurationVideoView from '../views/ConfigurationVideoView.vue'
Expand Down Expand Up @@ -81,6 +82,11 @@ const menus = [
title: 'Development',
component: markRaw(ConfigurationDevelopmentView),
},
{
icon: 'mdi-protocol',
title: 'MAVLink',
component: markRaw(ConfigurationMAVLinkView),
},
{
icon: 'mdi-rocket',
title: 'Mission',
Expand Down
112 changes: 112 additions & 0 deletions src/components/development/MAVLinkInspector.vue
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>
33 changes: 33 additions & 0 deletions src/views/ConfigurationMAVLinkView.vue
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>

0 comments on commit 259a1b6

Please sign in to comment.