From 09a9bd73a4e0e8bc42a369de8070ed10b2acf2df Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 5 Feb 2021 13:28:08 +1100 Subject: [PATCH] ArduCopter: move handling of last-seen-SYSID_MYGCS up to GCS base class --- ArduCopter/Copter.h | 1 - ArduCopter/GCS_Mavlink.cpp | 20 +++----------------- ArduCopter/GCS_Mavlink.h | 1 - ArduCopter/events.cpp | 9 +++++++-- ArduCopter/failsafe.cpp | 2 +- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/ArduCopter/Copter.h b/ArduCopter/Copter.h index 5e8c80cceb..172f82d8c7 100644 --- a/ArduCopter/Copter.h +++ b/ArduCopter/Copter.h @@ -386,7 +386,6 @@ private: // Failsafe struct { - uint32_t last_heartbeat_ms; // the time when the last HEARTBEAT message arrived from a GCS - used for triggering gcs failsafe uint32_t terrain_first_failure_ms; // the first time terrain data access failed - used to calculate the duration of the failure uint32_t terrain_last_failure_ms; // the most recent time terrain data access failed diff --git a/ArduCopter/GCS_Mavlink.cpp b/ArduCopter/GCS_Mavlink.cpp index 51d1ab460e..4daa0e6b2c 100644 --- a/ArduCopter/GCS_Mavlink.cpp +++ b/ArduCopter/GCS_Mavlink.cpp @@ -562,13 +562,6 @@ void GCS_MAVLINK_Copter::send_banner() copter.motors->get_type_string()); } -// a RC override message is considered to be a 'heartbeat' from the ground station for failsafe purposes -void GCS_MAVLINK_Copter::handle_rc_channels_override(const mavlink_message_t &msg) -{ - copter.failsafe.last_heartbeat_ms = AP_HAL::millis(); - GCS_MAVLINK::handle_rc_channels_override(msg); -} - void GCS_MAVLINK_Copter::handle_command_ack(const mavlink_message_t &msg) { copter.command_ack_counter++; @@ -999,14 +992,6 @@ void GCS_MAVLINK_Copter::handleMessage(const mavlink_message_t &msg) switch (msg.msgid) { - case MAVLINK_MSG_ID_HEARTBEAT: // MAV ID: 0 - { - // We keep track of the last time we received a heartbeat from our GCS for failsafe purposes - if (msg.sysid != copter.g.sysid_my_gcs) break; - copter.failsafe.last_heartbeat_ms = AP_HAL::millis(); - break; - } - case MAVLINK_MSG_ID_MANUAL_CONTROL: { if (msg.sysid != copter.g.sysid_my_gcs) { @@ -1031,8 +1016,9 @@ void GCS_MAVLINK_Copter::handleMessage(const mavlink_message_t &msg) manual_override(copter.channel_throttle, packet.z, 0, 1000, tnow); manual_override(copter.channel_yaw, packet.r, 1000, 2000, tnow); - // a manual control message is considered to be a 'heartbeat' from the ground station for failsafe purposes - copter.failsafe.last_heartbeat_ms = tnow; + // a manual control message is considered to be a 'heartbeat' + // from the ground station for failsafe purposes + gcs().sysid_myggcs_seen(tnow); break; } diff --git a/ArduCopter/GCS_Mavlink.h b/ArduCopter/GCS_Mavlink.h index 2c8a381c81..e404b0ddf1 100644 --- a/ArduCopter/GCS_Mavlink.h +++ b/ArduCopter/GCS_Mavlink.h @@ -49,7 +49,6 @@ private: void handle_command_ack(const mavlink_message_t &msg) override; bool handle_guided_request(AP_Mission::Mission_Command &cmd) override; void handle_change_alt_request(AP_Mission::Mission_Command &cmd) override; - void handle_rc_channels_override(const mavlink_message_t &msg) override; bool try_send_message(enum ap_message id) override; void packetReceived(const mavlink_status_t &status, diff --git a/ArduCopter/events.cpp b/ArduCopter/events.cpp index 13ad80d95a..f5a97ddb86 100644 --- a/ArduCopter/events.cpp +++ b/ArduCopter/events.cpp @@ -112,13 +112,18 @@ void Copter::handle_battery_failsafe(const char *type_str, const int8_t action) void Copter::failsafe_gcs_check() { // Bypass GCS failsafe checks if disabled or GCS never connected - if (g.failsafe_gcs == FS_GCS_DISABLED || failsafe.last_heartbeat_ms == 0) { + if (g.failsafe_gcs == FS_GCS_DISABLED) { + return; + } + + const uint32_t gcs_last_seen_ms = gcs().sysid_myggcs_last_seen_time_ms(); + if (gcs_last_seen_ms == 0) { return; } // calc time since last gcs update // note: this only looks at the heartbeat from the device id set by g.sysid_my_gcs - const uint32_t last_gcs_update_ms = millis() - failsafe.last_heartbeat_ms; + const uint32_t last_gcs_update_ms = millis() - gcs_last_seen_ms; const uint32_t gcs_timeout_ms = uint32_t(constrain_float(g2.fs_gcs_timeout * 1000.0f, 0.0f, UINT32_MAX)); // Determine which event to trigger diff --git a/ArduCopter/failsafe.cpp b/ArduCopter/failsafe.cpp index c3ee045c88..75e44f36ec 100644 --- a/ArduCopter/failsafe.cpp +++ b/ArduCopter/failsafe.cpp @@ -84,6 +84,6 @@ void Copter::afs_fs_check(void) #else const bool fence_breached = false; #endif - g2.afs.check(failsafe.last_heartbeat_ms, fence_breached, last_radio_update_ms); + g2.afs.check(fence_breached, last_radio_update_ms); } #endif