From 643e7e039a1029cbf620a8d61d5a4f4f33d98977 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 11 Apr 2018 22:16:23 +1000 Subject: [PATCH] AP_GPS: log received data Also log a set of flag values if a driver is deleted --- libraries/AP_GPS/AP_GPS.cpp | 28 ++++++++++++++++++++++++++++ libraries/AP_GPS/AP_GPS.h | 2 ++ libraries/AP_GPS/GPS_Backend.cpp | 12 +----------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/libraries/AP_GPS/AP_GPS.cpp b/libraries/AP_GPS/AP_GPS.cpp index 9cbbd77ea4..c5c4dc1805 100644 --- a/libraries/AP_GPS/AP_GPS.cpp +++ b/libraries/AP_GPS/AP_GPS.cpp @@ -585,6 +585,22 @@ AP_GPS::GPS_Status AP_GPS::highest_supported_status(uint8_t instance) const return AP_GPS::GPS_OK_FIX_3D; } +bool AP_GPS::should_df_log() const +{ + DataFlash_Class *instance = DataFlash_Class::instance(); + if (instance == nullptr) { + return false; + } + if (_log_gps_bit == (uint32_t)-1) { + return false; + } + if (!instance->should_log(_log_gps_bit)) { + return false; + } + return true; +} + + /* update one GPS instance. This should be called at 10Hz or greater */ @@ -624,6 +640,7 @@ void AP_GPS::update_instance(uint8_t instance) // if we did not get a message, and the idle timer of 2 seconds // has expired, re-initialise the GPS. This will cause GPS // detection to run again + bool data_should_be_logged = false; if (!result) { if (tnow - timing[instance].last_message_time_ms > GPS_TIMEOUT_MS) { memset(&state[instance], 0, sizeof(state[instance])); @@ -642,6 +659,9 @@ void AP_GPS::update_instance(uint8_t instance) drivers[instance] = nullptr; state[instance].status = NO_GPS; } + // log this data as a "flag" that the GPS is no longer + // valid (see PR#8144) + data_should_be_logged = true; } } else { // delta will only be correct after parsing two messages @@ -650,6 +670,14 @@ void AP_GPS::update_instance(uint8_t instance) if (state[instance].status >= GPS_OK_FIX_2D) { timing[instance].last_fix_time_ms = tnow; } + + data_should_be_logged = true; + } + + if (data_should_be_logged && + should_df_log() && + !AP::ahrs().have_ekf_logging()) { + DataFlash_Class::instance()->Log_Write_GPS(instance); } } diff --git a/libraries/AP_GPS/AP_GPS.h b/libraries/AP_GPS/AP_GPS.h index 5a3c84c917..e90d84e97b 100644 --- a/libraries/AP_GPS/AP_GPS.h +++ b/libraries/AP_GPS/AP_GPS.h @@ -551,6 +551,8 @@ private: // calculate the blended state void calc_blended_state(void); + bool should_df_log() const; + // Auto configure types enum GPS_AUTO_CONFIG { GPS_AUTO_CONFIG_DISABLE = 0, diff --git a/libraries/AP_GPS/GPS_Backend.cpp b/libraries/AP_GPS/GPS_Backend.cpp index 5742915a2e..466aa914eb 100644 --- a/libraries/AP_GPS/GPS_Backend.cpp +++ b/libraries/AP_GPS/GPS_Backend.cpp @@ -172,17 +172,7 @@ void AP_GPS_Backend::Write_DataFlash_Log_Startup_messages() const bool AP_GPS_Backend::should_df_log() const { - DataFlash_Class *instance = DataFlash_Class::instance(); - if (instance == nullptr) { - return false; - } - if (gps._log_gps_bit == (uint32_t)-1) { - return false; - } - if (!instance->should_log(gps._log_gps_bit)) { - return false; - } - return true; + return gps.should_df_log(); }