From 82e7476532488624235623b2cf0d7f038f9d2eaf Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 14 Dec 2022 12:14:18 +1100 Subject: [PATCH] Rover: code-generate chan-fetching methods A recent PR had to change every single one of these methods, which was kind of unfortunate. So generate the methods using a #define so the duplication happens at preprocessor-time. --- Rover/GCS_Rover.h | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/Rover/GCS_Rover.h b/Rover/GCS_Rover.h index b9fbac77ed..acd1dd2426 100644 --- a/Rover/GCS_Rover.h +++ b/Rover/GCS_Rover.h @@ -9,22 +9,12 @@ class GCS_Rover : public GCS public: - // return GCS link at offset ofs - GCS_MAVLINK_Rover *chan(const uint8_t ofs) override { - if (ofs > _num_gcs) { - INTERNAL_ERROR(AP_InternalError::error_t::gcs_offset); - return nullptr; - } - return (GCS_MAVLINK_Rover*)_chan[ofs]; - } - // return GCS link at offset ofs - const GCS_MAVLINK_Rover *chan(const uint8_t ofs) const override { - if (ofs > _num_gcs) { - INTERNAL_ERROR(AP_InternalError::error_t::gcs_offset); - return nullptr; - } - return (GCS_MAVLINK_Rover*)_chan[ofs]; - } + // the following define expands to a pair of methods to retrieve a + // pointer to an object of the correct subclass for the link at + // offset ofs. These are of the form: + // GCS_MAVLINK_XXXX *chan(const uint8_t ofs) override; + // const GCS_MAVLINK_XXXX *chan(const uint8_t ofs) override const; + GCS_MAVLINK_CHAN_METHOD_DEFINITIONS(GCS_MAVLINK_Rover); uint32_t custom_mode() const override; MAV_TYPE frame_type() const override;