PX4 Firmware
PX4 Autopilot Software http://px4.io
px4::logger::LogWriter Class Reference

Manages starting, stopping & writing of logged data using the configured backend. More...

#include <log_writer.h>

Collaboration diagram for px4::logger::LogWriter:

Public Types

typedef uint8_t Backend
 bitfield to specify a backend More...
 

Public Member Functions

 LogWriter (Backend configured_backend, size_t file_buffer_size)
 
 ~LogWriter ()
 
bool init ()
 
Backend backend () const
 
void thread_stop ()
 stop all running threads and wait for them to exit More...
 
void start_log_file (LogType type, const char *filename)
 
void stop_log_file (LogType type)
 
void start_log_mavlink ()
 
void stop_log_mavlink ()
 
bool is_started (LogType type) const
 whether logging is currently active or not (any of the selected backends). More...
 
bool is_started (LogType type, Backend query_backend) const
 whether logging is currently active or not for a specific backend. More...
 
int write_message (LogType type, void *ptr, size_t size, uint64_t dropout_start=0)
 Write a single ulog message (including header). More...
 
void select_write_backend (Backend sel_backend)
 Select a backend, so that future calls to write_message() only write to the selected sel_backend, until unselect_write_backend() is called. More...
 
void unselect_write_backend ()
 
void lock ()
 
void unlock ()
 
void notify ()
 
size_t get_total_written_file (LogType type) const
 
size_t get_buffer_size_file (LogType type) const
 
size_t get_buffer_fill_count_file (LogType type) const
 
pthread_t thread_id_file () const
 
void set_need_reliable_transfer (bool need_reliable)
 Indicate to the underlying backend whether future write_message() calls need a reliable transfer. More...
 
bool need_reliable_transfer () const
 

Static Public Attributes

static constexpr Backend BackendFile = 1 << 0
 
static constexpr Backend BackendMavlink = 1 << 1
 
static constexpr Backend BackendAll = BackendFile | BackendMavlink
 

Private Attributes

LogWriterFile_log_writer_file = nullptr
 
LogWriterMavlink_log_writer_mavlink = nullptr
 
LogWriterFile_log_writer_file_for_write
 pointer that is used for writing, to temporarily select write backends More...
 
LogWriterMavlink_log_writer_mavlink_for_write = nullptr
 
const Backend _backend
 

Detailed Description

Manages starting, stopping & writing of logged data using the configured backend.

Definition at line 48 of file log_writer.h.

Member Typedef Documentation

◆ Backend

bitfield to specify a backend

Definition at line 53 of file log_writer.h.

Constructor & Destructor Documentation

◆ LogWriter()

px4::logger::LogWriter::LogWriter ( Backend  configured_backend,
size_t  file_buffer_size 
)

◆ ~LogWriter()

px4::logger::LogWriter::~LogWriter ( )

Definition at line 87 of file log_writer.cpp.

References _log_writer_file, and _log_writer_mavlink.

Member Function Documentation

◆ backend()

Backend px4::logger::LogWriter::backend ( ) const
inline

Definition at line 63 of file log_writer.h.

References _backend, is_started(), select_write_backend(), start_log_file(), start_log_mavlink(), stop_log_file(), stop_log_mavlink(), thread_stop(), and write_message().

Referenced by px4::logger::Logger::configured_backend_mode(), px4::logger::Logger::run(), and px4::logger::Logger::start_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_buffer_fill_count_file()

size_t px4::logger::LogWriter::get_buffer_fill_count_file ( LogType  type) const
inline

Definition at line 134 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::get_buffer_fill_count().

Referenced by px4::logger::Logger::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_buffer_size_file()

size_t px4::logger::LogWriter::get_buffer_size_file ( LogType  type) const
inline

Definition at line 127 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::get_buffer_size().

Here is the call graph for this function:

◆ get_total_written_file()

size_t px4::logger::LogWriter::get_total_written_file ( LogType  type) const
inline

Definition at line 120 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::get_total_written().

Here is the call graph for this function:

◆ init()

bool px4::logger::LogWriter::init ( )

Definition at line 61 of file log_writer.cpp.

References _log_writer_file, _log_writer_mavlink, px4::logger::LogWriterMavlink::init(), px4::logger::LogWriterFile::init(), and px4::logger::LogWriterFile::thread_start().

Referenced by px4::logger::Logger::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_started() [1/2]

bool px4::logger::LogWriter::is_started ( LogType  type) const

whether logging is currently active or not (any of the selected backends).

Definition at line 98 of file log_writer.cpp.

References _log_writer_file, _log_writer_mavlink, px4::logger::Full, px4::logger::LogWriterMavlink::is_started(), and px4::logger::LogWriterFile::is_started().

Referenced by backend(), px4::logger::Logger::run(), px4::logger::Logger::start_log_file(), and px4::logger::Logger::stop_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_started() [2/2]

bool px4::logger::LogWriter::is_started ( LogType  type,
Backend  query_backend 
) const

whether logging is currently active or not for a specific backend.

Definition at line 113 of file log_writer.cpp.

References _log_writer_file, _log_writer_mavlink, BackendFile, BackendMavlink, px4::logger::Full, px4::logger::LogWriterMavlink::is_started(), and px4::logger::LogWriterFile::is_started().

Here is the call graph for this function:

◆ lock()

void px4::logger::LogWriter::lock ( )
inline

Definition at line 105 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::lock().

Referenced by px4::logger::Logger::run(), px4::logger::Logger::write_all_add_logged_msg(), px4::logger::Logger::write_changed_parameters(), px4::logger::Logger::write_formats(), px4::logger::Logger::write_header(), px4::logger::Logger::write_info(), px4::logger::Logger::write_info_multiple(), px4::logger::Logger::write_info_template(), and px4::logger::Logger::write_parameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ need_reliable_transfer()

bool px4::logger::LogWriter::need_reliable_transfer ( ) const
inline

Definition at line 160 of file log_writer.h.

References _log_writer_file, _log_writer_mavlink, px4::logger::LogWriterMavlink::need_reliable_transfer(), and px4::logger::LogWriterFile::need_reliable_transfer().

Referenced by px4::logger::Logger::write_add_logged_msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify()

void px4::logger::LogWriter::notify ( )
inline

Definition at line 115 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::notify().

Referenced by px4::logger::Logger::run(), px4::logger::Logger::start_log_file(), px4::logger::Logger::start_log_mavlink(), px4::logger::Logger::write_changed_parameters(), and px4::logger::Logger::write_parameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_write_backend()

void px4::logger::LogWriter::select_write_backend ( Backend  sel_backend)

Select a backend, so that future calls to write_message() only write to the selected sel_backend, until unselect_write_backend() is called.

Parameters
backend

Definition at line 181 of file log_writer.cpp.

References _log_writer_file, _log_writer_file_for_write, _log_writer_mavlink, _log_writer_mavlink_for_write, BackendFile, and BackendMavlink.

Referenced by backend(), px4::logger::Logger::start_log_file(), px4::logger::Logger::start_log_mavlink(), and unselect_write_backend().

Here is the caller graph for this function:

◆ set_need_reliable_transfer()

void px4::logger::LogWriter::set_need_reliable_transfer ( bool  need_reliable)
inline

Indicate to the underlying backend whether future write_message() calls need a reliable transfer.

Needed for header integrity.

Definition at line 153 of file log_writer.h.

References _log_writer_file, _log_writer_mavlink, px4::logger::LogWriterMavlink::set_need_reliable_transfer(), and px4::logger::LogWriterFile::set_need_reliable_transfer().

Referenced by px4::logger::Logger::start_log_file(), px4::logger::Logger::start_log_mavlink(), px4::logger::Logger::stop_log_file(), px4::logger::Logger::write_add_logged_msg(), and px4::logger::Logger::write_load_output().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_log_file()

void px4::logger::LogWriter::start_log_file ( LogType  type,
const char *  filename 
)

Definition at line 126 of file log_writer.cpp.

References _log_writer_file, and px4::logger::LogWriterFile::start_log().

Referenced by backend(), and px4::logger::Logger::start_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_log_mavlink()

void px4::logger::LogWriter::start_log_mavlink ( )

Definition at line 140 of file log_writer.cpp.

References _log_writer_mavlink, and px4::logger::LogWriterMavlink::start_log().

Referenced by backend(), and px4::logger::Logger::start_log_mavlink().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_log_file()

void px4::logger::LogWriter::stop_log_file ( LogType  type)

Definition at line 133 of file log_writer.cpp.

References _log_writer_file, and px4::logger::LogWriterFile::stop_log().

Referenced by backend(), and px4::logger::Logger::stop_log_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_log_mavlink()

void px4::logger::LogWriter::stop_log_mavlink ( )

Definition at line 147 of file log_writer.cpp.

References _log_writer_mavlink, and px4::logger::LogWriterMavlink::stop_log().

Referenced by backend(), and px4::logger::Logger::stop_log_mavlink().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_id_file()

pthread_t px4::logger::LogWriter::thread_id_file ( ) const
inline

Definition at line 141 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::thread_id().

Referenced by px4::logger::Logger::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thread_stop()

void px4::logger::LogWriter::thread_stop ( )

stop all running threads and wait for them to exit

Definition at line 154 of file log_writer.cpp.

References _log_writer_file, and px4::logger::LogWriterFile::thread_stop().

Referenced by backend(), and px4::logger::Logger::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unlock()

void px4::logger::LogWriter::unlock ( )
inline

Definition at line 110 of file log_writer.h.

References _log_writer_file, and px4::logger::LogWriterFile::unlock().

Referenced by px4::logger::Logger::run(), px4::logger::Logger::write_all_add_logged_msg(), px4::logger::Logger::write_changed_parameters(), px4::logger::Logger::write_formats(), px4::logger::Logger::write_header(), px4::logger::Logger::write_info(), px4::logger::Logger::write_info_multiple(), px4::logger::Logger::write_info_template(), and px4::logger::Logger::write_parameters().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unselect_write_backend()

void px4::logger::LogWriter::unselect_write_backend ( )
inline

Definition at line 101 of file log_writer.h.

References select_write_backend().

Referenced by px4::logger::Logger::start_log_file(), and px4::logger::Logger::start_log_mavlink().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_message()

int px4::logger::LogWriter::write_message ( LogType  type,
void *  ptr,
size_t  size,
uint64_t  dropout_start = 0 
)

Write a single ulog message (including header).

The caller must call lock() before calling this.

Parameters
dropout_starttimestamp when lastest dropout occured. 0 if no dropout at the moment.
Returns
0 on success (or if no logging started), -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

Definition at line 161 of file log_writer.cpp.

References _log_writer_file_for_write, _log_writer_mavlink_for_write, px4::logger::Full, px4::logger::LogWriterMavlink::write_message(), and px4::logger::LogWriterFile::write_message().

Referenced by backend(), and px4::logger::Logger::write_message().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _backend

const Backend px4::logger::LogWriter::_backend
private

Definition at line 178 of file log_writer.h.

Referenced by backend().

◆ _log_writer_file

◆ _log_writer_file_for_write

LogWriterFile* px4::logger::LogWriter::_log_writer_file_for_write
private
Initial value:
=
nullptr

pointer that is used for writing, to temporarily select write backends

Definition at line 174 of file log_writer.h.

Referenced by LogWriter(), select_write_backend(), and write_message().

◆ _log_writer_mavlink

LogWriterMavlink* px4::logger::LogWriter::_log_writer_mavlink = nullptr
private

◆ _log_writer_mavlink_for_write

LogWriterMavlink* px4::logger::LogWriter::_log_writer_mavlink_for_write = nullptr
private

Definition at line 176 of file log_writer.h.

Referenced by LogWriter(), select_write_backend(), and write_message().

◆ BackendAll

constexpr Backend px4::logger::LogWriter::BackendAll = BackendFile | BackendMavlink
static

◆ BackendFile

◆ BackendMavlink


The documentation for this class was generated from the following files: