Skip to content

Commit

Permalink
logger: parallel mavlink logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jnippula authored and jlaitine committed Oct 26, 2023
1 parent bdd8196 commit 7f41dc1
Show file tree
Hide file tree
Showing 9 changed files with 603 additions and 30 deletions.
4 changes: 4 additions & 0 deletions src/modules/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
if(CONFIG_LOGGER_PARALLEL_LOGGING)
set(LOGGER_PARALLEL_COMPILE_FLAG "-DLOGGER_PARALLEL_LOGGING")
endif()

px4_add_module(
MODULE modules__logger
Expand All @@ -38,6 +41,7 @@ px4_add_module(
COMPILE_FLAGS
${MAX_CUSTOM_OPT_LEVEL}
-Wno-cast-align # TODO: fix and enable
${LOGGER_PARALLEL_COMPILE_FLAG}
SRCS
logged_topics.cpp
logger.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/modules/logger/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ menuconfig USER_LOGGER
depends on BOARD_PROTECTED && MODULES_LOGGER
---help---
Put logger in userspace memory

menuconfig LOGGER_PARALLEL_LOGGING
bool "Custom mavlink logging protocol in logger"
default n
depends on MODULES_LOGGER
---help---
Utilize custom mavlink logging protocol for speed up logging start phase
13 changes: 11 additions & 2 deletions src/modules/logger/log_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void LogWriter::thread_stop()
}
}

int LogWriter::write_message(LogType type, void *ptr, size_t size, uint64_t dropout_start)
int LogWriter::write_message(LogType type, void *ptr, size_t size, uint64_t dropout_start, bool reliable, bool wait)
{
int ret_file = 0, ret_mavlink = 0;

Expand All @@ -167,7 +167,16 @@ int LogWriter::write_message(LogType type, void *ptr, size_t size, uint64_t drop
}

if (_log_writer_mavlink_for_write && type == LogType::Full) {
ret_mavlink = _log_writer_mavlink_for_write->write_message(ptr, size);
#ifdef LOGGER_PARALLEL_LOGGING

if (reliable) {
ret_mavlink = _log_writer_mavlink_for_write->write_reliable_message(ptr, size, wait);

} else
#endif
{
ret_mavlink = _log_writer_mavlink_for_write->write_message(ptr, size);
}
}

// file backend errors takes precedence
Expand Down
23 changes: 20 additions & 3 deletions src/modules/logger/log_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ class LogWriter

void stop_log_mavlink();

#ifdef LOGGER_PARALLEL_LOGGING
void wait_fifo_empty()
{
if (_log_writer_mavlink) {
_log_writer_mavlink->wait_fifo_count(0);

while (_log_writer_mavlink->reliable_fifo_is_sending()) {
usleep(10000);
}
}
}
#endif

/**
* whether logging is currently active or not (any of the selected backends).
*/
Expand All @@ -90,15 +103,16 @@ class LogWriter
* -1 if not enough space in the buffer left (file backend), -2 mavlink backend failed
* add type -> pass through, but not to mavlink if mission log
*/
int write_message(LogType type, void *ptr, size_t size, uint64_t dropout_start = 0);
int write_message(LogType type, void *ptr, size_t size, uint64_t dropout_start = 0, bool reliable = false,
bool wait = false);

/**
* Select a backend, so that future calls to write_message() only write to the selected
* sel_backend, until unselect_write_backend() is called.
* @param backend
*/
void select_write_backend(Backend sel_backend);
void unselect_write_backend() { select_write_backend(BackendAll); }
void unselect_write_backend() { select_write_backend(_backend); }

/* file logging methods */

Expand Down Expand Up @@ -154,7 +168,11 @@ class LogWriter
{
if (_log_writer_file) { _log_writer_file->set_need_reliable_transfer(need_reliable); }

#ifndef LOGGER_PARALLEL_LOGGING

if (_log_writer_mavlink) { _log_writer_mavlink->set_need_reliable_transfer(need_reliable && mavlink_backed_too); }

#endif
}

bool need_reliable_transfer() const
Expand All @@ -165,7 +183,6 @@ class LogWriter

return false;
}

#if defined(PX4_CRYPTO)
void set_encryption_parameters(px4_crypto_algorithm_t algorithm, uint8_t key_idx, uint8_t exchange_key_idx)
{
Expand Down
Loading

0 comments on commit 7f41dc1

Please sign in to comment.