mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-25 16:56:25 +08:00
mavlink: bring class LogListHelper into MavlinkLogHandler (#14452)
This is in order to avoid dynamic allocation of LogListHelper when downloading logs.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2014, 2015 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2014, 2020 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -46,52 +46,12 @@
|
||||
|
||||
class Mavlink;
|
||||
|
||||
// Log Listing Helper
|
||||
class LogListHelper
|
||||
{
|
||||
public:
|
||||
LogListHelper();
|
||||
~LogListHelper();
|
||||
|
||||
public:
|
||||
static void delete_all(const char *dir);
|
||||
|
||||
public:
|
||||
|
||||
bool get_entry(int idx, uint32_t &size, uint32_t &date, char *filename = 0, int filename_len = 0);
|
||||
bool open_for_transmit();
|
||||
size_t get_log_data(uint8_t len, uint8_t *buffer);
|
||||
|
||||
enum {
|
||||
LOG_HANDLER_IDLE,
|
||||
LOG_HANDLER_LISTING,
|
||||
LOG_HANDLER_SENDING_DATA
|
||||
};
|
||||
|
||||
int next_entry;
|
||||
int last_entry;
|
||||
int log_count;
|
||||
|
||||
int current_status;
|
||||
uint16_t current_log_index;
|
||||
uint32_t current_log_size;
|
||||
uint32_t current_log_data_offset;
|
||||
uint32_t current_log_data_remaining;
|
||||
FILE *current_log_filep;
|
||||
char current_log_filename[128];
|
||||
|
||||
private:
|
||||
void _init();
|
||||
bool _get_session_date(const char *path, const char *dir, time_t &date);
|
||||
void _scan_logs(FILE *f, const char *dir, time_t &date);
|
||||
bool _get_log_time_size(const char *path, const char *file, time_t &date, uint32_t &size);
|
||||
};
|
||||
|
||||
// MAVLink LOG_* Message Handler
|
||||
class MavlinkLogHandler
|
||||
{
|
||||
public:
|
||||
MavlinkLogHandler(Mavlink *mavlink);
|
||||
~MavlinkLogHandler();
|
||||
|
||||
// Handle possible LOG message
|
||||
void handle_message(const mavlink_message_t *msg);
|
||||
@@ -105,15 +65,43 @@ public:
|
||||
unsigned get_size();
|
||||
|
||||
private:
|
||||
enum class LogHandlerState {
|
||||
Inactive, //There is no active action of log handler
|
||||
Idle, //The log handler is not sending list/data, but list has been sent
|
||||
Listing, //File list is being send
|
||||
SendingData //File Data is being send
|
||||
};
|
||||
void _log_message(const mavlink_message_t *msg);
|
||||
void _log_request_list(const mavlink_message_t *msg);
|
||||
void _log_request_data(const mavlink_message_t *msg);
|
||||
void _log_request_erase(const mavlink_message_t *msg);
|
||||
void _log_request_end(const mavlink_message_t *msg);
|
||||
|
||||
void _reset_list_helper();
|
||||
void _init_list_helper();
|
||||
bool _get_session_date(const char *path, const char *dir, time_t &date);
|
||||
void _scan_logs(FILE *f, const char *dir, time_t &date);
|
||||
bool _get_log_time_size(const char *path, const char *file, time_t &date, uint32_t &size);
|
||||
static void _delete_all(const char *dir);
|
||||
bool _get_entry(int idx, uint32_t &size, uint32_t &date, char *filename = 0, int filename_len = 0);
|
||||
bool _open_for_transmit();
|
||||
size_t _get_log_data(uint8_t len, uint8_t *buffer);
|
||||
void _close_and_unlink_files();
|
||||
|
||||
size_t _log_send_listing();
|
||||
size_t _log_send_data();
|
||||
|
||||
LogListHelper *_pLogHandlerHelper;
|
||||
LogHandlerState _current_status{LogHandlerState::Inactive};
|
||||
Mavlink *_mavlink;
|
||||
|
||||
int _next_entry{0};
|
||||
int _last_entry{0};
|
||||
int _log_count{0};
|
||||
|
||||
uint16_t _current_log_index{UINT16_MAX};
|
||||
uint32_t _current_log_size{0};
|
||||
uint32_t _current_log_data_offset{0};
|
||||
uint32_t _current_log_data_remaining{0};
|
||||
FILE *_current_log_filep{nullptr};
|
||||
char _current_log_filename[128]; //TODO: consider to allocate on runtime
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user