mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
server
update main command line arguments
This commit is contained in:
+27
-13
@@ -38,28 +38,42 @@ int main(int argc, char *argv[])
|
|||||||
<< "port",
|
<< "port",
|
||||||
QCoreApplication::translate("main", "Port for the unisim server [default: 9002]."),
|
QCoreApplication::translate("main", "Port for the unisim server [default: 9002]."),
|
||||||
QCoreApplication::translate("main", "port"), QLatin1String("9002"));
|
QCoreApplication::translate("main", "port"), QLatin1String("9002"));
|
||||||
QCommandLineOption can_port_option(QStringList() << "c"
|
QCommandLineOption can_port0_option(QStringList() << "c0", QCoreApplication::translate("main", "CAN device 0."),
|
||||||
<< "can",
|
QCoreApplication::translate("main", "can device 0."));
|
||||||
QCoreApplication::translate("main", "CAN device."),
|
QCommandLineOption can_port1_option(QStringList() << "c1", QCoreApplication::translate("main", "CAN device 1."),
|
||||||
QCoreApplication::translate("main", "can device"));
|
QCoreApplication::translate("main", "can device 1."));
|
||||||
QCommandLineOption uart_port_option(QStringList() << "u"
|
QCommandLineOption can_port2_option(QStringList() << "c2", QCoreApplication::translate("main", "CAN device 2."),
|
||||||
<< "uart",
|
QCoreApplication::translate("main", "can device 2."));
|
||||||
QCoreApplication::translate("main", "uart device."),
|
QCommandLineOption uart_port0_option(QStringList() << "u0", QCoreApplication::translate("main", "uart device 0."),
|
||||||
QCoreApplication::translate("main", "uart device"));
|
QCoreApplication::translate("main", "uart device 0."));
|
||||||
|
QCommandLineOption uart_port1_option(QStringList() << "u1", QCoreApplication::translate("main", "uart device 1."),
|
||||||
|
QCoreApplication::translate("main", "uart device 1."));
|
||||||
|
QCommandLineOption uart_port2_option(QStringList() << "u2", QCoreApplication::translate("main", "uart device 2."),
|
||||||
|
QCoreApplication::translate("main", "uart device 2."));
|
||||||
|
QCommandLineOption uart_port3_option(QStringList() << "u3", QCoreApplication::translate("main", "uart device 3."),
|
||||||
|
QCoreApplication::translate("main", "uart device 3."));
|
||||||
parser.addOption(port_option);
|
parser.addOption(port_option);
|
||||||
parser.addOption(can_port_option);
|
parser.addOption(can_port0_option);
|
||||||
parser.addOption(uart_port_option);
|
parser.addOption(can_port1_option);
|
||||||
|
parser.addOption(can_port2_option);
|
||||||
|
parser.addOption(uart_port0_option);
|
||||||
|
parser.addOption(uart_port1_option);
|
||||||
|
parser.addOption(uart_port2_option);
|
||||||
|
parser.addOption(uart_port3_option);
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
uint16_t port = parser.value(port_option).toUShort();
|
uint16_t port = parser.value(port_option).toUShort();
|
||||||
QString can_port = parser.value(can_port_option);
|
QStringList can_ports;
|
||||||
QString uart_port = parser.value(uart_port_option);
|
QStringList uart_ports;
|
||||||
|
can_ports << parser.value(can_port0_option) << parser.value(can_port1_option) << parser.value(can_port2_option);
|
||||||
|
uart_ports << parser.value(uart_port0_option) << parser.value(uart_port1_option) << parser.value(uart_port2_option)
|
||||||
|
<< parser.value(uart_port3_option);
|
||||||
|
|
||||||
// Initialize the logger
|
// Initialize the logger
|
||||||
init_logger();
|
init_logger();
|
||||||
|
|
||||||
// The server starts in this thread
|
// The server starts in this thread
|
||||||
SPDLOG_INFO("Starting server");
|
SPDLOG_INFO("Starting server");
|
||||||
Simulators simulators(port, can_port, uart_port);
|
Simulators simulators(port, can_ports, uart_ports);
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(CAN_Wrapper);
|
#include "CAN_wrapper.hpp"
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(UI_item);
|
Q_FORWARD_DECLARE_OBJC_CLASS(UI_item);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -33,12 +33,12 @@ class Communication
|
|||||||
* @brief Array of CAN interfaces
|
* @brief Array of CAN interfaces
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
CAN_Wrapper *can_if[3] = {nullptr, nullptr, nullptr};
|
std::unique_ptr<CAN_Wrapper> can_if[3] = {nullptr, nullptr, nullptr};
|
||||||
/**
|
/**
|
||||||
* @brief Array of UART interfaces
|
* @brief Array of UART interfaces
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
QSerialPort *uart_if[4] = {nullptr, nullptr, nullptr, nullptr};
|
std::unique_ptr<QSerialPort> uart_if[4] = {nullptr, nullptr, nullptr, nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+31
-23
@@ -9,34 +9,44 @@
|
|||||||
|
|
||||||
typedef Simulator_base *(*Get_Sim)(Communication *, QObject *);
|
typedef Simulator_base *(*Get_Sim)(Communication *, QObject *);
|
||||||
|
|
||||||
Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent)
|
Simulators::Simulators(uint16_t port, QStringList can_devs, QStringList uart_devs, QObject *parent)
|
||||||
: QObject(parent), m_server_thread(new QThread), m_server(new Websocket(port, nullptr)),
|
: QObject(parent), m_server_thread(new QThread), m_server(new Websocket(port, nullptr)), m_com(new Communication)
|
||||||
m_can_wrapper(new CAN_Wrapper(new CAN_Interface(this), this)), m_serial(new QSerialPort(this)),
|
|
||||||
m_com(new Communication)
|
|
||||||
{
|
{
|
||||||
m_server->moveToThread(m_server_thread);
|
m_server->moveToThread(m_server_thread);
|
||||||
m_server_thread->start();
|
m_server_thread->start();
|
||||||
// TODO: Cleanup this code and make it possible to add multiple com devices
|
|
||||||
if (!can_dev.isEmpty())
|
|
||||||
{
|
|
||||||
m_can_wrapper->connect_to_dev(can_dev);
|
|
||||||
}
|
|
||||||
if (!uart_dev.isEmpty())
|
|
||||||
{
|
|
||||||
m_serial->setPortName(uart_dev);
|
|
||||||
m_serial->setBaudRate(QSerialPort::Baud115200);
|
|
||||||
m_serial->setDataBits(QSerialPort::Data8);
|
|
||||||
m_serial->setParity(QSerialPort::NoParity);
|
|
||||||
m_serial->setStopBits(QSerialPort::OneStop);
|
|
||||||
m_serial->setFlowControl(QSerialPort::NoFlowControl);
|
|
||||||
|
|
||||||
if (!m_serial->open(QIODevice::ReadWrite))
|
size_t count = 0;
|
||||||
|
for (const auto &can_dev : can_devs)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
if (can_dev.isEmpty())
|
||||||
|
continue;
|
||||||
|
m_com->can_if[count - 1] = std::make_unique<CAN_Wrapper>(this);
|
||||||
|
m_com->can_if[count - 1]->connect_to_dev(can_dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (const auto &uart_dev : uart_devs)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
if (uart_dev.isEmpty())
|
||||||
|
continue;
|
||||||
|
m_com->uart_if[count - 1] = std::make_unique<QSerialPort>(this);
|
||||||
|
|
||||||
|
m_com->uart_if[count - 1]->setPortName("/dev/" + uart_dev);
|
||||||
|
m_com->uart_if[count - 1]->setBaudRate(QSerialPort::Baud115200);
|
||||||
|
m_com->uart_if[count - 1]->setDataBits(QSerialPort::Data8);
|
||||||
|
m_com->uart_if[count - 1]->setParity(QSerialPort::NoParity);
|
||||||
|
m_com->uart_if[count - 1]->setStopBits(QSerialPort::OneStop);
|
||||||
|
m_com->uart_if[count - 1]->setFlowControl(QSerialPort::NoFlowControl);
|
||||||
|
|
||||||
|
if (!m_com->uart_if[count - 1]->open(QIODevice::ReadWrite))
|
||||||
{
|
{
|
||||||
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
SPDLOG_CRITICAL("UART: /dev/{} {}", m_com->uart_if[count - 1]->portName().toStdString(), m_com->uart_if[count - 1]->errorString().toStdString());
|
||||||
|
m_com->uart_if[count - 1]->deleteLater();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_com->can_if[0] = m_can_wrapper;
|
|
||||||
m_com->uart_if[0] = m_serial;
|
|
||||||
|
|
||||||
QLibrary lib;
|
QLibrary lib;
|
||||||
QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so", QDir::Files,
|
QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so", QDir::Files,
|
||||||
@@ -70,8 +80,6 @@ Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject
|
|||||||
|
|
||||||
Simulators::~Simulators()
|
Simulators::~Simulators()
|
||||||
{
|
{
|
||||||
if (m_serial->isOpen())
|
|
||||||
m_serial->close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Simulators::active_simulator_name() const
|
std::string Simulators::active_simulator_name() const
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ class Simulators : public QObject
|
|||||||
* @brief Construct a new Simulators object
|
* @brief Construct a new Simulators object
|
||||||
*
|
*
|
||||||
* @param port The port for the websocket server
|
* @param port The port for the websocket server
|
||||||
* @param can_dev The CAN device path
|
* @param can_devs The list of CAN device paths
|
||||||
* @param uart_dev The UART device path
|
* @param uart_devs The list of UART device paths
|
||||||
* @param parent The parent QObject
|
* @param parent The parent QObject
|
||||||
*/
|
*/
|
||||||
Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent = nullptr);
|
Simulators(uint16_t port, QStringList can_devs, QStringList uart_devs, QObject *parent = nullptr);
|
||||||
/**
|
/**
|
||||||
* @brief Destroy the Simulators object
|
* @brief Destroy the Simulators object
|
||||||
*
|
*
|
||||||
@@ -147,8 +147,6 @@ class Simulators : public QObject
|
|||||||
private:
|
private:
|
||||||
QThread *m_server_thread;
|
QThread *m_server_thread;
|
||||||
Websocket *m_server;
|
Websocket *m_server;
|
||||||
CAN_Wrapper *m_can_wrapper;
|
|
||||||
QSerialPort *m_serial;
|
|
||||||
Communication *m_com;
|
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 = "";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
EXPORT_SIM(Can_Debugger);
|
EXPORT_SIM(Can_Debugger);
|
||||||
|
|
||||||
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
||||||
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->can_if[0]),
|
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->can_if[0].get()),
|
||||||
m_can_ui(Color::Black, Color::White)
|
m_can_ui(Color::Black, Color::White)
|
||||||
{
|
{
|
||||||
PUSH_UI_ITEM(m_can_ui);
|
PUSH_UI_ITEM(m_can_ui);
|
||||||
|
|||||||
Reference in New Issue
Block a user