QGCUASParamManager.cc 2.67 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 12 13
    mav(uas),
    paramDataModel(NULL),
    paramCommsMgr(NULL)
14
{
15
    paramDataModel = uas->getParamDataModel();
tstellanova's avatar
tstellanova committed
16 17 18 19 20 21
    paramCommsMgr = uas->getParamCommsMgr();
    mav->setParamManager(this);

    // Load default values and tooltips
    loadParamMetaInfoCSV();

tstellanova's avatar
tstellanova committed
22 23


24 25 26
}


27 28
bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
29
    return paramDataModel->getOnboardParamValue(component,parameter,value);
tstellanova's avatar
tstellanova committed
30
}
31

tstellanova's avatar
tstellanova committed
32

33 34 35
void QGCUASParamManager::requestParameterUpdate(int component, const QString& parameter)
{
    if (mav) {
tstellanova's avatar
tstellanova committed
36
        paramCommsMgr->requestParameterUpdate(component,parameter);
37 38 39
    }
}

tstellanova's avatar
tstellanova committed
40 41


tstellanova's avatar
tstellanova committed
42 43 44 45 46 47 48 49 50
/**
 * Send a request to deliver the list of onboard parameters
 * to the MAV.
 */
void QGCUASParamManager::requestParameterList()
{
    if (!mav) {
        return;
    }
tstellanova's avatar
tstellanova committed
51
    //paramDataModel->forgetAllOnboardParameters(); //TODO really??
tstellanova's avatar
tstellanova committed
52
    setParameterStatusMsg(tr("Requested param list.. waiting"));
tstellanova's avatar
tstellanova committed
53
    paramCommsMgr->requestParameterList();
tstellanova's avatar
tstellanova committed
54
}
55 56 57 58 59 60 61 62 63 64 65 66 67


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
68 69 70 71
void QGCUASParamManager::setParameter(int component, QString parameterName, QVariant value)
{
    paramCommsMgr->setParameter(component,parameterName,value);
}
tstellanova's avatar
tstellanova committed
72

tstellanova's avatar
tstellanova committed
73 74 75 76 77 78
void QGCUASParamManager::sendPendingParameters()
{
    paramCommsMgr->sendPendingParameters();
}


tstellanova's avatar
tstellanova committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

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;
}