From 01dfb0e21dd7f30b140e1abea4ca6cd119beedf1 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Sat, 25 Oct 2025 12:27:43 +0200 Subject: [PATCH] server doxygen Add documentation to the server --- UI/ui_button.hpp | 36 ++++++ UI/ui_can.hpp | 84 +++++++++++++ UI/ui_checkbox.hpp | 50 +++++++- UI/ui_combobox.hpp | 54 +++++++++ UI/ui_dial.hpp | 87 ++++++++++++++ UI/ui_double_spinbox.hpp | 53 +++++++++ UI/ui_hex_spinbox.hpp | 49 ++++++++ UI/ui_item.cpp | 4 - UI/ui_item.hpp | 182 ++++++++++++++++++++++++++++- UI/ui_label.hpp | 28 +++++ UI/ui_led.hpp | 37 ++++++ UI/ui_plot.hpp | 77 ++++++++++++ UI/ui_slider.hpp | 87 ++++++++++++++ UI/ui_spinbox.hpp | 53 +++++++++ UI/ui_stacked_widget.hpp | 41 +++++++ UI/ui_status_bar.hpp | 42 +++++++ UI/ui_tab_widget.hpp | 70 +++++++++++ UI/ui_table.hpp | 98 +++++++++++++++- UI/ui_textbox.hpp | 48 ++++++++ UI/ui_thermo.hpp | 114 ++++++++++++++++++ server/CAN/CAN_interface.hpp | 39 +++++++ server/VISA/visa.cpp | 2 +- server/VISA/visa.hpp | 56 ++++++++- server/gpio/gpio.hpp | 34 ++++++ server/simulator_base.hpp | 72 +++++++++++- server/simulators.cpp | 4 +- server/simulators.hpp | 85 +++++++++++++- server/simulators/can_debugger.cpp | 2 +- server/websocket.cpp | 12 +- server/websocket.hpp | 57 ++++++++- 30 files changed, 1635 insertions(+), 22 deletions(-) diff --git a/UI/ui_button.hpp b/UI/ui_button.hpp index caee94e..38655dd 100644 --- a/UI/ui_button.hpp +++ b/UI/ui_button.hpp @@ -3,18 +3,54 @@ #define UI_BUTTON_TYPE std::string("ui_button") +/** + * @brief Class representing a UI button + * + */ class UI_button : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI button object + * + * @param text The text to display on the button + * @param fg_color The foreground color of the button + * @param bg_color The background color of the button + * @param parent The parent QObject + */ UI_button(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Construct a UI button object + * + * @param parent The parent QObject + */ UI_button(QObject *parent = nullptr); + /** + * @brief Deserialize the button from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the button to JSON + * + * @param id The id of the button + * @return json The JSON representation of the button + */ json to_json(size_t id) const override; + /** + * @brief Handle a click event on the button + * + */ void click() override; signals: + /** + * @brief Signal emitted when the button is clicked + * + */ void clicked(); }; diff --git a/UI/ui_can.hpp b/UI/ui_can.hpp index 52e019f..e31629e 100644 --- a/UI/ui_can.hpp +++ b/UI/ui_can.hpp @@ -4,35 +4,119 @@ #define UI_CAN_TYPE std::string("ui_can") +/** + * @brief Class representing a CAN UI item + * + */ class CanFrame { public: + /** + * @brief Construct a new Can Frame object + * + * @param sid The standard identifier + * @param dlc The data length code + * @param payload The data payload + */ CanFrame(uint32_t sid, uint8_t dlc, std::array payload) : m_SID(sid), m_DLC(dlc), m_payload(payload) { } + /** + * @brief Get the Standard Identifier + * + * @return uint32_t The standard identifier + */ uint32_t m_SID; + /** + * @brief The Data Length Code + * + */ uint8_t m_DLC; + /** + * @brief The Payload + * + */ std::array m_payload; }; +/** + * @brief Class representing a CAN UI item + * + */ class UI_can : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI can object + * + * @param fg_color The foreground color + * @param bg_color The background color + * @param parent The parent QObject + */ UI_can(Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Construct a UI can object + * + * @param parent The parent QObject + */ UI_can(QObject *parent = nullptr); + /** + * @brief Add a CAN message to the send buffer + * + * @param msg The CAN message to add + */ void add_send_message(QCanBusFrame msg); + /** + * @brief Add a CAN message to the receive buffer + * + * @param msg The CAN message to add + */ void add_received_message(QCanBusFrame msg); + /** + * @brief Clear the send buffer + * + */ void clear_send_buffer(); + /** + * @brief Clear the receive buffer + * + */ void clear_receive_buffer(); + /** + * @brief Deserialize the CAN item from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the CAN item to JSON + * + * @param id The id of the CAN item + * @return json The JSON representation of the CAN item + */ json to_json(size_t id) const override; + /** + * @brief Handle a CAN send event + * + * @param id The CAN identifier + * @param dlc The data length code + * @param payload The data payload + */ void can_send(uint32_t id, uint8_t dlc, std::array payload) override; + /** + * @brief Clear the CAN item + * + */ void clear() override; signals: + /** + * @brief Signal emitted when a CAN message wants to be sent + * @param msg The CAN message sent + */ void send(QCanBusFrame msg); private: diff --git a/UI/ui_checkbox.hpp b/UI/ui_checkbox.hpp index 6ddb0ee..ff55b6c 100644 --- a/UI/ui_checkbox.hpp +++ b/UI/ui_checkbox.hpp @@ -3,22 +3,70 @@ #define UI_CHECKBOX_TYPE std::string("ui_checkbox") +/** + * @brief Class representing a UI checkbox + * + */ class UI_checkbox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI checkbox object + * + * @param parent The parent QObject + */ UI_checkbox(QObject *parent = nullptr); + /** + * @brief Construct a UI checkbox object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param parent The parent QObject + */ UI_checkbox(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Handle a click event on the checkbox + * + */ void click() override; + /** + * @brief Set the state of the checkbox + * + * @param state The state to set + */ void set_state(bool state); + /** + * @brief Get the state of the checkbox + * + * @return true If checked + * @return false If unchecked + */ bool state() const; + /** + * @brief Deserialize the checkbox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the checkbox to JSON + * + * @param id The id of the checkbox + * @return json The JSON representation of the checkbox + */ json to_json(size_t id) const override; signals: - void changed(bool); + /** + * @brief Signal emitted when the checkbox state changes + * + * @param checked The new state of the checkbox + */ + void changed(bool checked); private: bool m_checked; diff --git a/UI/ui_combobox.hpp b/UI/ui_combobox.hpp index 718d276..57fec59 100644 --- a/UI/ui_combobox.hpp +++ b/UI/ui_combobox.hpp @@ -3,22 +3,76 @@ #define UI_COMBOBOX_TYPE std::string("ui_combobox") +/** + * @brief Class representing a UI combobox + * + */ class UI_combobox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI combobox object + * + * @param parent The parent QObject + */ UI_combobox(QObject *parent = nullptr); + /** + * @brief Construct a UI combobox object + * + * @param fg_color The foreground color + * @param bg_color The background color + * @param options The list of options + * @param selected The initially selected option + * @param parent The parent QObject + */ UI_combobox(Color fg_color, Color bg_color, std::vector options, size_t selected = 0, QObject *parent = nullptr); + /** + * @brief Set the selected option by index + * + * @param selected The index of the option to select + */ void set_selected(size_t selected) override; + /** + * @brief Set the selected option by text + * + * @param selected The text of the option to select + */ void set_selected(std::string selected); + /** + * @brief Get the index of the selected option + * + * @return size_t The index of the selected option + */ size_t selected() const; + /** + * @brief Get the text of the selected option + * + * @return std::string The text of the selected option + */ std::string selected_text() const; + /** + * @brief Deserialize the combobox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the combobox to JSON + * + * @param id The id of the combobox + * @return json The JSON representation of the combobox + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the selected option changes + * + * @param selected The text of the newly selected option + */ void changed(std::string selected); private: diff --git a/UI/ui_dial.hpp b/UI/ui_dial.hpp index 73e078d..1f4d691 100644 --- a/UI/ui_dial.hpp +++ b/UI/ui_dial.hpp @@ -3,26 +3,113 @@ #define UI_DIAL_TYPE std::string("ui_dial") +/** + * @brief Class representing a UI dial + * + */ class UI_dial : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI dial object + * + * @param text The text to display + * @param unit The unit of the dial + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_dial(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI dial object + * + * @param text The text to display + * @param unit The unit of the dial + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_dial(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI dial object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_dial(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI dial object + * + * @param text The text to display + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_dial(std::string text, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI dial object + * + * @param parent The parent QObject + */ UI_dial(QObject *parent = nullptr); + /** + * @brief Set the value of the dial + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the dial + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the dial + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the dial + * + * @return double The maximum value + */ double max() const; + /** + * @brief Get the unit of the dial + * + * @return std::string The unit of the dial + */ std::string unit() const; + /** + * @brief Deserialize the dial from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the dial to JSON + * + * @param id The id of the dial + * @return json The JSON representation of the dial + */ json to_json(size_t id) const override; private: diff --git a/UI/ui_double_spinbox.hpp b/UI/ui_double_spinbox.hpp index 0ec3123..ef75be2 100644 --- a/UI/ui_double_spinbox.hpp +++ b/UI/ui_double_spinbox.hpp @@ -3,22 +3,75 @@ #define UI_DOUBLE_SPINBOX_TYPE std::string("ui_double_spinbox") +/** + * @brief Class representing a UI double spinbox + * + */ class UI_double_spinbox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI double spinbox object + * + * @param parent The parent QObject + */ explicit UI_double_spinbox(QObject *parent = nullptr); + /** + * @brief Construct a UI double spinbox object + * + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_double_spinbox(double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Set the value of the double spinbox + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the double spinbox + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the double spinbox + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the double spinbox + * + * @return double The maximum value + */ double max() const; + /** + * @brief Deserialize the double spinbox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the double spinbox to JSON + * + * @param id The id of the double spinbox + * @return json The JSON representation of the double spinbox + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the double spinbox value changes + * + * @param value The new value + */ void changed(double value); private: diff --git a/UI/ui_hex_spinbox.hpp b/UI/ui_hex_spinbox.hpp index 1ded6dc..dd8afbe 100644 --- a/UI/ui_hex_spinbox.hpp +++ b/UI/ui_hex_spinbox.hpp @@ -7,18 +7,67 @@ class UI_hex_spinbox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI hex spinbox object + * + * @param parent The parent QObject + */ explicit UI_hex_spinbox(QObject *parent = nullptr); + /** + * @brief Construct a UI hex spinbox object + * + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_hex_spinbox(double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Set the value of the hex spinbox + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the hex spinbox + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the hex spinbox + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the hex spinbox + * + * @return double The maximum value + */ double max() const; + /** + * @brief Deserialize the hex spinbox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the hex spinbox to JSON + * + * @param id The id of the hex spinbox + * @return json The JSON representation of the hex spinbox + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the hex spinbox value changes + * + * @param value The new value + */ void changed(double value); private: diff --git a/UI/ui_item.cpp b/UI/ui_item.cpp index 980a746..2d1b3cd 100644 --- a/UI/ui_item.cpp +++ b/UI/ui_item.cpp @@ -17,10 +17,6 @@ UI_item::UI_item(const json &j, QObject *parent) : QObject(parent) from_json(j); } -UI_item::~UI_item() -{ -} - std::string UI_item::type() const { return m_type; diff --git a/UI/ui_item.hpp b/UI/ui_item.hpp index 5b87ad6..0224e0d 100644 --- a/UI/ui_item.hpp +++ b/UI/ui_item.hpp @@ -10,58 +10,238 @@ using json = nlohmann::json; #define UNUSED(x) (void)(x) +/** + * @brief Base class representing a UI item + * + */ class UI_item : public QObject { Q_OBJECT public: + /** + * @brief Construct a new UI item object + * + * @param type The type of the UI item + * @param parent The parent QObject + */ explicit UI_item(std::string type, QObject *parent = nullptr); + /** + * @brief Construct a new UI item object + * + * @param type The type of the UI item + * @param text The text of the UI item + * @param fg_color The foreground color of the UI item + * @param bg_color The background color of the UI item + * @param parent The parent QObject + */ explicit UI_item(std::string type, std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Construct a new UI item object from JSON + * + * @param j The JSON object + * @param parent The parent QObject + */ explicit UI_item(const json &j, QObject *parent = nullptr); - ~UI_item(); + /** + * @brief Get the type of the UI item + * + * @return std::string The type of the UI item + */ std::string type() const; + /** + * @brief Check if the JSON object is of the correct type + * + * @param j The JSON object + * @return true If the JSON object is of the correct type + * @return false If the JSON object is not of the correct type + */ bool is_type(json j); + /** + * @brief Set the text of the UI item + * + * @param text The text to set + */ virtual void set_text(std::string text); + /** + * @brief Append text to the UI item + * + * @param text The text to append + */ void append_text(std::string text); + /** + * @brief Get the text of the UI item + * + * @return std::string The text of the UI item + */ std::string text() const; + /** + * @brief Set the foreground color of the UI item + * + * @param fg_color The foreground color to set + */ void set_fg_color(Color fg_color); + /** + * @brief Get the foreground color of the UI item + * + * @return Color The foreground color of the UI item + */ Color fg_color() const; + /** + * @brief Set the background color of the UI item + * + * @param bg_color The background color to set + */ void set_bg_color(Color bg_color); + /** + * @brief Get the background color of the UI item + * + * @return Color The background color of the UI item + */ Color bg_color() const; + /** + * @brief Enable or disable the UI item + * + * @param enabled True to enable, false to disable + */ void set_enabled(bool enabled); + /** + * @brief Check if the UI item is enabled + * + * @return true If enabled + * @return false If disabled + */ bool is_enabled() const; + /** + * @brief Set the visibility of the UI item + * + * @param visible True to show, false to hide + */ void set_visible(bool visible); + /** + * @brief Check if the UI item is visible + * + * @return true If visible + * @return false If hidden + */ bool is_visible() const; + /** + * @brief Deserialize the UI item from JSON + * + * @param j The JSON object + */ virtual void from_json(const json &j); + /** + * @brief Serialize the UI item to JSON + * + * @param id The id of the UI item + * @return json The JSON representation of the UI item + */ virtual json to_json(size_t id) const; + /** + * @brief Virtual method to handle click events + * + */ virtual void click(); + /** + * @brief Virtual method to set the selected option (for comboboxes) + * + * @param selected The index of the option to select + */ virtual void set_selected(size_t selected); + /** + * @brief Virtual method to set the value (for spinboxes) + * + * @param value The value to set + */ virtual void set_value(double value); + /** + * @brief Virtual method to handle CAN send events + * + * @param id The CAN ID + * @param dlc The data length code + * @param payload The payload data + */ virtual void can_send(uint32_t id, uint8_t dlc, std::array payload); + /** + * @brief Virtual method to clear the UI item + * + */ virtual void clear(); signals: + /** + * @brief Signal emitted when the UI item changes + * + */ void ui_changed(); protected: + /** + * @brief Setup the UI item properties + * + * @param text Enable text property + * @param fg_color Enable foreground color property + * @param bg_color Enable background color property + */ void setup_item(bool text, bool fg_color, bool bg_color); + /** + * @brief The id of the UI item + * + */ size_t m_id; + /** + * @brief The type of the UI item + * + */ std::string m_type; + /** + * @brief The text of the UI item + * + */ std::string m_text; + /** + * @brief Whether the text property is enabled + * + */ bool m_text_enabled = true; + /** + * @brief The foreground color of the UI item + * + */ Color m_fg_color; + /** + * @brief Whether the foreground color property is enabled + * + */ bool m_fg_color_enabled = true; + /** + * @brief The background color of the UI item + * + */ Color m_bg_color; + /** + * @brief Whether the background color property is enabled + * + */ bool m_bg_color_enabled = true; + /** + * @brief Whether the UI item is enabled + * + */ bool m_enabled; + /** + * @brief Whether the UI item is visible + * + */ bool m_visible; }; diff --git a/UI/ui_label.hpp b/UI/ui_label.hpp index 49daedc..80c9be0 100644 --- a/UI/ui_label.hpp +++ b/UI/ui_label.hpp @@ -4,13 +4,41 @@ #define UI_LABEL_TYPE std::string("ui_label") +/** + * @brief Class representing a UI label + * + */ class UI_label : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI label object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param parent The parent QObject + */ UI_label(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Construct a UI label object + * + * @param parent The parent QObject + */ UI_label(QObject *parent = nullptr); + /** + * @brief Deserialize the label from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the label to JSON + * + * @param id The id of the label + * @return json The JSON representation of the label + */ json to_json(size_t id) const override; }; diff --git a/UI/ui_led.hpp b/UI/ui_led.hpp index 0d18fcf..6882d78 100644 --- a/UI/ui_led.hpp +++ b/UI/ui_led.hpp @@ -4,15 +4,52 @@ #define UI_LED_TYPE std::string("ui_led") +/** + * @brief Class representing a UI led + * + */ class UI_led : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI led object + * + * @param parent The parent QObject + */ UI_led(QObject *parent = nullptr); + /** + * @brief Construct a UI led object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param parent The parent QObject + */ UI_led(std::string text, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Set the state of the LED + * + * @param state The state to set + * @param on The color when the LED is on + * @param off The color when the LED is off + * @return true If the state was changed + * @return false If the state was not changed + */ bool set_led(bool state, Color on, Color off); + /** + * @brief Deserialize the LED from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the LED to JSON + * + * @param id The id of the LED + * @return json The JSON representation of the LED + */ json to_json(size_t id) const override; }; diff --git a/UI/ui_plot.hpp b/UI/ui_plot.hpp index 8f2fa78..249897d 100644 --- a/UI/ui_plot.hpp +++ b/UI/ui_plot.hpp @@ -2,24 +2,101 @@ #include "ui_item.hpp" #define UI_PLOT_TYPE std::string("ui_plot") +/** + * @brief Class representing a UI plot + * + */ class UI_plot : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI plot object + * + * @param parent The parent QObject + */ explicit UI_plot(QObject *parent = nullptr); + /** + * @brief Construct a UI plot object + * + * @param text The text to display + * @param x_label The label for the x-axis + * @param y_label The label for the y-axis + * @param parent The parent QObject + */ UI_plot(std::string text, std::string x_label, std::string y_label, QObject *parent = nullptr); + /** + * @brief Set the label for the x-axis + * + * @param name The name to set + */ void set_x_label(std::string name); + /** + * @brief Get the label for the x-axis + * + * @return std::string The x-axis label + */ std::string x_label() const; + + /** + * @brief Set the label for the y-axis + * + * @param name The name to set + */ void set_y_label(std::string name); + /** + * @brief Get the label for the y-axis + * + * @return std::string The y-axis label + */ std::string y_label() const; + + /** + * @brief Add a value to the plot + * + * @param y The y value to add + */ void add_value(double y); + /** + * @brief Add a value pair to the plot + * + * @param x The x value to add + * @param y The y value to add + */ void add_value(double x, double y); + /** + * @brief Get the x and y values of the plot + * This is only for testing purposes + * + * @return a list of x values and a list of y values + */ const std::vector &x_vals() const; + /** + * @brief Get the y values of the plot + * This is only for testing purposes + * + * @return a list of y values + */ const std::vector &y_vals() const; + /** + * @brief Clear all values from the plot + * + */ void clean_vals(); + /** + * @brief Deserialize the plot from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the plot to JSON + * + * @param id The id of the plot + * @return json The JSON representation of the plot + */ json to_json(size_t id) const override; private: diff --git a/UI/ui_slider.hpp b/UI/ui_slider.hpp index ed33aaf..321954e 100644 --- a/UI/ui_slider.hpp +++ b/UI/ui_slider.hpp @@ -3,27 +3,114 @@ #define UI_SLIDER_TYPE std::string("ui_slider") +/** + * @brief Class representing a UI slider + * + */ class UI_slider : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI slider object + * + * @param text The text to display + * @param unit The unit of the slider + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_slider(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI slider object + * + * @param text The text to display + * @param unit The unit of the slider + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_slider(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI slider object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_slider(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI slider object + * + * @param text The text to display + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_slider(std::string text, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI slider object + * + * @param parent The parent QObject + */ UI_slider(QObject *parent = nullptr); + /** + * @brief Set the value of the slider + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the slider + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the slider + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the slider + * + * @return double The maximum value + */ double max() const; + /** + * @brief Deserialize the slider from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the slider to JSON + * + * @param id The id of the slider + * @return json The JSON representation of the slider + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the slider value changes + * + * @param value The new value of the slider + */ void changed(double value); private: diff --git a/UI/ui_spinbox.hpp b/UI/ui_spinbox.hpp index 52cc6ad..43c219d 100644 --- a/UI/ui_spinbox.hpp +++ b/UI/ui_spinbox.hpp @@ -3,22 +3,75 @@ #define UI_SPINBOX_TYPE std::string("ui_spinbox") +/** + * @brief Class representing a UI spinbox + * + */ class UI_spinbox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI spinbox object + * + * @param parent The parent QObject + */ explicit UI_spinbox(QObject *parent = nullptr); + /** + * @brief Construct a UI spinbox object + * + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_spinbox(double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Set the value of the spinbox + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the spinbox + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the spinbox + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the spinbox + * + * @return double The maximum value + */ double max() const; + /** + * @brief Deserialize the spinbox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the spinbox to JSON + * + * @param id The id of the spinbox + * @return json The JSON representation of the spinbox + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the spinbox value changes + * + * @param value The new value of the spinbox + */ void changed(double value); private: diff --git a/UI/ui_stacked_widget.hpp b/UI/ui_stacked_widget.hpp index dd3451d..d967ab8 100644 --- a/UI/ui_stacked_widget.hpp +++ b/UI/ui_stacked_widget.hpp @@ -2,18 +2,59 @@ #include "ui_item.hpp" #define UI_STACKED_WIDGET_TYPE std::string("ui_stacked_widget") +/** + * @brief Class representing a UI stacked widget + * + */ class UI_stacked_widget : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI stacked widget object + * + * @param parent The parent QObject + */ explicit UI_stacked_widget(QObject *parent = nullptr); + /** + * @brief Construct a UI stacked widget object + * + * @param tab_count The number of tabs + * @param current_tab The currently selected tab + * @param parent The parent QObject + */ UI_stacked_widget(size_t tab_count, size_t current_tab, QObject *parent = nullptr); + /** + * @brief Set the selected tab by index + * + * @param selected The index of the tab to select + */ void set_selected(size_t selected) override; + /** + * @brief Get the index of the selected tab + * + * @return size_t The index of the selected tab + */ size_t selected() const; + /** + * @brief Advance to the next tab + * + */ void advance_tab(); + /** + * @brief Deserialize the stacked widget from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the stacked widget to JSON + * + * @param id The id of the stacked widget + * @return json The JSON representation of the stacked widget + */ json to_json(size_t id) const override; private: diff --git a/UI/ui_status_bar.hpp b/UI/ui_status_bar.hpp index 94e96c8..10a66c8 100644 --- a/UI/ui_status_bar.hpp +++ b/UI/ui_status_bar.hpp @@ -2,18 +2,60 @@ #include "ui_item.hpp" #define UI_STATUS_BAR_TYPE std::string("ui_status_bar") +/** + * @brief Class representing a UI status bar + * + */ class UI_status_bar : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI status bar object + * + * @param parent The parent QObject + */ explicit UI_status_bar(QObject *parent = nullptr); + /** + * @brief Construct a UI status bar object + * + * @param message The initial message + * @param parent The parent QObject + */ UI_status_bar(std::string message, QObject *parent = nullptr); + /** + * @brief Show a message on the status bar + * + * @param message The message to show + * @param timeout The timeout in milliseconds (0 for no timeout) + */ void show_message(std::string message, size_t timeout = 0); + /** + * @brief Get the current message + * + * @return std::string The current message + */ std::string message() const; + /** + * @brief Get the timeout for the current message + * + * @return size_t The timeout in milliseconds + */ size_t timeout() const; + /** + * @brief Deserialize the status bar from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the status bar to JSON + * + * @param id The id of the status bar + * @return json The JSON representation of the status bar + */ json to_json(size_t id) const override; private: diff --git a/UI/ui_tab_widget.hpp b/UI/ui_tab_widget.hpp index 0c3d8d6..44850f7 100644 --- a/UI/ui_tab_widget.hpp +++ b/UI/ui_tab_widget.hpp @@ -3,27 +3,97 @@ #define UI_TAB_WIDGET_TYPE std::string("ui_tab_widget") +/** + * @brief Class representing a UI tab widget + * + */ class UI_tab_widget : public UI_item { Q_OBJECT public: + /** * @brief Construct a UI tab widget object + * + * @param parent The parent QObject + */ explicit UI_tab_widget(QObject *parent = nullptr); + /** + * @brief Construct a UI tab widget object + * + * @param tab_names The names of the tabs + * @param selected The initially selected tab + * @param parent The parent QObject + */ UI_tab_widget(std::vector tab_names, size_t selected = 0, QObject *parent = nullptr); + /** + * @brief Set the selected tab by index + * + * @param selected The index of the tab to select + */ void set_selected(size_t selected) override; + /** + * @brief Get the index of the selected tab + * + * @return size_t The index of the selected tab + */ size_t selected() const; + /** + * @brief Set the visibility of a tab by index + * + * @param index The index of the tab + * @param visible True to show, false to hide + */ void set_visible(size_t index, bool visible); + /** + * @brief Get the visibility of a tab by index + * + * @param index The index of the tab + * @return true If the tab is visible + * @return false If the tab is hidden + */ bool visible(size_t index) const; + /** + * @brief Set the name of a tab by index + * + * @param index The index of the tab + * @param name The name to set + */ void set_tab_name(size_t index, std::string name); + /** + * @brief Get the name of a tab by index + * + * @param index The index of the tab + * @return std::string The name of the tab + */ std::string tab_name(size_t index) const; + /** + * @brief Advance to the next tab + * + */ void advance_tab(); + /** + * @brief Deserialize the tab widget from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the tab widget to JSON + * + * @param id The id of the tab widget + * @return json The JSON representation of the tab widget + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the selected tab changes + * + * @param index The index of the newly selected tab + */ void changed(size_t index); private: diff --git a/UI/ui_table.hpp b/UI/ui_table.hpp index d50e4ef..be22468 100644 --- a/UI/ui_table.hpp +++ b/UI/ui_table.hpp @@ -3,35 +3,131 @@ #define UI_TABLE_TYPE std::string("ui_table") +/** + * @brief Class representing a UI table + * + */ class UI_table : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI table object + * + * @param parent The parent QObject + */ explicit UI_table(QObject *parent = nullptr); + /** + * @brief Construct a UI table object + * + * @param row_count The number of rows + * @param column_count The number of columns + * @param row_labels The labels for the rows + * @param column_labels The labels for the columns + * @param parent The parent QObject + */ explicit UI_table(size_t row_count, size_t column_count, std::vector row_labels, std::vector column_labels, QObject *parent = nullptr); + /** + * @brief Set the number of rows in the table + * + * @param count The number of rows + */ void set_row_count(size_t count); + /** + * @brief Get the number of rows in the table + * + * @return size_t The number of rows + */ size_t row_count() const; + + /** + * @brief Set the number of columns in the table + * + * @param count The number of columns + */ void set_column_count(size_t count); + /** + * @brief Get the number of columns in the table + * + * @return size_t The number of columns + */ size_t column_count() const; + + /** + * @brief Get the capacity of the table (rows * columns) + * + * @return size_t The capacity of the table + */ size_t capacity() const; + + /** + * @brief Set the label for a specific row + * + * @param index The index of the row + * @param label The label to set + */ void set_row_label(size_t index, std::string label); + /** + * @brief Get the label of a specific row + * + * @param index The index of the row + * @return std::string The label of the row + */ std::string row_label(size_t index) const; + + /** + * @brief Set the label for a specific column + * + * @param index The index of the column + * @param label The label to set + */ void set_column_label(size_t index, std::string label); + /** + * @brief Get the label of a specific column + * + * @param index The index of the column + * @return std::string The label of the column + */ std::string column_label(size_t index) const; + /** + * @brief Insert an item into the table at the specified row and column + * + * @param row The row of the item + * @param column The column of the item + * @param text The text of the item + */ void insert_item(size_t row, size_t column, std::string text); + /** + * @brief Get the item at the specified row and column + * + * @param row The row of the item + * @param column The column of the item + * @return std::string The text of the item + */ std::string item(size_t row, size_t column) const; /** - * @brief empty_item This function clears the item and makes it invalid + * @brief empty_item This function clears the item * @param row The row of the item * @param column The column of the item */ void empty_item(size_t row, size_t column); + /** + * @brief Deserialize the table from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the table to JSON + * + * @param id The id of the table + * @return json The JSON representation of the table + */ json to_json(size_t id) const override; private: diff --git a/UI/ui_textbox.hpp b/UI/ui_textbox.hpp index 5314473..49b888c 100644 --- a/UI/ui_textbox.hpp +++ b/UI/ui_textbox.hpp @@ -4,21 +4,69 @@ #define UI_TEXTBOX_TYPE std::string("ui_textbox") +/** + * @brief Class representing a UI textbox + * + */ class UI_textbox : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI textbox object + * + * @param hint The hint text + * @param fg_color The foreground color + * @param bg_color The background color + * @param parent The parent QObject + */ UI_textbox(std::string hint, Color fg_color, Color bg_color, QObject *parent = nullptr); + /** + * @brief Construct a UI textbox object + * + * @param parent The parent QObject + */ UI_textbox(QObject *parent = nullptr); + /** + * @brief Set the text of the textbox + * + * @param text The text to set + */ void set_text(std::string text) override; + /** + * @brief Get the hint text of the textbox + * + * @param hint The hint text to set + */ void set_hint(std::string hint); + /** + * @brief Get the hint text of the textbox + * + * @return std::string The hint text + */ std::string hint() const; + /** + * @brief Deserialize the textbox from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the textbox to JSON + * + * @param id The id of the textbox + * @return json The JSON representation of the textbox + */ json to_json(size_t id) const override; signals: + /** + * @brief Signal emitted when the text changes + * + * @param text The new text + */ void changed(std::string text); private: diff --git a/UI/ui_thermo.hpp b/UI/ui_thermo.hpp index 7576133..f5b7206 100644 --- a/UI/ui_thermo.hpp +++ b/UI/ui_thermo.hpp @@ -4,32 +4,146 @@ #define UI_THERMO_TYPE std::string("ui_thermo") // TODO: Add color scale +/** + * @brief Class representing a UI thermometer + * + */ class UI_thermo : public UI_item { Q_OBJECT public: + /** + * @brief Construct a UI thermometer object + * + * @param text The text to display + * @param unit The unit of the thermometer + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_thermo(std::string text, std::string unit, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI thermometer object + * + * @param text The text to display + * @param unit The unit of the thermometer + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_thermo(std::string text, std::string unit, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI thermometer object + * + * @param text The text to display + * @param fg_color The foreground color + * @param bg_color The background color + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_thermo(std::string text, Color fg_color, Color bg_color, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI thermometer object + * + * @param text The text to display + * @param min The minimum value + * @param max The maximum value + * @param value The initial value + * @param parent The parent QObject + */ UI_thermo(std::string text, double min, double max, double value, QObject *parent = nullptr); + /** + * @brief Construct a UI thermometer object + * + * @param parent The parent QObject + */ UI_thermo(QObject *parent = nullptr); + /** + * @brief Set the value of the thermometer + * + * @param value The value to set + */ void set_value(double value) override; + /** + * @brief Get the value of the thermometer + * + * @return double The current value + */ double value() const; + /** + * @brief Get the minimum value of the thermometer + * + * @return double The minimum value + */ double min() const; + /** + * @brief Get the maximum value of the thermometer + * + * @return double The maximum value + */ double max() const; + /** + * @brief Set the start color object + * + * @param color + */ void set_start_color(Color color); + /** + * @brief Set the end color object + * + * @param color + */ void set_end_color(Color color); + /** + * @brief Add a color stop at the given value + * + * @param value The value at which to add the color stop + * @param color The color of the stop + */ void add_color_stop(double value, Color color); + /** + * @brief Add a normalized color stop at the given value + * + * @param value The normalized value (0.0 to 1.0) at which to add the color stop + * @param color The color of the stop + */ void add_color_stop_normalized(double value, Color color); + /** + * @brief Remove the color stop at the given value + * + * @param value The value of the color stop to remove + */ void remove_color_stop(double value); + /** + * @brief Remove the normalized color stop at the given value + * + * @param value The normalized value (0.0 to 1.0) of the color stop to remove + */ void remove_color_stop_normalized(double value); + /** + * @brief Deserialize the thermometer from JSON + * + * @param j The JSON object + */ void from_json(const json &j) override; + /** + * @brief Serialize the thermometer to JSON + * + * @param id The id of the thermometer + * @return json The JSON representation of the thermometer + */ json to_json(size_t id) const override; private: diff --git a/server/CAN/CAN_interface.hpp b/server/CAN/CAN_interface.hpp index 02a5d55..53965c0 100644 --- a/server/CAN/CAN_interface.hpp +++ b/server/CAN/CAN_interface.hpp @@ -4,20 +4,59 @@ #include #include +/** + * @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; }; diff --git a/server/VISA/visa.cpp b/server/VISA/visa.cpp index 25eeae2..13cc785 100644 --- a/server/VISA/visa.cpp +++ b/server/VISA/visa.cpp @@ -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(); diff --git a/server/VISA/visa.hpp b/server/VISA/visa.hpp index ea17ca9..a61e674 100644 --- a/server/VISA/visa.hpp +++ b/server/VISA/visa.hpp @@ -1,23 +1,77 @@ #pragma once #include +/** + * @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: diff --git a/server/gpio/gpio.hpp b/server/gpio/gpio.hpp index 8f761e5..d4b9449 100644 --- a/server/gpio/gpio.hpp +++ b/server/gpio/gpio.hpp @@ -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: diff --git a/server/simulator_base.hpp b/server/simulator_base.hpp index 3506d7c..a1ba0b9 100644 --- a/server/simulator_base.hpp +++ b/server/simulator_base.hpp @@ -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 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; }; diff --git a/server/simulators.cpp b/server/simulators.cpp index 0dadce4..5e336bb 100644 --- a/server/simulators.cpp +++ b/server/simulators.cpp @@ -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, diff --git a/server/simulators.hpp b/server/simulators.hpp index 283c2f0..323c3ae 100644 --- a/server/simulators.hpp +++ b/server/simulators.hpp @@ -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 A list of simulator names + */ std::vector 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: diff --git a/server/simulators/can_debugger.cpp b/server/simulators/can_debugger.cpp index 95ec5e0..272ea2c 100644 --- a/server/simulators/can_debugger.cpp +++ b/server/simulators/can_debugger.cpp @@ -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); diff --git a/server/websocket.cpp b/server/websocket.cpp index 5342148..3eb21c3 100644 --- a/server/websocket.cpp +++ b/server/websocket.cpp @@ -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(); diff --git a/server/websocket.hpp b/server/websocket.hpp index fd4e393..e07022e 100644 --- a/server/websocket.hpp +++ b/server/websocket.hpp @@ -1,29 +1,84 @@ #pragma once -#include #include #include 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: