QGCUASParamManager.cc 3.13 KB
Newer Older
1 2
#include "QGCUASParamManager.h"

tstellanova's avatar
tstellanova committed
3 4 5 6
#include <QApplication>>
#include <QDir>

#include "UASInterface.h"
tstellanova's avatar
tstellanova committed
7 8
#include "UASParameterCommsMgr.h"

9 10
QGCUASParamManager::QGCUASParamManager(UASInterface* uas, QWidget *parent) :
    QWidget(parent),
tstellanova's avatar
tstellanova committed
11
    mav(uas)
12
{
13
    paramDataModel = uas->getParamDataModel();
tstellanova's avatar
tstellanova committed
14 15 16 17 18 19
    paramCommsMgr = uas->getParamCommsMgr();
    mav->setParamManager(this);

    // Load default values and tooltips
    loadParamMetaInfoCSV();

tstellanova's avatar
tstellanova committed
20

tstellanova's avatar
tstellanova committed
21 22 23
//    // Connect retransmission guard
//    connect(this, SIGNAL(parameterUpdateRequested(int,QString)),
//            this, SLOT(requestParameterUpdate(int,QString)));
tstellanova's avatar
tstellanova committed
24 25 26 27 28 29 30

//    //TODO connect in paramCommsMgr instead
//    connect(this, SIGNAL(parameterUpdateRequestedById(int,int)),
//            mav, SLOT(requestParameter(int,int)));

    // New parameters from UAS

tstellanova's avatar
tstellanova committed
31
    void parameterUpdated(int compId, QString paramName, QVariant value);
tstellanova's avatar
tstellanova committed
32 33 34 35 36 37 38


//    connect(uas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)),
//            this, SLOT(receivedParameterUpdate(int,int,int,int,QString,QVariant)));



tstellanova's avatar
tstellanova committed
39 40


41 42 43
}


44 45
bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
tstellanova's avatar
tstellanova committed
46 47
    return paramDataModel->getOnboardParameterValue(component,parameter,value);
}
48

tstellanova's avatar
tstellanova committed
49

50 51 52
void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter)
{
    if (mav) {
tstellanova's avatar
tstellanova committed
53
        paramCommsMgr->requestParameterUpdate(component,parameter);
54 55 56
    }
}

tstellanova's avatar
tstellanova committed
57 58


tstellanova's avatar
tstellanova committed
59 60 61 62 63 64 65 66 67
/**
 * Send a request to deliver the list of onboard parameters
 * to the MAV.
 */
void QGCUASParamManager::requestParameterList()
{
    if (!mav) {
        return;
    }
tstellanova's avatar
tstellanova committed
68
    //paramDataModel->forgetAllOnboardParameters(); //TODO really??
tstellanova's avatar
tstellanova committed
69
    setParameterStatusMsg(tr("Requested param list.. waiting"));
tstellanova's avatar
tstellanova committed
70
    paramCommsMgr->requestParameterList();
tstellanova's avatar
tstellanova committed
71
}
72 73 74 75 76 77 78 79 80 81 82 83 84


void QGCUASParamManager::setParameterStatusMsg(const QString& msg)
{
    qDebug() << "parameterStatusMsg: " << msg;
    parameterStatusMsg = msg;
}

void QGCUASParamManager::setParamDescriptions(const QMap<QString,QString>& paramInfo) {
    paramDataModel->setParamDescriptions(paramInfo);
}


tstellanova's avatar
tstellanova committed
85 86 87 88
void QGCUASParamManager::setParameter(int component, QString parameterName, QVariant value)
{
    paramCommsMgr->setParameter(component,parameterName,value);
}
tstellanova's avatar
tstellanova committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121


void QGCUASParamManager::loadParamMetaInfoCSV()
{
    // Load default values and tooltips
    QString autopilot(mav->getAutopilotTypeName());

    QDir appDir = QApplication::applicationDirPath();
    appDir.cd("files");
    QString fileName = QString("%1/%2/parameter_tooltips/tooltips.txt").arg(appDir.canonicalPath()).arg(autopilot.toLower());
    QFile paramMetaFile(fileName);

    qDebug() << "loadParamMetaInfoCSV for autopilot: " << autopilot << " from file: " << fileName;

    if (!paramMetaFile.open(QIODevice::ReadOnly | QIODevice::Text))  {
        qWarning() << "loadParamMetaInfoCSV couldn't open:" << fileName;
        return;
    }

    QTextStream in(&paramMetaFile);
    paramDataModel->loadParamMetaInfoFromStream(in);
    paramMetaFile.close();

}

/**
 * @return The MAV of this mgr. Unless the MAV object has been destroyed, this
 *         pointer is never zero.
 */
UASInterface* QGCUASParamManager::getUAS()
{
    return mav;
}