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}/
|
||||
)
|
||||
|
||||
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.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
|
||||
+20
-1
@@ -1,6 +1,22 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#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[])
|
||||
{
|
||||
@@ -22,6 +38,9 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(portOption);
|
||||
|
||||
parser.process(a);
|
||||
// Initialize the logger
|
||||
init_logger();
|
||||
SPDLOG_INFO("Starting GUI");
|
||||
|
||||
QString host = parser.value(hostOption);
|
||||
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)
|
||||
{
|
||||
QD << "out_of_range::what(): " << ex.what();
|
||||
SPDLOG_CRITICAL("out_of_range: {}", ex.what());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,21 +102,21 @@ void MainWindow::check_active_sim(QString 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);
|
||||
return;
|
||||
}
|
||||
|
||||
QD << "Current sim:" << name;
|
||||
SPDLOG_DEBUG("Current sim:", name);
|
||||
|
||||
if (name == m_selected_sim_name)
|
||||
{
|
||||
QD << "Name set and the same";
|
||||
SPDLOG_DEBUG("Name set and the same");
|
||||
open_sim_window();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+25
-30
@@ -19,8 +19,12 @@ QWidget* SimulatorBase::id_to_ui(size_t id)
|
||||
void SimulatorBase::showEvent( QShowEvent* event )
|
||||
{
|
||||
QWidget::showEvent( event );
|
||||
QD << "Connecting callbacks";
|
||||
setup_cb();
|
||||
SPDLOG_DEBUG("Connecting callbacks");
|
||||
|
||||
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);
|
||||
this->m_timer_update->start(m_refresh_rate);
|
||||
m_open = true;
|
||||
@@ -30,7 +34,7 @@ void SimulatorBase::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
if (m_open == true)
|
||||
{
|
||||
QD << "Disconnecting callbacks";
|
||||
SPDLOG_DEBUG("Disconnecting callbacks");
|
||||
QWidget::closeEvent(event);
|
||||
m_timer_update->stop();
|
||||
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)
|
||||
{
|
||||
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"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto label = qobject_cast<QLabel*>(widget);
|
||||
if (label == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QLabel";
|
||||
SPDLOG_WARN("widget is not of type QLabel");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,14 +163,14 @@ void SimulatorBase::process_ui_slider(json& uiItem)
|
||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto slider = qobject_cast<QwtSlider*>(widget);
|
||||
if (slider == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QwtSlider";
|
||||
SPDLOG_WARN("widget is not of type QwtSlider");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -210,14 +207,14 @@ void SimulatorBase::process_ui_dial(json& uiItem)
|
||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto dial = qobject_cast<QwtDial*>(widget);
|
||||
if (dial == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QwtDial";
|
||||
SPDLOG_WARN("widget is not of type QwtDial");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,14 +245,14 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto thermo = qobject_cast<QwtThermo*>(widget);
|
||||
if (thermo == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QwtThermo";
|
||||
SPDLOG_WARN("widget is not of type QwtThermo");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -282,8 +279,7 @@ void SimulatorBase::process_ui_thermo(json& uiItem)
|
||||
|
||||
void SimulatorBase::process_ui_textbox(json& uiItem)
|
||||
{
|
||||
QD << "Not implemented";
|
||||
emit quit();
|
||||
SPDLOG_CRITICAL("Not implemented");
|
||||
}
|
||||
|
||||
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"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto combobox = qobject_cast<QComboBox*>(widget);
|
||||
if (combobox == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QComboBox";
|
||||
SPDLOG_WARN("widget is not of type QComboBox");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,8 +314,7 @@ void SimulatorBase::process_ui_combobox(json& uiItem)
|
||||
|
||||
void SimulatorBase::process_ui_radiobutton(json& uiItem)
|
||||
{
|
||||
QD << "Not implemented";
|
||||
emit quit();
|
||||
SPDLOG_CRITICAL("Not implemented");
|
||||
}
|
||||
|
||||
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"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto button = qobject_cast<QPushButton*>(widget);
|
||||
if (button == nullptr)
|
||||
{
|
||||
QD << "widget is not of type QPushButton";
|
||||
SPDLOG_WARN("widget is not of type QPushButton");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -389,14 +384,14 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto led = qobject_cast<Led*>(widget);
|
||||
if (led == nullptr)
|
||||
{
|
||||
QD << "widget is not of type led";
|
||||
SPDLOG_WARN("widget is not of type led");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -444,14 +439,14 @@ void SimulatorBase::process_ui_can(json& uiItem)
|
||||
QWidget* widget = id_to_ui(uiItem["id"]);
|
||||
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;
|
||||
}
|
||||
|
||||
auto can_ui = qobject_cast<Can_Transceive*>(widget);
|
||||
if (can_ui == nullptr)
|
||||
{
|
||||
QD << "widget is not of type led";
|
||||
SPDLOG_WARN("widget is not of type led");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,17 +9,14 @@
|
||||
#include "led.h"
|
||||
#include <magic_enum.hpp>
|
||||
#include "IterableEnum.hpp"
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define QD qDebug() << "Debug:" << __FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << ":"
|
||||
|
||||
class SimulatorBase : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SimulatorBase(Web_socket_wrapper* api, QWidget* parent = nullptr);
|
||||
void setup_cb(void);
|
||||
void sim_update(void);
|
||||
QWidget* id_to_ui(size_t id);
|
||||
virtual QLabel* id_to_label(size_t name) {return nullptr;}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "web_socket_wrapper.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "magic_enum.hpp"
|
||||
|
||||
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()
|
||||
{
|
||||
qDebug() << "Pong timeout";
|
||||
SPDLOG_CRITICAL("Pong timeout");
|
||||
m_web_socket->close();
|
||||
emit on_closed();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user