Browse Source

AP_Logger: remove Prep and NeedPrep functions

These were only being called directly after Init(), so just tacked them
onto the end of those functions.

The checks in NeedPrep turned out to be mostly redundant.
c415-sdk
Peter Barker 4 years ago committed by Andrew Tridgell
parent
commit
ef0b860a48
  1. 6
      libraries/AP_Logger/AP_Logger.cpp
  2. 3
      libraries/AP_Logger/AP_Logger.h
  3. 2
      libraries/AP_Logger/AP_Logger_Backend.h
  4. 22
      libraries/AP_Logger/AP_Logger_Block.cpp
  5. 2
      libraries/AP_Logger/AP_Logger_Block.h
  6. 40
      libraries/AP_Logger/AP_Logger_File.cpp
  7. 4
      libraries/AP_Logger/AP_Logger_File.h
  8. 1
      libraries/AP_Logger/AP_Logger_MAVLink.h

6
libraries/AP_Logger/AP_Logger.cpp

@ -233,8 +233,6 @@ void AP_Logger::Init(const struct LogStructure *structures, uint8_t num_types) @@ -233,8 +233,6 @@ void AP_Logger::Init(const struct LogStructure *structures, uint8_t num_types)
backends[i]->Init();
}
Prep();
start_io_thread();
EnableWrites(true);
@ -731,10 +729,6 @@ bool AP_Logger::CardInserted(void) { @@ -731,10 +729,6 @@ bool AP_Logger::CardInserted(void) {
return false;
}
void AP_Logger::Prep() {
FOR_EACH_BACKEND(Prep());
}
void AP_Logger::StopLogging()
{
FOR_EACH_BACKEND(stop_logging());

3
libraries/AP_Logger/AP_Logger.h

@ -490,9 +490,6 @@ private: @@ -490,9 +490,6 @@ private:
bool labels_string_is_good(const char *labels) const;
#endif
// possibly expensive calls to start log system:
void Prep();
bool _writes_enabled:1;
bool _force_log_disarmed:1;

2
libraries/AP_Logger/AP_Logger_Backend.h

@ -22,8 +22,6 @@ public: @@ -22,8 +22,6 @@ public:
// erase handling
virtual void EraseAll() = 0;
virtual void Prep() = 0;
/* Write a block of data at current offset */
bool WriteBlock(const void *pBuffer, uint16_t size) {
return WritePrioritisedBlock(pBuffer, size, false);

22
libraries/AP_Logger/AP_Logger_Block.cpp

@ -57,6 +57,12 @@ void AP_Logger_Block::Init(void) @@ -57,6 +57,12 @@ void AP_Logger_Block::Init(void)
}
WITH_SEMAPHORE(sem);
if (NeedErase()) {
EraseAll();
} else {
validate_log_structure();
}
}
uint32_t AP_Logger_Block::bufferspace_available()
@ -344,22 +350,6 @@ void AP_Logger_Block::periodic_10Hz(const uint32_t now) @@ -344,22 +350,6 @@ void AP_Logger_Block::periodic_10Hz(const uint32_t now)
}
}
void AP_Logger_Block::Prep()
{
if (hal.util->get_soft_armed()) {
// do not want to do any filesystem operations while we are e.g. flying
return;
}
WITH_SEMAPHORE(sem);
if (NeedErase()) {
EraseAll();
} else {
validate_log_structure();
}
}
/*
* we need to erase if the logging format has changed
*/

2
libraries/AP_Logger/AP_Logger_Block.h

@ -17,8 +17,6 @@ public: @@ -17,8 +17,6 @@ public:
// erase handling
void EraseAll() override;
void Prep() override;
// high level interface
uint16_t find_last_log() override;
void get_log_boundaries(uint16_t list_entry, uint32_t & start_page, uint32_t & end_page) override;

40
libraries/AP_Logger/AP_Logger_File.cpp

@ -104,6 +104,8 @@ void AP_Logger_File::Init() @@ -104,6 +104,8 @@ void AP_Logger_File::Init()
if (custom_dir != nullptr){
_log_directory = custom_dir;
}
Prep_MinSpace();
}
bool AP_Logger_File::file_exists(const char *filename) const
@ -280,6 +282,11 @@ void AP_Logger_File::Prep_MinSpace() @@ -280,6 +282,11 @@ void AP_Logger_File::Prep_MinSpace()
// don't clear space if watchdog reset, it takes too long
return;
}
if (!CardInserted()) {
return;
}
const uint16_t first_log_to_remove = find_oldest_log();
if (first_log_to_remove == 0) {
// no files to remove
@ -288,8 +295,6 @@ void AP_Logger_File::Prep_MinSpace() @@ -288,8 +295,6 @@ void AP_Logger_File::Prep_MinSpace()
const int64_t target_free = (int64_t)_front._params.min_MB_free * MB_to_B;
_cached_oldest_log = 0;
uint16_t log_to_remove = first_log_to_remove;
uint16_t count = 0;
@ -316,6 +321,7 @@ void AP_Logger_File::Prep_MinSpace() @@ -316,6 +321,7 @@ void AP_Logger_File::Prep_MinSpace()
filename_to_remove, (double)avail*B_to_MB, (double)target_free*B_to_MB);
EXPECT_DELAY_MS(2000);
if (AP::FS().unlink(filename_to_remove) == -1) {
_cached_oldest_log = 0;
hal.console->printf("Failed to remove %s: %s\n", filename_to_remove, strerror(errno));
free(filename_to_remove);
if (errno == ENOENT) {
@ -336,36 +342,6 @@ void AP_Logger_File::Prep_MinSpace() @@ -336,36 +342,6 @@ void AP_Logger_File::Prep_MinSpace()
} while (log_to_remove != first_log_to_remove);
}
void AP_Logger_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;
}
Prep_MinSpace();
}
bool AP_Logger_File::NeedPrep()
{
if (!CardInserted()) {
// should not have been called?!
return false;
}
const int64_t actual = disk_space_avail();
if (actual == -1) {
return false;
}
if (actual < (int64_t)_front._params.min_MB_free * MB_to_B) {
return true;
}
return false;
}
/*
construct a log file name given a log number.
The number in the log filename will *not* be zero-padded.

4
libraries/AP_Logger/AP_Logger_File.h

@ -28,9 +28,6 @@ public: @@ -28,9 +28,6 @@ public:
// erase handling
void EraseAll() override;
// possibly time-consuming preparation handling:
void Prep() override;
/* Write a block of data at current offset */
bool _WritePrioritisedBlock(const void *pBuffer, uint16_t size, bool is_critical) override;
uint32_t bufferspace_available() override;
@ -90,7 +87,6 @@ private: @@ -90,7 +87,6 @@ private:
int64_t disk_space();
void ensure_log_directory_exists();
bool NeedPrep();
bool file_exists(const char *filename) const;
bool log_exists(const uint16_t lognum) const;

1
libraries/AP_Logger/AP_Logger_MAVLink.h

@ -50,7 +50,6 @@ public: @@ -50,7 +50,6 @@ public:
void EraseAll() override {}
void PrepForArming() override {}
void Prep() override { }
// high level interface
uint16_t find_last_log(void) override { return 0; }

Loading…
Cancel
Save