Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
logging::MRDTRoveCommSink Class Reference

A custom logger sink designed to send formatted log messages over the RoveComm protocol. This class extends quill::Sink and is tailored for use in the Autonomy system, where log messages need to be transmitted as packets over a network to a BaseStation via UDP. More...

#include <AutonomyLogging.h>

Inheritance diagram for logging::MRDTRoveCommSink:
Collaboration diagram for logging::MRDTRoveCommSink:

Public Member Functions

 MRDTRoveCommSink (std::string const &szFormatPattern, std::string const &szTimeFormat, quill::Timezone qTimestampTimezone)
 Constructs a new MRDTRoveCommSink object with the specified format pattern, time format, and optional timezone. This constructor initializes the sink with the necessary format settings for logging messages and prepares them to be transmitted over the RoveComm protocol.
 
 ~MRDTRoveCommSink () override=default
 Destroy the MRDTRoveCommSink object.
 
void write_log (const quill::MacroMetadata *qLogMetadata, uint64_t unLogTimestamp, std::string_view szThreadID, std::string_view szThreadName, const std::string &szProcessID, std::string_view szLoggerName, quill::LogLevel qLogLevel, std::string_view szLogLevelDescription, std::string_view szLogLevelShortCode, const std::vector< std::pair< std::string, std::string > > *vNamedArgs, std::string_view szLogMessage, std::string_view) override
 Formats a log message and sends it as a RoveComm packet to the BaseStation. The log message is formatted using the provided metadata, thread, and process information, then packed and transmitted via RoveComm protocol to a specified IP address and port.
 
void flush_sink () noexcept override
 This method should never be called by this codebase, it is called internally by the quill library.
 

Private Member Functions

std::vector< char > StringToVector (const std::string &szString)
 A utility function to convert a string to a vector that is no longer than 255 characters long.
 

Private Attributes

quill::PatternFormatter qFormatter
 

Detailed Description

A custom logger sink designed to send formatted log messages over the RoveComm protocol. This class extends quill::Sink and is tailored for use in the Autonomy system, where log messages need to be transmitted as packets over a network to a BaseStation via UDP.

The MRDTRoveCommSink class formats log messages using a specified pattern and time format, and then transmits the formatted messages as RoveCommPacket objects. It integrates with the Quill logging framework and is designed to handle both real-time and networked logging scenarios.

Key Features:

  • Customizable log message formats using a pattern.
  • Integration with the RoveComm protocol for network transmission of log messages.
  • Handles the conversion of log messages to a format suitable for network transmission.
  • Inherits from quill::Sink for seamless integration with Quill's logging framework.
Note
This class is intended for use in networked logging scenarios where logs are transmitted to a BaseStation using the RoveComm protocol. It should not be called directly but instead used as part of the Quill logging framework.
See also
quill::Sink
rovecomm::RoveCommPacket
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-03-17

Constructor & Destructor Documentation

◆ MRDTRoveCommSink()

logging::MRDTRoveCommSink::MRDTRoveCommSink ( std::string const &  szFormatPattern,
std::string const &  szTimeFormat,
quill::Timezone  qTimestampTimezone 
)
inline

Constructs a new MRDTRoveCommSink object with the specified format pattern, time format, and optional timezone. This constructor initializes the sink with the necessary format settings for logging messages and prepares them to be transmitted over the RoveComm protocol.

Parameters
szFormatPattern- The pattern used to format the log message.
szTimeFormat- The format of the timestamp in the log message.
qTimestampTimezone- The timezone used for the timestamp (default: LocalTime).
Note
Ensure that the format pattern and time format are correctly set to match the expected format for the log messages. This is crucial for ensuring the proper transmission and interpretation of log data over the RoveComm protocol.
Warning
Misconfiguration of the format pattern or time format may lead to incorrect log formatting and potential issues with packet transmission.
See also
quill::Sink
rovecomm::RoveCommPacket
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-03-17
455 :
456 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
457 {}

◆ ~MRDTRoveCommSink()

logging::MRDTRoveCommSink::~MRDTRoveCommSink ( )
overridedefault

Destroy the MRDTRoveCommSink object.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-03-17

Member Function Documentation

◆ StringToVector()

std::vector< char > logging::MRDTRoveCommSink::StringToVector ( const std::string &  szString)
inlineprivate

A utility function to convert a string to a vector that is no longer than 255 characters long.

Parameters
szString- The string to convert
Returns
std::vector<char> - The string shown as a vector of characters.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-03-17
418 {
419 std::vector<char> result;
420 int length = std::min(static_cast<int>(szString.length()), 255);
421 result.reserve(length);
422
423 for (int i = 0; i < length; ++i)
424 {
425 result.push_back(szString[i]);
426 }
427
428 return result;
429 }
Here is the caller graph for this function:

◆ write_log()

void logging::MRDTRoveCommSink::write_log ( const quill::MacroMetadata *  qLogMetadata,
uint64_t  unLogTimestamp,
std::string_view  szThreadID,
std::string_view  szThreadName,
const std::string &  szProcessID,
std::string_view  szLoggerName,
quill::LogLevel  qLogLevel,
std::string_view  szLogLevelDescription,
std::string_view  szLogLevelShortCode,
const std::vector< std::pair< std::string, std::string > > *  vNamedArgs,
std::string_view  szLogMessage,
std::string_view  log_statement 
)
override

Formats a log message and sends it as a RoveComm packet to the BaseStation. The log message is formatted using the provided metadata, thread, and process information, then packed and transmitted via RoveComm protocol to a specified IP address and port.

This function utilizes a custom formatter to combine metadata and log message content into a single formatted string, which is then converted into a RoveCommPacket and sent to the BaseStation over UDP.

Parameters
qLogMetadata- Metadata about the log statement (e.g., file, line number).
unLogTimestamp- The timestamp of the log statement.
szThreadID- The ID of the thread that generated the log.
szThreadName- The name of the thread that generated the log.
szProcessID- The ID of the process that generated the log.
szLoggerName- The name of the logger that generated the log.
qLogLevel- The level/severity of the log statement (currently unused).
szLogLevelDescription- A description of the log level.
szLogLevelShortCode- A short code representing the log level.
vNamedArgs- Optional named arguments passed with the log statement.
szLogMessage- The actual log message content.
log_statement- The full log statement (currently unused).
Note
This method formats the log message and sends it as a RoveComm packet to the BaseStation if both UDP and TCP statuses are active. The log level and log statement parameters are not currently used in the packet creation.
This method should not be called directly. It is meant to be invoked by the logging framework as part of the log handling process.
See also
quill::MacroMetadata
rovecomm::RoveCommPacket
network::SendUDPPacket
Warning
Ensure that the RoveComm protocol is correctly configured and that both UDP and TCP statuses are active before calling this method to avoid packet transmission failure.
Attention
The formatter must be properly configured to ensure the correct format of the log message before it is sent as a RoveComm packet.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-08-16
397 {
398 // Not using these (for now)
399 (void) qLogLevel;
400 (void) log_statement;
401
402 // Format the log message
403 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp, // Timestamp
404 szThreadID, // Thread ID
405 szThreadName, // Thread name
406 szProcessID, // Process ID
407 szLoggerName, // Logger name
408 szLogLevelDescription, // Log level description
409 szLogLevelShortCode, // Log level short code
410 *qLogMetadata, // Log statement metadata
411 vNamedArgs, // Named arguments
412 szLogMessage // Log message
413 );
414
415 // Check if logging level is permitted
416 if (static_cast<int>(g_eRoveCommLogLevel) <= static_cast<int>(qLogLevel))
417 {
418 // Construct a RoveComm packet with the logging data.
419 rovecomm::RoveCommPacket<char> stPacket;
420 stPacket.unDataId = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_ID;
421 stPacket.unDataCount = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_COUNT;
422 stPacket.eDataType = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_TYPE;
423 stPacket.vData = StringToVector({szFormattedLogMessage.data(), szFormattedLogMessage.size()});
424
425 // Send log command over RoveComm to BaseStation.
426 if (network::g_bRoveCommUDPStatus && network::g_bRoveCommTCPStatus)
427 {
428 network::g_pRoveCommUDPNode->SendUDPPacket(stPacket, "0.0.0.0", constants::ROVECOMM_OUTGOING_UDP_PORT);
429 }
430 }
431 }
std::vector< char > StringToVector(const std::string &szString)
A utility function to convert a string to a vector that is no longer than 255 characters long.
Definition AutonomyLogging.h:417
Here is the call graph for this function:

◆ flush_sink()

void logging::MRDTRoveCommSink::flush_sink ( )
inlineoverridenoexcept

This method should never be called by this codebase, it is called internally by the quill library.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-03-17
487{}

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