mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
server logger
move over to qt signals that are processed in simulators
This commit is contained in:
@@ -69,7 +69,7 @@ foreach(sim ${sims})
|
|||||||
# Create a library for each .cpp file
|
# Create a library for each .cpp file
|
||||||
add_library(sim_${LIB_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/simulators/${LIB_NAME}.hpp ${CMAKE_CURRENT_SOURCE_DIR}/simulators/${LIB_NAME}.cpp)
|
add_library(sim_${LIB_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/simulators/${LIB_NAME}.hpp ${CMAKE_CURRENT_SOURCE_DIR}/simulators/${LIB_NAME}.cpp)
|
||||||
target_link_libraries(sim_${LIB_NAME} PRIVATE Qt::SerialBus magic_enum::magic_enum nlohmann_json::nlohmann_json)
|
target_link_libraries(sim_${LIB_NAME} PRIVATE Qt::SerialBus magic_enum::magic_enum nlohmann_json::nlohmann_json)
|
||||||
target_include_directories(sim_${LIB_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/extensions ${CMAKE_SOURCE_DIR}/UI ${CMAKE_SOURCE_DIR}/external/color ${CMAKE_SOURCE_DIR}/external/spdlog/include ${CMAKE_SOURCE_DIR}/external/cpp-templates)
|
target_include_directories(sim_${LIB_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/extensions ${CMAKE_SOURCE_DIR}/UI ${CMAKE_SOURCE_DIR}/external/color ${CMAKE_SOURCE_DIR}/external/cpp-templates)
|
||||||
add_custom_command(TARGET sim_${LIB_NAME} POST_BUILD
|
add_custom_command(TARGET sim_${LIB_NAME} POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
$<TARGET_FILE:sim_${LIB_NAME}>
|
$<TARGET_FILE:sim_${LIB_NAME}>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "spdlog/spdlog.h"
|
|
||||||
#include <QSerialPort>
|
#include <QSerialPort>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -22,6 +21,14 @@ Q_FORWARD_DECLARE_OBJC_CLASS(UI_item);
|
|||||||
return new sim(com, parent); \
|
return new sim(com, parent); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define LOG_SRC_LOC(level, msg) emit log_signal(__FILE__, __LINE__, __FUNCTION__, (int)level, msg)
|
||||||
|
#define LOG_TRACE(msg) LOG_SRC_LOC(Log_level_enum::trace, msg)
|
||||||
|
#define LOG_DEBUG(msg) LOG_SRC_LOC(Log_level_enum::debug, msg)
|
||||||
|
#define LOG_INFO(msg) LOG_SRC_LOC(Log_level_enum::info, msg)
|
||||||
|
#define LOG_WARN(msg) LOG_SRC_LOC(Log_level_enum::warn, msg)
|
||||||
|
#define LOG_ERROR(msg) LOG_SRC_LOC(Log_level_enum::err, msg)
|
||||||
|
#define LOG_CRITICAL(msg) LOG_SRC_LOC(Log_level_enum::critical, msg)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Struct holding all communication interfaces
|
* @brief Struct holding all communication interfaces
|
||||||
*
|
*
|
||||||
@@ -49,6 +56,17 @@ class Simulator_base : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum class Log_level_enum : int
|
||||||
|
{
|
||||||
|
trace,
|
||||||
|
debug,
|
||||||
|
info,
|
||||||
|
warn,
|
||||||
|
err,
|
||||||
|
critical,
|
||||||
|
off,
|
||||||
|
n_levels
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Simulator_base object
|
* @brief Construct a new Simulator_base object
|
||||||
*
|
*
|
||||||
@@ -171,6 +189,8 @@ class Simulator_base : public QObject
|
|||||||
*/
|
*/
|
||||||
void sim_changed();
|
void sim_changed();
|
||||||
|
|
||||||
|
void log_signal(const char *filename_in, int line_in, const char *funcname_in, int level, QString msg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief The name of the simulator
|
* @brief The name of the simulator
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "simulators.hpp"
|
#include "simulators.hpp"
|
||||||
#define INTERNAL
|
#define INTERNAL
|
||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
@@ -153,6 +154,11 @@ void Simulators::switch_simulator(std::string name)
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
|
connect(m_simulators.at(m_current_simulator).get(), &Simulator_base::log_signal, this,
|
||||||
|
[](const char *filename_in, int line_in, const char *funcname_in, int level, QString msg) {
|
||||||
|
spdlog::default_logger_raw()->log(spdlog::source_loc{filename_in, line_in, funcname_in},
|
||||||
|
(spdlog::level::level_enum)level, msg.toStdString());
|
||||||
|
});
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ void Test_Sim::timer()
|
|||||||
void Test_Sim::run_at_startup()
|
void Test_Sim::run_at_startup()
|
||||||
{
|
{
|
||||||
// Run at startup
|
// Run at startup
|
||||||
SPDLOG_INFO("Test_Sim started");
|
LOG_INFO("Test_Sim started");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Sim::button_clicked(UI_button *id)
|
void Test_Sim::button_clicked(UI_button *id)
|
||||||
@@ -86,7 +86,7 @@ void Test_Sim::slider_changed(UI_slider *id, double value)
|
|||||||
{
|
{
|
||||||
if (id == &m_slider)
|
if (id == &m_slider)
|
||||||
{
|
{
|
||||||
SPDLOG_INFO("Test slider changed to {}", value);
|
LOG_INFO(QString("Test slider changed to %0").arg(value));
|
||||||
m_label.set_text(std::to_string(value));
|
m_label.set_text(std::to_string(value));
|
||||||
m_dial.set_value(value);
|
m_dial.set_value(value);
|
||||||
m_thermo.set_value(value);
|
m_thermo.set_value(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user