GCS_MAVLink: move accept_packet to base class

This commit is contained in:
Peter Barker 2018-12-14 10:12:09 +11:00 committed by Peter Barker
parent 17af4c8933
commit 759a8e5553
2 changed files with 20 additions and 1 deletions

View File

@ -129,6 +129,7 @@ public:
AP_HAL::UARTDriver *get_uart() { return _port; }
virtual uint8_t sysid_my_gcs() const = 0;
virtual bool sysid_enforce() const { return false; }
static const struct AP_Param::GroupInfo var_info[];
@ -278,7 +279,7 @@ protected:
// overridable method to check for packet acceptance. Allows for
// enforcement of GCS sysid
virtual bool accept_packet(const mavlink_status_t &status, mavlink_message_t &msg) { return true; }
bool accept_packet(const mavlink_status_t &status, mavlink_message_t &msg);
virtual AP_Rally *get_rally() const = 0;
virtual AP_AdvancedFailsafe *get_advanced_failsafe() const { return nullptr; };
virtual AP_VisualOdom *get_visual_odom() const { return nullptr; }

View File

@ -3945,6 +3945,24 @@ uint32_t GCS_MAVLINK::correct_offboard_timestamp_usec_to_ms(uint64_t offboard_us
return corrected_us / 1000U;
}
/*
return true if we will accept this packet. Used to implement SYSID_ENFORCE
*/
bool GCS_MAVLINK::accept_packet(const mavlink_status_t &status,
mavlink_message_t &msg)
{
if (!sysid_enforce()) {
return true;
}
if (msg.msgid == MAVLINK_MSG_ID_RADIO ||
msg.msgid == MAVLINK_MSG_ID_RADIO_STATUS) {
return true;
}
return (msg.sysid == sysid_my_gcs());
}
GCS &gcs()
{
return *GCS::instance();