mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-22 00:28:30 -04:00
DataFlash: move Init from LogFile.cpp to Dataflash.cpp (NFC)
This commit is contained in:
parent
a9b8e4b5d3
commit
2746edfd32
@ -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];
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user