mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
client move to spdlog
This commit is contained in:
@@ -99,7 +99,7 @@ target_include_directories(Simulator-CVS_I10
|
|||||||
${PROJECT_BINARY_DIR}/
|
${PROJECT_BINARY_DIR}/
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(Simulator-CVS_I10 PRIVATE qwt Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets magic_enum::magic_enum nlohmann_json::nlohmann_json)
|
target_link_libraries(client PRIVATE qwt spdlog Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::WebSockets magic_enum::magic_enum nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
# If you are developing for iOS or macOS you should consider setting an
|
# If you are developing for iOS or macOS you should consider setting an
|
||||||
|
|||||||
+20
-1
@@ -1,6 +1,22 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include "spdlog/async.h"
|
||||||
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
void init_logger()
|
||||||
|
{
|
||||||
|
spdlog::init_thread_pool(8192, 1);
|
||||||
|
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
|
//auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("log-sim_us.txt", 1024 * 1024 * 10, 3);
|
||||||
|
std::vector<spdlog::sink_ptr> sinks{stdout_sink/*, rotating_sink*/};
|
||||||
|
auto logger = std::make_shared<spdlog::async_logger>("sim_us", sinks.begin(), sinks.end(), spdlog::thread_pool(),
|
||||||
|
spdlog::async_overflow_policy::block);
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
|
spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] %@: %v");
|
||||||
|
spdlog::flush_every(std::chrono::seconds(3));
|
||||||
|
spdlog::set_level(spdlog::level::trace);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@@ -22,6 +38,9 @@ int main(int argc, char *argv[])
|
|||||||
parser.addOption(portOption);
|
parser.addOption(portOption);
|
||||||
|
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
|
// Initialize the logger
|
||||||
|
init_logger();
|
||||||
|
SPDLOG_INFO("Starting GUI");
|
||||||
|
|
||||||
QString host = parser.value(hostOption);
|
QString host = parser.value(hostOption);
|
||||||
uint16_t port = parser.value(portOption).toUShort();
|
uint16_t port = parser.value(portOption).toUShort();
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ void MainWindow::open_sim(QString sim_name)
|
|||||||
}
|
}
|
||||||
catch (const std::out_of_range& ex)
|
catch (const std::out_of_range& ex)
|
||||||
{
|
{
|
||||||
QD << "out_of_range::what(): " << ex.what();
|
SPDLOG_CRITICAL("out_of_range: {}", ex.what());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,21 +102,21 @@ void MainWindow::check_active_sim(QString name)
|
|||||||
{
|
{
|
||||||
if (name == "")
|
if (name == "")
|
||||||
{
|
{
|
||||||
QD << "Name not set";
|
SPDLOG_DEBUG("Name not set");
|
||||||
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QD << "Current sim:" << name;
|
SPDLOG_DEBUG("Current sim:", name);
|
||||||
|
|
||||||
if (name == m_selected_sim_name)
|
if (name == m_selected_sim_name)
|
||||||
{
|
{
|
||||||
QD << "Name set and the same";
|
SPDLOG_DEBUG("Name set and the same");
|
||||||
open_sim_window();
|
open_sim_window();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QD << "Name set and wrong";
|
SPDLOG_DEBUG("Name set and wrong");
|
||||||
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
m_web_socket->send_command(Web_socket_wrapper::Command::switch_simulator, m_selected_sim_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-30
@@ -19,8 +19,12 @@ QWidget* SimulatorBase::id_to_ui(size_t id)
|
|||||||
void SimulatorBase::showEvent( QShowEvent* event )
|
void SimulatorBase::showEvent( QShowEvent* event )
|
||||||
{
|
{
|
||||||
QWidget::showEvent( event );
|
QWidget::showEvent( event );
|
||||||
QD << "Connecting callbacks";
|
SPDLOG_DEBUG("Connecting callbacks");
|
||||||
setup_cb();
|
|
||||||
|
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json& j){on_cmd_cb(j);});
|
||||||
|
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json& j){on_event_cb(j);});
|
||||||
|
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this]{m_error_dialog->open();});
|
||||||
|
|
||||||
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
m_web_socket->send_command(Web_socket_wrapper::Command::get_UI_elements);
|
||||||
this->m_timer_update->start(m_refresh_rate);
|
this->m_timer_update->start(m_refresh_rate);
|
||||||
m_open = true;
|
m_open = true;
|
||||||
@@ -30,7 +34,7 @@ void SimulatorBase::closeEvent(QCloseEvent* event)
|
|||||||
{
|
{
|
||||||
if (m_open == true)
|
if (m_open == true)
|
||||||
{
|
{
|
||||||
QD << "Disconnecting callbacks";
|
SPDLOG_DEBUG("Disconnecting callbacks");
|
||||||
QWidget::closeEvent(event);
|
QWidget::closeEvent(event);
|
||||||
m_timer_update->stop();
|
m_timer_update->stop();
|
||||||
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
disconnect(m_web_socket, nullptr, nullptr, nullptr);
|
||||||
@@ -39,13 +43,6 @@ void SimulatorBase::closeEvent(QCloseEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::setup_cb(void)
|
|
||||||
{
|
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_command_cb, this, [=, this](json& j){on_cmd_cb(j);});
|
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_event_cb, this, [=, this](json& j){on_event_cb(j);});
|
|
||||||
connect(m_web_socket, &Web_socket_wrapper::on_closed, this, [=, this]{m_error_dialog->open();});
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimulatorBase::on_cmd_cb(json& j)
|
void SimulatorBase::on_cmd_cb(json& j)
|
||||||
{
|
{
|
||||||
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Command::end);
|
auto response = magic_enum::enum_cast<Web_socket_wrapper::Command>(std::string(j.at("type"))).value_or(Web_socket_wrapper::Command::end);
|
||||||
@@ -141,14 +138,14 @@ void SimulatorBase::process_ui_label(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto label = qobject_cast<QLabel*>(widget);
|
auto label = qobject_cast<QLabel*>(widget);
|
||||||
if (label == nullptr)
|
if (label == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QLabel";
|
SPDLOG_WARN("widget is not of type QLabel");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,14 +163,14 @@ void SimulatorBase::process_ui_slider(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto slider = qobject_cast<QwtSlider*>(widget);
|
auto slider = qobject_cast<QwtSlider*>(widget);
|
||||||
if (slider == nullptr)
|
if (slider == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QwtSlider";
|
SPDLOG_WARN("widget is not of type QwtSlider");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,14 +207,14 @@ void SimulatorBase::process_ui_dial(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dial = qobject_cast<QwtDial*>(widget);
|
auto dial = qobject_cast<QwtDial*>(widget);
|
||||||
if (dial == nullptr)
|
if (dial == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QwtDial";
|
SPDLOG_WARN("widget is not of type QwtDial");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,14 +245,14 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thermo = qobject_cast<QwtThermo*>(widget);
|
auto thermo = qobject_cast<QwtThermo*>(widget);
|
||||||
if (thermo == nullptr)
|
if (thermo == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QwtThermo";
|
SPDLOG_WARN("widget is not of type QwtThermo");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,8 +279,7 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
|||||||
|
|
||||||
void SimulatorBase::process_ui_textbox(json& uiItem)
|
void SimulatorBase::process_ui_textbox(json& uiItem)
|
||||||
{
|
{
|
||||||
QD << "Not implemented";
|
SPDLOG_CRITICAL("Not implemented");
|
||||||
emit quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_combobox(json& uiItem)
|
void SimulatorBase::process_ui_combobox(json& uiItem)
|
||||||
@@ -291,14 +287,14 @@ void SimulatorBase::process_ui_combobox(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto combobox = qobject_cast<QComboBox*>(widget);
|
auto combobox = qobject_cast<QComboBox*>(widget);
|
||||||
if (combobox == nullptr)
|
if (combobox == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QComboBox";
|
SPDLOG_WARN("widget is not of type QComboBox");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,8 +314,7 @@ void SimulatorBase::process_ui_combobox(json& uiItem)
|
|||||||
|
|
||||||
void SimulatorBase::process_ui_radiobutton(json& uiItem)
|
void SimulatorBase::process_ui_radiobutton(json& uiItem)
|
||||||
{
|
{
|
||||||
QD << "Not implemented";
|
SPDLOG_CRITICAL("Not implemented");
|
||||||
emit quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulatorBase::process_ui_button(json& uiItem)
|
void SimulatorBase::process_ui_button(json& uiItem)
|
||||||
@@ -328,14 +323,14 @@ void SimulatorBase::process_ui_button(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto button = qobject_cast<QPushButton*>(widget);
|
auto button = qobject_cast<QPushButton*>(widget);
|
||||||
if (button == nullptr)
|
if (button == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type QPushButton";
|
SPDLOG_WARN("widget is not of type QPushButton");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,14 +384,14 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto led = qobject_cast<Led*>(widget);
|
auto led = qobject_cast<Led*>(widget);
|
||||||
if (led == nullptr)
|
if (led == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type led";
|
SPDLOG_WARN("widget is not of type led");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,14 +439,14 @@ void SimulatorBase::process_ui_can(json& uiItem)
|
|||||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||||
if (widget == nullptr)
|
if (widget == nullptr)
|
||||||
{
|
{
|
||||||
QD << "id_to_ui returned null on " << QString::number((size_t)uiItem["id"]);
|
SPDLOG_WARN("id_to_ui returned null on {}", QString::number((size_t)uiItem["id"]).toStdString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto can_ui = qobject_cast<Can_Transceive*>(widget);
|
auto can_ui = qobject_cast<Can_Transceive*>(widget);
|
||||||
if (can_ui == nullptr)
|
if (can_ui == nullptr)
|
||||||
{
|
{
|
||||||
QD << "widget is not of type led";
|
SPDLOG_WARN("widget is not of type led");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,17 +9,14 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include <magic_enum.hpp>
|
#include <magic_enum.hpp>
|
||||||
#include "IterableEnum.hpp"
|
#include "IterableEnum.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
#define QD qDebug() << "Debug:" << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << ":"
|
|
||||||
|
|
||||||
class SimulatorBase : public QMainWindow {
|
class SimulatorBase : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SimulatorBase(Web_socket_wrapper* api, QWidget* parent = nullptr);
|
explicit SimulatorBase(Web_socket_wrapper* api, QWidget* parent = nullptr);
|
||||||
void setup_cb(void);
|
|
||||||
void sim_update(void);
|
void sim_update(void);
|
||||||
QWidget* id_to_ui(size_t id);
|
QWidget* id_to_ui(size_t id);
|
||||||
virtual QLabel* id_to_label(size_t name) {return nullptr;}
|
virtual QLabel* id_to_label(size_t name) {return nullptr;}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "web_socket_wrapper.h"
|
#include "web_socket_wrapper.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
#include "magic_enum.hpp"
|
#include "magic_enum.hpp"
|
||||||
|
|
||||||
Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent) :
|
Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent) :
|
||||||
@@ -185,7 +186,7 @@ void Web_socket_wrapper::m_on_pong(quint64 elapsedTime)
|
|||||||
|
|
||||||
void Web_socket_wrapper::m_on_pong_timeout()
|
void Web_socket_wrapper::m_on_pong_timeout()
|
||||||
{
|
{
|
||||||
qDebug() << "Pong timeout";
|
SPDLOG_CRITICAL("Pong timeout");
|
||||||
m_web_socket->close();
|
m_web_socket->close();
|
||||||
emit on_closed();
|
emit on_closed();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user