Skip to content
Snippets Groups Projects
QGCParamWidget.h 4.33 KiB
Newer Older
  • Learn to ignore specific revisions
  • /*=====================================================================
    
    QGroundControl Open Source Ground Control Station
    
    
    (c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
    
    
    This file is part of the QGROUNDCONTROL project
    
        QGROUNDCONTROL 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.
    
        QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
    
    ======================================================================*/
    
    /**
     * @file
     *   @brief Declaration of class QGCParamWidget
     *   @author Lorenz Meier <mail@qgroundcontrol.org>
     */
    
    
    pixhawk's avatar
    pixhawk committed
    #ifndef QGCPARAMWIDGET_H
    #define QGCPARAMWIDGET_H
    
    #include <QWidget>
    #include <QTreeWidget>
    #include <QTreeWidgetItem>
    #include <QMap>
    
    lm's avatar
    lm committed
    #include <QLabel>
    
    pixhawk's avatar
    pixhawk committed
    
    #include "UASInterface.h"
    
    
    /**
     * @brief Widget to read/set onboard parameters
     */
    
    pixhawk's avatar
    pixhawk committed
    class QGCParamWidget : public QWidget
    {
    Q_OBJECT
    public:
        explicit QGCParamWidget(UASInterface* uas, QWidget *parent = 0);
    
        /** @brief Get the UAS of this widget */
    
    pixhawk's avatar
    pixhawk committed
        UASInterface* getUAS();
    signals:
    
        /** @brief A parameter was changed in the widget, NOT onboard */
    
        void parameterChanged(int component, QString parametername, float value);
    
        /** @brief Request a single parameter */
        void requestParameter(int component, int parameter);
    
    pixhawk's avatar
    pixhawk committed
    public slots:
    
        /** @brief Add a component to the list */
        void addComponent(int uas, int component, QString componentName);
    
    lm's avatar
    lm committed
        /** @brief Add a parameter to the list with retransmission / safety checks */
        void addParameter(int uas, int component, int paramCount, int paramId, QString parameterName, float value);
    
        /** @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 Read the parameters from permanent storage to RAM */
        void readParameters();
    
        /** @brief Clear the parameter list */
    
    pixhawk's avatar
    pixhawk committed
        void clear();
    
    lm's avatar
    lm committed
        /** @brief Update when user changes parameters */
    
        void parameterItemChanged(QTreeWidgetItem* prev, int column);
    
    
        /** @brief Store parameters to a file */
        void saveParameters();
        /** @brief Load parameters from a file */
        void loadParameters();
    
    
        /** @brief Check for missing parameters */
        void retransmissionGuardTick();
    
    
    pixhawk's avatar
    pixhawk committed
    protected:
    
    lm's avatar
    lm committed
        UASInterface* mav;   ///< The MAV this widget is controlling
        QTreeWidget* tree;   ///< The parameter tree
        QLabel* statusLabel; ///< Parameter transmission label
    
        QMap<int, QTreeWidgetItem*>* components; ///< The list of components
    
    pixhawk's avatar
    pixhawk committed
        QMap<int, QMap<QString, QTreeWidgetItem*>* > paramGroups; ///< Parameter groups
    
    lm's avatar
    lm committed
        QMap<int, QMap<QString, float>* > changedValues; ///< Changed values
    
        QMap<int, QMap<QString, float>* > parameters; ///< All parameters
    
    lm's avatar
    lm committed
        QVector<bool> received; ///< Successfully received parameters
    
    lm's avatar
    lm committed
        QMap<int, QList<int>* > transmissionMissingPackets; ///< Missing packets
        bool transmissionListMode;       ///< Currently requesting list
        QMap<int, bool> transmissionListSizeKnown;  ///< List size initialized?
        bool transmissionActive;         ///< Missing packets, working on list?
        quint64 transmissionStarted;     ///< Timeout
    
        QTimer retransmissionTimer;      ///< Timer handling parameter retransmission
    
    lm's avatar
    lm committed
        const static int retransmissionTimeout = 250; ///< Retransmission request timeout, in milliseconds
    
    
        /** @brief Activate / deactivate parameter retransmission */
        void setRetransmissionGuardEnabled(bool enabled);
    
    pixhawk's avatar
    pixhawk committed
    };
    
    #endif // QGCPARAMWIDGET_H