-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from MissouriMRDT/feature/rovecomm-logger
Add RoveComm Logger
- Loading branch information
Showing
14 changed files
with
257 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ Contoller | |
cpptools | ||
cschlosser | ||
CUDA | ||
CURRENTLOG | ||
CURRENTSTATE | ||
deadband | ||
debfile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,11 @@ | |
******************************************************************************/ | ||
|
||
#include "AutonomyLogging.h" | ||
#include "AutonomyNetworking.h" | ||
|
||
/// \cond | ||
#include <RoveComm/RoveComm.h> | ||
#include <RoveComm/RoveCommManifest.h> | ||
#include <iostream> | ||
|
||
/// \endcond | ||
|
@@ -30,6 +33,7 @@ namespace logging | |
///////////////////////////////////////// | ||
quill::Logger* g_qFileLogger; | ||
quill::Logger* g_qConsoleLogger; | ||
quill::Logger* g_qRoveCommLogger; | ||
quill::Logger* g_qSharedLogger; | ||
std::string g_szProgramStartTimeString; | ||
|
||
|
@@ -82,17 +86,22 @@ namespace logging | |
std::filesystem::path szFullOutputPath = szFilePath / szFilenameWithExtension; | ||
|
||
// Create Handlers | ||
std::shared_ptr<quill::Handler> qFileHandler = quill::rotating_file_handler(szFullOutputPath); | ||
std::shared_ptr<quill::Handler> qConsoleHandler = quill::stdout_handler(); | ||
std::shared_ptr<quill::Handler> qFileHandler = quill::rotating_file_handler(szFullOutputPath); | ||
std::shared_ptr<quill::Handler> qConsoleHandler = quill::stdout_handler(); | ||
std::shared_ptr<quill::Handler> qRoveCommHandler = quill::create_handler<RoveCommHandler>("RoveCommHandler"); | ||
|
||
// Configure Patterns | ||
qFileHandler->set_pattern("%(ascii_time) %(level_name) [%(thread)] [%(filename):%(lineno)] %(message)", // format | ||
"%Y-%m-%d %H:%M:%S.%Qms", // timestamp format | ||
quill::Timezone::GmtTime); // timestamp's timezone | ||
qFileHandler->set_pattern("%(ascii_time) %(level_name) [%(thread)] [%(filename):%(lineno)] %(message)", // format | ||
"%Y-%m-%d %H:%M:%S.%Qms", // timestamp format | ||
quill::Timezone::GmtTime); // timestamp's timezone | ||
|
||
qConsoleHandler->set_pattern("%(ascii_time) %(level_name) [%(thread)] [%(filename):%(lineno)] %(message)", // format | ||
"%Y-%m-%d %H:%M:%S.%Qms", // timestamp format | ||
quill::Timezone::GmtTime); // timestamp's timezone | ||
qConsoleHandler->set_pattern("%(ascii_time) %(level_name) [%(thread)] [%(filename):%(lineno)] %(message)", // format | ||
"%Y-%m-%d %H:%M:%S.%Qms", // timestamp format | ||
quill::Timezone::GmtTime); // timestamp's timezone | ||
|
||
qRoveCommHandler->set_pattern("%(ascii_time) %(level_name) [%(thread)] [%(filename):%(lineno)] %(message)", // format | ||
"%Y-%m-%d %H:%M:%S.%Qms", // timestamp format | ||
quill::Timezone::GmtTime); // timestamp's timezone | ||
|
||
// Enable Color Console | ||
static_cast<quill::ConsoleHandler*>(qConsoleHandler.get())->enable_console_colours(); | ||
|
@@ -109,20 +118,52 @@ namespace logging | |
// Set Handler Filters | ||
qFileHandler->add_filter(std::make_unique<LoggingFilter>("FileFilter", quill::LogLevel::TraceL3)); | ||
qConsoleHandler->add_filter(std::make_unique<LoggingFilter>("ConsoleFilter", quill::LogLevel::Info)); | ||
qRoveCommHandler->add_filter(std::make_unique<LoggingFilter>("RoveCommFilter", quill::LogLevel::Info)); | ||
|
||
// Create Loggers | ||
g_qFileLogger = quill::create_logger("FILE_LOGGER", {qFileHandler}); | ||
g_qConsoleLogger = quill::create_logger("CONSOLE_LOGGER", {qConsoleHandler}); | ||
g_qSharedLogger = quill::create_logger("SHARED_LOGGER", {qFileHandler, qConsoleHandler}); | ||
g_qFileLogger = quill::create_logger("FILE_LOGGER", {qFileHandler}); | ||
g_qConsoleLogger = quill::create_logger("CONSOLE_LOGGER", {qConsoleHandler}); | ||
g_qRoveCommLogger = quill::create_logger("ROVECOMM_LOGGER", {qRoveCommHandler}); | ||
g_qSharedLogger = quill::create_logger("SHARED_LOGGER", {qFileHandler, qConsoleHandler, qRoveCommHandler}); | ||
|
||
// Set Base Logging Levels | ||
g_qSharedLogger->set_log_level(quill::LogLevel::TraceL3); | ||
g_qFileLogger->set_log_level(quill::LogLevel::TraceL3); | ||
g_qConsoleLogger->set_log_level(quill::LogLevel::TraceL3); | ||
g_qRoveCommLogger->set_log_level(quill::LogLevel::TraceL3); | ||
g_qSharedLogger->set_log_level(quill::LogLevel::TraceL3); | ||
|
||
// Enable Backtrace | ||
g_qFileLogger->init_backtrace(2, quill::LogLevel::Critical); | ||
g_qConsoleLogger->init_backtrace(2, quill::LogLevel::Critical); | ||
g_qRoveCommLogger->init_backtrace(2, quill::LogLevel::Critical); | ||
g_qSharedLogger->init_backtrace(2, quill::LogLevel::Critical); | ||
} | ||
|
||
/****************************************************************************** | ||
* @brief This method should never be called by this codebase, it is called | ||
* internally by the quill library. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
void RoveCommHandler::write(quill::fmt_buffer_t const& formatted_log_message, quill::TransitEvent const& log_event) | ||
{ | ||
// Not using these. | ||
(void) log_event; | ||
|
||
std::string szTemp{formatted_log_message.data(), formatted_log_message.size()}; | ||
|
||
// Construct a RoveComm packet with the logging data. | ||
rovecomm::RoveCommPacket<char> stPacket; | ||
stPacket.unDataId = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_ID; | ||
stPacket.unDataCount = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_COUNT; | ||
stPacket.eDataType = manifest::Autonomy::TELEMETRY.find("CURRENTLOG")->second.DATA_TYPE; | ||
stPacket.vData = StringToVector({formatted_log_message.data(), formatted_log_message.size()}); | ||
|
||
// Send log command over RoveComm to BaseStation. | ||
if (network::g_bRoveCommUDPStatus && network::g_bRoveCommTCPStatus) | ||
{ | ||
network::g_pRoveCommUDPNode->SendUDPPacket(stPacket, "0.0.0.0", constants::ROVECOMM_OUTGOING_UDP_PORT); | ||
} | ||
} | ||
} // namespace logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ | |
#include <quill/Quill.h> | ||
/// \endcond | ||
|
||
#include "./AutonomyConstants.h" | ||
|
||
#ifndef AUTONOMY_LOGGING_H | ||
#define AUTONOMY_LOGGING_H | ||
|
||
|
@@ -56,6 +58,7 @@ namespace logging | |
extern quill::Logger* g_qFileLogger; | ||
extern quill::Logger* g_qConsoleLogger; | ||
extern quill::Logger* g_qSharedLogger; | ||
extern quill::Logger* g_qRoveCommLogger; | ||
extern std::string g_szProgramStartTimeString; | ||
|
||
///////////////////////////////////////// | ||
|
@@ -122,5 +125,79 @@ namespace logging | |
} | ||
}; | ||
|
||
///////////////////////////////////////// | ||
// Define namespace custom handler | ||
///////////////////////////////////////// | ||
|
||
/****************************************************************************** | ||
* @brief This class serves as a container class for a custom logger type | ||
* defined to send logging messages over RoveComm from Autonomy. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
class RoveCommHandler : public quill::Handler | ||
{ | ||
private: | ||
/****************************************************************************** | ||
* @brief A utility function to convert a string to a vector that is no longer | ||
* than 255 characters long. | ||
* | ||
* @param szString - The string to convert | ||
* @return std::vector<char> - The string shown as a vector of characters. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
std::vector<char> StringToVector(const std::string& szString) | ||
{ | ||
std::vector<char> result; | ||
int length = std::min(static_cast<int>(szString.length()), 255); | ||
result.reserve(length); | ||
|
||
for (int i = 0; i < length; ++i) | ||
{ | ||
result.push_back(szString[i]); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public: | ||
/****************************************************************************** | ||
* @brief Construct a new RoveCommHandler object. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
RoveCommHandler() = default; | ||
|
||
/****************************************************************************** | ||
* @brief Destroy the RoveCommHandler object. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
~RoveCommHandler() override = default; | ||
|
||
/****************************************************************************** | ||
* @brief This method should never be called by this codebase, it is called | ||
* internally by the quill library. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
void write(quill::fmt_buffer_t const& formatted_log_message, quill::TransitEvent const& log_event) override; | ||
|
||
/****************************************************************************** | ||
* @brief This method should never be called by this codebase, it is called | ||
* internally by the quill library. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
void flush() noexcept override {} | ||
}; | ||
|
||
} // namespace logging | ||
#endif // AUTONOMY_LOGGING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/****************************************************************************** | ||
* @brief Defines functions and objects used for Autonomy Networking | ||
* | ||
* @file AutonomyNetworking.cpp | ||
* @author Eli Byrd ([email protected]), ClayJay3 ([email protected]) | ||
* @date 2024-03-17 | ||
* | ||
* @copyright Copyright Mars Rover Design Team 2024 - All Rights Reserved | ||
******************************************************************************/ | ||
|
||
#include "AutonomyNetworking.h" | ||
|
||
/****************************************************************************** | ||
* @brief Defines functions and objects used for Autonomy Networking | ||
* | ||
* @file AutonomyNetworking.cpp | ||
* @author Eli Byrd ([email protected]), ClayJay3 ([email protected]) | ||
* @date 2024-03-17 | ||
* | ||
* @copyright Copyright Mars Rover Design Team 2024 - All Rights Reserved | ||
******************************************************************************/ | ||
|
||
#include "AutonomyNetworking.h" | ||
|
||
/****************************************************************************** | ||
* @brief Namespace containing all networking types/structs that will be used | ||
* project wide. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
namespace network | ||
{ | ||
// RoveComm Instances: | ||
rovecomm::RoveCommUDP* g_pRoveCommUDPNode; | ||
rovecomm::RoveCommTCP* g_pRoveCommTCPNode; | ||
|
||
// RoveComm Status: | ||
bool g_bRoveCommUDPStatus = false; | ||
bool g_bRoveCommTCPStatus = false; | ||
} // namespace network |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/****************************************************************************** | ||
* @brief Defines functions and objects used for Autonomy Networking | ||
* | ||
* @file AutonomyNetworking.h | ||
* @author Eli Byrd ([email protected]), ClayJay3 ([email protected]) | ||
* @date 2024-03-17 | ||
* | ||
* @copyright Copyright Mars Rover Design Team 2024 - All Rights Reserved | ||
******************************************************************************/ | ||
|
||
/// \cond | ||
#include <RoveComm/RoveComm.h> | ||
#include <chrono> | ||
#include <ctime> | ||
#include <iostream> | ||
|
||
/// \endcond | ||
|
||
#ifndef AUTONOMY_NETWORKING_H | ||
#define AUTONOMY_NETWORKING_H | ||
|
||
/****************************************************************************** | ||
* @brief Namespace containing all networking types/structs that will be used | ||
* project wide. | ||
* | ||
* @author Eli Byrd ([email protected]) | ||
* @date 2024-03-17 | ||
******************************************************************************/ | ||
namespace network | ||
{ | ||
// RoveComm Instances: | ||
extern rovecomm::RoveCommUDP* g_pRoveCommUDPNode; // Global RoveComm UDP Instance. | ||
extern rovecomm::RoveCommTCP* g_pRoveCommTCPNode; // Global RoveComm TCP Instance. | ||
|
||
// RoveComm Status: | ||
extern bool g_bRoveCommUDPStatus; | ||
extern bool g_bRoveCommTCPStatus; | ||
} // namespace network | ||
|
||
#endif // AUTONOMY_NETWORKING_H |
Oops, something went wrong.