diff --git a/mavground.qrc b/mavground.qrc index 30278ecca8850d994750c2ef83e5ffe8d33a946a..15c9f733eb083417b83e82a9f699cf5f525e06f6 100644 --- a/mavground.qrc +++ b/mavground.qrc @@ -1,5 +1,5 @@ - + images/control/launch.svg images/status/dialog-error.svg images/status/dialog-warning.svg @@ -78,8 +78,9 @@ images/style-mission.css images/splash.png audio/alert.wav + demo-log.txt - - images/Vera.ttf + + images/Vera.ttf diff --git a/src/Core.cc b/src/Core.cc index 607f9c9fb552b24fb16cee5703edf4f82b9cb383..1b2320292d7ef425ede249873da4c472c16cc823 100644 --- a/src/Core.cc +++ b/src/Core.cc @@ -132,14 +132,9 @@ Core::Core(int &argc, char* argv[]) : QApplication(argc, argv) } } - MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(MG::DIR::getSupportFilesDirectory() + "/demo-log.txt"); + // MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(MG::DIR::getSupportFilesDirectory() + "/demo-log.txt"); + MAVLinkSimulationLink* simulationLink = new MAVLinkSimulationLink(":/demo-log.txt"); mainWindow->addLink(simulationLink); - - //CommConfigurationWindow* simulationWidget = new CommConfigurationWindow(simulationLink, mavlink, this); - //ui.menuNetwork->addAction(commWidget->getAction()); - //simulationLink->connect(); - - } /** diff --git a/src/comm/MAVLinkSimulationLink.cc b/src/comm/MAVLinkSimulationLink.cc index 84986e6be9cd6c7275739c6db9f137de2c076007..45133c282748a5a5529d95a95df3c6e14bd8cbea 100644 --- a/src/comm/MAVLinkSimulationLink.cc +++ b/src/comm/MAVLinkSimulationLink.cc @@ -550,6 +550,7 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) break; case MAVLINK_MSG_ID_PARAM_REQUEST_LIST: { + qDebug() << "GCS REQUESTED PARAM LIST FROM SIMULATION"; mavlink_param_request_list_t read; mavlink_msg_param_request_list_decode(&msg, &read); if (read.target_system == systemId) @@ -579,6 +580,8 @@ void MAVLinkSimulationLink::writeBytes(const char* data, qint64 size) //add data into datastream memcpy(stream+streampointer,buffer, bufferlength); streampointer+=bufferlength; + + qDebug() << "SIMULATION SENT PARAMETERS TO GCS"; } } } diff --git a/src/comm/MAVLinkXMLParser.cc b/src/comm/MAVLinkXMLParser.cc index 6653af7b1a9aa57d10ee38edb2c3e5f8c6c3d151..48e0605ad33dee19dd6318fc602a86de0fe72f16 100644 --- a/src/comm/MAVLinkXMLParser.cc +++ b/src/comm/MAVLinkXMLParser.cc @@ -91,6 +91,7 @@ bool MAVLinkXMLParser::generate() QString commentContainer = "/**\n * @brief Send a %1 message\n *\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n"; QString commentEntry = " * @param %1 %2\n"; QString idDefine = QString("#define MAVLINK_MSG_ID_%1 %2").arg(messageName.toUpper(), QString::number(messageId)); + QString arrayDefines = ""; QString cStructName = QString("mavlink_%1_t").arg(messageName); QString cStruct = "typedef struct __%1 \n{\n%2\n} %1;"; QString cStructLines = ""; @@ -137,6 +138,7 @@ bool MAVLinkXMLParser::generate() packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); //%4\n").arg(arrayType, fieldName, QString::number(arrayLength), e2.text()); // Add decode function for this type decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName); + arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength)); } else // Handle simple types like integers and floats @@ -206,7 +208,7 @@ bool MAVLinkXMLParser::generate() encode = encode.arg(messageName).arg(cStructName).arg(packArguments); decode = decode.arg(messageName).arg(cStructName).arg(decodeLines); compactSend = compactSend.arg(channelType, messageType, messageName, sendArguments, packParameters); - QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + encode + "\n" + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + decode; + QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + arrayDefines + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + encode + "\n" + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + decode; cFiles.append(qMakePair(QString("mavlink_msg_%1.h").arg(messageName), cFile)); } } diff --git a/src/uas/UAS.cc b/src/uas/UAS.cc index 07de03641f90ae07d855a65929241e84693c8cfc..8ac5e5e08301a2581f26367a05a30b1dc52fe63e 100644 --- a/src/uas/UAS.cc +++ b/src/uas/UAS.cc @@ -154,6 +154,9 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message) case MAV_MODE_AUTO: mode = "AUTO MODE"; break; + case MAV_MODE_GUIDED: + mode = "GUIDED MODE"; + break; case MAV_MODE_READY: mode = "READY"; break; @@ -547,7 +550,31 @@ void UAS::requestWaypoints() void UAS::requestParameters() { mavlink_message_t msg; - mavlink_msg_param_request_list_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg); + mavlink_msg_param_request_list_pack(mavlink->getSystemId(), mavlink->getComponentId(), &msg, this->getUASID(), 0); + sendMessage(msg); +} + +void UAS::writeParameters() +{ + mavlink_message_t msg; + +} + +void UAS::setParameter(int component, QString id, float value) +{ + mavlink_message_t msg; + mavlink_param_set_t p; + p.param_value = value; + p.target_system = uasId; + p.target_component = component; + + // Copy string into buffer, ensuring not to exceed the buffer size + char* s = (char*)id.toStdString().c_str(); + for (int i = 0; (i < id.length() && i < sizeof(p.param_id)); i++) + { + p.param_id[i] = *s; + } + mavlink_msg_param_set_encode(mavlink->getSystemId(), mavlink->getComponentId(), &msg, &p); sendMessage(msg); } diff --git a/src/uas/UAS.h b/src/uas/UAS.h index 8b702dbc95856d3a2d48ae2e756b236c1ff80579..21737d2c6d7a311f1971a79b2f95d9ac4ef700a4 100644 --- a/src/uas/UAS.h +++ b/src/uas/UAS.h @@ -51,7 +51,8 @@ public: UAS(MAVLinkProtocol* protocol, int id = 0); ~UAS(); - enum BatteryType { + enum BatteryType + { NICD = 0, NIMH = 1, LIION = 2, @@ -187,6 +188,12 @@ public slots: /** @brief Set current mode of operation, e.g. auto or manual */ void setMode(int mode); + /** @brief Set a system parameter */ + void setParameter(int component, QString id, float value); + + /** @brief Write parameters to permanent storage */ + void writeParameters(); + signals: /** @brief The main/battery voltage has changed/was updated */ diff --git a/src/uas/UASInterface.h b/src/uas/UASInterface.h index 7db0a5ce0792e1cbcbcab579349712799d882aa1..3757ed099f977ad81cbb153e25cb241e120f4207 100644 --- a/src/uas/UASInterface.h +++ b/src/uas/UASInterface.h @@ -173,6 +173,15 @@ public slots: virtual void clearWaypointList() = 0; /** @brief Request all onboard parameters of all components */ virtual void requestParameters() = 0; + /** @brief Write parameter to permanent storage */ + virtual void writeParameters() = 0; + /** @brief Set a system parameter + * @param component ID of the system component to write the parameter to + * @param id String identifying the parameter + * @warning The length of the ID string is limited by the MAVLink format! Take care to not exceed it + * @param value Value of the parameter, IEEE 754 single precision floating point + */ + virtual void setParameter(int component, QString id, float value) = 0; /** * @brief Add a link to the list of current links diff --git a/src/ui/ParameterInterface.cc b/src/ui/ParameterInterface.cc index 469d8f218f22254c64aa3b674e9d51b0be60aa2d..546c214545b60f9e1b2341d8ccd57e9b7db5e899 100644 --- a/src/ui/ParameterInterface.cc +++ b/src/ui/ParameterInterface.cc @@ -17,7 +17,6 @@ ParameterInterface::ParameterInterface(QWidget *parent) : // Setup UI connections connect(m_ui->vehicleComboBox, SIGNAL(activated(int)), this, SLOT(selectUAS(int))); - connect(m_ui->readParamsButton, SIGNAL(clicked()), this, SLOT(requestParameterList())); // Setup MAV connections connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); @@ -51,78 +50,8 @@ void ParameterInterface::addUAS(UASInterface* uas) curr = uas->getUASID(); qDebug() << "first widget"; } - - // Connect signals - connect(uas, SIGNAL(parameterChanged(int,int,QString,float)), this, SLOT(addParameter(int,int,QString,float))); -} - -void ParameterInterface::requestParameterList() -{ - UASInterface* mav; - QGCParamWidget* widget = paramWidgets->value(curr); - if (widget != NULL) - { - mav = widget->getUAS(); - mav->requestParameters(); - // Clear view - widget->clear(); - } -} - -/** - * - * @param uas System which has the component - * @param component id of the component - * @param componentName human friendly name of the component - */ -void ParameterInterface::addComponent(int uas, int component, QString componentName) -{ - QGCParamWidget* widget = paramWidgets->value(uas); - if (widget != NULL) - { - widget->addComponent(component, componentName); - } -} - -void ParameterInterface::addParameter(int uas, int component, QString parameterName, float value) -{ - QGCParamWidget* widget = paramWidgets->value(uas); - if (widget != NULL) - { - widget->addParameter(component, parameterName, value); - } } -/** - * @param uas system - * @param component the subsystem which has the parameter - * @param parameterName name of the parameter, as delivered by the system - * @param value value of the parameter - */ -void ParameterInterface::setParameter(UASInterface* uas, int component, QString parameterName, float value) -{ - Q_UNUSED(uas); -} - -/** - * @param - */ -void ParameterInterface::commitParameter(UASInterface* uas, int component, QString parameterName, float value) -{ - -} - -/* -void ParameterInterface::commitParameters(UASInterface* uas) -{ - -}*/ - -/** - * - */ - - void ParameterInterface::changeEvent(QEvent *e) { switch (e->type()) { diff --git a/src/ui/ParameterInterface.h b/src/ui/ParameterInterface.h index f8848e5d7046f307886d5af1b0d0d69337cf75fa..3b0ded750bfc5e526cae9ecbd7ef6c75facec58a 100644 --- a/src/ui/ParameterInterface.h +++ b/src/ui/ParameterInterface.h @@ -2,9 +2,7 @@ #define PARAMETERINTERFACE_H #include -#include -#include -#include + #include "ui_ParameterInterface.h" #include "UASInterface.h" #include "ParamTreeModel.h" @@ -23,11 +21,6 @@ public: public slots: void addUAS(UASInterface* uas); void selectUAS(int index); - void addComponent(int uas, int component, QString componentName); - void addParameter(int uas, int component, QString parameterName, float value); - void requestParameterList(); - void setParameter(UASInterface* uas, int component, QString parameterName, float value); - void commitParameter(UASInterface* uas, int component, QString parameterName, float value); protected: virtual void changeEvent(QEvent *e); diff --git a/src/ui/ParameterInterface.ui b/src/ui/ParameterInterface.ui index a48cac827dcbaa49440d0d90f88e3a4a549a1298..7d6d62ad70e7043d0bc46143388af27d67d3e0fe 100644 --- a/src/ui/ParameterInterface.ui +++ b/src/ui/ParameterInterface.ui @@ -110,31 +110,10 @@ - + - - - - Read - - - - - - - Write permanently - - - - - - - Backup - - - - + diff --git a/src/ui/QGCParamWidget.cc b/src/ui/QGCParamWidget.cc index 25f34419475f3b9f10a63aef61696bc13fd7b2a1..f270e3aa6f146f3d7093f7fbbcda4a4200fbe1f5 100644 --- a/src/ui/QGCParamWidget.cc +++ b/src/ui/QGCParamWidget.cc @@ -1,26 +1,41 @@ -#include +#include +#include #include "QGCParamWidget.h" #include "UASInterface.h" #include QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : - QWidget(parent), - mav(uas), - components(new QMap()) + QWidget(parent), + mav(uas), + components(new QMap()) { // Create tree widget tree = new QTreeWidget(this); + tree->setColumnWidth(0, 150); // Set tree widget as widget onto this component - QHBoxLayout* horizontalLayout; + QGridLayout* horizontalLayout; //form->setAutoFillBackground(false); - horizontalLayout = new QHBoxLayout(this); - horizontalLayout->setSpacing(0); + horizontalLayout = new QGridLayout(this); + horizontalLayout->setSpacing(6); horizontalLayout->setMargin(0); horizontalLayout->setSizeConstraint(QLayout::SetMinimumSize); - horizontalLayout->addWidget(tree); + horizontalLayout->addWidget(tree, 0, 0, 1, 3); + QPushButton* readButton = new QPushButton(tr("Read")); + connect(readButton, SIGNAL(clicked()), this, SLOT(requestParameterList())); + horizontalLayout->addWidget(readButton, 1, 0); + + QPushButton* setButton = new QPushButton(tr("Set (RAM)")); + connect(setButton, SIGNAL(clicked()), this, SLOT(setParameters())); + horizontalLayout->addWidget(setButton, 1, 1); + + QPushButton* writeButton = new QPushButton(tr("Write (Disk)")); + connect(writeButton, SIGNAL(clicked()), this, SLOT(writeParameters())); + horizontalLayout->addWidget(writeButton, 1, 2); + + // Set layout this->setLayout(horizontalLayout); // Set header @@ -29,6 +44,11 @@ QGCParamWidget::QGCParamWidget(UASInterface* uas, QWidget *parent) : headerItems.append("Value"); tree->setHeaderLabels(headerItems); tree->setColumnCount(2); + + // Connect signals/slots + connect(this, SIGNAL(parameterChanged(int,QString,float)), mav, SLOT(setParameter(int,QString,float))); + // New parameters from UAS + connect(uas, SIGNAL(parameterChanged(int,int,QString,float)), this, SLOT(addParameter(int,int,QString,float))); } UASInterface* QGCParamWidget::getUAS() @@ -42,8 +62,9 @@ UASInterface* QGCParamWidget::getUAS() * @param component id of the component * @param componentName human friendly name of the component */ -void QGCParamWidget::addComponent(int component, QString componentName) +void QGCParamWidget::addComponent(int uas, int component, QString componentName) { + Q_UNUSED(uas); QStringList list; list.append(componentName); list.append(QString::number(component)); @@ -58,8 +79,14 @@ void QGCParamWidget::addComponent(int component, QString componentName) } } -void QGCParamWidget::addParameter(int component, QString parameterName, float value) +/** + * @param uas System which has the component + * @param component id of the component + * @param parameterName human friendly name of the parameter + */ +void QGCParamWidget::addParameter(int uas, int component, QString parameterName, float value) { + Q_UNUSED(uas); // Insert parameter into map //tree->appendParam(component, parameterName, value); QStringList plist; @@ -70,12 +97,49 @@ void QGCParamWidget::addParameter(int component, QString parameterName, float va // Get component if (!components->contains(component)) { - addComponent(component, "Component #" + QString::number(component)); + addComponent(uas, component, "Component #" + QString::number(component)); } components->value(component)->addChild(item); + item->setFlags(item->flags() | Qt::ItemIsEditable); + //connect(item, SIGNAL()) + tree->expandAll(); tree->update(); } +void QGCParamWidget::requestParameterList() +{ + mav->requestParameters(); + // Clear view + clear(); +} + +/** + * @param component the subsystem which has the parameter + * @param parameterName name of the parameter, as delivered by the system + * @param value value of the parameter + */ +void QGCParamWidget::setParameter(int component, QString parameterName, float value) +{ + +} + +void QGCParamWidget::setParameters() +{ + //mav->setParameter(component, parameterName, value); + // Iterate through all components, through all parameters and emit them + /*QMap::iterator i; + for (i = components->begin(); i != components->end(); ++i) + { + int compid = i.key(); + i.value()->children(); + }*/ +} + +void QGCParamWidget::writeParameters() +{ + mav->writeParameters(); +} + void QGCParamWidget::clear() { tree->clear(); diff --git a/src/ui/QGCParamWidget.h b/src/ui/QGCParamWidget.h index 87c56b3874263cc284f20e64595836f7ad670edb..e794ba2cfd3127765852f6b7b87eff10606f1eeb 100644 --- a/src/ui/QGCParamWidget.h +++ b/src/ui/QGCParamWidget.h @@ -8,22 +8,37 @@ #include "UASInterface.h" +/** + * @brief Widget to read/set onboard parameters + */ class QGCParamWidget : public QWidget { Q_OBJECT public: explicit QGCParamWidget(UASInterface* uas, QWidget *parent = 0); + /** @brief Get the UAS of this widget */ UASInterface* getUAS(); signals: - + void parameterChanged(int component, QString parametername, float value); public slots: - void addComponent(int component, QString componentName); - void addParameter(int component, QString parameterName, float value); + /** @brief Add a component to the list */ + void addComponent(int uas, int component, QString componentName); + /** @brief Add a parameter to the list */ + void addParameter(int uas, int component, QString parameterName, float value); + /** @brief Request list of parameters from MAV */ + void requestParameterList(); + /** @brief Set one parameter, changes value in RAM of MAV */ + void setParameter(int component, QString parameterName, float value); + /** @brief Set all parameters, changes the value in RAM of MAV */ + void setParameters(); + /** @brief Write the current parameters to permanent storage (EEPROM/HDD) */ + void writeParameters(); + /** @brief Clear the parameter list */ void clear(); protected: - UASInterface* mav; - QTreeWidget* tree; - QMap* components; + UASInterface* mav; ///< The MAV this widget is controlling + QTreeWidget* tree; ///< The parameter tree + QMap* components; ///< The list of components };