Intercepting and Handling MAVLink Messages

Hello Dears,

I hope you’re all doing well. I’m currently working on a plugin for Mission Planner that requires intercepting and handling MAVLink messages from the autopilot. As part of my plugin’s functionality, I’m trying to find a method or event that allows me to listen to incoming MAVLink messages and respond accordingly.

notice : MainV2.gcs.ReceivedPacket += Gcs_ReceivedPacket; is just my imgination.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MissionPlanner.Utilities;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading.Tasks;
using MissionPlanner;
using static MAVLink;
//loadassembly: MissionPlanner.WebAPIs



namespace MessageInterceptionExample
{
    public class MessageInterceptionPlugin :  MissionPlanner.Plugin.Plugin
    {
        public override string Name => "Message Interception Plugin";
        public override string Version => "1.0";
        public override string Author => "Dave Bonsall";


        public override bool Init()
        {
            return true;
        }

        public override bool Loaded()
        {
            return true;
        }

        public override bool Exit()
        {
            return true;
        }


        // Constructor
        public MessageInterceptionPlugin()
        {
            // Subscribe to the ReceivedPacket event 
            MainV2.gcs.ReceivedPacket += Gcs_ReceivedPacket;
        }

        // Event handler for ReceivedPacket event
        private void Gcs_ReceivedPacket(object sender, MAVLinkMessage packet)
        {
            // Here, i want to intercept and handle incoming MAVLink messages
            // For example, i want to log the message information or process specific messages

            Console.WriteLine($"Received MAVLink message with ID: {packet.msgid}");

            
        }
    
  }
}

However, I’m not certain about the exact way to achieve this in the latest version of Mission Planner. Could anyone kindly provide insights on how I can intercept and handle MAVLink messages within the current environment?

Best Regards
Dave

Browsing the code could help a lot

[
532fb580-b307-11ea-8e3c-2e605207af9c.jpeg

MissionPlanner/plugins/example-watchbutton.cs at master · ArduPilot/MissionPlanner
github.com

](https://github.com/ArduPilot/MissionPlanner/blob/master/plugins/example-watchbutton.cs)

1 Like

Documentation and links to examples:

https://ardupilot.org/planner/docs/using-python-scripts-in-mission-planner.html

Thanks a lot it’s helped me a lot