mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
server
move to communication struct
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
#include "simulator_base.hpp"
|
#include "simulator_base.hpp"
|
||||||
|
|
||||||
Simulator_base::Simulator_base(std::string name, CAN_Wrapper *can_wrapper, QSerialPort *serial,
|
Simulator_base::Simulator_base(std::string name, Communication* com,
|
||||||
std::chrono::milliseconds interval, QObject *parent)
|
std::chrono::milliseconds interval, QObject *parent)
|
||||||
: QObject(parent), m_name(name), m_timer(new QTimer(this)), m_interval(interval), m_can_wrapper(can_wrapper),
|
: QObject(parent), m_name(name), m_timer(new QTimer(this)), m_interval(interval), m_com(com)
|
||||||
m_serial(serial)
|
|
||||||
{
|
{
|
||||||
connect(m_timer, &QTimer::timeout, this, [this] { timer(); });
|
connect(m_timer, &QTimer::timeout, this, [this] { timer(); });
|
||||||
m_UI_items.reserve(50);
|
m_UI_items.reserve(50);
|
||||||
|
|||||||
@@ -7,6 +7,15 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#define PUSH_UI_ITEM(item) push_ui_item(&item)
|
#define PUSH_UI_ITEM(item) push_ui_item(&item)
|
||||||
|
struct Communication
|
||||||
|
{
|
||||||
|
CAN_Wrapper* c_if1 = nullptr;
|
||||||
|
CAN_Wrapper* c_if2 = nullptr;
|
||||||
|
QSerialPort* s_if1 = nullptr;
|
||||||
|
QSerialPort* s_if2 = nullptr;
|
||||||
|
QSerialPort* s_if3 = nullptr;
|
||||||
|
QSerialPort* s_if4 = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
class Simulator_base : public QObject
|
class Simulator_base : public QObject
|
||||||
{
|
{
|
||||||
@@ -18,7 +27,7 @@ class Simulator_base : public QObject
|
|||||||
* @param name The name of the simulator
|
* @param name The name of the simulator
|
||||||
* @param interval The interval of the timer (default is 100ms)
|
* @param interval The interval of the timer (default is 100ms)
|
||||||
*/
|
*/
|
||||||
Simulator_base(std::string name, CAN_Wrapper *can_wrapper = nullptr, QSerialPort *serial = nullptr,
|
Simulator_base(std::string name, Communication* comms,
|
||||||
std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject *parent = nullptr);
|
std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject *parent = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -108,6 +117,5 @@ class Simulator_base : public QObject
|
|||||||
std::vector<UI_item *> m_UI_items;
|
std::vector<UI_item *> m_UI_items;
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
std::chrono::milliseconds m_interval;
|
std::chrono::milliseconds m_interval;
|
||||||
CAN_Wrapper *m_can_wrapper;
|
Communication* m_com;
|
||||||
QSerialPort *m_serial;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject
|
|||||||
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_com.c_if1 = m_can_wrapper;
|
||||||
|
m_com.s_if1 = m_serial;
|
||||||
|
|
||||||
INSERT_SIMULATOR(Test_Sim);
|
INSERT_SIMULATOR(Test_Sim);
|
||||||
INSERT_SIMULATOR(Can_Debugger);
|
INSERT_SIMULATOR(Can_Debugger);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "websocket.hpp"
|
#include "websocket.hpp"
|
||||||
|
|
||||||
#define INSERT_SIMULATOR(type) \
|
#define INSERT_SIMULATOR(type) \
|
||||||
m_simulators.insert(std::make_pair(type().name(), std::make_unique<type>(m_can_wrapper, m_serial, this)));
|
m_simulators.insert(std::make_pair(type().name(), std::make_unique<type>(&m_com, this)));
|
||||||
|
|
||||||
class Simulators : public QObject
|
class Simulators : public QObject
|
||||||
{
|
{
|
||||||
@@ -59,6 +59,7 @@ class Simulators : public QObject
|
|||||||
Websocket *m_server;
|
Websocket *m_server;
|
||||||
CAN_Wrapper *m_can_wrapper;
|
CAN_Wrapper *m_can_wrapper;
|
||||||
QSerialPort *m_serial;
|
QSerialPort *m_serial;
|
||||||
|
Communication m_com;
|
||||||
std::map<std::string, std::unique_ptr<Simulator_base>> m_simulators;
|
std::map<std::string, std::unique_ptr<Simulator_base>> m_simulators;
|
||||||
std::string m_current_simulator = "";
|
std::string m_current_simulator = "";
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "can_debugger.hpp"
|
#include "can_debugger.hpp"
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(CAN_Wrapper *can_wrapper, QSerialPort *serial, QObject *parent)
|
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
||||||
: Simulator_base("Can Debugger", can_wrapper, serial, std::chrono::milliseconds(100), parent),
|
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent),
|
||||||
m_wrapper(can_wrapper), m_can_ui(Color::Black, Color::White)
|
m_wrapper(com->c_if1), m_can_ui(Color::Black, Color::White)
|
||||||
{
|
{
|
||||||
PUSH_UI_ITEM(m_can_ui);
|
PUSH_UI_ITEM(m_can_ui);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Can_Debugger : public Simulator_base
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Can_Debugger(CAN_Wrapper *can_wrapper = nullptr, QSerialPort *serial = nullptr, QObject *parent = nullptr);
|
explicit Can_Debugger(Communication *serial = nullptr, QObject *parent = nullptr);
|
||||||
void timer() override;
|
void timer() override;
|
||||||
void run_at_startup() override;
|
void run_at_startup() override;
|
||||||
void run_at_stop() override;
|
void run_at_stop() override;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "test_sim.hpp"
|
#include "test_sim.hpp"
|
||||||
|
|
||||||
Test_Sim::Test_Sim(CAN_Wrapper *can_wrapper, QSerialPort *serial, QObject *parent)
|
Test_Sim::Test_Sim(Communication* com, QObject *parent)
|
||||||
: Simulator_base("Test Sim", can_wrapper, serial, std::chrono::milliseconds(1000), parent),
|
: Simulator_base("Test Sim", com, std::chrono::milliseconds(1000), parent),
|
||||||
m_button("Off", Color::White, Color::Red),
|
m_button("Off", Color::White, Color::Red),
|
||||||
m_combobox(Color::White, Color::Black, {"Option 1", "Option 2", "Option 3"}, 0),
|
m_combobox(Color::White, Color::Black, {"Option 1", "Option 2", "Option 3"}, 0),
|
||||||
m_label("Label", Color::White, Color::Black), m_checkbox("Option 1", Color::Default, Color::Default),
|
m_label("Label", Color::White, Color::Black), m_checkbox("Option 1", Color::Default, Color::Default),
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Test_Sim : public Simulator_base
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Test_Sim(CAN_Wrapper *can_wrapper = nullptr, QSerialPort *serial = nullptr, QObject *parent = nullptr);
|
explicit Test_Sim(Communication* comms = nullptr, QObject *parent = nullptr);
|
||||||
void timer() override;
|
void timer() override;
|
||||||
void run_at_startup() override;
|
void run_at_startup() override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user