From 6cc4afaa566d41b56a1644c03302b3840efbd047 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 23 Feb 2023 16:06:48 +1100 Subject: [PATCH] GCS_MAVLink: add method to get link (not just channel number) for mavtype and compid --- libraries/GCS_MAVLink/GCS.h | 3 +++ libraries/GCS_MAVLink/GCS_MAVLink.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/libraries/GCS_MAVLink/GCS.h b/libraries/GCS_MAVLink/GCS.h index 947768e469..8b3708b8f4 100644 --- a/libraries/GCS_MAVLink/GCS.h +++ b/libraries/GCS_MAVLink/GCS.h @@ -389,6 +389,9 @@ public: returns true if a match is found */ static bool find_by_mavtype_and_compid(uint8_t mav_type, uint8_t compid, uint8_t &sysid, mavlink_channel_t &channel) { return routing.find_by_mavtype_and_compid(mav_type, compid, sysid, channel); } + // same as above, but returns a pointer to the GCS_MAVLINK object + // corresponding to the channel + static GCS_MAVLINK *find_by_mavtype_and_compid(uint8_t mav_type, uint8_t compid, uint8_t &sysid); // update signing timestamp on GPS lock static void update_signing_timestamp(uint64_t timestamp_usec); diff --git a/libraries/GCS_MAVLink/GCS_MAVLink.cpp b/libraries/GCS_MAVLink/GCS_MAVLink.cpp index 7e1ef4126c..23a6f77cbe 100644 --- a/libraries/GCS_MAVLink/GCS_MAVLink.cpp +++ b/libraries/GCS_MAVLink/GCS_MAVLink.cpp @@ -48,6 +48,14 @@ mavlink_system_t mavlink_system = {7,1}; // routing table MAVLink_routing GCS_MAVLINK::routing; +GCS_MAVLINK *GCS_MAVLINK::find_by_mavtype_and_compid(uint8_t mav_type, uint8_t compid, uint8_t &sysid) { + mavlink_channel_t channel; + if (!routing.find_by_mavtype_and_compid(mav_type, compid, sysid, channel)) { + return nullptr; + } + return gcs().chan(channel); +} + // set a channel as private. Private channels get sent heartbeats, but // don't get broadcast packets or forwarded packets void GCS_MAVLINK::set_channel_private(mavlink_channel_t _chan)