diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f0927286803bab1cd4165c9a0399b002c8f8351..99fc298ae0193e8fd99bd41f570ab9440824ac3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,8 @@ add_executable(groundstation src/shared/Modules/OrientationVisualizer/OrientationVisualizer.cpp src/shared/Modules/MainStateViewer/MainStateViewer.cpp src/shared/Modules/PayloadStateViewer/PayloadStateViewer.cpp + src/shared/Modules/RefuelingButton/RefuelingButton.cpp + src/shared/Modules/RefuelingButton/MessageFormElementRefButton.cpp src/shared/Modules/Tabs/TabsModule.cpp src/shared/Modules/Test/TestModule.cpp src/shared/Modules/TimerController/TimerControllerModule.cpp diff --git a/SkywardHub.pro b/SkywardHub.pro index 27a4769f25f8ea4518784405822149549c91ec33..bdbd651b3d965b1785949f1ee0d5e47afbc178e1 100644 --- a/SkywardHub.pro +++ b/SkywardHub.pro @@ -34,6 +34,8 @@ SOURCES += \ src/shared/Modules/Test/TestModule.cpp \ src/shared/Modules/ModulesList.cpp \ src/shared/Modules/RefuelingVisualizer/RefuelingVisualizer.cpp \ + src/shared/Modules/RefuelingButton/RefuelingButton.cpp \ + src/shared/Modules/RefuelingButton/MessageFormElementRefButton.cpp \ src/shared/Modules/Splitter/Splitter.cpp \ src/shared/Modules/DefaultModule/DefaultModule.cpp \ src/shared/Modules/CommandPad/CommandPad.cpp \ @@ -89,6 +91,8 @@ HEADERS += \ src/shared/Modules/PayloadStateViewer/PayloadStatesList.h \ src/shared/Modules/PayloadStateViewer/PayloadStateViewer.h \ src/shared/Modules/RefuelingVisualizer/RefuelingVisualizer.h \ + src/shared/Modules/RefuelingButton/RefuelingButton.h \ + src/shared/Modules/RefuelingButton/MessageFormElementRefButton.h \ src/shared/Modules/FileStream/FileStreamModule.h \ src/shared/Modules/Graph/Graph.h \ src/shared/Modules/Test/TestModule.h \ diff --git a/src/shared/Modules/ModuleInfo.h b/src/shared/Modules/ModuleInfo.h index 6dd058ad10ded6b2dabbc238cd324e2bb3ab11a9..8c7aba6c097381cc535ecc26286ad4e8f7bbb0a5 100644 --- a/src/shared/Modules/ModuleInfo.h +++ b/src/shared/Modules/ModuleInfo.h @@ -42,6 +42,7 @@ enum ModuleId VALUESCONVERTERVIEWER, TIMER_CONTROLLER, MODULETEST, + REFUELING_BUTTON, TABS, FILTER_SELECTOR, VALVESVIEWER, diff --git a/src/shared/Modules/ModulesList.cpp b/src/shared/Modules/ModulesList.cpp index e13f9a3612e80088ed086adc21bb30d2785a72fa..2fed62e516347df769070d9f6962c33c510e25c5 100644 --- a/src/shared/Modules/ModulesList.cpp +++ b/src/shared/Modules/ModulesList.cpp @@ -32,6 +32,9 @@ #include <Modules/OrientationVisualizer/OrientationVisualizer.h> #include <Modules/OutgoingMessagesViewer/OutgoingMessagesViewerModule.h> #include <Modules/PayloadStateViewer/PayloadStateViewer.h> +#include <Modules/RefuelingButton/RefuelingButton.h> +#include <Modules/RefuelingButton/RefuelingButton.h> +#include <Modules/RefuelingVisualizer/RefuelingVisualizer.h> #include <Modules/Splitter/Splitter.h> #include <Modules/Tabs/TabsModule.h> #include <Modules/Test/TestModule.h> @@ -159,6 +162,13 @@ void ModulesList::createModuleList() refuelingVisualizer.setFactory([]() { return new RefuelingVisualizer(); }); tabs.addModuleSourceFiles("Modules/RefuelingVisualizer/"); modulesInfo.append(refuelingVisualizer); + + + ModuleInfo refuelingButton(ModuleId::REFUELING_BUTTON, "RefuelingButton", + ModuleCategory::UTILITIES); + refuelingButton.setFactory([]() { return new RefuelingButton(); }); + tabs.addModuleSourceFiles("Modules/RefuelingButton/"); + addModuleInfo(refuelingButton); } // ____________________________________________________________________________________________ diff --git a/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.cpp b/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6817bd0b2678cf0a6eeac6bb6b880f26929b65bf --- /dev/null +++ b/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.cpp @@ -0,0 +1,289 @@ +/* + * This file is part of Skyward Hub. + * + * Skyward Hub is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Skyward Hub is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * Skyward Hub. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "MessageFormElementRefButton.h" + +#include <Modules/SkywardHubStrings.h> + +MessageFormElementRefButton::MessageFormElementRefButton() {} + +MessageFormElementRefButton::~MessageFormElementRefButton() +{ + for (auto key : comboBoxMap.keys()) + { + delete comboBoxMap[key].first; + delete comboBoxMap[key].second; + } + + for (auto key : floatMap.keys()) + { + delete std::get<0>(floatMap[key]); + delete std::get<1>(floatMap[key]); + } + + for (auto key : integerMap.keys()) + { + delete std::get<0>(integerMap[key]); + delete std::get<1>(integerMap[key]); + } +} + +bool MessageFormElementRefButton::addComboBox(QString id, QString label, + const QMap<QString, int>& options) +{ + if (!comboBoxMap.contains(id) && !floatMap.contains(id) && + !integerMap.contains(id)) + { + auto* comboBox = new QComboBox; + comboBox->setSizePolicy( + QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); + + for (auto key : options.keys()) + comboBox->addItem(key, options[key]); + + comboBoxMap[id] = {new QLabel(label), comboBox}; + return true; + } + else + { + return false; + } +} + +bool MessageFormElementRefButton::addFloat(QString id, QString label, float min, + float max, int decimals) +{ + if (!comboBoxMap.contains(id) && !floatMap.contains(id) && + !integerMap.contains(id)) + { + auto* lineEdit = new QLineEdit; + lineEdit->setSizePolicy( + QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); + lineEdit->setValidator(new QDoubleValidator(min, max, decimals)); + floatMap[id] = {new QLabel(label), lineEdit, min, max, decimals}; + return true; + } + else + { + return false; + } +} + +bool MessageFormElementRefButton::addInteger(QString id, QString label, int min, + int max) +{ + if (!comboBoxMap.contains(id) && !floatMap.contains(id) && + !integerMap.contains(id)) + { + auto* lineEdit = new QLineEdit; + lineEdit->setSizePolicy( + QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum)); + lineEdit->setValidator(new QIntValidator(min, max)); + integerMap[id] = {new QLabel(label), lineEdit, min, max}; + return true; + } + else + { + return false; + } +} + +XmlObject MessageFormElementRefButton::toXmlObject(XmlObject& obj) +{ + for (auto key : comboBoxMap.keys()) + { + auto comboBox = comboBoxMap[key]; + XmlObject comboBoxXml("combo_box"); + comboBoxXml.addAttribute("id", key); + comboBoxXml.addAttribute("text", comboBox.second->currentText()); + obj.addChild(comboBoxXml); + } + + for (auto key : floatMap.keys()) + { + auto floatField = floatMap[key]; + XmlObject floatFieldXml("float_field"); + floatFieldXml.addAttribute("id", key); + floatFieldXml.addAttribute("text", std::get<1>(floatField)->text()); + floatFieldXml.addAttribute("min", std::get<2>(floatField)); + floatFieldXml.addAttribute("max", std::get<3>(floatField)); + floatFieldXml.addAttribute("decimals", std::get<4>(floatField)); + obj.addChild(floatFieldXml); + } + + for (auto key : floatMap.keys()) + { + auto integerField = floatMap[key]; + XmlObject integerFieldXml("integer_field"); + integerFieldXml.addAttribute("id", key); + integerFieldXml.addAttribute("text", std::get<1>(integerField)->text()); + integerFieldXml.addAttribute("min", std::get<2>(integerField)); + integerFieldXml.addAttribute("max", std::get<3>(integerField)); + obj.addChild(integerFieldXml); + } + + return obj; +} + +void MessageFormElementRefButton::fromXmlObject(const XmlObject& obj) +{ + for (int i = 0; i < obj.childCount(); i++) + { + auto child = obj.childAt(i); + auto key = child.getAttribute("id"); + + if (child.getObjectName() == "combo_box" && comboBoxMap.contains(key)) + { + auto comboBox = comboBoxMap[key]; + comboBox.second->setCurrentText(child.getAttribute("text")); + } + else if (child.getObjectName() == "float_field" && + floatMap.contains(key)) + { + auto floatField = floatMap[key]; + std::get<1>(floatField)->setText(child.getAttribute("text")); + child.getAttribute("min", std::get<2>(floatField)); + child.getAttribute("max", std::get<3>(floatField)); + child.getAttribute("decimals", std::get<4>(floatField)); + std::get<1>(floatField) + ->setValidator(new QDoubleValidator(std::get<2>(floatField), + std::get<3>(floatField), + std::get<4>(floatField))); + } + else if (child.getObjectName() == "integer_field" && + integerMap.contains(key)) + { + auto integerField = integerMap[key]; + std::get<1>(integerField)->setText(child.getAttribute("text")); + child.getAttribute("min", std::get<2>(integerField)); + child.getAttribute("max", std::get<3>(integerField)); + std::get<1>(integerField) + ->setValidator(new QIntValidator(std::get<2>(integerField), + std::get<3>(integerField))); + } + } +} + +void MessageFormElementRefButton::applyToGridLayout(QGridLayout* layout) +{ + for (auto key : comboBoxMap.keys()) + { + auto label = comboBoxMap[key].first; + auto comboBox = comboBoxMap[key].second; + + int rows = layout->rowCount(); + layout->addWidget(label, rows, 0, Qt::AlignRight); + layout->addWidget(comboBox, rows, 1); + + label->show(); + comboBox->show(); + } + + for (auto key : floatMap.keys()) + { + auto label = std::get<0>(floatMap[key]); + auto floatField = std::get<1>(floatMap[key]); + + int rows = layout->rowCount(); + layout->addWidget(label, rows, 0, Qt::AlignRight); + layout->addWidget(floatField, rows, 1); + + label->show(); + floatField->show(); + } + + for (auto key : integerMap.keys()) + { + auto label = std::get<0>(integerMap[key]); + auto integerField = std::get<1>(integerMap[key]); + + int rows = layout->rowCount(); + layout->addWidget(label, rows, 0, Qt::AlignRight); + layout->addWidget(integerField, rows, 1); + + label->show(); + integerField->show(); + } +} + +void MessageFormElementRefButton::removeFromGridLayout(QGridLayout* layout) +{ + for (auto key : comboBoxMap.keys()) + { + auto label = comboBoxMap[key].first; + auto comboBox = comboBoxMap[key].second; + + layout->removeWidget(label); + layout->removeWidget(comboBox); + + label->hide(); + comboBox->hide(); + } + + for (auto key : floatMap.keys()) + { + auto label = std::get<0>(floatMap[key]); + auto floatField = std::get<1>(floatMap[key]); + + layout->removeWidget(label); + layout->removeWidget(floatField); + + label->hide(); + floatField->hide(); + } + + for (auto key : integerMap.keys()) + { + auto label = std::get<0>(integerMap[key]); + auto integerField = std::get<1>(integerMap[key]); + + layout->removeWidget(label); + layout->removeWidget(integerField); + + label->hide(); + integerField->hide(); + } +} + +Message MessageFormElementRefButton::prepareMessage(const QString& messageId) +{ + Message message(Topic{SkywardHubStrings::commandsTopic + "/" + messageId}); + + for (auto key : comboBoxMap.keys()) + { + auto comboBox = comboBoxMap[key].second; + auto msg = Field{(uint64_t)comboBox->currentData().toInt()}; + message.setField(key, msg); + } + + for (auto key : floatMap.keys()) + { + auto floatField = std::get<1>(floatMap[key]); + auto msg = Field{floatField->text().toDouble()}; + message.setField(key, msg); + } + + for (auto key : integerMap.keys()) + { + auto integerField = std::get<1>(integerMap[key]); + auto msg = Field{(uint64_t)integerField->text().toInt()}; + message.setField(key, msg); + } + + return message; +} \ No newline at end of file diff --git a/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.h b/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.h new file mode 100644 index 0000000000000000000000000000000000000000..52b0f5e3d6a7a76029784971b7d8b8d949184110 --- /dev/null +++ b/src/shared/Modules/RefuelingButton/MessageFormElementRefButton.h @@ -0,0 +1,79 @@ +/* + * This file is part of Skyward Hub. + * + * Skyward Hub is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Skyward Hub is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * Skyward Hub. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <Core/Message/Message.h> +#include <Core/XmlObject.h> + +#include <QComboBox> +#include <QGridLayout> +#include <QLabel> +#include <QLineEdit> +#include <QMap> +#include <QString> + + class MessageFormElementRefButton +{ +public: + MessageFormElementRefButton(); + + ~MessageFormElementRefButton(); + + /** + * @brief Adds a new combo box field to the form. + * + * @return false if there is already a field with the given id. + */ + bool addComboBox(QString id, QString label, + const QMap<QString, int>& options); + + /** + * @brief Adds a new float field to the form. + * + * @return false if there is already a field with the given id. + */ + bool addFloat(QString id, QString label, + float min = std::numeric_limits<float>::min(), + float max = std::numeric_limits<float>::max(), + int decimals = 2); + + /** + * @brief Adds a new integer field to the form. + * + * @return false if there is already a field with the given id. + */ + bool addInteger(QString id, QString label, + int min = std::numeric_limits<int>::min(), + int max = std::numeric_limits<int>::max()); + + XmlObject toXmlObject(XmlObject& obj); + + void fromXmlObject(const XmlObject& obj); + + void applyToGridLayout(QGridLayout* layout); + + void removeFromGridLayout(QGridLayout* layout); + + Message prepareMessage(const QString& messageId); + +private: + QMap<QString, QPair<QLabel*, QComboBox*>> comboBoxMap; + QMap<QString, std::tuple<QLabel*, QLineEdit*, float, float, int>> floatMap; + QMap<QString, std::tuple<QLabel*, QLineEdit*, int, int>> integerMap; +}; diff --git a/src/shared/Modules/RefuelingButton/MessagesListRefButton.h b/src/shared/Modules/RefuelingButton/MessagesListRefButton.h new file mode 100644 index 0000000000000000000000000000000000000000..af36178178f84e858d09ea3241efc88518865a97 --- /dev/null +++ b/src/shared/Modules/RefuelingButton/MessagesListRefButton.h @@ -0,0 +1,182 @@ +/* + * This file is part of Skyward Hub. + * + * Skyward Hub is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Skyward Hub is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * Skyward Hub. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <Modules/Mavlink/MavlinkVersionHeader.h> +#include <Modules/RefuelingButton/MessageFormElementRefButton.h> + +#include <QMap> +#include <QString> + +namespace MessagesListRefButton +{ + +static const QStringList messagesList{ + "PING_TC", + "COMMAND_TC", + "SYSTEM_TM_REQUEST_TC", + "SENSOR_TM_REQUEST_TC", + "SERVO_TM_REQUEST_TC", + "SET_SERVO_ANGLE_TC", + "WIGGLE_SERVO_TC", + "RESET_SERVO_TC", + "SET_REFERENCE_ALTITUDE_TC", + "SET_REFERENCE_TEMPERATURE_TC", + "SET_ORIENTATION_TC", + "SET_COORDINATES_TC", + "RAW_EVENT_TC", + "SET_DEPLOYMENT_ALTITUDE_TC", + "SET_TARGET_COORDINATES_TC", + "SET_ALGORITHM_TC", +}; + +static const QMap<QString, int> systemTmList{ + {"MAV_SYS_ID", MAV_SYS_ID}, + {"MAV_FSM_ID", MAV_FSM_ID}, + {"MAV_PIN_OBS_ID", MAV_PIN_OBS_ID}, + {"MAV_LOGGER_ID", MAV_LOGGER_ID}, + {"MAV_MAVLINK_STATS", MAV_MAVLINK_STATS}, + {"MAV_TASK_STATS_ID", MAV_TASK_STATS_ID}, + {"MAV_ADA_ID", MAV_ADA_ID}, + {"MAV_NAS_ID", MAV_NAS_ID}, + {"MAV_CAN_ID", MAV_CAN_ID}, + {"MAV_FLIGHT_ID", MAV_FLIGHT_ID}, + {"MAV_STATS_ID", MAV_STATS_ID}, + {"MAV_SENSORS_STATE_ID", MAV_SENSORS_STATE_ID}, +}; + +static const QMap<QString, int> sensorsList{ + {"MAV_GPS_ID", MAV_GPS_ID}, + {"MAV_BMX160_ID", MAV_BMX160_ID}, + {"MAV_VN100_ID", MAV_VN100_ID}, + {"MAV_MPU9250_ID", MAV_MPU9250_ID}, + {"MAV_ADS_ID", MAV_ADS_ID}, + {"MAV_MS5803_ID", MAV_MS5803_ID}, + {"MAV_BME280_ID", MAV_BME280_ID}, + {"MAV_CURRENT_SENSE_ID", MAV_CURRENT_SENSE_ID}, + {"MAV_LIS3MDL_ID", MAV_LIS3MDL_ID}, + {"MAV_DPL_PRESS_ID", MAV_DPL_PRESS_ID}, + {"MAV_STATIC_PRESS_ID", MAV_STATIC_PRESS_ID}, + {"MAV_PITOT_PRESS_ID", MAV_PITOT_PRESS_ID}, + {"MAV_BATTERY_VOLTAGE_ID", MAV_BATTERY_VOLTAGE_ID}, + {"MAV_LOAD_CELL_ID", MAV_LOAD_CELL_ID}, +}; + +static const QMap<QString, int> commandsList{ + {"MAV_CMD_ARM", MAV_CMD_ARM}, + {"MAV_CMD_DISARM", MAV_CMD_DISARM}, + {"MAV_CMD_CALIBRATE", MAV_CMD_CALIBRATE}, + {"MAV_CMD_FORCE_INIT", MAV_CMD_FORCE_INIT}, + {"MAV_CMD_FORCE_LAUNCH", MAV_CMD_FORCE_LAUNCH}, + {"MAV_CMD_FORCE_LANDING", MAV_CMD_FORCE_LANDING}, + {"MAV_CMD_FORCE_APOGEE", MAV_CMD_FORCE_APOGEE}, + {"MAV_CMD_FORCE_EXPULSION", MAV_CMD_FORCE_EXPULSION}, + {"MAV_CMD_FORCE_MAIN", MAV_CMD_FORCE_MAIN}, + {"MAV_CMD_START_LOGGING", MAV_CMD_START_LOGGING}, + {"MAV_CMD_STOP_LOGGING", MAV_CMD_STOP_LOGGING}, + {"MAV_CMD_FORCE_REBOOT", MAV_CMD_FORCE_REBOOT}, + {"MAV_CMD_ENTER_TEST_MODE", MAV_CMD_ENTER_TEST_MODE}, + {"MAV_CMD_EXIT_TEST_MODE", MAV_CMD_EXIT_TEST_MODE}, + {"MAV_CMD_START_RECORDING", MAV_CMD_START_RECORDING}, + {"MAV_CMD_STOP_RECORDING", MAV_CMD_STOP_RECORDING}, +}; + +const QMap<QString, int> servosList{ + {"AIR_BRAKES_SERVO", AIR_BRAKES_SERVO}, + {"EXPULSION_SERVO", EXPULSION_SERVO}, + {"PARAFOIL_LEFT_SERVO", PARAFOIL_LEFT_SERVO}, + {"PARAFOIL_RIGHT_SERVO", PARAFOIL_RIGHT_SERVO}, +}; + +inline void fillMessagesMap( + QMap<QString, MessageFormElementRefButton *> &formElements) +{ + MessageFormElementRefButton *element; + + element = new MessageFormElementRefButton(); + formElements["PING_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("command_id", "Command:", commandsList); + formElements["COMMAND_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("tm_id", "Telemetry:", systemTmList); + formElements["SYSTEM_TM_REQUEST_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("sensor_id", "Sensor:", sensorsList); + formElements["SENSOR_TM_REQUEST_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("servo_id", "Servo:", servosList); + formElements["SERVO_TM_REQUEST_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("servo_id", "Servo:", servosList); + element->addFloat("angle", "Angle:", 0, 180, 2); + formElements["SET_SERVO_ANGLE_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("servo_id", "Servo:", servosList); + formElements["WIGGLE_SERVO_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addComboBox("servo_id", "Servo:", servosList); + formElements["RESET_SERVO_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("ref_altitude", "Altitude:", 0, 9999, 2); + formElements["SET_REFERENCE_ALTITUDE_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("ref_temp", "Temperature:", 0, 999, 2); + formElements["SET_REFERENCE_TEMPERATURE_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("yaw", "Yaw:", -180, 180, 2); + element->addFloat("pitch", "Pitch:", -180, 180, 2); + element->addFloat("roll", "Roll:", -180, 180, 2); + formElements["SET_ORIENTATION_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("latitude", "Latitude:", -90, 90, 6); + element->addFloat("longitude", "Longitude:", -90, 90, 6); + formElements["SET_COORDINATES_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addInteger("topic_id", "Topic:", 0, 999); + element->addInteger("event_id", "Event:", 0, 999); + formElements["RAW_EVENT_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("dpl_altitude", "Altitude:", 0, 9999, 2); + formElements["SET_DEPLOYMENT_ALTITUDE_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addFloat("latitude", "Latitude:", -90, 90, 6); + element->addFloat("longitude", "Longitude:", -90, 90, 6); + formElements["SET_TARGET_COORDINATES_TC"] = element; + + element = new MessageFormElementRefButton(); + element->addInteger("algorithm_number", "Algorithm:", 0, 999); + formElements["SET_ALGORITHM_TC"] = element; +} + +} // namespace MessagesListRefButton \ No newline at end of file diff --git a/src/shared/Modules/RefuelingButton/RefuelingButton.cpp b/src/shared/Modules/RefuelingButton/RefuelingButton.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4baef3f36a864426e846d0a4cd96afd7b8a87655 --- /dev/null +++ b/src/shared/Modules/RefuelingButton/RefuelingButton.cpp @@ -0,0 +1,115 @@ +/* + * This file is part of Skyward Hub. + * + * Skyward Hub is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Skyward Hub is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * Skyward Hub. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "RefuelingButton.h" + +#include <Modules/RefuelingButton/MessagesListRefButton.h> + +#include <QVBoxLayout> + +RefuelingButton::RefuelingButton(QWidget *parent) : DefaultModule(parent) +{ + setupUi(); + defaultContextMenuSetup(); +} + +RefuelingButton::~RefuelingButton() +{ + delete messagesListComboBox; + for (auto key : formElements.keys()) + delete formElements[key]; +} + +QWidget *RefuelingButton::toWidget() { return this; } + +XmlObject RefuelingButton::toXmlObject() +{ + XmlObject obj = XmlObject(getName(ModuleId::REFUELING_BUTTON)); + + auto key = messagesListComboBox->currentText(); + if (formElements.contains(key)) + { + obj.addAttribute("message_id", key); + formElements[key]->toXmlObject(obj); + } + + return obj; +} + +void RefuelingButton::fromXmlObject(const XmlObject &obj) +{ + if (obj.getObjectName() == getName(ModuleId::REFUELING_BUTTON)) + { + auto key = obj.getAttribute("message_id"); + + if (formElements.contains(key)) + { + formElements[key]->fromXmlObject(obj); + messagesListComboBox->setCurrentText(key); + } + } +} + +void RefuelingButton::setupUi() +{ + QVBoxLayout *outerLayout = new QVBoxLayout; + outerLayout->addStretch(); + + messagesListComboBox = new QComboBox; + messagesListComboBox->setSizePolicy( + QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + messagesListComboBox->addItems(MessagesListRefButton::messagesList); + outerLayout->addWidget(messagesListComboBox); + + QGridLayout *formGridLayout = new QGridLayout; + outerLayout->addLayout(formGridLayout); + + QPushButton *sendButton = new QPushButton("Send"); + outerLayout->addWidget(sendButton); + + setLayout(outerLayout); + + MessagesListRefButton::fillMessagesMap(formElements); + + // Set default value + currentMessage = "PING_TC"; + messagesListComboBox->setCurrentText(currentMessage); + + connect(messagesListComboBox, &QComboBox::currentTextChanged, this, + [=](QString key) + { + if (formElements.contains(key)) + { + formElements[currentMessage]->removeFromGridLayout( + formGridLayout); + formElements[key]->applyToGridLayout(formGridLayout); + currentMessage = key; + } + }); + + connect(sendButton, &QPushButton::clicked, + [=]() + { + auto key = messagesListComboBox->currentText(); + if (formElements.contains(key)) + { + auto message = formElements[key]->prepareMessage(key); + getCore()->getMessageBroker()->publish(message); + } + }); +} diff --git a/src/shared/Modules/RefuelingButton/RefuelingButton.h b/src/shared/Modules/RefuelingButton/RefuelingButton.h new file mode 100644 index 0000000000000000000000000000000000000000..abbaa00bcda79a053fdf98fb6bcdd6267ca21785 --- /dev/null +++ b/src/shared/Modules/RefuelingButton/RefuelingButton.h @@ -0,0 +1,45 @@ +/* + * This file is part of Skyward Hub. + * + * Skyward Hub is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * Skyward Hub is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * Skyward Hub. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <Modules/DefaultModule/DefaultModule.h> +#include <Modules/RefuelingButton/MessageFormElementRefButton.h> + +#include <tuple> + +class RefuelingButton : public DefaultModule +{ + Q_OBJECT + +public: + explicit RefuelingButton(QWidget* parent = nullptr); + ~RefuelingButton(); + + QWidget* toWidget() override; + + XmlObject toXmlObject() override; + void fromXmlObject(const XmlObject& xmlObject) override; + +private: + void setupUi(); + + QString currentMessage; + QComboBox* messagesListComboBox; + QMap<QString, MessageFormElementRefButton*> formElements; +};