From 2746edfd3233ead96aa3df58f1bbfbf6e6a30d1b Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 30 Mar 2017 12:08:24 +1100 Subject: [PATCH] DataFlash: move Init from LogFile.cpp to Dataflash.cpp (NFC) --- libraries/DataFlash/DataFlash.cpp | 58 +++++++++++++++++++++++++++++++ libraries/DataFlash/LogFile.cpp | 55 ----------------------------- 2 files changed, 58 insertions(+), 55 deletions(-) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index 7f6e729d91..dc9636ad98 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -2,6 +2,9 @@ #include "DataFlash_Backend.h" +#include "DataFlash_File.h" +#include "DataFlash_MAVLink.h" + DataFlash_Class *DataFlash_Class::_instance; const AP_Param::GroupInfo DataFlash_Class::var_info[] = { @@ -42,6 +45,61 @@ const AP_Param::GroupInfo DataFlash_Class::var_info[] = { AP_GROUPEND }; +void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_types) +{ + if (_next_backend == DATAFLASH_MAX_BACKENDS) { + AP_HAL::panic("Too many backends"); + return; + } + _num_types = num_types; + _structures = structures; + +#if defined(HAL_BOARD_LOG_DIRECTORY) + if (_params.backend_types == DATAFLASH_BACKEND_FILE || + _params.backend_types == DATAFLASH_BACKEND_BOTH) { + DFMessageWriter_DFLogStart *message_writer = + new DFMessageWriter_DFLogStart(_firmware_string); + if (message_writer != nullptr) { +#if HAL_OS_POSIX_IO + backends[_next_backend] = new DataFlash_File(*this, + message_writer, + HAL_BOARD_LOG_DIRECTORY); +#endif + } + if (backends[_next_backend] == nullptr) { + hal.console->printf("Unable to open DataFlash_File"); + } else { + _next_backend++; + } + } +#endif + +#if DATAFLASH_MAVLINK_SUPPORT + if (_params.backend_types == DATAFLASH_BACKEND_MAVLINK || + _params.backend_types == DATAFLASH_BACKEND_BOTH) { + if (_next_backend == DATAFLASH_MAX_BACKENDS) { + AP_HAL::panic("Too many backends"); + return; + } + DFMessageWriter_DFLogStart *message_writer = + new DFMessageWriter_DFLogStart(_firmware_string); + if (message_writer != nullptr) { + backends[_next_backend] = new DataFlash_MAVLink(*this, + message_writer); + } + if (backends[_next_backend] == nullptr) { + hal.console->printf("Unable to open DataFlash_MAVLink"); + } else { + _next_backend++; + } + } +#endif + + for (uint8_t i=0; i<_next_backend; i++) { + backends[i]->Init(); + } +} + const struct LogStructure *DataFlash_Class::structure(uint16_t num) const { return &_structures[num]; diff --git a/libraries/DataFlash/LogFile.cpp b/libraries/DataFlash/LogFile.cpp index 5610d0831f..80c099d5cf 100644 --- a/libraries/DataFlash/LogFile.cpp +++ b/libraries/DataFlash/LogFile.cpp @@ -20,61 +20,6 @@ extern const AP_HAL::HAL& hal; -void DataFlash_Class::Init(const struct LogStructure *structures, uint8_t num_types) -{ - if (_next_backend == DATAFLASH_MAX_BACKENDS) { - AP_HAL::panic("Too many backends"); - return; - } - _num_types = num_types; - _structures = structures; - -#if defined(HAL_BOARD_LOG_DIRECTORY) - if (_params.backend_types == DATAFLASH_BACKEND_FILE || - _params.backend_types == DATAFLASH_BACKEND_BOTH) { - DFMessageWriter_DFLogStart *message_writer = - new DFMessageWriter_DFLogStart(_firmware_string); - if (message_writer != nullptr) { -#if HAL_OS_POSIX_IO - backends[_next_backend] = new DataFlash_File(*this, - message_writer, - HAL_BOARD_LOG_DIRECTORY); -#endif - } - if (backends[_next_backend] == nullptr) { - hal.console->printf("Unable to open DataFlash_File"); - } else { - _next_backend++; - } - } -#endif - -#if DATAFLASH_MAVLINK_SUPPORT - if (_params.backend_types == DATAFLASH_BACKEND_MAVLINK || - _params.backend_types == DATAFLASH_BACKEND_BOTH) { - if (_next_backend == DATAFLASH_MAX_BACKENDS) { - AP_HAL::panic("Too many backends"); - return; - } - DFMessageWriter_DFLogStart *message_writer = - new DFMessageWriter_DFLogStart(_firmware_string); - if (message_writer != nullptr) { - backends[_next_backend] = new DataFlash_MAVLink(*this, - message_writer); - } - if (backends[_next_backend] == nullptr) { - hal.console->printf("Unable to open DataFlash_MAVLink"); - } else { - _next_backend++; - } - } -#endif - - for (uint8_t i=0; i<_next_backend; i++) { - backends[i]->Init(); - } -} - // This function determines the number of whole or partial log files in the DataFlash // Wholly overwritten files are (of course) lost. uint16_t DataFlash_Block::get_num_logs(void)