42 #define MOUNTPOINT PX4_STORAGEDIR 49 #define PX4LOG_REGULAR_FILE DTYPE_FILE 50 #define PX4LOG_DIRECTORY DTYPE_DIRECTORY 52 #define PX4LOG_REGULAR_FILE DT_REG 53 #define PX4LOG_DIRECTORY DT_DIR 58 #ifdef MAVLINK_LOG_HANDLER_VERBOSE 59 #define PX4LOG_WARN(fmt, ...) warnx(fmt, ##__VA_ARGS__) 61 #define PX4LOG_WARN(fmt, ...) 66 stat_file(
const char *
file, time_t *date =
nullptr, uint32_t *size =
nullptr)
70 if (stat(file, &st) == 0) {
71 if (date) { *date = st.st_mtime; }
73 if (size) { *size = st.st_size; }
83 : _pLogHandlerHelper(nullptr),
94 case MAVLINK_MSG_ID_LOG_REQUEST_LIST:
98 case MAVLINK_MSG_ID_LOG_REQUEST_DATA:
102 case MAVLINK_MSG_ID_LOG_ERASE:
106 case MAVLINK_MSG_ID_LOG_REQUEST_END:
118 return MAVLINK_MSG_ID_LOG_ENTRY_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
122 return MAVLINK_MSG_ID_LOG_DATA_LEN + MAVLINK_NUM_NON_PAYLOAD_BYTES;
135 #define MAX_BYTES_SEND 256 * 1024 155 mavlink_log_request_list_t request;
156 mavlink_msg_log_request_list_decode(msg, &request);
182 PX4LOG_WARN(
"\nMavlinkLogHandler::_log_request_list: start: %u last: %u count: %u\n",
196 PX4LOG_WARN(
"MavlinkLogHandler::_log_request_data Log request with no list requested.\n");
200 mavlink_log_request_data_t request;
201 mavlink_msg_log_request_data_decode(msg, &request);
205 PX4LOG_WARN(
"MavlinkLogHandler::_log_request_data Requested log %u but we only have %u.\n", request.id,
217 uint32_t time_utc = 0;
267 PX4LOG_WARN(
"MavlinkLogHandler::_log_request_end\n");
279 mavlink_log_entry_t response;
282 response.size = size;
283 response.time_utc = date;
297 PX4LOG_WARN(
"MavlinkLogHandler::_log_send_listing id: %u count: %u last: %u size: %u date: %u status: %d\n",
300 response.last_log_num,
304 return sizeof(response);
311 mavlink_log_data_t response;
312 memset(&response, 0,
sizeof(response));
315 if (len >
sizeof(response.data)) {
316 len =
sizeof(response.data);
322 response.count = read_size;
331 return sizeof(response);
339 , current_status(LOG_HANDLER_IDLE)
340 , current_log_index(UINT16_MAX)
341 , current_log_size(0)
342 , current_log_data_offset(0)
343 , current_log_data_remaining(0)
344 , current_log_filep(nullptr)
373 while (fgets(line,
sizeof(line), f)) {
375 if (count++ == idx) {
378 if (sscanf(line,
"%u %u %s", &date, &size, file) == 3) {
379 if (filename && filename_len > 0) {
380 strncpy(filename, file, filename_len);
381 filename[filename_len - 1] = 0;
473 struct dirent *result =
nullptr;
475 while ((result = readdir(dp))) {
479 int ret = snprintf(log_path,
sizeof(log_path),
"%s/%s",
kLogRoot, result->d_name);
480 bool path_is_ok = (ret > 0) && (ret < (
int)
sizeof(log_path));
504 if (strlen(dir) > 4) {
508 if (date > 60 * 60 * 24) {
514 if (strncmp(dir,
"sess", 4) == 0) {
517 if (sscanf(&dir[4],
"%u", &u) == 1) {
518 date = u * 60 * 60 * 24;
531 DIR *dp = opendir(dir);
534 struct dirent *result =
nullptr;
536 while ((result = readdir(dp))) {
540 char log_file_path[128];
541 int ret = snprintf(log_file_path,
sizeof(log_file_path),
"%s/%s", dir, result->d_name);
542 bool path_is_ok = (ret > 0) && (ret < (
int)
sizeof(log_file_path));
547 fprintf(f,
"%u %u %s\n", (
unsigned)ldate, (
unsigned)size, log_file_path);
562 if (file && file[0]) {
563 if (strstr(file,
".px4log") || strstr(file,
".ulg")) {
567 if (date > 60 * 60 * 24) {
573 if (strncmp(file,
"log", 3) == 0) {
576 if (sscanf(&file[3],
"%u", &u) == 1) {
595 DIR *dp = opendir(dir);
601 struct dirent *result =
nullptr;
603 while ((result = readdir(dp))) {
605 if (result ==
nullptr) {
611 int ret = snprintf(log_path,
sizeof(log_path),
"%s/%s", dir, result->d_name);
612 bool path_is_ok = (ret > 0) && (ret < (
int)
sizeof(log_path));
617 if (rmdir(log_path)) {
618 PX4LOG_WARN(
"MavlinkLogHandler::delete_all Error removing %s\n", log_path);
625 int ret = snprintf(log_path,
sizeof(log_path),
"%s/%s", dir, result->d_name);
626 bool path_is_ok = (ret > 0) && (ret < (
int)
sizeof(log_path));
629 if (unlink(log_path)) {
630 PX4LOG_WARN(
"MavlinkLogHandler::delete_all Error deleting %s\n", log_path);
static void delete_all(const char *dir)
#define PX4LOG_WARN(fmt,...)
void _log_request_list(const mavlink_message_t *msg)
uint16_t current_log_index
uint32_t current_log_data_remaining
void _log_request_end(const mavlink_message_t *msg)
void send(const hrt_abstime t)
Handle sending of messages.
size_t _log_send_listing()
MAVLink 2.0 protocol interface definition.
static bool stat_file(const char *file, time_t *date=nullptr, uint32_t *size=nullptr)
void handle_message(const mavlink_message_t *msg)
char current_log_filename[128]
size_t get_log_data(uint8_t len, uint8_t *buffer)
unsigned get_free_tx_buf()
Get the free space in the transmit buffer.
bool _get_log_time_size(const char *path, const char *file, time_t &date, uint32_t &size)
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
#define PX4LOG_REGULAR_FILE
LogListHelper * _pLogHandlerHelper
bool get_entry(int idx, uint32_t &size, uint32_t &date, char *filename=0, int filename_len=0)
MavlinkLogHandler(Mavlink *mavlink)
static const char * kLogData
bool _get_session_date(const char *path, const char *dir, time_t &date)
void _scan_logs(FILE *f, const char *dir, time_t &date)
static const char * kLogRoot
void _log_request_data(const mavlink_message_t *msg)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
uint32_t current_log_data_offset
mavlink_channel_t get_channel() const
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
uint32_t current_log_size
struct @83::@85::@87 file
static const char * kTmpData
void _log_request_erase(const mavlink_message_t *msg)