logger: add free space check (need at least 50MB to start)

This commit is contained in:
Beat Küng
2016-05-14 11:27:07 +02:00
committed by Lorenz Meier
parent 501544520f
commit fc51f81bf5
2 changed files with 47 additions and 0 deletions
+40
View File
@@ -47,6 +47,14 @@
#include <px4_includes.h>
#include <px4_getopt.h>
#include <px4_log.h>
#include <systemlib/mavlink_log.h>
#ifdef __PX4_DARWIN
#include <sys/param.h>
#include <sys/mount.h>
#else
#include <sys/statfs.h>
#endif
#define GPS_EPOCH_SECS ((time_t)1234567890ULL)
@@ -452,6 +460,10 @@ void Logger::run()
return;
}
if (check_free_space() == 1) {
return;
}
uORB::Subscription<vehicle_status_s> vehicle_status_sub(ORB_ID(vehicle_status));
uORB::Subscription<parameter_update_s> parameter_update_sub(ORB_ID(parameter_update));
@@ -647,6 +659,11 @@ void Logger::run()
if (ret) {
PX4_WARN("join failed: %d", ret);
}
if (_mavlink_log_pub) {
orb_unadvertise(_mavlink_log_pub);
_mavlink_log_pub = nullptr;
}
}
int Logger::create_log_dir(tm *tt)
@@ -803,6 +820,9 @@ void Logger::start_log()
return;
}
/* print logging path, important to find log file later */
mavlink_log_info(&_mavlink_log_pub, "[logger] file: %s", file_name);
_writer.start_log(file_name);
write_version();
write_formats();
@@ -1001,5 +1021,25 @@ void Logger::write_changed_parameters()
_writer.notify();
}
int Logger::check_free_space()
{
/* use statfs to determine the number of blocks left */
struct statfs statfs_buf;
if (statfs(LOG_ROOT, &statfs_buf) != 0) {
return PX4_ERROR;
}
/* use a threshold of 50 MiB */
if (statfs_buf.f_bavail < (px4_statfs_buf_f_bavail_t)(50 * 1024 * 1024 / statfs_buf.f_bsize)) {
mavlink_and_console_log_critical(&_mavlink_log_pub,
"[logger] Not logging; SD almost full: %u MiB",
(unsigned int)(statfs_buf.f_bavail / 1024U * statfs_buf.f_bsize / 1024U));
return 1;
}
return PX4_OK;
}
}
}
+7
View File
@@ -107,6 +107,12 @@ private:
*/
int get_log_file_name(char *file_name, size_t file_name_size);
/**
* Check if there is enough free space left on the SD Card
* @return 0 on success, 1 if not enough space, <0 on error
*/
int check_free_space();
void start_log();
void stop_log();
@@ -164,6 +170,7 @@ private:
LogWriter _writer;
uint32_t _log_interval;
param_t _log_utc_offset;
orb_advert_t _mavlink_log_pub = nullptr;
};
Logger *logger_ptr = nullptr;