From 6a03af8f3e028958e02f5010ebfd20bbf738f9b6 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 15 Jun 2017 11:21:17 +1000 Subject: [PATCH] DataFlash: make EnableWrites a frontend thing --- libraries/DataFlash/DataFlash.cpp | 6 ++---- libraries/DataFlash/DataFlash.h | 6 +++++- libraries/DataFlash/DataFlash_Backend.cpp | 2 +- libraries/DataFlash/DataFlash_Backend.h | 7 +------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index 3941052fd9..6b418f3370 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -109,6 +109,8 @@ void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_ty Prep(); + EnableWrites(true); + GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "Prepared log system"); } @@ -458,10 +460,6 @@ bool DataFlash_Class::logging_started(void) { return false; } -void DataFlash_Class::EnableWrites(bool enable) { - FOR_EACH_BACKEND(EnableWrites(enable)); -} - // for DataFlash_MAVLink void DataFlash_Class::remote_log_block_status_msg(mavlink_channel_t chan, mavlink_message_t* msg) { diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index 161b20b0e0..3d7ce3fd38 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -104,7 +104,8 @@ public: /* poke backends to start if they're not already started */ void StartUnstartedLogging(void); - void EnableWrites(bool enable); + void EnableWrites(bool enable) { _writes_enabled = enable; } + bool WritesEnabled() const { return _writes_enabled; } void StopLogging(); @@ -288,4 +289,7 @@ private: // possibly expensive calls to start log system: void Prep(); + + bool _writes_enabled; + }; diff --git a/libraries/DataFlash/DataFlash_Backend.cpp b/libraries/DataFlash/DataFlash_Backend.cpp index 81b6418ff4..b76a4798fe 100644 --- a/libraries/DataFlash/DataFlash_Backend.cpp +++ b/libraries/DataFlash/DataFlash_Backend.cpp @@ -262,7 +262,7 @@ bool DataFlash_Backend::Log_Write(const uint8_t msg_type, va_list arg_list, bool bool DataFlash_Backend::WritesOK() const { - if (!_writes_enabled) { + if (!_front.WritesEnabled()) { return false; } if (!_front.vehicle_is_armed() && !_front.log_while_disarmed()) { diff --git a/libraries/DataFlash/DataFlash_Backend.h b/libraries/DataFlash/DataFlash_Backend.h index dcf5bb52a1..fcf0eecec2 100644 --- a/libraries/DataFlash/DataFlash_Backend.h +++ b/libraries/DataFlash/DataFlash_Backend.h @@ -51,12 +51,9 @@ public: virtual void ShowDeviceInfo(AP_HAL::BetterStream *port) = 0; virtual void ListAvailableLogs(AP_HAL::BetterStream *port) = 0; - void EnableWrites(bool enable) { _writes_enabled = enable; } virtual bool logging_started(void) const { return log_write_started; } - virtual void Init() { - _writes_enabled = true; - } + virtual void Init() { } void set_mission(const AP_Mission *mission); @@ -142,8 +139,6 @@ protected: virtual bool WritesOK() const; - bool _writes_enabled = false; - /* read a block */