mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
server doxygen
Add documentation to the server
This commit is contained in:
@@ -4,20 +4,59 @@
|
||||
#include <QCanBusFrame>
|
||||
#include <QObject>
|
||||
|
||||
/**
|
||||
* @brief Class representing a CAN interface
|
||||
*
|
||||
*/
|
||||
class CAN_Interface : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new CAN Interface object
|
||||
*
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
CAN_Interface(QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Destroy the CAN Interface object
|
||||
*
|
||||
*/
|
||||
~CAN_Interface();
|
||||
|
||||
/**
|
||||
* @brief Connect to a CAN device
|
||||
*
|
||||
* @param dev The device to connect to (e.g. "can0")
|
||||
*/
|
||||
void connect_to_dev(QString dev);
|
||||
|
||||
/**
|
||||
* @brief Send a CAN frame
|
||||
*
|
||||
* @param frame The frame to send
|
||||
*/
|
||||
void send_frame(const QCanBusFrame frame);
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a CAN frame is received
|
||||
*
|
||||
* @param frame The received CAN frame
|
||||
*/
|
||||
void frame_received(QCanBusFrame frame);
|
||||
/**
|
||||
* @brief Signal emitted when a CAN frame is sent
|
||||
*
|
||||
* @param frame The sent CAN frame
|
||||
*/
|
||||
void frame_send(QCanBusFrame frame);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Private method to process CAN bus errors
|
||||
*
|
||||
* @param error The CAN bus error
|
||||
*/
|
||||
void processErrors(QCanBusDevice::CanBusError error) const;
|
||||
QCanBusDevice *m_canDevice;
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ void Visa::send(QString data)
|
||||
m_tcp_socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
QString Visa::querry(QString data)
|
||||
QString Visa::query(QString data)
|
||||
{
|
||||
uint32_t counter = 0;
|
||||
m_data.clear();
|
||||
|
||||
+55
-1
@@ -1,23 +1,77 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
/**
|
||||
* @brief Class representing a VISA interface also known as SCIPI over TCP/IP
|
||||
*
|
||||
*/
|
||||
class Visa : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Visa object
|
||||
*
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
explicit Visa(QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Destroy the Visa object
|
||||
*
|
||||
*/
|
||||
~Visa();
|
||||
|
||||
/**
|
||||
* @brief Connect to a VISA device
|
||||
*
|
||||
* @param ip The IP address of the VISA device
|
||||
* @param port The port number of the VISA device
|
||||
*/
|
||||
void connect(QString ip, quint16 port);
|
||||
/**
|
||||
* @brief Disconnect from the VISA device
|
||||
*
|
||||
*/
|
||||
void disconnect();
|
||||
|
||||
/**
|
||||
* @brief Check if the VISA device is connected
|
||||
*
|
||||
* @return true If the device is connected
|
||||
* @return false If the device is not connected
|
||||
*/
|
||||
bool connected() const;
|
||||
|
||||
/**
|
||||
* @brief Send data to the VISA device
|
||||
*
|
||||
* @param data The data to send
|
||||
*/
|
||||
void send(QString data);
|
||||
QString querry(QString data);
|
||||
/**
|
||||
* @brief Query the VISA device
|
||||
*
|
||||
* @param data The query data
|
||||
* @return QString The response from the device
|
||||
*/
|
||||
QString query(QString data);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the device is disconnected
|
||||
*
|
||||
*/
|
||||
void s_disconnected();
|
||||
/**
|
||||
* @brief Signal emitted when the device is connected
|
||||
*
|
||||
*/
|
||||
void s_connected();
|
||||
/**
|
||||
* @brief Signal emitted when data is ready to be read
|
||||
*
|
||||
* @param data The data that is ready to be read
|
||||
*/
|
||||
void s_data_ready(QString data);
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,19 +6,53 @@
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Class representing a GPIO pin
|
||||
*
|
||||
*/
|
||||
class GPIO : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief Enum representing pin direction
|
||||
*
|
||||
*/
|
||||
enum Direction
|
||||
{
|
||||
Input,
|
||||
Output
|
||||
};
|
||||
/**
|
||||
* @brief Construct a new GPIO object
|
||||
*
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
explicit GPIO(QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Destroy the GPIO object
|
||||
*
|
||||
*/
|
||||
~GPIO();
|
||||
|
||||
/**
|
||||
* @brief Configure a GPIO pin as input or output
|
||||
*
|
||||
* @param dir The direction of the pin (Input or Output)
|
||||
* @param gpio The GPIO pin number
|
||||
*/
|
||||
void configure_pin(Direction dir, uint8_t gpio);
|
||||
/**
|
||||
* @brief Set the value of the GPIO pin
|
||||
*
|
||||
* @param val The value to set (true for high, false for low)
|
||||
*/
|
||||
void set_value(bool val);
|
||||
/**
|
||||
* @brief Get the value of the GPIO pin
|
||||
*
|
||||
* @return bool The value of the pin (true for high, false for low)
|
||||
*/
|
||||
bool value();
|
||||
|
||||
private:
|
||||
|
||||
@@ -22,17 +22,29 @@ Q_FORWARD_DECLARE_OBJC_CLASS(UI_item);
|
||||
return new sim(com, parent); \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Struct holding all communication interfaces
|
||||
*
|
||||
*/
|
||||
class Communication
|
||||
{
|
||||
public:
|
||||
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;
|
||||
/**
|
||||
* @brief Array of CAN interfaces
|
||||
*
|
||||
*/
|
||||
CAN_Wrapper *can_if[3] = {nullptr, nullptr, nullptr};
|
||||
/**
|
||||
* @brief Array of UART interfaces
|
||||
*
|
||||
*/
|
||||
QSerialPort *uart_if[4] = {nullptr, nullptr, nullptr, nullptr};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base class for all simulators
|
||||
*
|
||||
*/
|
||||
class Simulator_base : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -41,7 +53,9 @@ class Simulator_base : public QObject
|
||||
* @brief Construct a new Simulator_base object
|
||||
*
|
||||
* @param name The name of the simulator
|
||||
* @param comms The communication interfaces
|
||||
* @param interval The interval of the timer (default is 100ms)
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
Simulator_base(std::string name, Communication *comms,
|
||||
std::chrono::milliseconds interval = std::chrono::milliseconds(100), QObject *parent = nullptr);
|
||||
@@ -76,6 +90,12 @@ class Simulator_base : public QObject
|
||||
*/
|
||||
UI_item *get_UI_item(size_t id) const;
|
||||
|
||||
/**
|
||||
* @brief Get the id of a UI item by pointer
|
||||
*
|
||||
* @param ptr A pointer to the UI item
|
||||
* @return size_t The id of the UI item, or -1 if not found
|
||||
*/
|
||||
size_t ptr_to_id(UI_item *ptr) const
|
||||
{
|
||||
size_t id = 0;
|
||||
@@ -121,17 +141,57 @@ class Simulator_base : public QObject
|
||||
*/
|
||||
virtual void run_at_stop() {};
|
||||
|
||||
/**
|
||||
* @brief Shutdown the system
|
||||
*
|
||||
*/
|
||||
void shutdown();
|
||||
/**
|
||||
* @brief Reboot the system
|
||||
*
|
||||
*/
|
||||
void reboot();
|
||||
|
||||
/**
|
||||
* @brief Check if a specific bit is high in the input data
|
||||
*
|
||||
* @param data The input data
|
||||
* @param pinnummer The pin number to check
|
||||
* @return true If the bit is high
|
||||
* @return false If the bit is low
|
||||
*/
|
||||
bool check_input_high(uint32_t data, uint16_t pinnummer);
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the ui of the simulator changes
|
||||
*
|
||||
*/
|
||||
void sim_changed();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief The name of the simulator
|
||||
*
|
||||
*/
|
||||
std::string m_name;
|
||||
/**
|
||||
* @brief The UI items of the simulator
|
||||
*
|
||||
*/
|
||||
std::vector<UI_item *> m_UI_items;
|
||||
/**
|
||||
* @brief The timer for the simulator
|
||||
*
|
||||
*/
|
||||
QTimer *m_timer;
|
||||
/**
|
||||
* @brief The interval of the timer
|
||||
*
|
||||
*/
|
||||
std::chrono::milliseconds m_interval;
|
||||
/**
|
||||
* @brief The communication interface
|
||||
*
|
||||
*/
|
||||
Communication *m_com;
|
||||
};
|
||||
|
||||
@@ -35,8 +35,8 @@ Simulators::Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject
|
||||
SPDLOG_CRITICAL("Error {}", m_serial->errorString().toStdString());
|
||||
}
|
||||
}
|
||||
m_com->c_if1 = m_can_wrapper;
|
||||
m_com->s_if1 = m_serial;
|
||||
m_com->can_if[0] = m_can_wrapper;
|
||||
m_com->uart_if[0] = m_serial;
|
||||
|
||||
QLibrary lib;
|
||||
QDirIterator it(QCoreApplication::applicationDirPath(), QStringList() << "*.so", QDir::Files,
|
||||
|
||||
+84
-1
@@ -17,10 +17,18 @@ Q_FORWARD_DECLARE_OBJC_CLASS(Communication);
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
/**
|
||||
* @brief Class managing all simulators
|
||||
*
|
||||
*/
|
||||
class Simulators : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
* @brief Enumeration of commands
|
||||
*
|
||||
*/
|
||||
enum class Command
|
||||
{
|
||||
get_UI_element,
|
||||
@@ -32,6 +40,10 @@ class Simulators : public QObject
|
||||
begin = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enumeration of events
|
||||
*
|
||||
*/
|
||||
enum class Event
|
||||
{
|
||||
clicked,
|
||||
@@ -45,20 +57,91 @@ class Simulators : public QObject
|
||||
begin = 0
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Construct a new Simulators object
|
||||
*
|
||||
* @param port The port for the websocket server
|
||||
* @param can_dev The CAN device path
|
||||
* @param uart_dev The UART device path
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
Simulators(uint16_t port, QString can_dev, QString uart_dev, QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Destroy the Simulators object
|
||||
*
|
||||
*/
|
||||
~Simulators();
|
||||
|
||||
/**
|
||||
* @brief Get the name of the active simulator
|
||||
*
|
||||
* @return std::string The name of the active simulator
|
||||
*/
|
||||
std::string active_simulator_name() const;
|
||||
/**
|
||||
* @brief Start the active simulator
|
||||
*
|
||||
*/
|
||||
void start();
|
||||
/**
|
||||
* @brief Stop the active simulator
|
||||
*
|
||||
*/
|
||||
void stop();
|
||||
/**
|
||||
* @brief Switch to a different simulator
|
||||
*
|
||||
* @param name The name of the simulator to switch to
|
||||
*/
|
||||
void switch_simulator(std::string name);
|
||||
/**
|
||||
* @brief List all available simulators
|
||||
*
|
||||
* @return std::vector<std::string> A list of simulator names
|
||||
*/
|
||||
std::vector<std::string> list_simulators() const;
|
||||
/**
|
||||
* @brief Check if no simulator is active
|
||||
*
|
||||
* @return true If no simulator is active
|
||||
* @return false If a simulator is active
|
||||
*/
|
||||
bool is_not_active() const;
|
||||
/**
|
||||
* @brief Get a pointer to the active simulator
|
||||
* Throws a lock on the simulators map
|
||||
*
|
||||
* @return Simulator_base* A pointer to the active simulator
|
||||
*/
|
||||
Simulator_base *invoke_active_simulator();
|
||||
/**
|
||||
* @brief Get the changed UI items in json format
|
||||
* Throws a lock on the simulators map
|
||||
*
|
||||
* @return json The changed UI items
|
||||
*/
|
||||
json changed_UI_items();
|
||||
|
||||
// parsing of websocket messages
|
||||
// Functions in message_parser.cpp
|
||||
/**
|
||||
* @brief Parse a websocket message
|
||||
*
|
||||
* @param message The message to parse
|
||||
* @return QString The parsed message
|
||||
*/
|
||||
QString message_parser(QString message);
|
||||
/**
|
||||
* @brief Parse a command in json format
|
||||
*
|
||||
* @param command The command to parse
|
||||
* @return json The parsed command
|
||||
*/
|
||||
json command_parser(json command);
|
||||
/**
|
||||
* @brief Handle an event in json format
|
||||
*
|
||||
* @param event The event to handle
|
||||
*/
|
||||
void event_handler(json event);
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
EXPORT_SIM(Can_Debugger);
|
||||
|
||||
Can_Debugger::Can_Debugger(Communication *com, QObject *parent)
|
||||
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->c_if1),
|
||||
: Simulator_base("Can Debugger", com, std::chrono::milliseconds(100), parent), m_wrapper(com->can_if[0]),
|
||||
m_can_ui(Color::Black, Color::White)
|
||||
{
|
||||
PUSH_UI_ITEM(m_can_ui);
|
||||
|
||||
+10
-2
@@ -24,8 +24,16 @@ Websocket::Websocket(uint16_t port, QString key_file, QString cert_file, QObject
|
||||
QSslConfiguration sslConfiguration;
|
||||
QFile certFile(cert_file);
|
||||
QFile keyFile(key_file);
|
||||
certFile.open(QIODevice::ReadOnly);
|
||||
keyFile.open(QIODevice::ReadOnly);
|
||||
bool certFileOpened = certFile.open(QIODevice::ReadOnly);
|
||||
if (!certFileOpened)
|
||||
{
|
||||
SPDLOG_CRITICAL("WebSocket: Unable to open certificate file: {}", cert_file.toStdString());
|
||||
}
|
||||
bool keyFileOpened = keyFile.open(QIODevice::ReadOnly);
|
||||
if (!keyFileOpened)
|
||||
{
|
||||
SPDLOG_CRITICAL("WebSocket: Unable to open key file: {}", key_file.toStdString());
|
||||
}
|
||||
QSslCertificate certificate(&certFile, QSsl::Pem);
|
||||
QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
|
||||
certFile.close();
|
||||
|
||||
+56
-1
@@ -1,29 +1,84 @@
|
||||
#pragma once
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
|
||||
QT_FORWARD_DECLARE_CLASS(QWebSocket)
|
||||
|
||||
/**
|
||||
* @brief Class managing a WebSocket server
|
||||
*
|
||||
*/
|
||||
class Websocket : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Websocket object
|
||||
*
|
||||
* @param port The port to listen on
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
Websocket(uint16_t port, QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Construct a new Websocket object with SSL
|
||||
*
|
||||
* @param port The port to listen on
|
||||
* @param key_file The path to the SSL key file
|
||||
* @param cert_file The path to the SSL certificate file
|
||||
* @param parent The parent QObject
|
||||
*/
|
||||
Websocket(uint16_t port, QString key_file, QString cert_file, QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief Destroy the Websocket object
|
||||
*
|
||||
*/
|
||||
~Websocket();
|
||||
|
||||
/**
|
||||
* @brief Broadcast a message to all connected clients
|
||||
*
|
||||
* @param message The message to send
|
||||
*/
|
||||
void broadcast(QString message);
|
||||
/**
|
||||
* @brief Send a message to a specific client
|
||||
*
|
||||
* @param conn The client connection
|
||||
* @param message The message to send
|
||||
*/
|
||||
void send(QWebSocket *conn, QString message);
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when a message is received from a client
|
||||
*
|
||||
* @param conn The client connection
|
||||
* @param message The received message
|
||||
*/
|
||||
void on_message(QWebSocket *conn, QString message);
|
||||
/**
|
||||
* @brief Signal emitted when the server is closed
|
||||
*
|
||||
*/
|
||||
void closed();
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief Private Slot called when a new client connection is established
|
||||
*
|
||||
*/
|
||||
void onNewConnection();
|
||||
/**
|
||||
* @brief Private Slot called when a text message is received from a client
|
||||
*
|
||||
* @param message The received message
|
||||
*/
|
||||
void processTextMessage(QString message);
|
||||
/**
|
||||
* @brief Private Slot called when a client disconnects
|
||||
*
|
||||
*/
|
||||
void socketDisconnected();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user