From 91b62abfe54e47089a1480902a5a4dad2501d206 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 12 Jun 2017 23:05:02 +1000 Subject: [PATCH] DataFlash: simplify dataflash initialisation --- libraries/DataFlash/DataFlash.cpp | 6 ++++++ libraries/DataFlash/DataFlash.h | 8 ++++---- libraries/DataFlash/DataFlash_File.cpp | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index 3eb7e2a22d..f8167d5d96 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -4,6 +4,7 @@ #include "DataFlash_File.h" #include "DataFlash_MAVLink.h" +#include DataFlash_Class *DataFlash_Class::_instance; @@ -49,6 +50,7 @@ const AP_Param::GroupInfo DataFlash_Class::var_info[] = { void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_types) { + GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "Preparing log system"); #if CONFIG_HAL_BOARD == HAL_BOARD_SITL validate_structures(structures, num_types); dump_structures(structures, num_types); @@ -104,6 +106,10 @@ void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_ty for (uint8_t i=0; i<_next_backend; i++) { backends[i]->Init(); } + + Prep(); + + GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "Prepared log system"); } #if CONFIG_HAL_BOARD == HAL_BOARD_SITL diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index fc0f16cf5b..bb204d50f6 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -74,10 +74,6 @@ public: bool NeedErase(void); void EraseAll(); - // possibly expensive calls to start log system: - bool NeedPrep(); - void Prep(); - // get a pointer to structures const struct LogStructure *get_structures(uint8_t &num_types) { num_types = _num_types; @@ -286,4 +282,8 @@ private: void dump_structures(const struct LogStructure *structures, const uint8_t num_types); void Log_Write_EKF_Timing(const char *name, uint64_t time_us, const struct ekf_timing &timing); + + // possibly expensive calls to start log system: + void Prep(); + bool NeedPrep(); }; diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index c571c31aa7..dcc4c6cb9a 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -397,6 +397,9 @@ void DataFlash_File::Prep_MinSpace() #endif void DataFlash_File::Prep() { + if (!NeedPrep()) { + return; + } if (hal.util->get_soft_armed()) { // do not want to do any filesystem operations while we are e.g. flying return;