Skip to content

Commit

Permalink
Merge pull request #208 from MissouriMRDT/feature/rovecomm-logger
Browse files Browse the repository at this point in the history
Add RoveComm Logger
  • Loading branch information
Byrdman32 authored Mar 18, 2024
2 parents fe453b9 + 3c95302 commit ba87b91
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 59 deletions.
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,36 +150,37 @@ endif()
## Link Libraries to Executable
target_link_libraries(${EXE_NAME} PRIVATE Threads::Threads
Eigen3::Eigen
RoveComm_CPP
quill::quill
${OpenCV_LIBS}
${GeographicLib_LIBRARIES}
${ZED_LIBS}
RoveComm_CPP
)

## Package Executable
install(TARGETS ${EXE_NAME} RUNTIME_DEPENDENCIES DIRECTORIES ${OpenCV_LIBS} ${GeographicLib_LIBRARIES} ${ZED_LIBS} quill::quill RoveComm_CPP RUNTIME DESTINATION bin)
install(TARGETS ${EXE_NAME} RUNTIME_DEPENDENCIES DIRECTORIES RoveComm_CPP ${OpenCV_LIBS} ${GeographicLib_LIBRARIES} ${ZED_LIBS} quill::quill RUNTIME DESTINATION bin)

## Unit/Integration Tests
file(GLOB_RECURSE UnitTests_SRC CONFIGURE_DEPENDS "tests/Unit/*.cc")
file(GLOB_RECURSE IntegrationTests_SRC CONFIGURE_DEPENDS "tests/Integration/*.cc")
file(GLOB_RECURSE Algorithms_SRC CONFIGURE_DEPENDS "src/algorithms/*.cpp")
file(GLOB Logging_SRC CONFIGURE_DEPENDS "src/AutonomyLogging.cpp")
file(GLOB Network_SRC CONFIGURE_DEPENDS "src/AutonomyNetworking.cpp")
file(GLOB Logging_SRC CONFIGURE_DEPENDS "src/AutonomyLogging.cpp")

list(LENGTH UnitTests_SRC UnitTests_LEN)
list(LENGTH IntegrationTests_SRC IntegrationTests_LEN)

if (UnitTests_LEN GREATER 0)
add_executable(${EXE_NAME}_UnitTests ${UnitTests_SRC} ${Algorithms_SRC} ${Logging_SRC})
target_link_libraries(${EXE_NAME}_UnitTests GTest::gtest GTest::gtest_main quill::quill ${OpenCV_LIBS} ${GeographicLib_LIBRARIES})
add_executable(${EXE_NAME}_UnitTests ${UnitTests_SRC} ${Algorithms_SRC} ${Network_SRC} ${Logging_SRC})
target_link_libraries(${EXE_NAME}_UnitTests GTest::gtest GTest::gtest_main RoveComm_CPP quill::quill ${OpenCV_LIBS} ${GeographicLib_LIBRARIES})
add_test(Unit_Tests ${EXE_NAME}_UnitTests)
else()
message("No Unit Tests!")
endif()

if (IntegrationTests_LEN GREATER 0)
add_executable(${EXE_NAME}_IntegrationTests ${IntegrationTests_SRC} ${Algorithms_SRC} ${Logging_SRC})
target_link_libraries(${EXE_NAME}_IntegrationTests GTest::gtest GTest::gtest_main quill::quill ${OpenCV_LIBS} ${GeographicLib_LIBRARIES})
add_executable(${EXE_NAME}_IntegrationTests ${IntegrationTests_SRC} ${Algorithms_SRC} ${Network_SRC} ${Logging_SRC})
target_link_libraries(${EXE_NAME}_IntegrationTests GTest::gtest GTest::gtest_main RoveComm_CPP quill::quill ${OpenCV_LIBS} ${GeographicLib_LIBRARIES})
add_test(Integration_Tests ${EXE_NAME}_IntegrationTests)
else()
message("No Integration Tests!")
Expand Down
1 change: 1 addition & 0 deletions data/Custom_Dictionaries/Autonomy-Dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Contoller
cpptools
cschlosser
CUDA
CURRENTLOG
CURRENTSTATE
deadband
debfile
Expand Down
4 changes: 0 additions & 4 deletions src/AutonomyGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ namespace globals
DriveBoard* g_pDriveBoard;
MultimediaBoard* g_pMultimediaBoard;
NavigationBoard* g_pNavigationBoard;

// RoveComm Instances:
rovecomm::RoveCommUDP* g_pRoveCommUDPNode;
rovecomm::RoveCommTCP* g_pRoveCommTCPNode;
} // namespace globals
5 changes: 0 additions & 5 deletions src/AutonomyGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "handlers/WaypointHandler.h"

/// \cond
#include <RoveComm/RoveComm.h>
#include <chrono>
#include <ctime>
#include <iostream>
Expand Down Expand Up @@ -60,10 +59,6 @@ namespace globals
extern DriveBoard* g_pDriveBoard; // Global Drive Board Driver
extern MultimediaBoard* g_pMultimediaBoard; // Global Multimedia Board Driver
extern NavigationBoard* g_pNavigationBoard; // Global Navigation Board Driver

// RoveComm Instances:
extern rovecomm::RoveCommUDP* g_pRoveCommUDPNode; // Global RoveComm UDP Instance.
extern rovecomm::RoveCommTCP* g_pRoveCommTCPNode; // Global RoveComm TCP Instance.
} // namespace globals

#endif // AUTONOMY_GLOBALS_H
65 changes: 53 additions & 12 deletions src/AutonomyLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
******************************************************************************/

#include "AutonomyLogging.h"
#include "AutonomyNetworking.h"

/// \cond
#include <RoveComm/RoveComm.h>
#include <RoveComm/RoveCommManifest.h>
#include <iostream>

/// \endcond
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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
77 changes: 77 additions & 0 deletions src/AutonomyLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <quill/Quill.h>
/// \endcond

#include "./AutonomyConstants.h"

#ifndef AUTONOMY_LOGGING_H
#define AUTONOMY_LOGGING_H

Expand Down Expand Up @@ -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;

/////////////////////////////////////////
Expand Down Expand Up @@ -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
41 changes: 41 additions & 0 deletions src/AutonomyNetworking.cpp
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
40 changes: 40 additions & 0 deletions src/AutonomyNetworking.h
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
Loading

0 comments on commit ba87b91

Please sign in to comment.