LCOV - code coverage report
Current view: top level - GCS_MAVLink - MissionItemProtocol.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 6 9 66.7 %
Date: 2026-09-09 11:02:08 Functions: 4 6 66.7 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "GCS_MAVLink.h"
       4             : 
       5             : #include "ap_message.h"
       6             : 
       7             : #include <stdint.h>
       8             : 
       9             : // MissionItemProtocol objects are used for transfering missions from
      10             : // a GCS to ArduPilot and vice-versa.
      11             : //
      12             : // There exists one MissionItemProtocol instance for each of the types
      13             : // of item that might be transfered - e.g. MissionItemProtocol_Rally
      14             : // for rally point uploads.  These objects are static in GCS_MAVLINK
      15             : // and used by all of the backends.
      16             : //
      17             : // While prompting the GCS for items required to complete the mission,
      18             : // a link is stored to the link the MissionItemProtocol should send
      19             : // requests out on, and the "receiving" boolean is true.  In this
      20             : // state downloading of items (and the item count!) is blocked.
      21             : // Starting of uploads (for the same protocol) is also blocked -
      22             : // essentially the GCS uploading a set of items (e.g. a mission) has a
      23             : // mutex over the mission.
      24             : class MissionItemProtocol
      25             : {
      26             : public:
      27             : 
      28             :     // note that all of these methods are named after the packet they
      29             :     // are handling; the "mission" part just comes as part of that.
      30             :     void handle_mission_request_list(const class GCS_MAVLINK &link,
      31             :                                      const mavlink_mission_request_list_t &packet,
      32             :                                      const mavlink_message_t &msg);
      33             :     void handle_mission_request_int(GCS_MAVLINK &link,
      34             :                                     const mavlink_mission_request_int_t &packet,
      35             :                                     const mavlink_message_t &msg);
      36             :     void handle_mission_request(GCS_MAVLINK &link,
      37             :                                 const mavlink_mission_request_t &packet,
      38             :                                 const mavlink_message_t &msg);
      39             : 
      40             :     void handle_mission_count(class GCS_MAVLINK &link,
      41             :                               const mavlink_mission_count_t &packet,
      42             :                               const mavlink_message_t &msg);
      43             :     void handle_mission_write_partial_list(GCS_MAVLINK &link,
      44             :                                            const mavlink_message_t &msg,
      45             :                                            const mavlink_mission_write_partial_list_t &packet);
      46             : 
      47             :     // called on receipt of a MISSION_ITEM or MISSION_ITEM_INT packet;
      48             :     // the former is converted to the latter.
      49             :     void handle_mission_item(const mavlink_message_t &msg,
      50             :                              const mavlink_mission_item_int_t &cmd);
      51             : 
      52             :     void handle_mission_clear_all(const GCS_MAVLINK &link,
      53             :                                   const mavlink_message_t &msg);
      54             : 
      55             :     void queued_request_send();
      56             :     void update();
      57             : 
      58       22077 :     bool active_link_is(const GCS_MAVLINK *_link) const { return _link == link; };
      59             : 
      60             :     virtual MAV_MISSION_TYPE mission_type() const = 0;
      61             : 
      62             :     bool receiving; // currently sending requests and expecting items
      63             : 
      64             :     // a method for GCS_MAVLINK to send warnings about received
      65             :     // MISSION_ITEM messages (we should be getting MISSION_ITEM_INT)
      66             :     void send_mission_item_warning();
      67             : 
      68             : protected:
      69             : 
      70             :     GCS_MAVLINK *link; // link currently receiving waypoints on
      71             : 
      72             :     // return the ap_message which can be queued to be sent to send a
      73             :     // item request to the GCS:
      74             :     virtual ap_message next_item_ap_message_id() const = 0;
      75             : 
      76             :     virtual bool clear_all_items() = 0;
      77             : 
      78             :     uint16_t        request_last; // last request index
      79             : 
      80             : private:
      81             : 
      82             :     // returns true if we are either not receiving, or we successfully
      83             :     // cancelled an existing upload:
      84             :     bool cancel_upload(const GCS_MAVLINK &_link, const mavlink_message_t &msg);
      85             : 
      86             :     virtual void truncate(const mavlink_mission_count_t &packet) = 0;
      87             : 
      88             :     uint16_t        request_i; // request index
      89             : 
      90             :     // waypoints
      91             :     uint8_t         dest_sysid;  // where to send requests
      92             :     uint8_t         dest_compid; // "
      93             :     uint32_t        timelast_receive_ms;
      94             :     uint32_t        timelast_request_ms;
      95             :     const uint16_t  upload_timeout_ms = 8000;
      96             : 
      97             :     // if a transfer is made with MISSION_REQUEST rather than
      98             :     // MISSION_REQUEST we issue a warning - once per transfer.
      99             :     bool mission_request_warning_sent = false;
     100             :     // if a GCS supplied a MISSION_ITEM instead of a MISSION_ITEM_INT
     101             :     // then we issue a warning - once per transfer.
     102             :     bool mission_item_warning_sent = false;
     103             : 
     104             :     // support for GCS getting waypoints etc from us:
     105             :     virtual MAV_MISSION_RESULT get_item(uint16_t seq,
     106             :                                         mavlink_mission_item_int_t &ret_packet) = 0;
     107             : 
     108             :     void init_send_requests(GCS_MAVLINK &_link,
     109             :                             const mavlink_message_t &msg,
     110             :                             const int16_t _request_first,
     111             :                             const int16_t _request_last);
     112        2170 :     virtual MAV_MISSION_RESULT allocate_receive_resources(const uint16_t count) WARN_IF_UNUSED {
     113        2170 :         return MAV_MISSION_ACCEPTED;
     114             :     }
     115           4 :     virtual MAV_MISSION_RESULT allocate_update_resources() WARN_IF_UNUSED {
     116           4 :         return MAV_MISSION_ACCEPTED;
     117             :     }
     118        2174 :     virtual void free_upload_resources() { }
     119             : 
     120             :     void send_mission_ack(const mavlink_message_t &msg, MAV_MISSION_RESULT result) const;
     121             :     void send_mission_ack(const GCS_MAVLINK &link, const mavlink_message_t &msg, MAV_MISSION_RESULT result) const;
     122             : 
     123             :     virtual uint16_t item_count() const = 0;
     124             :     virtual uint16_t max_items() const = 0;
     125             : 
     126             :     virtual MAV_MISSION_RESULT replace_item(const mavlink_mission_item_int_t &mission_item_int) = 0;
     127             :     virtual MAV_MISSION_RESULT append_item(const mavlink_mission_item_int_t &mission_item_int) = 0;
     128             : 
     129             :     // complete - method called when transfer is complete - backends
     130             :     // are expected to override this method to do any required tidy up.
     131           0 :     virtual MAV_MISSION_RESULT complete(const GCS_MAVLINK &_link) {
     132           0 :         return MAV_MISSION_ACCEPTED;
     133             :     };
     134             :     // transfer_is_complete - tidy up after a transfer is complete;
     135             :     // this method will call complete() so the backends can do their
     136             :     // bit.
     137             :     void transfer_is_complete(const GCS_MAVLINK &_link, const mavlink_message_t &msg);
     138             : 
     139             :     // timeout - called if the GCS fails to continue to supply items
     140             :     // in a transfer.  Backends are expected to tidy themselves up in
     141             :     // this routine
     142           0 :     virtual void timeout() {};
     143             : 
     144             :     bool mavlink2_requirement_met(const GCS_MAVLINK &_link, const mavlink_message_t &msg) const;
     145             : };

Generated by: LCOV version 1.14